1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
5 \\ / A nd | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 inline Tensor2D<Cmpt>::Tensor2D()
39 inline Tensor2D<Cmpt>::Tensor2D(const VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>& vs)
41 VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>(vs)
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();
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();
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;
78 inline Tensor2D<Cmpt>::Tensor2D(Istream& is)
80 VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>(is)
84 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
87 inline Vector2D<Cmpt> Tensor2D<Cmpt>::x() const
89 return Vector2D<Cmpt>(this->v_[XX], this->v_[XY]);
93 inline Vector2D<Cmpt> Tensor2D<Cmpt>::y() const
95 return Vector2D<Cmpt>(this->v_[YX], this->v_[YY]);
100 inline const Cmpt& Tensor2D<Cmpt>::xx() const
106 template <class Cmpt>
107 inline const Cmpt& Tensor2D<Cmpt>::xy() const
113 template <class Cmpt>
114 inline const Cmpt& Tensor2D<Cmpt>::yx() const
120 template <class Cmpt>
121 inline const Cmpt& Tensor2D<Cmpt>::yy() const
127 template <class Cmpt>
128 inline Cmpt& Tensor2D<Cmpt>::xx()
134 template <class Cmpt>
135 inline Cmpt& Tensor2D<Cmpt>::xy()
141 template <class Cmpt>
142 inline Cmpt& Tensor2D<Cmpt>::yx()
148 template <class Cmpt>
149 inline Cmpt& Tensor2D<Cmpt>::yy()
155 template <class Cmpt>
156 inline const Cmpt& Tensor2D<Cmpt>::operator()
162 return this->operator[](i*Tensor2D<Cmpt>::dim + j);
166 template <class Cmpt>
167 inline Cmpt& Tensor2D<Cmpt>::operator()
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>
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>
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()
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>
223 t.xx()*v.x() + t.xy()*v.y(),
224 t.yx()*v.x() + t.yy()*v.y()
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>
235 v.x()*t.xx() + v.y()*t.yx(),
236 v.x()*t.xy() + v.y()*t.yy()
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>
247 v1.x()*v2.x(), v1.x()*v2.y(),
248 v1.y()*v2.x(), v1.y()*v2.y()
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)
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>
275 t.xx(), 0.5*(t.xy() + t.yx()),
276 0.5*(t.yx() + t.xy()), t.yy()
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>
286 t.xx() + t.xx(), t.xy() + t.yx(),
287 t.yx() + t.xy(), t.yy() + t.yy()
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>
297 0.0, 0.5*(t.xy() - t.yx()),
298 0.5*(t.yx() - t.xy()), 0.0
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>
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)
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)
363 //- Return the 2nd invariant of a tensor
364 template <class Cmpt>
365 inline Cmpt invariantII(const Tensor2D<Cmpt>& t)
372 t.xx()*t.xx() + t.xy()*t.xy()
373 + t.yx()*t.yx() + t.yy()*t.yy()
379 //- Return the 3rd invariant of a tensor
380 template <class Cmpt>
381 inline Cmpt invariantIII(const Tensor2D<Cmpt>& t)
389 template <class Cmpt>
390 inline Tensor2D<Cmpt>
391 operator+(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
393 return Tensor2D<Cmpt>
395 st1.ii() + t2.xx(), t2.xy(),
396 t2.yx(), st1.ii() + t2.yy()
401 template <class Cmpt>
402 inline Tensor2D<Cmpt>
403 operator+(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
405 return Tensor2D<Cmpt>
407 t1.xx() + st2.ii(), t1.xy(),
408 t1.yx(), t1.yy() + st2.ii()
413 template <class Cmpt>
414 inline Tensor2D<Cmpt>
415 operator-(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
417 return Tensor2D<Cmpt>
419 st1.ii() - t2.xx(), -t2.xy(),
420 -t2.yx(), st1.ii() - t2.yy()
425 template <class Cmpt>
426 inline Tensor2D<Cmpt>
427 operator-(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
429 return Tensor2D<Cmpt>
431 t1.xx() - st2.ii(), t1.xy(),
432 t1.yx(), t1.yy() - st2.ii()
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>
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>
468 //- Double-dot-product between a spherical tensor and a tensor
469 template <class 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>
480 operator&&(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
482 return(t1.xx()*st2.ii() + t1.yy()*st2.ii());
487 class typeOfSum<SphericalTensor2D<Cmpt>, Tensor2D<Cmpt> >
491 typedef Tensor2D<Cmpt> type;
495 class typeOfSum<Tensor2D<Cmpt>, SphericalTensor2D<Cmpt> >
499 typedef Tensor2D<Cmpt> type;
504 class innerProduct<Tensor2D<Cmpt>, Tensor2D<Cmpt> >
508 typedef Tensor2D<Cmpt> type;
512 class innerProduct<SphericalTensor2D<Cmpt>, Tensor2D<Cmpt> >
516 typedef Tensor2D<Cmpt> type;
520 class innerProduct<Tensor2D<Cmpt>, SphericalTensor2D<Cmpt> >
524 typedef Tensor2D<Cmpt> type;
528 class innerProduct<Tensor2D<Cmpt>, Vector2D<Cmpt> >
532 typedef Vector2D<Cmpt> type;
536 class innerProduct<Vector2D<Cmpt>, Tensor2D<Cmpt> >
540 typedef Vector2D<Cmpt> type;
544 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
546 } // End namespace Foam
548 // ************************************************************************* //