symmTensor2D.C
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) 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 "symmTensor2D.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 template<>
34 const char* const Foam::symmTensor2D::vsType::typeName = "symmTensor2D";
35 
36 template<>
38 {
39  "xx", "xy",
40  "yy"
41 };
42 
43 template<>
45 (
46  symmTensor2D::uniform(0)
47 );
48 
49 template<>
51 (
52  symmTensor2D::uniform(1)
53 );
54 
55 template<>
57 (
58  symmTensor2D::uniform(VGREAT)
59 );
60 
61 template<>
63 (
64  symmTensor2D::uniform(-VGREAT)
65 );
66 
67 template<>
69 (
70  symmTensor2D::uniform(ROOTVGREAT)
71 );
72 
73 template<>
75 (
76  symmTensor2D::uniform(-ROOTVGREAT)
77 );
78 
79 template<>
81 (
82  1, 0,
83  1
84 );
85 
86 
87 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
88 
90 {
91  // Return diagonal if T is effectively diagonal tensor
92  if (sqr(T.xy()) < ROOTSMALL)
93  {
94  return vector2D(T.diag());
95  }
96 
97  //(K:Eqs. 3.2-3.3)
98  const scalar skewTrace = T.xx() - T.yy();
99  const scalar trace = tr(T);
100  const scalar gap = sign(skewTrace)*hypot(skewTrace, 2*T.xy());
101 
102  return vector2D(0.5*(trace + gap), 0.5*(trace - gap));
103 }
104 
105 
107 (
108  const symmTensor2D& T,
109  const scalar eVal,
110  const vector2D& standardBasis
111 )
112 {
113  // Construct the characteristic equation system for this eigenvalue
114  const tensor2D A(T - eVal*tensor2D::I);
115 
116  // Evaluate the eigenvector using the largest divisor
117  if (mag(A.yy()) > mag(A.xx()) && mag(A.yy()) > SMALL)
118  {
119  const vector2D eVec(1, -A.yx()/A.yy());
120 
121  #ifdef FULLDEBUG
122  if (mag(eVec) < SMALL)
123  {
125  << "Eigenvector magnitude should be non-zero:"
126  << "mag(eigenvector) = " << mag(eVec)
127  << abort(FatalError);
128  }
129  #endif
130 
131  return eVec/mag(eVec);
132  }
133  else if (mag(A.xx()) > SMALL)
134  {
135  const vector2D eVec(-A.xy()/A.xx(), 1);
136 
137  #ifdef FULLDEBUG
138  if (mag(eVec) < SMALL)
139  {
141  << "Eigenvector magnitude should be non-zero:"
142  << "mag(eigenvector) = " << mag(eVec)
143  << abort(FatalError);
144  }
145  #endif
146 
147  return eVec/mag(eVec);
148  }
150  // Repeated eigenvalue
151  return vector2D(-standardBasis.y(), standardBasis.x());
152 }
153 
154 
156 (
157  const symmTensor2D& T,
158  const vector2D& eVals
159 )
160 {
161  // (K:Eq. 3.5)
162  const scalar skewTrace = T.xx() - T.yy();
163 
164  if (mag(skewTrace) > SMALL)
165  {
166  const scalar phi = 0.5*atan(2*T.xy()/skewTrace);
167  const scalar cphi = cos(phi);
168  const scalar sphi = sin(phi);
169  return tensor2D(cphi, sphi, -sphi, cphi);
170  }
171  else if (mag(T.xy()) > SMALL)
172  {
173  const scalar a = 0.70710678; // phi ~ 45deg
174  return tensor2D(a, sign(T.xy())*a, -1*sign(T.xy())*a, a);
175  }
176 
177  // (K:p. 3)
178  return tensor2D(1, 0, 0, 1);
179 }
180 
181 
183 {
184  const vector2D eVals(eigenValues(T));
185 
186  return eigenVectors(T, eVals);
187 }
188 
189 
190 // ************************************************************************* //
vector eigenVector(const symmTensor &T, const scalar eVal, const vector &standardBasis1, const vector &standardBasis2)
Return a real eigenvector corresponding to a given real eigenvalue of a given symmTensor.
Definition: symmTensor.C:146
dimensionedScalar sign(const dimensionedScalar &ds)
static const char *const typeName
Definition: VectorSpace.H:121
static const Form max
Definition: VectorSpace.H:125
static const SymmTensor2D I
Definition: SymmTensor2D.H:78
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
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
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Vector2D< scalar > vector2D
A 2D vector of scalars obtained from the generic Vector2D.
Definition: vector2D.H:56
static const char *const componentNames[]
Definition: VectorSpace.H:122
static const Form rootMin
Definition: VectorSpace.H:128
A templated (2 x 2) tensor of objects of <T> derived from VectorSpace.
Definition: Tensor2D.H:52
static const Form min
Definition: VectorSpace.H:126
dimensionedTensor eigenVectors(const dimensionedSymmTensor &dt)
dimensionedScalar cos(const dimensionedScalar &ds)
static const Identity< scalar > I
Definition: Identity.H:100
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
errorManip< error > abort(error &err)
Definition: errorManip.H:139
dimensionedScalar sin(const dimensionedScalar &ds)
const volScalarField & T
static const Form rootMax
Definition: VectorSpace.H:127
dimensionedScalar atan(const dimensionedScalar &ds)
A templated (2 x 2) symmetric tensor of objects of <T>, effectively containing 3 elements, derived from VectorSpace.
Definition: SymmTensor2D.H:54
static const Form one
Definition: VectorSpace.H:124
dimensionedVector eigenValues(const dimensionedSymmTensor &dt)
static const Foam::dimensionedScalar A("", Foam::dimPressure, 611.21)
dimensionedScalar hypot(const dimensionedScalar &x, const dimensionedScalar &y)
static const Form zero
Definition: VectorSpace.H:123
SymmTensor2D< scalar > symmTensor2D
SymmTensor2D of scalars, i.e. SymmTensor2D<scalar>.
Definition: symmTensor2D.H:62
Tensor2D< scalar > tensor2D
Tensor2D of scalars, i.e. Tensor2D<scalar>.
Definition: symmTensor2D.H:64