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
00028
00029 namespace Foam
00030 {
00031
00032
00033
00034
00035 template <class Cmpt>
00036 inline Tensor<Cmpt>::Tensor()
00037 {}
00038
00039
00040
00041 template <class Cmpt>
00042 inline Tensor<Cmpt>::Tensor(const VectorSpace<Tensor<Cmpt>, Cmpt, 9>& vs)
00043 :
00044 VectorSpace<Tensor<Cmpt>, Cmpt, 9>(vs)
00045 {}
00046
00047
00048
00049 template <class Cmpt>
00050 inline Tensor<Cmpt>::Tensor
00051 (
00052 const Cmpt txx, const Cmpt txy, const Cmpt txz,
00053 const Cmpt tyx, const Cmpt tyy, const Cmpt tyz,
00054 const Cmpt tzx, const Cmpt tzy, const Cmpt tzz
00055 )
00056 {
00057 this->v_[XX] = txx; this->v_[XY] = txy; this->v_[XZ] = txz;
00058 this->v_[YX] = tyx; this->v_[YY] = tyy; this->v_[YZ] = tyz;
00059 this->v_[ZX] = tzx; this->v_[ZY] = tzy; this->v_[ZZ] = tzz;
00060 }
00061
00062
00063
00064 template <class Cmpt>
00065 inline Tensor<Cmpt>::Tensor(Istream& is)
00066 :
00067 VectorSpace<Tensor<Cmpt>, Cmpt, 9>(is)
00068 {}
00069
00070
00071
00072
00073 template <class Cmpt>
00074 inline const Vector<Cmpt>& Tensor<Cmpt>::x() const
00075 {
00076 return reinterpret_cast<const Vector<Cmpt>&>(this->v_[XX]);
00077 }
00078
00079 template <class Cmpt>
00080 inline const Vector<Cmpt>& Tensor<Cmpt>::y() const
00081 {
00082 return reinterpret_cast<const Vector<Cmpt>&>(this->v_[YX]);
00083 }
00084
00085 template <class Cmpt>
00086 inline const Vector<Cmpt>& Tensor<Cmpt>::z() const
00087 {
00088 return reinterpret_cast<const Vector<Cmpt>&>(this->v_[ZX]);
00089 }
00090
00091
00092 template <class Cmpt>
00093 inline Vector<Cmpt>& Tensor<Cmpt>::x()
00094 {
00095 return reinterpret_cast<Vector<Cmpt>&>(this->v_[XX]);
00096 }
00097
00098 template <class Cmpt>
00099 inline Vector<Cmpt>& Tensor<Cmpt>::y()
00100 {
00101 return reinterpret_cast<Vector<Cmpt>&>(this->v_[YX]);
00102 }
00103
00104 template <class Cmpt>
00105 inline Vector<Cmpt>& Tensor<Cmpt>::z()
00106 {
00107 return reinterpret_cast<Vector<Cmpt>&>(this->v_[ZX]);
00108 }
00109
00110
00111 template <class Cmpt>
00112 inline const Cmpt& Tensor<Cmpt>::xx() const
00113 {
00114 return this->v_[XX];
00115 }
00116
00117 template <class Cmpt>
00118 inline const Cmpt& Tensor<Cmpt>::xy() const
00119 {
00120 return this->v_[XY];
00121 }
00122
00123 template <class Cmpt>
00124 inline const Cmpt& Tensor<Cmpt>::xz() const
00125 {
00126 return this->v_[XZ];
00127 }
00128
00129
00130 template <class Cmpt>
00131 inline const Cmpt& Tensor<Cmpt>::yx() const
00132 {
00133 return this->v_[YX];
00134 }
00135
00136 template <class Cmpt>
00137 inline const Cmpt& Tensor<Cmpt>::yy() const
00138 {
00139 return this->v_[YY];
00140 }
00141
00142 template <class Cmpt>
00143 inline const Cmpt& Tensor<Cmpt>::yz() const
00144 {
00145 return this->v_[YZ];
00146 }
00147
00148
00149 template <class Cmpt>
00150 inline const Cmpt& Tensor<Cmpt>::zx() const
00151 {
00152 return this->v_[ZX];
00153 }
00154
00155 template <class Cmpt>
00156 inline const Cmpt& Tensor<Cmpt>::zy() const
00157 {
00158 return this->v_[ZY];
00159 }
00160
00161 template <class Cmpt>
00162 inline const Cmpt& Tensor<Cmpt>::zz() const
00163 {
00164 return this->v_[ZZ];
00165 }
00166
00167
00168 template <class Cmpt>
00169 inline Cmpt& Tensor<Cmpt>::xx()
00170 {
00171 return this->v_[XX];
00172 }
00173
00174 template <class Cmpt>
00175 inline Cmpt& Tensor<Cmpt>::xy()
00176 {
00177 return this->v_[XY];
00178 }
00179
00180 template <class Cmpt>
00181 inline Cmpt& Tensor<Cmpt>::xz()
00182 {
00183 return this->v_[XZ];
00184 }
00185
00186
00187 template <class Cmpt>
00188 inline Cmpt& Tensor<Cmpt>::yx()
00189 {
00190 return this->v_[YX];
00191 }
00192
00193 template <class Cmpt>
00194 inline Cmpt& Tensor<Cmpt>::yy()
00195 {
00196 return this->v_[YY];
00197 }
00198
00199 template <class Cmpt>
00200 inline Cmpt& Tensor<Cmpt>::yz()
00201 {
00202 return this->v_[YZ];
00203 }
00204
00205
00206 template <class Cmpt>
00207 inline Cmpt& Tensor<Cmpt>::zx()
00208 {
00209 return this->v_[ZX];
00210 }
00211
00212 template <class Cmpt>
00213 inline Cmpt& Tensor<Cmpt>::zy()
00214 {
00215 return this->v_[ZY];
00216 }
00217
00218 template <class Cmpt>
00219 inline Cmpt& Tensor<Cmpt>::zz()
00220 {
00221 return this->v_[ZZ];
00222 }
00223
00224
00225
00226 template <class Cmpt>
00227 inline Tensor<Cmpt> Tensor<Cmpt>::T() const
00228 {
00229 return Tensor<Cmpt>
00230 (
00231 xx(), yx(), zx(),
00232 xy(), yy(), zy(),
00233 xz(), yz(), zz()
00234 );
00235 }
00236
00237
00238
00239
00240
00241 template <class Cmpt>
00242 inline Vector<Cmpt> operator*(const Tensor<Cmpt>& t)
00243 {
00244 return Vector<Cmpt>(t.yz(), -t.xz(), t.xy());
00245 }
00246
00247
00248
00249 template <class Cmpt>
00250 inline Tensor<Cmpt> operator*(const Vector<Cmpt>& v)
00251 {
00252 return Tensor<Cmpt>
00253 (
00254 0, -v.z(), v.y(),
00255 v.z(), 0, -v.x(),
00256 -v.y(), v.x(), 0
00257 );
00258 }
00259
00260
00261
00262 template <class Cmpt>
00263 inline typename innerProduct<Tensor<Cmpt>, Tensor<Cmpt> >::type
00264 operator&(const Tensor<Cmpt>& t1, const Tensor<Cmpt>& t2)
00265 {
00266 return Tensor<Cmpt>
00267 (
00268 t1.xx()*t2.xx() + t1.xy()*t2.yx() + t1.xz()*t2.zx(),
00269 t1.xx()*t2.xy() + t1.xy()*t2.yy() + t1.xz()*t2.zy(),
00270 t1.xx()*t2.xz() + t1.xy()*t2.yz() + t1.xz()*t2.zz(),
00271
00272 t1.yx()*t2.xx() + t1.yy()*t2.yx() + t1.yz()*t2.zx(),
00273 t1.yx()*t2.xy() + t1.yy()*t2.yy() + t1.yz()*t2.zy(),
00274 t1.yx()*t2.xz() + t1.yy()*t2.yz() + t1.yz()*t2.zz(),
00275
00276 t1.zx()*t2.xx() + t1.zy()*t2.yx() + t1.zz()*t2.zx(),
00277 t1.zx()*t2.xy() + t1.zy()*t2.yy() + t1.zz()*t2.zy(),
00278 t1.zx()*t2.xz() + t1.zy()*t2.yz() + t1.zz()*t2.zz()
00279 );
00280 }
00281
00282
00283 template <class Cmpt>
00284 inline typename innerProduct<Tensor<Cmpt>, Vector<Cmpt> >::type
00285 operator&(const Tensor<Cmpt>& t, const Vector<Cmpt>& v)
00286 {
00287 return Vector<Cmpt>
00288 (
00289 t.xx()*v.x() + t.xy()*v.y() + t.xz()*v.z(),
00290 t.yx()*v.x() + t.yy()*v.y() + t.yz()*v.z(),
00291 t.zx()*v.x() + t.zy()*v.y() + t.zz()*v.z()
00292 );
00293 }
00294
00295
00296 template <class Cmpt>
00297 inline typename innerProduct<Vector<Cmpt>, Tensor<Cmpt> >::type
00298 operator&(const Vector<Cmpt>& v, const Tensor<Cmpt>& t)
00299 {
00300 return Vector<Cmpt>
00301 (
00302 v.x()*t.xx() + v.y()*t.yx() + v.z()*t.zx(),
00303 v.x()*t.xy() + v.y()*t.yy() + v.z()*t.zy(),
00304 v.x()*t.xz() + v.y()*t.yz() + v.z()*t.zz()
00305 );
00306 }
00307
00308
00309 template <class Cmpt>
00310 inline typename outerProduct<Vector<Cmpt>, Vector<Cmpt> >::type
00311 operator*(const Vector<Cmpt>& v1, const Vector<Cmpt>& v2)
00312 {
00313 return Tensor<Cmpt>
00314 (
00315 v1.x()*v2.x(), v1.x()*v2.y(), v1.x()*v2.z(),
00316 v1.y()*v2.x(), v1.y()*v2.y(), v1.y()*v2.z(),
00317 v1.z()*v2.x(), v1.z()*v2.y(), v1.z()*v2.z()
00318 );
00319 }
00320
00321
00322
00323 template <class Cmpt>
00324 inline scalar tr(const Tensor<Cmpt>& t)
00325 {
00326 return t.xx() + t.yy() + t.zz();
00327 }
00328
00329
00330 template <class Cmpt>
00331 inline Tensor<Cmpt> symm(const Tensor<Cmpt>& t)
00332 {
00333 return Tensor<Cmpt>
00334 (
00335 t.xx(), 0.5*(t.xy() + t.yx()), 0.5*(t.xz() + t.zx()),
00336 0.5*(t.yx() + t.xy()), t.yy(), 0.5*(t.yz() + t.zy()),
00337 0.5*(t.zx() + t.xz()), 0.5*(t.zy() + t.yz()), t.zz()
00338 );
00339 }
00340
00341
00342 template <class Cmpt>
00343 inline Tensor<Cmpt> skew(const Tensor<Cmpt>& t)
00344 {
00345 return Tensor<Cmpt>
00346 (
00347 0.0, 0.5*(t.xy() - t.yx()), 0.5*(t.xz() - t.zx()),
00348 0.5*(t.yx() - t.xy()), 0.0, 0.5*(t.yz() - t.zy()),
00349 0.5*(t.zx() - t.xz()), 0.5*(t.zy() - t.yz()), 0.0
00350 );
00351 }
00352
00353
00354 template <class Cmpt>
00355 inline scalar det(const Tensor<Cmpt>& t)
00356 {
00357 return
00358 (
00359 t.xx()*t.yy()*t.zz() + t.xy()*t.yz()*t.zx()
00360 + t.xz()*t.yx()*t.zy() - t.xx()*t.yz()*t.zy()
00361 - t.xy()*t.yx()*t.zz() - t.xz()*t.yy()*t.zx()
00362 );
00363 }
00364
00365
00366 template <class Cmpt>
00367 inline Tensor<Cmpt> cofactors(const Tensor<Cmpt>& t)
00368 {
00369 return Tensor<Cmpt>
00370 (
00371 t.yy()*t.zz() - t.zy()*t.yz(),
00372 t.zx()*t.yz() - t.yx()*t.zz(),
00373 t.yx()*t.zy() - t.yy()*t.zx(),
00374
00375 t.xz()*t.zy() - t.xy()*t.zz(),
00376 t.xx()*t.zz() - t.xz()*t.zx(),
00377 t.xy()*t.zx() - t.xx()*t.zy(),
00378
00379 t.xy()*t.yz() - t.xz()*t.yy(),
00380 t.yx()*t.xz() - t.xx()*t.yz(),
00381 t.xx()*t.yy() - t.yx()*t.xy()
00382 );
00383 }
00384
00385
00386 template <class Cmpt>
00387 inline Tensor<Cmpt> inv(const Tensor<Cmpt>& t)
00388 {
00389 return Tensor<Cmpt>
00390 (
00391 t.yy()*t.zz() - t.zy()*t.yz(),
00392 t.xz()*t.zy() - t.xy()*t.zz(),
00393 t.xy()*t.yz() - t.xz()*t.yy(),
00394
00395 t.zx()*t.yz() - t.yx()*t.zz(),
00396 t.xx()*t.zz() - t.xz()*t.zx(),
00397 t.yx()*t.xz() - t.xx()*t.yz(),
00398
00399 t.yx()*t.zy() - t.yy()*t.zx(),
00400 t.xy()*t.zx() - t.xx()*t.zy(),
00401 t.xx()*t.yy() - t.yx()*t.xy()
00402 )/det(t);
00403 }
00404
00405
00406
00407 template <class Cmpt>
00408 inline scalar invariantI(const Tensor<Cmpt>& t)
00409 {
00410 return tr(t);
00411 }
00412
00413
00414
00415 template <class Cmpt>
00416 inline scalar invariantII(const Tensor<Cmpt>& t)
00417 {
00418 return
00419 (
00420 0.5*sqr(tr(t))
00421 - 0.5*
00422 (
00423 t.xx()*t.xx() + t.xy()*t.xy() + t.xz()*t.xz()
00424 + t.yx()*t.yx() + t.yy()*t.yy() + t.yz()*t.yz()
00425 + t.zx()*t.zx() + t.zy()*t.zy() + t.zz()*t.zz()
00426 )
00427 );
00428 }
00429
00430
00431
00432 template <class Cmpt>
00433 inline scalar invariantIII(const Tensor<Cmpt>& t)
00434 {
00435 return det(t);
00436 }
00437
00438
00439
00440
00441 }
00442
00443