1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
28 Generic templated field type.
39 \*---------------------------------------------------------------------------*/
45 #include "direction.H"
46 #include "VectorSpace.H"
47 #include "scalarList.H"
48 #include "labelList.H"
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 // Forward declaration of friend functions and operators
60 //- Pre-declare related SubField type
65 Ostream& operator<<(Ostream&, const Field<Type>&);
68 Ostream& operator<<(Ostream&, const tmp<Field<Type> >&);
73 /*---------------------------------------------------------------------------*\
74 Class Field Declaration
75 \*---------------------------------------------------------------------------*/
87 typedef typename pTraits<Type>::cmptType cmptType;
89 //- Declare type of subField
90 typedef SubField<Type> subField;
93 // Static data members
95 static const char* const typeName;
98 // Static Member Functions
100 //- Return a null field
101 inline static const Field<Type>& null()
103 return *reinterpret_cast< Field<Type>* >(0);
110 // Used for temporary fields which are initialised after construction
113 //- Construct given size
114 // Used for temporary fields which are initialised after construction
115 explicit Field(const label);
117 //- Construct given size and initial value
118 Field(const label, const Type&);
120 //- Construct as copy of a UList\<Type\>
121 explicit Field(const UList<Type>&);
123 //- Construct by transferring the List contents
124 explicit Field(const Xfer<List<Type> >&);
126 //- Construct by 1 to 1 mapping from the given field
129 const UList<Type>& mapF,
130 const labelUList& mapAddressing
133 //- Construct by 1 to 1 mapping from the given tmp field
136 const tmp<Field<Type> >& tmapF,
137 const labelUList& mapAddressing
140 //- Construct by interpolative mapping from the given field
143 const UList<Type>& mapF,
144 const labelListList& mapAddressing,
145 const scalarListList& weights
148 //- Construct by interpolative mapping from the given tmp field
151 const tmp<Field<Type> >& tmapF,
152 const labelListList& mapAddressing,
153 const scalarListList& weights
156 //- Construct by mapping from the given field
159 const UList<Type>& mapF,
160 const FieldMapper& map
163 //- Construct by mapping from the given tmp field
166 const tmp<Field<Type> >& tmapF,
167 const FieldMapper& map
170 //- Construct as copy
171 Field(const Field<Type>&);
173 //- Construct as copy or re-use as specified.
174 Field(Field<Type>&, bool reUse);
176 //- Construct by transferring the Field contents
177 Field(const Xfer<Field<Type> >&);
179 #ifdef __INTEL_COMPILER
180 //- Construct as copy of subField
181 Field(const typename Field<Type>::subField&);
184 //- Construct as copy of tmp<Field>
185 # ifdef ConstructFromTmp
186 Field(const tmp<Field<Type> >&);
189 //- Construct from Istream
192 //- Construct from a dictionary entry
193 Field(const word& keyword, const dictionary&, const label size);
196 tmp<Field<Type> > clone() const;
198 //- Return a pointer to a new calculatedFvPatchFieldField created on
199 // freestore without setting patchField values
200 template<class Type2>
201 static tmp<Field<Type> > NewCalculatedType(const Field<Type2>& f)
203 return tmp<Field<Type> >(new Field<Type>(f.size()));
209 //- 1 to 1 map from the given field
212 const UList<Type>& mapF,
213 const labelUList& mapAddressing
216 //- 1 to 1 map from the given tmp field
219 const tmp<Field<Type> >& tmapF,
220 const labelUList& mapAddressing
223 //- Interpolative map from the given field
226 const UList<Type>& mapF,
227 const labelListList& mapAddressing,
228 const scalarListList& weights
231 //- Interpolative map from the given tmp field
234 const tmp<Field<Type> >& tmapF,
235 const labelListList& mapAddressing,
236 const scalarListList& weights
239 //- Map from the given field
242 const UList<Type>& mapF,
243 const FieldMapper& map
246 //- Map from the given tmp field
249 const tmp<Field<Type> >& tmapF,
250 const FieldMapper& map
256 const FieldMapper& map
259 //- 1 to 1 reverse-map from the given field
262 const UList<Type>& mapF,
263 const labelUList& mapAddressing
266 //- 1 to 1 reverse-map from the given tmp field
269 const tmp<Field<Type> >& tmapF,
270 const labelUList& mapAddressing
273 //- Interpolative reverse map from the given field
276 const UList<Type>& mapF,
277 const labelUList& mapAddressing,
278 const UList<scalar>& weights
281 //- Interpolative reverse map from the given tmp field
284 const tmp<Field<Type> >& tmapF,
285 const labelUList& mapAddressing,
286 const UList<scalar>& weights
289 //- Negate this field
292 //- Return a component field of the field
293 tmp<Field<cmptType> > component(const direction) const;
295 //- Replace a component field of the field
296 void replace(const direction, const UList<cmptType>&);
298 //- Replace a component field of the field
299 void replace(const direction, const tmp<Field<cmptType> >&);
301 //- Replace a component field of the field
302 void replace(const direction, const cmptType&);
304 //- Return the field transpose (only defined for second rank tensors)
305 tmp<Field<Type> > T() const;
307 //- Write the field as a dictionary entry
308 void writeEntry(const word& keyword, Ostream& os) const;
313 void operator=(const Field<Type>&);
314 void operator=(const UList<Type>&);
315 void operator=(const SubField<Type>&);
316 void operator=(const tmp<Field<Type> >&);
317 void operator=(const Type&);
319 template<class Form, class Cmpt, int nCmpt>
320 void operator=(const VectorSpace<Form,Cmpt,nCmpt>&);
322 void operator+=(const UList<Type>&);
323 void operator+=(const tmp<Field<Type> >&);
325 void operator-=(const UList<Type>&);
326 void operator-=(const tmp<Field<Type> >&);
328 void operator*=(const UList<scalar>&);
329 void operator*=(const tmp<Field<scalar> >&);
331 void operator/=(const UList<scalar>&);
332 void operator/=(const tmp<Field<scalar> >&);
334 void operator+=(const Type&);
335 void operator-=(const Type&);
337 void operator*=(const scalar&);
338 void operator/=(const scalar&);
341 // IOstream operators
343 friend Ostream& operator<< <Type>
344 (Ostream&, const Field<Type>&);
346 friend Ostream& operator<< <Type>
347 (Ostream&, const tmp<Field<Type> >&);
351 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
353 } // End namespace Foam
355 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
357 #include "FieldFunctions.H"
363 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
367 // ************************************************************************* //