Field.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2015-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::Field
29
30Description
31 Generic templated field type.
32
33SourceFiles
34 FieldFunctions.H
35 FieldFunctionsM.H
36 FieldMapper.H
37 FieldI.H
38 FieldM.H
39 Field.C
40 FieldFunctions.C
41 FieldFunctionsM.C
42
43\*---------------------------------------------------------------------------*/
44
45#ifndef Foam_Field_H
46#define Foam_Field_H
47
48#include "tmp.H"
49#include "direction.H"
50#include "labelList.H"
51#include "scalarList.H"
52#include "FieldBase.H"
53#include "VectorSpace.H"
54
55// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56
57namespace Foam
58{
59
60// Forward Declarations
61class FieldMapper;
62class dictionary;
63
64template<class Type> class Field;
65template<class Type> class SubField;
66
67template<class Type>
69
70template<class Type>
72
73
74/*---------------------------------------------------------------------------*\
75 Class Field Declaration
76\*---------------------------------------------------------------------------*/
77
78template<class Type>
79class Field
80:
81 public FieldBase,
82 public List<Type>
83{
84public:
85
86 //- Component type
87 typedef typename pTraits<Type>::cmptType cmptType;
88
89 //- Declare type of subField
91
92
93 // Static Member Functions
94
95 //- Return nullObject reference Field
96 inline static const Field<Type>& null();
97
98
99 // Constructors
100
101 //- Default construct
102 // For temporary fields that are initialised after construction
103 inline constexpr Field() noexcept;
104
105 //- Construct given size
106 // For temporary fields that are initialised after construction
107 inline explicit Field(const label len);
108
109 //- Construct given size and initial value
110 inline Field(const label len, const Type& val);
111
112 //- Construct given size and initial values of zero
113 inline Field(const label len, const Foam::zero);
114
115 //- Construct with length=1, copying the value as the only content
116 inline Field(const Foam::one, const Type& val);
117
118 //- Construct with length=1, moving the value as the only content
119 inline Field(const Foam::one, Type&& val);
120
121 //- Construct with length=1, initializing content to zero
122 inline Field(const Foam::one, const Foam::zero);
123
124 //- Copy construct
125 inline Field(const Field<Type>& fld);
126
127 //- Copy construct from UList<Type>
128 inline explicit Field(const UList<Type>& list);
129
130 //- Copy construct from IndirectList
131 template<class Addr>
132 inline explicit Field(const IndirectListBase<Type, Addr>& list);
133
134 //- Move construct from Field
135 inline Field(Field<Type>&& fld);
136
137 //- Move construct from List
138 inline Field(List<Type>&& list);
139
140 //- Move construct from DynamicList
141 template<int SizeMin>
142 inline Field(DynamicList<Type, SizeMin>&& list);
143
144 //- Construct by 1 to 1 mapping from the given field
145 Field
146 (
147 const UList<Type>& mapF,
148 const labelUList& mapAddressing
149 );
150
151 //- Construct by 1 to 1 mapping from the given tmp field
152 Field
153 (
154 const tmp<Field<Type>>& tmapF,
155 const labelUList& mapAddressing
156 );
157
158 //- Construct by interpolative mapping from the given field
159 Field
160 (
161 const UList<Type>& mapF,
162 const labelListList& mapAddressing,
163 const scalarListList& weights
164 );
165
166 //- Construct by interpolative mapping from the given tmp field
167 Field
168 (
169 const tmp<Field<Type>>& tmapF,
170 const labelListList& mapAddressing,
171 const scalarListList& weights
172 );
173
174 //- Construct by mapping from the given field
175 Field
176 (
177 const UList<Type>& mapF,
178 const FieldMapper& map,
179 const bool applyFlip = true
180 );
181
182 //- Construct by mapping from the given field
183 Field
184 (
185 const UList<Type>& mapF,
186 const FieldMapper& map,
187 const Type& defaultValue,
188 const bool applyFlip = true
189 );
190
191 //- Construct by mapping from the given field
192 Field
193 (
194 const UList<Type>& mapF,
195 const FieldMapper& map,
196 const UList<Type>& defaultValues,
197 const bool applyFlip = true
198 );
199
200 //- Construct by mapping from the given tmp field
201 Field
202 (
203 const tmp<Field<Type>>& tmapF,
204 const FieldMapper& map,
205 const bool applyFlip = true
206 );
207
208 //- Construct by mapping from the given tmp field.
209 //- Uses supplied uniform value for unmapped items
210 Field
211 (
212 const tmp<Field<Type>>& tmapF,
213 const FieldMapper& map,
214 const Type& defaultValue,
215 const bool applyFlip = true
216 );
217
218 //- Construct by mapping from the given tmp field.
219 //- Uses supplied values for unmapped items
220 Field
221 (
222 const tmp<Field<Type>>& tmapF,
223 const FieldMapper& map,
224 const UList<Type>& defaultValues,
225 const bool applyFlip = true
226 );
227
228 //- Copy construct or re-use as specified.
229 inline Field(Field<Type>& fld, bool reuse);
230
231 //- Copy or move construct from tmp
232 inline Field(const tmp<Field<Type>>& tfld);
233
234 //- Construct from Istream
235 inline Field(Istream& is);
236
237 //- Construct from a dictionary entry
238 Field(const word& keyword, const dictionary& dict, const label len);
239
240 //- Clone
241 inline tmp<Field<Type>> clone() const;
242
243 //- Return a pointer to a new Field created on freestore
244 static autoPtr<Field<Type>> New(Istream& is)
245 {
246 return autoPtr<Field<Type>>(new Field<Type>(is));
247 }
248
249 //- Return a pointer to a new calculatedFvPatchFieldField created on
250 //- freestore without setting patchField values
251 template<class Type2>
253 {
254 return tmp<Field<Type>>::New(f.size());
255 }
256
257
258 // Member Functions
259
260 //- 1 to 1 map from the given field
261 void map
262 (
263 const UList<Type>& mapF,
264 const labelUList& mapAddressing
265 );
266
267 //- 1 to 1 map from the given tmp field
268 void map
269 (
270 const tmp<Field<Type>>& tmapF,
271 const labelUList& mapAddressing
272 );
273
274 //- Interpolative map from the given field
275 void map
276 (
277 const UList<Type>& mapF,
278 const labelListList& mapAddressing,
279 const scalarListList& weights
280 );
281
282 //- Interpolative map from the given tmp field
283 void map
284 (
285 const tmp<Field<Type>>& tmapF,
286 const labelListList& mapAddressing,
287 const scalarListList& weights
288 );
289
290 //- Map from the given field
291 void map
292 (
293 const UList<Type>& mapF,
294 const FieldMapper& map,
295 const bool applyFlip = true
296 );
297
298 //- Map from the given tmp field
299 void map
300 (
301 const tmp<Field<Type>>& tmapF,
302 const FieldMapper& map,
303 const bool applyFlip = true
304 );
305
306 //- Map from self
307 void autoMap
308 (
309 const FieldMapper& map,
310 const bool applyFlip = true
311 );
312
313 //- 1 to 1 reverse-map from the given field
314 void rmap
315 (
316 const UList<Type>& mapF,
317 const labelUList& mapAddressing
318 );
319
320 //- 1 to 1 reverse-map from the given tmp field
321 void rmap
322 (
323 const tmp<Field<Type>>& tmapF,
324 const labelUList& mapAddressing
325 );
326
327 //- Interpolative reverse map from the given field
328 void rmap
329 (
330 const UList<Type>& mapF,
331 const labelUList& mapAddressing,
332 const UList<scalar>& weights
333 );
334
335 //- Interpolative reverse map from the given tmp field
336 void rmap
337 (
338 const tmp<Field<Type>>& tmapF,
339 const labelUList& mapAddressing,
340 const UList<scalar>& weights
341 );
342
343 //- Inplace negate this field (negative).
344 // Inverts the state for a bool field.
345 void negate();
346
347 //- Inplace normalise this field.
348 //- Generally a no-op except for vector fields.
349 // Vector fields are normalised by their magnitude.
350 // Small vectors (mag less than ROOTVSMALL) are set to zero.
351 void normalise();
352
353 //- Return a component field of the field
355
356 //- Replace a component field of the field
357 void replace(const direction, const UList<cmptType>&);
358
359 //- Replace a component field of the field
360 void replace(const direction, const tmp<Field<cmptType>>&);
361
362 //- Replace a component field of the field
363 void replace(const direction, const cmptType&);
364
365 template<class VSForm>
366 VSForm block(const label start) const;
367
368 //- Return the field transpose (only defined for second rank tensors)
369 tmp<Field<Type>> T() const;
370
371 //- Write the field as a dictionary entry
372 void writeEntry(const word& keyword, Ostream& os) const;
373
374
375 // Other Access
376
377 //- Return SubField slice (non-const access) - no range checking
378 SubField<Type> slice(const label pos, label len = -1);
379
380 //- Return SubField slice (const access) - no range checking
381 const SubField<Type> slice(const label pos, label len = -1) const;
382
383 //- Return SubField slice (non-const access) - with range checking
385
386 //- Return SubField slice (const access) - with range checking
387 const SubField<Type> slice(const labelRange& range) const;
388
389
390 // Member Operators
391
392 //- Copy assignment
393 void operator=(const Field<Type>&);
394 void operator=(const tmp<Field<Type>>&);
395
396 inline void operator=(const UList<Type>& rhs);
397 inline void operator=(const SubField<Type>& rhs);
398
399 //- Copy assign from IndirectList
400 template<class Addr>
401 inline void operator=(const IndirectListBase<Type, Addr>& rhs);
402
403 //- Move assignment
404 inline void operator=(Field<Type>&& rhs);
405 inline void operator=(List<Type>&& rhs);
406
407 template<int SizeMin>
408 inline void operator=(DynamicList<Type, SizeMin>&& rhs);
409
410
411 //- Value assignment
412 inline void operator=(const Type& val);
413 inline void operator=(const Foam::zero);
414
415 template<class Form, class Cmpt, direction nCmpt>
417
418 void operator+=(const UList<Type>&);
419 void operator+=(const tmp<Field<Type>>&);
420
421 void operator-=(const UList<Type>&);
422 void operator-=(const tmp<Field<Type>>&);
423
424 void operator*=(const UList<scalar>&);
425 void operator*=(const tmp<Field<scalar>>&);
426
427 void operator/=(const UList<scalar>&);
428 void operator/=(const tmp<Field<scalar>>&);
429
430 void operator+=(const Type&);
431 void operator-=(const Type&);
432
433 void operator*=(const scalar&);
434 void operator/=(const scalar&);
435
436
437 // IOstream operators
439 friend Ostream& operator<< <Type>
440 (Ostream&, const Field<Type>&);
442 friend Ostream& operator<< <Type>
443 (Ostream&, const tmp<Field<Type>>&);
444};
445
446
447// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
448
449} // End namespace Foam
450
451// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
452
453#include "FieldI.H"
454#include "FieldFunctions.H"
455
456#ifdef NoRepository
457 #include "Field.C"
458#endif
459
460// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
461
462#endif
463
464// ************************************************************************* //
scalar range
Info<< nl<< "Wrote faMesh in vtk format: "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.mesh().time().globalPath()/"finiteArea-edges"));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
Template invariant parts for Field and SubField.
Definition: FieldBase.H:53
Abstract base class to hold the Field mapping addressing and weights.
Definition: FieldMapper.H:50
Generic templated field type.
Definition: Field.H:82
static tmp< Field< Type > > NewCalculatedType(const Field< Type2 > &f)
Definition: Field.H:251
static const Field< Type > & null()
Return nullObject reference Field.
Definition: FieldI.H:31
static autoPtr< Field< Type > > New(Istream &is)
Return a pointer to a new Field created on freestore.
Definition: Field.H:243
tmp< Field< Type > > T() const
Return the field transpose (only defined for second rank tensors)
Definition: Field.C:605
void operator=(const Field< Type > &)
Copy assignment.
Definition: Field.C:641
void autoMap(const FieldMapper &map, const bool applyFlip=true)
Map from self.
Definition: Field.C:403
void operator+=(const UList< Type > &)
Definition: Field.C:693
void operator-=(const UList< Type > &)
Definition: Field.C:694
void operator=(const tmp< Field< Type > > &)
SubField< Type > subField
Declare type of subField.
Definition: Field.H:89
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:86
void writeEntry(const word &keyword, Ostream &os) const
Write the field as a dictionary entry.
Definition: Field.C:614
void replace(const direction, const UList< cmptType > &)
Replace a component field of the field.
Definition: Field.C:557
constexpr Field() noexcept
Default construct.
Definition: FieldI.H:40
void operator*=(const UList< scalar > &)
Definition: Field.C:695
tmp< Field< Type > > clone() const
Clone.
Definition: FieldI.H:162
void operator/=(const UList< scalar > &)
Definition: Field.C:696
void negate()
Inplace negate this field (negative).
Definition: Field.C:530
void map(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 map from the given field
Definition: Field.C:240
void normalise()
Definition: Field.C:538
void rmap(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 reverse-map from the given field
Definition: Field.C:466
tmp< Field< cmptType > > component(const direction) const
Return a component field of the field.
Definition: Field.C:545
SubField< Type > slice(const label pos, label len=-1)
Return SubField slice (non-const access) - no range checking.
Definition: SubField.H:178
Base for lists with indirect addressing, templated on the list contents type and the addressing type....
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
SubField is a Field obtained as a section of another Field, without its own allocation....
Definition: SubField.H:62
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Templated vector space.
Definition: VectorSpace.H:79
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
Definition: block.H:61
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:66
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:58
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:62
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:63
Direction is an 8-bit unsigned integer type used to represent Cartesian directions,...
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
dimensionedScalar pos(const dimensionedScalar &ds)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
uint8_t direction
Definition: direction.H:56
const direction noexcept
Definition: Scalar.H:223
labelList f(nPoints)
dictionary dict
A non-counting (dummy) refCount.
Definition: refCount.H:59