Commit a48bc874 authored by Mark Olesen's avatar Mark Olesen
Browse files

use dictionary::readIfPresent wherever reasonable

parent 7f963163
......@@ -83,10 +83,7 @@ bool Foam::IOobject::readHeader(Istream& is)
}
// The note entry is optional
if (headerDict.found("note"))
{
note_ = string(headerDict.lookup("note"));
}
headerDict.readIfPresent("note", note_);
}
else
{
......
......@@ -49,7 +49,6 @@ bool Foam::IOobject::writeHeader(Ostream& os) const
<< " format " << os.format() << ";\n"
<< " class " << type() << ";\n";
// outdent for visibility and more space
if (note().size())
{
os << " note " << note() << ";\n";
......
......@@ -101,14 +101,12 @@ void Foam::Time::setControls()
{
// default is to resume calculation from "latestTime"
word startFrom("latestTime");
if (controlDict_.found("startFrom"))
{
controlDict_.lookup("startFrom") >> startFrom;
}
controlDict_.readIfPresent("startFrom", startFrom);
if (startFrom == "startTime")
{
startTime_ = readScalar(controlDict_.lookup("startTime"));
controlDict_.lookup("startTime") >> startTime_;
}
else
{
......@@ -158,7 +156,7 @@ void Foam::Time::setControls()
FatalErrorIn("Time::setControls()")
<< "Start time is not the same for all processors" << nl
<< "processor " << Pstream::myProcNo() << " has startTime "
<< startTime_ << exit(FatalError);
<< startTime_ << exit(FatalError);
}
}
......@@ -176,15 +174,13 @@ void Foam::Time::setControls()
)
);
if (timeDict.found("deltaT"))
if (timeDict.readIfPresent("deltaT", deltaTSave_))
{
deltaTSave_ = readScalar(timeDict.lookup("deltaT"));
deltaT0_ = deltaTSave_;
}
if (timeDict.found("index"))
if (timeDict.readIfPresent("index", startTimeIndex_))
{
timeDict.lookup("index") >> startTimeIndex_;
timeIndex_ = startTimeIndex_;
}
}
......@@ -503,20 +499,9 @@ void Foam::Time::setTime(const instant& inst, const label newIndex)
)
);
if (timeDict.found("deltaT"))
{
deltaT_ = readScalar(timeDict.lookup("deltaT"));
}
if (timeDict.found("deltaT0"))
{
deltaT0_ = readScalar(timeDict.lookup("deltaT0"));
}
if (timeDict.found("index"))
{
timeIndex_ = readLabel(timeDict.lookup("index"));
}
timeDict.readIfPresent("deltaT", deltaT_);
timeDict.readIfPresent("deltaT0", deltaT0_);
timeDict.readIfPresent("index", timeIndex_);
}
......@@ -647,7 +632,7 @@ Foam::Time& Foam::Time::operator++()
case wcRunTime:
case wcAdjustableRunTime:
{
label outputTimeIndex =
label outputTimeIndex =
label(((value() - startTime_) + 0.5*deltaT_)/writeInterval_);
if (outputTimeIndex > outputTimeIndex_)
......
......@@ -44,10 +44,8 @@ void Foam::Time::readDict()
);
}
if (controlDict_.found("writeInterval"))
if (controlDict_.readIfPresent("writeInterval", writeInterval_))
{
controlDict_.lookup("writeInterval") >> writeInterval_;
if (writeControl_ == wcTimeStep && label(writeInterval_) < 1)
{
FatalIOErrorIn("Time::readDict()", controlDict_)
......@@ -60,10 +58,8 @@ void Foam::Time::readDict()
controlDict_.lookup("writeFrequency") >> writeInterval_;
}
if (controlDict_.found("purgeWrite"))
if (controlDict_.readIfPresent("purgeWrite", purgeWrite_))
{
purgeWrite_ = readInt(controlDict_.lookup("purgeWrite"));
if (purgeWrite_ < 0)
{
WarningIn("Time::readDict()")
......@@ -106,10 +102,7 @@ void Foam::Time::readDict()
}
}
if (controlDict_.found("timePrecision"))
{
precision_ = readLabel(controlDict_.lookup("timePrecision"));
}
controlDict_.readIfPresent("timePrecision", precision_);
// stopAt at 'endTime' or a specified value
// if nothing is specified, the endTime is zero
......@@ -119,18 +112,14 @@ void Foam::Time::readDict()
if (stopAt_ == saEndTime)
{
endTime_ = readScalar(controlDict_.lookup("endTime"));
controlDict_.lookup("endTime") >> endTime_;
}
else
{
endTime_ = GREAT;
}
}
else if (controlDict_.found("endTime"))
{
endTime_ = readScalar(controlDict_.lookup("endTime"));
}
else
else if (!controlDict_.readIfPresent("endTime", endTime_))
{
endTime_ = 0;
}
......@@ -175,10 +164,7 @@ void Foam::Time::readDict()
);
}
if (controlDict_.found("graphFormat"))
{
graphFormat_ = word(controlDict_.lookup("graphFormat"));
}
controlDict_.readIfPresent("graphFormat", graphFormat_);
if (controlDict_.found("runTimeModifiable"))
{
......
......@@ -87,8 +87,7 @@ class lduMatrix
public:
//- Class returned by the solver
// containing performance statistics
//- Class returned by the solver, containing performance statistics
class solverPerformance
{
word solverName_;
......@@ -237,16 +236,6 @@ public:
// Protected Member Functions
//- Read a control parameter from controlDict
template<class T>
inline void readControl
(
const dictionary& controlDict,
T& control,
const word& controlName
);
//- Read the control parameters from the controlDict_
virtual void readControls();
......@@ -318,7 +307,6 @@ public:
Istream& solverData
);
// Selectors
//- Return a new solver
......@@ -333,6 +321,7 @@ public:
);
// Destructor
virtual ~solver()
......@@ -749,7 +738,7 @@ public:
const lduInterfaceFieldPtrsList&,
const direction cmpt
) const;
//- Matrix transpose multiplication with updated interfaces.
void Tmul
(
......@@ -800,7 +789,7 @@ public:
scalarField& result,
const direction cmpt
) const;
//- Update interfaced interfaces for matrix operations
void updateMatrixInterfaces
(
......@@ -810,7 +799,7 @@ public:
scalarField& result,
const direction cmpt
) const;
template<class Type>
tmp<Field<Type> > H(const Field<Type>&) const;
......
......@@ -171,9 +171,9 @@ Foam::lduMatrix::solver::solver
void Foam::lduMatrix::solver::readControls()
{
readControl(controlDict_, maxIter_, "maxIter");
readControl(controlDict_, tolerance_, "tolerance");
readControl(controlDict_, relTol_, "relTol");
controlDict_.readIfPresent("maxIter", maxIter_);
controlDict_.readIfPresent("tolerance", tolerance_);
controlDict_.readIfPresent("relTol", relTol_);
}
......
......@@ -31,21 +31,6 @@ Description
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class T>
inline void Foam::lduMatrix::solver::readControl
(
const dictionary& controlDict,
T& control,
const word& controlName
)
{
if (controlDict.found(controlName))
{
controlDict.lookup(controlName) >> control;
}
}
template<class Type>
Foam::tmp<Foam::Field<Type> > Foam::lduMatrix::H(const Field<Type>& psi) const
{
......
......@@ -75,7 +75,7 @@ Foam::GAMGPreconditioner::~GAMGPreconditioner()
void Foam::GAMGPreconditioner::readControls()
{
GAMGSolver::readControls();
readControl(controlDict_, nVcycles_, "nVcycles");
controlDict_.readIfPresent("nVcycles", nVcycles_);
}
......
......@@ -154,13 +154,12 @@ void Foam::GAMGSolver::readControls()
{
lduMatrix::solver::readControls();
readControl(controlDict_, cacheAgglomeration_, "cacheAgglomeration");
readControl(controlDict_, nPreSweeps_, "nPreSweeps");
readControl(controlDict_, nPostSweeps_, "nPostSweeps");
readControl(controlDict_, nFinestSweeps_, "nFinestSweeps");
readControl(controlDict_, scaleCorrection_, "scaleCorrection");
readControl(controlDict_, directSolveCoarsest_, "directSolveCoarsest");
controlDict_.readIfPresent("cacheAgglomeration", cacheAgglomeration_);
controlDict_.readIfPresent("nPreSweeps", nPreSweeps_);
controlDict_.readIfPresent("nPostSweeps", nPostSweeps_);
controlDict_.readIfPresent("nFinestSweeps", nFinestSweeps_);
controlDict_.readIfPresent("scaleCorrection", scaleCorrection_);
controlDict_.readIfPresent("directSolveCoarsest", directSolveCoarsest_);
}
......
......@@ -72,7 +72,7 @@ Foam::smoothSolver::smoothSolver
void Foam::smoothSolver::readControls()
{
lduMatrix::solver::readControls();
readControl(controlDict_, nSweeps_, "nSweeps");
controlDict_.readIfPresent("nSweeps", nSweeps_);
}
......
......@@ -97,7 +97,7 @@ public:
const dictionary& solverDict(const word& name) const;
//- Return the stream of solver parameters for the given field
// (Provided for backward compatibility only)
// @deprecated Backward compatibility only - should use solverDict
ITstream& solver(const word& name) const;
......
......@@ -52,10 +52,7 @@ Foam::patchIdentifier::patchIdentifier
name_(name),
boundaryIndex_(index)
{
if (dict.found("physicalType"))
{
dict.lookup("physicalType") >> physicalType_;
}
dict.readIfPresent("physicalType", physicalType_);
}
......
......@@ -622,10 +622,8 @@ Foam::cyclicPolyPatch::cyclicPolyPatch
rotationAxis_(vector::zero),
rotationCentre_(point::zero)
{
if (dict.found("featureCos"))
{
dict.lookup("featureCos") >> featureCos_;
}
dict.readIfPresent("featureCos", featureCos_);
if (dict.found("transform"))
{
transform_ = transformTypeNames.read(dict.lookup("transform"));
......
......@@ -27,14 +27,9 @@ License
#include "polyPatch.H"
#include "dictionary.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
autoPtr<polyPatch> polyPatch::New
Foam::autoPtr<Foam::polyPatch> Foam::polyPatch::New
(
const word& patchType,
const word& name,
......@@ -72,7 +67,7 @@ autoPtr<polyPatch> polyPatch::New
}
autoPtr<polyPatch> polyPatch::New
Foam::autoPtr<Foam::polyPatch> Foam::polyPatch::New
(
const word& name,
const dictionary& dict,
......@@ -89,10 +84,7 @@ autoPtr<polyPatch> polyPatch::New
word patchType(dict.lookup("type"));
if (dict.found("geometricType"))
{
dict.lookup("geometricType") >> patchType;
}
dict.readIfPresent("geometricType", patchType);
dictionaryConstructorTable::iterator cstrIter =
dictionaryConstructorTablePtr_->find(patchType);
......@@ -124,8 +116,4 @@ autoPtr<polyPatch> polyPatch::New
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //
......@@ -77,19 +77,14 @@ void Foam::preservePatchTypes
const dictionary& patchDict =
patchDictionary.subDict(patchNames[patchi]);
patchTypes[patchi] = word(patchDict.lookup("type"));
if (patchDict.found("geometricType"))
{
patchTypes[patchi] =
word(patchDict.lookup("geometricType"));
}
if (patchDict.found("physicalType"))
{
patchPhysicalTypes[patchi] =
word(patchDict.lookup("physicalType"));
}
patchDict.lookup("type") >> patchTypes[patchi];
patchDict.readIfPresent("geometricType", patchTypes[patchi]);
patchDict.readIfPresent
(
"physicalType",
patchPhysicalTypes[patchi]
);
}
}
......@@ -98,10 +93,7 @@ void Foam::preservePatchTypes
const dictionary& patchDict =
patchDictionary.subDict(defaultFacesName);
if (patchDict.found("geometricType"))
{
defaultFacesType = word(patchDict.lookup("geometricType"));
}
patchDict.readIfPresent("geometricType", defaultFacesType);
}
}
......
......@@ -175,9 +175,7 @@ Foam::layerParameters::layerParameters
featureAngle_(readScalar(dict.lookup("featureAngle"))),
concaveAngle_
(
dict.found("concaveAngle")
? readScalar(dict.lookup("concaveAngle"))
: defaultConcaveAngle
dict.lookupOrDefault("concaveAngle", defaultConcaveAngle)
),
nGrow_(readLabel(dict.lookup("nGrow"))),
nSmoothSurfaceNormals_
......@@ -242,9 +240,7 @@ Foam::layerParameters::layerParameters
featureAngle_(readScalar(dict.lookup("featureAngle"))),
concaveAngle_
(
dict.found("concaveAngle")
? readScalar(dict.lookup("concaveAngle"))
: defaultConcaveAngle
dict.lookupOrDefault("concaveAngle", defaultConcaveAngle)
),
nGrow_(readLabel(dict.lookup("nGrow"))),
nSmoothSurfaceNormals_
......
......@@ -171,14 +171,10 @@ void Foam::ensightPart::reconstruct(Istream& is)
forAll(elementTypes(), elemI)
{
word key(elementTypes()[elemI]);
if (dict.found(key))
{
dict.lookup(key) >> elemLists_[elemI];
}
else
{
elemLists_[elemI].clear();
}
elemLists_[elemI].clear();
dict.readIfPresent(key, elemLists_[elemI]);
size_ += elemLists_[elemI].size();
}
......
......@@ -745,17 +745,17 @@ void Foam::meshReaders::STARCD::readBoundary(const fileName& inputName)
iter != boundaryRegion_.end()
)
{
if (iter().found("BoundaryType"))
{
iter().lookup("BoundaryType") >> patchTypes_[patchI];
foundType = true;
}
if (iter().found("Label"))
{
iter().lookup("Label") >> patchNames_[patchI];
foundName = true;
}
foundType = iter().readIfPresent
(
"BoundaryType",
patchTypes_[patchI]
);
foundName = iter().readIfPresent
(
"Label",
patchNames_[patchI]
);
}
// consistent names, in long form and in lowercase
......
......@@ -69,7 +69,7 @@ Foam::label Foam::metisDecomp::decompose
// Method of decomposition
// recursive: multi-level recursive bisection (default)
// k-way: multi-level k-way
// k-way: multi-level k-way
word method("k-way");
// decomposition options. 0 = use defaults
......@@ -88,15 +88,12 @@ Foam::label Foam::metisDecomp::decompose
// Check for user supplied weights and decomp options
if (decompositionDict_.found("metisCoeffs"))
{
dictionary metisDecompCoeffs
(
decompositionDict_.subDict("metisCoeffs")
);
const dictionary& metisCoeffs =
decompositionDict_.subDict("metisCoeffs");
word weightsFile;
if (metisDecompCoeffs.found("method"))
if (metisCoeffs.readIfPresent("method", method))
{
metisDecompCoeffs.lookup("method") >> method;
if (method != "recursive" && method != "k-way")
{
FatalErrorIn("metisDecomp::decompose()")
......@@ -106,14 +103,12 @@ Foam::label Foam::metisDecomp::decompose
<< exit(FatalError);
}
Info<< "metisDecomp : Using Metis options " << options
<< endl << endl;
Info<< "metisDecomp : Using Metis method " << method
<< nl << endl;
}
if (metisDecompCoeffs.found("options"))
if (metisCoeffs.readIfPresent("options", options))
{
metisDecompCoeffs.lookup("options") >> options;
if (options.size() != 5)
{
FatalErrorIn("metisDecomp::decompose()")
......@@ -124,12 +119,11 @@ Foam::label Foam::metisDecomp::decompose
}
Info<< "metisDecomp : Using Metis options " << options
<< endl << endl;
<< nl << endl;
}
if (metisDecompCoeffs.found("processorWeights"))
if (metisCoeffs.readIfPresent("processorWeights", processorWeights))
{
metisDecompCoeffs.lookup("processorWeights") >> processorWeights;
processorWeights /= sum(processorWeights);
if (processorWeights.size() != nProcessors_)
......@@ -142,20 +136,15 @@ Foam::label Foam::metisDecomp::decompose
}
}
if (metisDecompCoeffs.found("cellWeightsFile"))
if (metisCoeffs.readIfPresent("cellWeightsFile", weightsFile))
{
Info<< "metisDecomp : Using cell-based weights." << endl;
word cellWeightsFile
(
metisDecompCoeffs.lookup("cellWeightsFile")
);
IOList<int> cellIOWeights
(
IOobject
(
cellWeightsFile,
weightsFile,
mesh_.time().timeName(),
mesh_,
IOobject::MUST_READ,
......@@ -174,20 +163,15 @@ Foam::label Foam::metisDecomp::decompose
}
//- faceWeights disabled. Only makes sense for cellCells from mesh.
//if (metisDecompCoeffs.found("faceWeightsFile"))
//if (metisCoeffs.readIfPresent("faceWeightsFile", weightsFile))
//{
// Info<< "metisDecomp : Using face-based weights." << endl;
//
// word faceWeightsFile
// (
// metisDecompCoeffs.lookup("faceWeightsFile")
// );
//