1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6 \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of cfMesh.
11 cfMesh 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 cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
28 Implementation od 2 x 2 matrix
30 \*---------------------------------------------------------------------------*/
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 inline void matrix2D::calculateDeterminant()
45 const FixedList<FixedList<scalar, 2>, 2>& mat = *this;
46 det_ = mat[0][0] * mat[1][1] - mat[0][1] * mat[1][0];
48 calculatedDet_ = true;
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 inline matrix2D::matrix2D()
59 inline matrix2D::matrix2D(const matrix2D& m)
61 FixedList<FixedList<scalar, 2>, 2>(m),
63 calculatedDet_(m.calculatedDet_)
66 inline matrix2D::~matrix2D()
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
71 inline scalar matrix2D::determinant()
73 calculateDeterminant();
78 inline matrix2D matrix2D::inverse()
80 calculateDeterminant();
82 const FixedList<FixedList<scalar, 2>, 2>& mat = *this;
85 imat[0][0] = mat[1][1] / det_;
86 imat[0][1] = -1.0 * mat[0][1] / det_;
87 imat[1][0] = -1.0 * mat[1][0] / det_;
88 imat[1][1] = mat[0][0] / det_;
90 return matrix2D(imat);
93 inline FixedList<scalar, 2> matrix2D::solve
95 const FixedList<scalar, 2>& source
98 FixedList<scalar, 2> result;
99 result[0] = solveFirst(source);
100 result[1] = solveSecond(source);
105 inline scalar matrix2D::solveFirst(const FixedList<scalar, 2>& source)
107 calculateDeterminant();
109 const FixedList<FixedList<scalar, 2>, 2>& mat = *this;
113 mat[1][1] * source[0] -
114 mat[0][1] * source[1]
118 inline scalar matrix2D::solveSecond(const FixedList<scalar, 2>& source)
120 calculateDeterminant();
122 const FixedList<FixedList<scalar, 2>, 2>& mat = *this;
126 -1.0 * mat[1][0] * source[0] +
127 mat[0][0] * source[1]
131 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
133 } // End namespace Foam
135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //