SymmTensorI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "Vector.H"
27 #include "Tensor.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class Cmpt>
33 {}
34 
35 
36 template<class Cmpt>
38 :
40 {}
41 
42 
43 template<class Cmpt>
44 template<class Cmpt2>
46 (
47  const VectorSpace<SymmTensor<Cmpt2>, Cmpt2, 6>& vs
48 )
49 :
50  SymmTensor::vsType(vs)
51 {}
52 
53 
54 template<class Cmpt>
56 {
57  this->v_[XX] = st.ii(); this->v_[XY] = 0; this->v_[XZ] = 0;
58  this->v_[YY] = st.ii(); this->v_[YZ] = 0;
59  this->v_[ZZ] = st.ii();
60 }
61 
62 
63 template<class Cmpt>
65 (
66  const Cmpt txx, const Cmpt txy, const Cmpt txz,
67  const Cmpt tyy, const Cmpt tyz,
68  const Cmpt tzz
69 )
70 {
71  this->v_[XX] = txx; this->v_[XY] = txy; this->v_[XZ] = txz;
72  this->v_[YY] = tyy; this->v_[YZ] = tyz;
73  this->v_[ZZ] = tzz;
74 }
75 
76 
77 template<class Cmpt>
79 :
80  SymmTensor::vsType(is)
81 {}
82 
83 
84 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
85 
86 template<class Cmpt>
87 inline const Cmpt& Foam::SymmTensor<Cmpt>::xx() const
88 {
89  return this->v_[XX];
90 }
91 
92 template<class Cmpt>
93 inline const Cmpt& Foam::SymmTensor<Cmpt>::xy() const
94 {
95  return this->v_[XY];
96 }
97 
98 template<class Cmpt>
99 inline const Cmpt& Foam::SymmTensor<Cmpt>::xz() const
100 {
101  return this->v_[XZ];
102 }
103 
104 template<class Cmpt>
105 inline const Cmpt& Foam::SymmTensor<Cmpt>::yx() const
106 {
107  return this->v_[XY];
108 }
109 
110 template<class Cmpt>
111 inline const Cmpt& Foam::SymmTensor<Cmpt>::yy() const
112 {
113  return this->v_[YY];
114 }
115 
116 template<class Cmpt>
117 inline const Cmpt& Foam::SymmTensor<Cmpt>::yz() const
118 {
119  return this->v_[YZ];
120 }
121 
122 template<class Cmpt>
123 inline const Cmpt& Foam::SymmTensor<Cmpt>::zx() const
124 {
125  return this->v_[XZ];
126 }
127 
128 template<class Cmpt>
129 inline const Cmpt& Foam::SymmTensor<Cmpt>::zy() const
130 {
131  return this->v_[YZ];
132 }
133 
134 template<class Cmpt>
135 inline const Cmpt& Foam::SymmTensor<Cmpt>::zz() const
136 {
137  return this->v_[ZZ];
138 }
139 
140 
141 template<class Cmpt>
143 {
144  return this->v_[XX];
145 }
146 
147 template<class Cmpt>
149 {
150  return this->v_[XY];
151 }
152 
153 template<class Cmpt>
155 {
156  return this->v_[XZ];
157 }
158 
159 template<class Cmpt>
161 {
162  return this->v_[YY];
163 }
164 
165 template<class Cmpt>
167 {
168  return this->v_[YZ];
169 }
170 
171 template<class Cmpt>
173 {
174  return this->v_[ZZ];
175 }
176 
177 
178 template<class Cmpt>
180 {
181  return *this;
182 }
183 
184 
185 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
186 
187 template<class Cmpt>
189 {
190  this->v_[XX] = st.ii(); this->v_[XY] = 0; this->v_[XZ] = 0;
191  this->v_[YY] = st.ii(); this->v_[YZ] = 0;
192  this->v_[ZZ] = st.ii();
193 }
194 
195 
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197 
198 namespace Foam
199 {
200 
201 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
202 
203 //- Hodge Dual operator (tensor -> vector)
204 template<class Cmpt>
206 {
207  return Vector<Cmpt>(st.yz(), -st.xz(), st.xy());
208 }
209 
210 
211 //- Inner-product between two symmetric tensors
212 template<class Cmpt>
213 inline Tensor<Cmpt>
215 {
216  return Tensor<Cmpt>
217  (
218  st1.xx()*st2.xx() + st1.xy()*st2.xy() + st1.xz()*st2.xz(),
219  st1.xx()*st2.xy() + st1.xy()*st2.yy() + st1.xz()*st2.yz(),
220  st1.xx()*st2.xz() + st1.xy()*st2.yz() + st1.xz()*st2.zz(),
221 
222  st1.xy()*st2.xx() + st1.yy()*st2.xy() + st1.yz()*st2.xz(),
223  st1.xy()*st2.xy() + st1.yy()*st2.yy() + st1.yz()*st2.yz(),
224  st1.xy()*st2.xz() + st1.yy()*st2.yz() + st1.yz()*st2.zz(),
225 
226  st1.xz()*st2.xx() + st1.yz()*st2.xy() + st1.zz()*st2.xz(),
227  st1.xz()*st2.xy() + st1.yz()*st2.yy() + st1.zz()*st2.yz(),
228  st1.xz()*st2.xz() + st1.yz()*st2.yz() + st1.zz()*st2.zz()
229  );
230 }
231 
232 
233 //- Double-dot-product between a symmetric tensor and a symmetric tensor
234 template<class Cmpt>
235 inline Cmpt
237 {
238  return
239  (
240  st1.xx()*st2.xx() + 2*st1.xy()*st2.xy() + 2*st1.xz()*st2.xz()
241  + st1.yy()*st2.yy() + 2*st1.yz()*st2.yz()
242  + st1.zz()*st2.zz()
243  );
244 }
245 
246 
247 //- Inner-product between a symmetric tensor and a vector
248 template<class Cmpt>
249 inline Vector<Cmpt>
251 {
252  return Vector<Cmpt>
253  (
254  st.xx()*v.x() + st.xy()*v.y() + st.xz()*v.z(),
255  st.xy()*v.x() + st.yy()*v.y() + st.yz()*v.z(),
256  st.xz()*v.x() + st.yz()*v.y() + st.zz()*v.z()
257  );
258 }
259 
260 
261 //- Inner-product between a vector and a symmetric tensor
262 template<class Cmpt>
263 inline Vector<Cmpt>
265 {
266  return Vector<Cmpt>
267  (
268  v.x()*st.xx() + v.y()*st.xy() + v.z()*st.xz(),
269  v.x()*st.xy() + v.y()*st.yy() + v.z()*st.yz(),
270  v.x()*st.xz() + v.y()*st.yz() + v.z()*st.zz()
271  );
272 }
273 
274 
275 //- Inner-sqr of a symmetric tensor
276 template<class Cmpt>
277 inline SymmTensor<Cmpt>
279 {
280  return SymmTensor<Cmpt>
281  (
282  st.xx()*st.xx() + st.xy()*st.xy() + st.xz()*st.xz(),
283  st.xx()*st.xy() + st.xy()*st.yy() + st.xz()*st.yz(),
284  st.xx()*st.xz() + st.xy()*st.yz() + st.xz()*st.zz(),
285 
286  st.xy()*st.xy() + st.yy()*st.yy() + st.yz()*st.yz(),
287  st.xy()*st.xz() + st.yy()*st.yz() + st.yz()*st.zz(),
288 
289  st.xz()*st.xz() + st.yz()*st.yz() + st.zz()*st.zz()
290  );
291 }
292 
293 
294 template<class Cmpt>
295 inline Cmpt magSqr(const SymmTensor<Cmpt>& st)
296 {
297  return
298  (
299  magSqr(st.xx()) + 2*magSqr(st.xy()) + 2*magSqr(st.xz())
300  + magSqr(st.yy()) + 2*magSqr(st.yz())
301  + magSqr(st.zz())
302  );
303 }
304 
305 
306 //- Return the trace of a symmetric tensor
307 template<class Cmpt>
308 inline Cmpt tr(const SymmTensor<Cmpt>& st)
309 {
310  return st.xx() + st.yy() + st.zz();
311 }
312 
313 
314 //- Return the spherical part of a symmetric tensor
315 template<class Cmpt>
317 {
318  return (1.0/3.0)*tr(st);
319 }
320 
321 
322 //- Return the symmetric part of a symmetric tensor, i.e. itself
323 template<class Cmpt>
324 inline const SymmTensor<Cmpt>& symm(const SymmTensor<Cmpt>& st)
325 {
326  return st;
327 }
328 
329 
330 //- Return twice the symmetric part of a symmetric tensor
331 template<class Cmpt>
333 {
334  return 2*st;
335 }
336 
337 
338 //- Return the deviatoric part of a symmetric tensor
339 template<class Cmpt>
341 {
342  return st - SphericalTensor<Cmpt>::oneThirdI*tr(st);
343 }
344 
345 
346 //- Return the deviatoric part of a symmetric tensor
347 template<class Cmpt>
349 {
350  return st - SphericalTensor<Cmpt>::twoThirdsI*tr(st);
351 }
352 
353 
354 //- Return the determinant of a symmetric tensor
355 template<class Cmpt>
356 inline Cmpt det(const SymmTensor<Cmpt>& st)
357 {
358  return
359  (
360  st.xx()*st.yy()*st.zz() + st.xy()*st.yz()*st.xz()
361  + st.xz()*st.xy()*st.yz() - st.xx()*st.yz()*st.yz()
362  - st.xy()*st.xy()*st.zz() - st.xz()*st.yy()*st.xz()
363  );
364 }
365 
366 
367 //- Return the cofactor symmetric tensor of a symmetric tensor
368 template<class Cmpt>
370 {
371  return SymmTensor<Cmpt>
372  (
373  st.yy()*st.zz() - st.yz()*st.yz(),
374  st.xz()*st.yz() - st.xy()*st.zz(),
375  st.xy()*st.yz() - st.xz()*st.yy(),
376 
377  st.xx()*st.zz() - st.xz()*st.xz(),
378  st.xy()*st.xz() - st.xx()*st.yz(),
379 
380  st.xx()*st.yy() - st.xy()*st.xy()
381  );
382 }
383 
384 
385 //- Return the inverse of a symmetric tensor give the determinant
386 template<class Cmpt>
387 inline SymmTensor<Cmpt> inv(const SymmTensor<Cmpt>& st, const Cmpt detst)
388 {
389  return SymmTensor<Cmpt>
390  (
391  st.yy()*st.zz() - st.yz()*st.yz(),
392  st.xz()*st.yz() - st.xy()*st.zz(),
393  st.xy()*st.yz() - st.xz()*st.yy(),
394 
395  st.xx()*st.zz() - st.xz()*st.xz(),
396  st.xy()*st.xz() - st.xx()*st.yz(),
397 
398  st.xx()*st.yy() - st.xy()*st.xy()
399  )/detst;
400 }
401 
402 
403 //- Return the inverse of a symmetric tensor
404 template<class Cmpt>
406 {
407  return inv(st, det(st));
408 }
409 
410 
411 //- Return the 1st invariant of a symmetric tensor
412 template<class Cmpt>
413 inline Cmpt invariantI(const SymmTensor<Cmpt>& st)
414 {
415  return tr(st);
416 }
417 
418 
419 //- Return the 2nd invariant of a symmetric tensor
420 template<class Cmpt>
421 inline Cmpt invariantII(const SymmTensor<Cmpt>& st)
422 {
423  return
424  (
425  st.xx()*st.yy() + st.yy()*st.zz() + st.xx()*st.zz()
426  - sqr(st.xy()) - sqr(st.yz()) - sqr(st.xz())
427  );
428 }
429 
430 
431 //- Return the 3rd invariant of a symmetric tensor
432 template<class Cmpt>
433 inline Cmpt invariantIII(const SymmTensor<Cmpt>& st)
434 {
435  return det(st);
436 }
437 
438 
439 template<class Cmpt>
440 inline SymmTensor<Cmpt>
442 {
443  return SymmTensor<Cmpt>
444  (
445  spt1.ii() + st2.xx(), st2.xy(), st2.xz(),
446  spt1.ii() + st2.yy(), st2.yz(),
447  spt1.ii() + st2.zz()
448  );
449 }
450 
451 
452 template<class Cmpt>
453 inline SymmTensor<Cmpt>
455 {
456  return SymmTensor<Cmpt>
457  (
458  st1.xx() + spt2.ii(), st1.xy(), st1.xz(),
459  st1.yy() + spt2.ii(), st1.yz(),
460  st1.zz() + spt2.ii()
461  );
462 }
463 
464 
465 template<class Cmpt>
466 inline SymmTensor<Cmpt>
468 {
469  return SymmTensor<Cmpt>
470  (
471  spt1.ii() - st2.xx(), -st2.xy(), -st2.xz(),
472  spt1.ii() - st2.yy(), -st2.yz(),
473  spt1.ii() - st2.zz()
474  );
475 }
476 
477 
478 template<class Cmpt>
479 inline SymmTensor<Cmpt>
481 {
482  return SymmTensor<Cmpt>
483  (
484  st1.xx() - spt2.ii(), st1.xy(), st1.xz(),
485  st1.yy() - spt2.ii(), st1.yz(),
486  st1.zz() - spt2.ii()
487  );
488 }
489 
490 
491 //- Inner-product between a spherical symmetric tensor and a symmetric tensor
492 template<class Cmpt>
493 inline SymmTensor<Cmpt>
495 {
496  return SymmTensor<Cmpt>
497  (
498  spt1.ii()*st2.xx(), spt1.ii()*st2.xy(), spt1.ii()*st2.xz(),
499  spt1.ii()*st2.yy(), spt1.ii()*st2.yz(),
500  spt1.ii()*st2.zz()
501  );
502 }
503 
504 
505 //- Inner-product between a tensor and a spherical tensor
506 template<class Cmpt>
507 inline SymmTensor<Cmpt>
509 {
510  return SymmTensor<Cmpt>
511  (
512  st1.xx()*spt2.ii(), st1.xy()*spt2.ii(), st1.xz()*spt2.ii(),
513  st1.yy()*spt2.ii(), st1.yz()*spt2.ii(),
514  st1.zz()*spt2.ii()
515  );
516 }
517 
518 
519 //- Double-dot-product between a spherical tensor and a symmetric tensor
520 template<class Cmpt>
521 inline Cmpt
523 {
524  return(spt1.ii()*st2.xx() + spt1.ii()*st2.yy() + spt1.ii()*st2.zz());
525 }
526 
527 
528 //- Double-dot-product between a tensor and a spherical tensor
529 template<class Cmpt>
530 inline Cmpt
532 {
533  return(st1.xx()*spt2.ii() + st1.yy()*spt2.ii() + st1.zz()*spt2.ii());
534 }
535 
536 
537 template<class Cmpt>
539 {
540  return SymmTensor<Cmpt>
541  (
542  v.x()*v.x(), v.x()*v.y(), v.x()*v.z(),
543  v.y()*v.y(), v.y()*v.z(),
544  v.z()*v.z()
545  );
546 }
547 
548 
549 template<class Cmpt>
550 class outerProduct<SymmTensor<Cmpt>, Cmpt>
551 {
552 public:
553 
555 };
556 
557 template<class Cmpt>
558 class outerProduct<Cmpt, SymmTensor<Cmpt>>
559 {
560 public:
561 
563 };
564 
565 template<class Cmpt>
566 class innerProduct<SymmTensor<Cmpt>, SymmTensor<Cmpt>>
567 {
568 public:
569 
571 };
572 
573 template<class Cmpt>
574 class innerProduct<SymmTensor<Cmpt>, Vector<Cmpt>>
575 {
576 public:
577 
579 };
580 
581 template<class Cmpt>
582 class innerProduct<Vector<Cmpt>, SymmTensor<Cmpt>>
583 {
584 public:
585 
587 };
588 
589 
590 template<class Cmpt>
592 {
593 public:
594 
596 };
597 
598 template<class Cmpt>
600 {
601 public:
602 
604 };
605 
606 template<class Cmpt>
608 {
609 public:
610 
612 };
613 
614 template<class Cmpt>
616 {
617 public:
618 
620 };
621 
622 
623 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
624 
625 } // End namespace Foam
626 
627 // ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
Templated 3D SphericalTensor derived from VectorSpace adding construction from 1 component,...
const Cmpt & ii() const
Templated 3D symmetric tensor derived from VectorSpace adding construction from 6 components,...
Definition: SymmTensor.H:56
const Cmpt & xx() const
Definition: SymmTensorI.H:87
const Cmpt & yx() const
Definition: SymmTensorI.H:105
const Cmpt & yz() const
Definition: SymmTensorI.H:117
const Cmpt & xz() const
Definition: SymmTensorI.H:99
const Cmpt & zz() const
Definition: SymmTensorI.H:135
const Cmpt & xy() const
Definition: SymmTensorI.H:93
const Cmpt & zx() const
Definition: SymmTensorI.H:123
const Cmpt & zy() const
Definition: SymmTensorI.H:129
const Cmpt & yy() const
Definition: SymmTensorI.H:111
SymmTensor()
Construct null.
Definition: SymmTensorI.H:32
void operator=(const SphericalTensor< Cmpt > &)
Assign to given SphericalTensor.
Definition: SymmTensorI.H:188
const SymmTensor< Cmpt > & T() const
Transpose.
Definition: SymmTensorI.H:179
Templated 3D tensor derived from MatrixSpace adding construction from 9 components,...
Definition: Tensor.H:67
Templated vector space.
Definition: VectorSpace.H:85
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition: Vector.H:60
const Cmpt & z() const
Definition: VectorI.H:87
const Cmpt & y() const
Definition: VectorI.H:81
const Cmpt & x() const
Definition: VectorI.H:75
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:50
Namespace for OpenFOAM.
static const zero Zero
Definition: zero.H:97
Cmpt invariantI(const SymmTensor< Cmpt > &st)
Return the 1st invariant of a symmetric tensor.
Definition: SymmTensorI.H:413
void dev2(LagrangianPatchField< tensor > &f, const LagrangianPatchField< tensor > &f1)
void dev(LagrangianPatchField< tensor > &f, const LagrangianPatchField< tensor > &f1)
void twoSymm(LagrangianPatchField< tensor > &f, const LagrangianPatchField< tensor > &f1)
SphericalTensor< Cmpt > sph(const DiagTensor< Cmpt > &dt)
Return the spherical part of a diagonal tensor.
Definition: DiagTensorI.H:353
void det(LagrangianPatchField< scalar > &f, const LagrangianPatchField< tensor > &f1)
Cmpt invariantIII(const SymmTensor< Cmpt > &st)
Return the 3rd invariant of a symmetric tensor.
Definition: SymmTensorI.H:433
dimensionedSymmTensor cof(const dimensionedSymmTensor &dt)
void symm(LagrangianPatchField< tensor > &f, const LagrangianPatchField< tensor > &f1)
Cmpt invariantII(const SymmTensor< Cmpt > &st)
Return the 2nd invariant of a symmetric tensor.
Definition: SymmTensorI.H:421
void sqr(LagrangianPatchField< typename outerProduct< Type, Type >::type > &f, const LagrangianPatchField< Type > &f1)
tmp< VolField< Type > > operator&(const fvMatrix< Type > &, const DimensionedField< Type, volMesh > &)
void tr(LagrangianPatchField< scalar > &f, const LagrangianPatchField< tensor > &f1)
tmp< fvMatrix< Type > > operator*(const volScalarField::Internal &, const fvMatrix< Type > &)
tmp< fvMatrix< Type > > operator+(const fvMatrix< Type > &, const fvMatrix< Type > &)
void inv(LagrangianPatchField< tensor > &f, const LagrangianPatchField< tensor > &f1)
void magSqr(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
dimensionedSymmTensor innerSqr(const dimensionedSymmTensor &dt)
tmp< fvMatrix< Type > > operator-(const fvMatrix< Type > &)
dimensioned< typename scalarProduct< Type1, Type2 >::type > operator&&(const dimensioned< Type1 > &, const dimensioned< Type2 > &)