23#include "fasp_functs.h"
29#include "PreMGRecurAMLI.inl"
30#include "PreMGSmoother.inl"
31#include "PreMGUtil.inl"
67 const REAL tol = param->
tol * 1e-4;
75 dvector *b1 = &mgl[l + 1].
b, *e1 = &mgl[l + 1].
x;
94 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
95 printf(
"### DEBUG: n=%d, nnz=%d\n", mgl[0].A.row, mgl[0].
A.
nnz);
98 if (prtlvl >=
PRINT_MOST) printf(
"AMLI level %d, smoother %d.\n", l, smoother);
100 if (l < mgl[l].num_levels - 1) {
103 if (l < mgl[l].ILU_levels) {
109 else if (l < mgl->SWZ_levels) {
111 switch (mgl[l].Schwarz.SWZ_type) {
129 fasp_smoother_dcsr_gs_multicolor(&mgl[l].x, &mgl[l].A, &mgl[l].b,
132 fasp_dcsr_presmoothing(smoother, A0, b0, e0, param->
presmooth_iter, 0,
133 m0 - 1, 1, relax, ndeg, smooth_order, ordering);
157 for (i = 1; i <= degree; i++) {
177 alpha =
MIN(alpha, 1.0);
191 if (l < mgl[l].ILU_levels) {
197 else if (l < mgl->SWZ_levels) {
199 switch (mgl[l].Schwarz.SWZ_type) {
215 fasp_smoother_dcsr_gs_multicolor(&mgl[l].x, &mgl[l].A, &mgl[l].b,
218 fasp_dcsr_postsmoothing(smoother, A0, b0, e0, param->
postsmooth_iter, 0,
219 m0 - 1, -1, relax, ndeg, smooth_order, ordering);
227 switch (coarse_solver) {
233 fasp_pardiso_solve(A0, b0, e0, &mgl[l].pdata, 0);
248 fasp_umfpack_solve(A0, b0, e0, mgl[l].Numeric, 0);
262 fasp_coarse_itsolver(A0, b0, e0, tol, prtlvl);
267 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
299 const REAL tol = param->
tol * 1e-4;
302 dvector *b0 = &mgl[l].
b, *e0 = &mgl[l].
x;
303 dvector *b1 = &mgl[l + 1].
b, *e1 = &mgl[l + 1].
x;
316 uH.
val = mgl[l + 1].
w.
val + m1;
323 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
324 printf(
"### DEBUG: n=%d, nnz=%d\n", mgl[0].A.row, mgl[0].
A.
nnz);
328 printf(
"Nonlinear AMLI level %d, smoother %d.\n", num_levels, smoother);
330 if (l < num_levels - 1) {
333 if (l < mgl[l].ILU_levels) {
339 else if (l < mgl->SWZ_levels) {
341 switch (mgl[l].Schwarz.SWZ_type) {
359 fasp_smoother_dcsr_gs_multicolor(&mgl[l].x, &mgl[l].A, &mgl[l].b,
362 fasp_dcsr_presmoothing(smoother, A0, b0, e0, param->
presmooth_iter, 0,
363 m0 - 1, 1, relax, ndeg, smooth_order, ordering);
385 if (mgl[l + 1].cycle_type <= 1) {
408 Kcycle_dcsr_pgcg(A1, b1, &uH, &pc);
411 Kcycle_dcsr_pgcr(A1, b1, &uH, &pc);
428 if (l < mgl[l].ILU_levels) {
432 }
else if (l < mgl->SWZ_levels) {
434 switch (mgl[l].Schwarz.SWZ_type) {
450 fasp_smoother_dcsr_gs_multicolor(&mgl[l].x, &mgl[l].A, &mgl[l].b,
453 fasp_dcsr_postsmoothing(smoother, A0, b0, e0, param->
postsmooth_iter, 0,
454 m0 - 1, -1, relax, ndeg, smooth_order, ordering);
462 switch (coarse_solver) {
468 fasp_pardiso_solve(A0, b0, e0, &mgl[l].pdata, 0);
483 fasp_umfpack_solve(A0, b0, e0, mgl[l].Numeric, 0);
497 fasp_coarse_itsolver(A0, b0, e0, tol, prtlvl);
502 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
537 dvector *b0 = &mgl[l].
b, *e0 = &mgl[l].
x;
538 dvector *b1 = &mgl[l + 1].
b, *e1 = &mgl[l + 1].
x;
549 uH.
val = mgl[l + 1].
w.
val + m1;
551 bH.
val = mgl[l + 1].
w.
val + 2 * m1;
554 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
555 printf(
"### DEBUG: n=%d, nnz=%d\n", mgl[0].A.ROW, mgl[0].
A.
NNZ);
563 printf(
"Nonlinear AMLI: level %d, smoother %d.\n", l, smoother);
565 if (l < num_levels - 1) {
570 if (l < param->ILU_levels) {
578 for (i = 0; i < steps; i++)
587 for (i = 0; i < steps; i++)
588#
if BAMG_GS0_DiagInv || 1
595 for (i = 0; i < steps; i++)
602 for (i = 0; i < steps; i++)
605 mgl[l].diaginv.val, relax);
608 printf(
"### ERROR: Unknown smoother type %d!\n", smoother);
629 if (l == num_levels - 2) {
661 param->
tol * 1e-8, maxit,
MIN(maxit, 30), 1,
677 if (l < param->ILU_levels) {
685 for (i = 0; i < steps; i++)
695 for (i = 0; i < steps; i++)
696#
if BAMG_GS0_DiagInv || 1
703 for (i = 0; i < steps; i++)
710 for (i = 0; i < steps; i++)
713 mgl[l].diaginv.val, relax);
716 printf(
"### ERROR: Unknown smoother type %d!\n", smoother);
730 switch (coarse_solver) {
736 fasp_pardiso_solve(&mgl[l].Ac, b0, e0, &mgl[l].pdata, 0);
751 fasp_umfpack_solve(&mgl[l].Ac, b0, e0, mgl[l].Numeric, 0);
765 fasp_coarse_itsolver(&mgl[l].Ac, b0, e0, tol, prtlvl);
773 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
792 const REAL lambda_min,
796 const REAL mu0 = 1.0 / lambda_max, mu1 = 1.0 / lambda_min;
797 const REAL c = (sqrt(mu0) + sqrt(mu1)) * (sqrt(mu0) + sqrt(mu1));
798 const REAL a = (4 * mu0 * mu1) / (c);
800 const REAL kappa = lambda_max / lambda_min;
801 const REAL delta = (sqrt(kappa) - 1.0) / (sqrt(kappa) + 1.0);
802 const REAL b = delta * delta;
805 coef[0] = 0.5 * (mu0 + mu1);
808 else if (degree == 1) {
810 coef[1] = -1.0 * mu0 * mu1;
813 else if (degree > 1) {
818 REAL *coef_k, *coef_km1;
820 coef_km1 = work + degree;
828 coef[0] = a - b * coef_km1[0] + (1 + b) * coef_k[0];
830 for (i = 1; i < degree - 1; i++) {
831 coef[i] = -b * coef_km1[i] + (1 + b) * coef_k[i] - a * coef_k[i - 1];
834 coef[degree - 1] = (1 + b) * coef_k[degree - 1] - a * coef_k[degree - 2];
836 coef[degree] = -a * coef_k[degree - 1];
844 printf(
"### ERROR: Wrong AMLI degree %d!\n", degree);
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_chkerr(const SHORT status, const char *fctname)
Check error status and print out error messages before quit.
void fasp_param_amg_to_prec(precond_data *pcdata, const AMG_param *amgparam)
Set precond_data with AMG_param.
void fasp_param_amg_to_precbsr(precond_data_bsr *pcdata, const AMG_param *amgparam)
Set precond_data_bsr with AMG_param.
void fasp_dvec_set(INT n, dvector *x, const REAL val)
Initialize dvector x[i]=val for i=0:n-1.
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_ax(const INT n, const REAL a, REAL *x)
x = a*x
void fasp_blas_darray_axpy(const INT n, const REAL a, const REAL *x, REAL *y)
y = a*x + y
void fasp_dcsr_swz_forward(SWZ_data *swzdata, SWZ_param *swzparam, dvector *x, dvector *b)
Schwarz smoother: forward sweep.
void fasp_dcsr_swz_backward(SWZ_data *swzdata, SWZ_param *swzparam, dvector *x, dvector *b)
Schwarz smoother: backward sweep.
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_agg(const dCSRmat *A, const REAL *x, REAL *y)
Matrix-vector multiplication y = A*x (nonzeros of A = 1)
void fasp_blas_dcsr_mxv(const dCSRmat *A, const REAL *x, REAL *y)
Matrix-vector multiplication y = A*x.
void fasp_blas_dcsr_aAxpy_agg(const REAL alpha, const dCSRmat *A, const REAL *x, REAL *y)
Matrix-vector multiplication y = alpha*A*x + y (nonzeros of A = 1)
REAL fasp_blas_dcsr_vmv(const dCSRmat *A, const REAL *x, const REAL *y)
vector-Matrix-vector multiplication alpha = 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_smoother_dbsr_gs1(dBSRmat *A, dvector *b, dvector *u, INT order, INT *mark, REAL *diaginv)
Gauss-Seidel relaxation.
void fasp_smoother_dbsr_gs_descend1(dBSRmat *A, dvector *b, dvector *u)
Gauss-Seidel relaxation in the descending order.
void fasp_smoother_dbsr_jacobi1(dBSRmat *A, dvector *b, dvector *u, REAL *diaginv)
Jacobi relaxation.
void fasp_smoother_dbsr_gs_ascend1(dBSRmat *A, dvector *b, dvector *u)
Gauss-Seidel relaxation in the ascending order.
void fasp_smoother_dbsr_ilu(dBSRmat *A, dvector *b, dvector *x, void *data)
ILU method as the smoother in solving Au=b with multigrid method.
void fasp_smoother_dbsr_sor1(dBSRmat *A, dvector *b, dvector *u, INT order, INT *mark, REAL *diaginv, REAL weight)
SOR relaxation.
void fasp_smoother_dcsr_ilu(dCSRmat *A, dvector *b, dvector *x, void *data)
ILU method as a smoother.
INT fasp_solver_dbsr_pvfgmres(dBSRmat *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)
Solve "Ax=b" using PFGMRES(right preconditioned) iterative method in which the restart parameter can ...
void fasp_precond_dbsr_namli(REAL *r, REAL *z, void *data)
Nonlinear AMLI-cycle AMG preconditioner.
void fasp_precond_namli(REAL *r, REAL *z, void *data)
Nonlinear AMLI AMG preconditioner.
void fasp_solver_namli(AMG_data *mgl, AMG_param *param, INT l, INT num_levels)
Solve Ax=b with recursive nonlinear AMLI-cycle.
void fasp_amg_amli_coef(const REAL lambda_max, const REAL lambda_min, const INT degree, REAL *coef)
Compute the coefficients of the polynomial used by AMLI-cycle.
void fasp_solver_namli_bsr(AMG_data_bsr *mgl, AMG_param *param, INT l, INT num_levels)
Solve Ax=b with recursive nonlinear AMLI-cycle.
void fasp_solver_amli(AMG_data *mgl, AMG_param *param, INT l)
Solve Ax=b with recursive AMLI-cycle.
int fasp_solver_mumps_steps(dCSRmat *ptrA, dvector *b, dvector *u, Mumps_data *mumps)
Solve Ax=b by MUMPS in three steps.
int fasp_solver_superlu(dCSRmat *ptrA, dvector *b, dvector *u, const SHORT prtlvl)
Solve Au=b by SuperLU.
Main header file for the FASP project.
#define SHORT
FASP integer and floating point numbers.
#define ERROR_SOLVER_TYPE
#define SCHWARZ_SYMMETRIC
#define ON
Definition of switch.
#define PRINT_NONE
Print level for all subroutines – not including DEBUG output.
Data for multigrid levels in dBSRmat format.
dBSRmat A
pointer to the matrix at level level_num
Mumps_data mumps
data for MUMPS
dvector b
pointer to the right-hand side at level level_num
dvector x
pointer to the iterative solution at level level_num
dvector w
temporary work space
ILU_data LU
ILU matrix for ILU smoother.
dCSRmat A
pointer to the matrix at level level_num
Mumps_data mumps
data for MUMPS
dvector b
pointer to the right-hand side at level level_num
dvector x
pointer to the iterative solution at level level_num
dvector w
temporary work space
ivector cfmark
pointer to the CF marker at level level_num
ILU_data LU
ILU matrix for ILU smoother.
Parameters for AMG methods.
SHORT print_level
print level for AMG
SHORT polynomial_degree
degree of the polynomial smoother
SHORT nl_amli_krylov_type
type of Krylov method used by Nonlinear AMLI cycle
SHORT coarse_scaling
switch of scaling of the coarse grid correction
REAL * amli_coef
coefficients of the polynomial used by AMLI cycle
SHORT AMG_type
type of AMG method
REAL tol
stopping tolerance for AMG solver
SHORT coarse_solver
coarse solver type
REAL relaxation
relaxation parameter for Jacobi and SOR smoother
SHORT smoother
smoother type
SHORT amli_degree
degree of the polynomial used by AMLI cycle
INT SWZ_blksolver
type of Schwarz block solver
SHORT postsmooth_iter
number of postsmoothers
INT SWZ_levels
number of levels use Schwarz smoother
SHORT presmooth_iter
number of presmoothers
SHORT smooth_order
smoother order
Parameters for Schwarz method.
INT SWZ_blksolver
type of Schwarz block solver
Block sparse row storage matrix of REAL type.
INT NNZ
number of nonzero sub-blocks in matrix A, NNZ
INT nb
dimension of each sub-block
INT ROW
number of rows of sub-blocks in matrix A, M
Sparse matrix of REAL type in CSR format.
REAL * val
nonzero entries of A
INT row
row number of matrix A, m
INT nnz
number of nonzero entries
Vector with n entries of REAL type.
REAL * val
actual vector entries
INT * val
actual vector entries
Data for preconditioners in dBSRmat format.
AMG_data_bsr * mgl_data
AMG preconditioner data.
INT max_levels
max number of AMG levels
INT maxit
max number of iterations of AMG preconditioner
Data for preconditioners.
AMG_data * mgl_data
AMG preconditioner data.
SHORT max_levels
max number of AMG levels
INT maxit
max number of iterations of AMG preconditioner
Preconditioner data and action.
void * data
data for preconditioner, void pointer
void(* fct)(REAL *, REAL *, void *)
action for preconditioner, void function pointer