Changeset 11743
- Timestamp:
- 03/20/12 09:51:05 (13 years ago)
- Location:
- issm/trunk-jpl/src/c
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/objects/Numerics/Matrix.cpp
r11734 r11743 26 26 Matrix::Matrix(){ 27 27 28 this->M=0;29 this->N=0;30 31 28 #ifdef _HAVE_PETSC_ 32 29 this->matrix=NULL; … … 40 37 /*}}}*/ 41 38 /*FUNCTION Matrix::Matrix(int M,int N){{{1*/ 42 Matrix::Matrix(int pM,int pN){ 43 44 this->M=pM; 45 this->N=pN; 46 47 #ifdef _HAVE_PETSC_ 48 this->matrix=NewMat(pM,pN); 49 #else 50 this->matrix=new SeqMat(pM,pN); 51 #endif 52 #ifdef _HAVE_ADOLC_ 53 this->amatrix=(adouble*)xmalloc(pM*pN*sizeof(adouble)); 39 Matrix::Matrix(int M,int N){ 40 41 #ifdef _HAVE_PETSC_ 42 this->matrix=NewMat(M,N); 43 #else 44 this->matrix=new SeqMat(M,N); 45 #endif 46 #ifdef _HAVE_ADOLC_ 47 this->amatrix=(adouble*)xmalloc(M*N*sizeof(adouble)); 54 48 #endif 55 49 } 56 50 /*}}}*/ 57 51 /*FUNCTION Matrix::Matrix(int M,int N,double sparsity){{{1*/ 58 Matrix::Matrix(int pM,int pN,double sparsity){ 59 60 this->M=pM; 61 this->N=pN; 62 63 #ifdef _HAVE_PETSC_ 64 this->matrix=NewMat(pM,pN,sparsity); 65 #else 66 this->matrix=new SeqMat(pM,pN,sparsity); 67 #endif 68 #ifdef _HAVE_ADOLC_ 69 this->amatrix=(adouble*)xmalloc(pM*pN*sizeof(adouble)); 52 Matrix::Matrix(int M,int N,double sparsity){ 53 54 #ifdef _HAVE_PETSC_ 55 this->matrix=NewMat(M,N,sparsity); 56 #else 57 this->matrix=new SeqMat(M,N,sparsity); 58 #endif 59 #ifdef _HAVE_ADOLC_ 60 this->amatrix=(adouble*)xmalloc(M*N*sizeof(adouble)); 70 61 #endif 71 62 } 72 63 /*}}}*/ 73 64 /*FUNCTION Matrix::Matrix(double* serial_mat, int M,int N,double sparsity){{{1*/ 74 Matrix::Matrix(double* serial_mat, int pM,int pN,double sparsity){ 75 76 this->M=pM; 77 this->N=pN; 65 Matrix::Matrix(double* serial_mat, int M,int N,double sparsity){ 78 66 79 67 #ifdef _HAVE_PETSC_ 80 68 int i; 81 int* idxm=NULL; 82 int* idxn=NULL; 83 84 this->matrix=NewMat(pM,pN,sparsity); 85 86 idxm=(int*)xmalloc(M*sizeof(int)); 87 idxn=(int*)xmalloc(N*sizeof(int)); 69 70 int* idxm=(int*)xmalloc(M*sizeof(int)); 71 int* idxn=(int*)xmalloc(N*sizeof(int)); 88 72 for(i=0;i<M;i++)idxm[i]=i; 89 73 for(i=0;i<N;i++)idxn[i]=i; 90 74 75 this->matrix=NewMat(M,N,sparsity); 91 76 MatSetValues(this->matrix,M,idxm,N,idxn,serial_mat,INSERT_VALUES); 92 93 77 MatAssemblyBegin(this->matrix,MAT_FINAL_ASSEMBLY); 94 78 MatAssemblyEnd(this->matrix,MAT_FINAL_ASSEMBLY); … … 97 81 xfree((void**)&idxn); 98 82 #else 99 this->matrix=new SeqMat(serial_mat, pM,pN,sparsity);100 #endif 101 #ifdef _HAVE_ADOLC_ 102 this->amatrix=(adouble*)xmalloc( pM*pN*sizeof(adouble));83 this->matrix=new SeqMat(serial_mat,M,N,sparsity); 84 #endif 85 #ifdef _HAVE_ADOLC_ 86 this->amatrix=(adouble*)xmalloc(M*N*sizeof(adouble)); 103 87 #endif 104 88 } 105 89 /*}}}*/ 106 90 /*FUNCTION Matrix::Matrix(int M,int N,int connectivity,int numberofdofspernode){{{1*/ 107 Matrix::Matrix(int pM,int pN,int connectivity,int numberofdofspernode){ 108 109 this->M=pM; 110 this->N=pN; 111 112 #ifdef _HAVE_PETSC_ 113 this->matrix=NewMat(pM,pN,connectivity,numberofdofspernode); 114 #else 115 this->matrix=new SeqMat(pM,pN,connectivity,numberofdofspernode); 116 #endif 117 #ifdef _HAVE_ADOLC_ 118 this->amatrix=(adouble*)xmalloc(pM*pN*sizeof(adouble)); 91 Matrix::Matrix(int M,int N,int connectivity,int numberofdofspernode){ 92 93 #ifdef _HAVE_PETSC_ 94 this->matrix=NewMat(M,N,connectivity,numberofdofspernode); 95 #else 96 this->matrix=new SeqMat(M,N,connectivity,numberofdofspernode); 97 #endif 98 #ifdef _HAVE_ADOLC_ 99 this->amatrix=(adouble*)xmalloc(M*N*sizeof(adouble)); 119 100 #endif 120 101 } … … 183 164 184 165 #ifdef _HAVE_PETSC_ 185 MatlabMatrixToPetscMatrix(&matrix->matrix, &matrix->M,&matrix->N,mxmatrix);166 MatlabMatrixToPetscMatrix(&matrix->matrix,NULL,NULL,mxmatrix); 186 167 #else 187 168 matrix->matrix=MatlabMatrixToSeqMat(mxmatrix); -
issm/trunk-jpl/src/c/objects/Numerics/Matrix.h
r11734 r11743 1 1 /*!\file: Matrix.h 2 * \brief wrapper to matrix objects. The goal is to control which API (PETS C,Scalpack, Plapack?)2 * \brief wrapper to matrix objects. The goal is to control which API (PETSc,Scalpack, Plapack?) 3 3 * implements our underlying matrix format. 4 4 */ … … 32 32 public: 33 33 34 int M,N;35 36 34 #ifdef _HAVE_PETSC_ 37 35 Mat matrix; -
issm/trunk-jpl/src/c/objects/Numerics/Vector.cpp
r11739 r11743 51 51 Vector::Vector(double* serial_vec,int M){ 52 52 53 int i,j; 54 55 #ifdef _HAVE_PETSC_ 56 int* idxm=NULL; 53 #ifdef _HAVE_PETSC_ 54 int* idxm=(int*)xmalloc(M*sizeof(int)); 55 for(int i=0;i<M;i++) idxm[i]=i; 57 56 58 57 this->vector=NewVec(M); 59 60 idxm=(int*)xmalloc(M*sizeof(int));61 for(i=0;i<M;i++)idxm[i]=i;62 58 VecSetValues(this->vector,M,idxm,serial_vec,INSERT_VALUES); 63 64 59 VecAssemblyBegin(this->vector); 65 60 VecAssemblyEnd(this->vector); 66 61 67 62 xfree((void**)&idxm); 68 69 63 #else 70 64 this->vector=new SeqVec(serial_vec,M); … … 112 106 113 107 #ifdef _HAVE_PETSC_ 114 if(!this->vector){ 115 printf("Vector size: 0\n"); 116 } 117 else VecView(this->vector,PETSC_VIEWER_STDOUT_WORLD); 108 _assert_(this->vector); 109 VecView(this->vector,PETSC_VIEWER_STDOUT_WORLD); 118 110 #else 119 111 this->vector->Echo(); … … 212 204 213 205 #ifdef _HAVE_PETSC_ 214 if(!this->vector)*pM=0;206 _assert_(this->vector); 215 207 else VecGetSize(this->vector,pM); 216 208 #else … … 218 210 #endif 219 211 212 } 213 /*}}}*/ 214 /*FUNCTION Vector::IsEmpty{{{1*/ 215 bool Vector::IsEmpty(void){ 216 217 int M; 218 this->GetSize(&M); 219 220 if(M==0) 221 return true; 222 else 223 return false; 220 224 } 221 225 /*}}}*/ … … 224 228 225 229 #ifdef _HAVE_PETSC_ 226 if(!this->vector)*pM=0;227 elseVecGetLocalSize(this->vector,pM);230 _assert_(this->vector); 231 VecGetLocalSize(this->vector,pM); 228 232 #else 229 233 this->vector->GetLocalSize(pM); … … 236 240 237 241 Vector* output=NULL; 238 output=new Vector();239 #ifdef _HAVE_PETSC_242 #ifdef _HAVE_PETSC_ 243 _assert_(this->vector); 240 244 Vec vec_output=NULL; 241 if(!this->vector){ 242 VecDuplicate(this->vector,&vec_output); 243 output->vector=vec_output; 244 } 245 #else 245 VecDuplicate(this->vector,&vec_output); 246 output=new Vector(vec_output); 247 #else 248 output=new Vector(); 246 249 output->vector=this->vector->Duplicate(); 247 250 #endif -
issm/trunk-jpl/src/c/objects/Numerics/Vector.h
r11734 r11743 1 1 /*!\file: Vector.h 2 * \brief wrapper to vector objects. The goal is to control which API (PETS C,Scalpack, Plapack?)2 * \brief wrapper to vector objects. The goal is to control which API (PETSc,Scalpack, Plapack?) 3 3 * implements our underlying vector format. 4 4 */ … … 32 32 33 33 #ifdef _HAVE_PETSC_ 34 Vec vector;34 Vec vector; 35 35 #else 36 SeqVec* vector;36 SeqVec* vector; 37 37 #endif 38 38 #ifdef _HAVE_ADOLC_ 39 adouble* avector;39 adouble* avector; 40 40 #endif 41 41 … … 54 54 mxArray* ToMatlabVector(void); 55 55 #endif 56 void Assemble(void); 57 void SetValues(int ssize, int* list, double* values, InsMode mode); 58 void SetValue(int dof, double value, InsMode mode); 59 void GetValue(double* pvalue, int dof); 60 void GetSize(int* pM); 61 void GetLocalSize(int* pM); 62 Vector* Duplicate(void); 63 void Set(double value); 64 void AXPY(Vector* X, double a); 65 void AYPX(Vector* X, double a); 66 double* ToMPISerial(void); 67 void Copy(Vector* to); 68 double Norm(NormMode norm_type); 69 void Scale(double scale_factor); 70 void PointwiseDivide(Vector* x,Vector* y); 71 double Dot(Vector* vector); 56 void AXPY(Vector *X, double a); 57 void AYPX(Vector *X, double a); 58 void Assemble(void); 59 void Copy(Vector *to); 60 double Dot(Vector *vector); 61 Vector *Duplicate(void); 62 void GetValue(double *pvalue, int dof); 63 void GetSize(int *pM); 64 void GetLocalSize(int *pM); 65 bool IsEmpty(void); 66 double Norm(NormMode norm_type); 67 void PointwiseDivide(Vector *x,Vector*y); 68 void Scale(double scale_factor); 69 void Set(double value); 70 void SetValues(int ssize, int *list, double*values, InsMode mode); 71 void SetValue(int dof, double value, InsMode mode); 72 double *ToMPISerial(void); 72 73 /*}}}*/ 73 74 }; -
issm/trunk-jpl/src/c/toolkits/petsc/patches/MatlabMatrixToPetscMatrix.cpp
r9320 r11743 116 116 /*Assign output pointer: */ 117 117 *pmatrix=matrix; 118 *pmatrix_rows=rows;119 *pmatrix_cols=cols;118 if(pmatrix_rows) *pmatrix_rows=rows; 119 if(pmatrix_cols) *pmatrix_cols=cols; 120 120 121 121 return 1; -
issm/trunk-jpl/src/c/toolkits/petsc/patches/MatlabVectorToPetscVector.cpp
r9320 r11743 94 94 VecAssemblyEnd(vector); 95 95 96 97 96 /*Assign output pointer: */ 98 97 *pvector=vector;
Note:
See TracChangeset
for help on using the changeset viewer.