
/* ===purpose=== */

/**********************************************************************************************************************************/
/***********************************************  Preconditioned Iterative Solver  ************************************************/
/*****************************  Definitions of wide range variables, arrays, functions and parameters  ****************************/
/**********************************************************************************************************************************/

/* Developer: Sylvain Nintcheu Fata */
/* Version:   V.1.1                 */
/* Released:  Jun 14, 2012          */


#ifndef _BEM_PCOND_IT_SOLV_H_
#define _BEM_PCOND_IT_SOLV_H_

#include <stdbool.h>


/* Iterative Solver
 *----ldim-----= Dimension of the iterative solver BiCGSTAB(ldim)
 *---mxmatvec--= Maximum number of matrix-vector mutiplications in the iterative solver BiCGSTAB(ldim)
 *---slv_eps---= Tolerance on the BiCGSTAB(ldim) iterative solver
 */
int ldim;
int mxmatvec;
double slv_eps;


/* Preconditioner
 *--sparseflg--= Parameter that determines the sparsity pattern of the preconditoner
 *-------------= sparseflg = 0 ==> no sparse approximation of the Discretized BIE matrix g <==> no preconditioner
 *-------------= sparseflg = 1 ==> Cell self-interactions are used for the sparse approximation of the Discretized BIE matrix g
 *-------------= sparseflg = 1+n ==> Partial or Complete nearfield, i.e, Cell + n Neighbors are used for the sparse approximation
 *-------------= of the Discretized BIE matrix g
 
 *-----gcsr----= Preconditioner <==> Sparse approximation of the Discretized BIE matrix g in Compressed Sparse Row (CSR) format
 *-----note----= Array gcsr is allocated and initialized in function "cbem_lap_solv" (see cbem_lap_solv.c)

 *----igcsr----= Pointers in gcsr of the beginning of each row of g
 *-----note----= Array igcsr is allocated and initialized in function "cbem_lap_solv" (see cbem_lap_solv.c)

 *----jgcsr----= Column indices of the entries of gcsr as stored in the Discretized BIE matrix g
 *-----note----= Array jgcsr is allocated and initialized in function "cbem_lap_solv" (see cbem_lap_solv.c)
 */
int sparseflg;
int *igcsr, *jgcsr;
double *gcsr;


void coo2csr(int n, int nnz, double *ca, int *ia, int *ja); /* Convert ca from coordinate to compressed sparse row format */
void csr_ilu0(int n, double *ca, int *ia, int *ja); /* Zero Fill-in Incomplete LU Factorization */
void csr_ilu0sol(int n, double *ca, int *ia, int *ja, double *b); /* Solve the system: A*x=b, ca == Compressed A */
void ilu0_l_pcond(int m, double *x); /* Apply a left preconditioner */
void mat_vec(int m, double *x, double *y); /* Compute the matrix-vector product: y=A*x */
void bicgstabl(int l, int n, double *x, bool nonzero_x, double *b,
               void (*matvec)(int, double *, double *), /* Compute the matrix-vector product: y=A*x */
	       void (*l_precond)(int, double *), /* Apply a left preconditioner if pcond=true, i.e. solve the system: M*y=x */
               bool pcond, double *toler,
	       int *mxmatvec, int *info); /* Iterative solution of a real non-symmetric linear system: A*x=b */

#endif /* _BEM_PCOND_IT_SOLV_H_ */
