BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / OpenFOAM / primitives / Tensor2D / Tensor2DI.H
blob1760cc1f5fc0f811edd94d641ef1d15385dd11ee
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, 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];
105 template <class Cmpt>
106 inline const Cmpt& Tensor2D<Cmpt>::xy() const
108     return this->v_[XY];
111 template <class Cmpt>
112 inline const Cmpt& Tensor2D<Cmpt>::yx() const
114     return this->v_[YX];
117 template <class Cmpt>
118 inline const Cmpt& Tensor2D<Cmpt>::yy() const
120     return this->v_[YY];
124 template <class Cmpt>
125 inline Cmpt& Tensor2D<Cmpt>::xx()
127     return this->v_[XX];
130 template <class Cmpt>
131 inline Cmpt& Tensor2D<Cmpt>::xy()
133     return this->v_[XY];
136 template <class Cmpt>
137 inline Cmpt& Tensor2D<Cmpt>::yx()
139     return this->v_[YX];
142 template <class Cmpt>
143 inline Cmpt& Tensor2D<Cmpt>::yy()
145     return this->v_[YY];
149 template <class Cmpt>
150 inline Tensor2D<Cmpt> Tensor2D<Cmpt>::T() const
152     return Tensor2D<Cmpt>
153     (
154         xx(), yx(),
155         xy(), yy()
156     );
160 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
162 template <class Cmpt>
163 inline void Tensor2D<Cmpt>::operator=(const SphericalTensor2D<Cmpt>& st)
165     this->v_[XX] = st.ii(); this->v_[XY] = 0;
166     this->v_[YX] = 0; this->v_[YY] = st.ii();
171 // * * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * //
173 //- Inner-product between two tensors
174 template <class Cmpt>
175 inline typename innerProduct<Tensor2D<Cmpt>, Tensor2D<Cmpt> >::type
176 operator&(const Tensor2D<Cmpt>& t1, const Tensor2D<Cmpt>& t2)
178     return Tensor2D<Cmpt>
179     (
180         t1.xx()*t2.xx() + t1.xy()*t2.yx(),
181         t1.xx()*t2.xy() + t1.xy()*t2.yy(),
183         t1.yx()*t2.xx() + t1.yy()*t2.yx(),
184         t1.yx()*t2.xy() + t1.yy()*t2.yy()
185     );
188 //- Inner-product between a tensor and a vector
189 template <class Cmpt>
190 inline typename innerProduct<Tensor2D<Cmpt>, Vector2D<Cmpt> >::type
191 operator&(const Tensor2D<Cmpt>& t, const Vector2D<Cmpt>& v)
193     return Vector2D<Cmpt>
194     (
195         t.xx()*v.x() + t.xy()*v.y(),
196         t.yx()*v.x() + t.yy()*v.y()
197     );
200 //- Inner-product between a vector and a tensor
201 template <class Cmpt>
202 inline typename innerProduct<Vector2D<Cmpt>, Tensor2D<Cmpt> >::type
203 operator&(const Vector2D<Cmpt>& v, const Tensor2D<Cmpt>& t)
205     return Vector2D<Cmpt>
206     (
207         v.x()*t.xx() + v.y()*t.yx(),
208         v.x()*t.xy() + v.y()*t.yy()
209     );
212 //- Outer-product between two vectors
213 template <class Cmpt>
214 inline typename outerProduct<Vector2D<Cmpt>, Vector2D<Cmpt> >::type
215 operator*(const Vector2D<Cmpt>& v1, const Vector2D<Cmpt>& v2)
217     return Tensor2D<Cmpt>
218     (
219         v1.x()*v2.x(), v1.x()*v2.y(),
220         v1.y()*v2.x(), v1.y()*v2.y()
221     );
225 //- Return the trace of a tensor
226 template <class Cmpt>
227 inline Cmpt tr(const Tensor2D<Cmpt>& t)
229     return t.xx() + t.yy();
233 //- Return the spherical part of a tensor
234 template <class Cmpt>
235 inline SphericalTensor2D<Cmpt> sph(const Tensor2D<Cmpt>& t)
237     return 0.5*tr(t);
241 //- Return the symmetric part of a tensor
242 template <class Cmpt>
243 inline Tensor2D<Cmpt> symm(const Tensor2D<Cmpt>& t)
245     return Tensor2D<Cmpt>
246     (
247         t.xx(), 0.5*(t.xy() + t.yx()),
248         0.5*(t.yx() + t.xy()), t.yy()
249     );
252 //- Return the twice the symmetric part of a tensor
253 template <class Cmpt>
254 inline Tensor2D<Cmpt> twoSymm(const Tensor2D<Cmpt>& t)
256     return Tensor2D<Cmpt>
257     (
258         t.xx() + t.xx(), t.xy() + t.yx(),
259         t.yx() + t.xy(), t.yy() + t.yy()
260     );
263 //- Return the skew-symmetric part of a tensor
264 template <class Cmpt>
265 inline Tensor2D<Cmpt> skew(const Tensor2D<Cmpt>& t)
267     return Tensor2D<Cmpt>
268     (
269         0.0, 0.5*(t.xy() - t.yx()),
270         0.5*(t.yx() - t.xy()), 0.0
271     );
275 //- Return the deviatoric part of a tensor
276 template <class Cmpt>
277 inline Tensor2D<Cmpt> dev(const Tensor2D<Cmpt>& t)
279     return t - SphericalTensor2D<Cmpt>::oneThirdI*tr(t);
283 //- Return the deviatoric part of a tensor
284 template <class Cmpt>
285 inline Tensor2D<Cmpt> dev2(const Tensor2D<Cmpt>& t)
287     return t - SphericalTensor2D<Cmpt>::twoThirdsI*tr(t);
291 //- Return the determinant of a tensor
292 template <class Cmpt>
293 inline Cmpt det(const Tensor2D<Cmpt>& t)
295     return(t.xx()*t.yy() - t.xy()*t.yx());
299 //- Return the cofactor tensor of a tensor
300 template <class Cmpt>
301 inline Tensor2D<Cmpt> cof(const Tensor2D<Cmpt>& t)
303     return Tensor2D<Cmpt>
304     (
305         t.yy(), -t.xy(),
306        -t.yx(),  t.xx()
307     );
311 //- Return the inverse of a tensor given the determinant
312 template <class Cmpt>
313 inline Tensor2D<Cmpt> inv(const Tensor2D<Cmpt>& t, const Cmpt dett)
315     return cof(t)/dett;
319 //- Return the inverse of a tensor
320 template <class Cmpt>
321 inline Tensor2D<Cmpt> inv(const Tensor2D<Cmpt>& t)
323     return inv(t, det(t));
327 //- Return the 1st invariant of a tensor
328 template <class Cmpt>
329 inline Cmpt invariantI(const Tensor2D<Cmpt>& t)
331     return tr(t);
335 //- Return the 2nd invariant of a tensor
336 template <class Cmpt>
337 inline Cmpt invariantII(const Tensor2D<Cmpt>& t)
339     return
340     (
341         0.5*sqr(tr(t))
342       - 0.5*
343         (
344            t.xx()*t.xx() + t.xy()*t.xy()
345          + t.yx()*t.yx() + t.yy()*t.yy()
346         )
347     );
351 //- Return the 3rd invariant of a tensor
352 template <class Cmpt>
353 inline Cmpt invariantIII(const Tensor2D<Cmpt>& t)
355     return det(t);
361 template <class Cmpt>
362 inline Tensor2D<Cmpt>
363 operator+(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
365     return Tensor2D<Cmpt>
366     (
367         st1.ii() + t2.xx(), t2.xy(),
368         t2.yx(),            st1.ii() + t2.yy()
369     );
373 template <class Cmpt>
374 inline Tensor2D<Cmpt>
375 operator+(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
377     return Tensor2D<Cmpt>
378     (
379         t1.xx() + st2.ii(), t1.xy(),
380         t1.yx(),            t1.yy() + st2.ii()
381     );
385 template <class Cmpt>
386 inline Tensor2D<Cmpt>
387 operator-(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
389     return Tensor2D<Cmpt>
390     (
391         st1.ii() - t2.xx(), -t2.xy(),
392        -t2.yx(),             st1.ii() - t2.yy()
393     );
397 template <class Cmpt>
398 inline Tensor2D<Cmpt>
399 operator-(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
401     return Tensor2D<Cmpt>
402     (
403         t1.xx() - st2.ii(), t1.xy(),
404         t1.yx(),            t1.yy() - st2.ii()
405     );
409 //- Inner-product between a spherical tensor and a tensor
410 template <class Cmpt>
411 inline Tensor2D<Cmpt>
412 operator&(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
414     return Tensor2D<Cmpt>
415     (
416         st1.ii()*t2.xx(),
417         st1.ii()*t2.xy(),
418                           st1.ii()*t2.yx(),
419                           st1.ii()*t2.yy()
420     );
424 //- Inner-product between a tensor and a spherical tensor
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(),
432                           t1.xy()*st2.ii(),
434         t1.yx()*st2.ii(),
435                           t1.yy()*st2.ii()
436     );
440 //- Double-dot-product between a spherical tensor and a tensor
441 template <class Cmpt>
442 inline Cmpt
443 operator&&(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
445     return(st1.ii()*t2.xx() + st1.ii()*t2.yy());
449 //- Double-dot-product between a tensor and a spherical tensor
450 template <class Cmpt>
451 inline Cmpt
452 operator&&(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
454     return(t1.xx()*st2.ii() + t1.yy()*st2.ii());
458 template<class Cmpt>
459 class typeOfSum<SphericalTensor2D<Cmpt>, Tensor2D<Cmpt> >
461 public:
463     typedef Tensor2D<Cmpt> type;
466 template<class Cmpt>
467 class typeOfSum<Tensor2D<Cmpt>, SphericalTensor2D<Cmpt> >
469 public:
471     typedef Tensor2D<Cmpt> type;
475 template<class Cmpt>
476 class innerProduct<Tensor2D<Cmpt>, Tensor2D<Cmpt> >
478 public:
480     typedef Tensor2D<Cmpt> type;
483 template<class Cmpt>
484 class innerProduct<SphericalTensor2D<Cmpt>, Tensor2D<Cmpt> >
486 public:
488     typedef Tensor2D<Cmpt> type;
491 template<class Cmpt>
492 class innerProduct<Tensor2D<Cmpt>, SphericalTensor2D<Cmpt> >
494 public:
496     typedef Tensor2D<Cmpt> type;
499 template<class Cmpt>
500 class innerProduct<Tensor2D<Cmpt>, Vector2D<Cmpt> >
502 public:
504     typedef Vector2D<Cmpt> type;
507 template<class Cmpt>
508 class innerProduct<Vector2D<Cmpt>, Tensor2D<Cmpt> >
510 public:
512     typedef Vector2D<Cmpt> type;
517 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
519 } // End namespace Foam
521 // ************************************************************************* //