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