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) < VSMALL)
737  {
739  << "Tensor is not invertible due to the (almost) zero determinant:"
740  << " Tensor = " << t << nl
741  << " det(Tensor) = " << dett
742  << abort(FatalError);
743  }
744  #endif
745 
746  return cof(t).T()/dett;
747 }
748 
749 
750 //- Return the inverse of a Tensor
751 template<class Cmpt>
752 inline Tensor<Cmpt> inv(const Tensor<Cmpt>& t)
753 {
754  return inv(t, det(t));
755 }
756 
757 
758 //- Return the inverse of this Tensor
759 template<class Cmpt>
761 {
762  return Foam::inv(*this);
763 }
764 
765 
766 //- Return the 1st invariant of a Tensor
767 template<class Cmpt>
768 inline Cmpt invariantI(const Tensor<Cmpt>& t)
769 {
770  return tr(t);
771 }
772 
773 
774 //- Return the 2nd invariant of a Tensor
775 template<class Cmpt>
776 inline Cmpt invariantII(const Tensor<Cmpt>& t)
777 {
778  return
779  (
780  t.xx()*t.yy() + t.yy()*t.zz() + t.xx()*t.zz()
781  - t.xy()*t.yx() - t.yz()*t.zy() - t.xz()*t.zx()
782  );
783 }
784 
785 
786 //- Return the 3rd invariant of a Tensor
787 template<class Cmpt>
788 inline Cmpt invariantIII(const Tensor<Cmpt>& t)
789 {
790  return det(t);
791 }
792 
793 
794 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
795 
796 //- Sum of a SphericalTensor and a Tensor
797 template<class Cmpt>
798 inline Tensor<Cmpt>
800 {
801  return Tensor<Cmpt>
802  (
803  st1.ii() + t2.xx(), t2.xy(), t2.xz(),
804  t2.yx(), st1.ii() + t2.yy(), t2.yz(),
805  t2.zx(), t2.zy(), st1.ii() + t2.zz()
806  );
807 }
808 
809 
810 //- Sum of a Tensor and a SphericalTensor
811 template<class Cmpt>
812 inline Tensor<Cmpt>
814 {
815  return Tensor<Cmpt>
816  (
817  t1.xx() + st2.ii(), t1.xy(), t1.xz(),
818  t1.yx(), t1.yy() + st2.ii(), t1.yz(),
819  t1.zx(), t1.zy(), t1.zz() + st2.ii()
820  );
821 }
822 
823 
824 //- Sum of a SymmTensor and a Tensor
825 template<class Cmpt>
826 inline Tensor<Cmpt>
828 {
829  return Tensor<Cmpt>
830  (
831  st1.xx() + t2.xx(), st1.xy() + t2.xy(), st1.xz() + t2.xz(),
832  st1.xy() + t2.yx(), st1.yy() + t2.yy(), st1.yz() + t2.yz(),
833  st1.xz() + t2.zx(), st1.yz() + t2.zy(), st1.zz() + t2.zz()
834  );
835 }
836 
837 
838 //- Sum of a Tensor and a SymmTensor
839 template<class Cmpt>
840 inline Tensor<Cmpt>
842 {
843  return Tensor<Cmpt>
844  (
845  t1.xx() + st2.xx(), t1.xy() + st2.xy(), t1.xz() + st2.xz(),
846  t1.yx() + st2.xy(), t1.yy() + st2.yy(), t1.yz() + st2.yz(),
847  t1.zx() + st2.xz(), t1.zy() + st2.yz(), t1.zz() + st2.zz()
848  );
849 }
850 
851 
852 //- Subtract a Tensor from a SphericalTensor
853 template<class Cmpt>
854 inline Tensor<Cmpt>
856 {
857  return Tensor<Cmpt>
858  (
859  st1.ii() - t2.xx(), -t2.xy(), -t2.xz(),
860  -t2.yx(), st1.ii() - t2.yy(), -t2.yz(),
861  -t2.zx(), -t2.zy(), st1.ii() - t2.zz()
862  );
863 }
864 
865 
866 //- Subtract a SphericalTensor from a Tensor
867 template<class Cmpt>
868 inline Tensor<Cmpt>
870 {
871  return Tensor<Cmpt>
872  (
873  t1.xx() - st2.ii(), t1.xy(), t1.xz(),
874  t1.yx(), t1.yy() - st2.ii(), t1.yz(),
875  t1.zx(), t1.zy(), t1.zz() - st2.ii()
876  );
877 }
878 
879 
880 //- Subtract a Tensor from a SymmTensor
881 template<class Cmpt>
882 inline Tensor<Cmpt>
884 {
885  return Tensor<Cmpt>
886  (
887  st1.xx() - t2.xx(), st1.xy() - t2.xy(), st1.xz() - t2.xz(),
888  st1.xy() - t2.yx(), st1.yy() - t2.yy(), st1.yz() - t2.yz(),
889  st1.xz() - t2.zx(), st1.yz() - t2.zy(), st1.zz() - t2.zz()
890  );
891 }
892 
893 
894 //- Subtract a SymmTensor from a Tensor
895 template<class Cmpt>
896 inline Tensor<Cmpt>
898 {
899  return Tensor<Cmpt>
900  (
901  t1.xx() - st2.xx(), t1.xy() - st2.xy(), t1.xz() - st2.xz(),
902  t1.yx() - st2.xy(), t1.yy() - st2.yy(), t1.yz() - st2.yz(),
903  t1.zx() - st2.xz(), t1.zy() - st2.yz(), t1.zz() - st2.zz()
904  );
905 }
906 
907 
908 //- Return the Hodge dual of a Tensor as a Vector
909 template<class Cmpt>
911 {
912  return Vector<Cmpt>(t.yz(), -t.xz(), t.xy());
913 }
914 
915 
916 //- Return the Hodge dual of a Vector as a Tensor
917 template<class Cmpt>
919 {
920  return Tensor<Cmpt>
921  (
922  Zero, -v.z(), v.y(),
923  v.z(), Zero, -v.x(),
924  -v.y(), v.x(), Zero
925  );
926 }
927 
928 
929 //- Division of a Vector by a Tensor
930 template<class Cmpt>
931 inline typename innerProduct<Vector<Cmpt>, Tensor<Cmpt>>::type
933 {
934  return inv(t) & v;
935 }
936 
937 
938 //- Division of a Tensor by a Cmpt
939 template<class Cmpt>
940 inline Tensor<Cmpt>
941 operator/(const Tensor<Cmpt>& t, const Cmpt s)
942 {
943  #ifdef FULLDEBUG
944  if (mag(s) < VSMALL)
945  {
947  << "Tensor = " << t
948  << " is not divisible due to a zero value in Cmpt:"
949  << "Cmpt = " << s
950  << abort(FatalError);
951  }
952  #endif
953 
954  return Tensor<Cmpt>
955  (
956  t.xx()/s, t.xy()/s, t.xz()/s,
957  t.yx()/s, t.yy()/s, t.yz()/s,
958  t.zx()/s, t.zy()/s, t.zz()/s
959  );
960 }
961 
962 
963 //- Inner-product of a Tensor and a Tensor
964 template<class Cmpt>
965 inline typename innerProduct<Tensor<Cmpt>, Tensor<Cmpt>>::type
966 operator&(const Tensor<Cmpt>& t1, const Tensor<Cmpt>& t2)
967 {
968  return t1.inner(t2);
969 }
970 
971 
972 //- Inner-product of a SphericalTensor and a Tensor
973 template<class Cmpt>
974 inline Tensor<Cmpt>
976 {
977  return Tensor<Cmpt>
978  (
979  st1.ii()*t2.xx(), st1.ii()*t2.xy(), st1.ii()*t2.xz(),
980  st1.ii()*t2.yx(), st1.ii()*t2.yy(), st1.ii()*t2.yz(),
981  st1.ii()*t2.zx(), st1.ii()*t2.zy(), st1.ii()*t2.zz()
982  );
983 }
984 
985 
986 //- Inner-product of a Tensor and a SphericalTensor
987 template<class Cmpt>
988 inline Tensor<Cmpt>
990 {
991  return Tensor<Cmpt>
992  (
993  t1.xx()*st2.ii(), t1.xy()*st2.ii(), t1.xz()*st2.ii(),
994  t1.yx()*st2.ii(), t1.yy()*st2.ii(), t1.yz()*st2.ii(),
995  t1.zx()*st2.ii(), t1.zy()*st2.ii(), t1.zz()*st2.ii()
996  );
997 }
998 
999 
1000 //- Inner-product of a SymmTensor and a Tensor
1001 template<class Cmpt>
1002 inline Tensor<Cmpt>
1004 {
1005  return Tensor<Cmpt>
1006  (
1007  st1.xx()*t2.xx() + st1.xy()*t2.yx() + st1.xz()*t2.zx(),
1008  st1.xx()*t2.xy() + st1.xy()*t2.yy() + st1.xz()*t2.zy(),
1009  st1.xx()*t2.xz() + st1.xy()*t2.yz() + st1.xz()*t2.zz(),
1010 
1011  st1.xy()*t2.xx() + st1.yy()*t2.yx() + st1.yz()*t2.zx(),
1012  st1.xy()*t2.xy() + st1.yy()*t2.yy() + st1.yz()*t2.zy(),
1013  st1.xy()*t2.xz() + st1.yy()*t2.yz() + st1.yz()*t2.zz(),
1014 
1015  st1.xz()*t2.xx() + st1.yz()*t2.yx() + st1.zz()*t2.zx(),
1016  st1.xz()*t2.xy() + st1.yz()*t2.yy() + st1.zz()*t2.zy(),
1017  st1.xz()*t2.xz() + st1.yz()*t2.yz() + st1.zz()*t2.zz()
1018  );
1019 }
1020 
1021 
1022 //- Inner-product of a Tensor and a SymmTensor
1023 template<class Cmpt>
1024 inline Tensor<Cmpt>
1026 {
1027  return Tensor<Cmpt>
1028  (
1029  t1.xx()*st2.xx() + t1.xy()*st2.xy() + t1.xz()*st2.xz(),
1030  t1.xx()*st2.xy() + t1.xy()*st2.yy() + t1.xz()*st2.yz(),
1031  t1.xx()*st2.xz() + t1.xy()*st2.yz() + t1.xz()*st2.zz(),
1032 
1033  t1.yx()*st2.xx() + t1.yy()*st2.xy() + t1.yz()*st2.xz(),
1034  t1.yx()*st2.xy() + t1.yy()*st2.yy() + t1.yz()*st2.yz(),
1035  t1.yx()*st2.xz() + t1.yy()*st2.yz() + t1.yz()*st2.zz(),
1036 
1037  t1.zx()*st2.xx() + t1.zy()*st2.xy() + t1.zz()*st2.xz(),
1038  t1.zx()*st2.xy() + t1.zy()*st2.yy() + t1.zz()*st2.yz(),
1039  t1.zx()*st2.xz() + t1.zy()*st2.yz() + t1.zz()*st2.zz()
1040  );
1041 }
1042 
1043 
1044 //- Inner-product of a Tensor and a Vector
1045 template<class Cmpt>
1046 inline typename innerProduct<Tensor<Cmpt>, Vector<Cmpt>>::type
1048 {
1049  return Vector<Cmpt>
1050  (
1051  t.xx()*v.x() + t.xy()*v.y() + t.xz()*v.z(),
1052  t.yx()*v.x() + t.yy()*v.y() + t.yz()*v.z(),
1053  t.zx()*v.x() + t.zy()*v.y() + t.zz()*v.z()
1054  );
1055 }
1056 
1057 
1058 //- Inner-product of a Vector and a Tensor
1059 template<class Cmpt>
1060 inline typename innerProduct<Vector<Cmpt>, Tensor<Cmpt>>::type
1062 {
1063  return Vector<Cmpt>
1064  (
1065  v.x()*t.xx() + v.y()*t.yx() + v.z()*t.zx(),
1066  v.x()*t.xy() + v.y()*t.yy() + v.z()*t.zy(),
1067  v.x()*t.xz() + v.y()*t.yz() + v.z()*t.zz()
1068  );
1069 }
1070 
1071 
1072 //- Double-inner-product of a SphericalTensor and a Tensor
1073 template<class Cmpt>
1074 inline Cmpt
1076 {
1077  return (st1.ii()*t2.xx() + st1.ii()*t2.yy() + st1.ii()*t2.zz());
1078 }
1079 
1080 
1081 //- Double-inner-product of a Tensor and a SphericalTensor
1082 template<class Cmpt>
1083 inline Cmpt
1085 {
1086  return (t1.xx()*st2.ii() + t1.yy()*st2.ii() + t1.zz()*st2.ii());
1087 }
1088 
1089 
1090 //- Double-inner-product of a SymmTensor and a Tensor
1091 template<class Cmpt>
1092 inline Cmpt
1094 {
1095  return
1096  (
1097  st1.xx()*t2.xx() + st1.xy()*t2.xy() + st1.xz()*t2.xz() +
1098  st1.xy()*t2.yx() + st1.yy()*t2.yy() + st1.yz()*t2.yz() +
1099  st1.xz()*t2.zx() + st1.yz()*t2.zy() + st1.zz()*t2.zz()
1100  );
1101 }
1102 
1103 
1104 //- Double-inner-product of a Tensor and a SymmTensor
1105 template<class Cmpt>
1106 inline Cmpt
1108 {
1109  return
1110  (
1111  t1.xx()*st2.xx() + t1.xy()*st2.xy() + t1.xz()*st2.xz() +
1112  t1.yx()*st2.xy() + t1.yy()*st2.yy() + t1.yz()*st2.yz() +
1113  t1.zx()*st2.xz() + t1.zy()*st2.yz() + t1.zz()*st2.zz()
1114  );
1115 }
1116 
1117 
1118 //- Outer-product of a Vector and a Vector
1119 template<class Cmpt>
1120 inline typename outerProduct<Vector<Cmpt>, Vector<Cmpt>>::type
1121 operator*(const Vector<Cmpt>& v1, const Vector<Cmpt>& v2)
1122 {
1123  return Tensor<Cmpt>
1124  (
1125  v1.x()*v2.x(), v1.x()*v2.y(), v1.x()*v2.z(),
1126  v1.y()*v2.x(), v1.y()*v2.y(), v1.y()*v2.z(),
1127  v1.z()*v2.x(), v1.z()*v2.y(), v1.z()*v2.z()
1128  );
1129 }
1130 
1131 
1132 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1133 
1134 template<class Cmpt>
1135 class typeOfSum<SphericalTensor<Cmpt>, Tensor<Cmpt>>
1136 {
1137 public:
1138 
1140 };
1141 
1142 
1143 template<class Cmpt>
1144 class typeOfSum<Tensor<Cmpt>, SphericalTensor<Cmpt>>
1145 {
1146 public:
1147 
1149 };
1150 
1151 
1152 template<class Cmpt>
1154 {
1155 public:
1156 
1158 };
1159 
1160 
1161 template<class Cmpt>
1163 {
1164 public:
1165 
1167 };
1168 
1169 
1170 template<class Cmpt>
1171 class typeOfSum<SymmTensor<Cmpt>, Tensor<Cmpt>>
1172 {
1173 public:
1174 
1176 };
1177 
1178 
1179 template<class Cmpt>
1180 class typeOfSum<Tensor<Cmpt>, SymmTensor<Cmpt>>
1181 {
1182 public:
1183 
1185 };
1186 
1187 
1188 template<class Cmpt>
1189 class innerProduct<SymmTensor<Cmpt>, Tensor<Cmpt>>
1190 {
1191 public:
1192 
1194 };
1195 
1196 
1197 template<class Cmpt>
1198 class innerProduct<Tensor<Cmpt>, SymmTensor<Cmpt>>
1199 {
1200 public:
1201 
1203 };
1204 
1205 
1206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1207 
1208 } // End namespace Foam
1209 
1210 // ************************************************************************* //
Foam::typeOfSum< Tensor< Cmpt >, SphericalTensor< Cmpt > >::type
Tensor< Cmpt > type
Definition: TensorI.H:1148
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:760
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:1184
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:1175
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:1202
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:1193
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:453
Foam::Tensor::y
Vector< Cmpt > y() const
Extract vector for row 1.
Definition: TensorI.H:285
Foam::nl
constexpr char nl
Definition: Ostream.H:404
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:1139
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:1166
Foam::twoSymm
dimensionedSymmTensor twoSymm(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:95
Foam::innerProduct< SphericalTensor< Cmpt >, Tensor< Cmpt > >::type
Tensor< Cmpt > type
Definition: TensorI.H:1157
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