matrix2DI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 Class
25  matrix2D
26 
27 Description
28  Implementation od 2 x 2 matrix
29 
30 \*---------------------------------------------------------------------------*/
31 
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
41 {
42  if( calculatedDet_ )
43  return;
44 
45  const FixedList<FixedList<scalar, 2>, 2>& mat = *this;
46  det_ = mat[0][0] * mat[1][1] - mat[0][1] * mat[1][0];
47 
48  calculatedDet_ = true;
49 }
50 
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 
53 inline matrix2D::matrix2D()
54 :
55  det_(),
56  calculatedDet_(false)
57 {}
58 
59 inline matrix2D::matrix2D(const matrix2D& m)
60 :
61  FixedList<FixedList<scalar, 2>, 2>(m),
62  det_(m.det_),
63  calculatedDet_(m.calculatedDet_)
64 {}
65 
66 inline matrix2D::~matrix2D()
67 {}
68 
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
70 
71 inline scalar matrix2D::determinant()
72 {
74 
75  return det_;
76 }
77 
79 {
81 
82  const FixedList<FixedList<scalar, 2>, 2>& mat = *this;
83 
84  matrix2D imat;
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_;
89 
90  return matrix2D(imat);
91 }
92 
94 (
95  const FixedList<scalar, 2>& source
96 )
97 {
98  FixedList<scalar, 2> result;
99  result[0] = solveFirst(source);
100  result[1] = solveSecond(source);
101 
102  return result;
103 }
104 
105 inline scalar matrix2D::solveFirst(const FixedList<scalar, 2>& source)
106 {
108 
109  const FixedList<FixedList<scalar, 2>, 2>& mat = *this;
110 
111  return
112  (
113  mat[1][1] * source[0] -
114  mat[0][1] * source[1]
115  ) / det_;
116 }
117 
118 inline scalar matrix2D::solveSecond(const FixedList<scalar, 2>& source)
119 {
121 
122  const FixedList<FixedList<scalar, 2>, 2>& mat = *this;
123 
124  return
125  (
126  -1.0 * mat[1][0] * source[0] +
127  mat[0][0] * source[1]
128  ) / det_;
129 }
130 
131 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
132 
133 } // End namespace Foam
134 
135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::matrix2D::determinant
scalar determinant()
return matrix determinant
Definition: matrix2DI.H:70
Foam::matrix2D::solveSecond
scalar solveSecond(const FixedList< scalar, 2 > &source)
return the second component of the solution vector
Definition: matrix2DI.H:117
Foam::matrix2D::matrix2D
matrix2D()
Null constructor.
Definition: matrix2DI.H:52
Foam::matrix2D::solveFirst
scalar solveFirst(const FixedList< scalar, 2 > &source)
return the first component of the solution vector
Definition: matrix2DI.H:104
Foam::matrix2D::calculatedDet_
bool calculatedDet_
Definition: matrix2D.H:53
Foam::matrix2D
Definition: matrix2D.H:48
Foam::matrix2D::inverse
matrix2D inverse()
return inverse matrix
Definition: matrix2DI.H:77
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::FixedList
A 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:53
Foam::matrix2D::solve
FixedList< scalar, 2 > solve(const FixedList< scalar, 2 > &source)
find the solution of the system with the given rhs
Definition: matrix2DI.H:93
Foam::matrix2D::~matrix2D
~matrix2D()
Definition: matrix2DI.H:65
Foam::matrix2D::calculateDeterminant
void calculateDeterminant()
calculate matrix determinant
Definition: matrix2DI.H:39
Foam::matrix2D::det_
scalar det_
Definition: matrix2D.H:52