Loading...
Searching...
No Matches
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-2024 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
26Class
27 Foam::PatchFunction1Types::ConstantField
28
29Description
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
45SourceFiles
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
57namespace Foam
58{
59namespace PatchFunction1Types
60{
61
62/*---------------------------------------------------------------------------*\
63 Class ConstantField Declaration
64\*---------------------------------------------------------------------------*/
65
66template<class Type>
67class 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
100public:
101
102 //- Runtime type information
103 TypeName("constant");
104
105
106 // Constructors
107
108 //- Construct from a uniform value
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 setting patch
151 explicit ConstantField
152 (
154 const polyPatch& pp
155 );
156
157 //- Copy construct
158 explicit ConstantField(const ConstantField<Type>& rhs);
159
160 //- Return a clone
161 virtual tmp<PatchFunction1<Type>> clone() const
162 {
163 return PatchFunction1<Type>::Clone(*this);
164 }
165
166 //- Return a clone, setting the patch
167 virtual tmp<PatchFunction1<Type>> clone(const polyPatch& pp) const
168 {
169 return PatchFunction1<Type>::Clone(*this, pp);
170 }
171
172
173 //- Destructor
174 virtual ~ConstantField() = default;
175
176
177 // Member Functions
178
179 //- Value is independent of x
180 virtual inline bool constant() const
181 {
182 return true;
183 }
184
185 //- Is value uniform (i.e. independent of coordinate)
186 virtual inline bool uniform() const
187 {
188 return isUniform_ && PatchFunction1<Type>::uniform();
189 }
191
192 // Evaluation
193
194 //- Return constant value
195 virtual inline tmp<Field<Type>> value(const scalar x) const;
196
197 //- Integrate between two values
198 virtual inline tmp<Field<Type>> integrate
200 const scalar x1,
201 const scalar x2
202 ) const;
203
204
205 // Mapping
206
207 //- Map (and resize as needed) from self given a mapping object
208 virtual void autoMap(const FieldMapper& mapper);
209
210 //- Reverse map the given PatchFunction1 onto this PatchFunction1
211 virtual void rmap
212 (
213 const PatchFunction1<Type>& pf1,
214 const labelList& addr
215 );
216
217
218 // I-O
219
220 //- Write in dictionary format
221 virtual void writeData(Ostream& os) const;
222};
223
224
225// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226
227} // End namespace PatchFunction1Types
228} // End namespace Foam
229
230// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
231
232#include "ConstantFieldI.H"
233
234#ifdef NoRepository
235 #include "ConstantField.C"
236#endif
237
238// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
239
240#endif
241
242// ************************************************************************* //
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Abstract base class to hold the Field mapping addressing and weights.
Definition FieldMapper.H:44
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
virtual tmp< Field< Type > > integrate(const scalar x1, const scalar x2) const
Integrate between two values.
virtual bool uniform() const
Is value uniform (i.e. independent of coordinate).
virtual void rmap(const PatchFunction1< Type > &pf1, const labelList &addr)
Reverse map the given PatchFunction1 onto this PatchFunction1.
virtual ~ConstantField()=default
Destructor.
virtual void autoMap(const FieldMapper &mapper)
Map (and resize as needed) from self given a mapping object.
virtual void writeData(Ostream &os) const
Write in dictionary format.
virtual tmp< PatchFunction1< Type > > clone(const polyPatch &pp) const
Return a clone, setting the patch.
virtual bool constant() const
Value is independent of x.
virtual tmp< Field< Type > > value(const scalar x) const
Return constant value.
virtual tmp< PatchFunction1< Type > > clone() const
Return a clone.
TypeName("constant")
Runtime type information.
ConstantField(const polyPatch &pp, const word &entryName, const Type &uniformValue, const dictionary &dict=dictionary::null, const bool faceValues=true)
Construct from a uniform value.
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
const polyPatch const word const word & entryName
virtual bool uniform() const =0
Is value uniform (i.e. independent of coordinate).
const polyPatch const word const word const dictionary & dict
static tmp< PatchFunction1< Type > > Clone(const Derived &fun)
Clone a PatchFunction1.
const polyPatch & pp
const polyPatch const word const word const dictionary const bool faceValues
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition dictionary.H:487
A keyword and a list of tokens is an 'entry'.
Definition entry.H:66
A patch is a list of labels that address the faces in the global face list.
Definition polyPatch.H:73
A class for managing temporary objects.
Definition tmp.H:75
A class for handling words, derived from Foam::string.
Definition word.H:66
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition List.H:62
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68