Skip to content

Commit

Permalink
typeIOobject: Template typed form of IOobject for type-checked object…
Browse files Browse the repository at this point in the history
… file and header reading

used to check the existence of and open an object file, read and check the
header without constructing the object.

'typeIOobject' operates in an equivalent and consistent manner to 'regIOobject'
but the type information is provided by the template argument rather than via
virtual functions for which the derived object would need to be constructed,
which is the case for 'regIOobject'.

'typeIOobject' replaces the previous separate functions 'typeHeaderOk' and
'typeFilePath' with a single consistent interface.
  • Loading branch information
Henry Weller committed Aug 12, 2021
1 parent 0a3a631 commit b912332
Show file tree
Hide file tree
Showing 114 changed files with 515 additions and 476 deletions.
4 changes: 2 additions & 2 deletions applications/solvers/electromagnetics/mhdFoam/createPhiB.H
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
IOobject phiBHeader
typeIOobject<surfaceScalarField> phiBHeader
(
"phiB",
runTime.timeName(),
Expand All @@ -9,7 +9,7 @@ IOobject phiBHeader

surfaceScalarField* phiBPtr = nullptr;

if (phiBHeader.typeHeaderOk<surfaceScalarField>(true))
if (phiBHeader.headerOk())
{
Info<< "Reading face flux ";

Expand Down
8 changes: 4 additions & 4 deletions applications/solvers/lagrangian/particleFoam/createFields.H
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ volScalarField mu
Info<< "Constructing clouds" << endl;
parcelCloudList clouds(rhoInf, U, mu, g);

IOobject Hheader
typeIOobject<volVectorField> Hheader
(
"H",
runTime.timeName(),
Expand All @@ -67,14 +67,14 @@ IOobject Hheader

autoPtr<volVectorField> HPtr;

if (Hheader.typeHeaderOk<volVectorField>(true))
if (Hheader.headerOk())
{
Info<< "\nReading field H\n" << endl;

HPtr.reset(new volVectorField (Hheader, mesh));
}

IOobject HdotGradHheader
typeIOobject<volVectorField> HdotGradHheader
(
"HdotGradH",
runTime.timeName(),
Expand All @@ -85,7 +85,7 @@ IOobject HdotGradHheader

autoPtr<volVectorField> HdotGradHPtr;

if (HdotGradHheader.typeHeaderOk<volVectorField>(true))
if (HdotGradHheader.headerOk())
{
Info<< "Reading field HdotGradH" << endl;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Info<< "Reading non-inertial frame fields" << endl;

IOobject linearAccelerationHeader
typeIOobject<uniformDimensionedVectorField> linearAccelerationHeader
(
"linearAcceleration",
runTime.timeName(),
Expand All @@ -11,13 +11,7 @@

autoPtr<uniformDimensionedVectorField> linearAccelerationPtr;

if
(
linearAccelerationHeader.typeHeaderOk<uniformDimensionedVectorField>
(
true
)
)
if (linearAccelerationHeader.headerOk())
{
Info<< " Reading " << linearAccelerationHeader.name() << endl;

Expand All @@ -28,7 +22,7 @@
}


IOobject angularVelocityHeader
typeIOobject<uniformDimensionedVectorField> angularVelocityHeader
(
"angularVelocity",
runTime.timeName(),
Expand All @@ -39,7 +33,7 @@

autoPtr<uniformDimensionedVectorField> angularVelocityPtr;

if (angularVelocityHeader.typeHeaderOk<uniformDimensionedVectorField>(true))
if (angularVelocityHeader.headerOk())
{
Info<< " Reading " << angularVelocityHeader.name() << endl;

Expand All @@ -50,7 +44,7 @@
}


IOobject angularAccelerationHeader
typeIOobject<uniformDimensionedVectorField> angularAccelerationHeader
(
"angularAcceleration",
runTime.timeName(),
Expand All @@ -61,13 +55,7 @@

autoPtr<uniformDimensionedVectorField> angularAccelerationPtr;

if
(
angularAccelerationHeader.typeHeaderOk<uniformDimensionedVectorField>
(
true
)
)
if (angularAccelerationHeader.headerOk())
{
Info<< " Reading " << angularAccelerationHeader.name() << endl;

Expand All @@ -78,7 +66,7 @@
}


IOobject centreOfRotationHeader
typeIOobject<uniformDimensionedVectorField> centreOfRotationHeader
(
"centreOfRotation",
runTime.timeName(),
Expand All @@ -89,13 +77,7 @@

autoPtr<uniformDimensionedVectorField> centreOfRotationPtr;

if
(
centreOfRotationHeader.typeHeaderOk<uniformDimensionedVectorField>
(
true
)
)
if (centreOfRotationHeader.headerOk())
{
Info<< " Reading " << centreOfRotationHeader.name() << endl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Foam::IOobject Foam::twoPhaseChangeModel::createIOobject
const compressibleTwoPhaseMixture& mixture
) const
{
IOobject io
typeIOobject<IOdictionary> io
(
phaseChangePropertiesName,
mixture.alpha1().mesh().time().constant(),
Expand All @@ -55,7 +55,7 @@ Foam::IOobject Foam::twoPhaseChangeModel::createIOobject
IOobject::NO_WRITE
);

if (io.typeHeaderOk<IOdictionary>(true))
if (io.headerOk())
{
io.readOpt() = IOobject::MUST_READ_IF_MODIFIED;
return io;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Foam::autoPtr<Foam::twoPhaseChangeModel> Foam::twoPhaseChangeModel::New
const compressibleTwoPhaseMixture& mixture
)
{
IOobject twoPhaseChangeModelIO
typeIOobject<IOdictionary> twoPhaseChangeModelIO
(
IOobject
(
Expand All @@ -47,7 +47,7 @@ Foam::autoPtr<Foam::twoPhaseChangeModel> Foam::twoPhaseChangeModel::New

word modelType(twoPhaseChangeModels::noPhaseChange::typeName);

if (twoPhaseChangeModelIO.typeHeaderOk<IOdictionary>(false))
if (twoPhaseChangeModelIO.headerOk())
{
IOdictionary(twoPhaseChangeModelIO).lookup
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ Foam::MovingPhaseModel<BasePhaseModel>::phi(const volVectorField& U) const
{
word phiName(IOobject::groupName("phi", this->name()));

IOobject phiHeader
typeIOobject<surfaceScalarField> phiHeader
(
phiName,
U.mesh().time().timeName(),
U.mesh(),
IOobject::NO_READ
);

if (phiHeader.typeHeaderOk<surfaceScalarField>(true))
if (phiHeader.headerOk())
{
Info<< "Reading face flux field " << phiName << endl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ int main(int argc, char *argv[])

Info<< "Checking for motionProperties\n" << endl;

IOobject motionObj
typeIOobject<IOdictionary> motionObj
(
"motionProperties",
runTime.constant(),
Expand All @@ -651,7 +651,7 @@ int main(int argc, char *argv[])
// corrector for mesh motion
twoDPointCorrector* correct2DPtr = nullptr;

if (motionObj.typeHeaderOk<IOdictionary>(true))
if (motionObj.headerOk())
{
Info<< "Reading " << runTime.constant() / "motionProperties"
<< endl << endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
Expand Down Expand Up @@ -230,15 +230,15 @@ int main(int argc, char *argv[])


// Refinement level
IOobject refHeader
typeIOobject<labelIOList> refHeader
(
"refinementLevel",
runTime.timeName(),
polyMesh::defaultRegion,
runTime
);

if (!readLevel && refHeader.typeHeaderOk<labelIOList>(true))
if (!readLevel && refHeader.headerOk())
{
WarningInFunction
<< "Detected " << refHeader.name() << " file in "
Expand Down
6 changes: 3 additions & 3 deletions applications/utilities/mesh/advanced/selectCells/edgeStats.C
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
Expand Down Expand Up @@ -74,7 +74,7 @@ Foam::edgeStats::edgeStats(const polyMesh& mesh)
mesh_(mesh),
normalDir_(3)
{
IOobject motionObj
typeIOobject<IOdictionary> motionObj
(
"motionProperties",
mesh.time().constant(),
Expand All @@ -83,7 +83,7 @@ Foam::edgeStats::edgeStats(const polyMesh& mesh)
IOobject::NO_WRITE
);

if (motionObj.typeHeaderOk<IOdictionary>(true))
if (motionObj.headerOk())
{
Info<< "Reading " << mesh.time().constant() / "motionProperties"
<< endl << endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
&& runTime.timeName() != "0"
)
{
IOobject io
typeIOobject<IOdictionary> io
(
"time",
runTime.timeName(),
Expand All @@ -19,7 +19,7 @@
false
);

if (io.typeHeaderOk<IOdictionary>(true))
if (io.headerOk())
{
IOdictionary timeObject
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
&& runTime.timeName() != "0"
)
{
IOobject io
typeIOobject<IOdictionary> io
(
"time",
runTime.timeName(),
Expand All @@ -19,7 +19,7 @@
false
);

if (io.typeHeaderOk<IOdictionary>(true))
if (io.headerOk())
{
IOdictionary timeObject
(
Expand Down
7 changes: 5 additions & 2 deletions applications/utilities/mesh/generation/blockMesh/blockMesh.C
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,12 @@ int main(int argc, char *argv[])
}
}

IOobject meshDictIO(systemDictIO(dictName, args, runTime, regionName));
typeIOobject<IOdictionary> meshDictIO
(
systemDictIO(dictName, args, runTime, regionName)
);

if (!meshDictIO.typeHeaderOk<IOdictionary>(true))
if (!meshDictIO.headerOk())
{
FatalErrorInFunction
<< "Cannot find file " << meshDictIO.relativeObjectPath()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void createDummyFvMeshFiles(const polyMesh& mesh, const word& regionName)
{
// Create dummy system/fv*
{
IOobject io
typeIOobject<IOdictionary> io
(
"fvSchemes",
mesh.time().system(),
Expand All @@ -95,9 +95,9 @@ void createDummyFvMeshFiles(const polyMesh& mesh, const word& regionName)
false
);

Info<< "Testing:" << io.objectPath<IOdictionary>() << endl;
Info<< "Testing:" << io.objectPath() << endl;

if (!io.typeHeaderOk<IOdictionary>(false))
if (!io.headerOk())
{
Info<< "Writing dummy " << regionName/io.name() << endl;
dictionary dummyDict;
Expand All @@ -112,7 +112,7 @@ void createDummyFvMeshFiles(const polyMesh& mesh, const word& regionName)
}
}
{
IOobject io
typeIOobject<IOdictionary> io
(
"fvSolution",
mesh.time().system(),
Expand All @@ -123,7 +123,7 @@ void createDummyFvMeshFiles(const polyMesh& mesh, const word& regionName)
false
);

if (!io.typeHeaderOk<IOdictionary>(false))
if (!io.headerOk())
{
Info<< "Writing dummy " << regionName/io.name() << endl;
dictionary dummyDict;
Expand Down
Loading

0 comments on commit b912332

Please sign in to comment.