Field.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::Field
26 
27 Description
28  Generic templated field type.
29 
30 SourceFiles
31  FieldFunctions.H
32  FieldFunctionsM.H
33  FieldM.H
34  Field.C
35  FieldFunctions.C
36  FieldFunctionsM.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef Field_H
41 #define Field_H
42 
43 #include "tmp.H"
44 #include "direction.H"
45 #include "VectorSpace.H"
46 #include "scalarList.H"
47 #include "labelList.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 // Forward declaration of friend functions and operators
55 
56 template<class Type>
57 class Field;
58 
59 //- Pre-declare related SubField type
60 template<class Type>
61 class SubField;
62 
63 template<class Type>
64 void writeEntry(Ostream& os, const Field<Type>&);
65 
66 template<class Type>
68 
69 template<class Type>
71 
72 class unitConversion;
73 class dictionary;
74 
75 /*---------------------------------------------------------------------------*\
76  Class Field Declaration
77 \*---------------------------------------------------------------------------*/
78 
79 template<class Type>
80 class Field
81 :
82  public tmp<Field<Type>>::refCount,
83  public List<Type>
84 {
85  // Private Member Functions
86 
87  //- Return reference to copy of this field if mapF is the same field
88  // otherwise return mapF
89  const UList<Type>& copySelf
90  (
91  const UList<Type>& mapF,
92  tmp<Field<Type>>& tmapFcpy
93  ) const;
94 
95 
96 public:
97 
98  //- Component type
99  typedef typename pTraits<Type>::cmptType cmptType;
100 
101  //- Declare type of subField
102  typedef SubField<Type> subField;
103 
104 
105  // Static Data Members
106 
107  static const char* const typeName;
108 
109 
110  // Static Member Functions
111 
112  //- Return a null field
113  inline static const Field<Type>& null()
114  {
115  return NullObjectRef<Field<Type>>();
116  }
117 
118 
119  // Constructors
120 
121  //- Construct null
122  // Used for temporary fields which are initialised after construction
123  Field();
124 
125  //- Construct given size
126  // Used for temporary fields which are initialised after construction
127  explicit Field(const label);
128 
129  //- Construct given size and initial value
130  Field(const label, const Type&);
131 
132  //- Construct given size and initialised to zero
133  Field(const label, const zero);
134 
135  //- Copy constructor of a UList<Type>
136  explicit Field(const UList<Type>&);
137 
138  //- Mover constructor transferring the List contents
139  explicit Field(List<Type>&&);
140 
141  //- Copy constructor of a UIndirectList<Type>
142  explicit Field(const UIndirectList<Type>&);
143 
144  //- Copy constructor
145  Field(const Field<Type>&);
146 
147  //- Copy constructor or reuse as specified.
148  Field(Field<Type>&, bool reuse);
149 
150  //- Move constructor transferring the Field contents
151  Field(Field<Type>&&);
152 
153  //- Copy constructor of tmp<Field>
154  Field(const tmp<Field<Type>>&);
155 
156  //- Construct by 1 to 1 mapping from the given field
157  Field
158  (
159  const UList<Type>& mapF,
160  const labelUList& mapAddressing
161  );
162 
163  //- Construct by 1 to 1 mapping from the given tmp field
164  Field
165  (
166  const tmp<Field<Type>>& tmapF,
167  const labelUList& mapAddressing
168  );
169 
170  //- Construct by interpolative mapping from the given field
171  Field
172  (
173  const UList<Type>& mapF,
174  const labelListList& mapAddressing,
175  const scalarListList& weights
176  );
177 
178  //- Construct by interpolative mapping from the given tmp field
179  Field
180  (
181  const tmp<Field<Type>>& tmapF,
182  const labelListList& mapAddressing,
183  const scalarListList& weights
184  );
185 
186  //- Construct from Istream
187  Field(Istream&);
188 
189  //- Construct from a dictionary entry
190  Field(const word& keyword, const dictionary&, const label size);
191 
192  //- Construct from a dictionary entry with unit conversion
193  Field
194  (
195  const word& keyword,
196  const unitConversion&,
197  const dictionary&,
198  const label size
199  );
200 
201  //- Clone
202  tmp<Field<Type>> clone() const;
203 
204  //- Return a pointer to a new calculatedFvPatchFieldField created on
205  // freestore without setting patchField values
206  template<class Type2>
208  {
209  return tmp<Field<Type>>(new Field<Type>(f.size()));
210  }
211 
212 
213  // Member Functions
214 
215  //- 1 to 1 map from the given field
216  void map
217  (
218  const UList<Type>& mapF,
219  const labelUList& mapAddressing
220  );
221 
222  //- 1 to 1 map from the given tmp field
223  void map
224  (
225  const tmp<Field<Type>>& tmapF,
226  const labelUList& mapAddressing
227  );
228 
229  //- Interpolative map from the given field
230  void map
231  (
232  const UList<Type>& mapF,
233  const labelListList& mapAddressing,
234  const scalarListList& weights
235  );
236 
237  //- Interpolative map from the given tmp field
238  void map
239  (
240  const tmp<Field<Type>>& tmapF,
241  const labelListList& mapAddressing,
242  const scalarListList& weights
243  );
244 
245  //- 1 to 1 reverse-map from the given field
246  void rmap
247  (
248  const UList<Type>& mapF,
249  const labelUList& mapAddressing
250  );
251 
252  //- 1 to 1 reverse-map from the given tmp field
253  void rmap
254  (
255  const tmp<Field<Type>>& tmapF,
256  const labelUList& mapAddressing
257  );
258 
259  //- Interpolative reverse map from the given field
260  void rmap
261  (
262  const UList<Type>& mapF,
263  const labelUList& mapAddressing,
264  const UList<scalar>& weights
265  );
266 
267  //- Interpolative reverse map from the given tmp field
268  void rmap
269  (
270  const tmp<Field<Type>>& tmapF,
271  const labelUList& mapAddressing,
272  const UList<scalar>& weights
273  );
274 
275  //- Reset the field values to the given field
276  // Equivalent to operator=
277  void reset(const Field<Type>&);
278 
279  //- Negate this field
280  void negate();
281 
282  //- Return a component field of the field
284 
285  //- Replace a component field of the field
286  void replace(const direction, const UList<cmptType>&);
287 
288  //- Replace a component field of the field
289  void replace(const direction, const tmp<Field<cmptType>>&);
290 
291  //- Replace a component field of the field
292  void replace(const direction, const cmptType&);
293 
294  template<class VSForm>
295  VSForm block(const label start) const;
296 
297  //- Return the field transpose (only defined for second rank tensors)
298  tmp<Field<Type>> T() const;
299 
300 
301  // Member Operators
302 
303  void operator=(const Field<Type>&);
304  void operator=(Field<Type>&&);
305  void operator=(const UList<Type>&);
306  void operator=(List<Type>&&);
307  void operator=(const SubField<Type>&);
308  void operator=(const tmp<Field<Type>>&);
309  void operator=(const Type&);
310  void operator=(const zero);
311 
312  template<class Form, class Cmpt, direction nCmpt>
314 
315  void operator+=(const UList<Type>&);
316  void operator+=(const tmp<Field<Type>>&);
317 
318  void operator-=(const UList<Type>&);
319  void operator-=(const tmp<Field<Type>>&);
320 
321  void operator*=(const UList<scalar>&);
322  void operator*=(const tmp<Field<scalar>>&);
323 
324  void operator/=(const UList<scalar>&);
325  void operator/=(const tmp<Field<scalar>>&);
326 
327  void operator+=(const Type&);
328  void operator-=(const Type&);
329 
330  void operator*=(const scalar&);
331  void operator/=(const scalar&);
332 
333 
334  // IOstream Operators
335 
336  friend Ostream& operator<< <Type>
337  (Ostream&, const Field<Type>&);
338 
339  friend Ostream& operator<< <Type>
340  (Ostream&, const tmp<Field<Type>>&);
341 };
342 
343 
344 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
345 
346 } // End namespace Foam
347 
348 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
349 
350 #include "FieldFunctions.H"
351 
352 #ifdef NoRepository
353  #include "Field.C"
354 #endif
355 
356 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
357 
358 #endif
359 
360 // ************************************************************************* //
Pre-declare SubField and related Field type.
Definition: Field.H:83
tmp< Field< Type > > T() const
Return the field transpose (only defined for second rank tensors)
Definition: Field.C:539
Field()
Construct null.
Definition: Field.C:41
void operator=(const Field< Type > &)
Definition: Field.C:550
void operator=(const tmp< Field< Type >> &)
void operator+=(const UList< Type > &)
Definition: Field.C:655
void operator-=(const UList< Type > &)
Definition: Field.C:656
SubField< Type > subField
Declare type of subField.
Definition: Field.H:101
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:98
void replace(const direction, const UList< cmptType > &)
Replace a component field of the field.
Definition: Field.C:491
void operator*=(const UList< scalar > &)
Definition: Field.C:657
tmp< Field< Type > > clone() const
Clone.
Definition: Field.C:264
void operator/=(const UList< scalar > &)
Definition: Field.C:658
void reset(const Field< Type > &)
Reset the field values to the given field.
Definition: Field.C:456
void negate()
Negate this field.
Definition: Field.C:470
void map(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 map from the given field
Definition: Field.C:289
void rmap(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 reverse-map from the given field
Definition: Field.C:386
static tmp< Field< Type > > NewCalculatedType(const Field< Type2 > &f)
Return a pointer to a new calculatedFvPatchFieldField created on.
Definition: Field.H:206
tmp< Field< cmptType > > component(const direction) const
Return a component field of the field.
Definition: Field.C:479
VSForm block(const label start) const
Definition: Field.C:527
static const char *const typeName
Definition: Field.H:106
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
label size() const
Return the number of elements in the UList.
Definition: ListI.H:171
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Pre-declare related SubField type.
Definition: SubField.H:63
A List with indirect addressing.
Definition: UIndirectList.H:60
Templated vector space.
Definition: VectorSpace.H:85
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Traits class for primitives.
Definition: pTraits.H:53
Reference counter for various OpenFOAM components.
Definition: refCount.H:50
A class for managing temporary objects.
Definition: tmp.H:55
Unit conversion structure. Contains the associated dimensions and the multiplier with which to conver...
A class for handling words, derived from string.
Definition: word.H:62
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:50
Direction is an 8-bit unsigned integer type used to represent the Cartesian directions etc.
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
uint8_t direction
Definition: direction.H:45
labelList f(nPoints)