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 :
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>
95 {
96  return *this;
97 }
98 
99 
100 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
101 
102 template<class Cmpt>
104 (
105  const SphericalTensor2D<Cmpt>& st
106 )
107 {
108  this->v_[XX] = st.ii(); this->v_[XY] = Zero;
109  this->v_[YY] = st.ii();
110 }
111 
112 
113 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
114 
115 namespace Foam
116 {
118 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
119 
120 //- Return the trace of a SymmTensor2D
121 template<class Cmpt>
122 inline Cmpt tr(const SymmTensor2D<Cmpt>& st)
123 {
124  return st.xx() + st.yy();
125 }
126 
128 //- Return the spherical part of a SymmTensor2D
129 template<class Cmpt>
131 {
133  (
134  0.5*tr(st)
135  );
136 }
137 
138 
139 //- Return the symmetric part of a SymmTensor2D, i.e. itself
140 template<class Cmpt>
141 inline const SymmTensor2D<Cmpt>& symm(const SymmTensor2D<Cmpt>& st)
142 {
143  return st;
144 }
145 
146 
147 //- Return twice the symmetric part of a SymmTensor2D, i.e. twice itself
148 template<class Cmpt>
149 inline SymmTensor2D<Cmpt> twoSymm(const SymmTensor2D<Cmpt>& st)
150 {
151  return 2*st;
152 }
153 
154 
155 //- Return the deviatoric part of a SymmTensor2D
156 template<class Cmpt>
157 inline SymmTensor2D<Cmpt> dev(const SymmTensor2D<Cmpt>& st)
158 {
159  return st - sph(st);
160 }
161 
162 
163 //- Return the two-third deviatoric part of a SymmTensor2D
164 template<class Cmpt>
165 inline SymmTensor2D<Cmpt> dev2(const SymmTensor2D<Cmpt>& st)
166 {
167  return st - 2*sph(st);
168 }
169 
171 //- Return the determinant of a SymmTensor2D
172 template<class Cmpt>
173 inline Cmpt det(const SymmTensor2D<Cmpt>& st)
174 {
175  return (st.xx()*st.yy() - st.xy()*st.xy());
176 }
177 
178 
179 //- Return the cofactor SymmTensor2D of a SymmTensor2D
180 template<class Cmpt>
181 inline SymmTensor2D<Cmpt> cof(const SymmTensor2D<Cmpt>& st)
182 {
183  return SymmTensor2D<Cmpt>
184  (
185  st.yy(), -st.yx(),
186  st.xx()
187  );
188 }
189 
191 //- Return the inverse of a SymmTensor2D using a given determinant
192 template<class Cmpt>
193 inline SymmTensor2D<Cmpt> inv(const SymmTensor2D<Cmpt>& st, const Cmpt detst)
194 {
195  #ifdef FULLDEBUG
196  if (mag(detst) < SMALL)
197  {
199  << "SymmTensor2D is not invertible due to the zero determinant:"
200  << "det(SymmTensor2D) = " << mag(detst)
201  << abort(FatalError);
202  }
203  #endif
204  // cofactor and adjugate matrices of SymmTensor are the same, hence no .T()
205  return cof(st)/detst;
206 }
207 
208 
209 //- Return the inverse of a SymmTensor2D
210 template<class Cmpt>
211 inline SymmTensor2D<Cmpt> inv(const SymmTensor2D<Cmpt>& st)
212 {
213  return inv(st, det(st));
214 }
215 
216 
217 //- Return the 1st invariant of a SymmTensor2D
218 template<class Cmpt>
219 inline Cmpt invariantI(const SymmTensor2D<Cmpt>& st)
220 {
221  return tr(st);
222 }
223 
225 //- Return the 2nd invariant of a SymmTensor2D
226 template<class Cmpt>
227 inline Cmpt invariantII(const SymmTensor2D<Cmpt>& st)
228 {
229  return det(st);
230 }
231 
232 
233 //- Return the inner-product of a SymmTensor2D with itself
234 template<class Cmpt>
235 inline SymmTensor2D<Cmpt>
236 innerSqr(const SymmTensor2D<Cmpt>& st)
237 {
238  return SymmTensor2D<Cmpt>
239  (
240  st.xx()*st.xx() + st.xy()*st.xy(),
241  st.xx()*st.xy() + st.xy()*st.yy(),
242  st.xy()*st.xy() + st.yy()*st.yy()
243  );
244 }
245 
246 
247 //- Return the square of Frobenius norm of a SymmTensor2D as a Cmpt
248 template<class Cmpt>
249 inline Cmpt magSqr(const SymmTensor2D<Cmpt>& st)
250 {
251  return Cmpt
252  (
253  mag(st.xx()*st.xx()) + 2*mag(st.xy()*st.xy())
254  + mag(st.yy()*st.yy())
255  );
256 }
257 
258 
259 //- Outer-product of a Vector2D with itself
260 template<class Cmpt>
261 inline SymmTensor2D<Cmpt> sqr(const Vector2D<Cmpt>& v)
262 {
263  return SymmTensor2D<Cmpt>
264  (
265  v.x()*v.x(), v.x()*v.y(),
266  v.y()*v.y()
267  );
268 }
269 
271 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
272 
273 //- Sum of a SphericalTensor2D and a SymmTensor2D
274 template<class Cmpt>
275 inline SymmTensor2D<Cmpt>
277 {
278  return SymmTensor2D<Cmpt>
279  (
280  spt1.ii() + st2.xx(), st2.xy(),
281  spt1.ii() + st2.yy()
282  );
283 }
285 
286 //- Sum of a SymmTensor2D and a SphericalTensor2D
287 template<class Cmpt>
288 inline SymmTensor2D<Cmpt>
290 {
291  return SymmTensor2D<Cmpt>
292  (
293  st1.xx() + spt2.ii(), st1.xy(),
294  st1.yy() + spt2.ii()
295  );
296 }
297 
298 
299 //- Subtract a SymmTensor2D from a SphericalTensor2D
300 template<class Cmpt>
303 {
304  return SymmTensor2D<Cmpt>
305  (
306  spt1.ii() - st2.xx(), -st2.xy(),
307  spt1.ii() - st2.yy()
308  );
309 }
310 
311 
312 //- Subtract a SphericalTensor2D from a SymmTensor2D
313 template<class Cmpt>
314 inline SymmTensor2D<Cmpt>
315 operator-(const SymmTensor2D<Cmpt>& st1, const SphericalTensor2D<Cmpt>& spt2)
316 {
317  return SymmTensor2D<Cmpt>
318  (
319  st1.xx() - spt2.ii(), st1.xy(),
320  st1.yy() - spt2.ii()
321  );
322 }
323 
324 
325 //- Division of a SymmTensor2D by a Cmpt
326 template<class Cmpt>
327 inline SymmTensor2D<Cmpt>
328 operator/(const SymmTensor2D<Cmpt>& st, const Cmpt s)
329 {
330  return SymmTensor2D<Cmpt>
331  (
332  st.xx()/s, st.xy()/s,
333  st.yy()/s
334  );
335 }
336 
337 
338 //- Inner-product of a SymmTensor2D and a SymmTensor2D
339 template<class Cmpt>
340 inline Tensor2D<Cmpt>
341 operator&(const SymmTensor2D<Cmpt>& st1, const SymmTensor2D<Cmpt>& st2)
342 {
343  return Tensor2D<Cmpt>
344  (
345  st1.xx()*st2.xx() + st1.xy()*st2.xy(),
346  st1.xx()*st2.xy() + st1.xy()*st2.yy(),
347 
348  st1.xy()*st2.xx() + st1.yy()*st2.xy(),
349  st1.xy()*st2.xy() + st1.yy()*st2.yy()
350  );
351 }
352 
353 
354 //- Inner-product of a SphericalTensor2D and a SymmTensor2D
355 template<class Cmpt>
356 inline SymmTensor2D<Cmpt>
357 operator&(const SphericalTensor2D<Cmpt>& spt1, const SymmTensor2D<Cmpt>& st2)
358 {
359  return SymmTensor2D<Cmpt>
360  (
361  spt1.ii()*st2.xx(), spt1.ii()*st2.xy(),
362  spt1.ii()*st2.yy()
363  );
364 }
365 
366 
367 //- Inner-product of a SymmTensor2D and a SphericalTensor2D
368 template<class Cmpt>
369 inline SymmTensor2D<Cmpt>
370 operator&(const SymmTensor2D<Cmpt>& st1, const SphericalTensor2D<Cmpt>& spt2)
371 {
372  return SymmTensor2D<Cmpt>
373  (
374  st1.xx()*spt2.ii(), st1.xy()*spt2.ii(),
375  st1.yy()*spt2.ii()
376  );
377 }
378 
379 
380 //- Inner-product of a SymmTensor2D and a Vector2D
381 template<class Cmpt>
382 inline Vector2D<Cmpt>
383 operator&(const SymmTensor2D<Cmpt>& st, const Vector2D<Cmpt>& v)
384 {
385  return Vector2D<Cmpt>
386  (
387  st.xx()*v.x() + st.xy()*v.y(),
388  st.xy()*v.x() + st.yy()*v.y()
389  );
390 }
391 
392 
393 //- Inner-product of a Vector2D and a SymmTensor2D
394 template<class Cmpt>
395 inline Vector2D<Cmpt>
396 operator&(const Vector2D<Cmpt>& v, const SymmTensor2D<Cmpt>& st)
397 {
398  return Vector2D<Cmpt>
399  (
400  v.x()*st.xx() + v.y()*st.xy(),
401  v.x()*st.xy() + v.y()*st.yy()
402  );
403 }
404 
405 
406 //- Double-inner-product of a SymmTensor2D and a SymmTensor2D
407 template<class Cmpt>
408 inline Cmpt
410 {
411  return
412  (
413  st1.xx()*st2.xx() + 2*st1.xy()*st2.xy()
414  + st1.yy()*st2.yy()
415  );
416 }
417 
418 
419 //- Double-inner-product of a SphericalTensor2D and a SymmTensor2D
420 template<class Cmpt>
421 inline Cmpt
422 operator&&(const SphericalTensor2D<Cmpt>& spt1, const SymmTensor2D<Cmpt>& st2)
423 {
424  return (spt1.ii()*st2.xx() + spt1.ii()*st2.yy());
425 }
426 
427 
428 //- Double-inner-product of a SymmTensor2D and a SphericalTensor2D
429 template<class Cmpt>
430 inline Cmpt
431 operator&&(const SymmTensor2D<Cmpt>& st1, const SphericalTensor2D<Cmpt>& spt2)
432 {
433  return (st1.xx()*spt2.ii() + st1.yy()*spt2.ii());
434 }
435 
436 
437 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
438 
439 template<class Cmpt>
440 class outerProduct<SymmTensor2D<Cmpt>, Cmpt>
441 {
442 public:
443 
444  typedef SymmTensor2D<Cmpt> type;
445 };
446 
447 template<class Cmpt>
448 class outerProduct<Cmpt, SymmTensor2D<Cmpt>>
449 {
450 public:
451 
452  typedef SymmTensor2D<Cmpt> type;
453 };
455 template<class Cmpt>
456 class innerProduct<SymmTensor2D<Cmpt>, SymmTensor2D<Cmpt>>
457 {
458 public:
459 
460  typedef Tensor2D<Cmpt> type;
461 };
462 
463 template<class Cmpt>
464 class innerProduct<SymmTensor2D<Cmpt>, Vector2D<Cmpt>>
465 {
466 public:
467 
468  typedef Vector2D<Cmpt> type;
469 };
470 
471 template<class Cmpt>
472 class innerProduct<Vector2D<Cmpt>, SymmTensor2D<Cmpt>>
473 {
474 public:
475 
476  typedef Vector2D<Cmpt> type;
477 };
478 
479 
480 template<class Cmpt>
481 class typeOfSum<SphericalTensor2D<Cmpt>, SymmTensor2D<Cmpt>>
482 {
483 public:
484 
485  typedef SymmTensor2D<Cmpt> type;
486 };
487 
488 template<class Cmpt>
490 {
491 public:
492 
494 };
495 
496 template<class Cmpt>
498 {
499 public:
500 
502 };
503 
504 template<class Cmpt>
506 {
507 public:
508 
510 };
511 
512 
513 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
514 
515 } // End namespace Foam
516 
517 // ************************************************************************* //
Cmpt invariantII(const SymmTensor< Cmpt > &st)
Return the 2nd invariant of a SymmTensor.
Definition: SymmTensorI.H:375
SymmTensor2D()=default
Default construct.
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:578
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
const Cmpt & xy() const noexcept
Definition: SymmTensor2D.H:142
Templated vector space.
Definition: VectorSpace.H:52
dimensionSet operator &&(const dimensionSet &ds1, const dimensionSet &ds2)
const Cmpt & yx() const noexcept
Definition: SymmTensor2D.H:143
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
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:87
tmp< faMatrix< Type > > operator+(const faMatrix< Type > &, const faMatrix< Type > &)
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)
const SymmTensor2D< Cmpt > & T() const
Return non-Hermitian transpose.
Definition: SymmTensor2DI.H:87
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)
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:365
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:58
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
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:157