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

DimensionedField.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::DimensionedField
00027 
00028 Description
00029     Field with dimensions and associated with geometry type GeoMesh which is
00030     used to size the field and a reference to it is maintained.
00031 
00032 SourceFiles
00033     DimensionedFieldI.H
00034     DimensionedField.C
00035     DimensionedFieldIO.C
00036 
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #ifndef DimensionedField_H
00040 #define DimensionedField_H
00041 
00042 #include "regIOobject.H"
00043 #include "Field.H"
00044 #include "dimensionedType.H"
00045 
00046 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00047 
00048 namespace Foam
00049 {
00050 
00051 // Forward declaration of friend functions and operators
00052 
00053 template<class Type, class GeoMesh> class DimensionedField;
00054 
00055 template<class Type, class GeoMesh> Ostream& operator<<
00056 (
00057     Ostream&,
00058     const DimensionedField<Type, GeoMesh>&
00059 );
00060 
00061 template<class Type, class GeoMesh> Ostream& operator<<
00062 (
00063     Ostream&,
00064     const tmp<DimensionedField<Type, GeoMesh> >&
00065 );
00066 
00067 
00068 /*---------------------------------------------------------------------------*\
00069                            Class DimensionedField Declaration
00070 \*---------------------------------------------------------------------------*/
00071 
00072 template<class Type, class GeoMesh>
00073 class DimensionedField
00074 :
00075     public regIOobject,
00076     public Field<Type>
00077 {
00078 
00079 public:
00080 
00081     // Public typedefs
00082 
00083         typedef typename GeoMesh::Mesh Mesh;
00084         typedef typename Field<Type>::cmptType cmptType;
00085 
00086 
00087 private:
00088 
00089     // Private data
00090 
00091         //- Reference to mesh
00092         const Mesh& mesh_;
00093 
00094         //- Dimension set for this field
00095         dimensionSet dimensions_;
00096 
00097 
00098 public:
00099 
00100     //- Runtime type information
00101     TypeName("DimensionedField");
00102 
00103     // Static Member Functions
00104 
00105         //- Return a null DimensionedField
00106         inline static const DimensionedField<Type, GeoMesh>& null();
00107 
00108 
00109     // Constructors
00110 
00111         //- Construct from components
00112         DimensionedField
00113         (
00114             const IOobject&,
00115             const Mesh& mesh,
00116             const dimensionSet&,
00117             const Field<Type>&
00118         );
00119 
00120         //- Construct from components
00121         //  Used for temporary fields which are initialised after construction
00122         DimensionedField
00123         (
00124             const IOobject&,
00125             const Mesh& mesh,
00126             const dimensionSet&
00127         );
00128 
00129         //- Construct from components
00130         DimensionedField
00131         (
00132             const IOobject&,
00133             const Mesh& mesh,
00134             const dimensioned<Type>&
00135         );
00136 
00137         //- Construct from Istream
00138         DimensionedField
00139         (
00140             const IOobject&,
00141             const Mesh& mesh,
00142             const word& fieldDictEntry="value"
00143         );
00144 
00145         void readField
00146         (
00147             const dictionary& fieldDict,
00148             const word& fieldDictEntry="value"
00149         );
00150 
00151         //- Construct as copy
00152         DimensionedField
00153         (
00154             const DimensionedField<Type, GeoMesh>&
00155         );
00156 
00157         //- Construct as copy or re-use as specified.
00158         DimensionedField
00159         (
00160             DimensionedField<Type, GeoMesh>&,
00161             bool reUse
00162         );
00163 
00164         //- Construct by transferring the DimensionedField
00165         DimensionedField
00166         (
00167             const Xfer<DimensionedField<Type, GeoMesh> >&
00168         );
00169 
00170         //- Construct as copy of tmp<DimensionedField> deleting argument
00171 #       ifdef ConstructFromTmp
00172         DimensionedField
00173         (
00174             const tmp<DimensionedField<Type, GeoMesh> >&
00175         );
00176 #       endif
00177 
00178         //- Construct as copy resetting IO parameters
00179         DimensionedField
00180         (
00181             const IOobject&,
00182             const DimensionedField<Type, GeoMesh>&
00183         );
00184 
00185         //- Construct as copy resetting name
00186         DimensionedField
00187         (
00188             const word& newName,
00189             const DimensionedField<Type, GeoMesh>&
00190         );
00191 
00192         //- Construct as copy resetting name and re-use as specified.
00193         DimensionedField
00194         (
00195             const word& newName,
00196             DimensionedField<Type, GeoMesh>&,
00197             bool reUse
00198         );
00199 
00200         //- Construct by transferring the DimensionedField with a new name
00201         DimensionedField
00202         (
00203             const word& newName,
00204             const Xfer<DimensionedField<Type, GeoMesh> >&
00205         );
00206 
00207         //- Construct as copy resetting name
00208 #       ifdef ConstructFromTmp
00209         DimensionedField
00210         (
00211             const word& newName,
00212             const tmp<DimensionedField<Type, GeoMesh> >&
00213         );
00214 #       endif
00215 
00216         //- Clone
00217         tmp<DimensionedField<Type, GeoMesh> > clone() const;
00218 
00219 
00220     //- Destructor
00221     virtual ~DimensionedField();
00222 
00223 
00224     // Member Functions
00225 
00226         //- Return mesh
00227         inline const Mesh& mesh() const;
00228 
00229         //- Return dimensions
00230         inline const dimensionSet& dimensions() const;
00231 
00232         //- Return non-const access to dimensions
00233         inline dimensionSet& dimensions();
00234 
00235         inline const Field<Type>& field() const;
00236 
00237         inline Field<Type>& field();
00238 
00239         //- Return a component field of the field
00240         tmp<DimensionedField<cmptType, GeoMesh> > component
00241         (
00242             const direction
00243         ) const;
00244 
00245         //- Replace a component field of the field
00246         void replace
00247         (
00248             const direction,
00249             const DimensionedField<cmptType, GeoMesh>&
00250         );
00251 
00252         //- Replace a component field of the field
00253         void replace
00254         (
00255             const direction,
00256             const tmp<DimensionedField<cmptType, GeoMesh> >&
00257         );
00258 
00259         //- Return the field transpose (only defined for second rank tensors)
00260         tmp<DimensionedField<Type, GeoMesh> > T() const;
00261 
00262         //- Calculate and return arithmetic average
00263         dimensioned<Type> average() const;
00264 
00265         //- Calculate and return weighted average
00266         dimensioned<Type> weightedAverage
00267         (
00268             const DimensionedField<scalar, GeoMesh>&
00269         ) const;
00270 
00271         //- Calculate and return weighted average
00272         dimensioned<Type> weightedAverage
00273         (
00274             const tmp<DimensionedField<scalar, GeoMesh> >&
00275         ) const;
00276 
00277 
00278         // Write
00279 
00280             bool writeData(Ostream&, const word& fieldDictEntry) const;
00281 
00282             bool writeData(Ostream&) const;
00283 
00284 
00285     // Member Operators
00286 
00287         void operator=(const DimensionedField<Type, GeoMesh>&);
00288         void operator=(const tmp<DimensionedField<Type, GeoMesh> >&);
00289         void operator=(const dimensioned<Type>&);
00290 
00291         void operator+=(const DimensionedField<Type, GeoMesh>&);
00292         void operator+=(const tmp<DimensionedField<Type, GeoMesh> >&);
00293 
00294         void operator-=(const DimensionedField<Type, GeoMesh>&);
00295         void operator-=(const tmp<DimensionedField<Type, GeoMesh> >&);
00296 
00297         void operator*=(const DimensionedField<scalar, GeoMesh>&);
00298         void operator*=(const tmp<DimensionedField<scalar, GeoMesh> >&);
00299 
00300         void operator/=(const DimensionedField<scalar, GeoMesh>&);
00301         void operator/=(const tmp<DimensionedField<scalar, GeoMesh> >&);
00302 
00303         void operator+=(const dimensioned<Type>&);
00304         void operator-=(const dimensioned<Type>&);
00305 
00306         void operator*=(const dimensioned<scalar>&);
00307         void operator/=(const dimensioned<scalar>&);
00308 
00309 
00310     // Ostream Operators
00311 
00312         friend Ostream& operator<< <Type, GeoMesh>
00313         (
00314             Ostream&,
00315             const DimensionedField<Type, GeoMesh>&
00316         );
00317 
00318         friend Ostream& operator<< <Type, GeoMesh>
00319         (
00320             Ostream&,
00321             const tmp<DimensionedField<Type, GeoMesh> >&
00322         );
00323 };
00324 
00325 
00326 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00327 
00328 } // End namespace Foam
00329 
00330 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00331 
00332 #include "DimensionedFieldI.H"
00333 #include "DimensionedFieldFunctions.H"
00334 
00335 #ifdef NoRepository
00336 #   include "DimensionedField.C"
00337 #endif
00338 
00339 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00340 
00341 #endif
00342 
00343 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd