CEPS  24.01
Cardiac ElectroPhysiology Simulator
GeomCell.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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
31 
33  m_cellType (CepsCellType::Simplex),
34  m_jacobian (JacobianMatrixType (3, 0)),
35  m_invJacobian (InverseJacobianMatrixType (0, 3)),
36  m_detJacobian (0.),
37  m_invJcomputed (false),
38  m_normal (CepsMathVertex(0.,0.,0.)),
39  m_diameter (-1.),
40  m_nodeSharingCells({})
41 {}
42 
44  GeomCell()
45 {
46  m_globalIndex = gID;
47  m_nodes = nodes;
48 }
49 
50 GeomNode*
52 {
53  CEPS_ABORT_IF(m_nodes.size()==0,"trying to get node with minimal index of cell with no nodes");
54 
55  const GeomNode* node = getNodeAt(0);
57 
58  for (auto n : m_nodes)
59  if (ceps::isValidPtr(n) and n->getGlobalIndex()<id)
60  {
61  node = n;
62  id = node->getGlobalIndex();
63  }
64 
66  "nullptr node, so we can not deduce the node with minimal index"
67  );
68  return const_cast<GeomNode*>(node);
69 }
70 
71 const CepsCellType&
73 {
74  return m_cellType;
75 }
76 
77 void
79 {
87  return;
88 }
89 
90 // --------------------------------------------------------------------------------
91 // Jacobian
92 // --------------------------------------------------------------------------------
93 
96 {
97  return m_detJacobian;
98 }
99 
102 {
103  CEPS_ABORT_IF (this->getDimension()==0,
104  "Trying to get jacobian matrix of element with global index #"
105  << getGlobalIndex () << "\nwhich is a 0D element"
106  );
107  return m_jacobian;
108 }
109 
112 {
113 
114  CEPS_ABORT_IF (this->getDimension()==0,
115  "Trying to get jacobian matrix of element with global index #"
116  << getGlobalIndex() << std::endl << "which is a 0D element"
117  );
118  if (not this->m_invJcomputed or this->m_invJacobian.rows() == 0)
120  return m_invJacobian;
121 }
122 
123 void
125 {
127 
130 
132  "Determinant of geometrical element #" << getGlobalIndex () << "is non-positive."
133  );
134  return;
135 }
136 
137 void
139 {
140  m_normal = n;
141 }
142 
145 {
146  return m_normal;
147 }
148 
149 void
151 {
152  m_nodeSharingCells = nCellIds;
153 }
154 
157 {
158  return m_nodeSharingCells;
159 }
160 
161 CepsReal
163 {
164  if (m_diameter<0)
165  computeDiameter();
166  return m_diameter;
167 }
168 
169 void
171 {
172  m_cellType = cellType;
173  setDimension (dim);
174  m_jacobian.setZero (3, nNodes-1);
175  m_invJacobian.setZero (nNodes-1, 3);
176  m_invJcomputed = false;
177  return;
178 }
179 
180 void
182 {
183  m_nodes.resize(nNodes);
184  std::copy(nodes, nodes + nNodes, m_nodes.begin ());
185  refresh();
186  return;
187 }
188 
189 void
191 {
192  CepsUInt size = m_nodes.size();
193  for (CepsUInt i=0 ;i<size;i++)
194  for (CepsUInt j=i+1;j<size;j++)
195  {
198  m_diameter = std::max(m_diameter,CepsVertex(n1-n2).norm2());
199  }
200 }
201 
204 {
206  "Passed cell is nullptr"
207  );
208  CepsStandardArgs args;
209  args.cellId = cell->getGlobalIndex();
210  args.attr = cell->getAttributes();
211  return args;
212 }
CepsCellType
Enum for different shapes of cells.
Definition: CepsEnums.hpp:128
@ Simplex
Simplices.
#define CEPS_ABORT_IF(condition, message)
Stops the execution with a message if condition is true. If testing is enabled, only throws a runtime...
CepsGlobalIndex CepsCellGlobalIndex
Indices of cells.
Definition: CepsTypes.hpp:222
std::set< _Type, _Compare, _Alloc > CepsSet
C++ set.
Definition: CepsTypes.hpp:209
std::vector< _Type, _Alloc > CepsVector
C++ vector.
Definition: CepsTypes.hpp:155
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
Definition: CepsTypes.hpp:109
float CepsReal
Need single precision floating point.
Definition: CepsTypes.hpp:100
Eigen::Matrix< CepsScalar, 3, 1 > CepsMathVertex
Vertex, eigen format.
Definition: CepsTypes.hpp:135
CepsGlobalIndex CepsNodeGlobalIndex
Indices of nodes.
Definition: CepsTypes.hpp:224
CepsArray3< CepsReal > CepsReal3D
Three real scalars, used like this for compatibility in polynomials.
Definition: CepsTypes.hpp:178
CepsStandardArgs getStandardArgsFrom(GeomCell *cell)
Returns a CepsStandardArgs structure with data from given cell.
Definition: GeomCell.cpp:203
CepsReal3D & getCoordinates()
Get three coordinates, read & write.
Definition: CepsVertex.cpp:174
Abstract class for geometrical cell. On top of index and attributes managament, the cell has informat...
Definition: GeomCell.hpp:48
JacobianMatrixType m_jacobian
Jacobian Matrix.
Definition: GeomCell.hpp:191
void setNodeSharingCellsIndices(const CepsSet< CepsCellGlobalIndex > &nCellIds)
Cells that share at least one node with self.
Definition: GeomCell.cpp:150
InverseJacobianMatrixType m_invJacobian
Inverse of Jacobian Matrix.
Definition: GeomCell.hpp:192
virtual CepsUInt getNumberOfNodes() const =0
Volume for 3D, area for 2D, length for 1D, 0 for points.
CepsBool m_invJcomputed
Flag to trigger computation of invJ.
Definition: GeomCell.hpp:194
void initialize(CepsUInt dim, CepsCellType cellType, CepsUInt nNodes)
internal init method
Definition: GeomCell.cpp:170
Eigen::Matrix< CepsReal, 3, Eigen::Dynamic > JacobianMatrixType
Typedef for jaccobian matrix.
Definition: GeomCell.hpp:53
virtual void computeJacobianMatrix()=0
Compute geometrical Jacobian matrix.
const CepsCellType & getCellType() const
Get the type of cell.
Definition: GeomCell.cpp:72
CepsMathVertex getNormal() const
Sets the normal vector, (useful for boundary cells only)
Definition: GeomCell.cpp:144
Eigen::Matrix< CepsReal, Eigen::Dynamic, 3 > InverseJacobianMatrixType
Typedef for inverse jaccobian matrix.
Definition: GeomCell.hpp:55
virtual void reset()
Wipes content.
Definition: GeomCell.cpp:78
GeomCell()
default constructor
Definition: GeomCell.cpp:32
CepsReal getJacobianDeterminant() const
Jacobian of geometrical deformation from reference cell.
Definition: GeomCell.cpp:95
virtual CepsBool checkJacobianDeterminant()=0
Tells if determinant is negative, tries to swap points to make it positive.
const CepsSet< CepsCellGlobalIndex > & getNodeSharingCellsIndices() const
Cells that share at least one node with self.
Definition: GeomCell.cpp:156
virtual void initializeNodes(GeomNode *const *nodes, CepsUInt nNodes)
internal init method
Definition: GeomCell.cpp:181
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
CepsReal getDiameter()
Size of cell.
Definition: GeomCell.cpp:162
CepsSet< CepsCellGlobalIndex > m_nodeSharingCells
IDs of cells that have a node in common.
Definition: GeomCell.hpp:197
virtual const InverseJacobianMatrixType & getInverseJacobianMatrix()
Jacobian Matrix of deformation from reference cell (3 rows for R^3, element dimension columns)
Definition: GeomCell.cpp:111
CepsReal m_diameter
Size of cell.
Definition: GeomCell.hpp:196
virtual void refresh()
Recomputes jacobian matrix and determinant.
Definition: GeomCell.cpp:124
virtual void computeInverseJacobianMatrix()=0
Compute inverse of geometrical Jacobian matrix.
CepsMathVertex m_normal
For boundary cells, outward normal vector.
Definition: GeomCell.hpp:195
void setNormal(CepsMathVertex n)
Sets the normal vector, (useful for boundary cells only)
Definition: GeomCell.cpp:138
virtual void computeJacobianDeterminant()=0
Compute geometrical Jacobian determinant.
void computeDiameter()
Computes size of cell (max edge length)
Definition: GeomCell.cpp:190
CepsCellType m_cellType
Cell type.
Definition: GeomCell.hpp:190
GeomNode * getNodeWithMinimalIndex() const
Returns node with smallest index (used eg to determine ownership)
Definition: GeomCell.cpp:51
Base class for nodes used in meshes.
Definition: GeomNode.hpp:53
void reset()
Equivalent to HoldsAttributes::clear()
CepsSet< CepsAttribute > & getAttributes()
Returns the attributes of the entity.
void reset()
Sets the entity as NOT being on boundary.
void reset()
Equivalent to HoldsCells::clearCells.
void setDimension(const CepsUInt &dim)
Set the dimension of the object.
const CepsUInt & getDimension() const
Get the dimension of the object.
void reset()
Set the dimension of the object to 0.
const CepsGlobalIndex & getGlobalIndex() const
Get the index
CepsGlobalIndex m_globalIndex
the index
void reset()
Set the index to 0u.
CepsVector< GeomNode * > m_nodes
The node pointers.
Definition: HoldsNodes.hpp:215
void reset()
Equivalent to HoldsNodes::clearNodes.
GeomNode * getNodeAt(const CepsUInt &i)
Pointer to the i-th node.
void reset()
Gives ownership to rank(), removes halos.
CepsBool isValidPtr(_Type *ptr)
Tells if pointer is not null.
Definition: CepsMemory.hpp:61
const _Type & max(const CepsVector< _Type, _Alloc > &vec)
Returns the maximum of the vector, const version.
Definition: CepsVector.hpp:464
CepsBool isNullPtr(_Type *ptr)
Tells if passed pointer is null.
Definition: CepsMemory.hpp:45
Structure used to pass arguments to SAFunc (see pde directory) The flags of the SAFunc allows extract...
Definition: CepsTypes.hpp:239
CepsSet< CepsAttribute > attr
attributes
Definition: CepsTypes.hpp:243
CepsCellGlobalIndex cellId
cell index
Definition: CepsTypes.hpp:245