28#include "fasp_functs.h"
70 INT iter=0, stag = 1, moresteps = 1, maxmsteps=1;
71 INT flag, maxstagsteps, half_step=0;
73 REAL alpha,beta,omega,rho,rho1,rtv,tt;
74 REAL normr,normr_act,normph,normx,imin;
75 REAL norm_sh,norm_xhalf,normrmin,factor;
80 REAL *r=work, *rt=r+m, *p=rt+m, *v=p+m;
81 REAL *ph=v+m, *xhalf=ph+m, *s=xhalf+m, *sh=s+m;
82 REAL *t = sh+m, *xmin = t+m;
85 if ( PrtLvl >
PRINT_NONE ) printf(
"\nCalling BiCGstab solver (CSR) ...\n");
88 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
89 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
110 if ( normr <= tolb ) {
133 for (iter=1;iter <= MaxIt;iter++) {
138 if ((rho ==0.0 )|| (
ABS(rho) >= DBL_MAX )) {
147 beta = (rho/rho1)*(alpha/omega);
149 if ((beta == 0)||(
ABS(beta) > DBL_MAX )) {
170 if (( rtv==0.0 )||(
ABS(rtv) > DBL_MAX )){
177 if (
ABS(alpha) > DBL_MAX ){
185 if (
ABS(alpha)*normph < DBL_EPSILON*normx )
199 factor = absres/absres0;
200 fasp_itinfo(PrtLvl,StopType,iter,normr_act/n2b,absres,factor);
203 if ((normr <= tolb)||(stag >= maxstagsteps)||moresteps)
209 if (normr_act <= tolb) {
216 printf(
"Flag = %d Stag = %d Itermin = %.1f Half_step = %d\n",
217 flag,stag,imin,half_step);
221 if ((stag >= maxstagsteps) && (moresteps == 0)) stag = 0;
223 moresteps = moresteps + 1;
224 if (moresteps >= maxmsteps) {
233 if ( stag >= maxstagsteps ) {
238 if ( normr_act < normrmin )
240 normrmin = normr_act;
245 printf(
"Flag = %d Stag = %d Itermin = %.1f Half_step = %d\n",
246 flag,stag,imin,half_step);
260 if ( (tt == 0) ||( tt >= DBL_MAX ) ) {
267 if (
ABS(omega) > DBL_MAX ) {
275 if (
ABS(omega)*norm_sh < DBL_EPSILON*norm_xhalf )
286 if ( (normr <= tolb) || (stag >= maxstagsteps) || moresteps )
291 if ( normr_act <= tolb ) {
296 if ((stag >= maxstagsteps) && (moresteps == 0)) stag = 0;
298 moresteps = moresteps + 1;
299 if ( moresteps >= maxmsteps ) {
307 if ( normr_act < normrmin ) {
308 normrmin = normr_act;
313 if ( stag >= maxstagsteps ) {
318 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
326 relres = normr_act / n2b;
332 if ( normr <= normr_act) {
338 relres = normr_act/n2b;
342 if ( PrtLvl >
PRINT_NONE ) ITS_FINAL(iter,MaxIt,relres);
345 printf(
"Flag = %d Stag = %d Itermin = %.1f Half_step = %d\n",
346 flag,stag,imin,half_step);
352 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
384 const REAL tol,
const REAL abstol,
const INT MaxIt,
391 INT iter=0, stag = 1, moresteps = 1, maxmsteps=1;
392 INT flag, maxstagsteps, half_step=0;
394 REAL alpha,beta,omega,rho,rho1,rtv,tt;
395 REAL normr,normr_act,normph,normx,imin;
396 REAL norm_sh,norm_xhalf,normrmin,factor;
401 REAL *r=work, *rt=r+m, *p=rt+m, *v=p+m;
402 REAL *ph=v+m, *xhalf=ph+m, *s=xhalf+m, *sh=s+m;
403 REAL *t = sh+m, *xmin = t+m;
406 if ( PrtLvl >
PRINT_NONE ) printf(
"\nCalling BiCGstab solver (BSR) ...\n");
409 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
410 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
431 if ( normr <= tolb ) {
454 for (iter=1;iter <= MaxIt;iter++) {
459 if ((rho ==0.0 )|| (
ABS(rho) >= DBL_MAX )) {
468 beta = (rho/rho1)*(alpha/omega);
470 if ((beta == 0)||(
ABS(beta) > DBL_MAX )) {
491 if (( rtv==0.0 )||(
ABS(rtv) > DBL_MAX )) {
498 if (
ABS(alpha) > DBL_MAX ) {
506 if (
ABS(alpha)*normph < DBL_EPSILON*normx )
520 factor = absres/absres0;
521 fasp_itinfo(PrtLvl,StopType,iter,normr_act/n2b,absres,factor);
524 if ((normr <= tolb)||(stag >= maxstagsteps)||moresteps)
530 if (normr_act <= tolb) {
537 printf(
"Flag = %d Stag = %d Itermin = %.1f Half_step = %d\n",
538 flag,stag,imin,half_step);
542 if ((stag >= maxstagsteps) && (moresteps == 0)) stag = 0;
544 moresteps = moresteps + 1;
545 if (moresteps >= maxmsteps){
554 if ( stag >= maxstagsteps ) {
559 if ( normr_act < normrmin )
561 normrmin = normr_act;
566 printf(
"Flag = %d Stag = %d Itermin = %.1f Half_step = %d\n",
567 flag,stag,imin,half_step);
581 if ( (tt == 0) ||( tt >= DBL_MAX ) ) {
588 if (
ABS(omega) > DBL_MAX ) {
596 if (
ABS(omega)*norm_sh < DBL_EPSILON*norm_xhalf )
607 if ( (normr <= tolb) || (stag >= maxstagsteps) || moresteps )
612 if ( normr_act <= tolb ) {
617 if ((stag >= maxstagsteps) && (moresteps == 0)) stag = 0;
619 moresteps = moresteps + 1;
620 if ( moresteps >= maxmsteps ) {
628 if ( normr_act < normrmin ) {
629 normrmin = normr_act;
634 if ( stag >= maxstagsteps )
640 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
648 relres = normr_act / n2b;
654 if ( normr <= normr_act) {
660 relres = normr_act/n2b;
664 if ( PrtLvl >
PRINT_NONE ) ITS_FINAL(iter,MaxIt,relres);
667 printf(
"Flag = %d Stag = %d Itermin = %.1f Half_step = %d\n",
668 flag,stag,imin,half_step);
674 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
706 const REAL tol,
const REAL abstol,
const INT MaxIt,
713 INT iter=0, stag = 1, moresteps = 1, maxmsteps=1;
714 INT flag, maxstagsteps, half_step=0;
716 REAL alpha,beta,omega,rho,rho1,rtv,tt;
717 REAL normr,normr_act,normph,normx,imin;
718 REAL norm_sh,norm_xhalf,normrmin,factor;
723 REAL *r=work, *rt=r+m, *p=rt+m, *v=p+m;
724 REAL *ph=v+m, *xhalf=ph+m, *s=xhalf+m, *sh=s+m;
725 REAL *t = sh+m, *xmin = t+m;
728 if ( PrtLvl >
PRINT_NONE ) printf(
"\nCalling BiCGstab solver (BLC) ...\n");
731 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
732 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
753 if ( normr <= tolb ) {
776 for (iter=1;iter <= MaxIt;iter++) {
781 if ((rho ==0.0 )|| (
ABS(rho) >= DBL_MAX )) {
790 beta = (rho/rho1)*(alpha/omega);
792 if ((beta == 0)||(
ABS(beta) > DBL_MAX )) {
813 if (( rtv==0.0 )||(
ABS(rtv) > DBL_MAX )) {
820 if (
ABS(alpha) > DBL_MAX ) {
828 if (
ABS(alpha)*normph < DBL_EPSILON*normx )
842 factor = absres/absres0;
843 fasp_itinfo(PrtLvl,StopType,iter,normr_act/n2b,absres,factor);
846 if ((normr <= tolb)||(stag >= maxstagsteps)||moresteps)
852 if (normr_act <= tolb) {
859 printf(
"Flag = %d Stag = %d Itermin = %.1f Half_step = %d\n",
860 flag,stag,imin,half_step);
864 if ((stag >= maxstagsteps) && (moresteps == 0)) stag = 0;
866 moresteps = moresteps + 1;
867 if (moresteps >= maxmsteps) {
876 if ( stag >= maxstagsteps ) {
881 if ( normr_act < normrmin )
883 normrmin = normr_act;
888 printf(
"Flag = %d Stag = %d Itermin = %.1f Half_step = %d\n",
889 flag,stag,imin,half_step);
903 if ( (tt == 0) ||( tt >= DBL_MAX ) ) {
910 if (
ABS(omega) > DBL_MAX ) {
918 if (
ABS(omega)*norm_sh < DBL_EPSILON*norm_xhalf )
929 if ( (normr <= tolb) || (stag >= maxstagsteps) || moresteps )
934 if ( normr_act <= tolb ) {
939 if ((stag >= maxstagsteps) && (moresteps == 0)) stag = 0;
941 moresteps = moresteps + 1;
942 if ( moresteps >= maxmsteps ) {
950 if ( normr_act < normrmin ) {
951 normrmin = normr_act;
956 if ( stag >= maxstagsteps )
962 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
970 relres = normr_act / n2b;
976 if ( normr <= normr_act) {
982 relres = normr_act/n2b;
986 if ( PrtLvl >
PRINT_NONE ) ITS_FINAL(iter,MaxIt,relres);
989 printf(
"Flag = %d Stag = %d Itermin = %.1f Half_step = %d\n",
990 flag,stag,imin,half_step);
996 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
1028 const REAL tol,
const REAL abstol,
const INT MaxIt,
1035 INT iter=0, stag = 1, moresteps = 1, maxmsteps=1;
1036 INT flag, maxstagsteps, half_step=0;
1038 REAL alpha,beta,omega,rho,rho1,rtv,tt;
1039 REAL normr,normr_act,normph,normx,imin;
1040 REAL norm_sh,norm_xhalf,normrmin,factor;
1045 REAL *r=work, *rt=r+m, *p=rt+m, *v=p+m;
1046 REAL *ph=v+m, *xhalf=ph+m, *s=xhalf+m, *sh=s+m;
1047 REAL *t = sh+m, *xmin = t+m;
1050 if ( PrtLvl >
PRINT_NONE ) printf(
"\nCalling BiCGstab solver (STR) ...\n");
1053 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
1054 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
1075 if ( normr <= tolb ) {
1098 for (iter=1;iter <= MaxIt;iter++) {
1103 if ((rho ==0.0 )|| (
ABS(rho) >= DBL_MAX )) {
1112 beta = (rho/rho1)*(alpha/omega);
1114 if ((beta == 0)||(
ABS(beta) > DBL_MAX )) {
1135 if (( rtv==0.0 )||(
ABS(rtv) > DBL_MAX )) {
1142 if (
ABS(alpha) > DBL_MAX ) {
1150 if (
ABS(alpha)*normph < DBL_EPSILON*normx )
1164 factor = absres/absres0;
1165 fasp_itinfo(PrtLvl,StopType,iter,normr_act/n2b,absres,factor);
1168 if ((normr <= tolb)||(stag >= maxstagsteps)||moresteps)
1174 if (normr_act <= tolb){
1181 printf(
"Flag = %d Stag = %d Itermin = %.1f Half_step = %d\n",
1182 flag,stag,imin,half_step);
1186 if ((stag >= maxstagsteps) && (moresteps == 0)) stag = 0;
1188 moresteps = moresteps + 1;
1189 if (moresteps >= maxmsteps){
1198 if ( stag >= maxstagsteps ) {
1203 if ( normr_act < normrmin )
1205 normrmin = normr_act;
1210 printf(
"Flag = %d Stag = %d Itermin = %.1f Half_step = %d\n",
1211 flag,stag,imin,half_step);
1225 if ( (tt == 0) ||( tt >= DBL_MAX ) ) {
1232 if (
ABS(omega) > DBL_MAX ) {
1240 if (
ABS(omega)*norm_sh < DBL_EPSILON*norm_xhalf )
1251 if ( (normr <= tolb) || (stag >= maxstagsteps) || moresteps )
1256 if ( normr_act <= tolb ) {
1261 if ((stag >= maxstagsteps) && (moresteps == 0)) stag = 0;
1263 moresteps = moresteps + 1;
1264 if ( moresteps >= maxmsteps ) {
1272 if ( normr_act < normrmin ) {
1273 normrmin = normr_act;
1278 if ( stag >= maxstagsteps )
1284 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
1292 relres = normr_act / n2b;
1298 if ( normr <= normr_act ) {
1304 relres = normr_act/n2b;
1308 if ( PrtLvl >
PRINT_NONE ) ITS_FINAL(iter,MaxIt,relres);
1311 printf(
"Flag = %d Stag = %d Itermin = %.1f Half_step = %d\n",
1312 flag,stag,imin,half_step);
1318 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
1350 const REAL tol,
const REAL abstol,
const INT MaxIt,
1357 INT iter=0, stag = 1, moresteps = 1, maxmsteps=1;
1358 INT flag, maxstagsteps, half_step=0;
1360 REAL alpha,beta,omega,rho,rho1,rtv,tt;
1361 REAL normr,normr_act,normph,normx,imin;
1362 REAL norm_sh,norm_xhalf,normrmin,factor;
1367 REAL *r=work, *rt=r+m, *p=rt+m, *v=p+m;
1368 REAL *ph=v+m, *xhalf=ph+m, *s=xhalf+m, *sh=s+m;
1369 REAL *t = sh+m, *xmin = t+m;
1372 if ( PrtLvl >
PRINT_NONE ) printf(
"\nCalling BiCGstab solver (MatFree) ...\n");
1375 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
1376 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
1399 if (normr <= tolb) {
1423 for (iter=1;iter <= MaxIt;iter++) {
1428 if ((rho ==0.0 )|| (
ABS(rho) >= DBL_MAX )) {
1437 beta = (rho/rho1)*(alpha/omega);
1439 if ((beta == 0)||(
ABS(beta) > DBL_MAX )) {
1460 if (( rtv==0.0 )||(
ABS(rtv) > DBL_MAX )) {
1467 if (
ABS(alpha) > DBL_MAX ) {
1475 if (
ABS(alpha)*normph < DBL_EPSILON*normx )
1489 factor = absres/absres0;
1490 fasp_itinfo(PrtLvl,StopType,iter,normr_act/n2b,absres,factor);
1493 if ((normr <= tolb)||(stag >= maxstagsteps)||moresteps)
1500 if (normr_act <= tolb){
1507 printf(
"Flag = %d Stag = %d Itermin = %.1f Half_step = %d\n",
1508 flag,stag,imin,half_step);
1512 if ((stag >= maxstagsteps) && (moresteps == 0)) stag = 0;
1514 moresteps = moresteps + 1;
1515 if (moresteps >= maxmsteps){
1524 if ( stag >= maxstagsteps ) {
1529 if ( normr_act < normrmin )
1531 normrmin = normr_act;
1536 printf(
"Flag = %d Stag = %d Itermin = %.1f Half_step = %d\n",
1537 flag,stag,imin,half_step);
1552 if ((tt == 0) ||( tt >= DBL_MAX )) {
1559 if (
ABS(omega) > DBL_MAX )
1568 if (
ABS(omega)*norm_sh < DBL_EPSILON*norm_xhalf )
1579 if ( (normr <= tolb)||(stag >= maxstagsteps)||moresteps )
1586 if (normr_act <= tolb)
1593 if ((stag >= maxstagsteps) && (moresteps == 0)) stag = 0;
1595 moresteps = moresteps + 1;
1596 if (moresteps >= maxmsteps)
1604 if (normr_act < normrmin)
1606 normrmin = normr_act;
1611 if (stag >= maxstagsteps)
1617 if ( PrtLvl >=
PRINT_MORE ) ITS_REALRES(relres);
1625 relres = normr_act / n2b;
1632 if ( normr <= normr_act ) {
1638 relres = normr_act/n2b;
1642 if ( PrtLvl >
PRINT_NONE ) ITS_FINAL(iter,MaxIt,relres);
1645 printf(
"Flag = %d Stag = %d Itermin = %.1f Half_step = %d\n",
1646 flag,stag,imin,half_step);
1652 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.
REAL fasp_blas_darray_dotprod(const INT n, const REAL *x, const REAL *y)
Inner product of two arraies x and y.
void fasp_blas_darray_axpyz(const INT n, const REAL a, const REAL *x, const REAL *y, REAL *z)
z = a*x + y
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_pbcgs(dBSRmat *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 BSR matrix.
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.
INT fasp_solver_dcsr_pbcgs(dCSRmat *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 CSR matrix.
INT fasp_solver_dblc_pbcgs(dBLCmat *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 BLC matrix.
INT fasp_solver_pbcgs(mxv_matfree *mf, 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.
Main header file for the FASP project.
#define SHORT
FASP integer and floating point numbers.
#define ERROR_SOLVER_MAXIT
#define BIGREAL
Some global constants.
#define PRINT_NONE
Print level for all subroutines – not including DEBUG output.
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
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