mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: IOobject::selectIO helper method
- centralizes IOobject handling and treatment of alternative locations. If an alternative file location is specified, it will be used instead. - provide decompositionMethod::canonicalName instead of using "decomposeParDict" in various places.
This commit is contained in:
@ -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<cyclicPolyPatch>(patches[patchi]))
|
||||
if (isA<cyclicPolyPatch>(pp))
|
||||
{
|
||||
hasCyclic = true;
|
||||
break;
|
||||
|
||||
@ -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<fileName>("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())
|
||||
{
|
||||
|
||||
@ -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<fileName>("dict", "");
|
||||
|
||||
IOobject dictIO = IOobject::selectIO
|
||||
(
|
||||
dictPath,
|
||||
mesh,
|
||||
IOobject::MUST_READ
|
||||
IOobject
|
||||
(
|
||||
dictName,
|
||||
runTime.system(),
|
||||
mesh,
|
||||
IOobject::MUST_READ
|
||||
),
|
||||
dictPath
|
||||
);
|
||||
|
||||
if (!dictIO.typeHeaderOk<IOdictionary>(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<IOdictionary>(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<IOdictionary>(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
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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<fileName>(optionName, "")
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
@ -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<IOobject> 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<fileName>("dict", "")
|
||||
);
|
||||
|
||||
|
||||
if (!csDictIoPtr->typeHeaderOk<coordinateSystems>(false))
|
||||
if (!ioCsys.typeHeaderOk<coordinateSystems>(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"))
|
||||
{
|
||||
|
||||
@ -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<IOobject> 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<fileName>("dict", "")
|
||||
);
|
||||
|
||||
|
||||
if (!ioPtr->typeHeaderOk<coordinateSystems>(false))
|
||||
if (!ioCsys.typeHeaderOk<coordinateSystems>(false))
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< ioPtr->objectPath() << nl
|
||||
<< ioCsys.objectPath() << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
coordinateSystems csLst(ioPtr());
|
||||
coordinateSystems csLst(ioCsys);
|
||||
|
||||
if (args.found("from"))
|
||||
{
|
||||
|
||||
@ -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<IOobject> 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<fileName>("dict", "")
|
||||
);
|
||||
|
||||
|
||||
if (!ioPtr->typeHeaderOk<coordinateSystems>(false))
|
||||
if (!ioCsys.typeHeaderOk<coordinateSystems>(false))
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< ioPtr->objectPath() << nl
|
||||
<< ioCsys.objectPath() << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
coordinateSystems csLst(ioPtr());
|
||||
coordinateSystems csLst(ioCsys);
|
||||
|
||||
if (args.found("from"))
|
||||
{
|
||||
|
||||
@ -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<fileName>("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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user