initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / OpenFOAM / primitives / Tensor2D / Tensor2DI.H
blobf98d472f927f5409e9740d167b30690ffaa38ad1
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 \*---------------------------------------------------------------------------*/
27 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 namespace Foam
32 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
34 //- Construct null
35 template <class Cmpt>
36 inline Tensor2D<Cmpt>::Tensor2D()
40 //- Construct given VectorSpace
41 template <class Cmpt>
42 inline Tensor2D<Cmpt>::Tensor2D(const VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>& vs)
44     VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>(vs)
48 //- Construct given SphericalTensor2D
49 template <class Cmpt>
50 inline Tensor2D<Cmpt>::Tensor2D(const SphericalTensor2D<Cmpt>& st)
52     this->v_[XX] = st.ii(); this->v_[XY] = 0;
53     this->v_[YX] = 0; this->v_[YY] = st.ii();
57 //- Construct from components
58 template <class Cmpt>
59 inline Tensor2D<Cmpt>::Tensor2D
61     const Cmpt txx, const Cmpt txy,
62     const Cmpt tyx, const Cmpt tyy
65     this->v_[XX] = txx; this->v_[XY] = txy;
66     this->v_[YX] = tyx; this->v_[YY] = tyy;
70 //- Construct from Istream
71 template <class Cmpt>
72 inline Tensor2D<Cmpt>::Tensor2D(Istream& is)
74     VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>(is)
78 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
80 template <class Cmpt>
81 inline const Vector2D<Cmpt>&  Tensor2D<Cmpt>::x() const
83     return reinterpret_cast<const Vector2D<Cmpt>&>(this->v_[XX]);
86 template <class Cmpt>
87 inline const Vector2D<Cmpt>&  Tensor2D<Cmpt>::y() const
89     return reinterpret_cast<const Vector2D<Cmpt>&>(this->v_[YX]);
93 template <class Cmpt>
94 inline Vector2D<Cmpt>&  Tensor2D<Cmpt>::x()
96     return reinterpret_cast<Vector2D<Cmpt>&>(this->v_[XX]);
99 template <class Cmpt>
100 inline Vector2D<Cmpt>&  Tensor2D<Cmpt>::y()
102     return reinterpret_cast<Vector2D<Cmpt>&>(this->v_[YX]);
106 template <class Cmpt>
107 inline const Cmpt&  Tensor2D<Cmpt>::xx() const
109     return this->v_[XX];
112 template <class Cmpt>
113 inline const Cmpt&  Tensor2D<Cmpt>::xy() const
115     return this->v_[XY];
118 template <class Cmpt>
119 inline const Cmpt&  Tensor2D<Cmpt>::yx() const
121     return this->v_[YX];
124 template <class Cmpt>
125 inline const Cmpt&  Tensor2D<Cmpt>::yy() const
127     return this->v_[YY];
131 template <class Cmpt>
132 inline Cmpt& Tensor2D<Cmpt>::xx()
134     return this->v_[XX];
137 template <class Cmpt>
138 inline Cmpt& Tensor2D<Cmpt>::xy()
140     return this->v_[XY];
143 template <class Cmpt>
144 inline Cmpt& Tensor2D<Cmpt>::yx()
146     return this->v_[YX];
149 template <class Cmpt>
150 inline Cmpt& Tensor2D<Cmpt>::yy()
152     return this->v_[YY];
156 //- Return tensor transpose
157 template <class Cmpt>
158 inline Tensor2D<Cmpt> Tensor2D<Cmpt>::T() const
160     return Tensor2D<Cmpt>
161     (
162         xx(), yx(),
163         xy(), yy()
164     );
168 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
170 template <class Cmpt>
171 inline void Tensor2D<Cmpt>::operator=(const SphericalTensor2D<Cmpt>& st)
173     this->v_[XX] = st.ii(); this->v_[XY] = 0;
174     this->v_[YX] = 0; this->v_[YY] = st.ii();
179 // * * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * //
181 //- Inner-product between two tensors
182 template <class Cmpt>
183 inline typename innerProduct<Tensor2D<Cmpt>, Tensor2D<Cmpt> >::type
184 operator&(const Tensor2D<Cmpt>& t1, const Tensor2D<Cmpt>& t2)
186     return Tensor2D<Cmpt>
187     (
188         t1.xx()*t2.xx() + t1.xy()*t2.yx(),
189         t1.xx()*t2.xy() + t1.xy()*t2.yy(),
191         t1.yx()*t2.xx() + t1.yy()*t2.yx(),
192         t1.yx()*t2.xy() + t1.yy()*t2.yy()
193     );
196 //- Inner-product between a tensor and a vector
197 template <class Cmpt>
198 inline typename innerProduct<Tensor2D<Cmpt>, Vector2D<Cmpt> >::type
199 operator&(const Tensor2D<Cmpt>& t, const Vector2D<Cmpt>& v)
201     return Vector2D<Cmpt>
202     (
203         t.xx()*v.x() + t.xy()*v.y(),
204         t.yx()*v.x() + t.yy()*v.y()
205     );
208 //- Inner-product between a vector and a tensor
209 template <class Cmpt>
210 inline typename innerProduct<Vector2D<Cmpt>, Tensor2D<Cmpt> >::type
211 operator&(const Vector2D<Cmpt>& v, const Tensor2D<Cmpt>& t)
213     return Vector2D<Cmpt>
214     (
215         v.x()*t.xx() + v.y()*t.yx(),
216         v.x()*t.xy() + v.y()*t.yy()
217     );
220 //- Outer-product between two vectors
221 template <class Cmpt>
222 inline typename outerProduct<Vector2D<Cmpt>, Vector2D<Cmpt> >::type
223 operator*(const Vector2D<Cmpt>& v1, const Vector2D<Cmpt>& v2)
225     return Tensor2D<Cmpt>
226     (
227         v1.x()*v2.x(), v1.x()*v2.y(),
228         v1.y()*v2.x(), v1.y()*v2.y()
229     );
233 //- Return the trace of a tensor
234 template <class Cmpt>
235 inline Cmpt tr(const Tensor2D<Cmpt>& t)
237     return t.xx() + t.yy();
241 //- Return the spherical part of a tensor
242 template <class Cmpt>
243 inline SphericalTensor2D<Cmpt> sph(const Tensor2D<Cmpt>& t)
245     return 0.5*tr(t);
249 //- Return the symmetric part of a tensor
250 template <class Cmpt>
251 inline Tensor2D<Cmpt> symm(const Tensor2D<Cmpt>& t)
253     return Tensor2D<Cmpt>
254     (
255         t.xx(), 0.5*(t.xy() + t.yx()),
256         0.5*(t.yx() + t.xy()), t.yy()
257     );
260 //- Return the twice the symmetric part of a tensor
261 template <class Cmpt>
262 inline Tensor2D<Cmpt> twoSymm(const Tensor2D<Cmpt>& t)
264     return Tensor2D<Cmpt>
265     (
266         t.xx() + t.xx(), t.xy() + t.yx(),
267         t.yx() + t.xy(), t.yy() + t.yy()
268     );
271 //- Return the skew-symmetric part of a tensor
272 template <class Cmpt>
273 inline Tensor2D<Cmpt> skew(const Tensor2D<Cmpt>& t)
275     return Tensor2D<Cmpt>
276     (
277         0.0, 0.5*(t.xy() - t.yx()),
278         0.5*(t.yx() - t.xy()), 0.0
279     );
283 //- Return the deviatoric part of a tensor
284 template <class Cmpt>
285 inline Tensor2D<Cmpt> dev(const Tensor2D<Cmpt>& t)
287     return t - SphericalTensor2D<Cmpt>::oneThirdI*tr(t);
291 //- Return the deviatoric part of a tensor
292 template <class Cmpt>
293 inline Tensor2D<Cmpt> dev2(const Tensor2D<Cmpt>& t)
295     return t - SphericalTensor2D<Cmpt>::twoThirdsI*tr(t);
299 //- Return the determinant of a tensor
300 template <class Cmpt>
301 inline Cmpt det(const Tensor2D<Cmpt>& t)
303     return(t.xx()*t.yy() - t.xy()*t.yx());
306 //- Return the inverse of a tensor give the determinant
307 template <class Cmpt>
308 inline Tensor2D<Cmpt> inv(const Tensor2D<Cmpt>& t, const Cmpt dett)
310     return Tensor2D<Cmpt>
311     (
312         t.yy(), -t.xy(),
313        -t.yx(),  t.xx()
314     )/dett;
317 //- Return the inverse of a tensor
318 template <class Cmpt>
319 inline Tensor2D<Cmpt> inv(const Tensor2D<Cmpt>& t)
321     return inv(t, det(t));
325 //- Return the 1st invariant of a tensor
326 template <class Cmpt>
327 inline Cmpt invariantI(const Tensor2D<Cmpt>& t)
329     return tr(t);
333 //- Return the 2nd invariant of a tensor
334 template <class Cmpt>
335 inline Cmpt invariantII(const Tensor2D<Cmpt>& t)
337     return
338     (
339         0.5*sqr(tr(t))
340       - 0.5*
341         (
342            t.xx()*t.xx() + t.xy()*t.xy()
343          + t.yx()*t.yx() + t.yy()*t.yy()
344         )
345     );
349 //- Return the 3rd invariant of a tensor
350 template <class Cmpt>
351 inline Cmpt invariantIII(const Tensor2D<Cmpt>& t)
353     return det(t);
359 template <class Cmpt>
360 inline Tensor2D<Cmpt>
361 operator+(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
363     return Tensor2D<Cmpt>
364     (
365         st1.ii() + t2.xx(), t2.xy(),
366         t2.yx(),            st1.ii() + t2.yy()
367     );
371 template <class Cmpt>
372 inline Tensor2D<Cmpt>
373 operator+(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
375     return Tensor2D<Cmpt>
376     (
377         t1.xx() + st2.ii(), t1.xy(),
378         t1.yx(),            t1.yy() + st2.ii()
379     );
383 template <class Cmpt>
384 inline Tensor2D<Cmpt>
385 operator-(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
387     return Tensor2D<Cmpt>
388     (
389         st1.ii() - t2.xx(), -t2.xy(),
390        -t2.yx(),             st1.ii() - t2.yy()
391     );
395 template <class Cmpt>
396 inline Tensor2D<Cmpt>
397 operator-(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
399     return Tensor2D<Cmpt>
400     (
401         t1.xx() - st2.ii(), t1.xy(),
402         t1.yx(),            t1.yy() - st2.ii()
403     );
407 //- Inner-product between a spherical tensor and a tensor
408 template <class Cmpt>
409 inline Tensor2D<Cmpt>
410 operator&(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
412     return Tensor2D<Cmpt>
413     (
414         st1.ii()*t2.xx(),
415         st1.ii()*t2.xy(),
416                           st1.ii()*t2.yx(),
417                           st1.ii()*t2.yy()
418     );
422 //- Inner-product between a tensor and a spherical tensor
423 template <class Cmpt>
424 inline Tensor2D<Cmpt>
425 operator&(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
427     return Tensor2D<Cmpt>
428     (
429         t1.xx()*st2.ii(),
430                           t1.xy()*st2.ii(),
432         t1.yx()*st2.ii(),
433                           t1.yy()*st2.ii()
434     );
438 //- Double-dot-product between a spherical tensor and a tensor
439 template <class Cmpt>
440 inline Cmpt
441 operator&&(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
443     return(st1.ii()*t2.xx() + st1.ii()*t2.yy());
447 //- Double-dot-product between a tensor and a spherical tensor
448 template <class Cmpt>
449 inline Cmpt
450 operator&&(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
452     return(t1.xx()*st2.ii() + t1.yy()*st2.ii());
456 template<class Cmpt>
457 class typeOfSum<SphericalTensor2D<Cmpt>, Tensor2D<Cmpt> >
459 public:
461     typedef Tensor2D<Cmpt> type;
464 template<class Cmpt>
465 class typeOfSum<Tensor2D<Cmpt>, SphericalTensor2D<Cmpt> >
467 public:
469     typedef Tensor2D<Cmpt> type;
473 template<class Cmpt>
474 class innerProduct<SphericalTensor2D<Cmpt>, Tensor2D<Cmpt> >
476 public:
478     typedef Tensor2D<Cmpt> type;
481 template<class Cmpt>
482 class innerProduct<Tensor2D<Cmpt>, SphericalTensor2D<Cmpt> >
484 public:
486     typedef Tensor2D<Cmpt> type;
490 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
492 } // End namespace Foam
494 // ************************************************************************* //