ENH: make search of instances in IOobject::typeHeaderOk optional (issue #245)

- in specific cases it can be useful to suppress searching the instances.
  For example, if one only wishes to check if a "points" is available at
  the given time instance, without searching backwards through all
  times.
This commit is contained in:
Mark Olesen
2016-11-21 14:28:40 +01:00
parent c554dc7b7d
commit 784461b2fa
9 changed files with 57 additions and 50 deletions

View File

@ -18,8 +18,10 @@ if (!fieldsToUse.found(fieldName))
fieldName, fieldName,
timeDirs[n1].name(), timeDirs[n1].name(),
mesh, mesh,
IOobject::NO_READ IOobject::NO_READ,
).typeHeaderOk<volScalarField>(false) IOobject::NO_WRITE,
false // no register
).typeHeaderOk<volScalarField>(false, false)
); );
if (variableGood) if (variableGood)

View File

@ -7,8 +7,6 @@ if (timeDirs.size() > 1 && Pstream::master())
// We already loaded a mesh (usually from constant). // We already loaded a mesh (usually from constant).
// See if any other "polyMesh/points" files exist too. // See if any other "polyMesh/points" files exist too.
const fileName& baseDir = mesh.time().path();
Info<< "Search for moving mesh ... " << flush; Info<< "Search for moving mesh ... " << flush;
forAll(timeDirs, timeI) forAll(timeDirs, timeI)
{ {
@ -17,7 +15,6 @@ if (timeDirs.size() > 1 && Pstream::master())
meshMoving = meshMoving =
( (
timeName != mesh.pointsInstance() timeName != mesh.pointsInstance()
&& isDir(baseDir/timeName/polyMesh::meshSubDir)
&& IOobject && IOobject
( (
"points", "points",
@ -27,7 +24,7 @@ if (timeDirs.size() > 1 && Pstream::master())
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false // no register false // no register
).typeHeaderOk<pointIOField>(true) ).typeHeaderOk<pointIOField>(true, false)
); );
if (meshMoving) if (meshMoving)

View File

@ -8,15 +8,12 @@ if (timeDirs.size() > 1 && Pstream::master())
// We already loaded a mesh (usually from constant). // We already loaded a mesh (usually from constant).
// See if any other "polyMesh/points" files exist too. // See if any other "polyMesh/points" files exist too.
const fileName& baseDir = mesh.time().path();
Info<< "Search for moving mesh ... " << flush; Info<< "Search for moving mesh ... " << flush;
forAll(timeDirs, timeI) forAll(timeDirs, timeI)
{ {
meshMoving = meshMoving =
( (
isDir(baseDir/timeDirs[timeI].name()/polyMesh::meshSubDir) IOobject
&& IOobject
( (
"points", "points",
timeDirs[timeI].name(), timeDirs[timeI].name(),
@ -25,7 +22,7 @@ if (timeDirs.size() > 1 && Pstream::master())
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false // no register false // no register
).typeHeaderOk<pointIOField>(true) ).typeHeaderOk<pointIOField>(true, false)
); );
if (meshMoving) if (meshMoving)

View File

@ -21,10 +21,10 @@
runTime, runTime,
IOobject::READ_IF_PRESENT, IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false false // no register
); );
if (io.typeHeaderOk<IOdictionary>(true)) if (io.typeHeaderOk<IOdictionary>(true, false))
{ {
io.readOpt() = IOobject::MUST_READ_IF_MODIFIED; io.readOpt() = IOobject::MUST_READ_IF_MODIFIED;
IOdictionary timeObject(io); IOdictionary timeObject(io);

View File

@ -4,10 +4,13 @@
"points", "points",
runTime.timeName(), runTime.timeName(),
polyMesh::meshSubDir, polyMesh::meshSubDir,
mesh mesh,
IOobject::NO_READ,
IOobject::NO_WRITE,
false // no register
); );
if (io.typeHeaderOk<pointIOField>(true)) if (io.typeHeaderOk<pointIOField>(true, false))
{ {
// Read new points // Read new points
io.readOpt() = IOobject::MUST_READ; io.readOpt() = IOobject::MUST_READ;

View File

@ -1,27 +1,20 @@
IOobject ioPoints
(
"points",
runTime.timeName(),
mesh.name(),
mesh
);
if (ioPoints.typeHeaderOk<pointIOField>(true))
{ {
Info<< "new points available" << endl; IOobject io
// Reading new points
pointIOField newPoints
(
IOobject
( (
"points", "points",
runTime.timeName(), runTime.timeName(),
mesh.name(), mesh.name(),
mesh, mesh,
IOobject::MUST_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
) false // no register
); );
mesh.movePoints(newPoints); if (io.typeHeaderOk<pointIOField>(true, false))
{
Info<< "new points available" << endl;
// Read new points
io.readOpt() = IOobject::MUST_READ;
mesh.movePoints(pointIOField(io));
}
} }

View File

@ -425,10 +425,16 @@ public:
//- Read header //- Read header
bool readHeader(Istream&); bool readHeader(Istream&);
//- Read header (uses typeFilePath to find file) and check header //- Read header (uses typeFilePath to find file) and check its info.
// info. Optionally checks headerClassName against type // Optionally checks headerClassName against the type-name.
// When search is false, simply use the current instance,
// otherwise search previous instances.
template<class Type> template<class Type>
bool typeHeaderOk(const bool checkType = true); bool typeHeaderOk
(
const bool checkType = true,
const bool search = true
);
//- Helper: warn that type does not support re-reading //- Helper: warn that type does not support re-reading
template<class Type> template<class Type>
@ -489,18 +495,23 @@ template<>
Ostream& operator<<(Ostream& os, const InfoProxy<IOobject>& ip); Ostream& operator<<(Ostream& os, const InfoProxy<IOobject>& ip);
//- Template function for obtaining global status //- Template function for obtaining global vs. local status
template<class T> template<class T>
inline bool typeGlobal() inline bool typeGlobal()
{ {
return false; return false;
} }
//- Template function for obtaining filePath //- Template function for obtaining local or global filePath
template<class T> template<class T>
inline fileName typeFilePath(const IOobject& io) inline fileName typeFilePath(const IOobject& io, const bool search=true)
{ {
return (typeGlobal<T>() ? io.globalFilePath() : io.localFilePath()); return
(
typeGlobal<T>()
? io.globalFilePath(search)
: io.localFilePath(search)
);
} }

View File

@ -32,7 +32,11 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type> template<class Type>
bool Foam::IOobject::typeHeaderOk(const bool checkType) bool Foam::IOobject::typeHeaderOk
(
const bool checkType,
const bool search
)
{ {
bool ok = true; bool ok = true;
@ -48,7 +52,7 @@ bool Foam::IOobject::typeHeaderOk(const bool checkType)
// Determine local status // Determine local status
if (!masterOnly || Pstream::master()) if (!masterOnly || Pstream::master())
{ {
Istream* isPtr = objectStream(typeFilePath<Type>(*this)); Istream* isPtr = objectStream(typeFilePath<Type>(*this, search));
// If the stream has failed return // If the stream has failed return
if (!isPtr) if (!isPtr)

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -30,11 +30,11 @@ namespace Foam
{ {
defineTemplateTypeNameAndDebug(IOMap<dictionary>, 0); defineTemplateTypeNameAndDebug(IOMap<dictionary>, 0);
//- Template specialisation for obtaining filePath //- Template specialization for global status
template<> template<>
fileName typeFilePath<IOMap<dictionary>>(const IOobject& io) bool typeGlobal<IOMap<dictionary>>()
{ {
return io.globalFilePath(); return true;
} }
} }