OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen 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-2007 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     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 template friend fuctions * * * * * * * //
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     // Constructors
00100 
00101         //- Construct null
00102         //  Used for temporary fields which are initialised after construction
00103         Field();
00104 
00105         //- Construct given size
00106         //  Used for temporary fields which are initialised after construction
00107         explicit Field(const label);
00108 
00109         //- Construct given size and initial value
00110         Field(const label, const Type&);
00111 
00112         //- Construct as copy of a UList<Type>
00113         explicit Field(const UList<Type>&);
00114 
00115         //- Construct by 1 to 1 mapping from the given field
00116         Field
00117         (
00118             const UList<Type>& mapF,
00119             const labelList& mapAddressing
00120         );
00121 
00122         //- Construct by 1 to 1 mapping from the given tmp field
00123         Field
00124         (
00125             const tmp<Field<Type> >& tmapF,
00126             const labelList& mapAddressing
00127         );
00128 
00129         //- Construct by interpolative mapping from the given field
00130         Field
00131         (
00132             const UList<Type>& mapF,
00133             const labelListList& mapAddressing,
00134             const scalarListList& weights
00135         );
00136 
00137         //- Construct by interpolative mapping from the given tmp field
00138         Field
00139         (
00140             const tmp<Field<Type> >& tmapF,
00141             const labelListList& mapAddressing,
00142             const scalarListList& weights
00143         );
00144 
00145         //- Construct by mapping from the given field
00146         Field
00147         (
00148             const UList<Type>& mapF,
00149             const FieldMapper& map
00150         );
00151 
00152         //- Construct by mapping from the given tmp field
00153         Field
00154         (
00155             const tmp<Field<Type> >& tmapF,
00156             const FieldMapper& map
00157         );
00158 
00159         //- Construct as copy
00160         Field(const Field<Type>&);
00161 
00162         //- Construct as copy or re-use as specified.
00163         Field(Field<Type>&, bool reUse);
00164 
00165         //- Construct as copy of subField
00166         Field(const typename Field<Type>::subField&);
00167 
00168         //- Construct as copy of tmp<Field>
00169 #       ifdef ConstructFromTmp
00170         Field(const tmp<Field<Type> >&);
00171 #       endif
00172 
00173         //- Construct from Istream
00174         Field(Istream&);
00175 
00176         //- Construct from a dictionary entry
00177         Field(const word& keyword, const dictionary& dict, const label size);
00178 
00179         //- Clone
00180         tmp<Field<Type> > clone() const;
00181 
00182         //- Return a pointer to a new calculatedFvPatchFieldField created on
00183         //  freestore without setting patchField values
00184         template<class Type2>
00185         static tmp<Field<Type> > NewCalculatedType(const Field<Type2>& f)
00186         {
00187             return tmp<Field<Type> >(new Field<Type>(f.size()));
00188         }
00189 
00190 
00191     // Member functions
00192 
00193         //- Return a null Field
00194         static Field<Type>& null();
00195 
00196 
00197         //- 1 to 1 map from the given field
00198         void map
00199         (
00200             const UList<Type>& mapF,
00201             const labelList& mapAddressing
00202         );
00203 
00204         //- 1 to 1 map from the given tmp field
00205         void map
00206         (
00207             const tmp<Field<Type> >& tmapF,
00208             const labelList& mapAddressing
00209         );
00210 
00211         //- Interpolative map from the given field
00212         void map
00213         (
00214             const UList<Type>& mapF,
00215             const labelListList& mapAddressing,
00216             const scalarListList& weights
00217         );
00218 
00219         //- Interpolative map from the given tmp field
00220         void map
00221         (
00222             const tmp<Field<Type> >& tmapF,
00223             const labelListList& mapAddressing,
00224             const scalarListList& weights
00225         );
00226 
00227         //- Map from the given field
00228         void map
00229         (
00230             const UList<Type>& mapF,
00231             const FieldMapper& map
00232         );
00233 
00234         //- Map from the given tmp field
00235         void map
00236         (
00237             const tmp<Field<Type> >& tmapF,
00238             const FieldMapper& map
00239         );
00240 
00241         //- Map from self
00242         void autoMap
00243         (
00244             const FieldMapper& map
00245         );
00246 
00247         //- 1 to 1 reverse-map from the given field
00248         void rmap
00249         (
00250             const UList<Type>& mapF,
00251             const labelList& mapAddressing
00252         );
00253 
00254         //- 1 to 1 reverse-map from the given tmp field
00255         void rmap
00256         (
00257             const tmp<Field<Type> >& tmapF,
00258             const labelList& mapAddressing
00259         );
00260 
00261         //- Interpolative reverse map from the given field
00262         void rmap
00263         (
00264             const UList<Type>& mapF,
00265             const labelList& mapAddressing,
00266             const scalarList& weights
00267         );
00268 
00269         //- Interpolative reverse map from the given tmp field
00270         void rmap
00271         (
00272             const tmp<Field<Type> >& tmapF,
00273             const labelList& mapAddressing,
00274             const scalarList& weights
00275         );
00276 
00277         //- Negate this field
00278         void negate();
00279 
00280         //- Return a component field of the field
00281         tmp<Field<cmptType> > component(const direction) const;
00282 
00283         //- Replace a component field of the field
00284         void replace(const direction, const UList<cmptType>&);
00285 
00286         //- Replace a component field of the field
00287         void replace(const direction, const tmp<Field<cmptType> >&);
00288 
00289         //- Replace a component field of the field
00290         void replace(const direction, const cmptType&);
00291 
00292         //- Return the field transpose (only defined for second rank tensors)
00293         tmp<Field<Type> > T() const;
00294 
00295         //- Write the field as a dictionary entry
00296         void writeEntry(const word& keyword, Ostream& os) const;
00297 
00298 
00299     // Member operators
00300 
00301         void operator=(const Field<Type>&);
00302         void operator=(const UList<Type>&);
00303         void operator=(const SubField<Type>&);
00304         void operator=(const tmp<Field<Type> >&);
00305         void operator=(const Type&);
00306 
00307         template<class Form, class Cmpt, int nCmpt>
00308         void operator=(const VectorSpace<Form,Cmpt,nCmpt>&);
00309 
00310         void operator+=(const UList<Type>&);
00311         void operator+=(const tmp<Field<Type> >&);
00312 
00313         void operator-=(const UList<Type>&);
00314         void operator-=(const tmp<Field<Type> >&);
00315 
00316         void operator*=(const UList<scalar>&);
00317         void operator*=(const tmp<Field<scalar> >&);
00318 
00319         void operator/=(const UList<scalar>&);
00320         void operator/=(const tmp<Field<scalar> >&);
00321 
00322         void operator+=(const Type&);
00323         void operator-=(const Type&);
00324 
00325         void operator*=(const scalar&);
00326         void operator/=(const scalar&);
00327 
00328 
00329     // IOstream operators
00330 
00331         friend Ostream& operator<< <Type>(Ostream&, const Field<Type>&);
00332         friend Ostream& operator<< <Type>(Ostream&, const tmp<Field<Type> >&);
00333 };
00334 
00335 
00336 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00337 
00338 } // End namespace Foam
00339 
00340 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00341 
00342 #include "FieldFunctions.H"
00343 
00344 #ifdef NoRepository
00345 #   include "Field.C"
00346 #endif
00347 
00348 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00349 
00350 #endif
00351 
00352 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd