1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 surfaceRedistributePar
29 (Re)distribution of triSurface. Either takes an undecomposed surface
30 or an already decomposed surface and redistribute it so each processor
31 has all triangles that overlap its mesh.
34 - best decomposition option is hierarchGeomDecomp since
35 guarantees square decompositions.
36 - triangles might be present on multiple processors.
37 - merging uses geometric tolerance so take care with writing precision.
39 \*---------------------------------------------------------------------------*/
41 #include "treeBoundBox.H"
42 #include "FixedList.H"
44 #include "objectRegistry.H"
47 #include "distributedTriSurfaceMesh.H"
48 #include "mapDistribute.H"
49 #include "triSurfaceFields.H"
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 // Print on master all the per-processor surface stats.
60 const List<List<treeBoundBox> >& meshBb
63 // Determine surface bounding boxes, faces, points
64 List<treeBoundBox> surfBb(Pstream::nProcs());
66 surfBb[Pstream::myProcNo()] = treeBoundBox(s.points());
67 Pstream::gatherList(surfBb);
68 Pstream::scatterList(surfBb);
71 labelList nPoints(Pstream::nProcs());
72 nPoints[Pstream::myProcNo()] = s.points().size();
73 Pstream::gatherList(nPoints);
74 Pstream::scatterList(nPoints);
76 labelList nFaces(Pstream::nProcs());
77 nFaces[Pstream::myProcNo()] = s.size();
78 Pstream::gatherList(nFaces);
79 Pstream::scatterList(nFaces);
83 const List<treeBoundBox>& bbs = meshBb[procI];
85 Info<< "processor" << procI << endl
86 << "\tMesh bounds : " << bbs[0] << nl;
87 for (label i = 1; i < bbs.size(); i++)
89 Info<< "\t " << bbs[i]<< nl;
91 Info<< "\tSurface bounding box : " << surfBb[procI] << nl
92 << "\tTriangles : " << nFaces[procI] << nl
93 << "\tVertices : " << nPoints[procI]
102 int main(int argc, char *argv[])
104 argList::validArgs.append("triSurfaceMesh");
105 argList::validArgs.append("distributionType");
107 argList::validOptions.insert("keepNonMapped", "");
108 # include "setRootCase.H"
109 # include "createTime.H"
110 runTime.functionObjects().off();
112 fileName surfFileName(args.additionalArgs()[0]);
113 Info<< "Reading surface from " << surfFileName << nl << endl;
115 const word distType(args.additionalArgs()[1]);
117 Info<< "Using distribution method "
118 << distributedTriSurfaceMesh::distributionTypeNames_[distType]
119 << " " << distType << nl << endl;
121 bool keepNonMapped = args.options().found("keepNonMapped");
125 Info<< "Preserving surface outside of mesh bounds." << nl << endl;
129 Info<< "Removing surface outside of mesh bounds." << nl << endl;
133 if (!Pstream::parRun())
135 FatalErrorIn(args.executable())
136 << "Please run this program on the decomposed case."
137 << " It will read surface " << surfFileName
138 << " and decompose it such that it overlaps the mesh bounding box."
143 # include "createPolyMesh.H"
145 Random rndGen(653213);
147 // Determine mesh bounding boxes:
148 List<List<treeBoundBox> > meshBb(Pstream::nProcs());
150 meshBb[Pstream::myProcNo()] = List<treeBoundBox>
155 boundBox(mesh.points(), false)
156 ).extend(rndGen, 1E-3)
158 Pstream::gatherList(meshBb);
159 Pstream::scatterList(meshBb);
164 surfFileName, // name
165 //runTime.findInstance("triSurface", surfFileName), // instance
166 runTime.constant(), // instance
167 "triSurface", // local
173 const fileName actualPath(io.filePath());
174 fileName localPath(actualPath);
175 localPath.replace(runTime.rootPath() + '/', "");
177 if (actualPath == io.objectPath())
179 Info<< "Loading local (decomposed) surface " << localPath << nl <<endl;
183 Info<< "Loading undecomposed surface " << localPath << nl << endl;
187 // Create dummy dictionary for bounding boxes if does not exist.
188 if (!isFile(actualPath / "Dict"))
191 dict.add("bounds", meshBb[Pstream::myProcNo()]);
192 dict.add("distributionType", distType);
193 dict.add("mergeDistance", SMALL);
210 Info<< "Writing dummy bounds dictionary to " << ioDict.name()
213 ioDict.regIOobject::writeObject
216 IOstream::currentVersion,
217 ioDict.time().writeCompression()
223 distributedTriSurfaceMesh surfMesh(io);
224 Info<< "Loaded surface" << nl << endl;
227 // Generate a test field
229 const triSurface& s = static_cast<const triSurface&>(surfMesh);
231 autoPtr<triSurfaceVectorField> fcPtr
233 new triSurfaceVectorField
237 surfMesh.searchableSurface::name(), // name
238 surfMesh.searchableSurface::instance(), // instance
239 surfMesh.searchableSurface::local(), // local
248 triSurfaceVectorField& fc = fcPtr();
252 fc[triI] = s[triI].centre(s.points());
255 // Steal pointer and store object on surfMesh
256 fcPtr.ptr()->store();
260 // Write per-processor stats
261 Info<< "Before redistribution:" << endl;
262 writeProcStats(surfMesh, meshBb);
266 Info<< "Redistributing surface" << nl << endl;
267 autoPtr<mapDistribute> faceMap;
268 autoPtr<mapDistribute> pointMap;
271 meshBb[Pstream::myProcNo()],
282 // Write per-processor stats
283 Info<< "After redistribution:" << endl;
284 writeProcStats(surfMesh, meshBb);
287 Info<< "Writing surface." << nl << endl;
288 surfMesh.searchableSurface::write();
290 Info<< "End\n" << endl;
296 // ************************************************************************* //