diff --git a/applications/utilities/mesh/generation/blockMesh/blockMesh.C b/applications/utilities/mesh/generation/blockMesh/blockMesh.C index 3be403bfb2..bd4b18180b 100644 --- a/applications/utilities/mesh/generation/blockMesh/blockMesh.C +++ b/applications/utilities/mesh/generation/blockMesh/blockMesh.C @@ -149,7 +149,7 @@ int main(int argc, char *argv[]) { if (isDir(dictPath)) { - dictPath = dictPath / dictName; + dictPath /= dictName; } } // Check if dictionary is present in the constant directory @@ -255,10 +255,9 @@ int main(int argc, char *argv[]) const pointField& cellCentres = topo.cellCentres(); - forAll(cellCentres, celli) + for (const point& cc : cellCentres) { //point cc = b.blockShape().centre(b.points()); - const point& cc = cellCentres[celli]; str << "v " << cc.x() << ' ' << cc.y() << ' ' << cc.z() << nl; } @@ -388,9 +387,9 @@ int main(int argc, char *argv[]) { const polyPatchList& patches = mesh.boundaryMesh(); bool hasCyclic = false; - forAll(patches, patchi) + for (const polyPatch& pp : patches) { - if (isA(patches[patchi])) + if (isA(pp)) { hasCyclic = true; break; diff --git a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C index a2f4ac6fd7..f586cf1ac6 100644 --- a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C +++ b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C @@ -788,32 +788,29 @@ int main(int argc, char *argv[]) dictionary decomposeDict; if (Pstream::parRun()) { - fileName decompDictFile; - args.readIfPresent("decomposeParDict", decompDictFile); - - // A demand-driven decompositionMethod can have issues finding - // an alternative decomposeParDict location. + // Ensure demand-driven decompositionMethod finds alternative + // decomposeParDict location properly. IOdictionary* dictPtr = new IOdictionary ( - decompositionModel::selectIO + IOobject::selectIO ( IOobject ( - "decomposeParDict", + decompositionModel::canonicalName, runTime.system(), runTime, IOobject::MUST_READ, IOobject::NO_WRITE ), - decompDictFile + args.lookupOrDefault("decomposeParDict", "") ) ); // Store it on the object registry, but to be found it must also // have the expected "decomposeParDict" name. - dictPtr->rename("decomposeParDict"); + dictPtr->rename(decompositionModel::canonicalName); runTime.store(dictPtr); decomposeDict = *dictPtr; @@ -1425,7 +1422,7 @@ int main(int argc, char *argv[]) decomposeDict ) ); - decompositionMethod& decomposer = decomposerPtr(); + decompositionMethod& decomposer = *decomposerPtr; if (Pstream::parRun() && !decomposer.parallelAware()) { diff --git a/applications/utilities/mesh/manipulation/refineMesh/refineMesh.C b/applications/utilities/mesh/manipulation/refineMesh/refineMesh.C index 7d7ee1a7eb..be93e9d65c 100644 --- a/applications/utilities/mesh/manipulation/refineMesh/refineMesh.C +++ b/applications/utilities/mesh/manipulation/refineMesh/refineMesh.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -182,7 +182,6 @@ int main(int argc, char *argv[]) // Read/construct control dictionary // - const bool readDict = args.found("dict"); const bool refineAllCells = args.found("all"); const bool overwrite = args.found("overwrite"); @@ -191,55 +190,57 @@ int main(int argc, char *argv[]) // Dictionary to control refinement dictionary refineDict; - const word dictName("refineMeshDict"); - if (readDict) + // The -all option has precedence over -dict, or anything else + if (!refineAllCells) { - fileName dictPath = args["dict"]; - if (isDir(dictPath)) - { - dictPath = dictPath/dictName; - } + const word dictName("refineMeshDict"); - IOobject dictIO + // Obtain dictPath here for messages + fileName dictPath = args.lookupOrDefault("dict", ""); + + IOobject dictIO = IOobject::selectIO ( - dictPath, - mesh, - IOobject::MUST_READ + IOobject + ( + dictName, + runTime.system(), + mesh, + IOobject::MUST_READ + ), + dictPath ); - if (!dictIO.typeHeaderOk(true)) + // 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(true)) + { + refineDict = IOdictionary(dictIO); + + Info<< "Refining according to "; + + if (dictPath.empty()) + { + Info<< dictName; + } + else + { + 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); } - - Info<< "Refining according to " << dictPath << nl << endl; - - refineDict = IOdictionary(dictIO); - } - else if (!refineAllCells) - { - IOobject dictIO - ( - dictName, - runTime.system(), - mesh, - IOobject::MUST_READ - ); - - if (dictIO.typeHeaderOk(true)) - { - Info<< "Refining according to " << dictName << nl << endl; - - refineDict = IOdictionary(dictIO); - } - else - { - Info<< "Refinement dictionary " << dictName << " not found" << endl; - } } if (refineDict.size()) @@ -346,9 +347,8 @@ int main(int argc, char *argv[]) // Create cellSet with added cells for easy inspection cellSet newCells(mesh, "refinedCells", refCells.size()); - forAll(oldToNew, oldCelli) + for (const labelList& added : oldToNew) { - const labelList& added = oldToNew[oldCelli]; newCells.insert(added); } @@ -361,7 +361,6 @@ int main(int argc, char *argv[]) newCells.write(); - // // Invert cell split to construct map from new to old // @@ -392,9 +391,9 @@ int main(int argc, char *argv[]) if (added.size()) { - forAll(added, i) + for (const label celli : added) { - newToOld[added[i]] = oldCelli; + newToOld[celli] = oldCelli; } } else diff --git a/applications/utilities/parallelProcessing/decomposePar/decomposePar.C b/applications/utilities/parallelProcessing/decomposePar/decomposePar.C index 21b2268efc..92cbf96ba0 100644 --- a/applications/utilities/parallelProcessing/decomposePar/decomposePar.C +++ b/applications/utilities/parallelProcessing/decomposePar/decomposePar.C @@ -392,11 +392,11 @@ int main(int argc, char *argv[]) ( IOdictionary ( - decompositionModel::selectIO + IOobject::selectIO ( IOobject ( - "decomposeParDict", + decompositionModel::canonicalName, runTime.time().system(), regionDir, // region (if non-default) runTime, diff --git a/applications/utilities/preProcessing/mapFields/mapFields.C b/applications/utilities/preProcessing/mapFields/mapFields.C index 6a7d887347..75afb798bc 100644 --- a/applications/utilities/preProcessing/mapFields/mapFields.C +++ b/applications/utilities/preProcessing/mapFields/mapFields.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -51,29 +51,22 @@ int readNumProcs const Time& runTime ) { - const word dictName = "decomposeParDict"; - fileName dictFile; - if (args.readIfPresent(optionName, dictFile) && isDir(dictFile)) - { - dictFile = dictFile / dictName; - } - return decompositionMethod::nDomains ( IOdictionary ( - decompositionModel::selectIO + IOobject::selectIO ( IOobject ( - dictName, + decompositionModel::canonicalName, runTime.system(), runTime, IOobject::MUST_READ, IOobject::NO_WRITE, - false + false // do not register ), - dictFile + args.lookupOrDefault(optionName, "") ) ) ); diff --git a/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C b/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C index 7fa8af95e7..0ca90a5b7a 100644 --- a/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C +++ b/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -152,59 +152,29 @@ int main(int argc, char *argv[]) if (args.found("from") || args.found("to")) { - autoPtr csDictIoPtr; - - 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 + IOobject ioCsys = IOobject::selectIO + ( + IOobject ( - new IOobject - ( - dictPath, - runTime, - IOobject::MUST_READ, - IOobject::NO_WRITE, - false - ) - ); - } - else - { - csDictIoPtr.reset - ( - new IOobject - ( - dictName, - runTime.constant(), - runTime, - IOobject::MUST_READ, - IOobject::NO_WRITE, - false - ) - ); - } + coordinateSystems::typeName, + runTime.constant(), + runTime, + IOobject::MUST_READ, + IOobject::NO_WRITE, + false + ), + args.lookupOrDefault("dict", "") + ); - - if (!csDictIoPtr->typeHeaderOk(false)) + if (!ioCsys.typeHeaderOk(false)) { FatalErrorInFunction << "Cannot open coordinateSystems file\n " - << csDictIoPtr->objectPath() << nl + << ioCsys.objectPath() << nl << exit(FatalError); } - coordinateSystems csLst(csDictIoPtr()); + coordinateSystems csLst(ioCsys); if (args.found("from")) { diff --git a/applications/utilities/surface/surfaceMeshExport/surfaceMeshExport.C b/applications/utilities/surface/surfaceMeshExport/surfaceMeshExport.C index ffb717dfec..65abe34eb9 100644 --- a/applications/utilities/surface/surfaceMeshExport/surfaceMeshExport.C +++ b/applications/utilities/surface/surfaceMeshExport/surfaceMeshExport.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -141,53 +141,28 @@ int main(int argc, char *argv[]) if (args.found("from") || args.found("to")) { - autoPtr ioPtr; - - if (args.found("dict")) - { - const fileName dictPath = args["dict"]; - - ioPtr.reset + IOobject ioCsys = IOobject::selectIO + ( + IOobject ( - new IOobject - ( - ( - isDir(dictPath) - ? dictPath/coordinateSystems::typeName - : dictPath - ), - runTime, - IOobject::MUST_READ, - IOobject::NO_WRITE, - false - ) - ); - } - else - { - ioPtr.reset - ( - new IOobject - ( - coordinateSystems::typeName, - runTime.constant(), - runTime, - IOobject::MUST_READ, - IOobject::NO_WRITE, - false - ) - ); - } + coordinateSystems::typeName, + runTime.constant(), + runTime, + IOobject::MUST_READ, + IOobject::NO_WRITE, + false + ), + args.lookupOrDefault("dict", "") + ); - - if (!ioPtr->typeHeaderOk(false)) + if (!ioCsys.typeHeaderOk(false)) { FatalErrorInFunction - << ioPtr->objectPath() << nl + << ioCsys.objectPath() << nl << exit(FatalError); } - coordinateSystems csLst(ioPtr()); + coordinateSystems csLst(ioCsys); if (args.found("from")) { diff --git a/applications/utilities/surface/surfaceMeshImport/surfaceMeshImport.C b/applications/utilities/surface/surfaceMeshImport/surfaceMeshImport.C index 453a04b1f3..48b29a2118 100644 --- a/applications/utilities/surface/surfaceMeshImport/surfaceMeshImport.C +++ b/applications/utilities/surface/surfaceMeshImport/surfaceMeshImport.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -154,53 +154,28 @@ int main(int argc, char *argv[]) if (args.found("from") || args.found("to")) { - autoPtr ioPtr; - - if (args.found("dict")) - { - const fileName dictPath = args["dict"]; - - ioPtr.reset + IOobject ioCsys = IOobject::selectIO + ( + IOobject ( - new IOobject - ( - ( - isDir(dictPath) - ? dictPath/coordinateSystems::typeName - : dictPath - ), - runTime, - IOobject::MUST_READ, - IOobject::NO_WRITE, - false - ) - ); - } - else - { - ioPtr.reset - ( - new IOobject - ( - coordinateSystems::typeName, - runTime.constant(), - runTime, - IOobject::MUST_READ, - IOobject::NO_WRITE, - false - ) - ); - } + coordinateSystems::typeName, + runTime.constant(), + runTime, + IOobject::MUST_READ, + IOobject::NO_WRITE, + false + ), + args.lookupOrDefault("dict", "") + ); - - if (!ioPtr->typeHeaderOk(false)) + if (!ioCsys.typeHeaderOk(false)) { FatalErrorInFunction - << ioPtr->objectPath() << nl + << ioCsys.objectPath() << nl << exit(FatalError); } - coordinateSystems csLst(ioPtr()); + coordinateSystems csLst(ioCsys); if (args.found("from")) { diff --git a/applications/utilities/surface/surfaceRedistributePar/surfaceRedistributePar.C b/applications/utilities/surface/surfaceRedistributePar/surfaceRedistributePar.C index b24db921fb..41a8cd3486 100644 --- a/applications/utilities/surface/surfaceRedistributePar/surfaceRedistributePar.C +++ b/applications/utilities/surface/surfaceRedistributePar/surfaceRedistributePar.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / 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 This file is part of OpenFOAM. @@ -159,32 +159,29 @@ int main(int argc, char *argv[]) // -decomposeParDict option. if (distType == distributedTriSurfaceMesh::INDEPENDENT) { - fileName decompDictFile; - args.readIfPresent("decomposeParDict", decompDictFile); - - // A demand-driven decompositionMethod can have issues finding - // an alternative decomposeParDict location. + // Ensure demand-driven decompositionMethod finds alternative + // decomposeParDict location properly. IOdictionary* dictPtr = new IOdictionary ( - decompositionModel::selectIO + IOobject::selectIO ( IOobject ( - "decomposeParDict", + decompositionModel::canonicalName, runTime.system(), runTime, IOobject::MUST_READ, IOobject::NO_WRITE ), - decompDictFile + args.lookupOrDefault("decomposeParDict", "") ) ); // Store it on the object registry, but to be found it must also // have the expected "decomposeParDict" name. - dictPtr->rename("decomposeParDict"); + dictPtr->rename(decompositionModel::canonicalName); runTime.store(dictPtr); } diff --git a/src/OpenFOAM/db/IOobject/IOobject.C b/src/OpenFOAM/db/IOobject/IOobject.C index 16d2052583..ffb6d42ee2 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.C +++ b/src/OpenFOAM/db/IOobject/IOobject.C @@ -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(); } diff --git a/src/OpenFOAM/db/IOobject/IOobject.H b/src/OpenFOAM/db/IOobject/IOobject.H index 466d8086e5..0bf7c438a6 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.H +++ b/src/OpenFOAM/db/IOobject/IOobject.H @@ -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 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. diff --git a/src/OpenFOAM/db/IOobject/IOobjectI.H b/src/OpenFOAM/db/IOobject/IOobjectI.H index 3a97ffabf9..2bcea039d5 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectI.H +++ b/src/OpenFOAM/db/IOobject/IOobjectI.H @@ -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_; diff --git a/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C b/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C index b794f6c209..86418838a2 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C +++ b/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C @@ -26,7 +26,7 @@ License #include "IOobject.H" #include "dictionary.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // bool Foam::IOobject::readHeader(Istream& is) { diff --git a/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C b/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C index 96f47f61a6..441f0b893d 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C +++ b/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C @@ -21,10 +21,6 @@ License You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . -Description - Writes the header description of the File to the stream - associated with the File. - \*---------------------------------------------------------------------------*/ #include "IOobject.H" diff --git a/src/OpenFOAM/include/setConstantMeshDictionaryIO.H b/src/OpenFOAM/include/setConstantMeshDictionaryIO.H index 90571b7041..84be1121c2 100644 --- a/src/OpenFOAM/include/setConstantMeshDictionaryIO.H +++ b/src/OpenFOAM/include/setConstantMeshDictionaryIO.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("dict", "") +); diff --git a/src/OpenFOAM/include/setConstantRunTimeDictionaryIO.H b/src/OpenFOAM/include/setConstantRunTimeDictionaryIO.H new file mode 100644 index 0000000000..7333f2b54d --- /dev/null +++ b/src/OpenFOAM/include/setConstantRunTimeDictionaryIO.H @@ -0,0 +1,12 @@ +IOobject dictIO = IOobject::selectIO +( + IOobject + ( + dictName, + runTime.constant(), + runTime, + IOobject::MUST_READ_IF_MODIFIED, + IOobject::NO_WRITE + ), + args.lookupOrDefault("dict", "") +); diff --git a/src/OpenFOAM/include/setSystemMeshDictionaryIO.H b/src/OpenFOAM/include/setSystemMeshDictionaryIO.H index 230fc664d5..02d264b2d9 100644 --- a/src/OpenFOAM/include/setSystemMeshDictionaryIO.H +++ b/src/OpenFOAM/include/setSystemMeshDictionaryIO.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.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("dict", "") +); diff --git a/src/OpenFOAM/include/setSystemRunTimeDictionaryIO.H b/src/OpenFOAM/include/setSystemRunTimeDictionaryIO.H index 4761a564f8..98d4f1d551 100644 --- a/src/OpenFOAM/include/setSystemRunTimeDictionaryIO.H +++ b/src/OpenFOAM/include/setSystemRunTimeDictionaryIO.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.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("dict", "") +); diff --git a/src/lumpedPointMotion/lumpedPointIOMovement.C b/src/lumpedPointMotion/lumpedPointIOMovement.C index 5c52611762..81cc4073bb 100644 --- a/src/lumpedPointMotion/lumpedPointIOMovement.C +++ b/src/lumpedPointMotion/lumpedPointIOMovement.C @@ -41,7 +41,7 @@ Foam::lumpedPointIOMovement::lookupInRegistry(const objectRegistry& obr) { return obr.lookupObjectPtr ( - lumpedPointMovement::dictionaryName + lumpedPointMovement::canonicalName ); } @@ -57,7 +57,7 @@ Foam::lumpedPointIOMovement::New ( IOobject ( - lumpedPointMovement::dictionaryName, + lumpedPointMovement::canonicalName, obr.time().caseSystem(), obr, IOobject::MUST_READ, diff --git a/src/lumpedPointMotion/lumpedPointMovement.C b/src/lumpedPointMotion/lumpedPointMovement.C index 30b0f22f97..b29cc4e042 100644 --- a/src/lumpedPointMotion/lumpedPointMovement.C +++ b/src/lumpedPointMotion/lumpedPointMovement.C @@ -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& 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 diff --git a/src/lumpedPointMotion/lumpedPointMovement.H b/src/lumpedPointMotion/lumpedPointMovement.H index 4524b3e7e2..c575ccd729 100644 --- a/src/lumpedPointMotion/lumpedPointMovement.H +++ b/src/lumpedPointMotion/lumpedPointMovement.H @@ -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); + } + }; diff --git a/src/parallel/decompose/decompose/decompositionModel.C b/src/parallel/decompose/decompose/decompositionModel.C index b2c948c919..04046196a7 100644 --- a/src/parallel/decompose/decompose/decompositionModel.C +++ b/src/parallel/decompose/decompose/decompositionModel.C @@ -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 - ); -} - - // ************************************************************************* // diff --git a/src/parallel/decompose/decompose/decompositionModel.H b/src/parallel/decompose/decompose/decompositionModel.H index 9503bcf078..b89ad319a1 100644 --- a/src/parallel/decompose/decompose/decompositionModel.H +++ b/src/parallel/decompose/decompose/decompositionModel.H @@ -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 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); + } + }; diff --git a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C index c78d329a66..07e3fb0ed4 100644 --- a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C +++ b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C @@ -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 + + const auto* dictPtr = + searchableSurface::time().lookupObjectPtr ( + // == decompositionModel::canonicalName "decomposeParDict" - ) - ) - { - decomposer_ = decompositionMethod::New - ( - searchableSurface::time().lookupObject - ( - "decomposeParDict" - ) ); + + if (dictPtr) + { + decomposer_ = decompositionMethod::New(*dictPtr); } else { @@ -832,6 +828,7 @@ Foam::distributedTriSurfaceMesh::independentlyDistributedBbs ( IOobject ( + // == decompositionModel::canonicalName "decomposeParDict", searchableSurface::time().system(), searchableSurface::time(),