FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

motionSmootherCheck.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "motionSmoother.H"
00027 #include <dynamicMesh/polyMeshGeometry.H>
00028 #include <OpenFOAM/IOmanip.H>
00029 
00030 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00031 
00032 bool Foam::motionSmoother::checkMesh
00033 (
00034     const bool report,
00035     const polyMesh& mesh,
00036     const dictionary& dict,
00037     const labelList& checkFaces,
00038     labelHashSet& wrongFaces
00039 )
00040 {
00041     List<labelPair> emptyBaffles;
00042     return checkMesh
00043     (
00044         report,
00045         mesh,
00046         dict,
00047         checkFaces,
00048         emptyBaffles,
00049         wrongFaces
00050     );
00051 }
00052 
00053 bool Foam::motionSmoother::checkMesh
00054 (
00055     const bool report,
00056     const polyMesh& mesh,
00057     const dictionary& dict,
00058     const labelList& checkFaces,
00059     const List<labelPair>& baffles,
00060     labelHashSet& wrongFaces
00061 )
00062 {
00063     const scalar maxNonOrtho
00064     (
00065         readScalar(dict.lookup("maxNonOrtho", true))
00066     );
00067     const scalar minVol
00068     (
00069         readScalar(dict.lookup("minVol", true))
00070     );
00071     const scalar maxConcave
00072     (
00073         readScalar(dict.lookup("maxConcave", true))
00074     );
00075     const scalar minArea
00076     (
00077         readScalar(dict.lookup("minArea", true))
00078     );
00079     const scalar maxIntSkew
00080     (
00081         readScalar(dict.lookup("maxInternalSkewness", true))
00082     );
00083     const scalar maxBounSkew
00084     (
00085         readScalar(dict.lookup("maxBoundarySkewness", true))
00086     );
00087     const scalar minWeight
00088     (
00089         readScalar(dict.lookup("minFaceWeight", true))
00090     );
00091     const scalar minVolRatio
00092     (
00093         readScalar(dict.lookup("minVolRatio", true))
00094     );
00095     const scalar minTwist
00096     (
00097         readScalar(dict.lookup("minTwist", true))
00098     );
00099     const scalar minTriangleTwist
00100     (
00101         readScalar(dict.lookup("minTriangleTwist", true))
00102     );
00103     const scalar minDet
00104     (
00105         readScalar(dict.lookup("minDeterminant", true))
00106     );
00107 
00108     label nWrongFaces = 0;
00109 
00110     Info<< "Checking faces in error :" << endl;
00111     //Pout.setf(ios_base::left);
00112 
00113     if (maxNonOrtho < 180.0-SMALL)
00114     {
00115         polyMeshGeometry::checkFaceDotProduct
00116         (
00117             report,
00118             maxNonOrtho,
00119             mesh,
00120             mesh.cellCentres(),
00121             mesh.faceAreas(),
00122             checkFaces,
00123             baffles,
00124             &wrongFaces
00125         );
00126 
00127         label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
00128 
00129         Info<< "    non-orthogonality > "
00130             << setw(3) << maxNonOrtho
00131             << " degrees                        : "
00132             << nNewWrongFaces-nWrongFaces << endl;
00133 
00134         nWrongFaces = nNewWrongFaces;
00135     }
00136 
00137     if (minVol > -GREAT)
00138     {
00139         polyMeshGeometry::checkFacePyramids
00140         (
00141             report,
00142             minVol,
00143             mesh,
00144             mesh.cellCentres(),
00145             mesh.points(),
00146             checkFaces,
00147             baffles,
00148             &wrongFaces
00149         );
00150 
00151         label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
00152 
00153         Info<< "    faces with face pyramid volume < "
00154             << setw(5) << minVol << "                 : "
00155             << nNewWrongFaces-nWrongFaces << endl;
00156 
00157         nWrongFaces = nNewWrongFaces;
00158     }
00159 
00160     if (maxConcave < 180.0-SMALL)
00161     {
00162         polyMeshGeometry::checkFaceAngles
00163         (
00164             report,
00165             maxConcave,
00166             mesh,
00167             mesh.faceAreas(),
00168             mesh.points(),
00169             checkFaces,
00170             &wrongFaces
00171         );
00172 
00173         label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
00174 
00175         Info<< "    faces with concavity > "
00176             << setw(3) << maxConcave
00177             << " degrees                     : "
00178             << nNewWrongFaces-nWrongFaces << endl;
00179 
00180         nWrongFaces = nNewWrongFaces;
00181     }
00182 
00183     if (minArea > -SMALL)
00184     {
00185         polyMeshGeometry::checkFaceArea
00186         (
00187             report,
00188             minArea,
00189             mesh,
00190             mesh.faceAreas(),
00191             checkFaces,
00192             &wrongFaces
00193         );
00194 
00195         label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
00196 
00197         Info<< "    faces with area < "
00198             << setw(5) << minArea
00199             << " m^2                            : "
00200             << nNewWrongFaces-nWrongFaces << endl;
00201 
00202         nWrongFaces = nNewWrongFaces;
00203     }
00204 
00205     if (maxIntSkew > 0 || maxBounSkew > 0)
00206     {
00207         polyMeshGeometry::checkFaceSkewness
00208         (
00209             report,
00210             maxIntSkew,
00211             maxBounSkew,
00212             mesh,
00213             mesh.cellCentres(),
00214             mesh.faceCentres(),
00215             mesh.faceAreas(),
00216             checkFaces,
00217             baffles,
00218             &wrongFaces
00219         );
00220 
00221         label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
00222 
00223         Info<< "    faces with skewness > "
00224             << setw(3) << maxIntSkew
00225             << " (internal) or " << setw(3) << maxBounSkew
00226             << " (boundary) : " << nNewWrongFaces-nWrongFaces << endl;
00227 
00228         nWrongFaces = nNewWrongFaces;
00229     }
00230 
00231     if (minWeight >= 0 && minWeight < 1)
00232     {
00233         polyMeshGeometry::checkFaceWeights
00234         (
00235             report,
00236             minWeight,
00237             mesh,
00238             mesh.cellCentres(),
00239             mesh.faceCentres(),
00240             mesh.faceAreas(),
00241             checkFaces,
00242             baffles,
00243             &wrongFaces
00244         );
00245 
00246         label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
00247 
00248         Info<< "    faces with interpolation weights (0..1)  < "
00249             << setw(5) << minWeight
00250             << "       : "
00251             << nNewWrongFaces-nWrongFaces << endl;
00252 
00253         nWrongFaces = nNewWrongFaces;
00254     }
00255 
00256     if (minVolRatio >= 0)
00257     {
00258         polyMeshGeometry::checkVolRatio
00259         (
00260             report,
00261             minVolRatio,
00262             mesh,
00263             mesh.cellVolumes(),
00264             checkFaces,
00265             baffles,
00266             &wrongFaces
00267         );
00268 
00269         label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
00270 
00271         Info<< "    faces with volume ratio of neighbour cells < "
00272             << setw(5) << minVolRatio
00273             << "     : "
00274             << nNewWrongFaces-nWrongFaces << endl;
00275 
00276         nWrongFaces = nNewWrongFaces;
00277     }
00278 
00279     if (minTwist > -1)
00280     {
00281         //Pout<< "Checking face twist: dot product of face normal "
00282         //    << "with face triangle normals" << endl;
00283         polyMeshGeometry::checkFaceTwist
00284         (
00285             report,
00286             minTwist,
00287             mesh,
00288             mesh.cellCentres(),
00289             mesh.faceAreas(),
00290             mesh.faceCentres(),
00291             mesh.points(),
00292             checkFaces,
00293             &wrongFaces
00294         );
00295 
00296         label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
00297 
00298         Info<< "    faces with face twist < "
00299             << setw(5) << minTwist
00300             << "                          : "
00301             << nNewWrongFaces-nWrongFaces << endl;
00302 
00303         nWrongFaces = nNewWrongFaces;
00304     }
00305 
00306     if (minTriangleTwist > -1)
00307     {
00308         //Pout<< "Checking triangle twist: dot product of consecutive triangle"
00309         //    << " normals resulting from face-centre decomposition" << endl;
00310         polyMeshGeometry::checkTriangleTwist
00311         (
00312             report,
00313             minTriangleTwist,
00314             mesh,
00315             mesh.faceAreas(),
00316             mesh.faceCentres(),
00317             mesh.points(),
00318             checkFaces,
00319             &wrongFaces
00320         );
00321 
00322         label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
00323 
00324         Info<< "    faces with triangle twist < "
00325             << setw(5) << minTriangleTwist
00326             << "                      : "
00327             << nNewWrongFaces-nWrongFaces << endl;
00328 
00329         nWrongFaces = nNewWrongFaces;
00330     }
00331 
00332     if (minDet > -1)
00333     {
00334         polyMeshGeometry::checkCellDeterminant
00335         (
00336             report,
00337             minDet,
00338             mesh,
00339             mesh.faceAreas(),
00340             checkFaces,
00341             polyMeshGeometry::affectedCells(mesh, checkFaces),
00342             &wrongFaces
00343         );
00344 
00345         label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
00346 
00347         Info<< "    faces on cells with determinant < "
00348             << setw(5) << minDet << "                : "
00349             << nNewWrongFaces-nWrongFaces << endl;
00350 
00351         nWrongFaces = nNewWrongFaces;
00352     }
00353 
00354     //Pout.setf(ios_base::right);
00355 
00356     return nWrongFaces > 0;
00357 }
00358 
00359 
00360 bool Foam::motionSmoother::checkMesh
00361 (
00362     const bool report,
00363     const polyMesh& mesh,
00364     const dictionary& dict,
00365     labelHashSet& wrongFaces
00366 )
00367 {
00368     return checkMesh
00369     (
00370         report,
00371         mesh,
00372         dict,
00373         identity(mesh.nFaces()),
00374         wrongFaces
00375     );
00376 }
00377 
00378 bool Foam::motionSmoother::checkMesh
00379 (
00380     const bool report,
00381     const dictionary& dict,
00382     const polyMeshGeometry& meshGeom,
00383     const labelList& checkFaces,
00384     labelHashSet& wrongFaces
00385 )
00386 {
00387     List<labelPair> emptyBaffles;
00388 
00389     return checkMesh
00390     (
00391         report,
00392         dict,
00393         meshGeom,
00394         checkFaces,
00395         emptyBaffles,
00396         wrongFaces
00397      );
00398 }
00399 
00400 
00401 bool Foam::motionSmoother::checkMesh
00402 (
00403     const bool report,
00404     const dictionary& dict,
00405     const polyMeshGeometry& meshGeom,
00406     const labelList& checkFaces,
00407     const List<labelPair>& baffles,
00408     labelHashSet& wrongFaces
00409 )
00410 {
00411     const scalar maxNonOrtho
00412     (
00413         readScalar(dict.lookup("maxNonOrtho", true))
00414     );
00415     const scalar minVol
00416     (
00417         readScalar(dict.lookup("minVol", true))
00418     );
00419     const scalar maxConcave
00420     (
00421         readScalar(dict.lookup("maxConcave", true))
00422     );
00423     const scalar minArea
00424     (
00425         readScalar(dict.lookup("minArea", true))
00426     );
00427     const scalar maxIntSkew
00428     (
00429         readScalar(dict.lookup("maxInternalSkewness", true))
00430     );
00431     const scalar maxBounSkew
00432     (
00433         readScalar(dict.lookup("maxBoundarySkewness", true))
00434     );
00435     const scalar minWeight
00436     (
00437         readScalar(dict.lookup("minFaceWeight", true))
00438     );
00439     const scalar minVolRatio
00440     (
00441         readScalar(dict.lookup("minVolRatio", true))
00442     );
00443     const scalar minTwist
00444     (
00445         readScalar(dict.lookup("minTwist", true))
00446     );
00447     const scalar minTriangleTwist
00448     (
00449         readScalar(dict.lookup("minTriangleTwist", true))
00450     );
00451     const scalar minDet
00452     (
00453         readScalar(dict.lookup("minDeterminant", true))
00454     );
00455 
00456     label nWrongFaces = 0;
00457 
00458     Info<< "Checking faces in error :" << endl;
00459     //Pout.setf(ios_base::left);
00460 
00461     if (maxNonOrtho < 180.0-SMALL)
00462     {
00463         meshGeom.checkFaceDotProduct
00464         (
00465             report,
00466             maxNonOrtho,
00467             checkFaces,
00468             baffles,
00469             &wrongFaces
00470         );
00471 
00472         label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
00473 
00474         Info<< "    non-orthogonality > "
00475             << setw(3) << maxNonOrtho
00476             << " degrees                        : "
00477             << nNewWrongFaces-nWrongFaces << endl;
00478 
00479         nWrongFaces = nNewWrongFaces;
00480     }
00481 
00482     if (minVol > -GREAT)
00483     {
00484         meshGeom.checkFacePyramids
00485         (
00486             report,
00487             minVol,
00488             meshGeom.mesh().points(),
00489             checkFaces,
00490             baffles,
00491             &wrongFaces
00492         );
00493 
00494         label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
00495 
00496         Info<< "    faces with face pyramid volume < "
00497             << setw(5) << minVol << "                 : "
00498             << nNewWrongFaces-nWrongFaces << endl;
00499 
00500         nWrongFaces = nNewWrongFaces;
00501     }
00502 
00503     if (maxConcave < 180.0-SMALL)
00504     {
00505         meshGeom.checkFaceAngles
00506         (
00507             report,
00508             maxConcave,
00509             meshGeom.mesh().points(),
00510             checkFaces,
00511             &wrongFaces
00512         );
00513 
00514         label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
00515 
00516         Info<< "    faces with concavity > "
00517             << setw(3) << maxConcave
00518             << " degrees                     : "
00519             << nNewWrongFaces-nWrongFaces << endl;
00520 
00521         nWrongFaces = nNewWrongFaces;
00522     }
00523 
00524     if (minArea > -SMALL)
00525     {
00526         meshGeom.checkFaceArea(report, minArea, checkFaces, &wrongFaces);
00527 
00528         label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
00529 
00530         Info<< "    faces with area < "
00531             << setw(5) << minArea
00532             << " m^2                            : "
00533             << nNewWrongFaces-nWrongFaces << endl;
00534 
00535         nWrongFaces = nNewWrongFaces;
00536     }
00537 
00538     if (maxIntSkew > 0 || maxBounSkew > 0)
00539     {
00540         meshGeom.checkFaceSkewness
00541         (
00542             report,
00543             maxIntSkew,
00544             maxBounSkew,
00545             checkFaces,
00546             baffles,
00547             &wrongFaces
00548         );
00549 
00550         label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
00551 
00552         Info<< "    faces with skewness > "
00553             << setw(3) << maxIntSkew
00554             << " (internal) or " << setw(3) << maxBounSkew
00555             << " (boundary) : " << nNewWrongFaces-nWrongFaces << endl;
00556 
00557         nWrongFaces = nNewWrongFaces;
00558     }
00559 
00560     if (minWeight >= 0 && minWeight < 1)
00561     {
00562         meshGeom.checkFaceWeights
00563         (
00564             report,
00565             minWeight,
00566             checkFaces,
00567             baffles,
00568             &wrongFaces
00569         );
00570 
00571         label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
00572 
00573         Info<< "    faces with interpolation weights (0..1)  < "
00574             << setw(5) << minWeight
00575             << "       : "
00576             << nNewWrongFaces-nWrongFaces << endl;
00577 
00578         nWrongFaces = nNewWrongFaces;
00579     }
00580 
00581     if (minVolRatio >= 0)
00582     {
00583         meshGeom.checkVolRatio
00584         (
00585             report,
00586             minVolRatio,
00587             checkFaces,
00588             baffles,
00589             &wrongFaces
00590         );
00591 
00592         label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
00593 
00594         Info<< "    faces with volume ratio of neighbour cells < "
00595             << setw(5) << minVolRatio
00596             << "     : "
00597             << nNewWrongFaces-nWrongFaces << endl;
00598 
00599         nWrongFaces = nNewWrongFaces;
00600     }
00601 
00602     if (minTwist > -1)
00603     {
00604         //Pout<< "Checking face twist: dot product of face normal "
00605         //    << "with face triangle normals" << endl;
00606         meshGeom.checkFaceTwist
00607         (
00608             report,
00609             minTwist,
00610             meshGeom.mesh().points(),
00611             checkFaces,
00612             &wrongFaces
00613         );
00614 
00615         label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
00616 
00617         Info<< "    faces with face twist < "
00618             << setw(5) << minTwist
00619             << "                          : "
00620             << nNewWrongFaces-nWrongFaces << endl;
00621 
00622         nWrongFaces = nNewWrongFaces;
00623     }
00624 
00625     if (minTriangleTwist > -1)
00626     {
00627         //Pout<< "Checking triangle twist: dot product of consecutive triangle"
00628         //    << " normals resulting from face-centre decomposition" << endl;
00629         meshGeom.checkTriangleTwist
00630         (
00631             report,
00632             minTriangleTwist,
00633             meshGeom.mesh().points(),
00634             checkFaces,
00635             &wrongFaces
00636         );
00637 
00638         label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
00639 
00640         Info<< "    faces with triangle twist < "
00641             << setw(5) << minTriangleTwist
00642             << "                      : "
00643             << nNewWrongFaces-nWrongFaces << endl;
00644 
00645         nWrongFaces = nNewWrongFaces;
00646     }
00647 
00648     if (minDet > -1)
00649     {
00650         meshGeom.checkCellDeterminant
00651         (
00652             report,
00653             minDet,
00654             checkFaces,
00655             meshGeom.affectedCells(meshGeom.mesh(), checkFaces),
00656             &wrongFaces
00657         );
00658 
00659         label nNewWrongFaces = returnReduce(wrongFaces.size(), sumOp<label>());
00660 
00661         Info<< "    faces on cells with determinant < "
00662             << setw(5) << minDet << "                : "
00663             << nNewWrongFaces-nWrongFaces << endl;
00664 
00665         nWrongFaces = nNewWrongFaces;
00666     }
00667 
00668     //Pout.setf(ios_base::right);
00669 
00670     return nWrongFaces > 0;
00671 }
00672 
00673 
00674 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines