Remove trailing whitespace systematically
[foam-extend-3.2.git] / src / foam / primitives / Tensor2D / Tensor2DI.H
blob438b04ab6e140e2dfb728b41ba3a714e9705be30
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     |
5     \\  /    A nd           | For copyright notice see file Copyright
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
28 namespace Foam
31 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
33 template <class Cmpt>
34 inline Tensor2D<Cmpt>::Tensor2D()
38 template <class Cmpt>
39 inline Tensor2D<Cmpt>::Tensor2D(const VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>& vs)
41     VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>(vs)
45 template <class Cmpt>
46 inline Tensor2D<Cmpt>::Tensor2D(const SphericalTensor2D<Cmpt>& st)
48     this->v_[XX] = st.ii(); this->v_[XY] = 0;
49     this->v_[YX] = 0; this->v_[YY] = st.ii();
53 template <class Cmpt>
54 inline Tensor2D<Cmpt>::Tensor2D
56     const Vector2D<Cmpt>& x,
57     const Vector2D<Cmpt>& y
60     this->v_[XX] = x.x(); this->v_[XY] = x.y();
61     this->v_[YX] = y.x(); this->v_[YY] = y.y();
65 template <class Cmpt>
66 inline Tensor2D<Cmpt>::Tensor2D
68     const Cmpt txx, const Cmpt txy,
69     const Cmpt tyx, const Cmpt tyy
72     this->v_[XX] = txx; this->v_[XY] = txy;
73     this->v_[YX] = tyx; this->v_[YY] = tyy;
77 template <class Cmpt>
78 inline Tensor2D<Cmpt>::Tensor2D(Istream& is)
80     VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>(is)
84 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
86 template <class Cmpt>
87 inline Vector2D<Cmpt> Tensor2D<Cmpt>::x() const
89     return Vector2D<Cmpt>(this->v_[XX], this->v_[XY]);
92 template <class Cmpt>
93 inline Vector2D<Cmpt> Tensor2D<Cmpt>::y() const
95     return Vector2D<Cmpt>(this->v_[YX], this->v_[YY]);
99 template <class Cmpt>
100 inline const Cmpt& Tensor2D<Cmpt>::xx() const
102     return this->v_[XX];
106 template <class Cmpt>
107 inline const Cmpt& Tensor2D<Cmpt>::xy() const
109     return this->v_[XY];
113 template <class Cmpt>
114 inline const Cmpt& Tensor2D<Cmpt>::yx() const
116     return this->v_[YX];
120 template <class Cmpt>
121 inline const Cmpt& Tensor2D<Cmpt>::yy() const
123     return this->v_[YY];
127 template <class Cmpt>
128 inline Cmpt& Tensor2D<Cmpt>::xx()
130     return this->v_[XX];
134 template <class Cmpt>
135 inline Cmpt& Tensor2D<Cmpt>::xy()
137     return this->v_[XY];
141 template <class Cmpt>
142 inline Cmpt& Tensor2D<Cmpt>::yx()
144     return this->v_[YX];
148 template <class Cmpt>
149 inline Cmpt& Tensor2D<Cmpt>::yy()
151     return this->v_[YY];
155 template <class Cmpt>
156 inline const Cmpt& Tensor2D<Cmpt>::operator()
158     const direction i,
159     const direction j
160 ) const
162     return this->operator[](i*Tensor2D<Cmpt>::dim + j);
166 template <class Cmpt>
167 inline Cmpt& Tensor2D<Cmpt>::operator()
169     const direction i,
170     const direction j
173     return this->operator[](i*Tensor2D<Cmpt>::dim + j);
177 template <class Cmpt>
178 inline Tensor2D<Cmpt> Tensor2D<Cmpt>::T() const
180     return Tensor2D<Cmpt>
181     (
182         xx(), yx(),
183         xy(), yy()
184     );
188 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
190 template <class Cmpt>
191 inline void Tensor2D<Cmpt>::operator=(const SphericalTensor2D<Cmpt>& st)
193     this->v_[XX] = st.ii(); this->v_[XY] = 0;
194     this->v_[YX] = 0; this->v_[YY] = st.ii();
199 // * * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * //
201 //- Inner-product between two tensors
202 template <class Cmpt>
203 inline typename innerProduct<Tensor2D<Cmpt>, Tensor2D<Cmpt> >::type
204 operator&(const Tensor2D<Cmpt>& t1, const Tensor2D<Cmpt>& t2)
206     return Tensor2D<Cmpt>
207     (
208         t1.xx()*t2.xx() + t1.xy()*t2.yx(),
209         t1.xx()*t2.xy() + t1.xy()*t2.yy(),
211         t1.yx()*t2.xx() + t1.yy()*t2.yx(),
212         t1.yx()*t2.xy() + t1.yy()*t2.yy()
213     );
216 //- Inner-product between a tensor and a vector
217 template <class Cmpt>
218 inline typename innerProduct<Tensor2D<Cmpt>, Vector2D<Cmpt> >::type
219 operator&(const Tensor2D<Cmpt>& t, const Vector2D<Cmpt>& v)
221     return Vector2D<Cmpt>
222     (
223         t.xx()*v.x() + t.xy()*v.y(),
224         t.yx()*v.x() + t.yy()*v.y()
225     );
228 //- Inner-product between a vector and a tensor
229 template <class Cmpt>
230 inline typename innerProduct<Vector2D<Cmpt>, Tensor2D<Cmpt> >::type
231 operator&(const Vector2D<Cmpt>& v, const Tensor2D<Cmpt>& t)
233     return Vector2D<Cmpt>
234     (
235         v.x()*t.xx() + v.y()*t.yx(),
236         v.x()*t.xy() + v.y()*t.yy()
237     );
240 //- Outer-product between two vectors
241 template <class Cmpt>
242 inline typename outerProduct<Vector2D<Cmpt>, Vector2D<Cmpt> >::type
243 operator*(const Vector2D<Cmpt>& v1, const Vector2D<Cmpt>& v2)
245     return Tensor2D<Cmpt>
246     (
247         v1.x()*v2.x(), v1.x()*v2.y(),
248         v1.y()*v2.x(), v1.y()*v2.y()
249     );
253 //- Return the trace of a tensor
254 template <class Cmpt>
255 inline Cmpt tr(const Tensor2D<Cmpt>& t)
257     return t.xx() + t.yy();
261 //- Return the spherical part of a tensor
262 template <class Cmpt>
263 inline SphericalTensor2D<Cmpt> sph(const Tensor2D<Cmpt>& t)
265     return 0.5*tr(t);
269 //- Return the symmetric part of a tensor
270 template <class Cmpt>
271 inline Tensor2D<Cmpt> symm(const Tensor2D<Cmpt>& t)
273     return Tensor2D<Cmpt>
274     (
275         t.xx(), 0.5*(t.xy() + t.yx()),
276         0.5*(t.yx() + t.xy()), t.yy()
277     );
280 //- Return the twice the symmetric part of a tensor
281 template <class Cmpt>
282 inline Tensor2D<Cmpt> twoSymm(const Tensor2D<Cmpt>& t)
284     return Tensor2D<Cmpt>
285     (
286         t.xx() + t.xx(), t.xy() + t.yx(),
287         t.yx() + t.xy(), t.yy() + t.yy()
288     );
291 //- Return the skew-symmetric part of a tensor
292 template <class Cmpt>
293 inline Tensor2D<Cmpt> skew(const Tensor2D<Cmpt>& t)
295     return Tensor2D<Cmpt>
296     (
297         0.0, 0.5*(t.xy() - t.yx()),
298         0.5*(t.yx() - t.xy()), 0.0
299     );
303 //- Return the deviatoric part of a tensor
304 template <class Cmpt>
305 inline Tensor2D<Cmpt> dev(const Tensor2D<Cmpt>& t)
307     return t - SphericalTensor2D<Cmpt>::oneThirdI*tr(t);
311 //- Return the deviatoric part of a tensor
312 template <class Cmpt>
313 inline Tensor2D<Cmpt> dev2(const Tensor2D<Cmpt>& t)
315     return t - SphericalTensor2D<Cmpt>::twoThirdsI*tr(t);
319 //- Return the determinant of a tensor
320 template <class Cmpt>
321 inline Cmpt det(const Tensor2D<Cmpt>& t)
323     return(t.xx()*t.yy() - t.xy()*t.yx());
327 //- Return the cofactor tensor of a tensor
328 template <class Cmpt>
329 inline Tensor2D<Cmpt> cof(const Tensor2D<Cmpt>& t)
331     return Tensor2D<Cmpt>
332     (
333         t.yy(), -t.xy(),
334        -t.yx(),  t.xx()
335     );
339 //- Return the inverse of a tensor given the determinant
340 template <class Cmpt>
341 inline Tensor2D<Cmpt> inv(const Tensor2D<Cmpt>& t, const Cmpt dett)
343     return cof(t)/dett;
347 //- Return the inverse of a tensor
348 template <class Cmpt>
349 inline Tensor2D<Cmpt> inv(const Tensor2D<Cmpt>& t)
351     return inv(t, det(t));
355 //- Return the 1st invariant of a tensor
356 template <class Cmpt>
357 inline Cmpt invariantI(const Tensor2D<Cmpt>& t)
359     return tr(t);
363 //- Return the 2nd invariant of a tensor
364 template <class Cmpt>
365 inline Cmpt invariantII(const Tensor2D<Cmpt>& t)
367     return
368     (
369         0.5*sqr(tr(t))
370       - 0.5*
371         (
372            t.xx()*t.xx() + t.xy()*t.xy()
373          + t.yx()*t.yx() + t.yy()*t.yy()
374         )
375     );
379 //- Return the 3rd invariant of a tensor
380 template <class Cmpt>
381 inline Cmpt invariantIII(const Tensor2D<Cmpt>& t)
383     return det(t);
389 template <class Cmpt>
390 inline Tensor2D<Cmpt>
391 operator+(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
393     return Tensor2D<Cmpt>
394     (
395         st1.ii() + t2.xx(), t2.xy(),
396         t2.yx(),            st1.ii() + t2.yy()
397     );
401 template <class Cmpt>
402 inline Tensor2D<Cmpt>
403 operator+(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
405     return Tensor2D<Cmpt>
406     (
407         t1.xx() + st2.ii(), t1.xy(),
408         t1.yx(),            t1.yy() + st2.ii()
409     );
413 template <class Cmpt>
414 inline Tensor2D<Cmpt>
415 operator-(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
417     return Tensor2D<Cmpt>
418     (
419         st1.ii() - t2.xx(), -t2.xy(),
420        -t2.yx(),             st1.ii() - t2.yy()
421     );
425 template <class Cmpt>
426 inline Tensor2D<Cmpt>
427 operator-(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
429     return Tensor2D<Cmpt>
430     (
431         t1.xx() - st2.ii(), t1.xy(),
432         t1.yx(),            t1.yy() - st2.ii()
433     );
437 //- Inner-product between a spherical tensor and a tensor
438 template <class Cmpt>
439 inline Tensor2D<Cmpt>
440 operator&(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
442     return Tensor2D<Cmpt>
443     (
444         st1.ii()*t2.xx(),
445         st1.ii()*t2.xy(),
446                           st1.ii()*t2.yx(),
447                           st1.ii()*t2.yy()
448     );
452 //- Inner-product between a tensor and a spherical tensor
453 template <class Cmpt>
454 inline Tensor2D<Cmpt>
455 operator&(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
457     return Tensor2D<Cmpt>
458     (
459         t1.xx()*st2.ii(),
460                           t1.xy()*st2.ii(),
462         t1.yx()*st2.ii(),
463                           t1.yy()*st2.ii()
464     );
468 //- Double-dot-product between a spherical tensor and a tensor
469 template <class Cmpt>
470 inline Cmpt
471 operator&&(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
473     return(st1.ii()*t2.xx() + st1.ii()*t2.yy());
477 //- Double-dot-product between a tensor and a spherical tensor
478 template <class Cmpt>
479 inline Cmpt
480 operator&&(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
482     return(t1.xx()*st2.ii() + t1.yy()*st2.ii());
486 template<class Cmpt>
487 class typeOfSum<SphericalTensor2D<Cmpt>, Tensor2D<Cmpt> >
489 public:
491     typedef Tensor2D<Cmpt> type;
494 template<class Cmpt>
495 class typeOfSum<Tensor2D<Cmpt>, SphericalTensor2D<Cmpt> >
497 public:
499     typedef Tensor2D<Cmpt> type;
503 template<class Cmpt>
504 class innerProduct<Tensor2D<Cmpt>, Tensor2D<Cmpt> >
506 public:
508     typedef Tensor2D<Cmpt> type;
511 template<class Cmpt>
512 class innerProduct<SphericalTensor2D<Cmpt>, Tensor2D<Cmpt> >
514 public:
516     typedef Tensor2D<Cmpt> type;
519 template<class Cmpt>
520 class innerProduct<Tensor2D<Cmpt>, SphericalTensor2D<Cmpt> >
522 public:
524     typedef Tensor2D<Cmpt> type;
527 template<class Cmpt>
528 class innerProduct<Tensor2D<Cmpt>, Vector2D<Cmpt> >
530 public:
532     typedef Vector2D<Cmpt> type;
535 template<class Cmpt>
536 class innerProduct<Vector2D<Cmpt>, Tensor2D<Cmpt> >
538 public:
540     typedef Vector2D<Cmpt> type;
544 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
546 } // End namespace Foam
548 // ************************************************************************* //