surfaceRedistributePar.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include "treeBoundBox.H"
00042 #include "FixedList.H"
00043 #include "argList.H"
00044 #include "Time.H"
00045 #include "polyMesh.H"
00046 #include "distributedTriSurfaceMesh.H"
00047 #include "mapDistribute.H"
00048 #include "triSurfaceFields.H"
00049 #include "Pair.H"
00050
00051 using namespace Foam;
00052
00053
00054
00055
00056 void writeProcStats
00057 (
00058 const triSurface& s,
00059 const List<List<treeBoundBox> >& meshBb
00060 )
00061 {
00062
00063 List<treeBoundBox> surfBb(Pstream::nProcs());
00064 {
00065 surfBb[Pstream::myProcNo()] = boundBox(s.points(), false);
00066 Pstream::gatherList(surfBb);
00067 Pstream::scatterList(surfBb);
00068 }
00069
00070 labelList nPoints(Pstream::nProcs());
00071 nPoints[Pstream::myProcNo()] = s.points().size();
00072 Pstream::gatherList(nPoints);
00073 Pstream::scatterList(nPoints);
00074
00075 labelList nFaces(Pstream::nProcs());
00076 nFaces[Pstream::myProcNo()] = s.size();
00077 Pstream::gatherList(nFaces);
00078 Pstream::scatterList(nFaces);
00079
00080 forAll(surfBb, procI)
00081 {
00082 const List<treeBoundBox>& bbs = meshBb[procI];
00083
00084 Info<< "processor" << procI << endl
00085 << "\tMesh bounds : " << bbs[0] << nl;
00086 for (label i = 1; i < bbs.size(); i++)
00087 {
00088 Info<< "\t " << bbs[i]<< nl;
00089 }
00090 Info<< "\tSurface bounding box : " << surfBb[procI] << nl
00091 << "\tTriangles : " << nFaces[procI] << nl
00092 << "\tVertices : " << nPoints[procI]
00093 << endl;
00094 }
00095 Info<< endl;
00096 }
00097
00098
00099
00100
00101 int main(int argc, char *argv[])
00102 {
00103 argList::validArgs.append("triSurfaceMesh");
00104 argList::validArgs.append("distributionType");
00105
00106 argList::validOptions.insert("keepNonMapped", "");
00107 # include "setRootCase.H"
00108 # include "createTime.H"
00109 runTime.functionObjects().off();
00110
00111 fileName surfFileName(args.additionalArgs()[0]);
00112 Info<< "Reading surface from " << surfFileName << nl << endl;
00113
00114 const word distType(args.additionalArgs()[1]);
00115
00116 Info<< "Using distribution method "
00117 << distributedTriSurfaceMesh::distributionTypeNames_[distType]
00118 << " " << distType << nl << endl;
00119
00120 bool keepNonMapped = args.options().found("keepNonMapped");
00121
00122 if (keepNonMapped)
00123 {
00124 Info<< "Preserving surface outside of mesh bounds." << nl << endl;
00125 }
00126 else
00127 {
00128 Info<< "Removing surface outside of mesh bounds." << nl << endl;
00129 }
00130
00131
00132 if (!Pstream::parRun())
00133 {
00134 FatalErrorIn(args.executable())
00135 << "Please run this program on the decomposed case."
00136 << " It will read surface " << surfFileName
00137 << " and decompose it such that it overlaps the mesh bounding box."
00138 << exit(FatalError);
00139 }
00140
00141
00142 # include "createPolyMesh.H"
00143
00144 Random rndGen(653213);
00145
00146
00147 List<List<treeBoundBox> > meshBb(Pstream::nProcs());
00148 {
00149 meshBb[Pstream::myProcNo()] = List<treeBoundBox>
00150 (
00151 1,
00152 treeBoundBox
00153 (
00154 boundBox(mesh.points(), false)
00155 ).extend(rndGen, 1E-3)
00156 );
00157 Pstream::gatherList(meshBb);
00158 Pstream::scatterList(meshBb);
00159 }
00160
00161 IOobject io
00162 (
00163 surfFileName,
00164
00165 runTime.constant(),
00166 "triSurface",
00167 runTime,
00168 IOobject::MUST_READ,
00169 IOobject::NO_WRITE
00170 );
00171
00172 const fileName actualPath(io.filePath());
00173 fileName localPath(actualPath);
00174 localPath.replace(runTime.rootPath() + '/', "");
00175
00176 if (actualPath == io.objectPath())
00177 {
00178 Info<< "Loading local (decomposed) surface " << localPath << nl <<endl;
00179 }
00180 else
00181 {
00182 Info<< "Loading undecomposed surface " << localPath << nl << endl;
00183 }
00184
00185
00186
00187 if (!isFile(actualPath / "Dict"))
00188 {
00189 dictionary dict;
00190 dict.add("bounds", meshBb[Pstream::myProcNo()]);
00191 dict.add("distributionType", distType);
00192 dict.add("mergeDistance", SMALL);
00193
00194 IOdictionary ioDict
00195 (
00196 IOobject
00197 (
00198 io.name() + "Dict",
00199 io.instance(),
00200 io.local(),
00201 io.db(),
00202 IOobject::NO_READ,
00203 IOobject::NO_WRITE,
00204 false
00205 ),
00206 dict
00207 );
00208
00209 Info<< "Writing dummy bounds dictionary to " << ioDict.name()
00210 << nl << endl;
00211
00212 ioDict.regIOobject::writeObject
00213 (
00214 IOstream::ASCII,
00215 IOstream::currentVersion,
00216 ioDict.time().writeCompression()
00217 );
00218 }
00219
00220
00221
00222 distributedTriSurfaceMesh surfMesh(io);
00223 Info<< "Loaded surface" << nl << endl;
00224
00225
00226
00227 {
00228 const triSurface& s = static_cast<const triSurface&>(surfMesh);
00229
00230 autoPtr<triSurfaceVectorField> fcPtr
00231 (
00232 new triSurfaceVectorField
00233 (
00234 IOobject
00235 (
00236 surfMesh.searchableSurface::name(),
00237 surfMesh.searchableSurface::instance(),
00238 surfMesh.searchableSurface::local(),
00239 surfMesh,
00240 IOobject::NO_READ,
00241 IOobject::AUTO_WRITE
00242 ),
00243 surfMesh,
00244 dimLength
00245 )
00246 );
00247 triSurfaceVectorField& fc = fcPtr();
00248
00249 forAll(fc, triI)
00250 {
00251 fc[triI] = s[triI].centre(s.points());
00252 }
00253
00254
00255 fcPtr.ptr()->store();
00256 }
00257
00258
00259
00260 Info<< "Before redistribution:" << endl;
00261 writeProcStats(surfMesh, meshBb);
00262
00263
00264
00265 Info<< "Redistributing surface" << nl << endl;
00266 autoPtr<mapDistribute> faceMap;
00267 autoPtr<mapDistribute> pointMap;
00268 surfMesh.distribute
00269 (
00270 meshBb[Pstream::myProcNo()],
00271 keepNonMapped,
00272 faceMap,
00273 pointMap
00274 );
00275 faceMap.clear();
00276 pointMap.clear();
00277
00278 Info<< endl;
00279
00280
00281
00282 Info<< "After redistribution:" << endl;
00283 writeProcStats(surfMesh, meshBb);
00284
00285
00286 Info<< "Writing surface." << nl << endl;
00287 surfMesh.searchableSurface::write();
00288
00289 Info<< "End\n" << endl;
00290
00291 return 0;
00292 }
00293
00294
00295
Copyright © 2000-2009 OpenCFD Ltd