systemDict: Consistent handling of the -dict option

The -dict option is now handled correctly and consistently across all
applications with -dict options. The logic associated with doing so has
been centralised.

If a relative path is given to the -dict option, then it is assumed to
be relative to the case directory. If an absolute path is given, then it
is used without reference to the case directory. In both cases, if the
path is found to be a directory, then the standard dictionary name is
appended to the path.

Resolves bug report http://bugs.openfoam.org/view.php?id=3692
This commit is contained in:
Will Bainbridge
2021-07-02 11:44:02 +01:00
parent 2fe27ab56e
commit c63c1a90c2
17 changed files with 113 additions and 233 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -51,6 +51,7 @@ Usage
#include "Time.H" #include "Time.H"
#include "IOdictionary.H" #include "IOdictionary.H"
#include "IOPtrList.H" #include "IOPtrList.H"
#include "systemDict.H"
#include "blockMesh.H" #include "blockMesh.H"
#include "attachPolyTopoChanger.H" #include "attachPolyTopoChanger.H"
@ -72,6 +73,7 @@ using namespace Foam;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
argList::noParallel(); argList::noParallel();
#include "addDictOption.H"
argList::addBoolOption argList::addBoolOption
( (
"blockTopology", "blockTopology",
@ -82,12 +84,6 @@ int main(int argc, char *argv[])
"noClean", "noClean",
"keep the existing files in the polyMesh" "keep the existing files in the polyMesh"
); );
argList::addOption
(
"dict",
"file",
"specify alternative dictionary for the blockMesh description"
);
argList::addNote argList::addNote
( (
@ -129,42 +125,6 @@ int main(int argc, char *argv[])
regionPath = regionName; regionPath = regionName;
} }
// Search for the appropriate blockMesh dictionary....
fileName dictPath;
// Check if the dictionary is specified on the command-line
if (args.optionFound("dict"))
{
dictPath = args["dict"];
dictPath =
(
isDir(dictPath)
? dictPath/dictName
: dictPath
);
}
// Check if dictionary is present in the constant directory
else if
(
exists
(
runTime.path()/runTime.constant()
/regionPath/polyMesh::meshSubDir/dictName
)
)
{
dictPath =
runTime.constant()
/regionPath/polyMesh::meshSubDir/dictName;
}
// Otherwise assume the dictionary is present in the system directory
else
{
dictPath = runTime.system()/regionPath/dictName;
}
if (!args.optionFound("noClean")) if (!args.optionFound("noClean"))
{ {
fileName polyMeshPath fileName polyMeshPath
@ -189,14 +149,7 @@ int main(int argc, char *argv[])
} }
} }
IOobject meshDictIO IOobject meshDictIO(systemDictIO(dictName, args, runTime, regionName));
(
dictPath,
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
);
if (!meshDictIO.typeHeaderOk<IOdictionary>(true)) if (!meshDictIO.typeHeaderOk<IOdictionary>(true))
{ {

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -29,20 +29,10 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::mirrorFvMesh::mirrorFvMesh(const IOobject& io, const word& dictName) Foam::mirrorFvMesh::mirrorFvMesh(const IOobject& io, const IOobject& dictIO)
: :
fvMesh(io), fvMesh(io),
mirrorMeshDict_ mirrorMeshDict_(dictIO)
(
IOobject
(
dictName,
time().system(),
*this,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
{ {
plane mirrorPlane(mirrorMeshDict_); plane mirrorPlane(mirrorMeshDict_);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -70,7 +70,7 @@ public:
// Constructors // Constructors
//- Construct from IOobject //- Construct from IOobject
mirrorFvMesh(const IOobject& io, const word& dictName); mirrorFvMesh(const IOobject& io, const IOobject& dictIO);
//- Disallow default bitwise copy construction //- Disallow default bitwise copy construction
mirrorFvMesh(const mirrorFvMesh&) = delete; mirrorFvMesh(const mirrorFvMesh&) = delete;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -34,6 +34,7 @@ Description
#include "mirrorFvMesh.H" #include "mirrorFvMesh.H"
#include "mapPolyMesh.H" #include "mapPolyMesh.H"
#include "hexRef8Data.H" #include "hexRef8Data.H"
#include "systemDict.H"
using namespace Foam; using namespace Foam;
@ -48,10 +49,6 @@ int main(int argc, char *argv[])
#include "createTime.H" #include "createTime.H"
const bool overwrite = args.optionFound("overwrite"); const bool overwrite = args.optionFound("overwrite");
const word dictName
(
args.optionLookupOrDefault<word>("dict", "mirrorMeshDict")
);
mirrorFvMesh mesh mirrorFvMesh mesh
( (
@ -61,7 +58,7 @@ int main(int argc, char *argv[])
runTime.constant(), runTime.constant(),
runTime runTime
), ),
dictName systemDictIO("mirrorMeshDict", args, runTime)
); );
hexRef8Data refData hexRef8Data refData

View File

@ -45,6 +45,7 @@ Description
#include "labelIOList.H" #include "labelIOList.H"
#include "IOdictionary.H" #include "IOdictionary.H"
#include "syncTools.H" #include "syncTools.H"
#include "systemDict.H"
using namespace Foam; using namespace Foam;
@ -187,55 +188,34 @@ int main(int argc, char *argv[])
labelList refCells; labelList refCells;
// Dictionary to control refinement // Dictionary to control refinement
dictionary refineDict;
const word dictName("refineMeshDict"); const word dictName("refineMeshDict");
IOobject dictIO(systemDictIO(dictName, args, runTime));
dictionary refineDict;
if (readDict) if (readDict)
{ {
fileName dictPath = args["dict"];
if (isDir(dictPath))
{
dictPath = dictPath/dictName;
}
IOobject dictIO
(
dictPath,
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,
runTime.system(),
mesh,
IOobject::MUST_READ
);
if (dictIO.typeHeaderOk<IOdictionary>(true)) if (dictIO.typeHeaderOk<IOdictionary>(true))
{ {
Info<< "Refining according to " << dictName << nl << endl; Info<< "Refining according to " << dictIO.path() << nl << endl;
refineDict = IOdictionary(dictIO); refineDict = IOdictionary(dictIO);
} }
else else
{ {
Info<< "Refinement dictionary " << dictName << " not found" << endl; FatalErrorInFunction
<< "Cannot open specified refinement dictionary "
<< dictIO.path() << exit(FatalError);
}
}
else if (!refineAllCells)
{
if (dictIO.typeHeaderOk<IOdictionary>(true))
{
Info<< "Refining according to " << dictIO.path() << nl << endl;
refineDict = IOdictionary(dictIO);
}
else
{
Info<< "Refinement dictionary " << dictIO.path() << " not found"
<< nl << endl;
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -97,6 +97,7 @@ Usage
#include "tensorFieldIOField.H" #include "tensorFieldIOField.H"
#include "pointFields.H" #include "pointFields.H"
#include "regionProperties.H" #include "regionProperties.H"
#include "systemDict.H"
#include "readFields.H" #include "readFields.H"
#include "dimFieldDecomposer.H" #include "dimFieldDecomposer.H"
@ -216,6 +217,7 @@ int main(int argc, char *argv[])
); );
argList::noParallel(); argList::noParallel();
#include "addDictOption.H"
#include "addRegionOption.H" #include "addRegionOption.H"
#include "addAllRegionsOption.H" #include "addAllRegionsOption.H"
argList::addBoolOption argList::addBoolOption
@ -260,13 +262,6 @@ int main(int argc, char *argv[])
"only decompose geometry if the number of domains has changed" "only decompose geometry if the number of domains has changed"
); );
argList::addOption
(
"dict",
"dictionary file name",
"specify alternative decomposition dictionary"
);
// Include explicit constant options, have zero from time range // Include explicit constant options, have zero from time range
timeSelector::addOptions(true, false); timeSelector::addOptions(true, false);
@ -303,26 +298,6 @@ int main(int argc, char *argv[])
// Set time from database // Set time from database
#include "createTime.H" #include "createTime.H"
// Check if the dictionary is specified on the command-line
fileName dictPath = fileName::null;
if (args.optionFound("dict"))
{
dictPath = args["dict"];
if (!isFile(dictPath))
{
dictPath = dictPath/dictName;
}
if (!isFile(dictPath))
{
FatalErrorInFunction
<< "Specified -dict " << args["dict"] << " but neither "
<< args["dict"] << " nor " << args["dict"]/dictName
<< " could be found" << nl << exit(FatalError);
}
}
// Allow override of time // Allow override of time
instantList times = timeSelector::selectIfPresent(runTime, args); instantList times = timeSelector::selectIfPresent(runTime, args);
@ -409,26 +384,9 @@ int main(int argc, char *argv[])
// Get the dictionary IO // Get the dictionary IO
const IOobject dictIO const IOobject dictIO
( (
dictPath == fileName::null systemDictIO(dictName, args, runTime, regionName)
? IOobject
(
dictName,
runTime.time().system(),
regionDir, // use region if non-standard
runTime,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE,
false
)
: IOobject
(
dictPath,
runTime,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE,
false
)
); );
// Get requested numberOfSubdomains. Note: have no mesh yet so // Get requested numberOfSubdomains. Note: have no mesh yet so
// cannot use decompositionModel::New // cannot use decompositionModel::New
const label nDomains = const label nDomains =

View File

@ -39,6 +39,7 @@ Description
#include "OFstream.H" #include "OFstream.H"
#include "passiveParticleCloud.H" #include "passiveParticleCloud.H"
#include "setWriter.H" #include "setWriter.H"
#include "systemDict.H"
using namespace Foam; using namespace Foam;

View File

@ -1,8 +1,9 @@
const word dictName("particleTrackDict"); const word dictName("particleTrackDict");
#include "setConstantMeshDictionaryIO.H" IOdictionary propsDict
(
IOdictionary propsDict(dictIO); systemDict(dictName, args, runTime, word::null, runTime.constant())
);
word cloudName(propsDict.lookup("cloudName")); word cloudName(propsDict.lookup("cloudName"));

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -39,6 +39,7 @@ Description
#include "timeSelector.H" #include "timeSelector.H"
#include "OFstream.H" #include "OFstream.H"
#include "passiveParticleCloud.H" #include "passiveParticleCloud.H"
#include "systemDict.H"
#include "SortableList.H" #include "SortableList.H"
#include "IOobjectList.H" #include "IOobjectList.H"

View File

@ -1,19 +1,6 @@
word dictName("noiseDict"); const word dictName("noiseDict");
if (args.optionFound("dict"))
{
dictName = args["dict"];
}
IOdictionary dict IOdictionary dict(systemDict(dictName, args, runTime));
(
IOobject
(
dictName,
runTime.system(),
runTime,
IOobject::MUST_READ
)
);
// reference pressure // reference pressure
scalar pRef = dict.lookupOrDefault("pRef", 0.0); scalar pRef = dict.lookupOrDefault("pRef", 0.0);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -83,6 +83,7 @@ See also
#include "Time.H" #include "Time.H"
#include "Table.H" #include "Table.H"
#include "IOdictionary.H" #include "IOdictionary.H"
#include "systemDict.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -41,6 +41,7 @@ Description
#include "labelListIOList.H" #include "labelListIOList.H"
#include "syncTools.H" #include "syncTools.H"
#include "globalIndex.H" #include "globalIndex.H"
#include "systemDict.H"
using namespace Foam; using namespace Foam;
@ -56,10 +57,11 @@ int main(int argc, char *argv[])
const word dictName("viewFactorsDict"); const word dictName("viewFactorsDict");
#include "setConstantMeshDictionaryIO.H"
// Read control dictionary // Read control dictionary
const IOdictionary agglomDict(dictIO); const IOdictionary agglomDict
(
systemDict(dictName, args, runTime, word::null, runTime.constant())
);
bool writeAgglom = readBool(agglomDict.lookup("writeFacesAgglomeration")); bool writeAgglom = readBool(agglomDict.lookup("writeFacesAgglomeration"));

View File

@ -29,20 +29,32 @@ License
// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
Foam::IOdictionary Foam::systemDict Foam::IOobject Foam::systemDictIO
( (
const word& dictName, const word& dictName,
const argList& args, const argList& args,
const objectRegistry& mesh const objectRegistry& ob,
const word& regionName,
const word& systemName
) )
{ {
fileName dictPath = ""; fileName dictPath = fileName::null;
if (args.optionFound("dict")) if (args.optionFound("dict"))
{ {
dictPath = args["dict"]; dictPath = args["dict"];
if (isDir(dictPath))
if
(
isDir
(
dictPath.isAbsolute()
? dictPath
: ob.time().globalPath()/dictPath
)
)
{ {
dictPath = dictPath / dictName; dictPath = dictPath/dictName;
} }
} }
@ -50,34 +62,48 @@ Foam::IOdictionary Foam::systemDict
{ {
Info<< "Reading " << dictPath << nl << endl; Info<< "Reading " << dictPath << nl << endl;
return IOdictionary return
(
IOobject IOobject
( (
dictPath, dictPath,
mesh, ob.time(),
IOobject::MUST_READ_IF_MODIFIED, IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE IOobject::NO_WRITE
) );
);
} }
else else
{ {
Info<< "Reading " << dictName << nl << endl; Info<< "Reading " << dictName << nl << endl;
return IOdictionary return
(
IOobject IOobject
( (
dictName, dictName,
mesh.time().system(), systemName == word::null ? ob.time().system() : systemName,
mesh, regionName == polyMesh::defaultRegion ? word::null : regionName,
ob,
IOobject::MUST_READ_IF_MODIFIED, IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE IOobject::NO_WRITE
) );
);
} }
} }
Foam::IOdictionary Foam::systemDict
(
const word& dictName,
const argList& args,
const objectRegistry& ob,
const word& regionName,
const word& systemName
)
{
return
IOdictionary
(
systemDictIO(dictName, args, ob, regionName, systemName)
);
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -38,6 +38,7 @@ SourceFiles
#include "argList.H" #include "argList.H"
#include "IOdictionary.H" #include "IOdictionary.H"
#include "polyMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -46,11 +47,22 @@ namespace Foam
// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
IOobject systemDictIO
(
const word& dictName,
const argList& args,
const objectRegistry& ob,
const word& regionName = polyMesh::defaultRegion,
const word& systemName = word::null // defaults to ob.time().system()
);
IOdictionary systemDict IOdictionary systemDict
( (
const word& dictName, const word& dictName,
const argList& args, const argList& args,
const objectRegistry& mesh const objectRegistry& ob,
const word& regionName = polyMesh::defaultRegion,
const word& systemName = word::null // defaults to ob.time().system()
); );
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -1,29 +0,0 @@
fileName dictPath = "";
if (args.optionFound("dict"))
{
dictPath = args["dict"];
if (isDir(dictPath))
{
dictPath = dictPath / dictName;
}
}
IOobject dictIO
(
dictName,
runTime.constant(),
mesh,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
);
if (dictPath.size())
{
dictIO = IOobject
(
dictPath,
mesh,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
);
}

View File

@ -11,13 +11,13 @@ runApplication -s porous blockMesh -region porous
# Create rotor blades in air region # Create rotor blades in air region
runApplication -s air.1 \ runApplication -s air.1 \
topoSet -region air -dict system/topoSetDict.1 topoSet -region air -dict system/air/topoSetDict.1
runApplication createBaffles -region air -overwrite runApplication createBaffles -region air -overwrite
# Create rotor zone in air region for MRF # Create rotor zone in air region for MRF
runApplication -s air.2 \ runApplication -s air.2 \
topoSet -region air -dict system/topoSetDict.2 topoSet -region air -dict system/air/topoSetDict.2
rm -rf constant/air/polyMesh/sets rm -rf constant/air/polyMesh/sets

View File

@ -10,9 +10,9 @@ application=$(getApplication)
runApplication blockMesh runApplication blockMesh
runApplication transformPoints "scale=(1.6666 1 1)" runApplication transformPoints "scale=(1.6666 1 1)"
runApplication mirrorMesh -dict mirrorMeshDict.x -overwrite runApplication mirrorMesh -dict system/mirrorMeshDict.x -overwrite
rm log.mirrorMesh rm log.mirrorMesh
runApplication mirrorMesh -dict mirrorMeshDict.y -overwrite runApplication mirrorMesh -dict system/mirrorMeshDict.y -overwrite
runApplication topoSet runApplication topoSet
runApplication createPatch -overwrite runApplication createPatch -overwrite