1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Generic dimensioned Type class
34 \*---------------------------------------------------------------------------*/
36 #ifndef dimensionedType_H
37 #define dimensionedType_H
40 #include "direction.H"
41 #include "dimensionSet.H"
42 #include "VectorSpace.H"
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 // Forward declaration of friend functions and operators
51 template<class Type> class dimensioned;
54 Istream& operator>>(Istream&, dimensioned<Type>&);
57 Ostream& operator<<(Ostream&, const dimensioned<Type>&);
61 /*---------------------------------------------------------------------------*\
62 Class dimensioned Declaration
63 \*---------------------------------------------------------------------------*/
74 dimensionSet dimensions_;
83 typedef typename pTraits<Type>::cmptType cmptType;
88 //- Construct given a name, a value and its dimensionSet.
89 dimensioned(const word&, const dimensionSet&, const Type);
91 //- Construct from a dimensioned<Type> changing the name.
92 dimensioned(const word&, const dimensioned<Type>&);
94 //- Construct given a value (creates dimensionless value).
95 dimensioned(const Type& t)
97 name_(::Foam::name(t)),
102 //- Construct from Istream.
103 dimensioned(Istream&);
105 //- Construct from an Istream with a given name
106 dimensioned(const word&, Istream&);
108 //- Construct from an Istream with a given name and dimensions
109 dimensioned(const word&, const dimensionSet&, Istream&);
111 //- Construct from dictionary, supplying default value so that if the
112 // value is not found, it is added into the dictionary.
113 static dimensioned<Type> lookupOrAddToDict
117 const Type& defaultValue = pTraits<Type>::zero,
118 const dimensionSet& dims = dimless
124 //- Return const reference to name.
125 const word& name() const;
127 //- Return non-const reference to name.
130 //- Return const reference to dimensions.
131 const dimensionSet& dimensions() const;
133 //- Return non-const reference to dimensions.
134 dimensionSet& dimensions();
136 //- Return const reference to value.
137 const Type& value() const;
139 //- Return non-const reference to value.
142 //- Return a component as a dimensioned<cmptType>
143 dimensioned<cmptType> component(const direction) const;
145 //- Return a component with a dimensioned<cmptType>
146 void replace(const direction, const dimensioned<cmptType>&);
148 //- Return transpose.
149 dimensioned<Type> T() const;
151 //- Update the value of the dimensioned<Type> if it is found in the
153 bool readIfPresent(const dictionary&);
158 //- Return a component as a dimensioned<cmptType>
159 dimensioned<cmptType> operator[](const direction) const;
161 void operator+=(const dimensioned<Type>&);
162 void operator-=(const dimensioned<Type>&);
163 void operator*=(const scalar);
164 void operator/=(const scalar);
167 // IOstream operators
169 friend Istream& operator>>
173 (Istream&, dimensioned<Type>&);
175 friend Ostream& operator<<
179 (Ostream&, const dimensioned<Type>&);
183 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
185 template<class Type, int r>
186 dimensioned<typename powProduct<Type, r>::type>
189 const dimensioned<Type>&,
190 typename powProduct<Type, r>::type
191 = pTraits<typename powProduct<Type, r>::type>::zero
195 dimensioned<typename outerProduct<Type, Type>::type>
196 sqr(const dimensioned<Type>&);
199 dimensioned<scalar> magSqr(const dimensioned<Type>&);
202 dimensioned<scalar> mag(const dimensioned<Type>&);
205 dimensioned<Type> cmptMultiply
207 const dimensioned<Type>&,
208 const dimensioned<Type>&
212 dimensioned<Type> cmptDivide
214 const dimensioned<Type>&,
215 const dimensioned<Type>&
219 dimensioned<Type> max(const dimensioned<Type>&, const dimensioned<Type>&);
222 dimensioned<Type> min(const dimensioned<Type>&, const dimensioned<Type>&);
225 bool operator>(const dimensioned<Type>&, const dimensioned<Type>&);
228 bool operator<(const dimensioned<Type>&, const dimensioned<Type>&);
231 dimensioned<Type> operator+(const dimensioned<Type>&, const dimensioned<Type>&);
234 dimensioned<Type> operator-(const dimensioned<Type>&);
237 dimensioned<Type> operator-(const dimensioned<Type>&, const dimensioned<Type>&);
240 dimensioned<Type> operator*
242 const dimensioned<scalar>&,
243 const dimensioned<Type>&
247 dimensioned<Type> operator/
249 const dimensioned<Type>&,
250 const dimensioned<scalar>&
257 #define PRODUCT_OPERATOR(product, op, opFunc) \
259 template<class Type1, class Type2> \
260 dimensioned<typename product<Type1, Type2>::type> \
261 operator op(const dimensioned<Type1>&, const dimensioned<Type2>&); \
263 template<class Type, class Form, class Cmpt, int nCmpt> \
264 dimensioned<typename product<Type, Form>::type> \
267 const dimensioned<Type>&, \
268 const VectorSpace<Form,Cmpt,nCmpt>& \
271 template<class Type, class Form, class Cmpt, int nCmpt> \
272 dimensioned<typename product<Form, Type>::type> \
275 const VectorSpace<Form,Cmpt,nCmpt>&, \
276 const dimensioned<Type>& \
279 PRODUCT_OPERATOR(outerProduct, *, outer)
280 PRODUCT_OPERATOR(crossProduct, ^, cross)
281 PRODUCT_OPERATOR(innerProduct, &, dot)
282 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
284 #undef PRODUCT_OPERATOR
287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
289 } // End namespace Foam
291 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
294 # include "dimensionedType.C"
297 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
301 // ************************************************************************* //