1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
27 #include "mathematicalConstants.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 const char* const tensor2D::typeName = "tensor2D";
40 const char* tensor2D::componentNames[] =
47 const tensor2D tensor2D::zero
54 const tensor2D tensor2D::one
61 const tensor2D tensor2D::max
68 const tensor2D tensor2D::min
75 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
77 // Return eigenvalues in ascending order of absolute values
78 vector2D eigenValues(const tensor2D& t)
83 if (mag(t.xy()) < SMALL && mag(t.yx()) < SMALL)
90 scalar mb = t.xx() + t.yy();
91 scalar c = t.xx()*t.yy() - t.xy()*t.yx();
93 // If there is a zero root
101 scalar disc = sqr(mb) - 4*c;
105 scalar q = sqrt(disc);
112 FatalErrorIn("eigenValues(const tensor2D&)")
113 << "zero and complex eigenvalues in tensor2D: " << t
114 << abort(FatalError);
119 // Sort the eigenvalues into ascending order
120 if (mag(i) > mag(ii))
125 return vector2D(i, ii);
129 vector2D eigenVector(const tensor2D& t, const scalar lambda)
133 return vector2D::zero;
136 if (mag(t.xy()) < SMALL && mag(t.yx()) < SMALL)
138 if (lambda > min(t.xx(), t.yy()))
140 return vector2D(1, 0);
144 return vector2D(0, 1);
147 else if (mag(t.xy()) < SMALL)
149 return vector2D(lambda - t.yy(), t.yx());
153 return vector2D(t.xy(), lambda - t.yy());
158 tensor2D eigenVectors(const tensor2D& t)
160 vector2D evals(eigenValues(t));
164 eigenVector(t, evals.x()),
165 eigenVector(t, evals.y())
172 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
174 } // End namespace Foam
176 // ************************************************************************* //