mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: basics for expression string handling
This commit is contained in:
committed by
Andrew Heather
parent
42a9a6ae5a
commit
fae91edd85
@ -139,6 +139,15 @@ $(strings)/stringOps/toScalar/evalStringToScalarDriver.C
|
|||||||
$(strings)/stringOps/toScalar/evalStringToScalarLemonParser.lyy-m4
|
$(strings)/stringOps/toScalar/evalStringToScalarLemonParser.lyy-m4
|
||||||
$(strings)/stringOps/toScalar/evalStringToScalarScanner.cc
|
$(strings)/stringOps/toScalar/evalStringToScalarScanner.cc
|
||||||
|
|
||||||
|
expr = expressions
|
||||||
|
$(expr)/exprEntry/expressionEntry.C
|
||||||
|
$(expr)/exprEntry/expressionEntryBool.C
|
||||||
|
$(expr)/exprEntry/expressionEntryDimensioned.C
|
||||||
|
$(expr)/exprEntry/expressionEntryStrings.C
|
||||||
|
$(expr)/exprEntry/expressionEntryVectors.C
|
||||||
|
$(expr)/exprString/exprString.C
|
||||||
|
$(expr)/exprTools/exprTools.C
|
||||||
|
|
||||||
ops = primitives/ops
|
ops = primitives/ops
|
||||||
$(ops)/flipOp.C
|
$(ops)/flipOp.C
|
||||||
|
|
||||||
|
|||||||
378
src/OpenFOAM/expressions/exprEntry/expressionEntry.C
Normal file
378
src/OpenFOAM/expressions/exprEntry/expressionEntry.C
Normal file
@ -0,0 +1,378 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Original code Copyright (C) 2014-2018 Bernhard Gschaider
|
||||||
|
Copyright (C) 2019 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "expressionEntry.H"
|
||||||
|
#include "stringOps.H"
|
||||||
|
#include "runTimeSelectionTables.H"
|
||||||
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace exprTools
|
||||||
|
{
|
||||||
|
|
||||||
|
defineTypeName(expressionEntry);
|
||||||
|
defineRunTimeSelectionTable(expressionEntry, empty);
|
||||||
|
|
||||||
|
// Various types can be used directly without any changes
|
||||||
|
|
||||||
|
addNamedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
expressionEntry,
|
||||||
|
expressionEntry,
|
||||||
|
empty,
|
||||||
|
direct
|
||||||
|
);
|
||||||
|
|
||||||
|
addNamedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
expressionEntry,
|
||||||
|
expressionEntry,
|
||||||
|
empty,
|
||||||
|
label
|
||||||
|
);
|
||||||
|
|
||||||
|
addNamedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
expressionEntry,
|
||||||
|
expressionEntry,
|
||||||
|
empty,
|
||||||
|
scalar
|
||||||
|
);
|
||||||
|
|
||||||
|
addNamedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
expressionEntry,
|
||||||
|
expressionEntry,
|
||||||
|
empty,
|
||||||
|
word
|
||||||
|
);
|
||||||
|
|
||||||
|
} // End namespace exprTools
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
// Same code as in stringOps.C
|
||||||
|
|
||||||
|
// Acceptable values for $variable names.
|
||||||
|
//
|
||||||
|
// Similar to word::valid(), except we don't have the benefit of a parser
|
||||||
|
// to filter out other unacceptable entries for us.
|
||||||
|
//
|
||||||
|
// Does not currently accept '/' in a variable name.
|
||||||
|
// We would like "$file/$name" to expand as two variables.
|
||||||
|
static inline bool validVariableChar(char c)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
(
|
||||||
|
std::isalnum(c)
|
||||||
|
|| c == '.'
|
||||||
|
|| c == ':'
|
||||||
|
|| c == '_'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// For input string of "$variable with other" return the length of
|
||||||
|
// the variable.
|
||||||
|
//
|
||||||
|
// Intentionally will not capture ':+', ':-' alterations. Use ${ .. } for that
|
||||||
|
static inline std::string::size_type findVariableLen
|
||||||
|
(
|
||||||
|
const std::string& s,
|
||||||
|
std::string::size_type pos,
|
||||||
|
const char sigil = '$'
|
||||||
|
)
|
||||||
|
{
|
||||||
|
std::string::size_type len = 0;
|
||||||
|
|
||||||
|
if (pos < s.length())
|
||||||
|
{
|
||||||
|
if (s[pos] == sigil)
|
||||||
|
{
|
||||||
|
// Skip leading '$' in the count!
|
||||||
|
++pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
for
|
||||||
|
(
|
||||||
|
auto iter = s.cbegin() + pos;
|
||||||
|
iter != s.cend() && validVariableChar(*iter);
|
||||||
|
++iter
|
||||||
|
)
|
||||||
|
{
|
||||||
|
++len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // End anonymous namespace
|
||||||
|
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
|
inline static const entry* getVariableOrDie
|
||||||
|
(
|
||||||
|
const word& name,
|
||||||
|
const dictionary& dict
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const entry* eptr = dict.findScoped(name, keyType::LITERAL_RECURSIVE);
|
||||||
|
|
||||||
|
if (!eptr)
|
||||||
|
{
|
||||||
|
FatalIOErrorInFunction(dict)
|
||||||
|
<< "No dictionary entry " << name << nl
|
||||||
|
<< exit(FatalIOError);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eptr->isDict())
|
||||||
|
{
|
||||||
|
FatalIOErrorInFunction(dict)
|
||||||
|
<< "Found dictionary " << name << " instead of entry" << nl
|
||||||
|
<< exit(FatalIOError);
|
||||||
|
}
|
||||||
|
|
||||||
|
return eptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::autoPtr<Foam::exprTools::expressionEntry>
|
||||||
|
Foam::exprTools::expressionEntry::New
|
||||||
|
(
|
||||||
|
const word& name
|
||||||
|
)
|
||||||
|
{
|
||||||
|
auto cstrIter = emptyConstructorTablePtr_->cfind(name);
|
||||||
|
|
||||||
|
if (!cstrIter.found())
|
||||||
|
{
|
||||||
|
FatalErrorInLookup
|
||||||
|
(
|
||||||
|
"expressionEntry",
|
||||||
|
name,
|
||||||
|
*emptyConstructorTablePtr_
|
||||||
|
) << exit(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
return autoPtr<expressionEntry>(cstrIter()());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::expressions::exprString
|
||||||
|
Foam::exprTools::expressionEntry::expand
|
||||||
|
(
|
||||||
|
const std::string& orig,
|
||||||
|
const dictionary& dict
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// This is much like stringOps::inplaceExpand
|
||||||
|
constexpr const char sigil = '$';
|
||||||
|
|
||||||
|
// Copy to a exprString, without any validation (using assign)
|
||||||
|
expressions::exprString s;
|
||||||
|
s.assign(orig);
|
||||||
|
|
||||||
|
std::string::size_type varBeg = 0;
|
||||||
|
|
||||||
|
while
|
||||||
|
(
|
||||||
|
(varBeg = s.find(sigil, varBeg)) != std::string::npos
|
||||||
|
// && varBeg < s.size()-1
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// No handling of escape characters
|
||||||
|
|
||||||
|
if (varBeg == s.size()-1)
|
||||||
|
{
|
||||||
|
// Die if we ended with a '$'
|
||||||
|
FatalErrorInFunction
|
||||||
|
<< "'" << sigil << "' found at end of " << s
|
||||||
|
<< "(originally " << orig << ')' << nl
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string::size_type varEnd = varBeg;
|
||||||
|
std::string::size_type delim = 0;
|
||||||
|
|
||||||
|
word castTo, varName;
|
||||||
|
|
||||||
|
if (s[varBeg+1] == '[')
|
||||||
|
{
|
||||||
|
// An expression pattern with $[...]
|
||||||
|
|
||||||
|
varEnd = s.find(']', varBeg);
|
||||||
|
delim = 1;
|
||||||
|
|
||||||
|
if (varEnd == std::string::npos)
|
||||||
|
{
|
||||||
|
FatalErrorInFunction
|
||||||
|
<< "No correct terminating ']' found in " << s
|
||||||
|
<< " (originally " << orig << ")" << nl
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look for embedded (type) cast
|
||||||
|
|
||||||
|
const auto lparen = varBeg+2;
|
||||||
|
if (lparen < s.size() && s[lparen] == '(')
|
||||||
|
{
|
||||||
|
const auto rparen = s.find(')', lparen);
|
||||||
|
|
||||||
|
if (rparen > varEnd)
|
||||||
|
{
|
||||||
|
// Handles both "$[( ...]" and "$[( ...])" cases
|
||||||
|
|
||||||
|
auto& err = FatalErrorInFunction;
|
||||||
|
|
||||||
|
if (rparen == std::string::npos)
|
||||||
|
{
|
||||||
|
err << "No closing ')' found in ";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
err << "Closing ')' found outside of";
|
||||||
|
}
|
||||||
|
|
||||||
|
err << " substring "
|
||||||
|
<< s.substr(varBeg, varEnd-varBeg)
|
||||||
|
<< " (" << orig << ')' << nl
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
castTo.assign(s.substr(lparen+1, rparen - lparen - 1));
|
||||||
|
varName.assign(s.substr(rparen+1, varEnd - rparen - 1));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
varName.assign
|
||||||
|
(
|
||||||
|
s.substr(varBeg + 1 + delim, varEnd - varBeg - 2*delim)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
stringOps::inplaceTrim(varName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (s[varBeg+1] == '{')
|
||||||
|
{
|
||||||
|
varEnd = s.find('}', varBeg);
|
||||||
|
delim = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Handling regular $var construct
|
||||||
|
varEnd += findVariableLen(s, varBeg, sigil);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (varEnd == std::string::npos)
|
||||||
|
{
|
||||||
|
// Likely parsed '${...' without closing '}' - abort
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (varEnd == varBeg)
|
||||||
|
{
|
||||||
|
// Parsed '${}' or $badChar - skip over or die?
|
||||||
|
FatalErrorInFunction
|
||||||
|
<< "No valid character after the $ in " << s
|
||||||
|
<< "(originally " << orig << ")" << endl
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Assign - assumed to be validated with findVariableLen()
|
||||||
|
varName.assign
|
||||||
|
(
|
||||||
|
s.substr(varBeg + 1 + delim, varEnd - varBeg - 2*delim)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Length of original text to replace (incl. decorators)
|
||||||
|
const auto replaceLen = (varEnd - varBeg + 1);
|
||||||
|
|
||||||
|
const entry* eptr = getVariableOrDie(varName, dict);
|
||||||
|
|
||||||
|
std::string varValue;
|
||||||
|
|
||||||
|
if (castTo.empty())
|
||||||
|
{
|
||||||
|
// Serialized with spaces
|
||||||
|
varValue = eptr->stream().toString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
varValue = expressionEntry::New(castTo)->toExpr(*eptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
s.std::string::replace(varBeg, replaceLen, varValue);
|
||||||
|
varBeg += varValue.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::expressions::exprString
|
||||||
|
Foam::exprTools::expressionEntry::getExpression
|
||||||
|
(
|
||||||
|
const word& name,
|
||||||
|
const dictionary& dict,
|
||||||
|
const bool removeComments
|
||||||
|
)
|
||||||
|
{
|
||||||
|
string str(dict.get<string>(name));
|
||||||
|
|
||||||
|
if (removeComments)
|
||||||
|
{
|
||||||
|
stringOps::inplaceRemoveComments(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
return expand(str, dict);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
177
src/OpenFOAM/expressions/exprEntry/expressionEntry.H
Normal file
177
src/OpenFOAM/expressions/exprEntry/expressionEntry.H
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Original code Copyright (C) 2014-2018 Bernhard Gschaider
|
||||||
|
Copyright (C) 2019 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::exprTools::expressionEntry
|
||||||
|
|
||||||
|
Description
|
||||||
|
Convert dictionary entry to a stringified expression.
|
||||||
|
|
||||||
|
The general OpenFOAM dictionary expansions will result in
|
||||||
|
space-separated values. For example,
|
||||||
|
|
||||||
|
\verbatim
|
||||||
|
origin (0.21 0 0.01);
|
||||||
|
|
||||||
|
condition "mag(pos() - $centre) < 0.5";
|
||||||
|
\endverbatim
|
||||||
|
|
||||||
|
this will expand to the following:
|
||||||
|
|
||||||
|
\verbatim
|
||||||
|
condition "mag(pos() - (0.21 0 0.01)) < 0.5";
|
||||||
|
\endverbatim
|
||||||
|
|
||||||
|
For these type of expressions, we'd would like better control.
|
||||||
|
Using instead the special expansions, we can add an effective
|
||||||
|
type cast.
|
||||||
|
|
||||||
|
\verbatim
|
||||||
|
condition "mag(pos() - $[(vector)centre]) < 0.5";
|
||||||
|
\endverbatim
|
||||||
|
|
||||||
|
which will expand to the following:
|
||||||
|
|
||||||
|
\verbatim
|
||||||
|
condition "mag(pos() - vector(0.21,0,0.01)) < 0.5";
|
||||||
|
\endverbatim
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
expressionEntry.C
|
||||||
|
expressionEntryI.H
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef exprTools_expressionEntry_H
|
||||||
|
#define exprTools_expressionEntry_H
|
||||||
|
|
||||||
|
#include "exprString.H"
|
||||||
|
#include "primitiveEntry.H"
|
||||||
|
#include "runTimeSelectionTables.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace exprTools
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class expressionEntry Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class expressionEntry
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
//- Stringified version of data with comma-separated components.
|
||||||
|
//- Uses prefix corresponding to the pTraits of Type.
|
||||||
|
template<class Type>
|
||||||
|
static string toExprStr(const Type& data);
|
||||||
|
|
||||||
|
//- Comma-separated stringified version of primitiveEntry of Type.
|
||||||
|
//- Prefix corresponding to the pTraits of Type
|
||||||
|
template<class Type>
|
||||||
|
static string toExprStr(ITstream& is);
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//- Runtime type information
|
||||||
|
TypeNameNoDebug("expressionEntry");
|
||||||
|
|
||||||
|
declareRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
autoPtr,
|
||||||
|
expressionEntry,
|
||||||
|
empty,
|
||||||
|
(),
|
||||||
|
()
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct null
|
||||||
|
expressionEntry() = default;
|
||||||
|
|
||||||
|
|
||||||
|
// Selectors
|
||||||
|
|
||||||
|
//- Return an entry to expression converter
|
||||||
|
static autoPtr<expressionEntry> New(const word& name);
|
||||||
|
|
||||||
|
|
||||||
|
//- Destructor
|
||||||
|
virtual ~expressionEntry() = default;
|
||||||
|
|
||||||
|
|
||||||
|
// Static Member Functions
|
||||||
|
|
||||||
|
//- Generic concatenate tokens to space-separated string.
|
||||||
|
inline static string evaluate(const entry& e);
|
||||||
|
|
||||||
|
//- Expand expression with dictionary entries
|
||||||
|
static expressions::exprString expand
|
||||||
|
(
|
||||||
|
const std::string& str,
|
||||||
|
const dictionary& dict
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Get and expand expression with dictionary entries
|
||||||
|
// Optionally strip C/C++ comments from the input
|
||||||
|
static expressions::exprString getExpression
|
||||||
|
(
|
||||||
|
const word& name,
|
||||||
|
const dictionary& dict,
|
||||||
|
const bool removeComments = false
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- To string. Normally with comma separators.
|
||||||
|
virtual string toExpr(const entry& e) const
|
||||||
|
{
|
||||||
|
return evaluate(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace exprTools
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#include "expressionEntryI.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
59
src/OpenFOAM/expressions/exprEntry/expressionEntryBool.C
Normal file
59
src/OpenFOAM/expressions/exprEntry/expressionEntryBool.C
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2019 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "expressionEntryBool.H"
|
||||||
|
#include "Switch.H"
|
||||||
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace exprTools
|
||||||
|
{
|
||||||
|
|
||||||
|
addNamedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
expressionEntry,
|
||||||
|
boolEntry,
|
||||||
|
empty,
|
||||||
|
bool
|
||||||
|
);
|
||||||
|
|
||||||
|
} // End namespace exprTools
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::string Foam::exprTools::boolEntry::evaluate(const entry& e)
|
||||||
|
{
|
||||||
|
return Switch::name(e.get<bool>());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
77
src/OpenFOAM/expressions/exprEntry/expressionEntryBool.H
Normal file
77
src/OpenFOAM/expressions/exprEntry/expressionEntryBool.H
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2019 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::exprTools::boolEntry
|
||||||
|
|
||||||
|
Description
|
||||||
|
Expression representation of a bool : (false/true)
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
expressionEntryBool.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef exprTools_expressionEntryBool_H
|
||||||
|
#define exprTools_expressionEntryBool_H
|
||||||
|
|
||||||
|
#include "expressionEntry.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace exprTools
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class boolEntry Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
struct boolEntry
|
||||||
|
:
|
||||||
|
public exprTools::expressionEntry
|
||||||
|
{
|
||||||
|
//- To string
|
||||||
|
static string evaluate(const entry& e);
|
||||||
|
|
||||||
|
//- To string
|
||||||
|
virtual string toExpr(const entry& e) const
|
||||||
|
{
|
||||||
|
return evaluate(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace exprTools
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
114
src/OpenFOAM/expressions/exprEntry/expressionEntryDimensioned.C
Normal file
114
src/OpenFOAM/expressions/exprEntry/expressionEntryDimensioned.C
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Original code Copyright (C) 2014-2018 Bernhard Gschaider
|
||||||
|
Copyright (C) 2019 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "expressionEntryDimensioned.H"
|
||||||
|
#include "primitiveEntry.H"
|
||||||
|
#include "dimensionedScalar.H"
|
||||||
|
#include "dimensionedVector.H"
|
||||||
|
#include "dimensionedTensor.H"
|
||||||
|
#include "dimensionedSymmTensor.H"
|
||||||
|
#include "dimensionedSphericalTensor.H"
|
||||||
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace exprTools
|
||||||
|
{
|
||||||
|
|
||||||
|
addNamedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
expressionEntry,
|
||||||
|
dimensionedScalarEntry,
|
||||||
|
empty,
|
||||||
|
dimensionedScalar
|
||||||
|
);
|
||||||
|
|
||||||
|
addNamedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
expressionEntry,
|
||||||
|
dimensionedVectorEntry,
|
||||||
|
empty,
|
||||||
|
dimensionedVector
|
||||||
|
);
|
||||||
|
|
||||||
|
addNamedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
expressionEntry,
|
||||||
|
dimensionedTensorEntry,
|
||||||
|
empty,
|
||||||
|
dimensionedTensor
|
||||||
|
);
|
||||||
|
|
||||||
|
addNamedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
expressionEntry,
|
||||||
|
dimensionedSymmTensorEntry,
|
||||||
|
empty,
|
||||||
|
dimensionedSymmTensor
|
||||||
|
);
|
||||||
|
|
||||||
|
addNamedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
expressionEntry,
|
||||||
|
dimensionedSphericalTensorEntry,
|
||||||
|
empty,
|
||||||
|
dimensionedSphericalTensor
|
||||||
|
);
|
||||||
|
|
||||||
|
} // End namespace exprTools
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#undef defineExpressionEntryType
|
||||||
|
#define defineExpressionEntryType(DimType) \
|
||||||
|
Foam::string Foam::exprTools::DimType##Entry::evaluate(const entry& e) \
|
||||||
|
{ \
|
||||||
|
DimType dt(dynamicCast<const primitiveEntry&>(e)); \
|
||||||
|
return toExprStr<DimType::value_type>(dt.value()); \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::string Foam::exprTools::dimensionedScalarEntry::evaluate(const entry& e)
|
||||||
|
{
|
||||||
|
dimensionedScalar dt(dynamicCast<const primitiveEntry&>(e));
|
||||||
|
return std::to_string(dt.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
defineExpressionEntryType(dimensionedVector);
|
||||||
|
defineExpressionEntryType(dimensionedTensor);
|
||||||
|
defineExpressionEntryType(dimensionedSymmTensor);
|
||||||
|
defineExpressionEntryType(dimensionedSphericalTensor);
|
||||||
|
|
||||||
|
#undef defineExpressionEntryType
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -0,0 +1,80 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Original code Copyright (C) 2014-2018 Bernhard Gschaider
|
||||||
|
Copyright (C) 2019 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Description
|
||||||
|
Creates an expression string from various standard dimensioned types.
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
expressionEntryDimensioned.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef exprTools_expressionEntryDimensioned_H
|
||||||
|
#define exprTools_expressionEntryDimensioned_H
|
||||||
|
|
||||||
|
#include "expressionEntry.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace exprTools
|
||||||
|
{
|
||||||
|
|
||||||
|
#undef declareExpressionEntryType
|
||||||
|
#define declareExpressionEntryType(DimType) \
|
||||||
|
/*! \brief Create an expression string from a DimType as its value */ \
|
||||||
|
struct DimType##Entry : public exprTools::expressionEntry \
|
||||||
|
{ \
|
||||||
|
/*! To string */ \
|
||||||
|
static string evaluate(const entry& e); \
|
||||||
|
\
|
||||||
|
/*! To string */ \
|
||||||
|
virtual string toExpr(const entry& e) const \
|
||||||
|
{ \
|
||||||
|
return evaluate(e); \
|
||||||
|
} \
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
declareExpressionEntryType(dimensionedScalar);
|
||||||
|
declareExpressionEntryType(dimensionedVector);
|
||||||
|
declareExpressionEntryType(dimensionedTensor);
|
||||||
|
declareExpressionEntryType(dimensionedSymmTensor);
|
||||||
|
declareExpressionEntryType(dimensionedSphericalTensor);
|
||||||
|
|
||||||
|
#undef declareExpressionEntryType
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace exprTools
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
69
src/OpenFOAM/expressions/exprEntry/expressionEntryI.H
Normal file
69
src/OpenFOAM/expressions/exprEntry/expressionEntryI.H
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Original code Copyright (C) 2014-2018 Bernhard Gschaider
|
||||||
|
Copyright (C) 2019 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "OStringStream.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline Foam::string
|
||||||
|
Foam::exprTools::expressionEntry::evaluate(const entry& e)
|
||||||
|
{
|
||||||
|
return e.stream().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
inline Foam::string
|
||||||
|
Foam::exprTools::expressionEntry::toExprStr(const Type& data)
|
||||||
|
{
|
||||||
|
OStringStream buf;
|
||||||
|
|
||||||
|
buf << pTraits<Type>::typeName << '(';
|
||||||
|
for (direction cmpt=0; cmpt < pTraits<Type>::nComponents; ++cmpt)
|
||||||
|
{
|
||||||
|
if (cmpt) buf << ',';
|
||||||
|
buf << component(data, cmpt);
|
||||||
|
}
|
||||||
|
buf << ')';
|
||||||
|
|
||||||
|
return buf.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
inline Foam::string
|
||||||
|
Foam::exprTools::expressionEntry::toExprStr(ITstream& is)
|
||||||
|
{
|
||||||
|
Type data(Zero);
|
||||||
|
is >> data;
|
||||||
|
|
||||||
|
return toExprStr<Type>(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
58
src/OpenFOAM/expressions/exprEntry/expressionEntryStrings.C
Normal file
58
src/OpenFOAM/expressions/exprEntry/expressionEntryStrings.C
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2019 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "expressionEntryStrings.H"
|
||||||
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace exprTools
|
||||||
|
{
|
||||||
|
|
||||||
|
addNamedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
expressionEntry,
|
||||||
|
stringEntry,
|
||||||
|
empty,
|
||||||
|
string
|
||||||
|
);
|
||||||
|
|
||||||
|
addNamedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
expressionEntry,
|
||||||
|
stringEntry,
|
||||||
|
empty,
|
||||||
|
fileName
|
||||||
|
);
|
||||||
|
|
||||||
|
} // End namespace exprTools
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
81
src/OpenFOAM/expressions/exprEntry/expressionEntryStrings.H
Normal file
81
src/OpenFOAM/expressions/exprEntry/expressionEntryStrings.H
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Original code Copyright (C) 2014-2018 Bernhard Gschaider
|
||||||
|
Copyright (C) 2019 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::exprTools::stringEntry
|
||||||
|
|
||||||
|
Description
|
||||||
|
Creates an expression from a string (removing surrounding quotes)
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
expressionEntryStrings.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef exprTools_expressionEntryStrings_H
|
||||||
|
#define exprTools_expressionEntryStrings_H
|
||||||
|
|
||||||
|
#include "expressionEntry.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace exprTools
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class stringEntry Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
struct stringEntry
|
||||||
|
:
|
||||||
|
public exprTools::expressionEntry
|
||||||
|
{
|
||||||
|
//- To string
|
||||||
|
static string evaluate(const entry& e)
|
||||||
|
{
|
||||||
|
return e.get<string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- To string
|
||||||
|
virtual string toExpr(const entry& e) const
|
||||||
|
{
|
||||||
|
return evaluate(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace exprTools
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
95
src/OpenFOAM/expressions/exprEntry/expressionEntryVectors.C
Normal file
95
src/OpenFOAM/expressions/exprEntry/expressionEntryVectors.C
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2019 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "vector.H"
|
||||||
|
#include "tensor.H"
|
||||||
|
#include "symmTensor.H"
|
||||||
|
#include "sphericalTensor.H"
|
||||||
|
#include "expressionEntryVectors.H"
|
||||||
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace exprTools
|
||||||
|
{
|
||||||
|
|
||||||
|
addNamedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
expressionEntry,
|
||||||
|
vectorEntry,
|
||||||
|
empty,
|
||||||
|
vector
|
||||||
|
);
|
||||||
|
|
||||||
|
addNamedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
expressionEntry,
|
||||||
|
tensorEntry,
|
||||||
|
empty,
|
||||||
|
tensor
|
||||||
|
);
|
||||||
|
|
||||||
|
addNamedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
expressionEntry,
|
||||||
|
symmTensorEntry,
|
||||||
|
empty,
|
||||||
|
symmTensor
|
||||||
|
);
|
||||||
|
|
||||||
|
addNamedToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
expressionEntry,
|
||||||
|
sphericalTensorEntry,
|
||||||
|
empty,
|
||||||
|
sphericalTensor
|
||||||
|
);
|
||||||
|
|
||||||
|
} // End namespace exprTools
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#undef defineExpressionEntryType
|
||||||
|
#define defineExpressionEntryType(Type) \
|
||||||
|
Foam::string Foam::exprTools::Type##Entry::evaluate(const entry& e) \
|
||||||
|
{ \
|
||||||
|
return toExprStr<Type>(e.stream()); \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
defineExpressionEntryType(vector);
|
||||||
|
defineExpressionEntryType(tensor);
|
||||||
|
defineExpressionEntryType(symmTensor);
|
||||||
|
defineExpressionEntryType(sphericalTensor);
|
||||||
|
|
||||||
|
#undef defineExpressionEntryType
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
79
src/OpenFOAM/expressions/exprEntry/expressionEntryVectors.H
Normal file
79
src/OpenFOAM/expressions/exprEntry/expressionEntryVectors.H
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Original code Copyright (C) 2014-2018 Bernhard Gschaider
|
||||||
|
Copyright (C) 2019 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Description
|
||||||
|
Creates an expression string from common VectorSpace types
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
expressionEntryVectors.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef exprTools_expressionEntryVectors_H
|
||||||
|
#define exprTools_expressionEntryVectors_H
|
||||||
|
|
||||||
|
#include "expressionEntry.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace exprTools
|
||||||
|
{
|
||||||
|
|
||||||
|
#undef declareExpressionEntryType
|
||||||
|
#define declareExpressionEntryType(Type) \
|
||||||
|
/*! \brief Create an expression string from a Type */ \
|
||||||
|
struct Type##Entry : public exprTools::expressionEntry \
|
||||||
|
{ \
|
||||||
|
/*! To string */ \
|
||||||
|
static string evaluate(const entry& e); \
|
||||||
|
\
|
||||||
|
/*! To string */ \
|
||||||
|
virtual string toExpr(const entry& e) const \
|
||||||
|
{ \
|
||||||
|
return evaluate(e); \
|
||||||
|
} \
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
declareExpressionEntryType(vector);
|
||||||
|
declareExpressionEntryType(tensor);
|
||||||
|
declareExpressionEntryType(symmTensor);
|
||||||
|
declareExpressionEntryType(sphericalTensor);
|
||||||
|
|
||||||
|
#undef declareExpressionEntryType
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace exprTools
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
62
src/OpenFOAM/expressions/exprString/exprString.C
Normal file
62
src/OpenFOAM/expressions/exprString/exprString.C
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2019 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "exprString.H"
|
||||||
|
#include "stringOps.H"
|
||||||
|
#include "expressionEntry.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::expressions::exprString&
|
||||||
|
Foam::expressions::exprString::expand
|
||||||
|
(
|
||||||
|
const dictionary& dict,
|
||||||
|
const bool removeComments
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (removeComments)
|
||||||
|
{
|
||||||
|
stringOps::inplaceRemoveComments(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not quite as efficient as it could be, but wish to have a copy
|
||||||
|
// of the original input for the sake of reporting errors
|
||||||
|
|
||||||
|
if (std::string::npos != find('$'))
|
||||||
|
{
|
||||||
|
(*this) = exprTools::expressionEntry::expand(*this, dict);
|
||||||
|
|
||||||
|
#ifdef FULLDEBUG
|
||||||
|
(void)valid();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
172
src/OpenFOAM/expressions/exprString/exprString.H
Normal file
172
src/OpenFOAM/expressions/exprString/exprString.H
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Original code Copyright (C) 2012-2018 Bernhard Gschaider
|
||||||
|
Copyright (C) 2019 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Namespace
|
||||||
|
Foam::expressions::exprString
|
||||||
|
|
||||||
|
Description
|
||||||
|
A variant of Foam::string with expansion of dictionary variables
|
||||||
|
into a comma-separated form.
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
exprString.C
|
||||||
|
exprStringI.H
|
||||||
|
|
||||||
|
SeeAlso
|
||||||
|
Foam::exprTools::expressionEntry
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef expressions_exprString_H
|
||||||
|
#define expressions_exprString_H
|
||||||
|
|
||||||
|
#include "string.H"
|
||||||
|
#include "dictionary.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace expressions
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class exprString Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class exprString
|
||||||
|
:
|
||||||
|
public string
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct null
|
||||||
|
exprString() = default;
|
||||||
|
|
||||||
|
//- Copy construct
|
||||||
|
exprString(const exprString& rhs) = default;
|
||||||
|
|
||||||
|
//- Move construct
|
||||||
|
exprString(exprString&& rhs) = default;
|
||||||
|
|
||||||
|
//- Copy construct from std::string
|
||||||
|
inline explicit exprString(const std::string& s, bool doValidate=true);
|
||||||
|
|
||||||
|
//- Move construct from std::string
|
||||||
|
inline explicit exprString(std::string&& s, bool doValidate=true);
|
||||||
|
|
||||||
|
//- Construct as copy of character array
|
||||||
|
inline explicit exprString(const char* s, bool doValidate=true);
|
||||||
|
|
||||||
|
//- Copy construct and expand with dictionary variables
|
||||||
|
// Optionally strip C/C++ comments from the input
|
||||||
|
inline exprString
|
||||||
|
(
|
||||||
|
const std::string& str,
|
||||||
|
const dictionary& dict,
|
||||||
|
const bool removeComments = false
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Move construct and expand with dictionary variables
|
||||||
|
// Optionally strip C/C++ comments from the input
|
||||||
|
inline exprString
|
||||||
|
(
|
||||||
|
std::string&& str,
|
||||||
|
const dictionary& dict,
|
||||||
|
const bool removeComments = false
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Construct from Istream and expand with dictionary variables
|
||||||
|
// Optionally strip C/C++ comments from the input
|
||||||
|
inline exprString
|
||||||
|
(
|
||||||
|
Istream& is,
|
||||||
|
const dictionary& dict,
|
||||||
|
const bool removeComments = false
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//- Destructor
|
||||||
|
~exprString() = default;
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- Copy convert string to exprString.
|
||||||
|
// No expansions, know what you are doing.
|
||||||
|
inline static exprString toExpr(const std::string& str);
|
||||||
|
|
||||||
|
//- Move convert string to exprString.
|
||||||
|
// No expansions, know what you are doing.
|
||||||
|
inline static exprString toExpr(std::string&& str);
|
||||||
|
|
||||||
|
//- Inplace expansion with dictionary variables
|
||||||
|
// Optionally strip C/C++ comments from the input
|
||||||
|
exprString& expand
|
||||||
|
(
|
||||||
|
const dictionary& dict,
|
||||||
|
const bool removeComments = false
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Check for unexpanded '$' entries. Fatal if any exist.
|
||||||
|
inline bool valid() const;
|
||||||
|
|
||||||
|
|
||||||
|
// Member Operators
|
||||||
|
|
||||||
|
//- Copy assign
|
||||||
|
exprString& operator=(const exprString& str) = default;
|
||||||
|
|
||||||
|
//- Move assign
|
||||||
|
exprString& operator=(exprString&& str) = default;
|
||||||
|
|
||||||
|
//- Copy assign from c-string (no expansions)
|
||||||
|
inline exprString& operator=(const char* str);
|
||||||
|
|
||||||
|
//- Copy assign from string (no expansions)
|
||||||
|
inline exprString& operator=(const std::string& str);
|
||||||
|
|
||||||
|
//- Move assign from string (no expansions)
|
||||||
|
inline exprString& operator=(std::string&& str);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace expressions
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#include "exprStringI.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
205
src/OpenFOAM/expressions/exprString/exprStringI.H
Normal file
205
src/OpenFOAM/expressions/exprString/exprStringI.H
Normal file
@ -0,0 +1,205 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Original code Copyright (C) 2012-2018 Bernhard Gschaider
|
||||||
|
Copyright (C) 2019 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "error.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline Foam::expressions::exprString::exprString
|
||||||
|
(
|
||||||
|
const std::string& s,
|
||||||
|
bool doValidate
|
||||||
|
)
|
||||||
|
:
|
||||||
|
string(s)
|
||||||
|
{
|
||||||
|
#ifdef FULLDEBUG
|
||||||
|
if (doValidate)
|
||||||
|
{
|
||||||
|
(void)valid();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::expressions::exprString::exprString
|
||||||
|
(
|
||||||
|
std::string&& s,
|
||||||
|
bool doValidate
|
||||||
|
)
|
||||||
|
:
|
||||||
|
string(std::move(s))
|
||||||
|
{
|
||||||
|
#ifdef FULLDEBUG
|
||||||
|
if (doValidate)
|
||||||
|
{
|
||||||
|
(void)valid();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::expressions::exprString::exprString
|
||||||
|
(
|
||||||
|
const char* s,
|
||||||
|
bool doValidate
|
||||||
|
)
|
||||||
|
:
|
||||||
|
string(s)
|
||||||
|
{
|
||||||
|
#ifdef FULLDEBUG
|
||||||
|
if (doValidate)
|
||||||
|
{
|
||||||
|
(void)valid();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::expressions::exprString::exprString
|
||||||
|
(
|
||||||
|
const std::string& str,
|
||||||
|
const dictionary& dict,
|
||||||
|
const bool removeComments
|
||||||
|
)
|
||||||
|
:
|
||||||
|
string(str)
|
||||||
|
{
|
||||||
|
expand(dict, removeComments);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::expressions::exprString::exprString
|
||||||
|
(
|
||||||
|
std::string&& str,
|
||||||
|
const dictionary& dict,
|
||||||
|
const bool removeComments
|
||||||
|
)
|
||||||
|
:
|
||||||
|
string(std::move(str))
|
||||||
|
{
|
||||||
|
expand(dict, removeComments);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::expressions::exprString::exprString
|
||||||
|
(
|
||||||
|
Istream& is,
|
||||||
|
const dictionary& dict,
|
||||||
|
const bool removeComments
|
||||||
|
)
|
||||||
|
:
|
||||||
|
string(is)
|
||||||
|
{
|
||||||
|
expand(dict, removeComments);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline bool Foam::expressions::exprString::valid() const
|
||||||
|
{
|
||||||
|
const bool ok = (std::string::npos == find('$'));
|
||||||
|
|
||||||
|
#ifdef FULLDEBUG
|
||||||
|
if (!ok)
|
||||||
|
{
|
||||||
|
FatalErrorInFunction
|
||||||
|
<< "Unexpanded '$' in " << *this << nl
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::expressions::exprString
|
||||||
|
Foam::expressions::exprString::toExpr(const std::string& str)
|
||||||
|
{
|
||||||
|
exprString expr;
|
||||||
|
|
||||||
|
expr.string::operator=(str);
|
||||||
|
|
||||||
|
return expr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::expressions::exprString
|
||||||
|
Foam::expressions::exprString::toExpr(std::string&& str)
|
||||||
|
{
|
||||||
|
exprString expr;
|
||||||
|
|
||||||
|
expr.string::operator=(std::move(str));
|
||||||
|
|
||||||
|
return expr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline Foam::expressions::exprString&
|
||||||
|
Foam::expressions::exprString::operator=(const char* str)
|
||||||
|
{
|
||||||
|
string::operator=(str);
|
||||||
|
|
||||||
|
#ifdef FULLDEBUG
|
||||||
|
(void)valid();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::expressions::exprString&
|
||||||
|
Foam::expressions::exprString::operator=(const std::string& str)
|
||||||
|
{
|
||||||
|
string::operator=(str);
|
||||||
|
|
||||||
|
#ifdef FULLDEBUG
|
||||||
|
(void)valid();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::expressions::exprString&
|
||||||
|
Foam::expressions::exprString::operator=(std::string&& str)
|
||||||
|
{
|
||||||
|
string::operator=(std::move(str));
|
||||||
|
|
||||||
|
#ifdef FULLDEBUG
|
||||||
|
(void)valid();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
202
src/OpenFOAM/expressions/exprTools/exprTools.C
Normal file
202
src/OpenFOAM/expressions/exprTools/exprTools.C
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2019 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Note
|
||||||
|
Ideas based on swak4Foam driver code (2010-2018)
|
||||||
|
from Bernhard Gschaider <bgschaid@hfd-research.com>
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "exprTools.H"
|
||||||
|
#include "stringOps.H"
|
||||||
|
#include "DynamicList.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
|
//! \cond file-scope
|
||||||
|
|
||||||
|
// Maximum depth for recursive variable names
|
||||||
|
static constexpr label maxRecursionDepth_ = 100;
|
||||||
|
|
||||||
|
|
||||||
|
static List<expressions::exprString> expandExprStrings
|
||||||
|
(
|
||||||
|
const UList<string>& inputs,
|
||||||
|
const dictionary& dict,
|
||||||
|
bool mandatory,
|
||||||
|
label recursionDepth
|
||||||
|
)
|
||||||
|
{
|
||||||
|
///Info<< "::expandExprStrings " << inputs << endl;
|
||||||
|
|
||||||
|
DynamicList<expressions::exprString> result;
|
||||||
|
|
||||||
|
for (const string& input : inputs)
|
||||||
|
{
|
||||||
|
// Allow inline list of semicolon-separated variables
|
||||||
|
const auto varExpressions = stringOps::split<string>(input, ';');
|
||||||
|
|
||||||
|
for (const auto& subMatch : varExpressions)
|
||||||
|
{
|
||||||
|
string varExpr(stringOps::trim(subMatch.str()));
|
||||||
|
|
||||||
|
if (varExpr.empty())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
///Info<< "Checking " << varExpr << endl;
|
||||||
|
|
||||||
|
// Expand #otherVariable as dictionary lookup
|
||||||
|
if (varExpr[0] == '#')
|
||||||
|
{
|
||||||
|
///Info<< "Expand: " << varExpr << endl;
|
||||||
|
|
||||||
|
List<expressions::exprString> expansions
|
||||||
|
(
|
||||||
|
exprTools::getList
|
||||||
|
(
|
||||||
|
dict,
|
||||||
|
varExpr.substr(1),
|
||||||
|
mandatory,
|
||||||
|
recursionDepth
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
///Info<< "Expanded " << varExpr.c_string() << ": "
|
||||||
|
/// << expansions << nl;
|
||||||
|
|
||||||
|
result.reserve(result.size() + expansions.size());
|
||||||
|
for (expressions::exprString& str : expansions)
|
||||||
|
{
|
||||||
|
result.append(std::move(str));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.append(expressions::exprString(varExpr, dict));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.shrink();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \endcond
|
||||||
|
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::List<Foam::expressions::exprString>
|
||||||
|
Foam::exprTools::getList
|
||||||
|
(
|
||||||
|
const dictionary& dict,
|
||||||
|
const word& keyword,
|
||||||
|
bool mandatory,
|
||||||
|
label recursionDepth
|
||||||
|
)
|
||||||
|
{
|
||||||
|
List<expressions::exprString> result;
|
||||||
|
|
||||||
|
// Catch empty keyword as a no-op (eg, when called recursively)
|
||||||
|
if (keyword.empty())
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
const entry* eptr = dict.findEntry(keyword, keyType::LITERAL_RECURSIVE);
|
||||||
|
|
||||||
|
if (!eptr)
|
||||||
|
{
|
||||||
|
if (mandatory)
|
||||||
|
{
|
||||||
|
FatalIOErrorInFunction(dict)
|
||||||
|
<< "Missing mandatory entry: " << keyword << nl << nl
|
||||||
|
<< exit(FatalIOError);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (++recursionDepth > maxRecursionDepth_)
|
||||||
|
{
|
||||||
|
FatalIOErrorInFunction(dict)
|
||||||
|
<< "Exceeded recursion depth (" << maxRecursionDepth_
|
||||||
|
<< ") while reading list " << keyword << nl
|
||||||
|
<< "Likely caused by circular referencing" << nl
|
||||||
|
<< exit(FatalIOError);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ITstream& is = eptr->stream();
|
||||||
|
token firstToken(is);
|
||||||
|
|
||||||
|
List<string> list;
|
||||||
|
|
||||||
|
if
|
||||||
|
(
|
||||||
|
firstToken.isLabel()
|
||||||
|
||
|
||||||
|
(
|
||||||
|
firstToken.type() == token::PUNCTUATION
|
||||||
|
&& firstToken.pToken() == token::BEGIN_LIST
|
||||||
|
)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// A list of strings
|
||||||
|
is.rewind();
|
||||||
|
is >> list;
|
||||||
|
}
|
||||||
|
else if (firstToken.isString())
|
||||||
|
{
|
||||||
|
// A single string
|
||||||
|
list.resize(1);
|
||||||
|
list[0] = firstToken.stringToken();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FatalIOErrorInFunction(dict)
|
||||||
|
<< " Entry '"<< keyword
|
||||||
|
<< "' not a string or list of strings" << nl
|
||||||
|
<< exit(FatalError);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for excess tokens
|
||||||
|
dict.checkITstream(is, keyword);
|
||||||
|
|
||||||
|
// Expand List<string> to List<expressions::exprString>
|
||||||
|
return expandExprStrings(list, dict, mandatory, recursionDepth);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
192
src/OpenFOAM/expressions/exprTools/exprTools.H
Normal file
192
src/OpenFOAM/expressions/exprTools/exprTools.H
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2019 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Namespace
|
||||||
|
Foam::exprTools
|
||||||
|
|
||||||
|
Description
|
||||||
|
Helper methods for creating expressions.
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
exprTools.C
|
||||||
|
exprToolsTemplates.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef exprTools_H
|
||||||
|
#define exprTools_H
|
||||||
|
|
||||||
|
#include "exprString.H"
|
||||||
|
#include "scalar.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Namespace exprTools Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
namespace exprTools
|
||||||
|
{
|
||||||
|
|
||||||
|
//- Stringified value for zero of given type
|
||||||
|
template<class Type>
|
||||||
|
string zeroValue();
|
||||||
|
|
||||||
|
//- Stringified version of data with comma separators between components
|
||||||
|
template<class Type>
|
||||||
|
string toString(const Type& data, const word& prefix);
|
||||||
|
|
||||||
|
//- Stringified version of data with comma separators between components.
|
||||||
|
//- Uses prefix corresponding to the pTraits of Type.
|
||||||
|
template<class Type>
|
||||||
|
string toString(const Type& data);
|
||||||
|
|
||||||
|
//- Stringified version of primitiveEntry of Type.
|
||||||
|
//- Uses comma separators and prefix corresponding to the pTraits of Type
|
||||||
|
template<class Type>
|
||||||
|
string toString(ITstream& is);
|
||||||
|
|
||||||
|
//- Get an expression string list from a dictionary
|
||||||
|
// Supports list and inline specifications, as well as indirect
|
||||||
|
// inclusion of other expression string lists.
|
||||||
|
//
|
||||||
|
// Syntax examples,
|
||||||
|
// \code
|
||||||
|
//
|
||||||
|
// // Single items. Inline or list format.
|
||||||
|
// list1a "var1=p";
|
||||||
|
// list1b ( "var1=p" );
|
||||||
|
//
|
||||||
|
// // Multiple items. Inline or list format.
|
||||||
|
// list2a "var2=T; var3=U; var4=rho";
|
||||||
|
// list2b ( "var2=T" "var3=U; var4=rho" );
|
||||||
|
//
|
||||||
|
// // Indirection. Inline or list format.
|
||||||
|
// list3a "#list1a; #list2b";
|
||||||
|
// list2b ( "var1=p" "#list2a" );
|
||||||
|
//
|
||||||
|
// \endcode
|
||||||
|
List<expressions::exprString> getList
|
||||||
|
(
|
||||||
|
const dictionary& dict,
|
||||||
|
const word& keyword,
|
||||||
|
bool mandatory = true,
|
||||||
|
label recursionDepth = 0
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// Boolean-like values
|
||||||
|
|
||||||
|
//- Convert [0-1] values (usually scalars) as false/true
|
||||||
|
template<class T>
|
||||||
|
struct toBoolOp
|
||||||
|
{
|
||||||
|
int operator()(const T& val) const
|
||||||
|
{
|
||||||
|
return (0.5 < Foam::mag(val));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//- No conversion needed for bool
|
||||||
|
template<>
|
||||||
|
struct toBoolOp<bool>
|
||||||
|
{
|
||||||
|
int operator()(bool val) const
|
||||||
|
{
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//- Inverse test of toBoolOp()
|
||||||
|
template<class T>
|
||||||
|
struct toBoolNotOp
|
||||||
|
{
|
||||||
|
int operator()(const T& val) const
|
||||||
|
{
|
||||||
|
return (Foam::mag(val) < 0.5);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//- Inverse test of toBoolOp, no conversion needed for bool
|
||||||
|
template<>
|
||||||
|
struct toBoolNotOp<bool>
|
||||||
|
{
|
||||||
|
int operator()(bool val) const
|
||||||
|
{
|
||||||
|
return !val;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//- Logical 'and' with scalars as (false, true) values
|
||||||
|
template<class T>
|
||||||
|
struct toBoolAndOp
|
||||||
|
{
|
||||||
|
int operator()(const T& a, const T& b) const
|
||||||
|
{
|
||||||
|
return (toBoolOp<T>()(a) && toBoolOp<T>()(b));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//- Logical 'or' with scalars as (false, true) values
|
||||||
|
template<class T>
|
||||||
|
struct toBoolOrOp
|
||||||
|
{
|
||||||
|
int operator()(const T& a, const T& b) const
|
||||||
|
{
|
||||||
|
return (toBoolOp<T>()(a) || toBoolOp<T>()(b));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//- Logical 'xor' with scalars as (false, true) values
|
||||||
|
template<class T>
|
||||||
|
struct toBoolXorOp
|
||||||
|
{
|
||||||
|
int operator()(const T& a, const T& b) const
|
||||||
|
{
|
||||||
|
return (toBoolOp<T>()(a) ? toBoolNotOp<T>()(b) : toBoolOp<T>()(b));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // End namespace exprTools
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#ifdef NoRepository
|
||||||
|
#include "exprToolsTemplates.C"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
86
src/OpenFOAM/expressions/exprTools/exprToolsTemplates.C
Normal file
86
src/OpenFOAM/expressions/exprTools/exprToolsTemplates.C
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2019 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "OStringStream.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::string Foam::exprTools::zeroValue()
|
||||||
|
{
|
||||||
|
OStringStream buf;
|
||||||
|
|
||||||
|
buf << pTraits<Type>::typeName << '(';
|
||||||
|
for (direction cmpt=0; cmpt < pTraits<Type>::nComponents; ++cmpt)
|
||||||
|
{
|
||||||
|
if (cmpt) buf << ',';
|
||||||
|
buf << 0;
|
||||||
|
}
|
||||||
|
buf << ')';
|
||||||
|
|
||||||
|
return buf.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::string Foam::exprTools::toString
|
||||||
|
(
|
||||||
|
const Type& data,
|
||||||
|
const word& prefix
|
||||||
|
)
|
||||||
|
{
|
||||||
|
OStringStream buf;
|
||||||
|
|
||||||
|
buf << prefix << '(';
|
||||||
|
for (direction cmpt=0; cmpt < pTraits<Type>::nComponents; ++cmpt)
|
||||||
|
{
|
||||||
|
if (cmpt) buf << ',';
|
||||||
|
buf << component(data, cmpt);
|
||||||
|
}
|
||||||
|
buf << ')';
|
||||||
|
|
||||||
|
return buf.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::string Foam::exprTools::toString(const Type& data)
|
||||||
|
{
|
||||||
|
return toString<Type>(data, pTraits<Type>::typeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::string Foam::exprTools::toString(ITstream& is)
|
||||||
|
{
|
||||||
|
Type data(Zero);
|
||||||
|
is >> data;
|
||||||
|
|
||||||
|
return toString<Type>(data, pTraits<Type>::typeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
Reference in New Issue
Block a user