Commit 5f88e427 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: allow "<case>", "<system>" ... in the string expansions (issue #792)

- the expansions were previously required as slash to follow, but
  now either are possible.

    "<case>", "<case>/" 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
parent fc5895f1
......@@ -72,26 +72,28 @@ int main(int argc, char *argv[])
const auto& cstr
:
{
"~OpenFOAM/controlDict",
"<etc>/controlDict",
"$FOAM_CASE/test",
"<case>/test",
"$FOAM_CASE/constant/test",
"<case>/constant/test",
"<constant>/test",
"$FOAM_CASE/system/test",
"<case>/system/test",
"<system>/test",
"~OpenFOAM/controlDict", "<etc>/controlDict",
"$FOAM_CASE/xyz", "<case>/xyz",
"$FOAM_CASE/constant/xyz", "<constant>/xyz",
"$FOAM_CASE/system/xyz", "<system>/xyz",
// corner cases
"~OpenFOAM", "<etc>",
"~OpenFOAM/", "<etc>/",
"$FOAM_CASE", "<case>",
"$FOAM_CASE/constant", "<constant>",
"$FOAM_CASE/system", "<system>",
"$FOAM_CASE/", "<case>/",
"$FOAM_CASE/constant/", "<constant>/",
"$FOAM_CASE/system/", "<system>/",
}
)
{
string input(cstr);
string output(stringOps::expand(input));
Info<<"input: " << input << nl
Info<< "input: " << input << nl
<< "expand: " << output << nl << nl;
}
}
......
......@@ -112,10 +112,10 @@ sigmaRadialCoeffs
offsetSurfaceCoeffs
{
// Surface that mesh has been meshed to
baseSurface "$FOAM_CASE/constant/triSurface/DTC-scaled-inflated.obj";
baseSurface "<constant>/triSurface/DTC-scaled-inflated.obj";
// Surface to fill in to
offsetSurface "$FOAM_CASE/constant/triSurface/DTC-scaled.obj";
offsetSurface "<constant>/triSurface/DTC-scaled.obj";
}
......
......@@ -150,7 +150,7 @@ void createFieldFiles
field.add
(
"#include",
"${FOAM_CASE}/system" + regionPath + "caseProperties"
"$FOAM_CASE/system" + regionPath + "caseProperties"
);
field.add("dimensions", fieldDimensions[i]);
......
......@@ -74,7 +74,7 @@ addLayersControls
meshQualityControls
{
#include "${FOAM_CASE}/system/meshQualityDict"
#include "<system>/meshQualityDict"
}
debug 0;
......
......@@ -14,13 +14,13 @@ FoamFile
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
constructFrom patch;
sourceCase "$FOAM_CASE";
constructFrom patch;
sourceCase "<case>";
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;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -42,7 +42,7 @@ Description
Read csv format:
\verbatim
readerType csv;
file "$FOAM_CASE/constant/p0vsTime.csv";
file "<constant>/p0vsTime.csv";
hasHeaderLine true; // skip first line
timeColumn 0; // time is in column 0
valueColumns (1); // value starts in column 1
......
......@@ -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 <tag>
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);
}
}
......
......@@ -35,7 +35,7 @@ Description
inlet
{
type timeVaryingUniformFixedValue;
fileName "$FOAM_CASE/time-series";
fileName "<case>/time-series";
outOfBounds clamp; // (error|warn|clamp|repeat)
}
\endverbatim
......
......@@ -50,7 +50,7 @@ Description
\verbatim
communication
{
commsDir "${FOAM_CASE}/comms";
commsDir "<case>/comms";
waitInterval 1;
timeOut 100;
initByExternal no;
......
......@@ -80,7 +80,7 @@ Usage
componentColumns 1(1);
separator ",";
mergeSeparators no;
file "$FOAM_CASE/constant/pressureVsU";
file "<constant>/pressureVsU";
}
value uniform 0;
}
......
......@@ -86,7 +86,7 @@ Usage
type externalCoupled;
...
log yes;
commsDir "${FOAM_CASE}/comms";
commsDir "<case>/comms";
initByExternal yes;
stateEnd remove; // (remove | done)
......
......@@ -40,13 +40,13 @@ Usage
libs ("libutilityFunctionObjects.so");
writeControl timeStep;
writeInterval 1;
fileToUpdate "$FOAM_CASE/system/fvSolution";
fileToUpdate "<system>/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 "<system>/fvSolution.0")
(0.10 "<system>/fvSolution.10")
(0.20 "<system>/fvSolution.20")
(0.35 "<system>/fvSolution.35")
);
...
}
......
......@@ -14,13 +14,13 @@ FoamFile
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
constructFrom mesh;
sourceCase "$FOAM_CASE";
sourcePatches (outlet);
constructFrom mesh;
sourceCase "<case>";
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;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -14,13 +14,13 @@ FoamFile
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
constructFrom mesh;
sourceCase "$FOAM_CASE";
sourcePatches (outlet);
constructFrom mesh;
sourceCase "<case>";
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;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -14,13 +14,13 @@ FoamFile
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
constructFrom mesh;
sourceCase "$FOAM_CASE";
sourcePatches (outlet);
constructFrom mesh;
sourceCase "<case>";
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;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment