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
178 friend Istream& operator>> <Type>
179 (Istream&, dimensioned<Type>&);
181 friend Ostream& operator<< <Type>
182 (Ostream&, const dimensioned<Type>&);
187 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
189 template<class Type, int r>
190 dimensioned<typename powProduct<Type, r>::type>
193 const dimensioned<Type>&,
194 typename powProduct<Type, r>::type
195 = pTraits<typename powProduct<Type, r>::type>::zero
199 dimensioned<typename outerProduct<Type, Type>::type>
200 sqr(const dimensioned<Type>&);
203 dimensioned<scalar> magSqr(const dimensioned<Type>&);
206 dimensioned<scalar> mag(const dimensioned<Type>&);
209 dimensioned<Type> cmptMultiply
211 const dimensioned<Type>&,
212 const dimensioned<Type>&
216 dimensioned<Type> cmptDivide
218 const dimensioned<Type>&,
219 const dimensioned<Type>&
223 dimensioned<Type> max(const dimensioned<Type>&, const dimensioned<Type>&);
226 dimensioned<Type> min(const dimensioned<Type>&, const dimensioned<Type>&);
229 bool operator>(const dimensioned<Type>&, const dimensioned<Type>&);
232 bool operator<(const dimensioned<Type>&, const dimensioned<Type>&);
235 dimensioned<Type> operator+(const dimensioned<Type>&, const dimensioned<Type>&);
238 dimensioned<Type> operator-(const dimensioned<Type>&);
241 dimensioned<Type> operator-(const dimensioned<Type>&, const dimensioned<Type>&);
244 dimensioned<Type> operator*
246 const dimensioned<scalar>&,
247 const dimensioned<Type>&
251 dimensioned<Type> operator/
253 const dimensioned<Type>&,
254 const dimensioned<scalar>&
261 #define PRODUCT_OPERATOR(product, op, opFunc) \
263 template<class Type1, class Type2> \
264 dimensioned<typename product<Type1, Type2>::type> \
265 operator op(const dimensioned<Type1>&, const dimensioned<Type2>&); \
267 template<class Type, class Form, class Cmpt, int nCmpt> \
268 dimensioned<typename product<Type, Form>::type> \
271 const dimensioned<Type>&, \
272 const VectorSpace<Form,Cmpt,nCmpt>& \
275 template<class Type, class Form, class Cmpt, int nCmpt> \
276 dimensioned<typename product<Form, Type>::type> \
279 const VectorSpace<Form,Cmpt,nCmpt>&, \
280 const dimensioned<Type>& \
283 PRODUCT_OPERATOR(outerProduct, *, outer)
284 PRODUCT_OPERATOR(crossProduct, ^, cross)
285 PRODUCT_OPERATOR(innerProduct, &, dot)
286 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
288 #undef PRODUCT_OPERATOR
291 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
293 } // End namespace Foam
295 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
298 # include "dimensionedType.C"
301 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
305 // ************************************************************************* //