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-2025 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 bool Foam::SymmTensor<Cmpt>::is_identity(const scalar tol) const
243 {
244  return
245  (
246  Foam::mag(xx() - pTraits<Cmpt>::one) < tol
247  && Foam::mag(yy() - pTraits<Cmpt>::one) < tol
248  && Foam::mag(zz() - pTraits<Cmpt>::one) < tol
249  && Foam::mag(xy()) < tol
250  && Foam::mag(xz()) < tol
251  && Foam::mag(yz()) < tol
252  );
253 }
254 
255 
256 template<class Cmpt>
257 inline Cmpt Foam::SymmTensor<Cmpt>::det() const
258 {
259  return
260  (
261  xx()*yy()*zz() + xy()*yz()*xz()
262  + xz()*xy()*yz() - xx()*yz()*yz()
263  - xy()*xy()*zz() - xz()*yy()*xz()
264  );
265 }
266 
267 
268 template<class Cmpt>
269 inline Cmpt Foam::SymmTensor<Cmpt>::det2D(const direction excludeCmpt) const
270 {
271  switch (excludeCmpt)
272  {
273  case 0: // Eliminate x
274  {
275  return (yy()*zz() - yz()*yz());
276  }
277 
278  case 1: // Eliminate y
279  {
280  return (xx()*zz() - xz()*xz());
281  }
282  }
284  // Fall-through: Eliminate z
285  return (xx()*yy() - xy()*xy());
286 }
287 
288 
289 template<class Cmpt>
291 {
292  // symmetric: cof() == adjunct()
293  return SymmTensor<Cmpt>
294  (
295  yy()*zz() - yz()*yz(), xz()*yz() - xy()*zz(), xy()*yz() - xz()*yy(),
296  xx()*zz() - xz()*xz(), xy()*xz() - xx()*yz(),
297  xx()*yy() - xy()*xy()
298  );
299 }
300 
301 
302 template<class Cmpt>
304 {
305  // symmetric: cof() == adjunct()
306  return this->adjunct();
307 }
308 
309 
310 template<class Cmpt>
312 (
313  const direction excludeCmpt
314 ) const
315 {
316  switch (excludeCmpt)
317  {
318  case 0: // Eliminate x
319  {
320  return SymmTensor<Cmpt>
321  (
322  Zero, Zero, Zero,
323  zz(), -yz(),
324  yy()
325  );
326  }
327 
328  case 1: // Eliminate y
329  {
330  return SymmTensor<Cmpt>
331  (
332  zz(), Zero, -xz(),
333  Zero, Zero,
334  xx()
335  );
336  }
337  }
338 
339  // Fall-through: Eliminate z
340  return SymmTensor<Cmpt>
341  (
342  yy(), -xy(), Zero,
343  xx(), Zero,
345  );
346 }
347 
348 
349 template<class Cmpt>
351 (
352  const direction excludeCmpt
353 ) const
354 {
355  const Cmpt detval = this->det2D(excludeCmpt);
357  return this->adjunct2D(excludeCmpt)/detval;
358 }
359 
360 
361 // Invert without much error handling
362 template<class Cmpt>
364 {
365  const Cmpt detval = this->det();
366 
367  #ifdef FULLDEBUG
368  if (mag(detval) < VSMALL)
369  {
371  << "Tensor not properly invertible, determinant:"
372  << detval << " tensor:" << *this << nl
373  << abort(FatalError);
374  }
375  #endif
377  return this->adjunct()/detval;
378 }
379 
380 
381 // Invert with some error handling
382 template<class Cmpt>
384 {
385  {
386  // Attempt to identify and handle 2-D cases.
387  // - use diagSqr instead of magSqr for fewer operations
388  const scalar magSqr_xx = Foam::magSqr(xx());
389  const scalar magSqr_yy = Foam::magSqr(yy());
390  const scalar magSqr_zz = Foam::magSqr(zz());
391 
392  // SMALL: 1e-15 (double), 1e-6 (float), but 1e-6 may be adequate
393 
394  const scalar threshold = SMALL * (magSqr_xx + magSqr_yy + magSqr_zz);
395 
396  const bool small_xx = (magSqr_xx < threshold);
397  const bool small_yy = (magSqr_yy < threshold);
398  const bool small_zz = (magSqr_zz < threshold);
399 
400  if (small_xx || small_yy || small_zz)
401  {
402  SymmTensor<Cmpt> work(*this);
403 
404  if (small_xx) { work.xx() += pTraits<Cmpt>::one; }
405  if (small_yy) { work.yy() += pTraits<Cmpt>::one; }
406  if (small_zz) { work.zz() += pTraits<Cmpt>::one; }
407 
408  const Cmpt detval = work.det();
409 
410  if (mag(detval) < ROOTVSMALL)
411  {
412  // Appears to be nearly zero - leave untouched?
413  return SymmTensor<Cmpt>(Zero);
414  }
415 
416  work = work.adjunct()/detval;
417 
418  if (small_xx) { work.xx() -= pTraits<Cmpt>::one; }
419  if (small_yy) { work.yy() -= pTraits<Cmpt>::one; }
420  if (small_zz) { work.zz() -= pTraits<Cmpt>::one; }
421 
422  return work;
423  }
424  }
425 
426  const Cmpt detval = this->det();
427 
428  if (mag(detval) < ROOTVSMALL)
429  {
430  // Appears to be nearly zero - leave untouched?
431  return SymmTensor<Cmpt>(Zero);
432  }
433 
434  return this->adjunct()/detval;
435 }
436 
437 
438 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
439 
440 template<class Cmpt>
442 {
443  this->v_[XX] = st.ii(); this->v_[XY] = Zero; this->v_[XZ] = Zero;
444  this->v_[YY] = st.ii(); this->v_[YZ] = Zero;
445  this->v_[ZZ] = st.ii();
446 }
447 
448 
449 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
450 
451 namespace Foam
452 {
454 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
455 
456 //- Return the trace of a SymmTensor
457 template<class Cmpt>
458 inline Cmpt tr(const SymmTensor<Cmpt>& st)
459 {
460  return st.xx() + st.yy() + st.zz();
461 }
462 
464 //- Return the spherical part of a SymmTensor
465 template<class Cmpt>
467 {
468  return SphericalTensor<Cmpt>
469  (
470  (1.0/3.0)*tr(st)
471  );
472 }
473 
474 
475 //- Return the symmetric part of a SymmTensor, i.e. itself
476 template<class Cmpt>
477 inline const SymmTensor<Cmpt>& symm(const SymmTensor<Cmpt>& st)
478 {
479  return st;
480 }
481 
482 
483 //- Return twice the symmetric part of a SymmTensor
484 template<class Cmpt>
485 inline SymmTensor<Cmpt> twoSymm(const SymmTensor<Cmpt>& st)
486 {
487  return 2*st;
488 }
489 
490 
491 //- Return the deviatoric part of the symmetric part of a SymmTensor
492 template<class Cmpt>
493 inline SymmTensor<Cmpt> devSymm(const SymmTensor<Cmpt>& st)
494 {
495  return dev(st);
496 }
497 
498 
499 //- Return the deviatoric part of twice the symmetric part of a SymmTensor
500 template<class Cmpt>
501 inline SymmTensor<Cmpt> devTwoSymm(const SymmTensor<Cmpt>& st)
502 {
503  return dev2(st);
504 }
505 
507 //- Return the deviatoric part of a SymmTensor
508 template<class Cmpt>
509 inline SymmTensor<Cmpt> dev(const SymmTensor<Cmpt>& st)
510 {
511  return st - sph(st);
512 }
513 
514 
515 //- Return the two-third deviatoric part of a SymmTensor
516 template<class Cmpt>
517 inline SymmTensor<Cmpt> dev2(const SymmTensor<Cmpt>& st)
518 {
519  return st - 2*sph(st);
520 }
521 
522 
523 //- Return the determinant of a SymmTensor
524 template<class Cmpt>
525 inline Cmpt det(const SymmTensor<Cmpt>& st)
526 {
527  return st.det();
528 }
529 
530 
531 //- Return the cofactor of a SymmTensor as a SymmTensor
532 template<class Cmpt>
533 inline SymmTensor<Cmpt> cof(const SymmTensor<Cmpt>& st)
534 {
535  return st.cof();
536 }
537 
538 
539 //- Return the inverse of a SymmTensor, using given determinant value
540 template<class Cmpt>
541 inline SymmTensor<Cmpt> inv(const SymmTensor<Cmpt>& st, const Cmpt detval)
542 {
543  #ifdef FULLDEBUG
544  if (mag(detval) < VSMALL)
545  {
547  << "SymmTensor not properly invertible, determinant:"
548  << detval << " tensor:" << st << nl
549  << abort(FatalError);
550  }
551  #endif
552 
553  return st.adjunct()/detval;
554 }
555 
557 //- Return the inverse of a SymmTensor
558 template<class Cmpt>
559 inline SymmTensor<Cmpt> inv(const SymmTensor<Cmpt>& st)
560 {
561  return st.inv();
562 }
563 
564 
565 //- Return the 1st invariant of a SymmTensor
566 template<class Cmpt>
567 inline Cmpt invariantI(const SymmTensor<Cmpt>& st)
568 {
569  return tr(st);
570 }
571 
572 
573 //- Return the 2nd invariant of a SymmTensor
574 template<class Cmpt>
575 inline Cmpt invariantII(const SymmTensor<Cmpt>& st)
576 {
577  return
578  (
579  st.xx()*st.yy() + st.yy()*st.zz() + st.xx()*st.zz()
580  - st.xy()*st.xy() - st.yz()*st.yz() - st.xz()*st.xz()
581  );
582 }
583 
584 
585 //- Return the 3rd invariant of a SymmTensor
586 template<class Cmpt>
587 inline Cmpt invariantIII(const SymmTensor<Cmpt>& st)
588 {
589  return det(st);
590 }
591 
592 
593 //- Return the inner-product of a SymmTensor with itself
594 template<class Cmpt>
595 inline SymmTensor<Cmpt>
597 {
598  return SymmTensor<Cmpt>
599  (
600  st.xx()*st.xx() + st.xy()*st.xy() + st.xz()*st.xz(),
601  st.xx()*st.xy() + st.xy()*st.yy() + st.xz()*st.yz(),
602  st.xx()*st.xz() + st.xy()*st.yz() + st.xz()*st.zz(),
603 
604  st.xy()*st.xy() + st.yy()*st.yy() + st.yz()*st.yz(),
605  st.xy()*st.xz() + st.yy()*st.yz() + st.yz()*st.zz(),
606 
607  st.xz()*st.xz() + st.yz()*st.yz() + st.zz()*st.zz()
608  );
609 }
611 
612 //- Return the square of Frobenius norm of a SymmTensor
613 template<class Cmpt>
614 inline Foam::scalar magSqr(const SymmTensor<Cmpt>& st)
615 {
616  return
617  (
618  magSqr(st.xx()) + 2*magSqr(st.xy()) + 2*magSqr(st.xz())
619  + magSqr(st.yy()) + 2*magSqr(st.yz())
620  + magSqr(st.zz())
621  );
622 }
623 
624 
625 //- Return the square of a Vector as a SymmTensor
626 template<class Cmpt>
627 inline SymmTensor<Cmpt> sqr(const Vector<Cmpt>& v)
628 {
629  return SymmTensor<Cmpt>
630  (
631  v.x()*v.x(), v.x()*v.y(), v.x()*v.z(),
632  v.y()*v.y(), v.y()*v.z(),
633  v.z()*v.z()
634  );
635 }
636 
637 
638 //- Linear interpolation of symmetric tensors a and b by factor t
639 template<class Cmpt>
640 inline SymmTensor<Cmpt> lerp
641 (
642  const SymmTensor<Cmpt>& a,
643  const SymmTensor<Cmpt>& b,
644  const scalar t
645 )
646 {
647  const scalar onet = (1-t);
648 
649  return SymmTensor<Cmpt>
650  (
651  onet*a.xx() + t*b.xx(),
652  onet*a.xy() + t*b.xy(),
653  onet*a.xz() + t*b.xz(),
654  onet*a.yy() + t*b.yy(),
655  onet*a.yz() + t*b.yz(),
656  onet*a.zz() + t*b.zz()
657  );
658 }
659 
660 
661 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
662 
663 //- Sum of a SphericalTensor and a SymmTensor
664 template<class Cmpt>
665 inline SymmTensor<Cmpt>
666 operator+(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
667 {
668  return SymmTensor<Cmpt>
669  (
670  spt1.ii() + st2.xx(), st2.xy(), st2.xz(),
671  spt1.ii() + st2.yy(), st2.yz(),
672  spt1.ii() + st2.zz()
673  );
674 }
675 
676 
677 //- Sum of a SymmTensor and a SphericalTensor
678 template<class Cmpt>
679 inline SymmTensor<Cmpt>
680 operator+(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2)
681 {
682  return SymmTensor<Cmpt>
683  (
684  st1.xx() + spt2.ii(), st1.xy(), st1.xz(),
685  st1.yy() + spt2.ii(), st1.yz(),
686  st1.zz() + spt2.ii()
687  );
688 }
689 
690 
691 //- Subtract a SymmTensor from a SphericalTensor
692 template<class Cmpt>
693 inline SymmTensor<Cmpt>
694 operator-(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
695 {
696  return SymmTensor<Cmpt>
697  (
698  spt1.ii() - st2.xx(), -st2.xy(), -st2.xz(),
699  spt1.ii() - st2.yy(), -st2.yz(),
700  spt1.ii() - st2.zz()
701  );
702 }
703 
704 
705 //- Subtract a SphericalTensor from a SymmTensor
706 template<class Cmpt>
707 inline SymmTensor<Cmpt>
708 operator-(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2)
709 {
710  return SymmTensor<Cmpt>
711  (
712  st1.xx() - spt2.ii(), st1.xy(), st1.xz(),
713  st1.yy() - spt2.ii(), st1.yz(),
714  st1.zz() - spt2.ii()
715  );
716 }
717 
718 
719 //- Return the Hodge dual of a SymmTensor as a Vector
720 template<class Cmpt>
721 inline Vector<Cmpt> operator*(const SymmTensor<Cmpt>& st)
722 {
723  return Vector<Cmpt>(st.yz(), -st.xz(), st.xy());
724 }
725 
726 
727 //- Division of a SymmTensor by a Cmpt
728 template<class Cmpt>
729 inline SymmTensor<Cmpt>
730 operator/(const SymmTensor<Cmpt>& st, const Cmpt s)
731 {
732  return SymmTensor<Cmpt>
733  (
734  st.xx()/s, st.xy()/s, st.xz()/s,
735  st.yy()/s, st.yz()/s,
736  st.zz()/s
737  );
738 }
739 
740 
741 //- Inner-product of a SymmTensor and a SymmTensor
742 template<class Cmpt>
743 inline Tensor<Cmpt>
744 operator&(const SymmTensor<Cmpt>& st1, const SymmTensor<Cmpt>& st2)
745 {
746  return Tensor<Cmpt>
747  (
748  st1.xx()*st2.xx() + st1.xy()*st2.xy() + st1.xz()*st2.xz(),
749  st1.xx()*st2.xy() + st1.xy()*st2.yy() + st1.xz()*st2.yz(),
750  st1.xx()*st2.xz() + st1.xy()*st2.yz() + st1.xz()*st2.zz(),
751 
752  st1.xy()*st2.xx() + st1.yy()*st2.xy() + st1.yz()*st2.xz(),
753  st1.xy()*st2.xy() + st1.yy()*st2.yy() + st1.yz()*st2.yz(),
754  st1.xy()*st2.xz() + st1.yy()*st2.yz() + st1.yz()*st2.zz(),
755 
756  st1.xz()*st2.xx() + st1.yz()*st2.xy() + st1.zz()*st2.xz(),
757  st1.xz()*st2.xy() + st1.yz()*st2.yy() + st1.zz()*st2.yz(),
758  st1.xz()*st2.xz() + st1.yz()*st2.yz() + st1.zz()*st2.zz()
759  );
760 }
761 
763 //- Inner-product of a SphericalTensor and a SymmTensor
764 template<class Cmpt>
765 inline SymmTensor<Cmpt>
766 operator&(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
767 {
768  return SymmTensor<Cmpt>
769  (
770  spt1.ii()*st2.xx(), spt1.ii()*st2.xy(), spt1.ii()*st2.xz(),
771  spt1.ii()*st2.yy(), spt1.ii()*st2.yz(),
772  spt1.ii()*st2.zz()
773  );
774 }
775 
776 
777 //- Inner-product of a SymmTensor and a SphericalTensor
778 template<class Cmpt>
779 inline SymmTensor<Cmpt>
780 operator&(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2)
781 {
782  return SymmTensor<Cmpt>
783  (
784  st1.xx()*spt2.ii(), st1.xy()*spt2.ii(), st1.xz()*spt2.ii(),
785  st1.yy()*spt2.ii(), st1.yz()*spt2.ii(),
786  st1.zz()*spt2.ii()
787  );
788 }
790 
791 //- Inner-product of a SymmTensor and a Vector
792 template<class Cmpt>
793 inline Vector<Cmpt>
794 operator&(const SymmTensor<Cmpt>& st, const Vector<Cmpt>& v)
795 {
796  return Vector<Cmpt>
797  (
798  st.xx()*v.x() + st.xy()*v.y() + st.xz()*v.z(),
799  st.xy()*v.x() + st.yy()*v.y() + st.yz()*v.z(),
800  st.xz()*v.x() + st.yz()*v.y() + st.zz()*v.z()
801  );
802 }
803 
804 
805 //- Inner-product of a Vector and a SymmTensor
806 template<class Cmpt>
807 inline Vector<Cmpt>
808 operator&(const Vector<Cmpt>& v, const SymmTensor<Cmpt>& st)
809 {
810  return Vector<Cmpt>
811  (
812  v.x()*st.xx() + v.y()*st.xy() + v.z()*st.xz(),
813  v.x()*st.xy() + v.y()*st.yy() + v.z()*st.yz(),
814  v.x()*st.xz() + v.y()*st.yz() + v.z()*st.zz()
815  );
816 }
817 
818 
819 //- Double-inner-product of a SymmTensor and a SymmTensor
820 template<class Cmpt>
821 inline Cmpt
822 operator&&(const SymmTensor<Cmpt>& st1, const SymmTensor<Cmpt>& st2)
823 {
824  return
825  (
826  st1.xx()*st2.xx() + 2*st1.xy()*st2.xy() + 2*st1.xz()*st2.xz()
827  + st1.yy()*st2.yy() + 2*st1.yz()*st2.yz()
828  + st1.zz()*st2.zz()
829  );
830 }
831 
832 
833 //- Double-inner-product of a SphericalTensor and a SymmTensor
834 template<class Cmpt>
835 inline Cmpt
836 operator&&(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2)
837 {
838  return (spt1.ii()*st2.xx() + spt1.ii()*st2.yy() + spt1.ii()*st2.zz());
839 }
840 
841 
842 //- Double-inner-product of a SymmTensor and a SphericalTensor
843 template<class Cmpt>
844 inline Cmpt
846 {
847  return (st1.xx()*spt2.ii() + st1.yy()*spt2.ii() + st1.zz()*spt2.ii());
848 }
849 
850 
851 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
852 
853 template<class Cmpt>
854 class outerProduct<SymmTensor<Cmpt>, Cmpt>
855 {
856 public:
857 
858  typedef SymmTensor<Cmpt> type;
859 };
860 
861 template<class Cmpt>
862 class outerProduct<Cmpt, SymmTensor<Cmpt>>
863 {
864 public:
865 
866  typedef SymmTensor<Cmpt> type;
867 };
868 
869 template<class Cmpt>
870 class innerProduct<SymmTensor<Cmpt>, SymmTensor<Cmpt>>
871 {
872 public:
873 
874  typedef Tensor<Cmpt> type;
875 };
876 
877 template<class Cmpt>
878 class innerProduct<SymmTensor<Cmpt>, Vector<Cmpt>>
879 {
880 public:
881 
882  typedef Vector<Cmpt> type;
883 };
884 
885 template<class Cmpt>
886 class innerProduct<Vector<Cmpt>, SymmTensor<Cmpt>>
887 {
888 public:
889 
890  typedef Vector<Cmpt> type;
891 };
892 
894 template<class Cmpt>
895 class typeOfSum<SphericalTensor<Cmpt>, SymmTensor<Cmpt>>
896 {
897 public:
898 
899  typedef SymmTensor<Cmpt> type;
900 };
901 
902 template<class Cmpt>
903 class typeOfSum<SymmTensor<Cmpt>, SphericalTensor<Cmpt>>
904 {
905 public:
906 
907  typedef SymmTensor<Cmpt> type;
908 };
909 
910 template<class Cmpt>
911 class innerProduct<SphericalTensor<Cmpt>, SymmTensor<Cmpt>>
912 {
913 public:
914 
915  typedef SymmTensor<Cmpt> type;
916 };
918 template<class Cmpt>
919 class innerProduct<SymmTensor<Cmpt>, SphericalTensor<Cmpt>>
920 {
921 public:
922 
923  typedef SymmTensor<Cmpt> type;
924 };
926 
927 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
928 
929 } // End namespace Foam
930 
931 // ************************************************************************* //
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:596
Cmpt det(const SymmTensor< Cmpt > &st)
Return the determinant of a SymmTensor.
Definition: SymmTensorI.H:536
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:600
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:61
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:496
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:117
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:376
dimensionedSymmTensor twoSymm(const dimensionedSymmTensor &dt)
Cmpt det() const
The determinate.
Definition: SymmTensorI.H:250
const Cmpt & zz() const noexcept
Definition: SymmTensor.H:158
SymmTensor< Cmpt > adjunct() const
Return adjunct matrix (transpose of cofactor matrix)
Definition: SymmTensorI.H:283
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:344
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:610
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:305
const Cmpt & ii() const noexcept
SymmTensor< Cmpt > cof() const
Return cofactor matrix (transpose of adjunct matrix)
Definition: SymmTensorI.H:296
const Cmpt & xx() const noexcept
Definition: SymmTensor.H:150
bool is_identity(const scalar tol=ROOTVSMALL) const
Is identity tensor?
Definition: SymmTensorI.H:235
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:262
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:586
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:356
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:506
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.