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