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