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

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