From b7c0cdefce9b3c0abf8a97e6c57fdc7c397dd444 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Thu, 11 Jul 2019 09:46:42 +0100 Subject: [PATCH] dictionary: Added support for absolute paths when reading dictionaries referred to within keywords For example in the combustion/coldEngineFoam/freePiston/0/p field the internalField entry may be obtained from the include/caseSettings dictionary using either a relative path: internalField uniform $include/caseSettings!internalField/p; or an absolute path: internalField uniform ${$FOAM_CASE/0/include/caseSettings!internalField/p}; in which recursive substitution using ${...} is applied to expand the $FOAM_CASE environment variable. --- src/OpenFOAM/db/dictionary/dictionary.C | 11 ++++++-- .../combustion/coldEngineFoam/freePiston/0/T | 7 ++--- .../combustion/coldEngineFoam/freePiston/0/U | 9 +++--- .../coldEngineFoam/freePiston/0/air | 5 ++-- .../coldEngineFoam/freePiston/0/alphat | 28 ++++++++++++++----- .../coldEngineFoam/freePiston/0/epsilon | 7 ++--- .../freePiston/0/include/boundaryConditions | 5 ++-- .../freePiston/0/include/caseSettings | 1 + .../combustion/coldEngineFoam/freePiston/0/k | 7 ++--- .../coldEngineFoam/freePiston/0/nut | 28 ++++++++++++++----- .../combustion/coldEngineFoam/freePiston/0/p | 7 ++--- 11 files changed, 72 insertions(+), 43 deletions(-) diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C index 3d2f08da8c..e646ce06f3 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.C +++ b/src/OpenFOAM/db/dictionary/dictionary.C @@ -31,7 +31,7 @@ License #include "DynamicList.H" #include "inputSyntaxEntry.H" #include "fileOperation.H" - +#include "stringOps.H" /* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */ @@ -330,7 +330,12 @@ const Foam::entry* Foam::dictionary::lookupScopedSubEntryPtr // Lookup in the dictionary specified by file name // created from the part of the keyword before the '!' - const fileName fName = keyword.substr(0, emarkPos); + fileName fName = keyword.substr(0, emarkPos); + + if (!fName.isAbsolute()) + { + fName = topDict().name().path()/fName; + } if (fName == topDict().name()) { @@ -351,7 +356,7 @@ const Foam::entry* Foam::dictionary::lookupScopedSubEntryPtr autoPtr ifsPtr ( - fileHandler().NewIFstream(topDict().name().path()/fName) + fileHandler().NewIFstream(fName) ); ISstream& ifs = ifsPtr(); diff --git a/tutorials/combustion/coldEngineFoam/freePiston/0/T b/tutorials/combustion/coldEngineFoam/freePiston/0/T index bda2f9458c..c3a471c589 100644 --- a/tutorials/combustion/coldEngineFoam/freePiston/0/T +++ b/tutorials/combustion/coldEngineFoam/freePiston/0/T @@ -14,12 +14,11 @@ FoamFile object T; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#include "include/caseSettings" +#inputSyntax slash; dimensions [0 0 0 1 0 0 0]; -internalField uniform $:internalField.T; +internalField uniform $include/caseSettings!internalField/T; boundaryField { @@ -35,7 +34,7 @@ boundaryField liner { - $:wall.T; + $include/caseSettings!wall/T; } cylinderHead diff --git a/tutorials/combustion/coldEngineFoam/freePiston/0/U b/tutorials/combustion/coldEngineFoam/freePiston/0/U index 567a48aa99..f9ee829058 100644 --- a/tutorials/combustion/coldEngineFoam/freePiston/0/U +++ b/tutorials/combustion/coldEngineFoam/freePiston/0/U @@ -14,12 +14,11 @@ FoamFile object U; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#include "include/caseSettings" +#inputSyntax slash; dimensions [0 1 -1 0 0 0 0]; -internalField uniform $:internalField.U; +internalField uniform $include/caseSettings!internalField/U; boundaryField { @@ -35,7 +34,7 @@ boundaryField liner { - $:wall.U; + $include/caseSettings!wall/U; } cylinderHead @@ -45,7 +44,7 @@ boundaryField piston { - $:piston.U; + $include/caseSettings!piston/U; } } diff --git a/tutorials/combustion/coldEngineFoam/freePiston/0/air b/tutorials/combustion/coldEngineFoam/freePiston/0/air index b7f11f1c90..1a8fd32459 100644 --- a/tutorials/combustion/coldEngineFoam/freePiston/0/air +++ b/tutorials/combustion/coldEngineFoam/freePiston/0/air @@ -14,8 +14,7 @@ FoamFile object air; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#include "include/caseSettings" +#inputSyntax slash; dimensions [0 0 0 0 0 0 0]; @@ -35,7 +34,7 @@ boundaryField liner { - $:wall.p; + $include/caseSettings!wall/p; } cylinderHead diff --git a/tutorials/combustion/coldEngineFoam/freePiston/0/alphat b/tutorials/combustion/coldEngineFoam/freePiston/0/alphat index bbd84f83f7..38007571c2 100644 --- a/tutorials/combustion/coldEngineFoam/freePiston/0/alphat +++ b/tutorials/combustion/coldEngineFoam/freePiston/0/alphat @@ -14,8 +14,7 @@ FoamFile object alphat; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#include "include/caseSettings" +#inputSyntax slash; dimensions [1 -1 -1 0 0 0 0]; @@ -27,11 +26,26 @@ boundaryField { type wedge; } - front { $back; } - liner { $:wall.alphat; } - cylinderHead { $liner; } - piston { $liner; } -} + + front + { + $back; + } + + liner + { + $include/caseSettings!wall/alphat; + } + + cylinderHead + { + $liner; + } + + piston + { + $liner; + } } diff --git a/tutorials/combustion/coldEngineFoam/freePiston/0/epsilon b/tutorials/combustion/coldEngineFoam/freePiston/0/epsilon index 4b7b39e06a..07cf54cd41 100644 --- a/tutorials/combustion/coldEngineFoam/freePiston/0/epsilon +++ b/tutorials/combustion/coldEngineFoam/freePiston/0/epsilon @@ -14,12 +14,11 @@ FoamFile object epsilon; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#include "include/caseSettings" +#inputSyntax slash; dimensions [0 2 -3 0 0 0 0]; -internalField uniform $:internalField.epsilon; +internalField uniform $include/caseSettings!internalField/epsilon; boundaryField { @@ -35,7 +34,7 @@ boundaryField liner { - $:wall.epsilon; + $include/caseSettings!wall/epsilon; } cylinderHead diff --git a/tutorials/combustion/coldEngineFoam/freePiston/0/include/boundaryConditions b/tutorials/combustion/coldEngineFoam/freePiston/0/include/boundaryConditions index 554c95f1ce..bfc8bb7048 100644 --- a/tutorials/combustion/coldEngineFoam/freePiston/0/include/boundaryConditions +++ b/tutorials/combustion/coldEngineFoam/freePiston/0/include/boundaryConditions @@ -13,6 +13,7 @@ FoamFile object boundaryConditions; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#inputSyntax slash; wall { @@ -35,13 +36,13 @@ wall k { type kqRWallFunction; - value uniform $:internalField.k; + value uniform $!internalField/k; } epsilon { type epsilonWallFunction; - value uniform $:internalField.epsilon; + value uniform $!internalField/epsilon; } nut diff --git a/tutorials/combustion/coldEngineFoam/freePiston/0/include/caseSettings b/tutorials/combustion/coldEngineFoam/freePiston/0/include/caseSettings index 3d77f0d33a..dc11a7de3e 100644 --- a/tutorials/combustion/coldEngineFoam/freePiston/0/include/caseSettings +++ b/tutorials/combustion/coldEngineFoam/freePiston/0/include/caseSettings @@ -13,6 +13,7 @@ FoamFile object caseSettings; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#inputSyntax slash; internalField { diff --git a/tutorials/combustion/coldEngineFoam/freePiston/0/k b/tutorials/combustion/coldEngineFoam/freePiston/0/k index bff12ce1cd..7ca0227b8e 100644 --- a/tutorials/combustion/coldEngineFoam/freePiston/0/k +++ b/tutorials/combustion/coldEngineFoam/freePiston/0/k @@ -14,12 +14,11 @@ FoamFile object k; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#include "include/caseSettings" +#inputSyntax slash; dimensions [0 2 -2 0 0 0 0]; -internalField uniform $:internalField.k; +internalField uniform $include/caseSettings!internalField/k; boundaryField { @@ -35,7 +34,7 @@ boundaryField liner { - $:wall.k; + $include/caseSettings!wall/k; } cylinderHead diff --git a/tutorials/combustion/coldEngineFoam/freePiston/0/nut b/tutorials/combustion/coldEngineFoam/freePiston/0/nut index 4699fe28e1..c96bdc6f11 100644 --- a/tutorials/combustion/coldEngineFoam/freePiston/0/nut +++ b/tutorials/combustion/coldEngineFoam/freePiston/0/nut @@ -14,8 +14,7 @@ FoamFile object nut; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#include "include/caseSettings" +#inputSyntax slash; dimensions [0 2 -1 0 0 0 0]; @@ -27,11 +26,26 @@ boundaryField { type wedge; } - front { $back; } - liner { $:wall.nut; } - cylinderHead { $liner; } - piston { $liner; } -} + + front + { + $back; + } + + liner + { + $include/caseSettings!wall/nut; + } + + cylinderHead + { + $liner; + } + + piston + { + $liner; + } } diff --git a/tutorials/combustion/coldEngineFoam/freePiston/0/p b/tutorials/combustion/coldEngineFoam/freePiston/0/p index de5d4b69a9..7b0f0886a8 100644 --- a/tutorials/combustion/coldEngineFoam/freePiston/0/p +++ b/tutorials/combustion/coldEngineFoam/freePiston/0/p @@ -14,12 +14,11 @@ FoamFile object p; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#include "include/caseSettings" +#inputSyntax slash; dimensions [1 -1 -2 0 0 0 0]; -internalField uniform $:internalField.p; +internalField uniform $include/caseSettings!internalField/p; boundaryField { @@ -35,7 +34,7 @@ boundaryField liner { - $:wall.p; + $include/caseSettings!wall/p; } cylinderHead