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 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
126  explicit PatchExprField(const PatchExprField<Type>& rhs);
127 
128  //- Copy construct setting patch
129  explicit PatchExprField
130  (
131  const PatchExprField<Type>& rhs,
132  const polyPatch& pp
133  );
134 
135  //- Construct and return a clone
136  virtual tmp<PatchFunction1<Type>> clone() const
137  {
139  (
140  new PatchExprField<Type>(*this)
141  );
142  }
143 
144  //- Construct and return a clone setting patch
145  virtual tmp<PatchFunction1<Type>> clone(const polyPatch& pp) const
146  {
148  (
149  new PatchExprField<Type>(*this, pp)
150  );
151  }
152 
153 
154  //- Destructor
155  virtual ~PatchExprField() = default;
156 
157 
158  // Member Functions
159 
160  // Evaluation
161 
162  //- Return value.
163  // The parameter 'x' is accessible as 'arg' in the function
164  virtual tmp<Field<Type>> value(const scalar x) const;
165 
166  //- Is value constant (i.e. independent of x)
167  virtual inline bool constant() const
168  {
169  return false;
170  }
171 
172  //- Is value uniform (i.e. independent of coordinate)
173  virtual inline bool uniform() const
174  {
175  return false;
176  }
177 
178  //- Integrate between two values
179  virtual tmp<Field<Type>> integrate
180  (
181  const scalar x1,
182  const scalar x2
183  ) const;
184 
185 
186  // Mapping
187 
188  //- Map (and resize as needed) from self given a mapping object
189  virtual void autoMap(const FieldMapper& mapper);
190 
191  //- Reverse map the given PatchFunction1 onto this PatchFunction1
192  virtual void rmap
193  (
194  const PatchFunction1<Type>& pf1,
195  const labelList& addr
196  );
197 
198 
199  // IO
200 
201  //- Write in dictionary format
202  virtual void writeData(Ostream& os) const;
203 };
204 
205 
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 
208 } // End namespace PatchFunction1Types
209 } // End namespace Foam
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 #ifdef NoRepository
214  #include "PatchFunction1Expression.C"
215 #endif
216 
217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
218 
219 #endif
220 
221 // ************************************************************************* //
Foam::PatchFunction1Types::PatchExprField::clone
virtual tmp< PatchFunction1< Type > > clone() const
Construct and return a clone.
Definition: PatchFunction1Expression.H:135
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
patchExprDriver.H
PatchFunction1.H
Foam::PatchFunction1Types::PatchExprField::integrate
virtual tmp< Field< Type > > integrate(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: PatchFunction1Expression.C:117
Foam::PatchFunction1Types::PatchExprField::value
virtual tmp< Field< Type > > value(const scalar x) const
Return value.
Definition: PatchFunction1Expression.C:96
Foam::FieldMapper
Abstract base class to hold the Field mapping addressing and weights.
Definition: FieldMapper.H:49
PatchFunction1Expression.C
Foam::PatchFunction1::entryName
const polyPatch const word const word & entryName
Definition: PatchFunction1.H:118
Foam::PatchFunction1Types::PatchExprField::rmap
virtual void rmap(const PatchFunction1< Type > &pf1, const labelList &addr)
Reverse map the given PatchFunction1 onto this PatchFunction1.
Definition: PatchFunction1Expression.C:139
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::PatchFunction1Types::PatchExprField::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: PatchFunction1Expression.C:150
Foam::PatchFunction1Types::PatchExprField::clone
virtual tmp< PatchFunction1< Type > > clone(const polyPatch &pp) const
Construct and return a clone setting patch.
Definition: PatchFunction1Expression.H:144
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::PatchFunction1Types::PatchExprField::PatchExprField
PatchExprField(const polyPatch &pp, const word &redirectType, const word &entryName, const dictionary &dict, const bool faceValues=true)
Construct from patch, entry name and dictionary.
Definition: PatchFunction1Expression.C:35
os
OBJstream os(runTime.globalPath()/outputName)
Foam::PatchFunction1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: PatchFunction1.H:60
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::expressions::patchExpr::parseDriver
Driver for patch expressions.
Definition: patchExprDriver.H:159
Foam::PatchFunction1::pp
const polyPatch & pp
Definition: PatchFunction1.H:116
Foam::PatchFunction1Types::PatchExprField::autoMap
virtual void autoMap(const FieldMapper &mapper)
Map (and resize as needed) from self given a mapping object.
Definition: PatchFunction1Expression.C:129
Foam::PatchFunction1Types::PatchExprField
PatchFunction1 with values supplied by a parsed expression.
Definition: PatchFunction1Expression.H:83
Foam::PatchFunction1Types::PatchExprField::~PatchExprField
virtual ~PatchExprField()=default
Destructor.
Foam::PatchFunction1::dict
const polyPatch const word const word const dictionary & dict
Definition: PatchFunction1.H:119
Foam::List< label >
Foam::expressions::exprString
Definition: exprString.H:60
Foam::PatchFunction1::faceValues
const polyPatch const word const word const dictionary const bool faceValues
Definition: PatchFunction1.H:121
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::PatchFunction1Types::PatchExprField::uniform
virtual bool uniform() const
Is value uniform (i.e. independent of coordinate)
Definition: PatchFunction1Expression.H:172
Foam::PatchFunction1Types::PatchExprField::TypeName
TypeName("expression")
Runtime type information.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::PatchFunction1Types::PatchExprField::constant
virtual bool constant() const
Is value constant (i.e. independent of x)
Definition: PatchFunction1Expression.H:166
Foam::PatchFunction1Types::PatchExprField::operator=
void operator=(const PatchExprField< Type > &)=delete
No copy assignment.