CEPS  24.01
Cardiac ElectroPhysiology Simulator
GeomSimplices.cpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
32 
33 // ======================================================
34 // 0D element
35 
36 template<>
38 getMeasure () const
39 {
40  CEPS_ABORT ("cannot return 0-dim element measure");
41  return 0.0;
42 }
43 
44 template<>
47 {
49  // const JacType &J = m_jacobian;
50  // InvJacType &Jinv = m_invJacobian;
51  // const CepsReal &det = m_detJacobian;
52  m_invJcomputed = true;
53  return;
54 }
55 
56 template<>
59 {
60  m_detJacobian = 1.0;
61  return;
62 }
63 
64 // ======================================================
65 // 1D element
66 
67 template<>
69 getMeasure () const
70 {
71  return getJacobianDeterminant ();
72 }
73 
74 template<>
75 void GeomCableCell::
77 {
79  const JacobianMatrixType &J = m_jacobian;
81  const CepsReal &det = m_detJacobian;
82 
83  Jinv.row (0) = J.col (0) / det / det;
84 
85  m_invJcomputed = true;
86  return;
87 }
88 
89 template<>
90 void GeomCableCell::
92 {
93  m_detJacobian = getJacobianMatrix ().col (0).norm ();
94  return;
95 }
96 
97 // ======================================================
98 // 2D element
99 
100 template<>
102 getMeasure () const
103 {
104  return getJacobianDeterminant () / 2.0;
105 }
106 
107 template<>
110 {
112  const JacobianMatrixType &J = m_jacobian;
114 
115  CepsReal a = J (0, 0) * J (0, 0) + J (1, 0) * J (1, 0) + J (2, 0) * J (2, 0);
116  CepsReal b = J (0, 0) * J (0, 1) + J (1, 0) * J (1, 1) + J (2, 0) * J (2, 1);
117  CepsReal c = b;
118  CepsReal d = J (0, 1) * J (0, 1) + J (1, 1) * J (1, 1) + J (2, 1) * J (2, 1);
119  CepsReal det_1 = a * d - b * c;
120  CepsReal a_m_inv = +d / det_1;
121  CepsReal b_m_inv = -b / det_1;
122  CepsReal c_m_inv = -c / det_1;
123  CepsReal d_m_inv = +a / det_1;
124 
125  Jinv (0, 0) = a_m_inv * J (0, 0) + b_m_inv * J (0, 1);
126  Jinv (1, 0) = c_m_inv * J (0, 0) + d_m_inv * J (0, 1);
127  Jinv (0, 1) = a_m_inv * J (1, 0) + b_m_inv * J (1, 1);
128  Jinv (1, 1) = c_m_inv * J (1, 0) + d_m_inv * J (1, 1);
129  Jinv (0, 2) = a_m_inv * J (2, 0) + b_m_inv * J (2, 1);
130  Jinv (1, 2) = c_m_inv * J (2, 0) + d_m_inv * J (2, 1);
131 
132  m_invJcomputed = true;
133  return;
134 }
135 
136 template<>
139 {
141  m_detJacobian = J.col (0).cross (J.col (1)).norm ();
142  return;
143 }
144 
145 // ======================================================
146 // 3D element
147 
148 template<>
150 getMeasure () const
151 {
152  return getJacobianDeterminant () / 6.0;
153 }
154 
155 template<>
156 void GeomTetraCell::
158 {
160  const JacobianMatrixType &J = m_jacobian;
162  const CepsReal &det = m_detJacobian;
163 
164  Jinv (0, 0) = +(J (1, 1) * J (2, 2) - J (1, 2) * J (2, 1)) / det;
165  Jinv (1, 0) = -(J (1, 0) * J (2, 2) - J (1, 2) * J (2, 0)) / det;
166  Jinv (2, 0) = +(J (1, 0) * J (2, 1) - J (1, 1) * J (2, 0)) / det;
167  Jinv (0, 1) = -(J (0, 1) * J (2, 2) - J (0, 2) * J (2, 1)) / det;
168  Jinv (1, 1) = +(J (0, 0) * J (2, 2) - J (0, 2) * J (2, 0)) / det;
169  Jinv (2, 1) = -(J (0, 0) * J (2, 1) - J (0, 1) * J (2, 0)) / det;
170  Jinv (0, 2) = +(J (0, 1) * J (1, 2) - J (0, 2) * J (1, 1)) / det;
171  Jinv (1, 2) = -(J (0, 0) * J (1, 2) - J (0, 2) * J (1, 0)) / det;
172  Jinv (2, 2) = +(J (0, 0) * J (1, 1) - J (0, 1) * J (1, 0)) / det;
173 
174  m_invJcomputed = true;
175  return;
176 }
177 
178 template<>
179 void GeomTetraCell::
181 {
183  m_detJacobian = J.determinant ();
184  return;
185 }
#define CEPS_ABORT(message)
Stops the execution with a message. If testing is enabled, only throws a runtime_error.
float CepsReal
Need single precision floating point.
Definition: CepsTypes.hpp:100
JacobianMatrixType m_jacobian
Jacobian Matrix.
Definition: GeomCell.hpp:191
InverseJacobianMatrixType m_invJacobian
Inverse of Jacobian Matrix.
Definition: GeomCell.hpp:192
CepsBool m_invJcomputed
Flag to trigger computation of invJ.
Definition: GeomCell.hpp:194
Eigen::Matrix< CepsReal, 3, Eigen::Dynamic > JacobianMatrixType
Typedef for jaccobian matrix.
Definition: GeomCell.hpp:53
Eigen::Matrix< CepsReal, Eigen::Dynamic, 3 > InverseJacobianMatrixType
Typedef for inverse jaccobian matrix.
Definition: GeomCell.hpp:55
CepsReal getJacobianDeterminant() const
Jacobian of geometrical deformation from reference cell.
Definition: GeomCell.cpp:95
CepsReal m_detJacobian
determinant of Jacobian matrix
Definition: GeomCell.hpp:193
virtual const JacobianMatrixType & getJacobianMatrix()
Jacobian Matrix of deformation from reference cell (3 rows for R^3, element dimension columns)
Definition: GeomCell.cpp:101
void computeJacobianDeterminant() override
Computes the determinant of the Jacobian matrix (specialized by dimension)
CepsReal getMeasure() const override
Element size: volume for tetrahedron, area for triangle and length for cable.
void computeInverseJacobianMatrix() override
Computes the inverse of the jacobian matrix.
CepsBool checkJacobianDeterminant() override
Checks if determinant is non-positive, and tries to reorder element's nodes if it is.