ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / OpenFOAM / dimensionedTypes / dimensionedType / dimensionedType.H
blob03fd0084ef2d8164e11afc466582ee6af677ed8c
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
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
19     for more details.
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/>.
24 Class
25     Foam::dimensioned
27 Description
28     Generic dimensioned Type class
30 SourceFiles
31     dimensionedType.C
33 \*---------------------------------------------------------------------------*/
35 #ifndef dimensionedType_H
36 #define dimensionedType_H
38 #include "word.H"
39 #include "direction.H"
40 #include "dimensionSet.H"
41 #include "VectorSpace.H"
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 namespace Foam
48 // Forward declaration of friend functions and operators
50 template<class Type> class dimensioned;
52 template<class Type>
53 Istream& operator>>(Istream&, dimensioned<Type>&);
55 template<class Type>
56 Ostream& operator<<(Ostream&, const dimensioned<Type>&);
58 class dictionary;
60 /*---------------------------------------------------------------------------*\
61                            Class dimensioned Declaration
62 \*---------------------------------------------------------------------------*/
64 template <class Type>
65 class dimensioned
67     // private data
69         //- Variable name
70         word name_;
72         //- The dimension set
73         dimensionSet dimensions_;
75         //- The data value
76         Type value_;
79 public:
81     //- Component type
82     typedef typename pTraits<Type>::cmptType cmptType;
85     // Constructors
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)
95         :
96             name_(::Foam::name(t)),
97             dimensions_(dimless),
98             value_(t)
99         {}
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
112         (
113             const word&,
114             const dictionary&,
115             const Type& defaultValue = pTraits<Type>::zero,
116             const dimensionSet& dims = dimless
117         );
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
122         (
123             const word&,
124             dictionary&,
125             const Type& defaultValue = pTraits<Type>::zero,
126             const dimensionSet& dims = dimless
127         );
130     // Member functions
132         //- Return const reference to name.
133         const word& name() const;
135         //- Return non-const reference to name.
136         word& 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.
148         Type& 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&);
163     // Member operators
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
195 template<class Type>
196 dimensioned<typename outerProduct<Type, Type>::type>
197 sqr(const dimensioned<Type>&);
199 template<class Type>
200 dimensioned<scalar> magSqr(const dimensioned<Type>&);
202 template<class Type>
203 dimensioned<scalar> mag(const dimensioned<Type>&);
205 template<class Type>
206 dimensioned<Type> cmptMultiply
208     const dimensioned<Type>&,
209     const dimensioned<Type>&
212 template<class Type>
213 dimensioned<Type> cmptDivide
215     const dimensioned<Type>&,
216     const dimensioned<Type>&
219 template<class Type>
220 dimensioned<Type> max(const dimensioned<Type>&, const dimensioned<Type>&);
222 template<class Type>
223 dimensioned<Type> min(const dimensioned<Type>&, const dimensioned<Type>&);
225 template<class Type>
226 bool operator>(const dimensioned<Type>&, const dimensioned<Type>&);
228 template<class Type>
229 bool operator<(const dimensioned<Type>&, const dimensioned<Type>&);
231 template<class Type>
232 dimensioned<Type> operator+(const dimensioned<Type>&, const dimensioned<Type>&);
234 template<class Type>
235 dimensioned<Type> operator-(const dimensioned<Type>&);
237 template<class Type>
238 dimensioned<Type> operator-(const dimensioned<Type>&, const dimensioned<Type>&);
240 template<class Type>
241 dimensioned<Type> operator*
243     const dimensioned<scalar>&,
244     const dimensioned<Type>&
247 template<class Type>
248 dimensioned<Type> operator/
250     const dimensioned<Type>&,
251     const dimensioned<scalar>&
255 // Products
256 // ~~~~~~~~
258 #define PRODUCT_OPERATOR(product, op, opFunc)                                 \
259                                                                               \
260 template<class Type1, class Type2>                                            \
261 dimensioned<typename product<Type1, Type2>::type>                             \
262 operator op(const dimensioned<Type1>&, const dimensioned<Type2>&);            \
263                                                                               \
264 template<class Type, class Form, class Cmpt, int nCmpt>                       \
265 dimensioned<typename product<Type, Form>::type>                               \
266 operator op                                                                   \
267 (                                                                             \
268     const dimensioned<Type>&,                                                 \
269     const VectorSpace<Form,Cmpt,nCmpt>&                                       \
270 );                                                                            \
271                                                                               \
272 template<class Type, class Form, class Cmpt, int nCmpt>                       \
273 dimensioned<typename product<Form, Type>::type>                               \
274 operator op                                                                   \
275 (                                                                             \
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
294 #ifdef NoRepository
295 #   include "dimensionedType.C"
296 #endif
298 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
300 #endif
302 // ************************************************************************* //