utilities: Rationalised and standardised the handling of the -dict option

This commit is contained in:
Henry Weller
2021-03-05 13:42:46 +00:00
parent d4d21c9c04
commit cf552e6343
16 changed files with 197 additions and 142 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -53,6 +53,7 @@ Usage
#include "fvMesh.H"
#include "polyMeshFilter.H"
#include "faceSet.H"
#include "systemDict.H"
using namespace Foam;
@ -92,12 +93,7 @@ int main(int argc, char *argv[])
const word oldInstance = mesh.pointsInstance();
const word dictName("collapseDict");
#include "setSystemMeshDictionaryIO.H"
Info<< "Reading " << dictName << nl << endl;
IOdictionary collapseDict(dictIO);
const dictionary collapseDict(systemDict("collapseDict", args, mesh));
const bool overwrite = args.optionFound("overwrite");

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -59,7 +59,7 @@ Description
#include "meshTools.H"
#include "Pair.H"
#include "globalIndex.H"
#include "IOdictionary.H"
#include "systemDict.H"
using namespace Foam;
@ -327,8 +327,6 @@ label findCell(const primitiveMesh& mesh, const point& nearPoint)
}
int main(int argc, char *argv[])
{
#include "addOverwriteOption.H"
@ -341,19 +339,7 @@ int main(int argc, char *argv[])
const bool overwrite = args.optionFound("overwrite");
Info<< "Reading modifyMeshDict\n" << endl;
IOdictionary dict
(
IOobject
(
"modifyMeshDict",
runTime.system(),
mesh,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
)
);
const dictionary dict(systemDict("modifyMeshDict", args, mesh));
// Read all from the dictionary.
List<Pair<point>> pointsToMove(dict.lookup("pointsToMove"));

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -45,6 +45,7 @@ Description
#include "MeshedSurfaces.H"
#include "globalIndex.H"
#include "cellSet.H"
#include "systemDict.H"
#include "extrudedMesh.H"
#include "extrudeModel.H"
@ -266,7 +267,7 @@ int main(int argc, char *argv[])
#include "addDictOption.H"
#include "setRootCase.H"
#include "createTimeExtruded.H"
#include "createTime.H"
// Get optional regionName
word regionName;
@ -275,30 +276,16 @@ int main(int argc, char *argv[])
{
regionDir = regionName;
Info<< "Create mesh " << regionName << " for time = "
<< runTimeExtruded.timeName() << nl << endl;
<< runTime.timeName() << nl << endl;
}
else
{
regionName = fvMesh::defaultRegion;
Info<< "Create mesh for time = "
<< runTimeExtruded.timeName() << nl << endl;
<< runTime.timeName() << nl << endl;
}
const word dictName
(
args.optionLookupOrDefault<word>("dict", "extrudeMeshDict")
);
IOdictionary dict
(
IOobject
(
dictName,
runTimeExtruded.system(),
runTimeExtruded,
IOobject::MUST_READ_IF_MODIFIED
)
);
const dictionary dict(systemDict("extrudeMeshDict", args, runTime));
// Point generator
autoPtr<extrudeModel> model(extrudeModel::New(dict));
@ -376,13 +363,6 @@ int main(int argc, char *argv[])
<< " on mesh " << sourceCasePath << nl
<< endl;
Time runTime
(
Time::controlDictName,
sourceRootDir,
sourceCaseDir
);
#include "createMesh.H"
const polyBoundaryMesh& patches = mesh.boundaryMesh();
@ -711,8 +691,8 @@ int main(int argc, char *argv[])
IOobject
(
regionName,
runTimeExtruded.constant(),
runTimeExtruded,
runTime.constant(),
runTime,
IOobject::NO_READ,
IOobject::AUTO_WRITE,
false
@ -795,8 +775,8 @@ int main(int argc, char *argv[])
IOobject
(
extrudedMesh::defaultRegion,
runTimeExtruded.constant(),
runTimeExtruded
runTime.constant(),
runTime
),
fMesh,
model()
@ -1040,7 +1020,7 @@ int main(int argc, char *argv[])
}
}
mesh.setInstance(runTimeExtruded.constant());
mesh.setInstance(runTime.constant());
Info<< "Writing mesh to " << mesh.localObjectPath() << nl << endl;
if (!mesh.write())

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -126,6 +126,7 @@ Notes:
#include "fvMeshTools.H"
#include "OBJstream.H"
#include "PatchTools.H"
#include "systemDict.H"
using namespace Foam;
@ -1406,11 +1407,7 @@ int main(int argc, char *argv[])
bool overwrite = args.optionFound("overwrite");
const word dictName("extrudeToRegionMeshDict");
#include "setSystemMeshDictionaryIO.H"
IOdictionary dict(dictIO);
const dictionary dict(systemDict("extrudeToRegionMeshDict", args, mesh));
// Point generator

View File

@ -58,6 +58,7 @@ Description
#include "globalIndex.H"
#include "IOmanip.H"
#include "fvMeshTools.H"
#include "systemDict.H"
using namespace Foam;
@ -731,9 +732,7 @@ int main(int argc, char *argv[])
// Read meshing dictionary
const word dictName("snappyHexMeshDict");
#include "setSystemMeshDictionaryIO.H"
const IOdictionary meshDict(dictIO);
const dictionary meshDict(systemDict("snappyHexMeshDict", args, mesh));
// all surface geometry

View File

@ -51,6 +51,7 @@ Description
#include "faceSelection.H"
#include "searchableSurface.H"
#include "fvMeshTools.H"
#include "systemDict.H"
using namespace Foam;
@ -450,17 +451,13 @@ int main(int argc, char *argv[])
const word oldInstance = mesh.pointsInstance();
const word dictName("createBafflesDict");
#include "setSystemMeshDictionaryIO.H"
Switch internalFacesOnly(false);
Switch fields(false);
PtrList<faceSelection> selectors;
{
Info<< "Reading baffle criteria from " << dictName << nl << endl;
IOdictionary dict(dictIO);
const dictionary dict(systemDict("createBafflesDict", args, mesh));
dict.lookup("internalFacesOnly") >> internalFacesOnly;
fields = dict.lookupOrDefault("fields", false);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -49,7 +49,7 @@ Description
#include "polyTopoChange.H"
#include "polyModifyFace.H"
#include "wordReList.H"
#include "IOdictionary.H"
#include "systemDict.H"
using namespace Foam;
@ -488,12 +488,7 @@ int main(int argc, char *argv[])
const word oldInstance = mesh.pointsInstance();
const word dictName("createPatchDict");
#include "setSystemMeshDictionaryIO.H"
Info<< "Reading " << dictName << nl << endl;
IOdictionary dict(dictIO);
const dictionary dict(systemDict("createPatchDict", args, mesh));
// Whether to synchronise points
const Switch pointSync(dict.lookup("pointSync"));

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -49,6 +49,7 @@ Description
#include "cellSet.H"
#include "faceSet.H"
#include "pointSet.H"
#include "systemDict.H"
#ifdef FOAM_USE_ZOLTAN
#include "zoltanRenumber.H"
@ -691,18 +692,16 @@ int main(int argc, char *argv[])
bool renumberSets = true;
// Construct renumberMethod
autoPtr<IOdictionary> renumberDictPtr;
autoPtr<dictionary> renumberDictPtr;
autoPtr<renumberMethod> renumberPtr;
if (readDict)
{
const word dictName("renumberMeshDict");
#include "setSystemMeshDictionaryIO.H"
Info<< "Renumber according to " << dictName << nl << endl;
renumberDictPtr.reset(new IOdictionary(dictIO));
const IOdictionary& renumberDict = renumberDictPtr();
renumberDictPtr.reset
(
new dictionary(systemDict("renumberMeshDict", args, mesh))
);
const dictionary& renumberDict = renumberDictPtr();
renumberPtr = renumberMethod::New(renumberDict);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -39,7 +39,7 @@ Description
#include "cellZoneSet.H"
#include "faceZoneSet.H"
#include "pointZoneSet.H"
#include "IOdictionary.H"
#include "systemDict.H"
using namespace Foam;
@ -211,12 +211,7 @@ int main(int argc, char *argv[])
const bool noSync = args.optionFound("noSync");
const word dictName("topoSetDict");
#include "setSystemMeshDictionaryIO.H"
Info<< "Reading " << dictName << "\n" << endl;
IOdictionary topoSetDict(dictIO);
const dictionary topoSetDict(systemDict("topoSetDict", args, mesh));
// Read set construct info from dictionary
PtrList<dictionary> actions(topoSetDict.lookup("actions"));

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -80,6 +80,7 @@ Note
#include "volFields.H"
#include "stringListOps.H"
#include "timeSelector.H"
#include "systemDict.H"
using namespace Foam;
@ -508,10 +509,7 @@ int main(int argc, char *argv[])
// Get the replacement rules from a dictionary
const word dictName("changeDictionaryDict");
#include "setSystemMeshDictionaryIO.H"
IOdictionary dict(dictIO);
const dictionary dict(systemDict("changeDictionaryDict", args, mesh));
const dictionary* replaceDictsPtr = &dict;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -33,9 +33,12 @@ Description
#include "cellSet.H"
#include "faceSet.H"
#include "volFields.H"
#include "systemDict.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
bool setCellFieldType
(
@ -373,7 +376,6 @@ public:
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
@ -384,12 +386,7 @@ int main(int argc, char *argv[])
#include "createTime.H"
#include "createNamedMesh.H"
const word dictName("setFieldsDict");
#include "setSystemMeshDictionaryIO.H"
Info<< "Reading " << dictName << "\n" << endl;
IOdictionary setFieldsDict(dictIO);
const dictionary setFieldsDict(systemDict("setFieldsDict", args, mesh));
if (setFieldsDict.found("defaultFieldValues"))
{
@ -402,7 +399,6 @@ int main(int argc, char *argv[])
Info<< endl;
}
Info<< "Setting field region values" << endl;
PtrList<entry> regions(setFieldsDict.lookup("regions"));

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -39,6 +39,7 @@ Description
#include "wallPolyPatch.H"
#include "waveAlphaFvPatchScalarField.H"
#include "waveVelocityFvPatchVectorField.H"
#include "systemDict.H"
using namespace Foam;
@ -78,10 +79,7 @@ int main(int argc, char *argv[])
#include "createNamedMesh.H"
const word dictName("setWavesDict");
#include "setSystemMeshDictionaryIO.H"
Info<< "Reading " << dictName << "\n" << endl;
IOdictionary setWavesDict(dictIO);
const dictionary setWavesDict(systemDict("setWavesDict", args, mesh));
#include "readGravitationalAcceleration.H"

View File

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

View File

@ -0,0 +1,83 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "systemDict.H"
#include "IOdictionary.H"
#include "Time.H"
// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
Foam::dictionary Foam::systemDict
(
const word& dictName,
const argList& args,
const objectRegistry& mesh
)
{
fileName dictPath = "";
if (args.optionFound("dict"))
{
dictPath = args["dict"];
if (isDir(dictPath))
{
dictPath = dictPath / dictName;
}
}
if (dictPath.size())
{
Info<< "Reading " << dictPath << nl << endl;
return IOdictionary
(
IOobject
(
dictPath,
mesh,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
)
);
}
else
{
Info<< "Reading " << dictName << nl << endl;
return IOdictionary
(
IOobject
(
dictName,
mesh.time().system(),
mesh,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
)
);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::systemDict
Description
Read and return the specified dictionary from system or from path provided
with the -dict option.
SourceFiles
systemDict.C
\*---------------------------------------------------------------------------*/
#ifndef systemDict_H
#define systemDict_H
#include "argList.H"
#include "objectRegistry.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
dictionary systemDict
(
const word& dictName,
const argList& args,
const objectRegistry& mesh
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

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.system(),
mesh,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
);
if (dictPath.size())
{
dictIO = IOobject
(
dictPath,
mesh,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
);
}