FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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