tensor2D.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "tensor2D.H"
27 #include "quadraticEqn.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 template<>
32 const char* const Foam::tensor2D::vsType::typeName = "tensor2D";
33 
34 template<>
35 const char* const Foam::tensor2D::vsType::componentNames[] =
36 {
37  "xx", "xy",
38  "yx", "yy"
39 };
40 
41 template<>
43 (
44  tensor2D::uniform(0)
45 );
46 
47 template<>
49 (
50  tensor2D::uniform(1)
51 );
52 
53 template<>
55 (
56  tensor2D::uniform(vGreat)
57 );
58 
59 template<>
61 (
62  tensor2D::uniform(-vGreat)
63 );
64 
65 template<>
67 (
68  tensor2D::uniform(rootVGreat)
69 );
70 
71 template<>
73 (
74  tensor2D::uniform(-rootVGreat)
75 );
76 
77 template<>
79 (
80  tensor2D::uniform(NaN)
81 );
82 
83 template<>
85 (
86  1, 0,
87  0, 1
88 );
89 
90 
91 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
92 
94 {
95  // Coefficients of the characteristic quadratic polynomial (a = 1)
96  const scalar b = - t.xx() - t.yy();
97  const scalar c = t.xx()*t.yy() - t.xy()*t.yx();
98 
99  // Solve
100  Roots<2> roots = quadraticEqn(1, b, c).roots();
101 
102  // Check the root types
103  vector2D lambda = vector2D::zero;
104  forAll(roots, i)
105  {
106  switch (roots.type(i))
107  {
108  case rootType::real:
109  lambda[i] = roots[i];
110  break;
111  case rootType::complex:
113  << "Complex eigenvalues detected for tensor: " << t
114  << endl;
115  lambda[i] = 0;
116  break;
117  case rootType::posInf:
118  lambda[i] = vGreat;
119  break;
120  case rootType::negInf:
121  lambda[i] = - vGreat;
122  break;
123  case rootType::nan:
125  << "Eigenvalue calculation failed for tensor: " << t
126  << exit(FatalError);
127  }
128  }
129 
130  // Sort the eigenvalues into ascending order
131  if (lambda.x() > lambda.y())
132  {
133  Swap(lambda.x(), lambda.y());
134  }
135 
136  return lambda;
137 }
138 
139 
141 (
142  const tensor2D& T,
143  const scalar lambda,
144  const vector2D& direction1
145 )
146 {
147  // Construct the linear system for this eigenvalue
149 
150  // Evaluate the eigenvector using the largest divisor
151  if (mag(A.yy()) > mag(A.xx()) && mag(A.yy()) > small)
152  {
153  vector2D ev(1, - A.yx()/A.yy());
154 
155  return ev/mag(ev);
156  }
157  else if (mag(A.xx()) > small)
158  {
159  vector2D ev(- A.xy()/A.xx(), 1);
160 
161  return ev/mag(ev);
162  }
163 
164  // Repeated eigenvalue
165  return vector2D(- direction1.y(), direction1.x());
166 }
167 
168 
170 {
171  vector2D Ux(1, 0), Uy(0, 1);
172 
173  Ux = eigenVector(T, lambdas.x(), Uy);
174  Uy = eigenVector(T, lambdas.y(), Ux);
175 
176  return tensor2D(Ux, Uy);
177 }
178 
179 
181 {
182  const vector2D lambdas(eigenValues(T));
183 
184  return eigenVectors(T, lambdas);
185 }
186 
187 
188 // ************************************************************************* //
static const Foam::dimensionedScalar A("A", Foam::dimPressure, 611.21)
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Templated storage for the roots of polynomial equations, plus flags to indicate the nature of the roo...
Definition: Roots.H:67
void type(const direction i, const rootType t)
Set the type of the i-th root.
Definition: RootsI.H:120
Templated 2D tensor derived from VectorSpace adding construction from 4 components,...
Definition: Tensor2D.H:59
const Cmpt & xx() const
Definition: Tensor2DI.H:113
const Cmpt & yx() const
Definition: Tensor2DI.H:125
static const Tensor2D I
Definition: Tensor2D.H:75
const Cmpt & xy() const
Definition: Tensor2DI.H:119
const Cmpt & yy() const
Definition: Tensor2DI.H:131
const Cmpt & y() const
Definition: Vector2DI.H:74
const Cmpt & x() const
Definition: Vector2DI.H:68
static const Form zero
Definition: VectorSpace.H:118
static const char *const componentNames[]
Definition: VectorSpace.H:117
static const Form one
Definition: VectorSpace.H:119
static const Form nan
Definition: VectorSpace.H:124
static const Form rootMax
Definition: VectorSpace.H:122
static const Form max
Definition: VectorSpace.H:120
static const Form rootMin
Definition: VectorSpace.H:123
static const Form min
Definition: VectorSpace.H:121
static const char *const typeName
Definition: VectorSpace.H:116
Quadratic equation of the form a*x^2 + b*x + c = 0.
Definition: quadraticEqn.H:52
Roots< 2 > roots() const
Get the roots.
Definition: quadraticEqn.C:31
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
volScalarField & b
Definition: createFields.H:25
dimensionedScalar lambda(viscosity->lookup("lambda"))
#define WarningInFunction
Report a warning using Foam::Warning.
const dimensionedScalar c
Speed of light in a vacuum.
Vector2D< scalar > vector2D
vector2D obtained from generic Vector2D
Definition: vector2D.H:49
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
dimensionedTensor eigenVectors(const dimensionedTensor &dt)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
Tensor2D< scalar > tensor2D
Tensor2D or scalars.
Definition: tensor2D.H:49
static const Identity< scalar > I
Definition: Identity.H:93
dimensioned< scalar > mag(const dimensioned< Type > &)
dimensionedVector eigenValues(const dimensionedTensor &dt)
error FatalError
void Swap(T &a, T &b)
Definition: Swap.H:43
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
vector eigenVector(const tensor &T, const scalar lambda, const vector &direction1, const vector &direction2)
Definition: tensor.C:140