1 |
|
2 |
/******************************************************* |
3 |
* |
4 |
* Copyright (c) 2003-2009 by University of Queensland |
5 |
* Earth Systems Science Computational Center (ESSCC) |
6 |
* http://www.uq.edu.au/esscc |
7 |
* |
8 |
* Primary Business: Queensland, Australia |
9 |
* Licensed under the Open Software License version 3.0 |
10 |
* http://www.opensource.org/licenses/osl-3.0.php |
11 |
* |
12 |
*******************************************************/ |
13 |
|
14 |
|
15 |
#ifndef INC_SOLVER |
16 |
#define INC_SOLVER |
17 |
|
18 |
#include "SystemMatrix.h" |
19 |
#include "performance.h" |
20 |
#include "Functions.h" |
21 |
|
22 |
#define PASO_TRACE |
23 |
/* error codes used in the solver */ |
24 |
#define SOLVER_NO_ERROR 0 |
25 |
#define SOLVER_MAXITER_REACHED 1 |
26 |
#define SOLVER_INPUT_ERROR -1 |
27 |
#define SOLVER_MEMORY_ERROR -9 |
28 |
#define SOLVER_BREAKDOWN -10 |
29 |
#define SOLVER_NEGATIVE_NORM_ERROR -11 |
30 |
|
31 |
#define TOLERANCE_FOR_SCALARS (double)(0.) |
32 |
#define PASO_ONE (double)(1.0) |
33 |
#define PASO_ZERO (double)(0.0) |
34 |
|
35 |
#define MAX_BLOCK_SIZE 3 |
36 |
|
37 |
/* static double ONE=1.; */ |
38 |
/* static double ZERO=0.;*/ |
39 |
/*static double TOLERANCE_FOR_SCALARS=0.;*/ |
40 |
|
41 |
/* jacobi preconditioner */ |
42 |
|
43 |
typedef struct Paso_Solver_Jacobi { |
44 |
dim_t n_block; |
45 |
dim_t n; |
46 |
double* values; |
47 |
index_t* pivot; |
48 |
} Paso_Solver_Jacobi; |
49 |
|
50 |
|
51 |
/* ILU preconditioner */ |
52 |
struct Paso_Solver_ILU { |
53 |
dim_t n_block; |
54 |
dim_t n; |
55 |
index_t num_colors; |
56 |
index_t* colorOf; |
57 |
index_t* main_iptr; |
58 |
double* factors; |
59 |
Paso_Pattern* pattern; |
60 |
}; |
61 |
typedef struct Paso_Solver_ILU Paso_Solver_ILU; |
62 |
|
63 |
/* GS preconditioner */ |
64 |
struct Paso_Solver_GS { |
65 |
dim_t n_block; |
66 |
dim_t n; |
67 |
index_t num_colors; |
68 |
index_t* colorOf; |
69 |
index_t* main_iptr; |
70 |
double* diag; |
71 |
Paso_SparseMatrix * factors; |
72 |
Paso_Pattern* pattern; |
73 |
dim_t sweeps; |
74 |
double* x_old; |
75 |
}; |
76 |
typedef struct Paso_Solver_GS Paso_Solver_GS; |
77 |
|
78 |
/* RILU preconditioner */ |
79 |
struct Paso_Solver_RILU { |
80 |
dim_t n; |
81 |
dim_t n_block; |
82 |
dim_t n_F; |
83 |
dim_t n_C; |
84 |
double* inv_A_FF; |
85 |
index_t* A_FF_pivot; |
86 |
Paso_SparseMatrix * A_FC; |
87 |
Paso_SparseMatrix * A_CF; |
88 |
index_t* rows_in_F; |
89 |
index_t* rows_in_C; |
90 |
index_t* mask_F; |
91 |
index_t* mask_C; |
92 |
double* x_F; |
93 |
double* b_F; |
94 |
double* x_C; |
95 |
double* b_C; |
96 |
struct Paso_Solver_RILU * RILU_of_Schur; |
97 |
}; |
98 |
typedef struct Paso_Solver_RILU Paso_Solver_RILU; |
99 |
|
100 |
/* AMG preconditioner */ |
101 |
struct Paso_Solver_AMG { |
102 |
dim_t n; |
103 |
dim_t level; |
104 |
bool_t coarsest_level; |
105 |
dim_t n_block; |
106 |
dim_t n_F; |
107 |
dim_t n_C; |
108 |
double* inv_A_FF; |
109 |
index_t* A_FF_pivot; |
110 |
Paso_SparseMatrix * A_FC; |
111 |
Paso_SparseMatrix * A_CF; |
112 |
index_t* rows_in_F; |
113 |
index_t* rows_in_C; |
114 |
index_t* mask_F; |
115 |
index_t* mask_C; |
116 |
double* x_F; |
117 |
double* b_F; |
118 |
double* x_C; |
119 |
double* b_C; |
120 |
Paso_SparseMatrix * A; |
121 |
Paso_SparseMatrix * AOffset1; |
122 |
void* solver; |
123 |
Paso_Solver_Jacobi* GS; |
124 |
struct Paso_Solver_AMG * AMG_of_Schur; |
125 |
}; |
126 |
typedef struct Paso_Solver_AMG Paso_Solver_AMG; |
127 |
|
128 |
/* AMG preconditioner on blocks*/ |
129 |
struct Paso_Solver_AMG_System { |
130 |
dim_t block_size; |
131 |
Paso_SparseMatrix *block[MAX_BLOCK_SIZE]; |
132 |
Paso_Solver_AMG *amgblock[MAX_BLOCK_SIZE]; |
133 |
}; |
134 |
typedef struct Paso_Solver_AMG_System Paso_Solver_AMG_System; |
135 |
|
136 |
|
137 |
/* general preconditioner interface */ |
138 |
|
139 |
typedef struct Paso_Solver_Preconditioner { |
140 |
dim_t type; |
141 |
/* jacobi preconditioner */ |
142 |
Paso_Solver_Jacobi* jacobi; |
143 |
/* ilu preconditioner */ |
144 |
Paso_Solver_ILU* ilu; |
145 |
/* rilu preconditioner */ |
146 |
Paso_Solver_RILU* rilu; |
147 |
/* Gauss-Seidel preconditioner */ |
148 |
Paso_Solver_GS* gs; |
149 |
/* amg preconditioner */ |
150 |
Paso_Solver_AMG* amg; |
151 |
/* amg on System */ |
152 |
Paso_Solver_AMG_System* amgSystem; |
153 |
|
154 |
} Paso_Solver_Preconditioner; |
155 |
|
156 |
void Paso_Solver(Paso_SystemMatrix*,double*,double*,Paso_Options*,Paso_Performance* pp); |
157 |
void Paso_Solver_free(Paso_SystemMatrix*); |
158 |
err_t Paso_Solver_BiCGStab( Paso_SystemMatrix * A, double* B, double * X, dim_t *iter, double * tolerance, Paso_Performance* pp); |
159 |
err_t Paso_Solver_PCG( Paso_SystemMatrix * A, double* B, double * X, dim_t *iter, double * tolerance, Paso_Performance* pp); |
160 |
err_t Paso_Solver_TFQMR( Paso_SystemMatrix * A, double* B, double * X, dim_t *iter, double * tolerance, Paso_Performance* pp); |
161 |
err_t Paso_Solver_MINRES( Paso_SystemMatrix * A, double* B, double * X, dim_t *iter, double * tolerance, Paso_Performance* pp); |
162 |
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); |
163 |
void Paso_Preconditioner_free(Paso_Solver_Preconditioner*); |
164 |
void Paso_Solver_setPreconditioner(Paso_SystemMatrix* A,Paso_Options* options); |
165 |
void Paso_Solver_solvePreconditioner(Paso_SystemMatrix* A,double*,double*); |
166 |
void Paso_Solver_applyBlockDiagonalMatrix(dim_t n_block,dim_t n,double* D,index_t* pivot,double* x,double* b); |
167 |
|
168 |
void Paso_Solver_ILU_free(Paso_Solver_ILU * in); |
169 |
Paso_Solver_ILU* Paso_Solver_getILU(Paso_SparseMatrix * A_p,bool_t verbose); |
170 |
void Paso_Solver_solveILU(Paso_Solver_ILU * ilu, double * x, double * b); |
171 |
|
172 |
void Paso_Solver_GS_free(Paso_Solver_GS * in); |
173 |
Paso_Solver_GS* Paso_Solver_getGS(Paso_SparseMatrix * A_p,bool_t verbose); |
174 |
void Paso_Solver_solveGS(Paso_Solver_GS * gs, double * x, double * b); |
175 |
|
176 |
void Paso_Solver_RILU_free(Paso_Solver_RILU * in); |
177 |
Paso_Solver_RILU* Paso_Solver_getRILU(Paso_SparseMatrix * A_p,bool_t verbose); |
178 |
void Paso_Solver_solveRILU(Paso_Solver_RILU * rilu, double * x, double * b); |
179 |
|
180 |
void Paso_Solver_AMG_System_free(Paso_Solver_AMG_System * in); |
181 |
void Paso_Solver_AMG_free(Paso_Solver_AMG * in); |
182 |
Paso_Solver_AMG* Paso_Solver_getAMG(Paso_SparseMatrix * A_p,dim_t level,Paso_Options* options); |
183 |
void Paso_Solver_solveAMG(Paso_Solver_AMG * amg, double * x, double * b); |
184 |
|
185 |
void Paso_Solver_updateIncompleteSchurComplement(Paso_SparseMatrix* A_CC, Paso_SparseMatrix *A_CF,double* invA_FF,index_t* A_FF_pivot, Paso_SparseMatrix *A_FC); |
186 |
Paso_Solver_Jacobi* Paso_Solver_getJacobi(Paso_SparseMatrix * A_p); |
187 |
void Paso_Solver_solveJacobi(Paso_Solver_Jacobi * prec, double * x, double * b); |
188 |
void Paso_Solver_Jacobi_free(Paso_Solver_Jacobi * in); |
189 |
|
190 |
err_t Paso_Solver_GMRES2(Paso_Function * F, const double* f0, const double* x0, double * x, dim_t *iter, double* tolerance, Paso_Performance* pp); |
191 |
err_t Paso_Solver_NewtonGMRES(Paso_Function *F, double *x, Paso_Options* options, Paso_Performance* pp); |
192 |
|
193 |
Paso_Function * Paso_Function_LinearSystem_alloc(Paso_SystemMatrix* A, double* b, Paso_Options* options); |
194 |
err_t Paso_Function_LinearSystem_call(Paso_Function * F,double* value, const double* arg, Paso_Performance *pp); |
195 |
void Paso_Function_LinearSystem_free(Paso_Function * F); |
196 |
err_t Paso_Function_LinearSystem_setInitialGuess(Paso_SystemMatrix* A, double* x, Paso_Performance *pp); |
197 |
|
198 |
#endif /* #ifndef INC_SOLVER */ |