OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

checkTopology.C

Go to the documentation of this file.
00001 #include "checkTopology.H"
00002 #include "polyMesh.H"
00003 #include "Time.H"
00004 #include "regionSplit.H"
00005 #include "cellSet.H"
00006 #include "faceSet.H"
00007 #include "pointSet.H"
00008 #include "IOmanip.H"
00009 
00010 bool Foam::checkSync(const wordList& names)
00011 {
00012     List<wordList> allNames(Pstream::nProcs());
00013     allNames[Pstream::myProcNo()] = names;
00014     Pstream::gatherList(allNames);
00015 
00016     bool hasError = false;
00017 
00018     for (label procI = 1; procI < allNames.size(); procI++)
00019     {
00020         if (allNames[procI] != allNames[0])
00021         {
00022             hasError = true;
00023 
00024             Info<< " ***Inconsistent zones across processors, "
00025                    "processor 0 has zones:" << allNames[0]
00026                 << ", processor " << procI << " has zones:"
00027                 << allNames[procI]
00028                 << endl;
00029         }
00030     }
00031     return hasError;
00032 }
00033 
00034 
00035 Foam::label Foam::checkTopology
00036 (
00037     const polyMesh& mesh,
00038     const bool allTopology,
00039     const bool allGeometry
00040 )
00041 {
00042     label noFailedChecks = 0;
00043 
00044     Info<< "Checking topology..." << endl;
00045 
00046     // Check if the boundary definition is unique
00047     mesh.boundaryMesh().checkDefinition(true);
00048 
00049     // Check if the boundary processor patches are correct
00050     mesh.boundaryMesh().checkParallelSync(true);
00051 
00052     // Check names of zones are equal
00053     if (checkSync(mesh.cellZones().names()))
00054     {
00055         noFailedChecks++;
00056     }
00057     if (checkSync(mesh.faceZones().names()))
00058     {
00059         noFailedChecks++;
00060     }
00061     if (checkSync(mesh.pointZones().names()))
00062     {
00063         noFailedChecks++;
00064     }
00065 
00066     // Check contents of faceZones consistent
00067     {
00068         forAll(mesh.faceZones(), zoneI)
00069         {
00070             if (mesh.faceZones()[zoneI].checkParallelSync(false))
00071             {
00072                 Info<< " ***FaceZone " << mesh.faceZones()[zoneI].name()
00073                     << " is not correctly synchronised"
00074                     << " acrosss coupled boundaries."
00075                     << " (coupled faces both"
00076                     << " present in set but with opposite flipmap)" << endl;
00077                 noFailedChecks++;
00078             }
00079         }
00080     }
00081 
00082     {
00083         pointSet points(mesh, "unusedPoints", mesh.nPoints()/100);
00084         if (mesh.checkPoints(true, &points))
00085         {
00086             noFailedChecks++;
00087 
00088             label nPoints = returnReduce(points.size(), sumOp<label>());
00089 
00090             Info<< "  <<Writing " << nPoints
00091                 << " unused points to set " << points.name() << endl;
00092             points.write();
00093         }
00094     }
00095 
00096     {
00097         faceSet faces(mesh, "upperTriangularFace", mesh.nFaces()/100);
00098         if (mesh.checkUpperTriangular(true, &faces))
00099         {
00100             noFailedChecks++;
00101         }
00102 
00103         label nFaces = returnReduce(faces.size(), sumOp<label>());
00104 
00105         if (nFaces > 0)
00106         {
00107             Info<< "  <<Writing " << nFaces
00108                 << " unordered faces to set " << faces.name() << endl;
00109             faces.write();
00110         }
00111     }
00112 
00113     if (allTopology)
00114     {
00115         cellSet cells(mesh, "zipUpCells", mesh.nCells()/100);
00116         if (mesh.checkCellsZipUp(true, &cells))
00117         {
00118             noFailedChecks++;
00119 
00120             label nCells = returnReduce(cells.size(), sumOp<label>());
00121 
00122             Info<< "  <<Writing " << nCells
00123                 << " cells with over used edges to set " << cells.name()
00124                 << endl;
00125             cells.write();
00126         }
00127     }
00128 
00129     {
00130         faceSet faces(mesh, "outOfRangeFaces", mesh.nFaces()/100);
00131         if (mesh.checkFaceVertices(true, &faces))
00132         {
00133             noFailedChecks++;
00134 
00135             label nFaces = returnReduce(faces.size(), sumOp<label>());
00136 
00137             Info<< "  <<Writing " << nFaces
00138                 << " faces with out-of-range or duplicate vertices to set "
00139                 << faces.name() << endl;
00140             faces.write();
00141         }
00142     }
00143 
00144     if (allTopology)
00145     {
00146         faceSet faces(mesh, "edgeFaces", mesh.nFaces()/100);
00147         if (mesh.checkFaceFaces(true, &faces))
00148         {
00149             noFailedChecks++;
00150 
00151             label nFaces = returnReduce(faces.size(), sumOp<label>());
00152 
00153             Info<< "  <<Writing " << nFaces
00154                 << " faces with incorrect edges to set " << faces.name()
00155                 << endl;
00156             faces.write();
00157         }
00158     }
00159 
00160     if (allTopology)
00161     {
00162         labelList nInternalFaces(mesh.nCells(), 0);
00163 
00164         for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
00165         {
00166             nInternalFaces[mesh.faceOwner()[faceI]]++;
00167             nInternalFaces[mesh.faceNeighbour()[faceI]]++;
00168         }
00169         const polyBoundaryMesh& patches = mesh.boundaryMesh();
00170         forAll(patches, patchI)
00171         {
00172             if (patches[patchI].coupled())
00173             {
00174                 const unallocLabelList& owners = patches[patchI].faceCells();
00175 
00176                 forAll(owners, i)
00177                 {
00178                     nInternalFaces[owners[i]]++;
00179                 }
00180             }
00181         }
00182 
00183         faceSet oneCells(mesh, "oneInternalFaceCells", mesh.nCells()/100);
00184         faceSet twoCells(mesh, "twoInternalFacesCells", mesh.nCells()/100);
00185 
00186         forAll(nInternalFaces, cellI)
00187         {
00188             if (nInternalFaces[cellI] <= 1)
00189             {
00190                 oneCells.insert(cellI);
00191             }
00192             else if (nInternalFaces[cellI] == 2)
00193             {
00194                 twoCells.insert(cellI);
00195             }
00196         }
00197 
00198         label nOneCells = returnReduce(oneCells.size(), sumOp<label>());
00199 
00200         if (nOneCells > 0)
00201         {
00202             Info<< "  <<Writing " << nOneCells
00203                 << " cells with with single non-boundary face to set "
00204                 << oneCells.name()
00205                 << endl;
00206             oneCells.write();
00207         }
00208 
00209         label nTwoCells = returnReduce(twoCells.size(), sumOp<label>());
00210 
00211         if (nTwoCells > 0)
00212         {
00213             Info<< "  <<Writing " << nTwoCells
00214                 << " cells with with single non-boundary face to set "
00215                 << twoCells.name()
00216                 << endl;
00217             twoCells.write();
00218         }
00219     }
00220 
00221     {
00222         regionSplit rs(mesh);
00223 
00224         if (rs.nRegions() == 1)
00225         {
00226             Info<< "    Number of regions: " << rs.nRegions() << " (OK)."
00227                 << endl;
00228 
00229         }
00230         else
00231         {
00232             Info<< "   *Number of regions: " << rs.nRegions() << endl;
00233 
00234             Info<< "    The mesh has multiple regions which are not connected "
00235                    "by any face." << endl
00236                 << "  <<Writing region information to "
00237                 << mesh.time().timeName()/"cellToRegion"
00238                 << endl;
00239 
00240             labelIOList ctr
00241             (
00242                 IOobject
00243                 (
00244                     "cellToRegion",
00245                     mesh.time().timeName(),
00246                     mesh,
00247                     IOobject::NO_READ,
00248                     IOobject::NO_WRITE
00249                 ),
00250                 rs
00251             );
00252             ctr.write();
00253         }
00254     }
00255 
00256     if (!Pstream::parRun())
00257     {
00258         Pout<< "\nChecking patch topology for multiply connected surfaces ..."
00259             << endl;
00260 
00261         const polyBoundaryMesh& patches = mesh.boundaryMesh();
00262 
00263         // Non-manifold points
00264         pointSet points
00265         (
00266             mesh,
00267             "nonManifoldPoints",
00268             mesh.nPoints()/100
00269         );
00270 
00271         Pout.setf(ios_base::left);
00272 
00273         Pout<< "    "
00274             << setw(20) << "Patch"
00275             << setw(9) << "Faces"
00276             << setw(9) << "Points"
00277             << setw(34) << "Surface topology";
00278         if (allGeometry)
00279         {
00280             Pout<< " Bounding box";
00281         }
00282         Pout<< endl;
00283 
00284         forAll(patches, patchI)
00285         {
00286             const polyPatch& pp = patches[patchI];
00287 
00288                 Pout<< "    "
00289                     << setw(20) << pp.name()
00290                     << setw(9) << pp.size()
00291                     << setw(9) << pp.nPoints();
00292 
00293 
00294             primitivePatch::surfaceTopo pTyp = pp.surfaceType();
00295 
00296             if (pp.empty())
00297             {
00298                 Pout<< setw(34) << "ok (empty)";
00299             }
00300             else if (pTyp == primitivePatch::MANIFOLD)
00301             {
00302                 if (pp.checkPointManifold(true, &points))
00303                 {
00304                     Pout<< setw(34) << "multiply connected (shared point)";
00305                 }
00306                 else
00307                 {
00308                     Pout<< setw(34) << "ok (closed singly connected)";
00309                 }
00310 
00311                 // Add points on non-manifold edges to make set complete
00312                 pp.checkTopology(false, &points);
00313             }
00314             else
00315             {
00316                 pp.checkTopology(false, &points);
00317 
00318                 if (pTyp == primitivePatch::OPEN)
00319                 {
00320                     Pout<< setw(34) << "ok (non-closed singly connected)";
00321                 }
00322                 else
00323                 {
00324                     Pout<< setw(34) << "multiply connected (shared edge)";
00325                 }
00326             }
00327 
00328             if (allGeometry)
00329             {
00330                 const pointField& pts = pp.points();
00331                 const labelList& mp = pp.meshPoints();
00332 
00333                 boundBox bb;   // zero-sized
00334                 if (returnReduce(mp.size(), sumOp<label>()) > 0)
00335                 {
00336                     bb.min() = pts[mp[0]];
00337                     bb.max() = pts[mp[0]];
00338                     for (label i = 1; i < mp.size(); i++)
00339                     {
00340                         bb.min() = min(bb.min(), pts[mp[i]]);
00341                         bb.max() = max(bb.max(), pts[mp[i]]);
00342                     }
00343                     reduce(bb.min(), minOp<vector>());
00344                     reduce(bb.max(), maxOp<vector>());
00345                 }
00346                 Pout<< ' ' << bb;
00347             }
00348             Pout<< endl;
00349         }
00350 
00351         if (points.size())
00352         {
00353             Pout<< "  <<Writing " << points.size()
00354                 << " conflicting points to set "
00355                 << points.name() << endl;
00356 
00357             points.write();
00358         }
00359 
00360         //Pout.setf(ios_base::right);
00361     }
00362 
00363     // Force creation of all addressing if requested.
00364     // Errors will be reported as required
00365     if (allTopology)
00366     {
00367         mesh.cells();
00368         mesh.faces();
00369         mesh.edges();
00370         mesh.points();
00371         mesh.faceOwner();
00372         mesh.faceNeighbour();
00373         mesh.cellCells();
00374         mesh.edgeCells();
00375         mesh.pointCells();
00376         mesh.edgeFaces();
00377         mesh.pointFaces();
00378         mesh.cellEdges();
00379         mesh.faceEdges();
00380         mesh.pointEdges();
00381     }
00382 
00383     return noFailedChecks;
00384 }
Copyright © 2000-2009 OpenCFD Ltd