1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 const char* const tensor2D::typeName = "tensor2D";
39 const char* tensor2D::componentNames[] =
46 const tensor2D tensor2D::zero
53 const tensor2D tensor2D::one
60 const tensor2D tensor2D::max
67 const tensor2D tensor2D::min
74 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
76 // Return eigenvalues in ascending order of absolute values
77 vector2D eigenValues(const tensor2D& t)
82 if (mag(t.xy()) < SMALL && mag(t.yx()) < SMALL)
89 scalar mb = t.xx() + t.yy();
90 scalar c = t.xx()*t.yy() - t.xy()*t.yx();
92 // If there is a zero root
100 scalar disc = sqr(mb) - 4*c;
104 scalar q = sqrt(disc);
111 FatalErrorIn("eigenValues(const tensor2D&)")
112 << "zero and complex eigenvalues in tensor2D: " << t
113 << abort(FatalError);
118 // Sort the eigenvalues into ascending order
119 if (mag(i) > mag(ii))
124 return vector2D(i, ii);
128 vector2D eigenVector(const tensor2D& t, const scalar lambda)
132 return vector2D::zero;
135 if (mag(t.xy()) < SMALL && mag(t.yx()) < SMALL)
137 if (lambda > min(t.xx(), t.yy()))
139 return vector2D(1, 0);
143 return vector2D(0, 1);
146 else if (mag(t.xy()) < SMALL)
148 return vector2D(lambda - t.yy(), t.yx());
152 return vector2D(t.xy(), lambda - t.yy());
157 tensor2D eigenVectors(const tensor2D& t)
159 vector2D evals(eigenValues(t));
163 eigenVector(t, evals.x()),
164 eigenVector(t, evals.y())
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
173 } // End namespace Foam
175 // ************************************************************************* //