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