mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
etc/controlDict: add support for merging etc/controlDict with user-specialised versions
This commit is contained in:
@ -2,7 +2,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) 2004-2010 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -61,7 +61,12 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (args.optionFound("old") || args.optionFound("new"))
|
if (args.optionFound("old") || args.optionFound("new"))
|
||||||
{
|
{
|
||||||
dictionary controlDict(IFstream(findEtcFile("controlDict", true))());
|
fileNameList controlDictFiles = findEtcFile("controlDict", true);
|
||||||
|
dictionary controlDict;
|
||||||
|
forAllReverse(controlDictFiles, cdfi)
|
||||||
|
{
|
||||||
|
controlDict.merge(dictionary(IFstream(controlDictFiles[cdfi])()));
|
||||||
|
}
|
||||||
|
|
||||||
wordHashSet oldDebug
|
wordHashSet oldDebug
|
||||||
(
|
(
|
||||||
|
|||||||
@ -264,10 +264,11 @@ bool Foam::chDir(const fileName& dir)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory)
|
Foam::fileNameList Foam::findEtcFiles(const fileName& name, bool mandatory)
|
||||||
{
|
{
|
||||||
//
|
fileNameList results;
|
||||||
// search for user files in
|
|
||||||
|
// Search for user files in
|
||||||
// * ~/.OpenFOAM/VERSION
|
// * ~/.OpenFOAM/VERSION
|
||||||
// * ~/.OpenFOAM
|
// * ~/.OpenFOAM
|
||||||
//
|
//
|
||||||
@ -277,19 +278,17 @@ Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory)
|
|||||||
fileName fullName = searchDir/FOAMversion/name;
|
fileName fullName = searchDir/FOAMversion/name;
|
||||||
if (isFile(fullName))
|
if (isFile(fullName))
|
||||||
{
|
{
|
||||||
return fullName;
|
results.append(fullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
fullName = searchDir/name;
|
fullName = searchDir/name;
|
||||||
if (isFile(fullName))
|
if (isFile(fullName))
|
||||||
{
|
{
|
||||||
return fullName;
|
results.append(fullName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Search for group (site) files in
|
||||||
//
|
|
||||||
// search for group (site) files in
|
|
||||||
// * $WM_PROJECT_SITE/VERSION
|
// * $WM_PROJECT_SITE/VERSION
|
||||||
// * $WM_PROJECT_SITE
|
// * $WM_PROJECT_SITE
|
||||||
//
|
//
|
||||||
@ -301,19 +300,18 @@ Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory)
|
|||||||
fileName fullName = searchDir/FOAMversion/name;
|
fileName fullName = searchDir/FOAMversion/name;
|
||||||
if (isFile(fullName))
|
if (isFile(fullName))
|
||||||
{
|
{
|
||||||
return fullName;
|
results.append(fullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
fullName = searchDir/name;
|
fullName = searchDir/name;
|
||||||
if (isFile(fullName))
|
if (isFile(fullName))
|
||||||
{
|
{
|
||||||
return fullName;
|
results.append(fullName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//
|
|
||||||
// OR search for group (site) files in
|
// OR search for group (site) files in
|
||||||
// * $WM_PROJECT_INST_DIR/site/VERSION
|
// * $WM_PROJECT_INST_DIR/site/VERSION
|
||||||
// * $WM_PROJECT_INST_DIR/site
|
// * $WM_PROJECT_INST_DIR/site
|
||||||
@ -324,20 +322,18 @@ Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory)
|
|||||||
fileName fullName = searchDir/"site"/FOAMversion/name;
|
fileName fullName = searchDir/"site"/FOAMversion/name;
|
||||||
if (isFile(fullName))
|
if (isFile(fullName))
|
||||||
{
|
{
|
||||||
return fullName;
|
results.append(fullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
fullName = searchDir/"site"/name;
|
fullName = searchDir/"site"/name;
|
||||||
if (isFile(fullName))
|
if (isFile(fullName))
|
||||||
{
|
{
|
||||||
return fullName;
|
results.append(fullName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Search for other (shipped) files in
|
||||||
//
|
|
||||||
// search for other (shipped) files in
|
|
||||||
// * $WM_PROJECT_DIR/etc
|
// * $WM_PROJECT_DIR/etc
|
||||||
//
|
//
|
||||||
searchDir = getEnv("WM_PROJECT_DIR");
|
searchDir = getEnv("WM_PROJECT_DIR");
|
||||||
@ -346,24 +342,41 @@ Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory)
|
|||||||
fileName fullName = searchDir/"etc"/name;
|
fileName fullName = searchDir/"etc"/name;
|
||||||
if (isFile(fullName))
|
if (isFile(fullName))
|
||||||
{
|
{
|
||||||
return fullName;
|
results.append(fullName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not found
|
// Not found
|
||||||
// abort if the file is mandatory, otherwise return null
|
if (results.empty())
|
||||||
if (mandatory)
|
|
||||||
{
|
{
|
||||||
std::cerr
|
// Abort if the file is mandatory, otherwise return null
|
||||||
<< "--> FOAM FATAL ERROR in Foam::findEtcFile() :"
|
if (mandatory)
|
||||||
" could not find mandatory file\n '"
|
{
|
||||||
<< name.c_str() << "'\n\n" << std::endl;
|
std::cerr
|
||||||
::exit(1);
|
<< "--> FOAM FATAL ERROR in Foam::findEtcFiles() :"
|
||||||
|
" could not find mandatory file\n '"
|
||||||
|
<< name.c_str() << "'\n\n" << std::endl;
|
||||||
|
::exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return null-constructed fileName rather than fileName::null
|
// Return list of matching paths or empty list if none found
|
||||||
// to avoid cyclic dependencies in the construction of globals
|
return results;
|
||||||
return fileName();
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory)
|
||||||
|
{
|
||||||
|
fileNameList results(findEtcFiles(name, mandatory));
|
||||||
|
|
||||||
|
if (results.size())
|
||||||
|
{
|
||||||
|
return results[0];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return fileName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -75,10 +75,15 @@ Foam::dictionary& Foam::debug::controlDict()
|
|||||||
{
|
{
|
||||||
if (!controlDictPtr_)
|
if (!controlDictPtr_)
|
||||||
{
|
{
|
||||||
controlDictPtr_ = new dictionary
|
fileNameList controlDictFiles = findEtcFiles("controlDict", true);
|
||||||
(
|
controlDictPtr_ = new dictionary();
|
||||||
IFstream(findEtcFile("controlDict", true))()
|
forAllReverse(controlDictFiles, cdfi)
|
||||||
);
|
{
|
||||||
|
controlDictPtr_->merge
|
||||||
|
(
|
||||||
|
dictionary(IFstream(controlDictFiles[cdfi])())
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return *controlDictPtr_;
|
return *controlDictPtr_;
|
||||||
|
|||||||
@ -93,7 +93,7 @@ fileName cwd();
|
|||||||
// else return false
|
// else return false
|
||||||
bool chDir(const fileName& dir);
|
bool chDir(const fileName& dir);
|
||||||
|
|
||||||
//- Search for a file from user/group/shipped directories.
|
//- Search for files from user/group/shipped directories.
|
||||||
// The search scheme allows for version-specific and
|
// The search scheme allows for version-specific and
|
||||||
// version-independent files using the following hierarchy:
|
// version-independent files using the following hierarchy:
|
||||||
// - \b user settings:
|
// - \b user settings:
|
||||||
@ -108,7 +108,14 @@ bool chDir(const fileName& dir);
|
|||||||
// - \b other (shipped) settings:
|
// - \b other (shipped) settings:
|
||||||
// - $WM_PROJECT_DIR/etc/
|
// - $WM_PROJECT_DIR/etc/
|
||||||
//
|
//
|
||||||
// \return The full path name or fileName() if the name cannot be found
|
// \return The list of full paths of all the matching files or
|
||||||
|
// an empty list if the name cannot be found.
|
||||||
|
// Optionally abort if the file cannot be found
|
||||||
|
fileNameList findEtcFiles(const fileName&, bool mandatory=false);
|
||||||
|
|
||||||
|
//- Search for a file using findEtcFiles.
|
||||||
|
// \return The full path name of the first file found which in the
|
||||||
|
// search hierarchy or an empty fileName if the name cannot be found.
|
||||||
// Optionally abort if the file cannot be found
|
// Optionally abort if the file cannot be found
|
||||||
fileName findEtcFile(const fileName&, bool mandatory=false);
|
fileName findEtcFile(const fileName&, bool mandatory=false);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user