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-2023 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 dictionary;
73 
74 /*---------------------------------------------------------------------------*\
75  Class Field Declaration
76 \*---------------------------------------------------------------------------*/
77 
78 template<class Type>
79 class Field
80 :
81  public tmp<Field<Type>>::refCount,
82  public List<Type>
83 {
84  // Private Member Functions
85 
86  //- Return reference to copy of this field if mapF is the same field
87  // otherwise return mapF
88  const UList<Type>& copySelf
89  (
90  const UList<Type>& mapF,
91  tmp<Field<Type>>& tmapFcpy
92  ) const;
93 
94 
95 public:
96 
97  //- Component type
98  typedef typename pTraits<Type>::cmptType cmptType;
99 
100  //- Declare type of subField
101  typedef SubField<Type> subField;
102 
103 
104  // Static Data Members
105 
106  static const char* const typeName;
107 
108 
109  // Static Member Functions
110 
111  //- Return a null field
112  inline static const Field<Type>& null()
113  {
114  return NullObjectRef<Field<Type>>();
115  }
116 
117 
118  // Constructors
119 
120  //- Construct null
121  // Used for temporary fields which are initialised after construction
122  Field();
123 
124  //- Construct given size
125  // Used for temporary fields which are initialised after construction
126  explicit Field(const label);
127 
128  //- Construct given size and initial value
129  Field(const label, const Type&);
130 
131  //- Construct given size and initialised to zero
132  Field(const label, const zero);
133 
134  //- Copy constructor of a UList<Type>
135  explicit Field(const UList<Type>&);
136 
137  //- Mover constructor transferring the List contents
138  explicit Field(List<Type>&&);
139 
140  //- Copy constructor of a UIndirectList<Type>
141  explicit Field(const UIndirectList<Type>&);
142 
143  //- Copy constructor
144  Field(const Field<Type>&);
145 
146  //- Copy constructor or re-use as specified.
147  Field(Field<Type>&, bool reuse);
148 
149  //- Move constructor transferring the Field contents
150  Field(Field<Type>&&);
151 
152  //- Copy constructor of tmp<Field>
153  Field(const tmp<Field<Type>>&);
154 
155  //- Construct by 1 to 1 mapping from the given field
156  Field
157  (
158  const UList<Type>& mapF,
159  const labelUList& mapAddressing
160  );
161 
162  //- Construct by 1 to 1 mapping from the given tmp field
163  Field
164  (
165  const tmp<Field<Type>>& tmapF,
166  const labelUList& mapAddressing
167  );
168 
169  //- Construct by interpolative mapping from the given field
170  Field
171  (
172  const UList<Type>& mapF,
173  const labelListList& mapAddressing,
174  const scalarListList& weights
175  );
176 
177  //- Construct by interpolative mapping from the given tmp field
178  Field
179  (
180  const tmp<Field<Type>>& tmapF,
181  const labelListList& mapAddressing,
182  const scalarListList& weights
183  );
184 
185  //- Construct from Istream
186  Field(Istream&);
187 
188  //- Construct from a dictionary entry
189  Field(const word& keyword, const dictionary&, const label size);
190 
191  //- Clone
192  tmp<Field<Type>> clone() const;
193 
194  //- Return a pointer to a new calculatedFvPatchFieldField created on
195  // freestore without setting patchField values
196  template<class Type2>
198  {
199  return tmp<Field<Type>>(new Field<Type>(f.size()));
200  }
201 
202 
203  // Member Functions
204 
205  //- 1 to 1 map from the given field
206  void map
207  (
208  const UList<Type>& mapF,
209  const labelUList& mapAddressing
210  );
211 
212  //- 1 to 1 map from the given tmp field
213  void map
214  (
215  const tmp<Field<Type>>& tmapF,
216  const labelUList& mapAddressing
217  );
218 
219  //- Interpolative map from the given field
220  void map
221  (
222  const UList<Type>& mapF,
223  const labelListList& mapAddressing,
224  const scalarListList& weights
225  );
226 
227  //- Interpolative map from the given tmp field
228  void map
229  (
230  const tmp<Field<Type>>& tmapF,
231  const labelListList& mapAddressing,
232  const scalarListList& weights
233  );
234 
235  //- 1 to 1 reverse-map from the given field
236  void rmap
237  (
238  const UList<Type>& mapF,
239  const labelUList& mapAddressing
240  );
241 
242  //- 1 to 1 reverse-map from the given tmp field
243  void rmap
244  (
245  const tmp<Field<Type>>& tmapF,
246  const labelUList& mapAddressing
247  );
248 
249  //- Interpolative reverse map from the given field
250  void rmap
251  (
252  const UList<Type>& mapF,
253  const labelUList& mapAddressing,
254  const UList<scalar>& weights
255  );
256 
257  //- Interpolative reverse map from the given tmp field
258  void rmap
259  (
260  const tmp<Field<Type>>& tmapF,
261  const labelUList& mapAddressing,
262  const UList<scalar>& weights
263  );
264 
265  //- Reset the field values to the given field
266  // Equivalent to operator=
267  void reset(const Field<Type>&);
268 
269  //- Negate this field
270  void negate();
271 
272  //- Return a component field of the field
274 
275  //- Replace a component field of the field
276  void replace(const direction, const UList<cmptType>&);
277 
278  //- Replace a component field of the field
279  void replace(const direction, const tmp<Field<cmptType>>&);
280 
281  //- Replace a component field of the field
282  void replace(const direction, const cmptType&);
283 
284  template<class VSForm>
285  VSForm block(const label start) const;
286 
287  //- Return the field transpose (only defined for second rank tensors)
288  tmp<Field<Type>> T() const;
289 
290 
291  // Member Operators
292 
293  void operator=(const Field<Type>&);
294  void operator=(Field<Type>&&);
295  void operator=(const UList<Type>&);
296  void operator=(List<Type>&&);
297  void operator=(const SubField<Type>&);
298  void operator=(const tmp<Field<Type>>&);
299  void operator=(const Type&);
300  void operator=(const zero);
301 
302  template<class Form, class Cmpt, direction nCmpt>
304 
305  void operator+=(const UList<Type>&);
306  void operator+=(const tmp<Field<Type>>&);
307 
308  void operator-=(const UList<Type>&);
309  void operator-=(const tmp<Field<Type>>&);
310 
311  void operator*=(const UList<scalar>&);
312  void operator*=(const tmp<Field<scalar>>&);
313 
314  void operator/=(const UList<scalar>&);
315  void operator/=(const tmp<Field<scalar>>&);
316 
317  void operator+=(const Type&);
318  void operator-=(const Type&);
319 
320  void operator*=(const scalar&);
321  void operator/=(const scalar&);
322 
323 
324  // IOstream Operators
325 
326  friend Ostream& operator<< <Type>
327  (Ostream&, const Field<Type>&);
328 
329  friend Ostream& operator<< <Type>
330  (Ostream&, const tmp<Field<Type>>&);
331 };
332 
333 
334 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
335 
336 } // End namespace Foam
337 
338 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
339 
340 #include "FieldFunctions.H"
341 
342 #ifdef NoRepository
343  #include "Field.C"
344 #endif
345 
346 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
347 
348 #endif
349 
350 // ************************************************************************* //
Pre-declare SubField and related Field type.
Definition: Field.H:82
tmp< Field< Type > > T() const
Return the field transpose (only defined for second rank tensors)
Definition: Field.C:515
Field()
Construct null.
Definition: Field.C:40
void operator=(const Field< Type > &)
Definition: Field.C:526
void operator=(const tmp< Field< Type >> &)
void operator+=(const UList< Type > &)
Definition: Field.C:631
void operator-=(const UList< Type > &)
Definition: Field.C:632
SubField< Type > subField
Declare type of subField.
Definition: Field.H:100
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:97
void replace(const direction, const UList< cmptType > &)
Replace a component field of the field.
Definition: Field.C:467
void operator*=(const UList< scalar > &)
Definition: Field.C:633
tmp< Field< Type > > clone() const
Clone.
Definition: Field.C:240
void operator/=(const UList< scalar > &)
Definition: Field.C:634
void reset(const Field< Type > &)
Reset the field values to the given field.
Definition: Field.C:432
void negate()
Negate this field.
Definition: Field.C:446
void map(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 map from the given field
Definition: Field.C:265
void rmap(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 reverse-map from the given field
Definition: Field.C:362
static tmp< Field< Type > > NewCalculatedType(const Field< Type2 > &f)
Return a pointer to a new calculatedFvPatchFieldField created on.
Definition: Field.H:196
tmp< Field< cmptType > > component(const direction) const
Return a component field of the field.
Definition: Field.C:455
VSForm block(const label start) const
Definition: Field.C:503
static const char *const typeName
Definition: Field.H:105
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:79
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
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
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 &, const ensightPart &)
uint8_t direction
Definition: direction.H:45
labelList f(nPoints)