1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 const tensor2D tensor2D::max
69 const tensor2D tensor2D::min
76 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
78 // Return eigenvalues in ascending order of absolute values
79 vector2D eigenValues(const tensor2D& t)
84 if (mag(t.xy()) < SMALL && mag(t.yx()) < SMALL)
91 scalar mb = t.xx() + t.yy();
92 scalar c = t.xx()*t.yy() - t.xy()*t.yx();
94 // If there is a zero root
102 scalar disc = sqr(mb) - 4*c;
106 scalar q = sqrt(disc);
113 FatalErrorIn("eigenValues(const tensor2D&)")
114 << "zero and complex eigenvalues in tensor2D: " << t
115 << abort(FatalError);
120 // Sort the eigenvalues into ascending order
121 if (mag(i) > mag(ii))
126 return vector2D(i, ii);
130 vector2D eigenVector(const tensor2D& t, const scalar lambda)
134 return vector2D::zero;
137 if (mag(t.xy()) < SMALL && mag(t.yx()) < SMALL)
139 if (lambda > min(t.xx(), t.yy()))
141 return vector2D(1, 0);
145 return vector2D(0, 1);
148 else if (mag(t.xy()) < SMALL)
150 return vector2D(lambda - t.yy(), t.yx());
154 return vector2D(t.xy(), lambda - t.yy());
159 tensor2D eigenVectors(const tensor2D& t)
161 vector2D evals(eigenValues(t));
164 evs.x() = eigenVector(t, evals.x());
165 evs.y() = eigenVector(t, evals.y());
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
173 } // End namespace Foam
175 // ************************************************************************* //