1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
28 Generic dimensioned Type class
33 \*---------------------------------------------------------------------------*/
35 #ifndef dimensionedType_H
36 #define dimensionedType_H
39 #include "direction.H"
40 #include "dimensionSet.H"
41 #include "VectorSpace.H"
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 // Forward declaration of friend functions and operators
50 template<class Type> class dimensioned;
53 Istream& operator>>(Istream&, dimensioned<Type>&);
56 Ostream& operator<<(Ostream&, const dimensioned<Type>&);
60 /*---------------------------------------------------------------------------*\
61 Class dimensioned Declaration
62 \*---------------------------------------------------------------------------*/
73 dimensionSet dimensions_;
82 typedef typename pTraits<Type>::cmptType cmptType;
87 //- Construct given a name, a value and its dimensionSet.
88 dimensioned(const word&, const dimensionSet&, const Type);
90 //- Construct from a dimensioned<Type> changing the name.
91 dimensioned(const word&, const dimensioned<Type>&);
93 //- Construct given a value (creates dimensionless value).
94 dimensioned(const Type& t)
96 name_(::Foam::name(t)),
101 //- Construct from Istream.
102 dimensioned(Istream&);
104 //- Construct from an Istream with a given name
105 dimensioned(const word&, Istream&);
107 //- Construct from an Istream with a given name and dimensions
108 dimensioned(const word&, const dimensionSet&, Istream&);
110 //- Construct from dictionary, with default value.
111 static dimensioned<Type> lookupOrDefault
115 const Type& defaultValue = pTraits<Type>::zero,
116 const dimensionSet& dims = dimless
119 //- Construct from dictionary, with default value.
120 // If the value is not found, it is added into the dictionary.
121 static dimensioned<Type> lookupOrAddToDict
125 const Type& defaultValue = pTraits<Type>::zero,
126 const dimensionSet& dims = dimless
132 //- Return const reference to name.
133 const word& name() const;
135 //- Return non-const reference to name.
138 //- Return const reference to dimensions.
139 const dimensionSet& dimensions() const;
141 //- Return non-const reference to dimensions.
142 dimensionSet& dimensions();
144 //- Return const reference to value.
145 const Type& value() const;
147 //- Return non-const reference to value.
150 //- Return a component as a dimensioned<cmptType>
151 dimensioned<cmptType> component(const direction) const;
153 //- Return a component with a dimensioned<cmptType>
154 void replace(const direction, const dimensioned<cmptType>&);
156 //- Return transpose.
157 dimensioned<Type> T() const;
159 //- Update the value of dimensioned<Type> if found in the dictionary.
160 bool readIfPresent(const dictionary&);
165 //- Return a component as a dimensioned<cmptType>
166 dimensioned<cmptType> operator[](const direction) const;
168 void operator+=(const dimensioned<Type>&);
169 void operator-=(const dimensioned<Type>&);
170 void operator*=(const scalar);
171 void operator/=(const scalar);
174 // IOstream operators
176 friend Istream& operator>> <Type>
177 (Istream&, dimensioned<Type>&);
179 friend Ostream& operator<< <Type>
180 (Ostream&, const dimensioned<Type>&);
184 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
186 template<class Type, int r>
187 dimensioned<typename powProduct<Type, r>::type>
190 const dimensioned<Type>&,
191 typename powProduct<Type, r>::type
192 = pTraits<typename powProduct<Type, r>::type>::zero
196 dimensioned<typename outerProduct<Type, Type>::type>
197 sqr(const dimensioned<Type>&);
200 dimensioned<scalar> magSqr(const dimensioned<Type>&);
203 dimensioned<scalar> mag(const dimensioned<Type>&);
206 dimensioned<Type> cmptMultiply
208 const dimensioned<Type>&,
209 const dimensioned<Type>&
213 dimensioned<Type> cmptDivide
215 const dimensioned<Type>&,
216 const dimensioned<Type>&
220 dimensioned<Type> max(const dimensioned<Type>&, const dimensioned<Type>&);
223 dimensioned<Type> min(const dimensioned<Type>&, const dimensioned<Type>&);
226 bool operator>(const dimensioned<Type>&, const dimensioned<Type>&);
229 bool operator<(const dimensioned<Type>&, const dimensioned<Type>&);
232 dimensioned<Type> operator+(const dimensioned<Type>&, const dimensioned<Type>&);
235 dimensioned<Type> operator-(const dimensioned<Type>&);
238 dimensioned<Type> operator-(const dimensioned<Type>&, const dimensioned<Type>&);
241 dimensioned<Type> operator*
243 const dimensioned<scalar>&,
244 const dimensioned<Type>&
248 dimensioned<Type> operator/
250 const dimensioned<Type>&,
251 const dimensioned<scalar>&
258 #define PRODUCT_OPERATOR(product, op, opFunc) \
260 template<class Type1, class Type2> \
261 dimensioned<typename product<Type1, Type2>::type> \
262 operator op(const dimensioned<Type1>&, const dimensioned<Type2>&); \
264 template<class Type, class Form, class Cmpt, int nCmpt> \
265 dimensioned<typename product<Type, Form>::type> \
268 const dimensioned<Type>&, \
269 const VectorSpace<Form,Cmpt,nCmpt>& \
272 template<class Type, class Form, class Cmpt, int nCmpt> \
273 dimensioned<typename product<Form, Type>::type> \
276 const VectorSpace<Form,Cmpt,nCmpt>&, \
277 const dimensioned<Type>& \
280 PRODUCT_OPERATOR(outerProduct, *, outer)
281 PRODUCT_OPERATOR(crossProduct, ^, cross)
282 PRODUCT_OPERATOR(innerProduct, &, dot)
283 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
285 #undef PRODUCT_OPERATOR
288 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
290 } // End namespace Foam
292 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
295 # include "dimensionedType.C"
298 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
302 // ************************************************************************* //