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

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