Changeset 12417
- Timestamp:
- 06/15/12 11:40:32 (13 years ago)
- Location:
- issm/trunk-jpl/src/c/modules/Solverx
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/modules/Solverx/Solverx.h
r11726 r12417 19 19 #ifdef _HAVE_PETSC_ 20 20 void SolverxPetsc(Vec* puf, Mat Kff, Vec pf, Vec uf0,Vec df, Parameters* parameters); 21 void 21 void DofTypesToIndexSet(IS* pisv, IS* pisp, Vec df,int typeenum); 22 22 #endif 23 23 24 24 #ifdef _HAVE_GSL_ 25 void SolverxGsl(SeqVec** puf,SeqMat* Kff, SeqVec* pf); 25 void SolverxGsl(SeqVec** puf,SeqMat* Kff, SeqVec* pf); 26 void SolverxGsl(double** pX,double* A,double* B,int n); 26 27 #endif 27 28 -
issm/trunk-jpl/src/c/modules/Solverx/SolverxGsl.cpp
r11760 r12417 13 13 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 14 14 #endif 15 16 15 #include <gsl/gsl_linalg.h> 17 16 18 void SolverxGsl(SeqVec** puf,SeqMat* Kff, SeqVec* pf){17 void SolverxGsl(SeqVec** puf,SeqMat* Kff, SeqVec* pf){/*{{{*/ 19 18 20 /*intermediary: */ 21 SeqMat* KffCopy=NULL; 22 23 /*Output: */ 24 SeqVec* uf = NULL; 25 19 /*Intermediaries*/ 20 SeqMat* KffCopy = NULL; 21 SeqVec* uf = NULL; 26 22 27 23 /*GSL Matrices and vectors: */ … … 33 29 /*We are going to do an in place LU decomp, so we need to save the matrix with its original structure: */ 34 30 KffCopy=Kff->Duplicate(); 35 36 31 37 32 /*Intermediary: */ … … 63 58 gsl_permutation_free (p); 64 59 gsl_vector_free (x); 65 66 60 delete KffCopy; 67 68 61 69 62 /*Assign output pointers:*/ 70 63 *puf=uf; 71 } 64 }/*}}}*/ 65 void SolverxGsl(double** pX,double* A,double* B,int n){/*{{{*/ 66 67 /*GSL Matrices and vectors: */ 68 int s; 69 gsl_matrix_view a; 70 gsl_vector_view b; 71 gsl_vector *x = NULL; 72 gsl_permutation *p = NULL; 73 74 /*A will be modified by LU decomposition. Use copy*/ 75 double* Acopy = (double*)xmalloc(n*n*sizeof(double)); 76 memcpy(Acopy,A,n*n*sizeof(double)); 77 78 /*Initialize gsl matrices and vectors: */ 79 a = gsl_matrix_view_array (Acopy,n,n); 80 b = gsl_vector_view_array (B,n); 81 x = gsl_vector_alloc (n); 82 83 /*Run LU and solve: */ 84 p = gsl_permutation_alloc (n); 85 gsl_linalg_LU_decomp (&a.matrix, p, &s); 86 gsl_linalg_LU_solve (&a.matrix, p, &b.vector, x); 87 88 //printf ("x = \n"); 89 //gsl_vector_fprintf (stdout, x, "%g"); 90 91 /*Copy result*/ 92 double* X = (double*)xmalloc(n*sizeof(double)); 93 memcpy(X,gsl_vector_ptr(x,0),n*sizeof(double)); 94 95 /*Clean up and assign output pointer*/ 96 xfree((void**)&Acopy); 97 gsl_permutation_free(p); 98 gsl_vector_free(x); 99 *pX=X; 100 }/*}}}*/
Note:
See TracChangeset
for help on using the changeset viewer.