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
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -61,7 +61,12 @@ int main(int argc, char *argv[])
|
||||
|
||||
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
|
||||
(
|
||||
|
||||
@ -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)
|
||||
{
|
||||
//
|
||||
// search for user files in
|
||||
fileNameList results;
|
||||
|
||||
// Search for user files in
|
||||
// * ~/.OpenFOAM/VERSION
|
||||
// * ~/.OpenFOAM
|
||||
//
|
||||
@ -277,19 +278,17 @@ Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory)
|
||||
fileName fullName = searchDir/FOAMversion/name;
|
||||
if (isFile(fullName))
|
||||
{
|
||||
return fullName;
|
||||
results.append(fullName);
|
||||
}
|
||||
|
||||
fullName = searchDir/name;
|
||||
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
|
||||
//
|
||||
@ -301,19 +300,18 @@ Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory)
|
||||
fileName fullName = searchDir/FOAMversion/name;
|
||||
if (isFile(fullName))
|
||||
{
|
||||
return fullName;
|
||||
results.append(fullName);
|
||||
}
|
||||
|
||||
fullName = searchDir/name;
|
||||
if (isFile(fullName))
|
||||
{
|
||||
return fullName;
|
||||
results.append(fullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// OR search for group (site) files in
|
||||
// * $WM_PROJECT_INST_DIR/site/VERSION
|
||||
// * $WM_PROJECT_INST_DIR/site
|
||||
@ -324,20 +322,18 @@ Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory)
|
||||
fileName fullName = searchDir/"site"/FOAMversion/name;
|
||||
if (isFile(fullName))
|
||||
{
|
||||
return fullName;
|
||||
results.append(fullName);
|
||||
}
|
||||
|
||||
fullName = searchDir/"site"/name;
|
||||
if (isFile(fullName))
|
||||
{
|
||||
return fullName;
|
||||
results.append(fullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// search for other (shipped) files in
|
||||
// Search for other (shipped) files in
|
||||
// * $WM_PROJECT_DIR/etc
|
||||
//
|
||||
searchDir = getEnv("WM_PROJECT_DIR");
|
||||
@ -346,25 +342,42 @@ Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory)
|
||||
fileName fullName = searchDir/"etc"/name;
|
||||
if (isFile(fullName))
|
||||
{
|
||||
return fullName;
|
||||
results.append(fullName);
|
||||
}
|
||||
}
|
||||
|
||||
// Not found
|
||||
// abort if the file is mandatory, otherwise return null
|
||||
if (results.empty())
|
||||
{
|
||||
// Abort if the file is mandatory, otherwise return null
|
||||
if (mandatory)
|
||||
{
|
||||
std::cerr
|
||||
<< "--> FOAM FATAL ERROR in Foam::findEtcFile() :"
|
||||
<< "--> 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
|
||||
// to avoid cyclic dependencies in the construction of globals
|
||||
// Return list of matching paths or empty list if none found
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory)
|
||||
{
|
||||
fileNameList results(findEtcFiles(name, mandatory));
|
||||
|
||||
if (results.size())
|
||||
{
|
||||
return results[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
return fileName();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Foam::mkDir(const fileName& pathName, mode_t mode)
|
||||
|
||||
@ -75,11 +75,16 @@ Foam::dictionary& Foam::debug::controlDict()
|
||||
{
|
||||
if (!controlDictPtr_)
|
||||
{
|
||||
controlDictPtr_ = new dictionary
|
||||
fileNameList controlDictFiles = findEtcFiles("controlDict", true);
|
||||
controlDictPtr_ = new dictionary();
|
||||
forAllReverse(controlDictFiles, cdfi)
|
||||
{
|
||||
controlDictPtr_->merge
|
||||
(
|
||||
IFstream(findEtcFile("controlDict", true))()
|
||||
dictionary(IFstream(controlDictFiles[cdfi])())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return *controlDictPtr_;
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ fileName cwd();
|
||||
// else return false
|
||||
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
|
||||
// version-independent files using the following hierarchy:
|
||||
// - \b user settings:
|
||||
@ -108,7 +108,14 @@ bool chDir(const fileName& dir);
|
||||
// - \b other (shipped) settings:
|
||||
// - $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
|
||||
fileName findEtcFile(const fileName&, bool mandatory=false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user