24#include "fasp_functs.h"
71 INT iter = 0, stag = 1, more_step = 1, restart_step = 1;
74 REAL normu2, normuu, normp, infnormu, factor;
75 REAL alpha, alpha0, alpha1, temp2;
79 REAL *p0=work, *p1=work+m, *p2=p1+m, *z0=p2+m, *z1=z0+m;
80 REAL *t0=z1+m, *t1=t0+m, *t=t1+m, *tp=t+m, *tz=tp+m, *r=tz+m;
83 if ( PrtLvl >
PRINT_NONE ) printf(
"\nCalling MinRes solver (CSR) ...\n");
86 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
87 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
104 switch ( StopType ) {
108 relres = absres0/normr0;
113 relres = absres0/normr0;
118 relres = absres0/normu2;
121 printf(
"### ERROR: Unknown stopping type! [%s]\n", __FUNCTION__);
126 if ( relres < tol || absres0 < abstol )
goto FINISHED;
129 fasp_itinfo(PrtLvl,StopType,iter,relres,absres0,0.0);
158 while ( iter++ < MaxIt ) {
213 switch ( StopType ) {
216 absres = sqrt(temp2);
217 relres = absres/normr0;
225 absres = sqrt(temp2);
226 relres = absres/normr0;
230 absres = sqrt(temp2);
231 relres = absres/normu2;
236 factor = absres/absres0;
239 fasp_itinfo(PrtLvl,StopType,iter,relres,absres,factor);
241 if ( factor > 0.9 ) {
245 if (infnormu <= sol_inf_tol) {
253 normuu =
ABS(alpha)*(normuu/normu2);
255 if ( normuu < maxdiff ) {
257 if ( stag < MaxStag ) {
259 ITS_DIFFRES(normuu,relres);
271 absres = sqrt(temp2);
272 relres = absres/normr0;
280 absres = sqrt(temp2);
281 relres = absres/normr0;
285 absres = sqrt(temp2);
286 relres = absres/normu2;
290 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
295 if ( stag >= MaxStag ) {
342 if ( relres < tol ) {
344 if ( PrtLvl >=
PRINT_MORE ) ITS_COMPRES(relres);
354 absres = sqrt(temp2);
355 relres = absres/normr0;
363 absres = sqrt(temp2);
364 relres = absres/normr0;
368 absres = sqrt(temp2);
369 relres = absres/normu2;
373 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
376 if ( relres < tol )
break;
378 if ( more_step >= MaxRestartStep ) {
430 if ( PrtLvl >
PRINT_NONE ) ITS_FINAL(iter,MaxIt,relres);
436 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
471 const REAL tol,
const REAL abstol,
const INT MaxIt,
480 INT iter = 0, stag = 1, more_step = 1, restart_step = 1;
483 REAL normu2, normuu, normp, infnormu, factor;
484 REAL alpha, alpha0, alpha1, temp2;
488 REAL *p0=work, *p1=work+m, *p2=p1+m, *z0=p2+m, *z1=z0+m;
489 REAL *t0=z1+m, *t1=t0+m, *t=t1+m, *tp=t+m, *tz=tp+m, *r=tz+m;
492 if ( PrtLvl >
PRINT_NONE ) printf(
"\nCalling MinRes solver (BLC) ...\n");
495 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
496 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
513 switch ( StopType ) {
517 relres = absres0/normr0;
522 relres = absres0/normr0;
527 relres = absres0/normu2;
530 printf(
"### ERROR: Unknown stopping type! [%s]\n", __FUNCTION__);
535 if ( relres < tol || absres0 < abstol )
goto FINISHED;
538 fasp_itinfo(PrtLvl,StopType,iter,relres,absres0,0.0);
567 while ( iter++ < MaxIt ) {
622 switch ( StopType ) {
625 absres = sqrt(temp2);
626 relres = absres/normr0;
634 absres = sqrt(temp2);
635 relres = absres/normr0;
639 absres = sqrt(temp2);
640 relres = absres/normu2;
645 factor = absres/absres0;
648 fasp_itinfo(PrtLvl,StopType,iter,relres,absres,factor);
650 if ( factor > 0.9 ) {
654 if (infnormu <= sol_inf_tol) {
662 normuu =
ABS(alpha)*(normuu/normu2);
664 if ( normuu < maxdiff ) {
666 if ( stag < MaxStag ) {
668 ITS_DIFFRES(normuu,relres);
680 absres = sqrt(temp2);
681 relres = absres/normr0;
689 absres = sqrt(temp2);
690 relres = absres/normr0;
694 absres = sqrt(temp2);
695 relres = absres/normu2;
699 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
704 if ( stag >= MaxStag ) {
751 if ( relres < tol ) {
753 if ( PrtLvl >=
PRINT_MORE ) ITS_COMPRES(relres);
763 absres = sqrt(temp2);
764 relres = absres/normr0;
772 absres = sqrt(temp2);
773 relres = absres/normr0;
777 absres = sqrt(temp2);
778 relres = absres/normu2;
782 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
785 if ( relres < tol )
break;
787 if ( more_step >= MaxRestartStep ) {
839 if ( PrtLvl >
PRINT_NONE ) ITS_FINAL(iter,MaxIt,relres);
845 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
877 const REAL tol,
const REAL abstol,
const INT MaxIt,
886 INT iter = 0, stag = 1, more_step = 1, restart_step = 1;
889 REAL normu2, normuu, normp, infnormu, factor;
890 REAL alpha, alpha0, alpha1, temp2;
894 REAL *p0=work, *p1=work+m, *p2=p1+m, *z0=p2+m, *z1=z0+m;
895 REAL *t0=z1+m, *t1=t0+m, *t=t1+m, *tp=t+m, *tz=tp+m, *r=tz+m;
898 if ( PrtLvl >
PRINT_NONE ) printf(
"\nCalling MinRes solver (STR) ...\n");
901 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
902 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
919 switch ( StopType ) {
923 relres = absres0/normr0;
928 relres = absres0/normr0;
933 relres = absres0/normu2;
936 printf(
"### ERROR: Unknown stopping type! [%s]\n", __FUNCTION__);
941 if ( relres < tol || absres0 < abstol )
goto FINISHED;
944 fasp_itinfo(PrtLvl,StopType,iter,relres,absres0,0.0);
973 while ( iter++ < MaxIt ) {
1008 normp = sqrt(normp);
1028 switch ( StopType ) {
1031 absres = sqrt(temp2);
1032 relres = absres/normr0;
1040 absres = sqrt(temp2);
1041 relres = absres/normr0;
1045 absres = sqrt(temp2);
1046 relres = absres/normu2;
1051 factor = absres/absres0;
1054 fasp_itinfo(PrtLvl,StopType,iter,relres,absres,factor);
1056 if ( factor > 0.9 ) {
1060 if (infnormu <= sol_inf_tol) {
1068 normuu =
ABS(alpha)*(normuu/normu2);
1070 if ( normuu < maxdiff ) {
1072 if ( stag < MaxStag ) {
1074 ITS_DIFFRES(normuu,relres);
1086 absres = sqrt(temp2);
1087 relres = absres/normr0;
1095 absres = sqrt(temp2);
1096 relres = absres/normr0;
1100 absres = sqrt(temp2);
1101 relres = absres/normu2;
1105 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
1110 if ( stag >= MaxStag ) {
1136 normp = sqrt(normp);
1156 if ( relres < tol ) {
1158 if ( PrtLvl >=
PRINT_MORE ) ITS_COMPRES(relres);
1168 absres = sqrt(temp2);
1169 relres = absres/normr0;
1177 absres = sqrt(temp2);
1178 relres = absres/normr0;
1182 absres = sqrt(temp2);
1183 relres = absres/normu2;
1187 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
1190 if ( relres < tol )
break;
1192 if ( more_step >= MaxRestartStep ) {
1220 normp = sqrt(normp);
1244 if ( PrtLvl >
PRINT_NONE ) ITS_FINAL(iter,MaxIt,relres);
1250 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
1284 const REAL tol,
const REAL abstol,
const INT MaxIt,
1293 INT iter = 0, stag = 1, more_step = 1, restart_step = 1;
1296 REAL normu2, normuu, normp, infnormu, factor;
1297 REAL alpha, alpha0, alpha1, temp2;
1301 REAL *p0=work, *p1=work+m, *p2=p1+m, *z0=p2+m, *z1=z0+m;
1302 REAL *t0=z1+m, *t1=t0+m, *t=t1+m, *tp=t+m, *tz=tp+m, *r=tz+m;
1305 if ( PrtLvl >
PRINT_NONE ) printf(
"\nCalling MinRes solver (MatFree) ...\n");
1308 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
1309 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
1313 stag=1; more_step=1; restart_step=1;
1333 relres=absres0/normr0;
1338 relres=absres0/normu2;
1343 relres=absres0/normr0;
1348 if ( relres < tol || absres0 < abstol )
goto FINISHED;
1376 while( iter++ < MaxIt) {
1441 relres=sqrt(temp2)/normr0;
1444 relres=sqrt(temp2)/normu2;
1447 relres=sqrt(temp2)/normr0;
1452 factor=absres/absres0;
1455 fasp_itinfo(PrtLvl,StopType,iter,relres,absres,factor);
1459 if ( infnormu <= sol_inf_tol ) {
1466 normuu=
ABS(alpha)*(normuu/normu2);
1469 if (normuu<maxdiff) {
1470 if ( stag < MaxStag ) {
1472 ITS_DIFFRES(normuu,relres);
1484 relres=sqrt(temp2)/normr0;
1492 relres=sqrt(temp2)/normr0;
1495 relres=sqrt(temp2)/normu2;
1499 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
1504 if ( stag >= MaxStag ) {
1550 if ( relres < tol ) {
1551 if ( PrtLvl >=
PRINT_MORE ) ITS_COMPRES(relres);
1560 relres=sqrt(temp2)/normr0;
1568 relres=sqrt(temp2)/normr0;
1571 relres=sqrt(temp2)/normu2;
1575 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
1578 if ( relres < tol )
break;
1580 if ( more_step >= MaxRestartStep ) {
1586 if ( more_step < MaxRestartStep ) {
1635 if ( PrtLvl >
PRINT_NONE ) ITS_FINAL(iter,MaxIt,relres);
1641 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.
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_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_pminres(dCSRmat *A, dvector *b, dvector *u, precond *pc, const REAL tol, const REAL abstol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
A preconditioned minimal residual (Minres) method for solving Au=b.
INT fasp_solver_pminres(mxv_matfree *mf, dvector *b, dvector *u, precond *pc, const REAL tol, const REAL abstol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
A preconditioned minimal residual (Minres) method for solving Au=b.
INT fasp_solver_dblc_pminres(dBLCmat *A, dvector *b, dvector *u, precond *pc, const REAL tol, const REAL abstol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
A preconditioned minimal residual (Minres) method for solving Au=b.
INT fasp_solver_dstr_pminres(dSTRmat *A, dvector *b, dvector *u, precond *pc, const REAL tol, const REAL abstol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
A preconditioned minimal residual (Minres) method for solving Au=b.
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
Matrix-vector multiplication, replace the actual matrix.
void * data
data for MxV, can be a Matrix or something else
void(* fct)(const void *, const REAL *, REAL *)
action for MxV, void function pointer
Preconditioner data and action.
void * data
data for preconditioner, void pointer
void(* fct)(REAL *, REAL *, void *)
action for preconditioner, void function pointer