1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
28 #include "mathematicalConstants.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 const char* const tensor2D::typeName = "tensor2D";
41 const char* tensor2D::componentNames[] =
48 const tensor2D tensor2D::zero
55 const tensor2D tensor2D::one
62 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
64 // Return eigenvalues in ascending order of absolute values
65 vector2D eigenValues(const tensor2D& t)
70 if (mag(t.xy()) < SMALL && mag(t.yx()) < SMALL)
77 scalar mb = t.xx() + t.yy();
78 scalar c = t.xx()*t.yy() - t.xy()*t.yx();
80 // If there is a zero root
88 scalar disc = sqr(mb) - 4*c;
92 scalar q = sqrt(disc);
99 FatalErrorIn("eigenValues(const tensor2D&)")
100 << "zero and complex eigenvalues in tensor2D: " << t
101 << abort(FatalError);
106 // Sort the eigenvalues into ascending order
107 if (mag(i) > mag(ii))
112 return vector2D(i, ii);
116 vector2D eigenVector(const tensor2D& t, const scalar lambda)
120 return vector2D::zero;
123 if (mag(t.xy()) < SMALL && mag(t.yx()) < SMALL)
125 if (lambda > min(t.xx(), t.yy()))
127 return vector2D(1, 0);
131 return vector2D(0, 1);
134 else if (mag(t.xy()) < SMALL)
136 return vector2D(lambda - t.yy(), t.yx());
140 return vector2D(t.xy(), lambda - t.yy());
145 tensor2D eigenVectors(const tensor2D& t)
147 vector2D evals(eigenValues(t));
150 evs.x() = eigenVector(t, evals.x());
151 evs.y() = eigenVector(t, evals.y());
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 } // End namespace Foam
161 // ************************************************************************* //