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 by transferring the List contents
127  explicit Field(const Xfer<List<Type>>&);
128 
129  //- Construct by 1 to 1 mapping from the given field
130  Field
131  (
132  const UList<Type>& mapF,
133  const labelUList& mapAddressing
134  );
135 
136  //- Construct by 1 to 1 mapping from the given tmp field
137  Field
138  (
139  const tmp<Field<Type>>& tmapF,
140  const labelUList& mapAddressing
141  );
142 
143  //- Construct by interpolative mapping from the given field
144  Field
145  (
146  const UList<Type>& mapF,
147  const labelListList& mapAddressing,
148  const scalarListList& weights
149  );
150 
151  //- Construct by interpolative mapping from the given tmp field
152  Field
153  (
154  const tmp<Field<Type>>& tmapF,
155  const labelListList& mapAddressing,
156  const scalarListList& weights
157  );
158 
159  //- Construct by mapping from the given field
160  Field
161  (
162  const UList<Type>& mapF,
163  const FieldMapper& map,
164  const bool applyFlip = true
165  );
166 
167  //- Construct by mapping from the given field
168  Field
169  (
170  const UList<Type>& mapF,
171  const FieldMapper& map,
172  const Type& defaultValue,
173  const bool applyFlip = true
174  );
175 
176  //- Construct by mapping from the given field
177  Field
178  (
179  const UList<Type>& mapF,
180  const FieldMapper& map,
181  const UList<Type>& defaultValues,
182  const bool applyFlip = true
183  );
184 
185  //- Construct by mapping from the given tmp field
186  Field
187  (
188  const tmp<Field<Type>>& tmapF,
189  const FieldMapper& map,
190  const bool applyFlip = true
191  );
192 
193  //- Construct by mapping from the given tmp field. Supplied uniform
194  // value for unmapped items
195  Field
196  (
197  const tmp<Field<Type>>& tmapF,
198  const FieldMapper& map,
199  const Type& defaultValue,
200  const bool applyFlip = true
201  );
202 
203  //- Construct by mapping from the given tmp field. Supplied values
204  // for unmapped items
205  Field
206  (
207  const tmp<Field<Type>>& tmapF,
208  const FieldMapper& map,
209  const UList<Type>& defaultValues,
210  const bool applyFlip = true
211  );
212 
213  //- Construct as copy
214  Field(const Field<Type>&);
215 
216  //- Construct as copy or re-use as specified.
217  Field(Field<Type>&, bool reuse);
218 
219  //- Construct by transferring the Field contents
220  Field(const Xfer<Field<Type>>&);
221 
222  //- Construct as copy of tmp<Field>
223  #ifndef NoConstructFromTmp
224  Field(const tmp<Field<Type>>&);
225  #endif
226 
227  //- Construct from Istream
228  Field(Istream&);
229 
230  //- Construct from a dictionary entry
231  Field(const word& keyword, const dictionary&, const label size);
232 
233  //- Clone
234  tmp<Field<Type>> clone() const;
235 
236  //- Return a pointer to a new calculatedFvPatchFieldField created on
237  // freestore without setting patchField values
238  template<class Type2>
240  {
241  return tmp<Field<Type>>(new Field<Type>(f.size()));
242  }
243 
244 
245  // Member Functions
246 
247  //- 1 to 1 map from the given field
248  void map
249  (
250  const UList<Type>& mapF,
251  const labelUList& mapAddressing
252  );
253 
254  //- 1 to 1 map from the given tmp field
255  void map
256  (
257  const tmp<Field<Type>>& tmapF,
258  const labelUList& mapAddressing
259  );
260 
261  //- Interpolative map from the given field
262  void map
263  (
264  const UList<Type>& mapF,
265  const labelListList& mapAddressing,
266  const scalarListList& weights
267  );
268 
269  //- Interpolative map from the given tmp field
270  void map
271  (
272  const tmp<Field<Type>>& tmapF,
273  const labelListList& mapAddressing,
274  const scalarListList& weights
275  );
276 
277  //- Map from the given field
278  void map
279  (
280  const UList<Type>& mapF,
281  const FieldMapper& map,
282  const bool applyFlip = true
283  );
284 
285  //- Map from the given tmp field
286  void map
287  (
288  const tmp<Field<Type>>& tmapF,
289  const FieldMapper& map,
290  const bool applyFlip = true
291  );
292 
293  //- Map from self
294  void autoMap
295  (
296  const FieldMapper& map,
297  const bool applyFlip = true
298  );
299 
300  //- 1 to 1 reverse-map from the given field
301  void rmap
302  (
303  const UList<Type>& mapF,
304  const labelUList& mapAddressing
305  );
306 
307  //- 1 to 1 reverse-map from the given tmp field
308  void rmap
309  (
310  const tmp<Field<Type>>& tmapF,
311  const labelUList& mapAddressing
312  );
313 
314  //- Interpolative reverse map from the given field
315  void rmap
316  (
317  const UList<Type>& mapF,
318  const labelUList& mapAddressing,
319  const UList<scalar>& weights
320  );
321 
322  //- Interpolative reverse map from the given tmp field
323  void rmap
324  (
325  const tmp<Field<Type>>& tmapF,
326  const labelUList& mapAddressing,
327  const UList<scalar>& weights
328  );
329 
330  //- Negate this field
331  void negate();
332 
333  //- Return a component field of the field
335 
336  //- Replace a component field of the field
337  void replace(const direction, const UList<cmptType>&);
338 
339  //- Replace a component field of the field
340  void replace(const direction, const tmp<Field<cmptType>>&);
341 
342  //- Replace a component field of the field
343  void replace(const direction, const cmptType&);
344 
345  template<class VSForm>
346  VSForm block(const label start) const;
347 
348  //- Return the field transpose (only defined for second rank tensors)
349  tmp<Field<Type>> T() const;
350 
351  //- Write the field as a dictionary entry
352  void writeEntry(const word& keyword, Ostream& os) const;
353 
354 
355  // Member operators
356 
357  void operator=(const Field<Type>&);
358  void operator=(const UList<Type>&);
359  void operator=(const SubField<Type>&);
360  void operator=(const tmp<Field<Type>>&);
361  void operator=(const Type&);
362  void operator=(const zero);
363 
364  template<class Form, class Cmpt, direction nCmpt>
366 
367  void operator+=(const UList<Type>&);
368  void operator+=(const tmp<Field<Type>>&);
369 
370  void operator-=(const UList<Type>&);
371  void operator-=(const tmp<Field<Type>>&);
372 
373  void operator*=(const UList<scalar>&);
374  void operator*=(const tmp<Field<scalar>>&);
375 
376  void operator/=(const UList<scalar>&);
377  void operator/=(const tmp<Field<scalar>>&);
378 
379  void operator+=(const Type&);
380  void operator-=(const Type&);
381 
382  void operator*=(const scalar&);
383  void operator/=(const scalar&);
384 
385 
386  // IOstream operators
387 
388  friend Ostream& operator<< <Type>
389  (Ostream&, const Field<Type>&);
390 
391  friend Ostream& operator<< <Type>
392  (Ostream&, const tmp<Field<Type>>&);
393 };
394 
395 
396 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
397 
398 } // End namespace Foam
399 
400 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
401 
402 #include "FieldFunctions.H"
403 
404 #ifdef NoRepository
405  #include "Field.C"
406 #endif
407 
408 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
409 
410 #endif
411 
412 // ************************************************************************* //
static tmp< Field< Type > > NewCalculatedType(const Field< Type2 > &f)
Return a pointer to a new calculatedFvPatchFieldField created on.
Definition: Field.H:238
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
uint8_t direction
Definition: direction.H:46
void operator-=(const UList< Type > &)
Definition: Field.C:842
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:641
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
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.
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:719
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:662
tmp< Field< Type > > clone() const
Clone.
Definition: Field.C:341
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
VSForm block(const label start) const
Definition: Field.C:698
void map(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 map from the given field
Definition: Field.C:351
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
tmp< Field< Type > > T() const
Return the field transpose (only defined for second rank tensors)
Definition: Field.C:710
void operator=(const Field< Type > &)
Definition: Field.C:757
tmp< Field< cmptType > > component(const direction) const
Return a component field of the field.
Definition: Field.C:650
labelList f(nPoints)
label size() const
Return the number of elements in the UList.
void autoMap(const FieldMapper &map, const bool applyFlip=true)
Map from self.
Definition: Field.C:514
void rmap(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 reverse-map from the given field
Definition: Field.C:577
Direction is an 8-bit unsigned integer type used to represent the Cartesian directions etc...
static const Field< Type > & null()
Return a null field.
Definition: Field.H:100
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:841
A class for managing temporary objects.
Definition: PtrList.H:54
void operator/=(const UList< scalar > &)
Definition: Field.C:844
void operator*=(const UList< scalar > &)
Definition: Field.C:843
Namespace for OpenFOAM.