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-2020 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 "VectorSpace.H"
51 #include "scalarList.H"
52 #include "labelList.H"
53 #include "FieldBase.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  return NullObjectRef<Field<Type>>();
99  }
100 
101 
102  // Constructors
103 
104  //- Construct null
105  // For temporary fields that are initialised after construction
106  inline constexpr Field() noexcept;
107 
108  //- Construct given size
109  // For temporary fields that are initialised after construction
110  inline explicit Field(const label len);
111 
112  //- Construct given size and initial value
113  inline Field(const label len, const Type& val);
114 
115  //- Construct given size and initial values of zero
116  inline Field(const label len, const Foam::zero);
117 
118  //- Construct with length=1, copying the value as the only content
119  inline Field(const Foam::one, const Type& val);
120 
121  //- Construct with length=1, moving the value as the only content
122  inline Field(const Foam::one, Type&& val);
123 
124  //- Construct with length=1, initializing content to zero
125  inline Field(const Foam::one, const Foam::zero);
126 
127  //- Copy construct
128  inline Field(const Field<Type>& fld);
129 
130  //- Copy construct from UList<Type>
131  inline explicit Field(const UList<Type>& list);
132 
133  //- Copy construct from IndirectList
134  template<class Addr>
135  inline explicit Field(const IndirectListBase<Type, Addr>& list);
136 
137  //- Move construct from Field
138  inline Field(Field<Type>&& fld);
139 
140  //- Move construct from List
141  inline Field(List<Type>&& list);
142 
143  //- Move construct from DynamicList
144  template<int SizeMin>
145  inline Field(DynamicList<Type, SizeMin>&& list);
146 
147  //- Construct by 1 to 1 mapping from the given field
148  Field
149  (
150  const UList<Type>& mapF,
151  const labelUList& mapAddressing
152  );
153 
154  //- Construct by 1 to 1 mapping from the given tmp field
155  Field
156  (
157  const tmp<Field<Type>>& tmapF,
158  const labelUList& mapAddressing
159  );
160 
161  //- Construct by interpolative mapping from the given field
162  Field
163  (
164  const UList<Type>& mapF,
165  const labelListList& mapAddressing,
166  const scalarListList& weights
167  );
168 
169  //- Construct by interpolative mapping from the given tmp field
170  Field
171  (
172  const tmp<Field<Type>>& tmapF,
173  const labelListList& mapAddressing,
174  const scalarListList& weights
175  );
176 
177  //- Construct by mapping from the given field
178  Field
179  (
180  const UList<Type>& mapF,
181  const FieldMapper& map,
182  const bool applyFlip = true
183  );
184 
185  //- Construct by mapping from the given field
186  Field
187  (
188  const UList<Type>& mapF,
189  const FieldMapper& map,
190  const Type& defaultValue,
191  const bool applyFlip = true
192  );
193 
194  //- Construct by mapping from the given field
195  Field
196  (
197  const UList<Type>& mapF,
198  const FieldMapper& map,
199  const UList<Type>& defaultValues,
200  const bool applyFlip = true
201  );
202 
203  //- Construct by mapping from the given tmp field
204  Field
205  (
206  const tmp<Field<Type>>& tmapF,
207  const FieldMapper& map,
208  const bool applyFlip = true
209  );
210 
211  //- Construct by mapping from the given tmp field.
212  //- Uses supplied uniform value for unmapped items
213  Field
214  (
215  const tmp<Field<Type>>& tmapF,
216  const FieldMapper& map,
217  const Type& defaultValue,
218  const bool applyFlip = true
219  );
220 
221  //- Construct by mapping from the given tmp field.
222  //- Uses supplied values for unmapped items
223  Field
224  (
225  const tmp<Field<Type>>& tmapF,
226  const FieldMapper& map,
227  const UList<Type>& defaultValues,
228  const bool applyFlip = true
229  );
230 
231  //- Copy construct or re-use as specified.
232  inline Field(Field<Type>& fld, bool reuse);
233 
234  //- Copy or move construct from tmp
235  inline Field(const tmp<Field<Type>>& tfld);
236 
237  //- Construct from Istream
238  inline Field(Istream& is);
239 
240  //- Construct from a dictionary entry
241  Field(const word& keyword, const dictionary& dict, const label len);
242 
243  //- Clone
244  inline tmp<Field<Type>> clone() const;
245 
246  //- Return a pointer to a new Field created on freestore
247  static autoPtr<Field<Type>> New(Istream& is)
248  {
249  return autoPtr<Field<Type>>(new Field<Type>(is));
250  }
251 
252  //- Return a pointer to a new calculatedFvPatchFieldField created on
253  //- freestore without setting patchField values
254  template<class Type2>
256  {
257  return tmp<Field<Type>>::New(f.size());
258  }
259 
260 
261  // Member Functions
262 
263  //- 1 to 1 map from the given field
264  void map
265  (
266  const UList<Type>& mapF,
267  const labelUList& mapAddressing
268  );
269 
270  //- 1 to 1 map from the given tmp field
271  void map
272  (
273  const tmp<Field<Type>>& tmapF,
274  const labelUList& mapAddressing
275  );
276 
277  //- Interpolative map from the given field
278  void map
279  (
280  const UList<Type>& mapF,
281  const labelListList& mapAddressing,
282  const scalarListList& weights
283  );
284 
285  //- Interpolative map from the given tmp field
286  void map
287  (
288  const tmp<Field<Type>>& tmapF,
289  const labelListList& mapAddressing,
290  const scalarListList& weights
291  );
292 
293  //- Map from the given field
294  void map
295  (
296  const UList<Type>& mapF,
297  const FieldMapper& map,
298  const bool applyFlip = true
299  );
300 
301  //- Map from the given tmp field
302  void map
303  (
304  const tmp<Field<Type>>& tmapF,
305  const FieldMapper& map,
306  const bool applyFlip = true
307  );
308 
309  //- Map from self
310  void autoMap
311  (
312  const FieldMapper& map,
313  const bool applyFlip = true
314  );
315 
316  //- 1 to 1 reverse-map from the given field
317  void rmap
318  (
319  const UList<Type>& mapF,
320  const labelUList& mapAddressing
321  );
322 
323  //- 1 to 1 reverse-map from the given tmp field
324  void rmap
325  (
326  const tmp<Field<Type>>& tmapF,
327  const labelUList& mapAddressing
328  );
329 
330  //- Interpolative reverse map from the given field
331  void rmap
332  (
333  const UList<Type>& mapF,
334  const labelUList& mapAddressing,
335  const UList<scalar>& weights
336  );
337 
338  //- Interpolative reverse map from the given tmp field
339  void rmap
340  (
341  const tmp<Field<Type>>& tmapF,
342  const labelUList& mapAddressing,
343  const UList<scalar>& weights
344  );
345 
346  //- Negate this field (negative).
347  // Inverts the state for a bool field.
348  void negate();
349 
350  //- Return a component field of the field
352 
353  //- Replace a component field of the field
354  void replace(const direction, const UList<cmptType>&);
355 
356  //- Replace a component field of the field
357  void replace(const direction, const tmp<Field<cmptType>>&);
358 
359  //- Replace a component field of the field
360  void replace(const direction, const cmptType&);
361 
362  template<class VSForm>
363  VSForm block(const label start) const;
364 
365  //- Return the field transpose (only defined for second rank tensors)
366  tmp<Field<Type>> T() const;
367 
368  //- Write the field as a dictionary entry
369  void writeEntry(const word& keyword, Ostream& os) const;
370 
371 
372  // Member Operators
373 
374  //- Copy assignment
375  void operator=(const Field<Type>&);
376  void operator=(const tmp<Field<Type>>&);
377  inline void operator=(const UList<Type>&);
378  inline void operator=(const SubField<Type>&);
379 
380  //- Move assignment
381  inline void operator=(Field<Type>&& rhs);
382  inline void operator=(List<Type>&& rhs);
383 
384  template<int SizeMin>
385  inline void operator=(DynamicList<Type, SizeMin>&& rhs);
386 
387 
388  //- Value assignment
389  inline void operator=(const Type& val);
390  inline void operator=(const Foam::zero);
391 
392  template<class Form, class Cmpt, direction nCmpt>
394 
395  void operator+=(const UList<Type>&);
396  void operator+=(const tmp<Field<Type>>&);
397 
398  void operator-=(const UList<Type>&);
399  void operator-=(const tmp<Field<Type>>&);
400 
401  void operator*=(const UList<scalar>&);
402  void operator*=(const tmp<Field<scalar>>&);
403 
404  void operator/=(const UList<scalar>&);
405  void operator/=(const tmp<Field<scalar>>&);
406 
407  void operator+=(const Type&);
408  void operator-=(const Type&);
409 
410  void operator*=(const scalar&);
411  void operator/=(const scalar&);
412 
413 
414  // IOstream operators
415 
416  friend Ostream& operator<< <Type>
417  (Ostream&, const Field<Type>&);
418 
419  friend Ostream& operator<< <Type>
420  (Ostream&, const tmp<Field<Type>>&);
421 };
422 
423 
424 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
425 
426 } // End namespace Foam
427 
428 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
429 
430 #include "FieldI.H"
431 #include "FieldFunctions.H"
432 
433 #ifdef NoRepository
434  #include "Field.C"
435 #endif
436 
437 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
438 
439 #endif
440 
441 // ************************************************************************* //
VectorSpace.H
Foam::FieldBase
Template invariant parts for Field.
Definition: FieldBase.H:50
Foam::Field::operator-=
void operator-=(const UList< Type > &)
Definition: Field.C:700
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
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:415
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:699
Foam::Field::clone
tmp< Field< Type > > clone() const
Clone.
Definition: FieldI.H:153
Foam::Field::Field
constexpr Field() noexcept
Construct null.
Definition: FieldI.H:31
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:252
Foam::SubField
SubField is a Field obtained as a section of another Field.
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:246
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:611
FieldBase.H
Foam::Field::replace
void replace(const direction, const UList< cmptType > &)
Replace a component field of the field.
Definition: Field.C:563
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:478
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::Field::negate
void negate()
Negate this field (negative).
Definition: Field.C:542
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:551
Foam::Field::operator=
void operator=(const Field< Type > &)
Copy assignment.
Definition: Field.C:647
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:620
Foam::Field::operator/=
void operator/=(const UList< scalar > &)
Definition: Field.C:702
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
tmp.H
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
Traits class for primitives.
Definition: pTraits.H:54
Foam::Field::block
VSForm block(const label start) const
Definition: Field.C:599
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:701
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::Field::NewCalculatedType
static tmp< Field< Type > > NewCalculatedType(const Field< Type2 > &f)
Definition: Field.H:254
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::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