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