From 5f88e4271ee50271ae06d8da58d69c7f07595a2d Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 11 Apr 2018 23:10:49 +0200 Subject: [PATCH] ENH: allow "", "" ... in the string expansions (issue #792) - the expansions were previously required as slash to follow, but now either are possible. "", "/" both yield the same as "$FOAM_CASE" and will not have a trailing slash in the result. The expansion of "$FOAM_CASE/" will however have a trailing slash. - adjust additional files using these expansions --- applications/test/string/Test-string.C | 26 +++++---- .../extrude/extrudeMesh/extrudeMeshDict | 4 +- .../createZeroDirectory/createZeroDirectory.C | 2 +- .../mesh/generation/snappyHexMeshDict.cfg | 2 +- .../axisymmetricJet/system/extrudeMeshDict | 13 +++-- .../interpolationTable/interpolationTable.H | 2 +- .../primitives/strings/stringOps/stringOps.C | 57 +++++++++++++------ ...timeVaryingUniformFixedValueFaPatchField.H | 2 +- .../general/coupling/externalFileCoupler.H | 2 +- .../derived/fan/fanFvPatchField.H | 2 +- .../field/externalCoupled/externalCoupled.H | 2 +- .../timeActivatedFileUpdate.H | 10 ++-- .../RAS/waterChannel/system/extrudeMeshDict | 12 ++-- .../RAS/waterChannel/system/extrudeMeshDict.1 | 12 ++-- .../RAS/waterChannel/system/extrudeMeshDict.2 | 12 ++-- 15 files changed, 93 insertions(+), 67 deletions(-) diff --git a/applications/test/string/Test-string.C b/applications/test/string/Test-string.C index 6fe33b37d5..f10fb9c056 100644 --- a/applications/test/string/Test-string.C +++ b/applications/test/string/Test-string.C @@ -72,26 +72,28 @@ int main(int argc, char *argv[]) const auto& cstr : { - "~OpenFOAM/controlDict", - "/controlDict", + "~OpenFOAM/controlDict", "/controlDict", + "$FOAM_CASE/xyz", "/xyz", + "$FOAM_CASE/constant/xyz", "/xyz", + "$FOAM_CASE/system/xyz", "/xyz", - "$FOAM_CASE/test", - "/test", + // corner cases + "~OpenFOAM", "", + "~OpenFOAM/", "/", + "$FOAM_CASE", "", + "$FOAM_CASE/constant", "", + "$FOAM_CASE/system", "", - "$FOAM_CASE/constant/test", - "/constant/test", - "/test", - - "$FOAM_CASE/system/test", - "/system/test", - "/test", + "$FOAM_CASE/", "/", + "$FOAM_CASE/constant/", "/", + "$FOAM_CASE/system/", "/", } ) { string input(cstr); string output(stringOps::expand(input)); - Info<<"input: " << input << nl + Info<< "input: " << input << nl << "expand: " << output << nl << nl; } } diff --git a/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudeMeshDict b/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudeMeshDict index 249a3816ba..4eecb73922 100644 --- a/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudeMeshDict +++ b/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudeMeshDict @@ -112,10 +112,10 @@ sigmaRadialCoeffs offsetSurfaceCoeffs { // Surface that mesh has been meshed to - baseSurface "$FOAM_CASE/constant/triSurface/DTC-scaled-inflated.obj"; + baseSurface "/triSurface/DTC-scaled-inflated.obj"; // Surface to fill in to - offsetSurface "$FOAM_CASE/constant/triSurface/DTC-scaled.obj"; + offsetSurface "/triSurface/DTC-scaled.obj"; } diff --git a/applications/utilities/preProcessing/createZeroDirectory/createZeroDirectory.C b/applications/utilities/preProcessing/createZeroDirectory/createZeroDirectory.C index 482876a0d1..ebe09b2219 100644 --- a/applications/utilities/preProcessing/createZeroDirectory/createZeroDirectory.C +++ b/applications/utilities/preProcessing/createZeroDirectory/createZeroDirectory.C @@ -150,7 +150,7 @@ void createFieldFiles field.add ( "#include", - "${FOAM_CASE}/system" + regionPath + "caseProperties" + "$FOAM_CASE/system" + regionPath + "caseProperties" ); field.add("dimensions", fieldDimensions[i]); diff --git a/etc/caseDicts/mesh/generation/snappyHexMeshDict.cfg b/etc/caseDicts/mesh/generation/snappyHexMeshDict.cfg index e533afe9c1..fc21a42e6e 100644 --- a/etc/caseDicts/mesh/generation/snappyHexMeshDict.cfg +++ b/etc/caseDicts/mesh/generation/snappyHexMeshDict.cfg @@ -74,7 +74,7 @@ addLayersControls meshQualityControls { - #include "${FOAM_CASE}/system/meshQualityDict" + #include "/meshQualityDict" } debug 0; diff --git a/etc/templates/axisymmetricJet/system/extrudeMeshDict b/etc/templates/axisymmetricJet/system/extrudeMeshDict index a88f62ad77..310d3ac717 100644 --- a/etc/templates/axisymmetricJet/system/extrudeMeshDict +++ b/etc/templates/axisymmetricJet/system/extrudeMeshDict @@ -14,13 +14,13 @@ FoamFile } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -constructFrom patch; -sourceCase "$FOAM_CASE"; +constructFrom patch; +sourceCase ""; -sourcePatches (front); +sourcePatches (front); exposedPatchName back; -extrudeModel wedge; +extrudeModel wedge; sectorCoeffs { @@ -29,7 +29,8 @@ sectorCoeffs angle 1; } -flipNormals false; -mergeFaces false; +flipNormals false; + +mergeFaces false; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.H b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.H index e75040703e..a7dbe18e6e 100644 --- a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.H +++ b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.H @@ -42,7 +42,7 @@ Description Read csv format: \verbatim readerType csv; - file "$FOAM_CASE/constant/p0vsTime.csv"; + file "/p0vsTime.csv"; hasHeaderLine true; // skip first line timeColumn 0; // time is in column 0 valueColumns (1); // value starts in column 1 diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C index 2d31027626..51d095d1e1 100644 --- a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C +++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C @@ -50,13 +50,29 @@ static void expandLeadingTag(std::string& s, const char b, const char e) } auto delim = s.find(e); - if (delim == std::string::npos || s[++delim] != '/') + if (delim == std::string::npos) { - return; // Ignore if there is no '/' after + return; // Error: no closing delim - ignore expansion + } + + fileName file; + + const char nextC = s[++delim]; + + // Require the following character to be '/' or the end of string. + if (nextC) + { + if (nextC != '/') + { + return; + } + + file.assign(s.substr(delim + 1)); } const std::string tag(s, 1, delim-2); - fileName file(s.substr(delim + 1)); + + // Note that file is also allowed to be an empty string. if (tag == "etc") { @@ -120,25 +136,32 @@ static void expandLeading(std::string& s) { return; } - else if (s[0] == '.') + + switch (s[0]) { - // Expand a lone '.' and an initial './' into cwd - if (s.size() == 1) + case '.': { - s = cwd(); + // Expand a lone '.' and an initial './' into cwd + if (s.size() == 1) + { + s = cwd(); + } + else if (s[1] == '/') + { + s.std::string::replace(0, 1, cwd()); + } + break; } - else if (s[1] == '/') + case '<': { - s.std::string::replace(0, 1, cwd()); + expandLeadingTag(s, '<', '>'); + break; + } + case '~': + { + expandLeadingTilde(s); + break; } - } - else if (s[0] == '<') - { - expandLeadingTag(s, '<', '>'); - } - else if (s[0] == '~') - { - expandLeadingTilde(s); } } diff --git a/src/finiteArea/fields/faPatchFields/derived/timeVaryingUniformFixedValue/timeVaryingUniformFixedValueFaPatchField.H b/src/finiteArea/fields/faPatchFields/derived/timeVaryingUniformFixedValue/timeVaryingUniformFixedValueFaPatchField.H index 91f23917b8..c381989c51 100644 --- a/src/finiteArea/fields/faPatchFields/derived/timeVaryingUniformFixedValue/timeVaryingUniformFixedValueFaPatchField.H +++ b/src/finiteArea/fields/faPatchFields/derived/timeVaryingUniformFixedValue/timeVaryingUniformFixedValueFaPatchField.H @@ -35,7 +35,7 @@ Description inlet { type timeVaryingUniformFixedValue; - fileName "$FOAM_CASE/time-series"; + fileName "/time-series"; outOfBounds clamp; // (error|warn|clamp|repeat) } \endverbatim diff --git a/src/finiteVolume/cfdTools/general/coupling/externalFileCoupler.H b/src/finiteVolume/cfdTools/general/coupling/externalFileCoupler.H index 6a4dfc303b..79aaaeb859 100644 --- a/src/finiteVolume/cfdTools/general/coupling/externalFileCoupler.H +++ b/src/finiteVolume/cfdTools/general/coupling/externalFileCoupler.H @@ -50,7 +50,7 @@ Description \verbatim communication { - commsDir "${FOAM_CASE}/comms"; + commsDir "/comms"; waitInterval 1; timeOut 100; initByExternal no; diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.H index de5f8f197a..ab6c69e8df 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchField.H @@ -80,7 +80,7 @@ Usage componentColumns 1(1); separator ","; mergeSeparators no; - file "$FOAM_CASE/constant/pressureVsU"; + file "/pressureVsU"; } value uniform 0; } diff --git a/src/functionObjects/field/externalCoupled/externalCoupled.H b/src/functionObjects/field/externalCoupled/externalCoupled.H index 1d8a0834f3..6a1a566d34 100644 --- a/src/functionObjects/field/externalCoupled/externalCoupled.H +++ b/src/functionObjects/field/externalCoupled/externalCoupled.H @@ -86,7 +86,7 @@ Usage type externalCoupled; ... log yes; - commsDir "${FOAM_CASE}/comms"; + commsDir "/comms"; initByExternal yes; stateEnd remove; // (remove | done) diff --git a/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.H b/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.H index e6fbedcc82..18db47c80a 100644 --- a/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.H +++ b/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.H @@ -40,13 +40,13 @@ Usage libs ("libutilityFunctionObjects.so"); writeControl timeStep; writeInterval 1; - fileToUpdate "$FOAM_CASE/system/fvSolution"; + fileToUpdate "/fvSolution"; timeVsFile ( - (-1 "$FOAM_CASE/system/fvSolution.0") - (0.10 "$FOAM_CASE/system/fvSolution.10") - (0.20 "$FOAM_CASE/system/fvSolution.20") - (0.35 "$FOAM_CASE/system/fvSolution.35") + (-1 "/fvSolution.0") + (0.10 "/fvSolution.10") + (0.20 "/fvSolution.20") + (0.35 "/fvSolution.35") ); ... } diff --git a/tutorials/multiphase/interFoam/RAS/waterChannel/system/extrudeMeshDict b/tutorials/multiphase/interFoam/RAS/waterChannel/system/extrudeMeshDict index 162864464b..ba4b9d1e8d 100644 --- a/tutorials/multiphase/interFoam/RAS/waterChannel/system/extrudeMeshDict +++ b/tutorials/multiphase/interFoam/RAS/waterChannel/system/extrudeMeshDict @@ -14,13 +14,13 @@ FoamFile } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -constructFrom mesh; -sourceCase "$FOAM_CASE"; -sourcePatches (outlet); +constructFrom mesh; +sourceCase ""; +sourcePatches (outlet); -flipNormals false; +flipNormals false; -extrudeModel linearDirection; +extrudeModel linearDirection; nLayers 40; expansionRatio 1.0; @@ -32,6 +32,6 @@ linearDirectionCoeffs thickness 40; } -mergeFaces false; +mergeFaces false; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/tutorials/multiphase/interFoam/RAS/waterChannel/system/extrudeMeshDict.1 b/tutorials/multiphase/interFoam/RAS/waterChannel/system/extrudeMeshDict.1 index ce065d0b9d..d6d01112e2 100644 --- a/tutorials/multiphase/interFoam/RAS/waterChannel/system/extrudeMeshDict.1 +++ b/tutorials/multiphase/interFoam/RAS/waterChannel/system/extrudeMeshDict.1 @@ -14,13 +14,13 @@ FoamFile } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -constructFrom mesh; -sourceCase "$FOAM_CASE"; -sourcePatches (outlet); +constructFrom mesh; +sourceCase ""; +sourcePatches (outlet); -flipNormals false; +flipNormals false; -extrudeModel linearDirection; +extrudeModel linearDirection; nLayers 60; expansionRatio 1.0; @@ -32,6 +32,6 @@ linearDirectionCoeffs thickness 60; } -mergeFaces false; +mergeFaces false; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/tutorials/multiphase/interFoam/RAS/waterChannel/system/extrudeMeshDict.2 b/tutorials/multiphase/interFoam/RAS/waterChannel/system/extrudeMeshDict.2 index 162864464b..ba4b9d1e8d 100644 --- a/tutorials/multiphase/interFoam/RAS/waterChannel/system/extrudeMeshDict.2 +++ b/tutorials/multiphase/interFoam/RAS/waterChannel/system/extrudeMeshDict.2 @@ -14,13 +14,13 @@ FoamFile } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -constructFrom mesh; -sourceCase "$FOAM_CASE"; -sourcePatches (outlet); +constructFrom mesh; +sourceCase ""; +sourcePatches (outlet); -flipNormals false; +flipNormals false; -extrudeModel linearDirection; +extrudeModel linearDirection; nLayers 40; expansionRatio 1.0; @@ -32,6 +32,6 @@ linearDirectionCoeffs thickness 40; } -mergeFaces false; +mergeFaces false; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //