1 #include "checkTopology.H"
4 #include "regionSplit.H"
10 bool Foam::checkSync(const wordList& names)
12 List<wordList> allNames(Pstream::nProcs());
13 allNames[Pstream::myProcNo()] = names;
14 Pstream::gatherList(allNames);
15 Pstream::scatterList(allNames);
17 bool hasError = false;
19 for (label procI = 1; procI < allNames.size(); procI++)
21 if (allNames[procI] != allNames[0])
25 Info<< " ***Inconsistent zones across processors, "
26 "processor 0 has zones:" << allNames[0]
27 << ", processor " << procI << " has zones:"
36 Foam::label Foam::checkTopology
39 const bool allTopology,
40 const bool allGeometry
43 label noFailedChecks = 0;
45 Info<< "Checking topology..." << endl;
47 // Check if the boundary definition is unique
48 mesh.boundaryMesh().checkDefinition(true);
50 // Check if the boundary processor patches are correct
51 mesh.boundaryMesh().checkParallelSync(true);
53 // Check names of zones are equal
54 if (checkSync(mesh.cellZones().names()))
58 if (checkSync(mesh.faceZones().names()))
62 if (checkSync(mesh.pointZones().names()))
67 // Check contents of faceZones consistent
69 forAll(mesh.faceZones(), zoneI)
71 if (mesh.faceZones()[zoneI].checkParallelSync(false))
73 Info<< " ***FaceZone " << mesh.faceZones()[zoneI].name()
74 << " is not correctly synchronised"
75 << " across coupled boundaries."
76 << " (coupled faces are either not both "
77 << " present in set or have same flipmap)" << endl;
84 pointSet points(mesh, "unusedPoints", mesh.nPoints()/100);
85 if (mesh.checkPoints(true, &points))
89 label nPoints = returnReduce(points.size(), sumOp<label>());
91 Info<< " <<Writing " << nPoints
92 << " unused points to set " << points.name() << endl;
98 faceSet faces(mesh, "upperTriangularFace", mesh.nFaces()/100);
99 if (mesh.checkUpperTriangular(true, &faces))
104 label nFaces = returnReduce(faces.size(), sumOp<label>());
108 Info<< " <<Writing " << nFaces
109 << " unordered faces to set " << faces.name() << endl;
116 cellSet cells(mesh, "zipUpCells", mesh.nCells()/100);
117 if (mesh.checkCellsZipUp(true, &cells))
121 label nCells = returnReduce(cells.size(), sumOp<label>());
123 Info<< " <<Writing " << nCells
124 << " cells with over used edges to set " << cells.name()
131 faceSet faces(mesh, "outOfRangeFaces", mesh.nFaces()/100);
132 if (mesh.checkFaceVertices(true, &faces))
136 label nFaces = returnReduce(faces.size(), sumOp<label>());
138 Info<< " <<Writing " << nFaces
139 << " faces with out-of-range or duplicate vertices to set "
140 << faces.name() << endl;
147 faceSet faces(mesh, "edgeFaces", mesh.nFaces()/100);
148 if (mesh.checkFaceFaces(true, &faces))
152 label nFaces = returnReduce(faces.size(), sumOp<label>());
154 Info<< " <<Writing " << nFaces
155 << " faces with incorrect edges to set " << faces.name()
163 labelList nInternalFaces(mesh.nCells(), 0);
165 for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
167 nInternalFaces[mesh.faceOwner()[faceI]]++;
168 nInternalFaces[mesh.faceNeighbour()[faceI]]++;
170 const polyBoundaryMesh& patches = mesh.boundaryMesh();
171 forAll(patches, patchI)
173 if (patches[patchI].coupled())
175 const unallocLabelList& owners = patches[patchI].faceCells();
179 nInternalFaces[owners[i]]++;
184 faceSet oneCells(mesh, "oneInternalFaceCells", mesh.nCells()/100);
185 faceSet twoCells(mesh, "twoInternalFacesCells", mesh.nCells()/100);
187 forAll(nInternalFaces, cellI)
189 if (nInternalFaces[cellI] <= 1)
191 oneCells.insert(cellI);
193 else if (nInternalFaces[cellI] == 2)
195 twoCells.insert(cellI);
199 label nOneCells = returnReduce(oneCells.size(), sumOp<label>());
203 Info<< " <<Writing " << nOneCells
204 << " cells with with single non-boundary face to set "
210 label nTwoCells = returnReduce(twoCells.size(), sumOp<label>());
214 Info<< " <<Writing " << nTwoCells
215 << " cells with with single non-boundary face to set "
223 regionSplit rs(mesh);
225 if (rs.nRegions() == 1)
227 Info<< " Number of regions: " << rs.nRegions() << " (OK)."
233 Info<< " *Number of regions: " << rs.nRegions() << endl;
235 Info<< " The mesh has multiple regions which are not connected "
236 "by any face." << endl
237 << " <<Writing region information to "
238 << mesh.time().timeName()/"cellToRegion"
246 mesh.time().timeName(),
257 if (!Pstream::parRun())
259 Pout<< "\nChecking patch topology for multiply connected surfaces ..."
262 const polyBoundaryMesh& patches = mesh.boundaryMesh();
264 // Non-manifold points
272 Pout.setf(ios_base::left);
275 << setw(20) << "Patch"
276 << setw(9) << "Faces"
277 << setw(9) << "Points"
278 << setw(34) << "Surface topology";
281 Pout<< " Bounding box";
285 forAll(patches, patchI)
287 const polyPatch& pp = patches[patchI];
290 << setw(20) << pp.name()
291 << setw(9) << pp.size()
292 << setw(9) << pp.nPoints();
295 primitivePatch::surfaceTopo pTyp = pp.surfaceType();
299 Pout<< setw(34) << "ok (empty)";
301 else if (pTyp == primitivePatch::MANIFOLD)
303 if (pp.checkPointManifold(true, &points))
305 Pout<< setw(34) << "multiply connected (shared point)";
309 Pout<< setw(34) << "ok (closed singly connected)";
312 // Add points on non-manifold edges to make set complete
313 pp.checkTopology(false, &points);
317 pp.checkTopology(false, &points);
319 if (pTyp == primitivePatch::OPEN)
321 Pout<< setw(34) << "ok (non-closed singly connected)";
325 Pout<< setw(34) << "multiply connected (shared edge)";
331 const pointField& pts = pp.points();
332 const labelList& mp = pp.meshPoints();
334 boundBox bb; // zero-sized
335 if (returnReduce(mp.size(), sumOp<label>()) > 0)
337 bb.min() = pts[mp[0]];
338 bb.max() = pts[mp[0]];
339 for (label i = 1; i < mp.size(); i++)
341 bb.min() = min(bb.min(), pts[mp[i]]);
342 bb.max() = max(bb.max(), pts[mp[i]]);
344 reduce(bb.min(), minOp<vector>());
345 reduce(bb.max(), maxOp<vector>());
354 Pout<< " <<Writing " << points.size()
355 << " conflicting points to set "
356 << points.name() << endl;
361 //Pout.setf(ios_base::right);
364 // Force creation of all addressing if requested.
365 // Errors will be reported as required
373 mesh.faceNeighbour();
384 return noFailedChecks;