1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 surfaceRedistributePar
28 (Re)distribution of triSurface. Either takes an undecomposed surface
29 or an already decomposed surface and redistribute it so each processor
30 has all triangles that overlap its mesh.
33 - best decomposition option is hierarchGeomDecomp since
34 guarantees square decompositions.
35 - triangles might be present on multiple processors.
36 - merging uses geometric tolerance so take care with writing precision.
38 \*---------------------------------------------------------------------------*/
40 #include "treeBoundBox.H"
41 #include "FixedList.H"
43 #include "objectRegistry.H"
46 #include "distributedTriSurfaceMesh.H"
47 #include "mapDistribute.H"
48 #include "triSurfaceFields.H"
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 // Print on master all the per-processor surface stats.
59 const List<List<treeBoundBox> >& meshBb
62 // Determine surface bounding boxes, faces, points
63 List<treeBoundBox> surfBb(Pstream::nProcs());
65 surfBb[Pstream::myProcNo()] = treeBoundBox(s.points());
66 Pstream::gatherList(surfBb);
67 Pstream::scatterList(surfBb);
70 labelList nPoints(Pstream::nProcs());
71 nPoints[Pstream::myProcNo()] = s.points().size();
72 Pstream::gatherList(nPoints);
73 Pstream::scatterList(nPoints);
75 labelList nFaces(Pstream::nProcs());
76 nFaces[Pstream::myProcNo()] = s.size();
77 Pstream::gatherList(nFaces);
78 Pstream::scatterList(nFaces);
82 const List<treeBoundBox>& bbs = meshBb[procI];
84 Info<< "processor" << procI << endl
85 << "\tMesh bounds : " << bbs[0] << nl;
86 for (label i = 1; i < bbs.size(); i++)
88 Info<< "\t " << bbs[i]<< nl;
90 Info<< "\tSurface bounding box : " << surfBb[procI] << nl
91 << "\tTriangles : " << nFaces[procI] << nl
92 << "\tVertices : " << nPoints[procI]
101 int main(int argc, char *argv[])
103 argList::validArgs.append("triSurfaceMesh");
104 argList::validArgs.append("distributionType");
106 argList::validOptions.insert("keepNonMapped", "");
107 # include "setRootCase.H"
108 # include "createTime.H"
109 runTime.functionObjects().off();
111 fileName surfFileName(args.additionalArgs()[0]);
112 Info<< "Reading surface from " << surfFileName << nl << endl;
114 const word distType(args.additionalArgs()[1]);
116 Info<< "Using distribution method "
117 << distributedTriSurfaceMesh::distributionTypeNames_[distType]
118 << " " << distType << nl << endl;
120 bool keepNonMapped = args.options().found("keepNonMapped");
124 Info<< "Preserving surface outside of mesh bounds." << nl << endl;
128 Info<< "Removing surface outside of mesh bounds." << nl << endl;
132 if (!Pstream::parRun())
134 FatalErrorIn(args.executable())
135 << "Please run this program on the decomposed case."
136 << " It will read surface " << surfFileName
137 << " and decompose it such that it overlaps the mesh bounding box."
142 # include "createPolyMesh.H"
144 Random rndGen(653213);
146 // Determine mesh bounding boxes:
147 List<List<treeBoundBox> > meshBb(Pstream::nProcs());
149 meshBb[Pstream::myProcNo()] = List<treeBoundBox>
154 boundBox(mesh.points(), false)
155 ).extend(rndGen, 1E-3)
157 Pstream::gatherList(meshBb);
158 Pstream::scatterList(meshBb);
163 surfFileName, // name
164 //runTime.findInstance("triSurface", surfFileName), // instance
165 runTime.constant(), // instance
166 "triSurface", // local
172 const fileName actualPath(io.filePath());
173 fileName localPath(actualPath);
174 localPath.replace(runTime.rootPath() + '/', "");
176 if (actualPath == io.objectPath())
178 Info<< "Loading local (decomposed) surface " << localPath << nl <<endl;
182 Info<< "Loading undecomposed surface " << localPath << nl << endl;
186 // Create dummy dictionary for bounding boxes if does not exist.
187 if (!isFile(actualPath / "Dict"))
190 dict.add("bounds", meshBb[Pstream::myProcNo()]);
191 dict.add("distributionType", distType);
192 dict.add("mergeDistance", SMALL);
209 Info<< "Writing dummy bounds dictionary to " << ioDict.name()
212 ioDict.regIOobject::writeObject
215 IOstream::currentVersion,
216 ioDict.time().writeCompression()
222 distributedTriSurfaceMesh surfMesh(io);
223 Info<< "Loaded surface" << nl << endl;
226 // Generate a test field
228 const triSurface& s = static_cast<const triSurface&>(surfMesh);
230 autoPtr<triSurfaceVectorField> fcPtr
232 new triSurfaceVectorField
236 surfMesh.searchableSurface::name(), // name
237 surfMesh.searchableSurface::instance(), // instance
238 surfMesh.searchableSurface::local(), // local
247 triSurfaceVectorField& fc = fcPtr();
251 fc[triI] = s[triI].centre(s.points());
254 // Steal pointer and store object on surfMesh
255 fcPtr.ptr()->store();
259 // Write per-processor stats
260 Info<< "Before redistribution:" << endl;
261 writeProcStats(surfMesh, meshBb);
265 Info<< "Redistributing surface" << nl << endl;
266 autoPtr<mapDistribute> faceMap;
267 autoPtr<mapDistribute> pointMap;
270 meshBb[Pstream::myProcNo()],
281 // Write per-processor stats
282 Info<< "After redistribution:" << endl;
283 writeProcStats(surfMesh, meshBb);
286 Info<< "Writing surface." << nl << endl;
287 surfMesh.searchableSurface::write();
289 Info<< "End\n" << endl;
295 // ************************************************************************* //