surfaceMeshTriangulate.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 #include "argList.H"
00037 #include "Time.H"
00038 #include "polyMesh.H"
00039 #include "triSurface.H"
00040 #include "triSurfaceTools.H"
00041 #include "processorPolyPatch.H"
00042 #include "ListListOps.H"
00043
00044 using namespace Foam;
00045
00046
00047
00048
00049
00050 int main(int argc, char *argv[])
00051 {
00052 argList::validArgs.append("output file");
00053 # include "addRegionOption.H"
00054 argList::validOptions.insert("excludeProcPatches", "");
00055 argList::validOptions.insert("patches", "(patch0 .. patchN)");
00056
00057 # include "setRootCase.H"
00058 # include "createTime.H"
00059
00060 fileName outFileName(runTime.path()/args.additionalArgs()[0]);
00061
00062 Info<< "Extracting triSurface from boundaryMesh ..."
00063 << endl << endl;
00064
00065 Pout<< "Reading mesh from time " << runTime.value() << endl;
00066
00067 # include "createNamedPolyMesh.H"
00068
00069 bool includeProcPatches =
00070 !(
00071 args.optionFound("excludeProcPatches")
00072 || Pstream::parRun()
00073 );
00074
00075
00076
00077
00078
00079
00080
00081
00082 const polyBoundaryMesh& bMesh = mesh.boundaryMesh();
00083
00084 labelHashSet includePatches(bMesh.size());
00085
00086 if (args.optionFound("patches"))
00087 {
00088 wordList patchNames(args.optionLookup("patches")());
00089
00090 forAll(patchNames, patchNameI)
00091 {
00092 const word& patchName = patchNames[patchNameI];
00093
00094 label patchI = bMesh.findPatchID(patchName);
00095
00096 if (patchI == -1)
00097 {
00098 FatalErrorIn(args.executable()) << "No such patch "
00099 << patchName << endl << "Patches are " << bMesh.names()
00100 << exit(FatalError);
00101 }
00102 includePatches.insert(patchI);
00103 }
00104 }
00105 else
00106 {
00107 forAll(bMesh, patchI)
00108 {
00109 const polyPatch& patch = bMesh[patchI];
00110
00111 if
00112 (
00113 includeProcPatches
00114 || (patch.type() != processorPolyPatch::typeName)
00115 )
00116 {
00117 includePatches.insert(patchI);
00118 }
00119 else
00120 {
00121 Pout<< patch.name() << " : skipped since processorPatch"
00122 << endl;
00123 }
00124 }
00125 }
00126
00127 triSurface localSurface
00128 (
00129 triSurfaceTools::triangulate
00130 (
00131 mesh.boundaryMesh(),
00132 includePatches
00133 )
00134 );
00135
00136
00137
00138 if (!Pstream::parRun())
00139 {
00140 Info<< "Writing surface to " << outFileName << endl;
00141
00142 localSurface.write(outFileName);
00143 }
00144 else
00145 {
00146
00147 fileName localPath = runTime.path()/runTime.caseName() + ".ftr";
00148
00149 Pout<< "Writing local surface to " << localPath << endl;
00150
00151 localSurface.write(localPath);
00152
00153 Info<< endl;
00154
00155
00156
00157 List<pointField> gatheredPoints(Pstream::nProcs());
00158
00159 gatheredPoints[Pstream::myProcNo()] = localSurface.points();
00160
00161 Pstream::gatherList(gatheredPoints);
00162
00163
00164
00165 List<geometricSurfacePatchList> gatheredPatches(Pstream::nProcs());
00166
00167 gatheredPatches[Pstream::myProcNo()] = localSurface.patches();
00168
00169 Pstream::gatherList(gatheredPatches);
00170
00171
00172
00173 List<List<labelledTri> > gatheredFaces(Pstream::nProcs());
00174
00175 gatheredFaces[Pstream::myProcNo()] = localSurface;
00176
00177 Pstream::gatherList(gatheredFaces);
00178
00179
00180 if (Pstream::master())
00181 {
00182
00183 pointField allPoints =
00184 ListListOps::combine<pointField>
00185 (
00186 gatheredPoints,
00187 accessOp<pointField>()
00188 );
00189
00190
00191 label nPatches = 0;
00192
00193 forAll(gatheredPatches, procI)
00194 {
00195 nPatches += gatheredPatches[procI].size();
00196 }
00197
00198
00199 label nFaces = 0;
00200
00201 forAll(gatheredFaces, procI)
00202 {
00203 nFaces += gatheredFaces[procI].size();
00204 }
00205
00206
00207
00208
00209
00210
00211
00212 label newPatchI = 0;
00213
00214
00215 HashTable<label> nameToIndex(2*nPatches);
00216
00217
00218 geometricSurfacePatchList allPatches(nPatches);
00219
00220 label newFaceI = 0;
00221
00222
00223 List<labelledTri> allFaces(nFaces);
00224
00225
00226 label pointOffset = 0;
00227
00228 for (label procI = 0; procI < Pstream::nProcs(); procI++)
00229 {
00230 Info<< "Processor " << procI << endl
00231 << "-----------" << endl;
00232
00233 const geometricSurfacePatchList& patches =
00234 gatheredPatches[procI];
00235
00236
00237 labelList localToGlobal(patches.size());
00238
00239 forAll(patches, patchI)
00240 {
00241 const geometricSurfacePatch& sp = patches[patchI];
00242
00243 if (!nameToIndex.found(sp.name()))
00244 {
00245 nameToIndex.insert(sp.name(), newPatchI);
00246
00247 localToGlobal[patchI] = newPatchI;
00248
00249 allPatches[newPatchI] = sp;
00250
00251 newPatchI++;
00252 }
00253 else
00254 {
00255 localToGlobal[patchI] = nameToIndex[sp.name()];
00256 }
00257 }
00258
00259 Info<< "Local patch to global patch mapping:"
00260 << endl;
00261
00262 forAll(patches, patchI)
00263 {
00264 Info<< " name : " << patches[patchI].name() << endl
00265 << " local : " << patchI << endl
00266 << " global : " << localToGlobal[patchI]
00267 << endl;
00268 }
00269
00270 Info<< "Local points added in global points starting at "
00271 << pointOffset
00272 << endl;
00273
00274
00275
00276 const List<labelledTri>& localFaces = gatheredFaces[procI];
00277
00278
00279 forAll(localFaces, faceI)
00280 {
00281 const labelledTri& f = localFaces[faceI];
00282
00283 allFaces[newFaceI++] =
00284 labelledTri
00285 (
00286 f[0] + pointOffset,
00287 f[1] + pointOffset,
00288 f[2] + pointOffset,
00289 localToGlobal[f.region()]
00290 );
00291 }
00292
00293 pointOffset += gatheredPoints[procI].size();
00294
00295 Info<< endl;
00296 }
00297 allPatches.setSize(newPatchI);
00298
00299
00300
00301
00302 triSurface allSurf(allFaces, allPatches, allPoints);
00303
00304
00305 allSurf.cleanup(false);
00306
00307
00308
00309 label slashIndex = runTime.caseName().find_last_of('/');
00310
00311 fileName globalCasePath(runTime.caseName().substr(0, slashIndex));
00312
00313 Info<< "Writing merged surface to " << globalCasePath << endl;
00314
00315
00316 fileName globalPath
00317 (
00318 runTime.rootPath()
00319 / globalCasePath
00320 / args.additionalArgs()[0]
00321 );
00322
00323 allSurf.write(globalPath);
00324 }
00325 }
00326
00327 Info << "End\n" << endl;
00328
00329 return 0;
00330 }
00331
00332
00333
Copyright © 2000-2009 OpenCFD Ltd