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

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);
}
}
......
<
......@@ -39,75 +39,61 @@ namespace Foam
void checkMeshDict::checkBasicSettings() const
{
// check if maxCellSize is valid
const scalar maxCellSize = readScalar(meshDict_.lookup("maxCellSize"));
bool bval;
scalar sval;
if (maxCellSize < 0)
// Check if maxCellSize is valid
sval = readScalar(meshDict_.lookup("maxCellSize"));
if (sval < 0)
{
FatalErrorInFunction
<< "maxCellSize is negative! Cannot generate the mesh!!"
<< exit(FatalError);
}
// check if boundaryCellSize makes sense
if (meshDict_.found("boundaryCellSize"))
// Check if boundaryCellSize makes sense
if (meshDict_.readIfPresent("boundaryCellSize", sval))
{
const scalar bcs = readScalar(meshDict_.lookup("boundaryCellSize"));
if (bcs < 0)
if (sval < 0)
{
WarningInFunction
<< "Boundary cell size is negative!!" << endl;
}
if (meshDict_.found("boundaryCellSizeRefinementThickness"))
if
(
meshDict_.readIfPresent
(
"boundaryCellSizeRefinementThickness",
sval
)
&& (sval < 0)
)
{
const scalar thickness =
readScalar
(
meshDict_.lookup("boundaryCellSizeRefinementThickness")
);
if (thickness < 0)
{
WarningInFunction
<< "Boundary cell size refinement thickness is negative!!"
<< endl;
}
WarningInFunction
<< "Boundary cell size refinement thickness is negative!!"
<< endl;
}
}
// check if minCellSize is valid
if (meshDict_.found("minCellSize"))
// Check if minCellSize is valid
if
(
meshDict_.readIfPresent("minCellSize", sval)
&& (sval < 0)
)
{
const scalar mcs = readScalar(meshDict_.lookup("minCellSize"));
if (mcs < 0)
{
FatalErrorInFunction
<< "Minimum cell size for automatic refinement is negative!!"
<< exit(FatalError);
}
FatalErrorInFunction
<< "Minimum cell size for automatic refinement is negative!!"
<< exit(FatalError);
}
// check if keepCellsIntersectingBoundary can be read correctly
if (meshDict_.found("keepCellsIntersectingBoundary"))
{
const bool keep =
readBool(meshDict_.lookup("keepCellsIntersectingBoundary"));
// Check if keepCellsIntersectingBoundary can be read correctly
meshDict_.readIfPresent("keepCellsIntersectingBoundary", bval);
meshDict_.readIfPresent("checkForGluedMesh", bval);
if (keep && meshDict_.found("checkForGluedMesh"))
{
readBool(meshDict_.lookup("checkForGluedMesh"));
}
}
// check if enforceConstraints is available
if (meshDict_.found("enforceGeometryConstraints"))
{
readBool(meshDict_.lookup("enforceGeometryConstraints"));
}
// Check if enforceConstraints is available
meshDict_.readIfPresent("enforceConstraints", bval);
}
......@@ -163,23 +149,21 @@ void checkMeshDict::checkLocalRefinementLevel() const
{
const dictionary& dict = refDict.subDict(entries[dictI]);
if (dict.found("cellSize"))
{
const scalar cs = readScalar(dict.lookup("cellSize"));
label ival;
scalar sval;
if (cs < 0.0)
if (dict.readIfPresent("cellSize", sval))
{
if (sval < 0.0)
{
WarningInFunction
<< "Cell size for " << entries[dictI]
<< " is negative" << endl;
}
}
else if (dict.found("additionalRefinementLevels"))
else if (dict.readIfPresent("additionalRefinementLevels", ival))
{
const label nLevels =
readLabel(dict.lookup("additionalRefinementLevels"));
if (nLevels < 0)
if (ival < 0)
{
WarningInFunction
<< "Refinement level for " << entries[dictI]
......@@ -194,12 +178,9 @@ void checkMeshDict::checkLocalRefinementLevel() const
<< "for " << entries[dictI] << exit(FatalError);
}
if (dict.found("refinementThickness"))
if (dict.readIfPresent("refinementThickness", sval))
{
const scalar s =
readScalar(dict.lookup("refinementThickness"));
if (s < 0)
if (sval < 0)
{
WarningInFunction
<< "Refinement thickness for " << entries[dictI]
......@@ -387,11 +368,12 @@ void checkMeshDict::checkSurfaceRefinements() const
<< surfaceSources[surfI] << exit(FatalError);
}
if (dict.found("cellSize"))
{
const scalar cs = readScalar(dict.lookup("cellSize"));
label ival;
scalar sval;
if (cs < VSMALL)
if (dict.readIfPresent("cellSize", sval))
{
if (sval < VSMALL)
{
FatalErrorInFunction
<< "Cell size for entry " << surfaceSources[surfI]
......@@ -399,12 +381,9 @@ void checkMeshDict::checkSurfaceRefinements() const
<< exit(FatalError);
}
}
else if (dict.found("additionalRefinementLevels"))