1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "motionSmoother.H"
27 #include "polyMeshGeometry.H"
30 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
32 bool Foam::motionSmoother::checkMesh
36 const dictionary& dict,
37 const labelList& checkFaces,
38 labelHashSet& wrongFaces
41 List<labelPair> emptyBaffles;
53 bool Foam::motionSmoother::checkMesh
57 const dictionary& dict,
58 const labelList& checkFaces,
59 const List<labelPair>& baffles,
60 labelHashSet& wrongFaces
63 const scalar maxNonOrtho
65 readScalar(dict.lookup("maxNonOrtho", true))
69 readScalar(dict.lookup("minVol", true))
71 const scalar minTetQuality
73 readScalar(dict.lookup("minTetQuality", true))
75 const scalar maxConcave
77 readScalar(dict.lookup("maxConcave", true))
81 readScalar(dict.lookup("minArea", true))
83 const scalar maxIntSkew
85 readScalar(dict.lookup("maxInternalSkewness", true))
87 const scalar maxBounSkew
89 readScalar(dict.lookup("maxBoundarySkewness", true))
91 const scalar minWeight
93 readScalar(dict.lookup("minFaceWeight", true))
95 const scalar minVolRatio
97 readScalar(dict.lookup("minVolRatio", true))
101 readScalar(dict.lookup("minTwist", true))
103 const scalar minTriangleTwist
105 readScalar(dict.lookup("minTriangleTwist", true))
109 readScalar(dict.lookup("minDeterminant", true))
111 label nWrongFaces = 0;
113 Info<< "Checking faces in error :" << endl;
114 //Pout.setf(ios_base::left);
116 if (maxNonOrtho < 180.0-SMALL)
118 polyMeshGeometry::checkFaceDotProduct
130 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
132 Info<< " non-orthogonality > "
133 << setw(3) << maxNonOrtho
135 << nNewWrongFaces-nWrongFaces << endl;
137 nWrongFaces = nNewWrongFaces;
142 polyMeshGeometry::checkFacePyramids
154 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
156 Info<< " faces with face pyramid volume < "
157 << setw(5) << minVol << " : "
158 << nNewWrongFaces-nWrongFaces << endl;
160 nWrongFaces = nNewWrongFaces;
163 if (minTetQuality > -GREAT)
165 polyMeshGeometry::checkFaceTets
178 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
180 Info<< " faces with face-decomposition tet quality < "
181 << setw(5) << minTetQuality << " : "
182 << nNewWrongFaces-nWrongFaces << endl;
184 nWrongFaces = nNewWrongFaces;
187 if (maxConcave < 180.0-SMALL)
189 polyMeshGeometry::checkFaceAngles
200 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
202 Info<< " faces with concavity > "
203 << setw(3) << maxConcave
205 << nNewWrongFaces-nWrongFaces << endl;
207 nWrongFaces = nNewWrongFaces;
210 if (minArea > -SMALL)
212 polyMeshGeometry::checkFaceArea
222 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
224 Info<< " faces with area < "
225 << setw(5) << minArea
227 << nNewWrongFaces-nWrongFaces << endl;
229 nWrongFaces = nNewWrongFaces;
232 if (maxIntSkew > 0 || maxBounSkew > 0)
234 polyMeshGeometry::checkFaceSkewness
248 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
250 Info<< " faces with skewness > "
251 << setw(3) << maxIntSkew
252 << " (internal) or " << setw(3) << maxBounSkew
253 << " (boundary) : " << nNewWrongFaces-nWrongFaces << endl;
255 nWrongFaces = nNewWrongFaces;
258 if (minWeight >= 0 && minWeight < 1)
260 polyMeshGeometry::checkFaceWeights
273 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
275 Info<< " faces with interpolation weights (0..1) < "
276 << setw(5) << minWeight
278 << nNewWrongFaces-nWrongFaces << endl;
280 nWrongFaces = nNewWrongFaces;
283 if (minVolRatio >= 0)
285 polyMeshGeometry::checkVolRatio
296 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
298 Info<< " faces with volume ratio of neighbour cells < "
299 << setw(5) << minVolRatio
301 << nNewWrongFaces-nWrongFaces << endl;
303 nWrongFaces = nNewWrongFaces;
308 //Pout<< "Checking face twist: dot product of face normal "
309 // << "with face triangle normals" << endl;
310 polyMeshGeometry::checkFaceTwist
323 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
325 Info<< " faces with face twist < "
326 << setw(5) << minTwist
328 << nNewWrongFaces-nWrongFaces << endl;
330 nWrongFaces = nNewWrongFaces;
333 if (minTriangleTwist > -1)
335 //Pout<< "Checking triangle twist: dot product of consecutive triangle"
336 // << " normals resulting from face-centre decomposition" << endl;
337 polyMeshGeometry::checkTriangleTwist
349 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
351 Info<< " faces with triangle twist < "
352 << setw(5) << minTriangleTwist
354 << nNewWrongFaces-nWrongFaces << endl;
356 nWrongFaces = nNewWrongFaces;
361 polyMeshGeometry::checkCellDeterminant
368 polyMeshGeometry::affectedCells(mesh, checkFaces),
372 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
374 Info<< " faces on cells with determinant < "
375 << setw(5) << minDet << " : "
376 << nNewWrongFaces-nWrongFaces << endl;
378 nWrongFaces = nNewWrongFaces;
381 //Pout.setf(ios_base::right);
383 return nWrongFaces > 0;
387 bool Foam::motionSmoother::checkMesh
390 const polyMesh& mesh,
391 const dictionary& dict,
392 labelHashSet& wrongFaces
400 identity(mesh.nFaces()),
405 bool Foam::motionSmoother::checkMesh
408 const dictionary& dict,
409 const polyMeshGeometry& meshGeom,
410 const labelList& checkFaces,
411 labelHashSet& wrongFaces
414 List<labelPair> emptyBaffles;
428 bool Foam::motionSmoother::checkMesh
431 const dictionary& dict,
432 const polyMeshGeometry& meshGeom,
433 const labelList& checkFaces,
434 const List<labelPair>& baffles,
435 labelHashSet& wrongFaces
438 const scalar maxNonOrtho
440 readScalar(dict.lookup("maxNonOrtho", true))
444 readScalar(dict.lookup("minVol", true))
446 const scalar minTetQuality
448 readScalar(dict.lookup("minTetQuality", true))
450 const scalar maxConcave
452 readScalar(dict.lookup("maxConcave", true))
456 readScalar(dict.lookup("minArea", true))
458 const scalar maxIntSkew
460 readScalar(dict.lookup("maxInternalSkewness", true))
462 const scalar maxBounSkew
464 readScalar(dict.lookup("maxBoundarySkewness", true))
466 const scalar minWeight
468 readScalar(dict.lookup("minFaceWeight", true))
470 const scalar minVolRatio
472 readScalar(dict.lookup("minVolRatio", true))
474 const scalar minTwist
476 readScalar(dict.lookup("minTwist", true))
478 const scalar minTriangleTwist
480 readScalar(dict.lookup("minTriangleTwist", true))
484 readScalar(dict.lookup("minDeterminant", true))
487 label nWrongFaces = 0;
489 Info<< "Checking faces in error :" << endl;
490 //Pout.setf(ios_base::left);
492 if (maxNonOrtho < 180.0-SMALL)
494 meshGeom.checkFaceDotProduct
503 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
505 Info<< " non-orthogonality > "
506 << setw(3) << maxNonOrtho
508 << nNewWrongFaces-nWrongFaces << endl;
510 nWrongFaces = nNewWrongFaces;
515 meshGeom.checkFacePyramids
519 meshGeom.mesh().points(),
525 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
527 Info<< " faces with face pyramid volume < "
528 << setw(5) << minVol << " : "
529 << nNewWrongFaces-nWrongFaces << endl;
531 nWrongFaces = nNewWrongFaces;
534 if (minTetQuality > -GREAT)
536 meshGeom.checkFaceTets
540 meshGeom.mesh().points(),
546 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
548 Info<< " faces with face-decomposition tet quality < "
549 << setw(5) << minTetQuality << " : "
550 << nNewWrongFaces-nWrongFaces << endl;
552 nWrongFaces = nNewWrongFaces;
555 if (maxConcave < 180.0-SMALL)
557 meshGeom.checkFaceAngles
561 meshGeom.mesh().points(),
566 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
568 Info<< " faces with concavity > "
569 << setw(3) << maxConcave
571 << nNewWrongFaces-nWrongFaces << endl;
573 nWrongFaces = nNewWrongFaces;
576 if (minArea > -SMALL)
578 meshGeom.checkFaceArea(report, minArea, checkFaces, &wrongFaces);
580 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
582 Info<< " faces with area < "
583 << setw(5) << minArea
585 << nNewWrongFaces-nWrongFaces << endl;
587 nWrongFaces = nNewWrongFaces;
590 if (maxIntSkew > 0 || maxBounSkew > 0)
592 meshGeom.checkFaceSkewness
602 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
604 Info<< " faces with skewness > "
605 << setw(3) << maxIntSkew
606 << " (internal) or " << setw(3) << maxBounSkew
607 << " (boundary) : " << nNewWrongFaces-nWrongFaces << endl;
609 nWrongFaces = nNewWrongFaces;
612 if (minWeight >= 0 && minWeight < 1)
614 meshGeom.checkFaceWeights
623 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
625 Info<< " faces with interpolation weights (0..1) < "
626 << setw(5) << minWeight
628 << nNewWrongFaces-nWrongFaces << endl;
630 nWrongFaces = nNewWrongFaces;
633 if (minVolRatio >= 0)
635 meshGeom.checkVolRatio
644 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
646 Info<< " faces with volume ratio of neighbour cells < "
647 << setw(5) << minVolRatio
649 << nNewWrongFaces-nWrongFaces << endl;
651 nWrongFaces = nNewWrongFaces;
656 //Pout<< "Checking face twist: dot product of face normal "
657 // << "with face triangle normals" << endl;
658 meshGeom.checkFaceTwist
662 meshGeom.mesh().points(),
667 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
669 Info<< " faces with face twist < "
670 << setw(5) << minTwist
672 << nNewWrongFaces-nWrongFaces << endl;
674 nWrongFaces = nNewWrongFaces;
677 if (minTriangleTwist > -1)
679 //Pout<< "Checking triangle twist: dot product of consecutive triangle"
680 // << " normals resulting from face-centre decomposition" << endl;
681 meshGeom.checkTriangleTwist
685 meshGeom.mesh().points(),
690 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
692 Info<< " faces with triangle twist < "
693 << setw(5) << minTriangleTwist
695 << nNewWrongFaces-nWrongFaces << endl;
697 nWrongFaces = nNewWrongFaces;
702 meshGeom.checkCellDeterminant
707 meshGeom.affectedCells(meshGeom.mesh(), checkFaces),
711 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
713 Info<< " faces on cells with determinant < "
714 << setw(5) << minDet << " : "
715 << nNewWrongFaces-nWrongFaces << endl;
717 nWrongFaces = nNewWrongFaces;
720 //Pout.setf(ios_base::right);
722 return nWrongFaces > 0;
726 // ************************************************************************* //