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 #include "primitiveMesh.H"
00028 #include "pyramidPointFaceRef.H"
00029 #include "ListOps.H"
00030 #include "mathematicalConstants.H"
00031 #include "SortableList.H"
00032
00033
00034
00035
00036 Foam::scalar Foam::primitiveMesh::closedThreshold_ = 1.0e-6;
00037 Foam::scalar Foam::primitiveMesh::aspectThreshold_ = 1000;
00038 Foam::scalar Foam::primitiveMesh::nonOrthThreshold_ = 70;
00039 Foam::scalar Foam::primitiveMesh::skewThreshold_ = 4;
00040
00041
00042
00043
00044 bool Foam::primitiveMesh::checkClosedBoundary(const bool report) const
00045 {
00046 if (debug)
00047 {
00048 Info<< "bool primitiveMesh::checkClosedBoundary("
00049 << "const bool) const: "
00050 << "checking whether the boundary is closed" << endl;
00051 }
00052
00053
00054
00055
00056 vector sumClosed(vector::zero);
00057 scalar sumMagClosedBoundary = 0;
00058
00059 const vectorField& areas = faceAreas();
00060
00061 for (label faceI = nInternalFaces(); faceI < areas.size(); faceI++)
00062 {
00063 sumClosed += areas[faceI];
00064 sumMagClosedBoundary += mag(areas[faceI]);
00065 }
00066
00067 reduce(sumClosed, sumOp<vector>());
00068 reduce(sumMagClosedBoundary, sumOp<scalar>());
00069
00070 vector openness = sumClosed/(sumMagClosedBoundary + VSMALL);
00071
00072 if (cmptMax(cmptMag(openness)) > closedThreshold_)
00073 {
00074 if (debug || report)
00075 {
00076 Info<< " ***Boundary openness " << openness
00077 << " possible hole in boundary description."
00078 << endl;
00079 }
00080
00081 return true;
00082 }
00083 else
00084 {
00085 if (debug || report)
00086 {
00087 Info<< " Boundary openness " << openness << " OK."
00088 << endl;
00089 }
00090
00091 return false;
00092 }
00093 }
00094
00095
00096 bool Foam::primitiveMesh::checkClosedCells
00097 (
00098 const bool report,
00099 labelHashSet* setPtr,
00100 labelHashSet* aspectSetPtr
00101 ) const
00102 {
00103 if (debug)
00104 {
00105 Info<< "bool primitiveMesh::checkClosedCells("
00106 << "const bool, labelHashSet*, labelHashSet*) const: "
00107 << "checking whether cells are closed" << endl;
00108 }
00109
00110
00111 const cellList& c = cells();
00112
00113 label nErrorClosed = 0;
00114
00115 forAll (c, cI)
00116 {
00117 const cell& curCell = c[cI];
00118
00119 if (min(curCell) < 0 || max(curCell) > nFaces())
00120 {
00121 if (setPtr)
00122 {
00123 setPtr->insert(cI);
00124 }
00125
00126 nErrorClosed++;
00127 }
00128 }
00129
00130 if (nErrorClosed > 0)
00131 {
00132 if (debug || report)
00133 {
00134 Info<< " ***Cells with invalid face labels found, number of cells "
00135 << nErrorClosed << endl;
00136 }
00137
00138 return true;
00139 }
00140
00141
00142
00143
00144 vectorField sumClosed(nCells(), vector::zero);
00145 vectorField sumMagClosed(nCells(), vector::zero);
00146
00147 const labelList& own = faceOwner();
00148 const labelList& nei = faceNeighbour();
00149 const vectorField& areas = faceAreas();
00150
00151 forAll (own, faceI)
00152 {
00153
00154 sumClosed[own[faceI]] += areas[faceI];
00155 sumMagClosed[own[faceI]] += cmptMag(areas[faceI]);
00156 }
00157
00158 forAll (nei, faceI)
00159 {
00160
00161 sumClosed[nei[faceI]] -= areas[faceI];
00162 sumMagClosed[nei[faceI]] += cmptMag(areas[faceI]);
00163 }
00164
00165 label nOpen = 0;
00166 scalar maxOpennessCell = 0;
00167
00168 label nAspect = 0;
00169 scalar maxAspectRatio = 0;
00170
00171 const scalarField& vols = cellVolumes();
00172
00173
00174 forAll (sumClosed, cellI)
00175 {
00176 scalar maxOpenness = 0;
00177
00178 for(direction cmpt=0; cmpt<vector::nComponents; cmpt++)
00179 {
00180 maxOpenness = max
00181 (
00182 maxOpenness,
00183 mag(sumClosed[cellI][cmpt])
00184 /(sumMagClosed[cellI][cmpt] + VSMALL)
00185 );
00186 }
00187
00188 maxOpennessCell = max(maxOpennessCell, maxOpenness);
00189
00190 if (maxOpenness > closedThreshold_)
00191 {
00192 if (setPtr)
00193 {
00194 setPtr->insert(cellI);
00195 }
00196
00197 nOpen++;
00198 }
00199
00200
00201
00202 scalar aspectRatio = max
00203 (
00204 cmptMax(sumMagClosed[cellI])
00205 /(cmptMin(sumMagClosed[cellI]) + VSMALL),
00206 1.0/6.0*cmptSum(sumMagClosed[cellI])/pow(vols[cellI], 2.0/3.0)
00207 );
00208
00209 maxAspectRatio = max(maxAspectRatio, aspectRatio);
00210
00211 if (aspectRatio > aspectThreshold_)
00212 {
00213 if (aspectSetPtr)
00214 {
00215 aspectSetPtr->insert(cellI);
00216 }
00217
00218 nAspect++;
00219 }
00220 }
00221
00222 reduce(nOpen, sumOp<label>());
00223 reduce(maxOpennessCell, maxOp<scalar>());
00224
00225 reduce(nAspect, sumOp<label>());
00226 reduce(maxAspectRatio, maxOp<scalar>());
00227
00228
00229 if (nOpen > 0)
00230 {
00231 if (debug || report)
00232 {
00233 Info<< " ***Open cells found, max cell openness: "
00234 << maxOpennessCell << ", number of open cells " << nOpen
00235 << endl;
00236 }
00237
00238 return true;
00239 }
00240
00241 if (nAspect > 0)
00242 {
00243 if (debug || report)
00244 {
00245 Info<< " ***High aspect ratio cells found, Max aspect ratio: "
00246 << maxAspectRatio
00247 << ", number of cells " << nAspect
00248 << endl;
00249 }
00250
00251 return true;
00252 }
00253
00254 if (debug || report)
00255 {
00256 Info<< " Max cell openness = " << maxOpennessCell << " OK." << nl
00257 << " Max aspect ratio = " << maxAspectRatio << " OK."
00258 << endl;
00259 }
00260
00261 return false;
00262 }
00263
00264
00265 bool Foam::primitiveMesh::checkFaceAreas
00266 (
00267 const bool report,
00268 labelHashSet* setPtr
00269 ) const
00270 {
00271 if (debug)
00272 {
00273 Info<< "bool primitiveMesh::checkFaceAreas("
00274 << "const bool, labelHashSet*) const: "
00275 << "checking face area magnitudes" << endl;
00276 }
00277
00278 const scalarField magFaceAreas = mag(faceAreas());
00279
00280 scalar minArea = GREAT;
00281 scalar maxArea = -GREAT;
00282
00283 forAll (magFaceAreas, faceI)
00284 {
00285 if (magFaceAreas[faceI] < VSMALL)
00286 {
00287 if (setPtr)
00288 {
00289 setPtr->insert(faceI);
00290 }
00291 }
00292
00293 minArea = min(minArea, magFaceAreas[faceI]);
00294 maxArea = max(maxArea, magFaceAreas[faceI]);
00295 }
00296
00297 reduce(minArea, minOp<scalar>());
00298 reduce(maxArea, maxOp<scalar>());
00299
00300 if (minArea < VSMALL)
00301 {
00302 if (debug || report)
00303 {
00304 Info<< " ***Zero or negative face area detected. "
00305 "Minimum area: " << minArea << endl;
00306 }
00307
00308 return true;
00309 }
00310 else
00311 {
00312 if (debug || report)
00313 {
00314 Info<< " Minumum face area = " << minArea
00315 << ". Maximum face area = " << maxArea
00316 << ". Face area magnitudes OK." << endl;
00317 }
00318
00319 return false;
00320 }
00321 }
00322
00323
00324 bool Foam::primitiveMesh::checkCellVolumes
00325 (
00326 const bool report,
00327 labelHashSet* setPtr
00328 ) const
00329 {
00330 if (debug)
00331 {
00332 Info<< "bool primitiveMesh::checkCellVolumes("
00333 << "const bool, labelHashSet*) const: "
00334 << "checking cell volumes" << endl;
00335 }
00336
00337 const scalarField& vols = cellVolumes();
00338
00339 scalar minVolume = GREAT;
00340 scalar maxVolume = -GREAT;
00341
00342 label nNegVolCells = 0;
00343
00344 forAll (vols, cellI)
00345 {
00346 if (vols[cellI] < VSMALL)
00347 {
00348 if (setPtr)
00349 {
00350 setPtr->insert(cellI);
00351 }
00352
00353 nNegVolCells++;
00354 }
00355
00356 minVolume = min(minVolume, vols[cellI]);
00357 maxVolume = max(maxVolume, vols[cellI]);
00358 }
00359
00360 reduce(minVolume, minOp<scalar>());
00361 reduce(maxVolume, maxOp<scalar>());
00362 reduce(nNegVolCells, sumOp<label>());
00363
00364 if (minVolume < VSMALL)
00365 {
00366 if (debug || report)
00367 {
00368 Info<< " ***Zero or negative cell volume detected. "
00369 << "Minimum negative volume: " << minVolume
00370 << ", Number of negative volume cells: " << nNegVolCells
00371 << endl;
00372 }
00373
00374 return true;
00375 }
00376 else
00377 {
00378 if (debug || report)
00379 {
00380 Info<< " Min volume = " << minVolume
00381 << ". Max volume = " << maxVolume
00382 << ". Total volume = " << gSum(vols)
00383 << ". Cell volumes OK." << endl;
00384 }
00385
00386 return false;
00387 }
00388 }
00389
00390
00391 bool Foam::primitiveMesh::checkFaceOrthogonality
00392 (
00393 const bool report,
00394 labelHashSet* setPtr
00395 ) const
00396 {
00397 if (debug)
00398 {
00399 Info<< "bool primitiveMesh::checkFaceOrthogonality("
00400 << "const bool, labelHashSet*) const: "
00401 << "checking mesh non-orthogonality" << endl;
00402 }
00403
00404
00405 const vectorField& centres = cellCentres();
00406 const vectorField& areas = faceAreas();
00407
00408 const labelList& own = faceOwner();
00409 const labelList& nei = faceNeighbour();
00410
00411
00412 const scalar severeNonorthogonalityThreshold =
00413 ::cos(nonOrthThreshold_/180.0*mathematicalConstant::pi);
00414
00415 scalar minDDotS = GREAT;
00416
00417 scalar sumDDotS = 0;
00418
00419 label severeNonOrth = 0;
00420
00421 label errorNonOrth = 0;
00422
00423 forAll (nei, faceI)
00424 {
00425 vector d = centres[nei[faceI]] - centres[own[faceI]];
00426 const vector& s = areas[faceI];
00427
00428 scalar dDotS = (d & s)/(mag(d)*mag(s) + VSMALL);
00429
00430 if (dDotS < severeNonorthogonalityThreshold)
00431 {
00432 if (dDotS > SMALL)
00433 {
00434 if (setPtr)
00435 {
00436 setPtr->insert(faceI);
00437 }
00438
00439 severeNonOrth++;
00440 }
00441 else
00442 {
00443 if (setPtr)
00444 {
00445 setPtr->insert(faceI);
00446 }
00447
00448 errorNonOrth++;
00449 }
00450 }
00451
00452 if (dDotS < minDDotS)
00453 {
00454 minDDotS = dDotS;
00455 }
00456
00457 sumDDotS += dDotS;
00458 }
00459
00460 reduce(minDDotS, minOp<scalar>());
00461 reduce(sumDDotS, sumOp<scalar>());
00462 reduce(severeNonOrth, sumOp<label>());
00463 reduce(errorNonOrth, sumOp<label>());
00464
00465 if (debug || report)
00466 {
00467 label neiSize = nei.size();
00468 reduce(neiSize, sumOp<label>());
00469
00470 if (neiSize > 0)
00471 {
00472 if (debug || report)
00473 {
00474 Info<< " Mesh non-orthogonality Max: "
00475 << ::acos(minDDotS)/mathematicalConstant::pi*180.0
00476 << " average: " <<
00477 ::acos(sumDDotS/neiSize)/mathematicalConstant::pi*180.0
00478 << endl;
00479 }
00480 }
00481
00482 if (severeNonOrth > 0)
00483 {
00484 Info<< " *Number of severely non-orthogonal faces: "
00485 << severeNonOrth << "." << endl;
00486 }
00487 }
00488
00489 if (errorNonOrth > 0)
00490 {
00491 if (debug || report)
00492 {
00493 Info<< " ***Number of non-orthogonality errors: "
00494 << errorNonOrth << "." << endl;
00495 }
00496
00497 return true;
00498 }
00499 else
00500 {
00501 if (debug || report)
00502 {
00503 Info<< " Non-orthogonality check OK." << endl;
00504 }
00505
00506 return false;
00507 }
00508 }
00509
00510
00511 bool Foam::primitiveMesh::checkFacePyramids
00512 (
00513 const bool report,
00514 const scalar minPyrVol,
00515 labelHashSet* setPtr
00516 ) const
00517 {
00518 if (debug)
00519 {
00520 Info<< "bool primitiveMesh::checkFacePyramids("
00521 << "const bool, const scalar, labelHashSet*) const: "
00522 << "checking face orientation" << endl;
00523 }
00524
00525
00526 const vectorField& ctrs = cellCentres();
00527
00528 const labelList& own = faceOwner();
00529 const labelList& nei = faceNeighbour();
00530
00531 const faceList& f = faces();
00532
00533 const pointField& p = points();
00534
00535 label nErrorPyrs = 0;
00536
00537 forAll (f, faceI)
00538 {
00539
00540 scalar pyrVol = pyramidPointFaceRef(f[faceI], ctrs[own[faceI]]).mag(p);
00541
00542 if (pyrVol > -minPyrVol)
00543 {
00544 if (setPtr)
00545 {
00546 setPtr->insert(faceI);
00547 }
00548
00549 nErrorPyrs++;
00550 }
00551
00552 if (isInternalFace(faceI))
00553 {
00554
00555 scalar pyrVol =
00556 pyramidPointFaceRef(f[faceI], ctrs[nei[faceI]]).mag(p);
00557
00558 if (pyrVol < minPyrVol)
00559 {
00560 if (setPtr)
00561 {
00562 setPtr->insert(faceI);
00563 }
00564
00565 nErrorPyrs++;
00566 }
00567 }
00568 }
00569
00570 reduce(nErrorPyrs, sumOp<label>());
00571
00572 if (nErrorPyrs > 0)
00573 {
00574 if (debug || report)
00575 {
00576 Info<< " ***Error in face pyramids: "
00577 << nErrorPyrs << " faces are incorrectly oriented."
00578 << endl;
00579 }
00580
00581 return true;
00582 }
00583 else
00584 {
00585 if (debug || report)
00586 {
00587 Info<< " Face pyramids OK." << endl;
00588 }
00589
00590 return false;
00591 }
00592 }
00593
00594
00595 bool Foam::primitiveMesh::checkFaceSkewness
00596 (
00597 const bool report,
00598 labelHashSet* setPtr
00599 ) const
00600 {
00601 if (debug)
00602 {
00603 Info<< "bool primitiveMesh::checkFaceSkewnesss("
00604 << "const bool, labelHashSet*) const: "
00605 << "checking face skewness" << endl;
00606 }
00607
00608
00609
00610
00611 const pointField& p = points();
00612 const faceList& fcs = faces();
00613
00614 const labelList& own = faceOwner();
00615 const labelList& nei = faceNeighbour();
00616 const vectorField& cellCtrs = cellCentres();
00617 const vectorField& faceCtrs = faceCentres();
00618 const vectorField& fAreas = faceAreas();
00619
00620 scalar maxSkew = 0;
00621 label nWarnSkew = 0;
00622
00623 forAll(nei, faceI)
00624 {
00625 vector Cpf = faceCtrs[faceI] - cellCtrs[own[faceI]];
00626 vector d = cellCtrs[nei[faceI]] - cellCtrs[own[faceI]];
00627
00628
00629 vector sv = Cpf - ((fAreas[faceI] & Cpf)/(fAreas[faceI] & d))*d;
00630 vector svHat = sv/(mag(sv) + VSMALL);
00631
00632
00633
00634
00635 scalar fd = 0.2*mag(d) + VSMALL;
00636 const face& f = fcs[faceI];
00637 forAll(f, pi)
00638 {
00639 fd = max(fd, mag(svHat & (p[f[pi]] - faceCtrs[faceI])));
00640 }
00641
00642
00643 scalar skewness = mag(sv)/fd;
00644
00645
00646
00647 if (skewness > skewThreshold_)
00648 {
00649 if (setPtr)
00650 {
00651 setPtr->insert(faceI);
00652 }
00653
00654 nWarnSkew++;
00655 }
00656
00657 if(skewness > maxSkew)
00658 {
00659 maxSkew = skewness;
00660 }
00661 }
00662
00663
00664
00665
00666
00667 for (label faceI = nInternalFaces(); faceI < nFaces(); faceI++)
00668 {
00669 vector Cpf = faceCtrs[faceI] - cellCtrs[own[faceI]];
00670
00671 vector normal = fAreas[faceI];
00672 normal /= mag(normal) + VSMALL;
00673 vector d = normal*(normal & Cpf);
00674
00675
00676
00677 vector sv = Cpf - ((fAreas[faceI]&Cpf)/((fAreas[faceI]&d)+VSMALL))*d;
00678 vector svHat = sv/(mag(sv) + VSMALL);
00679
00680
00681
00682
00683 scalar fd = 0.4*mag(d) + VSMALL;
00684 const face& f = fcs[faceI];
00685 forAll(f, pi)
00686 {
00687 fd = max(fd, mag(svHat & (p[f[pi]] - faceCtrs[faceI])));
00688 }
00689
00690
00691 scalar skewness = mag(sv)/fd;
00692
00693
00694
00695 if (skewness > skewThreshold_)
00696 {
00697 if (setPtr)
00698 {
00699 setPtr->insert(faceI);
00700 }
00701
00702 nWarnSkew++;
00703 }
00704
00705 if(skewness > maxSkew)
00706 {
00707 maxSkew = skewness;
00708 }
00709 }
00710
00711
00712 reduce(maxSkew, maxOp<scalar>());
00713 reduce(nWarnSkew, sumOp<label>());
00714
00715 if (nWarnSkew > 0)
00716 {
00717 if (debug || report)
00718 {
00719 Info<< " ***Max skewness = " << maxSkew
00720 << ", " << nWarnSkew << " highly skew faces detected"
00721 " which may impair the quality of the results"
00722 << endl;
00723 }
00724
00725 return true;
00726 }
00727 else
00728 {
00729 if (debug || report)
00730 {
00731 Info<< " Max skewness = " << maxSkew << " OK." << endl;
00732 }
00733
00734 return false;
00735 }
00736 }
00737
00738
00739 bool Foam::primitiveMesh::checkPoints
00740 (
00741 const bool report,
00742 labelHashSet* setPtr
00743 ) const
00744 {
00745 if (debug)
00746 {
00747 Info<< "bool primitiveMesh::checkPoints"
00748 << "(const bool, labelHashSet*) const: "
00749 << "checking points" << endl;
00750 }
00751
00752 label nFaceErrors = 0;
00753 label nCellErrors = 0;
00754
00755 const labelListList& pf = pointFaces();
00756
00757 forAll (pf, pointI)
00758 {
00759 if (pf[pointI].empty())
00760 {
00761 if (setPtr)
00762 {
00763 setPtr->insert(pointI);
00764 }
00765
00766 nFaceErrors++;
00767 }
00768 }
00769
00770
00771 forAll (pf, pointI)
00772 {
00773 const labelList& pc = pointCells(pointI);
00774
00775 if (pc.empty())
00776 {
00777 if (setPtr)
00778 {
00779 setPtr->insert(pointI);
00780 }
00781
00782 nCellErrors++;
00783 }
00784 }
00785
00786 reduce(nFaceErrors, sumOp<label>());
00787 reduce(nCellErrors, sumOp<label>());
00788
00789 if (nFaceErrors > 0 || nCellErrors > 0)
00790 {
00791 if (debug || report)
00792 {
00793 Info<< " ***Unused points found in the mesh, "
00794 "number unused by faces: " << nFaceErrors
00795 << " number unused by cells: " << nCellErrors
00796 << endl;
00797 }
00798
00799 return true;
00800 }
00801 else
00802 {
00803 if (debug || report)
00804 {
00805 Info<< " Point usage OK." << endl;
00806 }
00807
00808 return false;
00809 }
00810 }
00811
00812
00813
00814
00815
00816
00817 bool Foam::primitiveMesh::checkFaceAngles
00818 (
00819 const bool report,
00820 const scalar maxDeg,
00821 labelHashSet* setPtr
00822 ) const
00823 {
00824 if (debug)
00825 {
00826 Info<< "bool primitiveMesh::checkFaceAngles"
00827 << "(const bool, const scalar, labelHashSet*) const: "
00828 << "checking face angles" << endl;
00829 }
00830
00831 if (maxDeg < -SMALL || maxDeg > 180+SMALL)
00832 {
00833 FatalErrorIn
00834 (
00835 "primitiveMesh::checkFaceAngles"
00836 "(const bool, const scalar, labelHashSet*)"
00837 ) << "maxDeg should be [0..180] but is now " << maxDeg
00838 << exit(FatalError);
00839 }
00840
00841 const scalar maxSin = Foam::sin(maxDeg/180.0*mathematicalConstant::pi);
00842
00843 const pointField& p = points();
00844 const faceList& fcs = faces();
00845 vectorField faceNormals(faceAreas());
00846 faceNormals /= mag(faceNormals) + VSMALL;
00847
00848 scalar maxEdgeSin = 0.0;
00849
00850 label nConcave = 0;
00851
00852 label errorFaceI = -1;
00853
00854 forAll(fcs, faceI)
00855 {
00856 const face& f = fcs[faceI];
00857
00858
00859 vector ePrev(p[f[0]] - p[f[f.size()-1]]);
00860 scalar magEPrev = mag(ePrev);
00861 ePrev /= magEPrev + VSMALL;
00862
00863 forAll(f, fp0)
00864 {
00865
00866 label fp1 = f.fcIndex(fp0);
00867
00868
00869 vector e10(p[f[fp1]] - p[f[fp0]]);
00870 scalar magE10 = mag(e10);
00871 e10 /= magE10 + VSMALL;
00872
00873 if (magEPrev > SMALL && magE10 > SMALL)
00874 {
00875 vector edgeNormal = ePrev ^ e10;
00876 scalar magEdgeNormal = mag(edgeNormal);
00877
00878 if (magEdgeNormal < maxSin)
00879 {
00880
00881 }
00882 else
00883 {
00884
00885 edgeNormal /= magEdgeNormal;
00886
00887 if ((edgeNormal & faceNormals[faceI]) < SMALL)
00888 {
00889 if (faceI != errorFaceI)
00890 {
00891
00892 errorFaceI = faceI;
00893 nConcave++;
00894 }
00895
00896 if (setPtr)
00897 {
00898 setPtr->insert(faceI);
00899 }
00900
00901 maxEdgeSin = max(maxEdgeSin, magEdgeNormal);
00902 }
00903 }
00904 }
00905
00906 ePrev = e10;
00907 magEPrev = magE10;
00908 }
00909 }
00910
00911 reduce(nConcave, sumOp<label>());
00912 reduce(maxEdgeSin, maxOp<scalar>());
00913
00914 if (nConcave > 0)
00915 {
00916 scalar maxConcaveDegr =
00917 Foam::asin(Foam::min(1.0, maxEdgeSin))
00918 *180.0/mathematicalConstant::pi;
00919
00920 if (debug || report)
00921 {
00922 Info<< " *There are " << nConcave
00923 << " faces with concave angles between consecutive"
00924 << " edges. Max concave angle = " << maxConcaveDegr
00925 << " degrees." << endl;
00926 }
00927
00928 return true;
00929 }
00930 else
00931 {
00932 if (debug || report)
00933 {
00934 Info<< " All angles in faces OK." << endl;
00935 }
00936
00937 return false;
00938 }
00939 }
00940
00941
00942
00943
00944
00945 bool Foam::primitiveMesh::checkFaceFlatness
00946 (
00947 const bool report,
00948 const scalar warnFlatness,
00949 labelHashSet* setPtr
00950 ) const
00951 {
00952 if (debug)
00953 {
00954 Info<< "bool primitiveMesh::checkFaceFlatness"
00955 << "(const bool, const scalar, labelHashSet*) const: "
00956 << "checking face flatness" << endl;
00957 }
00958
00959 if (warnFlatness < 0 || warnFlatness > 1)
00960 {
00961 FatalErrorIn
00962 (
00963 "primitiveMesh::checkFaceFlatness"
00964 "(const bool, const scalar, labelHashSet*)"
00965 ) << "warnFlatness should be [0..1] but is now " << warnFlatness
00966 << exit(FatalError);
00967 }
00968
00969
00970 const pointField& p = points();
00971 const faceList& fcs = faces();
00972 const pointField& fctrs = faceCentres();
00973
00974
00975
00976 scalarField magAreas(mag(faceAreas()));
00977
00978 label nWarped = 0;
00979
00980 scalar minFlatness = GREAT;
00981 scalar sumFlatness = 0;
00982 label nSummed = 0;
00983
00984 forAll(fcs, faceI)
00985 {
00986 const face& f = fcs[faceI];
00987
00988 if (f.size() > 3 && magAreas[faceI] > VSMALL)
00989 {
00990 const point& fc = fctrs[faceI];
00991
00992
00993
00994
00995 scalar sumA = 0.0;
00996
00997 forAll(f, fp)
00998 {
00999 const point& thisPoint = p[f[fp]];
01000 const point& nextPoint = p[f.nextLabel(fp)];
01001
01002
01003 vector n = 0.5*((nextPoint - thisPoint)^(fc - thisPoint));
01004 sumA += mag(n);
01005 }
01006
01007 scalar flatness = magAreas[faceI] / (sumA+VSMALL);
01008
01009 sumFlatness += flatness;
01010 nSummed++;
01011
01012 minFlatness = min(minFlatness, flatness);
01013
01014 if (flatness < warnFlatness)
01015 {
01016 nWarped++;
01017
01018 if (setPtr)
01019 {
01020 setPtr->insert(faceI);
01021 }
01022 }
01023 }
01024 }
01025
01026
01027 reduce(nWarped, sumOp<label>());
01028 reduce(minFlatness, minOp<scalar>());
01029
01030 reduce(nSummed, sumOp<label>());
01031 reduce(sumFlatness, sumOp<scalar>());
01032
01033 if (debug || report)
01034 {
01035 if (nSummed > 0)
01036 {
01037 Info<< " Face flatness (1 = flat, 0 = butterfly) : average = "
01038 << sumFlatness / nSummed << " min = " << minFlatness << endl;
01039 }
01040 }
01041
01042
01043 if (nWarped> 0)
01044 {
01045 if (debug || report)
01046 {
01047 Info<< " *There are " << nWarped
01048 << " faces with ratio between projected and actual area < "
01049 << warnFlatness << endl;
01050
01051 Info<< " Minimum ratio (minimum flatness, maximum warpage) = "
01052 << minFlatness << endl;
01053 }
01054
01055 return true;
01056 }
01057 else
01058 {
01059 if (debug || report)
01060 {
01061 Info<< " All face flatness OK." << endl;
01062 }
01063
01064 return false;
01065 }
01066 }
01067
01068
01069
01070
01071
01072
01073
01074
01075 bool Foam::primitiveMesh::checkEdgeAlignment
01076 (
01077 const bool report,
01078 const Vector<label>& directions,
01079 labelHashSet* setPtr
01080 ) const
01081 {
01082 if (debug)
01083 {
01084 Info<< "bool primitiveMesh::checkEdgeAlignment("
01085 << "const bool, const Vector<label>&, labelHashSet*) const: "
01086 << "checking edge alignment" << endl;
01087 }
01088
01089 label nDirs = 0;
01090 for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
01091 {
01092 if (directions[cmpt] == 1)
01093 {
01094 nDirs++;
01095 }
01096 else if (directions[cmpt] != 0)
01097 {
01098 FatalErrorIn
01099 (
01100 "primitiveMesh::checkEdgeAlignment"
01101 "(const bool, const Vector<label>&, labelHashSet*)"
01102 ) << "directions should contain 0 or 1 but is now " << directions
01103 << exit(FatalError);
01104 }
01105 }
01106
01107 if (nDirs == vector::nComponents)
01108 {
01109 return false;
01110 }
01111
01112
01113
01114 const pointField& p = points();
01115 const faceList& fcs = faces();
01116
01117 EdgeMap<label> edgesInError;
01118
01119 forAll(fcs, faceI)
01120 {
01121 const face& f = fcs[faceI];
01122
01123 forAll(f, fp)
01124 {
01125 label p0 = f[fp];
01126 label p1 = f.nextLabel(fp);
01127 if (p0 < p1)
01128 {
01129 vector d(p[p1]-p[p0]);
01130 scalar magD = mag(d);
01131
01132 if (magD > ROOTVSMALL)
01133 {
01134 d /= magD;
01135
01136
01137 label nEmptyDirs = 0;
01138 label nNonEmptyDirs = 0;
01139 for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
01140 {
01141 if (mag(d[cmpt]) > 1e-6)
01142 {
01143 if (directions[cmpt] == 0)
01144 {
01145 nEmptyDirs++;
01146 }
01147 else
01148 {
01149 nNonEmptyDirs++;
01150 }
01151 }
01152 }
01153
01154 if (nEmptyDirs == 0)
01155 {
01156
01157 }
01158 else if (nEmptyDirs == 1)
01159 {
01160
01161 if (nNonEmptyDirs > 0)
01162 {
01163 edgesInError.insert(edge(p0, p1), faceI);
01164 }
01165 }
01166 else if (nEmptyDirs > 1)
01167 {
01168
01169 edgesInError.insert(edge(p0, p1), faceI);
01170 }
01171 }
01172 }
01173 }
01174 }
01175
01176 label nErrorEdges = returnReduce(edgesInError.size(), sumOp<label>());
01177
01178 if (nErrorEdges > 0)
01179 {
01180 if (debug || report)
01181 {
01182 Info<< " ***Number of edges not aligned with or perpendicular to "
01183 << "non-empty directions: " << nErrorEdges << endl;
01184 }
01185
01186 if (setPtr)
01187 {
01188 setPtr->resize(2*edgesInError.size());
01189 forAllConstIter(EdgeMap<label>, edgesInError, iter)
01190 {
01191 setPtr->insert(iter.key()[0]);
01192 setPtr->insert(iter.key()[1]);
01193 }
01194 }
01195
01196 return true;
01197 }
01198 else
01199 {
01200 if (debug || report)
01201 {
01202 Info<< " All edges aligned with or perpendicular to "
01203 << "non-empty directions." << endl;
01204 }
01205 return false;
01206 }
01207 }
01208
01209
01210 bool Foam::primitiveMesh::checkUpperTriangular
01211 (
01212 const bool report,
01213 labelHashSet* setPtr
01214 ) const
01215 {
01216 if (debug)
01217 {
01218 Info<< "bool primitiveMesh::checkUpperTriangular("
01219 << "const bool, labelHashSet*) const: "
01220 << "checking face ordering" << endl;
01221 }
01222
01223
01224 const labelList& own = faceOwner();
01225 const labelList& nei = faceNeighbour();
01226
01227 const cellList& c = cells();
01228
01229 label internal = nInternalFaces();
01230
01231
01232 bool error = false;
01233
01234 label nMultipleCells = false;
01235
01236
01237
01238 for (label faceI = 0; faceI < internal; faceI++)
01239 {
01240 if (own[faceI] >= nei[faceI])
01241 {
01242 error = true;
01243
01244 if (setPtr)
01245 {
01246 setPtr->insert(faceI);
01247 }
01248 }
01249 }
01250
01251
01252
01253
01254
01255 forAll (c, cellI)
01256 {
01257 const labelList& curFaces = c[cellI];
01258
01259
01260 SortableList<label> nbr(curFaces.size());
01261
01262 forAll(curFaces, i)
01263 {
01264 label faceI = curFaces[i];
01265
01266 if (faceI >= nInternalFaces())
01267 {
01268
01269 nbr[i] = labelMax;
01270 }
01271 else
01272 {
01273 label nbrCellI = nei[faceI];
01274
01275 if (nbrCellI == cellI)
01276 {
01277 nbrCellI = own[faceI];
01278 }
01279
01280 if (cellI < nbrCellI)
01281 {
01282
01283 nbr[i] = nbrCellI;
01284 }
01285 else
01286 {
01287
01288 nbr[i] = labelMax;
01289 }
01290 }
01291 }
01292
01293 nbr.sort();
01294
01295
01296
01297
01298
01299
01300 label prevCell = nbr[0];
01301 label prevFace = curFaces[nbr.indices()[0]];
01302
01303 bool hasMultipleFaces = false;
01304
01305 for (label i = 1; i < nbr.size(); i++)
01306 {
01307 label thisCell = nbr[i];
01308 label thisFace = curFaces[nbr.indices()[i]];
01309
01310 if (thisCell == labelMax)
01311 {
01312 break;
01313 }
01314
01315 if (thisCell == prevCell)
01316 {
01317 hasMultipleFaces = true;
01318
01319 if (setPtr)
01320 {
01321 setPtr->insert(prevFace);
01322 setPtr->insert(thisFace);
01323 }
01324 }
01325 else if (thisFace < prevFace)
01326 {
01327 error = true;
01328
01329 if (setPtr)
01330 {
01331 setPtr->insert(thisFace);
01332 }
01333 }
01334
01335 prevCell = thisCell;
01336 prevFace = thisFace;
01337 }
01338
01339 if (hasMultipleFaces)
01340 {
01341 nMultipleCells++;
01342 }
01343 }
01344
01345 reduce(error, orOp<bool>());
01346 reduce(nMultipleCells, sumOp<label>());
01347
01348 if ((debug || report) && nMultipleCells > 0)
01349 {
01350 Info<< " <<Found " << nMultipleCells
01351 << " neighbouring cells with multiple inbetween faces." << endl;
01352 }
01353
01354 if (error)
01355 {
01356 if (debug || report)
01357 {
01358 Info<< " ***Faces not in upper triangular order." << endl;
01359 }
01360
01361 return true;
01362 }
01363 else
01364 {
01365 if (debug || report)
01366 {
01367 Info<< " Upper triangular ordering OK." << endl;
01368 }
01369
01370 return false;
01371 }
01372 }
01373
01374
01375 bool Foam::primitiveMesh::checkCellsZipUp
01376 (
01377 const bool report,
01378 labelHashSet* setPtr
01379 ) const
01380 {
01381 if (debug)
01382 {
01383 Info<< "bool primitiveMesh::checkCellsZipUp("
01384 << "const bool, labelHashSet*) const: "
01385 << "checking topological cell openness" << endl;
01386 }
01387
01388 label nOpenCells = 0;
01389
01390 const faceList& f = faces();
01391 const cellList& c = cells();
01392
01393 forAll (c, cellI)
01394 {
01395 const labelList& curFaces = c[cellI];
01396
01397 const edgeList cellEdges = c[cellI].edges(f);
01398
01399 labelList edgeUsage(cellEdges.size(), 0);
01400
01401 forAll (curFaces, faceI)
01402 {
01403 edgeList curFaceEdges = f[curFaces[faceI]].edges();
01404
01405 forAll (curFaceEdges, faceEdgeI)
01406 {
01407 const edge& curEdge = curFaceEdges[faceEdgeI];
01408
01409 forAll (cellEdges, cellEdgeI)
01410 {
01411 if (cellEdges[cellEdgeI] == curEdge)
01412 {
01413 edgeUsage[cellEdgeI]++;
01414 break;
01415 }
01416 }
01417 }
01418 }
01419
01420 edgeList singleEdges(cellEdges.size());
01421 label nSingleEdges = 0;
01422
01423 forAll (edgeUsage, edgeI)
01424 {
01425 if (edgeUsage[edgeI] == 1)
01426 {
01427 singleEdges[nSingleEdges] = cellEdges[edgeI];
01428 nSingleEdges++;
01429 }
01430 else if (edgeUsage[edgeI] != 2)
01431 {
01432 if (setPtr)
01433 {
01434 setPtr->insert(cellI);
01435 }
01436 }
01437 }
01438
01439 if (nSingleEdges > 0)
01440 {
01441 if (setPtr)
01442 {
01443 setPtr->insert(cellI);
01444 }
01445
01446 nOpenCells++;
01447 }
01448 }
01449
01450 reduce(nOpenCells, sumOp<label>());
01451
01452 if (nOpenCells > 0)
01453 {
01454 if (debug || report)
01455 {
01456 Info<< " ***Open cells found, number of cells: " << nOpenCells
01457 << ". This problem may be fixable using the zipUpMesh utility."
01458 << endl;
01459 }
01460
01461 return true;
01462 }
01463 else
01464 {
01465 if (debug || report)
01466 {
01467 Info<< " Topological cell zip-up check OK." << endl;
01468 }
01469
01470 return false;
01471 }
01472 }
01473
01474
01475
01476 bool Foam::primitiveMesh::checkFaceVertices
01477 (
01478 const bool report,
01479 labelHashSet* setPtr
01480 ) const
01481 {
01482 if (debug)
01483 {
01484 Info<< "bool primitiveMesh::checkFaceVertices("
01485 << "const bool, labelHashSet*) const: "
01486 << "checking face vertices" << endl;
01487 }
01488
01489
01490 const faceList& f = faces();
01491
01492 label nErrorFaces = 0;
01493
01494 forAll (f, fI)
01495 {
01496 const face& curFace = f[fI];
01497
01498 if (min(curFace) < 0 || max(curFace) > nPoints())
01499 {
01500 if (setPtr)
01501 {
01502 setPtr->insert(fI);
01503 }
01504
01505 nErrorFaces++;
01506 }
01507
01508
01509 labelHashSet facePoints(2*curFace.size());
01510
01511 forAll(curFace, fp)
01512 {
01513 bool inserted = facePoints.insert(curFace[fp]);
01514
01515 if (!inserted)
01516 {
01517 if (setPtr)
01518 {
01519 setPtr->insert(fI);
01520 }
01521
01522 nErrorFaces++;
01523 }
01524 }
01525 }
01526
01527 reduce(nErrorFaces, sumOp<label>());
01528
01529 if (nErrorFaces > 0)
01530 {
01531 if (debug || report)
01532 {
01533 Info<< " Faces with invalid vertex labels found, "
01534 << " number of faces: " << nErrorFaces << endl;
01535 }
01536
01537 return true;
01538 }
01539 else
01540 {
01541 if (debug || report)
01542 {
01543 Info<< " Face vertices OK." << endl;
01544 }
01545
01546 return false;
01547 }
01548 }
01549
01550
01551
01552 bool Foam::primitiveMesh::checkDuplicateFaces
01553 (
01554 const label faceI,
01555 const Map<label>& nCommonPoints,
01556 label& nBaffleFaces,
01557 labelHashSet* setPtr
01558 ) const
01559 {
01560 bool error = false;
01561
01562 forAllConstIter(Map<label>, nCommonPoints, iter)
01563 {
01564 label nbFaceI = iter.key();
01565 label nCommon = iter();
01566
01567 const face& curFace = faces()[faceI];
01568 const face& nbFace = faces()[nbFaceI];
01569
01570 if (nCommon == nbFace.size() || nCommon == curFace.size())
01571 {
01572 if (nbFace.size() != curFace.size())
01573 {
01574 error = true;
01575 }
01576 else
01577 {
01578 nBaffleFaces++;
01579 }
01580
01581 if (setPtr)
01582 {
01583 setPtr->insert(faceI);
01584 setPtr->insert(nbFaceI);
01585 }
01586 }
01587 }
01588
01589 return error;
01590 }
01591
01592
01593
01594 bool Foam::primitiveMesh::checkCommonOrder
01595 (
01596 const label faceI,
01597 const Map<label>& nCommonPoints,
01598 labelHashSet* setPtr
01599 ) const
01600 {
01601 bool error = false;
01602
01603 forAllConstIter(Map<label>, nCommonPoints, iter)
01604 {
01605 label nbFaceI = iter.key();
01606 label nCommon = iter();
01607
01608 const face& curFace = faces()[faceI];
01609 const face& nbFace = faces()[nbFaceI];
01610
01611 if
01612 (
01613 nCommon >= 2
01614 && nCommon != nbFace.size()
01615 && nCommon != curFace.size()
01616 )
01617 {
01618 forAll(curFace, fp)
01619 {
01620
01621 label nb = findIndex(nbFace, curFace[fp]);
01622
01623 if (nb != -1)
01624 {
01625
01626
01627
01628
01629
01630
01631
01632
01633
01634
01635 label fpPlus1 = curFace.fcIndex(fp);
01636 label fpMin1 = curFace.rcIndex(fp);
01637
01638
01639 label nbPlus1 = nbFace.fcIndex(nb);
01640 label nbMin1 = nbFace.rcIndex(nb);
01641
01642
01643
01644 label curInc = labelMax;
01645 label nbInc = labelMax;
01646
01647 if (nbFace[nbPlus1] == curFace[fpPlus1])
01648 {
01649 curInc = 1;
01650 nbInc = 1;
01651 }
01652 else if (nbFace[nbPlus1] == curFace[fpMin1])
01653 {
01654 curInc = -1;
01655 nbInc = 1;
01656 }
01657 else if (nbFace[nbMin1] == curFace[fpMin1])
01658 {
01659 curInc = -1;
01660 nbInc = -1;
01661 }
01662 else
01663 {
01664 curInc = 1;
01665 nbInc = -1;
01666 }
01667
01668
01669
01670 label curNb = nb;
01671 label curFp = fp;
01672
01673 do
01674 {
01675 curFp += curInc;
01676
01677 if (curFp >= curFace.size())
01678 {
01679 curFp = 0;
01680 }
01681 else if (curFp < 0)
01682 {
01683 curFp = curFace.size()-1;
01684 }
01685
01686 curNb += nbInc;
01687
01688 if (curNb >= nbFace.size())
01689 {
01690 curNb = 0;
01691 }
01692 else if (curNb < 0)
01693 {
01694 curNb = nbFace.size()-1;
01695 }
01696 } while (curFace[curFp] == nbFace[curNb]);
01697
01698
01699
01700
01701
01702 curInc = -curInc;
01703 nbInc = -nbInc;
01704
01705 for (label commonI = 0; commonI < nCommon; commonI++)
01706 {
01707 curFp += curInc;
01708
01709 if (curFp >= curFace.size())
01710 {
01711 curFp = 0;
01712 }
01713 else if (curFp < 0)
01714 {
01715 curFp = curFace.size()-1;
01716 }
01717
01718 curNb += nbInc;
01719
01720 if (curNb >= nbFace.size())
01721 {
01722 curNb = 0;
01723 }
01724 else if (curNb < 0)
01725 {
01726 curNb = nbFace.size()-1;
01727 }
01728
01729 if (curFace[curFp] != nbFace[curNb])
01730 {
01731 if (setPtr)
01732 {
01733 setPtr->insert(faceI);
01734 setPtr->insert(nbFaceI);
01735 }
01736
01737 error = true;
01738
01739 break;
01740 }
01741 }
01742
01743
01744
01745 break;
01746 }
01747 }
01748 }
01749 }
01750
01751 return error;
01752 }
01753
01754
01755
01756
01757 bool Foam::primitiveMesh::checkFaceFaces
01758 (
01759 const bool report,
01760 labelHashSet* setPtr
01761 ) const
01762 {
01763 if (debug)
01764 {
01765 Info<< "bool primitiveMesh::checkFaceFaces(const bool, labelHashSet*)"
01766 << " const: " << "checking face-face connectivity" << endl;
01767 }
01768
01769 const labelListList& pf = pointFaces();
01770
01771 label nBaffleFaces = 0;
01772 label nErrorDuplicate = 0;
01773 label nErrorOrder = 0;
01774 Map<label> nCommonPoints(100);
01775
01776 for (label faceI = 0; faceI < nFaces(); faceI++)
01777 {
01778 const face& curFace = faces()[faceI];
01779
01780
01781
01782 nCommonPoints.clear();
01783
01784 forAll(curFace, fp)
01785 {
01786 label pointI = curFace[fp];
01787
01788 const labelList& nbs = pf[pointI];
01789
01790 forAll(nbs, nbI)
01791 {
01792 label nbFaceI = nbs[nbI];
01793
01794 if (faceI < nbFaceI)
01795 {
01796
01797
01798 Map<label>::iterator fnd = nCommonPoints.find(nbFaceI);
01799
01800 if (fnd == nCommonPoints.end())
01801 {
01802
01803 nCommonPoints.insert(nbFaceI, 1);
01804 }
01805 else
01806 {
01807 fnd()++;
01808 }
01809 }
01810 }
01811 }
01812
01813
01814
01815
01816 if (checkDuplicateFaces(faceI, nCommonPoints, nBaffleFaces, setPtr))
01817 {
01818 nErrorDuplicate++;
01819 }
01820
01821
01822 if (checkCommonOrder(faceI, nCommonPoints, setPtr))
01823 {
01824 nErrorOrder++;
01825 }
01826 }
01827
01828 reduce(nBaffleFaces, sumOp<label>());
01829 reduce(nErrorDuplicate, sumOp<label>());
01830 reduce(nErrorOrder, sumOp<label>());
01831
01832 if (nBaffleFaces)
01833 {
01834 Info<< " Number of identical duplicate faces (baffle faces): "
01835 << nBaffleFaces << endl;
01836 }
01837
01838 if (nErrorDuplicate > 0 || nErrorOrder > 0)
01839 {
01840 if (nErrorDuplicate > 0)
01841 {
01842 Info<< " ***Number of duplicate (not baffle) faces found: "
01843 << nErrorDuplicate << endl;
01844 }
01845
01846 if (nErrorOrder > 0)
01847 {
01848 Info<< " ***Number of faces with non-consecutive shared points: "
01849 << nErrorOrder << endl;
01850 }
01851
01852 return true;
01853 }
01854 else
01855 {
01856 if (debug || report)
01857 {
01858 Info<< " Face-face connectivity OK." << endl;
01859 }
01860
01861 return false;
01862 }
01863 }
01864
01865
01866
01867 bool Foam::primitiveMesh::checkCellDeterminant
01868 (
01869 const bool report,
01870 labelHashSet* setPtr
01871 ) const
01872 {
01873 if (debug)
01874 {
01875 Info<< "bool primitiveMesh::checkCellDeterminant(const bool"
01876 << ", labelHashSet*) const: "
01877 << "checking for under-determined cells" << endl;
01878 }
01879
01880 const cellList& c = cells();
01881
01882 label nErrorCells = 0;
01883
01884 scalar minDet = GREAT;
01885 scalar sumDet = 0;
01886 label nSummed = 0;
01887
01888 forAll (c, cellI)
01889 {
01890 const labelList& curFaces = c[cellI];
01891
01892
01893 scalar avgArea = 0;
01894
01895 label nInternalFaces = 0;
01896
01897 forAll(curFaces, i)
01898 {
01899 if (isInternalFace(curFaces[i]))
01900 {
01901 avgArea += mag(faceAreas()[curFaces[i]]);
01902
01903 nInternalFaces++;
01904 }
01905 }
01906
01907 if (nInternalFaces == 0)
01908 {
01909 if (setPtr)
01910 {
01911 setPtr->insert(cellI);
01912 }
01913
01914 nErrorCells++;
01915 }
01916 else
01917 {
01918 avgArea /= nInternalFaces;
01919
01920 symmTensor areaTensor(symmTensor::zero);
01921
01922 forAll(curFaces, i)
01923 {
01924 if (isInternalFace(curFaces[i]))
01925 {
01926 areaTensor += sqr(faceAreas()[curFaces[i]]/avgArea);
01927 }
01928 }
01929
01930 scalar determinant = mag(det(areaTensor));
01931
01932 minDet = min(determinant, minDet);
01933 sumDet += determinant;
01934 nSummed++;
01935
01936 if (determinant < 1e-3)
01937 {
01938 if (setPtr)
01939 {
01940 setPtr->insert(cellI);
01941 }
01942
01943 nErrorCells++;
01944 }
01945 }
01946 }
01947
01948 reduce(nErrorCells, sumOp<label>());
01949 reduce(minDet, minOp<scalar>());
01950 reduce(sumDet, sumOp<scalar>());
01951 reduce(nSummed, sumOp<label>());
01952
01953 if (debug || report)
01954 {
01955 if (nSummed > 0)
01956 {
01957 Info<< " Cell determinant (wellposedness) : minimum: " << minDet
01958 << " average: " << sumDet/nSummed
01959 << endl;
01960 }
01961 }
01962
01963 if (nErrorCells > 0)
01964 {
01965 if (debug || report)
01966 {
01967 Info<< " ***Cells with small determinant found, number of cells: "
01968 << nErrorCells << endl;
01969 }
01970
01971 return true;
01972 }
01973 else
01974 {
01975 if (debug || report)
01976 {
01977 Info<< " Cell determinant check OK." << endl;
01978 }
01979
01980 return false;
01981 }
01982
01983 return false;
01984 }
01985
01986
01987
01988
01989 bool Foam::primitiveMesh::checkTopology(const bool report) const
01990 {
01991 label noFailedChecks = 0;
01992
01993 if (checkPoints(report)) noFailedChecks++;
01994 if (checkUpperTriangular(report)) noFailedChecks++;
01995 if (checkCellsZipUp(report)) noFailedChecks++;
01996 if (checkFaceVertices(report)) noFailedChecks++;
01997 if (checkFaceFaces(report)) noFailedChecks++;
01998
01999
02000 if (noFailedChecks == 0)
02001 {
02002 if (debug || report)
02003 {
02004 Info<< " Mesh topology OK." << endl;
02005 }
02006
02007 return false;
02008 }
02009 else
02010 {
02011 if (debug || report)
02012 {
02013 Info<< " Failed " << noFailedChecks
02014 << " mesh topology checks." << endl;
02015 }
02016
02017 return true;
02018 }
02019 }
02020
02021
02022 bool Foam::primitiveMesh::checkGeometry(const bool report) const
02023 {
02024 label noFailedChecks = 0;
02025
02026 if (checkClosedBoundary(report)) noFailedChecks++;
02027 if (checkClosedCells(report)) noFailedChecks++;
02028 if (checkFaceAreas(report)) noFailedChecks++;
02029 if (checkCellVolumes(report)) noFailedChecks++;
02030 if (checkFaceOrthogonality(report)) noFailedChecks++;
02031 if (checkFacePyramids(report)) noFailedChecks++;
02032 if (checkFaceSkewness(report)) noFailedChecks++;
02033
02034 if (noFailedChecks == 0)
02035 {
02036 if (debug || report)
02037 {
02038 Info<< " Mesh geometry OK." << endl;
02039 }
02040 return false;
02041 }
02042 else
02043 {
02044 if (debug || report)
02045 {
02046 Info<< " Failed " << noFailedChecks
02047 << " mesh geometry checks." << endl;
02048 }
02049
02050 return true;
02051 }
02052 }
02053
02054
02055 bool Foam::primitiveMesh::checkMesh(const bool report) const
02056 {
02057 if (debug)
02058 {
02059 Info<< "bool primitiveMesh::checkMesh(const bool report) const: "
02060 << "checking primitiveMesh" << endl;
02061 }
02062
02063 label noFailedChecks = checkTopology(report) + checkGeometry(report);
02064
02065 if (noFailedChecks == 0)
02066 {
02067 if (debug || report)
02068 {
02069 Info<< "Mesh OK." << endl;
02070 }
02071
02072 return false;
02073 }
02074 else
02075 {
02076 if (debug || report)
02077 {
02078 Info<< " Failed " << noFailedChecks
02079 << " mesh checks." << endl;
02080 }
02081
02082 return true;
02083 }
02084 }
02085
02086
02087 Foam::scalar Foam::primitiveMesh::setClosedThreshold(const scalar val)
02088 {
02089 scalar prev = closedThreshold_;
02090 closedThreshold_ = val;
02091
02092 return prev;
02093 }
02094
02095
02096 Foam::scalar Foam::primitiveMesh::setAspectThreshold(const scalar val)
02097 {
02098 scalar prev = aspectThreshold_;
02099 aspectThreshold_ = val;
02100
02101 return prev;
02102 }
02103
02104
02105 Foam::scalar Foam::primitiveMesh::setNonOrthThreshold(const scalar val)
02106 {
02107 scalar prev = nonOrthThreshold_;
02108 nonOrthThreshold_ = val;
02109
02110 return prev;
02111 }
02112
02113
02114 Foam::scalar Foam::primitiveMesh::setSkewThreshold(const scalar val)
02115 {
02116 scalar prev = skewThreshold_;
02117 skewThreshold_ = val;
02118
02119 return prev;
02120 }
02121
02122
02123