1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 inline Tensor2D<Cmpt>::Tensor2D()
39 inline Tensor2D<Cmpt>::Tensor2D(const VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>& vs)
41 VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>(vs)
46 inline Tensor2D<Cmpt>::Tensor2D(const SphericalTensor2D<Cmpt>& st)
48 this->v_[XX] = st.ii(); this->v_[XY] = 0;
49 this->v_[YX] = 0; this->v_[YY] = st.ii();
54 inline Tensor2D<Cmpt>::Tensor2D
56 const Vector2D<Cmpt>& x,
57 const Vector2D<Cmpt>& y
60 this->v_[XX] = x.x(); this->v_[XY] = x.y();
61 this->v_[YX] = y.x(); this->v_[YY] = y.y();
66 inline Tensor2D<Cmpt>::Tensor2D
68 const Cmpt txx, const Cmpt txy,
69 const Cmpt tyx, const Cmpt tyy
72 this->v_[XX] = txx; this->v_[XY] = txy;
73 this->v_[YX] = tyx; this->v_[YY] = tyy;
78 inline Tensor2D<Cmpt>::Tensor2D(Istream& is)
80 VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>(is)
84 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
87 inline Vector2D<Cmpt> Tensor2D<Cmpt>::x() const
89 return Vector2D<Cmpt>(this->v_[XX], this->v_[XY]);
93 inline Vector2D<Cmpt> Tensor2D<Cmpt>::y() const
95 return Vector2D<Cmpt>(this->v_[YX], this->v_[YY]);
100 inline const Cmpt& Tensor2D<Cmpt>::xx() const
105 template <class Cmpt>
106 inline const Cmpt& Tensor2D<Cmpt>::xy() const
111 template <class Cmpt>
112 inline const Cmpt& Tensor2D<Cmpt>::yx() const
117 template <class Cmpt>
118 inline const Cmpt& Tensor2D<Cmpt>::yy() const
124 template <class Cmpt>
125 inline Cmpt& Tensor2D<Cmpt>::xx()
130 template <class Cmpt>
131 inline Cmpt& Tensor2D<Cmpt>::xy()
136 template <class Cmpt>
137 inline Cmpt& Tensor2D<Cmpt>::yx()
142 template <class Cmpt>
143 inline Cmpt& Tensor2D<Cmpt>::yy()
149 template <class Cmpt>
150 inline Tensor2D<Cmpt> Tensor2D<Cmpt>::T() const
152 return Tensor2D<Cmpt>
160 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
162 template <class Cmpt>
163 inline void Tensor2D<Cmpt>::operator=(const SphericalTensor2D<Cmpt>& st)
165 this->v_[XX] = st.ii(); this->v_[XY] = 0;
166 this->v_[YX] = 0; this->v_[YY] = st.ii();
171 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
173 //- Inner-product between two tensors
174 template <class Cmpt>
175 inline typename innerProduct<Tensor2D<Cmpt>, Tensor2D<Cmpt> >::type
176 operator&(const Tensor2D<Cmpt>& t1, const Tensor2D<Cmpt>& t2)
178 return Tensor2D<Cmpt>
180 t1.xx()*t2.xx() + t1.xy()*t2.yx(),
181 t1.xx()*t2.xy() + t1.xy()*t2.yy(),
183 t1.yx()*t2.xx() + t1.yy()*t2.yx(),
184 t1.yx()*t2.xy() + t1.yy()*t2.yy()
188 //- Inner-product between a tensor and a vector
189 template <class Cmpt>
190 inline typename innerProduct<Tensor2D<Cmpt>, Vector2D<Cmpt> >::type
191 operator&(const Tensor2D<Cmpt>& t, const Vector2D<Cmpt>& v)
193 return Vector2D<Cmpt>
195 t.xx()*v.x() + t.xy()*v.y(),
196 t.yx()*v.x() + t.yy()*v.y()
200 //- Inner-product between a vector and a tensor
201 template <class Cmpt>
202 inline typename innerProduct<Vector2D<Cmpt>, Tensor2D<Cmpt> >::type
203 operator&(const Vector2D<Cmpt>& v, const Tensor2D<Cmpt>& t)
205 return Vector2D<Cmpt>
207 v.x()*t.xx() + v.y()*t.yx(),
208 v.x()*t.xy() + v.y()*t.yy()
212 //- Outer-product between two vectors
213 template <class Cmpt>
214 inline typename outerProduct<Vector2D<Cmpt>, Vector2D<Cmpt> >::type
215 operator*(const Vector2D<Cmpt>& v1, const Vector2D<Cmpt>& v2)
217 return Tensor2D<Cmpt>
219 v1.x()*v2.x(), v1.x()*v2.y(),
220 v1.y()*v2.x(), v1.y()*v2.y()
225 //- Return the trace of a tensor
226 template <class Cmpt>
227 inline Cmpt tr(const Tensor2D<Cmpt>& t)
229 return t.xx() + t.yy();
233 //- Return the spherical part of a tensor
234 template <class Cmpt>
235 inline SphericalTensor2D<Cmpt> sph(const Tensor2D<Cmpt>& t)
241 //- Return the symmetric part of a tensor
242 template <class Cmpt>
243 inline Tensor2D<Cmpt> symm(const Tensor2D<Cmpt>& t)
245 return Tensor2D<Cmpt>
247 t.xx(), 0.5*(t.xy() + t.yx()),
248 0.5*(t.yx() + t.xy()), t.yy()
252 //- Return the twice the symmetric part of a tensor
253 template <class Cmpt>
254 inline Tensor2D<Cmpt> twoSymm(const Tensor2D<Cmpt>& t)
256 return Tensor2D<Cmpt>
258 t.xx() + t.xx(), t.xy() + t.yx(),
259 t.yx() + t.xy(), t.yy() + t.yy()
263 //- Return the skew-symmetric part of a tensor
264 template <class Cmpt>
265 inline Tensor2D<Cmpt> skew(const Tensor2D<Cmpt>& t)
267 return Tensor2D<Cmpt>
269 0.0, 0.5*(t.xy() - t.yx()),
270 0.5*(t.yx() - t.xy()), 0.0
275 //- Return the deviatoric part of a tensor
276 template <class Cmpt>
277 inline Tensor2D<Cmpt> dev(const Tensor2D<Cmpt>& t)
279 return t - SphericalTensor2D<Cmpt>::oneThirdI*tr(t);
283 //- Return the deviatoric part of a tensor
284 template <class Cmpt>
285 inline Tensor2D<Cmpt> dev2(const Tensor2D<Cmpt>& t)
287 return t - SphericalTensor2D<Cmpt>::twoThirdsI*tr(t);
291 //- Return the determinant of a tensor
292 template <class Cmpt>
293 inline Cmpt det(const Tensor2D<Cmpt>& t)
295 return(t.xx()*t.yy() - t.xy()*t.yx());
299 //- Return the cofactor tensor of a tensor
300 template <class Cmpt>
301 inline Tensor2D<Cmpt> cof(const Tensor2D<Cmpt>& t)
303 return Tensor2D<Cmpt>
311 //- Return the inverse of a tensor given the determinant
312 template <class Cmpt>
313 inline Tensor2D<Cmpt> inv(const Tensor2D<Cmpt>& t, const Cmpt dett)
319 //- Return the inverse of a tensor
320 template <class Cmpt>
321 inline Tensor2D<Cmpt> inv(const Tensor2D<Cmpt>& t)
323 return inv(t, det(t));
327 //- Return the 1st invariant of a tensor
328 template <class Cmpt>
329 inline Cmpt invariantI(const Tensor2D<Cmpt>& t)
335 //- Return the 2nd invariant of a tensor
336 template <class Cmpt>
337 inline Cmpt invariantII(const Tensor2D<Cmpt>& t)
344 t.xx()*t.xx() + t.xy()*t.xy()
345 + t.yx()*t.yx() + t.yy()*t.yy()
351 //- Return the 3rd invariant of a tensor
352 template <class Cmpt>
353 inline Cmpt invariantIII(const Tensor2D<Cmpt>& t)
361 template <class Cmpt>
362 inline Tensor2D<Cmpt>
363 operator+(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
365 return Tensor2D<Cmpt>
367 st1.ii() + t2.xx(), t2.xy(),
368 t2.yx(), st1.ii() + t2.yy()
373 template <class Cmpt>
374 inline Tensor2D<Cmpt>
375 operator+(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
377 return Tensor2D<Cmpt>
379 t1.xx() + st2.ii(), t1.xy(),
380 t1.yx(), t1.yy() + st2.ii()
385 template <class Cmpt>
386 inline Tensor2D<Cmpt>
387 operator-(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
389 return Tensor2D<Cmpt>
391 st1.ii() - t2.xx(), -t2.xy(),
392 -t2.yx(), st1.ii() - t2.yy()
397 template <class Cmpt>
398 inline Tensor2D<Cmpt>
399 operator-(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
401 return Tensor2D<Cmpt>
403 t1.xx() - st2.ii(), t1.xy(),
404 t1.yx(), t1.yy() - st2.ii()
409 //- Inner-product between a spherical tensor and a tensor
410 template <class Cmpt>
411 inline Tensor2D<Cmpt>
412 operator&(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
414 return Tensor2D<Cmpt>
424 //- Inner-product between a tensor and a spherical tensor
425 template <class Cmpt>
426 inline Tensor2D<Cmpt>
427 operator&(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
429 return Tensor2D<Cmpt>
440 //- Double-dot-product between a spherical tensor and a tensor
441 template <class Cmpt>
443 operator&&(const SphericalTensor2D<Cmpt>& st1, const Tensor2D<Cmpt>& t2)
445 return(st1.ii()*t2.xx() + st1.ii()*t2.yy());
449 //- Double-dot-product between a tensor and a spherical tensor
450 template <class Cmpt>
452 operator&&(const Tensor2D<Cmpt>& t1, const SphericalTensor2D<Cmpt>& st2)
454 return(t1.xx()*st2.ii() + t1.yy()*st2.ii());
459 class typeOfSum<SphericalTensor2D<Cmpt>, Tensor2D<Cmpt> >
463 typedef Tensor2D<Cmpt> type;
467 class typeOfSum<Tensor2D<Cmpt>, SphericalTensor2D<Cmpt> >
471 typedef Tensor2D<Cmpt> type;
476 class innerProduct<Tensor2D<Cmpt>, Tensor2D<Cmpt> >
480 typedef Tensor2D<Cmpt> type;
484 class innerProduct<SphericalTensor2D<Cmpt>, Tensor2D<Cmpt> >
488 typedef Tensor2D<Cmpt> type;
492 class innerProduct<Tensor2D<Cmpt>, SphericalTensor2D<Cmpt> >
496 typedef Tensor2D<Cmpt> type;
500 class innerProduct<Tensor2D<Cmpt>, Vector2D<Cmpt> >
504 typedef Vector2D<Cmpt> type;
508 class innerProduct<Vector2D<Cmpt>, Tensor2D<Cmpt> >
512 typedef Vector2D<Cmpt> type;
517 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
519 } // End namespace Foam
521 // ************************************************************************* //