Skip to content
Snippets Groups Projects
Commit 784461b2 authored by Mark Olesen's avatar Mark Olesen
Browse files

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.
parent c554dc7b
Branches
Tags
No related merge requests found
Showing with 57 additions and 50 deletions
......@@ -18,8 +18,10 @@ if (!fieldsToUse.found(fieldName))
fieldName,
timeDirs[n1].name(),
mesh,
IOobject::NO_READ
).typeHeaderOk<volScalarField>(false)
IOobject::NO_READ,
IOobject::NO_WRITE,
false // no register
).typeHeaderOk<volScalarField>(false, false)
);
if (variableGood)
......
......@@ -7,8 +7,6 @@ if (timeDirs.size() > 1 && Pstream::master())
// We already loaded a mesh (usually from constant).
// See if any other "polyMesh/points" files exist too.
const fileName& baseDir = mesh.time().path();
Info<< "Search for moving mesh ... " << flush;
forAll(timeDirs, timeI)
{
......@@ -17,7 +15,6 @@ if (timeDirs.size() > 1 && Pstream::master())
meshMoving =
(
timeName != mesh.pointsInstance()
&& isDir(baseDir/timeName/polyMesh::meshSubDir)
&& IOobject
(
"points",
......@@ -27,7 +24,7 @@ if (timeDirs.size() > 1 && Pstream::master())
IOobject::NO_READ,
IOobject::NO_WRITE,
false // no register
).typeHeaderOk<pointIOField>(true)
).typeHeaderOk<pointIOField>(true, false)
);
if (meshMoving)
......
......@@ -8,15 +8,12 @@ if (timeDirs.size() > 1 && Pstream::master())
// We already loaded a mesh (usually from constant).
// See if any other "polyMesh/points" files exist too.
const fileName& baseDir = mesh.time().path();
Info<< "Search for moving mesh ... " << flush;
forAll(timeDirs, timeI)
{
meshMoving =
(
isDir(baseDir/timeDirs[timeI].name()/polyMesh::meshSubDir)
&& IOobject
IOobject
(
"points",
timeDirs[timeI].name(),
......@@ -25,7 +22,7 @@ if (timeDirs.size() > 1 && Pstream::master())
IOobject::NO_READ,
IOobject::NO_WRITE,
false // no register
).typeHeaderOk<pointIOField>(true)
).typeHeaderOk<pointIOField>(true, false)
);
if (meshMoving)
......
......@@ -21,10 +21,10 @@
runTime,
IOobject::READ_IF_PRESENT,
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;
IOdictionary timeObject(io);
......
......@@ -4,10 +4,13 @@
"points",
runTime.timeName(),
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
io.readOpt() = IOobject::MUST_READ;
......
IOobject ioPoints
(
"points",
runTime.timeName(),
mesh.name(),
mesh
);
if (ioPoints.typeHeaderOk<pointIOField>(true))
{
Info<< "new points available" << endl;
// Reading new points
pointIOField newPoints
IOobject io
(
IOobject
(
"points",
runTime.timeName(),
mesh.name(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
"points",
runTime.timeName(),
mesh.name(),
mesh,
IOobject::NO_READ,
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));
}
}
......@@ -425,10 +425,16 @@ public:
//- Read header
bool readHeader(Istream&);
//- Read header (uses typeFilePath to find file) and check header
// info. Optionally checks headerClassName against type
//- Read header (uses typeFilePath to find file) and check its info.
// Optionally checks headerClassName against the type-name.
// When search is false, simply use the current instance,
// otherwise search previous instances.
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
template<class Type>
......@@ -489,18 +495,23 @@ template<>
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>
inline bool typeGlobal()
{
return false;
}
//- Template function for obtaining filePath
//- Template function for obtaining local or global filePath
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)
);
}
......
......@@ -32,7 +32,11 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
bool Foam::IOobject::typeHeaderOk(const bool checkType)
bool Foam::IOobject::typeHeaderOk
(
const bool checkType,
const bool search
)
{
bool ok = true;
......@@ -48,7 +52,7 @@ bool Foam::IOobject::typeHeaderOk(const bool checkType)
// Determine local status
if (!masterOnly || Pstream::master())
{
Istream* isPtr = objectStream(typeFilePath<Type>(*this));
Istream* isPtr = objectStream(typeFilePath<Type>(*this, search));
// If the stream has failed return
if (!isPtr)
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -30,11 +30,11 @@ namespace Foam
{
defineTemplateTypeNameAndDebug(IOMap<dictionary>, 0);
//- Template specialisation for obtaining filePath
//- Template specialization for global status
template<>
fileName typeFilePath<IOMap<dictionary>>(const IOobject& io)
bool typeGlobal<IOMap<dictionary>>()
{
return io.globalFilePath();
return true;
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment