Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Commits on Source (15)
Showing
with 201 additions and 92 deletions
......@@ -32,7 +32,7 @@ vertices
(
(0.0 0.0 0) //0
(10 0.0 0)
(10 0.0 0) //2
#calc #{ vector(10, 0, 0) #} //2
(0.0 0.0 0)
(0.0 $minY $z) //4
......
......@@ -32,7 +32,7 @@ vertices
(
(0.0 0.0 0) //0
(10 0.0 0)
(10 0.0 0) //2
#eval{ vector(10, 0, 0) } //2
(0.0 0.0 0)
(0.0 $minY $z) //4
......
......@@ -68,4 +68,8 @@ apiMonth #eval{ ($FOAM_API % 100) };
empty #eval "";
// Field of specified length
random #eval 4 { vector(rand(), 0, 0) ; /* trailing rubbish */ ; };
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -97,6 +97,7 @@ int main(int argc, char *argv[])
argList::addBoolOption("rules", "Print parser rules and exit");
argList::addBoolOption("tokens", "Print token names and exit");
argList::addOption("precision", "int", "Output with specified precision");
argList::addOption("size", "int", "Field output width (default: 1)");
// Flag arguments as optional so that -rules and -tokens works
argList::noMandatoryArgs();
......@@ -110,6 +111,7 @@ int main(int argc, char *argv[])
const bool printRules = args.found("rules");
const bool printNames = args.found("tokens");
const label fieldWidth = args.getOrDefault<label>("size", 1);
if (printNames || printRules)
{
......@@ -155,7 +157,7 @@ int main(int argc, char *argv[])
return 1;
}
Info<< stringOps::evaluate(expr).c_str() << nl;
Info<< stringOps::evaluate(fieldWidth, expr).c_str() << nl;
return 0;
}
......
......@@ -31,6 +31,8 @@ Description
#include "dictionary.H"
#include "Ostream.H"
#include "Pstream.H"
#include "pointField.H"
#include "tensor.H"
#include "unitConversion.H"
//{{{ begin codeInclude
......@@ -51,7 +53,7 @@ ${localCode}
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
extern "C" void ${typeName}(Ostream& os, const dictionary& dict)
extern "C" void ${typeName}(Foam::Ostream& os, const Foam::dictionary& dict)
{
//{{{ begin code
${code}
......
......@@ -6,7 +6,7 @@
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2011-2016 OpenFOAM Foundation
# Copyright (C) 2017-2020 OpenCFD Ltd.
# Copyright (C) 2017-2021 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
......@@ -25,6 +25,7 @@
# define the underlying compiler to be used
#
# User adjustments are controlled by these types of files:
# - config.csh/prefs.fjmpi
# - config.csh/prefs.intelmpi
# - config.csh/prefs.mpich
# - config.csh/prefs.mpich-gm
......@@ -223,7 +224,7 @@ case CRAY-MPICH:
setenv MPI_ARCH_PATH "$MPICH_DIR"
if ( ! -d "$MPI_ARCH_PATH" ) then
echo "%{_foamMpiWarning}invalid $WM_MPLIB directory" 1>&2
echo "%{_foamMpiWarning}invalid $WM_MPLIB directory"
echo " => $MPI_ARCH_PATH"
echo "Please set MPICH_DIR correctly"
endif
......@@ -269,12 +270,24 @@ case MPI:
case FJMPI:
setenv FOAM_MPI fjmpi
setenv MPI_ARCH_PATH /opt/FJSVmpi2
_foamEtc -config prefs.fjmpi ## Optional adjustments
_foamAddPath "$MPI_ARCH_PATH"/bin
_foamAddLib "$MPI_ARCH_PATH"/lib/sparcv9
_foamAddLib /opt/FSUNf90/lib/sparcv9
_foamAddLib /opt/FJSVpnidt/lib
# MPI_ARCH_PATH (prefs) or MPI_ROOT (inherited), in that order
if ( "$MPI_ARCH_PATH" != "" ) then
setenv MPI_ROOT "$MPI_ARCH_PATH"
else if ( $?MPI_ROOT ) then
setenv MPI_ARCH_PATH "$MPI_ROOT"
endif
if ( -d "$MPI_ARCH_PATH" ) then
setenv OPAL_PREFIX "$MPI_ARCH_PATH" # An openmpi-derivative
_foamAddPath "$MPI_ARCH_PATH"/bin
_foamAddLib "$MPI_ARCH_PATH"/lib64
else
echo "%{_foamMpiWarning}invalid $WM_MPLIB directory"
echo " => ${MPI_ARCH_PATH:-unset}"
echo "Please set MPI_ARCH_PATH or MPI_ROOT correctly"
endif
breaksw
......@@ -297,7 +310,7 @@ case SGIMPI:
setenv MPI_ARCH_PATH "$MPI_ROOT"
if ( ! -d "$MPI_ARCH_PATH" ) then
echo "%{_foamMpiWarning}invalid $WM_MPLIB directory" 1>&2
echo "%{_foamMpiWarning}invalid $WM_MPLIB directory"
echo " => $MPI_ARCH_PATH"
echo "Please set MPI_ROOT correctly"
endif
......@@ -339,8 +352,8 @@ case INTELMPI*:
endsw
else
echo "${_foamMpiWarning}invalid $WM_MPLIB directory" 1>&2
echo " => ${MPI_ARCH_PATH}" 1>&2
echo "${_foamMpiWarning}invalid $WM_MPLIB directory"
echo " => ${MPI_ARCH_PATH}"
echo "Please set I_MPI_ROOT or MPI_ROOT correctly."
endif
......
......@@ -125,7 +125,7 @@ case "system":
if ($?FOAM_VERBOSE && $?prompt) then
if ( $?pv_plugin_dir ) then
echo "Using paraview (system)"
echo " plugins : ${pv_plugin_dir}" 1>&2
echo " plugins : ${pv_plugin_dir}"
else
echo "system paraview (not found)"
endif
......
......@@ -6,7 +6,7 @@
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2011-2016 OpenFOAM Foundation
# Copyright (C) 2017-2020 OpenCFD Ltd.
# Copyright (C) 2017-2021 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
......@@ -25,6 +25,7 @@
# define the underlying compiler to be used
#
# User adjustments are controlled by these types of files:
# - config.sh/prefs.fjmpi
# - config.sh/prefs.intelmpi
# - config.sh/prefs.mpich
# - config.sh/prefs.mpich-gm
......@@ -289,12 +290,27 @@ MPI)
FJMPI)
export FOAM_MPI=fjmpi
export MPI_ARCH_PATH=/opt/FJSVmpi2
_foamEtc -config prefs.fjmpi ## Optional adjustments
_foamAddPath "$MPI_ARCH_PATH"/bin
_foamAddLib "$MPI_ARCH_PATH"/lib/sparcv9
_foamAddLib /opt/FSUNf90/lib/sparcv9
_foamAddLib /opt/FJSVpnidt/lib
# MPI_ARCH_PATH (prefs) or MPI_ROOT (inherited), in that order
if [ -n "$MPI_ARCH_PATH" ]
then
export MPI_ROOT="$MPI_ARCH_PATH"
elif [ -n "$MPI_ROOT" ]
then
export MPI_ARCH_PATH="$MPI_ROOT"
fi
if [ -d "$MPI_ARCH_PATH" ]
then
export OPAL_PREFIX="$MPI_ARCH_PATH" # An openmpi-derivative
_foamAddPath "$MPI_ARCH_PATH"/bin
_foamAddLib "$MPI_ARCH_PATH"/lib64
else
echo "%{_foamMpiWarning}invalid $WM_MPLIB directory" 1>&2
echo " => ${MPI_ARCH_PATH:-unset}" 1>&2
echo "Please set MPI_ARCH_PATH or MPI_ROOT correctly" 1>&2
fi
;;
......
Subproject commit 1b0a93c7c97aafab500bf77bf937d7ca8e8012a7
Subproject commit 8c45a9f68540db235269fe67ea6c717ee43a4f3e
Subproject commit 1cd40512997c9f2c93d00ba28279d69f2d6d4fa2
Subproject commit f76034ed81b59728b8793a122c194bc1276d90f5
Subproject commit f8a8c546396b8aba780e9ce14d6a781b05e50d4d
Subproject commit 23444fb94cf84a054cafec9855bc49ecc687da9c
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -31,6 +31,7 @@ License
#include "stringOps.H"
#include "fieldExprDriver.H"
#include "addToMemberFunctionSelectionTable.H"
#include <cctype>
#undef DetailInfo
#define DetailInfo if (::Foam::infoDetailLevel > 0) InfoErr
......@@ -69,34 +70,35 @@ Foam::tokenList Foam::functionEntries::evalEntry::evaluate
<< is.lineNumber() << " in file " << parentDict.name() << nl;
#endif
// String to evaluate
string s;
token tok(is);
if (!tok.good())
label fieldWidth(1); // Field width for the result
if (tok.isLabel())
{
FatalIOErrorInFunction(is)
<< "Bad token - could not get string to evaluate"
<< exit(FatalIOError);
return tokenList();
// - #eval INT "expr"
// - #eval INT { expr }
// - #eval INT #{ expr #}
fieldWidth = max(1, tok.labelToken());
is >> tok;
}
string s; // String to evaluate
if (tok.isString())
{
// - #eval "expr"
// - #eval #{ expr #}
s = tok.stringToken();
}
else if (tok == token::BEGIN_BLOCK)
else if (tok.isPunctuation(token::BEGIN_BLOCK))
{
// - #eval { expr }
dynamic_cast<ISstream&>(is).getLine(s, token::END_BLOCK);
}
else
{
is.putBack(tok);
FatalIOErrorInFunction(is)
<< "Invalid input for #eval" << nl
<< "Invalid input for #eval."
" Expecting a string or block to evaluate, but found" << nl
<< tok.info() << endl
<< exit(FatalIOError);
}
......@@ -111,15 +113,31 @@ Foam::tokenList Foam::functionEntries::evalEntry::evaluate
expressions::exprString::inplaceExpand(s, parentDict, true);
stringOps::inplaceTrim(s);
// An extraneous trailing ';' is a common input error, catch it now.
// May need to relax in the future, trim or something else
// An extraneous trailing ';' is a common input error.
// - trim if it does not influence the result
if (std::string::npos != s.find(';'))
const auto trailing = s.find(';');
if (std::string::npos != trailing)
{
FatalIOErrorInFunction(is)
<< "Invalid input for #eval" << nl
<< s << endl
<< exit(FatalIOError);
bool ignore = true;
for (size_t other = trailing; ignore && other < s.length(); ++other)
{
ignore = s[other] == ';' || std::isspace(s[other]);
}
if (ignore)
{
// Can trim trailing without semantical change
s.erase(trailing);
stringOps::inplaceTrim(s);
}
else
{
FatalIOErrorInFunction(is)
<< "Invalid input (after trailing ';') for #eval" << nl
<< s << endl
<< exit(FatalIOError);
}
}
#ifdef FULLDEBUG
......@@ -138,7 +156,7 @@ Foam::tokenList Foam::functionEntries::evalEntry::evaluate
expressions::exprResult result;
{
expressions::fieldExprDriver driver(1);
expressions::fieldExprDriver driver(fieldWidth);
driver.parse(s);
result = std::move(driver.result());
}
......@@ -152,11 +170,15 @@ Foam::tokenList Foam::functionEntries::evalEntry::evaluate
return tokenList();
}
// Could average/reduce to a single value, but probably not needed
//// result.testIfSingleValue(false); // No parallel check
OTstream toks;
result.writeValue(toks);
if (result.size() <= 1)
{
result.writeValue(toks);
}
else
{
result.writeField(toks);
}
return std::move(toks);
}
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -31,11 +31,12 @@ Description
with scalars, vectors etc.
The input can any form of string or, for convenience,
a '{}' delimited string literal. In all cases, C/C++ comment stripping
is also performed.
For example,
a '{}' delimited string literal.
In all cases, C/C++ comment stripping is performed.
The default size of the evaluated field is one,
which can be overridden by providing an initial integer value.
Some examples,
\verbatim
a 1;
b 3;
......@@ -45,12 +46,15 @@ Description
// ignore: sin(pi()*$a/$b)
sin(degToRad(45))
};
// With different field length:
points #eval 4 #{ vector(rand(), 0, 0) #};
\endverbatim
Note
The string expansions support use of environment variables.
Unknown variables will expand to an empty string, so it can be advisable
to an expansion with an alternative. For example,
to expand with an alternative. For example,
\verbatim
d #eval{ sin(degToRad( ${angle:-0} )) };
......
......@@ -624,21 +624,7 @@ void Foam::expressions::exprResult::writeDict
os.writeEntryIfDifferent<Switch>("isPointValue", false, isPointData_);
os.writeEntry<Switch>("isSingleValue", isUniform_);
const bool ok =
(
writeValueFieldChecked<scalar>(os)
|| writeValueFieldChecked<vector>(os)
|| writeValueFieldChecked<tensor>(os)
|| writeValueFieldChecked<symmTensor>(os)
|| writeValueFieldChecked<sphericalTensor>(os)
|| writeValueFieldChecked<bool>(os)
);
if (!ok)
{
WarningInFunction
<< "Unknown data type " << valType_ << endl;
}
this->writeField(os, "value");
}
if (subDict)
......@@ -650,6 +636,38 @@ void Foam::expressions::exprResult::writeDict
}
void Foam::expressions::exprResult::writeField
(
Ostream& os,
const word& keyword
) const
{
// const auto oldFmt = os.format(IOstream::ASCII);
DebugInFunction
<< Foam::name(this) << nl
<< "Format: "
<< IOstreamOption::formatNames[os.format()] << nl;
const bool ok =
(
writeFieldChecked<scalar>(keyword, os)
|| writeFieldChecked<vector>(keyword, os)
|| writeFieldChecked<tensor>(keyword, os)
|| writeFieldChecked<symmTensor>(keyword, os)
|| writeFieldChecked<sphericalTensor>(keyword, os)
|| writeFieldChecked<label>(keyword, os)
|| writeFieldChecked<bool>(keyword, os)
);
if (!ok)
{
WarningInFunction
<< "Unknown data type " << valType_ << endl;
}
}
void Foam::expressions::exprResult::writeValue
(
Ostream& os
......
......@@ -214,10 +214,11 @@ class exprResult
template<class Type>
bool writeSingleValueChecked(Ostream& os) const;
//- Type-checked writing of "value" field entry
//- Type-checked writing field as entry (if keyword is non-empty)
//- or as plain field (if keyword is empty)
// \return True if the type check was satisfied
template<class Type>
bool writeValueFieldChecked(Ostream& os) const;
bool writeFieldChecked(const word& keyword, Ostream& os) const;
//- Type-checked forwarding to Field::writeEntry
// \return True if the type check was satisfied
......@@ -516,6 +517,9 @@ public:
//- Write entry as dictionary contents
void writeDict(Ostream& os, const bool subDict=true) const;
//- Write the field, optionally as an entry
void writeField(Ostream& os, const word& keyword = "") const;
//- Write the single value, or the first value from field
void writeValue(Ostream& os) const;
......
......@@ -5,8 +5,8 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2018 Bernhard Gschaider <bgschaid@hfd-research.com>
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2012-2018 Bernhard Gschaider
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -496,7 +496,11 @@ bool Foam::expressions::exprResult::writeSingleValueChecked(Ostream& os) const
template<class Type>
bool Foam::expressions::exprResult::writeValueFieldChecked(Ostream& os) const
bool Foam::expressions::exprResult::writeFieldChecked
(
const word& keyword,
Ostream& os
) const
{
if (!isType<Type>())
{
......@@ -508,26 +512,46 @@ bool Foam::expressions::exprResult::writeValueFieldChecked(Ostream& os) const
if (isUniform_)
{
const Type& val = single_.get<Type>();
os.writeEntry("value", val);
if (keyword.empty())
{
os << val;
}
else
{
os.writeEntry(keyword, val);
}
}
else
{
// Zero-sized
const Field<Type> fld;
fld.writeEntry("value", os);
// Zero-sized - could write nothing, or a zero value
if (keyword.empty())
{
os << pTraits<Type>::zero;
}
else
{
Field<Type>().writeEntry(keyword, os);
}
}
}
else
{
const Field<Type>& fld = *static_cast<const Field<Type>*>(fieldPtr_);
if (isUniform_)
if (keyword.empty())
{
os.writeEntry("value", fld.first());
os << fld;
}
else
{
fld.writeEntry("value", os);
if (isUniform_)
{
os.writeEntry(keyword, fld.first());
}
else
{
fld.writeEntry(keyword, os);
}
}
}
......
......@@ -62,7 +62,7 @@
#define TOK_VECTOR_ID 62
#define TOK_SPH_TENSOR_ID 63
#define TOK_SYM_TENSOR_ID 64
#define TOK_UNIT_TENSOR 65
#define TOK_IDENTITY_TENSOR 65
#define TOK_TENSOR_ID 66
#define TOK_LTRUE 67
#define TOK_LFALSE 68
......
......@@ -7,7 +7,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -283,7 +283,7 @@ dnl
\*---------------------------------------------------------------------------*/
evaluate ::= _target_ (a) . { driver->setResult(a); }
tfield (lhs) ::= UNIT_TENSOR . { lhs = _new_tfield(Foam::tensor::I); }
tfield (lhs) ::= IDENTITY_TENSOR . { lhs = _new_tfield(Foam::tensor::I); }
rule_get_field(_target_, TENSOR_ID)
......
......@@ -7,7 +7,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -471,7 +471,7 @@ tr9:
goto st11;
tr11:
#line 292 "fieldExprScanner.rl"
{te = p+1;{ EMIT_TOKEN(UNIT_TENSOR); }}
{te = p+1;{ EMIT_TOKEN(IDENTITY_TENSOR); }}
goto st11;
tr12:
#line 235 "fieldExprScanner.rl"
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -289,7 +289,7 @@ static int driverTokenType
"Zero" =>{ EMIT_TOKEN(ZERO); };
"true" =>{ EMIT_TOKEN(LTRUE); };
"false" =>{ EMIT_TOKEN(LFALSE); };
"tensor::I" =>{ EMIT_TOKEN(UNIT_TENSOR); };
"tensor::I" =>{ EMIT_TOKEN(IDENTITY_TENSOR); };
"arg" =>{ EMIT_TOKEN(ARG); };
## "time" =>{ EMIT_TOKEN(TIME); };
......