Ice Sheet System Model  4.18
Code documentation
IssmMat.h
Go to the documentation of this file.
1 
5 #ifndef _ISSM_MAT_H_
6 #define _ISSM_MAT_H_
7 
8 /*Headers:*/
9 /*{{{*/
10 #ifdef HAVE_CONFIG_H
11  #include <config.h>
12 #else
13 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
14 #endif
15 
16 #include "../../shared/shared.h"
17 #include "../ToolkitOptions.h"
18 #include "./IssmToolkitUtils.h"
19 #include "../mumps/mumpsincludes.h"
20 /*}}}*/
21 
22 /*We need to template this class, in case we want to create Matrices that hold
23  IssmDouble* matrix or IssmPDouble* matrix.
24  Such matrices are useful for use without or with the matlab or python
25  interface (which do not care for IssmDouble types, but only rely on
26  IssmPDouble types)
27 */
28 template <class doubletype> class IssmVec;
29 template <class doubletype> class IssmDenseMat;
30 template <class doubletype> class IssmMpiDenseMat;
31 template <class doubletype> class IssmMpiSparseMat;
32 class Parameters;
33 
34 template <class doubletype>
35 class IssmMat{
36 
37  public:
38 
39  IssmAbsMat<doubletype>* matrix; /*abstract matrix, which implements object orientation*/
40 
41  /*IssmMat constructors, destructors*/
42  IssmMat(){ /*{{{*/
43 
45 
46  case DenseEnum:
47  this->matrix=new IssmDenseMat<doubletype>();
48  break;
49  case MpiDenseEnum:
50  #ifdef _HAVE_MPI_
51  this->matrix=new IssmMpiDenseMat<doubletype>();
52  #else
53  _error_("MpiDense matrix requires compilation of MPI!");
54  #endif
55  break;
56  case MpiSparseEnum:
57  #ifdef _HAVE_MPI_
58  this->matrix=new IssmMpiSparseMat<doubletype>();
59  #else
60  _error_("MpiSparse matrix requires compilation of MPI!");
61  #endif
62  break;
63  default:
64  _error_("matrix type not supported yet!");
65  }
66  }
67  /*}}}*/
68  IssmMat(int M,int N){ /*{{{*/
69 
71 
72  case DenseEnum:
73  this->matrix=new IssmDenseMat<doubletype>(M,N);
74  break;
75  case MpiDenseEnum:
76  #ifdef _HAVE_MPI_
77  this->matrix=new IssmMpiDenseMat<doubletype>(M,N);
78  #else
79  _error_("MpiDense matrix requires compilation of MPI!");
80  #endif
81  break;
82  case MpiSparseEnum:
83  #ifdef _HAVE_MPI_
84  this->matrix=new IssmMpiSparseMat<doubletype>(M,N);
85  #else
86  _error_("MpiSparse matrix requires compilation of MPI!");
87  #endif
88  break;
89  default:
90  _error_("matrix type not supported yet!");
91  }
92  }
93  /*}}}*/
94  IssmMat(int M,int N, doubletype sparsity){ /*{{{*/
95 
97 
98  case DenseEnum:
99  this->matrix=new IssmDenseMat<doubletype>(M,N,sparsity);
100  break;
101  case MpiDenseEnum:
102  #ifdef _HAVE_MPI_
103  this->matrix=new IssmMpiDenseMat<doubletype>(M,N,sparsity);
104  #else
105  _error_("MpiDense matrix requires compilation of MPI!");
106  #endif
107  break;
108  case MpiSparseEnum:
109  #ifdef _HAVE_MPI_
110  this->matrix=new IssmMpiSparseMat<doubletype>(M,N,sparsity);
111  #else
112  _error_("MpiSparse matrix requires compilation of MPI!");
113  #endif
114  break;
115  default:
116  _error_("matrix type not supported yet!");
117  }
118  }
119  /*}}}*/
120  IssmMat(int m,int n,int M,int N,int* d_nnz,int* o_nnz){ /*{{{*/
121 
123 
124  case DenseEnum:
125  this->matrix=new IssmDenseMat<doubletype>(m,n,M,N,d_nnz,o_nnz);
126  break;
127  case MpiDenseEnum:
128  #ifdef _HAVE_MPI_
129  this->matrix=new IssmMpiDenseMat<doubletype>(m,n,M,N,d_nnz,o_nnz);
130  #else
131  _error_("MpiDense matrix requires compilation of MPI!");
132  #endif
133  break;
134  case MpiSparseEnum:
135  #ifdef _HAVE_MPI_
136  this->matrix=new IssmMpiSparseMat<doubletype>(m,n,M,N,d_nnz,o_nnz);
137  #else
138  _error_("MpiSparse matrix requires compilation of MPI!");
139  #endif
140  break;
141  default:
142  _error_("matrix type not supported yet!");
143  }
144  }
145  /*}}}*/
146  IssmMat(doubletype* serial_mat,int M,int N,doubletype sparsity){ /*{{{*/
147 
149 
150  case DenseEnum:
151  this->matrix=new IssmDenseMat<doubletype>(serial_mat,M,N,sparsity);
152  break;
153  case MpiDenseEnum:
154  #ifdef _HAVE_MPI_
155  this->matrix=new IssmMpiDenseMat<doubletype>(serial_mat,M,N,sparsity);
156  #else
157  _error_("MpiDense matrix requires compilation of MPI!");
158  #endif
159  break;
160  case MpiSparseEnum:
161  #ifdef _HAVE_MPI_
162  this->matrix=new IssmMpiSparseMat<doubletype>(serial_mat,M,N,sparsity);
163  #else
164  _error_("MpiSparse matrix requires compilation of MPI!");
165  #endif
166  break;
167  default:
168  _error_("matrix type not supported yet!");
169  }
170 
171  }
172  /*}}}*/
173  IssmMat(int M,int N, int connectivity, int numberofdofspernode){ /*{{{*/
174 
176 
177  case DenseEnum:
178  this->matrix=new IssmDenseMat<doubletype>(M,N,connectivity,numberofdofspernode);
179  break;
180  case MpiDenseEnum:
181  #ifdef _HAVE_MPI_
182  this->matrix=new IssmMpiDenseMat<doubletype>(M,N,connectivity,numberofdofspernode);
183  #else
184  _error_("MpiDense matrix requires compilation of MPI!");
185  #endif
186  break;
187  case MpiSparseEnum:
188  #ifdef _HAVE_MPI_
189  this->matrix=new IssmMpiSparseMat<doubletype>(M,N,connectivity,numberofdofspernode);
190  #else
191  _error_("MpiSparse matrix requires compilation of MPI!");
192  #endif
193  break;
194  default:
195  _error_("matrix type not supported yet!");
196  }
197  }
198  /*}}}*/
199  ~IssmMat(){ /*{{{*/
200  delete matrix;
201  } /*}}}*/
202 
203  /*Functionality: */
204  void Echo(void){ /*{{{*/
205  matrix->Echo();
206  } /*}}}*/
207  void Assemble(void){ /*{{{*/
208  matrix->Assemble();
209  } /*}}}*/
210  doubletype Norm(NormMode mode){ /*{{{*/
211  return matrix->Norm(mode);
212  }
213  /*}}}*/
214  void GetSize(int* pM,int* pN){ /*{{{*/
215  matrix->GetSize(pM,pN);
216  } /*}}}*/
217  void GetLocalSize(int* pM,int* pN){ /*{{{*/
218  matrix->GetLocalSize(pM,pN);
219  } /*}}}*/
221  matrix->MatMult(X->vector,AX->vector);
222  } /*}}}*/
224 
225  IssmMat<doubletype>* issmmatrix=NULL;
226 
227  issmmatrix=new IssmMat<doubletype>();
228  issmmatrix->matrix=this->matrix->Duplicate();
229 
230  return issmmatrix;
231  } /*}}}*/
232  doubletype* ToSerial(void){/*{{{*/
233  return matrix->ToSerial();
234  }/*}}}*/
235  void SetValues(int m,int* idxm,int n,int* idxn,doubletype* values,InsMode mode){/*{{{*/
236  matrix->SetValues(m,idxm,n,idxn,values,mode);
237  }/*}}}*/
238  void Convert(MatrixType type){/*{{{*/
239  matrix->convert(type);
240  }/*}}}*/
241  void SetZero(void){/*{{{*/
242  matrix->SetZero();
243  }/*}}}*/
244  #ifndef _HAVE_WRAPPERS_
246 
247  IssmVec<doubletype>* outvector=NULL;
248 
249  outvector=new IssmVec<doubletype>();
250 
251  outvector->vector=this->matrix->Solve(pf->vector,parameters);
252 
253  return outvector;
254 
255  }/*}}}*/
256  #endif
257 };
258 
259 #endif //#ifndef _ISSMMAT_H_
IssmMat::IssmMat
IssmMat(int m, int n, int M, int N, int *d_nnz, int *o_nnz)
Definition: IssmMat.h:120
IssmToolkitUtils.h
routines used throughout the ISSM toolkit
IssmMat::SetZero
void SetZero(void)
Definition: IssmMat.h:241
IssmMatTypeFromToolkitOptions
int IssmMatTypeFromToolkitOptions(void)
Definition: IssmToolkitUtils.cpp:23
IssmMat::IssmMat
IssmMat(doubletype *serial_mat, int M, int N, doubletype sparsity)
Definition: IssmMat.h:146
Parameters
Declaration of Parameters class.
Definition: Parameters.h:18
IssmDenseMat
Definition: IssmDenseMat.h:39
IssmMat::Norm
doubletype Norm(NormMode mode)
Definition: IssmMat.h:210
DenseEnum
@ DenseEnum
Definition: EnumDefinitions.h:1034
IssmMat::Assemble
void Assemble(void)
Definition: IssmMat.h:207
IssmMat
Definition: IssmMat.h:35
IssmMat::SetValues
void SetValues(int m, int *idxm, int n, int *idxn, doubletype *values, InsMode mode)
Definition: IssmMat.h:235
IssmAbsMat::Solve
virtual IssmAbsVec< IssmDouble > * Solve(IssmAbsVec< IssmDouble > *pf, Parameters *parameters)=0
IssmAbsMat
Definition: IssmAbsMat.h:27
IssmMat::Duplicate
IssmMat< doubletype > * Duplicate(void)
Definition: IssmMat.h:223
IssmMat::~IssmMat
~IssmMat()
Definition: IssmMat.h:199
MatrixType
MatrixType
Definition: toolkitsenums.h:16
IssmMat::IssmMat
IssmMat(int M, int N, int connectivity, int numberofdofspernode)
Definition: IssmMat.h:173
IssmMat::Solve
IssmVec< doubletype > * Solve(IssmVec< doubletype > *pf, Parameters *parameters)
Definition: IssmMat.h:245
IssmMat::matrix
IssmAbsMat< doubletype > * matrix
Definition: IssmMat.h:39
IssmVec
Definition: IssmVec.h:34
IssmVec::vector
IssmAbsVec< doubletype > * vector
Definition: IssmVec.h:38
IssmMat::ToSerial
doubletype * ToSerial(void)
Definition: IssmMat.h:232
IssmAbsMat::Duplicate
virtual IssmAbsMat< doubletype > * Duplicate(void)=0
IssmMat::IssmMat
IssmMat(int M, int N, doubletype sparsity)
Definition: IssmMat.h:94
IssmMpiDenseMat
Definition: IssmMpiDenseMat.h:37
MpiSparseEnum
@ MpiSparseEnum
Definition: EnumDefinitions.h:1194
NormMode
NormMode
Definition: toolkitsenums.h:15
IssmMat::IssmMat
IssmMat(int M, int N)
Definition: IssmMat.h:68
IssmMat::IssmMat
IssmMat()
Definition: IssmMat.h:42
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
IssmMat::MatMult
void MatMult(IssmVec< doubletype > *X, IssmVec< doubletype > *AX)
Definition: IssmMat.h:220
IssmMpiSparseMat
Definition: IssmMpiSparseMat.h:37
IssmMat::Convert
void Convert(MatrixType type)
Definition: IssmMat.h:238
IssmMat::GetSize
void GetSize(int *pM, int *pN)
Definition: IssmMat.h:214
IssmMat::Echo
void Echo(void)
Definition: IssmMat.h:204
InsMode
InsMode
Definition: toolkitsenums.h:14
MpiDenseEnum
@ MpiDenseEnum
Definition: EnumDefinitions.h:1192
IssmMat::GetLocalSize
void GetLocalSize(int *pM, int *pN)
Definition: IssmMat.h:217