OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

primitiveMeshCheckMotion.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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026     Given a set of points, find out if the mesh resulting from point motion will
00027     be valid without actually changing the mesh.
00028 
00029 \*---------------------------------------------------------------------------*/
00030 
00031 #include "primitiveMesh.H"
00032 #include "pyramidPointFaceRef.H"
00033 #include "cell.H"
00034 #include "mathematicalConstants.H"
00035 
00036 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00037 
00038 
00039 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00040 
00041 bool Foam::primitiveMesh::checkMeshMotion
00042 (
00043     const pointField& newPoints,
00044     const bool report
00045 ) const
00046 {
00047     if (debug || report)
00048     {
00049         Pout<< "bool primitiveMesh::checkMeshMotion("
00050             << "const pointField& newPoints, const bool report) const: "
00051             << "checking mesh motion" << endl;
00052     }
00053 
00054     bool error = false;
00055 
00056     const faceList& f = faces();
00057 
00058     const labelList& own = faceOwner();
00059     const labelList& nei = faceNeighbour();
00060 
00061     vectorField fCtrs(nFaces());
00062     vectorField fAreas(nFaces());
00063 
00064     makeFaceCentresAndAreas(newPoints, fCtrs, fAreas);
00065 
00066     // Check cell volumes and calculate new cell centres
00067     vectorField cellCtrs(nCells());
00068     scalarField cellVols(nCells());
00069 
00070     makeCellCentresAndVols(fCtrs, fAreas, cellCtrs, cellVols);
00071 
00072     scalar minVolume = GREAT;
00073     label nNegVols = 0;
00074 
00075     forAll (cellVols, cellI)
00076     {
00077         if (cellVols[cellI] < VSMALL)
00078         {
00079             if (debug || report)
00080             {
00081                 Pout<< "Zero or negative cell volume detected for cell "
00082                     << cellI << ".  Volume = " << cellVols[cellI] << endl;
00083             }
00084 
00085             nNegVols++;
00086         }
00087 
00088         minVolume = min(minVolume, cellVols[cellI]);
00089     }
00090 
00091     if (nNegVols > 0)
00092     {
00093         error = true;
00094 
00095         Pout<< "Zero or negative cell volume in mesh motion in " << nNegVols
00096             << " cells.  Min volume: " << minVolume << endl;
00097     }
00098     else
00099     {
00100         if (debug || report)
00101         {
00102             Pout<< "Min volume = " << minVolume
00103                 << ".  Total volume = " << sum(cellVols)
00104                 << ".  Cell volumes OK." << endl;
00105         }
00106     }
00107 
00108     // Check face areas
00109 
00110     scalar minArea = GREAT;
00111     label nNegAreas = 0;
00112     label nPyrErrors = 0;
00113     label nDotProductErrors = 0;
00114 
00115     forAll (f, faceI)
00116     {
00117         const scalar a = Foam::mag(fAreas[faceI]);
00118 
00119         if (a < VSMALL)
00120         {
00121             if (debug || report)
00122             {
00123                 if (isInternalFace(faceI))
00124                 {
00125                     Pout<< "Zero or negative face area detected for "
00126                         << "internal face "<< faceI << " between cells "
00127                         << own[faceI] << " and " << nei[faceI]
00128                         << ".  Face area magnitude = " << a << endl;
00129                 }
00130                 else
00131                 {
00132                     Pout<< "Zero or negative face area detected for "
00133                         << "boundary face " << faceI << " next to cell "
00134                         << own[faceI] << ".  Face area magnitude = "
00135                         << a << endl;
00136                 }
00137             }
00138 
00139             nNegAreas++;
00140         }
00141 
00142         minArea = min(minArea, a);
00143 
00144         // Create the owner pyramid - it will have negative volume
00145         scalar pyrVol =
00146             pyramidPointFaceRef(f[faceI], cellCtrs[own[faceI]]).mag(newPoints);
00147 
00148         if (pyrVol > SMALL)
00149         {
00150             if (debug || report)
00151             {
00152                 Pout<< "Negative pyramid volume: " << -pyrVol
00153                     << " for face " << faceI << " " << f[faceI]
00154                     << "  and owner cell: " << own[faceI] << endl
00155                     << "Owner cell vertex labels: "
00156                     << cells()[own[faceI]].labels(f)
00157                     << endl;
00158             }
00159 
00160             nPyrErrors++;
00161         }
00162 
00163         if (isInternalFace(faceI))
00164         {
00165             // Create the neighbour pyramid - it will have positive volume
00166             scalar pyrVol =
00167                 pyramidPointFaceRef
00168                 (
00169                     f[faceI],
00170                     cellCtrs[nei[faceI]]
00171                 ).mag(newPoints);
00172 
00173             if (pyrVol < -SMALL)
00174             {
00175                 if (debug || report)
00176                 {
00177                     Pout<< "Negative pyramid volume: " << pyrVol
00178                         << " for face " << faceI << " " << f[faceI]
00179                         << "  and neighbour cell: " << nei[faceI] << nl
00180                         << "Neighbour cell vertex labels: "
00181                         << cells()[nei[faceI]].labels(f)
00182                         << endl;
00183                 }
00184 
00185                 nPyrErrors++;
00186             }
00187 
00188             const vector d = cellCtrs[nei[faceI]] - cellCtrs[own[faceI]];
00189             const vector& s = fAreas[faceI];
00190             scalar dDotS = (d & s)/(mag(d)*mag(s) + VSMALL);
00191 
00192             // Only write full message the first time
00193             if (dDotS < SMALL && nDotProductErrors == 0)
00194             {
00195                 // Non-orthogonality greater than 90 deg
00196                 WarningIn
00197                 (
00198                     "primitiveMesh::checkMeshMotion"
00199                     "(const pointField& newPoints, const bool report) const"
00200                 )   << "Severe non-orthogonality in mesh motion for face "
00201                     << faceI
00202                     << " between cells " << own[faceI] << " and " << nei[faceI]
00203                     << ": Angle = " << ::acos(dDotS)/mathematicalConstant::pi*180.0
00204                     << " deg." << endl;
00205 
00206                 nDotProductErrors++;
00207             }
00208         }
00209     }
00210 
00211     if (nNegAreas > 0)
00212     {
00213         error = true;
00214 
00215         WarningIn
00216         (
00217             "primitiveMesh::checkMeshMotion"
00218             "(const pointField& newPoints, const bool report) const"
00219         )   << "Zero or negative face area in mesh motion in " << nNegAreas
00220             << " faces.  Min area: " << minArea << endl;
00221     }
00222     else
00223     {
00224         if (debug || report)
00225         {
00226             Pout<< "Min area = " << minArea
00227                 << ".  Face areas OK." << endl;
00228         }
00229     }
00230 
00231     if (nPyrErrors > 0)
00232     {
00233         Pout<< "Detected " << nPyrErrors
00234             << " negative pyramid volume in mesh motion" << endl;
00235 
00236         error = true;
00237     }
00238     else
00239     {
00240         if (debug || report)
00241         {
00242             Pout<< "Pyramid volumes OK." << endl;
00243         }
00244     }
00245 
00246     if (nDotProductErrors > 0)
00247     {
00248         Pout<< "Detected " << nDotProductErrors
00249             << " in non-orthogonality in mesh motion." << endl;
00250 
00251         error = true;
00252     }
00253     else
00254     {
00255         if (debug || report)
00256         {
00257             Pout<< "Non-orthogonality check OK." << endl;
00258         }
00259     }
00260 
00261     if (!error && (debug || report))
00262     {
00263         Pout << "Mesh motion check OK." << endl;
00264     }
00265 
00266     return error;
00267 }
00268 
00269 
00270 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd