STYLE: use readIfPresent instead of found/lookup combination

This commit is contained in:
Mark Olesen
2010-05-20 08:52:45 +02:00
parent 227631742d
commit 9525d57d71
18 changed files with 114 additions and 162 deletions

View File

@ -29,14 +29,9 @@ License
#include "volFields.H" #include "volFields.H"
#include "mathematicalConstants.H" #include "mathematicalConstants.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
smoluchowskiJumpTFvPatchScalarField::smoluchowskiJumpTFvPatchScalarField Foam::smoluchowskiJumpTFvPatchScalarField::smoluchowskiJumpTFvPatchScalarField
( (
const fvPatch& p, const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF const DimensionedField<scalar, volMesh>& iF
@ -52,7 +47,8 @@ smoluchowskiJumpTFvPatchScalarField::smoluchowskiJumpTFvPatchScalarField
valueFraction() = 0.0; valueFraction() = 0.0;
} }
smoluchowskiJumpTFvPatchScalarField::smoluchowskiJumpTFvPatchScalarField
Foam::smoluchowskiJumpTFvPatchScalarField::smoluchowskiJumpTFvPatchScalarField
( (
const smoluchowskiJumpTFvPatchScalarField& ptf, const smoluchowskiJumpTFvPatchScalarField& ptf,
const fvPatch& p, const fvPatch& p,
@ -67,7 +63,7 @@ smoluchowskiJumpTFvPatchScalarField::smoluchowskiJumpTFvPatchScalarField
{} {}
smoluchowskiJumpTFvPatchScalarField::smoluchowskiJumpTFvPatchScalarField Foam::smoluchowskiJumpTFvPatchScalarField::smoluchowskiJumpTFvPatchScalarField
( (
const fvPatch& p, const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF, const DimensionedField<scalar, volMesh>& iF,
@ -118,7 +114,7 @@ smoluchowskiJumpTFvPatchScalarField::smoluchowskiJumpTFvPatchScalarField
} }
smoluchowskiJumpTFvPatchScalarField::smoluchowskiJumpTFvPatchScalarField Foam::smoluchowskiJumpTFvPatchScalarField::smoluchowskiJumpTFvPatchScalarField
( (
const smoluchowskiJumpTFvPatchScalarField& ptpsf, const smoluchowskiJumpTFvPatchScalarField& ptpsf,
const DimensionedField<scalar, volMesh>& iF const DimensionedField<scalar, volMesh>& iF
@ -134,7 +130,7 @@ smoluchowskiJumpTFvPatchScalarField::smoluchowskiJumpTFvPatchScalarField
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// Map from self // Map from self
void smoluchowskiJumpTFvPatchScalarField::autoMap void Foam::smoluchowskiJumpTFvPatchScalarField::autoMap
( (
const fvPatchFieldMapper& m const fvPatchFieldMapper& m
) )
@ -144,7 +140,7 @@ void smoluchowskiJumpTFvPatchScalarField::autoMap
// Reverse-map the given fvPatchField onto this fvPatchField // Reverse-map the given fvPatchField onto this fvPatchField
void smoluchowskiJumpTFvPatchScalarField::rmap void Foam::smoluchowskiJumpTFvPatchScalarField::rmap
( (
const fvPatchField<scalar>& ptf, const fvPatchField<scalar>& ptf,
const labelList& addr const labelList& addr
@ -155,7 +151,7 @@ void smoluchowskiJumpTFvPatchScalarField::rmap
// Update the coefficients associated with the patch field // Update the coefficients associated with the patch field
void smoluchowskiJumpTFvPatchScalarField::updateCoeffs() void Foam::smoluchowskiJumpTFvPatchScalarField::updateCoeffs()
{ {
if (updated()) if (updated())
{ {
@ -174,11 +170,16 @@ void smoluchowskiJumpTFvPatchScalarField::updateCoeffs()
// Prandtl number reading consistent with rhoCentralFoam // Prandtl number reading consistent with rhoCentralFoam
const dictionary& thermophysicalProperties = const dictionary& thermophysicalProperties =
db().lookupObject<IOdictionary>("thermophysicalProperties"); db().lookupObject<IOdictionary>("thermophysicalProperties");
dimensionedScalar Pr = dimensionedScalar("Pr", dimless, 1.0);
if (thermophysicalProperties.found("Pr")) dimensionedScalar Pr
{ (
Pr = thermophysicalProperties.lookup("Pr"); dimensionedScalar::lookupOrDefault
} (
"Pr",
thermophysicalProperties,
1.0
)
);
Field<scalar> C2 = pmu/prho Field<scalar> C2 = pmu/prho
*sqrt(ppsi*constant::mathematical::piByTwo) *sqrt(ppsi*constant::mathematical::piByTwo)
@ -197,7 +198,7 @@ void smoluchowskiJumpTFvPatchScalarField::updateCoeffs()
// Write // Write
void smoluchowskiJumpTFvPatchScalarField::write(Ostream& os) const void Foam::smoluchowskiJumpTFvPatchScalarField::write(Ostream& os) const
{ {
fvPatchScalarField::write(os); fvPatchScalarField::write(os);
os.writeKeyword("accommodationCoeff") os.writeKeyword("accommodationCoeff")
@ -211,10 +212,12 @@ void smoluchowskiJumpTFvPatchScalarField::write(Ostream& os) const
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
makePatchTypeField(fvPatchScalarField, smoluchowskiJumpTFvPatchScalarField); makePatchTypeField(fvPatchScalarField, smoluchowskiJumpTFvPatchScalarField);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // }
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -1,7 +1,6 @@
word fluxScheme("Kurganov"); word fluxScheme("Kurganov");
if (mesh.schemesDict().found("fluxScheme")) if (mesh.schemesDict().readIfPresent("fluxScheme", fluxScheme))
{ {
fluxScheme = word(mesh.schemesDict().lookup("fluxScheme"));
if ((fluxScheme == "Tadmor") || (fluxScheme == "Kurganov")) if ((fluxScheme == "Tadmor") || (fluxScheme == "Kurganov"))
{ {
Info<< "fluxScheme: " << fluxScheme << endl; Info<< "fluxScheme: " << fluxScheme << endl;

View File

@ -14,9 +14,13 @@ IOdictionary thermophysicalProperties
) )
); );
dimensionedScalar Pr = dimensionedScalar("Pr", dimless, 1.0); dimensionedScalar Pr
(
dimensionedScalar::lookupOrDefault
(
"Pr",
thermophysicalProperties,
1.0
)
);
if (thermophysicalProperties.found("Pr"))
{
Pr = thermophysicalProperties.lookup("Pr");
}

View File

@ -26,8 +26,13 @@
dimensionedScalar gamma = Cp/Cv; dimensionedScalar gamma = Cp/Cv;
dimensionedScalar Pr = dimensionedScalar("Pr", dimless, 1.0); dimensionedScalar Pr
if (thermodynamicProperties.found("Pr")) (
{ dimensionedScalar::lookupOrDefault
Pr = thermodynamicProperties.lookup("Pr"); (
} "Pr",
thermodynamicProperties,
1.0
)
);

View File

@ -175,10 +175,8 @@
); );
word dragPhase("blended"); word dragPhase("blended");
if (interfacialProperties.found("dragPhase")) if (interfacialProperties.readIfPresent("dragPhase", dragPhase))
{ {
dragPhase = word(interfacialProperties.lookup("dragPhase"));
bool validDrag = bool validDrag =
dragPhase == "a" || dragPhase == "b" || dragPhase == "blended"; dragPhase == "a" || dragPhase == "b" || dragPhase == "blended";

View File

@ -110,11 +110,7 @@ Foam::domainDecomposition::domainDecomposition(const IOobject& io)
procProcessorPatchStartIndex_(nProcs_), procProcessorPatchStartIndex_(nProcs_),
cyclicParallel_(false) cyclicParallel_(false)
{ {
if (decompositionDict_.found("distributed")) decompositionDict_.readIfPresent("distributed", distributed_);
{
Switch distributed(decompositionDict_.lookup("distributed"));
distributed_ = distributed;
}
} }

View File

@ -43,10 +43,10 @@ namespace Foam
addToRunTimeSelectionTable(polyPatch, cyclicPolyPatch, word); addToRunTimeSelectionTable(polyPatch, cyclicPolyPatch, word);
addToRunTimeSelectionTable(polyPatch, cyclicPolyPatch, dictionary); addToRunTimeSelectionTable(polyPatch, cyclicPolyPatch, dictionary);
}
template<> template<>
const char* NamedEnum<cyclicPolyPatch::transformType, 4>::names[] = const char* Foam::NamedEnum<Foam::cyclicPolyPatch::transformType, 4>::names[] =
{ {
"unknown", "unknown",
"rotational", "rotational",
@ -54,9 +54,8 @@ const char* NamedEnum<cyclicPolyPatch::transformType, 4>::names[] =
"noOrdering" "noOrdering"
}; };
const NamedEnum<cyclicPolyPatch::transformType, 4> const Foam::NamedEnum<Foam::cyclicPolyPatch::transformType, 4>
cyclicPolyPatch::transformTypeNames; Foam::cyclicPolyPatch::transformTypeNames;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -45,10 +45,7 @@ Foam::fvMotionSolverEngineMesh::fvMotionSolverEngineMesh(const IOobject& io)
pistonLayers_("pistonLayers", dimLength, 0.0), pistonLayers_("pistonLayers", dimLength, 0.0),
motionSolver_(*this, engineDB_.engineDict().lookup("motionSolver")) motionSolver_(*this, engineDB_.engineDict().lookup("motionSolver"))
{ {
if (engineDB_.engineDict().found("pistonLayers")) engineDB_.engineDict().readIfPresent("pistonLayers", pistonLayers_);
{
engineDB_.engineDict().lookup("pistonLayers") >> pistonLayers_;
}
} }

View File

@ -44,10 +44,7 @@ Foam::layeredEngineMesh::layeredEngineMesh(const IOobject& io)
engineMesh(io), engineMesh(io),
pistonLayers_("pistonLayers", dimLength, 0.0) pistonLayers_("pistonLayers", dimLength, 0.0)
{ {
if (engineDB_.engineDict().found("pistonLayers")) engineDB_.engineDict().readIfPresent("pistonLayers", pistonLayers_);
{
engineDB_.engineDict().lookup("pistonLayers") >> pistonLayers_;
}
} }

View File

@ -80,10 +80,7 @@ freestreamFvPatchField<Type>::freestreamFvPatchField
fvPatchField<Type>::operator=(freestreamValue()); fvPatchField<Type>::operator=(freestreamValue());
} }
if (dict.found("phi")) dict.readIfPresent("phi", this->phiName_);
{
dict.lookup("phi") >> this->phiName_;
}
} }

View File

@ -130,10 +130,7 @@ timeVaryingMappedFixedValueFvPatchField
<< endl; << endl;
} }
if (dict.found("fieldTableName")) dict.readIfPresent("fieldTableName", fieldTableName_);
{
dict.lookup("fieldTableName") >> fieldTableName_;
}
if (dict.found("value")) if (dict.found("value"))
{ {

View File

@ -229,18 +229,12 @@ void Foam::potential::potential::readPotentialDict()
if (potentialDict.found("external")) if (potentialDict.found("external"))
{ {
Info<< nl << "Reading external forces:" << endl; Info<< nl << "Reading external forces:" << endl;
const dictionary& externalDict = potentialDict.subDict("external"); const dictionary& externalDict = potentialDict.subDict("external");
// *********************************************************************
// gravity // gravity
externalDict.readIfPresent("gravity", gravity_);
if (externalDict.found("gravity"))
{
gravity_ = externalDict.lookup("gravity");
}
} }
Info<< nl << tab << "gravity = " << gravity_ << endl; Info<< nl << tab << "gravity = " << gravity_ << endl;

View File

@ -218,10 +218,7 @@ Foam::layerParameters::layerParameters
<< endl; << endl;
} }
if (dict.found("nRelaxedIter")) dict.readIfPresent("nRelaxedIter", nRelaxedIter_);
{
dict.lookup("nRelaxedIter") >> nRelaxedIter_;
}
if (nLayerIter_ < 0 || nRelaxedIter_ < 0) if (nLayerIter_ < 0 || nRelaxedIter_ < 0)
{ {
@ -303,10 +300,8 @@ Foam::layerParameters::layerParameters
<< endl; << endl;
} }
if (dict.found("nRelaxedIter")) dict.readIfPresent("nRelaxedIter", nRelaxedIter_);
{
dict.lookup("nRelaxedIter") >> nRelaxedIter_;
}
if (nLayerIter_ < 0 || nRelaxedIter_ < 0) if (nLayerIter_ < 0 || nRelaxedIter_ < 0)
{ {
FatalErrorIn("layerParameters::layerParameters(..)") FatalErrorIn("layerParameters::layerParameters(..)")

View File

@ -522,11 +522,9 @@ Foam::labelList Foam::meshRefinement::markFacesOnProblemCells
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Collapse checking parameters // Collapse checking parameters
scalar volFraction = -1; const scalar volFraction =
if (motionDict.found("minVolCollapseRatio")) motionDict.lookupOrDefault<scalar>("minVolCollapseRatio", -1);
{
volFraction = readScalar(motionDict.lookup("minVolCollapseRatio"));
}
const bool checkCollapse = (volFraction > 0); const bool checkCollapse = (volFraction > 0);
scalar minArea = -1; scalar minArea = -1;
scalar maxNonOrtho = -1; scalar maxNonOrtho = -1;

View File

@ -151,17 +151,10 @@ Foam::refinementSurfaces::refinementSurfaces
} }
// Global perpendicular angle // Global perpendicular angle
if (dict.found("perpendicularAngle")) dict.readIfPresent("perpendicularAngle", globalAngle[surfI]);
{
globalAngle[surfI] = readScalar(dict.lookup("perpendicularAngle"));
}
//// Global patch name per surface //// Global patch name per surface
//if (dict.found("patchType")) //dict.readIfPresent("patchType", globalPatchType[surfI]);
//{
// dict.lookup("patchType") >> globalPatchType[surfI];
//}
if (dict.found("regions")) if (dict.found("regions"))
{ {
@ -446,13 +439,7 @@ Foam::refinementSurfaces::refinementSurfaces
} }
// Global perpendicular angle // Global perpendicular angle
if (dict.found("perpendicularAngle")) dict.readIfPresent("perpendicularAngle", globalAngle[surfI]);
{
globalAngle[surfI] = readScalar
(
dict.lookup("perpendicularAngle")
);
}
if (dict.found("regions")) if (dict.found("regions"))
{ {

View File

@ -178,45 +178,39 @@ Foam::label Foam::ptscotchDecomp::decompose
// const dictionary& scotchCoeffs = // const dictionary& scotchCoeffs =
// decompositionDict_.subDict("ptscotchCoeffs"); // decompositionDict_.subDict("ptscotchCoeffs");
// //
// if (scotchCoeffs.found("writeGraph")) // if (scotchCoeffs.lookupOrDefault("writeGraph", false))
// { // {
// Switch writeGraph(scotchCoeffs.lookup("writeGraph")); // OFstream str(mesh_.time().path() / mesh_.name() + ".grf");
// //
// if (writeGraph) // Info<< "Dumping Scotch graph file to " << str.name() << endl
// << "Use this in combination with gpart." << endl;
//
// label version = 0;
// str << version << nl;
// // Numer of vertices
// str << xadj.size()-1 << ' ' << adjncy.size() << nl;
// // Numbering starts from 0
// label baseval = 0;
// // Has weights?
// label hasEdgeWeights = 0;
// label hasVertexWeights = 0;
// label numericflag = 10*hasEdgeWeights+hasVertexWeights;
// str << baseval << ' ' << numericflag << nl;
// for (label cellI = 0; cellI < xadj.size()-1; cellI++)
// { // {
// OFstream str(mesh_.time().path() / mesh_.name() + ".grf"); // label start = xadj[cellI];
// label end = xadj[cellI+1];
// str << end-start;
// //
// Info<< "Dumping Scotch graph file to " << str.name() << endl // for (label i = start; i < end; i++)
// << "Use this in combination with gpart." << endl;
//
// label version = 0;
// str << version << nl;
// // Numer of vertices
// str << xadj.size()-1 << ' ' << adjncy.size() << nl;
// // Numbering starts from 0
// label baseval = 0;
// // Has weights?
// label hasEdgeWeights = 0;
// label hasVertexWeights = 0;
// label numericflag = 10*hasEdgeWeights+hasVertexWeights;
// str << baseval << ' ' << numericflag << nl;
// for (label cellI = 0; cellI < xadj.size()-1; cellI++)
// { // {
// label start = xadj[cellI]; // str << ' ' << adjncy[i];
// label end = xadj[cellI+1];
// str << end-start;
//
// for (label i = start; i < end; i++)
// {
// str << ' ' << adjncy[i];
// }
// str << nl;
// } // }
// str << nl;
// } // }
// } // }
// } // }
// Strategy // Strategy
// ~~~~~~~~ // ~~~~~~~~

View File

@ -178,40 +178,35 @@ Foam::label Foam::scotchDecomp::decompose
const dictionary& scotchCoeffs = const dictionary& scotchCoeffs =
decompositionDict_.subDict("scotchCoeffs"); decompositionDict_.subDict("scotchCoeffs");
if (scotchCoeffs.found("writeGraph")) if (scotchCoeffs.lookupOrDefault("writeGraph", false))
{ {
Switch writeGraph(scotchCoeffs.lookup("writeGraph")); OFstream str(mesh_.time().path() / mesh_.name() + ".grf");
if (writeGraph) Info<< "Dumping Scotch graph file to " << str.name() << endl
<< "Use this in combination with gpart." << endl;
label version = 0;
str << version << nl;
// Numer of vertices
str << xadj.size()-1 << ' ' << adjncy.size() << nl;
// Numbering starts from 0
label baseval = 0;
// Has weights?
label hasEdgeWeights = 0;
label hasVertexWeights = 0;
label numericflag = 10*hasEdgeWeights+hasVertexWeights;
str << baseval << ' ' << numericflag << nl;
for (label cellI = 0; cellI < xadj.size()-1; cellI++)
{ {
OFstream str(mesh_.time().path() / mesh_.name() + ".grf"); label start = xadj[cellI];
label end = xadj[cellI+1];
str << end-start;
Info<< "Dumping Scotch graph file to " << str.name() << endl for (label i = start; i < end; i++)
<< "Use this in combination with gpart." << endl;
label version = 0;
str << version << nl;
// Numer of vertices
str << xadj.size()-1 << ' ' << adjncy.size() << nl;
// Numbering starts from 0
label baseval = 0;
// Has weights?
label hasEdgeWeights = 0;
label hasVertexWeights = 0;
label numericflag = 10*hasEdgeWeights+hasVertexWeights;
str << baseval << ' ' << numericflag << nl;
for (label cellI = 0; cellI < xadj.size()-1; cellI++)
{ {
label start = xadj[cellI]; str << ' ' << adjncy[i];
label end = xadj[cellI+1];
str << end-start;
for (label i = start; i < end; i++)
{
str << ' ' << adjncy[i];
}
str << nl;
} }
str << nl;
} }
} }
} }
@ -229,7 +224,6 @@ Foam::label Foam::scotchDecomp::decompose
const dictionary& scotchCoeffs = const dictionary& scotchCoeffs =
decompositionDict_.subDict("scotchCoeffs"); decompositionDict_.subDict("scotchCoeffs");
string strategy; string strategy;
if (scotchCoeffs.readIfPresent("strategy", strategy)) if (scotchCoeffs.readIfPresent("strategy", strategy))
{ {

View File

@ -76,11 +76,9 @@ sixDoFRigidBodyDisplacementPointPatchVectorField
rhoInf_ = readScalar(dict.lookup("rhoInf")); rhoInf_ = readScalar(dict.lookup("rhoInf"));
} }
if (dict.found("g")) if (dict.readIfPresent("g", g_))
{ {
lookupGravity_ = -2; lookupGravity_ = -2;
g_ = dict.lookup("g");
} }
if (!dict.found("value")) if (!dict.found("value"))