FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include <OpenFOAM/Vector_.H>
00027 #include <OpenFOAM/Tensor_.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 Tensor<Cmpt>
00189 operator&(const SymmTensor<Cmpt>& st1, const SymmTensor<Cmpt>& st2)
00190 {
00191     return Tensor<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.xx() + st1.yy()*st2.xy() + st1.yz()*st2.xz(),
00198         st1.xy()*st2.xy() + st1.yy()*st2.yy() + st1.yz()*st2.yz(),
00199         st1.xy()*st2.xz() + st1.yy()*st2.yz() + st1.yz()*st2.zz(),
00200 
00201         st1.xz()*st2.xx() + st1.yz()*st2.xy() + st1.zz()*st2.xz(),
00202         st1.xz()*st2.xy() + st1.yz()*st2.yy() + st1.zz()*st2.yz(),
00203         st1.xz()*st2.xz() + st1.yz()*st2.yz() + st1.zz()*st2.zz()
00204     );
00205 }
00206 
00207 
00208 //- Double-dot-product between a symmetric tensor and a symmetric tensor
00209 template <class Cmpt>
00210 inline Cmpt
00211 operator&&(const SymmTensor<Cmpt>& st1, const SymmTensor<Cmpt>& st2)
00212 {
00213     return
00214     (
00215         st1.xx()*st2.xx() + 2*st1.xy()*st2.xy() + 2*st1.xz()*st2.xz()
00216                           +   st1.yy()*st2.yy() + 2*st1.yz()*st2.yz()
00217                                                 +   st1.zz()*st2.zz()
00218     );
00219 }
00220 
00221 
00222 //- Inner-product between a symmetric tensor and a vector
00223 template <class Cmpt>
00224 inline Vector<Cmpt>
00225 operator&(const SymmTensor<Cmpt>& st, const Vector<Cmpt>& v)
00226 {
00227     return Vector<Cmpt>
00228     (
00229         st.xx()*v.x() + st.xy()*v.y() + st.xz()*v.z(),
00230         st.xy()*v.x() + st.yy()*v.y() + st.yz()*v.z(),
00231         st.xz()*v.x() + st.yz()*v.y() + st.zz()*v.z()
00232     );
00233 }
00234 
00235 
00236 //- Inner-product between a vector and a symmetric tensor
00237 template <class Cmpt>
00238 inline Vector<Cmpt>
00239 operator&(const Vector<Cmpt>& v, const SymmTensor<Cmpt>& st)
00240 {
00241     return Vector<Cmpt>
00242     (
00243         v.x()*st.xx() + v.y()*st.xy() + v.z()*st.xz(),
00244         v.x()*st.xy() + v.y()*st.yy() + v.z()*st.yz(),
00245         v.x()*st.xz() + v.y()*st.yz() + v.z()*st.zz()
00246     );
00247 }
00248 
00249 
00250 template <class Cmpt>
00251 inline Cmpt magSqr(const SymmTensor<Cmpt>& st)
00252 {
00253     return
00254     (
00255         magSqr(st.xx()) + 2*magSqr(st.xy()) + 2*magSqr(st.xz())
00256                         +   magSqr(st.yy()) + 2*magSqr(st.yz())
00257                                             +   magSqr(st.zz())
00258     );
00259 }
00260 
00261 
00262 //- Return the trace of a symmetric tensor
00263 template <class Cmpt>
00264 inline Cmpt tr(const SymmTensor<Cmpt>& st)
00265 {
00266     return st.xx() + st.yy() + st.zz();
00267 }
00268 
00269 
00270 //- Return the spherical part of a symmetric tensor
00271 template <class Cmpt>
00272 inline SphericalTensor<Cmpt> sph(const SymmTensor<Cmpt>& st)
00273 {
00274     return (1.0/3.0)*tr(st);
00275 }
00276 
00277 
00278 //- Return the symmetric part of a symmetric tensor, i.e. itself
00279 template <class Cmpt>
00280 inline const SymmTensor<Cmpt>& symm(const SymmTensor<Cmpt>& st)
00281 {
00282     return st;
00283 }
00284 
00285 
00286 //- Return twice the symmetric part of a symmetric tensor
00287 template <class Cmpt>
00288 inline SymmTensor<Cmpt> twoSymm(const SymmTensor<Cmpt>& st)
00289 {
00290     return 2*st;
00291 }
00292 
00293 
00294 //- Return the deviatoric part of a symmetric tensor
00295 template <class Cmpt>
00296 inline SymmTensor<Cmpt> dev(const SymmTensor<Cmpt>& st)
00297 {
00298     return st - SphericalTensor<Cmpt>::oneThirdI*tr(st);
00299 }
00300 
00301 
00302 //- Return the deviatoric part of a symmetric tensor
00303 template <class Cmpt>
00304 inline SymmTensor<Cmpt> dev2(const SymmTensor<Cmpt>& st)
00305 {
00306     return st - SphericalTensor<Cmpt>::twoThirdsI*tr(st);
00307 }
00308 
00309 
00310 //- Return the determinant of a symmetric tensor
00311 template <class Cmpt>
00312 inline Cmpt det(const SymmTensor<Cmpt>& st)
00313 {
00314     return
00315     (
00316         st.xx()*st.yy()*st.zz() + st.xy()*st.yz()*st.xz()
00317       + st.xz()*st.xy()*st.yz() - st.xx()*st.yz()*st.yz()
00318       - st.xy()*st.xy()*st.zz() - st.xz()*st.yy()*st.xz()
00319     );
00320 }
00321 
00322 
00323 //- Return the cofactor symmetric tensor of a symmetric tensor
00324 template <class Cmpt>
00325 inline SymmTensor<Cmpt> cof(const SymmTensor<Cmpt>& st)
00326 {
00327     return SymmTensor<Cmpt>
00328     (
00329         st.yy()*st.zz() - st.yz()*st.yz(),
00330         st.xz()*st.yz() - st.xy()*st.zz(),
00331         st.xy()*st.yz() - st.xz()*st.yy(),
00332 
00333         st.xx()*st.zz() - st.xz()*st.xz(),
00334         st.xy()*st.xz() - st.xx()*st.yz(),
00335 
00336         st.xx()*st.yy() - st.xy()*st.xy()
00337     );
00338 }
00339 
00340 
00341 //- Return the inverse of a symmetric tensor give the determinant
00342 template <class Cmpt>
00343 inline SymmTensor<Cmpt> inv(const SymmTensor<Cmpt>& st, const Cmpt detst)
00344 {
00345     return SymmTensor<Cmpt>
00346     (
00347         st.yy()*st.zz() - st.yz()*st.yz(),
00348         st.xz()*st.yz() - st.xy()*st.zz(),
00349         st.xy()*st.yz() - st.xz()*st.yy(),
00350 
00351         st.xx()*st.zz() - st.xz()*st.xz(),
00352         st.xy()*st.xz() - st.xx()*st.yz(),
00353 
00354         st.xx()*st.yy() - st.xy()*st.xy()
00355     )/detst;
00356 }
00357 
00358 
00359 //- Return the inverse of a symmetric tensor
00360 template <class Cmpt>
00361 inline SymmTensor<Cmpt> inv(const SymmTensor<Cmpt>& st)
00362 {
00363     return inv(st, det(st));
00364 }
00365 
00366 
00367 //- Return the 1st invariant of a symmetric tensor
00368 template <class Cmpt>
00369 inline Cmpt invariantI(const SymmTensor<Cmpt>& st)
00370 {
00371     return tr(st);
00372 }
00373 
00374 
00375 //- Return the 2nd invariant of a symmetric tensor
00376 template <class Cmpt>
00377 inline Cmpt invariantII(const SymmTensor<Cmpt>& st)
00378 {
00379     return
00380     (
00381         0.5*sqr(tr(st))
00382       - 0.5*
00383         (
00384            st.xx()*st.xx() + st.xy()*st.xy() + st.xz()*st.xz()
00385          + st.xy()*st.xy() + st.yy()*st.yy() + st.yz()*st.yz()
00386          + st.xz()*st.xz() + st.yz()*st.yz() + st.zz()*st.zz()
00387         )
00388     );
00389 }
00390 
00391 
00392 //- Return the 3rd invariant of a symmetric tensor
00393 template <class Cmpt>
00394 inline Cmpt invariantIII(const SymmTensor<Cmpt>& st)
00395 {
00396     return det(st);
00397 }
00398 
00399 
00400 template <class Cmpt>
00401 inline SymmTensor<Cmpt>
00402 operator+(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
00403 {
00404     return SymmTensor<Cmpt>
00405     (
00406         spt1.ii() + st2.xx(), st2.xy(),             st2.xz(),
00407                               spt1.ii() + st2.yy(), st2.yz(),
00408                                                     spt1.ii() + st2.zz()
00409     );
00410 }
00411 
00412 
00413 template <class Cmpt>
00414 inline SymmTensor<Cmpt>
00415 operator+(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2)
00416 {
00417     return SymmTensor<Cmpt>
00418     (
00419         st1.xx() + spt2.ii(), st1.xy(),             st1.xz(),
00420                               st1.yy() + spt2.ii(), st1.yz(),
00421                                                     st1.zz() + spt2.ii()
00422     );
00423 }
00424 
00425 
00426 template <class Cmpt>
00427 inline SymmTensor<Cmpt>
00428 operator-(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
00429 {
00430     return SymmTensor<Cmpt>
00431     (
00432         spt1.ii() - st2.xx(), -st2.xy(),             -st2.xz(),
00433                                spt1.ii() - st2.yy(), -st2.yz(),
00434                                                       spt1.ii() - st2.zz()
00435     );
00436 }
00437 
00438 
00439 template <class Cmpt>
00440 inline SymmTensor<Cmpt>
00441 operator-(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2)
00442 {
00443     return SymmTensor<Cmpt>
00444     (
00445         st1.xx() - spt2.ii(), st1.xy(),             st1.xz(),
00446                               st1.yy() - spt2.ii(), st1.yz(),
00447                                                     st1.zz() - spt2.ii()
00448     );
00449 }
00450 
00451 
00452 //- Inner-product between a spherical symmetric tensor and a symmetric tensor
00453 template <class Cmpt>
00454 inline SymmTensor<Cmpt>
00455 operator&(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
00456 {
00457     return SymmTensor<Cmpt>
00458     (
00459         spt1.ii()*st2.xx(), spt1.ii()*st2.xy(), spt1.ii()*st2.xz(),
00460                             spt1.ii()*st2.yy(), spt1.ii()*st2.yz(),
00461                                                 spt1.ii()*st2.zz()
00462     );
00463 }
00464 
00465 
00466 //- Inner-product between a tensor and a spherical tensor
00467 template <class Cmpt>
00468 inline SymmTensor<Cmpt>
00469 operator&(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2)
00470 {
00471     return SymmTensor<Cmpt>
00472     (
00473         st1.xx()*spt2.ii(), st1.xy()*spt2.ii(), st1.xz()*spt2.ii(),
00474                             st1.yy()*spt2.ii(), st1.yz()*spt2.ii(),
00475                                                 st1.zz()*spt2.ii()
00476     );
00477 }
00478 
00479 
00480 //- Double-dot-product between a spherical tensor and a symmetric tensor
00481 template <class Cmpt>
00482 inline Cmpt
00483 operator&&(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
00484 {
00485     return(spt1.ii()*st2.xx() + spt1.ii()*st2.yy() + spt1.ii()*st2.zz());
00486 }
00487 
00488 
00489 //- Double-dot-product between a tensor and a spherical tensor
00490 template <class Cmpt>
00491 inline Cmpt
00492 operator&&(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2)
00493 {
00494     return(st1.xx()*spt2.ii() + st1.yy()*spt2.ii() + st1.zz()*spt2.ii());
00495 }
00496 
00497 
00498 template <class Cmpt>
00499 inline SymmTensor<Cmpt> sqr(const Vector<Cmpt>& v)
00500 {
00501     return SymmTensor<Cmpt>
00502     (
00503         v.x()*v.x(), v.x()*v.y(), v.x()*v.z(),
00504                      v.y()*v.y(), v.y()*v.z(),
00505                                   v.z()*v.z()
00506     );
00507 }
00508 
00509 
00510 template<class Cmpt>
00511 class outerProduct<SymmTensor<Cmpt>, Cmpt>
00512 {
00513 public:
00514 
00515     typedef SymmTensor<Cmpt> type;
00516 };
00517 
00518 template<class Cmpt>
00519 class outerProduct<Cmpt, SymmTensor<Cmpt> >
00520 {
00521 public:
00522 
00523     typedef SymmTensor<Cmpt> type;
00524 };
00525 
00526 template<class Cmpt>
00527 class innerProduct<SymmTensor<Cmpt>, SymmTensor<Cmpt> >
00528 {
00529 public:
00530 
00531     typedef SymmTensor<Cmpt> type;
00532 };
00533 
00534 template<class Cmpt>
00535 class innerProduct<SymmTensor<Cmpt>, Vector<Cmpt> >
00536 {
00537 public:
00538 
00539     typedef Vector<Cmpt> type;
00540 };
00541 
00542 template<class Cmpt>
00543 class innerProduct<Vector<Cmpt>, SymmTensor<Cmpt> >
00544 {
00545 public:
00546 
00547     typedef Vector<Cmpt> type;
00548 };
00549 
00550 
00551 template<class Cmpt>
00552 class typeOfSum<SphericalTensor<Cmpt>, SymmTensor<Cmpt> >
00553 {
00554 public:
00555 
00556     typedef SymmTensor<Cmpt> type;
00557 };
00558 
00559 template<class Cmpt>
00560 class typeOfSum<SymmTensor<Cmpt>, SphericalTensor<Cmpt> >
00561 {
00562 public:
00563 
00564     typedef SymmTensor<Cmpt> type;
00565 };
00566 
00567 template<class Cmpt>
00568 class innerProduct<SphericalTensor<Cmpt>, SymmTensor<Cmpt> >
00569 {
00570 public:
00571 
00572     typedef SymmTensor<Cmpt> type;
00573 };
00574 
00575 template<class Cmpt>
00576 class innerProduct<SymmTensor<Cmpt>, SphericalTensor<Cmpt> >
00577 {
00578 public:
00579 
00580     typedef SymmTensor<Cmpt> type;
00581 };
00582 
00583 
00584 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00585 
00586 } // End namespace Foam
00587 
00588 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines