SymmTensor2DI.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) 2019-2023 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 
29 #include "Tensor2D.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class Cmpt>
35 :
37 {}
38 
39 
40 template<class Cmpt>
42 (
43  const VectorSpace<SymmTensor2D<Cmpt>, Cmpt, 3>& vs
44 )
45 :
46  SymmTensor2D::vsType(vs)
47 {}
48 
49 
50 template<class Cmpt>
52 {
53  this->v_[XX] = st.ii(); this->v_[XY] = Zero;
54  this->v_[YY] = st.ii();
55 }
56 
57 
58 template<class Cmpt>
60 (
61  const Cmpt txx, const Cmpt txy,
62  const Cmpt tyy
63 )
64 {
65  this->v_[XX] = txx; this->v_[XY] = txy;
66  this->v_[YY] = tyy;
67 }
68 
69 
70 template<class Cmpt>
72 :
74 {}
75 
76 
77 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
78 
79 template<class Cmpt>
81 {
82  return Vector2D<Cmpt>(this->v_[XX], this->v_[YY]);
83 }
84 
85 
86 template<class Cmpt>
88 {
89  this->v_[XX] = v.x(); this->v_[YY] = v.y();
90 }
91 
92 
93 template<class Cmpt>
94 inline Foam::scalar Foam::SymmTensor2D<Cmpt>::diagSqr() const
95 {
96  return
97  (
98  Foam::magSqr(this->xx())
99  + Foam::magSqr(this->yy())
100  );
101 }
102 
103 
104 template<class Cmpt>
105 inline Cmpt Foam::SymmTensor2D<Cmpt>::det() const
106 {
107  return (xx()*yy() - xy()*xy());
108 }
109 
110 
111 template<class Cmpt>
113 {
114  // symmetric: cof() == adjunct()
115  return SymmTensor2D<Cmpt>
116  (
117  yy(), -xy(),
118  xx()
119  );
120 }
121 
122 
123 template<class Cmpt>
125 {
126  // symmetric: cof() == adjunct()
127  return this->adjunct();
128 }
129 
130 
131 // Invert without much error handling
132 template<class Cmpt>
134 {
135  const Cmpt detval = this->det();
136 
137  #ifdef FULLDEBUG
138  if (mag(detval) < SMALL)
139  {
141  << "SymmTensor2D not properly invertible, determinant:"
142  << detval << " tensor:" << *this << nl
143  << abort(FatalError);
144  }
145  #endif
146 
147  return this->adjunct()/detval;
148 }
149 
150 
151 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
152 
153 template<class Cmpt>
155 (
156  const SphericalTensor2D<Cmpt>& st
157 )
158 {
159  this->v_[XX] = st.ii(); this->v_[XY] = Zero;
160  this->v_[YY] = st.ii();
161 }
162 
163 
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165 
166 namespace Foam
167 {
169 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
170 
171 //- Return the trace of a SymmTensor2D
172 template<class Cmpt>
173 inline Cmpt tr(const SymmTensor2D<Cmpt>& st)
174 {
175  return st.xx() + st.yy();
176 }
177 
179 //- Return the spherical part of a SymmTensor2D
180 template<class Cmpt>
182 {
184  (
185  0.5*tr(st)
186  );
187 }
188 
189 
190 //- Return the symmetric part of a SymmTensor2D, i.e. itself
191 template<class Cmpt>
192 inline const SymmTensor2D<Cmpt>& symm(const SymmTensor2D<Cmpt>& st)
193 {
194  return st;
195 }
196 
197 
198 //- Return twice the symmetric part of a SymmTensor2D, i.e. twice itself
199 template<class Cmpt>
200 inline SymmTensor2D<Cmpt> twoSymm(const SymmTensor2D<Cmpt>& st)
201 {
202  return 2*st;
203 }
204 
205 
206 //- Return the deviatoric part of a SymmTensor2D
207 template<class Cmpt>
208 inline SymmTensor2D<Cmpt> dev(const SymmTensor2D<Cmpt>& st)
209 {
210  return st - sph(st);
211 }
212 
213 
214 //- Return the two-third deviatoric part of a SymmTensor2D
215 template<class Cmpt>
216 inline SymmTensor2D<Cmpt> dev2(const SymmTensor2D<Cmpt>& st)
217 {
218  return st - 2*sph(st);
219 }
220 
222 //- Return the determinant of a SymmTensor2D
223 template<class Cmpt>
224 inline Cmpt det(const SymmTensor2D<Cmpt>& st)
225 {
226  return st.det();
227 }
228 
229 
230 //- Return the cofactor SymmTensor2D of a SymmTensor2D
231 template<class Cmpt>
232 inline SymmTensor2D<Cmpt> cof(const SymmTensor2D<Cmpt>& st)
233 {
234  return st.cof();
235 }
236 
237 
238 //- Return the inverse of a SymmTensor2D, using given determinant value
239 template<class Cmpt>
240 inline SymmTensor2D<Cmpt> inv(const SymmTensor2D<Cmpt>& st, const Cmpt detval)
241 {
242  #ifdef FULLDEBUG
243  if (mag(detval) < SMALL)
244  {
246  << "SymmTensor2D not properly invertible, determinant:"
247  << detval << " tensor:" << st << nl
248  << abort(FatalError);
249  }
250  #endif
252  return st.adjunct()/detval;
253 }
254 
255 
256 //- Return the inverse of a SymmTensor2D
257 template<class Cmpt>
258 inline SymmTensor2D<Cmpt> inv(const SymmTensor2D<Cmpt>& st)
259 {
260  return st.inv();
261 }
262 
263 
264 //- Return the 1st invariant of a SymmTensor2D
265 template<class Cmpt>
266 inline Cmpt invariantI(const SymmTensor2D<Cmpt>& st)
267 {
268  return tr(st);
269 }
270 
272 //- Return the 2nd invariant of a SymmTensor2D
273 template<class Cmpt>
274 inline Cmpt invariantII(const SymmTensor2D<Cmpt>& st)
275 {
276  return det(st);
277 }
278 
279 
280 //- Return the inner-product of a SymmTensor2D with itself
281 template<class Cmpt>
282 inline SymmTensor2D<Cmpt>
283 innerSqr(const SymmTensor2D<Cmpt>& st)
284 {
285  return SymmTensor2D<Cmpt>
286  (
287  st.xx()*st.xx() + st.xy()*st.xy(),
288  st.xx()*st.xy() + st.xy()*st.yy(),
289  st.xy()*st.xy() + st.yy()*st.yy()
290  );
291 }
292 
293 
294 //- Return the square of Frobenius norm of a SymmTensor2D
295 template<class Cmpt>
296 inline Foam::scalar magSqr(const SymmTensor2D<Cmpt>& st)
297 {
298  return
299  (
300  magSqr(st.xx()) + 2*magSqr(st.xy())
301  + magSqr(st.yy())
302  );
303 }
304 
305 
306 //- Outer-product of a Vector2D with itself
307 template<class Cmpt>
308 inline SymmTensor2D<Cmpt> sqr(const Vector2D<Cmpt>& v)
309 {
310  return SymmTensor2D<Cmpt>
311  (
312  v.x()*v.x(), v.x()*v.y(),
313  v.y()*v.y()
314  );
315 }
316 
318 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
319 
320 //- Sum of a SphericalTensor2D and a SymmTensor2D
321 template<class Cmpt>
322 inline SymmTensor2D<Cmpt>
324 {
325  return SymmTensor2D<Cmpt>
326  (
327  spt1.ii() + st2.xx(), st2.xy(),
328  spt1.ii() + st2.yy()
329  );
330 }
332 
333 //- Sum of a SymmTensor2D and a SphericalTensor2D
334 template<class Cmpt>
335 inline SymmTensor2D<Cmpt>
337 {
338  return SymmTensor2D<Cmpt>
339  (
340  st1.xx() + spt2.ii(), st1.xy(),
341  st1.yy() + spt2.ii()
342  );
343 }
344 
345 
346 //- Subtract a SymmTensor2D from a SphericalTensor2D
347 template<class Cmpt>
350 {
351  return SymmTensor2D<Cmpt>
352  (
353  spt1.ii() - st2.xx(), -st2.xy(),
354  spt1.ii() - st2.yy()
355  );
356 }
357 
358 
359 //- Subtract a SphericalTensor2D from a SymmTensor2D
360 template<class Cmpt>
361 inline SymmTensor2D<Cmpt>
362 operator-(const SymmTensor2D<Cmpt>& st1, const SphericalTensor2D<Cmpt>& spt2)
363 {
364  return SymmTensor2D<Cmpt>
365  (
366  st1.xx() - spt2.ii(), st1.xy(),
367  st1.yy() - spt2.ii()
368  );
369 }
370 
371 
372 //- Division of a SymmTensor2D by a Cmpt
373 template<class Cmpt>
374 inline SymmTensor2D<Cmpt>
375 operator/(const SymmTensor2D<Cmpt>& st, const Cmpt s)
376 {
377  return SymmTensor2D<Cmpt>
378  (
379  st.xx()/s, st.xy()/s,
380  st.yy()/s
381  );
382 }
383 
384 
385 //- Inner-product of a SymmTensor2D and a SymmTensor2D
386 template<class Cmpt>
387 inline Tensor2D<Cmpt>
388 operator&(const SymmTensor2D<Cmpt>& st1, const SymmTensor2D<Cmpt>& st2)
389 {
390  return Tensor2D<Cmpt>
391  (
392  st1.xx()*st2.xx() + st1.xy()*st2.xy(),
393  st1.xx()*st2.xy() + st1.xy()*st2.yy(),
394 
395  st1.xy()*st2.xx() + st1.yy()*st2.xy(),
396  st1.xy()*st2.xy() + st1.yy()*st2.yy()
397  );
398 }
399 
400 
401 //- Inner-product of a SphericalTensor2D and a SymmTensor2D
402 template<class Cmpt>
403 inline SymmTensor2D<Cmpt>
404 operator&(const SphericalTensor2D<Cmpt>& spt1, const SymmTensor2D<Cmpt>& st2)
405 {
406  return SymmTensor2D<Cmpt>
407  (
408  spt1.ii()*st2.xx(), spt1.ii()*st2.xy(),
409  spt1.ii()*st2.yy()
410  );
411 }
412 
413 
414 //- Inner-product of a SymmTensor2D and a SphericalTensor2D
415 template<class Cmpt>
416 inline SymmTensor2D<Cmpt>
417 operator&(const SymmTensor2D<Cmpt>& st1, const SphericalTensor2D<Cmpt>& spt2)
418 {
419  return SymmTensor2D<Cmpt>
420  (
421  st1.xx()*spt2.ii(), st1.xy()*spt2.ii(),
422  st1.yy()*spt2.ii()
423  );
424 }
425 
426 
427 //- Inner-product of a SymmTensor2D and a Vector2D
428 template<class Cmpt>
429 inline Vector2D<Cmpt>
430 operator&(const SymmTensor2D<Cmpt>& st, const Vector2D<Cmpt>& v)
431 {
432  return Vector2D<Cmpt>
433  (
434  st.xx()*v.x() + st.xy()*v.y(),
435  st.xy()*v.x() + st.yy()*v.y()
436  );
437 }
438 
439 
440 //- Inner-product of a Vector2D and a SymmTensor2D
441 template<class Cmpt>
442 inline Vector2D<Cmpt>
443 operator&(const Vector2D<Cmpt>& v, const SymmTensor2D<Cmpt>& st)
444 {
445  return Vector2D<Cmpt>
446  (
447  v.x()*st.xx() + v.y()*st.xy(),
448  v.x()*st.xy() + v.y()*st.yy()
449  );
450 }
451 
452 
453 //- Double-inner-product of a SymmTensor2D and a SymmTensor2D
454 template<class Cmpt>
455 inline Cmpt
457 {
458  return
459  (
460  st1.xx()*st2.xx() + 2*st1.xy()*st2.xy()
461  + st1.yy()*st2.yy()
462  );
463 }
464 
465 
466 //- Double-inner-product of a SphericalTensor2D and a SymmTensor2D
467 template<class Cmpt>
468 inline Cmpt
469 operator&&(const SphericalTensor2D<Cmpt>& spt1, const SymmTensor2D<Cmpt>& st2)
470 {
471  return (spt1.ii()*st2.xx() + spt1.ii()*st2.yy());
472 }
473 
474 
475 //- Double-inner-product of a SymmTensor2D and a SphericalTensor2D
476 template<class Cmpt>
477 inline Cmpt
478 operator&&(const SymmTensor2D<Cmpt>& st1, const SphericalTensor2D<Cmpt>& spt2)
479 {
480  return (st1.xx()*spt2.ii() + st1.yy()*spt2.ii());
481 }
482 
483 
484 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
485 
486 template<class Cmpt>
487 class outerProduct<SymmTensor2D<Cmpt>, Cmpt>
488 {
489 public:
490 
491  typedef SymmTensor2D<Cmpt> type;
492 };
493 
494 template<class Cmpt>
495 class outerProduct<Cmpt, SymmTensor2D<Cmpt>>
496 {
497 public:
498 
499  typedef SymmTensor2D<Cmpt> type;
500 };
502 template<class Cmpt>
503 class innerProduct<SymmTensor2D<Cmpt>, SymmTensor2D<Cmpt>>
504 {
505 public:
506 
507  typedef Tensor2D<Cmpt> type;
508 };
509 
510 template<class Cmpt>
511 class innerProduct<SymmTensor2D<Cmpt>, Vector2D<Cmpt>>
512 {
513 public:
514 
515  typedef Vector2D<Cmpt> type;
516 };
517 
518 template<class Cmpt>
519 class innerProduct<Vector2D<Cmpt>, SymmTensor2D<Cmpt>>
520 {
521 public:
522 
523  typedef Vector2D<Cmpt> type;
524 };
525 
526 
527 template<class Cmpt>
528 class typeOfSum<SphericalTensor2D<Cmpt>, SymmTensor2D<Cmpt>>
529 {
530 public:
531 
532  typedef SymmTensor2D<Cmpt> type;
533 };
534 
535 template<class Cmpt>
537 {
538 public:
539 
541 };
542 
543 template<class Cmpt>
545 {
546 public:
547 
549 };
550 
551 template<class Cmpt>
553 {
554 public:
555 
557 };
558 
559 
560 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
561 
562 } // End namespace Foam
563 
564 // ************************************************************************* //
Cmpt invariantII(const SymmTensor< Cmpt > &st)
Return the 2nd invariant of a SymmTensor.
Definition: SymmTensorI.H:581
SymmTensor2D()=default
Default construct.
SymmTensor2D< Cmpt > inv() const
Return inverse.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
const Cmpt & xx() const noexcept
Definition: SymmTensor2D.H:141
const Cmpt & y() const noexcept
Access to the vector y component.
Definition: Vector2D.H:132
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
Vector2D< Cmpt > diag() const
Extract the diagonal as a vector.
Definition: SymmTensor2DI.H:73
const Cmpt & ii() const noexcept
dimensionedSymmTensor sqr(const dimensionedVector &dv)
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
const Cmpt & xy() const noexcept
Definition: SymmTensor2D.H:142
Templated vector space.
Definition: VectorSpace.H:52
dimensionSet operator &&(const dimensionSet &ds1, const dimensionSet &ds2)
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
SymmTensor2D< Cmpt > adjunct() const
Return adjunct matrix (transpose of cofactor matrix)
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:118
dimensionedScalar det(const dimensionedSphericalTensor &dt)
SphericalTensor< Cmpt > sph(const DiagTensor< Cmpt > &dt)
Return the spherical part of a DiagTensor as a SphericalTensor.
Definition: DiagTensorI.H:110
tmp< faMatrix< Type > > operator+(const faMatrix< Type > &, const faMatrix< Type > &)
Cmpt det() const
The determinate.
Definition: SymmTensor2DI.H:98
A templated (2 x 2) tensor of objects of <T> derived from VectorSpace.
Definition: Tensor2D.H:52
dimensionedSymmTensor twoSymm(const dimensionedSymmTensor &dt)
const Cmpt & yy() const noexcept
Definition: SymmTensor2D.H:144
dimensionedSymmTensor dev(const dimensionedSymmTensor &dt)
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
errorManip< error > abort(error &err)
Definition: errorManip.H:139
tmp< faMatrix< Type > > operator-(const faMatrix< Type > &)
Unary negation.
dimensionedSymmTensor innerSqr(const dimensionedSymmTensor &dt)
const Cmpt & x() const noexcept
Access to the vector x component.
Definition: Vector2D.H:127
dimensionedSymmTensor dev2(const dimensionedSymmTensor &dt)
SymmTensor2D< Cmpt > cof() const
Return cofactor matrix (transpose of adjunct matrix)
dimensionedSymmTensor symm(const dimensionedSymmTensor &dt)
A templated (2 x 2) diagonal tensor of objects of <T>, effectively containing 1 element, derived from VectorSpace.
tmp< GeometricField< Type, faPatchField, areaMesh > > operator &(const faMatrix< Type > &, const DimensionedField< Type, areaMesh > &)
Cmpt invariantI(const SymmTensor< Cmpt > &st)
Return the 1st invariant of a SymmTensor.
Definition: SymmTensorI.H:571
A templated (2 x 2) symmetric tensor of objects of <T>, effectively containing 3 elements, derived from VectorSpace.
Definition: SymmTensor2D.H:54
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
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))
Templated 2D Vector derived from VectorSpace adding construction from 2 components, element access using x() and y() member functions and the inner-product (dot-product).
Definition: Vector2D.H:51
scalar diagSqr() const
The L2-norm squared of the diagonal.
Definition: SymmTensor2DI.H:87
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) - 2 >::type type
Definition: products.H:155
dimensionedSymmTensor cof(const dimensionedSymmTensor &dt)
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127