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-2020 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:
36 SymmTensor2D::vsType(Zero)
37{}
38
39
40template<class Cmpt>
42(
43 const VectorSpace<SymmTensor2D<Cmpt>, Cmpt, 3>& vs
44)
45:
47{}
48
49
50template<class Cmpt>
52{
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)
64{
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>
80inline const Cmpt& Foam::SymmTensor2D<Cmpt>::xx() const
81{
82 return this->v_[XX];
83}
84
85template<class Cmpt>
86inline const Cmpt& Foam::SymmTensor2D<Cmpt>::xy() const
87{
88 return this->v_[XY];
89}
90
91template<class Cmpt>
92inline const Cmpt& Foam::SymmTensor2D<Cmpt>::yx() const
93{
94 return this->v_[XY];
95}
96
97template<class Cmpt>
98inline const Cmpt& Foam::SymmTensor2D<Cmpt>::yy() const
99{
100 return this->v_[YY];
101}
102
103
104template<class Cmpt>
106{
107 return this->v_[XX];
108}
109
110template<class Cmpt>
112{
113 return this->v_[XY];
114}
115
116template<class Cmpt>
118{
119 return this->v_[XY];
120}
121
122template<class Cmpt>
124{
125 return this->v_[YY];
126}
127
128
129template<class Cmpt>
131{
132 return Vector2D<Cmpt>(this->v_[XX], this->v_[YY]);
133}
134
135
136template<class Cmpt>
138{
139 this->v_[XX] = v.x(); this->v_[YY] = v.y();
140}
141
142
143template<class Cmpt>
145{
146 return *this;
147}
148
149
150// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
151
152template<class Cmpt>
154(
156)
157{
158 this->v_[XX] = st.ii(); this->v_[XY] = Zero;
159 this->v_[YY] = st.ii();
160}
161
162
163// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164
165namespace Foam
166{
167
168// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
169
170//- Return the trace of a SymmTensor2D
171template<class Cmpt>
172inline Cmpt tr(const SymmTensor2D<Cmpt>& st)
173{
174 return st.xx() + st.yy();
175}
176
177
178//- Return the spherical part of a SymmTensor2D
179template<class Cmpt>
181{
183 (
184 0.5*tr(st)
185 );
186}
187
188
189//- Return the symmetric part of a SymmTensor2D, i.e. itself
190template<class Cmpt>
192{
193 return st;
194}
195
196
197//- Return twice the symmetric part of a SymmTensor2D, i.e. twice itself
198template<class Cmpt>
200{
201 return 2*st;
202}
203
204
205//- Return the deviatoric part of a SymmTensor2D
206template<class Cmpt>
208{
209 return st - sph(st);
210}
211
212
213//- Return the two-third deviatoric part of a SymmTensor2D
214template<class Cmpt>
216{
217 return st - 2*sph(st);
218}
219
220
221//- Return the determinant of a SymmTensor2D
222template<class Cmpt>
223inline Cmpt det(const SymmTensor2D<Cmpt>& st)
224{
225 return (st.xx()*st.yy() - st.xy()*st.xy());
226}
227
228
229//- Return the cofactor SymmTensor2D of a SymmTensor2D
230template<class Cmpt>
232{
233 return SymmTensor2D<Cmpt>
234 (
235 st.yy(), -st.yx(),
236 st.xx()
237 );
238}
239
240
241//- Return the inverse of a SymmTensor2D using a given determinant
242template<class Cmpt>
243inline SymmTensor2D<Cmpt> inv(const SymmTensor2D<Cmpt>& st, const Cmpt detst)
244{
245 #ifdef FULLDEBUG
246 if (mag(detst) < SMALL)
247 {
249 << "SymmTensor2D is not invertible due to the zero determinant:"
250 << "det(SymmTensor2D) = " << mag(detst)
251 << abort(FatalError);
252 }
253 #endif
254 // cofactor and adjugate matrices of SymmTensor are the same, hence no .T()
255 return cof(st)/detst;
256}
257
258
259//- Return the inverse of a SymmTensor2D
260template<class Cmpt>
262{
263 return inv(st, det(st));
264}
265
266
267//- Return the 1st invariant of a SymmTensor2D
268template<class Cmpt>
269inline Cmpt invariantI(const SymmTensor2D<Cmpt>& st)
270{
271 return tr(st);
272}
273
274
275//- Return the 2nd invariant of a SymmTensor2D
276template<class Cmpt>
277inline Cmpt invariantII(const SymmTensor2D<Cmpt>& st)
278{
279 return det(st);
280}
281
282
283//- Return the inner-product of a SymmTensor2D with itself
284template<class Cmpt>
285inline SymmTensor2D<Cmpt>
287{
288 return SymmTensor2D<Cmpt>
289 (
290 st.xx()*st.xx() + st.xy()*st.xy(),
291 st.xx()*st.xy() + st.xy()*st.yy(),
292 st.xy()*st.xy() + st.yy()*st.yy()
293 );
294}
295
296
297//- Return the square of Frobenius norm of a SymmTensor2D as a Cmpt
298template<class Cmpt>
299inline Cmpt magSqr(const SymmTensor2D<Cmpt>& st)
300{
301 return Cmpt
302 (
303 mag(st.xx()*st.xx()) + 2*mag(st.xy()*st.xy())
304 + mag(st.yy()*st.yy())
305 );
306}
307
308
309//- Outer-product of a Vector2D with itself
310template<class Cmpt>
312{
313 return SymmTensor2D<Cmpt>
314 (
315 v.x()*v.x(), v.x()*v.y(),
316 v.y()*v.y()
317 );
318}
319
320
321// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
322
323//- Sum of a SphericalTensor2D and a SymmTensor2D
324template<class Cmpt>
325inline SymmTensor2D<Cmpt>
327{
328 return SymmTensor2D<Cmpt>
329 (
330 spt1.ii() + st2.xx(), st2.xy(),
331 spt1.ii() + st2.yy()
332 );
333}
334
335
336//- Sum of a SymmTensor2D and a SphericalTensor2D
337template<class Cmpt>
338inline SymmTensor2D<Cmpt>
340{
341 return SymmTensor2D<Cmpt>
342 (
343 st1.xx() + spt2.ii(), st1.xy(),
344 st1.yy() + spt2.ii()
345 );
346}
347
348
349//- Subtract a SymmTensor2D from a SphericalTensor2D
350template<class Cmpt>
351inline SymmTensor2D<Cmpt>
353{
354 return SymmTensor2D<Cmpt>
355 (
356 spt1.ii() - st2.xx(), -st2.xy(),
357 spt1.ii() - st2.yy()
358 );
359}
360
361
362//- Subtract a SphericalTensor2D from a SymmTensor2D
363template<class Cmpt>
364inline SymmTensor2D<Cmpt>
366{
367 return SymmTensor2D<Cmpt>
368 (
369 st1.xx() - spt2.ii(), st1.xy(),
370 st1.yy() - spt2.ii()
371 );
372}
373
374
375//- Division of a SymmTensor2D by a Cmpt
376template<class Cmpt>
377inline SymmTensor2D<Cmpt>
378operator/(const SymmTensor2D<Cmpt>& st, const Cmpt s)
379{
380 return SymmTensor2D<Cmpt>
381 (
382 st.xx()/s, st.xy()/s,
383 st.yy()/s
384 );
385}
386
387
388//- Inner-product of a SymmTensor2D and a SymmTensor2D
389template<class Cmpt>
390inline Tensor2D<Cmpt>
392{
393 return Tensor2D<Cmpt>
394 (
395 st1.xx()*st2.xx() + st1.xy()*st2.xy(),
396 st1.xx()*st2.xy() + st1.xy()*st2.yy(),
397
398 st1.xy()*st2.xx() + st1.yy()*st2.xy(),
399 st1.xy()*st2.xy() + st1.yy()*st2.yy()
400 );
401}
402
403
404//- Inner-product of a SphericalTensor2D and a SymmTensor2D
405template<class Cmpt>
406inline SymmTensor2D<Cmpt>
408{
409 return SymmTensor2D<Cmpt>
410 (
411 spt1.ii()*st2.xx(), spt1.ii()*st2.xy(),
412 spt1.ii()*st2.yy()
413 );
414}
415
416
417//- Inner-product of a SymmTensor2D and a SphericalTensor2D
418template<class Cmpt>
419inline SymmTensor2D<Cmpt>
421{
422 return SymmTensor2D<Cmpt>
423 (
424 st1.xx()*spt2.ii(), st1.xy()*spt2.ii(),
425 st1.yy()*spt2.ii()
426 );
427}
428
429
430//- Inner-product of a SymmTensor2D and a Vector2D
431template<class Cmpt>
432inline Vector2D<Cmpt>
434{
435 return Vector2D<Cmpt>
436 (
437 st.xx()*v.x() + st.xy()*v.y(),
438 st.xy()*v.x() + st.yy()*v.y()
439 );
440}
441
442
443//- Inner-product of a Vector2D and a SymmTensor2D
444template<class Cmpt>
445inline Vector2D<Cmpt>
447{
448 return Vector2D<Cmpt>
449 (
450 v.x()*st.xx() + v.y()*st.xy(),
451 v.x()*st.xy() + v.y()*st.yy()
452 );
453}
454
455
456//- Double-inner-product of a SymmTensor2D and a SymmTensor2D
457template<class Cmpt>
458inline Cmpt
460{
461 return
462 (
463 st1.xx()*st2.xx() + 2*st1.xy()*st2.xy()
464 + st1.yy()*st2.yy()
465 );
466}
467
468
469//- Double-inner-product of a SphericalTensor2D and a SymmTensor2D
470template<class Cmpt>
471inline Cmpt
473{
474 return (spt1.ii()*st2.xx() + spt1.ii()*st2.yy());
475}
476
477
478//- Double-inner-product of a SymmTensor2D and a SphericalTensor2D
479template<class Cmpt>
480inline Cmpt
482{
483 return (st1.xx()*spt2.ii() + st1.yy()*spt2.ii());
484}
485
486
487// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
488
489template<class Cmpt>
490class outerProduct<SymmTensor2D<Cmpt>, Cmpt>
491{
492public:
493
495};
496
497template<class Cmpt>
498class outerProduct<Cmpt, SymmTensor2D<Cmpt>>
499{
500public:
501
503};
504
505template<class Cmpt>
507{
508public:
509
511};
512
513template<class Cmpt>
515{
516public:
517
519};
520
521template<class Cmpt>
523{
524public:
525
527};
528
529
530template<class Cmpt>
532{
533public:
534
536};
537
538template<class Cmpt>
540{
541public:
542
544};
545
546template<class Cmpt>
548{
549public:
550
552};
553
554template<class Cmpt>
556{
557public:
558
560};
561
562
563// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
564
565} // End namespace Foam
566
567// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A templated (2 x 2) diagonal tensor of objects of <T>, effectively containing 1 element,...
const Cmpt & ii() const
A templated (2 x 2) symmetric tensor of objects of <T>, effectively containing 3 elements,...
Definition: SymmTensor2D.H:61
const Cmpt & xx() const
Definition: SymmTensor2DI.H:80
const Cmpt & yx() const
Definition: SymmTensor2DI.H:92
const SymmTensor2D< Cmpt > & T() const
Return non-Hermitian transpose.
const Cmpt & xy() const
Definition: SymmTensor2DI.H:86
const Cmpt & yy() const
Definition: SymmTensor2DI.H:98
Vector2D< Cmpt > diag() const
Extract the diagonal as a vector.
SymmTensor2D()=default
Default construct.
A templated (2 x 2) tensor of objects of <T> derived from VectorSpace.
Definition: Tensor2D.H:59
Templated 2D Vector derived from VectorSpace adding construction from 2 components,...
Definition: Vector2D.H:58
const Cmpt & y() const
Access to the vector y component.
Definition: Vector2DI.H:73
const Cmpt & x() const
Access to the vector x component.
Definition: Vector2DI.H:66
Templated vector space.
Definition: VectorSpace.H:79
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:63
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
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 > &)
Cmpt invariantII(const SymmTensor< Cmpt > &st)
Return the 2nd invariant of a SymmTensor.
Definition: SymmTensorI.H:468
dimensionedSymmTensor twoSymm(const dimensionedSymmTensor &dt)
tmp< GeometricField< Type, fvPatchField, volMesh > > operator&(const fvMatrix< Type > &, const DimensionedField< Type, volMesh > &)
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
dimensionedSymmTensor cof(const dimensionedSymmTensor &dt)
Cmpt invariantI(const SymmTensor< Cmpt > &st)
Return the 1st invariant of a SymmTensor.
Definition: SymmTensorI.H:460
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
errorManip< error > abort(error &err)
Definition: errorManip.H:144
SphericalTensor< Cmpt > sph(const DiagTensor< Cmpt > &dt)
Return the spherical part of a DiagTensor as a SphericalTensor.
Definition: DiagTensorI.H:130
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
error FatalError
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)