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