CEPS  24.01
Cardiac ElectroPhysiology Simulator
DistributedMatrix.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 
32 // Depending on the compilation options, use
33 // one implementation. Default is PETSc
34 #ifdef CEPS_USE_PETSC
36 #endif // CEPS_USE_PETSC
37 
40  const CepsMathDynamic2D &subMat,
41  const CepsVector<CepsGlobalIndex> &indicesI,
42  const CepsVector<CepsGlobalIndex> &indicesJ
43 )
44 {
45  // Eigen matrices are column oriented
46  #ifdef CEPS_USE_PETSC
47  MatSetOption(m_A, MAT_ROW_ORIENTED, PETSC_FALSE);
48  #endif
49  CepsInt N = indicesI.size();
50  CepsInt M = indicesJ.size();
51  #ifdef CEPS_DEBUG_ENABLED
52  for (CepsUInt i=0; i<subMat.rows(); i++)
53  for (CepsUInt j=0; j<subMat.cols(); j++)
54  ceps::checkNanOrInf(subMat(i,j),
55  CepsString("while inserting coefficient in matrix at position (") +
56  ceps::toString(indicesI[i]) + "," + ceps::toString(indicesJ[j]) + ")"
57  );
58  #endif
59  addValues(subMat.data(),N,M,indicesI.data(),indicesJ.data());
60  return;
61 }
62 
65  const CepsVector<CepsGlobalIndex> &indicesI,
66  const CepsVector<CepsGlobalIndex> &indicesJ,
67  CepsMathDynamic2D &subMat
68 )
69 {
70 // Eigen matrices are column oriented
71 #ifdef CEPS_USE_PETSC
72  MatSetOption (m_A, MAT_ROW_ORIENTED, PETSC_FALSE);
73 #endif
74  CepsInt N = indicesI.size ();
75  subMat.resize (N, N);
76  getValues (subMat.data (), N, N, indicesI.data (), indicesJ.data ());
77  return;
78 }
79 
80 const PetscMatrix & DistributedMatrix::
81 getMatrix () const
82 {
83  return m_A;
84 }
std::basic_string< CepsChar > CepsString
C++ format string.
Definition: CepsTypes.hpp:128
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
int32_t CepsInt
Need 32 bit integer.
Definition: CepsTypes.hpp:106
Eigen::Matrix< CepsScalar, Eigen::Dynamic, Eigen::Dynamic > CepsMathDynamic2D
Dynamic 2D array, eigen format.
Definition: CepsTypes.hpp:140
void getSubMatrix(const CepsVector< CepsGlobalIndex > &indicesI, const CepsVector< CepsGlobalIndex > &indicesJ, CepsMathDynamic2D &subMat)
Insert each element of a distributed matrix in a small Eigen submatrix.
const PetscMatrix & getMatrix() const
The underlying matrix.
void addSubMatrix(const CepsMathDynamic2D &subMat, const CepsVector< CepsGlobalIndex > &indicesI, const CepsVector< CepsGlobalIndex > &indicesJ)
Add each element of a small square matrix in a distributed matrix.
void addValues(const CepsMathScalar *values, CepsInt nbRows, CepsInt nbColumns, const CepsGlobalIndex *rowIndices, const CepsGlobalIndex *columnIndices)
Add multiple values in the matrix at once.
PetscMatrix m_A
The main object.
void getValues(CepsMathScalar *values, CepsInt nbRows, CepsInt nbColumns, const CepsGlobalIndex *rowIndices, const CepsGlobalIndex *columnIndices)
Get multiple values in the matrix.
CepsString toString(_Tp value)
Convert a given value to a string (input has to be compatible with std::to_string)
Definition: CepsString.hpp:409
void checkNanOrInf(CepsReal v, CepsString message="")
Stops if value is NaN or infty.