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
This commit is contained in:
Mark Olesen
2018-04-11 23:10:49 +02:00
parent fc5895f1df
commit 5f88e4271e
15 changed files with 93 additions and 67 deletions

View File

@ -72,26 +72,28 @@ int main(int argc, char *argv[])
const auto& cstr
:
{
"~OpenFOAM/controlDict",
"<etc>/controlDict",
"~OpenFOAM/controlDict", "<etc>/controlDict",
"$FOAM_CASE/xyz", "<case>/xyz",
"$FOAM_CASE/constant/xyz", "<constant>/xyz",
"$FOAM_CASE/system/xyz", "<system>/xyz",
"$FOAM_CASE/test",
"<case>/test",
// corner cases
"~OpenFOAM", "<etc>",
"~OpenFOAM/", "<etc>/",
"$FOAM_CASE", "<case>",
"$FOAM_CASE/constant", "<constant>",
"$FOAM_CASE/system", "<system>",
"$FOAM_CASE/constant/test",
"<case>/constant/test",
"<constant>/test",
"$FOAM_CASE/system/test",
"<case>/system/test",
"<system>/test",
"$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;
}
}

View File

@ -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";
}

View File

@ -150,7 +150,7 @@ void createFieldFiles
field.add
(
"#include",
"${FOAM_CASE}/system" + regionPath + "caseProperties"
"$FOAM_CASE/system" + regionPath + "caseProperties"
);
field.add("dimensions", fieldDimensions[i]);

View File

@ -74,7 +74,7 @@ addLayersControls
meshQualityControls
{
#include "${FOAM_CASE}/system/meshQualityDict"
#include "<system>/meshQualityDict"
}
debug 0;

View File

@ -15,7 +15,7 @@ FoamFile
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
constructFrom patch;
sourceCase "$FOAM_CASE";
sourceCase "<case>";
sourcePatches (front);
exposedPatchName back;
@ -30,6 +30,7 @@ sectorCoeffs
}
flipNormals false;
mergeFaces false;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -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

View File

@ -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,7 +136,10 @@ static void expandLeading(std::string& s)
{
return;
}
else if (s[0] == '.')
switch (s[0])
{
case '.':
{
// Expand a lone '.' and an initial './' into cwd
if (s.size() == 1)
@ -131,14 +150,18 @@ static void expandLeading(std::string& s)
{
s.std::string::replace(0, 1, cwd());
}
break;
}
else if (s[0] == '<')
case '<':
{
expandLeadingTag(s, '<', '>');
break;
}
else if (s[0] == '~')
case '~':
{
expandLeadingTilde(s);
break;
}
}
}

View File

@ -35,7 +35,7 @@ Description
inlet
{
type timeVaryingUniformFixedValue;
fileName "$FOAM_CASE/time-series";
fileName "<case>/time-series";
outOfBounds clamp; // (error|warn|clamp|repeat)
}
\endverbatim

View File

@ -50,7 +50,7 @@ Description
\verbatim
communication
{
commsDir "${FOAM_CASE}/comms";
commsDir "<case>/comms";
waitInterval 1;
timeOut 100;
initByExternal no;

View File

@ -80,7 +80,7 @@ Usage
componentColumns 1(1);
separator ",";
mergeSeparators no;
file "$FOAM_CASE/constant/pressureVsU";
file "<constant>/pressureVsU";
}
value uniform 0;
}

View File

@ -86,7 +86,7 @@ Usage
type externalCoupled;
...
log yes;
commsDir "${FOAM_CASE}/comms";
commsDir "<case>/comms";
initByExternal yes;
stateEnd remove; // (remove | done)

View File

@ -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")
);
...
}

View File

@ -15,7 +15,7 @@ FoamFile
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
constructFrom mesh;
sourceCase "$FOAM_CASE";
sourceCase "<case>";
sourcePatches (outlet);
flipNormals false;

View File

@ -15,7 +15,7 @@ FoamFile
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
constructFrom mesh;
sourceCase "$FOAM_CASE";
sourceCase "<case>";
sourcePatches (outlet);
flipNormals false;

View File

@ -15,7 +15,7 @@ FoamFile
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
constructFrom mesh;
sourceCase "$FOAM_CASE";
sourceCase "<case>";
sourcePatches (outlet);
flipNormals false;