SymmTensorI.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "Tensor.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class Cmpt>
35 :
37 {}
38 
39 
40 template<class Cmpt>
41 template<class Cmpt2>
43 (
44  const VectorSpace<SymmTensor<Cmpt2>, Cmpt2, 6>& vs
45 )
46 :
47  SymmTensor::vsType(vs)
48 {}
49 
50 
51 template<class Cmpt>
53 {
54  this->v_[XX] = st.ii(); this->v_[XY] = Zero; this->v_[XZ] = Zero;
55  this->v_[YY] = st.ii(); this->v_[YZ] = Zero;
56  this->v_[ZZ] = st.ii();
57 }
58 
59 
60 template<class Cmpt>
62 (
63  const Vector<Cmpt>& x,
64  const Vector<Cmpt>& y,
65  const Vector<Cmpt>& z,
66  const bool transposed /* ignored */
67 )
68 {
69  this->rows(x, y, z);
70 }
71 
72 
73 template<class Cmpt>
75 (
76  const Cmpt txx, const Cmpt txy, const Cmpt txz,
77  const Cmpt tyy, const Cmpt tyz,
78  const Cmpt tzz
79 )
80 {
81  this->v_[XX] = txx; this->v_[XY] = txy; this->v_[XZ] = txz;
82  this->v_[YY] = tyy; this->v_[YZ] = tyz;
83  this->v_[ZZ] = tzz;
84 }
85 
86 
87 template<class Cmpt>
89 :
91 {}
92 
93 
94 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
95 
96 template<class Cmpt>
98 {
99  return Vector<Cmpt>(this->v_[XX], this->v_[XY], this->v_[XZ]);
100 }
101 
102 
103 template<class Cmpt>
105 {
106  return Vector<Cmpt>(this->v_[XY], this->v_[YY], this->v_[YZ]);
107 }
108 
109 
110 template<class Cmpt>
112 {
113  return Vector<Cmpt>(this->v_[XZ], this->v_[YZ], this->v_[ZZ]);
114 }
115 
116 
117 template<class Cmpt>
118 template<Foam::direction Idx>
120 {
121  if (Idx == 0) return x();
122  else if (Idx == 1) return y();
123  else if (Idx == 2) return z();
125  static_assert(Idx < 3, "Invalid row access");
126  return Zero;
127 }
128 
129 
130 template<class Cmpt>
132 {
133  switch (r)
134  {
135  case 0: return x(); break;
136  case 1: return y(); break;
137  case 2: return z(); break;
138  default:
140  << "Invalid row access " << r << abort(FatalError);
141  }
143  return Zero;
144 }
145 
146 
147 template<class Cmpt>
148 template<Foam::direction Idx>
149 inline void Foam::SymmTensor<Cmpt>::row(const Vector<Cmpt>& v)
150 {
151  if (Idx == 0)
152  {
153  this->v_[XX] = v.x(); this->v_[XY] = v.y(); this->v_[XZ] = v.z();
154  }
155  else if (Idx == 1)
156  {
157  this->v_[XY] = v.x(); this->v_[YY] = v.y(); this->v_[YZ] = v.z();
158  }
159  else if (Idx == 2)
160  {
161  this->v_[XZ] = v.x(); this->v_[YZ] = v.y(); this->v_[ZZ] = v.z();
162  }
164  static_assert(Idx < 3, "Invalid row access");
165 }
166 
167 
168 template<class Cmpt>
170 (
171  const Vector<Cmpt>& x,
172  const Vector<Cmpt>& y,
173  const Vector<Cmpt>& z
174 )
175 {
176  this->v_[XX] = x.x(); this->v_[XY] = x.y(); this->v_[XZ] = x.z();
177  this->v_[YY] = y.y(); this->v_[YZ] = y.z();
178  this->v_[ZZ] = z.z();
179 }
180 
181 
182 template<class Cmpt>
183 inline void Foam::SymmTensor<Cmpt>::row
184 (
185  const direction r,
186  const Vector<Cmpt>& v
187 )
188 {
189  switch (r)
190  {
191  case 0: row<0>(v); break;
192  case 1: row<1>(v); break;
193  case 2: row<2>(v); break;
194  default:
196  << "Invalid row access " << r << abort(FatalError);
197  }
198 }
199 
200 
201 template<class Cmpt>
203 {
204  return Vector<Cmpt>(this->v_[XX], this->v_[YY], this->v_[ZZ]);
205 }
206 
207 
208 template<class Cmpt>
210 {
211  this->v_[XX] = v.x(); this->v_[YY] = v.y(); this->v_[ZZ] = v.z();
212 }
213 
214 
215 template<class Cmpt>
217 {
218  this->v_[XX] += v.x(); this->v_[YY] += v.y(); this->v_[ZZ] += v.z();
219 }
220 
221 
222 template<class Cmpt>
224 {
225  this->v_[XX] -= v.x(); this->v_[YY] -= v.y(); this->v_[ZZ] -= v.z();
226 }
227 
228 
229 template<class Cmpt>
230 inline Foam::scalar Foam::SymmTensor<Cmpt>::diagSqr() const
231 {
232  return
233  (
234  Foam::magSqr(this->xx())
235  + Foam::magSqr(this->yy())
236  + Foam::magSqr(this->zz())
237  );
238 }
239 
240 
241 template<class Cmpt>
242 inline Cmpt Foam::SymmTensor<Cmpt>::det() const
243 {
244  return
245  (
246  xx()*yy()*zz() + xy()*yz()*xz()
247  + xz()*xy()*yz() - xx()*yz()*yz()
248  - xy()*xy()*zz() - xz()*yy()*xz()
249  );
250 }
251 
252 
253 template<class Cmpt>
254 inline Cmpt Foam::SymmTensor<Cmpt>::det2D(const direction excludeCmpt) const
255 {
256  switch (excludeCmpt)
257  {
258  case 0: // Eliminate x
259  {
260  return (yy()*zz() - yz()*yz());
261  }
262 
263  case 1: // Eliminate y
264  {
265  return (xx()*zz() - xz()*xz());
266  }
267  }
269  // Fall-through: Eliminate z
270  return (xx()*yy() - xy()*xy());
271 }
272 
273 
274 template<class Cmpt>
276 {
277  // symmetric: cof() == adjunct()
278  return SymmTensor<Cmpt>
279  (
280  yy()*zz() - yz()*yz(), xz()*yz() - xy()*zz(), xy()*yz() - xz()*yy(),
281  xx()*zz() - xz()*xz(), xy()*xz() - xx()*yz(),
282  xx()*yy() - xy()*xy()
283  );
284 }
285 
286 
287 template<class Cmpt>
289 {
290  // symmetric: cof() == adjunct()
291  return this->adjunct();
292 }
293 
294 
295 template<class Cmpt>
297 (
298  const direction excludeCmpt
299 ) const
300 {
301  switch (excludeCmpt)
302  {
303  case 0: // Eliminate x
304  {
305  return SymmTensor<Cmpt>
306  (
307  Zero, Zero, Zero,
308  zz(), -yz(),
309  yy()
310  );
311  }
312 
313  case 1: // Eliminate y
314  {
315  return SymmTensor<Cmpt>
316  (
317  zz(), Zero, -xz(),
318  Zero, Zero,
319  xx()
320  );
321  }
322  }
323 
324  // Fall-through: Eliminate z
325  return SymmTensor<Cmpt>
326  (
327  yy(), -xy(), Zero,
328  xx(), Zero,
330  );
331 }
332 
333 
334 template<class Cmpt>
336 (
337  const direction excludeCmpt
338 ) const
339 {
340  const Cmpt detval = this->det2D(excludeCmpt);
342  return this->adjunct2D(excludeCmpt)/detval;
343 }
344 
345 
346 // Invert without much error handling
347 template<class Cmpt>
349 {
350  const Cmpt detval = this->det();
351 
352  #ifdef FULLDEBUG
353  if (mag(detval) < VSMALL)
354  {
356  << "Tensor not properly invertible, determinant:"
357  << detval << " tensor:" << *this << nl
358  << abort(FatalError);
359  }
360  #endif
362  return this->adjunct()/detval;
363 }
364 
365 
366 // Invert with some error handling
367 template<class Cmpt>
369 {
370  {
371  // Attempt to identify and handle 2-D cases.
372  // - use diagSqr instead of magSqr for fewer operations
373  const scalar magSqr_xx = Foam::magSqr(xx());
374  const scalar magSqr_yy = Foam::magSqr(yy());
375  const scalar magSqr_zz = Foam::magSqr(zz());
376 
377  // SMALL: 1e-15 (double), 1e-6 (float), but 1e-6 may be adequate
378 
379  const scalar threshold = SMALL * (magSqr_xx + magSqr_yy + magSqr_zz);
380 
381  const bool small_xx = (magSqr_xx < threshold);
382  const bool small_yy = (magSqr_yy < threshold);
383  const bool small_zz = (magSqr_zz < threshold);
384 
385  if (small_xx || small_yy || small_zz)
386  {
387  SymmTensor<Cmpt> work(*this);
388 
389  if (small_xx) { work.xx() += pTraits<Cmpt>::one; }
390  if (small_yy) { work.yy() += pTraits<Cmpt>::one; }
391  if (small_zz) { work.zz() += pTraits<Cmpt>::one; }
392 
393  const Cmpt detval = work.det();
394 
395  if (mag(detval) < ROOTVSMALL)
396  {
397  // Appears to be nearly zero - leave untouched?
398  return SymmTensor<Cmpt>(Zero);
399  }
400 
401  work = work.adjunct()/detval;
402 
403  if (small_xx) { work.xx() -= pTraits<Cmpt>::one; }
404  if (small_yy) { work.yy() -= pTraits<Cmpt>::one; }
405  if (small_zz) { work.zz() -= pTraits<Cmpt>::one; }
406 
407  return work;
408  }
409  }
410 
411  const Cmpt detval = this->det();
412 
413  if (mag(detval) < ROOTVSMALL)
414  {
415  // Appears to be nearly zero - leave untouched?
416  return SymmTensor<Cmpt>(Zero);
417  }
418 
419  return this->adjunct()/detval;
420 }
421 
422 
423 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
424 
425 template<class Cmpt>
427 {
428  this->v_[XX] = st.ii(); this->v_[XY] = Zero; this->v_[XZ] = Zero;
429  this->v_[YY] = st.ii(); this->v_[YZ] = Zero;
430  this->v_[ZZ] = st.ii();
431 }
432 
433 
434 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
435 
436 namespace Foam
437 {
439 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
440 
441 //- Return the trace of a SymmTensor
442 template<class Cmpt>
443 inline Cmpt tr(const SymmTensor<Cmpt>& st)
444 {
445  return st.xx() + st.yy() + st.zz();
446 }
447 
449 //- Return the spherical part of a SymmTensor
450 template<class Cmpt>
452 {
453  return SphericalTensor<Cmpt>
454  (
455  (1.0/3.0)*tr(st)
456  );
457 }
458 
459 
460 //- Return the symmetric part of a SymmTensor, i.e. itself
461 template<class Cmpt>
462 inline const SymmTensor<Cmpt>& symm(const SymmTensor<Cmpt>& st)
463 {
464  return st;
465 }
466 
467 
468 //- Return twice the symmetric part of a SymmTensor
469 template<class Cmpt>
470 inline SymmTensor<Cmpt> twoSymm(const SymmTensor<Cmpt>& st)
471 {
472  return 2*st;
473 }
474 
475 
476 //- Return the deviatoric part of the symmetric part of a SymmTensor
477 template<class Cmpt>
478 inline SymmTensor<Cmpt> devSymm(const SymmTensor<Cmpt>& st)
479 {
480  return dev(st);
481 }
482 
483 
484 //- Return the deviatoric part of twice the symmetric part of a SymmTensor
485 template<class Cmpt>
486 inline SymmTensor<Cmpt> devTwoSymm(const SymmTensor<Cmpt>& st)
487 {
488  return dev2(st);
489 }
490 
492 //- Return the deviatoric part of a SymmTensor
493 template<class Cmpt>
494 inline SymmTensor<Cmpt> dev(const SymmTensor<Cmpt>& st)
495 {
496  return st - sph(st);
497 }
498 
499 
500 //- Return the two-third deviatoric part of a SymmTensor
501 template<class Cmpt>
502 inline SymmTensor<Cmpt> dev2(const SymmTensor<Cmpt>& st)
503 {
504  return st - 2*sph(st);
505 }
506 
507 
508 //- Return the determinant of a SymmTensor
509 template<class Cmpt>
510 inline Cmpt det(const SymmTensor<Cmpt>& st)
511 {
512  return st.det();
513 }
514 
515 
516 //- Return the cofactor of a SymmTensor as a SymmTensor
517 template<class Cmpt>
518 inline SymmTensor<Cmpt> cof(const SymmTensor<Cmpt>& st)
519 {
520  return st.cof();
521 }
522 
523 
524 //- Return the inverse of a SymmTensor, using given determinant value
525 template<class Cmpt>
526 inline SymmTensor<Cmpt> inv(const SymmTensor<Cmpt>& st, const Cmpt detval)
527 {
528  #ifdef FULLDEBUG
529  if (mag(detval) < VSMALL)
530  {
532  << "SymmTensor not properly invertible, determinant:"
533  << detval << " tensor:" << st << nl
534  << abort(FatalError);
535  }
536  #endif
537 
538  return st.adjunct()/detval;
539 }
540 
542 //- Return the inverse of a SymmTensor
543 template<class Cmpt>
544 inline SymmTensor<Cmpt> inv(const SymmTensor<Cmpt>& st)
545 {
546  return st.inv();
547 }
548 
549 
550 //- Return the 1st invariant of a SymmTensor
551 template<class Cmpt>
552 inline Cmpt invariantI(const SymmTensor<Cmpt>& st)
553 {
554  return tr(st);
555 }
556 
557 
558 //- Return the 2nd invariant of a SymmTensor
559 template<class Cmpt>
560 inline Cmpt invariantII(const SymmTensor<Cmpt>& st)
561 {
562  return
563  (
564  st.xx()*st.yy() + st.yy()*st.zz() + st.xx()*st.zz()
565  - st.xy()*st.xy() - st.yz()*st.yz() - st.xz()*st.xz()
566  );
567 }
568 
569 
570 //- Return the 3rd invariant of a SymmTensor
571 template<class Cmpt>
572 inline Cmpt invariantIII(const SymmTensor<Cmpt>& st)
573 {
574  return det(st);
575 }
576 
577 
578 //- Return the inner-product of a SymmTensor with itself
579 template<class Cmpt>
580 inline SymmTensor<Cmpt>
582 {
583  return SymmTensor<Cmpt>
584  (
585  st.xx()*st.xx() + st.xy()*st.xy() + st.xz()*st.xz(),
586  st.xx()*st.xy() + st.xy()*st.yy() + st.xz()*st.yz(),
587  st.xx()*st.xz() + st.xy()*st.yz() + st.xz()*st.zz(),
588 
589  st.xy()*st.xy() + st.yy()*st.yy() + st.yz()*st.yz(),
590  st.xy()*st.xz() + st.yy()*st.yz() + st.yz()*st.zz(),
591 
592  st.xz()*st.xz() + st.yz()*st.yz() + st.zz()*st.zz()
593  );
594 }
596 
597 //- Return the square of Frobenius norm of a SymmTensor
598 template<class Cmpt>
599 inline Foam::scalar magSqr(const SymmTensor<Cmpt>& st)
600 {
601  return
602  (
603  magSqr(st.xx()) + 2*magSqr(st.xy()) + 2*magSqr(st.xz())
604  + magSqr(st.yy()) + 2*magSqr(st.yz())
605  + magSqr(st.zz())
606  );
607 }
608 
609 
610 //- Return the square of a Vector as a SymmTensor
611 template<class Cmpt>
612 inline SymmTensor<Cmpt> sqr(const Vector<Cmpt>& v)
613 {
614  return SymmTensor<Cmpt>
615  (
616  v.x()*v.x(), v.x()*v.y(), v.x()*v.z(),
617  v.y()*v.y(), v.y()*v.z(),
618  v.z()*v.z()
619  );
620 }
621 
622 
623 //- Linear interpolation of symmetric tensors a and b by factor t
624 template<class Cmpt>
625 inline SymmTensor<Cmpt> lerp
626 (
627  const SymmTensor<Cmpt>& a,
628  const SymmTensor<Cmpt>& b,
629  const scalar t
630 )
631 {
632  const scalar onet = (1-t);
633 
634  return SymmTensor<Cmpt>
635  (
636  onet*a.xx() + t*b.xx(),
637  onet*a.xy() + t*b.xy(),
638  onet*a.xz() + t*b.xz(),
639  onet*a.yy() + t*b.yy(),
640  onet*a.yz() + t*b.yz(),
641  onet*a.zz() + t*b.zz()
642  );
643 }
644 
645 
646 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
647 
648 //- Sum of a SphericalTensor and a SymmTensor
649 template<class Cmpt>
650 inline SymmTensor<Cmpt>
651 operator+(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
652 {
653  return SymmTensor<Cmpt>
654  (
655  spt1.ii() + st2.xx(), st2.xy(), st2.xz(),
656  spt1.ii() + st2.yy(), st2.yz(),
657  spt1.ii() + st2.zz()
658  );
659 }
660 
661 
662 //- Sum of a SymmTensor and a SphericalTensor
663 template<class Cmpt>
664 inline SymmTensor<Cmpt>
665 operator+(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2)
666 {
667  return SymmTensor<Cmpt>
668  (
669  st1.xx() + spt2.ii(), st1.xy(), st1.xz(),
670  st1.yy() + spt2.ii(), st1.yz(),
671  st1.zz() + spt2.ii()
672  );
673 }
674 
675 
676 //- Subtract a SymmTensor from a SphericalTensor
677 template<class Cmpt>
678 inline SymmTensor<Cmpt>
679 operator-(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
680 {
681  return SymmTensor<Cmpt>
682  (
683  spt1.ii() - st2.xx(), -st2.xy(), -st2.xz(),
684  spt1.ii() - st2.yy(), -st2.yz(),
685  spt1.ii() - st2.zz()
686  );
687 }
688 
689 
690 //- Subtract a SphericalTensor from a SymmTensor
691 template<class Cmpt>
692 inline SymmTensor<Cmpt>
693 operator-(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2)
694 {
695  return SymmTensor<Cmpt>
696  (
697  st1.xx() - spt2.ii(), st1.xy(), st1.xz(),
698  st1.yy() - spt2.ii(), st1.yz(),
699  st1.zz() - spt2.ii()
700  );
701 }
702 
703 
704 //- Return the Hodge dual of a SymmTensor as a Vector
705 template<class Cmpt>
706 inline Vector<Cmpt> operator*(const SymmTensor<Cmpt>& st)
707 {
708  return Vector<Cmpt>(st.yz(), -st.xz(), st.xy());
709 }
710 
711 
712 //- Division of a SymmTensor by a Cmpt
713 template<class Cmpt>
714 inline SymmTensor<Cmpt>
715 operator/(const SymmTensor<Cmpt>& st, const Cmpt s)
716 {
717  return SymmTensor<Cmpt>
718  (
719  st.xx()/s, st.xy()/s, st.xz()/s,
720  st.yy()/s, st.yz()/s,
721  st.zz()/s
722  );
723 }
724 
725 
726 //- Inner-product of a SymmTensor and a SymmTensor
727 template<class Cmpt>
728 inline Tensor<Cmpt>
729 operator&(const SymmTensor<Cmpt>& st1, const SymmTensor<Cmpt>& st2)
730 {
731  return Tensor<Cmpt>
732  (
733  st1.xx()*st2.xx() + st1.xy()*st2.xy() + st1.xz()*st2.xz(),
734  st1.xx()*st2.xy() + st1.xy()*st2.yy() + st1.xz()*st2.yz(),
735  st1.xx()*st2.xz() + st1.xy()*st2.yz() + st1.xz()*st2.zz(),
736 
737  st1.xy()*st2.xx() + st1.yy()*st2.xy() + st1.yz()*st2.xz(),
738  st1.xy()*st2.xy() + st1.yy()*st2.yy() + st1.yz()*st2.yz(),
739  st1.xy()*st2.xz() + st1.yy()*st2.yz() + st1.yz()*st2.zz(),
740 
741  st1.xz()*st2.xx() + st1.yz()*st2.xy() + st1.zz()*st2.xz(),
742  st1.xz()*st2.xy() + st1.yz()*st2.yy() + st1.zz()*st2.yz(),
743  st1.xz()*st2.xz() + st1.yz()*st2.yz() + st1.zz()*st2.zz()
744  );
745 }
746 
748 //- Inner-product of a SphericalTensor and a SymmTensor
749 template<class Cmpt>
750 inline SymmTensor<Cmpt>
751 operator&(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
752 {
753  return SymmTensor<Cmpt>
754  (
755  spt1.ii()*st2.xx(), spt1.ii()*st2.xy(), spt1.ii()*st2.xz(),
756  spt1.ii()*st2.yy(), spt1.ii()*st2.yz(),
757  spt1.ii()*st2.zz()
758  );
759 }
760 
761 
762 //- Inner-product of a SymmTensor and a SphericalTensor
763 template<class Cmpt>
764 inline SymmTensor<Cmpt>
765 operator&(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2)
766 {
767  return SymmTensor<Cmpt>
768  (
769  st1.xx()*spt2.ii(), st1.xy()*spt2.ii(), st1.xz()*spt2.ii(),
770  st1.yy()*spt2.ii(), st1.yz()*spt2.ii(),
771  st1.zz()*spt2.ii()
772  );
773 }
775 
776 //- Inner-product of a SymmTensor and a Vector
777 template<class Cmpt>
778 inline Vector<Cmpt>
779 operator&(const SymmTensor<Cmpt>& st, const Vector<Cmpt>& v)
780 {
781  return Vector<Cmpt>
782  (
783  st.xx()*v.x() + st.xy()*v.y() + st.xz()*v.z(),
784  st.xy()*v.x() + st.yy()*v.y() + st.yz()*v.z(),
785  st.xz()*v.x() + st.yz()*v.y() + st.zz()*v.z()
786  );
787 }
788 
789 
790 //- Inner-product of a Vector and a SymmTensor
791 template<class Cmpt>
792 inline Vector<Cmpt>
793 operator&(const Vector<Cmpt>& v, const SymmTensor<Cmpt>& st)
794 {
795  return Vector<Cmpt>
796  (
797  v.x()*st.xx() + v.y()*st.xy() + v.z()*st.xz(),
798  v.x()*st.xy() + v.y()*st.yy() + v.z()*st.yz(),
799  v.x()*st.xz() + v.y()*st.yz() + v.z()*st.zz()
800  );
801 }
802 
803 
804 //- Double-inner-product of a SymmTensor and a SymmTensor
805 template<class Cmpt>
806 inline Cmpt
807 operator&&(const SymmTensor<Cmpt>& st1, const SymmTensor<Cmpt>& st2)
808 {
809  return
810  (
811  st1.xx()*st2.xx() + 2*st1.xy()*st2.xy() + 2*st1.xz()*st2.xz()
812  + st1.yy()*st2.yy() + 2*st1.yz()*st2.yz()
813  + st1.zz()*st2.zz()
814  );
815 }
816 
817 
818 //- Double-inner-product of a SphericalTensor and a SymmTensor
819 template<class Cmpt>
820 inline Cmpt
821 operator&&(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
822 {
823  return (spt1.ii()*st2.xx() + spt1.ii()*st2.yy() + spt1.ii()*st2.zz());
824 }
825 
826 
827 //- Double-inner-product of a SymmTensor and a SphericalTensor
828 template<class Cmpt>
829 inline Cmpt
831 {
832  return (st1.xx()*spt2.ii() + st1.yy()*spt2.ii() + st1.zz()*spt2.ii());
833 }
834 
835 
836 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
837 
838 template<class Cmpt>
839 class outerProduct<SymmTensor<Cmpt>, Cmpt>
840 {
841 public:
842 
843  typedef SymmTensor<Cmpt> type;
844 };
845 
846 template<class Cmpt>
847 class outerProduct<Cmpt, SymmTensor<Cmpt>>
848 {
849 public:
850 
851  typedef SymmTensor<Cmpt> type;
852 };
853 
854 template<class Cmpt>
855 class innerProduct<SymmTensor<Cmpt>, SymmTensor<Cmpt>>
856 {
857 public:
858 
859  typedef Tensor<Cmpt> type;
860 };
861 
862 template<class Cmpt>
863 class innerProduct<SymmTensor<Cmpt>, Vector<Cmpt>>
864 {
865 public:
866 
867  typedef Vector<Cmpt> type;
868 };
869 
870 template<class Cmpt>
871 class innerProduct<Vector<Cmpt>, SymmTensor<Cmpt>>
872 {
873 public:
874 
875  typedef Vector<Cmpt> type;
876 };
877 
879 template<class Cmpt>
880 class typeOfSum<SphericalTensor<Cmpt>, SymmTensor<Cmpt>>
881 {
882 public:
883 
884  typedef SymmTensor<Cmpt> type;
885 };
886 
887 template<class Cmpt>
888 class typeOfSum<SymmTensor<Cmpt>, SphericalTensor<Cmpt>>
889 {
890 public:
891 
892  typedef SymmTensor<Cmpt> type;
893 };
894 
895 template<class Cmpt>
896 class innerProduct<SphericalTensor<Cmpt>, SymmTensor<Cmpt>>
897 {
898 public:
899 
900  typedef SymmTensor<Cmpt> type;
901 };
903 template<class Cmpt>
904 class innerProduct<SymmTensor<Cmpt>, SphericalTensor<Cmpt>>
905 {
906 public:
907 
908  typedef SymmTensor<Cmpt> type;
909 };
911 
912 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
913 
914 } // End namespace Foam
915 
916 // ************************************************************************* //
Vector< Cmpt > x() const
Extract vector for row 0.
Definition: SymmTensorI.H:90
Cmpt invariantII(const SymmTensor< Cmpt > &st)
Return the 2nd invariant of a SymmTensor.
Definition: SymmTensorI.H:581
Cmpt det(const SymmTensor< Cmpt > &st)
Return the determinant of a SymmTensor.
Definition: SymmTensorI.H:521
const Cmpt & xz() const noexcept
Definition: SymmTensor.H:152
uint8_t direction
Definition: direction.H:46
A templated (3 x 3) symmetric tensor of objects of <T>, effectively containing 6 elements, derived from VectorSpace.
Definition: SymmTensor.H:50
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
dimensionedSymmTensor sqr(const dimensionedVector &dv)
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:75
Templated vector space.
Definition: VectorSpace.H:52
dimensionSet operator &&(const dimensionSet &ds1, const dimensionSet &ds2)
SymmTensor< Cmpt > devSymm(const SymmTensor< Cmpt > &st)
Return the deviatoric part of the symmetric part of a SymmTensor.
Definition: SymmTensorI.H:481
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
const Cmpt & y() const noexcept
Access to the vector y component.
Definition: Vector.H:140
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:118
dimensionedScalar det(const dimensionedSphericalTensor &dt)
SphericalTensor< Cmpt > sph(const DiagTensor< Cmpt > &dt)
Return the spherical part of a DiagTensor as a SphericalTensor.
Definition: DiagTensorI.H:110
tmp< faMatrix< Type > > operator+(const faMatrix< Type > &, const faMatrix< Type > &)
SymmTensor< Cmpt > safeInv() const
Return inverse, with (ad hoc) failsafe handling of 2D tensors.
Definition: SymmTensorI.H:361
dimensionedSymmTensor twoSymm(const dimensionedSymmTensor &dt)
Cmpt det() const
The determinate.
Definition: SymmTensorI.H:235
const Cmpt & zz() const noexcept
Definition: SymmTensor.H:158
SymmTensor< Cmpt > adjunct() const
Return adjunct matrix (transpose of cofactor matrix)
Definition: SymmTensorI.H:268
void subtractDiag(const Vector< Cmpt > &v)
Subtract from the diagonal.
Definition: SymmTensorI.H:216
Vector< Cmpt > diag() const
Extract the diagonal as a vector.
Definition: SymmTensorI.H:195
A templated (3 x 3) diagonal tensor of objects of <T>, effectively containing 1 element, derived from VectorSpace.
scalar y
dimensionedSymmTensor dev(const dimensionedSymmTensor &dt)
tmp< faMatrix< Type > > operator*(const areaScalarField::Internal &, const faMatrix< Type > &)
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
SymmTensor< Cmpt > inv2D(const direction excludeCmpt) const
Return inverse of 2D tensor (by excluding given direction)
Definition: SymmTensorI.H:329
scalar diagSqr() const
The L2-norm squared of the diagonal.
Definition: SymmTensorI.H:223
Cmpt invariantIII(const SymmTensor< Cmpt > &st)
Return the 3rd invariant of a SymmTensor.
Definition: SymmTensorI.H:595
Vector< Cmpt > y() const
Extract vector for row 1.
Definition: SymmTensorI.H:97
SymmTensor< Cmpt > adjunct2D(const direction excludeCmpt) const
Return 2D adjunct matrix by excluding given direction.
Definition: SymmTensorI.H:290
const Cmpt & ii() const noexcept
SymmTensor< Cmpt > cof() const
Return cofactor matrix (transpose of adjunct matrix)
Definition: SymmTensorI.H:281
const Cmpt & xx() const noexcept
Definition: SymmTensor.H:150
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
errorManip< error > abort(error &err)
Definition: errorManip.H:139
tmp< faMatrix< Type > > operator-(const faMatrix< Type > &)
Unary negation.
SymmTensor & operator=(const SymmTensor &)=default
Copy assignment.
Templated 3D Vector derived from VectorSpace adding construction from 3 components, element access using x(), y() and z() member functions and the inner-product (dot-product) and cross-product operators.
Definition: Vector.H:58
Cmpt det2D(const direction excludeCmpt) const
The 2D determinant by excluding given direction.
Definition: SymmTensorI.H:247
dimensionedSymmTensor innerSqr(const dimensionedSymmTensor &dt)
const Cmpt & x() const noexcept
Access to the vector x component.
Definition: Vector.H:135
dimensioned< Type > lerp(const dimensioned< Type > &a, const dimensioned< Type > &b, const scalar t)
const Cmpt & z() const noexcept
Access to the vector z component.
Definition: Vector.H:145
dimensionedSymmTensor dev2(const dimensionedSymmTensor &dt)
void addDiag(const Vector< Cmpt > &v)
Add to the diagonal.
Definition: SymmTensorI.H:209
const Cmpt & yy() const noexcept
Definition: SymmTensor.H:154
dimensionedSymmTensor symm(const dimensionedSymmTensor &dt)
tmp< GeometricField< Type, faPatchField, areaMesh > > operator &(const faMatrix< Type > &, const DimensionedField< Type, areaMesh > &)
Cmpt invariantI(const SymmTensor< Cmpt > &st)
Return the 1st invariant of a SymmTensor.
Definition: SymmTensorI.H:571
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
SymmTensor< Cmpt > inv() const
Return inverse.
Definition: SymmTensorI.H:341
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) - 2 >::type type
Definition: products.H:155
dimensionedSymmTensor cof(const dimensionedSymmTensor &dt)
Vector< Cmpt > row() const
Extract vector for given row: compile-time check of index.
const Cmpt & xy() const noexcept
Definition: SymmTensor.H:151
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
void rows(const Vector< Cmpt > &x, const Vector< Cmpt > &y, const Vector< Cmpt > &z)
Set row values.
Definition: SymmTensorI.H:163
Namespace for OpenFOAM.
Vector< Cmpt > z() const
Extract vector for row 2.
Definition: SymmTensorI.H:104
SymmTensor< Cmpt > devTwoSymm(const SymmTensor< Cmpt > &st)
Return the deviatoric part of twice the symmetric part of a SymmTensor.
Definition: SymmTensorI.H:491
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127
const Cmpt & yz() const noexcept
Definition: SymmTensor.H:155
SymmTensor()=default
Default construct.