Commit 84b10921 authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: reduced usage of Switch

- Since 'bool' and 'Switch' use the _identical_ input mechanism
  (ie, both accept true/false, on/off, yes/no, none, 1/0), the main
  reason to prefer one or the other is the output.

  The output for Switch is as text (eg, "true"), whereas for bool
  it is label (0 or 1). If the output is required for a dictionary,
  Switch may be appropriate. If the output is not required, or is only
  used for Pstream exchange, bool can be more appropriate.
parent 0f60cc92
......@@ -78,7 +78,6 @@ Description
#include "XiModel.H"
#include "PDRDragModel.H"
#include "ignition.H"
#include "Switch.H"
#include "bound.H"
#include "pimpleControl.H"
#include "fvOptions.H"
......
......@@ -63,7 +63,6 @@ Description
#include "XiModel.H"
#include "PDRDragModel.H"
#include "ignition.H"
#include "Switch.H"
#include "bound.H"
#include "dynamicRefineFvMesh.H"
#include "pimpleControl.H"
......
......@@ -58,14 +58,14 @@ Foam::PDRDragModel::PDRDragModel
(
PDRProperties.subDict
(
word(PDRProperties.lookup("PDRDragModel")) + "Coeffs"
PDRProperties.get<word>("PDRDragModel") + "Coeffs"
)
),
turbulence_(turbulence),
rho_(rho),
U_(U),
phi_(phi),
on_(PDRDragModelCoeffs_.lookup("drag"))
on_(PDRDragModelCoeffs_.get<bool>("drag"))
{}
......@@ -81,7 +81,7 @@ bool Foam::PDRDragModel::read(const dictionary& PDRProperties)
{
PDRDragModelCoeffs_ = PDRProperties.optionalSubDict(type() + "Coeffs");
PDRDragModelCoeffs_.lookup("drag") >> on_;
PDRDragModelCoeffs_.read("drag", on_);
return true;
}
......
......@@ -67,7 +67,7 @@ protected:
const volVectorField& U_;
const surfaceScalarField& phi_;
Switch on_;
bool on_;
private:
......
......@@ -36,9 +36,9 @@ Foam::autoPtr<Foam::PDRDragModel> Foam::PDRDragModel::New
const surfaceScalarField& phi
)
{
const word modelType(PDRProperties.lookup("PDRDragModel"));
const word modelType(PDRProperties.get<word>("PDRDragModel"));
Info<< "Selecting flame-wrinkling model " << modelType << endl;
Info<< "Selecting drag model " << modelType << endl;
auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType);
......
......@@ -165,8 +165,8 @@ bool Foam::PDRDragModels::basic::read(const dictionary& PDRProperties)
{
PDRDragModel::read(PDRProperties);
PDRDragModelCoeffs_.lookup("Csu") >> Csu.value();
PDRDragModelCoeffs_.lookup("Csk") >> Csk.value();
PDRDragModelCoeffs_.read("Csu", Csu.value());
PDRDragModelCoeffs_.read("Csk", Csk.value());
return true;
}
......
Switch adjustTimeStep(runTime.controlDict().lookup("adjustTimeStep"));
scalar maxDeltaT(readScalar(runTime.controlDict().lookup("maxDeltaT")));
bool adjustTimeStep(runTime.controlDict().get<bool>("adjustTimeStep"));
scalar maxDeltaT(runTime.controlDict().get<scalar>("maxDeltaT"));
runTime.controlDict().lookup("adjustTimeStep") >> adjustTimeStep;
runTime.controlDict().read("adjustTimeStep", adjustTimeStep);
maxDeltaT = readScalar(runTime.controlDict().lookup("maxDeltaT"));
runTime.controlDict().read("maxDeltaT", maxDeltaT);
IOporosityModelList pZones(mesh);
Switch pressureImplicitPorosity(false);
bool pressureImplicitPorosity(false);
// nUCorrectors used for pressureImplicitPorosity
int nUCorr = 0;
......
......@@ -13,9 +13,11 @@ IOdictionary gravitationalProperties
);
const dimensionedVector g(gravitationalProperties.lookup("g"));
const Switch rotating(gravitationalProperties.lookup("rotating"));
const bool rotating(gravitationalProperties.get<bool>("rotating"));
const dimensionedVector Omega =
(
rotating ? gravitationalProperties.lookup("Omega")
: dimensionedVector("Omega", -dimTime, vector(0,0,0));
: dimensionedVector("Omega", -dimTime, vector(0,0,0))
);
const dimensionedScalar magg = mag(g);
const dimensionedVector gHat = g/magg;
IOporosityModelList pZones(mesh);
Switch pressureImplicitPorosity(false);
bool pressureImplicitPorosity(false);
// nUCorrectors used for pressureImplicitPorosity
int nUCorr = 0;
......
......@@ -39,7 +39,7 @@ ThermalPhaseChangePhaseSystem
HeatAndMassTransferPhaseSystem<BasePhaseSystem>(mesh),
volatile_(this->lookup("volatile")),
saturationModel_(saturationModel::New(this->subDict("saturationModel"))),
massTransfer_(this->lookup("massTransfer"))
massTransfer_(this->template get<bool>("massTransfer"))
{
forAllConstIters(this->phasePairs_, phasePairIter)
......@@ -357,7 +357,7 @@ void Foam::ThermalPhaseChangePhaseSystem<BasePhaseSystem>::correctThermo()
volScalarField iDmdtNew(iDmdt);
if (massTransfer_ )
if (massTransfer_)
{
volScalarField H1
(
......
......@@ -43,7 +43,6 @@ SourceFiles
#include "HeatAndMassTransferPhaseSystem.H"
#include "saturationModel.H"
#include "Switch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -71,7 +70,7 @@ protected:
autoPtr<saturationModel> saturationModel_;
// Mass transfer enabled
Switch massTransfer_;
bool massTransfer_;
//- Interfacial Mass transfer rate
HashPtrTable<volScalarField, phasePairKey, phasePairKey::hash>
......
const dictionary& stressControl = mesh.solutionDict().subDict("stressAnalysis");
Switch compactNormalStress(stressControl.lookup("compactNormalStress"));
bool compactNormalStress(stressControl.get<bool>("compactNormalStress"));
......@@ -2,4 +2,4 @@
int nCorr = stressControl.lookupOrDefault<int>("nCorrectors", 1);
scalar convergenceTolerance(readScalar(stressControl.lookup("D")));
scalar convergenceTolerance(stressControl.get<scalar>("D"));
......@@ -184,9 +184,7 @@
volScalarField lambda(nu*E/((1.0 + nu)*(1.0 - 2.0*nu)));
volScalarField threeK(E/(1.0 - 2.0*nu));
Switch planeStress(mechanicalProperties.lookup("planeStress"));
if (planeStress)
if (mechanicalProperties.get<bool>("planeStress"))
{
Info<< "Plane Stress\n" << endl;
......
nCorr = stressControl.lookupOrDefault<int>("nCorrectors", 1);
convergenceTolerance = readScalar(stressControl.lookup("D"));
stressControl.lookup("compactNormalStress") >> compactNormalStress;
convergenceTolerance = stressControl.get<scalar>("D");
compactNormalStress = stressControl.get<bool>("compactNormalStress");
......@@ -12,7 +12,7 @@ IOdictionary thermalProperties
)
);
Switch thermalStress(thermalProperties.lookup("thermalStress"));
bool thermalStress(thermalProperties.get<bool>("thermalStress"));
volScalarField threeKalpha
(
......@@ -46,7 +46,6 @@ volScalarField DT
if (thermalStress)
{
autoPtr<volScalarField> CPtr;
IOobject CIO
......
......@@ -39,7 +39,6 @@ Description
\*---------------------------------------------------------------------------*/
#include "fvCFD.H"
#include "Switch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -164,9 +164,7 @@ void tractionDisplacementFvPatchVectorField::updateCoeffs()
scalarField lambda(nu*E/((1.0 + nu)*(1.0 - 2.0*nu)));
scalarField threeK(E/(1.0 - 2.0*nu));
Switch planeStress(mechanicalProperties.lookup("planeStress"));
if (planeStress)
if (mechanicalProperties.get<bool>("planeStress"))
{
lambda = nu*E/((1.0 + nu)*(1.0 - nu));
threeK = E/(1.0 - nu);
......@@ -185,9 +183,7 @@ void tractionDisplacementFvPatchVectorField::updateCoeffs()
+ twoMuLambda*fvPatchField<vector>::snGrad() - (n & sigmaD)
)/twoMuLambda;
Switch thermalStress(thermalProperties.lookup("thermalStress"));
if (thermalStress)
if (thermalProperties.get<bool>("thermalStress"))
{
const fvPatchField<scalar>& threeKalpha=
patch().lookupPatchField<volScalarField, scalar>("threeKalpha");
......
......@@ -39,7 +39,6 @@ Description
\*---------------------------------------------------------------------------*/
#include "fvCFD.H"
#include "Switch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -163,9 +163,7 @@ void tractionDisplacementCorrectionFvPatchVectorField::updateCoeffs()
scalarField mu(E/(2.0*(1.0 + nu)));
scalarField lambda(nu*E/((1.0 + nu)*(1.0 - 2.0*nu)));
Switch planeStress(mechanicalProperties.lookup("planeStress"));
if (planeStress)
if (mechanicalProperties.get<bool>("planeStress"))
{
lambda = nu*E/((1.0 + nu)*(1.0 - nu));
}
......
......@@ -89,9 +89,7 @@ Foam::edgeStats::edgeStats(const polyMesh& mesh)
IOdictionary motionProperties(motionObj);
Switch twoDMotion(motionProperties.lookup("twoDMotion"));
if (twoDMotion)
if (motionProperties.get<bool>("twoDMotion"))
{
Info<< "Correcting for 2D motion" << endl << endl;
......
......@@ -658,9 +658,7 @@ int main(int argc, char *argv[])
IOdictionary motionProperties(motionObj);
Switch twoDMotion(motionProperties.lookup("twoDMotion"));
if (twoDMotion)
if (motionProperties.get<bool>("twoDMotion"))
{
Info<< "Correcting for 2D motion" << endl << endl;
correct2DPtr = new twoDPointCorrector(mesh);
......
......@@ -297,7 +297,7 @@ int main(int argc, char *argv[])
autoPtr<extrudeModel> model(extrudeModel::New(dict));
// Whether to flip normals
const Switch flipNormals(dict.lookup("flipNormals"));
const bool flipNormals(dict.get<bool>("flipNormals"));
// What to extrude
const ExtrudeMode mode = ExtrudeModeNames.lookup
......@@ -983,8 +983,7 @@ int main(int argc, char *argv[])
// Merging front and back patch faces
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Switch mergeFaces(dict.lookup("mergeFaces"));
if (mergeFaces)
if (dict.get<bool>("mergeFaces"))
{
if (mode == MESH)
{
......@@ -1009,7 +1008,6 @@ int main(int argc, char *argv[])
}
polyTopoChanger stitcher(mesh);
stitcher.setSize(1);
......
......@@ -1536,8 +1536,8 @@ int main(int argc, char *argv[])
mappedPatchBase::sampleMode sampleMode =
mappedPatchBase::sampleModeNames_[dict.lookup("sampleMode")];
const Switch oneD(dict.lookup("oneD"));
Switch oneDNonManifoldEdges(false);
const bool oneD(dict.get<bool>("oneD"));
bool oneDNonManifoldEdges(false);
word oneDPatchType(emptyPolyPatch::typeName);
if (oneD)
{
......@@ -1545,7 +1545,7 @@ int main(int argc, char *argv[])
dict.lookup("oneDPolyPatchType") >> oneDPatchType;
}
const Switch adaptMesh(dict.lookup("adaptMesh"));
const bool adaptMesh(dict.get<bool>("adaptMesh"));
if (hasZones)
{
......
......@@ -97,7 +97,7 @@ Foam::automatic::automatic
(
const dictionary& cellSizeCalcTypeDict,
const triSurfaceMesh& surface,
const scalar& defaultCellSize
const scalar defaultCellSize
)
:
cellSizeCalculationType
......@@ -109,12 +109,15 @@ Foam::automatic::automatic
),
coeffsDict_(cellSizeCalcTypeDict.optionalSubDict(typeName + "Coeffs")),
surfaceName_(surface.searchableSurface::name()),
readCurvature_(Switch(coeffsDict_.lookup("curvature"))),
curvatureFile_(coeffsDict_.lookup("curvatureFile")),
readFeatureProximity_(Switch(coeffsDict_.lookup("featureProximity"))),
featureProximityFile_(coeffsDict_.lookup("featureProximityFile")),
readInternalCloseness_(Switch(coeffsDict_.lookup("internalCloseness"))),
internalClosenessFile_(coeffsDict_.lookup("internalClosenessFile")),
readCurvature_(coeffsDict_.get<bool>("curvature")),
readFeatureProximity_(coeffsDict_.get<bool>("featureProximity")),
readInternalCloseness_(coeffsDict_.get<bool>("internalCloseness")),
curvatureFile_(coeffsDict_.get<word>("curvatureFile")),
featureProximityFile_(coeffsDict_.get<word>("featureProximityFile")),
internalClosenessFile_(coeffsDict_.get<word>("internalClosenessFile")),
curvatureCellSizeCoeff_
(
readScalar(coeffsDict_.lookup("curvatureCellSizeCoeff"))
......
......@@ -37,7 +37,6 @@ SourceFiles
#include "cellSizeCalculationType.H"
#include "triSurfaceFields.H"
#include "PrimitivePatchInterpolation.H"
#include "Switch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -54,9 +53,6 @@ class automatic
:
public cellSizeCalculationType
{
private:
// Private data
//- Dictionary of coefficients for automatic cell sizing
......@@ -65,13 +61,12 @@ private:
//- Name of the surface. Used to write the cell size field
const fileName surfaceName_;
const Switch readCurvature_;
const word curvatureFile_;
const bool readCurvature_;
const bool readFeatureProximity_;
const bool readInternalCloseness_;
const Switch readFeatureProximity_;
const word curvatureFile_;
const word featureProximityFile_;
const Switch readInternalCloseness_;
const word internalClosenessFile_;
//- The curvature values are multiplied by the inverse of this value to
......@@ -100,13 +95,12 @@ public:
(
const dictionary& cellSizeCalcTypeDict,
const triSurfaceMesh& surface,
const scalar& defaultCellSize
const scalar defaultCellSize
);
//- Destructor
virtual ~automatic()
{}
virtual ~automatic() = default;
// Member Functions
......
......@@ -42,43 +42,30 @@ Foam::cvControls::cvControls
foamyHexMeshDict_.subDict("surfaceConformation")
);
pointPairDistanceCoeff_ = readScalar
(
surfDict.lookup("pointPairDistanceCoeff")
);
pointPairDistanceCoeff_ =
surfDict.get<scalar>("pointPairDistanceCoeff");
mixedFeaturePointPPDistanceCoeff_ = readScalar
(
surfDict.lookup("mixedFeaturePointPPDistanceCoeff")
);
mixedFeaturePointPPDistanceCoeff_ =
surfDict.get<scalar>("mixedFeaturePointPPDistanceCoeff");
featurePointExclusionDistanceCoeff_ = readScalar
(
surfDict.lookup("featurePointExclusionDistanceCoeff")
);
featurePointExclusionDistanceCoeff_ =
surfDict.get<scalar>("featurePointExclusionDistanceCoeff");
featureEdgeExclusionDistanceCoeff_ = readScalar
(
surfDict.lookup("featureEdgeExclusionDistanceCoeff")
);
featureEdgeExclusionDistanceCoeff_ =
surfDict.get<scalar>("featureEdgeExclusionDistanceCoeff");
surfaceSearchDistanceCoeff_ =
surfDict.get<scalar>("surfaceSearchDistanceCoeff");
surfaceSearchDistanceCoeff_ = readScalar
(
surfDict.lookup("surfaceSearchDistanceCoeff")
);
maxSurfaceProtrusionCoeff_ =
surfDict.get<scalar>("maxSurfaceProtrusionCoeff");
maxSurfaceProtrusionCoeff_ = readScalar
(
surfDict.lookup("maxSurfaceProtrusionCoeff")
);
maxQuadAngle_ = readScalar(surfDict.lookup("maxQuadAngle"));
maxQuadAngle_ = surfDict.get<scalar>("maxQuadAngle");
surfaceConformationRebuildFrequency_ = max
(
1,
readLabel(surfDict.lookup("surfaceConformationRebuildFrequency"))
surfDict.get<label>("surfaceConformationRebuildFrequency")
);
......@@ -87,33 +74,23 @@ Foam::cvControls::cvControls
surfDict.subDict("featurePointControls")
);
specialiseFeaturePoints_ = Switch
(
featurePointControlsDict.lookup("specialiseFeaturePoints")
);
specialiseFeaturePoints_ =
featurePointControlsDict.get<Switch>("specialiseFeaturePoints");
guardFeaturePoints_ = Switch
(
featurePointControlsDict.lookup("guardFeaturePoints")
);
guardFeaturePoints_ =
featurePointControlsDict.get<Switch>("guardFeaturePoints");
edgeAiming_ = Switch
(
featurePointControlsDict.lookup("edgeAiming")
);
edgeAiming_ =
featurePointControlsDict.get<Switch>("edgeAiming");
if (!guardFeaturePoints_)
{
snapFeaturePoints_ = Switch
(
featurePointControlsDict.lookup("snapFeaturePoints")
);
snapFeaturePoints_ =
featurePointControlsDict.get<Switch>("snapFeaturePoints");
}
circulateEdges_ = Switch
(
featurePointControlsDict.lookup("circulateEdges")
);
circulateEdges_ =
featurePointControlsDict.get<Switch>("circulateEdges");
// Controls for coarse surface conformation
......@@ -122,62 +99,47 @@ Foam::cvControls::cvControls
surfDict.subDict("conformationControls")
);
surfacePtExclusionDistanceCoeff_ = readScalar
(
conformationControlsDict.lookup("surfacePtExclusionDistanceCoeff")
);
surfacePtExclusionDistanceCoeff_ =
conformationControlsDict.get<scalar>("surfacePtExclusionDistanceCoeff");
edgeSearchDistCoeffSqr_ = sqr
(
readScalar
(
conformationControlsDict.lookup("edgeSearchDistCoeff")
)
conformationControlsDict.get<scalar>("edgeSearchDistCoeff")
);
surfacePtReplaceDistCoeffSqr_ = sqr