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  }
149 
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 // ************************************************************************* //
Foam::VectorSpace::rootMax
static const Form rootMax
Definition: VectorSpace.H:119
Foam::VectorSpace::one
static const Form one
Definition: VectorSpace.H:116
Foam::VectorSpace::componentNames
static const char *const componentNames[]
Definition: VectorSpace.H:114
symmTensor2D.H
Foam::eigenVector
vector eigenVector(const symmTensor &T, const scalar eVal, const vector &standardBasis1, const vector &standardBasis2)
Definition: symmTensor.C:152
Foam::eigenValues
dimensionedVector eigenValues(const dimensionedSymmTensor &dt)
Definition: dimensionedTensor.C:149
Foam::sin
dimensionedScalar sin(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:264
Foam::SymmTensor2D
A templated (2 x 2) symmetric tensor of objects of <T>, effectively containing 3 elements,...
Definition: SymmTensor2D.H:58
Foam::eigenVectors
dimensionedTensor eigenVectors(const dimensionedSymmTensor &dt)
Definition: dimensionedTensor.C:160
A
static const Foam::dimensionedScalar A("", Foam::dimPressure, 611.21)
Foam::tensor2D
Tensor2D< scalar > tensor2D
Tensor2D of scalars, i.e. Tensor2D<scalar>.
Definition: symmTensor2D.H:68
Foam::Vector2D< scalar >
Foam::sign
dimensionedScalar sign(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:166
Foam::Tensor2D
A templated (2 x 2) tensor of objects of <T> derived from VectorSpace.
Definition: Tensor2D.H:59
Foam::hypot
dimensionedScalar hypot(const dimensionedScalar &x, const dimensionedScalar &y)
Definition: dimensionedScalar.C:327
Foam::VectorSpace::min
static const Form min
Definition: VectorSpace.H:118
Foam::SymmTensor2D::I
static const SymmTensor2D I
Definition: SymmTensor2D.H:78
phi
surfaceScalarField & phi
Definition: setRegionFluidFields.H:8
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
T
const volScalarField & T
Definition: createFieldRefs.H:2
Foam::VectorSpace::rootMin
static const Form rootMin
Definition: VectorSpace.H:120
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::VectorSpace::max
static const Form max
Definition: VectorSpace.H:117
Foam::vector2D
Vector2D< scalar > vector2D
A 2D vector of scalars obtained from the generic Vector2D.
Definition: vector2D.H:51
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::atan
dimensionedScalar atan(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:269
Foam::VectorSpace::zero
static const Form zero
Definition: VectorSpace.H:115
Foam::tr
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:51
Foam::Vector2D::y
const Cmpt & y() const
Access to the vector y component.
Definition: Vector2DI.H:73
Foam::Vector2D::x
const Cmpt & x() const
Access to the vector x component.
Definition: Vector2DI.H:66
Foam::I
static const Identity< scalar > I
Definition: Identity.H:95
Foam::VectorSpace::typeName
static const char *const typeName
Definition: VectorSpace.H:113
Foam::cos
dimensionedScalar cos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:265