Tensor2DI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
27 
28 namespace Foam
29 {
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class Cmpt>
35 {}
36 
37 
38 template<class Cmpt>
40 :
41  VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>(vs)
42 {}
43 
44 
45 template<class Cmpt>
47 {
48  this->v_[XX] = st.xx(); this->v_[XY] = st.xy();
49  this->v_[YX] = st.xy(); this->v_[YY] = st.yy();
50 }
51 
52 
53 template<class Cmpt>
55 {
56  this->v_[XX] = st.ii(); this->v_[XY] = 0;
57  this->v_[YX] = 0; this->v_[YY] = st.ii();
58 }
59 
60 
61 template<class Cmpt>
63 (
64  const Vector2D<Cmpt>& x,
65  const Vector2D<Cmpt>& y
66 )
67 {
68  this->v_[XX] = x.x(); this->v_[XY] = x.y();
69  this->v_[YX] = y.x(); this->v_[YY] = y.y();
70 }
71 
72 
73 template<class Cmpt>
75 (
76  const Cmpt txx, const Cmpt txy,
77  const Cmpt tyx, const Cmpt tyy
78 )
79 {
80  this->v_[XX] = txx; this->v_[XY] = txy;
81  this->v_[YX] = tyx; this->v_[YY] = tyy;
82 }
83 
84 
85 template<class Cmpt>
87 :
88  VectorSpace<Tensor2D<Cmpt>, Cmpt, 4>(is)
89 {}
90 
91 
92 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
93 
94 template<class Cmpt>
96 {
97  return Vector2D<Cmpt>(this->v_[XX], this->v_[XY]);
98 }
99 
100 template<class Cmpt>
102 {
103  return Vector2D<Cmpt>(this->v_[YX], this->v_[YY]);
104 }
105 
106 
107 template<class Cmpt>
108 inline const Cmpt& Tensor2D<Cmpt>::xx() const
109 {
110  return this->v_[XX];
111 }
112 
113 template<class Cmpt>
114 inline const Cmpt& Tensor2D<Cmpt>::xy() const
115 {
116  return this->v_[XY];
117 }
118 
119 template<class Cmpt>
120 inline const Cmpt& Tensor2D<Cmpt>::yx() const
121 {
122  return this->v_[YX];
123 }
124 
125 template<class Cmpt>
126 inline const Cmpt& Tensor2D<Cmpt>::yy() const
127 {
128  return this->v_[YY];
129 }
130 
131 
132 template<class Cmpt>
133 inline Cmpt& Tensor2D<Cmpt>::xx()
134 {
135  return this->v_[XX];
136 }
137 
138 template<class Cmpt>
139 inline Cmpt& Tensor2D<Cmpt>::xy()
140 {
141  return this->v_[XY];
142 }
143 
144 template<class Cmpt>
145 inline Cmpt& Tensor2D<Cmpt>::yx()
146 {
147  return this->v_[YX];
148 }
149 
150 template<class Cmpt>
151 inline Cmpt& Tensor2D<Cmpt>::yy()
152 {
153  return this->v_[YY];
154 }
155 
156 
157 template<class Cmpt>
159 {
160  return Tensor2D<Cmpt>
161  (
162  xx(), yx(),
163  xy(), yy()
164  );
165 }
166 
167 
168 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
169 
170 template<class Cmpt>
172 {
173  this->v_[XX] = st.xx(); this->v_[XY] = st.xy();
174  this->v_[YX] = st.xy(); this->v_[YY] = st.yy();
175 }
176 
177 
178 template<class Cmpt>
180 {
181  this->v_[XX] = st.ii(); this->v_[XY] = 0;
182  this->v_[YX] = 0; this->v_[YY] = st.ii();
183 }
184 
185 
186 
187 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
188 
189 //- Inner-product between two tensors
190 template<class Cmpt>
193 {
194  return Tensor2D<Cmpt>
195  (
196  t1.xx()*t2.xx() + t1.xy()*t2.yx(),
197  t1.xx()*t2.xy() + t1.xy()*t2.yy(),
198 
199  t1.yx()*t2.xx() + t1.yy()*t2.yx(),
200  t1.yx()*t2.xy() + t1.yy()*t2.yy()
201  );
202 }
203 
204 //- Inner-product between a tensor and a vector
205 template<class Cmpt>
206 inline typename innerProduct<Tensor2D<Cmpt>, Vector2D<Cmpt> >::type
208 {
209  return Vector2D<Cmpt>
210  (
211  t.xx()*v.x() + t.xy()*v.y(),
212  t.yx()*v.x() + t.yy()*v.y()
213  );
214 }
215 
216 //- Inner-product between a vector and a tensor
217 template<class Cmpt>
218 inline typename innerProduct<Vector2D<Cmpt>, Tensor2D<Cmpt> >::type
220 {
221  return Vector2D<Cmpt>
222  (
223  v.x()*t.xx() + v.y()*t.yx(),
224  v.x()*t.xy() + v.y()*t.yy()
225  );
226 }
227 
228 //- Outer-product between two vectors
229 template<class Cmpt>
230 inline typename outerProduct<Vector2D<Cmpt>, Vector2D<Cmpt> >::type
232 {
233  return Tensor2D<Cmpt>
234  (
235  v1.x()*v2.x(), v1.x()*v2.y(),
236  v1.y()*v2.x(), v1.y()*v2.y()
237  );
238 }
239 
240 
241 //- Return the trace of a tensor
242 template<class Cmpt>
243 inline Cmpt tr(const Tensor2D<Cmpt>& t)
244 {
245  return t.xx() + t.yy();
246 }
247 
248 
249 //- Return the spherical part of a tensor
250 template<class Cmpt>
252 {
253  return 0.5*tr(t);
254 }
255 
256 
257 //- Return the symmetric part of a tensor
258 template<class Cmpt>
260 {
261  return SymmTensor2D<Cmpt>
262  (
263  t.xx(), 0.5*(t.xy() + t.yx()),
264  t.yy()
265  );
266 }
267 
268 //- Return the twice the symmetric part of a tensor
269 template<class Cmpt>
271 {
272  return SymmTensor2D<Cmpt>
273  (
274  t.xx() + t.xx(), t.xy() + t.yx(),
275  t.yy() + t.yy()
276  );
277 }
278 
279 //- Return the skew-symmetric part of a tensor
280 template<class Cmpt>
282 {
283  return Tensor2D<Cmpt>
284  (
285  0.0, 0.5*(t.xy() - t.yx()),
286  0.5*(t.yx() - t.xy()), 0.0
287  );
288 }
289 
290 
291 //- Return the deviatoric part of a tensor
292 template<class Cmpt>
294 {
296 }
297 
298 
299 //- Return the deviatoric part of a tensor
300 template<class Cmpt>
302 {
304 }
305 
306 
307 //- Return the determinant of a tensor
308 template<class Cmpt>
309 inline Cmpt det(const Tensor2D<Cmpt>& t)
310 {
311  return(t.xx()*t.yy() - t.xy()*t.yx());
312 }
313 
314 
315 //- Return the cofactor tensor of a tensor
316 template<class Cmpt>
318 {
319  return Tensor2D<Cmpt>
320  (
321  t.yy(), -t.xy(),
322  -t.yx(), t.xx()
323  );
324 }
325 
326 
327 //- Return the inverse of a tensor given the determinant
328 template<class Cmpt>
329 inline Tensor2D<Cmpt> inv(const Tensor2D<Cmpt>& t, const Cmpt dett)
330 {
331  return cof(t)/dett;
332 }
333 
334 
335 //- Return the inverse of a tensor
336 template<class Cmpt>
338 {
339  return inv(t, det(t));
340 }
341 
342 
343 //- Return the 1st invariant of a tensor
344 template<class Cmpt>
345 inline Cmpt invariantI(const Tensor2D<Cmpt>& t)
346 {
347  return tr(t);
348 }
349 
350 
351 //- Return the 2nd invariant of a tensor
352 template<class Cmpt>
353 inline Cmpt invariantII(const Tensor2D<Cmpt>& t)
354 {
355  return
356  (
357  0.5*sqr(tr(t))
358  - 0.5*
359  (
360  t.xx()*t.xx() + t.xy()*t.xy()
361  + t.yx()*t.yx() + t.yy()*t.yy()
362  )
363  );
364 }
365 
366 
367 //- Return the 3rd invariant of a tensor
368 template<class Cmpt>
369 inline Cmpt invariantIII(const Tensor2D<Cmpt>& t)
370 {
371  return det(t);
372 }
373 
374 
375 // * * * * * * * * * Mixed Tensor SphericalTensor Operators * * * * * * * * //
376 
377 template<class Cmpt>
378 inline Tensor2D<Cmpt>
380 {
381  return Tensor2D<Cmpt>
382  (
383  st1.ii() + t2.xx(), t2.xy(),
384  t2.yx(), st1.ii() + t2.yy()
385  );
386 }
387 
388 
389 template<class Cmpt>
390 inline Tensor2D<Cmpt>
392 {
393  return Tensor2D<Cmpt>
394  (
395  t1.xx() + st2.ii(), t1.xy(),
396  t1.yx(), t1.yy() + st2.ii()
397  );
398 }
399 
400 
401 template<class Cmpt>
402 inline Tensor2D<Cmpt>
404 {
405  return Tensor2D<Cmpt>
406  (
407  st1.ii() - t2.xx(), -t2.xy(),
408  -t2.yx(), st1.ii() - t2.yy()
409  );
410 }
411 
412 
413 template<class Cmpt>
414 inline Tensor2D<Cmpt>
416 {
417  return Tensor2D<Cmpt>
418  (
419  t1.xx() - st2.ii(), t1.xy(),
420  t1.yx(), t1.yy() - st2.ii()
421  );
422 }
423 
424 
425 //- Inner-product between a spherical tensor and a tensor
426 template<class Cmpt>
427 inline Tensor2D<Cmpt>
429 {
430  return Tensor2D<Cmpt>
431  (
432  st1.ii()*t2.xx(),
433  st1.ii()*t2.xy(),
434  st1.ii()*t2.yx(),
435  st1.ii()*t2.yy()
436  );
437 }
438 
439 
440 //- Inner-product between a tensor and a spherical tensor
441 template<class Cmpt>
442 inline Tensor2D<Cmpt>
444 {
445  return Tensor2D<Cmpt>
446  (
447  t1.xx()*st2.ii(),
448  t1.xy()*st2.ii(),
449 
450  t1.yx()*st2.ii(),
451  t1.yy()*st2.ii()
452  );
453 }
454 
455 
456 //- Double-dot-product between a spherical tensor and a tensor
457 template<class Cmpt>
458 inline Cmpt
460 {
461  return(st1.ii()*t2.xx() + st1.ii()*t2.yy());
462 }
463 
464 
465 //- Double-dot-product between a tensor and a spherical tensor
466 template<class Cmpt>
467 inline Cmpt
469 {
470  return(t1.xx()*st2.ii() + t1.yy()*st2.ii());
471 }
472 
473 
474 // * * * * * * * * * * Mixed Tensor SymmTensor Operators * * * * * * * * * * //
475 
476 template<class Cmpt>
477 inline Tensor2D<Cmpt>
479 {
480  return Tensor2D<Cmpt>
481  (
482  st1.xx() + t2.xx(), st1.xy() + t2.xy(),
483  st1.xy() + t2.yx(), st1.yy() + t2.yy()
484  );
485 }
486 
487 
488 template<class Cmpt>
489 inline Tensor2D<Cmpt>
491 {
492  return Tensor2D<Cmpt>
493  (
494  t1.xx() + st2.xx(), t1.xy() + st2.xy(),
495  t1.yx() + st2.xy(), t1.yy() + st2.yy()
496  );
497 }
498 
499 
500 template<class Cmpt>
501 inline Tensor2D<Cmpt>
503 {
504  return Tensor2D<Cmpt>
505  (
506  st1.xx() - t2.xx(), st1.xy() - t2.xy(),
507  st1.xy() - t2.yx(), st1.yy() - t2.yy()
508  );
509 }
510 
511 
512 template<class Cmpt>
513 inline Tensor2D<Cmpt>
515 {
516  return Tensor2D<Cmpt>
517  (
518  t1.xx() - st2.xx(), t1.xy() - st2.xy(),
519  t1.yx() - st2.xy(), t1.yy() - st2.yy()
520  );
521 }
522 
523 
524 //- Inner-product between a spherical tensor and a tensor
525 template<class Cmpt>
526 inline Tensor2D<Cmpt>
528 {
529  return Tensor2D<Cmpt>
530  (
531  st1.xx()*t2.xx() + st1.xy()*t2.yx(),
532  st1.xx()*t2.xy() + st1.xy()*t2.yy(),
533 
534  st1.xy()*t2.xx() + st1.yy()*t2.yx(),
535  st1.xy()*t2.xy() + st1.yy()*t2.yy()
536  );
537 }
538 
539 
540 //- Inner-product between a tensor and a spherical tensor
541 template<class Cmpt>
542 inline Tensor2D<Cmpt>
544 {
545  return Tensor2D<Cmpt>
546  (
547  t1.xx()*st2.xx() + t1.xy()*st2.xy(),
548  t1.xx()*st2.xy() + t1.xy()*st2.yy(),
549 
550  t1.yx()*st2.xx() + t1.yy()*st2.xy(),
551  t1.yx()*st2.xy() + t1.yy()*st2.yy()
552  );
553 }
554 
555 
556 //- Double-dot-product between a spherical tensor and a tensor
557 template<class Cmpt>
558 inline Cmpt
560 {
561  return
562  (
563  st1.xx()*t2.xx() + st1.xy()*t2.xy()
564  + st1.xy()*t2.yx() + st1.yy()*t2.yy()
565  );
566 }
567 
568 
569 //- Double-dot-product between a tensor and a spherical tensor
570 template<class Cmpt>
571 inline Cmpt
573 {
574  return
575  (
576  t1.xx()*st2.xx() + t1.xy()*st2.xy()
577  + t1.yx()*st2.xy() + t1.yy()*st2.yy()
578  );
579 }
580 
581 
582 template<class Cmpt>
584 {
585 public:
586 
588 };
589 
590 template<class Cmpt>
592 {
593 public:
594 
596 };
597 
598 
599 template<class Cmpt>
600 class innerProduct<Tensor2D<Cmpt>, Tensor2D<Cmpt> >
601 {
602 public:
603 
605 };
606 
607 template<class Cmpt>
609 {
610 public:
611 
613 };
614 
615 template<class Cmpt>
617 {
618 public:
619 
621 };
622 
623 template<class Cmpt>
624 class innerProduct<Tensor2D<Cmpt>, Vector2D<Cmpt> >
625 {
626 public:
627 
629 };
630 
631 template<class Cmpt>
632 class innerProduct<Vector2D<Cmpt>, Tensor2D<Cmpt> >
633 {
634 public:
635 
637 };
638 
639 
640 template<class Cmpt>
641 class outerProduct<Vector2D<Cmpt>, Vector2D<Cmpt> >
642 {
643 public:
644 
646 };
647 
648 
649 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
650 
651 } // End namespace Foam
652 
653 // ************************************************************************* //
Foam::outerProduct< Vector2D< Cmpt >, Vector2D< Cmpt > >::type
Tensor2D< Cmpt > type
Definition: Tensor2DI.H:645
Foam::symm
dimensionedSymmTensor symm(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:82
Foam::Tensor2D::T
Tensor2D< Cmpt > T() const
Transpose.
Definition: Tensor2DI.H:158
Foam::invariantIII
Cmpt invariantIII(const SymmTensor< Cmpt > &st)
Return the 3rd invariant of a symmetric tensor.
Definition: SymmTensorI.H:414
Foam::skew
dimensionedTensor skew(const dimensionedTensor &dt)
Definition: dimensionedTensor.C:135
Foam::operator&
tmp< GeometricField< Type, fvPatchField, volMesh > > operator&(const fvMatrix< Type > &, const DimensionedField< Type, volMesh > &)
Foam::invariantI
Cmpt invariantI(const SymmTensor< Cmpt > &st)
Return the 1st invariant of a symmetric tensor.
Definition: SymmTensorI.H:389
Foam::Tensor2D::xx
const Cmpt & xx() const
Definition: Tensor2DI.H:108
Foam::innerProduct
Definition: products.H:89
Foam::SymmTensor2D
Templated 2D symmetric tensor derived from VectorSpace adding construction from 4 components,...
Definition: SymmTensor2D.H:53
Foam::innerProduct< Tensor2D< Cmpt >, SphericalTensor2D< Cmpt > >::type
Tensor2D< Cmpt > type
Definition: Tensor2DI.H:620
Foam::Vector2D
Templated 2D Vector derived from VectorSpace adding construction from 2 components,...
Definition: Vector2D.H:51
Foam::dev2
dimensionedSymmTensor dev2(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:115
Foam::Tensor2D
Templated 2D tensor derived from VectorSpace adding construction from 4 components,...
Definition: Tensor2D.H:56
Foam::innerProduct< Tensor2D< Cmpt >, Tensor2D< Cmpt > >::type
Tensor2D< Cmpt > type
Definition: Tensor2DI.H:604
Foam::VectorSpace
Templated vector space.
Definition: VectorSpace.H:52
Foam::Tensor2D::yy
const Cmpt & yy() const
Definition: Tensor2DI.H:126
Foam::operator-
tmp< fvMatrix< Type > > operator-(const fvMatrix< Type > &)
Foam::Vector2D::y
const Cmpt & y() const
Definition: Vector2DI.H:73
Foam::typeOfSum
Definition: products.H:55
Foam::Tensor2D::yx
const Cmpt & yx() const
Definition: Tensor2DI.H:120
Foam::innerProduct< Vector2D< Cmpt >, Tensor2D< Cmpt > >::type
Vector2D< Cmpt > type
Definition: Tensor2DI.H:636
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::inv
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:71
Foam::Tensor2D::x
Vector2D< Cmpt > x() const
Definition: Tensor2DI.H:95
Foam::Vector2D::x
const Cmpt & x() const
Definition: Vector2DI.H:67
Foam::typeOfSum< Tensor2D< Cmpt >, SphericalTensor2D< Cmpt > >::type
Tensor2D< Cmpt > type
Definition: Tensor2DI.H:595
Foam::typeOfSum< SphericalTensor2D< Cmpt >, Tensor2D< Cmpt > >::type
Tensor2D< Cmpt > type
Definition: Tensor2DI.H:587
Foam::Tensor2D::y
Vector2D< Cmpt > y() const
Definition: Tensor2DI.H:101
Foam::sph
SphericalTensor< Cmpt > sph(const DiagTensor< Cmpt > &dt)
Return the spherical part of a diagonal tensor.
Definition: DiagTensorI.H:281
Foam::operator&&
dimensioned< typename scalarProduct< Type1, Type2 >::type > operator&&(const dimensioned< Type1 > &, const dimensioned< Type2 > &)
Foam::innerProduct< Tensor2D< Cmpt >, Vector2D< Cmpt > >::type
Vector2D< Cmpt > type
Definition: Tensor2DI.H:628
Foam::invariantII
Cmpt invariantII(const SymmTensor< Cmpt > &st)
Return the 2nd invariant of a symmetric tensor.
Definition: SymmTensorI.H:397
Foam::Tensor2D::Tensor2D
Tensor2D()
Construct null.
Definition: Tensor2DI.H:34
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::SymmTensor2D::yy
const Cmpt & yy() const
Definition: SymmTensor2DI.H:93
Foam::cof
dimensionedSymmTensor cof(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:137
Foam::operator*
tmp< fvMatrix< Type > > operator*(const DimensionedField< scalar, volMesh > &, const fvMatrix< Type > &)
Foam::SymmTensor2D::xx
const Cmpt & xx() const
Definition: SymmTensor2DI.H:81
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:49
Foam::SymmTensor2D::xy
const Cmpt & xy() const
Definition: SymmTensor2DI.H:87
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::Tensor2D::operator=
void operator=(const SymmTensor2D< Cmpt > &)
Copy SymmTensor2D.
Definition: Tensor2DI.H:171
Foam::SphericalTensor2D::ii
const Cmpt & ii() const
Definition: SphericalTensor2DI.H:71
Foam::tr
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:49
Foam::det
dimensionedScalar det(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:60
Foam::innerProduct< SphericalTensor2D< Cmpt >, Tensor2D< Cmpt > >::type
Tensor2D< Cmpt > type
Definition: Tensor2DI.H:612
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::twoSymm
dimensionedSymmTensor twoSymm(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:93
Foam::operator+
tmp< fvMatrix< Type > > operator+(const fvMatrix< Type > &, const fvMatrix< Type > &)
Foam::outerProduct
Definition: products.H:64
Foam::Tensor2D::xy
const Cmpt & xy() const
Definition: Tensor2DI.H:114
Foam::SphericalTensor2D
Templated 2D sphericalTensor derived from VectorSpace adding construction from 1 component,...
Definition: SphericalTensor2D.H:51
y
scalar y
Definition: LISASMDCalcMethod1.H:14
Foam::dev
dimensionedSymmTensor dev(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:104