Changeset 12417


Ignore:
Timestamp:
06/15/12 11:40:32 (13 years ago)
Author:
Mathieu Morlighem
Message:

Added simpler gsl slover

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  
    1919#ifdef _HAVE_PETSC_
    2020void    SolverxPetsc(Vec* puf, Mat Kff, Vec pf, Vec uf0,Vec df, Parameters* parameters);
    21 void    DofTypesToIndexSet(IS* pisv, IS* pisp, Vec df,int typeenum);
     21void  DofTypesToIndexSet(IS* pisv, IS* pisp, Vec df,int typeenum);
    2222#endif
    2323
    2424#ifdef _HAVE_GSL_
    25 void    SolverxGsl(SeqVec** puf,SeqMat* Kff, SeqVec* pf);
     25void SolverxGsl(SeqVec** puf,SeqMat* Kff, SeqVec* pf);
     26void SolverxGsl(double** pX,double* A,double* B,int n);
    2627#endif
    2728
  • issm/trunk-jpl/src/c/modules/Solverx/SolverxGsl.cpp

    r11760 r12417  
    1313#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
    1414#endif
    15  
    1615#include <gsl/gsl_linalg.h>
    1716
    18 void    SolverxGsl(SeqVec** puf,SeqMat* Kff, SeqVec* pf){
     17void SolverxGsl(SeqVec** puf,SeqMat* Kff, SeqVec* pf){/*{{{*/
    1918
    20         /*intermediary: */
    21         SeqMat* KffCopy=NULL;
    22 
    23         /*Output: */
    24         SeqVec*        uf               = NULL;
    25 
     19        /*Intermediaries*/
     20        SeqMat* KffCopy = NULL;
     21        SeqVec*  uf = NULL;
    2622       
    2723        /*GSL Matrices and vectors: */
     
    3329        /*We are going to do an in place LU decomp, so we need to save the matrix with its original structure: */
    3430        KffCopy=Kff->Duplicate();
    35 
    3631
    3732        /*Intermediary: */
     
    6358        gsl_permutation_free (p);
    6459        gsl_vector_free (x);
    65 
    6660        delete KffCopy;
    67 
    6861
    6962        /*Assign output pointers:*/
    7063        *puf=uf;
    71 }
     64}/*}}}*/
     65void 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.