OpenFOAM logo
Open Source CFD Toolkit

Field.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2005 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Field<T>
00027 
00028 Description
00029     Generic field type.
00030 
00031 SourceFiles
00032     Field.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef Field_H
00037 #define Field_H
00038 
00039 #include "direction.H"
00040 #include "VectorSpace.H"
00041 #include "scalarList.H"
00042 #include "labelList.H"
00043 
00044 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00045 
00046 namespace Foam
00047 {
00048 
00049 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
00050 
00051 template<class Type>
00052 class Field;
00053 
00054 //- Pre-declare related SubField type
00055 template<class Type>
00056 class SubField;
00057 
00058 template<class Type>
00059 Ostream& operator<<(Ostream&, const Field<Type>&);
00060 
00061 template<class Type>
00062 Ostream& operator<<(Ostream&, const tmp<Field<Type> >&);
00063 
00064 class FieldMapper;
00065 class dictionary;
00066 
00067 /*---------------------------------------------------------------------------*\
00068                            Class Field Declaration
00069 \*---------------------------------------------------------------------------*/
00070 
00071 template<class Type>
00072 class Field
00073 :
00074     public refCount,
00075     public List<Type>
00076 {
00077 
00078 public:
00079 
00080     //- Component type
00081     typedef typename pTraits<Type>::cmptType cmptType;
00082 
00083     //- Declare type of subField
00084     typedef SubField<Type> subField;
00085 
00086 
00087     // Static data members
00088 
00089         static const char* const typeName;
00090 
00091 
00092     // Constructors
00093 
00094         //- Construct null
00095         //  Used for temporary fields which are initialised after construction
00096         Field();
00097 
00098         //- Construct given size
00099         //  Used for temporary fields which are initialised after construction
00100         explicit Field(const label);
00101 
00102         //- Construct given size and initial value
00103         Field(const label, const Type&);
00104 
00105         //- Construct as copy of a UList<Type>
00106         explicit Field(const UList<Type>&);
00107 
00108         //- Construct by 1 to 1 mapping from the given field
00109         Field
00110         (
00111             const UList<Type>& mapF,
00112             const labelList& mapAddressing
00113         );
00114 
00115         //- Construct by 1 to 1 mapping from the given tmp field
00116         Field
00117         (
00118             const tmp<Field<Type> >& tmapF,
00119             const labelList& mapAddressing
00120         );
00121 
00122         //- Construct by interpolative mapping from the given field
00123         Field
00124         (
00125             const UList<Type>& mapF,
00126             const labelListList& mapAddressing,
00127             const scalarListList& weights
00128         );
00129 
00130         //- Construct by interpolative mapping from the given tmp field
00131         Field
00132         (
00133             const tmp<Field<Type> >& tmapF,
00134             const labelListList& mapAddressing,
00135             const scalarListList& weights
00136         );
00137 
00138         //- Construct by mapping from the given field
00139         Field
00140         (
00141             const UList<Type>& mapF,
00142             const FieldMapper& map
00143         );
00144 
00145         //- Construct by mapping from the given tmp field
00146         Field
00147         (
00148             const tmp<Field<Type> >& tmapF,
00149             const FieldMapper& map
00150         );
00151 
00152         //- Construct as copy
00153         Field(const Field<Type>&);
00154 
00155         //- Construct as copy or re-use as specified.
00156         Field(Field<Type>&, bool reUse);
00157 
00158         //- Construct as copy of subField
00159         Field(const typename Field<Type>::subField&);
00160 
00161         //- Construct as copy of tmp<Field>
00162 #       ifdef ConstructFromTmp
00163         Field(const tmp<Field<Type> >&);
00164 #       endif
00165 
00166         //- Construct from Istream
00167         Field(Istream&);
00168 
00169         //- Construct from a dictionary entry
00170         Field(const word& keyword, const dictionary& dict, const label size);
00171 
00172         //- Clone
00173         tmp<Field<Type> > clone() const;
00174 
00175         //- Return a pointer to a new calculatedFvPatchFieldField created on
00176         //  freestore without setting patchField values
00177         template<class Type2>
00178         static tmp<Field<Type> > NewCalculatedType
00179         (
00180             const Field<Type2>& f
00181         )
00182         {
00183             return tmp<Field<Type> >(new Field<Type>(f.size()));
00184         }
00185 
00186 
00187     // Member functions
00188 
00189         //- Return a null Field
00190         static Field<Type>& null();
00191 
00192 
00193         //- 1 to 1 map from the given field
00194         void map
00195         (
00196             const UList<Type>& mapF,
00197             const labelList& mapAddressing
00198         );
00199 
00200         //- 1 to 1 map from the given tmp field
00201         void map
00202         (
00203             const tmp<Field<Type> >& tmapF,
00204             const labelList& mapAddressing
00205         );
00206 
00207         //- Interpolative map from the given field
00208         void map
00209         (
00210             const UList<Type>& mapF,
00211             const labelListList& mapAddressing,
00212             const scalarListList& weights
00213         );
00214 
00215         //- Interpolative map from the given tmp field
00216         void map
00217         (
00218             const tmp<Field<Type> >& tmapF,
00219             const labelListList& mapAddressing,
00220             const scalarListList& weights
00221         );
00222 
00223         //- Map from the given field
00224         void map
00225         (
00226             const UList<Type>& mapF,
00227             const FieldMapper& map
00228         );
00229 
00230         //- Map from the given tmp field
00231         void map
00232         (
00233             const tmp<Field<Type> >& tmapF,
00234             const FieldMapper& map
00235         );
00236 
00237         //- Map from self
00238         void autoMap
00239         (
00240             const FieldMapper& map
00241         );
00242 
00243         //- 1 to 1 reverse-map from the given field
00244         void rmap
00245         (
00246             const UList<Type>& mapF,
00247             const labelList& mapAddressing
00248         );
00249 
00250         //- 1 to 1 reverse-map from the given tmp field
00251         void rmap
00252         (
00253             const tmp<Field<Type> >& tmapF,
00254             const labelList& mapAddressing
00255         );
00256 
00257         //- Interpolative reverse map from the given field
00258         void rmap
00259         (
00260             const UList<Type>& mapF,
00261             const labelList& mapAddressing,
00262             const scalarList& weights
00263         );
00264 
00265         //- Interpolative reverse map from the given tmp field
00266         void rmap
00267         (
00268             const tmp<Field<Type> >& tmapF,
00269             const labelList& mapAddressing,
00270             const scalarList& weights
00271         );
00272 
00273         //- Negate this field
00274         void negate();
00275 
00276         //- Return a component field of the field
00277         tmp<Field<cmptType> > component(const direction) const;
00278 
00279         //- Replace a component field of the field
00280         void replace(const direction, const UList<cmptType>&);
00281 
00282         //- Return the field transpose (only defined for second rank tensors)
00283         tmp<Field<Type> > T() const;
00284 
00285         //- Write the field as a dictionary entry
00286         void writeEntry(const word& keyword, Ostream& os) const;
00287 
00288 
00289     // Member operators
00290 
00291         void operator=(const Field<Type>&);
00292         void operator=(const UList<Type>&);
00293         void operator=(const SubField<Type>&);
00294         void operator=(const tmp<Field<Type> >&);
00295         void operator=(const Type&);
00296 
00297         void operator+=(const UList<Type>&);
00298         void operator+=(const tmp<Field<Type> >&);
00299 
00300         void operator-=(const UList<Type>&);
00301         void operator-=(const tmp<Field<Type> >&);
00302 
00303         void operator*=(const UList<scalar>&);
00304         void operator*=(const tmp<Field<scalar> >&);
00305 
00306         void operator/=(const UList<scalar>&);
00307         void operator/=(const tmp<Field<scalar> >&);
00308 
00309         void operator+=(const Type&);
00310         void operator-=(const Type&);
00311 
00312         void operator*=(const scalar&);
00313         void operator/=(const scalar&);
00314 
00315 
00316     // IOstream operators
00317 
00318         friend Ostream& operator<< <Type>(Ostream&, const Field<Type>&);
00319         friend Ostream& operator<< <Type>(Ostream&, const tmp<Field<Type> >&);
00320 };
00321 
00322 
00323 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00324 
00325 } // End namespace Foam
00326 
00327 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00328 
00329 #include "FieldFunctions.H"
00330 
00331 #ifdef NoRepository
00332 #   include "Field.C"
00333 #endif
00334 
00335 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00336 
00337 #endif
00338 
00339 // ************************************************************************* //
For further information go to www.openfoam.org