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 3 x 3 matrix
30 \*---------------------------------------------------------------------------*/
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 inline void matrix3D::calculateDeterminant()
45 const FixedList<FixedList<scalar, 3>, 3>& mat = *this;
48 mat[0][0] * (mat[1][1] * mat[2][2] - mat[1][2] * mat[2][1]) -
49 mat[0][1] * (mat[1][0] * mat[2][2] - mat[1][2] * mat[2][0]) +
50 mat[0][2] * (mat[1][0] * mat[2][1] - mat[1][1] * mat[2][0]);
52 calculatedDet_ = true;
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 inline matrix3D::matrix3D()
63 inline matrix3D::matrix3D(const matrix3D& m)
65 FixedList<FixedList<scalar, 3>, 3>(m),
67 calculatedDet_(m.calculatedDet_)
70 inline matrix3D::~matrix3D()
73 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
75 inline scalar matrix3D::determinant()
77 calculateDeterminant();
82 inline matrix3D matrix3D::inverse()
84 calculateDeterminant();
86 const FixedList<FixedList<scalar, 3>, 3>& mat = *this;
89 imat[0][0] = (mat[1][1] * mat[2][2] - mat[1][2] * mat[2][1]) / det_;
90 imat[0][1] = (mat[0][2] * mat[2][1] - mat[0][1] * mat[2][2]) / det_;
91 imat[0][2] = (mat[0][1] * mat[1][2] - mat[0][2] * mat[1][1]) / det_;
92 imat[1][0] = (mat[1][2] * mat[2][0] - mat[1][0] * mat[2][2]) / det_;
93 imat[1][1] = (mat[0][0] * mat[2][2] - mat[0][2] * mat[2][0]) / det_;
94 imat[1][2] = (mat[0][2] * mat[1][0] - mat[0][0] * mat[1][2]) / det_;
95 imat[2][0] = (mat[1][0] * mat[2][1] - mat[1][1] * mat[2][0]) / det_;
96 imat[2][1] = (mat[0][1] * mat[2][0] - mat[0][0] * mat[2][1]) / det_;
97 imat[2][2] = (mat[0][0] * mat[1][1] - mat[0][1] * mat[1][0]) / det_;
102 inline FixedList<scalar, 3> matrix3D::solve
104 const FixedList<scalar, 3>& source
107 FixedList<scalar, 3> result;
108 result[0] = solveFirst(source);
109 result[1] = solveSecond(source);
110 result[2] = solveThird(source);
115 inline scalar matrix3D::solveFirst(const FixedList<scalar, 3>& source)
117 calculateDeterminant();
119 const FixedList<FixedList<scalar, 3>, 3>& mat = *this;
123 (mat[1][1] * mat[2][2] - mat[1][2] * mat[2][1]) * source[0] +
124 (mat[0][2] * mat[2][1] - mat[0][1] * mat[2][2]) * source[1] +
125 (mat[0][1] * mat[1][2] - mat[0][2] * mat[1][1]) * source[2]
129 inline scalar matrix3D::solveSecond(const FixedList<scalar, 3>& source)
131 calculateDeterminant();
133 const FixedList<FixedList<scalar, 3>, 3>& mat = *this;
137 (mat[1][2] * mat[2][0] - mat[1][0] * mat[2][2]) * source[0] +
138 (mat[0][0] * mat[2][2] - mat[0][2] * mat[2][0]) * source[1] +
139 (mat[0][2] * mat[1][0] - mat[0][0] * mat[1][2]) * source[2]
143 inline scalar matrix3D::solveThird(const FixedList<scalar, 3>& source)
145 calculateDeterminant();
147 const FixedList<FixedList<scalar, 3>, 3>& mat = *this;
151 (mat[1][0] * mat[2][1] - mat[1][1] * mat[2][0]) * source[0] +
152 (mat[0][1] * mat[2][0] - mat[0][0] * mat[2][1]) * source[1] +
153 (mat[0][0] * mat[1][1] - mat[0][1] * mat[1][0]) * source[2]
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 } // End namespace Foam
161 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //