mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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:
@ -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)
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
@ -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",
|
||||||
(
|
runTime.timeName(),
|
||||||
"points",
|
mesh.name(),
|
||||||
runTime.timeName(),
|
mesh,
|
||||||
mesh.name(),
|
IOobject::NO_READ,
|
||||||
mesh,
|
IOobject::NO_WRITE,
|
||||||
IOobject::MUST_READ,
|
false // no register
|
||||||
IOobject::NO_WRITE
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
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
|
//- 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)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user