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-2020 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>
67 Ostream& operator<<(Ostream&, const Field<Type>&);
68 
69 template<class Type>
70 Ostream& operator<<(Ostream&, const tmp<Field<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
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 initialed 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  //- Negate this field
266  void negate();
267 
268  //- Return a component field of the field
270 
271  //- Replace a component field of the field
272  void replace(const direction, const UList<cmptType>&);
273 
274  //- Replace a component field of the field
275  void replace(const direction, const tmp<Field<cmptType>>&);
276 
277  //- Replace a component field of the field
278  void replace(const direction, const cmptType&);
279 
280  template<class VSForm>
281  VSForm block(const label start) const;
282 
283  //- Return the field transpose (only defined for second rank tensors)
284  tmp<Field<Type>> T() const;
285 
286 
287  // Member Operators
288 
289  void operator=(const Field<Type>&);
290  void operator=(Field<Type>&&);
291  void operator=(const UList<Type>&);
292  void operator=(List<Type>&&);
293  void operator=(const SubField<Type>&);
294  void operator=(const tmp<Field<Type>>&);
295  void operator=(const Type&);
296  void operator=(const zero);
297 
298  template<class Form, class Cmpt, direction nCmpt>
300 
301  void operator+=(const UList<Type>&);
302  void operator+=(const tmp<Field<Type>>&);
303 
304  void operator-=(const UList<Type>&);
305  void operator-=(const tmp<Field<Type>>&);
306 
307  void operator*=(const UList<scalar>&);
308  void operator*=(const tmp<Field<scalar>>&);
309 
310  void operator/=(const UList<scalar>&);
311  void operator/=(const tmp<Field<scalar>>&);
312 
313  void operator+=(const Type&);
314  void operator-=(const Type&);
315 
316  void operator*=(const scalar&);
317  void operator/=(const scalar&);
318 
319 
320  // IOstream Operators
321 
322  friend Ostream& operator<< <Type>
323  (Ostream&, const Field<Type>&);
324 
325  friend Ostream& operator<< <Type>
326  (Ostream&, const tmp<Field<Type>>&);
327 };
328 
329 
330 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
331 
332 } // End namespace Foam
333 
334 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
335 
336 #include "FieldFunctions.H"
337 
338 #ifdef NoRepository
339  #include "Field.C"
340 #endif
341 
342 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
343 
344 #endif
345 
346 // ************************************************************************* //
static tmp< Field< Type > > NewCalculatedType(const Field< Type2 > &f)
Return a pointer to a new calculatedFvPatchFieldField created on.
Definition: Field.H:196
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 operator-=(const UList< Type > &)
Definition: Field.C:618
Reference counter for various OpenFOAM components.
Definition: refCount.H:49
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
static const char *const typeName
Definition: Field.H:105
void negate()
Negate this field.
Definition: Field.C:432
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
uint8_t direction
Definition: direction.H:45
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:97
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Traits class for primitives.
Definition: pTraits.H:50
Templated vector space.
Definition: VectorSpace.H:53
Pre-declare related SubField type.
Definition: Field.H:60
void replace(const direction, const UList< cmptType > &)
Replace a component field of the field.
Definition: Field.C:453
Field()
Construct null.
Definition: Field.C:40
Pre-declare SubField and related Field type.
Definition: Field.H:56
A class for handling words, derived from string.
Definition: word.H:59
tmp< Field< Type > > clone() const
Clone.
Definition: Field.C:240
VSForm block(const label start) const
Definition: Field.C:489
void map(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 map from the given field
Definition: Field.C:265
tmp< Field< cmptType > > component(const direction) const
Return a component field of the field.
Definition: Field.C:441
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
void operator=(const Field< Type > &)
Definition: Field.C:512
labelList f(nPoints)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
void rmap(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 reverse-map from the given field
Definition: Field.C:362
Direction is an 8-bit unsigned integer type used to represent the Cartesian directions etc...
A List with indirect addressing.
Definition: fvMatrix.H:106
static const Field< Type > & null()
Return a null field.
Definition: Field.H:111
tmp< Field< Type > > T() const
Return the field transpose (only defined for second rank tensors)
Definition: Field.C:501
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:49
SubField< Type > subField
Declare type of subField.
Definition: Field.H:100
void operator+=(const UList< Type > &)
Definition: Field.C:617
A class for managing temporary objects.
Definition: PtrList.H:53
void operator/=(const UList< scalar > &)
Definition: Field.C:620
label size() const
Return the number of elements in the UList.
Definition: ListI.H:171
void operator*=(const UList< scalar > &)
Definition: Field.C:619
Namespace for OpenFOAM.