initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / fields / Fields / Field / Field.H
blob98e664ec8d5a503fb0ea98802fe0ab54dc8414f4
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Class
26     Foam::Field
28 Description
29     Generic templated field type.
31 SourceFiles
32     FieldFunctions.H
33     FieldFunctionsM.H
34     FieldMapper.H
35     FieldM.H
36     Field.C
37     FieldFunctions.C
38     FieldFunctionsM.C
40 \*---------------------------------------------------------------------------*/
42 #ifndef Field_H
43 #define Field_H
45 #include "tmp.H"
46 #include "direction.H"
47 #include "VectorSpace.H"
48 #include "scalarList.H"
49 #include "labelList.H"
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 namespace Foam
56 // Forward declaration of friend functions and operators
58 template<class Type>
59 class Field;
61 //- Pre-declare related SubField type
62 template<class Type>
63 class SubField;
65 template<class Type>
66 Ostream& operator<<(Ostream&, const Field<Type>&);
68 template<class Type>
69 Ostream& operator<<(Ostream&, const tmp<Field<Type> >&);
71 class FieldMapper;
72 class dictionary;
74 /*---------------------------------------------------------------------------*\
75                            Class Field Declaration
76 \*---------------------------------------------------------------------------*/
78 template<class Type>
79 class Field
81     public refCount,
82     public List<Type>
85 public:
87     //- Component type
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()
103         {
104             return *reinterpret_cast< Field<Type>* >(0);
105         }
108     // Constructors
110         //- Construct null
111         //  Used for temporary fields which are initialised after construction
112         Field();
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
128         Field
129         (
130             const UList<Type>& mapF,
131             const labelList& mapAddressing
132         );
134         //- Construct by 1 to 1 mapping from the given tmp field
135         Field
136         (
137             const tmp<Field<Type> >& tmapF,
138             const labelList& mapAddressing
139         );
141         //- Construct by interpolative mapping from the given field
142         Field
143         (
144             const UList<Type>& mapF,
145             const labelListList& mapAddressing,
146             const scalarListList& weights
147         );
149         //- Construct by interpolative mapping from the given tmp field
150         Field
151         (
152             const tmp<Field<Type> >& tmapF,
153             const labelListList& mapAddressing,
154             const scalarListList& weights
155         );
157         //- Construct by mapping from the given field
158         Field
159         (
160             const UList<Type>& mapF,
161             const FieldMapper& map
162         );
164         //- Construct by mapping from the given tmp field
165         Field
166         (
167             const tmp<Field<Type> >& tmapF,
168             const FieldMapper& map
169         );
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> >&);
186 #       endif
188         //- Construct from Istream
189         Field(Istream&);
191         //- Construct from a dictionary entry
192         Field(const word& keyword, const dictionary& dict, const label size);
194         //- Clone
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)
201         {
202             return tmp<Field<Type> >(new Field<Type>(f.size()));
203         }
206     // Member Functions
208         //- 1 to 1 map from the given field
209         void map
210         (
211             const UList<Type>& mapF,
212             const labelList& mapAddressing
213         );
215         //- 1 to 1 map from the given tmp field
216         void map
217         (
218             const tmp<Field<Type> >& tmapF,
219             const labelList& mapAddressing
220         );
222         //- Interpolative map from the given field
223         void map
224         (
225             const UList<Type>& mapF,
226             const labelListList& mapAddressing,
227             const scalarListList& weights
228         );
230         //- Interpolative map from the given tmp field
231         void map
232         (
233             const tmp<Field<Type> >& tmapF,
234             const labelListList& mapAddressing,
235             const scalarListList& weights
236         );
238         //- Map from the given field
239         void map
240         (
241             const UList<Type>& mapF,
242             const FieldMapper& map
243         );
245         //- Map from the given tmp field
246         void map
247         (
248             const tmp<Field<Type> >& tmapF,
249             const FieldMapper& map
250         );
252         //- Map from self
253         void autoMap
254         (
255             const FieldMapper& map
256         );
258         //- 1 to 1 reverse-map from the given field
259         void rmap
260         (
261             const UList<Type>& mapF,
262             const labelList& mapAddressing
263         );
265         //- 1 to 1 reverse-map from the given tmp field
266         void rmap
267         (
268             const tmp<Field<Type> >& tmapF,
269             const labelList& mapAddressing
270         );
272         //- Interpolative reverse map from the given field
273         void rmap
274         (
275             const UList<Type>& mapF,
276             const labelList& mapAddressing,
277             const scalarList& weights
278         );
280         //- Interpolative reverse map from the given tmp field
281         void rmap
282         (
283             const tmp<Field<Type> >& tmapF,
284             const labelList& mapAddressing,
285             const scalarList& weights
286         );
288         //- Negate this field
289         void negate();
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;
310     // Member operators
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"
358 #ifdef NoRepository
359 #   include "Field.C"
360 #endif
362 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
364 #endif
366 // ************************************************************************* //