1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
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 * * * * * * * * * * * * * * //
36 inline Tensor2D<Cmpt>::Tensor2D()
40 //- Construct given VectorSpace
42 inline Tensor2D<Cmpt>::Tensor2D(const VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>& vs)
44 VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>(vs)
48 //- Construct given SphericalTensor2D
50 inline Tensor2D<Cmpt>::Tensor2D(const SphericalTensor2D<Cmpt>& st)
52 this->v_[XX] = st.ii(); this->v_[XY] = 0;
53 this->v_[YX] = 0; this->v_[YY] = st.ii();
57 //- Construct from components
59 inline Tensor2D<Cmpt>::Tensor2D
61 const Cmpt txx, const Cmpt txy,
62 const Cmpt tyx, const Cmpt tyy
65 this->v_[XX] = txx; this->v_[XY] = txy;
66 this->v_[YX] = tyx; this->v_[YY] = tyy;
70 //- Construct from Istream
72 inline Tensor2D<Cmpt>::Tensor2D(Istream& is)
74 VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>(is)
78 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
81 inline const Vector2D<Cmpt>& Tensor2D<Cmpt>::x() const
83 return reinterpret_cast<const Vector2D<Cmpt>&>(this->v_[XX]);
87 inline const Vector2D<Cmpt>& Tensor2D<Cmpt>::y() const
89 return reinterpret_cast<const Vector2D<Cmpt>&>(this->v_[YX]);
94 inline Vector2D<Cmpt>& Tensor2D<Cmpt>::x()
96 return reinterpret_cast<Vector2D<Cmpt>&>(this->v_[XX]);
100 inline Vector2D<Cmpt>& Tensor2D<Cmpt>::y()
102 return reinterpret_cast<Vector2D<Cmpt>&>(this->v_[YX]);
106 template <class Cmpt>
107 inline const Cmpt& Tensor2D<Cmpt>::xx() const
112 template <class Cmpt>
113 inline const Cmpt& Tensor2D<Cmpt>::xy() const
118 template <class Cmpt>
119 inline const Cmpt& Tensor2D<Cmpt>::yx() const
124 template <class Cmpt>
125 inline const Cmpt& Tensor2D<Cmpt>::yy() const
131 template <class Cmpt>
132 inline Cmpt& Tensor2D<Cmpt>::xx()
137 template <class Cmpt>
138 inline Cmpt& Tensor2D<Cmpt>::xy()
143 template <class Cmpt>
144 inline Cmpt& Tensor2D<Cmpt>::yx()
149 template <class Cmpt>
150 inline Cmpt& Tensor2D<Cmpt>::yy()
156 //- Return tensor transpose
157 template <class Cmpt>
158 inline Tensor2D<Cmpt> Tensor2D<Cmpt>::T() const
160 return Tensor2D<Cmpt>
168 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
170 template <class Cmpt>
171 inline void Tensor2D<Cmpt>::operator=(const SphericalTensor2D<Cmpt>& st)
173 this->v_[XX] = st.ii(); this->v_[XY] = 0;
174 this->v_[YX] = 0; this->v_[YY] = st.ii();
179 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
181 //- Inner-product between two tensors
182 template <class Cmpt>
183 inline typename innerProduct<Tensor2D<Cmpt>, Tensor2D<Cmpt> >::type
184 operator&(const Tensor2D<Cmpt>& t1, const Tensor2D<Cmpt>& t2)
186 return Tensor2D<Cmpt>
188 t1.xx()*t2.xx() + t1.xy()*t2.yx(),
189 t1.xx()*t2.xy() + t1.xy()*t2.yy(),
191 t1.yx()*t2.xx() + t1.yy()*t2.yx(),
192 t1.yx()*t2.xy() + t1.yy()*t2.yy()
196 //- Inner-product between a tensor and a vector
197 template <class Cmpt>
198 inline typename innerProduct<Tensor2D<Cmpt>, Vector2D<Cmpt> >::type
199 operator&(const Tensor2D<Cmpt>& t, const Vector2D<Cmpt>& v)
201 return Vector2D<Cmpt>
203 t.xx()*v.x() + t.xy()*v.y(),
204 t.yx()*v.x() + t.yy()*v.y()
208 //- Inner-product between a vector and a tensor
209 template <class Cmpt>
210 inline typename innerProduct<Vector2D<Cmpt>, Tensor2D<Cmpt> >::type
211 operator&(const Vector2D<Cmpt>& v, const Tensor2D<Cmpt>& t)
213 return Vector2D<Cmpt>
215 v.x()*t.xx() + v.y()*t.yx(),
216 v.x()*t.xy() + v.y()*t.yy()
220 //- Outer-product between two vectors
221 template <class Cmpt>
222 inline typename outerProduct<Vector2D<Cmpt>, Vector2D<Cmpt> >::type
223 operator*(const Vector2D<Cmpt>& v1, const Vector2D<Cmpt>& v2)
225 return Tensor2D<Cmpt>
227 v1.x()*v2.x(), v1.x()*v2.y(),
228 v1.y()*v2.x(), v1.y()*v2.y()
233 //- Return the trace of a tensor
234 template <class Cmpt>
235 inline Cmpt tr(const Tensor2D<Cmpt>& t)
237 return t.xx() + t.yy();
241 //- Return the spherical part of a tensor
242 template <class Cmpt>
243 inline SphericalTensor2D<Cmpt> sph(const Tensor2D<Cmpt>& t)
249 //- Return the symmetric part of a tensor
250 template <class Cmpt>
251 inline Tensor2D<Cmpt> symm(const Tensor2D<Cmpt>& t)
253 return Tensor2D<Cmpt>
255 t.xx(), 0.5*(t.xy() + t.yx()),
256 0.5*(t.yx() + t.xy()), t.yy()
260 //- Return the twice the symmetric part of a tensor
261 template <class Cmpt>
262 inline Tensor2D<Cmpt> twoSymm(const Tensor2D<Cmpt>& t)
264 return Tensor2D<Cmpt>
266 t.xx() + t.xx(), t.xy() + t.yx(),
267 t.yx() + t.xy(), t.yy() + t.yy()
271 //- Return the skew-symmetric part of a tensor
272 template <class Cmpt>
273 inline Tensor2D<Cmpt> skew(const Tensor2D<Cmpt>& t)
275 return Tensor2D<Cmpt>
277 0.0, 0.5*(t.xy() - t.yx()),
278 0.5*(t.yx() - t.xy()), 0.0
283 //- Return the deviatoric part of a tensor
284 template <class Cmpt>
285 inline Tensor2D<Cmpt> dev(const Tensor2D<Cmpt>& t)
287 return t - SphericalTensor2D<Cmpt>::oneThirdI*tr(t);
291 //- Return the deviatoric part of a tensor
292 template <class Cmpt>
293 inline Tensor2D<Cmpt> dev2(const Tensor2D<Cmpt>& t)
295 return t - SphericalTensor2D<Cmpt>::twoThirdsI*tr(t);
299 //- Return the determinant of a tensor
300 template <class Cmpt>
301 inline Cmpt det(const Tensor2D<Cmpt>& t)
303 return(t.xx()*t.yy() - t.xy()*t.yx());
306 //- Return the inverse of a tensor give the determinant
307 template <class Cmpt>
308 inline Tensor2D<Cmpt> inv(const Tensor2D<Cmpt>& t, const Cmpt dett)
310 return Tensor2D<Cmpt>
317 //- Return the inverse of a tensor
318 template <class Cmpt>
319 inline Tensor2D<Cmpt> inv(const Tensor2D<Cmpt>& t)
321 return inv(t, det(t));
325 //- Return the 1st invariant of a tensor
326 template <class Cmpt>
327 inline Cmpt invariantI(const Tensor2D<Cmpt>& t)
333 //- Return the 2nd invariant of a tensor
334 template <class Cmpt>
335 inline Cmpt invariantII(const Tensor2D<Cmpt>& t)
342 t.xx()*t.xx() + t.xy()*t.xy()
343 + t.yx()*t.yx() + t.yy()*t.yy()
349 //- Return the 3rd invariant of a tensor
350 template <class Cmpt>
351 inline Cmpt invariantIII(const Tensor2D<Cmpt>& t)
359 template <class Cmpt>
360 inline Tensor2D<Cmpt>
361 operator+(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
363 return Tensor2D<Cmpt>
365 st1.ii() + t2.xx(), t2.xy(),
366 t2.yx(), st1.ii() + t2.yy()
371 template <class Cmpt>
372 inline Tensor2D<Cmpt>
373 operator+(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
375 return Tensor2D<Cmpt>
377 t1.xx() + st2.ii(), t1.xy(),
378 t1.yx(), t1.yy() + st2.ii()
383 template <class Cmpt>
384 inline Tensor2D<Cmpt>
385 operator-(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
387 return Tensor2D<Cmpt>
389 st1.ii() - t2.xx(), -t2.xy(),
390 -t2.yx(), st1.ii() - t2.yy()
395 template <class Cmpt>
396 inline Tensor2D<Cmpt>
397 operator-(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
399 return Tensor2D<Cmpt>
401 t1.xx() - st2.ii(), t1.xy(),
402 t1.yx(), t1.yy() - st2.ii()
407 //- Inner-product between a spherical tensor and a tensor
408 template <class Cmpt>
409 inline Tensor2D<Cmpt>
410 operator&(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
412 return Tensor2D<Cmpt>
422 //- Inner-product between a tensor and a spherical tensor
423 template <class Cmpt>
424 inline Tensor2D<Cmpt>
425 operator&(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
427 return Tensor2D<Cmpt>
438 //- Double-dot-product between a spherical tensor and a tensor
439 template <class Cmpt>
441 operator&&(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
443 return(st1.ii()*t2.xx() + st1.ii()*t2.yy());
447 //- Double-dot-product between a tensor and a spherical tensor
448 template <class Cmpt>
450 operator&&(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
452 return(t1.xx()*st2.ii() + t1.yy()*st2.ii());
457 class typeOfSum<SphericalTensor2D<Cmpt>, Tensor2D<Cmpt> >
461 typedef Tensor2D<Cmpt> type;
465 class typeOfSum<Tensor2D<Cmpt>, SphericalTensor2D<Cmpt> >
469 typedef Tensor2D<Cmpt> type;
474 class innerProduct<SphericalTensor2D<Cmpt>, Tensor2D<Cmpt> >
478 typedef Tensor2D<Cmpt> type;
482 class innerProduct<Tensor2D<Cmpt>, SphericalTensor2D<Cmpt> >
486 typedef Tensor2D<Cmpt> type;
490 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
492 } // End namespace Foam
494 // ************************************************************************* //