Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
33template<class Cmpt>
35:
37{}
38
39
40template<class Cmpt>
42(
43 const VectorSpace<SymmTensor2D<Cmpt>, Cmpt, 3>& vs
45:
47{}
48
49
50template<class Cmpt>
53 this->v_[XX] = st.ii(); this->v_[XY] = Zero;
54 this->v_[YY] = st.ii();
55}
56
57
58template<class Cmpt>
60(
61 const Cmpt txx, const Cmpt txy,
62 const Cmpt tyy
63)
65 this->v_[XX] = txx; this->v_[XY] = txy;
66 this->v_[YY] = tyy;
67}
68
69
70template<class Cmpt>
72:
74{}
75
76
77// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
78
79template<class Cmpt>
81{
82 return Vector2D<Cmpt>(this->v_[XX], this->v_[YY]);
83}
84
85
86template<class Cmpt>
88{
89 this->v_[XX] = v.x(); this->v_[YY] = v.y();
90}
91
92
93template<class Cmpt>
94inline Foam::scalar Foam::SymmTensor2D<Cmpt>::diagSqr() const
95{
96 return
97 (
99 + Foam::magSqr(this->yy())
100 );
101}
102
103
104template<class Cmpt>
106{
107 return (xx()*yy() - xy()*xy());
108}
109
110
111template<class Cmpt>
113{
114 // symmetric: cof() == adjunct()
115 return SymmTensor2D<Cmpt>
116 (
117 yy(), -xy(),
118 xx()
119 );
120}
121
122
123template<class Cmpt>
125{
126 // symmetric: cof() == adjunct()
127 return this->adjunct();
128}
129
130
131// Invert without much error handling
132template<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
153template<class Cmpt>
155(
157)
158{
159 this->v_[XX] = st.ii(); this->v_[XY] = Zero;
160 this->v_[YY] = st.ii();
161}
162
163
164// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165
166namespace Foam
167{
169// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
170
171//- Return the trace of a SymmTensor2D
172template<class Cmpt>
173inline Cmpt tr(const SymmTensor2D<Cmpt>& st)
174{
175 return st.xx() + st.yy();
176}
177
179//- Return the spherical part of a SymmTensor2D
180template<class Cmpt>
182{
184 (
185 0.5*tr(st)
186 );
187}
188
189
190//- Return the symmetric part of a SymmTensor2D, i.e. itself
191template<class Cmpt>
192inline 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
199template<class Cmpt>
200inline SymmTensor2D<Cmpt> twoSymm(const SymmTensor2D<Cmpt>& st)
202 return 2*st;
203}
204
205
206//- Return the deviatoric part of a SymmTensor2D
207template<class Cmpt>
208inline SymmTensor2D<Cmpt> dev(const SymmTensor2D<Cmpt>& st)
209{
210 return st - sph(st);
212
213
214//- Return the two-third deviatoric part of a SymmTensor2D
215template<class Cmpt>
216inline SymmTensor2D<Cmpt> dev2(const SymmTensor2D<Cmpt>& st)
217{
218 return st - 2*sph(st);
219}
220
222//- Return the determinant of a SymmTensor2D
223template<class Cmpt>
224inline Cmpt det(const SymmTensor2D<Cmpt>& st)
225{
226 return st.det();
227}
228
229
230//- Return the cofactor SymmTensor2D of a SymmTensor2D
231template<class Cmpt>
233{
234 return st.cof();
235}
236
237
238//- Return the inverse of a SymmTensor2D, using given determinant value
239template<class Cmpt>
240inline SymmTensor2D<Cmpt> inv(const SymmTensor2D<Cmpt>& st, const Cmpt detval)
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
257template<class Cmpt>
258inline SymmTensor2D<Cmpt> inv(const SymmTensor2D<Cmpt>& st)
259{
260 return st.inv();
261}
262
263
264//- Return the 1st invariant of a SymmTensor2D
265template<class Cmpt>
266inline Cmpt invariantI(const SymmTensor2D<Cmpt>& st)
267{
268 return tr(st);
269}
270
272//- Return the 2nd invariant of a SymmTensor2D
273template<class Cmpt>
274inline Cmpt invariantII(const SymmTensor2D<Cmpt>& st)
275{
276 return det(st);
277}
278
279
280//- Return the inner-product of a SymmTensor2D with itself
281template<class Cmpt>
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 );
292
293
294//- Return the square of Frobenius norm of a SymmTensor2D
295template<class Cmpt>
296inline 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
307template<class Cmpt>
308inline 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
321template<class 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
334template<class 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
347template<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
360template<class Cmpt>
361inline SymmTensor2D<Cmpt>
362operator-(const SymmTensor2D<Cmpt>& st1, const SphericalTensor2D<Cmpt>& spt2)
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
373template<class Cmpt>
374inline SymmTensor2D<Cmpt>
375operator/(const SymmTensor2D<Cmpt>& st, const Cmpt s)
376{
377 return SymmTensor2D<Cmpt>
379 st.xx()/s, st.xy()/s,
380 st.yy()/s
381 );
382}
383
384
385//- Inner-product of a SymmTensor2D and a SymmTensor2D
386template<class Cmpt>
387inline Tensor2D<Cmpt>
388operator&(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
402template<class Cmpt>
403inline SymmTensor2D<Cmpt>
404operator&(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
415template<class Cmpt>
416inline SymmTensor2D<Cmpt>
417operator&(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
428template<class Cmpt>
429inline Vector2D<Cmpt>
430operator&(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
441template<class Cmpt>
442inline Vector2D<Cmpt>
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
454template<class Cmpt>
455inline 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
467template<class Cmpt>
468inline Cmpt
469operator&&(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
476template<class Cmpt>
477inline Cmpt
478operator&&(const SymmTensor2D<Cmpt>& st1, const SphericalTensor2D<Cmpt>& spt2)
479{
480 return (st1.xx()*spt2.ii() + st1.yy()*spt2.ii());
481}
482
483
484// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
485
486template<class Cmpt>
487class outerProduct<SymmTensor2D<Cmpt>, Cmpt>
488{
489public:
490
491 typedef SymmTensor2D<Cmpt> type;
492};
493
494template<class Cmpt>
495class outerProduct<Cmpt, SymmTensor2D<Cmpt>>
496{
497public:
498
499 typedef SymmTensor2D<Cmpt> type;
500};
502template<class Cmpt>
503class innerProduct<SymmTensor2D<Cmpt>, SymmTensor2D<Cmpt>>
504{
505public:
506
507 typedef Tensor2D<Cmpt> type;
508};
509
510template<class Cmpt>
511class innerProduct<SymmTensor2D<Cmpt>, Vector2D<Cmpt>>
512{
513public:
514
515 typedef Vector2D<Cmpt> type;
517
518template<class Cmpt>
519class innerProduct<Vector2D<Cmpt>, SymmTensor2D<Cmpt>>
520{
521public:
522
523 typedef Vector2D<Cmpt> type;
524};
525
526
527template<class Cmpt>
528class typeOfSum<SphericalTensor2D<Cmpt>, SymmTensor2D<Cmpt>>
529{
530public:
531
532 typedef SymmTensor2D<Cmpt> type;
533};
534
535template<class Cmpt>
537{
538public:
539
541};
542
543template<class Cmpt>
545{
546public:
547
549};
550
551template<class Cmpt>
553{
554public:
555
557};
558
559
560// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
561
562} // End namespace Foam
563
564// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
A templated (2 x 2) diagonal tensor of objects of <T>, effectively containing 1 element,...
const Cmpt & ii() const noexcept
A templated (2 x 2) symmetric tensor of objects of <T>, effectively containing 3 elements,...
SymmTensor2D< Cmpt > cof() const
Return cofactor matrix (transpose of adjunct matrix).
scalar diagSqr() const
The L2-norm squared of the diagonal.
const Cmpt & yy() const noexcept
SymmTensor2D< Cmpt > adjunct() const
Return adjunct matrix (transpose of cofactor matrix).
Cmpt det() const
The determinate.
SymmTensor2D< Cmpt > inv() const
Return inverse.
const Cmpt & xx() const noexcept
Vector2D< Cmpt > diag() const
Extract the diagonal as a vector.
const Cmpt & xy() const noexcept
SymmTensor2D()=default
Default construct.
A templated (2 x 2) tensor of objects of <T> derived from VectorSpace.
Definition Tensor2D.H:55
Templated 2D Vector derived from VectorSpace adding construction from 2 components,...
Definition Vector2D.H:54
const Cmpt & x() const noexcept
Access to the vector x component.
Definition Vector2D.H:127
const Cmpt & y() const noexcept
Access to the vector y component.
Definition Vector2D.H:132
Templated vector space.
Definition VectorSpace.H:75
static const SymmTensor2D< Cmpt > zero
VectorSpace< SymmTensor2D< Cmpt >, Cmpt, Ncmpts > vsType
Definition VectorSpace.H:86
friend Ostream & operator(Ostream &, const VectorSpace< SymmTensor2D< Cmpt >, Cmpt, Ncmpts > &)
typeOfRank< typenamepTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) -2 >::type type
Definition products.H:155
typeOfRank< typenamepTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank)>::type type
Definition products.H:118
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
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))
Namespace for OpenFOAM.
tmp< faMatrix< Type > > operator-(const faMatrix< Type > &)
Unary negation.
dimensionedSymmTensor dev2(const dimensionedSymmTensor &dt)
dimensionedSymmTensor dev(const dimensionedSymmTensor &dt)
dimensionedScalar det(const dimensionedSphericalTensor &dt)
dimensionedSymmTensor symm(const dimensionedSymmTensor &dt)
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
tmp< faMatrix< Type > > operator+(const faMatrix< Type > &, const faMatrix< Type > &)
dimensionedSymmTensor twoSymm(const dimensionedSymmTensor &dt)
Cmpt invariantII(const SymmTensor2D< Cmpt > &st)
Return the 2nd invariant of a SymmTensor2D.
Cmpt invariantI(const SymmTensor2D< Cmpt > &st)
Return the 1st invariant of a SymmTensor2D.
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
dimensionedSymmTensor cof(const dimensionedSymmTensor &dt)
tmp< GeometricField< Type, faPatchField, areaMesh > > operator&(const faMatrix< Type > &, const DimensionedField< Type, areaMesh > &)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
errorManip< error > abort(error &err)
Definition errorManip.H:139
SphericalTensor< Cmpt > sph(const DiagTensor< Cmpt > &dt)
Return the spherical part of a DiagTensor as a SphericalTensor.
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
dimensionedSymmTensor innerSqr(const dimensionedSymmTensor &dt)
dimensioned< typename scalarProduct< Type1, Type2 >::type > operator&&(const dimensioned< Type1 > &, const dimensioned< Type2 > &)
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50