ENH: combinePatchFaces: have -meshQuality option

This commit is contained in:
mattijs
2012-11-14 09:30:59 +00:00
parent 4bdfee665d
commit d0c0fb9da2
2 changed files with 35 additions and 96 deletions

View File

@ -5,4 +5,5 @@ EXE_INC = \
EXE_LIBS = \ EXE_LIBS = \
-lmeshTools \ -lmeshTools \
-lsampling \
-ldynamicMesh -ldynamicMesh

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -53,105 +53,19 @@ Description
#include "polyMesh.H" #include "polyMesh.H"
#include "mapPolyMesh.H" #include "mapPolyMesh.H"
#include "unitConversion.H" #include "unitConversion.H"
#include "motionSmoother.H"
using namespace Foam; using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Same check as snapMesh
void checkSnapMesh
(
const Time& runTime,
const polyMesh& mesh,
labelHashSet& wrongFaces
)
{
IOdictionary snapDict
(
IOobject
(
"snapMeshDict",
runTime.system(),
mesh,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
)
);
// Max nonorthogonality allowed
scalar maxNonOrtho(readScalar(snapDict.lookup("maxNonOrtho")));
// Max concaveness allowed.
scalar maxConcave(readScalar(snapDict.lookup("maxConcave")));
// Min volume allowed (factor of minimum cellVolume)
scalar relMinVol(readScalar(snapDict.lookup("minVol")));
const scalar minCellVol = min(mesh.cellVolumes());
const scalar minPyrVol = relMinVol*minCellVol;
// Min area
scalar minArea(readScalar(snapDict.lookup("minArea")));
if (maxNonOrtho < 180.0-SMALL)
{
Pout<< "Checking non orthogonality" << endl;
label nOldSize = wrongFaces.size();
mesh.setNonOrthThreshold(maxNonOrtho);
mesh.checkFaceOrthogonality(false, &wrongFaces);
Pout<< "Detected " << wrongFaces.size() - nOldSize
<< " faces with non-orthogonality > " << maxNonOrtho << " degrees"
<< endl;
}
if (minPyrVol > -GREAT)
{
Pout<< "Checking face pyramids" << endl;
label nOldSize = wrongFaces.size();
mesh.checkFacePyramids(false, minPyrVol, &wrongFaces);
Pout<< "Detected additional " << wrongFaces.size() - nOldSize
<< " faces with illegal face pyramids" << endl;
}
if (maxConcave < 180.0-SMALL)
{
Pout<< "Checking face angles" << endl;
label nOldSize = wrongFaces.size();
mesh.checkFaceAngles(false, maxConcave, &wrongFaces);
Pout<< "Detected additional " << wrongFaces.size() - nOldSize
<< " faces with concavity > " << maxConcave << " degrees"
<< endl;
}
if (minArea > -SMALL)
{
Pout<< "Checking face areas" << endl;
label nOldSize = wrongFaces.size();
const scalarField magFaceAreas(mag(mesh.faceAreas()));
forAll(magFaceAreas, faceI)
{
if (magFaceAreas[faceI] < minArea)
{
wrongFaces.insert(faceI);
}
}
Pout<< "Detected additional " << wrongFaces.size() - nOldSize
<< " faces with area < " << minArea << " m^2" << endl;
}
}
// Merge faces on the same patch (usually from exposing refinement) // Merge faces on the same patch (usually from exposing refinement)
// Can undo merges if these cause problems. // Can undo merges if these cause problems.
label mergePatchFaces label mergePatchFaces
( (
const scalar minCos, const scalar minCos,
const scalar concaveSin, const scalar concaveSin,
const bool snapMeshDict, const autoPtr<IOdictionary>& qualDictPtr,
const Time& runTime, const Time& runTime,
polyMesh& mesh polyMesh& mesh
) )
@ -212,9 +126,9 @@ label mergePatchFaces
// Faces in error. // Faces in error.
labelHashSet errorFaces; labelHashSet errorFaces;
if (snapMeshDict) if (qualDictPtr.valid())
{ {
checkSnapMesh(runTime, mesh, errorFaces); motionSmoother::checkMesh(false, mesh, qualDictPtr(), errorFaces);
} }
else else
{ {
@ -437,8 +351,8 @@ int main(int argc, char *argv[])
); );
argList::addBoolOption argList::addBoolOption
( (
"snapMesh", "meshQuality",
"use system/snapMeshDict" "read user-defined mesh quality criterions from system/meshQualityDict"
); );
# include "setRootCase.H" # include "setRootCase.H"
@ -455,8 +369,8 @@ int main(int argc, char *argv[])
scalar concaveAngle = args.optionLookupOrDefault("concaveAngle", 30.0); scalar concaveAngle = args.optionLookupOrDefault("concaveAngle", 30.0);
scalar concaveSin = Foam::sin(degToRad(concaveAngle)); scalar concaveSin = Foam::sin(degToRad(concaveAngle));
const bool snapMeshDict = args.optionFound("snapMesh");
const bool overwrite = args.optionFound("overwrite"); const bool overwrite = args.optionFound("overwrite");
const bool meshQuality = args.optionFound("meshQuality");
Info<< "Merging all faces of a cell" << nl Info<< "Merging all faces of a cell" << nl
<< " - which are on the same patch" << nl << " - which are on the same patch" << nl
@ -468,23 +382,47 @@ int main(int argc, char *argv[])
<< " (sin:" << concaveSin << ')' << nl << " (sin:" << concaveSin << ')' << nl
<< endl; << endl;
autoPtr<IOdictionary> qualDict;
if (meshQuality)
{
Info<< "Enabling user-defined geometry checks." << nl << endl;
qualDict.reset
(
new IOdictionary
(
IOobject
(
"meshQualityDict",
mesh.time().system(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
);
}
if (!overwrite) if (!overwrite)
{ {
runTime++; runTime++;
} }
// Merge faces on same patch // Merge faces on same patch
label nChanged = mergePatchFaces label nChanged = mergePatchFaces
( (
minCos, minCos,
concaveSin, concaveSin,
snapMeshDict, qualDict,
runTime, runTime,
mesh mesh
); );
// Merge points on straight edges and remove unused points // Merge points on straight edges and remove unused points
if (snapMeshDict) if (qualDict.valid())
{ {
Info<< "Merging all 'loose' points on surface edges, " Info<< "Merging all 'loose' points on surface edges, "
<< "regardless of the angle they make." << endl; << "regardless of the angle they make." << endl;