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 | Copyright (C) 2011-2016 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  FieldMapper.H
34  FieldM.H
35  Field.C
36  FieldFunctions.C
37  FieldFunctionsM.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef Field_H
42 #define Field_H
43 
44 #include "tmp.H"
45 #include "direction.H"
46 #include "VectorSpace.H"
47 #include "scalarList.H"
48 #include "labelList.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 // Forward declaration of friend functions and operators
56 
57 template<class Type>
58 class Field;
59 
60 //- Pre-declare related SubField type
61 template<class Type>
62 class SubField;
63 
64 template<class Type>
65 Ostream& operator<<(Ostream&, const Field<Type>&);
66 
67 template<class Type>
68 Ostream& operator<<(Ostream&, const tmp<Field<Type>>&);
69 
70 class FieldMapper;
71 class dictionary;
72 
73 /*---------------------------------------------------------------------------*\
74  Class Field Declaration
75 \*---------------------------------------------------------------------------*/
76 
77 template<class Type>
78 class Field
79 :
80  public tmp<Field<Type>>::refCount,
81  public List<Type>
82 {
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 data members
94 
95  static const char* const typeName;
96 
97 
98  // Static Member Functions
99 
100  //- Return a null field
101  inline static const Field<Type>& null()
102  {
103  return NullObjectRef<Field<Type>>();
104  }
105 
106 
107  // Constructors
108 
109  //- Construct null
110  // Used for temporary fields which are initialised after construction
111  Field();
112 
113  //- Construct given size
114  // Used for temporary fields which are initialised after construction
115  explicit Field(const label);
116 
117  //- Construct given size and initial value
118  Field(const label, const Type&);
119 
120  //- Construct given size and initialed to zero
121  Field(const label, const zero);
122 
123  //- Construct as copy of a UList<Type>
124  explicit Field(const UList<Type>&);
125 
126  //- Construct as copy of a UIndirectList<Type>
127  explicit Field(const UIndirectList<Type>&);
128 
129  //- Construct by transferring the List contents
130  explicit Field(const Xfer<List<Type>>&);
131 
132  //- Construct by 1 to 1 mapping from the given field
133  Field
134  (
135  const UList<Type>& mapF,
136  const labelUList& mapAddressing
137  );
138 
139  //- Construct by 1 to 1 mapping from the given tmp field
140  Field
141  (
142  const tmp<Field<Type>>& tmapF,
143  const labelUList& mapAddressing
144  );
145 
146  //- Construct by interpolative mapping from the given field
147  Field
148  (
149  const UList<Type>& mapF,
150  const labelListList& mapAddressing,
151  const scalarListList& weights
152  );
153 
154  //- Construct by interpolative mapping from the given tmp field
155  Field
156  (
157  const tmp<Field<Type>>& tmapF,
158  const labelListList& mapAddressing,
159  const scalarListList& weights
160  );
161 
162  //- Construct by mapping from the given field
163  Field
164  (
165  const UList<Type>& mapF,
166  const FieldMapper& map,
167  const bool applyFlip = true
168  );
169 
170  //- Construct by mapping from the given field
171  Field
172  (
173  const UList<Type>& mapF,
174  const FieldMapper& map,
175  const Type& defaultValue,
176  const bool applyFlip = true
177  );
178 
179  //- Construct by mapping from the given field
180  Field
181  (
182  const UList<Type>& mapF,
183  const FieldMapper& map,
184  const UList<Type>& defaultValues,
185  const bool applyFlip = true
186  );
187 
188  //- Construct by mapping from the given tmp field
189  Field
190  (
191  const tmp<Field<Type>>& tmapF,
192  const FieldMapper& map,
193  const bool applyFlip = true
194  );
195 
196  //- Construct by mapping from the given tmp field. Supplied uniform
197  // value for unmapped items
198  Field
199  (
200  const tmp<Field<Type>>& tmapF,
201  const FieldMapper& map,
202  const Type& defaultValue,
203  const bool applyFlip = true
204  );
205 
206  //- Construct by mapping from the given tmp field. Supplied values
207  // for unmapped items
208  Field
209  (
210  const tmp<Field<Type>>& tmapF,
211  const FieldMapper& map,
212  const UList<Type>& defaultValues,
213  const bool applyFlip = true
214  );
215 
216  //- Construct as copy
217  Field(const Field<Type>&);
218 
219  //- Construct as copy or re-use as specified.
220  Field(Field<Type>&, bool reuse);
221 
222  //- Construct by transferring the Field contents
223  Field(const Xfer<Field<Type>>&);
224 
225  //- Construct as copy of tmp<Field>
226  #ifndef NoConstructFromTmp
227  Field(const tmp<Field<Type>>&);
228  #endif
229 
230  //- Construct from Istream
231  Field(Istream&);
232 
233  //- Construct from a dictionary entry
234  Field(const word& keyword, const dictionary&, const label size);
235 
236  //- Clone
237  tmp<Field<Type>> clone() const;
238 
239  //- Return a pointer to a new calculatedFvPatchFieldField created on
240  // freestore without setting patchField values
241  template<class Type2>
243  {
244  return tmp<Field<Type>>(new Field<Type>(f.size()));
245  }
246 
247 
248  // Member Functions
249 
250  //- 1 to 1 map from the given field
251  void map
252  (
253  const UList<Type>& mapF,
254  const labelUList& mapAddressing
255  );
256 
257  //- 1 to 1 map from the given tmp field
258  void map
259  (
260  const tmp<Field<Type>>& tmapF,
261  const labelUList& mapAddressing
262  );
263 
264  //- Interpolative map from the given field
265  void map
266  (
267  const UList<Type>& mapF,
268  const labelListList& mapAddressing,
269  const scalarListList& weights
270  );
271 
272  //- Interpolative map from the given tmp field
273  void map
274  (
275  const tmp<Field<Type>>& tmapF,
276  const labelListList& mapAddressing,
277  const scalarListList& weights
278  );
279 
280  //- Map from the given field
281  void map
282  (
283  const UList<Type>& mapF,
284  const FieldMapper& map,
285  const bool applyFlip = true
286  );
287 
288  //- Map from the given tmp field
289  void map
290  (
291  const tmp<Field<Type>>& tmapF,
292  const FieldMapper& map,
293  const bool applyFlip = true
294  );
295 
296  //- Map from self
297  void autoMap
298  (
299  const FieldMapper& map,
300  const bool applyFlip = true
301  );
302 
303  //- 1 to 1 reverse-map from the given field
304  void rmap
305  (
306  const UList<Type>& mapF,
307  const labelUList& mapAddressing
308  );
309 
310  //- 1 to 1 reverse-map from the given tmp field
311  void rmap
312  (
313  const tmp<Field<Type>>& tmapF,
314  const labelUList& mapAddressing
315  );
316 
317  //- Interpolative reverse map from the given field
318  void rmap
319  (
320  const UList<Type>& mapF,
321  const labelUList& mapAddressing,
322  const UList<scalar>& weights
323  );
324 
325  //- Interpolative reverse map from the given tmp field
326  void rmap
327  (
328  const tmp<Field<Type>>& tmapF,
329  const labelUList& mapAddressing,
330  const UList<scalar>& weights
331  );
332 
333  //- Negate this field
334  void negate();
335 
336  //- Return a component field of the field
338 
339  //- Replace a component field of the field
340  void replace(const direction, const UList<cmptType>&);
341 
342  //- Replace a component field of the field
343  void replace(const direction, const tmp<Field<cmptType>>&);
344 
345  //- Replace a component field of the field
346  void replace(const direction, const cmptType&);
347 
348  template<class VSForm>
349  VSForm block(const label start) const;
350 
351  //- Return the field transpose (only defined for second rank tensors)
352  tmp<Field<Type>> T() const;
353 
354  //- Write the field as a dictionary entry
355  void writeEntry(const word& keyword, Ostream& os) const;
356 
357 
358  // Member operators
359 
360  void operator=(const Field<Type>&);
361  void operator=(const UList<Type>&);
362  void operator=(const SubField<Type>&);
363  void operator=(const tmp<Field<Type>>&);
364  void operator=(const Type&);
365  void operator=(const zero);
366 
367  template<class Form, class Cmpt, direction nCmpt>
369 
370  void operator+=(const UList<Type>&);
371  void operator+=(const tmp<Field<Type>>&);
372 
373  void operator-=(const UList<Type>&);
374  void operator-=(const tmp<Field<Type>>&);
375 
376  void operator*=(const UList<scalar>&);
377  void operator*=(const tmp<Field<scalar>>&);
378 
379  void operator/=(const UList<scalar>&);
380  void operator/=(const tmp<Field<scalar>>&);
381 
382  void operator+=(const Type&);
383  void operator-=(const Type&);
384 
385  void operator*=(const scalar&);
386  void operator/=(const scalar&);
387 
388 
389  // IOstream operators
390 
391  friend Ostream& operator<< <Type>
392  (Ostream&, const Field<Type>&);
393 
394  friend Ostream& operator<< <Type>
395  (Ostream&, const tmp<Field<Type>>&);
396 };
397 
398 
399 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
400 
401 } // End namespace Foam
402 
403 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
404 
405 #include "FieldFunctions.H"
406 
407 #ifdef NoRepository
408  #include "Field.C"
409 #endif
410 
411 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
412 
413 #endif
414 
415 // ************************************************************************* //
static tmp< Field< Type > > NewCalculatedType(const Field< Type2 > &f)
Return a pointer to a new calculatedFvPatchFieldField created on.
Definition: Field.H:241
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
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:849
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:137
static const char *const typeName
Definition: Field.H:94
void negate()
Negate this field.
Definition: Field.C:648
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:60
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:86
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
Traits class for primitives.
Definition: pTraits.H:50
Templated vector space.
Definition: VectorSpace.H:53
void writeEntry(const word &keyword, Ostream &os) const
Write the field as a dictionary entry.
Definition: Field.C:726
Pre-declare related SubField type.
Definition: Field.H:61
void replace(const direction, const UList< cmptType > &)
Replace a component field of the field.
Definition: Field.C:669
Field()
Construct null.
Definition: Field.C:42
Abstract base class to hold the Field mapping addressing and weights.
Definition: FieldMapper.H:45
Pre-declare SubField and related Field type.
Definition: Field.H:57
A class for handling words, derived from string.
Definition: word.H:59
tmp< Field< Type > > clone() const
Clone.
Definition: Field.C:348
VSForm block(const label start) const
Definition: Field.C:705
void map(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 map from the given field
Definition: Field.C:358
tmp< Field< cmptType > > component(const direction) const
Return a component field of the field.
Definition: Field.C:657
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
void operator=(const Field< Type > &)
Definition: Field.C:764
labelList f(nPoints)
void autoMap(const FieldMapper &map, const bool applyFlip=true)
Map from self.
Definition: Field.C:521
void rmap(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 reverse-map from the given field
Definition: Field.C:584
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:100
tmp< Field< Type > > T() const
Return the field transpose (only defined for second rank tensors)
Definition: Field.C:717
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:89
void operator+=(const UList< Type > &)
Definition: Field.C:848
A class for managing temporary objects.
Definition: PtrList.H:53
void operator/=(const UList< scalar > &)
Definition: Field.C:851
label size() const
Return the number of elements in the UList.
Definition: ListI.H:170
void operator*=(const UList< scalar > &)
Definition: Field.C:850
Namespace for OpenFOAM.