Fast Auxiliary Space Preconditioning  1.8.4 Feb/15/2016
famg.c
Go to the documentation of this file.
1 
6 #include <time.h>
7 
8 #include "fasp.h"
9 #include "fasp_functs.h"
10 
11 /*---------------------------------*/
12 /*-- Public Functions --*/
13 /*---------------------------------*/
14 
32  dvector *b,
33  dvector *x,
34  AMG_param *param)
35 {
36  const SHORT max_levels = param->max_levels;
37  const SHORT prtlvl = param->print_level;
38  const SHORT amg_type = param->AMG_type;
39  const INT nnz = A->nnz, m = A->row, n = A->col;
40 
41  // local variables
42  AMG_data * mgl = fasp_amg_data_create(max_levels);
43  REAL FMG_start, FMG_end;
44 
45 #if DEBUG_MODE > 0
46  printf("###DEBUG: %s ...... [Start]\n", __FUNCTION__);
47  printf("###DEBUG: nr=%d, nc=%d, nnz=%d\n", m, n, nnz);
48 #endif
49 
50  if ( prtlvl > PRINT_NONE ) fasp_gettime(&FMG_start);
51 
52  // Step 0: initialize mgl[0] with A, b and x
53  mgl[0].A = fasp_dcsr_create(m,n,nnz);
54  fasp_dcsr_cp(A,&mgl[0].A);
55 
56  mgl[0].b = fasp_dvec_create(n);
57  fasp_dvec_cp(b,&mgl[0].b);
58 
59  mgl[0].x = fasp_dvec_create(n);
60  fasp_dvec_cp(x,&mgl[0].x);
61 
62  // Step 1: AMG setup phase
63  switch (amg_type) {
64 
65  case SA_AMG:
66  // Smoothed Aggregation AMG setup phase
67  if ( prtlvl > PRINT_NONE ) printf("\nCalling SA FAMG ...\n");
68  fasp_amg_setup_sa(mgl, param); break;
69 
70  case UA_AMG:
71  // Unsmoothed Aggregation AMG setup phase
72  if ( prtlvl > PRINT_NONE ) printf("\nCalling UA FAMG ...\n");
73  fasp_amg_setup_ua(mgl, param); break;
74 
75  default:
76  // Classical AMG setup phase
77  if ( prtlvl > PRINT_NONE ) printf("\nCalling FAMG ...\n");
78  fasp_amg_setup_rs(mgl, param);
79 
80  }
81 
82  // Step 2: FAMG solve phase
83  fasp_famg_solve(mgl, param);
84 
85  // Step 3: Save solution vector and return
86  fasp_dvec_cp(&mgl[0].x, x);
87 
88  // clean-up memory
89  fasp_amg_data_free(mgl, param);
90 
91  // print out CPU time if needed
92  if ( prtlvl > PRINT_NONE ) {
93  fasp_gettime(&FMG_end);
94  print_cputime("FAMG totally", FMG_end - FMG_start);
95  }
96 
97 #if DEBUG_MODE > 0
98  printf("### DEBUG: %s ...... [Finish]\n", __FUNCTION__);
99 #endif
100 
101  return;
102 }
103 
104 /*---------------------------------*/
105 /*-- End of File --*/
106 /*---------------------------------*/
dvector fasp_dvec_create(const INT m)
Create dvector data space of REAL type.
Definition: vec.c:56
dCSRmat fasp_dcsr_create(const INT m, const INT n, const INT nnz)
Create CSR sparse matrix data memory space.
Definition: sparse_csr.c:34
SHORT AMG_type
type of AMG method
Definition: fasp.h:586
Parameters for AMG solver.
Definition: fasp.h:583
#define REAL
Definition: fasp.h:67
SHORT fasp_amg_setup_ua(AMG_data *mgl, AMG_param *param)
Set up phase of unsmoothed aggregation AMG.
Definition: amg_setup_ua.c:38
dvector b
pointer to the right-hand side at level level_num
Definition: fasp.h:744
SHORT fasp_amg_setup_rs(AMG_data *mgl, AMG_param *param)
Setup phase of Ruge and Stuben's classic AMG.
Definition: amg_setup_rs.c:47
void fasp_dvec_cp(dvector *x, dvector *y)
Copy dvector x to dvector y.
Definition: vec.c:345
Vector with n entries of REAL type.
Definition: fasp.h:342
#define INT
Definition: fasp.h:64
void fasp_solver_famg(dCSRmat *A, dvector *b, dvector *x, AMG_param *param)
Solve Ax=b by full AMG.
Definition: famg.c:31
dvector x
pointer to the iterative solution at level level_num
Definition: fasp.h:747
SHORT fasp_amg_setup_sa(AMG_data *mgl, AMG_param *param)
Set up phase of smoothed aggregation AMG.
Definition: amg_setup_sa.c:48
void fasp_dcsr_cp(dCSRmat *A, dCSRmat *B)
copy a dCSRmat to a new one B=A
Definition: sparse_csr.c:723
AMG_data * fasp_amg_data_create(SHORT max_levels)
Create and initialize AMG_data for classical and SA AMG.
Definition: init.c:56
INT nnz
number of nonzero entries
Definition: fasp.h:157
INT col
column of matrix A, n
Definition: fasp.h:154
Main header file for FASP.
SHORT max_levels
max number of levels of AMG
Definition: fasp.h:598
void fasp_gettime(REAL *time)
Get system time.
Definition: timing.c:28
#define PRINT_NONE
Print level for all subroutines – not including DEBUG output.
Definition: fasp_const.h:79
INT row
row number of matrix A, m
Definition: fasp.h:151
Sparse matrix of REAL type in CSR format.
Definition: fasp.h:148
#define SHORT
FASP integer and floating point numbers.
Definition: fasp.h:63
dCSRmat A
pointer to the matrix at level level_num
Definition: fasp.h:735
void print_cputime(const char *message, const REAL cputime)
Print CPU walltime.
Definition: message.c:165
SHORT print_level
print level for AMG
Definition: fasp.h:589
Data for AMG solvers.
Definition: fasp.h:722
void fasp_famg_solve(AMG_data *mgl, AMG_param *param)
FMG – SOLVE phase.
Definition: amg_solve.c:281
void fasp_amg_data_free(AMG_data *mgl, AMG_param *param)
Free AMG_data data memeory space.
Definition: init.c:185
#define SA_AMG
Definition: fasp_const.h:163
#define UA_AMG
Definition: fasp_const.h:164