00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef INC_SOLVER
00016 #define INC_SOLVER
00017
00018 #include "SystemMatrix.h"
00019 #include "performance.h"
00020 #include "Functions.h"
00021
00022 #define PASO_TRACE
00023
00024 #define SOLVER_NO_ERROR 0
00025 #define SOLVER_MAXITER_REACHED 1
00026 #define SOLVER_INPUT_ERROR -1
00027 #define SOLVER_MEMORY_ERROR -9
00028 #define SOLVER_BREAKDOWN -10
00029 #define SOLVER_NEGATIVE_NORM_ERROR -11
00030
00031 #define TOLERANCE_FOR_SCALARS (double)(0.)
00032 #define PASO_ONE (double)(1.0)
00033 #define PASO_ZERO (double)(0.0)
00034
00035
00036
00037
00038
00039
00040
00041 typedef struct Paso_Solver_Jacobi {
00042 dim_t n_block;
00043 dim_t n;
00044 double* values;
00045 index_t* pivot;
00046 } Paso_Solver_Jacobi;
00047
00048
00049
00050 struct Paso_Solver_ILU {
00051 dim_t n_block;
00052 dim_t n;
00053 index_t num_colors;
00054 index_t* colorOf;
00055 index_t* main_iptr;
00056 double* factors;
00057 Paso_Pattern* pattern;
00058 };
00059 typedef struct Paso_Solver_ILU Paso_Solver_ILU;
00060
00061
00062 struct Paso_Solver_GS {
00063 dim_t n_block;
00064 dim_t n;
00065 index_t num_colors;
00066 index_t* colorOf;
00067 index_t* main_iptr;
00068 double* diag;
00069 Paso_SparseMatrix * factors;
00070 Paso_Pattern* pattern;
00071 dim_t sweeps;
00072 double* x_old;
00073 };
00074 typedef struct Paso_Solver_GS Paso_Solver_GS;
00075
00076
00077 struct Paso_Solver_RILU {
00078 dim_t n;
00079 dim_t n_block;
00080 dim_t n_F;
00081 dim_t n_C;
00082 double* inv_A_FF;
00083 index_t* A_FF_pivot;
00084 Paso_SparseMatrix * A_FC;
00085 Paso_SparseMatrix * A_CF;
00086 index_t* rows_in_F;
00087 index_t* rows_in_C;
00088 index_t* mask_F;
00089 index_t* mask_C;
00090 double* x_F;
00091 double* b_F;
00092 double* x_C;
00093 double* b_C;
00094 struct Paso_Solver_RILU * RILU_of_Schur;
00095 };
00096 typedef struct Paso_Solver_RILU Paso_Solver_RILU;
00097
00098
00099 struct Paso_Solver_AMG {
00100 dim_t n;
00101 dim_t level;
00102 bool_t coarsest_level;
00103 dim_t n_block;
00104 dim_t n_F;
00105 dim_t n_C;
00106 double* inv_A_FF;
00107 index_t* A_FF_pivot;
00108 Paso_SparseMatrix * A_FC;
00109 Paso_SparseMatrix * A_CF;
00110 index_t* rows_in_F;
00111 index_t* rows_in_C;
00112 index_t* mask_F;
00113 index_t* mask_C;
00114 double* x_F;
00115 double* b_F;
00116 double* x_C;
00117 double* b_C;
00118 Paso_SparseMatrix * A;
00119 void* solver;
00120 Paso_Solver_Jacobi* GS;
00121 struct Paso_Solver_AMG * AMG_of_Schur;
00122 };
00123 typedef struct Paso_Solver_AMG Paso_Solver_AMG;
00124
00125
00126
00127
00128 typedef struct Paso_Solver_Preconditioner {
00129 dim_t type;
00130
00131 Paso_Solver_Jacobi* jacobi;
00132
00133 Paso_Solver_ILU* ilu;
00134
00135 Paso_Solver_RILU* rilu;
00136
00137 Paso_Solver_GS* gs;
00138
00139 Paso_Solver_AMG* amg;
00140
00141 } Paso_Solver_Preconditioner;
00142
00143 void Paso_Solver(Paso_SystemMatrix*,double*,double*,Paso_Options*,Paso_Performance* pp);
00144 void Paso_Solver_free(Paso_SystemMatrix*);
00145 err_t Paso_Solver_BiCGStab( Paso_SystemMatrix * A, double* B, double * X, dim_t *iter, double * tolerance, Paso_Performance* pp);
00146 err_t Paso_Solver_PCG( Paso_SystemMatrix * A, double* B, double * X, dim_t *iter, double * tolerance, Paso_Performance* pp);
00147 err_t Paso_Solver_TFQMR( Paso_SystemMatrix * A, double* B, double * X, dim_t *iter, double * tolerance, Paso_Performance* pp);
00148 err_t Paso_Solver_MINRES( Paso_SystemMatrix * A, double* B, double * X, dim_t *iter, double * tolerance, Paso_Performance* pp);
00149 err_t Paso_Solver_GMRES(Paso_SystemMatrix * A, double * r, double * x, dim_t *num_iter, double * tolerance,dim_t length_of_recursion,dim_t restart, Paso_Performance* pp);
00150 void Paso_Preconditioner_free(Paso_Solver_Preconditioner*);
00151 void Paso_Solver_setPreconditioner(Paso_SystemMatrix* A,Paso_Options* options);
00152 void Paso_Solver_solvePreconditioner(Paso_SystemMatrix* A,double*,double*);
00153 void Paso_Solver_applyBlockDiagonalMatrix(dim_t n_block,dim_t n,double* D,index_t* pivot,double* x,double* b);
00154
00155 void Paso_Solver_ILU_free(Paso_Solver_ILU * in);
00156 Paso_Solver_ILU* Paso_Solver_getILU(Paso_SparseMatrix * A_p,bool_t verbose);
00157 void Paso_Solver_solveILU(Paso_Solver_ILU * ilu, double * x, double * b);
00158
00159 void Paso_Solver_GS_free(Paso_Solver_GS * in);
00160 Paso_Solver_GS* Paso_Solver_getGS(Paso_SparseMatrix * A_p,bool_t verbose);
00161 void Paso_Solver_solveGS(Paso_Solver_GS * gs, double * x, double * b);
00162
00163 void Paso_Solver_RILU_free(Paso_Solver_RILU * in);
00164 Paso_Solver_RILU* Paso_Solver_getRILU(Paso_SparseMatrix * A_p,bool_t verbose);
00165 void Paso_Solver_solveRILU(Paso_Solver_RILU * rilu, double * x, double * b);
00166
00167 void Paso_Solver_AMG_free(Paso_Solver_AMG * in);
00168 Paso_Solver_AMG* Paso_Solver_getAMG(Paso_SparseMatrix * A_p,dim_t level,Paso_Options* options);
00169 void Paso_Solver_solveAMG(Paso_Solver_AMG * amg, double * x, double * b);
00170
00171 void Paso_Solver_updateIncompleteSchurComplement(Paso_SparseMatrix* A_CC, Paso_SparseMatrix *A_CF,double* invA_FF,index_t* A_FF_pivot, Paso_SparseMatrix *A_FC);
00172 Paso_Solver_Jacobi* Paso_Solver_getJacobi(Paso_SparseMatrix * A_p);
00173 void Paso_Solver_solveJacobi(Paso_Solver_Jacobi * prec, double * x, double * b);
00174 void Paso_Solver_Jacobi_free(Paso_Solver_Jacobi * in);
00175
00176 err_t Paso_Solver_GMRES2(Paso_Function * F, const double* f0, const double* x0, double * x, dim_t *iter, double* tolerance, Paso_Performance* pp);
00177 err_t Paso_Solver_NewtonGMRES(Paso_Function *F, double *x, Paso_Options* options, Paso_Performance* pp);
00178
00179 Paso_Function * Paso_Function_LinearSystem_alloc(Paso_SystemMatrix* A, double* b, Paso_Options* options);
00180 err_t Paso_Function_LinearSystem_call(Paso_Function * F,double* value, const double* arg, Paso_Performance *pp);
00181 void Paso_Function_LinearSystem_free(Paso_Function * F);
00182 err_t Paso_Function_LinearSystem_setInitialGuess(Paso_SystemMatrix* A, double* x, Paso_Performance *pp);
00183
00184 #endif