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-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 
27 Class
28  Foam::Field
29 
30 Description
31  Generic templated field type.
32 
33 SourceFiles
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 Field_H
46 #define 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 
57 namespace Foam
58 {
59 
60 // Forward Declarations
61 class FieldMapper;
62 class dictionary;
63 
64 template<class Type> class Field;
65 template<class Type> class SubField;
66 
67 template<class Type>
69 
70 template<class Type>
72 
73 
74 /*---------------------------------------------------------------------------*\
75  Class Field Declaration
76 \*---------------------------------------------------------------------------*/
77 
78 template<class Type>
79 class Field
80 :
81  public FieldBase,
82  public List<Type>
83 {
84 public:
85 
86  //- Component type
87  typedef typename pTraits<Type>::cmptType cmptType;
88 
89  //- Declare type of subField
90  typedef SubField<Type> 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  //- Negate this field (negative).
344  // Inverts the state for a bool field.
345  void negate();
346 
347  //- Return a component field of the field
349 
350  //- Replace a component field of the field
351  void replace(const direction, const UList<cmptType>&);
352 
353  //- Replace a component field of the field
354  void replace(const direction, const tmp<Field<cmptType>>&);
355 
356  //- Replace a component field of the field
357  void replace(const direction, const cmptType&);
358 
359  template<class VSForm>
360  VSForm block(const label start) const;
361 
362  //- Return the field transpose (only defined for second rank tensors)
363  tmp<Field<Type>> T() const;
364 
365  //- Write the field as a dictionary entry
366  void writeEntry(const word& keyword, Ostream& os) const;
367 
368 
369  // Other Access
370 
371  //- Return SubField slice (non-const access) - no range checking
372  SubField<Type> slice(const label pos, label len = -1);
373 
374  //- Return SubField slice (const access) - no range checking
375  const SubField<Type> slice(const label pos, label len = -1) const;
376 
377  //- Return SubField slice (non-const access) - with range checking
379 
380  //- Return SubField slice (const access) - with range checking
381  const SubField<Type> slice(const labelRange& range) const;
382 
383 
384  // Member Operators
385 
386  //- Copy assignment
387  void operator=(const Field<Type>&);
388  void operator=(const tmp<Field<Type>>&);
389 
390  inline void operator=(const UList<Type>& rhs);
391  inline void operator=(const SubField<Type>& rhs);
392 
393  //- Copy assign from IndirectList
394  template<class Addr>
395  inline void operator=(const IndirectListBase<Type, Addr>& rhs);
396 
397  //- Move assignment
398  inline void operator=(Field<Type>&& rhs);
399  inline void operator=(List<Type>&& rhs);
400 
401  template<int SizeMin>
402  inline void operator=(DynamicList<Type, SizeMin>&& rhs);
403 
404 
405  //- Value assignment
406  inline void operator=(const Type& val);
407  inline void operator=(const Foam::zero);
408 
409  template<class Form, class Cmpt, direction nCmpt>
411 
412  void operator+=(const UList<Type>&);
413  void operator+=(const tmp<Field<Type>>&);
414 
415  void operator-=(const UList<Type>&);
416  void operator-=(const tmp<Field<Type>>&);
417 
418  void operator*=(const UList<scalar>&);
419  void operator*=(const tmp<Field<scalar>>&);
420 
421  void operator/=(const UList<scalar>&);
422  void operator/=(const tmp<Field<scalar>>&);
423 
424  void operator+=(const Type&);
425  void operator-=(const Type&);
426 
427  void operator*=(const scalar&);
428  void operator/=(const scalar&);
429 
430 
431  // IOstream operators
432 
433  friend Ostream& operator<< <Type>
434  (Ostream&, const Field<Type>&);
435 
436  friend Ostream& operator<< <Type>
437  (Ostream&, const tmp<Field<Type>>&);
438 };
439 
440 
441 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
442 
443 } // End namespace Foam
444 
445 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
446 
447 #include "FieldI.H"
448 #include "FieldFunctions.H"
449 
450 #ifdef NoRepository
451  #include "Field.C"
452 #endif
453 
454 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
455 
456 #endif
457 
458 // ************************************************************************* //
VectorSpace.H
Foam::FieldBase
Template invariant parts for Field and SubField.
Definition: FieldBase.H:50
Foam::Field::operator-=
void operator-=(const UList< Type > &)
Definition: Field.C:688
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Field::autoMap
void autoMap(const FieldMapper &map, const bool applyFlip=true)
Map from self.
Definition: Field.C:403
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:55
Foam::one
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:61
Foam::FieldMapper
Abstract base class to hold the Field mapping addressing and weights.
Definition: FieldMapper.H:49
Foam::Field::operator+=
void operator+=(const UList< Type > &)
Definition: Field.C:687
Foam::Field::clone
tmp< Field< Type > > clone() const
Clone.
Definition: FieldI.H:162
Foam::Field::Field
constexpr Field() noexcept
Default construct.
Definition: FieldI.H:40
scalarList.H
Foam::VectorSpace
Templated vector space.
Definition: VectorSpace.H:56
Foam::Field::map
void map(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 map from the given field
Definition: Field.C:240
Foam::SubField
SubField is a Field obtained as a section of another Field, without its own allocation....
Definition: Field.H:64
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::Field::New
static autoPtr< Field< Type > > New(Istream &is)
Return a pointer to a new Field created on freestore.
Definition: Field.H:243
Foam::Field::cmptType
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:86
Field.C
labelList.H
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::Field::T
tmp< Field< Type > > T() const
Return the field transpose (only defined for second rank tensors)
Definition: Field.C:599
FieldBase.H
Foam::labelRange
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:55
Foam::Field::replace
void replace(const direction, const UList< cmptType > &)
Replace a component field of the field.
Definition: Field.C:551
fld
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputLagrangian.H:23
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::Field::rmap
void rmap(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 reverse-map from the given field
Definition: Field.C:466
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::Field::negate
void negate()
Negate this field (negative).
Definition: Field.C:530
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Field::component
tmp< Field< cmptType > > component(const direction) const
Return a component field of the field.
Definition: Field.C:539
Foam::Field::operator=
void operator=(const Field< Type > &)
Copy assignment.
Definition: Field.C:635
direction.H
Direction is an 8-bit unsigned integer type used to represent Cartesian directions,...
FieldI.H
Foam::Field::writeEntry
void writeEntry(const word &keyword, Ostream &os) const
Write the field as a dictionary entry.
Definition: Field.C:608
Foam::Field::operator/=
void operator/=(const UList< scalar > &)
Definition: Field.C:690
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
tmp.H
range
scalar range
Definition: LISASMDCalcMethod1.H:12
f
labelList f(nPoints)
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::pTraits
A traits class, which is primarily used for primitives.
Definition: pTraits.H:56
Foam::Field::block
VSForm block(const label start) const
Definition: Field.C:587
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::Field::operator*=
void operator*=(const UList< scalar > &)
Definition: Field.C:689
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::Field::NewCalculatedType
static tmp< Field< Type > > NewCalculatedType(const Field< Type2 > &f)
Definition: Field.H:251
Foam::Field::subField
SubField< Type > subField
Declare type of subField.
Definition: Field.H:89
Foam::IndirectListBase
Base for lists with indirect addressing, templated on the list contents type and the addressing type....
Definition: IndirectListBase.H:56
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::Field::slice
SubField< Type > slice(const label pos, label len=-1)
Return SubField slice (non-const access) - no range checking.
Definition: SubField.H:178
Foam::zero
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:62
FieldFunctions.H
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:177