fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / OpenFOAM / dimensionedTypes / dimensionedType / dimensionedType.H
blobca48aa08c358e7f7e262554387a0828317415d09
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 #ifndef SWIG
178         friend Istream& operator>> <Type>
179         (Istream&, dimensioned<Type>&);
181         friend Ostream& operator<< <Type>
182         (Ostream&, const dimensioned<Type>&);
183 #endif
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
198 template<class Type>
199 dimensioned<typename outerProduct<Type, Type>::type>
200 sqr(const dimensioned<Type>&);
202 template<class Type>
203 dimensioned<scalar> magSqr(const dimensioned<Type>&);
205 template<class Type>
206 dimensioned<scalar> mag(const dimensioned<Type>&);
208 template<class Type>
209 dimensioned<Type> cmptMultiply
211     const dimensioned<Type>&,
212     const dimensioned<Type>&
215 template<class Type>
216 dimensioned<Type> cmptDivide
218     const dimensioned<Type>&,
219     const dimensioned<Type>&
222 template<class Type>
223 dimensioned<Type> max(const dimensioned<Type>&, const dimensioned<Type>&);
225 template<class Type>
226 dimensioned<Type> min(const dimensioned<Type>&, const dimensioned<Type>&);
228 template<class Type>
229 bool operator>(const dimensioned<Type>&, const dimensioned<Type>&);
231 template<class Type>
232 bool operator<(const dimensioned<Type>&, const dimensioned<Type>&);
234 template<class Type>
235 dimensioned<Type> operator+(const dimensioned<Type>&, const dimensioned<Type>&);
237 template<class Type>
238 dimensioned<Type> operator-(const dimensioned<Type>&);
240 template<class Type>
241 dimensioned<Type> operator-(const dimensioned<Type>&, const dimensioned<Type>&);
243 template<class Type>
244 dimensioned<Type> operator*
246     const dimensioned<scalar>&,
247     const dimensioned<Type>&
250 template<class Type>
251 dimensioned<Type> operator/
253     const dimensioned<Type>&,
254     const dimensioned<scalar>&
258 // Products
259 // ~~~~~~~~
261 #define PRODUCT_OPERATOR(product, op, opFunc)                                 \
262                                                                               \
263 template<class Type1, class Type2>                                            \
264 dimensioned<typename product<Type1, Type2>::type>                             \
265 operator op(const dimensioned<Type1>&, const dimensioned<Type2>&);            \
266                                                                               \
267 template<class Type, class Form, class Cmpt, int nCmpt>                       \
268 dimensioned<typename product<Type, Form>::type>                               \
269 operator op                                                                   \
270 (                                                                             \
271     const dimensioned<Type>&,                                                 \
272     const VectorSpace<Form,Cmpt,nCmpt>&                                       \
273 );                                                                            \
274                                                                               \
275 template<class Type, class Form, class Cmpt, int nCmpt>                       \
276 dimensioned<typename product<Form, Type>::type>                               \
277 operator op                                                                   \
278 (                                                                             \
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
297 #ifdef NoRepository
298 #   include "dimensionedType.C"
299 #endif
301 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
303 #endif
305 // ************************************************************************* //