1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 explicit 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, with default value.
112 static dimensioned<Type> lookupOrDefault
116 const Type& defaultValue = pTraits<Type>::zero,
117 const dimensionSet& dims = dimless
120 //- Construct from dictionary, with default value.
121 // If the value is not found, it is added into the dictionary.
122 static dimensioned<Type> lookupOrAddToDict
126 const Type& defaultValue = pTraits<Type>::zero,
127 const dimensionSet& dims = dimless
133 //- Return const reference to name.
134 const word& name() const;
136 //- Return non-const reference to name.
139 //- Return const reference to dimensions.
140 const dimensionSet& dimensions() const;
142 //- Return non-const reference to dimensions.
143 dimensionSet& dimensions();
145 //- Return const reference to value.
146 const Type& value() const;
148 //- Return non-const reference to value.
151 //- Return a component as a dimensioned<cmptType>
152 dimensioned<cmptType> component(const direction) const;
154 //- Return a component with a dimensioned<cmptType>
155 void replace(const direction, const dimensioned<cmptType>&);
157 //- Return transpose.
158 dimensioned<Type> T() const;
160 //- Update the value of dimensioned<Type> if found in the dictionary.
161 bool readIfPresent(const dictionary&);
166 //- Return a component as a dimensioned<cmptType>
167 dimensioned<cmptType> operator[](const direction) const;
169 void operator+=(const dimensioned<Type>&);
170 void operator-=(const dimensioned<Type>&);
171 void operator*=(const scalar);
172 void operator/=(const scalar);
175 // IOstream operators
177 friend Istream& operator>> <Type>
178 (Istream&, dimensioned<Type>&);
180 friend Ostream& operator<< <Type>
181 (Ostream&, const dimensioned<Type>&);
185 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
187 template<class Type, int r>
188 dimensioned<typename powProduct<Type, r>::type>
191 const dimensioned<Type>&,
192 typename powProduct<Type, r>::type
193 = pTraits<typename powProduct<Type, r>::type>::zero
197 dimensioned<typename outerProduct<Type, Type>::type>
198 sqr(const dimensioned<Type>&);
201 dimensioned<scalar> magSqr(const dimensioned<Type>&);
204 dimensioned<scalar> mag(const dimensioned<Type>&);
207 dimensioned<Type> cmptMultiply
209 const dimensioned<Type>&,
210 const dimensioned<Type>&
214 dimensioned<Type> cmptDivide
216 const dimensioned<Type>&,
217 const dimensioned<Type>&
221 dimensioned<Type> max(const dimensioned<Type>&, const dimensioned<Type>&);
224 dimensioned<Type> min(const dimensioned<Type>&, const dimensioned<Type>&);
227 bool operator>(const dimensioned<Type>&, const dimensioned<Type>&);
230 bool operator<(const dimensioned<Type>&, const dimensioned<Type>&);
233 dimensioned<Type> operator+(const dimensioned<Type>&, const dimensioned<Type>&);
236 dimensioned<Type> operator-(const dimensioned<Type>&);
239 dimensioned<Type> operator-(const dimensioned<Type>&, const dimensioned<Type>&);
242 dimensioned<Type> operator*
244 const dimensioned<scalar>&,
245 const dimensioned<Type>&
249 dimensioned<Type> operator/
251 const dimensioned<Type>&,
252 const dimensioned<scalar>&
259 #define PRODUCT_OPERATOR(product, op, opFunc) \
261 template<class Type1, class Type2> \
262 dimensioned<typename product<Type1, Type2>::type> \
263 operator op(const dimensioned<Type1>&, const dimensioned<Type2>&); \
265 template<class Type, class Form, class Cmpt, int nCmpt> \
266 dimensioned<typename product<Type, Form>::type> \
269 const dimensioned<Type>&, \
270 const VectorSpace<Form,Cmpt,nCmpt>& \
273 template<class Type, class Form, class Cmpt, int nCmpt> \
274 dimensioned<typename product<Form, Type>::type> \
277 const VectorSpace<Form,Cmpt,nCmpt>&, \
278 const dimensioned<Type>& \
281 PRODUCT_OPERATOR(outerProduct, *, outer)
282 PRODUCT_OPERATOR(crossProduct, ^, cross)
283 PRODUCT_OPERATOR(innerProduct, &, dot)
284 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
286 #undef PRODUCT_OPERATOR
289 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
291 } // End namespace Foam
293 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
296 # include "dimensionedType.C"
299 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
303 // ************************************************************************* //