tensor2D.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 | Copyright (C) 2011-2015 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 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 template<>
36 const char* const tensor2D::typeName = "tensor2D";
37 
38 template<>
39 const char* tensor2D::componentNames[] =
40 {
41  "xx", "xy",
42  "yx", "yy"
43 };
44 
45 template<>
47 (
48  0, 0,
49  0, 0
50 );
51 
52 template<>
54 (
55  1, 1,
56  1, 1
57 );
58 
59 template<>
61 (
62  VGREAT, VGREAT,
63  VGREAT, VGREAT
64 );
65 
66 template<>
68 (
69  -VGREAT, -VGREAT,
70  -VGREAT, -VGREAT
71 );
72 
73 template<>
75 (
76  1, 0,
77  0, 1
78 );
79 
80 
81 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
82 
83 // Return eigenvalues in ascending order of absolute values
85 {
86  scalar i = 0;
87  scalar ii = 0;
88 
89  if (mag(t.xy()) < SMALL && mag(t.yx()) < SMALL)
90  {
91  i = t.xx();
92  ii = t.yy();
93  }
94  else
95  {
96  scalar mb = t.xx() + t.yy();
97  scalar c = t.xx()*t.yy() - t.xy()*t.yx();
98 
99  // If there is a zero root
100  if (mag(c) < SMALL)
101  {
102  i = 0;
103  ii = mb;
104  }
105  else
106  {
107  scalar disc = sqr(mb) - 4*c;
108 
109  if (disc > 0)
110  {
111  scalar q = sqrt(disc);
112 
113  i = 0.5*(mb - q);
114  ii = 0.5*(mb + q);
115  }
116  else
117  {
119  << "zero and complex eigenvalues in tensor2D: " << t
120  << abort(FatalError);
121  }
122  }
123  }
124 
125  // Sort the eigenvalues into ascending order
126  if (i > ii)
127  {
128  Swap(i, ii);
129  }
130 
131  return vector2D(i, ii);
132 }
133 
134 
135 vector2D eigenVector(const tensor2D& t, const scalar lambda)
136 {
137  if (lambda < SMALL)
138  {
139  return vector2D::zero;
140  }
141 
142  if (mag(t.xy()) < SMALL && mag(t.yx()) < SMALL)
143  {
144  if (lambda > min(t.xx(), t.yy()))
145  {
146  return vector2D(1, 0);
147  }
148  else
149  {
150  return vector2D(0, 1);
151  }
152  }
153  else if (mag(t.xy()) < SMALL)
154  {
155  return vector2D(lambda - t.yy(), t.yx());
156  }
157  else
158  {
159  return vector2D(t.xy(), lambda - t.yy());
160  }
161 }
162 
163 
165 {
166  vector2D evals(eigenValues(t));
167 
168  tensor2D evs
169  (
170  eigenVector(t, evals.x()),
171  eigenVector(t, evals.y())
172  );
173 
174  return evs;
175 }
176 
177 
178 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179 
180 } // End namespace Foam
181 
182 // ************************************************************************* //
Foam::Tensor2D::zero
static const Tensor2D zero
Definition: Tensor2D.H:76
Foam::eigenVectors
dimensionedTensor eigenVectors(const dimensionedTensor &dt)
Definition: dimensionedTensor.C:157
Foam::Tensor2D::xx
const Cmpt & xx() const
Definition: Tensor2DI.H:108
Foam::Tensor2D::one
static const Tensor2D one
Definition: Tensor2D.H:77
tensor2D.H
Foam::Vector2D< scalar >
Foam::Vector2D< scalar >::zero
static const Vector2D zero
Definition: Vector2D.H:70
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::Tensor2D
Templated 2D tensor derived from VectorSpace adding construction from 4 components,...
Definition: Tensor2D.H:56
Foam::Tensor2D::yy
const Cmpt & yy() const
Definition: Tensor2DI.H:126
Foam::Vector2D::y
const Cmpt & y() const
Definition: Vector2DI.H:73
Foam::Tensor2D::yx
const Cmpt & yx() const
Definition: Tensor2DI.H:120
Foam::eigenVector
vector eigenVector(const tensor &, const scalar lambda)
Definition: tensor.C:207
Foam::eigenValues
dimensionedVector eigenValues(const dimensionedTensor &dt)
Definition: dimensionedTensor.C:146
Foam::Tensor2D::max
static const Tensor2D max
Definition: Tensor2D.H:78
Foam::Vector2D::x
const Cmpt & x() const
Definition: Vector2DI.H:67
Foam::FatalError
error FatalError
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::Tensor2D::min
static const Tensor2D min
Definition: Tensor2D.H:79
Foam::tensor2D
Tensor2D< scalar > tensor2D
Tensor2D or scalars.
Definition: tensor2D.H:49
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:49
Foam::vector2D
Vector2D< scalar > vector2D
vector2D obtained from generic Vector2D
Definition: vector2D.H:49
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:142
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::Tensor2D::typeName
static const char *const typeName
Definition: Tensor2D.H:73
Foam::Swap
void Swap(T &a, T &b)
Definition: Swap.H:43
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
lambda
dimensionedScalar lambda(laminarTransport.lookup("lambda"))
Foam::Tensor2D::xy
const Cmpt & xy() const
Definition: Tensor2DI.H:114
Foam::Tensor2D::componentNames
static const char * componentNames[]
Definition: Tensor2D.H:74
Foam::Tensor2D::I
static const Tensor2D I
Definition: Tensor2D.H:80