timeIOdictionary: New global IOdictionary type to handle writing of time-dependent global data

to the <case>/<time>/uniform or <case>/<processor>/<time>/uniform directory.

Adding a new form of IOdictionary for this purpose allows significant
simplification and rationalisation of regIOobject::writeObject, removing the
need for explicit treatment of different file types.
This commit is contained in:
Henry Weller
2021-08-05 22:28:05 +01:00
parent f8b00b3d80
commit 1278c865aa
23 changed files with 266 additions and 188 deletions

View File

@ -240,6 +240,7 @@ IOdictionary = db/IOobjects/IOdictionary
$(IOdictionary)/IOdictionary.C
$(IOdictionary)/IOdictionaryIO.C
$(IOdictionary)/localIOdictionary.C
$(IOdictionary)/timeIOdictionary.C
$(IOdictionary)/systemDict.C
db/IOobjects/IOMap/IOMapName.C

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -321,12 +321,6 @@ const Foam::Time& Foam::IOobject::time() const
}
const Foam::fileName& Foam::IOobject::caseName() const
{
return time().caseName();
}
Foam::word Foam::IOobject::group() const
{
return group(name_);
@ -339,12 +333,57 @@ Foam::word Foam::IOobject::member() const
}
bool Foam::IOobject::global() const
{
return false;
}
bool Foam::IOobject::globalWrite() const
{
return global();
}
const Foam::fileName& Foam::IOobject::rootPath() const
{
return time().rootPath();
}
const Foam::fileName& Foam::IOobject::caseName() const
{
if (globalWrite())
{
return time().globalCaseName();
}
else
{
return time().caseName();
}
}
Foam::fileName& Foam::IOobject::instance() const
{
if
(
instance_ != time().system()
&& instance_ != time().constant()
&& instance_ != time().timeName()
)
{
scalar timeValue;
if (readScalar(instance_.c_str(), timeValue))
{
instance_ = time().timeName();
}
}
return instance_;
}
Foam::fileName Foam::IOobject::path() const
{
if (instance().isAbsolute())

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -148,7 +148,7 @@ private:
string note_;
//- Instance path component
fileName instance_;
mutable fileName instance_;
//- Local path component
fileName local_;
@ -384,19 +384,24 @@ public:
// as <model>:<name>
inline word modelName(const char* name) const;
//- Return true if object is global, i.e. same for all processors
// Defaults to false, must be overridden by global IO classes
virtual bool global() const;
//- Return true if object is global, i.e. same for all processors
// and written to the global case directory,
// i.e. not the processor time directory
// Defaults to global()
virtual bool globalWrite() const;
const fileName& rootPath() const;
const fileName& caseName() const;
const fileName& instance() const
{
return instance_;
}
fileName& instance()
{
return instance_;
}
//- Return the instance directory, constant, system, <time> etc.
// If the instance is a time directory it is updated to the
// current time before return
fileName& instance() const;
const fileName& local() const
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -101,7 +101,7 @@ public:
using regIOobject::name;
//- Is object global
//- Return true as object is global, i.e. same for all processors
virtual bool global() const
{
return true;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2015-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2015-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -70,7 +70,8 @@ public:
// Member Functions
//- Is object global
//- Return false as object is not global,
// i.e. different for all processors
virtual bool global() const
{
return false;

View File

@ -0,0 +1,62 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "timeIOdictionary.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::timeIOdictionary::timeIOdictionary
(
const IOobject& io
)
:
IOdictionary(io, typeName)
{
readHeaderOk(IOstream::ASCII, typeName);
// For if MUST_READ_IF_MODIFIED
addWatch();
}
Foam::timeIOdictionary::timeIOdictionary
(
const IOobject& io,
const dictionary& dict
)
:
IOdictionary(io, typeName)
{
if (!readHeaderOk(IOstream::ASCII, typeName))
{
dictionary::operator=(dict);
}
// For if MUST_READ_IF_MODIFIED
addWatch();
}
// ************************************************************************* //

View File

@ -0,0 +1,88 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::timeIOdictionary
Description
timeIOdictionary derived from IOdictionary with globalWrite set false to
enable writing to processor time directories.
Used for time-dependent global data written to the <time>/uniform
directories.
SourceFiles
timeIOdictionary.C
\*---------------------------------------------------------------------------*/
#ifndef timeIOdictionary_H
#define timeIOdictionary_H
#include "IOdictionary.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class timeIOdictionary Declaration
\*---------------------------------------------------------------------------*/
class timeIOdictionary
:
public IOdictionary
{
public:
// Constructors
//- Construct given an IOobject and actual type name
timeIOdictionary(const IOobject& io);
//- Construct given an IOobject and dictionary
timeIOdictionary(const IOobject&, const dictionary&);
// Member Functions
//- Return false as the object is global, i.e. same for all processors
// but written to the processor time directory
virtual bool globalWrite() const
{
return false;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -24,6 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "Time.H"
#include "timeIOdictionary.H"
#include "argList.H"
// * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * //
@ -232,7 +233,7 @@ void Foam::Time::setControls()
}
}
IOdictionary timeDict
timeIOdictionary timeDict
(
IOobject
(
@ -911,7 +912,7 @@ void Foam::Time::setTime(const instant& inst, const label newIndex)
dimensionedScalar::name() = inst.name();
timeIndex_ = newIndex;
IOdictionary timeDict
timeIOdictionary timeDict
(
IOobject
(

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -24,6 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "Time.H"
#include "timeIOdictionary.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -251,7 +252,7 @@ bool Foam::Time::writeTimeDict() const
{
const word tmName(timeName());
IOdictionary timeDict
timeIOdictionary timeDict
(
IOobject
(

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -415,12 +415,6 @@ bool Foam::regIOobject::headerOk()
}
bool Foam::regIOobject::global() const
{
return false;
}
void Foam::regIOobject::operator=(const IOobject& io)
{
// Close any file

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -247,10 +247,6 @@ public:
//- Read object if modified (as set by call to modified)
virtual bool readIfModified();
//- Is object same for all processors
// Defaults to false, must be overridden by global IO classes
virtual bool global() const;
// Writing

View File

@ -59,88 +59,19 @@ bool Foam::regIOobject::writeObject
return false;
}
//- uncomment this if you want to write global objects on master only
bool isGlobal = global();
// bool isGlobal = false;
if (instance() == time().timeName())
{
// Mark as written to local directory
isGlobal = false;
}
else if
(
instance() != time().system()
&& instance() != time().caseSystem()
&& instance() != time().constant()
&& instance() != time().caseConstant()
)
{
// Update instance
const_cast<regIOobject&>(*this).instance() = time().timeName();
// Mark as written to local directory
isGlobal = false;
}
if (OFstream::debug)
{
if (isGlobal)
{
Pout<< "regIOobject::write() : "
<< "writing (global) file " << objectPath();
}
else
{
Pout<< "regIOobject::write() : "
<< "writing (local) file " << objectPath();
}
}
bool osGood = false;
// Write global objects on master only
// Everyone check or just master
bool masterOnly =
isGlobal
globalWrite()
&& (
regIOobject::fileModificationChecking == timeStampMaster
|| regIOobject::fileModificationChecking == inotifyMaster
);
bool osGood = false;
if (Pstream::master() || !masterOnly)
{
// if (mkDir(path()))
//{
// // Try opening an OFstream for object
// OFstream os(objectPath(), fmt, ver, cmp);
//
// // If any of these fail, return (leave error handling to Ostream
// // class)
// if (!os.good())
// {
// return false;
// }
//
// if (!writeHeader(os))
// {
// return false;
// }
//
// // Write the data to the Ostream
// if (!writeData(os))
// {
// return false;
// }
//
// writeEndDivider(os);
//
// osGood = os.good();
//}
osGood = fileHandler().writeObject(*this, fmt, ver, cmp, write);
}
else
@ -176,4 +107,5 @@ bool Foam::regIOobject::write(const bool write) const
);
}
// ************************************************************************* //

View File

@ -460,13 +460,7 @@ bool Foam::fileOperation::writeObject
{
if (write)
{
const fileName filePath
(
io.global() && !(io.instance() == io.time().timeName())
? io.rootPath()/io.time().globalCaseName()
/io.instance()/io.db().dbDir()/io.local()/io.name()
: io.objectPath()
);
const fileName filePath(io.objectPath());
mkDir(filePath.path());

View File

@ -25,6 +25,7 @@ License
#include "fieldAverage.H"
#include "fieldAverageItem.H"
#include "timeIOdictionary.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -205,7 +206,7 @@ void Foam::functionObjects::fieldAverage::writeAverages() const
void Foam::functionObjects::fieldAverage::writeAveragingProperties() const
{
IOdictionary propsDict
timeIOdictionary propsDict
(
IOobject
(
@ -253,7 +254,7 @@ void Foam::functionObjects::fieldAverage::readAveragingProperties()
false
);
if (!propsDictHeader.typeHeaderOk<IOdictionary>())
if (!propsDictHeader.typeHeaderOk<timeIOdictionary>())
{
Log << " Starting averaging at time "
<< obr_.time().timeName() << nl;
@ -261,7 +262,7 @@ void Foam::functionObjects::fieldAverage::readAveragingProperties()
return;
}
IOdictionary propsDict(propsDictHeader);
timeIOdictionary propsDict(propsDictHeader);
Log << " Restarting averaging for fields:" << nl;

View File

@ -26,6 +26,7 @@ License
#include "meanVelocityForce.H"
#include "volFields.H"
#include "fvMatrices.H"
#include "timeIOdictionary.H"
#include "IFstream.H"
#include "addToRunTimeSelectionTable.H"
@ -65,7 +66,7 @@ void Foam::fv::meanVelocityForce::writeProps
// Only write on output time
if (mesh().time().writeTime())
{
IOdictionary propsDict
timeIOdictionary propsDict
(
IOobject
(

View File

@ -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
@ -26,7 +26,7 @@ License
#include "Cloud.H"
#include "Time.H"
#include "IOPosition.H"
#include "IOdictionary.H"
#include "timeIOdictionary.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -50,9 +50,9 @@ void Foam::Cloud<ParticleType>::readCloudUniformProperties()
false
);
if (dictObj.typeHeaderOk<IOdictionary>(true))
if (dictObj.typeHeaderOk<timeIOdictionary>(true))
{
const IOdictionary uniformPropsDict(dictObj);
const timeIOdictionary uniformPropsDict(dictObj);
const word procName("processor" + Foam::name(Pstream::myProcNo()));
if (uniformPropsDict.found(procName))
@ -71,7 +71,7 @@ void Foam::Cloud<ParticleType>::readCloudUniformProperties()
template<class ParticleType>
void Foam::Cloud<ParticleType>::writeCloudUniformProperties() const
{
IOdictionary uniformPropsDict
timeIOdictionary uniformPropsDict
(
IOobject
(

View File

@ -53,7 +53,7 @@ SourceFiles
#include "particle.H"
#include "Cloud.H"
#include "IOdictionary.H"
#include "timeIOdictionary.H"
#include "autoPtr.H"
#include "Random.H"
#include "fvMesh.H"
@ -144,7 +144,7 @@ protected:
IOdictionary particleProperties_;
//- Dictionary of output properties
IOdictionary outputProperties_;
timeIOdictionary outputProperties_;
//- Solution properties
cloudSolution solution_;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -119,7 +119,7 @@ void Foam::regionModels::regionModel::initialise()
outputPropertiesPtr_.reset
(
new IOdictionary
new timeIOdictionary
(
IOobject
(

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -38,6 +38,7 @@ SourceFiles
#define regionModel_H
#include "fvMesh.H"
#include "timeIOdictionary.H"
#include "AMIInterpolation.H"
#include "regionModelFunctionObjectList.H"

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2016-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -24,14 +24,15 @@ License
\*---------------------------------------------------------------------------*/
#include "rigidBodyMeshMotion.H"
#include "addToRunTimeSelectionTable.H"
#include "polyMesh.H"
#include "pointPatchDist.H"
#include "pointConstraints.H"
#include "timeIOdictionary.H"
#include "uniformDimensionedFields.H"
#include "forces.H"
#include "OneConstant.H"
#include "mathematicalConstants.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -97,8 +98,8 @@ Foam::rigidBodyMeshMotion::rigidBodyMeshMotion
mesh.time().timeName(),
"uniform",
mesh
).typeHeaderOk<IOdictionary>(true)
? IOdictionary
).typeHeaderOk<timeIOdictionary>(true)
? timeIOdictionary
(
IOobject
(
@ -339,7 +340,7 @@ void Foam::rigidBodyMeshMotion::solve()
bool Foam::rigidBodyMeshMotion::write() const
{
IOdictionary dict
timeIOdictionary dict
(
IOobject
(

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2016-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -24,14 +24,15 @@ License
\*---------------------------------------------------------------------------*/
#include "rigidBodyMeshMotionSolver.H"
#include "addToRunTimeSelectionTable.H"
#include "polyMesh.H"
#include "pointPatchDist.H"
#include "pointConstraints.H"
#include "timeIOdictionary.H"
#include "uniformDimensionedFields.H"
#include "forces.H"
#include "OneConstant.H"
#include "mathematicalConstants.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -81,8 +82,8 @@ Foam::rigidBodyMeshMotionSolver::rigidBodyMeshMotionSolver
mesh.time().timeName(),
"uniform",
mesh
).typeHeaderOk<IOdictionary>(true)
? IOdictionary
).typeHeaderOk<timeIOdictionary>(true)
? timeIOdictionary
(
IOobject
(
@ -308,7 +309,7 @@ void Foam::rigidBodyMeshMotionSolver::updateMesh(const mapPolyMesh& mpm)
bool Foam::rigidBodyMeshMotionSolver::write() const
{
IOdictionary dict
timeIOdictionary dict
(
IOobject
(

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2013-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -24,13 +24,14 @@ License
\*---------------------------------------------------------------------------*/
#include "sixDoFRigidBodyMotionSolver.H"
#include "addToRunTimeSelectionTable.H"
#include "polyMesh.H"
#include "pointPatchDist.H"
#include "pointConstraints.H"
#include "timeIOdictionary.H"
#include "uniformDimensionedFields.H"
#include "forces.H"
#include "mathematicalConstants.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -65,8 +66,8 @@ Foam::sixDoFRigidBodyMotionSolver::sixDoFRigidBodyMotionSolver
mesh.time().timeName(),
"uniform",
mesh
).typeHeaderOk<IOdictionary>(true)
? IOdictionary
).typeHeaderOk<timeIOdictionary>(true)
? timeIOdictionary
(
IOobject
(
@ -254,7 +255,7 @@ void Foam::sixDoFRigidBodyMotionSolver::solve()
bool Foam::sixDoFRigidBodyMotionSolver::write() const
{
IOdictionary dict
timeIOdictionary dict
(
IOobject
(

View File

@ -1,42 +0,0 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class dictionary;
location "system";
object decomposeParDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
numberOfSubdomains 4;
method simple;
simpleCoeffs
{
n (2 2 1);
}
hierarchicalCoeffs
{
n (1 1 1);
order xyz;
}
manualCoeffs
{
dataFile "";
}
distributed no;
roots ( );
// ************************************************************************* //