Ignore:
Timestamp:
02/20/14 20:14:39 (12 years ago)
Author:
Mathieu Morlighem
Message:

NEW: added GslTriple solve to have a faster solution of Kriging

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/toolkits/gsl/DenseGslSolve.cpp

    r15070 r17328  
    3232}
    3333/*}}}*/
    34 void DenseGslSolve(/*output*/ IssmPDouble** px,/*stiffness matrix:*/ IssmPDouble* Kff, int Kff_M, int Kff_N, /*right hand side load vector: */ IssmPDouble* pf, int pf_M, Parameters* parameters){ /*{{{*/
     34void DenseGslSolve(IssmPDouble** px,IssmPDouble* Kff,int Kff_M,int Kff_N,IssmPDouble* pf,int pf_M,Parameters* parameters){ /*{{{*/
    3535
    3636        /*Intermediary: */
     
    4444        /*allocate output pointers: */
    4545        *px=x;
     46}
     47/*}}}*/
     48void DenseGslTripleSolve(IssmPDouble** pX1,IssmPDouble** pX2,IssmPDouble** pX3,IssmPDouble* A,IssmPDouble* B1,IssmPDouble* B2,IssmPDouble* B3,int n){/*{{{*/
     49
     50        /*Allocate output: */
     51        IssmPDouble *X1 = xNew<IssmPDouble>(n);
     52        IssmPDouble *X2 = xNew<IssmPDouble>(n);
     53        IssmPDouble *X3 = xNew<IssmPDouble>(n);
     54
     55#ifdef _HAVE_GSL_
     56        /*GSL Matrices and vectors: */
     57        int s;
     58
     59        double* Acopy = xNew<double>(n*n);
     60        xMemCpy(Acopy,A,n*n);
     61
     62        /*Initialize gsl matrices and vectors: */
     63        gsl_matrix_view a = gsl_matrix_view_array(Acopy,n,n);
     64        gsl_vector_view b1= gsl_vector_view_array(B1,n);
     65        gsl_vector_view b2= gsl_vector_view_array(B2,n);
     66        gsl_vector_view b3= gsl_vector_view_array(B3,n);
     67        gsl_vector_view x1= gsl_vector_view_array(X1,n);
     68        gsl_vector_view x2= gsl_vector_view_array(X2,n);
     69        gsl_vector_view x3= gsl_vector_view_array(X3,n);
     70
     71        /*Run LU and solve: */
     72        gsl_permutation* p = gsl_permutation_alloc (n);
     73        gsl_linalg_LU_decomp(&a.matrix,p,&s);
     74
     75        gsl_linalg_LU_solve(&a.matrix,p,&b1.vector,&x1.vector);
     76        gsl_linalg_LU_solve(&a.matrix,p,&b2.vector,&x2.vector);
     77        gsl_linalg_LU_solve(&a.matrix,p,&b3.vector,&x3.vector);
     78
     79        /*Clean up and assign output pointer*/
     80        xDelete(Acopy);
     81        gsl_permutation_free(p);
     82#endif
     83
     84        /*allocate output pointers: */
     85        *pX1=X1;
     86        *pX2=X2;
     87        *pX3=X3;
    4688}
    4789/*}}}*/
Note: See TracChangeset for help on using the changeset viewer.