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 -------------------------------------------------------------------------------
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 :
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 :
73  SymmTensor2D::vsType(is)
74 {}
75 
76 
77 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
78 
79 template<class Cmpt>
80 inline const Cmpt& Foam::SymmTensor2D<Cmpt>::xx() const
81 {
82  return this->v_[XX];
83 }
84 
85 template<class Cmpt>
86 inline const Cmpt& Foam::SymmTensor2D<Cmpt>::xy() const
87 {
88  return this->v_[XY];
89 }
90 
91 template<class Cmpt>
92 inline const Cmpt& Foam::SymmTensor2D<Cmpt>::yx() const
93 {
94  return this->v_[XY];
95 }
96 
97 template<class Cmpt>
98 inline const Cmpt& Foam::SymmTensor2D<Cmpt>::yy() const
99 {
100  return this->v_[YY];
101 }
102 
103 
104 template<class Cmpt>
106 {
107  return this->v_[XX];
108 }
109 
110 template<class Cmpt>
112 {
113  return this->v_[XY];
114 }
115 
116 template<class Cmpt>
118 {
119  return this->v_[XY];
120 }
121 
122 template<class Cmpt>
124 {
125  return this->v_[YY];
126 }
127 
128 
129 template<class Cmpt>
131 {
132  return Vector2D<Cmpt>(this->v_[XX], this->v_[YY]);
133 }
134 
135 
136 template<class Cmpt>
138 {
139  this->v_[XX] = v.x(); this->v_[YY] = v.y();
140 }
141 
142 
143 template<class Cmpt>
145 {
146  return *this;
147 }
148 
149 
150 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
151 
152 template<class Cmpt>
154 (
155  const SphericalTensor2D<Cmpt>& st
156 )
157 {
158  this->v_[XX] = st.ii(); this->v_[XY] = Zero;
159  this->v_[YY] = st.ii();
160 }
161 
162 
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 
165 namespace Foam
166 {
167 
168 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
169 
170 //- Return the trace of a SymmTensor2D
171 template<class Cmpt>
172 inline Cmpt tr(const SymmTensor2D<Cmpt>& st)
173 {
174  return st.xx() + st.yy();
175 }
176 
177 
178 //- Return the spherical part of a SymmTensor2D
179 template<class Cmpt>
181 {
183  (
184  0.5*tr(st)
185  );
186 }
187 
188 
189 //- Return the symmetric part of a SymmTensor2D, i.e. itself
190 template<class Cmpt>
192 {
193  return st;
194 }
195 
196 
197 //- Return twice the symmetric part of a SymmTensor2D, i.e. twice itself
198 template<class Cmpt>
200 {
201  return 2*st;
202 }
203 
204 
205 //- Return the deviatoric part of a SymmTensor2D
206 template<class Cmpt>
208 {
209  return st - sph(st);
210 }
211 
212 
213 //- Return the two-third deviatoric part of a SymmTensor2D
214 template<class Cmpt>
216 {
217  return st - 2*sph(st);
218 }
219 
220 
221 //- Return the determinant of a SymmTensor2D
222 template<class Cmpt>
223 inline 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
230 template<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
242 template<class Cmpt>
243 inline 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
260 template<class Cmpt>
262 {
263  return inv(st, det(st));
264 }
265 
266 
267 //- Return the 1st invariant of a SymmTensor2D
268 template<class Cmpt>
269 inline Cmpt invariantI(const SymmTensor2D<Cmpt>& st)
270 {
271  return tr(st);
272 }
273 
274 
275 //- Return the 2nd invariant of a SymmTensor2D
276 template<class Cmpt>
277 inline Cmpt invariantII(const SymmTensor2D<Cmpt>& st)
278 {
279  return det(st);
280 }
281 
282 
283 //- Return the inner-product of a SymmTensor2D with itself
284 template<class Cmpt>
285 inline 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
298 template<class Cmpt>
299 inline 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
310 template<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
324 template<class Cmpt>
325 inline 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
337 template<class Cmpt>
338 inline 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
350 template<class Cmpt>
351 inline 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
363 template<class Cmpt>
364 inline 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
376 template<class Cmpt>
377 inline SymmTensor2D<Cmpt>
378 operator/(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
389 template<class Cmpt>
390 inline 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
405 template<class Cmpt>
406 inline 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
418 template<class Cmpt>
419 inline 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
431 template<class Cmpt>
432 inline 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
444 template<class Cmpt>
445 inline 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
457 template<class Cmpt>
458 inline 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
470 template<class Cmpt>
471 inline 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
479 template<class Cmpt>
480 inline Cmpt
482 {
483  return (st1.xx()*spt2.ii() + st1.yy()*spt2.ii());
484 }
485 
486 
487 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
488 
489 template<class Cmpt>
490 class outerProduct<SymmTensor2D<Cmpt>, Cmpt>
491 {
492 public:
493 
495 };
496 
497 template<class Cmpt>
498 class outerProduct<Cmpt, SymmTensor2D<Cmpt>>
499 {
500 public:
501 
503 };
504 
505 template<class Cmpt>
507 {
508 public:
509 
511 };
512 
513 template<class Cmpt>
514 class innerProduct<SymmTensor2D<Cmpt>, Vector2D<Cmpt>>
515 {
516 public:
517 
519 };
520 
521 template<class Cmpt>
522 class innerProduct<Vector2D<Cmpt>, SymmTensor2D<Cmpt>>
523 {
524 public:
525 
527 };
528 
529 
530 template<class Cmpt>
532 {
533 public:
534 
536 };
537 
538 template<class Cmpt>
540 {
541 public:
542 
544 };
545 
546 template<class Cmpt>
548 {
549 public:
550 
552 };
553 
554 template<class Cmpt>
556 {
557 public:
558 
560 };
561 
562 
563 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
564 
565 } // End namespace Foam
566 
567 // ************************************************************************* //
Foam::symm
dimensionedSymmTensor symm(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:84
Foam::innerProduct< SymmTensor2D< Cmpt >, Vector2D< Cmpt > >::type
Vector2D< Cmpt > type
Definition: SymmTensor2DI.H:518
s
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))
Definition: gmvOutputSpray.H:25
Foam::operator&
tmp< GeometricField< Type, fvPatchField, volMesh > > operator&(const fvMatrix< Type > &, const DimensionedField< Type, volMesh > &)
Foam::invariantI
Cmpt invariantI(const SymmTensor< Cmpt > &st)
Return the 1st invariant of a SymmTensor.
Definition: SymmTensorI.H:342
Tensor2D.H
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::innerProduct
Definition: products.H:141
Foam::SymmTensor2D
A templated (2 x 2) symmetric tensor of objects of <T>, effectively containing 3 elements,...
Definition: SymmTensor2D.H:58
Foam::operator-
tmp< faMatrix< Type > > operator-(const faMatrix< Type > &)
Foam::innerProduct< SphericalTensor2D< Cmpt >, SymmTensor2D< Cmpt > >::type
SymmTensor2D< Cmpt > type
Definition: SymmTensor2DI.H:551
Foam::SphericalTensor2D::ii
const Cmpt & ii() const
Definition: SphericalTensor2DI.H:67
Foam::Vector2D
Templated 2D Vector derived from VectorSpace adding construction from 2 components,...
Definition: Vector2D.H:55
Foam::dev2
dimensionedSymmTensor dev2(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:117
Foam::innerSqr
dimensionedSymmTensor innerSqr(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:62
Foam::innerProduct< SymmTensor2D< Cmpt >, SphericalTensor2D< Cmpt > >::type
SymmTensor2D< Cmpt > type
Definition: SymmTensor2DI.H:559
Foam::SymmTensor2D::SymmTensor2D
SymmTensor2D()=default
Default construct.
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::Tensor2D
A templated (2 x 2) tensor of objects of <T> derived from VectorSpace.
Definition: Tensor2D.H:59
Foam::VectorSpace
Templated vector space.
Definition: VectorSpace.H:56
Foam::outerProduct< SymmTensor2D< Cmpt >, Cmpt >::type
SymmTensor2D< Cmpt > type
Definition: SymmTensor2DI.H:494
Foam::typeOfSum
Definition: products.H:97
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::inv
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:73
Foam::SymmTensor2D::diag
Vector2D< Cmpt > diag() const
Extract the diagonal as a vector.
Definition: SymmTensor2DI.H:130
Foam::sph
SphericalTensor< Cmpt > sph(const DiagTensor< Cmpt > &dt)
Return the spherical part of a DiagTensor as a SphericalTensor.
Definition: DiagTensorI.H:130
Foam::VectorSpace< SymmTensor2D< Cmpt >, Cmpt, 3 >::vsType
VectorSpace< SymmTensor2D< Cmpt >, Cmpt, Ncmpts > vsType
VectorSpace type.
Definition: VectorSpace.H:86
Foam::operator&&
dimensioned< typename scalarProduct< Type1, Type2 >::type > operator&&(const dimensioned< Type1 > &, const dimensioned< Type2 > &)
Foam::FatalError
error FatalError
Foam::invariantII
Cmpt invariantII(const SymmTensor< Cmpt > &st)
Return the 2nd invariant of a SymmTensor.
Definition: SymmTensorI.H:350
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::cof
dimensionedSymmTensor cof(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:139
Foam::operator/
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
Definition: dimensionedScalar.C:68
Foam::SymmTensor2D::T
const SymmTensor2D< Cmpt > & T() const
Return non-Hermitian transpose.
Definition: SymmTensor2DI.H:144
Foam::typeOfSum< SphericalTensor2D< Cmpt >, SymmTensor2D< Cmpt > >::type
SymmTensor2D< Cmpt > type
Definition: SymmTensor2DI.H:535
Foam::innerProduct< Vector2D< Cmpt >, SymmTensor2D< Cmpt > >::type
Vector2D< Cmpt > type
Definition: SymmTensor2DI.H:526
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::typeOfSum< SymmTensor2D< Cmpt >, SphericalTensor2D< Cmpt > >::type
SymmTensor2D< Cmpt > type
Definition: SymmTensor2DI.H:543
Foam::outerProduct< Cmpt, SymmTensor2D< Cmpt > >::type
SymmTensor2D< Cmpt > type
Definition: SymmTensor2DI.H:502
Foam::operator+
tmp< faMatrix< Type > > operator+(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::SymmTensor2D::yx
const Cmpt & yx() const
Definition: SymmTensor2DI.H:92
Foam::innerProduct< SymmTensor2D< Cmpt >, SymmTensor2D< Cmpt > >::type
Tensor2D< Cmpt > type
Definition: SymmTensor2DI.H:510
Foam::SymmTensor2D::xx
const Cmpt & xx() const
Definition: SymmTensor2DI.H:80
Foam::tr
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:51
Foam::det
dimensionedScalar det(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:62
Foam::SymmTensor2D::yy
const Cmpt & yy() const
Definition: SymmTensor2DI.H:98
Foam::Vector2D::y
const Cmpt & y() const
Access to the vector y component.
Definition: Vector2DI.H:73
Foam::twoSymm
dimensionedSymmTensor twoSymm(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:95
Foam::outerProduct
Definition: products.H:106
Foam::Vector2D::x
const Cmpt & x() const
Access to the vector x component.
Definition: Vector2DI.H:66
Foam::SphericalTensor2D
A templated (2 x 2) diagonal tensor of objects of <T>, effectively containing 1 element,...
Definition: SphericalTensor2D.H:57
Foam::SymmTensor2D::xy
const Cmpt & xy() const
Definition: SymmTensor2DI.H:86
Foam::zero
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:62
Foam::dev
dimensionedSymmTensor dev(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:106