1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 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
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 \*---------------------------------------------------------------------------*/
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 inline SymmTensor<Cmpt>::SymmTensor()
42 inline SymmTensor<Cmpt>::SymmTensor
44 const VectorSpace<SymmTensor<Cmpt>, Cmpt, 6>& vs
47 VectorSpace<SymmTensor<Cmpt>, Cmpt, 6>(vs)
52 inline SymmTensor<Cmpt>::SymmTensor(const SphericalTensor<Cmpt>& st)
54 this->v_[XX] = st.ii(); this->v_[XY] = 0; this->v_[XZ] = 0;
55 this->v_[YY] = st.ii(); this->v_[YZ] = 0;
56 this->v_[ZZ] = st.ii();
61 inline SymmTensor<Cmpt>::SymmTensor
63 const Cmpt txx, const Cmpt txy, const Cmpt txz,
64 const Cmpt tyy, const Cmpt tyz,
68 this->v_[XX] = txx; this->v_[XY] = txy; this->v_[XZ] = txz;
69 this->v_[YY] = tyy; this->v_[YZ] = tyz;
75 inline SymmTensor<Cmpt>::SymmTensor(Istream& is)
77 VectorSpace<SymmTensor<Cmpt>, Cmpt, 6>(is)
81 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
84 inline const Cmpt& SymmTensor<Cmpt>::xx() const
90 inline const Cmpt& SymmTensor<Cmpt>::xy() const
96 inline const Cmpt& SymmTensor<Cmpt>::xz() const
101 template <class Cmpt>
102 inline const Cmpt& SymmTensor<Cmpt>::yy() const
107 template <class Cmpt>
108 inline const Cmpt& SymmTensor<Cmpt>::yz() const
113 template <class Cmpt>
114 inline const Cmpt& SymmTensor<Cmpt>::zz() const
120 template <class Cmpt>
121 inline Cmpt& SymmTensor<Cmpt>::xx()
126 template <class Cmpt>
127 inline Cmpt& SymmTensor<Cmpt>::xy()
132 template <class Cmpt>
133 inline Cmpt& SymmTensor<Cmpt>::xz()
138 template <class Cmpt>
139 inline Cmpt& SymmTensor<Cmpt>::yy()
144 template <class Cmpt>
145 inline Cmpt& SymmTensor<Cmpt>::yz()
150 template <class Cmpt>
151 inline Cmpt& SymmTensor<Cmpt>::zz()
157 template <class Cmpt>
158 inline const SymmTensor<Cmpt>& SymmTensor<Cmpt>::T() const
164 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
166 template <class Cmpt>
167 inline void SymmTensor<Cmpt>::operator=(const SphericalTensor<Cmpt>& st)
169 this->v_[XX] = st.ii(); this->v_[XY] = 0; this->v_[XZ] = 0;
170 this->v_[YY] = st.ii(); this->v_[YZ] = 0;
171 this->v_[ZZ] = st.ii();
176 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
178 //- Hodge Dual operator (tensor -> vector)
179 template <class Cmpt>
180 inline Vector<Cmpt> operator*(const SymmTensor<Cmpt>& st)
182 return Vector<Cmpt>(st.yz(), -st.xz(), st.xy());
186 //- Inner-product between two symmetric tensors
187 template <class Cmpt>
188 inline SymmTensor<Cmpt>
189 operator&(const SymmTensor<Cmpt>& st1, const SymmTensor<Cmpt>& st2)
191 return SymmTensor<Cmpt>
193 st1.xx()*st2.xx() + st1.xy()*st2.xy() + st1.xz()*st2.xz(),
194 st1.xx()*st2.xy() + st1.xy()*st2.yy() + st1.xz()*st2.yz(),
195 st1.xx()*st2.xz() + st1.xy()*st2.yz() + st1.xz()*st2.zz(),
197 st1.xy()*st2.xy() + st1.yy()*st2.yy() + st1.yz()*st2.yz(),
198 st1.xy()*st2.xz() + st1.yy()*st2.yz() + st1.yz()*st2.zz(),
200 st1.xz()*st2.xz() + st1.yz()*st2.yz() + st1.zz()*st2.zz()
205 //- Double-dot-product between a symmetric tensor and a symmetric tensor
206 template <class Cmpt>
208 operator&&(const SymmTensor<Cmpt>& st1, const SymmTensor<Cmpt>& st2)
212 st1.xx()*st2.xx() + 2*st1.xy()*st2.xy() + 2*st1.xz()*st2.xz()
213 + st1.yy()*st2.yy() + 2*st1.yz()*st2.yz()
219 //- Inner-product between a symmetric tensor and a vector
220 template <class Cmpt>
222 operator&(const SymmTensor<Cmpt>& st, const Vector<Cmpt>& v)
226 st.xx()*v.x() + st.xy()*v.y() + st.xz()*v.z(),
227 st.xy()*v.x() + st.yy()*v.y() + st.yz()*v.z(),
228 st.xz()*v.x() + st.yz()*v.y() + st.zz()*v.z()
233 //- Inner-product between a vector and a symmetric tensor
234 template <class Cmpt>
236 operator&(const Vector<Cmpt>& v, const SymmTensor<Cmpt>& st)
240 v.x()*st.xx() + v.y()*st.xy() + v.z()*st.xz(),
241 v.x()*st.xy() + v.y()*st.yy() + v.z()*st.yz(),
242 v.x()*st.xz() + v.y()*st.yz() + v.z()*st.zz()
247 template <class Cmpt>
248 inline Cmpt magSqr(const SymmTensor<Cmpt>& st)
252 magSqr(st.xx()) + 2*magSqr(st.xy()) + 2*magSqr(st.xz())
253 + magSqr(st.yy()) + 2*magSqr(st.yz())
259 //- Return the trace of a symmetric tensor
260 template <class Cmpt>
261 inline Cmpt tr(const SymmTensor<Cmpt>& st)
263 return st.xx() + st.yy() + st.zz();
267 //- Return the spherical part of a symmetric tensor
268 template <class Cmpt>
269 inline SphericalTensor<Cmpt> sph(const SymmTensor<Cmpt>& st)
271 return (1.0/3.0)*tr(st);
275 //- Return the symmetric part of a symmetric tensor, i.e. itself
276 template <class Cmpt>
277 inline const SymmTensor<Cmpt>& symm(const SymmTensor<Cmpt>& st)
283 //- Return twice the symmetric part of a symmetric tensor
284 template <class Cmpt>
285 inline SymmTensor<Cmpt> twoSymm(const SymmTensor<Cmpt>& st)
291 //- Return the deviatoric part of a symmetric tensor
292 template <class Cmpt>
293 inline SymmTensor<Cmpt> dev(const SymmTensor<Cmpt>& st)
295 return st - SphericalTensor<Cmpt>::oneThirdI*tr(st);
299 //- Return the deviatoric part of a symmetric tensor
300 template <class Cmpt>
301 inline SymmTensor<Cmpt> dev2(const SymmTensor<Cmpt>& st)
303 return st - SphericalTensor<Cmpt>::twoThirdsI*tr(st);
307 //- Return the determinant of a symmetric tensor
308 template <class Cmpt>
309 inline Cmpt det(const SymmTensor<Cmpt>& st)
313 st.xx()*st.yy()*st.zz() + st.xy()*st.yz()*st.xz()
314 + st.xz()*st.xy()*st.yz() - st.xx()*st.yz()*st.yz()
315 - st.xy()*st.xy()*st.zz() - st.xz()*st.yy()*st.xz()
320 //- Return the cofactor symmetric tensor of a symmetric tensor
321 template <class Cmpt>
322 inline SymmTensor<Cmpt> cof(const SymmTensor<Cmpt>& st)
324 return SymmTensor<Cmpt>
326 st.yy()*st.zz() - st.yz()*st.yz(),
327 st.xz()*st.yz() - st.xy()*st.zz(),
328 st.xy()*st.yz() - st.xz()*st.yy(),
330 st.xx()*st.zz() - st.xz()*st.xz(),
331 st.xy()*st.xz() - st.xx()*st.yz(),
333 st.xx()*st.yy() - st.xy()*st.xy()
338 //- Return the inverse of a symmetric tensor give the determinant
339 template <class Cmpt>
340 inline SymmTensor<Cmpt> inv(const SymmTensor<Cmpt>& st, const Cmpt detst)
342 return SymmTensor<Cmpt>
344 st.yy()*st.zz() - st.yz()*st.yz(),
345 st.xz()*st.yz() - st.xy()*st.zz(),
346 st.xy()*st.yz() - st.xz()*st.yy(),
348 st.xx()*st.zz() - st.xz()*st.xz(),
349 st.xy()*st.xz() - st.xx()*st.yz(),
351 st.xx()*st.yy() - st.xy()*st.xy()
356 //- Return the inverse of a symmetric tensor
357 template <class Cmpt>
358 inline SymmTensor<Cmpt> inv(const SymmTensor<Cmpt>& st)
360 return inv(st, det(st));
364 //- Return the 1st invariant of a symmetric tensor
365 template <class Cmpt>
366 inline Cmpt invariantI(const SymmTensor<Cmpt>& st)
372 //- Return the 2nd invariant of a symmetric tensor
373 template <class Cmpt>
374 inline Cmpt invariantII(const SymmTensor<Cmpt>& st)
381 st.xx()*st.xx() + st.xy()*st.xy() + st.xz()*st.xz()
382 + st.xy()*st.xy() + st.yy()*st.yy() + st.yz()*st.yz()
383 + st.xz()*st.xz() + st.yz()*st.yz() + st.zz()*st.zz()
389 //- Return the 3rd invariant of a symmetric tensor
390 template <class Cmpt>
391 inline Cmpt invariantIII(const SymmTensor<Cmpt>& st)
397 template <class Cmpt>
398 inline SymmTensor<Cmpt>
399 operator+(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
401 return SymmTensor<Cmpt>
403 spt1.ii() + st2.xx(), st2.xy(), st2.xz(),
404 spt1.ii() + st2.yy(), st2.yz(),
410 template <class Cmpt>
411 inline SymmTensor<Cmpt>
412 operator+(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2)
414 return SymmTensor<Cmpt>
416 st1.xx() + spt2.ii(), st1.xy(), st1.xz(),
417 st1.yy() + spt2.ii(), st1.yz(),
423 template <class Cmpt>
424 inline SymmTensor<Cmpt>
425 operator-(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
427 return SymmTensor<Cmpt>
429 spt1.ii() - st2.xx(), -st2.xy(), -st2.xz(),
430 spt1.ii() - st2.yy(), -st2.yz(),
436 template <class Cmpt>
437 inline SymmTensor<Cmpt>
438 operator-(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2)
440 return SymmTensor<Cmpt>
442 st1.xx() - spt2.ii(), st1.xy(), st1.xz(),
443 st1.yy() - spt2.ii(), st1.yz(),
449 //- Inner-product between a spherical symmetric tensor and a symmetric tensor
450 template <class Cmpt>
451 inline SymmTensor<Cmpt>
452 operator&(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
454 return SymmTensor<Cmpt>
468 //- Inner-product between a tensor and a spherical tensor
469 template <class Cmpt>
470 inline SymmTensor<Cmpt>
471 operator&(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2)
473 return SymmTensor<Cmpt>
487 //- Double-dot-product between a spherical tensor and a symmetric tensor
488 template <class Cmpt>
490 operator&&(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
492 return(spt1.ii()*st2.xx() + spt1.ii()*st2.yy() + spt1.ii()*st2.zz());
496 //- Double-dot-product between a tensor and a spherical tensor
497 template <class Cmpt>
499 operator&&(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2)
501 return(st1.xx()*spt2.ii() + st1.yy()*spt2.ii() + st1.zz()*spt2.ii());
505 template <class Cmpt>
506 inline SymmTensor<Cmpt> sqr(const Vector<Cmpt>& v)
508 return SymmTensor<Cmpt>
510 v.x()*v.x(), v.x()*v.y(), v.x()*v.z(),
511 v.y()*v.y(), v.y()*v.z(),
518 class outerProduct<SymmTensor<Cmpt>, Cmpt>
522 typedef SymmTensor<Cmpt> type;
526 class outerProduct<Cmpt, SymmTensor<Cmpt> >
530 typedef SymmTensor<Cmpt> type;
534 class innerProduct<SymmTensor<Cmpt>, SymmTensor<Cmpt> >
538 typedef SymmTensor<Cmpt> type;
542 class innerProduct<SymmTensor<Cmpt>, Vector<Cmpt> >
546 typedef Vector<Cmpt> type;
550 class innerProduct<Vector<Cmpt>, SymmTensor<Cmpt> >
554 typedef Vector<Cmpt> type;
559 class typeOfSum<SphericalTensor<Cmpt>, SymmTensor<Cmpt> >
563 typedef SymmTensor<Cmpt> type;
567 class typeOfSum<SymmTensor<Cmpt>, SphericalTensor<Cmpt> >
571 typedef SymmTensor<Cmpt> type;
575 class innerProduct<SphericalTensor<Cmpt>, SymmTensor<Cmpt> >
579 typedef SymmTensor<Cmpt> type;
583 class innerProduct<SymmTensor<Cmpt>, SphericalTensor<Cmpt> >
587 typedef SymmTensor<Cmpt> type;
591 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
593 } // End namespace Foam
595 // ************************************************************************* //