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-2015 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 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 as copy of a UList<Type>
121  explicit Field(const UList<Type>&);
122 
123  //- Construct by transferring the List contents
124  explicit Field(const Xfer<List<Type> >&);
125 
126  //- Construct by 1 to 1 mapping from the given field
127  Field
128  (
129  const UList<Type>& mapF,
130  const labelUList& mapAddressing
131  );
132 
133  //- Construct by 1 to 1 mapping from the given tmp field
134  Field
135  (
136  const tmp<Field<Type> >& tmapF,
137  const labelUList& mapAddressing
138  );
139 
140  //- Construct by interpolative mapping from the given field
141  Field
142  (
143  const UList<Type>& mapF,
144  const labelListList& mapAddressing,
145  const scalarListList& weights
146  );
147 
148  //- Construct by interpolative mapping from the given tmp field
149  Field
150  (
151  const tmp<Field<Type> >& tmapF,
152  const labelListList& mapAddressing,
153  const scalarListList& weights
154  );
155 
156  //- Construct by mapping from the given field
157  Field
158  (
159  const UList<Type>& mapF,
160  const FieldMapper& map
161  );
162 
163  //- Construct by mapping from the given field
164  Field
165  (
166  const UList<Type>& mapF,
167  const FieldMapper& map,
168  const Type& defaultValue
169  );
170 
171  //- Construct by mapping from the given field
172  Field
173  (
174  const UList<Type>& mapF,
175  const FieldMapper& map,
176  const UList<Type>& defaultValues
177  );
178 
179  //- Construct by mapping from the given tmp field
180  Field
181  (
182  const tmp<Field<Type> >& tmapF,
183  const FieldMapper& map
184  );
185 
186  //- Construct by mapping from the given tmp field. Supplied uniform
187  // value for unmapped items
188  Field
189  (
190  const tmp<Field<Type> >& tmapF,
191  const FieldMapper& map,
192  const Type& defaultValue
193  );
194 
195  //- Construct by mapping from the given tmp field. Supplied values
196  // for unmapped items
197  Field
198  (
199  const tmp<Field<Type> >& tmapF,
200  const FieldMapper& map,
201  const UList<Type>& defaultValues
202  );
203 
204  //- Construct as copy
205  Field(const Field<Type>&);
206 
207  //- Construct as copy or re-use as specified.
208  Field(Field<Type>&, bool reUse);
209 
210  //- Construct by transferring the Field contents
211  Field(const Xfer<Field<Type> >&);
212 
213  //- Construct as copy of tmp<Field>
214  #ifndef NoConstructFromTmp
215  Field(const tmp<Field<Type> >&);
216  #endif
217 
218  //- Construct from Istream
219  Field(Istream&);
220 
221  //- Construct from a dictionary entry
222  Field(const word& keyword, const dictionary&, const label size);
223 
224  //- Clone
225  tmp<Field<Type> > clone() const;
226 
227  //- Return a pointer to a new calculatedFvPatchFieldField created on
228  // freestore without setting patchField values
229  template<class Type2>
231  {
232  return tmp<Field<Type> >(new Field<Type>(f.size()));
233  }
234 
235 
236  // Member Functions
237 
238  //- 1 to 1 map from the given field
239  void map
240  (
241  const UList<Type>& mapF,
242  const labelUList& mapAddressing
243  );
244 
245  //- 1 to 1 map from the given tmp field
246  void map
247  (
248  const tmp<Field<Type> >& tmapF,
249  const labelUList& mapAddressing
250  );
251 
252  //- Interpolative map from the given field
253  void map
254  (
255  const UList<Type>& mapF,
256  const labelListList& mapAddressing,
257  const scalarListList& weights
258  );
259 
260  //- Interpolative map from the given tmp field
261  void map
262  (
263  const tmp<Field<Type> >& tmapF,
264  const labelListList& mapAddressing,
265  const scalarListList& weights
266  );
267 
268  //- Map from the given field
269  void map
270  (
271  const UList<Type>& mapF,
272  const FieldMapper& map
273  );
274 
275  //- Map from the given tmp field
276  void map
277  (
278  const tmp<Field<Type> >& tmapF,
279  const FieldMapper& map
280  );
281 
282  //- Map from self
283  void autoMap
284  (
285  const FieldMapper& map
286  );
287 
288  //- 1 to 1 reverse-map from the given field
289  void rmap
290  (
291  const UList<Type>& mapF,
292  const labelUList& mapAddressing
293  );
294 
295  //- 1 to 1 reverse-map from the given tmp field
296  void rmap
297  (
298  const tmp<Field<Type> >& tmapF,
299  const labelUList& mapAddressing
300  );
301 
302  //- Interpolative reverse map from the given field
303  void rmap
304  (
305  const UList<Type>& mapF,
306  const labelUList& mapAddressing,
307  const UList<scalar>& weights
308  );
309 
310  //- Interpolative reverse map from the given tmp field
311  void rmap
312  (
313  const tmp<Field<Type> >& tmapF,
314  const labelUList& mapAddressing,
315  const UList<scalar>& weights
316  );
317 
318  //- Negate this field
319  void negate();
320 
321  //- Return a component field of the field
322  tmp<Field<cmptType> > component(const direction) const;
323 
324  //- Replace a component field of the field
325  void replace(const direction, const UList<cmptType>&);
326 
327  //- Replace a component field of the field
328  void replace(const direction, const tmp<Field<cmptType> >&);
329 
330  //- Replace a component field of the field
331  void replace(const direction, const cmptType&);
332 
333  //- Return the field transpose (only defined for second rank tensors)
334  tmp<Field<Type> > T() const;
335 
336  //- Write the field as a dictionary entry
337  void writeEntry(const word& keyword, Ostream& os) const;
338 
339 
340  // Member operators
341 
342  void operator=(const Field<Type>&);
343  void operator=(const UList<Type>&);
344  void operator=(const SubField<Type>&);
345  void operator=(const tmp<Field<Type> >&);
346  void operator=(const Type&);
347 
348  template<class Form, class Cmpt, int nCmpt>
350 
351  void operator+=(const UList<Type>&);
352  void operator+=(const tmp<Field<Type> >&);
353 
354  void operator-=(const UList<Type>&);
355  void operator-=(const tmp<Field<Type> >&);
356 
357  void operator*=(const UList<scalar>&);
358  void operator*=(const tmp<Field<scalar> >&);
359 
360  void operator/=(const UList<scalar>&);
361  void operator/=(const tmp<Field<scalar> >&);
362 
363  void operator+=(const Type&);
364  void operator-=(const Type&);
365 
366  void operator*=(const scalar&);
367  void operator/=(const scalar&);
368 
369 
370  // IOstream operators
371 
372  friend Ostream& operator<< <Type>
373  (Ostream&, const Field<Type>&);
374 
375  friend Ostream& operator<< <Type>
376  (Ostream&, const tmp<Field<Type> >&);
377 };
378 
379 
380 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
381 
382 } // End namespace Foam
383 
384 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
385 
386 #include "FieldFunctions.H"
387 
388 #ifdef NoRepository
389 # include "Field.C"
390 #endif
391 
392 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
393 
394 #endif
395 
396 // ************************************************************************* //
void operator+=(const UList< Type > &)
Definition: Field.C:752
unsigned char direction
Definition: direction.H:43
Pre-declare related SubField type.
Definition: Field.H:61
static const char *const typeName
Definition: Field.H:94
labelList f(nPoints)
tmp< Field< cmptType > > component(const direction) const
Return a component field of the field.
Definition: Field.C:578
Abstract base class to hold the Field mapping addressing and weights.
Definition: FieldMapper.H:43
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
tmp< Field< Type > > T() const
Return the field transpose (only defined for second rank tensors)
Definition: Field.C:625
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
A class for handling words, derived from string.
Definition: word.H:59
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
tmp< Field< Type > > clone() const
Clone.
Definition: Field.C:335
void size(const label)
Override size to be inconsistent with allocated storage.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
static const Field< Type > & null()
Return a null field.
Definition: Field.H:100
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
void operator*=(const UList< scalar > &)
Definition: Field.C:754
void autoMap(const FieldMapper &map)
Map from self.
Definition: Field.C:479
void operator=(const Field< Type > &)
Definition: Field.C:672
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:86
void writeEntry(const word &keyword, Ostream &os) const
Write the field as a dictionary entry.
Definition: Field.C:634
void map(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 map from the given field
Definition: Field.C:345
Pre-declare SubField and related Field type.
Definition: Field.H:57
Reference counter for various OpenFOAM components.
Definition: refCount.H:45
void operator-=(const UList< Type > &)
Definition: Field.C:753
void rmap(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 reverse-map from the given field
Definition: Field.C:505
void negate()
Negate this field.
Definition: Field.C:569
Traits class for primitives.
Definition: pTraits.H:50
Field()
Construct null.
Definition: Field.C:40
SubField< Type > subField
Declare type of subField.
Definition: Field.H:89
Direction is an integer type used to represent the Cartesian directions etc. Currently it is a typede...
Templated vector space.
Definition: VectorSpace.H:52
label size() const
Return the number of elements in the UList.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static tmp< Field< Type > > NewCalculatedType(const Field< Type2 > &f)
Return a pointer to a new calculatedFvPatchFieldField created on.
Definition: Field.H:229
void replace(const direction, const UList< cmptType > &)
Replace a component field of the field.
Definition: Field.C:590
void operator/=(const UList< scalar > &)
Definition: Field.C:755
A class for managing temporary objects.
Definition: PtrList.H:118