Skip to content
Snippets Groups Projects
Commit d03b9125 authored by Mark Olesen's avatar Mark Olesen
Browse files

Improved string expansion handling.

* delay fileName expansion in timeVarying BCs, add the possibility to use
relative directories
* export FOAM_ROOT from argList: "." and ".." for serial/parallel. This
allows us to specify a single movable location regardless of serial/parallel.
* only replace an isolated leading "./" with CWD, strip others. This
improves use for a relative names.
parent bbc69a46
Branches
Tags
No related merge requests found
......@@ -533,6 +533,16 @@ Foam::argList::argList
// Set the case as an environment variable
setEnv("FOAM_CASE", rootPath_/globalCase_, true);
// Set the relative parent directory as an environment variable
if (parRunControl_.parRun())
{
setEnv("FOAM_ROOT", "..", true);
}
else
{
setEnv("FOAM_ROOT", ".", true);
}
// Switch on signal trapping. We have to wait until after Pstream::init
// since this sets up its own ones.
sigFpe_.set();
......
......@@ -177,15 +177,7 @@ Foam::string& Foam::string::expand()
if (size())
{
// Expand initial '.' and './' into cwd
if (operator[](0) == '.')
{
if (size() == 1 || (size() > 1 && operator[](1) == '/'))
{
std::string::replace(0, 1, cwd());
}
}
else if (operator[](0) == '~')
if (operator[](0) == '~')
{
// Expand initial ~
// ~/ => home directory
......@@ -217,6 +209,34 @@ Foam::string& Foam::string::expand()
*this = home(user)/file;
}
}
else
{
// expand a lone initial '.' and './' into CWD
// otherwise strip leading './' sequences
while
(
operator[](0) == '.'
&& (size() == 1 || operator[](1) == '/')
)
{
// handle leading ".////" as well
size_type slashPos = 1;
while (size() > slashPos && operator[](slashPos) == '/')
{
++slashPos;
}
if (size() <= slashPos)
{
*this = cwd();
break;
}
else
{
std::string::erase(0, slashPos);
}
}
}
}
return *this;
......
......@@ -72,7 +72,7 @@ timeVaryingMassFlowRateInletVelocityFvPatchVectorField
)
:
massFlowRateInletVelocityFvPatchVectorField(p, iF, dict),
timeDataFile_(fileName(dict.lookup("timeDataFile")).expand()),
timeDataFile_(dict.lookup("timeDataFile")),
timeSeries_(word(dict.lookup("timeBounding")))
{}
......@@ -112,7 +112,10 @@ currentValue()
{
if (timeSeries_.size() == 0)
{
if (timeDataFile_.size() == 0)
fileName fName(timeDataFile_);
fName.expand();
if (fName.size() == 0)
{
FatalErrorIn
(
......@@ -124,10 +127,16 @@ currentValue()
}
else
{
// relative path
if (fName[0] != '/')
{
fName = this->db().path()/fName;
}
// just in case we change the interface to timeSeries
word boundType = timeBounding();
IFstream(timeDataFile_)() >> timeSeries_;
IFstream(fName)() >> timeSeries_;
timeSeries_.bounding(boundType);
// be a bit paranoid and check that the list is okay
......
......@@ -73,7 +73,7 @@ timeVaryingUniformFixedValueFvPatchField
)
:
fixedValueFvPatchField<Type>(p, iF),
timeDataFile_(fileName(dict.lookup("timeDataFile")).expand()),
timeDataFile_(dict.lookup("timeDataFile")),
timeSeries_(word(dict.lookup("timeBounding")))
{
if (dict.found("value"))
......@@ -125,7 +125,10 @@ currentValue()
{
if (timeSeries_.size() == 0)
{
if (timeDataFile_.size() == 0)
fileName fName(timeDataFile_);
fName.expand();
if (fName.size() == 0)
{
FatalErrorIn
(
......@@ -137,10 +140,16 @@ currentValue()
}
else
{
// relative path
if (fName[0] != '/')
{
fName = this->db().path()/fName;
}
// just in case we change the interface to timeSeries
word boundType = timeBounding();
IFstream(timeDataFile_)() >> timeSeries_;
IFstream(fName)() >> timeSeries_;
timeSeries_.bounding(boundType);
// be a bit paranoid and check that the list is okay
......
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