Function1Expression.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2020-2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::Function1Types::Function1Expression
28 
29 Description
30  Function1 with values supplied by a parsed expression.
31 
32 Usage
33  Example:
34  \verbatim
35  <patchName>
36  {
37  type uniformFixedValue;
38  uniformValue
39  {
40  type expression;
41 
42  // optional variables for use within the expression
43  variables
44  (
45  "start = 0.5"
46  "stop = 1"
47  );
48 
49  // A step function
50  expression
51  #{
52  mag(arg() > start && arg() < stop) * vector(1, 0, 0)
53  #};
54  }
55  }
56  \endverbatim
57 
58 Very much like '\#eval' but runtime
59 
60 See also
61  Foam::exprFixedValueFvPatchField
62 
63 SourceFiles
64  Function1Expression.C
65 
66 \*---------------------------------------------------------------------------*/
67 
68 #ifndef Function1Types_expression_H
69 #define Function1Types_expression_H
70 
71 #include "Function1.H"
72 #include "fieldExprDriver.H"
73 
74 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
75 
76 namespace Foam
77 {
78 namespace Function1Types
79 {
80 
81 /*---------------------------------------------------------------------------*\
82  Class Function1Expression Declaration
83 \*---------------------------------------------------------------------------*/
84 
85 template<class Type>
87 :
88  public Function1<Type>
89 {
90  // Private Data
91 
92  //- Dictionary contents for the function
93  const dictionary dict_;
94 
95  //- The expression
96  expressions::exprString valueExpr_;
97 
98  //- The expression driver
99  mutable expressions::fieldExprDriver driver_;
100 
101 
102 public:
103 
104  //- Runtime type information
105  TypeName("expression");
106 
107 
108  // Generated Methods
109 
110  //- No copy assignment
111  void operator=(const Function1Expression<Type>&) = delete;
112 
113 
114  // Constructors
115 
116  //- Construct from entry name, dictionary and optional registry
118  (
119  const word& entryName,
120  const dictionary& dict,
121  const objectRegistry* obrPtr = nullptr
122  );
123 
124  //- Copy construct
125  explicit Function1Expression(const Function1Expression<Type>& rhs);
126 
127  //- Construct and return a clone
128  virtual tmp<Function1<Type>> clone() const
129  {
131  }
132 
133 
134  //- Destructor
135  virtual ~Function1Expression() = default;
136 
137 
138  // Member Functions
139 
140  //- Return value.
141  // The parameter 'x' is accessible as 'arg' in the function
142  virtual Type value(const scalar x) const;
143 
144  //- Integrate between two values
145  virtual Type integrate
146  (
147  const scalar x1,
148  const scalar x2
149  ) const;
150 
151  //- Write in dictionary format
152  virtual void writeData(Ostream& os) const;
153 };
154 
155 
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 
158 } // End namespace Function1Types
159 } // End namespace Foam
160 
161 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 
163 #ifdef NoRepository
164  #include "Function1Expression.C"
165 #endif
166 
167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168 
169 #endif
170 
171 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Function1::entryName
const word & entryName
Definition: Function1.H:133
Function1.H
Foam::expressions::fieldExpr::parseDriver
Driver for generic primitive field expressions.
Definition: fieldExprDriver.H:82
Foam::Function1::dict
const word const dictionary & dict
Definition: Function1.H:134
Foam::Function1Types::Function1Expression::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Function1Expression.C:126
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: propellerInfo.H:291
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::Function1::obrPtr
const word const dictionary const objectRegistry * obrPtr
Definition: Function1.H:136
Foam::Function1Types::Function1Expression::clone
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
Definition: Function1Expression.H:127
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::Function1Types::Function1Expression::integrate
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: Function1Expression.C:114
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
fieldExprDriver.H
Foam::Function1Types::Function1Expression::Function1Expression
Function1Expression(const word &entryName, const dictionary &dict, const objectRegistry *obrPtr=nullptr)
Construct from entry name, dictionary and optional registry.
Definition: Function1Expression.C:34
Foam::Function1Types::Function1Expression::value
virtual Type value(const scalar x) const
Return value.
Definition: Function1Expression.C:81
Foam::Function1Types::Function1Expression::TypeName
TypeName("expression")
Runtime type information.
Foam::Function1Types::Function1Expression::~Function1Expression
virtual ~Function1Expression()=default
Destructor.
Foam::expressions::exprString
Definition: exprString.H:60
Function1Expression.C
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::Function1Types::Function1Expression
Function1 with values supplied by a parsed expression.
Definition: Function1Expression.H:85
Foam::Function1Types::Function1Expression::operator=
void operator=(const Function1Expression< Type > &)=delete
No copy assignment.