OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

SymmTensorI.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "Vector.H"
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033 
00034 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00035 
00036 template <class Cmpt>
00037 inline SymmTensor<Cmpt>::SymmTensor()
00038 {}
00039 
00040 
00041 template <class Cmpt>
00042 inline SymmTensor<Cmpt>::SymmTensor
00043 (
00044     const VectorSpace<SymmTensor<Cmpt>, Cmpt, 6>& vs
00045 )
00046 :
00047     VectorSpace<SymmTensor<Cmpt>, Cmpt, 6>(vs)
00048 {}
00049 
00050 
00051 template <class Cmpt>
00052 inline SymmTensor<Cmpt>::SymmTensor(const SphericalTensor<Cmpt>& st)
00053 {
00054     this->v_[XX] = st.ii(); this->v_[XY] = 0;       this->v_[XZ] = 0;
00055                             this->v_[YY] = st.ii(); this->v_[YZ] = 0;
00056                                                     this->v_[ZZ] = st.ii();
00057 }
00058 
00059 
00060 template <class Cmpt>
00061 inline SymmTensor<Cmpt>::SymmTensor
00062 (
00063     const Cmpt txx, const Cmpt txy, const Cmpt txz,
00064                     const Cmpt tyy, const Cmpt tyz,
00065                                     const Cmpt tzz
00066 )
00067 {
00068     this->v_[XX] = txx; this->v_[XY] = txy; this->v_[XZ] = txz;
00069                         this->v_[YY] = tyy; this->v_[YZ] = tyz;
00070                                             this->v_[ZZ] = tzz;
00071 }
00072 
00073 
00074 template <class Cmpt>
00075 inline SymmTensor<Cmpt>::SymmTensor(Istream& is)
00076 :
00077     VectorSpace<SymmTensor<Cmpt>, Cmpt, 6>(is)
00078 {}
00079 
00080 
00081 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00082 
00083 template <class Cmpt>
00084 inline const Cmpt&  SymmTensor<Cmpt>::xx() const
00085 {
00086     return this->v_[XX];
00087 }
00088 
00089 template <class Cmpt>
00090 inline const Cmpt&  SymmTensor<Cmpt>::xy() const
00091 {
00092     return this->v_[XY];
00093 }
00094 
00095 template <class Cmpt>
00096 inline const Cmpt&  SymmTensor<Cmpt>::xz() const
00097 {
00098     return this->v_[XZ];
00099 }
00100 
00101 template <class Cmpt>
00102 inline const Cmpt&  SymmTensor<Cmpt>::yy() const
00103 {
00104     return this->v_[YY];
00105 }
00106 
00107 template <class Cmpt>
00108 inline const Cmpt&  SymmTensor<Cmpt>::yz() const
00109 {
00110     return this->v_[YZ];
00111 }
00112 
00113 template <class Cmpt>
00114 inline const Cmpt&  SymmTensor<Cmpt>::zz() const
00115 {
00116     return this->v_[ZZ];
00117 }
00118 
00119 
00120 template <class Cmpt>
00121 inline Cmpt& SymmTensor<Cmpt>::xx()
00122 {
00123     return this->v_[XX];
00124 }
00125 
00126 template <class Cmpt>
00127 inline Cmpt& SymmTensor<Cmpt>::xy()
00128 {
00129     return this->v_[XY];
00130 }
00131 
00132 template <class Cmpt>
00133 inline Cmpt& SymmTensor<Cmpt>::xz()
00134 {
00135     return this->v_[XZ];
00136 }
00137 
00138 template <class Cmpt>
00139 inline Cmpt& SymmTensor<Cmpt>::yy()
00140 {
00141     return this->v_[YY];
00142 }
00143 
00144 template <class Cmpt>
00145 inline Cmpt& SymmTensor<Cmpt>::yz()
00146 {
00147     return this->v_[YZ];
00148 }
00149 
00150 template <class Cmpt>
00151 inline Cmpt& SymmTensor<Cmpt>::zz()
00152 {
00153     return this->v_[ZZ];
00154 }
00155 
00156 
00157 template <class Cmpt>
00158 inline const SymmTensor<Cmpt>& SymmTensor<Cmpt>::T() const
00159 {
00160     return *this;
00161 }
00162 
00163 
00164 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00165 
00166 template <class Cmpt>
00167 inline void SymmTensor<Cmpt>::operator=(const SphericalTensor<Cmpt>& st)
00168 {
00169     this->v_[XX] = st.ii(); this->v_[XY] = 0;       this->v_[XZ] = 0;
00170                             this->v_[YY] = st.ii(); this->v_[YZ] = 0;
00171                                                     this->v_[ZZ] = st.ii();
00172 }
00173 
00174 
00175 
00176 // * * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * //
00177 
00178 //- Hodge Dual operator (tensor -> vector)
00179 template <class Cmpt>
00180 inline Vector<Cmpt> operator*(const SymmTensor<Cmpt>& st)
00181 {
00182     return Vector<Cmpt>(st.yz(), -st.xz(), st.xy());
00183 }
00184 
00185 
00186 //- Inner-product between two symmetric tensors
00187 template <class Cmpt>
00188 inline SymmTensor<Cmpt>
00189 operator&(const SymmTensor<Cmpt>& st1, const SymmTensor<Cmpt>& st2)
00190 {
00191     return SymmTensor<Cmpt>
00192     (
00193         st1.xx()*st2.xx() + st1.xy()*st2.xy() + st1.xz()*st2.xz(),
00194         st1.xx()*st2.xy() + st1.xy()*st2.yy() + st1.xz()*st2.yz(),
00195         st1.xx()*st2.xz() + st1.xy()*st2.yz() + st1.xz()*st2.zz(),
00196 
00197         st1.xy()*st2.xy() + st1.yy()*st2.yy() + st1.yz()*st2.yz(),
00198         st1.xy()*st2.xz() + st1.yy()*st2.yz() + st1.yz()*st2.zz(),
00199 
00200         st1.xz()*st2.xz() + st1.yz()*st2.yz() + st1.zz()*st2.zz()
00201     );
00202 }
00203 
00204 
00205 //- Double-dot-product between a symmetric tensor and a symmetric tensor
00206 template <class Cmpt>
00207 inline Cmpt
00208 operator&&(const SymmTensor<Cmpt>& st1, const SymmTensor<Cmpt>& st2)
00209 {
00210     return
00211     (
00212         st1.xx()*st2.xx() + 2*st1.xy()*st2.xy() + 2*st1.xz()*st2.xz()
00213                           +   st1.yy()*st2.yy() + 2*st1.yz()*st2.yz()
00214                                                 +   st1.zz()*st2.zz()
00215     );
00216 }
00217 
00218 
00219 //- Inner-product between a symmetric tensor and a vector
00220 template <class Cmpt>
00221 inline Vector<Cmpt>
00222 operator&(const SymmTensor<Cmpt>& st, const Vector<Cmpt>& v)
00223 {
00224     return Vector<Cmpt>
00225     (
00226         st.xx()*v.x() + st.xy()*v.y() + st.xz()*v.z(),
00227         st.xy()*v.x() + st.yy()*v.y() + st.yz()*v.z(),
00228         st.xz()*v.x() + st.yz()*v.y() + st.zz()*v.z()
00229     );
00230 }
00231 
00232 
00233 //- Inner-product between a vector and a symmetric tensor
00234 template <class Cmpt>
00235 inline Vector<Cmpt>
00236 operator&(const Vector<Cmpt>& v, const SymmTensor<Cmpt>& st)
00237 {
00238     return Vector<Cmpt>
00239     (
00240         v.x()*st.xx() + v.y()*st.xy() + v.z()*st.xz(),
00241         v.x()*st.xy() + v.y()*st.yy() + v.z()*st.yz(),
00242         v.x()*st.xz() + v.y()*st.yz() + v.z()*st.zz()
00243     );
00244 }
00245 
00246 
00247 template <class Cmpt>
00248 inline Cmpt magSqr(const SymmTensor<Cmpt>& st)
00249 {
00250     return
00251     (
00252         magSqr(st.xx()) + 2*magSqr(st.xy()) + 2*magSqr(st.xz())
00253                         +   magSqr(st.yy()) + 2*magSqr(st.yz())
00254                                             +   magSqr(st.zz())
00255     );
00256 }
00257 
00258 
00259 //- Return the trace of a symmetric tensor
00260 template <class Cmpt>
00261 inline Cmpt tr(const SymmTensor<Cmpt>& st)
00262 {
00263     return st.xx() + st.yy() + st.zz();
00264 }
00265 
00266 
00267 //- Return the spherical part of a symmetric tensor
00268 template <class Cmpt>
00269 inline SphericalTensor<Cmpt> sph(const SymmTensor<Cmpt>& st)
00270 {
00271     return (1.0/3.0)*tr(st);
00272 }
00273 
00274 
00275 //- Return the symmetric part of a symmetric tensor, i.e. itself
00276 template <class Cmpt>
00277 inline const SymmTensor<Cmpt>& symm(const SymmTensor<Cmpt>& st)
00278 {
00279     return st;
00280 }
00281 
00282 
00283 //- Return twice the symmetric part of a symmetric tensor
00284 template <class Cmpt>
00285 inline SymmTensor<Cmpt> twoSymm(const SymmTensor<Cmpt>& st)
00286 {
00287     return 2*st;
00288 }
00289 
00290 
00291 //- Return the deviatoric part of a symmetric tensor
00292 template <class Cmpt>
00293 inline SymmTensor<Cmpt> dev(const SymmTensor<Cmpt>& st)
00294 {
00295     return st - SphericalTensor<Cmpt>::oneThirdI*tr(st);
00296 }
00297 
00298 
00299 //- Return the deviatoric part of a symmetric tensor
00300 template <class Cmpt>
00301 inline SymmTensor<Cmpt> dev2(const SymmTensor<Cmpt>& st)
00302 {
00303     return st - SphericalTensor<Cmpt>::twoThirdsI*tr(st);
00304 }
00305 
00306 
00307 //- Return the determinant of a symmetric tensor
00308 template <class Cmpt>
00309 inline Cmpt det(const SymmTensor<Cmpt>& st)
00310 {
00311     return
00312     (
00313         st.xx()*st.yy()*st.zz() + st.xy()*st.yz()*st.xz()
00314       + st.xz()*st.xy()*st.yz() - st.xx()*st.yz()*st.yz()
00315       - st.xy()*st.xy()*st.zz() - st.xz()*st.yy()*st.xz()
00316     );
00317 }
00318 
00319 
00320 //- Return the cofactor symmetric tensor of a symmetric tensor
00321 template <class Cmpt>
00322 inline SymmTensor<Cmpt> cof(const SymmTensor<Cmpt>& st)
00323 {
00324     return SymmTensor<Cmpt>
00325     (
00326         st.yy()*st.zz() - st.yz()*st.yz(),
00327         st.xz()*st.yz() - st.xy()*st.zz(),
00328         st.xy()*st.yz() - st.xz()*st.yy(),
00329 
00330         st.xx()*st.zz() - st.xz()*st.xz(),
00331         st.xy()*st.xz() - st.xx()*st.yz(),
00332 
00333         st.xx()*st.yy() - st.xy()*st.xy()
00334     );
00335 }
00336 
00337 
00338 //- Return the inverse of a symmetric tensor give the determinant
00339 template <class Cmpt>
00340 inline SymmTensor<Cmpt> inv(const SymmTensor<Cmpt>& st, const Cmpt detst)
00341 {
00342     return SymmTensor<Cmpt>
00343     (
00344         st.yy()*st.zz() - st.yz()*st.yz(),
00345         st.xz()*st.yz() - st.xy()*st.zz(),
00346         st.xy()*st.yz() - st.xz()*st.yy(),
00347 
00348         st.xx()*st.zz() - st.xz()*st.xz(),
00349         st.xy()*st.xz() - st.xx()*st.yz(),
00350 
00351         st.xx()*st.yy() - st.xy()*st.xy()
00352     )/detst;
00353 }
00354 
00355 
00356 //- Return the inverse of a symmetric tensor
00357 template <class Cmpt>
00358 inline SymmTensor<Cmpt> inv(const SymmTensor<Cmpt>& st)
00359 {
00360     return inv(st, det(st));
00361 }
00362 
00363 
00364 //- Return the 1st invariant of a symmetric tensor
00365 template <class Cmpt>
00366 inline Cmpt invariantI(const SymmTensor<Cmpt>& st)
00367 {
00368     return tr(st);
00369 }
00370 
00371 
00372 //- Return the 2nd invariant of a symmetric tensor
00373 template <class Cmpt>
00374 inline Cmpt invariantII(const SymmTensor<Cmpt>& st)
00375 {
00376     return
00377     (
00378         0.5*sqr(tr(st))
00379       - 0.5*
00380         (
00381            st.xx()*st.xx() + st.xy()*st.xy() + st.xz()*st.xz()
00382          + st.xy()*st.xy() + st.yy()*st.yy() + st.yz()*st.yz()
00383          + st.xz()*st.xz() + st.yz()*st.yz() + st.zz()*st.zz()
00384         )
00385     );
00386 }
00387 
00388 
00389 //- Return the 3rd invariant of a symmetric tensor
00390 template <class Cmpt>
00391 inline Cmpt invariantIII(const SymmTensor<Cmpt>& st)
00392 {
00393     return det(st);
00394 }
00395 
00396 
00397 template <class Cmpt>
00398 inline SymmTensor<Cmpt>
00399 operator+(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
00400 {
00401     return SymmTensor<Cmpt>
00402     (
00403         spt1.ii() + st2.xx(), st2.xy(),             st2.xz(),
00404                               spt1.ii() + st2.yy(), st2.yz(),
00405                                                     spt1.ii() + st2.zz()
00406     );
00407 }
00408 
00409 
00410 template <class Cmpt>
00411 inline SymmTensor<Cmpt>
00412 operator+(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2)
00413 {
00414     return SymmTensor<Cmpt>
00415     (
00416         st1.xx() + spt2.ii(), st1.xy(),             st1.xz(),
00417                               st1.yy() + spt2.ii(), st1.yz(),
00418                                                     st1.zz() + spt2.ii()
00419     );
00420 }
00421 
00422 
00423 template <class Cmpt>
00424 inline SymmTensor<Cmpt>
00425 operator-(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
00426 {
00427     return SymmTensor<Cmpt>
00428     (
00429         spt1.ii() - st2.xx(), -st2.xy(),             -st2.xz(),
00430                                spt1.ii() - st2.yy(), -st2.yz(),
00431                                                       spt1.ii() - st2.zz()
00432     );
00433 }
00434 
00435 
00436 template <class Cmpt>
00437 inline SymmTensor<Cmpt>
00438 operator-(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2)
00439 {
00440     return SymmTensor<Cmpt>
00441     (
00442         st1.xx() - spt2.ii(), st1.xy(),             st1.xz(),
00443                               st1.yy() - spt2.ii(), st1.yz(),
00444                                                     st1.zz() - spt2.ii()
00445     );
00446 }
00447 
00448 
00449 //- Inner-product between a spherical symmetric tensor and a symmetric tensor
00450 template <class Cmpt>
00451 inline SymmTensor<Cmpt>
00452 operator&(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
00453 {
00454     return SymmTensor<Cmpt>
00455     (
00456         spt1.ii()*st2.xx(), spt1.ii()*st2.xy(), spt1.ii()*st2.xz(),
00457                             spt1.ii()*st2.yy(), spt1.ii()*st2.yz(),
00458                                                 spt1.ii()*st2.zz()
00459     );
00460 }
00461 
00462 
00463 //- Inner-product between a tensor and a spherical tensor
00464 template <class Cmpt>
00465 inline SymmTensor<Cmpt>
00466 operator&(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2)
00467 {
00468     return SymmTensor<Cmpt>
00469     (
00470         st1.xx()*spt2.ii(), st1.xy()*spt2.ii(), st1.xz()*spt2.ii(),
00471                             st1.yy()*spt2.ii(), st1.yz()*spt2.ii(),
00472                                                 st1.zz()*spt2.ii()
00473     );
00474 }
00475 
00476 
00477 //- Double-dot-product between a spherical tensor and a symmetric tensor
00478 template <class Cmpt>
00479 inline Cmpt
00480 operator&&(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
00481 {
00482     return(spt1.ii()*st2.xx() + spt1.ii()*st2.yy() + spt1.ii()*st2.zz());
00483 }
00484 
00485 
00486 //- Double-dot-product between a tensor and a spherical tensor
00487 template <class Cmpt>
00488 inline Cmpt
00489 operator&&(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2)
00490 {
00491     return(st1.xx()*spt2.ii() + st1.yy()*spt2.ii() + st1.zz()*spt2.ii());
00492 }
00493 
00494 
00495 template <class Cmpt>
00496 inline SymmTensor<Cmpt> sqr(const Vector<Cmpt>& v)
00497 {
00498     return SymmTensor<Cmpt>
00499     (
00500         v.x()*v.x(), v.x()*v.y(), v.x()*v.z(),
00501                      v.y()*v.y(), v.y()*v.z(),
00502                                   v.z()*v.z()
00503     );
00504 }
00505 
00506 
00507 template<class Cmpt>
00508 class outerProduct<SymmTensor<Cmpt>, Cmpt>
00509 {
00510 public:
00511 
00512     typedef SymmTensor<Cmpt> type;
00513 };
00514 
00515 template<class Cmpt>
00516 class outerProduct<Cmpt, SymmTensor<Cmpt> >
00517 {
00518 public:
00519 
00520     typedef SymmTensor<Cmpt> type;
00521 };
00522 
00523 template<class Cmpt>
00524 class innerProduct<SymmTensor<Cmpt>, SymmTensor<Cmpt> >
00525 {
00526 public:
00527 
00528     typedef SymmTensor<Cmpt> type;
00529 };
00530 
00531 template<class Cmpt>
00532 class innerProduct<SymmTensor<Cmpt>, Vector<Cmpt> >
00533 {
00534 public:
00535 
00536     typedef Vector<Cmpt> type;
00537 };
00538 
00539 template<class Cmpt>
00540 class innerProduct<Vector<Cmpt>, SymmTensor<Cmpt> >
00541 {
00542 public:
00543 
00544     typedef Vector<Cmpt> type;
00545 };
00546 
00547 
00548 template<class Cmpt>
00549 class typeOfSum<SphericalTensor<Cmpt>, SymmTensor<Cmpt> >
00550 {
00551 public:
00552 
00553     typedef SymmTensor<Cmpt> type;
00554 };
00555 
00556 template<class Cmpt>
00557 class typeOfSum<SymmTensor<Cmpt>, SphericalTensor<Cmpt> >
00558 {
00559 public:
00560 
00561     typedef SymmTensor<Cmpt> type;
00562 };
00563 
00564 template<class Cmpt>
00565 class innerProduct<SphericalTensor<Cmpt>, SymmTensor<Cmpt> >
00566 {
00567 public:
00568 
00569     typedef SymmTensor<Cmpt> type;
00570 };
00571 
00572 template<class Cmpt>
00573 class innerProduct<SymmTensor<Cmpt>, SphericalTensor<Cmpt> >
00574 {
00575 public:
00576 
00577     typedef SymmTensor<Cmpt> type;
00578 };
00579 
00580 
00581 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00582 
00583 } // End namespace Foam
00584 
00585 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd