ConstantField.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) 2018-2022 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::ConstantField
28 
29 Description
30  Templated function that returns a constant value.
31 
32  Usage - for entry <entryName> returning the value <value>:
33  \verbatim
34  <entryName> constant <value>;
35  \endverbatim
36  or
37  \verbatim
38  <entryName>
39  {
40  type constant;
41  value <value>;
42  }
43  \endverbatim
44 
45 SourceFiles
46  ConstantField.C
47 
48 \*---------------------------------------------------------------------------*/
49 
50 #ifndef Foam_PatchFunction1Types_ConstantField_H
51 #define Foam_PatchFunction1Types_ConstantField_H
52 
53 #include "PatchFunction1.H"
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 namespace PatchFunction1Types
60 {
61 
62 /*---------------------------------------------------------------------------*\
63  Class ConstantField Declaration
64 \*---------------------------------------------------------------------------*/
65 
66 template<class Type>
67 class ConstantField
68 :
69  public PatchFunction1<Type>
70 {
71  // Private Data
72 
73  //- Is uniform?
74  bool isUniform_;
75 
76  //- If uniform the uniformValue
77  Type uniformValue_;
78 
79  //- ConstantField value
80  Field<Type> value_;
81 
82 
83  // Private Member Functions
84 
85  //- Helper to read value from dictionary entry
86  static Field<Type> getValue
87  (
88  const word& entryName,
89  const entry* eptr, // primitive or dictionary entry
90  const dictionary& dict, // For error context or for content
91  const label len,
92  bool& isUniform,
93  Type& uniformValue
94  );
95 
96  //- No copy assignment
97  void operator=(const ConstantField<Type>&) = delete;
98 
99 
100 public:
101 
102  //- Runtime type information
103  TypeName("constant");
104 
105 
106  // Constructors
107 
108  //- Construct from a uniform value
110  (
111  const polyPatch& pp,
112  const word& entryName,
113  const Type& uniformValue,
115  const bool faceValues = true
116  );
117 
118  //- Construct from components
120  (
121  const polyPatch& pp,
122  const word& entryName,
123  const bool isUniform,
124  const Type& uniformValue,
125  const Field<Type>& fieldValues,
127  const bool faceValues = true
128  );
129 
130  //- Construct from entry name and dictionary
132  (
133  const polyPatch& pp,
134  const word& redirectType,
135  const word& entryName,
136  const dictionary& dict,
137  const bool faceValues = true
138  );
139 
140  //- Construct from primitive entry, entry name and dictionary
142  (
143  const polyPatch& pp,
144  const entry* eptr,
145  const word& entryName,
146  const dictionary& dict,
147  const bool faceValues = true
148  );
149 
150  //- Copy construct
151  explicit ConstantField(const ConstantField<Type>& rhs);
152 
153  //- Copy construct setting patch
154  explicit ConstantField
155  (
156  const ConstantField<Type>& rhs,
157  const polyPatch& pp
158  );
159 
160  //- Construct and return a clone
161  virtual tmp<PatchFunction1<Type>> clone() const
162  {
163  return tmp<PatchFunction1<Type>>(new ConstantField<Type>(*this));
164  }
165 
166  //- Construct and return a clone setting patch
167  virtual tmp<PatchFunction1<Type>> clone(const polyPatch& pp) const
168  {
170  (
171  new ConstantField<Type>(*this, pp)
172  );
173  }
174 
175 
176  //- Destructor
177  virtual ~ConstantField() = default;
178 
179 
180  // Member Functions
181 
182  //- Value is independent of x
183  virtual inline bool constant() const
184  {
185  return true;
186  }
187 
188  //- Is value uniform (i.e. independent of coordinate)
189  virtual inline bool uniform() const
190  {
191  return isUniform_ && PatchFunction1<Type>::uniform();
192  }
193 
194 
195  // Evaluation
196 
197  //- Return constant value
198  virtual inline tmp<Field<Type>> value(const scalar x) const;
199 
200  //- Integrate between two values
201  virtual inline tmp<Field<Type>> integrate
202  (
203  const scalar x1,
204  const scalar x2
205  ) const;
206 
207 
208  // Mapping
209 
210  //- Map (and resize as needed) from self given a mapping object
211  virtual void autoMap(const FieldMapper& mapper);
212 
213  //- Reverse map the given PatchFunction1 onto this PatchFunction1
214  virtual void rmap
215  (
216  const PatchFunction1<Type>& pf1,
217  const labelList& addr
218  );
219 
220 
221  // I-O
222 
223  //- Write in dictionary format
224  virtual void writeData(Ostream& os) const;
225 };
226 
227 
228 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
229 
230 } // End namespace PatchFunction1Types
231 } // End namespace Foam
232 
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 
235 #include "ConstantFieldI.H"
236 
237 #ifdef NoRepository
238  #include "ConstantField.C"
239 #endif
240 
241 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242 
243 #endif
244 
245 // ************************************************************************* //
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual tmp< Field< Type > > value(const scalar x) const
Return constant value.
virtual tmp< Field< Type > > integrate(const scalar x1, const scalar x2) const
Integrate between two values.
virtual bool uniform() const =0
Is value uniform (i.e. independent of coordinate)
virtual tmp< PatchFunction1< Type > > clone() const
Construct and return a clone.
const polyPatch const word const word const dictionary & dict
virtual bool constant() const
Value is independent of x.
Templated function that returns a constant value.
Definition: ConstantField.H:62
ConstantField(const polyPatch &pp, const word &entryName, const Type &uniformValue, const dictionary &dict=dictionary::null, const bool faceValues=true)
Construct from a uniform value.
Definition: ConstantField.C:27
Abstract base class to hold the Field mapping addressing and weights.
Definition: FieldMapper.H:43
virtual void autoMap(const FieldMapper &mapper)
Map (and resize as needed) from self given a mapping object.
Generic templated field type.
Definition: Field.H:62
A class for handling words, derived from Foam::string.
Definition: word.H:63
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:474
virtual ~ConstantField()=default
Destructor.
virtual void rmap(const PatchFunction1< Type > &pf1, const labelList &addr)
Reverse map the given PatchFunction1 onto this PatchFunction1.
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...
OBJstream os(runTime.globalPath()/outputName)
virtual bool uniform() const
Is value uniform (i.e. independent of coordinate)
TypeName("constant")
Runtime type information.
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
virtual void writeData(Ostream &os) const
Write in dictionary format.
Namespace for OpenFOAM.
const polyPatch & pp
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:63