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:
Mark Olesen
2018-08-02 17:39:17 +02:00
parent 0e996431b7
commit 88e5334a9f
24 changed files with 303 additions and 402 deletions

View File

@ -149,7 +149,7 @@ int main(int argc, char *argv[])
{ {
if (isDir(dictPath)) if (isDir(dictPath))
{ {
dictPath = dictPath / dictName; dictPath /= dictName;
} }
} }
// Check if dictionary is present in the constant directory // Check if dictionary is present in the constant directory
@ -255,10 +255,9 @@ int main(int argc, char *argv[])
const pointField& cellCentres = topo.cellCentres(); const pointField& cellCentres = topo.cellCentres();
forAll(cellCentres, celli) for (const point& cc : cellCentres)
{ {
//point cc = b.blockShape().centre(b.points()); //point cc = b.blockShape().centre(b.points());
const point& cc = cellCentres[celli];
str << "v " << cc.x() << ' ' << cc.y() << ' ' << cc.z() << nl; str << "v " << cc.x() << ' ' << cc.y() << ' ' << cc.z() << nl;
} }
@ -388,9 +387,9 @@ int main(int argc, char *argv[])
{ {
const polyPatchList& patches = mesh.boundaryMesh(); const polyPatchList& patches = mesh.boundaryMesh();
bool hasCyclic = false; bool hasCyclic = false;
forAll(patches, patchi) for (const polyPatch& pp : patches)
{ {
if (isA<cyclicPolyPatch>(patches[patchi])) if (isA<cyclicPolyPatch>(pp))
{ {
hasCyclic = true; hasCyclic = true;
break; break;

View File

@ -788,32 +788,29 @@ int main(int argc, char *argv[])
dictionary decomposeDict; dictionary decomposeDict;
if (Pstream::parRun()) if (Pstream::parRun())
{ {
fileName decompDictFile; // Ensure demand-driven decompositionMethod finds alternative
args.readIfPresent("decomposeParDict", decompDictFile); // decomposeParDict location properly.
// A demand-driven decompositionMethod can have issues finding
// an alternative decomposeParDict location.
IOdictionary* dictPtr = new IOdictionary IOdictionary* dictPtr = new IOdictionary
( (
decompositionModel::selectIO IOobject::selectIO
( (
IOobject IOobject
( (
"decomposeParDict", decompositionModel::canonicalName,
runTime.system(), runTime.system(),
runTime, runTime,
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE IOobject::NO_WRITE
), ),
decompDictFile args.lookupOrDefault<fileName>("decomposeParDict", "")
) )
); );
// Store it on the object registry, but to be found it must also // Store it on the object registry, but to be found it must also
// have the expected "decomposeParDict" name. // have the expected "decomposeParDict" name.
dictPtr->rename("decomposeParDict"); dictPtr->rename(decompositionModel::canonicalName);
runTime.store(dictPtr); runTime.store(dictPtr);
decomposeDict = *dictPtr; decomposeDict = *dictPtr;
@ -1425,7 +1422,7 @@ int main(int argc, char *argv[])
decomposeDict decomposeDict
) )
); );
decompositionMethod& decomposer = decomposerPtr(); decompositionMethod& decomposer = *decomposerPtr;
if (Pstream::parRun() && !decomposer.parallelAware()) if (Pstream::parRun() && !decomposer.parallelAware())
{ {

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-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -182,7 +182,6 @@ int main(int argc, char *argv[])
// Read/construct control dictionary // Read/construct control dictionary
// //
const bool readDict = args.found("dict");
const bool refineAllCells = args.found("all"); const bool refineAllCells = args.found("all");
const bool overwrite = args.found("overwrite"); const bool overwrite = args.found("overwrite");
@ -191,54 +190,56 @@ int main(int argc, char *argv[])
// Dictionary to control refinement // Dictionary to control refinement
dictionary refineDict; dictionary refineDict;
// The -all option has precedence over -dict, or anything else
if (!refineAllCells)
{
const word dictName("refineMeshDict"); const word dictName("refineMeshDict");
if (readDict) // Obtain dictPath here for messages
{ fileName dictPath = args.lookupOrDefault<fileName>("dict", "");
fileName dictPath = args["dict"];
if (isDir(dictPath))
{
dictPath = dictPath/dictName;
}
IOobject dictIO IOobject dictIO = IOobject::selectIO
( (
dictPath, IOobject
mesh,
IOobject::MUST_READ
);
if (!dictIO.typeHeaderOk<IOdictionary>(true))
{
FatalErrorInFunction
<< "Cannot open specified refinement dictionary "
<< dictPath
<< exit(FatalError);
}
Info<< "Refining according to " << dictPath << nl << endl;
refineDict = IOdictionary(dictIO);
}
else if (!refineAllCells)
{
IOobject dictIO
( (
dictName, dictName,
runTime.system(), runTime.system(),
mesh, mesh,
IOobject::MUST_READ IOobject::MUST_READ
),
dictPath
); );
// The reported dictPath will not be full resolved for the output
// (it will just be the -dict value) but this is purely cosmetic.
if (dictIO.typeHeaderOk<IOdictionary>(true)) if (dictIO.typeHeaderOk<IOdictionary>(true))
{ {
Info<< "Refining according to " << dictName << nl << endl;
refineDict = IOdictionary(dictIO); refineDict = IOdictionary(dictIO);
Info<< "Refining according to ";
if (dictPath.empty())
{
Info<< dictName;
} }
else else
{ {
Info<< "Refinement dictionary " << dictName << " not found" << endl; Info<< dictPath;
}
Info<< nl << endl;
}
else if (dictPath.empty())
{
Info<< "Refinement dictionary " << dictName << " not found" << nl;
}
else
{
FatalErrorInFunction
<< "Cannot open specified refinement dictionary "
<< dictPath
<< exit(FatalError);
} }
} }
@ -346,9 +347,8 @@ int main(int argc, char *argv[])
// Create cellSet with added cells for easy inspection // Create cellSet with added cells for easy inspection
cellSet newCells(mesh, "refinedCells", refCells.size()); cellSet newCells(mesh, "refinedCells", refCells.size());
forAll(oldToNew, oldCelli) for (const labelList& added : oldToNew)
{ {
const labelList& added = oldToNew[oldCelli];
newCells.insert(added); newCells.insert(added);
} }
@ -361,7 +361,6 @@ int main(int argc, char *argv[])
newCells.write(); newCells.write();
// //
// Invert cell split to construct map from new to old // Invert cell split to construct map from new to old
// //
@ -392,9 +391,9 @@ int main(int argc, char *argv[])
if (added.size()) if (added.size())
{ {
forAll(added, i) for (const label celli : added)
{ {
newToOld[added[i]] = oldCelli; newToOld[celli] = oldCelli;
} }
} }
else else

View File

@ -392,11 +392,11 @@ int main(int argc, char *argv[])
( (
IOdictionary IOdictionary
( (
decompositionModel::selectIO IOobject::selectIO
( (
IOobject IOobject
( (
"decomposeParDict", decompositionModel::canonicalName,
runTime.time().system(), runTime.time().system(),
regionDir, // region (if non-default) regionDir, // region (if non-default)
runTime, runTime,

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-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -51,29 +51,22 @@ int readNumProcs
const Time& runTime const Time& runTime
) )
{ {
const word dictName = "decomposeParDict";
fileName dictFile;
if (args.readIfPresent(optionName, dictFile) && isDir(dictFile))
{
dictFile = dictFile / dictName;
}
return decompositionMethod::nDomains return decompositionMethod::nDomains
( (
IOdictionary IOdictionary
( (
decompositionModel::selectIO IOobject::selectIO
( (
IOobject IOobject
( (
dictName, decompositionModel::canonicalName,
runTime.system(), runTime.system(),
runTime, runTime,
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false false // do not register
), ),
dictFile args.lookupOrDefault<fileName>(optionName, "")
) )
) )
); );

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-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -152,59 +152,29 @@ int main(int argc, char *argv[])
if (args.found("from") || args.found("to")) if (args.found("from") || args.found("to"))
{ {
autoPtr<IOobject> csDictIoPtr; IOobject ioCsys = IOobject::selectIO
const word dictName("coordinateSystems::typeName");
// Note: cannot use setSystemRunTimeDictionaryIO.H since dictionary
// is in constant
fileName dictPath;
if (args.readIfPresent("dict", dictPath) && isDir(dictPath))
{
dictPath = dictPath / dictName;
}
if (dictPath.size())
{
csDictIoPtr.reset
( (
new IOobject IOobject
( (
dictPath, coordinateSystems::typeName,
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
}
else
{
csDictIoPtr.reset
(
new IOobject
(
dictName,
runTime.constant(), runTime.constant(),
runTime, runTime,
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false false
) ),
args.lookupOrDefault<fileName>("dict", "")
); );
}
if (!ioCsys.typeHeaderOk<coordinateSystems>(false))
if (!csDictIoPtr->typeHeaderOk<coordinateSystems>(false))
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Cannot open coordinateSystems file\n " << "Cannot open coordinateSystems file\n "
<< csDictIoPtr->objectPath() << nl << ioCsys.objectPath() << nl
<< exit(FatalError); << exit(FatalError);
} }
coordinateSystems csLst(csDictIoPtr()); coordinateSystems csLst(ioCsys);
if (args.found("from")) if (args.found("from"))
{ {

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-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -141,33 +141,9 @@ int main(int argc, char *argv[])
if (args.found("from") || args.found("to")) if (args.found("from") || args.found("to"))
{ {
autoPtr<IOobject> ioPtr; IOobject ioCsys = IOobject::selectIO
if (args.found("dict"))
{
const fileName dictPath = args["dict"];
ioPtr.reset
( (
new IOobject IOobject
(
(
isDir(dictPath)
? dictPath/coordinateSystems::typeName
: dictPath
),
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
}
else
{
ioPtr.reset
(
new IOobject
( (
coordinateSystems::typeName, coordinateSystems::typeName,
runTime.constant(), runTime.constant(),
@ -175,19 +151,18 @@ int main(int argc, char *argv[])
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false false
) ),
args.lookupOrDefault<fileName>("dict", "")
); );
}
if (!ioCsys.typeHeaderOk<coordinateSystems>(false))
if (!ioPtr->typeHeaderOk<coordinateSystems>(false))
{ {
FatalErrorInFunction FatalErrorInFunction
<< ioPtr->objectPath() << nl << ioCsys.objectPath() << nl
<< exit(FatalError); << exit(FatalError);
} }
coordinateSystems csLst(ioPtr()); coordinateSystems csLst(ioCsys);
if (args.found("from")) if (args.found("from"))
{ {

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-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -154,33 +154,9 @@ int main(int argc, char *argv[])
if (args.found("from") || args.found("to")) if (args.found("from") || args.found("to"))
{ {
autoPtr<IOobject> ioPtr; IOobject ioCsys = IOobject::selectIO
if (args.found("dict"))
{
const fileName dictPath = args["dict"];
ioPtr.reset
( (
new IOobject IOobject
(
(
isDir(dictPath)
? dictPath/coordinateSystems::typeName
: dictPath
),
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
}
else
{
ioPtr.reset
(
new IOobject
( (
coordinateSystems::typeName, coordinateSystems::typeName,
runTime.constant(), runTime.constant(),
@ -188,19 +164,18 @@ int main(int argc, char *argv[])
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false false
) ),
args.lookupOrDefault<fileName>("dict", "")
); );
}
if (!ioCsys.typeHeaderOk<coordinateSystems>(false))
if (!ioPtr->typeHeaderOk<coordinateSystems>(false))
{ {
FatalErrorInFunction FatalErrorInFunction
<< ioPtr->objectPath() << nl << ioCsys.objectPath() << nl
<< exit(FatalError); << exit(FatalError);
} }
coordinateSystems csLst(ioPtr()); coordinateSystems csLst(ioCsys);
if (args.found("from")) if (args.found("from"))
{ {

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-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -159,32 +159,29 @@ int main(int argc, char *argv[])
// -decomposeParDict option. // -decomposeParDict option.
if (distType == distributedTriSurfaceMesh::INDEPENDENT) if (distType == distributedTriSurfaceMesh::INDEPENDENT)
{ {
fileName decompDictFile; // Ensure demand-driven decompositionMethod finds alternative
args.readIfPresent("decomposeParDict", decompDictFile); // decomposeParDict location properly.
// A demand-driven decompositionMethod can have issues finding
// an alternative decomposeParDict location.
IOdictionary* dictPtr = new IOdictionary IOdictionary* dictPtr = new IOdictionary
( (
decompositionModel::selectIO IOobject::selectIO
( (
IOobject IOobject
( (
"decomposeParDict", decompositionModel::canonicalName,
runTime.system(), runTime.system(),
runTime, runTime,
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE IOobject::NO_WRITE
), ),
decompDictFile args.lookupOrDefault<fileName>("decomposeParDict", "")
) )
); );
// Store it on the object registry, but to be found it must also // Store it on the object registry, but to be found it must also
// have the expected "decomposeParDict" name. // have the expected "decomposeParDict" name.
dictPtr->rename("decomposeParDict"); dictPtr->rename(decompositionModel::canonicalName);
runTime.store(dictPtr); runTime.store(dictPtr);
} }

View File

@ -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 * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::IOobject::IOobject Foam::IOobject::IOobject
@ -339,12 +384,6 @@ Foam::IOobject::IOobject
{} {}
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
Foam::IOobject::~IOobject()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::objectRegistry& Foam::IOobject::db() const 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 Foam::fileName Foam::IOobject::path() const
{ {
if (isOutsideOfCase(instance())) if (isOutsideOfCase(instance()))
{ {
return instance(); return instance();
} }
else
{
return rootPath()/caseName()/instance()/db_.dbDir()/local(); return rootPath()/caseName()/instance()/db_.dbDir()/local();
}
} }

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-2017 OpenFOAM Foundation \\ / 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 License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,7 +25,7 @@ Class
Foam::IOobject Foam::IOobject
Description 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 objectRegistry management is supported, and provides the infrastructure
for performing stream I/O. for performing stream I/O.
@ -83,6 +83,7 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declarations
class Time; class Time;
class objectRegistry; class objectRegistry;
@ -184,7 +185,7 @@ public:
TypeName("IOobject"); TypeName("IOobject");
// Static data members // Static Data Members
//- Type of file modification checking //- Type of file modification checking
static fileCheckTypes fileModificationChecking; static fileCheckTypes fileModificationChecking;
@ -219,6 +220,27 @@ public:
template<class StringType> template<class StringType>
static inline word groupName(StringType name, const word& group); 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 // Constructors
@ -290,7 +312,7 @@ public:
//- Destructor //- Destructor
virtual ~IOobject(); virtual ~IOobject() = default;
// Member Functions // Member Functions
@ -355,10 +377,10 @@ public:
// Path components // Path components
//- Return group (extension part of name) //- Return group (extension part of name)
word group() const; inline word group() const;
//- Return member (name without the extension) //- Return member (name without the extension)
word member() const; inline word member() const;
const fileName& rootPath() const; const fileName& rootPath() const;
@ -370,17 +392,17 @@ public:
inline const fileName& local() const; inline const fileName& local() const;
//- Return complete path //- The complete path
fileName path() const; fileName path() const;
//- Return complete path with alternative instance and local //- The complete path with alternative instance and local
fileName path fileName path
( (
const word& instance, const word& instance,
const fileName& local = fileName::null const fileName& local = fileName::null
) const; ) const;
//- Return complete path + object name //- The complete path + object name
inline fileName objectPath() const; inline fileName objectPath() const;
//- Helper for filePath that searches locally. //- Helper for filePath that searches locally.

View File

@ -32,10 +32,8 @@ inline Foam::word Foam::IOobject::groupName(StringType name, const word& group)
{ {
return name; 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 inline const Foam::word& Foam::IOobject::headerClassName() const
{ {
return headerClassName_; return headerClassName_;

View File

@ -26,7 +26,7 @@ License
#include "IOobject.H" #include "IOobject.H"
#include "dictionary.H" #include "dictionary.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::IOobject::readHeader(Istream& is) bool Foam::IOobject::readHeader(Istream& is)
{ {

View File

@ -21,10 +21,6 @@ License
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. 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" #include "IOobject.H"

View File

@ -1,28 +1,12 @@
fileName dictPath; IOobject dictIO = IOobject::selectIO
if (args.readIfPresent("dict", dictPath))
{
if (isDir(dictPath))
{
dictPath = dictPath / dictName;
}
}
IOobject dictIO
( (
IOobject
(
dictName, dictName,
runTime.constant(), runTime.constant(),
mesh, mesh,
IOobject::MUST_READ_IF_MODIFIED, IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE IOobject::NO_WRITE
),
args.lookupOrDefault<fileName>("dict", "")
); );
if (dictPath.size())
{
dictIO = IOobject
(
dictPath,
mesh,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
);
}

View 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", "")
);

View File

@ -1,28 +1,12 @@
fileName dictPath; IOobject dictIO = IOobject::selectIO
if (args.readIfPresent("dict", dictPath))
{
if (isDir(dictPath))
{
dictPath = dictPath / dictName;
}
}
IOobject dictIO
( (
IOobject
(
dictName, dictName,
runTime.system(), runTime.system(),
mesh, mesh,
IOobject::MUST_READ_IF_MODIFIED, IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE IOobject::NO_WRITE
),
args.lookupOrDefault<fileName>("dict", "")
); );
if (dictPath.size())
{
dictIO = IOobject
(
dictPath.expand(),
mesh,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
);
}

View File

@ -1,28 +1,12 @@
fileName dictPath; IOobject dictIO = IOobject::selectIO
if (args.readIfPresent("dict", dictPath))
{
if (isDir(dictPath))
{
dictPath = dictPath / dictName;
}
}
IOobject dictIO
( (
IOobject
(
dictName, dictName,
runTime.system(), runTime.system(),
runTime, runTime,
IOobject::MUST_READ_IF_MODIFIED, IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE IOobject::NO_WRITE
),
args.lookupOrDefault<fileName>("dict", "")
); );
if (dictPath.size())
{
dictIO = IOobject
(
dictPath.expand(),
runTime,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
);
}

View File

@ -41,7 +41,7 @@ Foam::lumpedPointIOMovement::lookupInRegistry(const objectRegistry& obr)
{ {
return obr.lookupObjectPtr<lumpedPointIOMovement> return obr.lookupObjectPtr<lumpedPointIOMovement>
( (
lumpedPointMovement::dictionaryName lumpedPointMovement::canonicalName
); );
} }
@ -57,7 +57,7 @@ Foam::lumpedPointIOMovement::New
( (
IOobject IOobject
( (
lumpedPointMovement::dictionaryName, lumpedPointMovement::canonicalName,
obr.time().caseSystem(), obr.time().caseSystem(),
obr, obr,
IOobject::MUST_READ, IOobject::MUST_READ,

View File

@ -61,7 +61,7 @@ Foam::lumpedPointMovement::scalingNames
const Foam::word const Foam::word
Foam::lumpedPointMovement::dictionaryName("lumpedPointMovement"); Foam::lumpedPointMovement::canonicalName("lumpedPointMovement");
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
@ -117,31 +117,6 @@ static void writeList(Ostream& os, const string& header, const UList<T>& list)
} // End namespace Foam } // 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 * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::lumpedPointMovement::calcThresholds() const void Foam::lumpedPointMovement::calcThresholds() const

View File

@ -238,11 +238,8 @@ public:
// Static data members // Static data members
//- The standard dictionary name //- The canonical name ("lumpedPointMovement") for the dictionary
static const word dictionaryName; static const word canonicalName;
//- Helper: return IOobject with optionally absolute path provided
static IOobject selectIO(const IOobject&, const fileName&);
// Constructors // Constructors
@ -460,6 +457,22 @@ public:
const labelUList& patchLst, const labelUList& patchLst,
const pointField& points0 const pointField& points0
) const; ) 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);
}
}; };

View File

@ -34,6 +34,8 @@ namespace Foam
defineTypeNameAndDebug(decompositionModel, 0); defineTypeNameAndDebug(decompositionModel, 0);
} }
const Foam::word Foam::decompositionModel::canonicalName("decomposeParDict");
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -51,11 +53,11 @@ Foam::decompositionModel::decompositionModel
>(mesh), >(mesh),
IOdictionary IOdictionary
( (
selectIO IOobject::selectIO
( (
IOobject IOobject
( (
"decomposeParDict", canonicalName,
mesh.time().system(), mesh.time().system(),
mesh.local(), mesh.local(),
mesh.thisDb(), mesh.thisDb(),
@ -85,11 +87,11 @@ Foam::decompositionModel::decompositionModel
>(mesh), >(mesh),
IOdictionary IOdictionary
( (
selectIO IOobject::selectIO
( (
IOobject IOobject
( (
"decomposeParDict", canonicalName,
mesh.time().system(), mesh.time().system(),
mesh.local(), mesh.local(),
mesh.thisDb(), 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
);
}
// ************************************************************************* // // ************************************************************************* //

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) 2014-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -28,6 +28,7 @@ Description
MeshObject wrapper of decompositionMethod MeshObject wrapper of decompositionMethod
SourceFiles SourceFiles
decompositionModel.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -43,7 +44,7 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declaration of classes // Forward declarations
class mapPolyMesh; class mapPolyMesh;
class polyMesh; class polyMesh;
@ -62,7 +63,7 @@ class decompositionModel
public IOdictionary public IOdictionary
{ {
// Private data // Private Data
mutable autoPtr<decompositionMethod> decomposerPtr_; mutable autoPtr<decompositionMethod> decomposerPtr_;
@ -72,17 +73,21 @@ public:
// Declare name of the class and its debug switch // Declare name of the class and its debug switch
ClassName("decompositionModel"); ClassName("decompositionModel");
//- The canonical name ("decomposeParDict") under which the
//- MeshObject is registered
static const word canonicalName;
// Selectors // Selectors
//- Read (optionally from absolute path) & register on mesh //- Read (optionally from absolute path) and register on mesh
static const decompositionModel& New static const decompositionModel& New
( (
const polyMesh& mesh, const polyMesh& mesh,
const fileName& decompDictFile = "" const fileName& decompDictFile = ""
); );
//- Read (optionally from supplied dictionary) & register on mesh //- Read (optionally from supplied dictionary) and register on mesh
static const decompositionModel& New static const decompositionModel& New
( (
const polyMesh& mesh, const polyMesh& mesh,
@ -126,9 +131,6 @@ public:
return *decomposerPtr_; return *decomposerPtr_;
} }
//- Helper: return IOobject with optionally absolute path provided
static IOobject selectIO(const IOobject& io, const fileName& f);
// UpdateableMeshObject // UpdateableMeshObject
@ -140,6 +142,21 @@ public:
virtual void updateMesh(const mapPolyMesh&) 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);
}
}; };

View File

@ -806,21 +806,17 @@ Foam::distributedTriSurfaceMesh::independentlyDistributedBbs
{ {
// Use singleton decomposeParDict. Cannot use decompositionModel // Use singleton decomposeParDict. Cannot use decompositionModel
// here since we've only got Time and not a mesh. // here since we've only got Time and not a mesh.
if
( const auto* dictPtr =
searchableSurface::time().foundObject<IOdictionary> searchableSurface::time().lookupObjectPtr<IOdictionary>
( (
// == decompositionModel::canonicalName
"decomposeParDict" "decomposeParDict"
)
)
{
decomposer_ = decompositionMethod::New
(
searchableSurface::time().lookupObject<IOdictionary>
(
"decomposeParDict"
)
); );
if (dictPtr)
{
decomposer_ = decompositionMethod::New(*dictPtr);
} }
else else
{ {
@ -832,6 +828,7 @@ Foam::distributedTriSurfaceMesh::independentlyDistributedBbs
( (
IOobject IOobject
( (
// == decompositionModel::canonicalName
"decomposeParDict", "decomposeParDict",
searchableSurface::time().system(), searchableSurface::time().system(),
searchableSurface::time(), searchableSurface::time(),