OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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     Foam::Field
00027 
00028 Description
00029     Generic templated field type.
00030 
00031 SourceFiles
00032     FieldFunctions.H
00033     FieldFunctionsM.H
00034     FieldMapper.H
00035     FieldM.H
00036     Field.C
00037     FieldFunctions.C
00038     FieldFunctionsM.C
00039 
00040 \*---------------------------------------------------------------------------*/
00041 
00042 #ifndef Field_H
00043 #define Field_H
00044 
00045 #include "tmp.H"
00046 #include "direction.H"
00047 #include "VectorSpace.H"
00048 #include "scalarList.H"
00049 #include "labelList.H"
00050 
00051 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00052 
00053 namespace Foam
00054 {
00055 
00056 // Forward declaration of friend functions and operators
00057 
00058 template<class Type>
00059 class Field;
00060 
00061 //- Pre-declare related SubField type
00062 template<class Type>
00063 class SubField;
00064 
00065 template<class Type>
00066 Ostream& operator<<(Ostream&, const Field<Type>&);
00067 
00068 template<class Type>
00069 Ostream& operator<<(Ostream&, const tmp<Field<Type> >&);
00070 
00071 class FieldMapper;
00072 class dictionary;
00073 
00074 /*---------------------------------------------------------------------------*\
00075                            Class Field Declaration
00076 \*---------------------------------------------------------------------------*/
00077 
00078 template<class Type>
00079 class Field
00080 :
00081     public refCount,
00082     public List<Type>
00083 {
00084 
00085 public:
00086 
00087     //- Component type
00088     typedef typename pTraits<Type>::cmptType cmptType;
00089 
00090     //- Declare type of subField
00091     typedef SubField<Type> subField;
00092 
00093 
00094     // Static data members
00095 
00096         static const char* const typeName;
00097 
00098 
00099     // Static Member Functions
00100 
00101         //- Return a null field
00102         inline static const Field<Type>& null()
00103         {
00104             return *reinterpret_cast< Field<Type>* >(0);
00105         }
00106 
00107 
00108     // Constructors
00109 
00110         //- Construct null
00111         //  Used for temporary fields which are initialised after construction
00112         Field();
00113 
00114         //- Construct given size
00115         //  Used for temporary fields which are initialised after construction
00116         explicit Field(const label);
00117 
00118         //- Construct given size and initial value
00119         Field(const label, const Type&);
00120 
00121         //- Construct as copy of a UList<Type>
00122         explicit Field(const UList<Type>&);
00123 
00124         //- Construct by transferring the List contents
00125         explicit Field(const Xfer<List<Type> >&);
00126 
00127         //- Construct by 1 to 1 mapping from the given field
00128         Field
00129         (
00130             const UList<Type>& mapF,
00131             const labelList& mapAddressing
00132         );
00133 
00134         //- Construct by 1 to 1 mapping from the given tmp field
00135         Field
00136         (
00137             const tmp<Field<Type> >& tmapF,
00138             const labelList& mapAddressing
00139         );
00140 
00141         //- Construct by interpolative mapping from the given field
00142         Field
00143         (
00144             const UList<Type>& mapF,
00145             const labelListList& mapAddressing,
00146             const scalarListList& weights
00147         );
00148 
00149         //- Construct by interpolative mapping from the given tmp field
00150         Field
00151         (
00152             const tmp<Field<Type> >& tmapF,
00153             const labelListList& mapAddressing,
00154             const scalarListList& weights
00155         );
00156 
00157         //- Construct by mapping from the given field
00158         Field
00159         (
00160             const UList<Type>& mapF,
00161             const FieldMapper& map
00162         );
00163 
00164         //- Construct by mapping from the given tmp field
00165         Field
00166         (
00167             const tmp<Field<Type> >& tmapF,
00168             const FieldMapper& map
00169         );
00170 
00171         //- Construct as copy
00172         Field(const Field<Type>&);
00173 
00174         //- Construct as copy or re-use as specified.
00175         Field(Field<Type>&, bool reUse);
00176 
00177         //- Construct by transferring the Field contents
00178         Field(const Xfer<Field<Type> >&);
00179 
00180         //- Construct as copy of subField
00181         Field(const typename Field<Type>::subField&);
00182 
00183         //- Construct as copy of tmp<Field>
00184 #       ifdef ConstructFromTmp
00185         Field(const tmp<Field<Type> >&);
00186 #       endif
00187 
00188         //- Construct from Istream
00189         Field(Istream&);
00190 
00191         //- Construct from a dictionary entry
00192         Field(const word& keyword, const dictionary& dict, const label size);
00193 
00194         //- Clone
00195         tmp<Field<Type> > clone() const;
00196 
00197         //- Return a pointer to a new calculatedFvPatchFieldField created on
00198         //  freestore without setting patchField values
00199         template<class Type2>
00200         static tmp<Field<Type> > NewCalculatedType(const Field<Type2>& f)
00201         {
00202             return tmp<Field<Type> >(new Field<Type>(f.size()));
00203         }
00204 
00205 
00206     // Member Functions
00207 
00208         //- 1 to 1 map from the given field
00209         void map
00210         (
00211             const UList<Type>& mapF,
00212             const labelList& mapAddressing
00213         );
00214 
00215         //- 1 to 1 map from the given tmp field
00216         void map
00217         (
00218             const tmp<Field<Type> >& tmapF,
00219             const labelList& mapAddressing
00220         );
00221 
00222         //- Interpolative map from the given field
00223         void map
00224         (
00225             const UList<Type>& mapF,
00226             const labelListList& mapAddressing,
00227             const scalarListList& weights
00228         );
00229 
00230         //- Interpolative map from the given tmp field
00231         void map
00232         (
00233             const tmp<Field<Type> >& tmapF,
00234             const labelListList& mapAddressing,
00235             const scalarListList& weights
00236         );
00237 
00238         //- Map from the given field
00239         void map
00240         (
00241             const UList<Type>& mapF,
00242             const FieldMapper& map
00243         );
00244 
00245         //- Map from the given tmp field
00246         void map
00247         (
00248             const tmp<Field<Type> >& tmapF,
00249             const FieldMapper& map
00250         );
00251 
00252         //- Map from self
00253         void autoMap
00254         (
00255             const FieldMapper& map
00256         );
00257 
00258         //- 1 to 1 reverse-map from the given field
00259         void rmap
00260         (
00261             const UList<Type>& mapF,
00262             const labelList& mapAddressing
00263         );
00264 
00265         //- 1 to 1 reverse-map from the given tmp field
00266         void rmap
00267         (
00268             const tmp<Field<Type> >& tmapF,
00269             const labelList& mapAddressing
00270         );
00271 
00272         //- Interpolative reverse map from the given field
00273         void rmap
00274         (
00275             const UList<Type>& mapF,
00276             const labelList& mapAddressing,
00277             const scalarList& weights
00278         );
00279 
00280         //- Interpolative reverse map from the given tmp field
00281         void rmap
00282         (
00283             const tmp<Field<Type> >& tmapF,
00284             const labelList& mapAddressing,
00285             const scalarList& weights
00286         );
00287 
00288         //- Negate this field
00289         void negate();
00290 
00291         //- Return a component field of the field
00292         tmp<Field<cmptType> > component(const direction) const;
00293 
00294         //- Replace a component field of the field
00295         void replace(const direction, const UList<cmptType>&);
00296 
00297         //- Replace a component field of the field
00298         void replace(const direction, const tmp<Field<cmptType> >&);
00299 
00300         //- Replace a component field of the field
00301         void replace(const direction, const cmptType&);
00302 
00303         //- Return the field transpose (only defined for second rank tensors)
00304         tmp<Field<Type> > T() const;
00305 
00306         //- Write the field as a dictionary entry
00307         void writeEntry(const word& keyword, Ostream& os) const;
00308 
00309 
00310     // Member operators
00311 
00312         void operator=(const Field<Type>&);
00313         void operator=(const UList<Type>&);
00314         void operator=(const SubField<Type>&);
00315         void operator=(const tmp<Field<Type> >&);
00316         void operator=(const Type&);
00317 
00318         template<class Form, class Cmpt, int nCmpt>
00319         void operator=(const VectorSpace<Form,Cmpt,nCmpt>&);
00320 
00321         void operator+=(const UList<Type>&);
00322         void operator+=(const tmp<Field<Type> >&);
00323 
00324         void operator-=(const UList<Type>&);
00325         void operator-=(const tmp<Field<Type> >&);
00326 
00327         void operator*=(const UList<scalar>&);
00328         void operator*=(const tmp<Field<scalar> >&);
00329 
00330         void operator/=(const UList<scalar>&);
00331         void operator/=(const tmp<Field<scalar> >&);
00332 
00333         void operator+=(const Type&);
00334         void operator-=(const Type&);
00335 
00336         void operator*=(const scalar&);
00337         void operator/=(const scalar&);
00338 
00339 
00340     // IOstream operators
00341 
00342         friend Ostream& operator<< <Type>
00343         (Ostream&, const Field<Type>&);
00344 
00345         friend Ostream& operator<< <Type>
00346         (Ostream&, const tmp<Field<Type> >&);
00347 };
00348 
00349 
00350 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00351 
00352 } // End namespace Foam
00353 
00354 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00355 
00356 #include "FieldFunctions.H"
00357 
00358 #ifdef NoRepository
00359 #   include "Field.C"
00360 #endif
00361 
00362 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00363 
00364 #endif
00365 
00366 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd