1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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 \*---------------------------------------------------------------------------*/
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36 inline SymmTensor<Cmpt>::SymmTensor()
41 inline SymmTensor<Cmpt>::SymmTensor
43 const VectorSpace<SymmTensor<Cmpt>, Cmpt, 6>& vs
46 VectorSpace<SymmTensor<Cmpt>, Cmpt, 6>(vs)
51 inline SymmTensor<Cmpt>::SymmTensor(const SphericalTensor<Cmpt>& st)
53 this->v_[XX] = st.ii(); this->v_[XY] = 0; this->v_[XZ] = 0;
54 this->v_[YY] = st.ii(); this->v_[YZ] = 0;
55 this->v_[ZZ] = st.ii();
60 inline SymmTensor<Cmpt>::SymmTensor
62 const Cmpt txx, const Cmpt txy, const Cmpt txz,
63 const Cmpt tyy, const Cmpt tyz,
67 this->v_[XX] = txx; this->v_[XY] = txy; this->v_[XZ] = txz;
68 this->v_[YY] = tyy; this->v_[YZ] = tyz;
74 inline SymmTensor<Cmpt>::SymmTensor(Istream& is)
76 VectorSpace<SymmTensor<Cmpt>, Cmpt, 6>(is)
80 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
83 inline const Cmpt& SymmTensor<Cmpt>::xx() const
89 inline const Cmpt& SymmTensor<Cmpt>::xy() const
95 inline const Cmpt& SymmTensor<Cmpt>::xz() const
100 template <class Cmpt>
101 inline const Cmpt& SymmTensor<Cmpt>::yy() const
106 template <class Cmpt>
107 inline const Cmpt& SymmTensor<Cmpt>::yz() const
112 template <class Cmpt>
113 inline const Cmpt& SymmTensor<Cmpt>::zz() const
119 template <class Cmpt>
120 inline Cmpt& SymmTensor<Cmpt>::xx()
125 template <class Cmpt>
126 inline Cmpt& SymmTensor<Cmpt>::xy()
131 template <class Cmpt>
132 inline Cmpt& SymmTensor<Cmpt>::xz()
137 template <class Cmpt>
138 inline Cmpt& SymmTensor<Cmpt>::yy()
143 template <class Cmpt>
144 inline Cmpt& SymmTensor<Cmpt>::yz()
149 template <class Cmpt>
150 inline Cmpt& SymmTensor<Cmpt>::zz()
156 template <class Cmpt>
157 inline const SymmTensor<Cmpt>& SymmTensor<Cmpt>::T() const
163 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
165 template <class Cmpt>
166 inline void SymmTensor<Cmpt>::operator=(const SphericalTensor<Cmpt>& st)
168 this->v_[XX] = st.ii(); this->v_[XY] = 0; this->v_[XZ] = 0;
169 this->v_[YY] = st.ii(); this->v_[YZ] = 0;
170 this->v_[ZZ] = st.ii();
175 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
177 //- Hodge Dual operator (tensor -> vector)
178 template <class Cmpt>
179 inline Vector<Cmpt> operator*(const SymmTensor<Cmpt>& st)
181 return Vector<Cmpt>(st.yz(), -st.xz(), st.xy());
185 //- Inner-product between two symmetric tensors
186 template <class Cmpt>
187 inline SymmTensor<Cmpt>
188 operator&(const SymmTensor<Cmpt>& st1, const SymmTensor<Cmpt>& st2)
190 return SymmTensor<Cmpt>
192 st1.xx()*st2.xx() + st1.xy()*st2.xy() + st1.xz()*st2.xz(),
193 st1.xx()*st2.xy() + st1.xy()*st2.yy() + st1.xz()*st2.yz(),
194 st1.xx()*st2.xz() + st1.xy()*st2.yz() + st1.xz()*st2.zz(),
196 st1.xy()*st2.xy() + st1.yy()*st2.yy() + st1.yz()*st2.yz(),
197 st1.xy()*st2.xz() + st1.yy()*st2.yz() + st1.yz()*st2.zz(),
199 st1.xz()*st2.xz() + st1.yz()*st2.yz() + st1.zz()*st2.zz()
204 //- Double-dot-product between a symmetric tensor and a symmetric tensor
205 template <class Cmpt>
207 operator&&(const SymmTensor<Cmpt>& st1, const SymmTensor<Cmpt>& st2)
211 st1.xx()*st2.xx() + 2*st1.xy()*st2.xy() + 2*st1.xz()*st2.xz()
212 + st1.yy()*st2.yy() + 2*st1.yz()*st2.yz()
218 //- Inner-product between a symmetric tensor and a vector
219 template <class Cmpt>
221 operator&(const SymmTensor<Cmpt>& st, const Vector<Cmpt>& v)
225 st.xx()*v.x() + st.xy()*v.y() + st.xz()*v.z(),
226 st.xy()*v.x() + st.yy()*v.y() + st.yz()*v.z(),
227 st.xz()*v.x() + st.yz()*v.y() + st.zz()*v.z()
232 //- Inner-product between a vector and a symmetric tensor
233 template <class Cmpt>
235 operator&(const Vector<Cmpt>& v, const SymmTensor<Cmpt>& st)
239 v.x()*st.xx() + v.y()*st.xy() + v.z()*st.xz(),
240 v.x()*st.xy() + v.y()*st.yy() + v.z()*st.yz(),
241 v.x()*st.xz() + v.y()*st.yz() + v.z()*st.zz()
246 template <class Cmpt>
247 inline Cmpt magSqr(const SymmTensor<Cmpt>& st)
251 magSqr(st.xx()) + 2*magSqr(st.xy()) + 2*magSqr(st.xz())
252 + magSqr(st.yy()) + 2*magSqr(st.yz())
258 //- Return the trace of a symmetric tensor
259 template <class Cmpt>
260 inline Cmpt tr(const SymmTensor<Cmpt>& st)
262 return st.xx() + st.yy() + st.zz();
266 //- Return the spherical part of a symmetric tensor
267 template <class Cmpt>
268 inline SphericalTensor<Cmpt> sph(const SymmTensor<Cmpt>& st)
270 return (1.0/3.0)*tr(st);
274 //- Return the symmetric part of a symmetric tensor, i.e. itself
275 template <class Cmpt>
276 inline const SymmTensor<Cmpt>& symm(const SymmTensor<Cmpt>& st)
282 //- Return twice the symmetric part of a symmetric tensor
283 template <class Cmpt>
284 inline SymmTensor<Cmpt> twoSymm(const SymmTensor<Cmpt>& st)
290 //- Return the deviatoric part of a symmetric tensor
291 template <class Cmpt>
292 inline SymmTensor<Cmpt> dev(const SymmTensor<Cmpt>& st)
294 return st - SphericalTensor<Cmpt>::oneThirdI*tr(st);
298 //- Return the deviatoric part of a symmetric tensor
299 template <class Cmpt>
300 inline SymmTensor<Cmpt> dev2(const SymmTensor<Cmpt>& st)
302 return st - SphericalTensor<Cmpt>::twoThirdsI*tr(st);
306 //- Return the determinant of a symmetric tensor
307 template <class Cmpt>
308 inline Cmpt det(const SymmTensor<Cmpt>& st)
312 st.xx()*st.yy()*st.zz() + st.xy()*st.yz()*st.xz()
313 + st.xz()*st.xy()*st.yz() - st.xx()*st.yz()*st.yz()
314 - st.xy()*st.xy()*st.zz() - st.xz()*st.yy()*st.xz()
319 //- Return the cofactor symmetric tensor of a symmetric tensor
320 template <class Cmpt>
321 inline SymmTensor<Cmpt> cof(const SymmTensor<Cmpt>& st)
323 return SymmTensor<Cmpt>
325 st.yy()*st.zz() - st.yz()*st.yz(),
326 st.xz()*st.yz() - st.xy()*st.zz(),
327 st.xy()*st.yz() - st.xz()*st.yy(),
329 st.xx()*st.zz() - st.xz()*st.xz(),
330 st.xy()*st.xz() - st.xx()*st.yz(),
332 st.xx()*st.yy() - st.xy()*st.xy()
337 //- Return the inverse of a symmetric tensor give the determinant
338 template <class Cmpt>
339 inline SymmTensor<Cmpt> inv(const SymmTensor<Cmpt>& st, const Cmpt detst)
341 return SymmTensor<Cmpt>
343 st.yy()*st.zz() - st.yz()*st.yz(),
344 st.xz()*st.yz() - st.xy()*st.zz(),
345 st.xy()*st.yz() - st.xz()*st.yy(),
347 st.xx()*st.zz() - st.xz()*st.xz(),
348 st.xy()*st.xz() - st.xx()*st.yz(),
350 st.xx()*st.yy() - st.xy()*st.xy()
355 //- Return the inverse of a symmetric tensor
356 template <class Cmpt>
357 inline SymmTensor<Cmpt> inv(const SymmTensor<Cmpt>& st)
359 return inv(st, det(st));
363 //- Return the 1st invariant of a symmetric tensor
364 template <class Cmpt>
365 inline Cmpt invariantI(const SymmTensor<Cmpt>& st)
371 //- Return the 2nd invariant of a symmetric tensor
372 template <class Cmpt>
373 inline Cmpt invariantII(const SymmTensor<Cmpt>& st)
380 st.xx()*st.xx() + st.xy()*st.xy() + st.xz()*st.xz()
381 + st.xy()*st.xy() + st.yy()*st.yy() + st.yz()*st.yz()
382 + st.xz()*st.xz() + st.yz()*st.yz() + st.zz()*st.zz()
388 //- Return the 3rd invariant of a symmetric tensor
389 template <class Cmpt>
390 inline Cmpt invariantIII(const SymmTensor<Cmpt>& st)
396 template <class Cmpt>
397 inline SymmTensor<Cmpt>
398 operator+(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
400 return SymmTensor<Cmpt>
402 spt1.ii() + st2.xx(), st2.xy(), st2.xz(),
403 spt1.ii() + st2.yy(), st2.yz(),
409 template <class Cmpt>
410 inline SymmTensor<Cmpt>
411 operator+(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2)
413 return SymmTensor<Cmpt>
415 st1.xx() + spt2.ii(), st1.xy(), st1.xz(),
416 st1.yy() + spt2.ii(), st1.yz(),
422 template <class Cmpt>
423 inline SymmTensor<Cmpt>
424 operator-(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
426 return SymmTensor<Cmpt>
428 spt1.ii() - st2.xx(), -st2.xy(), -st2.xz(),
429 spt1.ii() - st2.yy(), -st2.yz(),
435 template <class Cmpt>
436 inline SymmTensor<Cmpt>
437 operator-(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2)
439 return SymmTensor<Cmpt>
441 st1.xx() - spt2.ii(), st1.xy(), st1.xz(),
442 st1.yy() - spt2.ii(), st1.yz(),
448 //- Inner-product between a spherical symmetric tensor and a symmetric tensor
449 template <class Cmpt>
450 inline SymmTensor<Cmpt>
451 operator&(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
453 return SymmTensor<Cmpt>
455 spt1.ii()*st2.xx(), spt1.ii()*st2.xy(), spt1.ii()*st2.xz(),
456 spt1.ii()*st2.yy(), spt1.ii()*st2.yz(),
462 //- Inner-product between a tensor and a spherical tensor
463 template <class Cmpt>
464 inline SymmTensor<Cmpt>
465 operator&(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2)
467 return SymmTensor<Cmpt>
469 st1.xx()*spt2.ii(), st1.xy()*spt2.ii(), st1.xz()*spt2.ii(),
470 st1.yy()*spt2.ii(), st1.yz()*spt2.ii(),
476 //- Double-dot-product between a spherical tensor and a symmetric tensor
477 template <class Cmpt>
479 operator&&(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
481 return(spt1.ii()*st2.xx() + spt1.ii()*st2.yy() + spt1.ii()*st2.zz());
485 //- Double-dot-product between a tensor and a spherical tensor
486 template <class Cmpt>
488 operator&&(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2)
490 return(st1.xx()*spt2.ii() + st1.yy()*spt2.ii() + st1.zz()*spt2.ii());
494 template <class Cmpt>
495 inline SymmTensor<Cmpt> sqr(const Vector<Cmpt>& v)
497 return SymmTensor<Cmpt>
499 v.x()*v.x(), v.x()*v.y(), v.x()*v.z(),
500 v.y()*v.y(), v.y()*v.z(),
507 class outerProduct<SymmTensor<Cmpt>, Cmpt>
511 typedef SymmTensor<Cmpt> type;
515 class outerProduct<Cmpt, SymmTensor<Cmpt> >
519 typedef SymmTensor<Cmpt> type;
523 class innerProduct<SymmTensor<Cmpt>, SymmTensor<Cmpt> >
527 typedef SymmTensor<Cmpt> type;
531 class innerProduct<SymmTensor<Cmpt>, Vector<Cmpt> >
535 typedef Vector<Cmpt> type;
539 class innerProduct<Vector<Cmpt>, SymmTensor<Cmpt> >
543 typedef Vector<Cmpt> type;
548 class typeOfSum<SphericalTensor<Cmpt>, SymmTensor<Cmpt> >
552 typedef SymmTensor<Cmpt> type;
556 class typeOfSum<SymmTensor<Cmpt>, SphericalTensor<Cmpt> >
560 typedef SymmTensor<Cmpt> type;
564 class innerProduct<SphericalTensor<Cmpt>, SymmTensor<Cmpt> >
568 typedef SymmTensor<Cmpt> type;
572 class innerProduct<SymmTensor<Cmpt>, SphericalTensor<Cmpt> >
576 typedef SymmTensor<Cmpt> type;
580 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
582 } // End namespace Foam
584 // ************************************************************************* //