Changeset 11734
- Timestamp:
- 03/19/12 20:11:39 (13 years ago)
- Location:
- issm/trunk-jpl/src/c/objects/Numerics
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/objects/Numerics/ElementMatrix.cpp
r11679 r11734 260 260 this->CheckConsistency(); 261 261 262 #ifdef _HAVE_PETSC_ 263 if(this->dofsymmetrical){ 264 /*only use row dofs to add values into global matrices: */ 265 266 if(this->row_fsize){ 267 /*first, retrieve values that are in the f-set from the g-set values matrix: */ 268 localvalues=(double*)xmalloc(this->row_fsize*this->row_fsize*sizeof(double)); 269 for(i=0;i<this->row_fsize;i++){ 270 for(j=0;j<this->row_fsize;j++){ 271 *(localvalues+this->row_fsize*i+j)=*(this->values+this->ncols*this->row_flocaldoflist[i]+this->row_flocaldoflist[j]); 272 } 262 if(this->dofsymmetrical){ 263 /*only use row dofs to add values into global matrices: */ 264 265 if(this->row_fsize){ 266 /*first, retrieve values that are in the f-set from the g-set values matrix: */ 267 localvalues=(double*)xmalloc(this->row_fsize*this->row_fsize*sizeof(double)); 268 for(i=0;i<this->row_fsize;i++){ 269 for(j=0;j<this->row_fsize;j++){ 270 *(localvalues+this->row_fsize*i+j)=*(this->values+this->ncols*this->row_flocaldoflist[i]+this->row_flocaldoflist[j]); 273 271 } 274 /*add local values into global matrix, using the fglobaldoflist: */275 MatSetValues(Kff->matrix,this->row_fsize,this->row_fglobaldoflist,this->row_fsize,this->row_fglobaldoflist,(const double*)localvalues,ADD_VALUES);276 277 /*Free ressources:*/ 278 xfree((void**)&localvalues);279 }280 281 282 if((this->row_ssize!=0) && (this->row_fsize!=0)){ 283 /*first, retrieve values that are in the f and s-set from the g-set values matrix: */284 localvalues=(double*)xmalloc(this->row_fsize*this->row_ssize*sizeof(double));285 for(i=0;i<this->row_fsize;i++){286 for(j=0;j<this->row_ssize;j++){287 *(localvalues+this->row_ssize*i+j)=*(this->values+this->ncols*this->row_flocaldoflist[i]+this->row_slocaldoflist[j]);288 }272 } 273 /*add local values into global matrix, using the fglobaldoflist: */ 274 Kff->SetValues(this->row_fsize,this->row_fglobaldoflist,this->row_fsize,this->row_fglobaldoflist,localvalues,ADD_VAL); 275 276 /*Free ressources:*/ 277 xfree((void**)&localvalues); 278 } 279 280 281 if((this->row_ssize!=0) && (this->row_fsize!=0)){ 282 /*first, retrieve values that are in the f and s-set from the g-set values matrix: */ 283 localvalues=(double*)xmalloc(this->row_fsize*this->row_ssize*sizeof(double)); 284 for(i=0;i<this->row_fsize;i++){ 285 for(j=0;j<this->row_ssize;j++){ 286 *(localvalues+this->row_ssize*i+j)=*(this->values+this->ncols*this->row_flocaldoflist[i]+this->row_slocaldoflist[j]); 289 287 } 290 /*add local values into global matrix, using the fglobaldoflist: */ 291 MatSetValues(Kfs->matrix,this->row_fsize,this->row_fglobaldoflist,this->row_ssize,this->row_sglobaldoflist,(const double*)localvalues,ADD_VALUES); 292 293 /*Free ressources:*/ 294 xfree((void**)&localvalues); 295 } 296 } 297 else{ 298 _error_(" non dofsymmetrical matrix AddToGlobal routine not support yet!"); 299 } 300 #else 301 _error_("not supported yet!"); 302 #endif 288 } 289 /*add local values into global matrix, using the fglobaldoflist: */ 290 Kfs->SetValues(this->row_fsize,this->row_fglobaldoflist,this->row_ssize,this->row_sglobaldoflist,localvalues,ADD_VAL); 291 292 /*Free ressources:*/ 293 xfree((void**)&localvalues); 294 } 295 } 296 else{ 297 _error_(" non dofsymmetrical matrix AddToGlobal routine not support yet!"); 298 } 303 299 304 300 } … … 316 312 this->CheckConsistency(); 317 313 318 #ifdef _HAVE_PETSC_ 319 if(this->dofsymmetrical){ 320 /*only use row dofs to add values into global matrices: */ 321 322 if(this->row_fsize){ 323 /*first, retrieve values that are in the f-set from the g-set values matrix: */ 324 localvalues=(double*)xmalloc(this->row_fsize*this->row_fsize*sizeof(double)); 325 for(i=0;i<this->row_fsize;i++){ 326 for(j=0;j<this->row_fsize;j++){ 327 *(localvalues+this->row_fsize*i+j)=*(this->values+this->ncols*this->row_flocaldoflist[i]+this->row_flocaldoflist[j]); 328 } 314 if(this->dofsymmetrical){ 315 /*only use row dofs to add values into global matrices: */ 316 317 if(this->row_fsize){ 318 /*first, retrieve values that are in the f-set from the g-set values matrix: */ 319 localvalues=(double*)xmalloc(this->row_fsize*this->row_fsize*sizeof(double)); 320 for(i=0;i<this->row_fsize;i++){ 321 for(j=0;j<this->row_fsize;j++){ 322 *(localvalues+this->row_fsize*i+j)=*(this->values+this->ncols*this->row_flocaldoflist[i]+this->row_flocaldoflist[j]); 329 323 } 330 /*add local values into global matrix, using the fglobaldoflist: */ 331 MatSetValues(Jff->matrix,this->row_fsize,this->row_fglobaldoflist,this->row_fsize,this->row_fglobaldoflist,(const double*)localvalues,ADD_VALUES); 332 333 /*Free ressources:*/ 334 xfree((void**)&localvalues); 335 } 336 337 } 338 else{ 339 _error_(" non dofsymmetrical matrix AddToGlobal routine not support yet!"); 340 } 341 #else 342 _error_("not supported yet!"); 343 #endif 324 } 325 /*add local values into global matrix, using the fglobaldoflist: */ 326 Jff->SetValues(this->row_fsize,this->row_fglobaldoflist,this->row_fsize,this->row_fglobaldoflist,localvalues,ADD_VAL); 327 328 /*Free ressources:*/ 329 xfree((void**)&localvalues); 330 } 331 332 } 333 else{ 334 _error_(" non dofsymmetrical matrix AddToGlobal routine not support yet!"); 335 } 344 336 345 337 } -
issm/trunk-jpl/src/c/objects/Numerics/ElementVector.cpp
r11679 r11734 166 166 double* localvalues=NULL; 167 167 168 #ifdef _HAVE_PETSC_ 169 if(this->fsize){ 170 /*first, retrieve values that are in the f-set from the g-set values vector: */ 171 localvalues=(double*)xmalloc(this->fsize*sizeof(double)); 172 for(i=0;i<this->fsize;i++){ 173 localvalues[i]=this->values[this->flocaldoflist[i]]; 174 } 175 /*add local values into global vector, using the fglobaldoflist: */ 176 VecSetValues(pf->vector,this->fsize,this->fglobaldoflist,(const double*)localvalues,ADD_VALUES); 177 178 /*Free ressources:*/ 179 xfree((void**)&localvalues); 180 } 181 #else 182 _error_("not supported yet!"); 183 #endif 168 if(this->fsize){ 169 /*first, retrieve values that are in the f-set from the g-set values vector: */ 170 localvalues=(double*)xmalloc(this->fsize*sizeof(double)); 171 for(i=0;i<this->fsize;i++){ 172 localvalues[i]=this->values[this->flocaldoflist[i]]; 173 } 174 /*add local values into global vector, using the fglobaldoflist: */ 175 pf->SetValues(this->fsize,this->fglobaldoflist,localvalues,ADD_VAL); 176 177 /*Free ressources:*/ 178 xfree((void**)&localvalues); 179 } 184 180 185 181 } … … 191 187 double* localvalues=NULL; 192 188 193 #ifdef _HAVE_PETSC_ 194 if(this->fsize){ 195 /*first, retrieve values that are in the f-set from the g-set values vector: */ 196 localvalues=(double*)xmalloc(this->fsize*sizeof(double)); 197 for(i=0;i<this->fsize;i++){ 198 localvalues[i]=this->values[this->flocaldoflist[i]]; 199 } 200 /*add local values into global vector, using the fglobaldoflist: */ 201 VecSetValues(pf->vector,this->fsize,this->fglobaldoflist,(const double*)localvalues,INSERT_VALUES); 202 203 /*Free ressources:*/ 204 xfree((void**)&localvalues); 205 } 206 #else 207 _error_("not supported yet!"); 208 #endif 189 if(this->fsize){ 190 /*first, retrieve values that are in the f-set from the g-set values vector: */ 191 localvalues=(double*)xmalloc(this->fsize*sizeof(double)); 192 for(i=0;i<this->fsize;i++){ 193 localvalues[i]=this->values[this->flocaldoflist[i]]; 194 } 195 /*add local values into global vector, using the fglobaldoflist: */ 196 pf->SetValues(this->fsize,this->fglobaldoflist,localvalues,INS_VAL); 197 198 /*Free ressources:*/ 199 xfree((void**)&localvalues); 200 } 209 201 210 202 } -
issm/trunk-jpl/src/c/objects/Numerics/Matrix.cpp
r11713 r11734 48 48 this->matrix=NewMat(pM,pN); 49 49 #else 50 this->matrix= (double*)xcalloc(pM*pN,sizeof(double));50 this->matrix=new SeqMat(pM,pN); 51 51 #endif 52 52 #ifdef _HAVE_ADOLC_ … … 64 64 this->matrix=NewMat(pM,pN,sparsity); 65 65 #else 66 this->matrix= (double*)xcalloc(pM*pN,sizeof(double));66 this->matrix=new SeqMat(pM,pN,sparsity); 67 67 #endif 68 68 #ifdef _HAVE_ADOLC_ … … 97 97 xfree((void**)&idxn); 98 98 #else 99 this->matrix= (double*)xcalloc(pM*pN,sizeof(double));99 this->matrix=new SeqMat(serial_mat,pM,pN,sparsity); 100 100 #endif 101 101 #ifdef _HAVE_ADOLC_ … … 113 113 this->matrix=NewMat(pM,pN,connectivity,numberofdofspernode); 114 114 #else 115 this->matrix= (double*)xcalloc(pM*pN,sizeof(double));115 this->matrix=new SeqMat(pM,pN,connectivity,numberofdofspernode); 116 116 #endif 117 117 #ifdef _HAVE_ADOLC_ … … 126 126 MatFree(&this->matrix); 127 127 #else 128 xfree((void**)&this->matrix);128 delete this->matrix; 129 129 #endif 130 130 #ifdef _HAVE_ADOLC_ … … 143 143 MatView(this->matrix,PETSC_VIEWER_STDOUT_WORLD); 144 144 #else 145 printf("Matrix size: %i-%i\n",M,N); 146 for(i=0;i<M;i++){ 147 for(j=0;j<N;j++){ 148 printf("%g ",*(matrix+N*i+j)); 149 } 150 printf("\n"); 151 } 145 this->matrix->Echo(); 152 146 #endif 153 147 … … 173 167 PetscMatrixToMatlabMatrix(&dataref,this->matrix); 174 168 #else 175 _error_("not implemented yet!");169 dataref=this->matrix->ToMatlabMatrix(); 176 170 #endif 177 171 return dataref; 178 172 173 } 174 /*}}}*/ 175 /*FUNCTION MatlabMatrixToMatrix{{{1*/ 176 Matrix* MatlabMatrixToMatrix(const mxArray* mxmatrix){ 177 178 int dummy; 179 Matrix* matrix=NULL; 180 181 /*allocate matrix object: */ 182 matrix=new Matrix(); 183 184 #ifdef _HAVE_PETSC_ 185 MatlabMatrixToPetscMatrix(&matrix->matrix,&matrix->M,&matrix->N,mxmatrix); 186 #else 187 matrix->matrix=MatlabMatrixToSeqMat(mxmatrix); 188 #endif 189 190 return matrix; 179 191 } 180 192 /*}}}*/ … … 190 202 #endif 191 203 #else 192 /*do nothing:*/204 this->matrix->Assemble(); 193 205 #endif 194 206 … … 203 215 MatNorm(this->matrix,ISSMToPetscNormMode(norm_type),&norm); 204 216 #else 205 _error_("not implemented yet!");217 norm=this->matrix->Norm(norm_type); 206 218 #endif 207 219 return norm; … … 215 227 MatGetSize(this->matrix,pM,pN); 216 228 #else 217 _error_("not implemented yet!");229 this->matrix->GetSize(pM,pN); 218 230 #endif 219 231 } … … 226 238 MatGetLocalSize(this->matrix,pM,pN); 227 239 #else 228 _error_("not implemented yet!");240 this->matrix->GetLocalSize(pM,pN); 229 241 #endif 230 242 } … … 238 250 MatMultPatch(this->matrix,X->vector,AX->vector); 239 251 #else 240 _error_("not implemented yet!");252 this->matrix->MatMult(X->vector,AX->vector); 241 253 #endif 242 254 } … … 249 261 output=new Matrix(); 250 262 251 #ifdef _HAVE_PETSC 263 #ifdef _HAVE_PETSC_ 252 264 _assert_(this->matrix); 253 265 MatDuplicate(this->matrix,MAT_COPY_VALUES,&output->matrix); 254 266 #else 255 _error_("not implemented yet!");267 output->matrix=this->matrix->Duplicate(); 256 268 #endif 257 269 } … … 262 274 double* output=NULL; 263 275 264 #ifdef _HAVE_PETSC 276 #ifdef _HAVE_PETSC_ 265 277 MatToSerial(&output,this->matrix); 266 278 #else 267 _error_("not implemented yet!");279 output=this->matrix->ToSerial(); 268 280 #endif 269 281 return output; 270 282 } 271 283 /*}}}*/ 284 /*FUNCTION Matrix::SetValues{{{1*/ 285 void Matrix::SetValues(int m,int* idxm,int n,int* idxn,double* values,InsMode mode){ 286 287 #ifdef _HAVE_PETSC_ 288 MatSetValues(this->matrix,m,idxm,n,idxn,values,ISSMToPetscInsertMode(mode)); 289 #else 290 this->matrix->SetValues(m,idxm,n,idxn,values,mode); 291 #endif 292 } 293 /*}}}*/ -
issm/trunk-jpl/src/c/objects/Numerics/Matrix.h
r11695 r11734 37 37 Mat matrix; 38 38 #else 39 double* matrix;39 SeqMat* matrix; 40 40 #endif 41 41 #ifdef _HAVE_ADOLC_ … … 63 63 Matrix* Duplicate(void); 64 64 double* ToSerial(void); 65 void SetValues(int m,int* idxm,int n,int* idxn,double* values,InsMode mode); 65 66 /*}}}*/ 66 67 67 68 }; 69 /*API: */ 70 #ifdef _SERIAL_ 71 Matrix* MatlabMatrixToMatrix(const mxArray* mxmatrix); 72 #endif 73 68 74 #endif //#ifndef _MATRIX_H_ -
issm/trunk-jpl/src/c/objects/Numerics/Vector.cpp
r11713 r11734 25 25 Vector::Vector(){ 26 26 27 this->M=0;28 27 #ifdef _HAVE_PETSC_ 29 28 this->vector=NULL; … … 42 41 this->vector=NewVec(pM,fromlocalsize); 43 42 #else 44 this->M=pM; 45 this->vector=(double*)xcalloc(pM,sizeof(double)); 43 this->vector=new SeqVec(pM,fromlocalsize); 46 44 #endif 47 45 #ifdef _HAVE_ADOLC_ … … 51 49 /*}}}*/ 52 50 /*FUNCTION Vector::Vector(double* serial_vec,int M){{{1*/ 53 Vector::Vector(double* serial_vec,int pM){51 Vector::Vector(double* serial_vec,int M){ 54 52 55 53 int i,j; … … 58 56 int* idxm=NULL; 59 57 60 this->vector=NewVec( pM);58 this->vector=NewVec(M); 61 59 62 60 idxm=(int*)xmalloc(M*sizeof(int)); … … 70 68 71 69 #else 72 this->M=pM; 73 this->vector=(double*)xcalloc(pM,sizeof(double)); 74 #endif 75 #ifdef _HAVE_ADOLC_ 76 this->avector=(adouble*)xmalloc(pM*sizeof(adouble)); 70 this->vector=new SeqVec(serial_vec,M); 71 #endif 72 #ifdef _HAVE_ADOLC_ 73 this->avector=(adouble*)xmalloc(M*sizeof(adouble)); 77 74 #endif 78 75 } … … 82 79 Vector::Vector(Vec petsc_vec){ 83 80 84 /*Get Vector size*/85 VecGetSize(petsc_vec,&this->M);86 87 81 /*copy vector*/ 88 82 VecDuplicate(petsc_vec,&this->vector); … … 98 92 VecFree(&this->vector); 99 93 #else 100 xfree((void**)&this->vector);94 delete this->vector; 101 95 #endif 102 96 #ifdef _HAVE_ADOLC_ … … 115 109 VecView(this->vector,PETSC_VIEWER_STDOUT_WORLD); 116 110 #else 117 printf("Vector size: %i\n",M); 118 for(i=0;i<M;i++){ 119 printf("%g\n ",*(vector+i)); 120 } 121 #endif 122 123 #ifdef _HAVE_ADOLC_ 124 /*Not sure about that one. Should we use the overloaded operator >>?*/ 125 printf("ADOLC Vector equivalent:" ); 126 for(i=0;i<M;i++){ 127 printf("%g\n ",*(avector+i)); 128 } 111 this->vector->Echo(); 112 #endif 113 114 #ifdef _HAVE_ADOLC_ 115 /*do nothing for now: */ 129 116 #endif 130 117 } … … 139 126 PetscVectorToMatlabVector(&dataref,this->vector); 140 127 #else 141 _error_("not implemented yet!");128 dataref=this->vector->ToMatlabVector(); 142 129 #endif 143 130 return dataref; 144 131 132 } 133 /*}}}*/ 134 /*FUNCTION MatlabVectorToVector{{{1*/ 135 Vector* MatlabVectorToVector(const mxArray* mxvector){ 136 137 int dummy; 138 Vector* vector=NULL; 139 140 /*allocate vector object: */ 141 vector=new Vector(); 142 143 #ifdef _HAVE_PETSC_ 144 MatlabVectorToPetscVector(&vector->vector,&dummy,mxvector); 145 #else 146 vector->vector=MatlabVectorToSeqVec(mxvector); 147 #endif 148 149 return vector; 145 150 } 146 151 /*}}}*/ … … 154 159 VecAssemblyEnd(this->vector); 155 160 #else 156 /*do nothing*/161 this->vector->Assemble(); 157 162 #endif 158 163 … … 167 172 VecSetValues(this->vector,ssize,list,values,ISSMToPetscInsertMode(mode)); 168 173 #else 169 _error_("not implemented yet!");174 this->vector->SetValues(ssize,list,values,mode); 170 175 #endif 171 176 … … 179 184 VecSetValues(this->vector,1,&dof,&value,ISSMToPetscInsertMode(mode)); 180 185 #else 181 _error_("not implemented yet!");186 this->vector->SetValue(dof,value,mode); 182 187 #endif 183 188 … … 191 196 VecGetValues(this->vector,1,&dof,pvalue); 192 197 #else 193 _error_("not implemented yet!");198 this->vector->GetValue(pvalue,dof); 194 199 #endif 195 200 } … … 202 207 VecGetSize(this->vector,pM); 203 208 #else 204 _error_("not implemented yet!");209 this->vector->GetSize(pM); 205 210 #endif 206 211 … … 214 219 VecGetLocalSize(this->vector,pM); 215 220 #else 216 _error_("not implemented yet!");221 this->vector->GetLocalSize(pM); 217 222 #endif 218 223 … … 229 234 VecDuplicate(this->vector,&vec_output); 230 235 output->vector=vec_output; 231 VecGetSize(output->vector,&output->M); 232 #else 233 _error_("not implemented yet!"); 236 #else 237 output->vector=this->vector->Duplicate(); 234 238 #endif 235 239 return output; … … 244 248 VecSet(this->vector,value); 245 249 #else 246 _error_("not implemented yet!");250 this->vector->Set(value); 247 251 #endif 248 252 … … 256 260 VecAXPY(this->vector,a,X->vector); 257 261 #else 258 _error_("not implemented yet!");262 this->vector->AXPY(X->vector,a); 259 263 #endif 260 264 } … … 267 271 VecAYPX(this->vector,a,X->vector); 268 272 #else 269 _error_("not implemented yet!");273 this->vector->AYPX(X->vector,a); 270 274 #endif 271 275 … … 280 284 VecToMPISerial(&vec_serial, this->vector); 281 285 #else 282 _error_("not implemented yet!");286 vec_serial=this->vector->ToMPISerial(); 283 287 #endif 284 288 … … 293 297 VecCopy(this->vector,to->vector); 294 298 #else 295 _error_("not implemented yet!");299 this->vector->Copy(to->vector); 296 300 #endif 297 301 … … 306 310 VecNorm(this->vector,ISSMToPetscNormMode(norm_type),&norm); 307 311 #else 308 _error_("not implemented yet!");312 norm=this->vector->Norm(norm_type); 309 313 #endif 310 314 return norm; … … 318 322 VecScale(this->vector,scale_factor); 319 323 #else 320 _error_("not implemented yet!");324 this->vector->Scale(scale_factor); 321 325 #endif 322 326 } … … 330 334 VecDot(this->vector,vector->vector,&dot); 331 335 #else 332 _error_("not implemented yet!");336 dot=this->vector->Dot(vector->vector); 333 337 #endif 334 338 return dot; … … 342 346 VecPointwiseDivide(this->vector,x->vector,y->vector); 343 347 #else 344 _error_("not implemented yet!");345 #endif 346 } 347 /*}}}*/ 348 this->vector->PointwiseDivide(x->vector,y->vector); 349 #endif 350 } 351 /*}}}*/ -
issm/trunk-jpl/src/c/objects/Numerics/Vector.h
r11704 r11734 31 31 public: 32 32 33 int M;34 35 33 #ifdef _HAVE_PETSC_ 36 34 Vec vector; 37 35 #else 38 double* vector;36 SeqVec* vector; 39 37 #endif 40 38 #ifdef _HAVE_ADOLC_ … … 74 72 /*}}}*/ 75 73 }; 74 75 /*API: */ 76 #ifdef _SERIAL_ 77 Vector* MatlabVectorToVector(const mxArray* mxvector); 78 #endif 79 76 80 #endif //#ifndef _VECTOR_H_
Note:
See TracChangeset
for help on using the changeset viewer.