mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: IOobject::selectIO helper method
- centralizes IOobject handling and treatment of alternative locations. If an alternative file location is specified, it will be used instead. - provide decompositionMethod::canonicalName instead of using "decomposeParDict" in various places.
This commit is contained in:
@ -192,6 +192,51 @@ bool Foam::IOobject::fileNameComponents
|
||||
}
|
||||
|
||||
|
||||
Foam::IOobject Foam::IOobject::selectIO
|
||||
(
|
||||
const IOobject& io,
|
||||
const fileName& altFile,
|
||||
const word& ioName
|
||||
)
|
||||
{
|
||||
if (altFile.empty())
|
||||
{
|
||||
return io;
|
||||
}
|
||||
|
||||
// Construct from file path instead
|
||||
|
||||
fileName altPath = altFile;
|
||||
|
||||
if (isDir(altPath))
|
||||
{
|
||||
// Resolve directories as well
|
||||
|
||||
if (ioName.empty())
|
||||
{
|
||||
altPath /= io.name();
|
||||
}
|
||||
else
|
||||
{
|
||||
altPath /= ioName;
|
||||
}
|
||||
}
|
||||
altPath.expand();
|
||||
|
||||
|
||||
return
|
||||
IOobject
|
||||
(
|
||||
altPath,
|
||||
io.db(),
|
||||
io.readOpt(),
|
||||
io.writeOpt(),
|
||||
io.registerObject(),
|
||||
io.globalObject()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::IOobject::IOobject
|
||||
@ -339,12 +384,6 @@ Foam::IOobject::IOobject
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::IOobject::~IOobject()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::objectRegistry& Foam::IOobject::db() const
|
||||
@ -371,28 +410,14 @@ const Foam::fileName& Foam::IOobject::caseName() const
|
||||
}
|
||||
|
||||
|
||||
Foam::word Foam::IOobject::group() const
|
||||
{
|
||||
return name_.ext();
|
||||
}
|
||||
|
||||
|
||||
Foam::word Foam::IOobject::member() const
|
||||
{
|
||||
return name_.lessExt();
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName Foam::IOobject::path() const
|
||||
{
|
||||
if (isOutsideOfCase(instance()))
|
||||
{
|
||||
return instance();
|
||||
}
|
||||
else
|
||||
{
|
||||
return rootPath()/caseName()/instance()/db_.dbDir()/local();
|
||||
}
|
||||
|
||||
return rootPath()/caseName()/instance()/db_.dbDir()/local();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -25,7 +25,7 @@ Class
|
||||
Foam::IOobject
|
||||
|
||||
Description
|
||||
IOobject defines the attributes of an object for which implicit
|
||||
Defines the attributes of an object for which implicit
|
||||
objectRegistry management is supported, and provides the infrastructure
|
||||
for performing stream I/O.
|
||||
|
||||
@ -83,6 +83,7 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
class Time;
|
||||
class objectRegistry;
|
||||
|
||||
@ -184,7 +185,7 @@ public:
|
||||
TypeName("IOobject");
|
||||
|
||||
|
||||
// Static data members
|
||||
// Static Data Members
|
||||
|
||||
//- Type of file modification checking
|
||||
static fileCheckTypes fileModificationChecking;
|
||||
@ -219,6 +220,27 @@ public:
|
||||
template<class StringType>
|
||||
static inline word groupName(StringType name, const word& group);
|
||||
|
||||
//- Return the IOobject, but also consider an alternative file name.
|
||||
//
|
||||
// \param io The expected IOobject to use
|
||||
// \param altFile Alternative fileName (ignored if empty).
|
||||
// \param ioName The alternative name for the IOobject when
|
||||
// the altFile resolves to a directory.
|
||||
//
|
||||
// \note If the alternative fileName is a non-empty string,
|
||||
// it defines the location but uses all other properties of the
|
||||
// expected IOobject.
|
||||
// The location may be an absolute or a relative path.
|
||||
// If it corresponds to a directory, the name of the
|
||||
// expected IOobject will be used in its resolution.
|
||||
// This expected name can provided via the ioName parameter.
|
||||
static IOobject selectIO
|
||||
(
|
||||
const IOobject& io,
|
||||
const fileName& altFile,
|
||||
const word& ioName = ""
|
||||
);
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
@ -290,7 +312,7 @@ public:
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~IOobject();
|
||||
virtual ~IOobject() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
@ -355,10 +377,10 @@ public:
|
||||
// Path components
|
||||
|
||||
//- Return group (extension part of name)
|
||||
word group() const;
|
||||
inline word group() const;
|
||||
|
||||
//- Return member (name without the extension)
|
||||
word member() const;
|
||||
inline word member() const;
|
||||
|
||||
const fileName& rootPath() const;
|
||||
|
||||
@ -370,17 +392,17 @@ public:
|
||||
|
||||
inline const fileName& local() const;
|
||||
|
||||
//- Return complete path
|
||||
//- The complete path
|
||||
fileName path() const;
|
||||
|
||||
//- Return complete path with alternative instance and local
|
||||
//- The complete path with alternative instance and local
|
||||
fileName path
|
||||
(
|
||||
const word& instance,
|
||||
const fileName& local = fileName::null
|
||||
) const;
|
||||
|
||||
//- Return complete path + object name
|
||||
//- The complete path + object name
|
||||
inline fileName objectPath() const;
|
||||
|
||||
//- Helper for filePath that searches locally.
|
||||
|
||||
@ -32,10 +32,8 @@ inline Foam::word Foam::IOobject::groupName(StringType name, const word& group)
|
||||
{
|
||||
return name;
|
||||
}
|
||||
else
|
||||
{
|
||||
return name + ('.' + group);
|
||||
}
|
||||
|
||||
return name + ('.' + group);
|
||||
}
|
||||
|
||||
|
||||
@ -49,6 +47,18 @@ inline const Foam::word& Foam::IOobject::name() const
|
||||
}
|
||||
|
||||
|
||||
inline Foam::word Foam::IOobject::group() const
|
||||
{
|
||||
return name_.ext();
|
||||
}
|
||||
|
||||
|
||||
inline Foam::word Foam::IOobject::member() const
|
||||
{
|
||||
return name_.lessExt();
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::word& Foam::IOobject::headerClassName() const
|
||||
{
|
||||
return headerClassName_;
|
||||
|
||||
@ -26,7 +26,7 @@ License
|
||||
#include "IOobject.H"
|
||||
#include "dictionary.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::IOobject::readHeader(Istream& is)
|
||||
{
|
||||
|
||||
@ -21,10 +21,6 @@ License
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Description
|
||||
Writes the header description of the File to the stream
|
||||
associated with the File.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "IOobject.H"
|
||||
|
||||
@ -1,28 +1,12 @@
|
||||
fileName dictPath;
|
||||
if (args.readIfPresent("dict", dictPath))
|
||||
{
|
||||
if (isDir(dictPath))
|
||||
{
|
||||
dictPath = dictPath / dictName;
|
||||
}
|
||||
}
|
||||
|
||||
IOobject dictIO
|
||||
IOobject dictIO = IOobject::selectIO
|
||||
(
|
||||
dictName,
|
||||
runTime.constant(),
|
||||
mesh,
|
||||
IOobject::MUST_READ_IF_MODIFIED,
|
||||
IOobject::NO_WRITE
|
||||
);
|
||||
|
||||
if (dictPath.size())
|
||||
{
|
||||
dictIO = IOobject
|
||||
IOobject
|
||||
(
|
||||
dictPath,
|
||||
dictName,
|
||||
runTime.constant(),
|
||||
mesh,
|
||||
IOobject::MUST_READ_IF_MODIFIED,
|
||||
IOobject::NO_WRITE
|
||||
);
|
||||
}
|
||||
),
|
||||
args.lookupOrDefault<fileName>("dict", "")
|
||||
);
|
||||
|
||||
12
src/OpenFOAM/include/setConstantRunTimeDictionaryIO.H
Normal file
12
src/OpenFOAM/include/setConstantRunTimeDictionaryIO.H
Normal file
@ -0,0 +1,12 @@
|
||||
IOobject dictIO = IOobject::selectIO
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
dictName,
|
||||
runTime.constant(),
|
||||
runTime,
|
||||
IOobject::MUST_READ_IF_MODIFIED,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
args.lookupOrDefault<fileName>("dict", "")
|
||||
);
|
||||
@ -1,28 +1,12 @@
|
||||
fileName dictPath;
|
||||
if (args.readIfPresent("dict", dictPath))
|
||||
{
|
||||
if (isDir(dictPath))
|
||||
{
|
||||
dictPath = dictPath / dictName;
|
||||
}
|
||||
}
|
||||
|
||||
IOobject dictIO
|
||||
IOobject dictIO = IOobject::selectIO
|
||||
(
|
||||
dictName,
|
||||
runTime.system(),
|
||||
mesh,
|
||||
IOobject::MUST_READ_IF_MODIFIED,
|
||||
IOobject::NO_WRITE
|
||||
);
|
||||
|
||||
if (dictPath.size())
|
||||
{
|
||||
dictIO = IOobject
|
||||
IOobject
|
||||
(
|
||||
dictPath.expand(),
|
||||
dictName,
|
||||
runTime.system(),
|
||||
mesh,
|
||||
IOobject::MUST_READ_IF_MODIFIED,
|
||||
IOobject::NO_WRITE
|
||||
);
|
||||
}
|
||||
),
|
||||
args.lookupOrDefault<fileName>("dict", "")
|
||||
);
|
||||
|
||||
@ -1,28 +1,12 @@
|
||||
fileName dictPath;
|
||||
if (args.readIfPresent("dict", dictPath))
|
||||
{
|
||||
if (isDir(dictPath))
|
||||
{
|
||||
dictPath = dictPath / dictName;
|
||||
}
|
||||
}
|
||||
|
||||
IOobject dictIO
|
||||
IOobject dictIO = IOobject::selectIO
|
||||
(
|
||||
dictName,
|
||||
runTime.system(),
|
||||
runTime,
|
||||
IOobject::MUST_READ_IF_MODIFIED,
|
||||
IOobject::NO_WRITE
|
||||
);
|
||||
|
||||
if (dictPath.size())
|
||||
{
|
||||
dictIO = IOobject
|
||||
IOobject
|
||||
(
|
||||
dictPath.expand(),
|
||||
dictName,
|
||||
runTime.system(),
|
||||
runTime,
|
||||
IOobject::MUST_READ_IF_MODIFIED,
|
||||
IOobject::NO_WRITE
|
||||
);
|
||||
}
|
||||
),
|
||||
args.lookupOrDefault<fileName>("dict", "")
|
||||
);
|
||||
|
||||
@ -41,7 +41,7 @@ Foam::lumpedPointIOMovement::lookupInRegistry(const objectRegistry& obr)
|
||||
{
|
||||
return obr.lookupObjectPtr<lumpedPointIOMovement>
|
||||
(
|
||||
lumpedPointMovement::dictionaryName
|
||||
lumpedPointMovement::canonicalName
|
||||
);
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ Foam::lumpedPointIOMovement::New
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
lumpedPointMovement::dictionaryName,
|
||||
lumpedPointMovement::canonicalName,
|
||||
obr.time().caseSystem(),
|
||||
obr,
|
||||
IOobject::MUST_READ,
|
||||
|
||||
@ -61,7 +61,7 @@ Foam::lumpedPointMovement::scalingNames
|
||||
|
||||
|
||||
const Foam::word
|
||||
Foam::lumpedPointMovement::dictionaryName("lumpedPointMovement");
|
||||
Foam::lumpedPointMovement::canonicalName("lumpedPointMovement");
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||
@ -117,31 +117,6 @@ static void writeList(Ostream& os, const string& header, const UList<T>& list)
|
||||
} // End namespace Foam
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
Foam::IOobject Foam::lumpedPointMovement::selectIO
|
||||
(
|
||||
const IOobject& io,
|
||||
const fileName& f
|
||||
)
|
||||
{
|
||||
return
|
||||
(
|
||||
f.size()
|
||||
? IOobject // construct from filePath instead
|
||||
(
|
||||
f,
|
||||
io.db(),
|
||||
io.readOpt(),
|
||||
io.writeOpt(),
|
||||
io.registerObject(),
|
||||
io.globalObject()
|
||||
)
|
||||
: io
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::lumpedPointMovement::calcThresholds() const
|
||||
|
||||
@ -238,11 +238,8 @@ public:
|
||||
|
||||
// Static data members
|
||||
|
||||
//- The standard dictionary name
|
||||
static const word dictionaryName;
|
||||
|
||||
//- Helper: return IOobject with optionally absolute path provided
|
||||
static IOobject selectIO(const IOobject&, const fileName&);
|
||||
//- The canonical name ("lumpedPointMovement") for the dictionary
|
||||
static const word canonicalName;
|
||||
|
||||
|
||||
// Constructors
|
||||
@ -460,6 +457,22 @@ public:
|
||||
const labelUList& patchLst,
|
||||
const pointField& points0
|
||||
) const;
|
||||
|
||||
|
||||
// Housekeeping
|
||||
|
||||
//- Compatibility method
|
||||
// \deprecated use IOobject::selectIO directly (AUG-2018)
|
||||
static IOobject selectIO
|
||||
(
|
||||
const IOobject& io,
|
||||
const fileName& altFile,
|
||||
const word& ioName = ""
|
||||
)
|
||||
{
|
||||
return IOobject::selectIO(io, altFile, ioName);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -34,6 +34,8 @@ namespace Foam
|
||||
defineTypeNameAndDebug(decompositionModel, 0);
|
||||
}
|
||||
|
||||
const Foam::word Foam::decompositionModel::canonicalName("decomposeParDict");
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
@ -51,11 +53,11 @@ Foam::decompositionModel::decompositionModel
|
||||
>(mesh),
|
||||
IOdictionary
|
||||
(
|
||||
selectIO
|
||||
IOobject::selectIO
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"decomposeParDict",
|
||||
canonicalName,
|
||||
mesh.time().system(),
|
||||
mesh.local(),
|
||||
mesh.thisDb(),
|
||||
@ -85,11 +87,11 @@ Foam::decompositionModel::decompositionModel
|
||||
>(mesh),
|
||||
IOdictionary
|
||||
(
|
||||
selectIO
|
||||
IOobject::selectIO
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"decomposeParDict",
|
||||
canonicalName,
|
||||
mesh.time().system(),
|
||||
mesh.local(),
|
||||
mesh.thisDb(),
|
||||
@ -140,29 +142,4 @@ const Foam::decompositionModel& Foam::decompositionModel::New
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::IOobject Foam::decompositionModel::selectIO
|
||||
(
|
||||
const IOobject& io,
|
||||
const fileName& f
|
||||
)
|
||||
{
|
||||
return
|
||||
(
|
||||
f.size()
|
||||
? IOobject // construct from filePath instead
|
||||
(
|
||||
f,
|
||||
io.db(),
|
||||
io.readOpt(),
|
||||
io.writeOpt(),
|
||||
io.registerObject(),
|
||||
io.globalObject()
|
||||
)
|
||||
: io
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -28,6 +28,7 @@ Description
|
||||
MeshObject wrapper of decompositionMethod
|
||||
|
||||
SourceFiles
|
||||
decompositionModel.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
@ -43,7 +44,7 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
// Forward declarations
|
||||
class mapPolyMesh;
|
||||
class polyMesh;
|
||||
|
||||
@ -62,7 +63,7 @@ class decompositionModel
|
||||
public IOdictionary
|
||||
{
|
||||
|
||||
// Private data
|
||||
// Private Data
|
||||
|
||||
mutable autoPtr<decompositionMethod> decomposerPtr_;
|
||||
|
||||
@ -72,17 +73,21 @@ public:
|
||||
// Declare name of the class and its debug switch
|
||||
ClassName("decompositionModel");
|
||||
|
||||
//- The canonical name ("decomposeParDict") under which the
|
||||
//- MeshObject is registered
|
||||
static const word canonicalName;
|
||||
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Read (optionally from absolute path) & register on mesh
|
||||
//- Read (optionally from absolute path) and register on mesh
|
||||
static const decompositionModel& New
|
||||
(
|
||||
const polyMesh& mesh,
|
||||
const fileName& decompDictFile = ""
|
||||
);
|
||||
|
||||
//- Read (optionally from supplied dictionary) & register on mesh
|
||||
//- Read (optionally from supplied dictionary) and register on mesh
|
||||
static const decompositionModel& New
|
||||
(
|
||||
const polyMesh& mesh,
|
||||
@ -126,9 +131,6 @@ public:
|
||||
return *decomposerPtr_;
|
||||
}
|
||||
|
||||
//- Helper: return IOobject with optionally absolute path provided
|
||||
static IOobject selectIO(const IOobject& io, const fileName& f);
|
||||
|
||||
|
||||
// UpdateableMeshObject
|
||||
|
||||
@ -140,6 +142,21 @@ public:
|
||||
virtual void updateMesh(const mapPolyMesh&)
|
||||
{}
|
||||
|
||||
|
||||
// Housekeeping
|
||||
|
||||
//- Compatibility method
|
||||
// \deprecated use IOobject::selectIO directly (AUG-2018)
|
||||
static IOobject selectIO
|
||||
(
|
||||
const IOobject& io,
|
||||
const fileName& altFile,
|
||||
const word& ioName = ""
|
||||
)
|
||||
{
|
||||
return IOobject::selectIO(io, altFile, ioName);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -806,21 +806,17 @@ Foam::distributedTriSurfaceMesh::independentlyDistributedBbs
|
||||
{
|
||||
// Use singleton decomposeParDict. Cannot use decompositionModel
|
||||
// here since we've only got Time and not a mesh.
|
||||
if
|
||||
(
|
||||
searchableSurface::time().foundObject<IOdictionary>
|
||||
|
||||
const auto* dictPtr =
|
||||
searchableSurface::time().lookupObjectPtr<IOdictionary>
|
||||
(
|
||||
// == decompositionModel::canonicalName
|
||||
"decomposeParDict"
|
||||
)
|
||||
)
|
||||
{
|
||||
decomposer_ = decompositionMethod::New
|
||||
(
|
||||
searchableSurface::time().lookupObject<IOdictionary>
|
||||
(
|
||||
"decomposeParDict"
|
||||
)
|
||||
);
|
||||
|
||||
if (dictPtr)
|
||||
{
|
||||
decomposer_ = decompositionMethod::New(*dictPtr);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -832,6 +828,7 @@ Foam::distributedTriSurfaceMesh::independentlyDistributedBbs
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
// == decompositionModel::canonicalName
|
||||
"decomposeParDict",
|
||||
searchableSurface::time().system(),
|
||||
searchableSurface::time(),
|
||||
|
||||
Reference in New Issue
Block a user