27#include "fasp_functs.h"
75 INT iter = 0, stag = 1, more_step = 1, restart_step = 1;
78 REAL normu2, normuu, normp, normuinf, factor;
79 REAL alpha, alpha0, alpha1, temp2;
85 REAL *p0=work, *p1=work+m, *p2=p1+m, *z0=p2+m, *z1=z0+m, *t0=z1+m;
86 REAL *t1=t0+m, *t=t1+m, *tp=t+m, *tz=tp+m, *r=tz+m, *u_best = r+m;
89 if ( PrtLvl >
PRINT_NONE ) printf(
"\nCalling Safe MinRes solver (CSR) ...\n");
92 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
93 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
110 switch ( StopType ) {
114 relres = absres0/normr0;
119 relres = absres0/normr0;
124 relres = absres0/normu2;
127 printf(
"### ERROR: Unknown stopping type! [%s]\n", __FUNCTION__);
132 if ( relres < tol )
goto FINISHED;
135 fasp_itinfo(PrtLvl,StopType,iter,relres,absres0,0.0);
164 while ( iter++ < MaxIt ) {
219 switch ( StopType ) {
222 absres = sqrt(temp2);
223 relres = absres/normr0;
231 absres = sqrt(temp2);
232 relres = absres/normr0;
236 absres = sqrt(temp2);
237 relres = absres/normu2;
242 factor = absres/absres0;
245 fasp_itinfo(PrtLvl,StopType,iter,relres,absres,factor);
251 goto RESTORE_BESTSOL;
254 if ( absres < absres_best - maxdiff) {
255 absres_best = absres;
262 if (normuinf <= sol_inf_tol) {
270 normuu =
ABS(alpha)*(normuu/normu2);
272 if ( normuu < maxdiff ) {
274 if ( stag < MaxStag ) {
276 ITS_DIFFRES(normuu,relres);
288 absres = sqrt(temp2);
289 relres = absres/normr0;
297 absres = sqrt(temp2);
298 relres = absres/normr0;
302 absres = sqrt(temp2);
303 relres = absres/normu2;
307 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
312 if ( stag >= MaxStag ) {
357 if ( relres < tol ) {
359 if ( PrtLvl >=
PRINT_MORE ) ITS_COMPRES(relres);
369 absres = sqrt(temp2);
370 relres = absres/normr0;
378 absres = sqrt(temp2);
379 relres = absres/normr0;
383 absres = sqrt(temp2);
384 relres = absres/normu2;
388 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
391 if ( relres < tol )
break;
393 if ( more_step >= MaxRestartStep ) {
445 if ( iter != iter_best ) {
451 switch ( StopType ) {
467 if ( absres > absres_best + maxdiff || isnan(absres) ) {
468 if ( PrtLvl >
PRINT_NONE ) ITS_RESTORE(iter_best);
470 relres = absres_best / normr0;
475 if ( PrtLvl >
PRINT_NONE ) ITS_FINAL(iter,MaxIt,relres);
481 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
517 const SHORT StopType,
526 INT iter = 0, stag = 1, more_step = 1, restart_step = 1;
529 REAL normu2, normuu, normp, normuinf, factor;
530 REAL alpha, alpha0, alpha1, temp2;
536 REAL *p0=work, *p1=work+m, *p2=p1+m, *z0=p2+m, *z1=z0+m, *t0=z1+m;
537 REAL *t1=t0+m, *t=t1+m, *tp=t+m, *tz=tp+m, *r=tz+m, *u_best = r+m;
540 if ( PrtLvl >
PRINT_NONE ) printf(
"\nCalling Safe MinRes solver (BLC) ...\n");
543 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
544 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
561 switch ( StopType ) {
565 relres = absres0/normr0;
570 relres = absres0/normr0;
575 relres = absres0/normu2;
578 printf(
"### ERROR: Unknown stopping type! [%s]\n", __FUNCTION__);
583 if ( relres < tol )
goto FINISHED;
586 fasp_itinfo(PrtLvl,StopType,iter,relres,absres0,0.0);
615 while ( iter++ < MaxIt ) {
670 switch ( StopType ) {
673 absres = sqrt(temp2);
674 relres = absres/normr0;
682 absres = sqrt(temp2);
683 relres = absres/normr0;
687 absres = sqrt(temp2);
688 relres = absres/normu2;
693 factor = absres/absres0;
696 fasp_itinfo(PrtLvl,StopType,iter,relres,absres,factor);
702 goto RESTORE_BESTSOL;
705 if ( absres < absres_best - maxdiff) {
706 absres_best = absres;
713 if (normuinf <= sol_inf_tol) {
721 normuu =
ABS(alpha)*(normuu/normu2);
723 if ( normuu < maxdiff ) {
725 if ( stag < MaxStag ) {
727 ITS_DIFFRES(normuu,relres);
739 absres = sqrt(temp2);
740 relres = absres/normr0;
748 absres = sqrt(temp2);
749 relres = absres/normr0;
753 absres = sqrt(temp2);
754 relres = absres/normu2;
758 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
763 if ( stag >= MaxStag ) {
808 if ( relres < tol ) {
810 if ( PrtLvl >=
PRINT_MORE ) ITS_COMPRES(relres);
820 absres = sqrt(temp2);
821 relres = absres/normr0;
829 absres = sqrt(temp2);
830 relres = absres/normr0;
834 absres = sqrt(temp2);
835 relres = absres/normu2;
839 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
842 if ( relres < tol )
break;
844 if ( more_step >= MaxRestartStep ) {
896 if ( iter != iter_best ) {
902 switch ( StopType ) {
918 if ( absres > absres_best + maxdiff || isnan(absres) ) {
919 if ( PrtLvl >
PRINT_NONE ) ITS_RESTORE(iter_best);
921 relres = absres_best / normr0;
926 if ( PrtLvl >
PRINT_NONE ) ITS_FINAL(iter,MaxIt,relres);
932 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
968 const SHORT StopType,
977 INT iter = 0, stag = 1, more_step = 1, restart_step = 1;
980 REAL normu2, normuu, normp, normuinf, factor;
981 REAL alpha, alpha0, alpha1, temp2;
987 REAL *p0=work, *p1=work+m, *p2=p1+m, *z0=p2+m, *z1=z0+m, *t0=z1+m;
988 REAL *t1=t0+m, *t=t1+m, *tp=t+m, *tz=tp+m, *r=tz+m, *u_best = r+m;
991 if ( PrtLvl >
PRINT_NONE ) printf(
"\nCalling Safe MinRes solver (STR) ...\n");
994 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
995 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
1012 switch ( StopType ) {
1016 relres = absres0/normr0;
1021 relres = absres0/normr0;
1026 relres = absres0/normu2;
1029 printf(
"### ERROR: Unknown stopping type! [%s]\n", __FUNCTION__);
1034 if ( relres < tol )
goto FINISHED;
1037 fasp_itinfo(PrtLvl,StopType,iter,relres,absres0,0.0);
1050 normp = sqrt(normp);
1066 while ( iter++ < MaxIt ) {
1101 normp = sqrt(normp);
1121 switch ( StopType ) {
1124 absres = sqrt(temp2);
1125 relres = absres/normr0;
1133 absres = sqrt(temp2);
1134 relres = absres/normr0;
1138 absres = sqrt(temp2);
1139 relres = absres/normu2;
1144 factor = absres/absres0;
1147 fasp_itinfo(PrtLvl,StopType,iter,relres,absres,factor);
1153 goto RESTORE_BESTSOL;
1156 if ( absres < absres_best - maxdiff) {
1157 absres_best = absres;
1164 if (normuinf <= sol_inf_tol) {
1172 normuu =
ABS(alpha)*(normuu/normu2);
1174 if ( normuu < maxdiff ) {
1176 if ( stag < MaxStag ) {
1178 ITS_DIFFRES(normuu,relres);
1190 absres = sqrt(temp2);
1191 relres = absres/normr0;
1199 absres = sqrt(temp2);
1200 relres = absres/normr0;
1204 absres = sqrt(temp2);
1205 relres = absres/normu2;
1209 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
1214 if ( stag >= MaxStag ) {
1240 normp = sqrt(normp);
1259 if ( relres < tol ) {
1261 if ( PrtLvl >=
PRINT_MORE ) ITS_COMPRES(relres);
1271 absres = sqrt(temp2);
1272 relres = absres/normr0;
1280 absres = sqrt(temp2);
1281 relres = absres/normr0;
1285 absres = sqrt(temp2);
1286 relres = absres/normu2;
1290 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
1293 if ( relres < tol )
break;
1295 if ( more_step >= MaxRestartStep ) {
1323 normp = sqrt(normp);
1347 if ( iter != iter_best ) {
1353 switch ( StopType ) {
1369 if ( absres > absres_best + maxdiff || isnan(absres) ) {
1370 if ( PrtLvl >
PRINT_NONE ) ITS_RESTORE(iter_best);
1372 relres = absres_best / normr0;
1377 if ( PrtLvl >
PRINT_NONE ) ITS_FINAL(iter,MaxIt,relres);
1383 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
void fasp_darray_set(const INT n, REAL *x, const REAL val)
Set initial value for an array to be x=val.
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.
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_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_dcsr_spminres(const dCSRmat *A, const dvector *b, dvector *u, precond *pc, const REAL tol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
A preconditioned minimal residual (Minres) method for solving Au=b with safety net.
INT fasp_solver_dstr_spminres(const dSTRmat *A, const dvector *b, dvector *u, precond *pc, const REAL tol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
A preconditioned minimal residual (Minres) method for solving Au=b with safety net.
INT fasp_solver_dblc_spminres(const dBLCmat *A, const dvector *b, dvector *u, precond *pc, const REAL tol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
A preconditioned minimal residual (Minres) 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.
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