intersection with triangle plane for miss
[OpenFOAM-1.5.x.git] / src / OpenFOAM / dimensionedTypes / dimensionedType / dimensionedType.H
blob7da310c026b486fa4c533a35f58e1409d615db0f
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
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         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, supplying default value so that if the
112         //  value is not found, it is added into the dictionary.
113         static dimensioned<Type> lookupOrAddToDict
114         (
115             const word&,
116             dictionary&,
117             const Type& defaultValue = pTraits<Type>::zero,
118             const dimensionSet& dims = dimless
119         );
122     // Member functions
124         //- Return const reference to name.
125         const word& name() const;
127         //- Return non-const reference to name.
128         word& name();
130         //- Return const reference to dimensions.
131         const dimensionSet& dimensions() const;
133         //- Return non-const reference to dimensions.
134         dimensionSet& dimensions();
136         //- Return const reference to value.
137         const Type& value() const;
139         //- Return non-const reference to value.
140         Type& value();
142         //- Return a component as a dimensioned<cmptType>
143         dimensioned<cmptType> component(const direction) const;
145         //- Return a component with a dimensioned<cmptType>
146         void replace(const direction, const dimensioned<cmptType>&);
148         //- Return transpose.
149         dimensioned<Type> T() const;
151         //- Update the value of the dimensioned<Type> if it is found in the
152         //  dictionary
153         bool readIfPresent(const dictionary&);
156     // Member operators
158         //- Return a component as a dimensioned<cmptType>
159         dimensioned<cmptType> operator[](const direction) const;
161         void operator+=(const dimensioned<Type>&);
162         void operator-=(const dimensioned<Type>&);
163         void operator*=(const scalar);
164         void operator/=(const scalar);
167     // IOstream operators
169         friend Istream& operator>>
170         #ifndef __CINT__
171         <Type>
172         #endif
173         (Istream&, dimensioned<Type>&);
175         friend Ostream& operator<<
176         #ifndef __CINT__
177         <Type>
178         #endif
179         (Ostream&, const dimensioned<Type>&);
183 // * * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * //
185 template<class Type, int r>
186 dimensioned<typename powProduct<Type, r>::type>
189     const dimensioned<Type>&,
190     typename powProduct<Type, r>::type
191   = pTraits<typename powProduct<Type, r>::type>::zero
194 template<class Type>
195 dimensioned<typename outerProduct<Type, Type>::type>
196 sqr(const dimensioned<Type>&);
198 template<class Type>
199 dimensioned<scalar> magSqr(const dimensioned<Type>&);
201 template<class Type>
202 dimensioned<scalar> mag(const dimensioned<Type>&);
204 template<class Type>
205 dimensioned<Type> cmptMultiply
207     const dimensioned<Type>&,
208     const dimensioned<Type>&
211 template<class Type>
212 dimensioned<Type> cmptDivide
214     const dimensioned<Type>&,
215     const dimensioned<Type>&
218 template<class Type>
219 dimensioned<Type> max(const dimensioned<Type>&, const dimensioned<Type>&);
221 template<class Type>
222 dimensioned<Type> min(const dimensioned<Type>&, const dimensioned<Type>&);
224 template<class Type>
225 bool operator>(const dimensioned<Type>&, const dimensioned<Type>&);
227 template<class Type>
228 bool operator<(const dimensioned<Type>&, const dimensioned<Type>&);
230 template<class Type>
231 dimensioned<Type> operator+(const dimensioned<Type>&, const dimensioned<Type>&);
233 template<class Type>
234 dimensioned<Type> operator-(const dimensioned<Type>&);
236 template<class Type>
237 dimensioned<Type> operator-(const dimensioned<Type>&, const dimensioned<Type>&);
239 template<class Type>
240 dimensioned<Type> operator*
242     const dimensioned<scalar>&,
243     const dimensioned<Type>&
246 template<class Type>
247 dimensioned<Type> operator/
249     const dimensioned<Type>&,
250     const dimensioned<scalar>&
254 // Products
255 // ~~~~~~~~
257 #define PRODUCT_OPERATOR(product, op, opFunc)                                 \
258                                                                               \
259 template<class Type1, class Type2>                                            \
260 dimensioned<typename product<Type1, Type2>::type>                             \
261 operator op(const dimensioned<Type1>&, const dimensioned<Type2>&);            \
262                                                                               \
263 template<class Type, class Form, class Cmpt, int nCmpt>                       \
264 dimensioned<typename product<Type, Form>::type>                               \
265 operator op                                                                   \
266 (                                                                             \
267     const dimensioned<Type>&,                                                 \
268     const VectorSpace<Form,Cmpt,nCmpt>&                                       \
269 );                                                                            \
270                                                                               \
271 template<class Type, class Form, class Cmpt, int nCmpt>                       \
272 dimensioned<typename product<Form, Type>::type>                               \
273 operator op                                                                   \
274 (                                                                             \
275     const VectorSpace<Form,Cmpt,nCmpt>&,                                      \
276     const dimensioned<Type>&                                                  \
279 PRODUCT_OPERATOR(outerProduct, *, outer)
280 PRODUCT_OPERATOR(crossProduct, ^, cross)
281 PRODUCT_OPERATOR(innerProduct, &, dot)
282 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
284 #undef PRODUCT_OPERATOR
287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
289 } // End namespace Foam
291 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
293 #ifdef NoRepository
294 #   include "dimensionedType.C"
295 #endif
297 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
299 #endif
301 // ************************************************************************* //