Changeset 13297
- Timestamp:
- 09/07/12 14:54:58 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/modules/Solverx/SolverxSeq.cpp
r13295 r13297 112 112 /*}}}*/ 113 113 114 int EDF_fov_forward_for_solverx(int n, IssmPDouble *inVal, int directionCount, IssmPDouble **inDeriv, int m, IssmPDouble *outVal, IssmPDouble **outDeriv) { /*{{{*/ 115 #ifdef _HAVE_GSL_ 116 // the matrix will be modified by LU decomposition. Use gsl_A copy 117 double* Acopy = xNew<double>(m*m); 118 xMemCpy(Acopy,inVal,m*m); 119 /*Initialize gsl matrices and vectors: */ 120 gsl_matrix_view gsl_A = gsl_matrix_view_array (Acopy,m,m); 121 gsl_vector_view gsl_b = gsl_vector_view_array (inVal+m*m,m); // the right hand side starts at address inVal+m*m 122 gsl_permutation *perm_p = gsl_permutation_alloc (m); 123 int signPerm; 124 // factorize 125 gsl_linalg_LU_decomp (&gsl_A.matrix, perm_p, &signPerm); 126 gsl_vector *gsl_x_p = gsl_vector_alloc (m); 127 // solve for the value 128 gsl_linalg_LU_solve (&gsl_A.matrix, perm_p, &gsl_b.vector, gsl_x_p); 129 /*Copy result*/ 130 xMemCpy(outVal,gsl_vector_ptr(gsl_x_p,0),m); 131 gsl_vector_free(gsl_x_p); 132 // solve for the derivatives acc. to A * dx = r with r=db - dA * x 133 double* r=xNew<double>(m); 134 gsl_vector *gsl_dx_p = gsl_vector_alloc(m); 135 for (int dir=0;dir<directionCount;++dir) { 136 // compute the RHS 137 for (int i=0; i<m; i++) { 138 r[i]=inDeriv[m*m+i][dir]; // this is db[i] 139 for (int j=0;j<m; j++) { 140 r[i]-=inDeriv[i*n+j][dir]*outVal[j]; // this is dA[i][j]*x[j] 141 } 142 } 143 gsl_vector_view gsl_r=gsl_vector_view_array(r,m); 144 gsl_linalg_LU_solve (&gsl_A.matrix, perm_p, &gsl_r.vector, gsl_dx_p); 145 // reuse r 146 xMemCpy(r,gsl_vector_ptr(gsl_dx_p,0),m); 147 for (int i=0; i<m; i++) { 148 outDeriv[i][dir]=r[i]; 149 } 150 } 151 gsl_vector_free(gsl_dx_p); 152 xDelete(r); 153 gsl_permutation_free(perm_p); 154 xDelete(Acopy); 155 #endif 156 return 0; 157 } 158 /*}}}*/ 159 114 160 void SolverxSeq(IssmDouble *X,IssmDouble *A,IssmDouble *B,int n, Parameters* parameters){/*{{{*/ 115 161 // pack inputs to conform to the EDF-prescribed interface
Note:
See TracChangeset
for help on using the changeset viewer.