diff --git a/applications/utilities/miscellaneous/foamDictionary/Make/options b/applications/utilities/miscellaneous/foamDictionary/Make/options index 41306609f2..42721097f8 100644 --- a/applications/utilities/miscellaneous/foamDictionary/Make/options +++ b/applications/utilities/miscellaneous/foamDictionary/Make/options @@ -1 +1,2 @@ EXE_INC = +EXE_LIBS = -lfiniteVolume diff --git a/applications/utilities/postProcessing/foamPostProcess/foamPostProcess.C b/applications/utilities/postProcessing/foamPostProcess/foamPostProcess.C index da5c449162..e67e5e7190 100644 --- a/applications/utilities/postProcessing/foamPostProcess/foamPostProcess.C +++ b/applications/utilities/postProcessing/foamPostProcess/foamPostProcess.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -217,7 +217,10 @@ int main(int argc, char *argv[]) { Info<< nl << "Available configured functionObjects:" - << functionObjectList::list() + << listAllConfigFiles + ( + functionEntries::includeFuncEntry::functionObjectDictPath + ) << endl; return 0; } diff --git a/etc/caseDicts/fvConstraints/limitLowPressure b/etc/caseDicts/fvConstraints/limitLowPressure new file mode 100644 index 0000000000..99b16beaee --- /dev/null +++ b/etc/caseDicts/fvConstraints/limitLowPressure @@ -0,0 +1,22 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: dev + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + object limitPressure; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +type limitPressure; + +selectionMode all; + +min <1e4>; + +//************************************************************************** // diff --git a/etc/caseDicts/general/fvConstraints/limitPressure b/etc/caseDicts/fvConstraints/limitPressure similarity index 74% rename from etc/caseDicts/general/fvConstraints/limitPressure rename to etc/caseDicts/fvConstraints/limitPressure index d77ed76644..7882b717a4 100644 --- a/etc/caseDicts/general/fvConstraints/limitPressure +++ b/etc/caseDicts/fvConstraints/limitPressure @@ -13,17 +13,16 @@ FoamFile } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -limitp -{ - type limitPressure; +type limitPressure; - // limits can be specified absolute - // min 200; - // max 500; +selectionMode all; - // ... or as multipliers on initial min/max values - minFactor 0.1; - maxFactor 1.5; -} +// limits can be specified absolute +// min <200>; +// max <500>; + +// ... or as multipliers on initial min/max values +minFactor <0.1>; +maxFactor <1.5>; //************************************************************************** // diff --git a/etc/caseDicts/general/fvConstraints/limitTemperature b/etc/caseDicts/fvConstraints/limitTemperature similarity index 85% rename from etc/caseDicts/general/fvConstraints/limitTemperature rename to etc/caseDicts/fvConstraints/limitTemperature index 8769faf403..3c90a5da05 100644 --- a/etc/caseDicts/general/fvConstraints/limitTemperature +++ b/etc/caseDicts/fvConstraints/limitTemperature @@ -13,12 +13,11 @@ FoamFile } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -limitT -{ - type limitTemperature; - min 200; - max 6000; - selectionMode all; -} +type limitTemperature; + +selectionMode all; + +min <200>; +max <6000>; //************************************************************************** // diff --git a/etc/caseDicts/general/fvModels/clouds b/etc/caseDicts/fvModels/clouds similarity index 83% rename from etc/caseDicts/general/fvModels/clouds rename to etc/caseDicts/fvModels/clouds index 6a80a1a2f2..4563ca9742 100644 --- a/etc/caseDicts/general/fvModels/clouds +++ b/etc/caseDicts/fvModels/clouds @@ -13,14 +13,12 @@ FoamFile } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -clouds -{ - type clouds; - libs - ( - "liblagrangianParcel.so" - "liblagrangianParcelTurbulence.so" - ); -} +type clouds; + +libs +( + "liblagrangianParcel.so" + "liblagrangianParcelTurbulence.so" +); // ************************************************************************* // diff --git a/etc/caseDicts/fvModels/porosity/porousZone b/etc/caseDicts/fvModels/porosity/porousZone new file mode 100644 index 0000000000..f80a64ab4f --- /dev/null +++ b/etc/caseDicts/fvModels/porosity/porousZone @@ -0,0 +1,55 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: dev + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + object porousZone; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +type explicitPorositySource; + +explicitPorositySourceCoeffs +{ + type DarcyForchheimer; + selectionMode cellZone; + cellZone ; // Specify the name of the cellZone + + DarcyForchheimerCoeffs + { + // Negative coeffs are multiplied by largest positive coeff, + // taking the magnitude, e.g. for -1000, coeff = |1e7*-1000| = 1e10 + + d [0 -2 0 0 0 0 0] (1e7 -1000 -1000); + f [0 -1 0 0 0 0 0] (0 0 0); + + coordinateSystem // Cartesian coordinates for the cellZone + { + x (1 0 0); + y (0 1 0); + #includeEtc "caseDicts/general/coordinateSystem/cartesianXY" + } + } + + fixedCoeffCoeffs + { + alpha [0 0 -1 0 0 0 0] (100 -1000 -1000); + beta [0 -1 0 0 0 0 0] (0 0 0); + rhoRef 1.205; + + coordinateSystem // Cylindrical coordinates for the cellZone + { + origin (0 0 0); + axis (0 0 1); + #includeEtc "caseDicts/general/coordinateSystem/cylindrical" + } + } +} + +//************************************************************************** // diff --git a/etc/caseDicts/fvModels/surfaceFilms b/etc/caseDicts/fvModels/surfaceFilms new file mode 100644 index 0000000000..c8e7b87c3d --- /dev/null +++ b/etc/caseDicts/fvModels/surfaceFilms @@ -0,0 +1,20 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: dev + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + object surfaceFilms; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +type surfaceFilms; + +libs ("libsurfaceFilmModels.so"); + +// ************************************************************************* // diff --git a/etc/caseDicts/general/fvModels/porosity/porousZone b/etc/caseDicts/general/fvModels/porosity/porousZone deleted file mode 100644 index 16c52f9931..0000000000 --- a/etc/caseDicts/general/fvModels/porosity/porousZone +++ /dev/null @@ -1,58 +0,0 @@ -/*--------------------------------*- C++ -*----------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Version: dev - \\/ M anipulation | -\*---------------------------------------------------------------------------*/ -FoamFile -{ - format ascii; - class dictionary; - object porousZone; -} -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -porousZone // Change to something more descriptive -{ - type explicitPorositySource; - - explicitPorositySourceCoeffs - { - type DarcyForchheimer; - selectionMode cellZone; - cellZone ; // Specify the name of the cellZone - - DarcyForchheimerCoeffs - { - // Negative coeffs are multiplied by largest positive coeff, - // taking the magnitude, e.g. for -1000, coeff = |1e7*-1000| = 1e10 - - d [0 -2 0 0 0 0 0] (1e7 -1000 -1000); - f [0 -1 0 0 0 0 0] (0 0 0); - - coordinateSystem // Cartesian coordinates for the cellZone - { - x (1 0 0); - y (0 1 0); - #includeEtc "caseDicts/general/coordinateSystem/cartesianXY" - } - } - - fixedCoeffCoeffs - { - alpha [0 0 -1 0 0 0 0] (100 -1000 -1000); - beta [0 -1 0 0 0 0 0] (0 0 0); - rhoRef 1.205; - - coordinateSystem // Cylindrical coordinates for the cellZone - { - origin (0 0 0); - axis (0 0 1); - #includeEtc "caseDicts/general/coordinateSystem/cylindrical" - } - } - } -} - -//************************************************************************** // diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C index 9e88f1932b..4580c0c8f4 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.C +++ b/src/OpenFOAM/db/dictionary/dictionary.C @@ -24,14 +24,10 @@ License \*---------------------------------------------------------------------------*/ #include "dictionary.H" -#include "primitiveEntry.H" #include "dictionaryEntry.H" #include "regExp.H" #include "OSHA1stream.H" -#include "DynamicList.H" #include "inputSyntaxEntry.H" -#include "fileOperation.H" -#include "stringOps.H" /* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */ @@ -1655,13 +1651,13 @@ Foam::dictionary Foam::operator| void Foam::dictArgList ( - const string& funcArgs, + const string& argString, word& funcName, wordReList& args, List>& namedArgs ) { - funcName = funcArgs; + funcName = argString; int argLevel = 0; bool namedArg = false; @@ -1672,8 +1668,8 @@ void Foam::dictArgList for ( - word::const_iterator iter = funcArgs.begin(); - iter != funcArgs.end(); + word::const_iterator iter = argString.begin(); + iter != argString.end(); ++iter ) { @@ -1683,7 +1679,7 @@ void Foam::dictArgList { if (argLevel == 0) { - funcName = funcArgs(start, i - start); + funcName = argString(start, i - start); start = i+1; } ++argLevel; @@ -1699,14 +1695,14 @@ void Foam::dictArgList Tuple2 ( argName, - funcArgs(start, i - start) + argString(start, i - start) ) ); namedArg = false; } else { - args.append(wordRe(funcArgs(start, i - start))); + args.append(wordRe(argString(start, i - start))); } start = i+1; } @@ -1722,7 +1718,7 @@ void Foam::dictArgList } else if (c == '=') { - argName = funcArgs(start, i - start); + argName = argString(start, i - start); string::stripInvalid(argName); start = i+1; namedArg = true; @@ -1738,7 +1734,7 @@ void Foam::dictArgList void Foam::dictArgList ( - const string& funcArgs, + const string& argString, wordReList& args, List>& namedArgs ) @@ -1752,8 +1748,8 @@ void Foam::dictArgList for ( - word::const_iterator iter = funcArgs.begin(); - iter != funcArgs.end(); + word::const_iterator iter = argString.begin(); + iter != argString.end(); ++iter ) { @@ -1763,9 +1759,9 @@ void Foam::dictArgList { ++argLevel; } - else if (c == ',' || std::next(iter) == funcArgs.end()) + else if (c == ',' || std::next(iter) == argString.end()) { - if (std::next(iter) == funcArgs.end()) + if (std::next(iter) == argString.end()) { if (c == ')') { @@ -1784,21 +1780,21 @@ void Foam::dictArgList Tuple2 ( argName, - funcArgs(start, i - start) + argString(start, i - start) ) ); namedArg = false; } else { - args.append(wordRe(funcArgs(start, i - start))); + args.append(wordRe(argString(start, i - start))); } start = i+1; } } else if (c == '=') { - argName = funcArgs(start, i - start); + argName = argString(start, i - start); string::stripInvalid(argName); start = i+1; namedArg = true; diff --git a/src/OpenFOAM/db/dictionary/dictionary.H b/src/OpenFOAM/db/dictionary/dictionary.H index 27656960e1..93c417c475 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.H +++ b/src/OpenFOAM/db/dictionary/dictionary.H @@ -53,7 +53,7 @@ SourceFiles #include "entry.H" #include "IDLList.H" #include "DLList.H" -#include "HashTable.H" +#include "HashSet.H" #include "ITstream.H" #include "wordReList.H" #include "Pair.H" @@ -750,7 +750,7 @@ dictionary operator|(const dictionary& dict1, const dictionary& dict2); //- Parse dictionary substitution argument list void dictArgList ( - const string& funcArgs, + const string& argString, word& funcName, wordReList& args, List>& namedArgs @@ -759,7 +759,7 @@ void dictArgList //- Parse dictionary substitution argument list void dictArgList ( - const string& funcArgs, + const string& argString, wordReList& args, List>& namedArgs ); @@ -767,6 +767,81 @@ void dictArgList //- Extracts dict name and keyword Pair dictAndKeyword(const word& scopedName); +//- Return the list of configuration files in +// user/group/shipped directories. +// The search scheme allows for version-specific and +// version-independent files using the following hierarchy: +// - \b user settings: +// - ~/.OpenFOAM/\/caseDicts/postProcessing +// - ~/.OpenFOAM/caseDicts/postProcessing +// - \b group (site) settings (when $WM_PROJECT_SITE is set): +// - $WM_PROJECT_SITE/\/etc/caseDicts/postProcessing +// - $WM_PROJECT_SITE/etc/caseDicts/postProcessing +// - \b group (site) settings (when $WM_PROJECT_SITE is not set): +// - $WM_PROJECT_INST_DIR/site/\/etc/ +// caseDicts/postProcessing +// - $WM_PROJECT_INST_DIR/site/etc/caseDicts/postProcessing +// - \b other (shipped) settings: +// - $WM_PROJECT_DIR/etc/caseDicts/postProcessing +wordList listAllConfigFiles +( + const fileName& configFilesPath +); + +//- Search for configuration file for given region +// and if not present also search the case directory as well as the +// user/group/shipped directories. +// The search scheme allows for version-specific and +// version-independent files using the following hierarchy: +// - \b user settings: +// - ~/.OpenFOAM/\/caseDicts/postProcessing +// - ~/.OpenFOAM/caseDicts/postProcessing +// - \b group (site) settings (when $WM_PROJECT_SITE is set): +// - $WM_PROJECT_SITE/\/etc/caseDicts/postProcessing +// - $WM_PROJECT_SITE/etc/caseDicts/postProcessing +// - \b group (site) settings (when $WM_PROJECT_SITE is not set): +// - $WM_PROJECT_INST_DIR/site/\/etc/ +// caseDicts/postProcessing +// - $WM_PROJECT_INST_DIR/site/etc/caseDicts/postProcessing +// - \b other (shipped) settings: +// - $WM_PROJECT_DIR/etc/caseDicts/postProcessing +// +// \return The path of the configuration file if found +// otherwise null +fileName findConfigFile +( + const word& funcName, + const fileName& configFilesPath, + const word& region = word::null +); + +//- Read the specified configuration file +// parsing the optional arguments included in the string +// 'argString', inserting 'field' or 'fields' entries as required +// and merging the resulting configuration dictionary into +// 'parentDict'. +// +// Parses the optional arguments: +// 'Q(U)' -> funcName = Q; args = (U) +// -> field U; +// +// Supports named arguments: +// 'patchAverage(patch=inlet, p,U)' +// or +// 'patchAverage(patch=inlet, field=(p U))' +// -> funcName = patchAverage; +// args = (patch=inlet, p,U) +// -> patch inlet; +// fields (p U); +bool readConfigFile +( + const string& argString, + dictionary& parentDict, + const fileName& configFilesPath, + const Pair& contextTypeAndValue, + const word& region = word::null +); + //- Write a dictionary entry void writeEntry(Ostream& os, const dictionary& dict); diff --git a/src/OpenFOAM/db/dictionary/dictionaryIO.C b/src/OpenFOAM/db/dictionary/dictionaryIO.C index ed7482a935..ccf3743639 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryIO.C +++ b/src/OpenFOAM/db/dictionary/dictionaryIO.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -27,6 +27,10 @@ License #include "IOobject.H" #include "inputSyntaxEntry.H" #include "inputModeEntry.H" +#include "stringOps.H" +#include "etcFiles.H" +#include "wordAndDictionary.H" +#include "OSspecific.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -176,13 +180,6 @@ bool Foam::dictionary::substituteKeyword(const word& keyword) } -// * * * * * * * * * * * * * * * IOstream Functions * * * * * * * * * * * * // - -void Foam::writeEntry(Ostream& os, const dictionary& value) -{ - os << value; -} - // * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * // @@ -248,4 +245,414 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const dictionary& dict) } +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +Foam::List> +unsetConfigEntries(const dictionary& configDict) +{ + const wordRe unsetPattern("<.*>"); + unsetPattern.compile(); + + List> unsetArgs; + + forAllConstIter(IDLList, configDict, iter) + { + if (iter().isStream()) + { + ITstream& its = iter().stream(); + OStringStream oss; + bool isUnset = false; + + forAll(its, i) + { + oss << its[i]; + if (its[i].isWord() && unsetPattern.match(its[i].wordToken())) + { + isUnset = true; + } + } + + if (isUnset) + { + unsetArgs.append + ( + Tuple2 + ( + iter().keyword(), + oss.str() + ) + ); + } + } + else + { + List> subUnsetArgs = + unsetConfigEntries(iter().dict()); + + forAll(subUnsetArgs, i) + { + unsetArgs.append + ( + Tuple2 + ( + iter().keyword() + '/' + subUnsetArgs[i].first(), + subUnsetArgs[i].second() + ) + ); + } + } + } + + return unsetArgs; +} + + +void listConfigFiles +( + const fileName& dir, + HashSet& foMap +) +{ + // Search specified directory for configuration files + { + fileNameList foFiles(fileHandler().readDir(dir)); + forAll(foFiles, f) + { + if (foFiles[f].ext().empty()) + { + foMap.insert(foFiles[f]); + } + } + } + + // Recurse into sub-directories + { + fileNameList foDirs(fileHandler().readDir(dir, fileType::directory)); + forAll(foDirs, fd) + { + listConfigFiles(dir/foDirs[fd], foMap); + } + } +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +Foam::fileName Foam::findConfigFile +( + const word& funcName, + const fileName& configFilesPath, + const word& region +) +{ + // First check if there is a configuration file in the + // region system directory + { + const fileName dictFile + ( + stringOps::expand("$FOAM_CASE")/"system"/region/funcName + ); + + if (isFile(dictFile)) + { + return dictFile; + } + } + + // Next, if the region is specified, check if there is a configuration file + // in the global system directory + if (region != word::null) + { + const fileName dictFile + ( + stringOps::expand("$FOAM_CASE")/"system"/funcName + ); + + if (isFile(dictFile)) + { + return dictFile; + } + } + + // Finally, check etc directories + { + const fileNameList etcDirs(findEtcDirs(configFilesPath)); + + forAll(etcDirs, i) + { + const fileName dictFile(search(funcName, etcDirs[i])); + + if (!dictFile.empty()) + { + return dictFile; + } + } + } + + return fileName::null; +} + + +Foam::wordList Foam::listAllConfigFiles +( + const fileName& configFilesPath +) +{ + HashSet foMap; + + fileNameList etcDirs(findEtcDirs(configFilesPath)); + + forAll(etcDirs, ed) + { + listConfigFiles(etcDirs[ed], foMap); + } + + return foMap.sortedToc(); +} + + +bool Foam::readConfigFile +( + const string& argString, + dictionary& parentDict, + const fileName& configFilesPath, + const Pair& contextTypeAndValue, + const word& region +) +{ + word funcType; + wordReList args; + List> namedArgs; + + dictArgList(argString, funcType, args, namedArgs); + + // Search for the configuration file + fileName path = findConfigFile(funcType, configFilesPath, region); + + if (path == fileName::null) + { + if (funcType == word::null) + { + FatalIOErrorInFunction(parentDict) + << "configuration file name not specified" + << nl << nl + << "Available configured objects:" + << listAllConfigFiles(configFilesPath) + << exit(FatalIOError); + } + else + { + FatalIOErrorInFunction(parentDict) + << "Cannot find configuration file " + << funcType << nl << nl + << "Available configured objects:" + << listAllConfigFiles(configFilesPath) + << exit(FatalIOError); + } + + return false; + } + + // Read the configuration file + autoPtr fileStreamPtr(fileHandler().NewIFstream(path)); + ISstream& fileStream = fileStreamPtr(); + + // Delay processing the functionEntries + // until after the function argument entries have been added + entry::disableFunctionEntries = true; + dictionary funcsDict(funcType, parentDict, fileStream); + entry::disableFunctionEntries = false; + + dictionary* funcDictPtr = &funcsDict; + + if (funcsDict.found(funcType) && funcsDict.isDict(funcType)) + { + funcDictPtr = &funcsDict.subDict(funcType); + } + + dictionary& funcDict = *funcDictPtr; + + // Store the funcDict as read for error reporting context + const dictionary funcDict0(funcDict); + + // Insert the 'field' and/or 'fields' and 'objects' entries corresponding + // to both the arguments and the named arguments + DynamicList fieldArgs; + forAll(args, i) + { + fieldArgs.append(wordAndDictionary(args[i], dictionary::null)); + } + forAll(namedArgs, i) + { + if (namedArgs[i].first() == "field") + { + IStringStream iss(namedArgs[i].second()); + fieldArgs.append(wordAndDictionary(iss)); + } + if + ( + namedArgs[i].first() == "fields" + || namedArgs[i].first() == "objects" + ) + { + IStringStream iss(namedArgs[i].second()); + fieldArgs.append(List(iss)); + } + } + if (fieldArgs.size() == 1) + { + funcDict.set("field", fieldArgs[0].first()); + funcDict.merge(fieldArgs[0].second()); + } + if (fieldArgs.size() >= 1) + { + funcDict.set("fields", fieldArgs); + funcDict.set("objects", fieldArgs); + } + + // Insert non-field arguments + forAll(namedArgs, i) + { + if + ( + namedArgs[i].first() != "field" + && namedArgs[i].first() != "fields" + && namedArgs[i].first() != "objects" + ) + { + const Pair dAk(dictAndKeyword(namedArgs[i].first())); + dictionary& subDict(funcDict.scopedDict(dAk.first())); + IStringStream entryStream + ( + dAk.second() + ' ' + namedArgs[i].second() + ';' + ); + subDict.set(entry::New(entryStream).ptr()); + } + } + + // Insert the region name if specified + if (region != word::null) + { + funcDict.set("region", region); + } + + // Set the name of the function entry to that specified by the optional + // funcName argument otherwise automatically generate a unique name + // from the function type and arguments + const word funcName + ( + funcDict.lookupOrDefault("funcName", string::validate(argString)) + ); + + // Check for anything in the configuration that has not been set + List> unsetArgs = unsetConfigEntries(funcDict); + bool hasUnsetError = false; + forAll(unsetArgs, i) + { + if + ( + unsetArgs[i].first() != "fields" + && unsetArgs[i].first() != "objects" + ) + { + hasUnsetError = true; + } + } + if (!hasUnsetError) + { + forAll(unsetArgs, i) + { + funcDict.set(unsetArgs[i].first(), wordList()); + } + } + else + { + FatalIOErrorInFunction(funcDict0) + << nl; + + forAll(unsetArgs, i) + { + FatalIOErrorInFunction(funcDict0) + << "Essential value for keyword '" << unsetArgs[i].first() + << "' not set" << nl; + } + + FatalIOErrorInFunction(funcDict0) + << nl << "In function entry:" << nl + << " " << argString.c_str() << nl + << nl << "In " << contextTypeAndValue.first().c_str() << ":" << nl + << " " << contextTypeAndValue.second().c_str() << nl; + + word funcType; + wordReList args; + List> namedArgs; + dictArgList(argString, funcType, args, namedArgs); + + string argList; + forAll(args, i) + { + args[i].strip(" \n"); + argList += (argList.size() ? ", " : "") + args[i]; + } + forAll(namedArgs, i) + { + namedArgs[i].second().strip(" \n"); + argList += + (argList.size() ? ", " : "") + + namedArgs[i].first() + " = " + namedArgs[i].second(); + } + forAll(unsetArgs, i) + { + unsetArgs[i].second().strip(" \n"); + argList += + (argList.size() ? ", " : "") + + unsetArgs[i].first() + " = " + unsetArgs[i].second(); + } + + FatalIOErrorInFunction(funcDict0) + << nl << "The function entry should be:" << nl + << " " << funcType << '(' << argList.c_str() << ')' + << exit(FatalIOError); + } + + // Re-parse the funcDict to execute the functionEntries + // now that the function argument entries have been added + dictionary funcArgsDict; + funcArgsDict.add(funcName, funcDict); + { + OStringStream os; + funcArgsDict.write(os); + funcArgsDict = dictionary + ( + funcType, + parentDict, + IStringStream(os.str())() + ); + } + + // Merge this configuration dictionary into parentDict + parentDict.merge(funcArgsDict); + parentDict.subDict(funcName).name() = funcDict.name(); + + return true; +} + + +// * * * * * * * * * * * * * * * IOstream Functions * * * * * * * * * * * * // + +void Foam::writeEntry(Ostream& os, const dictionary& value) +{ + os << value; +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeFuncEntry/includeFuncEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/includeFuncEntry/includeFuncEntry.C index f0787e0db7..49a1a778c3 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeFuncEntry/includeFuncEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/includeFuncEntry/includeFuncEntry.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -24,8 +24,6 @@ License \*---------------------------------------------------------------------------*/ #include "includeFuncEntry.H" -#include "functionObjectList.H" -#include "stringOps.H" #include "addToMemberFunctionSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -47,6 +45,12 @@ namespace functionEntries } +Foam::fileName Foam::functionEntries::includeFuncEntry::functionObjectDictPath +( + "caseDicts/postProcessing" +); + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // bool Foam::functionEntries::includeFuncEntry::execute @@ -58,10 +62,11 @@ bool Foam::functionEntries::includeFuncEntry::execute // Read line containing the function name and the optional arguments const string fNameArgs(readFuncNameArgs(is)); - return functionObjectList::readFunctionObject + return readConfigFile ( fNameArgs, parentDict, + functionObjectDictPath, {"file", is.name() + " at line " + Foam::name(is.lineNumber())} ); } diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeFuncEntry/includeFuncEntry.H b/src/OpenFOAM/db/dictionary/functionEntries/includeFuncEntry/includeFuncEntry.H index dcf4652736..d01ed97d3f 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeFuncEntry/includeFuncEntry.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/includeFuncEntry/includeFuncEntry.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -57,9 +57,6 @@ Description Other dictionary entries may also be specified using named arguments. -See also - Foam::functionObjectList - SourceFiles includeFuncEntry.C @@ -92,6 +89,13 @@ public: ClassName("includeFunc"); + // Static Data Members + + //- Default relative path to the directory structure + // containing the functionObject dictionary files + static fileName functionObjectDictPath; + + // Member Functions //- Execute the functionEntry in a sub-dict context diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C index 85230c0c9c..a78a6ae2bc 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -27,17 +27,6 @@ License #include "argList.H" #include "timeControlFunctionObject.H" #include "dictionaryEntry.H" -#include "stringOps.H" -#include "etcFiles.H" -#include "wordAndDictionary.H" - -/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */ - -Foam::fileName Foam::functionObjectList::functionObjectDictPath -( - "caseDicts/postProcessing" -); - // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // @@ -69,391 +58,6 @@ Foam::functionObject* Foam::functionObjectList::remove } -void Foam::functionObjectList::listDir -( - const fileName& dir, - HashSet& foMap -) -{ - // Search specified directory for functionObject configuration files - { - fileNameList foFiles(fileHandler().readDir(dir)); - forAll(foFiles, f) - { - if (foFiles[f].ext().empty()) - { - foMap.insert(foFiles[f]); - } - } - } - - // Recurse into sub-directories - { - fileNameList foDirs(fileHandler().readDir(dir, fileType::directory)); - forAll(foDirs, fd) - { - listDir(dir/foDirs[fd], foMap); - } - } -} - - -Foam::wordList Foam::functionObjectList::list() -{ - HashSet foMap; - - fileNameList etcDirs(findEtcDirs(functionObjectDictPath)); - - forAll(etcDirs, ed) - { - listDir(etcDirs[ed], foMap); - } - - return foMap.sortedToc(); -} - - -Foam::fileName Foam::functionObjectList::findDict -( - const word& funcName, - const word& region -) -{ - // First check if there is a functionObject dictionary file in the - // region system directory - { - const fileName dictFile - ( - stringOps::expand("$FOAM_CASE")/"system"/region/funcName - ); - - if (isFile(dictFile)) - { - return dictFile; - } - } - - // Next, if the region is specified, check if there is a functionObject - // dictionary file in the global system directory - if (region != word::null) - { - const fileName dictFile - ( - stringOps::expand("$FOAM_CASE")/"system"/funcName - ); - - if (isFile(dictFile)) - { - return dictFile; - } - } - - // Finally, check etc directories - { - const fileNameList etcDirs(findEtcDirs(functionObjectDictPath)); - - forAll(etcDirs, i) - { - const fileName dictFile(search(funcName, etcDirs[i])); - - if (!dictFile.empty()) - { - return dictFile; - } - } - } - - return fileName::null; -} - - -Foam::List> -Foam::functionObjectList::unsetEntries(const dictionary& funcDict) -{ - const wordRe unsetPattern("<.*>"); - unsetPattern.compile(); - - List> unsetArgs; - - forAllConstIter(IDLList, funcDict, iter) - { - if (iter().isStream()) - { - ITstream& its = iter().stream(); - OStringStream oss; - bool isUnset = false; - - forAll(its, i) - { - oss << its[i]; - if (its[i].isWord() && unsetPattern.match(its[i].wordToken())) - { - isUnset = true; - } - } - - if (isUnset) - { - unsetArgs.append - ( - Tuple2 - ( - iter().keyword(), - oss.str() - ) - ); - } - } - else - { - List> subUnsetArgs = - unsetEntries(iter().dict()); - - forAll(subUnsetArgs, i) - { - unsetArgs.append - ( - Tuple2 - ( - iter().keyword() + '/' + subUnsetArgs[i].first(), - subUnsetArgs[i].second() - ) - ); - } - } - } - - return unsetArgs; -} - - -bool Foam::functionObjectList::readFunctionObject -( - const string& funcArgs, - dictionary& functionsDict, - const Pair& contextTypeAndValue, - const word& region -) -{ - word funcType; - wordReList args; - List> namedArgs; - - dictArgList(funcArgs, funcType, args, namedArgs); - - // Search for the functionObject dictionary - fileName path = findDict(funcType, region); - - if (path == fileName::null) - { - if (funcType == word::null) - { - FatalIOErrorInFunction(functionsDict) - << "functionObject configuration file name not specified" - << nl << nl - << "Available configured functionObjects:" - << list() - << exit(FatalIOError); - } - else - { - FatalIOErrorInFunction(functionsDict) - << "Cannot find functionObject configuration file " - << funcType << nl << nl - << "Available configured functionObjects:" - << list() - << exit(FatalIOError); - } - - return false; - } - - // Read the functionObject dictionary - // IFstream fileStream(path); - autoPtr fileStreamPtr(fileHandler().NewIFstream(path)); - ISstream& fileStream = fileStreamPtr(); - - // Delay processing the functionEntries - // until after the function argument entries have been added - entry::disableFunctionEntries = true; - dictionary funcsDict(funcType, functionsDict, fileStream); - entry::disableFunctionEntries = false; - - dictionary* funcDictPtr = &funcsDict; - - if (funcsDict.found(funcType) && funcsDict.isDict(funcType)) - { - funcDictPtr = &funcsDict.subDict(funcType); - } - - dictionary& funcDict = *funcDictPtr; - - // Store the funcDict as read for error reporting context - const dictionary funcDict0(funcDict); - - // Insert the 'field' and/or 'fields' and 'objects' entries corresponding - // to both the arguments and the named arguments - DynamicList fieldArgs; - forAll(args, i) - { - fieldArgs.append(wordAndDictionary(args[i], dictionary::null)); - } - forAll(namedArgs, i) - { - if (namedArgs[i].first() == "field") - { - IStringStream iss(namedArgs[i].second()); - fieldArgs.append(wordAndDictionary(iss)); - } - if - ( - namedArgs[i].first() == "fields" - || namedArgs[i].first() == "objects" - ) - { - IStringStream iss(namedArgs[i].second()); - fieldArgs.append(List(iss)); - } - } - if (fieldArgs.size() == 1) - { - funcDict.set("field", fieldArgs[0].first()); - funcDict.merge(fieldArgs[0].second()); - } - if (fieldArgs.size() >= 1) - { - funcDict.set("fields", fieldArgs); - funcDict.set("objects", fieldArgs); - } - - // Insert non-field arguments - forAll(namedArgs, i) - { - if - ( - namedArgs[i].first() != "field" - && namedArgs[i].first() != "fields" - && namedArgs[i].first() != "objects" - ) - { - const Pair dAk(dictAndKeyword(namedArgs[i].first())); - dictionary& subDict(funcDict.scopedDict(dAk.first())); - IStringStream entryStream - ( - dAk.second() + ' ' + namedArgs[i].second() + ';' - ); - subDict.set(entry::New(entryStream).ptr()); - } - } - - // Insert the region name if specified - if (region != word::null) - { - funcDict.set("region", region); - } - - // Set the name of the function entry to that specified by the optional - // funcName argument otherwise automatically generate a unique name - // from the function type and arguments - const word funcName - ( - funcDict.lookupOrDefault("funcName", string::validate(funcArgs)) - ); - - // Check for anything in the configuration that has not been set - List> unsetArgs = unsetEntries(funcDict); - bool hasUnsetError = false; - forAll(unsetArgs, i) - { - if - ( - unsetArgs[i].first() != "fields" - && unsetArgs[i].first() != "objects" - ) - { - hasUnsetError = true; - } - } - if (!hasUnsetError) - { - forAll(unsetArgs, i) - { - funcDict.set(unsetArgs[i].first(), wordList()); - } - } - else - { - FatalIOErrorInFunction(funcDict0) - << nl; - - forAll(unsetArgs, i) - { - FatalIOErrorInFunction(funcDict0) - << "Essential value for keyword '" << unsetArgs[i].first() - << "' not set" << nl; - } - - FatalIOErrorInFunction(funcDict0) - << nl << "In function entry:" << nl - << " " << funcArgs.c_str() << nl - << nl << "In " << contextTypeAndValue.first().c_str() << ":" << nl - << " " << contextTypeAndValue.second().c_str() << nl; - - word funcType; - wordReList args; - List> namedArgs; - dictArgList(funcArgs, funcType, args, namedArgs); - - string argList; - forAll(args, i) - { - args[i].strip(" \n"); - argList += (argList.size() ? ", " : "") + args[i]; - } - forAll(namedArgs, i) - { - namedArgs[i].second().strip(" \n"); - argList += - (argList.size() ? ", " : "") - + namedArgs[i].first() + " = " + namedArgs[i].second(); - } - forAll(unsetArgs, i) - { - unsetArgs[i].second().strip(" \n"); - argList += - (argList.size() ? ", " : "") - + unsetArgs[i].first() + " = " + unsetArgs[i].second(); - } - - FatalIOErrorInFunction(funcDict0) - << nl << "The function entry should be:" << nl - << " " << funcType << '(' << argList.c_str() << ')' - << exit(FatalIOError); - } - - // Re-parse the funcDict to execute the functionEntries - // now that the function argument entries have been added - dictionary funcArgsDict; - funcArgsDict.add(funcName, funcDict); - { - OStringStream os; - funcArgsDict.write(os); - funcArgsDict = dictionary - ( - funcType, - functionsDict, - IStringStream(os.str())() - ); - } - - // Merge this functionObject dictionary into functionsDict - functionsDict.merge(funcArgsDict); - functionsDict.subDict(funcName).name() = funcDict.name(); - - return true; -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::functionObjectList::functionObjectList @@ -538,10 +142,11 @@ Foam::autoPtr Foam::functionObjectList::New if (args.optionFound("func")) { - readFunctionObject + readConfigFile ( args["func"], functionsDict, + functionEntries::includeFuncEntry::functionObjectDictPath, {"command", args.commandLine()}, region ); @@ -553,10 +158,11 @@ Foam::autoPtr Foam::functionObjectList::New forAll(funcs, i) { - readFunctionObject + readConfigFile ( funcs[i], functionsDict, + functionEntries::includeFuncEntry::functionObjectDictPath, {"command", args.commandLine()}, region ); diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H index 923297737f..0f7ab3fb17 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -43,9 +43,8 @@ SourceFiles #include "PtrList.H" #include "functionObject.H" #include "SHA1Digest.H" -#include "HashTable.H" #include "HashSet.H" -#include "dictionary.H" +#include "includeFuncEntry.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -94,26 +93,9 @@ class functionObjectList // Returns a nullptr (and index -1) if it didn't exist functionObject* remove(const word&, label& oldIndex); - //- Search the specified directory for functionObject - // configuration files, add to the given map and recurse - static void listDir(const fileName& dir, HashSet& foMap); - - //- Return unset entries and their placeholder values - static List> unsetEntries - ( - const dictionary& funcDict - ); - public: - // Static Data Members - - //- Default relative path to the directory structure - // containing the functionObject dictionary files - static fileName functionObjectDictPath; - - // Constructors //- Construct from Time and the execution setting. @@ -179,75 +161,6 @@ public: //- Find the ID of a given function object by name label findObjectID(const word& name) const; - //- Return the list of functionObject configuration files in - // user/group/shipped directories. - // The search scheme allows for version-specific and - // version-independent files using the following hierarchy: - // - \b user settings: - // - ~/.OpenFOAM/\/caseDicts/postProcessing - // - ~/.OpenFOAM/caseDicts/postProcessing - // - \b group (site) settings (when $WM_PROJECT_SITE is set): - // - $WM_PROJECT_SITE/\/etc/caseDicts/postProcessing - // - $WM_PROJECT_SITE/etc/caseDicts/postProcessing - // - \b group (site) settings (when $WM_PROJECT_SITE is not set): - // - $WM_PROJECT_INST_DIR/site/\/etc/ - // caseDicts/postProcessing - // - $WM_PROJECT_INST_DIR/site/etc/caseDicts/postProcessing - // - \b other (shipped) settings: - // - $WM_PROJECT_DIR/etc/caseDicts/postProcessing - static wordList list(); - - //- Search for functionObject dictionary file for given region - // and if not present also search the case directory as well as the - // user/group/shipped directories. - // The search scheme allows for version-specific and - // version-independent files using the following hierarchy: - // - \b user settings: - // - ~/.OpenFOAM/\/caseDicts/postProcessing - // - ~/.OpenFOAM/caseDicts/postProcessing - // - \b group (site) settings (when $WM_PROJECT_SITE is set): - // - $WM_PROJECT_SITE/\/etc/caseDicts/postProcessing - // - $WM_PROJECT_SITE/etc/caseDicts/postProcessing - // - \b group (site) settings (when $WM_PROJECT_SITE is not set): - // - $WM_PROJECT_INST_DIR/site/\/etc/ - // caseDicts/postProcessing - // - $WM_PROJECT_INST_DIR/site/etc/caseDicts/postProcessing - // - \b other (shipped) settings: - // - $WM_PROJECT_DIR/etc/caseDicts/postProcessing - // - // \return The path of the functionObject dictionary file if found - // otherwise null - static fileName findDict - ( - const word& funcName, - const word& region = word::null - ); - - //- Read the specified functionObject configuration dictionary - // parsing the optional arguments included in the string 'funcArgs', - // inserting 'field' or 'fields' entries as required and merging the - // resulting functionObject dictionary into 'functionsDict'. - // - // Parses the optional functionObject arguments: - // 'Q(U)' -> funcName = Q; args = (U) - // -> field U; - // - // Supports named arguments: - // 'patchAverage(patch=inlet, p,U)' - // or - // 'patchAverage(patch=inlet, field=(p U))' - // -> funcName = patchAverage; - // args = (patch=inlet, p,U) - // -> patch inlet; - // fields (p U); - static bool readFunctionObject - ( - const string& funcArgs, - dictionary& functionsDict, - const Pair& contextTypeAndValue, - const word& region = word::null - ); - //- Read and set the function objects if their data have changed bool read(); diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/postProcess.H b/src/OpenFOAM/db/functionObjects/functionObjectList/postProcess.H index bae038b43d..1c28c948c2 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/postProcess.H +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/postProcess.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -78,7 +78,10 @@ if (argList::postProcess(argc, argv)) { Info<< nl << "Available configured functionObjects:" - << functionObjectList::list() + << listAllConfigFiles + ( + functionEntries::includeFuncEntry::functionObjectDictPath + ) << endl; return 0; } diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index cffc714ee5..c7d1ab0ea5 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -500,10 +500,12 @@ $(MRF)/derivedFvPatchFields/MRFFreestreamVelocity/MRFFreestreamVelocityFvPatchVe fvModels = $(general)/fvModels $(fvModels)/fvModel.C $(fvModels)/fvModels.C +$(fvModels)/includeFvModelEntry/includeFvModelEntry.C fvConstraints = $(general)/fvConstraints $(fvConstraints)/fvConstraint.C $(fvConstraints)/fvConstraints.C +$(fvConstraints)/includeFvConstraintEntry/includeFvConstraintEntry.C cellSources = sets/cellSources $(cellSources)/fieldToCell/fieldToCell.C diff --git a/src/finiteVolume/cfdTools/general/fvConstraints/includeFvConstraintEntry/includeFvConstraintEntry.C b/src/finiteVolume/cfdTools/general/fvConstraints/includeFvConstraintEntry/includeFvConstraintEntry.C new file mode 100644 index 0000000000..0013f2144c --- /dev/null +++ b/src/finiteVolume/cfdTools/general/fvConstraints/includeFvConstraintEntry/includeFvConstraintEntry.C @@ -0,0 +1,76 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2023 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 . + +\*---------------------------------------------------------------------------*/ + +#include "includeFvConstraintEntry.H" +#include "addToMemberFunctionSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionEntries +{ + defineTypeNameAndDebug(includeFvConstraintEntry, 0); + + addToMemberFunctionSelectionTable + ( + functionEntry, + includeFvConstraintEntry, + execute, + dictionaryIstream + ); +} +} + + +Foam::fileName +Foam::functionEntries::includeFvConstraintEntry::fvConstraintDictPath +( + "caseDicts/fvConstraints" +); + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionEntries::includeFvConstraintEntry::execute +( + dictionary& parentDict, + Istream& is +) +{ + // Read line containing the function name and the optional arguments + const string fNameArgs(readFuncNameArgs(is)); + + return readConfigFile + ( + fNameArgs, + parentDict, + fvConstraintDictPath, + {"file", is.name() + " at line " + Foam::name(is.lineNumber())} + ); +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/fvConstraints/includeFvConstraintEntry/includeFvConstraintEntry.H b/src/finiteVolume/cfdTools/general/fvConstraints/includeFvConstraintEntry/includeFvConstraintEntry.H new file mode 100644 index 0000000000..37a11917dc --- /dev/null +++ b/src/finiteVolume/cfdTools/general/fvConstraints/includeFvConstraintEntry/includeFvConstraintEntry.H @@ -0,0 +1,123 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2023 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 . + +Class + Foam::functionEntries::includeFvConstraintEntry + +Description + Specify a fvConstraint dictionary file to include, expects the + fvConstraint name to follow with option arguments (without quotes). + + Searches for fvConstraint dictionary file in user/group/shipped + directories allowing for version-specific and version-independent files + using the following hierarchy: + - \b user settings: + - ~/.OpenFOAM/\/caseDicts/fvConstraints + - ~/.OpenFOAM/caseDicts/fvConstraints + - \b group (site) settings (when $WM_PROJECT_SITE is set): + - $WM_PROJECT_SITE/\/etc/caseDicts/fvConstraints + - $WM_PROJECT_SITE/etc/caseDicts/fvConstraints + - \b group (site) settings (when $WM_PROJECT_SITE is not set): + - $WM_PROJECT_INST_DIR/site/\/etc/caseDicts/fvConstraints + - $WM_PROJECT_INST_DIR/site/etc/caseDicts/fvConstraints + - \b other (shipped) settings: + - $WM_PROJECT_DIR/etc/caseDicts/fvConstraints + + The optional field arguments included in the name are inserted in 'field' or + 'fields' entries in the fvConstraint dictionary and included in the name + of the fvConstraint entry to avoid conflict. + + Examples: + \verbatim + #includeConstraint limitPressure(minFactor=0.1, maxFactor=2) + #includeConstraint limitTemperature(min=101, max=1000) + \endverbatim + or for a multiphase case: + \verbatim + #includeConstraint limitLowPressure(min=1e4) + #includeConstraint limitTemperature(phase=steam, min=270, max=2000) + #includeConstraint limitTemperature(phase=water, min=270, max=2000) + \endverbatim + + Other dictionary entries may also be specified using named arguments. + +See also + Foam::includeFvModelEntry + Foam::includeFuncEntry + +SourceFiles + includeFvConstraintEntry.C + +\*---------------------------------------------------------------------------*/ + +#ifndef includeFvConstraintEntry_H +#define includeFvConstraintEntry_H + +#include "functionEntry.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionEntries +{ + +/*---------------------------------------------------------------------------*\ + Class includeFvConstraintEntry Declaration +\*---------------------------------------------------------------------------*/ + +class includeFvConstraintEntry +: + public functionEntry +{ + +public: + + //- Runtime type information + ClassName("includeConstraint"); + + + // Static Data Members + + //- Default relative path to the directory structure + // containing the fvConstraint dictionary files + static fileName fvConstraintDictPath; + + + // Member Functions + + //- Execute the functionEntry in a sub-dict context + static bool execute(dictionary& parentDict, Istream&); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionEntries +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/fvModels/includeFvModelEntry/includeFvModelEntry.C b/src/finiteVolume/cfdTools/general/fvModels/includeFvModelEntry/includeFvModelEntry.C new file mode 100644 index 0000000000..ffc8fa65ea --- /dev/null +++ b/src/finiteVolume/cfdTools/general/fvModels/includeFvModelEntry/includeFvModelEntry.C @@ -0,0 +1,75 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2023 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 . + +\*---------------------------------------------------------------------------*/ + +#include "includeFvModelEntry.H" +#include "addToMemberFunctionSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionEntries +{ + defineTypeNameAndDebug(includeFvModelEntry, 0); + + addToMemberFunctionSelectionTable + ( + functionEntry, + includeFvModelEntry, + execute, + dictionaryIstream + ); +} +} + + +Foam::fileName Foam::functionEntries::includeFvModelEntry::fvModelDictPath +( + "caseDicts/fvModels" +); + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionEntries::includeFvModelEntry::execute +( + dictionary& parentDict, + Istream& is +) +{ + // Read line containing the function name and the optional arguments + const string fNameArgs(readFuncNameArgs(is)); + + return readConfigFile + ( + fNameArgs, + parentDict, + fvModelDictPath, + {"file", is.name() + " at line " + Foam::name(is.lineNumber())} + ); +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/fvModels/includeFvModelEntry/includeFvModelEntry.H b/src/finiteVolume/cfdTools/general/fvModels/includeFvModelEntry/includeFvModelEntry.H new file mode 100644 index 0000000000..f44f9252c9 --- /dev/null +++ b/src/finiteVolume/cfdTools/general/fvModels/includeFvModelEntry/includeFvModelEntry.H @@ -0,0 +1,117 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2023 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 . + +Class + Foam::functionEntries::includeFvModelEntry + +Description + Specify a fvModel dictionary file to include, expects the + fvModel name to follow with option arguments (without quotes). + + Searches for fvModel dictionary file in user/group/shipped + directories allowing for version-specific and version-independent files + using the following hierarchy: + - \b user settings: + - ~/.OpenFOAM/\/caseDicts/fvModels + - ~/.OpenFOAM/caseDicts/fvModels + - \b group (site) settings (when $WM_PROJECT_SITE is set): + - $WM_PROJECT_SITE/\/etc/caseDicts/fvModels + - $WM_PROJECT_SITE/etc/caseDicts/fvModels + - \b group (site) settings (when $WM_PROJECT_SITE is not set): + - $WM_PROJECT_INST_DIR/site/\/etc/caseDicts/fvModels + - $WM_PROJECT_INST_DIR/site/etc/caseDicts/fvModels + - \b other (shipped) settings: + - $WM_PROJECT_DIR/etc/caseDicts/fvModels + + The optional field arguments included in the name are inserted in 'field' or + 'fields' entries in the fvModel dictionary and included in the name + of the fvModel entry to avoid conflict. + + Examples: + \verbatim + #includeModel clouds + #includeModel surfaceFilms + \endverbatim + + Other dictionary entries may also be specified using named arguments. + +See also + Foam::includeFvConstraintEntry + Foam::includeFuncEntry + +SourceFiles + includeFvModelEntry.C + +\*---------------------------------------------------------------------------*/ + +#ifndef includeFvModelEntry_H +#define includeFvModelEntry_H + +#include "functionEntry.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionEntries +{ + +/*---------------------------------------------------------------------------*\ + Class includeFvModelEntry Declaration +\*---------------------------------------------------------------------------*/ + +class includeFvModelEntry +: + public functionEntry +{ + +public: + + //- Runtime type information + ClassName("includeModel"); + + + // Static Data Members + + //- Default relative path to the directory structure + // containing the fvModel dictionary files + static fileName fvModelDictPath; + + + // Member Functions + + //- Execute the functionEntry in a sub-dict context + static bool execute(dictionary& parentDict, Istream&); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionEntries +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/tutorials/modules/fluid/aerofoilNACA0012/system/fvConstraints b/tutorials/modules/fluid/aerofoilNACA0012/system/fvConstraints index 7eb7923513..fc104de927 100644 --- a/tutorials/modules/fluid/aerofoilNACA0012/system/fvConstraints +++ b/tutorials/modules/fluid/aerofoilNACA0012/system/fvConstraints @@ -13,22 +13,7 @@ FoamFile } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -limitp -{ - type limitPressure; - - minFactor 0.1; - maxFactor 2; -} - -limitT -{ - type limitTemperature; - - min 101; - max 1000; - - selectionMode all; -} +#includeConstraint limitPressure(minFactor=0.1, maxFactor=2) +#includeConstraint limitTemperature(min=101, max=1000) //************************************************************************** // diff --git a/tutorials/modules/fluid/aerofoilNACA0012Steady/system/fvConstraints b/tutorials/modules/fluid/aerofoilNACA0012Steady/system/fvConstraints index 83dd8a172b..cc71fae4eb 100644 --- a/tutorials/modules/fluid/aerofoilNACA0012Steady/system/fvConstraints +++ b/tutorials/modules/fluid/aerofoilNACA0012Steady/system/fvConstraints @@ -13,20 +13,7 @@ FoamFile } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -limitp -{ - type limitPressure; - - minFactor 0.1; - maxFactor 2; -} - -limitT -{ - type limitTemperature; - min 101; - max 1000; - selectionMode all; -} +#includeConstraint limitPressure(minFactor=0.1, maxFactor=2) +#includeConstraint limitTemperature(min=101, max=1000) // ************************************************************************* // diff --git a/tutorials/modules/multicomponentFluid/hotBoxes/constant/fvModels b/tutorials/modules/multicomponentFluid/hotBoxes/constant/fvModels index c0ccd0a504..4171329113 100644 --- a/tutorials/modules/multicomponentFluid/hotBoxes/constant/fvModels +++ b/tutorials/modules/multicomponentFluid/hotBoxes/constant/fvModels @@ -14,16 +14,7 @@ FoamFile } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -clouds -{ - type clouds; - libs ("liblagrangianParcel.so"); -} - -surfaceFilms -{ - type surfaceFilms; - libs ("libsurfaceFilmModels.so"); -} +#includeModel clouds +#includeModel surfaceFilms // ************************************************************************* // diff --git a/tutorials/modules/multiphaseEuler/steamInjection/system/fvConstraints b/tutorials/modules/multiphaseEuler/steamInjection/system/fvConstraints index d6cc15f6d1..d69959dd00 100644 --- a/tutorials/modules/multiphaseEuler/steamInjection/system/fvConstraints +++ b/tutorials/modules/multiphaseEuler/steamInjection/system/fvConstraints @@ -14,29 +14,8 @@ FoamFile } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -limitp -{ - type limitPressure; - - min 1e4; -} - -limitTsteam -{ - type limitTemperature; - selectionMode all; - min 270; - max 2000; - phase steam; -} - -limitTwater -{ - type limitTemperature; - selectionMode all; - min 270; - max 2000; - phase water; -} +#includeConstraint limitLowPressure(min=1e4) +#includeConstraint limitTemperature(phase=steam, min=270, max=2000) +#includeConstraint limitTemperature(phase=water, min=270, max=2000) // ************************************************************************* //