Fast Auxiliary Space Preconditioning 2.7.7 Aug/28/2022
Loading...
Searching...
No Matches
SolSTR.c
Go to the documentation of this file.
1
16#include <math.h>
17#include <time.h>
18
19#include "fasp.h"
20#include "fasp_functs.h"
21
22/*---------------------------------*/
23/*-- Declare Private Functions --*/
24/*---------------------------------*/
25
26#include "KryUtil.inl"
27
28/*---------------------------------*/
29/*-- Public Functions --*/
30/*---------------------------------*/
31
52 ITS_param* itparam)
53{
54 const SHORT prtlvl = itparam->print_level;
55 const SHORT itsolver_type = itparam->itsolver_type;
56 const SHORT stop_type = itparam->stop_type;
57 const SHORT restart = itparam->restart;
58 const INT MaxIt = itparam->maxit;
59 const REAL tol = itparam->tol;
60 const REAL abstol = itparam->abstol;
61
62 // local variables
64 REAL solve_start, solve_end;
65
66#if DEBUG_MODE > 0
67 printf("### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
68 printf("### DEBUG: rhs/sol size: %d %d\n", b->row, x->row);
69#endif
70
71 fasp_gettime(&solve_start);
72
73 /* Safe-guard checks on parameters */
74 ITS_CHECK(MaxIt, tol);
75
76 switch (itsolver_type) {
77
78 case SOLVER_CG:
79 iter = fasp_solver_dstr_pcg(A, b, x, pc, tol, abstol, MaxIt, stop_type,
80 prtlvl);
81 break;
82
83 case SOLVER_BiCGstab:
84 iter = fasp_solver_dstr_pbcgs(A, b, x, pc, tol, abstol, MaxIt, stop_type,
85 prtlvl);
86 break;
87
88 case SOLVER_GMRES:
89 iter = fasp_solver_dstr_pgmres(A, b, x, pc, tol, abstol, MaxIt, restart,
90 stop_type, prtlvl);
91 break;
92
93 case SOLVER_VGMRES:
94 iter = fasp_solver_dstr_pvgmres(A, b, x, pc, tol, abstol, MaxIt, restart,
95 stop_type, prtlvl);
96 break;
97
98 default:
99 printf("### ERROR: Unknown iterative solver type %d! [%s]\n", itsolver_type,
100 __FUNCTION__);
101 return ERROR_SOLVER_TYPE;
102 }
103
104 if ((prtlvl > PRINT_MIN) && (iter >= 0)) {
105 fasp_gettime(&solve_end);
106 fasp_cputime("Iterative method", solve_end - solve_start);
107 }
108
109#if DEBUG_MODE > 0
110 printf("### DEBUG: [--End--] %s ...\n", __FUNCTION__);
111#endif
112
113 return iter;
114}
115
133{
134 const SHORT prtlvl = itparam->print_level;
135 INT status = FASP_SUCCESS;
136 REAL solve_start, solve_end;
137
138#if DEBUG_MODE > 0
139 printf("### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
140#endif
141
142 // solver part
143 fasp_gettime(&solve_start);
144
145 status = fasp_solver_dstr_itsolver(A, b, x, NULL, itparam);
146
147 fasp_gettime(&solve_end);
148
149 if (prtlvl >= PRINT_MIN)
150 fasp_cputime("Krylov method totally", solve_end - solve_start);
151
152#if DEBUG_MODE > 0
153 printf("### DEBUG: [--End--] %s ...\n", __FUNCTION__);
154#endif
155
156 return status;
157}
158
176{
177 const SHORT prtlvl = itparam->print_level;
178 const INT ngrid = A->ngrid;
179
180 INT status = FASP_SUCCESS;
181 REAL solve_start, solve_end;
182 INT nc = A->nc, nc2 = nc * nc, i;
183
184 fasp_gettime(&solve_start);
185
186 // setup preconditioner
187 precond_diag_str diag;
188 fasp_dvec_alloc(ngrid * nc2, &(diag.diag));
189 fasp_darray_cp(ngrid * nc2, A->diag, diag.diag.val);
190
191 diag.nc = nc;
192
193 for (i = 0; i < ngrid; ++i) fasp_smat_inv(&(diag.diag.val[i * nc2]), nc);
194
195 precond* pc = (precond*)fasp_mem_calloc(1, sizeof(precond));
196
197 pc->data = &diag;
199
200#if DEBUG_MODE > 0
201 printf("### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
202#endif
203
204 // solver part
205 status = fasp_solver_dstr_itsolver(A, b, x, pc, itparam);
206
207 fasp_gettime(&solve_end);
208
209 if (prtlvl >= PRINT_MIN)
210 fasp_cputime("Diag_Krylov method totally", solve_end - solve_start);
211
212#if DEBUG_MODE > 0
213 printf("### DEBUG: [--End--] %s ...\n", __FUNCTION__);
214#endif
215
216 return status;
217}
218
237 ILU_param* iluparam)
238{
239 const SHORT prtlvl = itparam->print_level;
240 const INT ILU_lfil = iluparam->ILU_lfil;
241
242 INT status = FASP_SUCCESS;
243 REAL setup_start, setup_end, setup_time;
244 REAL solve_start, solve_end, solve_time;
245
246 // set up
247 dSTRmat LU;
248
249#if DEBUG_MODE > 0
250 printf("### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
251#endif
252
253 fasp_gettime(&setup_start);
254
255 if (ILU_lfil == 0) {
256 fasp_ilu_dstr_setup0(A, &LU);
257 } else if (ILU_lfil == 1) {
258 fasp_ilu_dstr_setup1(A, &LU);
259 } else {
260 printf("### ERROR: Illegal level of ILU fill-in (>1)! [%s]\n", __FUNCTION__);
261 return ERROR_MISC;
262 }
263
264 fasp_gettime(&setup_end);
265
266 setup_time = setup_end - setup_start;
267
268 if (prtlvl > PRINT_NONE)
269 printf("Structrued ILU(%d) setup costs %f seconds.\n", ILU_lfil, setup_time);
270
271 precond pc;
272 pc.data = &LU;
273 if (ILU_lfil == 0) {
275 } else if (ILU_lfil == 1) {
277 } else {
278 printf("### ERROR: Illegal level of ILU fill-in (>1)! [%s]\n", __FUNCTION__);
279 return ERROR_MISC;
280 }
281
282 // solver part
283 fasp_gettime(&solve_start);
284
285 status = fasp_solver_dstr_itsolver(A, b, x, &pc, itparam);
286
287 fasp_gettime(&solve_end);
288
289 if (prtlvl >= PRINT_MIN) {
290 solve_time = solve_end - solve_start;
291 printf("Iterative solver costs %f seconds.\n", solve_time);
292 fasp_cputime("ILU_Krylov method totally", setup_time + solve_time);
293 }
294
295 fasp_dstr_free(&LU);
296
297#if DEBUG_MODE > 0
298 printf("### DEBUG: [--End--] %s ...\n", __FUNCTION__);
299#endif
300
301 return status;
302}
303
324 ITS_param* itparam, ivector* neigh, ivector* order)
325{
326 // Parameter for iterative method
327 const SHORT prtlvl = itparam->print_level;
328
329 // Information about matrices
330 INT ngrid = A->ngrid;
331
332 // return parameter
333 INT status = FASP_SUCCESS;
334
335 // local parameter
336 REAL setup_start, setup_end, setup_time = 0;
337 REAL solve_start, solve_end, solve_time = 0;
338
339 dvector* diaginv;
340 ivector* pivot;
341
342#if DEBUG_MODE > 0
343 printf("### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
344#endif
345
346 // setup preconditioner
347 fasp_gettime(&setup_start);
348
349 diaginv = (dvector*)fasp_mem_calloc(ngrid, sizeof(dvector));
350 pivot = (ivector*)fasp_mem_calloc(ngrid, sizeof(ivector));
351 fasp_generate_diaginv_block(A, neigh, diaginv, pivot);
352
353 precond_data_str pcdata;
354 pcdata.A_str = A;
355 pcdata.diaginv = diaginv;
356 pcdata.pivot = pivot;
357 pcdata.order = order;
358 pcdata.neigh = neigh;
359
360 precond pc;
361 pc.data = &pcdata;
363
364 fasp_gettime(&setup_end);
365
366 if (prtlvl > PRINT_NONE) {
367 setup_time = setup_end - setup_start;
368 printf("Preconditioner setup costs %f seconds.\n", setup_time);
369 }
370
371 // solver part
372 fasp_gettime(&solve_start);
373
374 status = fasp_solver_dstr_itsolver(A, b, x, &pc, itparam);
375
376 fasp_gettime(&solve_end);
377 solve_time = solve_end - solve_start;
378
379 if (prtlvl >= PRINT_MIN) {
380 fasp_cputime("Iterative solver", solve_time);
381 fasp_cputime("BlockGS_Krylov method totally", setup_time + solve_time);
382 }
383
384#if DEBUG_MODE > 0
385 printf("### DEBUG: [--End--] %s ...\n", __FUNCTION__);
386#endif
387
388 return status;
389}
390
391/*---------------------------------*/
392/*-- End of File --*/
393/*---------------------------------*/
void fasp_darray_cp(const INT n, const REAL *x, REAL *y)
Copy an array to the other y=x.
Definition: AuxArray.c:210
void * fasp_mem_calloc(const unsigned int size, const unsigned int type)
Allocate, initiate, and check memory.
Definition: AuxMemory.c:65
void fasp_cputime(const char *message, const REAL cputime)
Print CPU walltime.
Definition: AuxMessage.c:179
void fasp_gettime(REAL *time)
Get system time.
Definition: AuxTiming.c:37
void fasp_dvec_alloc(const INT m, dvector *u)
Create dvector data space of REAL type.
Definition: AuxVector.c:105
void fasp_ilu_dstr_setup0(dSTRmat *A, dSTRmat *LU)
Get ILU(0) decomposition of a structured matrix A.
void fasp_ilu_dstr_setup1(dSTRmat *A, dSTRmat *LU)
Get ILU(1) decoposition of a structured matrix A.
SHORT fasp_smat_inv(REAL *a, const INT n)
Compute the inverse matrix of a small full matrix a.
void fasp_dstr_free(dSTRmat *A)
Free STR sparse matrix data memeory space.
Definition: BlaSparseSTR.c:136
void fasp_generate_diaginv_block(dSTRmat *A, ivector *neigh, dvector *diaginv, ivector *pivot)
Generate inverse of diagonal block for block smoothers.
INT fasp_solver_dstr_pbcgs(dSTRmat *A, dvector *b, dvector *u, precond *pc, const REAL tol, const REAL abstol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
Preconditioned BiCGstab method for solving Au=b for STR matrix.
Definition: KryPbcgs.c:1027
INT fasp_solver_dstr_pcg(dSTRmat *A, dvector *b, dvector *u, precond *pc, const REAL tol, const REAL abstol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
Preconditioned conjugate gradient method for solving Au=b.
Definition: KryPcg.c:970
INT fasp_solver_dstr_pgmres(dSTRmat *A, dvector *b, dvector *x, precond *pc, const REAL tol, const REAL abstol, const INT MaxIt, const SHORT restart, const SHORT StopType, const SHORT PrtLvl)
Preconditioned GMRES method for solving Au=b.
Definition: KryPgmres.c:998
INT fasp_solver_dstr_pvgmres(dSTRmat *A, dvector *b, dvector *x, precond *pc, const REAL tol, const REAL abstol, const INT MaxIt, const SHORT restart, const SHORT StopType, const SHORT PrtLvl)
Right preconditioned GMRES method in which the restart parameter can be adaptively modified during it...
Definition: KryPvgmres.c:1116
void fasp_precond_dstr_diag(REAL *r, REAL *z, void *data)
Diagonal preconditioner z=inv(D)*r.
Definition: PreSTR.c:44
void fasp_precond_dstr_blockgs(REAL *r, REAL *z, void *data)
CPR-type preconditioner (STR format)
Definition: PreSTR.c:1715
void fasp_precond_dstr_ilu1(REAL *r, REAL *z, void *data)
Preconditioning using STR_ILU(1) decomposition.
Definition: PreSTR.c:349
void fasp_precond_dstr_ilu0(REAL *r, REAL *z, void *data)
Preconditioning using STR_ILU(0) decomposition.
Definition: PreSTR.c:71
INT fasp_solver_dstr_itsolver(dSTRmat *A, dvector *b, dvector *x, precond *pc, ITS_param *itparam)
Solve Ax=b by standard Krylov methods.
Definition: SolSTR.c:51
INT fasp_solver_dstr_krylov_diag(dSTRmat *A, dvector *b, dvector *x, ITS_param *itparam)
Solve Ax=b by diagonal preconditioned Krylov methods.
Definition: SolSTR.c:175
INT fasp_solver_dstr_krylov_blockgs(dSTRmat *A, dvector *b, dvector *x, ITS_param *itparam, ivector *neigh, ivector *order)
Solve Ax=b by diagonal preconditioned Krylov methods.
Definition: SolSTR.c:323
INT fasp_solver_dstr_krylov_ilu(dSTRmat *A, dvector *b, dvector *x, ITS_param *itparam, ILU_param *iluparam)
Solve Ax=b by structured ILU preconditioned Krylov methods.
Definition: SolSTR.c:236
INT fasp_solver_dstr_krylov(dSTRmat *A, dvector *b, dvector *x, ITS_param *itparam)
Solve Ax=b by standard Krylov methods.
Definition: SolSTR.c:132
Main header file for the FASP project.
#define REAL
Definition: fasp.h:75
#define SHORT
FASP integer and floating point numbers.
Definition: fasp.h:71
#define INT
Definition: fasp.h:72
#define SOLVER_GMRES
Definition: fasp_const.h:106
#define ERROR_MISC
Definition: fasp_const.h:28
#define FASP_SUCCESS
Definition of return status and error messages.
Definition: fasp_const.h:19
#define ERROR_SOLVER_TYPE
Definition: fasp_const.h:41
#define SOLVER_VGMRES
Definition: fasp_const.h:107
#define SOLVER_BiCGstab
Definition: fasp_const.h:104
#define SOLVER_CG
Definition: fasp_const.h:103
#define PRINT_NONE
Print level for all subroutines – not including DEBUG output.
Definition: fasp_const.h:73
#define PRINT_MIN
Definition: fasp_const.h:74
Parameters for ILU.
Definition: fasp.h:404
INT ILU_lfil
level of fill-in for ILUk
Definition: fasp.h:413
Parameters for iterative solvers.
Definition: fasp.h:386
SHORT itsolver_type
Definition: fasp.h:389
SHORT print_level
Definition: fasp.h:388
REAL tol
Definition: fasp.h:395
INT restart
Definition: fasp.h:393
SHORT stop_type
Definition: fasp.h:392
REAL abstol
Definition: fasp.h:396
INT maxit
Definition: fasp.h:394
Structure matrix of REAL type.
Definition: fasp.h:316
REAL * diag
diagonal entries (length is ngrid*(nc^2))
Definition: fasp.h:337
INT ngrid
number of grids
Definition: fasp.h:334
INT nc
size of each block (number of components)
Definition: fasp.h:331
Vector with n entries of REAL type.
Definition: fasp.h:354
REAL * val
actual vector entries
Definition: fasp.h:360
INT row
number of rows
Definition: fasp.h:357
Vector with n entries of INT type.
Definition: fasp.h:368
Data for preconditioners in dSTRmat format.
Definition: fasp.h:987
ivector * neigh
array to store neighbor information
Definition: fasp.h:1061
ivector * pivot
the pivot for the GS/block GS smoother (whole reservoir matrix)
Definition: fasp.h:1049
dSTRmat * A_str
store the whole reservoir block in STR format
Definition: fasp.h:1038
ivector * order
order for smoothing
Definition: fasp.h:1058
dvector * diaginv
the inverse of the diagonals for GS/block GS smoother (whole reservoir matrix)
Definition: fasp.h:1046
Data for diagonal preconditioners in dSTRmat format.
Definition: fasp.h:1079
INT nc
number of components
Definition: fasp.h:1082
dvector diag
diagonal elements
Definition: fasp.h:1085
Preconditioner data and action.
Definition: fasp.h:1095
void * data
data for preconditioner, void pointer
Definition: fasp.h:1098
void(* fct)(REAL *, REAL *, void *)
action for preconditioner, void function pointer
Definition: fasp.h:1101