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

dimensionedType.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::dimensioned
00027 
00028 Description
00029     Generic dimensioned Type class
00030 
00031 SourceFiles
00032     dimensionedType.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef dimensionedType_H
00037 #define dimensionedType_H
00038 
00039 #include "word.H"
00040 #include "direction.H"
00041 #include "dimensionSet.H"
00042 #include "VectorSpace.H"
00043 
00044 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00045 
00046 namespace Foam
00047 {
00048 
00049 // Forward declaration of friend functions and operators
00050 
00051 template<class Type> class dimensioned;
00052 
00053 template<class Type>
00054 Istream& operator>>(Istream&, dimensioned<Type>&);
00055 
00056 template<class Type>
00057 Ostream& operator<<(Ostream&, const dimensioned<Type>&);
00058 
00059 class dictionary;
00060 
00061 /*---------------------------------------------------------------------------*\
00062                            Class dimensioned Declaration
00063 \*---------------------------------------------------------------------------*/
00064 
00065 template <class Type>
00066 class dimensioned
00067 {
00068     // private data
00069 
00070         //- Variable name
00071         word name_;
00072 
00073         //- The dimension set
00074         dimensionSet dimensions_;
00075 
00076         //- The data value
00077         Type value_;
00078 
00079 
00080 public:
00081 
00082     //- Component type
00083     typedef typename pTraits<Type>::cmptType cmptType;
00084 
00085 
00086     // Constructors
00087 
00088         //- Construct given a name, a value and its dimensionSet.
00089         dimensioned(const word&, const dimensionSet&, const Type);
00090 
00091         //- Construct from a dimensioned<Type> changing the name.
00092         dimensioned(const word&, const dimensioned<Type>&);
00093 
00094         //- Construct given a value (creates dimensionless value).
00095         dimensioned(const Type& t)
00096         :
00097             name_(::Foam::name(t)),
00098             dimensions_(dimless),
00099             value_(t)
00100         {}
00101 
00102         //- Construct from Istream.
00103         dimensioned(Istream&);
00104 
00105         //- Construct from an Istream with a given name
00106         dimensioned(const word&, Istream&);
00107 
00108         //- Construct from an Istream with a given name and dimensions
00109         dimensioned(const word&, const dimensionSet&, Istream&);
00110 
00111         //- Construct from dictionary, with default value.
00112         static dimensioned<Type> lookupOrDefault
00113         (
00114             const word&,
00115             const dictionary&,
00116             const Type& defaultValue = pTraits<Type>::zero,
00117             const dimensionSet& dims = dimless
00118         );
00119 
00120         //- Construct from dictionary, with default value.
00121         //  If the value is not found, it is added into the dictionary.
00122         static dimensioned<Type> lookupOrAddToDict
00123         (
00124             const word&,
00125             dictionary&,
00126             const Type& defaultValue = pTraits<Type>::zero,
00127             const dimensionSet& dims = dimless
00128         );
00129 
00130 
00131     // Member functions
00132 
00133         //- Return const reference to name.
00134         const word& name() const;
00135 
00136         //- Return non-const reference to name.
00137         word& name();
00138 
00139         //- Return const reference to dimensions.
00140         const dimensionSet& dimensions() const;
00141 
00142         //- Return non-const reference to dimensions.
00143         dimensionSet& dimensions();
00144 
00145         //- Return const reference to value.
00146         const Type& value() const;
00147 
00148         //- Return non-const reference to value.
00149         Type& value();
00150 
00151         //- Return a component as a dimensioned<cmptType>
00152         dimensioned<cmptType> component(const direction) const;
00153 
00154         //- Return a component with a dimensioned<cmptType>
00155         void replace(const direction, const dimensioned<cmptType>&);
00156 
00157         //- Return transpose.
00158         dimensioned<Type> T() const;
00159 
00160         //- Update the value of dimensioned<Type> if found in the dictionary.
00161         bool readIfPresent(const dictionary&);
00162 
00163 
00164     // Member operators
00165 
00166         //- Return a component as a dimensioned<cmptType>
00167         dimensioned<cmptType> operator[](const direction) const;
00168 
00169         void operator+=(const dimensioned<Type>&);
00170         void operator-=(const dimensioned<Type>&);
00171         void operator*=(const scalar);
00172         void operator/=(const scalar);
00173 
00174 
00175     // IOstream operators
00176 
00177         friend Istream& operator>> <Type>
00178         (Istream&, dimensioned<Type>&);
00179 
00180         friend Ostream& operator<< <Type>
00181         (Ostream&, const dimensioned<Type>&);
00182 };
00183 
00184 
00185 // * * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * //
00186 
00187 template<class Type, int r>
00188 dimensioned<typename powProduct<Type, r>::type>
00189 pow
00190 (
00191     const dimensioned<Type>&,
00192     typename powProduct<Type, r>::type
00193   = pTraits<typename powProduct<Type, r>::type>::zero
00194 );
00195 
00196 template<class Type>
00197 dimensioned<typename outerProduct<Type, Type>::type>
00198 sqr(const dimensioned<Type>&);
00199 
00200 template<class Type>
00201 dimensioned<scalar> magSqr(const dimensioned<Type>&);
00202 
00203 template<class Type>
00204 dimensioned<scalar> mag(const dimensioned<Type>&);
00205 
00206 template<class Type>
00207 dimensioned<Type> cmptMultiply
00208 (
00209     const dimensioned<Type>&,
00210     const dimensioned<Type>&
00211 );
00212 
00213 template<class Type>
00214 dimensioned<Type> cmptDivide
00215 (
00216     const dimensioned<Type>&,
00217     const dimensioned<Type>&
00218 );
00219 
00220 template<class Type>
00221 dimensioned<Type> max(const dimensioned<Type>&, const dimensioned<Type>&);
00222 
00223 template<class Type>
00224 dimensioned<Type> min(const dimensioned<Type>&, const dimensioned<Type>&);
00225 
00226 template<class Type>
00227 bool operator>(const dimensioned<Type>&, const dimensioned<Type>&);
00228 
00229 template<class Type>
00230 bool operator<(const dimensioned<Type>&, const dimensioned<Type>&);
00231 
00232 template<class Type>
00233 dimensioned<Type> operator+(const dimensioned<Type>&, const dimensioned<Type>&);
00234 
00235 template<class Type>
00236 dimensioned<Type> operator-(const dimensioned<Type>&);
00237 
00238 template<class Type>
00239 dimensioned<Type> operator-(const dimensioned<Type>&, const dimensioned<Type>&);
00240 
00241 template<class Type>
00242 dimensioned<Type> operator*
00243 (
00244     const dimensioned<scalar>&,
00245     const dimensioned<Type>&
00246 );
00247 
00248 template<class Type>
00249 dimensioned<Type> operator/
00250 (
00251     const dimensioned<Type>&,
00252     const dimensioned<scalar>&
00253 );
00254 
00255 
00256 // Products
00257 // ~~~~~~~~
00258 
00259 #define PRODUCT_OPERATOR(product, op, opFunc)                                 \
00260                                                                               \
00261 template<class Type1, class Type2>                                            \
00262 dimensioned<typename product<Type1, Type2>::type>                             \
00263 operator op(const dimensioned<Type1>&, const dimensioned<Type2>&);            \
00264                                                                               \
00265 template<class Type, class Form, class Cmpt, int nCmpt>                       \
00266 dimensioned<typename product<Type, Form>::type>                               \
00267 operator op                                                                   \
00268 (                                                                             \
00269     const dimensioned<Type>&,                                                 \
00270     const VectorSpace<Form,Cmpt,nCmpt>&                                       \
00271 );                                                                            \
00272                                                                               \
00273 template<class Type, class Form, class Cmpt, int nCmpt>                       \
00274 dimensioned<typename product<Form, Type>::type>                               \
00275 operator op                                                                   \
00276 (                                                                             \
00277     const VectorSpace<Form,Cmpt,nCmpt>&,                                      \
00278     const dimensioned<Type>&                                                  \
00279 );
00280 
00281 PRODUCT_OPERATOR(outerProduct, *, outer)
00282 PRODUCT_OPERATOR(crossProduct, ^, cross)
00283 PRODUCT_OPERATOR(innerProduct, &, dot)
00284 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
00285 
00286 #undef PRODUCT_OPERATOR
00287 
00288 
00289 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00290 
00291 } // End namespace Foam
00292 
00293 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00294 
00295 #ifdef NoRepository
00296 #   include "dimensionedType.C"
00297 #endif
00298 
00299 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00300 
00301 #endif
00302 
00303 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd