Commit 836dc16f authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: support an 'arg()' pseudo-function for fv-based expressions

parent 5bba554d
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2010-2018 Bernhard Gschaider <bgschaid@hfd-research.com>
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -92,6 +92,7 @@ Foam::expressions::exprDriver::exprDriver
result_(),
variableStrings_(),
variables_(),
arg1Value_(0),
stashedTokenId_(0),
// Controls
......@@ -120,6 +121,7 @@ Foam::expressions::exprDriver::exprDriver
result_(rhs.result_),
variableStrings_(rhs.variableStrings_),
variables_(rhs.variables_),
arg1Value_(rhs.arg1Value_),
stashedTokenId_(0),
debugScanner_(rhs.debugScanner_),
......@@ -194,6 +196,18 @@ void Foam::expressions::exprDriver::clearVariables()
}
void Foam::expressions::exprDriver::setArgument(scalar val)
{
arg1Value_ = val;
}
Foam::scalar Foam::expressions::exprDriver::argValue() const
{
return arg1Value_;
}
void Foam::expressions::exprDriver::evaluateVariable
(
const word& varName,
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Original code Copyright (C) 2010-2018 Bernhard Gschaider
Copyright (C) 2010-2018 Bernhard Gschaider
Copyright (C) 2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
......@@ -79,7 +79,7 @@ class exprDriver
{
protected:
// Private Data
// Protected Data
// Stored Data
......@@ -95,6 +95,9 @@ protected:
//- The variables table
HashTable<exprResult> variables_;
//- Special-purpose scalar reference argument
scalar arg1Value_;
// Controls, tracing etc.
......@@ -123,8 +126,6 @@ protected:
bool searchFiles_;
protected:
// Protected Member Functions
//- Read an interpolation table
......@@ -292,6 +293,14 @@ public:
}
// Globals, Mesh Related
//- Set special-purpose scalar reference argument.
// Typically available as \c arg() in an expression and
// may corrspond to table index, time value etc.
scalar argValue() const;
// General Controls
//- Get "look-behind" parsing context (internal bookkeeping)
......@@ -336,6 +345,11 @@ public:
//- Clear temporary variables and resets from expression strings
virtual void clearVariables();
//- Set special-purpose scalar reference argument.
// Typically available as \c arg() in an expression and
// may corrspond to table index, time value etc.
virtual void setArgument(const scalar val);
//- True if named variable exists
inline virtual bool hasVariable(const word& name) const;
......
......@@ -25,66 +25,67 @@
#define TOK_RPAREN 25
#define TOK_DEG_TO_RAD 26
#define TOK_RAD_TO_DEG 27
#define TOK_SCALAR_ID 28
#define TOK_MIN 29
#define TOK_COMMA 30
#define TOK_MAX 31
#define TOK_SUM 32
#define TOK_AVERAGE 33
#define TOK_EXP 34
#define TOK_LOG 35
#define TOK_LOG10 36
#define TOK_SQR 37
#define TOK_SQRT 38
#define TOK_CBRT 39
#define TOK_SIN 40
#define TOK_COS 41
#define TOK_TAN 42
#define TOK_ASIN 43
#define TOK_ACOS 44
#define TOK_ATAN 45
#define TOK_SINH 46
#define TOK_COSH 47
#define TOK_TANH 48
#define TOK_POW 49
#define TOK_ATAN2 50
#define TOK_POS 51
#define TOK_NEG 52
#define TOK_POS0 53
#define TOK_NEG0 54
#define TOK_SIGN 55
#define TOK_FLOOR 56
#define TOK_CEIL 57
#define TOK_ROUND 58
#define TOK_HYPOT 59
#define TOK_RAND 60
#define TOK_VECTOR_ID 61
#define TOK_SPH_TENSOR_ID 62
#define TOK_SYM_TENSOR_ID 63
#define TOK_UNIT_TENSOR 64
#define TOK_TENSOR_ID 65
#define TOK_LTRUE 66
#define TOK_LFALSE 67
#define TOK_BOOL 68
#define TOK_BOOL_ID 69
#define TOK_MAG 70
#define TOK_MAGSQR 71
#define TOK_VECTOR 72
#define TOK_TENSOR 73
#define TOK_SYM_TENSOR 74
#define TOK_SPH_TENSOR 75
#define TOK_CMPT_X 76
#define TOK_CMPT_Y 77
#define TOK_CMPT_Z 78
#define TOK_CMPT_XX 79
#define TOK_CMPT_XY 80
#define TOK_CMPT_XZ 81
#define TOK_CMPT_YX 82
#define TOK_CMPT_YY 83
#define TOK_CMPT_YZ 84
#define TOK_CMPT_ZX 85
#define TOK_CMPT_ZY 86
#define TOK_CMPT_ZZ 87
#define TOK_CMPT_II 88
#define TOK_TRANSPOSE 89
#define TOK_DIAG 90
#define TOK_ARG 28
#define TOK_SCALAR_ID 29
#define TOK_MIN 30
#define TOK_COMMA 31
#define TOK_MAX 32
#define TOK_SUM 33
#define TOK_AVERAGE 34
#define TOK_EXP 35
#define TOK_LOG 36
#define TOK_LOG10 37
#define TOK_SQR 38
#define TOK_SQRT 39
#define TOK_CBRT 40
#define TOK_SIN 41
#define TOK_COS 42
#define TOK_TAN 43
#define TOK_ASIN 44
#define TOK_ACOS 45
#define TOK_ATAN 46
#define TOK_SINH 47
#define TOK_COSH 48
#define TOK_TANH 49
#define TOK_POW 50
#define TOK_ATAN2 51
#define TOK_POS 52
#define TOK_NEG 53
#define TOK_POS0 54
#define TOK_NEG0 55
#define TOK_SIGN 56
#define TOK_FLOOR 57
#define TOK_CEIL 58
#define TOK_ROUND 59
#define TOK_HYPOT 60
#define TOK_RAND 61
#define TOK_VECTOR_ID 62
#define TOK_SPH_TENSOR_ID 63
#define TOK_SYM_TENSOR_ID 64
#define TOK_UNIT_TENSOR 65
#define TOK_TENSOR_ID 66
#define TOK_LTRUE 67
#define TOK_LFALSE 68
#define TOK_BOOL 69
#define TOK_BOOL_ID 70
#define TOK_MAG 71
#define TOK_MAGSQR 72
#define TOK_VECTOR 73
#define TOK_TENSOR 74
#define TOK_SYM_TENSOR 75
#define TOK_SPH_TENSOR 76
#define TOK_CMPT_X 77
#define TOK_CMPT_Y 78
#define TOK_CMPT_Z 79
#define TOK_CMPT_XX 80
#define TOK_CMPT_XY 81
#define TOK_CMPT_XZ 82
#define TOK_CMPT_YX 83
#define TOK_CMPT_YY 84
#define TOK_CMPT_YZ 85
#define TOK_CMPT_ZX 86
#define TOK_CMPT_ZY 87
#define TOK_CMPT_ZZ 88
#define TOK_CMPT_II 89
#define TOK_TRANSPOSE 90
#define TOK_DIAG 91
......@@ -164,6 +164,7 @@ svalue (lhs) ::= ZERO . { lhs = Foam::Zero; }
svalue (lhs) ::= PI LPAREN RPAREN . { lhs = Foam::constant::mathematical::pi; }
svalue (lhs) ::= DEG_TO_RAD LPAREN RPAREN . { lhs = Foam::degToRad(); }
svalue (lhs) ::= RAD_TO_DEG LPAREN RPAREN . { lhs = Foam::radToDeg(); }
svalue (lhs) ::= ARG LPAREN RPAREN . { lhs = driver->argValue(); }
dnl svalue (lhs) ::= TIME LPAREN RPAREN . { lhs = driver->timeValue(); }
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -290,6 +290,7 @@ static int driverTokenType
"true" =>{ EMIT_TOKEN(LTRUE); };
"false" =>{ EMIT_TOKEN(LFALSE); };
"tensor::I" =>{ EMIT_TOKEN(UNIT_TENSOR); };
"arg" =>{ EMIT_TOKEN(ARG); };
## "time" =>{ EMIT_TOKEN(TIME); };
## Identifier (field, etc - error if unknown)
......
......@@ -5,8 +5,8 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Original code Copyright (C) 2010-2018 Bernhard Gschaider
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2010-2018 Bernhard Gschaider
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -99,7 +99,7 @@ class fvExprDriver
static bool cacheSets_;
// Protected Data
// Private Data
// Stored Data
......@@ -431,7 +431,7 @@ public:
virtual label pointSize() const = 0;
// Mesh Related
// Globals, Mesh Related
//- The Time associated with the mesh
const Time& runTime() const;
......
......@@ -5,8 +5,8 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Original code Copyright (C) 2011-2018 Bernhard Gschaider
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2011-2018 Bernhard Gschaider
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -53,6 +53,25 @@ Foam::expressions::patchExprFieldBase::getFvPatch(const facePointPatch& pp)
}
const Foam::fvPatch&
Foam::expressions::patchExprFieldBase::getFvPatch(const polyPatch& pp)
{
const polyMesh& pmesh = pp.boundaryMesh().mesh();
const fvMesh* meshptr = isA<fvMesh>(pmesh);
if (!meshptr)
{
FatalErrorInFunction
<< "Poly patch not attached to a base fvMesh, "
<< "cannot use patch expressions" << nl << endl
<< exit(FatalError);
}
return meshptr->boundary()[pp.index()];
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::expressions::patchExprFieldBase::patchExprFieldBase()
......@@ -82,9 +101,9 @@ Foam::expressions::patchExprFieldBase::patchExprFieldBase
bool isPointVal
)
:
debug_(dict.lookupOrDefault("debug", false)),
debug_(dict.getOrDefault("debug", false)),
allowGradient_(allowGradient),
evalOnConstruct_(dict.lookupOrDefault<bool>("evalOnConstruct", false)),
evalOnConstruct_(dict.getOrDefault<bool>("evalOnConstruct", false)),
valueExpr_(),
gradExpr_(),
fracExpr_()
......
......@@ -5,8 +5,8 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Original code Copyright (C) 2011-2018 Bernhard Gschaider
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2011-2018 Bernhard Gschaider
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -58,6 +58,7 @@ namespace Foam
// Forward Declarations
class facePointPatch;
class fvPatch;
class polyPatch;
namespace expressions
{
......@@ -91,10 +92,13 @@ public:
//- Find (guess) fvPatch from a pointPatch
static const fvPatch& getFvPatch(const facePointPatch& fp);
//- Find (guess) fvPatch from a polyPatch
static const fvPatch& getFvPatch(const polyPatch& pp);
// Constructors
//- Null constructor
//- Default construct
patchExprFieldBase();
//- Construct with specified gradient handling
......
......@@ -25,86 +25,87 @@
#define TOK_RPAREN 25
#define TOK_DEG_TO_RAD 26
#define TOK_RAD_TO_DEG 27
#define TOK_TIME 28
#define TOK_SCALAR_ID 29
#define TOK_SSCALAR_ID 30
#define TOK_MIN 31
#define TOK_COMMA 32
#define TOK_MAX 33
#define TOK_SUM 34
#define TOK_AVERAGE 35
#define TOK_EXP 36
#define TOK_LOG 37
#define TOK_LOG10 38
#define TOK_SQR 39
#define TOK_SQRT 40
#define TOK_CBRT 41
#define TOK_SIN 42
#define TOK_COS 43
#define TOK_TAN 44
#define TOK_ASIN 45
#define TOK_ACOS 46
#define TOK_ATAN 47
#define TOK_SINH 48
#define TOK_COSH 49
#define TOK_TANH 50
#define TOK_POW 51
#define TOK_ATAN2 52
#define TOK_POS 53
#define TOK_NEG 54
#define TOK_POS0 55
#define TOK_NEG0 56
#define TOK_SIGN 57
#define TOK_FLOOR 58
#define TOK_CEIL 59
#define TOK_ROUND 60
#define TOK_HYPOT 61
#define TOK_RAND 62
#define TOK_VECTOR_ID 63
#define TOK_SVECTOR_ID 64
#define TOK_SPH_TENSOR_ID 65
#define TOK_SSPH_TENSOR_ID 66
#define TOK_SYM_TENSOR_ID 67
#define TOK_SSYM_TENSOR_ID 68
#define TOK_UNIT_TENSOR 69
#define TOK_TENSOR_ID 70
#define TOK_STENSOR_ID 71
#define TOK_LTRUE 72
#define TOK_LFALSE 73
#define TOK_BOOL 74
#define TOK_SBOOL_ID 75
#define TOK_FACE_AREA 76
#define TOK_FACE_EXPR 77
#define TOK_WEIGHT_AVERAGE 78
#define TOK_WEIGHT_SUM 79
#define TOK_POINT_EXPR 80
#define TOK_PSCALAR_ID 81
#define TOK_PVECTOR_ID 82
#define TOK_PSPH_TENSOR_ID 83
#define TOK_PSYM_TENSOR_ID 84
#define TOK_PTENSOR_ID 85
#define TOK_PBOOL_ID 86
#define TOK_POINTS 87
#define TOK_MAG 88
#define TOK_MAGSQR 89
#define TOK_VECTOR 90
#define TOK_TENSOR 91
#define TOK_SYM_TENSOR 92
#define TOK_SPH_TENSOR 93
#define TOK_CMPT_X 94
#define TOK_CMPT_Y 95
#define TOK_CMPT_Z 96
#define TOK_CMPT_XX 97
#define TOK_CMPT_XY 98
#define TOK_CMPT_XZ 99
#define TOK_CMPT_YX 100
#define TOK_CMPT_YY 101
#define TOK_CMPT_YZ 102
#define TOK_CMPT_ZX 103
#define TOK_CMPT_ZY 104
#define TOK_CMPT_ZZ 105
#define TOK_CMPT_II 106
#define TOK_TRANSPOSE 107
#define TOK_DIAG 108
#define TOK_POINT_TO_FACE 109
#define TOK_FACE_TO_POINT 110
#define TOK_ARG 28
#define TOK_TIME 29
#define TOK_SCALAR_ID 30
#define TOK_SSCALAR_ID 31
#define TOK_MIN 32
#define TOK_COMMA 33
#define TOK_MAX 34
#define TOK_SUM 35
#define TOK_AVERAGE 36
#define TOK_EXP 37
#define TOK_LOG 38
#define TOK_LOG10 39
#define TOK_SQR 40
#define TOK_SQRT 41
#define TOK_CBRT 42
#define TOK_SIN 43
#define TOK_COS 44
#define TOK_TAN 45
#define TOK_ASIN 46
#define TOK_ACOS 47
#define TOK_ATAN 48
#define TOK_SINH 49
#define TOK_COSH 50
#define TOK_TANH 51
#define TOK_POW 52
#define TOK_ATAN2 53
#define TOK_POS 54
#define TOK_NEG 55
#define TOK_POS0 56
#define TOK_NEG0 57
#define TOK_SIGN 58
#define TOK_FLOOR 59
#define TOK_CEIL 60
#define TOK_ROUND 61
#define TOK_HYPOT 62
#define TOK_RAND 63
#define TOK_VECTOR_ID 64
#define TOK_SVECTOR_ID 65
#define TOK_SPH_TENSOR_ID 66
#define TOK_SSPH_TENSOR_ID 67
#define TOK_SYM_TENSOR_ID 68
#define TOK_SSYM_TENSOR_ID 69
#define TOK_UNIT_TENSOR 70
#define TOK_TENSOR_ID 71
#define TOK_STENSOR_ID 72
#define TOK_LTRUE 73
#define TOK_LFALSE 74
#define TOK_BOOL 75
#define TOK_SBOOL_ID 76
#define TOK_FACE_AREA 77
#define TOK_FACE_EXPR 78
#define TOK_WEIGHT_AVERAGE 79
#define TOK_WEIGHT_SUM 80
#define TOK_POINT_EXPR 81
#define TOK_PSCALAR_ID 82
#define TOK_PVECTOR_ID 83
#define TOK_PSPH_TENSOR_ID 84
#define TOK_PSYM_TENSOR_ID 85
#define TOK_PTENSOR_ID 86
#define TOK_PBOOL_ID 87
#define TOK_POINTS 88
#define TOK_MAG 89
#define TOK_MAGSQR 90
#define TOK_VECTOR 91
#define TOK_TENSOR 92
#define TOK_SYM_TENSOR 93
#define TOK_SPH_TENSOR 94
#define TOK_CMPT_X 95
#define TOK_CMPT_Y 96
#define TOK_CMPT_Z 97
#define TOK_CMPT_XX 98
#define TOK_CMPT_XY 99
#define TOK_CMPT_XZ 100
#define TOK_CMPT_YX 101
#define TOK_CMPT_YY 102
#define TOK_CMPT_YZ 103
#define TOK_CMPT_ZX 104
#define TOK_CMPT_ZY 105
#define TOK_CMPT_ZZ 106
#define TOK_CMPT_II 107
#define TOK_TRANSPOSE 108
#define TOK_DIAG 109
#define TOK_POINT_TO_FACE 110
#define TOK_FACE_TO_POINT 111
......@@ -118,6 +118,7 @@ svalue (lhs) ::= ZERO . { lhs = Foam::Zero; }
svalue (lhs) ::= PI LPAREN RPAREN . { lhs = Foam::constant::mathematical::pi; }
svalue (lhs) ::= DEG_TO_RAD LPAREN RPAREN . { lhs = Foam::degToRad(); }
svalue (lhs) ::= RAD_TO_DEG LPAREN RPAREN . { lhs = Foam::radToDeg(); }
svalue (lhs) ::= ARG LPAREN RPAREN . { lhs = driver->argValue(); }
svalue (lhs) ::= TIME LPAREN RPAREN . { lhs = driver->timeValue(); }
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -416,6 +416,7 @@ static int driverTokenType
"true" =>{ EMIT_TOKEN(LTRUE); };
"false" =>{ EMIT_TOKEN(LFALSE); };
"tensor::I" =>{ EMIT_TOKEN(UNIT_TENSOR); };
"arg" =>{ EMIT_TOKEN(ARG); };
"time" =>{ EMIT_TOKEN(TIME); };
## Identifier (field, etc - error if unknown)
......
......@@ -25,95 +25,96 @@
#define TOK_RPAREN 25
#define TOK_DEG_TO_RAD 26
#define TOK_RAD_TO_DEG 27
#define TOK_TIME 28
#define TOK_SCALAR_ID 29
#define TOK_MIN 30
#define TOK_COMMA 31
#define TOK_MAX 32
#define TOK_SUM 33
#define TOK_AVERAGE 34
#define TOK_EXP 35
#define TOK_LOG 36
#define TOK_LOG10 37
#define TOK_SQR 38
#define TOK_SQRT 39
#define TOK_CBRT 40
#define TOK_SIN 41
#define TOK_COS 42
#define TOK_TAN 43
#define TOK_ASIN 44
#define TOK_ACOS 45
#define TOK_ATAN 46
#define TOK_SINH 47
#define TOK_COSH 48
#define TOK_TANH 49
#define TOK_POW 50
#define TOK_ATAN2 51
#define TOK_POS 52
#define TOK_NEG 53
#define TOK_POS0 54
#define TOK_NEG0 55
#define TOK_SIGN 56
#define TOK_FLOOR 57
#define TOK_CEIL 58
#define TOK_ROUND 59
#define TOK_HYPOT 60
#define TOK_RAND 61
#define TOK_VECTOR_ID 62
#define TOK_SPH_TENSOR_ID 63