Fast Auxiliary Space Preconditioning 2.7.7 Aug/28/2022
Loading...
Searching...
No Matches
PreMGRecur.c
Go to the documentation of this file.
1
17#include <time.h>
18
19#include "fasp.h"
20#include "fasp_functs.h"
21
22/*---------------------------------*/
23/*-- Declare Private Functions --*/
24/*---------------------------------*/
25
26#include "PreMGUtil.inl"
27#include "PreMGSmoother.inl"
28
29/*---------------------------------*/
30/*-- Public Functions --*/
31/*---------------------------------*/
32
48 AMG_param *param,
49 INT level)
50{
51 const SHORT prtlvl = param->print_level;
52 const SHORT smoother = param->smoother;
53 const SHORT cycle_type = param->cycle_type;
54 const SHORT coarse_solver = param->coarse_solver;
55 const SHORT smooth_order = param->smooth_order;
56 const REAL relax = param->relaxation;
57 const REAL tol = param->tol*1e-4;
58 const SHORT ndeg = param->polynomial_degree;
59
60 dvector *b0 = &mgl[level].b, *e0 = &mgl[level].x; // fine level b and x
61 dvector *b1 = &mgl[level+1].b, *e1 = &mgl[level+1].x; // coarse level b and x
62
63 dCSRmat *A0 = &mgl[level].A; // fine level matrix
64 dCSRmat *A1 = &mgl[level+1].A; // coarse level matrix
65 const INT m0 = A0->row, m1 = A1->row;
66
67 ILU_data *LU_level = &mgl[level].LU; // fine level ILU decomposition
68 REAL *r = mgl[level].w.val; // for residual
69 INT *ordering = mgl[level].cfmark.val; // for smoother ordering
70
71#if DEBUG_MODE > 0
72 printf("### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
73 printf("### DEBUG: n=%d, nnz=%d\n", mgl[0].A.row, mgl[0].A.nnz);
74#endif
75
76 if ( prtlvl >= PRINT_MOST )
77 printf("AMG level %d, smoother %d.\n", level, smoother);
78
79 if ( level < mgl[level].num_levels-1 ) {
80
81 // pre smoothing
82 if ( level < mgl[level].ILU_levels ) {
83 fasp_smoother_dcsr_ilu(A0, b0, e0, LU_level);
84 }
85 else {
86 fasp_dcsr_presmoothing(smoother,A0,b0,e0,param->presmooth_iter,
87 0,m0-1,1,relax,ndeg,smooth_order,ordering);
88 }
89
90 // form residual r = b - A x
91 fasp_darray_cp(m0,b0->val,r);
92 fasp_blas_dcsr_aAxpy(-1.0,A0,e0->val,r);
93
94 // restriction r1 = R*r0
95 fasp_blas_dcsr_mxv(&mgl[level].R, r, b1->val);
96
97 { // call MG recursively: type = 1 for V cycle, type = 2 for W cycle
98 SHORT i;
99 fasp_dvec_set(m1,e1,0.0);
100 for (i=0; i<cycle_type; ++i) fasp_solver_mgrecur (mgl, param, level+1);
101 }
102
103 // prolongation e0 = e0 + P*e1
104 fasp_blas_dcsr_aAxpy(1.0, &mgl[level].P, e1->val, e0->val);
105
106 // post smoothing
107 if ( level < mgl[level].ILU_levels ) {
108 fasp_smoother_dcsr_ilu(A0, b0, e0, LU_level);
109 }
110 else {
111 fasp_dcsr_postsmoothing(smoother,A0,b0,e0,param->postsmooth_iter,
112 0,m0-1,-1,relax,ndeg,smooth_order,ordering);
113 }
114
115 }
116
117 else { // coarsest level solver
118
119 switch (coarse_solver) {
120
121#if WITH_PARDISO
122 case SOLVER_PARDISO: {
123 /* use Intel MKL PARDISO direct solver on the coarsest level */
124 fasp_pardiso_solve(A0, b0, e0, &mgl[level].pdata, 0);
125 break;
126 }
127#endif
128
129#if WITH_SuperLU
130 case SOLVER_SUPERLU:
131 /* use SuperLU direct solver on the coarsest level */
132 fasp_solver_superlu(A0, b0, e0, 0);
133 break;
134#endif
135
136#if WITH_UMFPACK
137 case SOLVER_UMFPACK:
138 /* use UMFPACK direct solver on the coarsest level */
139 fasp_umfpack_solve(A0, b0, e0, mgl[level].Numeric, 0);
140 break;
141#endif
142
143#if WITH_MUMPS
144 case SOLVER_MUMPS:
145 /* use MUMPS direct solver on the coarsest level */
146 mgl[level].mumps.job = 2;
147 fasp_solver_mumps_steps(A0, b0, e0, &mgl[level].mumps);
148 break;
149#endif
150
151 /* use iterative solver on the coarsest level */
152 default:
153 fasp_coarse_itsolver(A0, b0, e0, tol, prtlvl);
154
155 }
156
157 }
158
159#if DEBUG_MODE > 0
160 printf("### DEBUG: [--End--] %s ...\n", __FUNCTION__);
161#endif
162}
163
164/*---------------------------------*/
165/*-- End of File --*/
166/*---------------------------------*/
void fasp_darray_cp(const INT n, const REAL *x, REAL *y)
Copy an array to the other y=x.
Definition: AuxArray.c:210
void fasp_dvec_set(INT n, dvector *x, const REAL val)
Initialize dvector x[i]=val for i=0:n-1.
Definition: AuxVector.c:222
void fasp_blas_dcsr_mxv(const dCSRmat *A, const REAL *x, REAL *y)
Matrix-vector multiplication y = A*x.
Definition: BlaSpmvCSR.c:242
void fasp_blas_dcsr_aAxpy(const REAL alpha, const dCSRmat *A, const REAL *x, REAL *y)
Matrix-vector multiplication y = alpha*A*x + y.
Definition: BlaSpmvCSR.c:494
void fasp_smoother_dcsr_ilu(dCSRmat *A, dvector *b, dvector *x, void *data)
ILU method as a smoother.
void fasp_solver_mgrecur(AMG_data *mgl, AMG_param *param, INT level)
Solve Ax=b with recursive multigrid K-cycle.
Definition: PreMGRecur.c:47
int fasp_solver_mumps_steps(dCSRmat *ptrA, dvector *b, dvector *u, Mumps_data *mumps)
Solve Ax=b by MUMPS in three steps.
Definition: XtrMumps.c:196
int fasp_solver_superlu(dCSRmat *ptrA, dvector *b, dvector *u, const SHORT prtlvl)
Solve Au=b by SuperLU.
Definition: XtrSuperlu.c:47
Main header file for the FASP project.
#define REAL
Definition: fasp.h:75
#define SHORT
FASP integer and floating point numbers.
Definition: fasp.h:71
#define INT
Definition: fasp.h:72
#define SOLVER_PARDISO
Definition: fasp_const.h:126
#define PRINT_MOST
Definition: fasp_const.h:77
#define SOLVER_MUMPS
Definition: fasp_const.h:125
#define SOLVER_SUPERLU
Definition: fasp_const.h:123
#define SOLVER_UMFPACK
Definition: fasp_const.h:124
Data for AMG methods.
Definition: fasp.h:804
dCSRmat A
pointer to the matrix at level level_num
Definition: fasp.h:817
Mumps_data mumps
data for MUMPS
Definition: fasp.h:866
dvector b
pointer to the right-hand side at level level_num
Definition: fasp.h:826
dvector x
pointer to the iterative solution at level level_num
Definition: fasp.h:829
dvector w
temporary work space
Definition: fasp.h:863
ivector cfmark
pointer to the CF marker at level level_num
Definition: fasp.h:840
ILU_data LU
ILU matrix for ILU smoother.
Definition: fasp.h:846
Parameters for AMG methods.
Definition: fasp.h:455
SHORT print_level
print level for AMG
Definition: fasp.h:461
SHORT polynomial_degree
degree of the polynomial smoother
Definition: fasp.h:497
REAL tol
stopping tolerance for AMG solver
Definition: fasp.h:467
SHORT coarse_solver
coarse solver type
Definition: fasp.h:500
REAL relaxation
relaxation parameter for Jacobi and SOR smoother
Definition: fasp.h:494
SHORT smoother
smoother type
Definition: fasp.h:482
SHORT cycle_type
type of AMG cycle
Definition: fasp.h:476
SHORT postsmooth_iter
number of postsmoothers
Definition: fasp.h:491
SHORT presmooth_iter
number of presmoothers
Definition: fasp.h:488
SHORT smooth_order
smoother order
Definition: fasp.h:485
Data for ILU setup.
Definition: fasp.h:651
INT job
work for MUMPS
Definition: fasp.h:615
Sparse matrix of REAL type in CSR format.
Definition: fasp.h:151
REAL * val
nonzero entries of A
Definition: fasp.h:169
INT row
row number of matrix A, m
Definition: fasp.h:154
INT nnz
number of nonzero entries
Definition: fasp.h:160
Vector with n entries of REAL type.
Definition: fasp.h:354
REAL * val
actual vector entries
Definition: fasp.h:360
INT * val
actual vector entries
Definition: fasp.h:374