From 49285512c7a60f89c208d8f896c56a035bb739bd Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 6 Jul 2011 12:40:06 +0100 Subject: [PATCH 1/4] etc/controlDict: add support for merging etc/controlDict with user-specialised versions --- .../foamDebugSwitches/foamDebugSwitches.C | 9 ++- src/OSspecific/POSIX/POSIX.C | 67 +++++++++++-------- src/OpenFOAM/global/debug/debug.C | 13 ++-- src/OpenFOAM/include/OSspecific.H | 11 ++- 4 files changed, 65 insertions(+), 35 deletions(-) diff --git a/applications/utilities/miscellaneous/foamDebugSwitches/foamDebugSwitches.C b/applications/utilities/miscellaneous/foamDebugSwitches/foamDebugSwitches.C index 8f0e53f4e2..7f84d96bc2 100644 --- a/applications/utilities/miscellaneous/foamDebugSwitches/foamDebugSwitches.C +++ b/applications/utilities/miscellaneous/foamDebugSwitches/foamDebugSwitches.C @@ -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 ( diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C index c79d8f0290..920d720cf5 100644 --- a/src/OSspecific/POSIX/POSIX.C +++ b/src/OSspecific/POSIX/POSIX.C @@ -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,24 +342,41 @@ 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 (mandatory) + if (results.empty()) { - std::cerr - << "--> FOAM FATAL ERROR in Foam::findEtcFile() :" - " could not find mandatory file\n '" - << name.c_str() << "'\n\n" << std::endl; - ::exit(1); + // Abort if the file is mandatory, otherwise return null + if (mandatory) + { + std::cerr + << "--> 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 fileName(); + // 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(); + } } diff --git a/src/OpenFOAM/global/debug/debug.C b/src/OpenFOAM/global/debug/debug.C index b0c696987a..2cd9c861fe 100644 --- a/src/OpenFOAM/global/debug/debug.C +++ b/src/OpenFOAM/global/debug/debug.C @@ -75,10 +75,15 @@ Foam::dictionary& Foam::debug::controlDict() { if (!controlDictPtr_) { - controlDictPtr_ = new dictionary - ( - IFstream(findEtcFile("controlDict", true))() - ); + fileNameList controlDictFiles = findEtcFiles("controlDict", true); + controlDictPtr_ = new dictionary(); + forAllReverse(controlDictFiles, cdfi) + { + controlDictPtr_->merge + ( + dictionary(IFstream(controlDictFiles[cdfi])()) + ); + } } return *controlDictPtr_; diff --git a/src/OpenFOAM/include/OSspecific.H b/src/OpenFOAM/include/OSspecific.H index b774997339..119c669b5f 100644 --- a/src/OpenFOAM/include/OSspecific.H +++ b/src/OpenFOAM/include/OSspecific.H @@ -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); From 2169a5de4039ab5388ce255b62c02d9cd13c7d56 Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 6 Jul 2011 12:40:15 +0100 Subject: [PATCH 2/4] etc/controlDict: Removed redundant entry --- etc/controlDict | 1 - 1 file changed, 1 deletion(-) diff --git a/etc/controlDict b/etc/controlDict index 9edaf1025e..352541fa75 100644 --- a/etc/controlDict +++ b/etc/controlDict @@ -24,7 +24,6 @@ Documentation "$WM_PROJECT_USER_DIR/html" "~OpenFOAM/html" "$WM_PROJECT_DIR/doc/Doxygen/html" - "$WM_PROJECT_DIR/doc/doxygen/html" ); doxySourceFileExts ( From 64ec1bab0716cb1d64c13504e26fc654e012d8e3 Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 6 Jul 2011 12:40:26 +0100 Subject: [PATCH 3/4] simpleFoam/motorBike tutorial: Changed loaded libraries to avoid error on completion --- .../simpleFoam/motorBike/system/controlDict | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tutorials/incompressible/simpleFoam/motorBike/system/controlDict b/tutorials/incompressible/simpleFoam/motorBike/system/controlDict index 3e5b2dfbd0..55c8016a8e 100644 --- a/tutorials/incompressible/simpleFoam/motorBike/system/controlDict +++ b/tutorials/incompressible/simpleFoam/motorBike/system/controlDict @@ -1,7 +1,7 @@ /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: dev | +| \\ / O peration | Version: 2.0.0 | | \\ / A nd | Web: www.OpenFOAM.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ @@ -16,19 +16,19 @@ FoamFile application simpleFoam; -startFrom latestTime; +startFrom latestTime; startTime 0; -stopAt nextWrite; +stopAt nextWrite; endTime 500; deltaT 1; -writeControl timeStep; +writeControl timeStep; -writeInterval 1; +writeInterval 1; purgeWrite 0; @@ -48,7 +48,7 @@ libs ( "libOpenFOAM.so" "libcompressibleTurbulenceModels.so" - "libincompressibleRASModels.so" + "libcompressibleRASModels.so" ); functions From 576805a3f2c930ee0b4121dbb426b42d5d7b70ce Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 6 Jul 2011 12:42:43 +0100 Subject: [PATCH 4/4] Corrected header --- .../incompressible/simpleFoam/motorBike/system/controlDict | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/incompressible/simpleFoam/motorBike/system/controlDict b/tutorials/incompressible/simpleFoam/motorBike/system/controlDict index 55c8016a8e..fc5893222c 100644 --- a/tutorials/incompressible/simpleFoam/motorBike/system/controlDict +++ b/tutorials/incompressible/simpleFoam/motorBike/system/controlDict @@ -1,7 +1,7 @@ /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: 2.0.0 | +| \\ / O peration | Version: dev | | \\ / A nd | Web: www.OpenFOAM.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/