PatchFunction1Expression.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-2024 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::PatchFunction1Types::PatchExprField
28 
29 Description
30  PatchFunction1 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  scalar(arg() > start && arg() < stop) * vector(1, 0, 0)
53  #};
54  }
55  }
56  \endverbatim
57 
58 See also
59  Foam::exprFixedValueFvPatchField
60 
61 SourceFiles
62  PatchFunction1Expression.C
63 
64 \*---------------------------------------------------------------------------*/
65 
66 #ifndef PatchFunction1Types_expression_H
67 #define PatchFunction1Types_expression_H
68 
69 #include "PatchFunction1.H"
70 #include "patchExprDriver.H"
71 
72 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
73 
74 namespace Foam
75 {
76 namespace PatchFunction1Types
77 {
78 
79 /*---------------------------------------------------------------------------*\
80  Class PatchExprField Declaration
81 \*---------------------------------------------------------------------------*/
82 
83 template<class Type>
84 class PatchExprField
85 :
86  public PatchFunction1<Type>
87 {
88  // Private Data
89 
90  //- Dictionary contents for the function
91  const dictionary dict_;
92 
93  //- The expression
94  expressions::exprString valueExpr_;
95 
96  //- The expression driver
98 
99 
100 public:
101 
102  //- Runtime type information
103  TypeName("expression");
104 
105 
106  // Generated Methods
107 
108  //- No copy assignment
109  void operator=(const PatchExprField<Type>&) = delete;
110 
111 
112  // Constructors
113 
114  //- Construct from patch, entry name and dictionary
115  // The patch must correspond to an fvPatch!
117  (
118  const polyPatch& pp,
119  const word& redirectType,
120  const word& entryName,
121  const dictionary& dict,
122  const bool faceValues = true
123  );
124 
125  //- Copy construct setting patch
126  explicit PatchExprField
127  (
128  const PatchExprField<Type>& rhs,
129  const polyPatch& pp
130  );
131 
132  //- Copy construct
133  explicit PatchExprField(const PatchExprField<Type>& rhs);
134 
135  //- Return a clone
136  virtual tmp<PatchFunction1<Type>> clone() const
137  {
138  return PatchFunction1<Type>::Clone(*this);
139  }
140 
141  //- Return a clone, setting the patch
142  virtual tmp<PatchFunction1<Type>> clone(const polyPatch& pp) const
143  {
144  return PatchFunction1<Type>::Clone(*this, pp);
145  }
146 
147 
148  //- Destructor
149  virtual ~PatchExprField() = default;
151 
152  // Member Functions
153 
154  // Evaluation
155 
156  //- Return value.
157  // The parameter 'x' is accessible as 'arg' in the function
158  virtual tmp<Field<Type>> value(const scalar x) const;
159 
160  //- Is value constant (i.e. independent of x)
161  virtual inline bool constant() const
162  {
163  return false;
164  }
165 
166  //- Is value uniform (i.e. independent of coordinate)
167  virtual inline bool uniform() const
168  {
169  return false;
170  }
171 
172  //- Integrate between two values
173  virtual tmp<Field<Type>> integrate
174  (
175  const scalar x1,
176  const scalar x2
177  ) const;
178 
179 
180  // Mapping
181 
182  //- Map (and resize as needed) from self given a mapping object
183  virtual void autoMap(const FieldMapper& mapper);
185  //- Reverse map the given PatchFunction1 onto this PatchFunction1
186  virtual void rmap
187  (
188  const PatchFunction1<Type>& pf1,
189  const labelList& addr
190  );
191 
193  // IO
194 
195  //- Write in dictionary format
196  virtual void writeData(Ostream& os) const;
197 };
198 
199 
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 
202 } // End namespace PatchFunction1Types
203 } // End namespace Foam
204 
205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
206 
207 #ifdef NoRepository
208  #include "PatchFunction1Expression.C"
209 #endif
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 #endif
214 
215 // ************************************************************************* //
PatchFunction1 with values supplied by a parsed expression.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
TypeName("expression")
Runtime type information.
virtual tmp< Field< Type > > integrate(const scalar x1, const scalar x2) const
Integrate between two values.
Driver for patch expressions.
const polyPatch const word const word const dictionary & dict
virtual void rmap(const PatchFunction1< Type > &pf1, const labelList &addr)
Reverse map the given PatchFunction1 onto this PatchFunction1.
void operator=(const PatchExprField< Type > &)=delete
No copy assignment.
Abstract base class to hold the Field mapping addressing and weights.
Definition: FieldMapper.H:43
virtual tmp< PatchFunction1< Type > > clone() const
Return a clone.
A class for handling words, derived from Foam::string.
Definition: word.H:63
A variant of Foam::string with expansion of dictionary variables into a comma-separated form...
Definition: exprString.H:55
virtual void writeData(Ostream &os) const
Write in dictionary format.
virtual tmp< Field< Type > > value(const scalar x) const
Return value.
const polyPatch const word const word & entryName
bool faceValues() const noexcept
Generate face or point values on patch?
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
virtual ~PatchExprField()=default
Destructor.
OBJstream os(runTime.globalPath()/outputName)
virtual void autoMap(const FieldMapper &mapper)
Map (and resize as needed) from self given a mapping object.
virtual bool constant() const
Is value constant (i.e. independent of x)
virtual bool uniform() const
Is value uniform (i.e. independent of coordinate)
A class for managing temporary objects.
Definition: HashPtrTable.H:50
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:69
PatchExprField(const polyPatch &pp, const word &redirectType, const word &entryName, const dictionary &dict, const bool faceValues=true)
Construct from patch, entry name and dictionary.
static tmp< PatchFunction1< Type > > Clone(const Derived &fun)
Clone a PatchFunction1.
Namespace for OpenFOAM.
const polyPatch & pp