OpenFOAM logo
Open Source CFD Toolkit

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-2005 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     dimensionedType
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 template friend functions  * * * * * * //
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 
00060 /*---------------------------------------------------------------------------*\
00061                            Class dimensioned Declaration
00062 \*---------------------------------------------------------------------------*/
00063 
00064 template <class Type>
00065 class dimensioned
00066 {
00067     // private data
00068 
00069         //- Variable name
00070         word name_;
00071 
00072         //- The dimension set
00073         dimensionSet dimensions_;
00074 
00075         //- The data value
00076         Type value_;
00077 
00078 
00079 public:
00080 
00081     //- Component type
00082     typedef typename pTraits<Type>::cmptType cmptType;
00083 
00084 
00085     // Constructors
00086 
00087         //- Construct given a name, a value and its dimensionSet.
00088         dimensioned(const word&, const dimensionSet&, const Type);
00089 
00090         //- Construct from a dimensioned<Type> changing the name.
00091         dimensioned(const word&, const dimensioned<Type>&);
00092 
00093         //- Construct given a value (creates dimensionless value).
00094         dimensioned(const Type& t)
00095         :
00096             name_(::Foam::name(t)),
00097             dimensions_(dimless),
00098             value_(t)
00099         {}
00100 
00101         //- Construct from Istream.
00102         dimensioned(Istream&);
00103 
00104 
00105     // Member functions
00106 
00107         //- Return const reference to name.
00108         const word& name() const;
00109 
00110         //- Return non-const reference to name.
00111         word& name();
00112 
00113         //- Return const reference to dimensions.
00114         const dimensionSet& dimensions() const;
00115 
00116         //- Return non-const reference to dimensions.
00117         dimensionSet& dimensions();
00118 
00119         //- Return const reference to value.
00120         const Type& value() const;
00121 
00122         //- Return non-const reference to value.
00123         Type& value();
00124 
00125         //- Return a component as a dimensioned<cmptType>
00126         dimensioned<cmptType> component(const direction) const;
00127 
00128         //- Return a component with a dimensioned<cmptType>
00129         void replace(const direction, const dimensioned<cmptType>&);
00130 
00131         //- Return transpose.
00132         dimensioned<Type> T() const;
00133 
00134 
00135     // Member operators
00136 
00137         //- Return a component as a dimensioned<cmptType>
00138         dimensioned<cmptType> operator[](const direction) const;
00139 
00140         void operator+=(const dimensioned<Type>&);
00141         void operator-=(const dimensioned<Type>&);
00142         void operator*=(const scalar);
00143         void operator/=(const scalar);
00144 
00145 
00146     // IOstream operators
00147 
00148         friend Istream& operator>> <Type>(Istream&, dimensioned<Type>&);
00149         friend Ostream& operator<< <Type>(Ostream&, const dimensioned<Type>&);
00150 };
00151 
00152 
00153 // * * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * //
00154 
00155 template<class Type, int r>
00156 dimensioned<typename powProduct<Type, r>::type>
00157 pow
00158 (
00159     const dimensioned<Type>&,
00160     typename powProduct<Type, r>::type
00161   = pTraits<typename powProduct<Type, r>::type>::zero
00162 );
00163 
00164 template<class Type>
00165 dimensioned<typename outerProduct<Type, Type>::type>
00166 sqr(const dimensioned<Type>&);
00167 
00168 template<class Type>
00169 dimensioned<scalar> magSqr(const dimensioned<Type>&);
00170 
00171 template<class Type>
00172 dimensioned<scalar> mag(const dimensioned<Type>&);
00173 
00174 template<class Type>
00175 dimensioned<Type> scale(const dimensioned<Type>&, const dimensioned<Type>&);
00176 
00177 template<class Type>
00178 dimensioned<Type> max(const dimensioned<Type>&, const dimensioned<Type>&);
00179 
00180 template<class Type>
00181 dimensioned<Type> min(const dimensioned<Type>&, const dimensioned<Type>&);
00182 
00183 template<class Type>
00184 bool operator>(const dimensioned<Type>&, const dimensioned<Type>&);
00185 
00186 template<class Type>
00187 bool operator<(const dimensioned<Type>&, const dimensioned<Type>&);
00188 
00189 template<class Type>
00190 dimensioned<Type> operator+(const dimensioned<Type>&, const dimensioned<Type>&);
00191 
00192 template<class Type>
00193 dimensioned<Type> operator-(const dimensioned<Type>&);
00194 
00195 template<class Type>
00196 dimensioned<Type> operator-(const dimensioned<Type>&, const dimensioned<Type>&);
00197 
00198 template<class Type>
00199 dimensioned<Type> operator*
00200 (
00201     const dimensioned<scalar>&,
00202     const dimensioned<Type>&
00203 );
00204 
00205 template<class Type>
00206 dimensioned<Type> operator/
00207 (
00208     const dimensioned<Type>&,
00209     const dimensioned<scalar>&
00210 );
00211 
00212 
00213 // Products
00214 // ~~~~~~~~
00215 
00216 #define PRODUCT_OPERATOR(product, op, opFunc)                                 \
00217                                                                               \
00218 template<class Type1, class Type2>                                            \
00219 dimensioned<typename product<Type1, Type2>::type>                             \
00220 operator op(const dimensioned<Type1>&, const dimensioned<Type2>&);            \
00221                                                                               \
00222 template<class Type, class Form, class Cmpt, int nCmpt>                       \
00223 dimensioned<typename product<Type, Form>::type>                               \
00224 operator op                                                                   \
00225 (                                                                             \
00226     const dimensioned<Type>&,                                                 \
00227     const VectorSpace<Form,Cmpt,nCmpt>&                                       \
00228 );                                                                            \
00229                                                                               \
00230 template<class Type, class Form, class Cmpt, int nCmpt>                       \
00231 dimensioned<typename product<Form, Type>::type>                               \
00232 operator op                                                                   \
00233 (                                                                             \
00234     const VectorSpace<Form,Cmpt,nCmpt>&,                                      \
00235     const dimensioned<Type>&                                                  \
00236 );
00237 
00238 PRODUCT_OPERATOR(outerProduct, *, outer)
00239 PRODUCT_OPERATOR(crossProduct, ^, cross)
00240 PRODUCT_OPERATOR(innerProduct, &, dot)
00241 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
00242 
00243 #undef PRODUCT_OPERATOR
00244 
00245 
00246 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00247 
00248 } // End namespace Foam
00249 
00250 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00251 
00252 #ifdef NoRepository
00253 #   include "dimensionedType.C"
00254 #endif
00255 
00256 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00257 
00258 #endif
00259 
00260 // ************************************************************************* //
For further information go to www.openfoam.org