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 "primitiveMeshGeometry.H"
00028 #include "pyramidPointFaceRef.H"
00029
00030 namespace Foam
00031 {
00032
00033
00034
00035 defineTypeNameAndDebug(primitiveMeshGeometry, 0);
00036
00037 }
00038
00039
00040
00041
00042 void Foam::primitiveMeshGeometry::updateFaceCentresAndAreas
00043 (
00044 const pointField& p,
00045 const labelList& changedFaces
00046 )
00047 {
00048 const faceList& fs = mesh_.faces();
00049
00050 forAll(changedFaces, i)
00051 {
00052 label facei = changedFaces[i];
00053
00054 const labelList& f = fs[facei];
00055 label nPoints = f.size();
00056
00057
00058
00059 if (nPoints == 3)
00060 {
00061 faceCentres_[facei] = (1.0/3.0)*(p[f[0]] + p[f[1]] + p[f[2]]);
00062 faceAreas_[facei] = 0.5*((p[f[1]] - p[f[0]])^(p[f[2]] - p[f[0]]));
00063 }
00064 else
00065 {
00066 vector sumN = vector::zero;
00067 scalar sumA = 0.0;
00068 vector sumAc = vector::zero;
00069
00070 point fCentre = p[f[0]];
00071 for (label pi = 1; pi < nPoints; pi++)
00072 {
00073 fCentre += p[f[pi]];
00074 }
00075
00076 fCentre /= nPoints;
00077
00078 for (label pi = 0; pi < nPoints; pi++)
00079 {
00080 const point& nextPoint = p[f[(pi + 1) % nPoints]];
00081
00082 vector c = p[f[pi]] + nextPoint + fCentre;
00083 vector n = (nextPoint - p[f[pi]])^(fCentre - p[f[pi]]);
00084 scalar a = mag(n);
00085
00086 sumN += n;
00087 sumA += a;
00088 sumAc += a*c;
00089 }
00090
00091 faceCentres_[facei] = (1.0/3.0)*sumAc/(sumA + VSMALL);
00092 faceAreas_[facei] = 0.5*sumN;
00093 }
00094 }
00095 }
00096
00097
00098 void Foam::primitiveMeshGeometry::updateCellCentresAndVols
00099 (
00100 const labelList& changedCells,
00101 const labelList& changedFaces
00102 )
00103 {
00104
00105 UIndirectList<vector>(cellCentres_, changedCells) = vector::zero;
00106 UIndirectList<scalar>(cellVolumes_, changedCells) = 0.0;
00107
00108 const labelList& own = mesh_.faceOwner();
00109 const labelList& nei = mesh_.faceNeighbour();
00110
00111
00112
00113 vectorField cEst(mesh_.nCells());
00114 UIndirectList<vector>(cEst, changedCells) = vector::zero;
00115 scalarField nCellFaces(mesh_.nCells());
00116 UIndirectList<scalar>(nCellFaces, changedCells) = 0.0;
00117
00118 forAll(changedFaces, i)
00119 {
00120 label faceI = changedFaces[i];
00121 cEst[own[faceI]] += faceCentres_[faceI];
00122 nCellFaces[own[faceI]] += 1;
00123
00124 if (mesh_.isInternalFace(faceI))
00125 {
00126 cEst[nei[faceI]] += faceCentres_[faceI];
00127 nCellFaces[nei[faceI]] += 1;
00128 }
00129 }
00130
00131 forAll(changedCells, i)
00132 {
00133 label cellI = changedCells[i];
00134 cEst[cellI] /= nCellFaces[cellI];
00135 }
00136
00137 forAll(changedFaces, i)
00138 {
00139 label faceI = changedFaces[i];
00140
00141
00142 scalar pyr3Vol = max
00143 (
00144 faceAreas_[faceI] & (faceCentres_[faceI] - cEst[own[faceI]]),
00145 VSMALL
00146 );
00147
00148
00149 vector pc = (3.0/4.0)*faceCentres_[faceI] + (1.0/4.0)*cEst[own[faceI]];
00150
00151
00152 cellCentres_[own[faceI]] += pyr3Vol*pc;
00153
00154
00155 cellVolumes_[own[faceI]] += pyr3Vol;
00156
00157 if (mesh_.isInternalFace(faceI))
00158 {
00159
00160 scalar pyr3Vol = max
00161 (
00162 faceAreas_[faceI] & (cEst[nei[faceI]] - faceCentres_[faceI]),
00163 VSMALL
00164 );
00165
00166
00167 vector pc =
00168 (3.0/4.0)*faceCentres_[faceI]
00169 + (1.0/4.0)*cEst[nei[faceI]];
00170
00171
00172 cellCentres_[nei[faceI]] += pyr3Vol*pc;
00173
00174
00175 cellVolumes_[nei[faceI]] += pyr3Vol;
00176 }
00177 }
00178
00179 forAll(changedCells, i)
00180 {
00181 label cellI = changedCells[i];
00182
00183 cellCentres_[cellI] /= cellVolumes_[cellI];
00184 cellVolumes_[cellI] *= (1.0/3.0);
00185 }
00186 }
00187
00188
00189 Foam::labelList Foam::primitiveMeshGeometry::affectedCells
00190 (
00191 const labelList& changedFaces
00192 ) const
00193 {
00194 const labelList& own = mesh_.faceOwner();
00195 const labelList& nei = mesh_.faceNeighbour();
00196
00197 labelHashSet affectedCells(2*changedFaces.size());
00198
00199 forAll(changedFaces, i)
00200 {
00201 label faceI = changedFaces[i];
00202
00203 affectedCells.insert(own[faceI]);
00204
00205 if (mesh_.isInternalFace(faceI))
00206 {
00207 affectedCells.insert(nei[faceI]);
00208 }
00209 }
00210 return affectedCells.toc();
00211 }
00212
00213
00214
00215
00216
00217
00218 Foam::primitiveMeshGeometry::primitiveMeshGeometry
00219 (
00220 const primitiveMesh& mesh
00221 )
00222 :
00223 mesh_(mesh)
00224 {
00225 correct();
00226 }
00227
00228
00229
00230
00231
00232
00233
00234
00235 void Foam::primitiveMeshGeometry::correct()
00236 {
00237 faceAreas_ = mesh_.faceAreas();
00238 faceCentres_ = mesh_.faceCentres();
00239 cellCentres_ = mesh_.cellCentres();
00240 cellVolumes_ = mesh_.cellVolumes();
00241 }
00242
00243
00244
00245 void Foam::primitiveMeshGeometry::correct
00246 (
00247 const pointField& p,
00248 const labelList& changedFaces
00249 )
00250 {
00251
00252 updateFaceCentresAndAreas(p, changedFaces);
00253
00254 updateCellCentresAndVols(affectedCells(changedFaces), changedFaces);
00255 }
00256
00257
00258 bool Foam::primitiveMeshGeometry::checkFaceDotProduct
00259 (
00260 const bool report,
00261 const scalar orthWarn,
00262 const primitiveMesh& mesh,
00263 const vectorField& cellCentres,
00264 const vectorField& faceAreas,
00265 const labelList& checkFaces,
00266 labelHashSet* setPtr
00267 )
00268 {
00269
00270
00271 const labelList& own = mesh.faceOwner();
00272 const labelList& nei = mesh.faceNeighbour();
00273
00274
00275 const scalar severeNonorthogonalityThreshold =
00276 ::cos(orthWarn/180.0*mathematicalConstant::pi);
00277
00278 scalar minDDotS = GREAT;
00279
00280 scalar sumDDotS = 0;
00281
00282 label severeNonOrth = 0;
00283
00284 label errorNonOrth = 0;
00285
00286 forAll(checkFaces, i)
00287 {
00288 label faceI = checkFaces[i];
00289
00290 if (mesh.isInternalFace(faceI))
00291 {
00292 vector d = cellCentres[nei[faceI]] - cellCentres[own[faceI]];
00293 const vector& s = faceAreas[faceI];
00294
00295 scalar dDotS = (d & s)/(mag(d)*mag(s) + VSMALL);
00296
00297 if (dDotS < severeNonorthogonalityThreshold)
00298 {
00299 if (dDotS > SMALL)
00300 {
00301 if (report)
00302 {
00303
00304 Pout<< "Severe non-orthogonality for face " << faceI
00305 << " between cells " << own[faceI]
00306 << " and " << nei[faceI]
00307 << ": Angle = "
00308 << ::acos(dDotS)/mathematicalConstant::pi*180.0
00309 << " deg." << endl;
00310 }
00311
00312 if (setPtr)
00313 {
00314 setPtr->insert(faceI);
00315 }
00316
00317 severeNonOrth++;
00318 }
00319 else
00320 {
00321
00322 if (report)
00323 {
00324 WarningIn
00325 (
00326 "primitiveMeshGeometry::checkFaceDotProduct"
00327 "(const bool, const scalar, const labelList&"
00328 ", labelHashSet*)"
00329 ) << "Severe non-orthogonality detected for face "
00330 << faceI
00331 << " between cells " << own[faceI] << " and "
00332 << nei[faceI]
00333 << ": Angle = "
00334 << ::acos(dDotS)/mathematicalConstant::pi*180.0
00335 << " deg." << endl;
00336 }
00337
00338 errorNonOrth++;
00339
00340 if (setPtr)
00341 {
00342 setPtr->insert(faceI);
00343 }
00344 }
00345 }
00346
00347 if (dDotS < minDDotS)
00348 {
00349 minDDotS = dDotS;
00350 }
00351
00352 sumDDotS += dDotS;
00353 }
00354 }
00355
00356 reduce(minDDotS, minOp<scalar>());
00357 reduce(sumDDotS, sumOp<scalar>());
00358 reduce(severeNonOrth, sumOp<label>());
00359 reduce(errorNonOrth, sumOp<label>());
00360
00361 label neiSize = nei.size();
00362 reduce(neiSize, sumOp<label>());
00363
00364
00365 if (neiSize > 0)
00366 {
00367 if (report && minDDotS < severeNonorthogonalityThreshold)
00368 {
00369 Info<< "Number of non-orthogonality errors: " << errorNonOrth
00370 << ". Number of severely non-orthogonal faces: "
00371 << severeNonOrth << "." << endl;
00372 }
00373 }
00374
00375 if (report)
00376 {
00377 if (neiSize > 0)
00378 {
00379 Info<< "Mesh non-orthogonality Max: "
00380 << ::acos(minDDotS)/mathematicalConstant::pi*180.0
00381 << " average: " <<
00382 ::acos(sumDDotS/neiSize)/mathematicalConstant::pi*180.0
00383 << endl;
00384 }
00385 }
00386
00387 if (errorNonOrth > 0)
00388 {
00389 if (report)
00390 {
00391 SeriousErrorIn
00392 (
00393 "primitiveMeshGeometry::checkFaceDotProduct"
00394 "(const bool, const scalar, const labelList&, labelHashSet*)"
00395 ) << "Error in non-orthogonality detected" << endl;
00396 }
00397
00398 return true;
00399 }
00400 else
00401 {
00402 if (report)
00403 {
00404 Info<< "Non-orthogonality check OK.\n" << endl;
00405 }
00406
00407 return false;
00408 }
00409 }
00410
00411
00412 bool Foam::primitiveMeshGeometry::checkFacePyramids
00413 (
00414 const bool report,
00415 const scalar minPyrVol,
00416 const primitiveMesh& mesh,
00417 const vectorField& cellCentres,
00418 const pointField& p,
00419 const labelList& checkFaces,
00420 labelHashSet* setPtr
00421 )
00422 {
00423
00424 const labelList& own = mesh.faceOwner();
00425 const labelList& nei = mesh.faceNeighbour();
00426
00427 const faceList& f = mesh.faces();
00428
00429 label nErrorPyrs = 0;
00430
00431 forAll(checkFaces, i)
00432 {
00433 label faceI = checkFaces[i];
00434
00435
00436 scalar pyrVol = pyramidPointFaceRef
00437 (
00438 f[faceI],
00439 cellCentres[own[faceI]]
00440 ).mag(p);
00441
00442 if (pyrVol > -minPyrVol)
00443 {
00444 if (report)
00445 {
00446 Pout<< "bool primitiveMeshGeometry::checkFacePyramids("
00447 << "const bool, const scalar, const pointField&"
00448 << ", const labelList&, labelHashSet*): "
00449 << "face " << faceI << " points the wrong way. " << endl
00450 << "Pyramid volume: " << -pyrVol
00451 << " Face " << f[faceI] << " area: " << f[faceI].mag(p)
00452 << " Owner cell: " << own[faceI] << endl
00453 << "Owner cell vertex labels: "
00454 << mesh.cells()[own[faceI]].labels(f)
00455 << endl;
00456 }
00457
00458
00459 if (setPtr)
00460 {
00461 setPtr->insert(faceI);
00462 }
00463
00464 nErrorPyrs++;
00465 }
00466
00467 if (mesh.isInternalFace(faceI))
00468 {
00469
00470 scalar pyrVol =
00471 pyramidPointFaceRef(f[faceI], cellCentres[nei[faceI]]).mag(p);
00472
00473 if (pyrVol < minPyrVol)
00474 {
00475 if (report)
00476 {
00477 Pout<< "bool primitiveMeshGeometry::checkFacePyramids("
00478 << "const bool, const scalar, const pointField&"
00479 << ", const labelList&, labelHashSet*): "
00480 << "face " << faceI << " points the wrong way. " << endl
00481 << "Pyramid volume: " << -pyrVol
00482 << " Face " << f[faceI] << " area: " << f[faceI].mag(p)
00483 << " Neighbour cell: " << nei[faceI] << endl
00484 << "Neighbour cell vertex labels: "
00485 << mesh.cells()[nei[faceI]].labels(f)
00486 << endl;
00487 }
00488
00489 if (setPtr)
00490 {
00491 setPtr->insert(faceI);
00492 }
00493
00494 nErrorPyrs++;
00495 }
00496 }
00497 }
00498
00499 reduce(nErrorPyrs, sumOp<label>());
00500
00501 if (nErrorPyrs > 0)
00502 {
00503 if (report)
00504 {
00505 SeriousErrorIn
00506 (
00507 "primitiveMeshGeometry::checkFacePyramids("
00508 "const bool, const scalar, const pointField&"
00509 ", const labelList&, labelHashSet*)"
00510 ) << "Error in face pyramids: faces pointing the wrong way!"
00511 << endl;
00512 }
00513
00514 return true;
00515 }
00516 else
00517 {
00518 if (report)
00519 {
00520 Info<< "Face pyramids OK.\n" << endl;
00521 }
00522
00523 return false;
00524 }
00525 }
00526
00527
00528 bool Foam::primitiveMeshGeometry::checkFaceSkewness
00529 (
00530 const bool report,
00531 const scalar internalSkew,
00532 const scalar boundarySkew,
00533 const primitiveMesh& mesh,
00534 const vectorField& cellCentres,
00535 const vectorField& faceCentres,
00536 const vectorField& faceAreas,
00537 const labelList& checkFaces,
00538 labelHashSet* setPtr
00539 )
00540 {
00541
00542
00543
00544 const labelList& own = mesh.faceOwner();
00545 const labelList& nei = mesh.faceNeighbour();
00546
00547 scalar maxSkew = 0;
00548
00549 label nWarnSkew = 0;
00550
00551 forAll(checkFaces, i)
00552 {
00553 label faceI = checkFaces[i];
00554
00555 if (mesh.isInternalFace(faceI))
00556 {
00557 scalar dOwn = mag(faceCentres[faceI] - cellCentres[own[faceI]]);
00558 scalar dNei = mag(faceCentres[faceI] - cellCentres[nei[faceI]]);
00559
00560 point faceIntersection =
00561 cellCentres[own[faceI]]*dNei/(dOwn+dNei)
00562 + cellCentres[nei[faceI]]*dOwn/(dOwn+dNei);
00563
00564 scalar skewness =
00565 mag(faceCentres[faceI] - faceIntersection)
00566 / (
00567 mag(cellCentres[nei[faceI]]-cellCentres[own[faceI]])
00568 + VSMALL
00569 );
00570
00571
00572
00573
00574 if (skewness > internalSkew)
00575 {
00576 if (report)
00577 {
00578 Pout<< "Severe skewness for face " << faceI
00579 << " skewness = " << skewness << endl;
00580 }
00581
00582 if (setPtr)
00583 {
00584 setPtr->insert(faceI);
00585 }
00586
00587 nWarnSkew++;
00588 }
00589
00590 if (skewness > maxSkew)
00591 {
00592 maxSkew = skewness;
00593 }
00594 }
00595 else
00596 {
00597
00598
00599
00600 vector faceNormal = faceAreas[faceI];
00601 faceNormal /= mag(faceNormal) + VSMALL;
00602
00603 vector dOwn = faceCentres[faceI] - cellCentres[own[faceI]];
00604
00605 vector dWall = faceNormal*(faceNormal & dOwn);
00606
00607 point faceIntersection = cellCentres[own[faceI]] + dWall;
00608
00609 scalar skewness =
00610 mag(faceCentres[faceI] - faceIntersection)
00611 /(2*mag(dWall) + VSMALL);
00612
00613
00614
00615
00616 if (skewness > boundarySkew)
00617 {
00618 if (report)
00619 {
00620 Pout<< "Severe skewness for boundary face " << faceI
00621 << " skewness = " << skewness << endl;
00622 }
00623
00624 if (setPtr)
00625 {
00626 setPtr->insert(faceI);
00627 }
00628
00629 nWarnSkew++;
00630 }
00631
00632 if (skewness > maxSkew)
00633 {
00634 maxSkew = skewness;
00635 }
00636 }
00637 }
00638
00639 reduce(maxSkew, maxOp<scalar>());
00640 reduce(nWarnSkew, sumOp<label>());
00641
00642 if (nWarnSkew > 0)
00643 {
00644 if (report)
00645 {
00646 WarningIn
00647 (
00648 "primitiveMeshGeometry::checkFaceSkewness"
00649 "(const bool, const scalar, const labelList&, labelHashSet*)"
00650 ) << "Large face skewness detected. Max skewness = "
00651 << 100*maxSkew
00652 << " percent.\nThis may impair the quality of the result." << nl
00653 << nWarnSkew << " highly skew faces detected."
00654 << endl;
00655 }
00656
00657 return true;
00658 }
00659 else
00660 {
00661 if (report)
00662 {
00663 Info<< "Max skewness = " << 100*maxSkew
00664 << " percent. Face skewness OK.\n" << endl;
00665 }
00666
00667 return false;
00668 }
00669 }
00670
00671
00672 bool Foam::primitiveMeshGeometry::checkFaceWeights
00673 (
00674 const bool report,
00675 const scalar warnWeight,
00676 const primitiveMesh& mesh,
00677 const vectorField& cellCentres,
00678 const vectorField& faceCentres,
00679 const vectorField& faceAreas,
00680 const labelList& checkFaces,
00681 labelHashSet* setPtr
00682 )
00683 {
00684
00685
00686 const labelList& own = mesh.faceOwner();
00687 const labelList& nei = mesh.faceNeighbour();
00688
00689 scalar minWeight = GREAT;
00690
00691 label nWarnWeight = 0;
00692
00693 forAll(checkFaces, i)
00694 {
00695 label faceI = checkFaces[i];
00696
00697 if (mesh.isInternalFace(faceI))
00698 {
00699 const point& fc = faceCentres[faceI];
00700
00701 scalar dOwn = mag(faceAreas[faceI] & (fc-cellCentres[own[faceI]]));
00702 scalar dNei = mag(faceAreas[faceI] & (cellCentres[nei[faceI]]-fc));
00703
00704 scalar weight = min(dNei,dOwn)/(dNei+dOwn);
00705
00706 if (weight < warnWeight)
00707 {
00708 if (report)
00709 {
00710 Pout<< "Small weighting factor for face " << faceI
00711 << " weight = " << weight << endl;
00712 }
00713
00714 if (setPtr)
00715 {
00716 setPtr->insert(faceI);
00717 }
00718
00719 nWarnWeight++;
00720 }
00721
00722 minWeight = min(minWeight, weight);
00723 }
00724 }
00725
00726 reduce(minWeight, minOp<scalar>());
00727 reduce(nWarnWeight, sumOp<label>());
00728
00729 if (minWeight < warnWeight)
00730 {
00731 if (report)
00732 {
00733 WarningIn
00734 (
00735 "primitiveMeshGeometry::checkFaceWeights"
00736 "(const bool, const scalar, const labelList&, labelHashSet*)"
00737 ) << "Small interpolation weight detected. Min weight = "
00738 << minWeight << '.' << nl
00739 << nWarnWeight << " faces with small weights detected."
00740 << endl;
00741 }
00742
00743 return true;
00744 }
00745 else
00746 {
00747 if (report)
00748 {
00749 Info<< "Min weight = " << minWeight
00750 << " percent. Weights OK.\n" << endl;
00751 }
00752
00753 return false;
00754 }
00755 }
00756
00757
00758
00759
00760
00761
00762 bool Foam::primitiveMeshGeometry::checkFaceAngles
00763 (
00764 const bool report,
00765 const scalar maxDeg,
00766 const primitiveMesh& mesh,
00767 const vectorField& faceAreas,
00768 const pointField& p,
00769 const labelList& checkFaces,
00770 labelHashSet* setPtr
00771 )
00772 {
00773 if (maxDeg < -SMALL || maxDeg > 180+SMALL)
00774 {
00775 FatalErrorIn
00776 (
00777 "primitiveMeshGeometry::checkFaceAngles"
00778 "(const bool, const scalar, const pointField&, const labelList&"
00779 ", labelHashSet*)"
00780 ) << "maxDeg should be [0..180] but is now " << maxDeg
00781 << abort(FatalError);
00782 }
00783
00784 const scalar maxSin = Foam::sin(maxDeg/180.0*mathematicalConstant::pi);
00785
00786 const faceList& fcs = mesh.faces();
00787
00788 scalar maxEdgeSin = 0.0;
00789
00790 label nConcave = 0;
00791
00792 label errorFaceI = -1;
00793
00794 forAll(checkFaces, i)
00795 {
00796 label faceI = checkFaces[i];
00797
00798 const face& f = fcs[faceI];
00799
00800 vector faceNormal = faceAreas[faceI];
00801 faceNormal /= mag(faceNormal) + VSMALL;
00802
00803
00804 vector ePrev(p[f[0]] - p[f[f.size()-1]]);
00805 scalar magEPrev = mag(ePrev);
00806 ePrev /= magEPrev + VSMALL;
00807
00808 forAll(f, fp0)
00809 {
00810
00811 label fp1 = f.fcIndex(fp0);
00812
00813
00814 vector e10(p[f[fp1]] - p[f[fp0]]);
00815 scalar magE10 = mag(e10);
00816 e10 /= magE10 + VSMALL;
00817
00818 if (magEPrev > SMALL && magE10 > SMALL)
00819 {
00820 vector edgeNormal = ePrev ^ e10;
00821 scalar magEdgeNormal = mag(edgeNormal);
00822
00823 if (magEdgeNormal < maxSin)
00824 {
00825
00826 }
00827 else
00828 {
00829
00830 edgeNormal /= magEdgeNormal;
00831
00832 if ((edgeNormal & faceNormal) < SMALL)
00833 {
00834 if (faceI != errorFaceI)
00835 {
00836
00837 errorFaceI = faceI;
00838 nConcave++;
00839 }
00840
00841 if (setPtr)
00842 {
00843 setPtr->insert(faceI);
00844 }
00845
00846 maxEdgeSin = max(maxEdgeSin, magEdgeNormal);
00847 }
00848 }
00849 }
00850
00851 ePrev = e10;
00852 magEPrev = magE10;
00853 }
00854 }
00855
00856 reduce(nConcave, sumOp<label>());
00857 reduce(maxEdgeSin, maxOp<scalar>());
00858
00859 if (report)
00860 {
00861 if (maxEdgeSin > SMALL)
00862 {
00863 scalar maxConcaveDegr =
00864 Foam::asin(Foam::min(1.0, maxEdgeSin))
00865 * 180.0/mathematicalConstant::pi;
00866
00867 Info<< "There are " << nConcave
00868 << " faces with concave angles between consecutive"
00869 << " edges. Max concave angle = " << maxConcaveDegr
00870 << " degrees.\n" << endl;
00871 }
00872 else
00873 {
00874 Info<< "All angles in faces are convex or less than " << maxDeg
00875 << " degrees concave.\n" << endl;
00876 }
00877 }
00878
00879 if (nConcave > 0)
00880 {
00881 if (report)
00882 {
00883 WarningIn
00884 (
00885 "primitiveMeshGeometry::checkFaceAngles"
00886 "(const bool, const scalar, const pointField&"
00887 ", const labelList&, labelHashSet*)"
00888 ) << nConcave << " face points with severe concave angle (> "
00889 << maxDeg << " deg) found.\n"
00890 << endl;
00891 }
00892
00893 return true;
00894 }
00895 else
00896 {
00897 return false;
00898 }
00899 }
00900
00901
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042 bool Foam::primitiveMeshGeometry::checkFaceTwist
01043 (
01044 const bool report,
01045 const scalar minTwist,
01046 const primitiveMesh& mesh,
01047 const vectorField& faceAreas,
01048 const vectorField& faceCentres,
01049 const pointField& p,
01050 const labelList& checkFaces,
01051 labelHashSet* setPtr
01052 )
01053 {
01054 if (minTwist < -1-SMALL || minTwist > 1+SMALL)
01055 {
01056 FatalErrorIn
01057 (
01058 "primitiveMeshGeometry::checkFaceTwist"
01059 "(const bool, const scalar, const primitiveMesh&, const pointField&"
01060 ", const labelList&, labelHashSet*)"
01061 ) << "minTwist should be [-1..1] but is now " << minTwist
01062 << abort(FatalError);
01063 }
01064
01065
01066 const faceList& fcs = mesh.faces();
01067
01068
01069
01070
01071 label nWarped = 0;
01072
01073 forAll(checkFaces, i)
01074 {
01075 label faceI = checkFaces[i];
01076
01077 const face& f = fcs[faceI];
01078
01079 scalar magArea = mag(faceAreas[faceI]);
01080
01081 if (f.size() > 3 && magArea > VSMALL)
01082 {
01083 const vector nf = faceAreas[faceI] / magArea;
01084
01085 const point& fc = faceCentres[faceI];
01086
01087 forAll(f, fpI)
01088 {
01089 vector triArea
01090 (
01091 triPointRef
01092 (
01093 p[f[fpI]],
01094 p[f.nextLabel(fpI)],
01095 fc
01096 ).normal()
01097 );
01098
01099 scalar magTri = mag(triArea);
01100
01101 if (magTri > VSMALL && ((nf & triArea/magTri) < minTwist))
01102 {
01103 nWarped++;
01104
01105 if (setPtr)
01106 {
01107 setPtr->insert(faceI);
01108 }
01109 }
01110 }
01111 }
01112 }
01113
01114
01115 reduce(nWarped, sumOp<label>());
01116
01117 if (report)
01118 {
01119 if (nWarped> 0)
01120 {
01121 Info<< "There are " << nWarped
01122 << " faces with cosine of the angle"
01123 << " between triangle normal and face normal less than "
01124 << minTwist << nl << endl;
01125 }
01126 else
01127 {
01128 Info<< "All faces are flat in that the cosine of the angle"
01129 << " between triangle normal and face normal less than "
01130 << minTwist << nl << endl;
01131 }
01132 }
01133
01134 if (nWarped > 0)
01135 {
01136 if (report)
01137 {
01138 WarningIn
01139 (
01140 "primitiveMeshGeometry::checkFaceTwist"
01141 "(const bool, const scalar, const primitiveMesh&"
01142 ", const pointField&, const labelList&, labelHashSet*)"
01143 ) << nWarped << " faces with severe warpage "
01144 << "(cosine of the angle between triangle normal and face normal"
01145 << " < " << minTwist << ") found.\n"
01146 << endl;
01147 }
01148
01149 return true;
01150 }
01151 else
01152 {
01153 return false;
01154 }
01155 }
01156
01157
01158 bool Foam::primitiveMeshGeometry::checkFaceArea
01159 (
01160 const bool report,
01161 const scalar minArea,
01162 const primitiveMesh& mesh,
01163 const vectorField& faceAreas,
01164 const labelList& checkFaces,
01165 labelHashSet* setPtr
01166 )
01167 {
01168 label nZeroArea = 0;
01169
01170 forAll(checkFaces, i)
01171 {
01172 label faceI = checkFaces[i];
01173
01174 if (mag(faceAreas[faceI]) < minArea)
01175 {
01176 if (setPtr)
01177 {
01178 setPtr->insert(faceI);
01179 }
01180 nZeroArea++;
01181 }
01182 }
01183
01184
01185 reduce(nZeroArea, sumOp<label>());
01186
01187 if (report)
01188 {
01189 if (nZeroArea > 0)
01190 {
01191 Info<< "There are " << nZeroArea
01192 << " faces with area < " << minArea << '.' << nl << endl;
01193 }
01194 else
01195 {
01196 Info<< "All faces have area > " << minArea << '.' << nl << endl;
01197 }
01198 }
01199
01200 if (nZeroArea > 0)
01201 {
01202 if (report)
01203 {
01204 WarningIn
01205 (
01206 "primitiveMeshGeometry::checkFaceArea"
01207 "(const bool, const scalar, const primitiveMesh&"
01208 ", const pointField&, const labelList&, labelHashSet*)"
01209 ) << nZeroArea << " faces with area < " << minArea
01210 << " found.\n"
01211 << endl;
01212 }
01213
01214 return true;
01215 }
01216 else
01217 {
01218 return false;
01219 }
01220 }
01221
01222
01223 bool Foam::primitiveMeshGeometry::checkCellDeterminant
01224 (
01225 const bool report,
01226 const scalar warnDet,
01227 const primitiveMesh& mesh,
01228 const vectorField& faceAreas,
01229 const labelList& checkFaces,
01230 const labelList& affectedCells,
01231 labelHashSet* setPtr
01232 )
01233 {
01234 const cellList& cells = mesh.cells();
01235
01236 scalar minDet = GREAT;
01237 scalar sumDet = 0.0;
01238 label nSumDet = 0;
01239 label nWarnDet = 0;
01240
01241 forAll(affectedCells, i)
01242 {
01243 const cell& cFaces = cells[affectedCells[i]];
01244
01245 tensor areaSum(tensor::zero);
01246 scalar magAreaSum = 0;
01247
01248 forAll(cFaces, cFaceI)
01249 {
01250 label faceI = cFaces[cFaceI];
01251
01252 scalar magArea = mag(faceAreas[faceI]);
01253
01254 magAreaSum += magArea;
01255 areaSum += faceAreas[faceI]*(faceAreas[faceI]/magArea);
01256 }
01257
01258 scalar scaledDet = det(areaSum/magAreaSum)/0.037037037037037;
01259
01260 minDet = min(minDet, scaledDet);
01261 sumDet += scaledDet;
01262 nSumDet++;
01263
01264 if (scaledDet < warnDet)
01265 {
01266 if (setPtr)
01267 {
01268
01269 forAll(cFaces, cFaceI)
01270 {
01271 label faceI = cFaces[cFaceI];
01272 setPtr->insert(faceI);
01273 }
01274 }
01275 nWarnDet++;
01276 }
01277 }
01278
01279 reduce(minDet, minOp<scalar>());
01280 reduce(sumDet, sumOp<scalar>());
01281 reduce(nSumDet, sumOp<label>());
01282 reduce(nWarnDet, sumOp<label>());
01283
01284 if (report)
01285 {
01286 if (nSumDet > 0)
01287 {
01288 Info<< "Cell determinant (1 = uniform cube) : average = "
01289 << sumDet / nSumDet << " min = " << minDet << endl;
01290 }
01291
01292 if (nWarnDet > 0)
01293 {
01294 Info<< "There are " << nWarnDet
01295 << " cells with determinant < " << warnDet << '.' << nl
01296 << endl;
01297 }
01298 else
01299 {
01300 Info<< "All faces have determinant > " << warnDet << '.' << nl
01301 << endl;
01302 }
01303 }
01304
01305 if (nWarnDet > 0)
01306 {
01307 if (report)
01308 {
01309 WarningIn
01310 (
01311 "primitiveMeshGeometry::checkCellDeterminant"
01312 "(const bool, const scalar, const primitiveMesh&"
01313 ", const pointField&, const labelList&, const labelList&"
01314 ", labelHashSet*)"
01315 ) << nWarnDet << " cells with determinant < " << warnDet
01316 << " found.\n"
01317 << endl;
01318 }
01319
01320 return true;
01321 }
01322 else
01323 {
01324 return false;
01325 }
01326 }
01327
01328
01329 bool Foam::primitiveMeshGeometry::checkFaceDotProduct
01330 (
01331 const bool report,
01332 const scalar orthWarn,
01333 const labelList& checkFaces,
01334 labelHashSet* setPtr
01335 ) const
01336 {
01337 return checkFaceDotProduct
01338 (
01339 report,
01340 orthWarn,
01341 mesh_,
01342 cellCentres_,
01343 faceAreas_,
01344 checkFaces,
01345 setPtr
01346 );
01347 }
01348
01349
01350 bool Foam::primitiveMeshGeometry::checkFacePyramids
01351 (
01352 const bool report,
01353 const scalar minPyrVol,
01354 const pointField& p,
01355 const labelList& checkFaces,
01356 labelHashSet* setPtr
01357 ) const
01358 {
01359 return checkFacePyramids
01360 (
01361 report,
01362 minPyrVol,
01363 mesh_,
01364 cellCentres_,
01365 p,
01366 checkFaces,
01367 setPtr
01368 );
01369 }
01370
01371
01372 bool Foam::primitiveMeshGeometry::checkFaceSkewness
01373 (
01374 const bool report,
01375 const scalar internalSkew,
01376 const scalar boundarySkew,
01377 const labelList& checkFaces,
01378 labelHashSet* setPtr
01379 ) const
01380 {
01381 return checkFaceSkewness
01382 (
01383 report,
01384 internalSkew,
01385 boundarySkew,
01386 mesh_,
01387 cellCentres_,
01388 faceCentres_,
01389 faceAreas_,
01390 checkFaces,
01391 setPtr
01392 );
01393 }
01394
01395
01396 bool Foam::primitiveMeshGeometry::checkFaceWeights
01397 (
01398 const bool report,
01399 const scalar warnWeight,
01400 const labelList& checkFaces,
01401 labelHashSet* setPtr
01402 ) const
01403 {
01404 return checkFaceWeights
01405 (
01406 report,
01407 warnWeight,
01408 mesh_,
01409 cellCentres_,
01410 faceCentres_,
01411 faceAreas_,
01412 checkFaces,
01413 setPtr
01414 );
01415 }
01416
01417
01418 bool Foam::primitiveMeshGeometry::checkFaceAngles
01419 (
01420 const bool report,
01421 const scalar maxDeg,
01422 const pointField& p,
01423 const labelList& checkFaces,
01424 labelHashSet* setPtr
01425 ) const
01426 {
01427 return checkFaceAngles
01428 (
01429 report,
01430 maxDeg,
01431 mesh_,
01432 faceAreas_,
01433 p,
01434 checkFaces,
01435 setPtr
01436 );
01437 }
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463 bool Foam::primitiveMeshGeometry::checkFaceTwist
01464 (
01465 const bool report,
01466 const scalar minTwist,
01467 const pointField& p,
01468 const labelList& checkFaces,
01469 labelHashSet* setPtr
01470 ) const
01471 {
01472 return checkFaceTwist
01473 (
01474 report,
01475 minTwist,
01476 mesh_,
01477 faceAreas_,
01478 faceCentres_,
01479 p,
01480 checkFaces,
01481 setPtr
01482 );
01483 }
01484
01485
01486 bool Foam::primitiveMeshGeometry::checkFaceArea
01487 (
01488 const bool report,
01489 const scalar minArea,
01490 const labelList& checkFaces,
01491 labelHashSet* setPtr
01492 ) const
01493 {
01494 return checkFaceArea
01495 (
01496 report,
01497 minArea,
01498 mesh_,
01499 faceAreas_,
01500 checkFaces,
01501 setPtr
01502 );
01503 }
01504
01505
01506 bool Foam::primitiveMeshGeometry::checkCellDeterminant
01507 (
01508 const bool report,
01509 const scalar warnDet,
01510 const labelList& checkFaces,
01511 const labelList& affectedCells,
01512 labelHashSet* setPtr
01513 ) const
01514 {
01515 return checkCellDeterminant
01516 (
01517 report,
01518 warnDet,
01519 mesh_,
01520 faceAreas_,
01521 checkFaces,
01522 affectedCells,
01523 setPtr
01524 );
01525 }
01526
01527
01528