Commit 109565f5 authored by Mark Olesen's avatar Mark Olesen

ENH: use updated dictionary methods

- Eg, readIfPresent() instead of found() followed by lookup()
parent 37f772b2
......@@ -62,10 +62,16 @@ void cartesian2DMeshGenerator::createCartesianMesh()
// create polyMesh from octree boxes
cartesianMeshExtractor cme(*octreePtr_, meshDict_, mesh_);
if (meshDict_.found("decomposePolyhedraIntoTetsAndPyrs"))
if
(
meshDict_.lookupOrDefault<bool>
(
"decomposePolyhedraIntoTetsAndPyrs",
false
)
)
{
if (readBool(meshDict_.lookup("decomposePolyhedraIntoTetsAndPyrs")))
cme.decomposeSplitHexes();
cme.decomposeSplitHexes();
}
cme.createMesh();
......
......@@ -61,10 +61,16 @@ void cartesianMeshGenerator::createCartesianMesh()
// create polyMesh from octree boxes
cartesianMeshExtractor cme(*octreePtr_, meshDict_, mesh_);
if (meshDict_.found("decomposePolyhedraIntoTetsAndPyrs"))
if
(
meshDict_.lookupOrDefault<bool>
(
"decomposePolyhedraIntoTetsAndPyrs",
false
)
)
{
if (readBool(meshDict_.lookup("decomposePolyhedraIntoTetsAndPyrs")))
cme.decomposeSplitHexes();
cme.decomposeSplitHexes();
}
cme.createMesh();
......@@ -169,12 +175,12 @@ void cartesianMeshGenerator::refBoundaryLayers()
void cartesianMeshGenerator::optimiseFinalMesh()
{
// untangle the surface if needed
bool enforceConstraints(false);
if (meshDict_.found("enforceGeometryConstraints"))
{
enforceConstraints =
readBool(meshDict_.lookup("enforceGeometryConstraints"));
}
const bool enforceConstraints =
meshDict_.lookupOrDefault<bool>
(
"enforceGeometryConstraints",
false
);
if (true)
{
......@@ -182,7 +188,9 @@ void cartesianMeshGenerator::optimiseFinalMesh()
meshSurfaceOptimizer surfOpt(mse, *octreePtr_);
if (enforceConstraints)
{
surfOpt.enforceConstraints();
}
surfOpt.optimizeSurface();
}
......@@ -192,7 +200,9 @@ void cartesianMeshGenerator::optimiseFinalMesh()
// final optimisation
meshOptimizer optimizer(mesh_);
if (enforceConstraints)
{
optimizer.enforceConstraints();
}
optimizer.optimizeMeshFV();
optimizer.optimizeLowQualityFaces();
......
......@@ -125,21 +125,23 @@ void tetMeshGenerator::generateBoundaryLayers()
const dictionary& bndLayers = meshDict_.subDict("boundaryLayers");
if (bndLayers.found("nLayers"))
label nLayers;
if (bndLayers.readIfPresent("nLayers", nLayers))
{
const label nLayers = readLabel(bndLayers.lookup("nLayers"));
if (nLayers > 0)
{
bl.addLayerForAllPatches();
}
}
else if (bndLayers.found("patchBoundaryLayers"))
{
const dictionary& patchLayers =
bndLayers.subDict("patchBoundaryLayers");
const wordList createLayers = patchLayers.toc();
forAll(createLayers, patchI)
bl.addLayerForPatch(createLayers[patchI]);
for (const word& patchName : patchLayers.toc())
{
bl.addLayerForPatch(patchName);
}
}
}
}
......@@ -148,16 +150,18 @@ void tetMeshGenerator::generateBoundaryLayers()
void tetMeshGenerator::optimiseFinalMesh()
{
// final optimisation
bool enforceConstraints(false);
if (meshDict_.found("enforceGeometryConstraints"))
{
enforceConstraints =
readBool(meshDict_.lookup("enforceGeometryConstraints"));
}
const bool enforceConstraints =
meshDict_.lookupOrDefault<bool>
(
"enforceGeometryConstraints",
false
);
meshOptimizer optimizer(mesh_);
if (enforceConstraints)
{
optimizer.enforceConstraints();
}
optimizer.optimizeSurface(*octreePtr_);
......
......@@ -260,83 +260,37 @@ void boxScaling::operator=(const dictionary& d)
: d
);
// unspecified centre is (0 0 0)
if (dict.found("centre"))
{
dict.lookup("centre") >> centre_;
}
else
if (!dict.readIfPresent("centre", centre_))
{
FatalErrorInFunction
<< "Entry centre is not specified!" << exit(FatalError);
centre_ = vector::zero;
}
// specify lengthX
if (dict.found("lengthX"))
{
lengthVec_.x() = readScalar(dict.lookup("lengthX"));
}
else
if (!dict.readIfPresent("lengthX", lengthVec_.x()))
{
FatalErrorInFunction
<< "Entry lengthX is not specified!" << exit(FatalError);
lengthVec_.x() = 0.0;
}
// specify lengthY
if (dict.found("lengthY"))
{
lengthVec_.y() = readScalar(dict.lookup("lengthY"));
}
else
if (!dict.readIfPresent("lengthY", lengthVec_.y()))
{
FatalErrorInFunction
<< "Entry lengthY is not specified!" << exit(FatalError);
lengthVec_.y() = 0.0;
}
// specify lengthZ
if (dict.found("lengthZ"))
{
lengthVec_.z() = readScalar(dict.lookup("lengthZ"));
}
else
if (!dict.readIfPresent("lengthZ", lengthVec_.z()))
{
FatalErrorInFunction
<< "Entry lengthZ is not specified!" << exit(FatalError);
lengthVec_.z() = 0.0;
}
// specify scaleX
if (dict.found("scaleX"))
{
scaleVec_.x() = readScalar(dict.lookup("scaleX"));
}
else
{
scaleVec_.x() = 1.0;
}
// specify scaleY
if (dict.found("scaleY"))
{
scaleVec_.y() = readScalar(dict.lookup("scaleY"));
}
else
{
scaleVec_.y() = 1.0;
}
// specify scaleX
if (dict.found("scaleZ"))
{
scaleVec_.z() = readScalar(dict.lookup("scaleZ"));
}
else
{
scaleVec_.z() = 1.0;
}
scaleVec_.x() = dict.lookupOrDefault<scalar>("scaleX", 1.0);
scaleVec_.y() = dict.lookupOrDefault<scalar>("scaleY", 1.0);
scaleVec_.z() = dict.lookupOrDefault<scalar>("scaleZ", 1.0);
calculateBndBox();
}
......
......@@ -222,12 +222,7 @@ void planeScaling::operator=(const dictionary& d)
: d
);
// unspecified centre is (0 0 0)
if (dict.found("origin"))
{
dict.lookup("origin") >> origin_;
}
else
if (!dict.readIfPresent("origin", origin_))
{
FatalErrorInFunction
<< "Entry origin is not specified!" << exit(FatalError);
......@@ -235,25 +230,14 @@ void planeScaling::operator=(const dictionary& d)
origin_ = vector::zero;
}
// specify normal
if (dict.found("normal"))
{
dict.lookup("normal") >> normal_;
}
else
if (!dict.readIfPresent("normal", normal_))
{
FatalErrorInFunction
<< "Entry lengthX is not specified!" << exit(FatalError);
<< "Entry normal is not specified!" << exit(FatalError);
normal_ = vector(1, 1, 1);
}
// specify translation distance
if (dict.found("scalingDistance"))
{
scalingDistance_ = readScalar(dict.lookup("scalingDistance"));
}
else
if (!dict.readIfPresent("scalingDistance", scalingDistance_))
{
FatalErrorInFunction
<< "Entry scalingDistance is not specified!" << exit(FatalError);
......@@ -261,12 +245,7 @@ void planeScaling::operator=(const dictionary& d)
scalingDistance_ = 0.0;
}
// specify scaling factor
if (dict.found("scalingFactor"))
{
scalingFactor_ = readScalar(dict.lookup("scalingFactor"));
}
else
if (!dict.readIfPresent("scalingFactor", scalingFactor_))
{
WarningInFunction
<< "Entry scalingFactor is not specified!" << endl;
......
......@@ -405,22 +405,28 @@ void refineBoundaryLayers::readSettings
const dictionary& bndLayers = meshDict.subDict("boundaryLayers");
// read global properties
if (bndLayers.found("nLayers"))
{
const label nLayers = readLabel(bndLayers.lookup("nLayers"));
refLayers.setGlobalNumberOfLayers(nLayers);
label nLayers;
if (bndLayers.readIfPresent("nLayers", nLayers))
{
refLayers.setGlobalNumberOfLayers(nLayers);
}
}
if (bndLayers.found("thicknessRatio"))
{
const scalar ratio =
readScalar(bndLayers.lookup("thicknessRatio"));
refLayers.setGlobalThicknessRatio(ratio);
scalar ratio;
if (bndLayers.readIfPresent("thicknessRatio", ratio))
{
refLayers.setGlobalThicknessRatio(ratio);
}
}
if (bndLayers.found("maxFirstLayerThickness"))
{
const scalar maxFirstThickness =
readScalar(bndLayers.lookup("maxFirstLayerThickness"));
refLayers.setGlobalMaxThicknessOfFirstLayer(maxFirstThickness);
scalar thick;
if (bndLayers.readIfPresent("maxFirstLayerThickness", thick))
{
refLayers.setGlobalMaxThicknessOfFirstLayer(thick);
}
}
// consider specified patches for exclusion from boundary layer creation
......@@ -453,41 +459,45 @@ void refineBoundaryLayers::readSettings
const dictionary& patchDict =
patchBndLayers.subDict(pName);
if (patchDict.found("nLayers"))
label nLayers;
if (patchDict.readIfPresent("nLayers", nLayers))
{
const label nLayers =
readLabel(patchDict.lookup("nLayers"));
refLayers.setNumberOfLayersForPatch(pName, nLayers);
}
if (patchDict.found("thicknessRatio"))
scalar ratio;
if (patchDict.readIfPresent("thicknessRatio", ratio))
{
const scalar ratio =
readScalar(patchDict.lookup("thicknessRatio"));
refLayers.setThicknessRatioForPatch(pName, ratio);
}
if (patchDict.found("maxFirstLayerThickness"))
scalar thick;
if
(
patchDict.readIfPresent
(
"maxFirstLayerThickness",
thick
)
)
{
const scalar maxFirstThickness =
readScalar
(
patchDict.lookup("maxFirstLayerThickness")
);
refLayers.setMaxThicknessOfFirstLayerForPatch
(
pName,
maxFirstThickness
thick
);
}
if (patchDict.found("allowDiscontinuity"))
{
const bool allowDiscontinuity =
readBool(patchDict.lookup("allowDiscontinuity"));
if (allowDiscontinuity)
{
refLayers.setInteruptForPatch(pName);
}
if
(
patchDict.lookupOrDefault<bool>
(
"allowDiscontinuity",
false
)
)
{
refLayers.setInteruptForPatch(pName);
}
}
else
......
......@@ -92,11 +92,9 @@ void triangulateNonPlanarBaseFaces::readSettings
const dictionary& optLayerDict =
layersDict.subDict("optimisationParameters");
if (optLayerDict.found("relFlatnessTol"))
scalar relTol;
if (optLayerDict.readIfPresent("relFlatnessTol", relTol))
{
const scalar relTol =
readScalar(optLayerDict.lookup("relFlatnessTol"));
triangulator.setRelativeTolerance(relTol);
}
}
......
......@@ -3096,11 +3096,10 @@ label findBadFacesAdditionalChecks
scalar minCellPartTetrahedra = VSMALL;
//Check whether quality criteria is specified by user
//if( mesh_.returnTime().foundObject<IOdictionary>("meshDict") )
if (mesh.returnTime().foundObject <IOdictionary>("meshDict"))
if (mesh.returnTime().foundObject<IOdictionary>("meshDict"))
{
const dictionary& meshDict =
mesh.returnTime().lookupObject <IOdictionary>("meshDict");
mesh.returnTime().lookupObject<IOdictionary>("meshDict");
if (meshDict.found("meshQualitySettings"))
{
......@@ -3108,14 +3107,8 @@ label findBadFacesAdditionalChecks
meshDict.subDict("meshQualitySettings");
//Reading maximum non-orthogonality defined by the user
if (qualityDict.found("maxNonOrthogonality"))
if (qualityDict.readIfPresent("maxNonOrthogonality", maxNonOrtho))
{
maxNonOrtho =
readScalar
(
qualityDict.lookup("maxNonOrthogonality")
);
polyMeshGenChecks::checkFaceDotProduct
(
mesh,
......@@ -3127,14 +3120,8 @@ label findBadFacesAdditionalChecks
}
//Reading maximum skewness defined by the user
if (qualityDict.found("maxSkewness"))
if (qualityDict.readIfPresent("maxSkewness", maxSkewness))
{
maxSkewness =
readScalar
(
qualityDict.lookup("maxSkewness")
);
polyMeshGenChecks::checkFaceSkewness
(
mesh,
......@@ -3143,18 +3130,11 @@ label findBadFacesAdditionalChecks
&badFaces,
activeFacePtr
);
}
//Reading face uniformity specified by the user
if (qualityDict.found("fcUniform"))
if (qualityDict.readIfPresent("fcUniform", fcUniform))
{
fcUniform =
readScalar
(
qualityDict.lookup("fcUniform")
);
polyMeshGenChecks::checkFaceUniformity
(
mesh,
......@@ -3166,10 +3146,8 @@ label findBadFacesAdditionalChecks
}
//Reading volume uniformity specified by the user
if (qualityDict.found("volUniform"))
if (qualityDict.readIfPresent("volUniform", volUniform))
{
volUniform = readScalar(qualityDict.lookup("volUniform"));
polyMeshGenChecks::checkVolumeUniformity
(
mesh,
......@@ -3181,10 +3159,8 @@ label findBadFacesAdditionalChecks
}
//Reading maximum face angle specified by the user
if (qualityDict.found("maxAngle"))
if (qualityDict.readIfPresent("maxAngle", maxAngle))
{
maxAngle = readScalar(qualityDict.lookup("maxAngle"));
polyMeshGenChecks::checkFaceAngles
(
mesh,
......@@ -3196,10 +3172,8 @@ label findBadFacesAdditionalChecks
}
//Reading minimum quality of tetrahedra defined by the user
if (qualityDict.found("minTetQuality"))
if (qualityDict.readIfPresent("minTetQuality", minTetQuality))
{
minTetQuality = readScalar(qualityDict.lookup("minTetQuality"));
polyMeshGenChecks::checkTetQuality
(
mesh,
......@@ -3211,10 +3185,8 @@ label findBadFacesAdditionalChecks
}
//Reading minimum face twist defined by the user
if (qualityDict.found("minFaceTwist"))
if (qualityDict.readIfPresent("minFaceTwist", minFaceTwist))
{
minFaceTwist = readScalar(qualityDict.lookup("minFaceTwist"));
polyMeshGenChecks::checkMinTwist
(
mesh,
......@@ -3226,11 +3198,15 @@ label findBadFacesAdditionalChecks
}
//Reading minimum cell determinant defined by the user
if (qualityDict.found("minCellDeterminant"))
if
(
qualityDict.readIfPresent
(
"minCellDeterminant",
minCellDeterminant
)
)
{
minCellDeterminant =
readScalar(qualityDict.lookup("minCellDeterminant"));
polyMeshGenChecks::checkCellDeterminant
(
mesh,
......@@ -3242,10 +3218,8 @@ label findBadFacesAdditionalChecks
}
//Reading minimum cell volume ratio defined by the user
if (qualityDict.found("minVolRatio"))
if (qualityDict.readIfPresent("minVolRatio", minVolRatio))
{
minVolRatio = readScalar(qualityDict.lookup("minVolRatio"));
polyMeshGenChecks::checkMinVolRatio
(
mesh,
......@@ -3257,11 +3231,15 @@ label findBadFacesAdditionalChecks
}
//Reading minimum face triangle twist defined by the user
if (qualityDict.found("minFaceTriangleTwist"))
if
(
qualityDict.readIfPresent
(
"minFaceTriangleTwist",
minFaceTriangleTwist
)
)
{
minFaceTriangleTwist =
readScalar(qualityDict.lookup("minFaceTriangleTwist"));
polyMeshGenChecks::checkTriangleTwist
(
mesh,
......@@ -3273,11 +3251,8 @@ label findBadFacesAdditionalChecks
}
//Reading minimum volume of the face pyramid defined by the user
if (qualityDict.found("minPyramidVolume"))
if (qualityDict.readIfPresent("minPyramidVolume", minPyramidVolume))
{
minPyramidVolume =
readScalar(qualityDict.lookup("minPyramidVolume"));
polyMeshGenChecks::checkFacePyramids
(
mesh,
......@@ -3289,11 +3264,8 @@ label findBadFacesAdditionalChecks
}
//Reading minimum area of a face defined by the user
if (qualityDict.found("minimumFaceArea"))
if (qualityDict.readIfPresent("minimumFaceArea", minimumFaceArea))
{
minimumFaceArea =
readScalar(qualityDict.lookup("minimumFaceArea"));
polyMeshGenChecks::checkFaceAreas
(
mesh,
......@@ -3305,10 +3277,8 @@ label findBadFacesAdditionalChecks
}
//Reading face flatness defined by the user
if (qualityDict.found("faceFlatness"))
if (qualityDict.readIfPresent("faceFlatness", faceFlatness))
{
faceFlatness = readScalar(qualityDict.lookup("faceFlatness"));
polyMeshGenChecks::checkFaceFlatness
(
mesh,
......@@ -3320,11 +3290,15 @@ label findBadFacesAdditionalChecks
}
//Reading minimum tetrahedral part of a cell defined by the user
if (qualityDict.found("minCellPartTetrahedra"))
if
(
qualityDict.readIfPresent
(
"minCellPartTetrahedra",
minCellPartTetrahedra
)
)
{
minCellPartTetrahedra =
readScalar(qualityDict.lookup("minCellPartTetrahedra"));
polyMeshGenChecks::checkCellPartTetrahedra
(
mesh,
......
......@@ -145,17 +145,9 @@ meshOctreeAddressing::meshOctreeAddressing
useDATABoxes_ = readBool(dict.lookup("keepCellsIntersectingBoundary"));
}
if (dict.found("nonManifoldMeshing"))
if (dict.lookupOrDefault<bool>("nonManifoldMeshing", false))
{
const bool nonManifoldMesh
(
readBool(dict.lookup("nonManifoldMeshing"))
);
if (nonManifoldMesh)
{
useDATABoxes_ = true;
}
useDATABoxes_ = true;
}
if (Pstream::parRun())
......
......@@ -510,25 +510,17 @@ void meshOctreeAddressing::findUsedBoxes() const
boxType[leafI] |= MESHCELL;
}
if (meshDict_.found("nonManifoldMeshing"))
if (meshDict_.lookupOrDefault<bool>("nonManifoldMeshing", false))
{
const bool nonManifoldMesh
(
readBool(meshDict_.lookup("nonManifoldMeshing"))
);
if (nonManifoldMesh)
# ifdef USE_OMP
# pragma omp parallel for schedule(dynamic, 40)
# endif
forAll(boxType, leafI)
{
# ifdef USE_OMP
# pragma omp parallel for schedule(dynamic, 40)
# endif
forAll(boxType, leafI)
const meshOctreeCubeBasic& leaf = octree_.returnLeaf(leafI);
if (leaf.cubeType() & meshOctreeCubeBasic::UNKNOWN)
{
const meshOctreeCubeBasic& leaf = octree_.returnLeaf(leafI);
if (leaf.cubeType() & meshOctreeCubeBasic::UNKNOWN)
{
boxType[leafI] |= MESHCELL;
}
boxType[leafI] |= MESHCELL;
}
}
}
......
......@@ -39,19 +39,12 @@ namespace Foam
void meshOctreeAddressing::checkGluedRegions()