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-2021 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
37SourceFiles
38 ConstantField.C
39
40\*---------------------------------------------------------------------------*/
41
42#ifndef PatchFunction1Types_ConstantField_H
43#define PatchFunction1Types_ConstantField_H
44
45#include "PatchFunction1.H"
46
47// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48
49namespace Foam
50{
51namespace PatchFunction1Types
52{
53
54/*---------------------------------------------------------------------------*\
55 Class ConstantField Declaration
56\*---------------------------------------------------------------------------*/
57
58template<class Type>
59class 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
91public:
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 {
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 //- Value is independent of x
174 virtual inline bool constant() const
175 {
176 return true;
177 }
178
179 //- Is value uniform (i.e. independent of coordinate)
180 virtual inline bool uniform() const
181 {
182 return isUniform_ && PatchFunction1<Type>::uniform();
183 }
184
185
186 // Evaluation
187
188 //- Return constant value
189 virtual inline tmp<Field<Type>> value(const scalar x) const;
190
191 //- Integrate between two values
192 virtual inline tmp<Field<Type>> integrate
193 (
194 const scalar x1,
195 const scalar x2
196 ) const;
197
198
199 // Mapping
200
201 //- Map (and resize as needed) from self given a mapping object
202 virtual void autoMap(const FieldMapper& mapper);
203
204 //- Reverse map the given PatchFunction1 onto this PatchFunction1
205 virtual void rmap
206 (
207 const PatchFunction1<Type>& pf1,
208 const labelList& addr
209 );
210
211
212 // I-O
213
214 //- Write in dictionary format
215 virtual void writeData(Ostream& os) const;
216};
217
218
219// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220
221} // End namespace PatchFunction1Types
222} // End namespace Foam
223
224// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225
226#include "ConstantFieldI.H"
227
228#ifdef NoRepository
229 #include "ConstantField.C"
230#endif
231
232// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
233
234#endif
235
236// ************************************************************************* //
Abstract base class to hold the Field mapping addressing and weights.
Definition: FieldMapper.H:50
Generic templated field type.
Definition: Field.H:82
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Templated function that returns a constant value.
Definition: ConstantField.H:61
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
Construct and return a clone setting 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
Construct and return a clone.
TypeName("constant")
Runtime type information.
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
const polyPatch & pp
const polyPatch const word const word const dictionary const bool faceValues
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:70
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73