28#include "fasp_functs.h"
74 const REAL TOL_s = tol*1e-2;
77 INT iter = 0, stag = 1, more_step = 1, restart_step = 1;
78 REAL alpha, beta, omega, temp1, temp2;
81 REAL reldiff, factor, normd, tempr, normuinf;
88 REAL *p = work, *z = work + m, *r = z + m, *t = r + m;
89 REAL *rho = t + m, *pp = rho + m, *s = pp + m, *sp = s + m, *u_best = sp + m;
92 if ( PrtLvl >
PRINT_NONE ) printf(
"\nCalling Safe BiCGstab solver (CSR) ...\n");
95 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
96 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
108 relres = absres0/normr0;
112 relres = absres0/normr0;
116 relres = absres0/normu;
119 printf(
"### ERROR: Unknown stopping type! [%s]\n", __FUNCTION__);
124 if (relres<tol)
goto FINISHED;
127 fasp_itinfo(PrtLvl,StopType,iter,relres,absres0,0.0);
137 while ( iter++ < MaxIt ) {
154 ITS_DIVZERO;
goto FINISHED;
196 beta = (temp1*alpha)/(temp2*omega);
199 ITS_DIVZERO;
goto RESTORE_BESTSOL;
211 reldiff = normd/normu;
213 if ( normd < TOL_s ) {
214 ITS_SMALLSP;
goto FINISHED;
221 relres = absres/normr0;
229 relres = absres/normr0;
233 relres = absres/normu;
241 goto RESTORE_BESTSOL;
244 if ( absres < absres_best - maxdiff) {
245 absres_best = absres;
251 factor = absres/absres0;
254 fasp_itinfo(PrtLvl,StopType,iter,relres,absres,factor);
258 if ( normuinf <= sol_inf_tol ) {
265 if ( (stag <= MaxStag) && (reldiff < maxdiff) ) {
268 ITS_DIFFRES(reldiff,relres);
291 relres = absres/normr0;
299 relres = absres/normr0;
303 relres = absres/normu;
307 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
312 if ( stag >= MaxStag ) {
324 if ( relres < tol ) {
325 if ( PrtLvl >=
PRINT_MORE ) ITS_COMPRES(relres);
346 relres = absres/normr0;
354 relres = tempr/normr0;
358 relres = absres/normu;
362 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
365 if ( relres < tol )
break;
367 if ( more_step >= MaxRestartStep ) {
385 if ( iter != iter_best ) {
391 switch ( StopType ) {
408 if ( absres > absres_best + maxdiff || isnan(absres) ) {
409 if ( PrtLvl >
PRINT_NONE ) ITS_RESTORE(iter_best);
411 relres = absres_best / normr0;
416 if ( PrtLvl >
PRINT_NONE ) ITS_FINAL(iter,MaxIt,relres);
422 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
458 const SHORT StopType,
465 const REAL TOL_s = tol*1e-2;
468 INT iter = 0, stag = 1, more_step = 1, restart_step = 1;
469 REAL alpha, beta, omega, temp1, temp2;
472 REAL reldiff, factor, normd, tempr, normuinf;
479 REAL *p = work, *z = work + m, *r = z + m, *t = r + m;
480 REAL *rho = t + m, *pp = rho + m, *s = pp + m, *sp = s + m, *u_best = sp + m;
483 if ( PrtLvl >
PRINT_NONE ) printf(
"\nCalling Safe BiCGstab solver (BSR) ...\n");
486 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
487 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
499 relres = absres0/normr0;
503 relres = absres0/normr0;
507 relres = absres0/normu;
510 printf(
"### ERROR: Unknown stopping type! [%s]\n", __FUNCTION__);
515 if (relres<tol)
goto FINISHED;
518 fasp_itinfo(PrtLvl,StopType,iter,relres,absres0,0.0);
528 while ( iter++ < MaxIt ) {
545 ITS_DIVZERO;
goto FINISHED;
587 beta = (temp1*alpha)/(temp2*omega);
590 ITS_DIVZERO;
goto RESTORE_BESTSOL;
602 reldiff = normd/normu;
604 if ( normd < TOL_s ) {
605 ITS_SMALLSP;
goto FINISHED;
612 relres = absres/normr0;
620 relres = absres/normr0;
624 relres = absres/normu;
632 goto RESTORE_BESTSOL;
635 if ( absres < absres_best - maxdiff) {
636 absres_best = absres;
642 factor = absres/absres0;
645 fasp_itinfo(PrtLvl,StopType,iter,relres,absres,factor);
649 if ( normuinf <= sol_inf_tol ) {
656 if ( (stag <= MaxStag) && (reldiff < maxdiff) ) {
659 ITS_DIFFRES(reldiff,relres);
682 relres = absres/normr0;
690 relres = absres/normr0;
694 relres = absres/normu;
698 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
703 if ( stag >= MaxStag ) {
715 if ( relres < tol ) {
716 if ( PrtLvl >=
PRINT_MORE ) ITS_COMPRES(relres);
737 relres = absres/normr0;
745 relres = tempr/normr0;
749 relres = absres/normu;
753 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
756 if ( relres < tol )
break;
758 if ( more_step >= MaxRestartStep ) {
776 if ( iter != iter_best ) {
782 switch ( StopType ) {
799 if ( absres > absres_best + maxdiff || isnan(absres) ) {
800 if ( PrtLvl >
PRINT_NONE ) ITS_RESTORE(iter_best);
802 relres = absres_best / normr0;
807 if ( PrtLvl >
PRINT_NONE ) ITS_FINAL(iter,MaxIt,relres);
813 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
849 const SHORT StopType,
856 const REAL TOL_s = tol*1e-2;
859 INT iter = 0, stag = 1, more_step = 1, restart_step = 1;
860 REAL alpha, beta, omega, temp1, temp2;
863 REAL reldiff, factor, normd, tempr, normuinf;
870 REAL *p = work, *z = work + m, *r = z + m, *t = r + m;
871 REAL *rho = t + m, *pp = rho + m, *s = pp + m, *sp = s + m, *u_best = sp + m;
874 if ( PrtLvl >
PRINT_NONE ) printf(
"\nCalling Safe BiCGstab solver (BLC) ...\n");
877 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
878 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
890 relres = absres0/normr0;
894 relres = absres0/normr0;
898 relres = absres0/normu;
901 printf(
"### ERROR: Unknown stopping type! [%s]\n", __FUNCTION__);
906 if (relres<tol)
goto FINISHED;
909 fasp_itinfo(PrtLvl,StopType,iter,relres,absres0,0.0);
919 while ( iter++ < MaxIt ) {
936 ITS_DIVZERO;
goto FINISHED;
978 beta = (temp1*alpha)/(temp2*omega);
981 ITS_DIVZERO;
goto RESTORE_BESTSOL;
993 reldiff = normd/normu;
995 if ( normd < TOL_s ) {
996 ITS_SMALLSP;
goto FINISHED;
1003 relres = absres/normr0;
1011 relres = absres/normr0;
1015 relres = absres/normu;
1023 goto RESTORE_BESTSOL;
1026 if ( absres < absres_best - maxdiff) {
1027 absres_best = absres;
1033 factor = absres/absres0;
1036 fasp_itinfo(PrtLvl,StopType,iter,relres,absres,factor);
1040 if ( normuinf <= sol_inf_tol ) {
1047 if ( (stag <= MaxStag) && (reldiff < maxdiff) ) {
1050 ITS_DIFFRES(reldiff,relres);
1073 relres = absres/normr0;
1081 relres = absres/normr0;
1085 relres = absres/normu;
1089 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
1094 if ( stag >= MaxStag ) {
1106 if ( relres < tol ) {
1107 if ( PrtLvl >=
PRINT_MORE ) ITS_COMPRES(relres);
1128 relres = absres/normr0;
1136 relres = tempr/normr0;
1140 relres = absres/normu;
1144 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
1147 if ( relres < tol )
break;
1149 if ( more_step >= MaxRestartStep ) {
1167 if ( iter != iter_best ) {
1173 switch ( StopType ) {
1190 if ( absres > absres_best + maxdiff || isnan(absres) ) {
1191 if ( PrtLvl >
PRINT_NONE ) ITS_RESTORE(iter_best);
1193 relres = absres_best / normr0;
1198 if ( PrtLvl >
PRINT_NONE ) ITS_FINAL(iter,MaxIt,relres);
1204 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
1240 const SHORT StopType,
1247 const REAL TOL_s = tol*1e-2;
1250 INT iter = 0, stag = 1, more_step = 1, restart_step = 1;
1251 REAL alpha, beta, omega, temp1, temp2;
1254 REAL reldiff, factor, normd, tempr, normuinf;
1261 REAL *p = work, *z = work + m, *r = z + m, *t = r + m;
1262 REAL *rho = t + m, *pp = rho + m, *s = pp + m, *sp = s + m, *u_best = sp + m;
1265 if ( PrtLvl >
PRINT_NONE ) printf(
"\nCalling Safe BiCGstab solver (STR) ...\n");
1268 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
1269 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
1281 relres = absres0/normr0;
1285 relres = absres0/normr0;
1289 relres = absres0/normu;
1292 printf(
"### ERROR: Unknown stopping type! [%s]\n", __FUNCTION__);
1297 if (relres<tol)
goto FINISHED;
1300 fasp_itinfo(PrtLvl,StopType,iter,relres,absres0,0.0);
1310 while ( iter++ < MaxIt ) {
1324 alpha = temp1/temp2;
1327 ITS_DIVZERO;
goto FINISHED;
1369 beta = (temp1*alpha)/(temp2*omega);
1372 ITS_DIVZERO;
goto RESTORE_BESTSOL;
1384 reldiff = normd/normu;
1386 if ( normd < TOL_s ) {
1387 ITS_SMALLSP;
goto FINISHED;
1394 relres = absres/normr0;
1402 relres = absres/normr0;
1406 relres = absres/normu;
1414 goto RESTORE_BESTSOL;
1417 if ( absres < absres_best - maxdiff) {
1418 absres_best = absres;
1424 factor = absres/absres0;
1427 fasp_itinfo(PrtLvl,StopType,iter,relres,absres,factor);
1431 if ( normuinf <= sol_inf_tol ) {
1438 if ( (stag <= MaxStag) && (reldiff < maxdiff) ) {
1441 ITS_DIFFRES(reldiff,relres);
1464 relres = absres/normr0;
1472 relres = absres/normr0;
1476 relres = absres/normu;
1480 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
1485 if ( stag >= MaxStag ) {
1497 if ( relres < tol ) {
1498 if ( PrtLvl >=
PRINT_MORE ) ITS_COMPRES(relres);
1519 relres = absres/normr0;
1527 relres = tempr/normr0;
1531 relres = absres/normu;
1535 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
1538 if ( relres < tol )
break;
1540 if ( more_step >= MaxRestartStep ) {
1558 if ( iter != iter_best ) {
1564 switch ( StopType ) {
1581 if ( absres > absres_best + maxdiff || isnan(absres) ) {
1582 if ( PrtLvl >
PRINT_NONE ) ITS_RESTORE(iter_best);
1584 relres = absres_best / normr0;
1589 if ( PrtLvl >
PRINT_NONE ) ITS_FINAL(iter,MaxIt,relres);
1595 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
void fasp_darray_cp(const INT n, const REAL *x, REAL *y)
Copy an array to the other y=x.
void fasp_mem_free(void *mem)
Free up previous allocated memory body and set pointer to NULL.
void * fasp_mem_calloc(const unsigned int size, const unsigned int type)
Allocate, initiate, and check memory.
void fasp_itinfo(const INT ptrlvl, const INT stop_type, const INT iter, const REAL relres, const REAL absres, const REAL factor)
Print out iteration information for iterative solvers.
SHORT fasp_dvec_isnan(const dvector *u)
Check a dvector whether there is NAN.
REAL fasp_blas_darray_dotprod(const INT n, const REAL *x, const REAL *y)
Inner product of two arraies x and y.
REAL fasp_blas_darray_norminf(const INT n, const REAL *x)
Linf norm of array x.
void fasp_blas_darray_axpby(const INT n, const REAL a, const REAL *x, const REAL b, REAL *y)
y = a*x + b*y
REAL fasp_blas_darray_norm2(const INT n, const REAL *x)
L2 norm of array x.
void fasp_blas_darray_axpy(const INT n, const REAL a, const REAL *x, REAL *y)
y = a*x + y
void fasp_blas_dblc_mxv(const dBLCmat *A, const REAL *x, REAL *y)
Matrix-vector multiplication y = A*x.
void fasp_blas_dblc_aAxpy(const REAL alpha, const dBLCmat *A, const REAL *x, REAL *y)
Matrix-vector multiplication y = alpha*A*x + y.
void fasp_blas_dbsr_aAxpy(const REAL alpha, const dBSRmat *A, const REAL *x, REAL *y)
Compute y := alpha*A*x + y.
void fasp_blas_dbsr_mxv(const dBSRmat *A, const REAL *x, REAL *y)
Compute y := A*x.
void fasp_blas_dcsr_mxv(const dCSRmat *A, const REAL *x, REAL *y)
Matrix-vector multiplication y = A*x.
void fasp_blas_dcsr_aAxpy(const REAL alpha, const dCSRmat *A, const REAL *x, REAL *y)
Matrix-vector multiplication y = alpha*A*x + y.
void fasp_blas_dstr_aAxpy(const REAL alpha, const dSTRmat *A, const REAL *x, REAL *y)
Matrix-vector multiplication y = alpha*A*x + y.
void fasp_blas_dstr_mxv(const dSTRmat *A, const REAL *x, REAL *y)
Matrix-vector multiplication y = A*x.
INT fasp_solver_dbsr_spbcgs(const dBSRmat *A, const dvector *b, dvector *u, precond *pc, const REAL tol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
Preconditioned BiCGstab method for solving Au=b with safety net.
INT fasp_solver_dstr_spbcgs(const dSTRmat *A, const dvector *b, dvector *u, precond *pc, const REAL tol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
Preconditioned BiCGstab method for solving Au=b with safety net.
INT fasp_solver_dcsr_spbcgs(const dCSRmat *A, const dvector *b, dvector *u, precond *pc, const REAL tol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
Preconditioned BiCGstab method for solving Au=b with safety net.
INT fasp_solver_dblc_spbcgs(const dBLCmat *A, const dvector *b, dvector *u, precond *pc, const REAL tol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
Preconditioned BiCGstab method for solving Au=b with safety net.
Main header file for the FASP project.
#define SHORT
FASP integer and floating point numbers.
#define MAX(a, b)
Definition of max, min, abs.
#define ERROR_SOLVER_STAG
#define ERROR_SOLVER_MAXIT
#define STOP_REL_RES
Definition of iterative solver stopping criteria types.
#define ERROR_SOLVER_SOLSTAG
#define BIGREAL
Some global constants.
#define PRINT_NONE
Print level for all subroutines – not including DEBUG output.
#define ERROR_SOLVER_TOLSMALL
Block REAL CSR matrix format.
Block sparse row storage matrix of REAL type.
Sparse matrix of REAL type in CSR format.
Structure matrix of REAL type.
Vector with n entries of REAL type.
REAL * val
actual vector entries
Preconditioner data and action.
void * data
data for preconditioner, void pointer
void(* fct)(REAL *, REAL *, void *)
action for preconditioner, void function pointer