1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Generic templated field type.
40 \*---------------------------------------------------------------------------*/
46 #include "direction.H"
47 #include "VectorSpace.H"
48 #include "scalarList.H"
49 #include "labelList.H"
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 // Forward declaration of friend functions and operators
61 //- Pre-declare related SubField type
66 Ostream& operator<<(Ostream&, const Field<Type>&);
69 Ostream& operator<<(Ostream&, const tmp<Field<Type> >&);
74 /*---------------------------------------------------------------------------*\
75 Class Field Declaration
76 \*---------------------------------------------------------------------------*/
88 typedef typename pTraits<Type>::cmptType cmptType;
90 //- Declare type of subField
91 typedef SubField<Type> subField;
94 // Static data members
96 static const char* const typeName;
99 // Static Member Functions
101 //- Return a null field
102 inline static const Field<Type>& null()
104 return *reinterpret_cast< Field<Type>* >(0);
111 // Used for temporary fields which are initialised after construction
114 //- Construct given size
115 // Used for temporary fields which are initialised after construction
116 explicit Field(const label);
118 //- Construct given size and initial value
119 Field(const label, const Type&);
121 //- Construct as copy of a UList\<Type\>
122 explicit Field(const UList<Type>&);
124 //- Construct by transferring the List contents
125 explicit Field(const Xfer<List<Type> >&);
127 //- Construct by 1 to 1 mapping from the given field
130 const UList<Type>& mapF,
131 const labelList& mapAddressing
134 //- Construct by 1 to 1 mapping from the given tmp field
137 const tmp<Field<Type> >& tmapF,
138 const labelList& mapAddressing
141 //- Construct by interpolative mapping from the given field
144 const UList<Type>& mapF,
145 const labelListList& mapAddressing,
146 const scalarListList& weights
149 //- Construct by interpolative mapping from the given tmp field
152 const tmp<Field<Type> >& tmapF,
153 const labelListList& mapAddressing,
154 const scalarListList& weights
157 //- Construct by mapping from the given field
160 const UList<Type>& mapF,
161 const FieldMapper& map
164 //- Construct by mapping from the given tmp field
167 const tmp<Field<Type> >& tmapF,
168 const FieldMapper& map
171 //- Construct as copy
172 Field(const Field<Type>&);
174 //- Construct as copy or re-use as specified.
175 Field(Field<Type>&, bool reUse);
177 //- Construct by transferring the Field contents
178 Field(const Xfer<Field<Type> >&);
180 //- Construct as copy of subField
181 Field(const typename Field<Type>::subField&);
183 //- Construct as copy of tmp<Field>
184 # ifdef ConstructFromTmp
185 Field(const tmp<Field<Type> >&);
188 //- Construct from Istream
191 //- Construct from a dictionary entry
192 Field(const word& keyword, const dictionary& dict, const label size);
195 tmp<Field<Type> > clone() const;
197 //- Return a pointer to a new calculatedFvPatchFieldField created on
198 // freestore without setting patchField values
199 template<class Type2>
200 static tmp<Field<Type> > NewCalculatedType(const Field<Type2>& f)
202 return tmp<Field<Type> >(new Field<Type>(f.size()));
208 //- 1 to 1 map from the given field
211 const UList<Type>& mapF,
212 const labelList& mapAddressing
215 //- 1 to 1 map from the given tmp field
218 const tmp<Field<Type> >& tmapF,
219 const labelList& mapAddressing
222 //- Interpolative map from the given field
225 const UList<Type>& mapF,
226 const labelListList& mapAddressing,
227 const scalarListList& weights
230 //- Interpolative map from the given tmp field
233 const tmp<Field<Type> >& tmapF,
234 const labelListList& mapAddressing,
235 const scalarListList& weights
238 //- Map from the given field
241 const UList<Type>& mapF,
242 const FieldMapper& map
245 //- Map from the given tmp field
248 const tmp<Field<Type> >& tmapF,
249 const FieldMapper& map
255 const FieldMapper& map
258 //- 1 to 1 reverse-map from the given field
261 const UList<Type>& mapF,
262 const labelList& mapAddressing
265 //- 1 to 1 reverse-map from the given tmp field
268 const tmp<Field<Type> >& tmapF,
269 const labelList& mapAddressing
272 //- Interpolative reverse map from the given field
275 const UList<Type>& mapF,
276 const labelList& mapAddressing,
277 const scalarList& weights
280 //- Interpolative reverse map from the given tmp field
283 const tmp<Field<Type> >& tmapF,
284 const labelList& mapAddressing,
285 const scalarList& weights
288 //- Negate this field
291 //- Return a component field of the field
292 tmp<Field<cmptType> > component(const direction) const;
294 //- Replace a component field of the field
295 void replace(const direction, const UList<cmptType>&);
297 //- Replace a component field of the field
298 void replace(const direction, const tmp<Field<cmptType> >&);
300 //- Replace a component field of the field
301 void replace(const direction, const cmptType&);
303 //- Return the field transpose (only defined for second rank tensors)
304 tmp<Field<Type> > T() const;
306 //- Write the field as a dictionary entry
307 void writeEntry(const word& keyword, Ostream& os) const;
312 void operator=(const Field<Type>&);
313 void operator=(const UList<Type>&);
314 void operator=(const SubField<Type>&);
315 void operator=(const tmp<Field<Type> >&);
316 void operator=(const Type&);
318 template<class Form, class Cmpt, int nCmpt>
319 void operator=(const VectorSpace<Form,Cmpt,nCmpt>&);
321 void operator+=(const UList<Type>&);
322 void operator+=(const tmp<Field<Type> >&);
324 void operator-=(const UList<Type>&);
325 void operator-=(const tmp<Field<Type> >&);
327 void operator*=(const UList<scalar>&);
328 void operator*=(const tmp<Field<scalar> >&);
330 void operator/=(const UList<scalar>&);
331 void operator/=(const tmp<Field<scalar> >&);
333 void operator+=(const Type&);
334 void operator-=(const Type&);
336 void operator*=(const scalar&);
337 void operator/=(const scalar&);
340 // IOstream operators
342 friend Ostream& operator<< <Type>
343 (Ostream&, const Field<Type>&);
345 friend Ostream& operator<< <Type>
346 (Ostream&, const tmp<Field<Type> >&);
350 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
352 } // End namespace Foam
354 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
356 #include "FieldFunctions.H"
362 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
366 // ************************************************************************* //