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