initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / primitives / Tensor2D / Tensor2DI.H
blob752be90d85f169c0df3fbb734864ae1aa32b2c04
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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 template <class Cmpt>
35 inline Tensor2D<Cmpt>::Tensor2D()
39 template <class Cmpt>
40 inline Tensor2D<Cmpt>::Tensor2D(const VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>& vs)
42     VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>(vs)
46 template <class Cmpt>
47 inline Tensor2D<Cmpt>::Tensor2D(const SphericalTensor2D<Cmpt>& st)
49     this->v_[XX] = st.ii(); this->v_[XY] = 0;
50     this->v_[YX] = 0; this->v_[YY] = st.ii();
54 template <class Cmpt>
55 inline Tensor2D<Cmpt>::Tensor2D
57     const Cmpt txx, const Cmpt txy,
58     const Cmpt tyx, const Cmpt tyy
61     this->v_[XX] = txx; this->v_[XY] = txy;
62     this->v_[YX] = tyx; this->v_[YY] = tyy;
66 template <class Cmpt>
67 inline Tensor2D<Cmpt>::Tensor2D(Istream& is)
69     VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>(is)
73 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
75 template <class Cmpt>
76 inline const Vector2D<Cmpt>&  Tensor2D<Cmpt>::x() const
78     return reinterpret_cast<const Vector2D<Cmpt>&>(this->v_[XX]);
81 template <class Cmpt>
82 inline const Vector2D<Cmpt>&  Tensor2D<Cmpt>::y() const
84     return reinterpret_cast<const Vector2D<Cmpt>&>(this->v_[YX]);
88 template <class Cmpt>
89 inline Vector2D<Cmpt>&  Tensor2D<Cmpt>::x()
91     return reinterpret_cast<Vector2D<Cmpt>&>(this->v_[XX]);
94 template <class Cmpt>
95 inline Vector2D<Cmpt>&  Tensor2D<Cmpt>::y()
97     return reinterpret_cast<Vector2D<Cmpt>&>(this->v_[YX]);
101 template <class Cmpt>
102 inline const Cmpt&  Tensor2D<Cmpt>::xx() const
104     return this->v_[XX];
107 template <class Cmpt>
108 inline const Cmpt&  Tensor2D<Cmpt>::xy() const
110     return this->v_[XY];
113 template <class Cmpt>
114 inline const Cmpt&  Tensor2D<Cmpt>::yx() const
116     return this->v_[YX];
119 template <class Cmpt>
120 inline const Cmpt&  Tensor2D<Cmpt>::yy() const
122     return this->v_[YY];
126 template <class Cmpt>
127 inline Cmpt& Tensor2D<Cmpt>::xx()
129     return this->v_[XX];
132 template <class Cmpt>
133 inline Cmpt& Tensor2D<Cmpt>::xy()
135     return this->v_[XY];
138 template <class Cmpt>
139 inline Cmpt& Tensor2D<Cmpt>::yx()
141     return this->v_[YX];
144 template <class Cmpt>
145 inline Cmpt& Tensor2D<Cmpt>::yy()
147     return this->v_[YY];
151 template <class Cmpt>
152 inline Tensor2D<Cmpt> Tensor2D<Cmpt>::T() const
154     return Tensor2D<Cmpt>
155     (
156         xx(), yx(),
157         xy(), yy()
158     );
162 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
164 template <class Cmpt>
165 inline void Tensor2D<Cmpt>::operator=(const SphericalTensor2D<Cmpt>& st)
167     this->v_[XX] = st.ii(); this->v_[XY] = 0;
168     this->v_[YX] = 0; this->v_[YY] = st.ii();
173 // * * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * //
175 //- Inner-product between two tensors
176 template <class Cmpt>
177 inline typename innerProduct<Tensor2D<Cmpt>, Tensor2D<Cmpt> >::type
178 operator&(const Tensor2D<Cmpt>& t1, const Tensor2D<Cmpt>& t2)
180     return Tensor2D<Cmpt>
181     (
182         t1.xx()*t2.xx() + t1.xy()*t2.yx(),
183         t1.xx()*t2.xy() + t1.xy()*t2.yy(),
185         t1.yx()*t2.xx() + t1.yy()*t2.yx(),
186         t1.yx()*t2.xy() + t1.yy()*t2.yy()
187     );
190 //- Inner-product between a tensor and a vector
191 template <class Cmpt>
192 inline typename innerProduct<Tensor2D<Cmpt>, Vector2D<Cmpt> >::type
193 operator&(const Tensor2D<Cmpt>& t, const Vector2D<Cmpt>& v)
195     return Vector2D<Cmpt>
196     (
197         t.xx()*v.x() + t.xy()*v.y(),
198         t.yx()*v.x() + t.yy()*v.y()
199     );
202 //- Inner-product between a vector and a tensor
203 template <class Cmpt>
204 inline typename innerProduct<Vector2D<Cmpt>, Tensor2D<Cmpt> >::type
205 operator&(const Vector2D<Cmpt>& v, const Tensor2D<Cmpt>& t)
207     return Vector2D<Cmpt>
208     (
209         v.x()*t.xx() + v.y()*t.yx(),
210         v.x()*t.xy() + v.y()*t.yy()
211     );
214 //- Outer-product between two vectors
215 template <class Cmpt>
216 inline typename outerProduct<Vector2D<Cmpt>, Vector2D<Cmpt> >::type
217 operator*(const Vector2D<Cmpt>& v1, const Vector2D<Cmpt>& v2)
219     return Tensor2D<Cmpt>
220     (
221         v1.x()*v2.x(), v1.x()*v2.y(),
222         v1.y()*v2.x(), v1.y()*v2.y()
223     );
227 //- Return the trace of a tensor
228 template <class Cmpt>
229 inline Cmpt tr(const Tensor2D<Cmpt>& t)
231     return t.xx() + t.yy();
235 //- Return the spherical part of a tensor
236 template <class Cmpt>
237 inline SphericalTensor2D<Cmpt> sph(const Tensor2D<Cmpt>& t)
239     return 0.5*tr(t);
243 //- Return the symmetric part of a tensor
244 template <class Cmpt>
245 inline Tensor2D<Cmpt> symm(const Tensor2D<Cmpt>& t)
247     return Tensor2D<Cmpt>
248     (
249         t.xx(), 0.5*(t.xy() + t.yx()),
250         0.5*(t.yx() + t.xy()), t.yy()
251     );
254 //- Return the twice the symmetric part of a tensor
255 template <class Cmpt>
256 inline Tensor2D<Cmpt> twoSymm(const Tensor2D<Cmpt>& t)
258     return Tensor2D<Cmpt>
259     (
260         t.xx() + t.xx(), t.xy() + t.yx(),
261         t.yx() + t.xy(), t.yy() + t.yy()
262     );
265 //- Return the skew-symmetric part of a tensor
266 template <class Cmpt>
267 inline Tensor2D<Cmpt> skew(const Tensor2D<Cmpt>& t)
269     return Tensor2D<Cmpt>
270     (
271         0.0, 0.5*(t.xy() - t.yx()),
272         0.5*(t.yx() - t.xy()), 0.0
273     );
277 //- Return the deviatoric part of a tensor
278 template <class Cmpt>
279 inline Tensor2D<Cmpt> dev(const Tensor2D<Cmpt>& t)
281     return t - SphericalTensor2D<Cmpt>::oneThirdI*tr(t);
285 //- Return the deviatoric part of a tensor
286 template <class Cmpt>
287 inline Tensor2D<Cmpt> dev2(const Tensor2D<Cmpt>& t)
289     return t - SphericalTensor2D<Cmpt>::twoThirdsI*tr(t);
293 //- Return the determinant of a tensor
294 template <class Cmpt>
295 inline Cmpt det(const Tensor2D<Cmpt>& t)
297     return(t.xx()*t.yy() - t.xy()*t.yx());
301 //- Return the cofactor tensor of a tensor
302 template <class Cmpt>
303 inline Tensor2D<Cmpt> cof(const Tensor2D<Cmpt>& t)
305     return Tensor2D<Cmpt>
306     (
307         t.yy(), -t.xy(),
308        -t.yx(),  t.xx()
309     );
313 //- Return the inverse of a tensor given the determinant
314 template <class Cmpt>
315 inline Tensor2D<Cmpt> inv(const Tensor2D<Cmpt>& t, const Cmpt dett)
317     return cof(t)/dett;
321 //- Return the inverse of a tensor
322 template <class Cmpt>
323 inline Tensor2D<Cmpt> inv(const Tensor2D<Cmpt>& t)
325     return inv(t, det(t));
329 //- Return the 1st invariant of a tensor
330 template <class Cmpt>
331 inline Cmpt invariantI(const Tensor2D<Cmpt>& t)
333     return tr(t);
337 //- Return the 2nd invariant of a tensor
338 template <class Cmpt>
339 inline Cmpt invariantII(const Tensor2D<Cmpt>& t)
341     return
342     (
343         0.5*sqr(tr(t))
344       - 0.5*
345         (
346            t.xx()*t.xx() + t.xy()*t.xy()
347          + t.yx()*t.yx() + t.yy()*t.yy()
348         )
349     );
353 //- Return the 3rd invariant of a tensor
354 template <class Cmpt>
355 inline Cmpt invariantIII(const Tensor2D<Cmpt>& t)
357     return det(t);
363 template <class Cmpt>
364 inline Tensor2D<Cmpt>
365 operator+(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
367     return Tensor2D<Cmpt>
368     (
369         st1.ii() + t2.xx(), t2.xy(),
370         t2.yx(),            st1.ii() + t2.yy()
371     );
375 template <class Cmpt>
376 inline Tensor2D<Cmpt>
377 operator+(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
379     return Tensor2D<Cmpt>
380     (
381         t1.xx() + st2.ii(), t1.xy(),
382         t1.yx(),            t1.yy() + st2.ii()
383     );
387 template <class Cmpt>
388 inline Tensor2D<Cmpt>
389 operator-(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
391     return Tensor2D<Cmpt>
392     (
393         st1.ii() - t2.xx(), -t2.xy(),
394        -t2.yx(),             st1.ii() - t2.yy()
395     );
399 template <class Cmpt>
400 inline Tensor2D<Cmpt>
401 operator-(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
403     return Tensor2D<Cmpt>
404     (
405         t1.xx() - st2.ii(), t1.xy(),
406         t1.yx(),            t1.yy() - st2.ii()
407     );
411 //- Inner-product between a spherical tensor and a tensor
412 template <class Cmpt>
413 inline Tensor2D<Cmpt>
414 operator&(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
416     return Tensor2D<Cmpt>
417     (
418         st1.ii()*t2.xx(),
419         st1.ii()*t2.xy(),
420                           st1.ii()*t2.yx(),
421                           st1.ii()*t2.yy()
422     );
426 //- Inner-product between a tensor and a spherical tensor
427 template <class Cmpt>
428 inline Tensor2D<Cmpt>
429 operator&(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
431     return Tensor2D<Cmpt>
432     (
433         t1.xx()*st2.ii(),
434                           t1.xy()*st2.ii(),
436         t1.yx()*st2.ii(),
437                           t1.yy()*st2.ii()
438     );
442 //- Double-dot-product between a spherical tensor and a tensor
443 template <class Cmpt>
444 inline Cmpt
445 operator&&(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
447     return(st1.ii()*t2.xx() + st1.ii()*t2.yy());
451 //- Double-dot-product between a tensor and a spherical tensor
452 template <class Cmpt>
453 inline Cmpt
454 operator&&(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
456     return(t1.xx()*st2.ii() + t1.yy()*st2.ii());
460 template<class Cmpt>
461 class typeOfSum<SphericalTensor2D<Cmpt>, Tensor2D<Cmpt> >
463 public:
465     typedef Tensor2D<Cmpt> type;
468 template<class Cmpt>
469 class typeOfSum<Tensor2D<Cmpt>, SphericalTensor2D<Cmpt> >
471 public:
473     typedef Tensor2D<Cmpt> type;
477 template<class Cmpt>
478 class innerProduct<SphericalTensor2D<Cmpt>, Tensor2D<Cmpt> >
480 public:
482     typedef Tensor2D<Cmpt> type;
485 template<class Cmpt>
486 class innerProduct<Tensor2D<Cmpt>, SphericalTensor2D<Cmpt> >
488 public:
490     typedef Tensor2D<Cmpt> type;
494 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
496 } // End namespace Foam
498 // ************************************************************************* //