Fix tutorials: typo in tutorials/viscoelastic/viscoelasticFluidFoam/S-MDCPP/constant...
[OpenFOAM-1.6-ext.git] / src / OpenFOAM / dimensionedTypes / dimensionedType / dimensionedType.H
blob3cb95b603d922d7b4f15e0e61766535ac6dd8108
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Class
26     Foam::dimensioned
28 Description
29     Generic dimensioned Type class
31 SourceFiles
32     dimensionedType.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef dimensionedType_H
37 #define dimensionedType_H
39 #include "word.H"
40 #include "direction.H"
41 #include "dimensionSet.H"
42 #include "VectorSpace.H"
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 namespace Foam
49 // Forward declaration of friend functions and operators
51 template<class Type> class dimensioned;
53 template<class Type>
54 Istream& operator>>(Istream&, dimensioned<Type>&);
56 template<class Type>
57 Ostream& operator<<(Ostream&, const dimensioned<Type>&);
59 class dictionary;
61 /*---------------------------------------------------------------------------*\
62                            Class dimensioned Declaration
63 \*---------------------------------------------------------------------------*/
65 template <class Type>
66 class dimensioned
68     // private data
70         //- Variable name
71         word name_;
73         //- The dimension set
74         dimensionSet dimensions_;
76         //- The data value
77         Type value_;
80 public:
82     //- Component type
83     typedef typename pTraits<Type>::cmptType cmptType;
86     // Constructors
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)
96         :
97             name_(::Foam::name(t)),
98             dimensions_(dimless),
99             value_(t)
100         {}
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
113         (
114             const word&,
115             const dictionary&,
116             const Type& defaultValue = pTraits<Type>::zero,
117             const dimensionSet& dims = dimless
118         );
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
123         (
124             const word&,
125             dictionary&,
126             const Type& defaultValue = pTraits<Type>::zero,
127             const dimensionSet& dims = dimless
128         );
131     // Member functions
133         //- Return const reference to name.
134         const word& name() const;
136         //- Return non-const reference to name.
137         word& 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.
149         Type& 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&);
164     // Member operators
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
196 template<class Type>
197 dimensioned<typename outerProduct<Type, Type>::type>
198 sqr(const dimensioned<Type>&);
200 template<class Type>
201 dimensioned<scalar> magSqr(const dimensioned<Type>&);
203 template<class Type>
204 dimensioned<scalar> mag(const dimensioned<Type>&);
206 template<class Type>
207 dimensioned<Type> cmptMultiply
209     const dimensioned<Type>&,
210     const dimensioned<Type>&
213 template<class Type>
214 dimensioned<Type> cmptDivide
216     const dimensioned<Type>&,
217     const dimensioned<Type>&
220 template<class Type>
221 dimensioned<Type> max(const dimensioned<Type>&, const dimensioned<Type>&);
223 template<class Type>
224 dimensioned<Type> min(const dimensioned<Type>&, const dimensioned<Type>&);
226 template<class Type>
227 bool operator>(const dimensioned<Type>&, const dimensioned<Type>&);
229 template<class Type>
230 bool operator<(const dimensioned<Type>&, const dimensioned<Type>&);
232 template<class Type>
233 dimensioned<Type> operator+(const dimensioned<Type>&, const dimensioned<Type>&);
235 template<class Type>
236 dimensioned<Type> operator-(const dimensioned<Type>&);
238 template<class Type>
239 dimensioned<Type> operator-(const dimensioned<Type>&, const dimensioned<Type>&);
241 template<class Type>
242 dimensioned<Type> operator*
244     const dimensioned<scalar>&,
245     const dimensioned<Type>&
248 template<class Type>
249 dimensioned<Type> operator/
251     const dimensioned<Type>&,
252     const dimensioned<scalar>&
256 // Products
257 // ~~~~~~~~
259 #define PRODUCT_OPERATOR(product, op, opFunc)                                 \
260                                                                               \
261 template<class Type1, class Type2>                                            \
262 dimensioned<typename product<Type1, Type2>::type>                             \
263 operator op(const dimensioned<Type1>&, const dimensioned<Type2>&);            \
264                                                                               \
265 template<class Type, class Form, class Cmpt, int nCmpt>                       \
266 dimensioned<typename product<Type, Form>::type>                               \
267 operator op                                                                   \
268 (                                                                             \
269     const dimensioned<Type>&,                                                 \
270     const VectorSpace<Form,Cmpt,nCmpt>&                                       \
271 );                                                                            \
272                                                                               \
273 template<class Type, class Form, class Cmpt, int nCmpt>                       \
274 dimensioned<typename product<Form, Type>::type>                               \
275 operator op                                                                   \
276 (                                                                             \
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
295 #ifdef NoRepository
296 #   include "dimensionedType.C"
297 #endif
299 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
301 #endif
303 // ************************************************************************* //