FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/tmp.H>
45 #include <OpenFOAM/direction.H>
46 #include <OpenFOAM/VectorSpace.H>
47 #include <OpenFOAM/scalarList.H>
48 #include <OpenFOAM/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
88 
89  //- Declare type of 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 *reinterpret_cast< Field<Type>* >(0);
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 unallocLabelList& 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 unallocLabelList& 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 tmp field
164  Field
165  (
166  const tmp<Field<Type> >& tmapF,
167  const FieldMapper& map
168  );
169 
170  //- Construct as copy
171  Field(const Field<Type>&);
172 
173  //- Construct as copy or re-use as specified.
174  Field(Field<Type>&, bool reUse);
175 
176  //- Construct by transferring the Field contents
177  Field(const Xfer<Field<Type> >&);
178 
179  //- Construct as copy of subField
180  Field(const typename Field<Type>::subField&);
181 
182  //- Construct as copy of tmp<Field>
183 # ifdef ConstructFromTmp
184  Field(const tmp<Field<Type> >&);
185 # endif
186 
187  //- Construct from Istream
188  Field(Istream&);
189 
190  //- Construct from a dictionary entry
191  Field(const word& keyword, const dictionary& dict, const label size);
192 
193  //- Clone
194  tmp<Field<Type> > clone() const;
195 
196  //- Return a pointer to a new calculatedFvPatchFieldField created on
197  // freestore without setting patchField values
198  template<class Type2>
200  {
201  return tmp<Field<Type> >(new Field<Type>(f.size()));
202  }
203 
204 
205  // Member Functions
206 
207  //- 1 to 1 map from the given field
208  void map
209  (
210  const UList<Type>& mapF,
211  const unallocLabelList& mapAddressing
212  );
213 
214  //- 1 to 1 map from the given tmp field
215  void map
216  (
217  const tmp<Field<Type> >& tmapF,
218  const unallocLabelList& mapAddressing
219  );
220 
221  //- Interpolative map from the given field
222  void map
223  (
224  const UList<Type>& mapF,
225  const labelListList& mapAddressing,
226  const scalarListList& weights
227  );
228 
229  //- Interpolative map from the given tmp field
230  void map
231  (
232  const tmp<Field<Type> >& tmapF,
233  const labelListList& mapAddressing,
234  const scalarListList& weights
235  );
236 
237  //- Map from the given field
238  void map
239  (
240  const UList<Type>& mapF,
241  const FieldMapper& map
242  );
243 
244  //- Map from the given tmp field
245  void map
246  (
247  const tmp<Field<Type> >& tmapF,
248  const FieldMapper& map
249  );
250 
251  //- Map from self
252  void autoMap
253  (
254  const FieldMapper& map
255  );
256 
257  //- 1 to 1 reverse-map from the given field
258  void rmap
259  (
260  const UList<Type>& mapF,
261  const unallocLabelList& mapAddressing
262  );
263 
264  //- 1 to 1 reverse-map from the given tmp field
265  void rmap
266  (
267  const tmp<Field<Type> >& tmapF,
268  const unallocLabelList& mapAddressing
269  );
270 
271  //- Interpolative reverse map from the given field
272  void rmap
273  (
274  const UList<Type>& mapF,
275  const unallocLabelList& mapAddressing,
276  const scalarList& weights
277  );
278 
279  //- Interpolative reverse map from the given tmp field
280  void rmap
281  (
282  const tmp<Field<Type> >& tmapF,
283  const unallocLabelList& mapAddressing,
284  const scalarList& weights
285  );
286 
287  //- Negate this field
288  void negate();
289 
290  //- Return a component field of the field
291  tmp<Field<cmptType> > component(const direction) const;
292 
293  //- Replace a component field of the field
294  void replace(const direction, const UList<cmptType>&);
295 
296  //- Replace a component field of the field
297  void replace(const direction, const tmp<Field<cmptType> >&);
298 
299  //- Replace a component field of the field
300  void replace(const direction, const cmptType&);
301 
302  //- Return the field transpose (only defined for second rank tensors)
303  tmp<Field<Type> > T() const;
304 
305  //- Write the field as a dictionary entry
306  void writeEntry(const word& keyword, Ostream& os) const;
307 
308 
309  // Member operators
310 
311  void operator=(const Field<Type>&);
312  void operator=(const UList<Type>&);
313  void operator=(const SubField<Type>&);
314  void operator=(const tmp<Field<Type> >&);
315  void operator=(const Type&);
316 
317  template<class Form, class Cmpt, int nCmpt>
319 
320  void operator+=(const UList<Type>&);
321  void operator+=(const tmp<Field<Type> >&);
322 
323  void operator-=(const UList<Type>&);
324  void operator-=(const tmp<Field<Type> >&);
325 
326  void operator*=(const UList<scalar>&);
327  void operator*=(const tmp<Field<scalar> >&);
328 
329  void operator/=(const UList<scalar>&);
330  void operator/=(const tmp<Field<scalar> >&);
331 
332  void operator+=(const Type&);
333  void operator-=(const Type&);
334 
335  void operator*=(const scalar&);
336  void operator/=(const scalar&);
337 
338 
339  // IOstream operators
340 
341  friend Ostream& operator<< <Type>
342  (Ostream&, const Field<Type>&);
343 
344  friend Ostream& operator<< <Type>
345  (Ostream&, const tmp<Field<Type> >&);
346 };
347 
348 
349 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
350 
351 } // End namespace Foam
352 
353 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
354 
355 #include "FieldFunctions.H"
356 
357 #ifdef NoRepository
358 # include "Field.C"
359 #endif
360 
361 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
362 
363 #endif
364 
365 // ************************ vim: set sw=4 sts=4 et: ************************ //