TensorI.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) 2016-2020 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 #include <type_traits>
29 
30 #include "SymmTensor.H"
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
34 template<class Cmpt>
36 :
37  Tensor::msType(Zero)
38 {}
39 
40 
41 template<class Cmpt>
42 template<class Cmpt2>
44 (
45  const MatrixSpace<Tensor<Cmpt2>, Cmpt2, 3, 3>& vs
46 )
47 :
48  Tensor::msType(vs)
49 {}
50 
51 
52 template<class Cmpt>
53 template<class Cmpt2>
55 (
56  const VectorSpace<Tensor<Cmpt2>, Cmpt2, 9>& vs
57 )
58 :
59  Tensor::msType(vs)
60 {}
61 
62 
63 template<class Cmpt>
65 {
66  this->v_[XX] = st.ii(); this->v_[XY] = Zero; this->v_[XZ] = Zero;
67  this->v_[YX] = Zero; this->v_[YY] = st.ii(); this->v_[YZ] = Zero;
68  this->v_[ZX] = Zero; this->v_[ZY] = Zero; this->v_[ZZ] = st.ii();
69 }
70 
71 
72 template<class Cmpt>
74 {
75  this->v_[XX] = st.xx(); this->v_[XY] = st.xy(); this->v_[XZ] = st.xz();
76  this->v_[YX] = st.xy(); this->v_[YY] = st.yy(); this->v_[YZ] = st.yz();
77  this->v_[ZX] = st.xz(); this->v_[ZY] = st.yz(); this->v_[ZZ] = st.zz();
78 }
79 
80 
81 template<class Cmpt>
83 (
84  const Vector<Vector<Cmpt>>& vecs,
85  const bool transposed
86 )
87 :
88  Tensor<Cmpt>(vecs.x(), vecs.y(), vecs.z(), transposed)
89 {}
90 
91 
92 template<class Cmpt>
94 (
95  const Vector<Cmpt>& x,
96  const Vector<Cmpt>& y,
97  const Vector<Cmpt>& z,
98  const bool transposed
99 )
100 {
101  if (transposed)
102  {
103  this->cols(x, y, z);
104  }
105  else
106  {
107  this->rows(x, y, z);
108  }
109 }
110 
111 
112 template<class Cmpt>
114 (
115  const Cmpt txx, const Cmpt txy, const Cmpt txz,
116  const Cmpt tyx, const Cmpt tyy, const Cmpt tyz,
117  const Cmpt tzx, const Cmpt tzy, const Cmpt tzz
118 )
119 {
120  this->v_[XX] = txx; this->v_[XY] = txy; this->v_[XZ] = txz;
121  this->v_[YX] = tyx; this->v_[YY] = tyy; this->v_[YZ] = tyz;
122  this->v_[ZX] = tzx; this->v_[ZY] = tzy; this->v_[ZZ] = tzz;
123 }
124 
125 
126 template<class Cmpt>
127 template
128 <
129  template<class, Foam::direction, Foam::direction> class Block2,
130  Foam::direction BRowStart,
131  Foam::direction BColStart
132 >
134 (
135  const Block2<Tensor<Cmpt>, BRowStart, BColStart>& block
136 )
137 :
138  Tensor::msType(block)
139 {}
140 
141 
142 template<class Cmpt>
144 :
145  Tensor::msType(is)
146 {}
147 
148 
149 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
150 
151 template<class Cmpt>
152 inline const Cmpt& Foam::Tensor<Cmpt>::xx() const
153 {
154  return this->v_[XX];
155 }
156 
157 
158 template<class Cmpt>
159 inline const Cmpt& Foam::Tensor<Cmpt>::xy() const
160 {
161  return this->v_[XY];
162 }
163 
164 
165 template<class Cmpt>
166 inline const Cmpt& Foam::Tensor<Cmpt>::xz() const
167 {
168  return this->v_[XZ];
169 }
170 
171 
172 template<class Cmpt>
173 inline const Cmpt& Foam::Tensor<Cmpt>::yx() const
174 {
175  return this->v_[YX];
176 }
177 
178 
179 template<class Cmpt>
180 inline const Cmpt& Foam::Tensor<Cmpt>::yy() const
181 {
182  return this->v_[YY];
183 }
184 
185 
186 template<class Cmpt>
187 inline const Cmpt& Foam::Tensor<Cmpt>::yz() const
188 {
189  return this->v_[YZ];
190 }
191 
192 
193 template<class Cmpt>
194 inline const Cmpt& Foam::Tensor<Cmpt>::zx() const
195 {
196  return this->v_[ZX];
197 }
198 
199 
200 template<class Cmpt>
201 inline const Cmpt& Foam::Tensor<Cmpt>::zy() const
202 {
203  return this->v_[ZY];
204 }
205 
206 
207 template<class Cmpt>
208 inline const Cmpt& Foam::Tensor<Cmpt>::zz() const
209 {
210  return this->v_[ZZ];
211 }
212 
213 
214 template<class Cmpt>
216 {
217  return this->v_[XX];
218 }
219 
220 
221 template<class Cmpt>
223 {
224  return this->v_[XY];
225 }
226 
227 
228 template<class Cmpt>
230 {
231  return this->v_[XZ];
232 }
233 
234 
235 template<class Cmpt>
237 {
238  return this->v_[YX];
239 }
240 
241 
242 template<class Cmpt>
244 {
245  return this->v_[YY];
246 }
247 
248 
249 template<class Cmpt>
251 {
252  return this->v_[YZ];
253 }
254 
255 
256 template<class Cmpt>
258 {
259  return this->v_[ZX];
260 }
261 
262 
263 template<class Cmpt>
265 {
266  return this->v_[ZY];
267 }
268 
269 
270 template<class Cmpt>
272 {
273  return this->v_[ZZ];
274 }
275 
276 
277 template<class Cmpt>
279 {
280  return Vector<Cmpt>(this->v_[XX], this->v_[XY], this->v_[XZ]);
281 }
282 
283 
284 template<class Cmpt>
286 {
287  return Vector<Cmpt>(this->v_[YX], this->v_[YY], this->v_[YZ]);
288 }
289 
290 
291 template<class Cmpt>
293 {
294  return Vector<Cmpt>(this->v_[ZX], this->v_[ZY], this->v_[ZZ]);
295 }
296 
297 
298 template<class Cmpt>
300 {
301  return Vector<Cmpt>(this->v_[XX], this->v_[YX], this->v_[ZX]);
302 }
303 
304 
305 template<class Cmpt>
307 {
308  return Vector<Cmpt>(this->v_[XY], this->v_[YY], this->v_[ZY]);
309 }
310 
311 
312 template<class Cmpt>
314 {
315  return Vector<Cmpt>(this->v_[XZ], this->v_[YZ], this->v_[ZZ]);
316 }
317 
318 
319 template<class Cmpt>
320 template<Foam::direction Col>
322 {
323  if (Col == 0) return cx();
324  else if (Col == 1) return cy();
325  else if (Col == 2) return cz();
326 
327  static_assert(Col < 3, "Invalid column access");
328  return Zero;
329 }
330 
331 
332 template<class Cmpt>
334 {
335  switch (c)
336  {
337  case 0: return cx(); break;
338  case 1: return cy(); break;
339  case 2: return cz(); break;
340  }
341 
343  << "Invalid column access " << c << abort(FatalError);
344 
345  return Zero;
346 }
347 
348 
349 template<class Cmpt>
350 template<Foam::direction Row>
352 {
353  if (Row == 0) return x();
354  else if (Row == 1) return y();
355  else if (Row == 2) return z();
356 
357  static_assert(Row < 3, "Invalid row access");
358  return Zero;
359 }
360 
361 
362 template<class Cmpt>
364 {
365  switch (r)
366  {
367  case 0: return x(); break;
368  case 1: return y(); break;
369  case 2: return z(); break;
370  }
371 
373  << "Invalid row access " << r << abort(FatalError);
374 
375  return Zero;
376 }
377 
378 
379 template<class Cmpt>
380 template<Foam::direction Col>
382 {
383  if (Col == 0)
384  {
385  this->v_[XX] = v.x();
386  this->v_[YX] = v.y();
387  this->v_[ZX] = v.z();
388  }
389  else if (Col == 1)
390  {
391  this->v_[XY] = v.x();
392  this->v_[YY] = v.y();
393  this->v_[ZY] = v.z();
394  }
395  else if (Col == 2)
396  {
397  this->v_[XZ] = v.x();
398  this->v_[YZ] = v.y();
399  this->v_[ZZ] = v.z();
400  }
401 
402  static_assert(Col < 3, "Invalid column access");
403 }
404 
405 
406 template<class Cmpt>
407 template<Foam::direction Row>
409 {
410  if (Row == 0)
411  {
412  this->v_[XX] = v.x(); this->v_[XY] = v.y(); this->v_[XZ] = v.z();
413  }
414  else if (Row == 1)
415  {
416  this->v_[YX] = v.x(); this->v_[YY] = v.y(); this->v_[YZ] = v.z();
417  }
418  else if (Row == 2)
419  {
420  this->v_[ZX] = v.x(); this->v_[ZY] = v.y(); this->v_[ZZ] = v.z();
421  }
422 
423  static_assert(Row < 3, "Invalid row access");
424 }
425 
426 
427 template<class Cmpt>
428 inline void Foam::Tensor<Cmpt>::cols
429 (
430  const Vector<Cmpt>& x,
431  const Vector<Cmpt>& y,
432  const Vector<Cmpt>& z
433 )
434 {
435  this->v_[XX] = x.x(); this->v_[XY] = y.x(); this->v_[XZ] = z.x();
436  this->v_[YX] = x.y(); this->v_[YY] = y.y(); this->v_[YZ] = z.y();
437  this->v_[ZX] = x.z(); this->v_[ZY] = y.z(); this->v_[ZZ] = z.z();
438 }
439 
440 
441 template<class Cmpt>
442 inline void Foam::Tensor<Cmpt>::rows
443 (
444  const Vector<Cmpt>& x,
445  const Vector<Cmpt>& y,
446  const Vector<Cmpt>& z
447 )
448 {
449  this->v_[XX] = x.x(); this->v_[XY] = x.y(); this->v_[XZ] = x.z();
450  this->v_[YX] = y.x(); this->v_[YY] = y.y(); this->v_[YZ] = y.z();
451  this->v_[ZX] = z.x(); this->v_[ZY] = z.y(); this->v_[ZZ] = z.z();
452 }
453 
454 
455 template<class Cmpt>
456 inline void Foam::Tensor<Cmpt>::col(const direction c, const Vector<Cmpt>& v)
457 {
458  switch (c)
459  {
460  case 0: col<0>(v); break;
461  case 1: col<1>(v); break;
462  case 2: col<2>(v); break;
463  default:
465  << "Invalid column access " << c << abort(FatalError);
466  break;
467  }
468 }
469 
470 
471 template<class Cmpt>
472 inline void Foam::Tensor<Cmpt>::row(const direction r, const Vector<Cmpt>& v)
473 {
474  switch (r)
475  {
476  case 0: row<0>(v); break;
477  case 1: row<1>(v); break;
478  case 2: row<2>(v); break;
479  default:
481  << "Invalid row access " << r << abort(FatalError);
482  break;
483  }
484 }
485 
486 
487 template<class Cmpt>
489 {
490  return Vector<Cmpt>(this->v_[XX], this->v_[YY], this->v_[ZZ]);
491 }
492 
493 
494 template<class Cmpt>
496 {
497  this->v_[XX] = v.x(); this->v_[YY] = v.y(); this->v_[ZZ] = v.z();
498 }
499 
500 
501 // * * * * * * * * * * * * * * * Member Operations * * * * * * * * * * * * * //
502 
503 template<class Cmpt>
505 {
506  return Tensor<Cmpt>
507  (
508  xx(), yx(), zx(),
509  xy(), yy(), zy(),
510  xz(), yz(), zz()
511  );
512 }
513 
514 
515 template<class Cmpt>
516 inline Foam::Tensor<Cmpt>
518 {
519  const Tensor<Cmpt>& t1 = *this;
520 
521  return Tensor<Cmpt>
522  (
523  t1.xx()*t2.xx() + t1.xy()*t2.yx() + t1.xz()*t2.zx(),
524  t1.xx()*t2.xy() + t1.xy()*t2.yy() + t1.xz()*t2.zy(),
525  t1.xx()*t2.xz() + t1.xy()*t2.yz() + t1.xz()*t2.zz(),
526 
527  t1.yx()*t2.xx() + t1.yy()*t2.yx() + t1.yz()*t2.zx(),
528  t1.yx()*t2.xy() + t1.yy()*t2.yy() + t1.yz()*t2.zy(),
529  t1.yx()*t2.xz() + t1.yy()*t2.yz() + t1.yz()*t2.zz(),
530 
531  t1.zx()*t2.xx() + t1.zy()*t2.yx() + t1.zz()*t2.zx(),
532  t1.zx()*t2.xy() + t1.zy()*t2.yy() + t1.zz()*t2.zy(),
533  t1.zx()*t2.xz() + t1.zy()*t2.yz() + t1.zz()*t2.zz()
534  );
535 }
536 
537 
538 template<class Cmpt>
539 inline Foam::Tensor<Cmpt>
541 {
542  const Tensor<Cmpt>& t1 = *this;
543 
544  return Tensor<Cmpt>
545  (
546  t1.xx()*t2.xx(), t1.xy()*t2.xy(), t1.xz()*t2.xz(),
547  t1.yx()*t2.yx(), t1.yy()*t2.yy(), t1.yz()*t2.yz(),
548  t1.zx()*t2.zx(), t1.zy()*t2.zy(), t1.zz()*t2.zz()
549  );
550 }
551 
552 
553 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
554 
555 template<class Cmpt>
557 {
558  *this = this->inner(t);
559 }
560 
561 
562 template<class Cmpt>
563 template<class Cmpt2>
564 inline void Foam::Tensor<Cmpt>::operator=
565 (
566  const VectorSpace<Tensor<Cmpt2>, Cmpt2, 9>& vs
567 )
568 {
569  VectorSpace<Tensor<Cmpt>, Cmpt, 9>::operator=(vs);
570 }
571 
572 
573 template<class Cmpt>
575 {
576  this->v_[XX] = st.ii(); this->v_[XY] = Zero; this->v_[XZ] = Zero;
577  this->v_[YX] = Zero; this->v_[YY] = st.ii(); this->v_[YZ] = Zero;
578  this->v_[ZX] = Zero; this->v_[ZY] = Zero; this->v_[ZZ] = st.ii();
579 }
580 
581 
582 template<class Cmpt>
584 {
585  this->v_[XX] = st.xx(); this->v_[XY] = st.xy(); this->v_[XZ] = st.xz();
586  this->v_[YX] = st.xy(); this->v_[YY] = st.yy(); this->v_[YZ] = st.yz();
587  this->v_[ZX] = st.xz(); this->v_[ZY] = st.yz(); this->v_[ZZ] = st.zz();
588 }
589 
590 
591 template<class Cmpt>
593 {
594  this->v_[XX] = tr.x().x();
595  this->v_[XY] = tr.x().y();
596  this->v_[XZ] = tr.x().z();
597 
598  this->v_[YX] = tr.y().x();
599  this->v_[YY] = tr.y().y();
600  this->v_[YZ] = tr.y().z();
601 
602  this->v_[ZX] = tr.z().x();
603  this->v_[ZY] = tr.z().y();
604  this->v_[ZZ] = tr.z().z();
605 }
606 
607 
608 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
609 
610 namespace Foam
611 {
612 
613 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
614 
615 //- Return the trace of a Tensor
616 template<class Cmpt>
617 inline Cmpt tr(const Tensor<Cmpt>& t)
618 {
619  return t.xx() + t.yy() + t.zz();
620 }
621 
622 
623 //- Return the spherical part of a Tensor
624 template<class Cmpt>
626 {
627  return SphericalTensor<Cmpt>
628  (
629  (1.0/3.0)*tr(t)
630  );
631 }
632 
633 
634 //- Return the symmetric part of a Tensor
635 template<class Cmpt>
637 {
638  return SymmTensor<Cmpt>
639  (
640  t.xx(), 0.5*(t.xy() + t.yx()), 0.5*(t.xz() + t.zx()),
641  t.yy(), 0.5*(t.yz() + t.zy()),
642  t.zz()
643  );
644 }
645 
646 
647 //- Return twice the symmetric part of a Tensor
648 template<class Cmpt>
650 {
651  return SymmTensor<Cmpt>
652  (
653  2*t.xx(), (t.xy() + t.yx()), (t.xz() + t.zx()),
654  2*t.yy(), (t.yz() + t.zy()),
655  2*t.zz()
656  );
657 }
658 
659 
660 //- Return the skew-symmetric part of a Tensor
661 template<class Cmpt>
663 {
664  return Tensor<Cmpt>
665  (
666  Zero, 0.5*(t.xy() - t.yx()), 0.5*(t.xz() - t.zx()),
667  0.5*(t.yx() - t.xy()), Zero, 0.5*(t.yz() - t.zy()),
668  0.5*(t.zx() - t.xz()), 0.5*(t.zy() - t.yz()), Zero
669  );
670 }
671 
672 
673 //- Return the skew-symmetric part of a SymmTensor as a Tensor
674 template<class Cmpt>
675 inline const Tensor<Cmpt>& skew(const SymmTensor<Cmpt>& st)
676 {
677  return Tensor<Cmpt>::zero;
678 }
679 
680 
681 //- Return the deviatoric part of a Tensor
682 template<class Cmpt>
683 inline Tensor<Cmpt> dev(const Tensor<Cmpt>& t)
684 {
685  return t - sph(t);
686 }
687 
688 
689 //- Return the two-third deviatoric part of a Tensor
690 template<class Cmpt>
692 {
693  return t - 2*sph(t);
694 }
695 
696 
697 //- Return the determinant of a Tensor
698 template<class Cmpt>
699 inline Cmpt det(const Tensor<Cmpt>& t)
700 {
701  return
702  (
703  t.xx()*t.yy()*t.zz() + t.xy()*t.yz()*t.zx()
704  + t.xz()*t.yx()*t.zy() - t.xx()*t.yz()*t.zy()
705  - t.xy()*t.yx()*t.zz() - t.xz()*t.yy()*t.zx()
706  );
707 }
708 
709 
710 //- Return the cofactor Tensor of a Tensor
711 template<class Cmpt>
712 inline Tensor<Cmpt> cof(const Tensor<Cmpt>& t)
713 {
714  return Tensor<Cmpt>
715  (
716  t.yy()*t.zz() - t.zy()*t.yz(),
717  t.zx()*t.yz() - t.yx()*t.zz(),
718  t.yx()*t.zy() - t.yy()*t.zx(),
719 
720  t.xz()*t.zy() - t.xy()*t.zz(),
721  t.xx()*t.zz() - t.xz()*t.zx(),
722  t.xy()*t.zx() - t.xx()*t.zy(),
723 
724  t.xy()*t.yz() - t.xz()*t.yy(),
725  t.yx()*t.xz() - t.xx()*t.yz(),
726  t.xx()*t.yy() - t.yx()*t.xy()
727  );
728 }
729 
730 
731 //- Return the inverse of a Tensor by using the given determinant
732 template<class Cmpt>
733 inline Tensor<Cmpt> inv(const Tensor<Cmpt>& t, const Cmpt dett)
734 {
735  #ifdef FULLDEBUG
736  if (mag(dett) < SMALL)
737  {
739  << "Tensor is not invertible due to the zero determinant:"
740  << "det(Tensor) = " << mag(dett)
741  << abort(FatalError);
742  }
743  #endif
744 
745  return cof(t).T()/dett;
746 }
747 
748 
749 //- Return the inverse of a Tensor
750 template<class Cmpt>
751 inline Tensor<Cmpt> inv(const Tensor<Cmpt>& t)
752 {
753  return inv(t, det(t));
754 }
755 
756 
757 //- Return the inverse of this Tensor
758 template<class Cmpt>
760 {
761  return Foam::inv(*this);
762 }
763 
764 
765 //- Return the 1st invariant of a Tensor
766 template<class Cmpt>
767 inline Cmpt invariantI(const Tensor<Cmpt>& t)
768 {
769  return tr(t);
770 }
771 
772 
773 //- Return the 2nd invariant of a Tensor
774 template<class Cmpt>
775 inline Cmpt invariantII(const Tensor<Cmpt>& t)
776 {
777  return
778  (
779  t.xx()*t.yy() + t.yy()*t.zz() + t.xx()*t.zz()
780  - t.xy()*t.yx() - t.yz()*t.zy() - t.xz()*t.zx()
781  );
782 }
783 
784 
785 //- Return the 3rd invariant of a Tensor
786 template<class Cmpt>
787 inline Cmpt invariantIII(const Tensor<Cmpt>& t)
788 {
789  return det(t);
790 }
791 
792 
793 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
794 
795 //- Sum of a SphericalTensor and a Tensor
796 template<class Cmpt>
797 inline Tensor<Cmpt>
799 {
800  return Tensor<Cmpt>
801  (
802  st1.ii() + t2.xx(), t2.xy(), t2.xz(),
803  t2.yx(), st1.ii() + t2.yy(), t2.yz(),
804  t2.zx(), t2.zy(), st1.ii() + t2.zz()
805  );
806 }
807 
808 
809 //- Sum of a Tensor and a SphericalTensor
810 template<class Cmpt>
811 inline Tensor<Cmpt>
813 {
814  return Tensor<Cmpt>
815  (
816  t1.xx() + st2.ii(), t1.xy(), t1.xz(),
817  t1.yx(), t1.yy() + st2.ii(), t1.yz(),
818  t1.zx(), t1.zy(), t1.zz() + st2.ii()
819  );
820 }
821 
822 
823 //- Sum of a SymmTensor and a Tensor
824 template<class Cmpt>
825 inline Tensor<Cmpt>
827 {
828  return Tensor<Cmpt>
829  (
830  st1.xx() + t2.xx(), st1.xy() + t2.xy(), st1.xz() + t2.xz(),
831  st1.xy() + t2.yx(), st1.yy() + t2.yy(), st1.yz() + t2.yz(),
832  st1.xz() + t2.zx(), st1.yz() + t2.zy(), st1.zz() + t2.zz()
833  );
834 }
835 
836 
837 //- Sum of a Tensor and a SymmTensor
838 template<class Cmpt>
839 inline Tensor<Cmpt>
841 {
842  return Tensor<Cmpt>
843  (
844  t1.xx() + st2.xx(), t1.xy() + st2.xy(), t1.xz() + st2.xz(),
845  t1.yx() + st2.xy(), t1.yy() + st2.yy(), t1.yz() + st2.yz(),
846  t1.zx() + st2.xz(), t1.zy() + st2.yz(), t1.zz() + st2.zz()
847  );
848 }
849 
850 
851 //- Subtract a Tensor from a SphericalTensor
852 template<class Cmpt>
853 inline Tensor<Cmpt>
855 {
856  return Tensor<Cmpt>
857  (
858  st1.ii() - t2.xx(), -t2.xy(), -t2.xz(),
859  -t2.yx(), st1.ii() - t2.yy(), -t2.yz(),
860  -t2.zx(), -t2.zy(), st1.ii() - t2.zz()
861  );
862 }
863 
864 
865 //- Subtract a SphericalTensor from a Tensor
866 template<class Cmpt>
867 inline Tensor<Cmpt>
869 {
870  return Tensor<Cmpt>
871  (
872  t1.xx() - st2.ii(), t1.xy(), t1.xz(),
873  t1.yx(), t1.yy() - st2.ii(), t1.yz(),
874  t1.zx(), t1.zy(), t1.zz() - st2.ii()
875  );
876 }
877 
878 
879 //- Subtract a Tensor from a SymmTensor
880 template<class Cmpt>
881 inline Tensor<Cmpt>
883 {
884  return Tensor<Cmpt>
885  (
886  st1.xx() - t2.xx(), st1.xy() - t2.xy(), st1.xz() - t2.xz(),
887  st1.xy() - t2.yx(), st1.yy() - t2.yy(), st1.yz() - t2.yz(),
888  st1.xz() - t2.zx(), st1.yz() - t2.zy(), st1.zz() - t2.zz()
889  );
890 }
891 
892 
893 //- Subtract a SymmTensor from a Tensor
894 template<class Cmpt>
895 inline Tensor<Cmpt>
897 {
898  return Tensor<Cmpt>
899  (
900  t1.xx() - st2.xx(), t1.xy() - st2.xy(), t1.xz() - st2.xz(),
901  t1.yx() - st2.xy(), t1.yy() - st2.yy(), t1.yz() - st2.yz(),
902  t1.zx() - st2.xz(), t1.zy() - st2.yz(), t1.zz() - st2.zz()
903  );
904 }
905 
906 
907 //- Return the Hodge dual of a Tensor as a Vector
908 template<class Cmpt>
910 {
911  return Vector<Cmpt>(t.yz(), -t.xz(), t.xy());
912 }
913 
914 
915 //- Return the Hodge dual of a Vector as a Tensor
916 template<class Cmpt>
918 {
919  return Tensor<Cmpt>
920  (
921  Zero, -v.z(), v.y(),
922  v.z(), Zero, -v.x(),
923  -v.y(), v.x(), Zero
924  );
925 }
926 
927 
928 //- Division of a Vector by a Tensor
929 template<class Cmpt>
930 inline typename innerProduct<Vector<Cmpt>, Tensor<Cmpt>>::type
932 {
933  return inv(t) & v;
934 }
935 
936 
937 //- Division of a Tensor by a Cmpt
938 template<class Cmpt>
939 inline Tensor<Cmpt>
940 operator/(const Tensor<Cmpt>& t, const Cmpt s)
941 {
942  #ifdef FULLDEBUG
943  if (mag(s) < VSMALL)
944  {
946  << "Tensor = " << t
947  << " is not divisible due to a zero value in Cmpt:"
948  << "Cmpt = " << s
949  << abort(FatalError);
950  }
951  #endif
952 
953  return Tensor<Cmpt>
954  (
955  t.xx()/s, t.xy()/s, t.xz()/s,
956  t.yx()/s, t.yy()/s, t.yz()/s,
957  t.zx()/s, t.zy()/s, t.zz()/s
958  );
959 }
960 
961 
962 //- Inner-product of a Tensor and a Tensor
963 template<class Cmpt>
964 inline typename innerProduct<Tensor<Cmpt>, Tensor<Cmpt>>::type
965 operator&(const Tensor<Cmpt>& t1, const Tensor<Cmpt>& t2)
966 {
967  return t1.inner(t2);
968 }
969 
970 
971 //- Inner-product of a SphericalTensor and a Tensor
972 template<class Cmpt>
973 inline Tensor<Cmpt>
975 {
976  return Tensor<Cmpt>
977  (
978  st1.ii()*t2.xx(), st1.ii()*t2.xy(), st1.ii()*t2.xz(),
979  st1.ii()*t2.yx(), st1.ii()*t2.yy(), st1.ii()*t2.yz(),
980  st1.ii()*t2.zx(), st1.ii()*t2.zy(), st1.ii()*t2.zz()
981  );
982 }
983 
984 
985 //- Inner-product of a Tensor and a SphericalTensor
986 template<class Cmpt>
987 inline Tensor<Cmpt>
989 {
990  return Tensor<Cmpt>
991  (
992  t1.xx()*st2.ii(), t1.xy()*st2.ii(), t1.xz()*st2.ii(),
993  t1.yx()*st2.ii(), t1.yy()*st2.ii(), t1.yz()*st2.ii(),
994  t1.zx()*st2.ii(), t1.zy()*st2.ii(), t1.zz()*st2.ii()
995  );
996 }
997 
998 
999 //- Inner-product of a SymmTensor and a Tensor
1000 template<class Cmpt>
1001 inline Tensor<Cmpt>
1003 {
1004  return Tensor<Cmpt>
1005  (
1006  st1.xx()*t2.xx() + st1.xy()*t2.yx() + st1.xz()*t2.zx(),
1007  st1.xx()*t2.xy() + st1.xy()*t2.yy() + st1.xz()*t2.zy(),
1008  st1.xx()*t2.xz() + st1.xy()*t2.yz() + st1.xz()*t2.zz(),
1009 
1010  st1.xy()*t2.xx() + st1.yy()*t2.yx() + st1.yz()*t2.zx(),
1011  st1.xy()*t2.xy() + st1.yy()*t2.yy() + st1.yz()*t2.zy(),
1012  st1.xy()*t2.xz() + st1.yy()*t2.yz() + st1.yz()*t2.zz(),
1013 
1014  st1.xz()*t2.xx() + st1.yz()*t2.yx() + st1.zz()*t2.zx(),
1015  st1.xz()*t2.xy() + st1.yz()*t2.yy() + st1.zz()*t2.zy(),
1016  st1.xz()*t2.xz() + st1.yz()*t2.yz() + st1.zz()*t2.zz()
1017  );
1018 }
1019 
1020 
1021 //- Inner-product of a Tensor and a SymmTensor
1022 template<class Cmpt>
1023 inline Tensor<Cmpt>
1025 {
1026  return Tensor<Cmpt>
1027  (
1028  t1.xx()*st2.xx() + t1.xy()*st2.xy() + t1.xz()*st2.xz(),
1029  t1.xx()*st2.xy() + t1.xy()*st2.yy() + t1.xz()*st2.yz(),
1030  t1.xx()*st2.xz() + t1.xy()*st2.yz() + t1.xz()*st2.zz(),
1031 
1032  t1.yx()*st2.xx() + t1.yy()*st2.xy() + t1.yz()*st2.xz(),
1033  t1.yx()*st2.xy() + t1.yy()*st2.yy() + t1.yz()*st2.yz(),
1034  t1.yx()*st2.xz() + t1.yy()*st2.yz() + t1.yz()*st2.zz(),
1035 
1036  t1.zx()*st2.xx() + t1.zy()*st2.xy() + t1.zz()*st2.xz(),
1037  t1.zx()*st2.xy() + t1.zy()*st2.yy() + t1.zz()*st2.yz(),
1038  t1.zx()*st2.xz() + t1.zy()*st2.yz() + t1.zz()*st2.zz()
1039  );
1040 }
1041 
1042 
1043 //- Inner-product of a Tensor and a Vector
1044 template<class Cmpt>
1045 inline typename innerProduct<Tensor<Cmpt>, Vector<Cmpt>>::type
1047 {
1048  return Vector<Cmpt>
1049  (
1050  t.xx()*v.x() + t.xy()*v.y() + t.xz()*v.z(),
1051  t.yx()*v.x() + t.yy()*v.y() + t.yz()*v.z(),
1052  t.zx()*v.x() + t.zy()*v.y() + t.zz()*v.z()
1053  );
1054 }
1055 
1056 
1057 //- Inner-product of a Vector and a Tensor
1058 template<class Cmpt>
1059 inline typename innerProduct<Vector<Cmpt>, Tensor<Cmpt>>::type
1061 {
1062  return Vector<Cmpt>
1063  (
1064  v.x()*t.xx() + v.y()*t.yx() + v.z()*t.zx(),
1065  v.x()*t.xy() + v.y()*t.yy() + v.z()*t.zy(),
1066  v.x()*t.xz() + v.y()*t.yz() + v.z()*t.zz()
1067  );
1068 }
1069 
1070 
1071 //- Double-inner-product of a SphericalTensor and a Tensor
1072 template<class Cmpt>
1073 inline Cmpt
1075 {
1076  return (st1.ii()*t2.xx() + st1.ii()*t2.yy() + st1.ii()*t2.zz());
1077 }
1078 
1079 
1080 //- Double-inner-product of a Tensor and a SphericalTensor
1081 template<class Cmpt>
1082 inline Cmpt
1084 {
1085  return (t1.xx()*st2.ii() + t1.yy()*st2.ii() + t1.zz()*st2.ii());
1086 }
1087 
1088 
1089 //- Double-inner-product of a SymmTensor and a Tensor
1090 template<class Cmpt>
1091 inline Cmpt
1093 {
1094  return
1095  (
1096  st1.xx()*t2.xx() + st1.xy()*t2.xy() + st1.xz()*t2.xz() +
1097  st1.xy()*t2.yx() + st1.yy()*t2.yy() + st1.yz()*t2.yz() +
1098  st1.xz()*t2.zx() + st1.yz()*t2.zy() + st1.zz()*t2.zz()
1099  );
1100 }
1101 
1102 
1103 //- Double-inner-product of a Tensor and a SymmTensor
1104 template<class Cmpt>
1105 inline Cmpt
1107 {
1108  return
1109  (
1110  t1.xx()*st2.xx() + t1.xy()*st2.xy() + t1.xz()*st2.xz() +
1111  t1.yx()*st2.xy() + t1.yy()*st2.yy() + t1.yz()*st2.yz() +
1112  t1.zx()*st2.xz() + t1.zy()*st2.yz() + t1.zz()*st2.zz()
1113  );
1114 }
1115 
1116 
1117 //- Outer-product of a Vector and a Vector
1118 template<class Cmpt>
1119 inline typename outerProduct<Vector<Cmpt>, Vector<Cmpt>>::type
1120 operator*(const Vector<Cmpt>& v1, const Vector<Cmpt>& v2)
1121 {
1122  return Tensor<Cmpt>
1123  (
1124  v1.x()*v2.x(), v1.x()*v2.y(), v1.x()*v2.z(),
1125  v1.y()*v2.x(), v1.y()*v2.y(), v1.y()*v2.z(),
1126  v1.z()*v2.x(), v1.z()*v2.y(), v1.z()*v2.z()
1127  );
1128 }
1129 
1130 
1131 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1132 
1133 template<class Cmpt>
1134 class typeOfSum<SphericalTensor<Cmpt>, Tensor<Cmpt>>
1135 {
1136 public:
1137 
1139 };
1140 
1141 
1142 template<class Cmpt>
1143 class typeOfSum<Tensor<Cmpt>, SphericalTensor<Cmpt>>
1144 {
1145 public:
1146 
1148 };
1149 
1150 
1151 template<class Cmpt>
1153 {
1154 public:
1155 
1157 };
1158 
1159 
1160 template<class Cmpt>
1162 {
1163 public:
1164 
1166 };
1167 
1168 
1169 template<class Cmpt>
1170 class typeOfSum<SymmTensor<Cmpt>, Tensor<Cmpt>>
1171 {
1172 public:
1173 
1175 };
1176 
1177 
1178 template<class Cmpt>
1179 class typeOfSum<Tensor<Cmpt>, SymmTensor<Cmpt>>
1180 {
1181 public:
1182 
1184 };
1185 
1186 
1187 template<class Cmpt>
1188 class innerProduct<SymmTensor<Cmpt>, Tensor<Cmpt>>
1189 {
1190 public:
1191 
1193 };
1194 
1195 
1196 template<class Cmpt>
1197 class innerProduct<Tensor<Cmpt>, SymmTensor<Cmpt>>
1198 {
1199 public:
1200 
1202 };
1203 
1204 
1205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1206 
1207 } // End namespace Foam
1208 
1209 // ************************************************************************* //
Foam::typeOfSum< Tensor< Cmpt >, SphericalTensor< Cmpt > >::type
Tensor< Cmpt > type
Definition: TensorI.H:1147
Foam::Tensor
A templated (3 x 3) tensor of objects of <T> derived from MatrixSpace.
Definition: complexI.H:275
Foam::Vector::x
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
Foam::symm
dimensionedSymmTensor symm(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:84
Foam::block
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
Definition: block.H:58
Foam::SymmTensor
A templated (3 x 3) symmetric tensor of objects of <T>, effectively containing 6 elements,...
Definition: SymmTensor.H:58
Foam::Tensor::zx
const Cmpt & zx() const
Definition: TensorI.H:194
s
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))
Definition: gmvOutputSpray.H:25
Foam::invariantIII
Cmpt invariantIII(const SymmTensor< Cmpt > &st)
Return the 3rd invariant of a SymmTensor.
Definition: SymmTensorI.H:362
Foam::skew
dimensionedTensor skew(const dimensionedTensor &dt)
Definition: dimensionedTensor.C:138
Foam::SymmTensor::yz
const Cmpt & yz() const
Definition: SymmTensorI.H:114
Foam::Tensor::inv
Tensor< Cmpt > inv() const
Return inverse.
Definition: TensorI.H:759
Foam::Tensor::z
Vector< Cmpt > z() const
Extract vector for row 2.
Definition: TensorI.H:292
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 SymmTensor.
Definition: SymmTensorI.H:342
Foam::SymmTensor::xz
const Cmpt & xz() const
Definition: SymmTensorI.H:96
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
SymmTensor.H
Foam::typeOfSum< Tensor< Cmpt >, SymmTensor< Cmpt > >::type
Tensor< Cmpt > type
Definition: TensorI.H:1183
Foam::innerProduct
Definition: products.H:141
Foam::operator-
tmp< faMatrix< Type > > operator-(const faMatrix< Type > &)
Foam::Tensor::inner
Tensor< Cmpt > inner(const Tensor< Cmpt > &t2) const
Inner-product of this with another Tensor.
Definition: TensorI.H:517
Foam::Tensor::yx
const Cmpt & yx() const
Definition: TensorI.H:173
Foam::tr
Cmpt tr(const Tensor< Cmpt > &t)
Return the trace of a Tensor.
Definition: TensorI.H:617
Foam::Tensor::cy
Vector< Cmpt > cy() const
Extract vector for column 1.
Definition: TensorI.H:306
Foam::typeOfSum< SymmTensor< Cmpt >, Tensor< Cmpt > >::type
Tensor< Cmpt > type
Definition: TensorI.H:1174
Foam::dev2
dimensionedSymmTensor dev2(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:117
Foam::dimensioned::T
dimensioned< Type > T() const
Return transpose.
Definition: dimensionedSphericalTensor.C:38
Foam::Vector::z
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
Foam::Tensor::row
Vector< Cmpt > row() const
Extract vector for given row.
Foam::Tensor::xz
const Cmpt & xz() const
Definition: TensorI.H:166
Foam::Tensor::operator=
Tensor & operator=(const Tensor &)=default
Copy assignment.
Foam::Tensor::yz
const Cmpt & yz() const
Definition: TensorI.H:187
Foam::VectorSpace
Templated vector space.
Definition: VectorSpace.H:56
Foam::SymmTensor::xx
const Cmpt & xx() const
Definition: SymmTensorI.H:84
Foam::MatrixSpace
Templated matrix space.
Definition: MatrixSpace.H:58
Foam::Tensor::zy
const Cmpt & zy() const
Definition: TensorI.H:201
Foam::typeOfSum
Definition: products.H:97
Foam::SymmTensor::xy
const Cmpt & xy() const
Definition: SymmTensorI.H:90
Foam::Tensor::yy
const Cmpt & yy() const
Definition: TensorI.H:180
Foam::Tensor::operator&=
void operator&=(const Tensor< Cmpt > &t)
Assign inner-product of this with another Tensor.
Definition: TensorI.H:556
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::inv
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:73
Foam::Tensor::schur
Tensor< Cmpt > schur(const Tensor< Cmpt > &t2) const
Schur-product of this with another Tensor.
Definition: TensorI.H:540
Foam::Tensor::cz
Vector< Cmpt > cz() const
Extract vector for column 2.
Definition: TensorI.H:313
Foam::Tensor::zz
const Cmpt & zz() const
Definition: TensorI.H:208
Foam::Tensor::x
Vector< Cmpt > x() const
Extract vector for row 0.
Definition: TensorI.H:278
Foam::Tensor::diag
Vector< Cmpt > diag() const
Extract the diagonal as a vector.
Definition: TensorI.H:488
Foam::innerProduct< Tensor< Cmpt >, SymmTensor< Cmpt > >::type
Tensor< Cmpt > type
Definition: TensorI.H:1201
Foam::sph
SphericalTensor< Cmpt > sph(const DiagTensor< Cmpt > &dt)
Return the spherical part of a DiagTensor as a SphericalTensor.
Definition: DiagTensorI.H:130
Foam::operator&&
dimensioned< typename scalarProduct< Type1, Type2 >::type > operator&&(const dimensioned< Type1 > &, const dimensioned< Type2 > &)
Foam::FatalError
error FatalError
Foam::Tensor::xy
const Cmpt & xy() const
Definition: TensorI.H:159
Foam::invariantII
Cmpt invariantII(const SymmTensor< Cmpt > &st)
Return the 2nd invariant of a SymmTensor.
Definition: SymmTensorI.H:350
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::cof
dimensionedSymmTensor cof(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:139
Foam::SphericalTensor::ii
const Cmpt & ii() const
Definition: SphericalTensorI.H:68
Foam::SphericalTensor
A templated (3 x 3) diagonal tensor of objects of <T>, effectively containing 1 element,...
Definition: SphericalTensor.H:57
Foam::operator/
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
Definition: dimensionedScalar.C:68
Foam::innerProduct< SymmTensor< Cmpt >, Tensor< Cmpt > >::type
Tensor< Cmpt > type
Definition: TensorI.H:1192
Foam::Tensor::xx
const Cmpt & xx() const
Definition: TensorI.H:152
Foam::Vector::y
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::Tensor::y
Vector< Cmpt > y() const
Extract vector for row 1.
Definition: TensorI.H:285
Foam::SymmTensor::yy
const Cmpt & yy() const
Definition: SymmTensorI.H:108
Foam::Tensor::cx
Vector< Cmpt > cx() const
Extract vector for column 0.
Definition: TensorI.H:299
Foam::Vector
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition: Vector.H:62
Foam::operator+
tmp< faMatrix< Type > > operator+(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::operator*
tmp< faMatrix< Type > > operator*(const areaScalarField &, const faMatrix< Type > &)
Foam::Tensor::cols
void cols(const Vector< Cmpt > &x, const Vector< Cmpt > &y, const Vector< Cmpt > &z)
Set column values.
Definition: TensorI.H:429
Foam::Tensor::Tensor
Tensor()=default
Default construct.
Foam::direction
uint8_t direction
Definition: direction.H:52
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::Tensor::T
Tensor< Cmpt > T() const
Return non-Hermitian transpose.
Definition: TensorI.H:504
Foam::SymmTensor::zz
const Cmpt & zz() const
Definition: SymmTensorI.H:132
Foam::typeOfSum< SphericalTensor< Cmpt >, Tensor< Cmpt > >::type
Tensor< Cmpt > type
Definition: TensorI.H:1138
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::tr
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:51
Foam::det
dimensionedScalar det(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:62
Foam::Tensor::col
Vector< Cmpt > col() const
Extract vector for given column.
Foam::Tensor::rows
void rows(const Vector< Cmpt > &x, const Vector< Cmpt > &y, const Vector< Cmpt > &z)
Set row values.
Definition: TensorI.H:443
Foam::innerProduct< Tensor< Cmpt >, SphericalTensor< Cmpt > >::type
Tensor< Cmpt > type
Definition: TensorI.H:1165
Foam::twoSymm
dimensionedSymmTensor twoSymm(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:95
Foam::innerProduct< SphericalTensor< Cmpt >, Tensor< Cmpt > >::type
Tensor< Cmpt > type
Definition: TensorI.H:1156
y
scalar y
Definition: LISASMDCalcMethod1.H:14
Foam::zero
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:62
Foam::dev
dimensionedSymmTensor dev(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:106