All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2018 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 :
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>::yy() const
106 {
107  return this->v_[YY];
108 }
109 
110 template<class Cmpt>
111 inline const Cmpt& Foam::SymmTensor<Cmpt>::yz() const
112 {
113  return this->v_[YZ];
114 }
115 
116 template<class Cmpt>
117 inline const Cmpt& Foam::SymmTensor<Cmpt>::zz() const
118 {
119  return this->v_[ZZ];
120 }
121 
122 
123 template<class Cmpt>
125 {
126  return this->v_[XX];
127 }
128 
129 template<class Cmpt>
131 {
132  return this->v_[XY];
133 }
134 
135 template<class Cmpt>
137 {
138  return this->v_[XZ];
139 }
140 
141 template<class Cmpt>
143 {
144  return this->v_[YY];
145 }
146 
147 template<class Cmpt>
149 {
150  return this->v_[YZ];
151 }
152 
153 template<class Cmpt>
155 {
156  return this->v_[ZZ];
157 }
158 
159 
160 template<class Cmpt>
162 {
163  return *this;
164 }
165 
166 
167 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
168 
169 template<class Cmpt>
171 {
172  this->v_[XX] = st.ii(); this->v_[XY] = 0; this->v_[XZ] = 0;
173  this->v_[YY] = st.ii(); this->v_[YZ] = 0;
174  this->v_[ZZ] = st.ii();
175 }
176 
177 
178 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179 
180 namespace Foam
181 {
182 
183 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
184 
185 //- Hodge Dual operator (tensor -> vector)
186 template<class Cmpt>
188 {
189  return Vector<Cmpt>(st.yz(), -st.xz(), st.xy());
190 }
191 
192 
193 //- Inner-product between two symmetric tensors
194 template<class Cmpt>
195 inline Tensor<Cmpt>
197 {
198  return Tensor<Cmpt>
199  (
200  st1.xx()*st2.xx() + st1.xy()*st2.xy() + st1.xz()*st2.xz(),
201  st1.xx()*st2.xy() + st1.xy()*st2.yy() + st1.xz()*st2.yz(),
202  st1.xx()*st2.xz() + st1.xy()*st2.yz() + st1.xz()*st2.zz(),
203 
204  st1.xy()*st2.xx() + st1.yy()*st2.xy() + st1.yz()*st2.xz(),
205  st1.xy()*st2.xy() + st1.yy()*st2.yy() + st1.yz()*st2.yz(),
206  st1.xy()*st2.xz() + st1.yy()*st2.yz() + st1.yz()*st2.zz(),
207 
208  st1.xz()*st2.xx() + st1.yz()*st2.xy() + st1.zz()*st2.xz(),
209  st1.xz()*st2.xy() + st1.yz()*st2.yy() + st1.zz()*st2.yz(),
210  st1.xz()*st2.xz() + st1.yz()*st2.yz() + st1.zz()*st2.zz()
211  );
212 }
213 
214 
215 //- Double-dot-product between a symmetric tensor and a symmetric tensor
216 template<class Cmpt>
217 inline Cmpt
219 {
220  return
221  (
222  st1.xx()*st2.xx() + 2*st1.xy()*st2.xy() + 2*st1.xz()*st2.xz()
223  + st1.yy()*st2.yy() + 2*st1.yz()*st2.yz()
224  + st1.zz()*st2.zz()
225  );
226 }
227 
228 
229 //- Inner-product between a symmetric tensor and a vector
230 template<class Cmpt>
231 inline Vector<Cmpt>
233 {
234  return Vector<Cmpt>
235  (
236  st.xx()*v.x() + st.xy()*v.y() + st.xz()*v.z(),
237  st.xy()*v.x() + st.yy()*v.y() + st.yz()*v.z(),
238  st.xz()*v.x() + st.yz()*v.y() + st.zz()*v.z()
239  );
240 }
241 
242 
243 //- Inner-product between a vector and a symmetric tensor
244 template<class Cmpt>
245 inline Vector<Cmpt>
247 {
248  return Vector<Cmpt>
249  (
250  v.x()*st.xx() + v.y()*st.xy() + v.z()*st.xz(),
251  v.x()*st.xy() + v.y()*st.yy() + v.z()*st.yz(),
252  v.x()*st.xz() + v.y()*st.yz() + v.z()*st.zz()
253  );
254 }
255 
256 
257 //- Inner-sqr of a symmetric tensor
258 template<class Cmpt>
259 inline SymmTensor<Cmpt>
261 {
262  return SymmTensor<Cmpt>
263  (
264  st.xx()*st.xx() + st.xy()*st.xy() + st.xz()*st.xz(),
265  st.xx()*st.xy() + st.xy()*st.yy() + st.xz()*st.yz(),
266  st.xx()*st.xz() + st.xy()*st.yz() + st.xz()*st.zz(),
267 
268  st.xy()*st.xy() + st.yy()*st.yy() + st.yz()*st.yz(),
269  st.xy()*st.xz() + st.yy()*st.yz() + st.yz()*st.zz(),
270 
271  st.xz()*st.xz() + st.yz()*st.yz() + st.zz()*st.zz()
272  );
273 }
274 
275 
276 template<class Cmpt>
277 inline Cmpt magSqr(const SymmTensor<Cmpt>& st)
278 {
279  return
280  (
281  magSqr(st.xx()) + 2*magSqr(st.xy()) + 2*magSqr(st.xz())
282  + magSqr(st.yy()) + 2*magSqr(st.yz())
283  + magSqr(st.zz())
284  );
285 }
286 
287 
288 //- Return the trace of a symmetric tensor
289 template<class Cmpt>
290 inline Cmpt tr(const SymmTensor<Cmpt>& st)
291 {
292  return st.xx() + st.yy() + st.zz();
293 }
294 
295 
296 //- Return the spherical part of a symmetric tensor
297 template<class Cmpt>
299 {
300  return (1.0/3.0)*tr(st);
301 }
302 
303 
304 //- Return the symmetric part of a symmetric tensor, i.e. itself
305 template<class Cmpt>
306 inline const SymmTensor<Cmpt>& symm(const SymmTensor<Cmpt>& st)
307 {
308  return st;
309 }
310 
311 
312 //- Return twice the symmetric part of a symmetric tensor
313 template<class Cmpt>
315 {
316  return 2*st;
317 }
318 
319 
320 //- Return the deviatoric part of a symmetric tensor
321 template<class Cmpt>
323 {
324  return st - SphericalTensor<Cmpt>::oneThirdI*tr(st);
325 }
326 
327 
328 //- Return the deviatoric part of a symmetric tensor
329 template<class Cmpt>
331 {
332  return st - SphericalTensor<Cmpt>::twoThirdsI*tr(st);
333 }
334 
335 
336 //- Return the determinant of a symmetric tensor
337 template<class Cmpt>
338 inline Cmpt det(const SymmTensor<Cmpt>& st)
339 {
340  return
341  (
342  st.xx()*st.yy()*st.zz() + st.xy()*st.yz()*st.xz()
343  + st.xz()*st.xy()*st.yz() - st.xx()*st.yz()*st.yz()
344  - st.xy()*st.xy()*st.zz() - st.xz()*st.yy()*st.xz()
345  );
346 }
347 
348 
349 //- Return the cofactor symmetric tensor of a symmetric tensor
350 template<class Cmpt>
352 {
353  return SymmTensor<Cmpt>
354  (
355  st.yy()*st.zz() - st.yz()*st.yz(),
356  st.xz()*st.yz() - st.xy()*st.zz(),
357  st.xy()*st.yz() - st.xz()*st.yy(),
358 
359  st.xx()*st.zz() - st.xz()*st.xz(),
360  st.xy()*st.xz() - st.xx()*st.yz(),
361 
362  st.xx()*st.yy() - st.xy()*st.xy()
363  );
364 }
365 
366 
367 //- Return the inverse of a symmetric tensor give the determinant
368 template<class Cmpt>
369 inline SymmTensor<Cmpt> inv(const SymmTensor<Cmpt>& st, const Cmpt detst)
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  )/detst;
382 }
383 
384 
385 //- Return the inverse of a symmetric tensor
386 template<class Cmpt>
388 {
389  return inv(st, det(st));
390 }
391 
392 
393 //- Return the 1st invariant of a symmetric tensor
394 template<class Cmpt>
395 inline Cmpt invariantI(const SymmTensor<Cmpt>& st)
396 {
397  return tr(st);
398 }
399 
400 
401 //- Return the 2nd invariant of a symmetric tensor
402 template<class Cmpt>
403 inline Cmpt invariantII(const SymmTensor<Cmpt>& st)
404 {
405  return
406  (
407  st.xx()*st.yy() + st.yy()*st.zz() + st.xx()*st.zz()
408  - sqr(st.xy()) - sqr(st.yz()) - sqr(st.xz())
409  );
410 }
411 
412 
413 //- Return the 3rd invariant of a symmetric tensor
414 template<class Cmpt>
415 inline Cmpt invariantIII(const SymmTensor<Cmpt>& st)
416 {
417  return det(st);
418 }
419 
420 
421 template<class Cmpt>
422 inline SymmTensor<Cmpt>
424 {
425  return SymmTensor<Cmpt>
426  (
427  spt1.ii() + st2.xx(), st2.xy(), st2.xz(),
428  spt1.ii() + st2.yy(), st2.yz(),
429  spt1.ii() + st2.zz()
430  );
431 }
432 
433 
434 template<class Cmpt>
435 inline SymmTensor<Cmpt>
437 {
438  return SymmTensor<Cmpt>
439  (
440  st1.xx() + spt2.ii(), st1.xy(), st1.xz(),
441  st1.yy() + spt2.ii(), st1.yz(),
442  st1.zz() + spt2.ii()
443  );
444 }
445 
446 
447 template<class Cmpt>
448 inline SymmTensor<Cmpt>
450 {
451  return SymmTensor<Cmpt>
452  (
453  spt1.ii() - st2.xx(), -st2.xy(), -st2.xz(),
454  spt1.ii() - st2.yy(), -st2.yz(),
455  spt1.ii() - st2.zz()
456  );
457 }
458 
459 
460 template<class Cmpt>
461 inline SymmTensor<Cmpt>
463 {
464  return SymmTensor<Cmpt>
465  (
466  st1.xx() - spt2.ii(), st1.xy(), st1.xz(),
467  st1.yy() - spt2.ii(), st1.yz(),
468  st1.zz() - spt2.ii()
469  );
470 }
471 
472 
473 //- Inner-product between a spherical symmetric tensor and a symmetric tensor
474 template<class Cmpt>
475 inline SymmTensor<Cmpt>
477 {
478  return SymmTensor<Cmpt>
479  (
480  spt1.ii()*st2.xx(), spt1.ii()*st2.xy(), spt1.ii()*st2.xz(),
481  spt1.ii()*st2.yy(), spt1.ii()*st2.yz(),
482  spt1.ii()*st2.zz()
483  );
484 }
485 
486 
487 //- Inner-product between a tensor and a spherical tensor
488 template<class Cmpt>
489 inline SymmTensor<Cmpt>
491 {
492  return SymmTensor<Cmpt>
493  (
494  st1.xx()*spt2.ii(), st1.xy()*spt2.ii(), st1.xz()*spt2.ii(),
495  st1.yy()*spt2.ii(), st1.yz()*spt2.ii(),
496  st1.zz()*spt2.ii()
497  );
498 }
499 
500 
501 //- Double-dot-product between a spherical tensor and a symmetric tensor
502 template<class Cmpt>
503 inline Cmpt
505 {
506  return(spt1.ii()*st2.xx() + spt1.ii()*st2.yy() + spt1.ii()*st2.zz());
507 }
508 
509 
510 //- Double-dot-product between a tensor and a spherical tensor
511 template<class Cmpt>
512 inline Cmpt
514 {
515  return(st1.xx()*spt2.ii() + st1.yy()*spt2.ii() + st1.zz()*spt2.ii());
516 }
517 
518 
519 template<class Cmpt>
521 {
522  return SymmTensor<Cmpt>
523  (
524  v.x()*v.x(), v.x()*v.y(), v.x()*v.z(),
525  v.y()*v.y(), v.y()*v.z(),
526  v.z()*v.z()
527  );
528 }
529 
530 
531 template<class Cmpt>
532 class outerProduct<SymmTensor<Cmpt>, Cmpt>
533 {
534 public:
535 
537 };
538 
539 template<class Cmpt>
540 class outerProduct<Cmpt, SymmTensor<Cmpt>>
541 {
542 public:
543 
545 };
546 
547 template<class Cmpt>
548 class innerProduct<SymmTensor<Cmpt>, SymmTensor<Cmpt>>
549 {
550 public:
551 
553 };
554 
555 template<class Cmpt>
556 class innerProduct<SymmTensor<Cmpt>, Vector<Cmpt>>
557 {
558 public:
559 
561 };
562 
563 template<class Cmpt>
564 class innerProduct<Vector<Cmpt>, SymmTensor<Cmpt>>
565 {
566 public:
567 
569 };
570 
571 
572 template<class Cmpt>
574 {
575 public:
576 
578 };
579 
580 template<class Cmpt>
582 {
583 public:
584 
586 };
587 
588 template<class Cmpt>
590 {
591 public:
592 
594 };
595 
596 template<class Cmpt>
598 {
599 public:
600 
602 };
603 
604 
605 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
606 
607 } // End namespace Foam
608 
609 // ************************************************************************* //
const Cmpt & yz() const
Definition: SymmTensorI.H:111
Cmpt invariantII(const SymmTensor< Cmpt > &st)
Return the 2nd invariant of a symmetric tensor.
Definition: SymmTensorI.H:403
Cmpt det(const SymmTensor< Cmpt > &st)
Return the determinant of a symmetric tensor.
Definition: SymmTensorI.H:338
Templated 3D symmetric tensor derived from VectorSpace adding construction from 6 components...
Definition: SymmTensor.H:53
Vector< Cmpt > operator*(const SymmTensor< Cmpt > &st)
Hodge Dual operator (tensor -> vector)
Definition: SymmTensorI.H:187
const Cmpt & xx() const
Definition: SymmTensorI.H:87
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
SymmTensor()
Construct null.
Definition: SymmTensorI.H:32
Templated vector space.
Definition: VectorSpace.H:53
SymmTensor< Cmpt > innerSqr(const SymmTensor< Cmpt > &st)
Inner-sqr of a symmetric tensor.
Definition: SymmTensorI.H:260
const Cmpt & z() const
Definition: VectorI.H:87
void operator=(const SphericalTensor< Cmpt > &)
Assign to given SphericalTensor.
Definition: SymmTensorI.H:170
const Cmpt & yy() const
Definition: SymmTensorI.H:105
const SymmTensor< Cmpt > & symm(const SymmTensor< Cmpt > &st)
Return the symmetric part of a symmetric tensor, i.e. itself.
Definition: SymmTensorI.H:306
Cmpt tr(const SymmTensor< Cmpt > &st)
Return the trace of a symmetric tensor.
Definition: SymmTensorI.H:290
const Cmpt & y() const
Definition: VectorI.H:81
SymmTensor< Cmpt > cof(const SymmTensor< Cmpt > &st)
Return the cofactor symmetric tensor of a symmetric tensor.
Definition: SymmTensorI.H:351
Templated 3D SphericalTensor derived from VectorSpace adding construction from 1 component, element access using th ii() member function and the inner-product (dot-product) and outer-product operators.
SymmTensor< Cmpt > twoSymm(const SymmTensor< Cmpt > &st)
Return twice the symmetric part of a symmetric tensor.
Definition: SymmTensorI.H:314
Cmpt magSqr(const SymmTensor< Cmpt > &st)
Definition: SymmTensorI.H:277
const Cmpt & xz() const
Definition: SymmTensorI.H:99
const Cmpt & zz() const
Definition: SymmTensorI.H:117
Cmpt invariantIII(const SymmTensor< Cmpt > &st)
Return the 3rd invariant of a symmetric tensor.
Definition: SymmTensorI.H:415
const Cmpt & ii() const
static const zero Zero
Definition: zero.H:97
SymmTensor< Cmpt > sqr(const Vector< Cmpt > &v)
Definition: SymmTensorI.H:520
const Cmpt & x() const
Definition: VectorI.H:75
SymmTensor< Cmpt > dev2(const SymmTensor< Cmpt > &st)
Return the deviatoric part of a symmetric tensor.
Definition: SymmTensorI.H:330
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:57
SymmTensor< Cmpt > inv(const SymmTensor< Cmpt > &st)
Return the inverse of a symmetric tensor.
Definition: SymmTensorI.H:387
Cmpt operator &&(const SymmTensor< Cmpt > &st1, const SphericalTensor< Cmpt > &spt2)
Double-dot-product between a tensor and a spherical tensor.
Definition: SymmTensorI.H:513
const SymmTensor< Cmpt > & T() const
Transpose.
Definition: SymmTensorI.H:161
SymmTensor< Cmpt > operator+(const SymmTensor< Cmpt > &st1, const SphericalTensor< Cmpt > &spt2)
Definition: SymmTensorI.H:436
SymmTensor< Cmpt > dev(const SymmTensor< Cmpt > &st)
Return the deviatoric part of a symmetric tensor.
Definition: SymmTensorI.H:322
Cmpt invariantI(const SymmTensor< Cmpt > &st)
Return the 1st invariant of a symmetric tensor.
Definition: SymmTensorI.H:395
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:49
SphericalTensor< Cmpt > sph(const SymmTensor< Cmpt > &st)
Return the spherical part of a symmetric tensor.
Definition: SymmTensorI.H:298
const Cmpt & xy() const
Definition: SymmTensorI.H:93
Templated 3D tensor derived from MatrixSpace adding construction from 9 components, element access using xx(), xy() etc. member functions and the inner-product (dot-product) and outer-product of two Vectors (tensor-product) operators.
Definition: complexI.H:215
SymmTensor< Cmpt > operator &(const SymmTensor< Cmpt > &st1, const SphericalTensor< Cmpt > &spt2)
Inner-product between a tensor and a spherical tensor.
Definition: SymmTensorI.H:490
SymmTensor< Cmpt > operator-(const SymmTensor< Cmpt > &st1, const SphericalTensor< Cmpt > &spt2)
Definition: SymmTensorI.H:462
Namespace for OpenFOAM.