Ice Sheet System Model  4.18
Code documentation
Public Member Functions | Data Fields
PetscMat Class Reference

#include <PetscMat.h>

Public Member Functions

 PetscMat ()
 
 PetscMat (int M, int N)
 
 PetscMat (int M, int N, IssmDouble sparsity)
 
 PetscMat (int m, int n, int M, int N, int *d_nnz, int *o_nnz)
 
 PetscMat (IssmDouble *serial_mat, int M, int N, IssmDouble sparsity)
 
 PetscMat (int M, int N, int connectivity, int numberofdofspernode)
 
 ~PetscMat ()
 
void AllocationInfo (void)
 
void Echo (void)
 
void Assemble (void)
 
IssmDouble Norm (NormMode norm_type)
 
void GetSize (int *pM, int *pN)
 
void GetLocalSize (int *pM, int *pN)
 
void MatMult (PetscVec *X, PetscVec *AX)
 
PetscMatDuplicate (void)
 
IssmDoubleToSerial (void)
 
void SetValues (int m, int *idxm, int n, int *idxn, IssmDouble *values, InsMode mode)
 
void Convert (MatrixType type)
 
void SetZero (void)
 

Data Fields

Mat matrix
 

Detailed Description

Definition at line 24 of file PetscMat.h.

Constructor & Destructor Documentation

◆ PetscMat() [1/6]

PetscMat::PetscMat ( )

Definition at line 21 of file PetscMat.cpp.

21  {/*{{{*/
22  this->matrix=NULL;
23  #ifdef _HAVE_AD_
24  this->amatrix=NULL;
25  #endif
26 
27 }

◆ PetscMat() [2/6]

PetscMat::PetscMat ( int  M,
int  N 
)

Definition at line 29 of file PetscMat.cpp.

29  {/*{{{*/
30 
31  this->matrix=NewMat(M,N,IssmComm::GetComm());
32 }

◆ PetscMat() [3/6]

PetscMat::PetscMat ( int  M,
int  N,
IssmDouble  sparsity 
)

Definition at line 34 of file PetscMat.cpp.

34  {/*{{{*/
35 
36  this->matrix=NewMat(M,N,sparsity,IssmComm::GetComm());
37 }

◆ PetscMat() [4/6]

PetscMat::PetscMat ( int  m,
int  n,
int  M,
int  N,
int *  d_nnz,
int *  o_nnz 
)

Definition at line 39 of file PetscMat.cpp.

39  {/*{{{*/
40 
41  MatCreate(IssmComm::GetComm(),&this->matrix);
42  MatSetSizes(this->matrix,m,n,M,N);
43  MatSetFromOptions(this->matrix);
44 
45  /*
46  * Versions of Petsc beyond 3.3 have changed the use of preallocation
47  * routines to distinguish between parallel builds and sequential. Since
48  * our Windows builds are currently only sequential, we need to change
49  * the way we use these functions.
50  *
51  * The following code computes the total number of non-zeroes per row of the
52  * matrix in question. In parallel builds it is nescessary to kep track of
53  * diagonal non zeros and off-diagonal (d_nnz and o_nnz). Sequential does
54  * not make that distinction.
55  */
56  #ifdef _HAVE_PETSC_MPI_
57  int* nnz = new int[M];
58  for(int i = 0; i < M; i++)
59  nnz[i] = o_nnz[i] + d_nnz[i];
60 
61  PetscErrorCode ierr = MatSeqAIJSetPreallocation(this->matrix,0,nnz);
62  delete[] nnz;
63  #else
64  PetscErrorCode ierr = MatMPIAIJSetPreallocation(this->matrix,0,d_nnz,0,o_nnz);
65  #endif
66  if(ierr) _error_("PETSc could not allocate matrix (probably not enough memory)");
67 // MatSetOption(this->matrix,MAT_NEW_NONZERO_ALLOCATION_ERR,PETSC_FALSE);
68 
69 }

◆ PetscMat() [5/6]

PetscMat::PetscMat ( IssmDouble serial_mat,
int  M,
int  N,
IssmDouble  sparsity 
)

Definition at line 71 of file PetscMat.cpp.

71  {/*{{{*/
72 
73  int i;
74  int* idxm=NULL;
75  int* idxn=NULL;
76 
77  if(M)idxm=xNew<int>(M);
78  if(N)idxn=xNew<int>(N);
79 
80  for(i=0;i<M;i++)idxm[i]=i;
81  for(i=0;i<N;i++)idxn[i]=i;
82 
83  this->matrix=NewMat(M,N,sparsity,IssmComm::GetComm());
84  MatSetValues(this->matrix,M,idxm,N,idxn,serial_mat,INSERT_VALUES);
85  MatAssemblyBegin(this->matrix,MAT_FINAL_ASSEMBLY);
86  MatAssemblyEnd(this->matrix,MAT_FINAL_ASSEMBLY);
87 
88  xDelete<int>(idxm);
89  xDelete<int>(idxn);
90 
91 }

◆ PetscMat() [6/6]

PetscMat::PetscMat ( int  M,
int  N,
int  connectivity,
int  numberofdofspernode 
)

Definition at line 93 of file PetscMat.cpp.

93  {/*{{{*/
94 
95  this->matrix=NewMat(M,N,connectivity,numberofdofspernode,IssmComm::GetComm());
96 
97 }

◆ ~PetscMat()

PetscMat::~PetscMat ( )

Definition at line 99 of file PetscMat.cpp.

99  {/*{{{*/
100  MatFree(&this->matrix);
101 }

Member Function Documentation

◆ AllocationInfo()

void PetscMat::AllocationInfo ( void  )

Definition at line 105 of file PetscMat.cpp.

105  {/*{{{*/
106 
107  MatInfo info;
108  MatGetInfo(this->matrix,MAT_GLOBAL_SUM,&info);
109  _printf0_("=========================== Stiffness matrix allocation info ===========================\n");
110  _printf0_("\n");
111  _printf0_(" Block size : "<<info.block_size << "\n");
112  _printf0_(" nz_allocated: "<<info.nz_allocated << "\n");
113  _printf0_(" nz_used : "<<info.nz_used << "\n");
114  _printf0_(" nz_unneeded : "<<info.nz_unneeded<<" ("<<double(info.nz_unneeded)/double(info.nz_allocated)*100.<<"%)\n");
115  _printf0_("\n");
116  _printf0_("========================================================================================\n");
117 }

◆ Echo()

void PetscMat::Echo ( void  )

Definition at line 119 of file PetscMat.cpp.

119  {/*{{{*/
120 
121  MatView(this->matrix,PETSC_VIEWER_STDOUT_WORLD);
122 }

◆ Assemble()

void PetscMat::Assemble ( void  )

Definition at line 124 of file PetscMat.cpp.

124  {/*{{{*/
125 
126  _assert_(this->matrix);
127  MatAssemblyBegin(this->matrix,MAT_FINAL_ASSEMBLY);
128  MatAssemblyEnd(this->matrix,MAT_FINAL_ASSEMBLY);
129 
130 }

◆ Norm()

IssmDouble PetscMat::Norm ( NormMode  norm_type)

Definition at line 132 of file PetscMat.cpp.

132  {/*{{{*/
133 
134  IssmDouble norm=0;
135  _assert_(this->matrix);
136  MatNorm(this->matrix,ISSMToPetscNormMode(mode),&norm);
137 
138  return norm;
139 
140 }

◆ GetSize()

void PetscMat::GetSize ( int *  pM,
int *  pN 
)

Definition at line 142 of file PetscMat.cpp.

142  {/*{{{*/
143 
144  _assert_(this->matrix);
145  MatGetSize(this->matrix,pM,pN);
146 }

◆ GetLocalSize()

void PetscMat::GetLocalSize ( int *  pM,
int *  pN 
)

Definition at line 148 of file PetscMat.cpp.

148  {/*{{{*/
149 
150  _assert_(this->matrix);
151  MatGetLocalSize(this->matrix,pM,pN);
152 
153 }

◆ MatMult()

void PetscMat::MatMult ( PetscVec X,
PetscVec AX 
)

Definition at line 155 of file PetscMat.cpp.

155  {/*{{{*/
156 
157  _assert_(this->matrix);
158  _assert_(X->vector);
160 
161 }

◆ Duplicate()

PetscMat * PetscMat::Duplicate ( void  )

Definition at line 163 of file PetscMat.cpp.

163  {/*{{{*/
164 
165  PetscMat* output=new PetscMat();
166  _assert_(this->matrix);
167  MatDuplicate(this->matrix,MAT_COPY_VALUES,&output->matrix);
168 
169  return output;
170 
171 }

◆ ToSerial()

IssmDouble * PetscMat::ToSerial ( void  )

Definition at line 173 of file PetscMat.cpp.

173  {/*{{{*/
174 
175  IssmDouble* output=NULL;
176 
177  MatToSerial(&output,this->matrix,IssmComm::GetComm());
178  return output;
179 
180 }

◆ SetValues()

void PetscMat::SetValues ( int  m,
int *  idxm,
int  n,
int *  idxn,
IssmDouble values,
InsMode  mode 
)

Definition at line 182 of file PetscMat.cpp.

182  {/*{{{*/
183 
184  PetscErrorCode ierr = MatSetValues(this->matrix,m,idxm,n,idxn,values,ISSMToPetscInsertMode(mode));
185  if(ierr) _error_("PETSc's MatSetValues reported an error");
186 
187 }

◆ Convert()

void PetscMat::Convert ( MatrixType  type)

Definition at line 189 of file PetscMat.cpp.

189  {/*{{{*/
190 
191  MatConvert(this->matrix,ISSMToPetscMatrixType(type),MAT_REUSE_MATRIX,&this->matrix);
192 
193 }

◆ SetZero()

void PetscMat::SetZero ( void  )

Definition at line 195 of file PetscMat.cpp.

195  {/*{{{*/
196  MatZeroEntries(this->matrix);
197 }

Field Documentation

◆ matrix

Mat PetscMat::matrix

Definition at line 27 of file PetscMat.h.


The documentation for this class was generated from the following files:
NewMat
Mat NewMat(int M, int N, ISSM_MPI_Comm comm)
Definition: NewMat.cpp:21
_assert_
#define _assert_(ignore)
Definition: exceptions.h:37
IssmDouble
double IssmDouble
Definition: types.h:37
_printf0_
#define _printf0_(StreamArgs)
Definition: Print.h:29
IssmComm::GetComm
static ISSM_MPI_Comm GetComm(void)
Definition: IssmComm.cpp:30
ISSMToPetscMatrixType
MatType ISSMToPetscMatrixType(MatrixType type)
Definition: ISSMToPetscMatrixType.cpp:20
PetscVec::vector
Vec vector
Definition: PetscVec.h:25
ISSMToPetscNormMode
NormType ISSMToPetscNormMode(NormMode mode)
Definition: ISSMToPetscNormMode.cpp:20
MatMultPatch
void MatMultPatch(Mat A, Vec X, Vec AX, ISSM_MPI_Comm comm)
Definition: MatMultPatch.cpp:23
MatToSerial
void MatToSerial(double **poutmatrix, Mat matrix, ISSM_MPI_Comm comm)
Definition: MatToSerial.cpp:14
MatFree
void MatFree(Mat *pmat)
Definition: MatFree.cpp:16
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
ISSMToPetscInsertMode
InsertMode ISSMToPetscInsertMode(InsMode mode)
Definition: ISSMToPetscInsertMode.cpp:20
PetscMat::matrix
Mat matrix
Definition: PetscMat.h:27
PetscMat
Definition: PetscMat.h:24
PetscMat::PetscMat
PetscMat()
Definition: PetscMat.cpp:21