SymmTensorI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 
36 template<class Cmpt>
38 {}
39 
40 
41 template<class Cmpt>
42 template<class Cmpt2>
44 (
45  const VectorSpace<SymmTensor<Cmpt2>, Cmpt2, 6>& vs
46 )
47 :
48  VectorSpace<SymmTensor<Cmpt>, Cmpt, 6>(vs)
49 {}
50 
51 
52 template<class Cmpt>
54 {
55  this->v_[XX] = st.ii(); this->v_[XY] = 0; this->v_[XZ] = 0;
56  this->v_[YY] = st.ii(); this->v_[YZ] = 0;
57  this->v_[ZZ] = st.ii();
58 }
59 
60 
61 template<class Cmpt>
63 (
64  const Cmpt txx, const Cmpt txy, const Cmpt txz,
65  const Cmpt tyy, const Cmpt tyz,
66  const Cmpt tzz
67 )
68 {
69  this->v_[XX] = txx; this->v_[XY] = txy; this->v_[XZ] = txz;
70  this->v_[YY] = tyy; this->v_[YZ] = tyz;
71  this->v_[ZZ] = tzz;
72 }
73 
74 
75 template<class Cmpt>
77 :
78  VectorSpace<SymmTensor<Cmpt>, Cmpt, 6>(is)
79 {}
80 
81 
82 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
83 
84 template<class Cmpt>
85 inline const Cmpt& SymmTensor<Cmpt>::xx() const
86 {
87  return this->v_[XX];
88 }
89 
90 template<class Cmpt>
91 inline const Cmpt& SymmTensor<Cmpt>::xy() const
92 {
93  return this->v_[XY];
94 }
95 
96 template<class Cmpt>
97 inline const Cmpt& SymmTensor<Cmpt>::xz() const
98 {
99  return this->v_[XZ];
100 }
101 
102 template<class Cmpt>
103 inline const Cmpt& SymmTensor<Cmpt>::yy() const
104 {
105  return this->v_[YY];
106 }
107 
108 template<class Cmpt>
109 inline const Cmpt& SymmTensor<Cmpt>::yz() const
110 {
111  return this->v_[YZ];
112 }
113 
114 template<class Cmpt>
115 inline const Cmpt& SymmTensor<Cmpt>::zz() const
116 {
117  return this->v_[ZZ];
118 }
119 
120 
121 template<class Cmpt>
122 inline Cmpt& SymmTensor<Cmpt>::xx()
123 {
124  return this->v_[XX];
125 }
126 
127 template<class Cmpt>
128 inline Cmpt& SymmTensor<Cmpt>::xy()
129 {
130  return this->v_[XY];
131 }
132 
133 template<class Cmpt>
134 inline Cmpt& SymmTensor<Cmpt>::xz()
135 {
136  return this->v_[XZ];
137 }
138 
139 template<class Cmpt>
140 inline Cmpt& SymmTensor<Cmpt>::yy()
141 {
142  return this->v_[YY];
143 }
144 
145 template<class Cmpt>
146 inline Cmpt& SymmTensor<Cmpt>::yz()
147 {
148  return this->v_[YZ];
149 }
150 
151 template<class Cmpt>
152 inline Cmpt& SymmTensor<Cmpt>::zz()
153 {
154  return this->v_[ZZ];
155 }
156 
157 
158 template<class Cmpt>
160 {
161  return *this;
162 }
163 
164 
165 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
166 
167 template<class Cmpt>
169 {
170  this->v_[XX] = st.ii(); this->v_[XY] = 0; this->v_[XZ] = 0;
171  this->v_[YY] = st.ii(); this->v_[YZ] = 0;
172  this->v_[ZZ] = st.ii();
173 }
174 
175 
176 
177 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
178 
179 //- Hodge Dual operator (tensor -> vector)
180 template<class Cmpt>
182 {
183  return Vector<Cmpt>(st.yz(), -st.xz(), st.xy());
184 }
185 
186 
187 //- Inner-product between two symmetric tensors
188 template<class Cmpt>
189 inline Tensor<Cmpt>
191 {
192  return Tensor<Cmpt>
193  (
194  st1.xx()*st2.xx() + st1.xy()*st2.xy() + st1.xz()*st2.xz(),
195  st1.xx()*st2.xy() + st1.xy()*st2.yy() + st1.xz()*st2.yz(),
196  st1.xx()*st2.xz() + st1.xy()*st2.yz() + st1.xz()*st2.zz(),
197 
198  st1.xy()*st2.xx() + st1.yy()*st2.xy() + st1.yz()*st2.xz(),
199  st1.xy()*st2.xy() + st1.yy()*st2.yy() + st1.yz()*st2.yz(),
200  st1.xy()*st2.xz() + st1.yy()*st2.yz() + st1.yz()*st2.zz(),
201 
202  st1.xz()*st2.xx() + st1.yz()*st2.xy() + st1.zz()*st2.xz(),
203  st1.xz()*st2.xy() + st1.yz()*st2.yy() + st1.zz()*st2.yz(),
204  st1.xz()*st2.xz() + st1.yz()*st2.yz() + st1.zz()*st2.zz()
205  );
206 }
207 
208 
209 //- Double-dot-product between a symmetric tensor and a symmetric tensor
210 template<class Cmpt>
211 inline Cmpt
213 {
214  return
215  (
216  st1.xx()*st2.xx() + 2*st1.xy()*st2.xy() + 2*st1.xz()*st2.xz()
217  + st1.yy()*st2.yy() + 2*st1.yz()*st2.yz()
218  + st1.zz()*st2.zz()
219  );
220 }
221 
222 
223 //- Inner-product between a symmetric tensor and a vector
224 template<class Cmpt>
225 inline Vector<Cmpt>
227 {
228  return Vector<Cmpt>
229  (
230  st.xx()*v.x() + st.xy()*v.y() + st.xz()*v.z(),
231  st.xy()*v.x() + st.yy()*v.y() + st.yz()*v.z(),
232  st.xz()*v.x() + st.yz()*v.y() + st.zz()*v.z()
233  );
234 }
235 
236 
237 //- Inner-product between a vector and a symmetric tensor
238 template<class Cmpt>
239 inline Vector<Cmpt>
241 {
242  return Vector<Cmpt>
243  (
244  v.x()*st.xx() + v.y()*st.xy() + v.z()*st.xz(),
245  v.x()*st.xy() + v.y()*st.yy() + v.z()*st.yz(),
246  v.x()*st.xz() + v.y()*st.yz() + v.z()*st.zz()
247  );
248 }
249 
250 
251 //- Inner-sqr of a symmetric tensor
252 template<class Cmpt>
253 inline SymmTensor<Cmpt>
255 {
256  return SymmTensor<Cmpt>
257  (
258  st.xx()*st.xx() + st.xy()*st.xy() + st.xz()*st.xz(),
259  st.xx()*st.xy() + st.xy()*st.yy() + st.xz()*st.yz(),
260  st.xx()*st.xz() + st.xy()*st.yz() + st.xz()*st.zz(),
261 
262  st.xy()*st.xy() + st.yy()*st.yy() + st.yz()*st.yz(),
263  st.xy()*st.xz() + st.yy()*st.yz() + st.yz()*st.zz(),
264 
265  st.xz()*st.xz() + st.yz()*st.yz() + st.zz()*st.zz()
266  );
267 }
268 
269 
270 template<class Cmpt>
271 inline Cmpt magSqr(const SymmTensor<Cmpt>& st)
272 {
273  return
274  (
275  magSqr(st.xx()) + 2*magSqr(st.xy()) + 2*magSqr(st.xz())
276  + magSqr(st.yy()) + 2*magSqr(st.yz())
277  + magSqr(st.zz())
278  );
279 }
280 
281 
282 //- Return the trace of a symmetric tensor
283 template<class Cmpt>
284 inline Cmpt tr(const SymmTensor<Cmpt>& st)
285 {
286  return st.xx() + st.yy() + st.zz();
287 }
288 
289 
290 //- Return the spherical part of a symmetric tensor
291 template<class Cmpt>
293 {
294  return (1.0/3.0)*tr(st);
295 }
296 
297 
298 //- Return the symmetric part of a symmetric tensor, i.e. itself
299 template<class Cmpt>
300 inline const SymmTensor<Cmpt>& symm(const SymmTensor<Cmpt>& st)
301 {
302  return st;
303 }
304 
305 
306 //- Return twice the symmetric part of a symmetric tensor
307 template<class Cmpt>
309 {
310  return 2*st;
311 }
312 
313 
314 //- Return the deviatoric part of a symmetric tensor
315 template<class Cmpt>
317 {
318  return st - SphericalTensor<Cmpt>::oneThirdI*tr(st);
319 }
320 
321 
322 //- Return the deviatoric part of a symmetric tensor
323 template<class Cmpt>
325 {
326  return st - SphericalTensor<Cmpt>::twoThirdsI*tr(st);
327 }
328 
329 
330 //- Return the determinant of a symmetric tensor
331 template<class Cmpt>
332 inline Cmpt det(const SymmTensor<Cmpt>& st)
333 {
334  return
335  (
336  st.xx()*st.yy()*st.zz() + st.xy()*st.yz()*st.xz()
337  + st.xz()*st.xy()*st.yz() - st.xx()*st.yz()*st.yz()
338  - st.xy()*st.xy()*st.zz() - st.xz()*st.yy()*st.xz()
339  );
340 }
341 
342 
343 //- Return the cofactor symmetric tensor of a symmetric tensor
344 template<class Cmpt>
346 {
347  return SymmTensor<Cmpt>
348  (
349  st.yy()*st.zz() - st.yz()*st.yz(),
350  st.xz()*st.yz() - st.xy()*st.zz(),
351  st.xy()*st.yz() - st.xz()*st.yy(),
352 
353  st.xx()*st.zz() - st.xz()*st.xz(),
354  st.xy()*st.xz() - st.xx()*st.yz(),
355 
356  st.xx()*st.yy() - st.xy()*st.xy()
357  );
358 }
359 
360 
361 //- Return the inverse of a symmetric tensor give the determinant
362 template<class Cmpt>
363 inline SymmTensor<Cmpt> inv(const SymmTensor<Cmpt>& st, const Cmpt detst)
364 {
365  return SymmTensor<Cmpt>
366  (
367  st.yy()*st.zz() - st.yz()*st.yz(),
368  st.xz()*st.yz() - st.xy()*st.zz(),
369  st.xy()*st.yz() - st.xz()*st.yy(),
370 
371  st.xx()*st.zz() - st.xz()*st.xz(),
372  st.xy()*st.xz() - st.xx()*st.yz(),
373 
374  st.xx()*st.yy() - st.xy()*st.xy()
375  )/detst;
376 }
377 
378 
379 //- Return the inverse of a symmetric tensor
380 template<class Cmpt>
382 {
383  return inv(st, det(st));
384 }
385 
386 
387 //- Return the 1st invariant of a symmetric tensor
388 template<class Cmpt>
389 inline Cmpt invariantI(const SymmTensor<Cmpt>& st)
390 {
391  return tr(st);
392 }
393 
394 
395 //- Return the 2nd invariant of a symmetric tensor
396 template<class Cmpt>
397 inline Cmpt invariantII(const SymmTensor<Cmpt>& st)
398 {
399  return
400  (
401  0.5*sqr(tr(st))
402  - 0.5*
403  (
404  st.xx()*st.xx() + st.xy()*st.xy() + st.xz()*st.xz()
405  + st.xy()*st.xy() + st.yy()*st.yy() + st.yz()*st.yz()
406  + st.xz()*st.xz() + st.yz()*st.yz() + st.zz()*st.zz()
407  )
408  );
409 }
410 
411 
412 //- Return the 3rd invariant of a symmetric tensor
413 template<class Cmpt>
414 inline Cmpt invariantIII(const SymmTensor<Cmpt>& st)
415 {
416  return det(st);
417 }
418 
419 
420 template<class Cmpt>
421 inline SymmTensor<Cmpt>
423 {
424  return SymmTensor<Cmpt>
425  (
426  spt1.ii() + st2.xx(), st2.xy(), st2.xz(),
427  spt1.ii() + st2.yy(), st2.yz(),
428  spt1.ii() + st2.zz()
429  );
430 }
431 
432 
433 template<class Cmpt>
434 inline SymmTensor<Cmpt>
436 {
437  return SymmTensor<Cmpt>
438  (
439  st1.xx() + spt2.ii(), st1.xy(), st1.xz(),
440  st1.yy() + spt2.ii(), st1.yz(),
441  st1.zz() + spt2.ii()
442  );
443 }
444 
445 
446 template<class Cmpt>
447 inline SymmTensor<Cmpt>
449 {
450  return SymmTensor<Cmpt>
451  (
452  spt1.ii() - st2.xx(), -st2.xy(), -st2.xz(),
453  spt1.ii() - st2.yy(), -st2.yz(),
454  spt1.ii() - st2.zz()
455  );
456 }
457 
458 
459 template<class Cmpt>
460 inline SymmTensor<Cmpt>
462 {
463  return SymmTensor<Cmpt>
464  (
465  st1.xx() - spt2.ii(), st1.xy(), st1.xz(),
466  st1.yy() - spt2.ii(), st1.yz(),
467  st1.zz() - spt2.ii()
468  );
469 }
470 
471 
472 //- Inner-product between a spherical symmetric tensor and a symmetric tensor
473 template<class Cmpt>
474 inline SymmTensor<Cmpt>
476 {
477  return SymmTensor<Cmpt>
478  (
479  spt1.ii()*st2.xx(), spt1.ii()*st2.xy(), spt1.ii()*st2.xz(),
480  spt1.ii()*st2.yy(), spt1.ii()*st2.yz(),
481  spt1.ii()*st2.zz()
482  );
483 }
484 
485 
486 //- Inner-product between a tensor and a spherical tensor
487 template<class Cmpt>
488 inline SymmTensor<Cmpt>
490 {
491  return SymmTensor<Cmpt>
492  (
493  st1.xx()*spt2.ii(), st1.xy()*spt2.ii(), st1.xz()*spt2.ii(),
494  st1.yy()*spt2.ii(), st1.yz()*spt2.ii(),
495  st1.zz()*spt2.ii()
496  );
497 }
498 
499 
500 //- Double-dot-product between a spherical tensor and a symmetric tensor
501 template<class Cmpt>
502 inline Cmpt
504 {
505  return(spt1.ii()*st2.xx() + spt1.ii()*st2.yy() + spt1.ii()*st2.zz());
506 }
507 
508 
509 //- Double-dot-product between a tensor and a spherical tensor
510 template<class Cmpt>
511 inline Cmpt
513 {
514  return(st1.xx()*spt2.ii() + st1.yy()*spt2.ii() + st1.zz()*spt2.ii());
515 }
516 
517 
518 template<class Cmpt>
520 {
521  return SymmTensor<Cmpt>
522  (
523  v.x()*v.x(), v.x()*v.y(), v.x()*v.z(),
524  v.y()*v.y(), v.y()*v.z(),
525  v.z()*v.z()
526  );
527 }
528 
529 
530 template<class Cmpt>
531 class outerProduct<SymmTensor<Cmpt>, Cmpt>
532 {
533 public:
534 
536 };
537 
538 template<class Cmpt>
539 class outerProduct<Cmpt, SymmTensor<Cmpt> >
540 {
541 public:
542 
544 };
545 
546 template<class Cmpt>
547 class innerProduct<SymmTensor<Cmpt>, SymmTensor<Cmpt> >
548 {
549 public:
550 
552 };
553 
554 template<class Cmpt>
555 class innerProduct<SymmTensor<Cmpt>, Vector<Cmpt> >
556 {
557 public:
558 
560 };
561 
562 template<class Cmpt>
563 class innerProduct<Vector<Cmpt>, SymmTensor<Cmpt> >
564 {
565 public:
566 
568 };
569 
570 
571 template<class Cmpt>
573 {
574 public:
575 
577 };
578 
579 template<class Cmpt>
581 {
582 public:
583 
585 };
586 
587 template<class Cmpt>
589 {
590 public:
591 
593 };
594 
595 template<class Cmpt>
597 {
598 public:
599 
601 };
602 
603 
604 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
605 
606 } // End namespace Foam
607 
608 // ************************************************************************* //
tmp< fvMatrix< Type > > operator*(const DimensionedField< scalar, volMesh > &, const fvMatrix< Type > &)
Templated 3D tensor derived from VectorSpace 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:224
const SymmTensor< Cmpt > & T() const
Transpose.
Definition: SymmTensorI.H:159
tmp< GeometricField< Type, fvPatchField, volMesh > > operator&(const fvMatrix< Type > &, const DimensionedField< Type, volMesh > &)
Templated 3D symmetric tensor derived from VectorSpace adding construction from 6 components...
Definition: SymmTensor.H:53
dimensioned< scalar > magSqr(const dimensioned< Type > &)
tmp< fvMatrix< Type > > operator+(const fvMatrix< Type > &, const fvMatrix< Type > &)
dimensionedSymmTensor cof(const dimensionedSymmTensor &dt)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
dimensionedSymmTensor dev2(const dimensionedSymmTensor &dt)
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.
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
Cmpt invariantI(const SymmTensor< Cmpt > &st)
Return the 1st invariant of a symmetric tensor.
Definition: SymmTensorI.H:389
const Cmpt & xy() const
Definition: SymmTensorI.H:91
dimensionedSymmTensor innerSqr(const dimensionedSymmTensor &dt)
Namespace for OpenFOAM.
dimensionedSymmTensor dev(const dimensionedSymmTensor &dt)
const Cmpt & xx() const
Definition: SymmTensorI.H:85
Cmpt invariantII(const SymmTensor< Cmpt > &st)
Return the 2nd invariant of a symmetric tensor.
Definition: SymmTensorI.H:397
const Cmpt & ii() const
tmp< fvMatrix< Type > > operator-(const fvMatrix< Type > &)
const Cmpt & xz() const
Definition: SymmTensorI.H:97
const Cmpt & y() const
Definition: VectorI.H:71
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
Cmpt invariantIII(const SymmTensor< Cmpt > &st)
Return the 3rd invariant of a symmetric tensor.
Definition: SymmTensorI.H:414
Cmpt v_[nCmpt]
The components of this vector space.
Definition: VectorSpace.H:95
SymmTensor()
Construct null.
Definition: SymmTensorI.H:37
dimensionedScalar det(const dimensionedSphericalTensor &dt)
const Cmpt & x() const
Definition: VectorI.H:65
const Cmpt & yy() const
Definition: SymmTensorI.H:103
const Cmpt & yz() const
Definition: SymmTensorI.H:109
const Cmpt & z() const
Definition: VectorI.H:77
const Cmpt & zz() const
Definition: SymmTensorI.H:115
dimensionedSymmTensor twoSymm(const dimensionedSymmTensor &dt)
SphericalTensor< Cmpt > sph(const DiagTensor< Cmpt > &dt)
Return the spherical part of a diagonal tensor.
Definition: DiagTensorI.H:281
Templated vector space.
Definition: VectorSpace.H:52
dimensioned< typename scalarProduct< Type1, Type2 >::type > operator&&(const dimensioned< Type1 > &, const dimensioned< Type2 > &)
dimensionedSymmTensor symm(const dimensionedSymmTensor &dt)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
void operator=(const SphericalTensor< Cmpt > &)
Construct given SphericalTensor.
Definition: SymmTensorI.H:168