1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "motionSmoother.H"
28 #include "polyMeshGeometry.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
44 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
46 bool Foam::motionSmoother::checkMesh
50 const dictionary& dict,
51 const labelList& checkFaces,
52 labelHashSet& wrongFaces
55 List<labelPair> emptyBaffles;
67 bool Foam::motionSmoother::checkMesh
71 const dictionary& dict,
72 const labelList& checkFaces,
73 const List<labelPair>& baffles,
74 labelHashSet& wrongFaces
77 const scalar maxNonOrtho(readScalar(dict.lookup("maxNonOrtho")));
78 const scalar minVol(readScalar(dict.lookup("minVol")));
79 const scalar maxConcave(readScalar(dict.lookup("maxConcave")));
80 const scalar minArea(readScalar(dict.lookup("minArea")));
81 const scalar maxIntSkew(readScalar(dict.lookup("maxInternalSkewness")));
82 const scalar maxBounSkew(readScalar(dict.lookup("maxBoundarySkewness")));
83 const scalar minWeight(readScalar(dict.lookup("minFaceWeight")));
84 const scalar minVolRatio(readScalar(dict.lookup("minVolRatio")));
85 const scalar minTwist(readScalar(dict.lookup("minTwist")));
86 const scalar minTriangleTwist(readScalar(dict.lookup("minTriangleTwist")));
87 const scalar minDet(readScalar(dict.lookup("minDeterminant")));
89 label nWrongFaces = 0;
91 Info<< "Checking faces in error :" << endl;
92 //Pout.setf(ios_base::left);
94 if (maxNonOrtho < 180.0-SMALL)
96 polyMeshGeometry::checkFaceDotProduct
108 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
110 Info<< " non-orthogonality > "
111 << setw(3) << maxNonOrtho
113 << nNewWrongFaces-nWrongFaces << endl;
115 nWrongFaces = nNewWrongFaces;
120 polyMeshGeometry::checkFacePyramids
132 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
134 Info<< " faces with face pyramid volume < "
135 << setw(5) << minVol << " : "
136 << nNewWrongFaces-nWrongFaces << endl;
138 nWrongFaces = nNewWrongFaces;
141 if (maxConcave < 180.0-SMALL)
143 polyMeshGeometry::checkFaceAngles
154 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
156 Info<< " faces with concavity > "
157 << setw(3) << maxConcave
159 << nNewWrongFaces-nWrongFaces << endl;
161 nWrongFaces = nNewWrongFaces;
164 if (minArea > -SMALL)
166 polyMeshGeometry::checkFaceArea
176 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
178 Info<< " faces with area < "
179 << setw(5) << minArea
181 << nNewWrongFaces-nWrongFaces << endl;
183 nWrongFaces = nNewWrongFaces;
186 if (maxIntSkew > 0 || maxBounSkew > 0)
188 polyMeshGeometry::checkFaceSkewness
202 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
204 Info<< " faces with skewness > "
205 << setw(3) << maxIntSkew
206 << " (internal) or " << setw(3) << maxBounSkew
207 << " (boundary) : " << nNewWrongFaces-nWrongFaces << endl;
209 nWrongFaces = nNewWrongFaces;
212 if (minWeight >= 0 && minWeight < 1)
214 polyMeshGeometry::checkFaceWeights
227 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
229 Info<< " faces with interpolation weights (0..1) < "
230 << setw(5) << minWeight
232 << nNewWrongFaces-nWrongFaces << endl;
234 nWrongFaces = nNewWrongFaces;
237 if (minVolRatio >= 0)
239 polyMeshGeometry::checkVolRatio
250 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
252 Info<< " faces with volume ratio of neighbour cells < "
253 << setw(5) << minVolRatio
255 << nNewWrongFaces-nWrongFaces << endl;
257 nWrongFaces = nNewWrongFaces;
262 //Pout<< "Checking face twist: dot product of face normal "
263 // << "with face triangle normals" << endl;
264 polyMeshGeometry::checkFaceTwist
277 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
279 Info<< " faces with face twist < "
280 << setw(5) << minTwist
282 << nNewWrongFaces-nWrongFaces << endl;
284 nWrongFaces = nNewWrongFaces;
287 if (minTriangleTwist > -1)
289 //Pout<< "Checking triangle twist: dot product of consecutive triangle"
290 // << " normals resulting from face-centre decomposition" << endl;
291 polyMeshGeometry::checkTriangleTwist
303 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
305 Info<< " faces with triangle twist < "
306 << setw(5) << minTriangleTwist
308 << nNewWrongFaces-nWrongFaces << endl;
310 nWrongFaces = nNewWrongFaces;
315 polyMeshGeometry::checkCellDeterminant
322 polyMeshGeometry::affectedCells(mesh, checkFaces),
326 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
328 Info<< " faces on cells with determinant < "
329 << setw(5) << minDet << " : "
330 << nNewWrongFaces-nWrongFaces << endl;
332 nWrongFaces = nNewWrongFaces;
335 //Pout.setf(ios_base::right);
337 return nWrongFaces > 0;
341 bool Foam::motionSmoother::checkMesh
344 const polyMesh& mesh,
345 const dictionary& dict,
346 labelHashSet& wrongFaces
354 identity(mesh.nFaces()),
359 bool Foam::motionSmoother::checkMesh
362 const dictionary& dict,
363 const polyMeshGeometry& meshGeom,
364 const labelList& checkFaces,
365 labelHashSet& wrongFaces
368 List<labelPair> emptyBaffles;
382 bool Foam::motionSmoother::checkMesh
385 const dictionary& dict,
386 const polyMeshGeometry& meshGeom,
387 const labelList& checkFaces,
388 const List<labelPair>& baffles,
389 labelHashSet& wrongFaces
392 const scalar maxNonOrtho(readScalar(dict.lookup("maxNonOrtho")));
393 const scalar minVol(readScalar(dict.lookup("minVol")));
394 const scalar maxConcave(readScalar(dict.lookup("maxConcave")));
395 const scalar minArea(readScalar(dict.lookup("minArea")));
396 const scalar maxIntSkew(readScalar(dict.lookup("maxInternalSkewness")));
397 const scalar maxBounSkew(readScalar(dict.lookup("maxBoundarySkewness")));
398 const scalar minWeight(readScalar(dict.lookup("minFaceWeight")));
399 const scalar minVolRatio(readScalar(dict.lookup("minVolRatio")));
400 const scalar minTwist(readScalar(dict.lookup("minTwist")));
401 const scalar minTriangleTwist(readScalar(dict.lookup("minTriangleTwist")));
402 const scalar minDet(readScalar(dict.lookup("minDeterminant")));
404 label nWrongFaces = 0;
406 Info<< "Checking faces in error :" << endl;
407 //Pout.setf(ios_base::left);
409 if (maxNonOrtho < 180.0-SMALL)
411 meshGeom.checkFaceDotProduct
420 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
422 Info<< " non-orthogonality > "
423 << setw(3) << maxNonOrtho
425 << nNewWrongFaces-nWrongFaces << endl;
427 nWrongFaces = nNewWrongFaces;
432 meshGeom.checkFacePyramids
436 meshGeom.mesh().points(),
442 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
444 Info<< " faces with face pyramid volume < "
445 << setw(5) << minVol << " : "
446 << nNewWrongFaces-nWrongFaces << endl;
448 nWrongFaces = nNewWrongFaces;
451 if (maxConcave < 180.0-SMALL)
453 meshGeom.checkFaceAngles
457 meshGeom.mesh().points(),
462 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
464 Info<< " faces with concavity > "
465 << setw(3) << maxConcave
467 << nNewWrongFaces-nWrongFaces << endl;
469 nWrongFaces = nNewWrongFaces;
472 if (minArea > -SMALL)
474 meshGeom.checkFaceArea(report, minArea, checkFaces, &wrongFaces);
476 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
478 Info<< " faces with area < "
479 << setw(5) << minArea
481 << nNewWrongFaces-nWrongFaces << endl;
483 nWrongFaces = nNewWrongFaces;
486 if (maxIntSkew > 0 || maxBounSkew > 0)
488 meshGeom.checkFaceSkewness
498 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
500 Info<< " faces with skewness > "
501 << setw(3) << maxIntSkew
502 << " (internal) or " << setw(3) << maxBounSkew
503 << " (boundary) : " << nNewWrongFaces-nWrongFaces << endl;
505 nWrongFaces = nNewWrongFaces;
508 if (minWeight >= 0 && minWeight < 1)
510 meshGeom.checkFaceWeights
519 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
521 Info<< " faces with interpolation weights (0..1) < "
522 << setw(5) << minWeight
524 << nNewWrongFaces-nWrongFaces << endl;
526 nWrongFaces = nNewWrongFaces;
529 if (minVolRatio >= 0)
531 meshGeom.checkVolRatio
540 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
542 Info<< " faces with volume ratio of neighbour cells < "
543 << setw(5) << minVolRatio
545 << nNewWrongFaces-nWrongFaces << endl;
547 nWrongFaces = nNewWrongFaces;
552 //Pout<< "Checking face twist: dot product of face normal "
553 // << "with face triangle normals" << endl;
554 meshGeom.checkFaceTwist
558 meshGeom.mesh().points(),
563 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
565 Info<< " faces with face twist < "
566 << setw(5) << minTwist
568 << nNewWrongFaces-nWrongFaces << endl;
570 nWrongFaces = nNewWrongFaces;
573 if (minTriangleTwist > -1)
575 //Pout<< "Checking triangle twist: dot product of consecutive triangle"
576 // << " normals resulting from face-centre decomposition" << endl;
577 meshGeom.checkTriangleTwist
581 meshGeom.mesh().points(),
586 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
588 Info<< " faces with triangle twist < "
589 << setw(5) << minTriangleTwist
591 << nNewWrongFaces-nWrongFaces << endl;
593 nWrongFaces = nNewWrongFaces;
598 meshGeom.checkCellDeterminant
603 meshGeom.affectedCells(meshGeom.mesh(), checkFaces),
607 label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
609 Info<< " faces on cells with determinant < "
610 << setw(5) << minDet << " : "
611 << nNewWrongFaces-nWrongFaces << endl;
613 nWrongFaces = nNewWrongFaces;
616 //Pout.setf(ios_base::right);
618 return nWrongFaces > 0;
622 // ************************************************************************* //