1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 inline Tensor2D<Cmpt>::Tensor2D()
40 inline Tensor2D<Cmpt>::Tensor2D(const VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>& vs)
42 VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>(vs)
47 inline Tensor2D<Cmpt>::Tensor2D(const SphericalTensor2D<Cmpt>& st)
49 this->v_[XX] = st.ii(); this->v_[XY] = 0;
50 this->v_[YX] = 0; this->v_[YY] = st.ii();
55 inline Tensor2D<Cmpt>::Tensor2D
57 const Cmpt txx, const Cmpt txy,
58 const Cmpt tyx, const Cmpt tyy
61 this->v_[XX] = txx; this->v_[XY] = txy;
62 this->v_[YX] = tyx; this->v_[YY] = tyy;
67 inline Tensor2D<Cmpt>::Tensor2D(Istream& is)
69 VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>(is)
73 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76 inline const Vector2D<Cmpt>& Tensor2D<Cmpt>::x() const
78 return reinterpret_cast<const Vector2D<Cmpt>&>(this->v_[XX]);
82 inline const Vector2D<Cmpt>& Tensor2D<Cmpt>::y() const
84 return reinterpret_cast<const Vector2D<Cmpt>&>(this->v_[YX]);
89 inline Vector2D<Cmpt>& Tensor2D<Cmpt>::x()
91 return reinterpret_cast<Vector2D<Cmpt>&>(this->v_[XX]);
95 inline Vector2D<Cmpt>& Tensor2D<Cmpt>::y()
97 return reinterpret_cast<Vector2D<Cmpt>&>(this->v_[YX]);
101 template <class Cmpt>
102 inline const Cmpt& Tensor2D<Cmpt>::xx() const
107 template <class Cmpt>
108 inline const Cmpt& Tensor2D<Cmpt>::xy() const
113 template <class Cmpt>
114 inline const Cmpt& Tensor2D<Cmpt>::yx() const
119 template <class Cmpt>
120 inline const Cmpt& Tensor2D<Cmpt>::yy() const
126 template <class Cmpt>
127 inline Cmpt& Tensor2D<Cmpt>::xx()
132 template <class Cmpt>
133 inline Cmpt& Tensor2D<Cmpt>::xy()
138 template <class Cmpt>
139 inline Cmpt& Tensor2D<Cmpt>::yx()
144 template <class Cmpt>
145 inline Cmpt& Tensor2D<Cmpt>::yy()
151 template <class Cmpt>
152 inline Tensor2D<Cmpt> Tensor2D<Cmpt>::T() const
154 return Tensor2D<Cmpt>
162 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
164 template <class Cmpt>
165 inline void Tensor2D<Cmpt>::operator=(const SphericalTensor2D<Cmpt>& st)
167 this->v_[XX] = st.ii(); this->v_[XY] = 0;
168 this->v_[YX] = 0; this->v_[YY] = st.ii();
173 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
175 //- Inner-product between two tensors
176 template <class Cmpt>
177 inline typename innerProduct<Tensor2D<Cmpt>, Tensor2D<Cmpt> >::type
178 operator&(const Tensor2D<Cmpt>& t1, const Tensor2D<Cmpt>& t2)
180 return Tensor2D<Cmpt>
182 t1.xx()*t2.xx() + t1.xy()*t2.yx(),
183 t1.xx()*t2.xy() + t1.xy()*t2.yy(),
185 t1.yx()*t2.xx() + t1.yy()*t2.yx(),
186 t1.yx()*t2.xy() + t1.yy()*t2.yy()
190 //- Inner-product between a tensor and a vector
191 template <class Cmpt>
192 inline typename innerProduct<Tensor2D<Cmpt>, Vector2D<Cmpt> >::type
193 operator&(const Tensor2D<Cmpt>& t, const Vector2D<Cmpt>& v)
195 return Vector2D<Cmpt>
197 t.xx()*v.x() + t.xy()*v.y(),
198 t.yx()*v.x() + t.yy()*v.y()
202 //- Inner-product between a vector and a tensor
203 template <class Cmpt>
204 inline typename innerProduct<Vector2D<Cmpt>, Tensor2D<Cmpt> >::type
205 operator&(const Vector2D<Cmpt>& v, const Tensor2D<Cmpt>& t)
207 return Vector2D<Cmpt>
209 v.x()*t.xx() + v.y()*t.yx(),
210 v.x()*t.xy() + v.y()*t.yy()
214 //- Outer-product between two vectors
215 template <class Cmpt>
216 inline typename outerProduct<Vector2D<Cmpt>, Vector2D<Cmpt> >::type
217 operator*(const Vector2D<Cmpt>& v1, const Vector2D<Cmpt>& v2)
219 return Tensor2D<Cmpt>
221 v1.x()*v2.x(), v1.x()*v2.y(),
222 v1.y()*v2.x(), v1.y()*v2.y()
227 //- Return the trace of a tensor
228 template <class Cmpt>
229 inline Cmpt tr(const Tensor2D<Cmpt>& t)
231 return t.xx() + t.yy();
235 //- Return the spherical part of a tensor
236 template <class Cmpt>
237 inline SphericalTensor2D<Cmpt> sph(const Tensor2D<Cmpt>& t)
243 //- Return the symmetric part of a tensor
244 template <class Cmpt>
245 inline Tensor2D<Cmpt> symm(const Tensor2D<Cmpt>& t)
247 return Tensor2D<Cmpt>
249 t.xx(), 0.5*(t.xy() + t.yx()),
250 0.5*(t.yx() + t.xy()), t.yy()
254 //- Return the twice the symmetric part of a tensor
255 template <class Cmpt>
256 inline Tensor2D<Cmpt> twoSymm(const Tensor2D<Cmpt>& t)
258 return Tensor2D<Cmpt>
260 t.xx() + t.xx(), t.xy() + t.yx(),
261 t.yx() + t.xy(), t.yy() + t.yy()
265 //- Return the skew-symmetric part of a tensor
266 template <class Cmpt>
267 inline Tensor2D<Cmpt> skew(const Tensor2D<Cmpt>& t)
269 return Tensor2D<Cmpt>
271 0.0, 0.5*(t.xy() - t.yx()),
272 0.5*(t.yx() - t.xy()), 0.0
277 //- Return the deviatoric part of a tensor
278 template <class Cmpt>
279 inline Tensor2D<Cmpt> dev(const Tensor2D<Cmpt>& t)
281 return t - SphericalTensor2D<Cmpt>::oneThirdI*tr(t);
285 //- Return the deviatoric part of a tensor
286 template <class Cmpt>
287 inline Tensor2D<Cmpt> dev2(const Tensor2D<Cmpt>& t)
289 return t - SphericalTensor2D<Cmpt>::twoThirdsI*tr(t);
293 //- Return the determinant of a tensor
294 template <class Cmpt>
295 inline Cmpt det(const Tensor2D<Cmpt>& t)
297 return(t.xx()*t.yy() - t.xy()*t.yx());
301 //- Return the cofactor tensor of a tensor
302 template <class Cmpt>
303 inline Tensor2D<Cmpt> cof(const Tensor2D<Cmpt>& t)
305 return Tensor2D<Cmpt>
313 //- Return the inverse of a tensor given the determinant
314 template <class Cmpt>
315 inline Tensor2D<Cmpt> inv(const Tensor2D<Cmpt>& t, const Cmpt dett)
321 //- Return the inverse of a tensor
322 template <class Cmpt>
323 inline Tensor2D<Cmpt> inv(const Tensor2D<Cmpt>& t)
325 return inv(t, det(t));
329 //- Return the 1st invariant of a tensor
330 template <class Cmpt>
331 inline Cmpt invariantI(const Tensor2D<Cmpt>& t)
337 //- Return the 2nd invariant of a tensor
338 template <class Cmpt>
339 inline Cmpt invariantII(const Tensor2D<Cmpt>& t)
346 t.xx()*t.xx() + t.xy()*t.xy()
347 + t.yx()*t.yx() + t.yy()*t.yy()
353 //- Return the 3rd invariant of a tensor
354 template <class Cmpt>
355 inline Cmpt invariantIII(const Tensor2D<Cmpt>& t)
363 template <class Cmpt>
364 inline Tensor2D<Cmpt>
365 operator+(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
367 return Tensor2D<Cmpt>
369 st1.ii() + t2.xx(), t2.xy(),
370 t2.yx(), st1.ii() + t2.yy()
375 template <class Cmpt>
376 inline Tensor2D<Cmpt>
377 operator+(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
379 return Tensor2D<Cmpt>
381 t1.xx() + st2.ii(), t1.xy(),
382 t1.yx(), t1.yy() + st2.ii()
387 template <class Cmpt>
388 inline Tensor2D<Cmpt>
389 operator-(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
391 return Tensor2D<Cmpt>
393 st1.ii() - t2.xx(), -t2.xy(),
394 -t2.yx(), st1.ii() - t2.yy()
399 template <class Cmpt>
400 inline Tensor2D<Cmpt>
401 operator-(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
403 return Tensor2D<Cmpt>
405 t1.xx() - st2.ii(), t1.xy(),
406 t1.yx(), t1.yy() - st2.ii()
411 //- Inner-product between a spherical tensor and a tensor
412 template <class Cmpt>
413 inline Tensor2D<Cmpt>
414 operator&(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
416 return Tensor2D<Cmpt>
426 //- Inner-product between a tensor and a spherical tensor
427 template <class Cmpt>
428 inline Tensor2D<Cmpt>
429 operator&(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
431 return Tensor2D<Cmpt>
442 //- Double-dot-product between a spherical tensor and a tensor
443 template <class Cmpt>
445 operator&&(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
447 return(st1.ii()*t2.xx() + st1.ii()*t2.yy());
451 //- Double-dot-product between a tensor and a spherical tensor
452 template <class Cmpt>
454 operator&&(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
456 return(t1.xx()*st2.ii() + t1.yy()*st2.ii());
461 class typeOfSum<SphericalTensor2D<Cmpt>, Tensor2D<Cmpt> >
465 typedef Tensor2D<Cmpt> type;
469 class typeOfSum<Tensor2D<Cmpt>, SphericalTensor2D<Cmpt> >
473 typedef Tensor2D<Cmpt> type;
478 class innerProduct<Tensor2D<Cmpt>, Tensor2D<Cmpt> >
482 typedef Tensor2D<Cmpt> type;
486 class innerProduct<SphericalTensor2D<Cmpt>, Tensor2D<Cmpt> >
490 typedef Tensor2D<Cmpt> type;
494 class innerProduct<Tensor2D<Cmpt>, SphericalTensor2D<Cmpt> >
498 typedef Tensor2D<Cmpt> type;
502 class innerProduct<Tensor2D<Cmpt>, Vector2D<Cmpt> >
506 typedef Vector2D<Cmpt> type;
510 class innerProduct<Vector2D<Cmpt>, Tensor2D<Cmpt> >
514 typedef Vector2D<Cmpt> type;
518 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
520 } // End namespace Foam
522 // ************************************************************************* //