OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen OpenCFD Solutions Contact OpenFOAM

Tensor2DI.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-2007 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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00028 
00029 namespace Foam
00030 {
00031 
00032 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00033 
00034 //- Construct null
00035 template <class Cmpt>
00036 inline Tensor2D<Cmpt>::Tensor2D()
00037 {}
00038 
00039 
00040 //- Construct given VectorSpace
00041 template <class Cmpt>
00042 inline Tensor2D<Cmpt>::Tensor2D(const VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>& vs)
00043 :
00044     VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>(vs)
00045 {}
00046 
00047 
00048 //- Construct given SphericalTensor2D
00049 template <class Cmpt>
00050 inline Tensor2D<Cmpt>::Tensor2D(const SphericalTensor2D<Cmpt>& st)
00051 {
00052     this->v_[XX] = st.ii(); this->v_[XY] = 0;
00053     this->v_[YX] = 0; this->v_[YY] = st.ii();
00054 }
00055 
00056 
00057 //- Construct from components
00058 template <class Cmpt>
00059 inline Tensor2D<Cmpt>::Tensor2D
00060 (
00061     const Cmpt txx, const Cmpt txy,
00062     const Cmpt tyx, const Cmpt tyy
00063 )
00064 {
00065     this->v_[XX] = txx; this->v_[XY] = txy;
00066     this->v_[YX] = tyx; this->v_[YY] = tyy;
00067 }
00068 
00069 
00070 //- Construct from Istream
00071 template <class Cmpt>
00072 inline Tensor2D<Cmpt>::Tensor2D(Istream& is)
00073 :
00074     VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>(is)
00075 {}
00076 
00077 
00078 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00079 
00080 template <class Cmpt>
00081 inline const Vector2D<Cmpt>&  Tensor2D<Cmpt>::x() const
00082 {
00083     return reinterpret_cast<const Vector2D<Cmpt>&>(this->v_[XX]);
00084 }
00085 
00086 template <class Cmpt>
00087 inline const Vector2D<Cmpt>&  Tensor2D<Cmpt>::y() const
00088 {
00089     return reinterpret_cast<const Vector2D<Cmpt>&>(this->v_[YX]);
00090 }
00091 
00092 
00093 template <class Cmpt>
00094 inline Vector2D<Cmpt>&  Tensor2D<Cmpt>::x()
00095 {
00096     return reinterpret_cast<Vector2D<Cmpt>&>(this->v_[XX]);
00097 }
00098 
00099 template <class Cmpt>
00100 inline Vector2D<Cmpt>&  Tensor2D<Cmpt>::y()
00101 {
00102     return reinterpret_cast<Vector2D<Cmpt>&>(this->v_[YX]);
00103 }
00104 
00105 
00106 template <class Cmpt>
00107 inline const Cmpt&  Tensor2D<Cmpt>::xx() const
00108 {
00109     return this->v_[XX];
00110 }
00111 
00112 template <class Cmpt>
00113 inline const Cmpt&  Tensor2D<Cmpt>::xy() const
00114 {
00115     return this->v_[XY];
00116 }
00117 
00118 template <class Cmpt>
00119 inline const Cmpt&  Tensor2D<Cmpt>::yx() const
00120 {
00121     return this->v_[YX];
00122 }
00123 
00124 template <class Cmpt>
00125 inline const Cmpt&  Tensor2D<Cmpt>::yy() const
00126 {
00127     return this->v_[YY];
00128 }
00129 
00130 
00131 template <class Cmpt>
00132 inline Cmpt& Tensor2D<Cmpt>::xx()
00133 {
00134     return this->v_[XX];
00135 }
00136 
00137 template <class Cmpt>
00138 inline Cmpt& Tensor2D<Cmpt>::xy()
00139 {
00140     return this->v_[XY];
00141 }
00142 
00143 template <class Cmpt>
00144 inline Cmpt& Tensor2D<Cmpt>::yx()
00145 {
00146     return this->v_[YX];
00147 }
00148 
00149 template <class Cmpt>
00150 inline Cmpt& Tensor2D<Cmpt>::yy()
00151 {
00152     return this->v_[YY];
00153 }
00154 
00155 
00156 //- Return tensor transpose
00157 template <class Cmpt>
00158 inline Tensor2D<Cmpt> Tensor2D<Cmpt>::T() const
00159 {
00160     return Tensor2D<Cmpt>
00161     (
00162         xx(), yx(),
00163         xy(), yy()
00164     );
00165 }
00166 
00167 
00168 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00169 
00170 template <class Cmpt>
00171 inline void Tensor2D<Cmpt>::operator=(const SphericalTensor2D<Cmpt>& st)
00172 {
00173     this->v_[XX] = st.ii(); this->v_[XY] = 0;
00174     this->v_[YX] = 0; this->v_[YY] = st.ii();
00175 }
00176 
00177 
00178 
00179 // * * * * * * * * * * * * * * * Global Operators  * * * * * * * * * * * * * //
00180 
00181 //- Inner-product between two tensors
00182 template <class Cmpt>
00183 inline typename innerProduct<Tensor2D<Cmpt>, Tensor2D<Cmpt> >::type
00184 operator&(const Tensor2D<Cmpt>& t1, const Tensor2D<Cmpt>& t2)
00185 {
00186     return Tensor2D<Cmpt>
00187     (
00188         t1.xx()*t2.xx() + t1.xy()*t2.yx(),
00189         t1.xx()*t2.xy() + t1.xy()*t2.yy(),
00190 
00191         t1.yx()*t2.xx() + t1.yy()*t2.yx(),
00192         t1.yx()*t2.xy() + t1.yy()*t2.yy()
00193     );
00194 }
00195 
00196 //- Inner-product between a tensor and a vector
00197 template <class Cmpt>
00198 inline typename innerProduct<Tensor2D<Cmpt>, Vector2D<Cmpt> >::type
00199 operator&(const Tensor2D<Cmpt>& t, const Vector2D<Cmpt>& v)
00200 {
00201     return Vector2D<Cmpt>
00202     (
00203         t.xx()*v.x() + t.xy()*v.y(),
00204         t.yx()*v.x() + t.yy()*v.y()
00205     );
00206 }
00207 
00208 //- Inner-product between a vector and a tensor
00209 template <class Cmpt>
00210 inline typename innerProduct<Vector2D<Cmpt>, Tensor2D<Cmpt> >::type
00211 operator&(const Vector2D<Cmpt>& v, const Tensor2D<Cmpt>& t)
00212 {
00213     return Vector2D<Cmpt>
00214     (
00215         v.x()*t.xx() + v.y()*t.yx(),
00216         v.x()*t.xy() + v.y()*t.yy()
00217     );
00218 }
00219 
00220 //- Outer-product between two vectors
00221 template <class Cmpt>
00222 inline typename outerProduct<Vector2D<Cmpt>, Vector2D<Cmpt> >::type
00223 operator*(const Vector2D<Cmpt>& v1, const Vector2D<Cmpt>& v2)
00224 {
00225     return Tensor2D<Cmpt>
00226     (
00227         v1.x()*v2.x(), v1.x()*v2.y(),
00228         v1.y()*v2.x(), v1.y()*v2.y()
00229     );
00230 }
00231 
00232 
00233 //- Return the trace of a tensor
00234 template <class Cmpt>
00235 inline Cmpt tr(const Tensor2D<Cmpt>& t)
00236 {
00237     return t.xx() + t.yy();
00238 }
00239 
00240 
00241 //- Return the spherical part of a tensor
00242 template <class Cmpt>
00243 inline SphericalTensor2D<Cmpt> sph(const Tensor2D<Cmpt>& t)
00244 {
00245     return 0.5*tr(t);
00246 }
00247 
00248 
00249 //- Return the symmetric part of a tensor
00250 template <class Cmpt>
00251 inline Tensor2D<Cmpt> symm(const Tensor2D<Cmpt>& t)
00252 {
00253     return Tensor2D<Cmpt>
00254     (
00255         t.xx(), 0.5*(t.xy() + t.yx()),
00256         0.5*(t.yx() + t.xy()), t.yy()
00257     );
00258 }
00259 
00260 //- Return the twice the symmetric part of a tensor
00261 template <class Cmpt>
00262 inline Tensor2D<Cmpt> twoSymm(const Tensor2D<Cmpt>& t)
00263 {
00264     return Tensor2D<Cmpt>
00265     (
00266         t.xx() + t.xx(), t.xy() + t.yx(),
00267         t.yx() + t.xy(), t.yy() + t.yy()
00268     );
00269 }
00270 
00271 //- Return the skew-symmetric part of a tensor
00272 template <class Cmpt>
00273 inline Tensor2D<Cmpt> skew(const Tensor2D<Cmpt>& t)
00274 {
00275     return Tensor2D<Cmpt>
00276     (
00277         0.0, 0.5*(t.xy() - t.yx()),
00278         0.5*(t.yx() - t.xy()), 0.0
00279     );
00280 }
00281 
00282 
00283 //- Return the deviatoric part of a tensor
00284 template <class Cmpt>
00285 inline Tensor2D<Cmpt> dev(const Tensor2D<Cmpt>& t)
00286 {
00287     return t - SphericalTensor2D<Cmpt>::oneThirdI*tr(t);
00288 }
00289 
00290 
00291 //- Return the deviatoric part of a tensor
00292 template <class Cmpt>
00293 inline Tensor2D<Cmpt> dev2(const Tensor2D<Cmpt>& t)
00294 {
00295     return t - SphericalTensor2D<Cmpt>::twoThirdsI*tr(t);
00296 }
00297 
00298 
00299 //- Return the determinant of a tensor
00300 template <class Cmpt>
00301 inline Cmpt det(const Tensor2D<Cmpt>& t)
00302 {
00303     return(t.xx()*t.yy() - t.xy()*t.yx());
00304 }
00305 
00306 //- Return the inverse of a tensor give the determinant
00307 template <class Cmpt>
00308 inline Tensor2D<Cmpt> inv(const Tensor2D<Cmpt>& t, const Cmpt dett)
00309 {
00310     return Tensor2D<Cmpt>
00311     (
00312         t.yy(), -t.xy(),
00313        -t.yx(),  t.xx()
00314     )/dett;
00315 }
00316 
00317 //- Return the inverse of a tensor
00318 template <class Cmpt>
00319 inline Tensor2D<Cmpt> inv(const Tensor2D<Cmpt>& t)
00320 {
00321     return inv(t, det(t));
00322 }
00323 
00324 
00325 //- Return the 1st invariant of a tensor
00326 template <class Cmpt>
00327 inline Cmpt invariantI(const Tensor2D<Cmpt>& t)
00328 {
00329     return tr(t);
00330 }
00331 
00332 
00333 //- Return the 2nd invariant of a tensor
00334 template <class Cmpt>
00335 inline Cmpt invariantII(const Tensor2D<Cmpt>& t)
00336 {
00337     return
00338     (
00339         0.5*sqr(tr(t))
00340       - 0.5*
00341         (
00342            t.xx()*t.xx() + t.xy()*t.xy()
00343          + t.yx()*t.yx() + t.yy()*t.yy()
00344         )
00345     );
00346 }
00347 
00348 
00349 //- Return the 3rd invariant of a tensor
00350 template <class Cmpt>
00351 inline Cmpt invariantIII(const Tensor2D<Cmpt>& t)
00352 {
00353     return det(t);
00354 }
00355 
00356 
00357 
00358 
00359 template <class Cmpt>
00360 inline Tensor2D<Cmpt>
00361 operator+(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
00362 {
00363     return Tensor2D<Cmpt>
00364     (
00365         st1.ii() + t2.xx(), t2.xy(),
00366         t2.yx(),            st1.ii() + t2.yy()
00367     );
00368 }
00369 
00370 
00371 template <class Cmpt>
00372 inline Tensor2D<Cmpt>
00373 operator+(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
00374 {
00375     return Tensor2D<Cmpt>
00376     (
00377         t1.xx() + st2.ii(), t1.xy(),
00378         t1.yx(),            t1.yy() + st2.ii()
00379     );
00380 }
00381 
00382 
00383 template <class Cmpt>
00384 inline Tensor2D<Cmpt>
00385 operator-(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
00386 {
00387     return Tensor2D<Cmpt>
00388     (
00389         st1.ii() - t2.xx(), -t2.xy(),
00390        -t2.yx(),             st1.ii() - t2.yy()
00391     );
00392 }
00393 
00394 
00395 template <class Cmpt>
00396 inline Tensor2D<Cmpt>
00397 operator-(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
00398 {
00399     return Tensor2D<Cmpt>
00400     (
00401         t1.xx() - st2.ii(), t1.xy(),
00402         t1.yx(),            t1.yy() - st2.ii()
00403     );
00404 }
00405 
00406 
00407 //- Inner-product between a spherical tensor and a tensor
00408 template <class Cmpt>
00409 inline Tensor2D<Cmpt>
00410 operator&(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
00411 {
00412     return Tensor2D<Cmpt>
00413     (
00414         st1.ii()*t2.xx(),
00415         st1.ii()*t2.xy(),
00416                           st1.ii()*t2.yx(),
00417                           st1.ii()*t2.yy()
00418     );
00419 }
00420 
00421 
00422 //- Inner-product between a tensor and a spherical tensor
00423 template <class Cmpt>
00424 inline Tensor2D<Cmpt>
00425 operator&(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
00426 {
00427     return Tensor2D<Cmpt>
00428     (
00429         t1.xx()*st2.ii(),
00430                           t1.xy()*st2.ii(),
00431 
00432         t1.yx()*st2.ii(),
00433                           t1.yy()*st2.ii()
00434     );
00435 }
00436 
00437 
00438 //- Double-dot-product between a spherical tensor and a tensor
00439 template <class Cmpt>
00440 inline Cmpt
00441 operator&&(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
00442 {
00443     return(st1.ii()*t2.xx() + st1.ii()*t2.yy());
00444 }
00445 
00446 
00447 //- Double-dot-product between a tensor and a spherical tensor
00448 template <class Cmpt>
00449 inline Cmpt
00450 operator&&(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
00451 {
00452     return(t1.xx()*st2.ii() + t1.yy()*st2.ii());
00453 }
00454 
00455 
00456 template<class Cmpt>
00457 class typeOfSum<SphericalTensor2D<Cmpt>, Tensor2D<Cmpt> >
00458 {
00459 public:
00460 
00461     typedef Tensor2D<Cmpt> type;
00462 };
00463 
00464 template<class Cmpt>
00465 class typeOfSum<Tensor2D<Cmpt>, SphericalTensor2D<Cmpt> >
00466 {
00467 public:
00468 
00469     typedef Tensor2D<Cmpt> type;
00470 };
00471 
00472 
00473 template<class Cmpt>
00474 class innerProduct<SphericalTensor2D<Cmpt>, Tensor2D<Cmpt> >
00475 {
00476 public:
00477 
00478     typedef Tensor2D<Cmpt> type;
00479 };
00480 
00481 template<class Cmpt>
00482 class innerProduct<Tensor2D<Cmpt>, SphericalTensor2D<Cmpt> >
00483 {
00484 public:
00485 
00486     typedef Tensor2D<Cmpt> type;
00487 };
00488 
00489 
00490 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00491 
00492 } // End namespace Foam
00493 
00494 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd