Fast Auxiliary Space Preconditioning 2.7.7 Aug/28/2022
Loading...
Searching...
No Matches
PreDataInit.c
Go to the documentation of this file.
1
16#include "fasp.h"
17#include "fasp_functs.h"
18
19/*---------------------------------*/
20/*-- Public Functions --*/
21/*---------------------------------*/
22
34{
35 pcdata->AMG_type = CLASSIC_AMG;
36 pcdata->print_level = PRINT_NONE;
37 pcdata->maxit = 500;
38 pcdata->max_levels = 20;
39 pcdata->tol = 1e-8;
40 pcdata->cycle_type = V_CYCLE;
41 pcdata->smoother = SMOOTHER_GS;
42 pcdata->smooth_order = CF_ORDER;
43 pcdata->presmooth_iter = 1;
44 pcdata->postsmooth_iter = 1;
45 pcdata->relaxation = 1.1;
46 pcdata->coarsening_type = 1;
47 pcdata->coarse_scaling = ON;
48 pcdata->amli_degree = 1;
50}
51
65{
66 max_levels = MAX(1, max_levels); // at least allocate one level
67
68 AMG_data* mgl = (AMG_data*)fasp_mem_calloc(max_levels, sizeof(AMG_data));
69
70 INT i;
71 for (i = 0; i < max_levels; ++i) {
72 mgl[i].max_levels = max_levels;
73 mgl[i].num_levels = 0;
74 mgl[i].near_kernel_dim = 0;
75 mgl[i].near_kernel_basis = NULL;
76 mgl[i].cycle_type = 0;
77#if MULTI_COLOR_ORDER
78 mgl[i].GS_Theta = 0.0E-2; // 0.0; //1.0E-2;
79#endif
80 }
81
82 return (mgl);
83}
84
102{
103 const INT max_levels = MAX(1, mgl[0].num_levels);
104
105 INT i;
106
107 switch (param->coarse_solver) {
108
109#if WITH_MUMPS
110 /* Destroy MUMPS direct solver on the coarsest level */
111 case SOLVER_MUMPS:
112 {
113 mgl[max_levels - 1].mumps.job = 3;
114 fasp_solver_mumps_steps(&mgl[max_levels - 1].A, &mgl[max_levels - 1].b,
115 &mgl[max_levels - 1].x,
116 &mgl[max_levels - 1].mumps);
117 break;
118 }
119#endif
120
121#if WITH_UMFPACK
122 /* Destroy UMFPACK direct solver on the coarsest level */
123 case SOLVER_UMFPACK:
124 {
125 fasp_mem_free(mgl[max_levels - 1].Numeric);
126 mgl[max_levels - 1].Numeric = NULL;
127 break;
128 }
129#endif
130
131#if WITH_PARDISO
132 /* Destroy PARDISO direct solver on the coarsest level */
133 case SOLVER_PARDISO:
134 {
135 fasp_pardiso_free_internal_mem(&mgl[max_levels - 1].pdata);
136 break;
137 }
138
139#endif
140 default: // Do nothing!
141 break;
142 }
143
144 for (i = 0; i < max_levels; ++i) {
145 fasp_ilu_data_free(&mgl[i].LU);
146 fasp_dcsr_free(&mgl[i].A);
147 if (max_levels > 1) {
148 fasp_dcsr_free(&mgl[i].P);
149 fasp_dcsr_free(&mgl[i].R);
150 }
151 fasp_dvec_free(&mgl[i].b);
152 fasp_dvec_free(&mgl[i].x);
153 fasp_dvec_free(&mgl[i].w);
154 fasp_ivec_free(&mgl[i].cfmark);
155 fasp_swz_data_free(&mgl[i].Schwarz);
156 }
157
158 for (i = 0; i < mgl->near_kernel_dim; ++i) {
160 mgl->near_kernel_basis[i] = NULL;
161 }
162
164 mgl->near_kernel_basis = NULL;
165 fasp_mem_free(mgl);
166 mgl = NULL;
167
168 if (param == NULL) return; // exit if no param given
169
170 if (param->cycle_type == AMLI_CYCLE) {
171 fasp_mem_free(param->amli_coef);
172 param->amli_coef = NULL;
173 }
174}
175
196{
197 const INT max_levels = MAX(1, mgl[0].num_levels);
198
199 INT i;
200
201 switch (param->coarse_solver) {
202
203#if WITH_MUMPS
204 /* Destroy MUMPS direct solver on the coarsest level */
205 case SOLVER_MUMPS:
206 {
207 mgl[max_levels - 1].mumps.job = 3;
208 fasp_solver_mumps_steps(&mgl[max_levels - 1].A, &mgl[max_levels - 1].b,
209 &mgl[max_levels - 1].x,
210 &mgl[max_levels - 1].mumps);
211 break;
212 }
213#endif
214
215#if WITH_UMFPACK
216 /* Destroy UMFPACK direct solver on the coarsest level */
217 case SOLVER_UMFPACK:
218 {
219 fasp_mem_free(mgl[max_levels - 1].Numeric);
220 mgl[max_levels - 1].Numeric = NULL;
221 break;
222 }
223#endif
224
225#if WITH_PARDISO
226 /* Destroy PARDISO direct solver on the coarsest level */
227 case SOLVER_PARDISO:
228 {
229 fasp_pardiso_free_internal_mem(&mgl[max_levels - 1].pdata);
230 break;
231 }
232
233#endif
234 default: // Do nothing!
235 break;
236 }
237
238 for (i = 0; i < max_levels; ++i) {
239 fasp_ilu_data_free(&mgl[i].LU);
240 // mgl[i].A is pointer variable, here don't free, Li Zhao, 05/20/2023
241 // fasp_dcsr_free(&mgl[i].A);
242 if (max_levels > 1) {
243 fasp_dcsr_free(&mgl[i].P);
244 fasp_dcsr_free(&mgl[i].R);
245 }
246 fasp_dvec_free(&mgl[i].b);
247 fasp_dvec_free(&mgl[i].x);
248 fasp_dvec_free(&mgl[i].w);
249 fasp_ivec_free(&mgl[i].cfmark);
250 fasp_swz_data_free(&mgl[i].Schwarz);
251 }
252
253 for (i = 0; i < mgl->near_kernel_dim; ++i) {
255 mgl->near_kernel_basis[i] = NULL;
256 }
257
259 mgl->near_kernel_basis = NULL;
260 fasp_mem_free(mgl);
261 mgl = NULL;
262
263 if (param == NULL) return; // exit if no param given
264
265 if (param->cycle_type == AMLI_CYCLE) {
266 fasp_mem_free(param->amli_coef);
267 param->amli_coef = NULL;
268 }
269}
270
284{
285 max_levels = MAX(1, max_levels); // at least allocate one level
286
287 AMG_data_bsr* mgl =
288 (AMG_data_bsr*)fasp_mem_calloc(max_levels, sizeof(AMG_data_bsr));
289
290 INT i;
291 for (i = 0; i < max_levels; ++i) {
292 mgl[i].max_levels = max_levels;
293 mgl[i].num_levels = 0;
294 mgl[i].near_kernel_dim = 0;
295 mgl[i].near_kernel_basis = NULL;
296 mgl[i].A_nk = NULL;
297 mgl[i].P_nk = NULL;
298 mgl[i].R_nk = NULL;
299 }
300
301 return (mgl);
302}
303
316void fasp_amg_data_bsr_free(AMG_data_bsr* mgl, AMG_param* param)
317{
318 const INT max_levels = MAX(1, mgl[0].num_levels);
319
320 INT i;
321 switch (param->coarse_solver) {
322
323#if WITH_MUMPS
324 /* Destroy MUMPS direct solver on the coarsest level */
325 case SOLVER_MUMPS:
326 {
327 mgl[max_levels - 1].mumps.job = 3;
328 fasp_solver_mumps_steps(&mgl[max_levels - 1].A, &mgl[max_levels - 1].b,
329 &mgl[max_levels - 1].x,
330 &mgl[max_levels - 1].mumps);
331 break;
332 }
333#endif
334
335#if WITH_UMFPACK
336 /* Destroy UMFPACK direct solver on the coarsest level */
337 case SOLVER_UMFPACK:
338 {
339 fasp_mem_free(mgl[max_levels - 1].Numeric);
340 mgl[max_levels - 1].Numeric = NULL;
341 break;
342 }
343#endif
344
345#if WITH_PARDISO
346 /* Destroy PARDISO direct solver on the coarsest level */
347 case SOLVER_PARDISO:
348 {
349 fasp_pardiso_free_internal_mem(&mgl[max_levels - 1].pdata);
350 break;
351 }
352
353#endif
354 default: // Do nothing!
355 break;
356 }
357
358 for (i = 0; i < max_levels; ++i) {
359
360 fasp_ilu_data_free(&mgl[i].LU);
361 fasp_dbsr_free(&mgl[i].A);
362 if (max_levels > 1) {
363 fasp_dbsr_free(&mgl[i].P);
364 fasp_dbsr_free(&mgl[i].R);
365 }
366 fasp_dvec_free(&mgl[i].b);
367 fasp_dvec_free(&mgl[i].x);
368 fasp_dvec_free(&mgl[i].diaginv);
369 fasp_dvec_free(&mgl[i].diaginv_SS);
370 fasp_dcsr_free(&mgl[i].Ac);
371
372 fasp_ilu_data_free(&mgl[i].PP_LU);
373 fasp_dcsr_free(&mgl[i].PP);
374 fasp_dcsr_free(&mgl[i].TT); // added by LiZhao, 05/23/2023
375 fasp_dbsr_free(&mgl[i].PT); // added by LiZhao, 05/19/2023
376 fasp_dbsr_free(&mgl[i].SS);
377 // fasp_dvec_free(&mgl[i].diaginv_SS);
378 fasp_dvec_free(&mgl[i].w);
379 fasp_ivec_free(&mgl[i].cfmark);
380
381 fasp_mem_free(mgl[i].pw);
382 mgl[i].pw = NULL;
383 fasp_mem_free(mgl[i].sw);
384 mgl[i].sw = NULL;
385 }
386
387 for (i = 0; i < mgl->near_kernel_dim; ++i) {
389 mgl->near_kernel_basis[i] = NULL;
390 }
392 mgl->near_kernel_basis = NULL;
393 fasp_mem_free(mgl);
394 mgl = NULL;
395}
396
411void fasp_ilu_data_create(const INT iwk, const INT nwork, ILU_data* iludata)
412{
413#if DEBUG_MODE > 0
414 printf("### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
415 printf("### DEBUG: iwk=%d, nwork=%d \n", iwk, nwork);
416#endif
417
418 iludata->ijlu = (INT*)fasp_mem_calloc(iwk, sizeof(INT));
419
420 if (iludata->type == ILUtp)
421 iludata->iperm = (INT*)fasp_mem_calloc(iludata->row * 2, sizeof(INT));
422
423 iludata->luval = (REAL*)fasp_mem_calloc(iwk, sizeof(REAL));
424
425 iludata->work = (REAL*)fasp_mem_calloc(nwork, sizeof(REAL));
426#if DEBUG_MODE > 0
427 printf("### DEBUG: %s ...... %d [End]\n", __FUNCTION__, __LINE__);
428#endif
429
430 return;
431}
432
446{
447 if (iludata == NULL) return; // There is nothing to do!
448
449 fasp_mem_free(iludata->ijlu);
450 iludata->ijlu = NULL;
451 fasp_mem_free(iludata->luval);
452 iludata->luval = NULL;
453 fasp_mem_free(iludata->work);
454 iludata->work = NULL;
455 fasp_mem_free(iludata->ilevL);
456 iludata->ilevL = NULL;
457 fasp_mem_free(iludata->jlevL);
458 iludata->jlevL = NULL;
459 fasp_mem_free(iludata->ilevU);
460 iludata->ilevU = NULL;
461 fasp_mem_free(iludata->jlevU);
462 iludata->jlevU = NULL;
463
464 if (iludata->type == ILUtp) {
465
466 if (iludata->A != NULL) {
467 // To permute the matrix back to its original state use the loop:
468 INT k;
469 const INT nnz = iludata->A->nnz;
470 const INT* iperm = iludata->iperm;
471 for (k = 0; k < nnz; k++) {
472 // iperm is in Fortran array format
473 iludata->A->JA[k] = iperm[iludata->A->JA[k]] - 1;
474 }
475 }
476
477 fasp_mem_free(iludata->iperm);
478 iludata->iperm = NULL;
479 }
480
481 iludata->row = iludata->col = iludata->nzlu = iludata->nwork = iludata->nb =
482 iludata->nlevL = iludata->nlevU = 0;
483}
484
495{
496 INT i;
497
498 if (swzdata == NULL) return; // There is nothing to do!
499
500 fasp_dcsr_free(&swzdata->A);
501
502 for (i = 0; i < swzdata->nblk; ++i) fasp_dcsr_free(&((swzdata->blk_data)[i]));
503
504 swzdata->nblk = 0;
505
506 fasp_mem_free(swzdata->iblock);
507 swzdata->iblock = NULL;
508 fasp_mem_free(swzdata->jblock);
509 swzdata->jblock = NULL;
510
511 fasp_dvec_free(&swzdata->rhsloc1);
512 fasp_dvec_free(&swzdata->xloc1);
513
514 swzdata->memt = 0;
515 fasp_mem_free(swzdata->mask);
516 swzdata->mask = NULL;
517 fasp_mem_free(swzdata->maxa);
518 swzdata->maxa = NULL;
519
520#if WITH_MUMPS
521 if (swzdata->mumps == NULL) return;
522
523 for (i = 0; i < swzdata->nblk; ++i) fasp_mumps_free(&((swzdata->mumps)[i]));
524#endif
525}
526
527/*---------------------------------*/
528/*-- End of File --*/
529/*---------------------------------*/
void fasp_mem_free(void *mem)
Free up previous allocated memory body and set pointer to NULL.
Definition: AuxMemory.c:152
void * fasp_mem_calloc(const unsigned int size, const unsigned int type)
Allocate, initiate, and check memory.
Definition: AuxMemory.c:65
void fasp_dvec_free(dvector *u)
Free vector data space of REAL type.
Definition: AuxVector.c:145
void fasp_ivec_free(ivector *u)
Free vector data space of INT type.
Definition: AuxVector.c:164
void fasp_dbsr_free(dBSRmat *A)
Free memory space for BSR format sparse matrix.
Definition: BlaSparseBSR.c:140
void fasp_dcsr_free(dCSRmat *A)
Free CSR sparse matrix data memory space.
Definition: BlaSparseCSR.c:184
void fasp_precond_data_init(precond_data *pcdata)
Initialize precond_data.
Definition: PreDataInit.c:33
void fasp_swz_data_free(SWZ_data *swzdata)
Free SWZ_data data memeory space.
Definition: PreDataInit.c:494
void fasp_ilu_data_create(const INT iwk, const INT nwork, ILU_data *iludata)
Allocate workspace for ILU factorization.
Definition: PreDataInit.c:411
AMG_data * fasp_amg_data_create(SHORT max_levels)
Create and initialize AMG_data for classical and SA AMG.
Definition: PreDataInit.c:64
AMG_data_bsr * fasp_amg_data_bsr_create(SHORT max_levels)
Create and initialize AMG_data data sturcture for AMG/SAMG (BSR format)
Definition: PreDataInit.c:283
void fasp_amg_data_free(AMG_data *mgl, AMG_param *param)
Free AMG_data data memeory space.
Definition: PreDataInit.c:101
void fasp_amg_data_free1(AMG_data *mgl, AMG_param *param)
Free AMG_data data memeory space.
Definition: PreDataInit.c:195
void fasp_ilu_data_free(ILU_data *iludata)
Create ILU_data sturcture.
Definition: PreDataInit.c:445
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
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 MAX(a, b)
Definition of max, min, abs.
Definition: fasp.h:82
#define INT
Definition: fasp.h:72
#define AMLI_CYCLE
Definition: fasp_const.h:181
#define SOLVER_PARDISO
Definition: fasp_const.h:126
#define SOLVER_MUMPS
Definition: fasp_const.h:125
#define ILUtp
Definition: fasp_const.h:151
#define V_CYCLE
Definition of cycle types.
Definition: fasp_const.h:179
#define SMOOTHER_GS
Definition: fasp_const.h:191
#define SOLVER_UMFPACK
Definition: fasp_const.h:124
#define CF_ORDER
Definition: fasp_const.h:241
#define CLASSIC_AMG
Definition of AMG types.
Definition: fasp_const.h:163
#define ON
Definition of switch.
Definition: fasp_const.h:67
#define PRINT_NONE
Print level for all subroutines – not including DEBUG output.
Definition: fasp_const.h:73
#define SOLVER_GCG
Definition: fasp_const.h:109
Data for multigrid levels in dBSRmat format.
Definition: fasp_block.h:146
INT near_kernel_dim
dimension of the near kernel for SAMG
Definition: fasp_block.h:223
REAL * pw
pointer to the auxiliary vectors for pressure block
Definition: fasp_block.h:199
dCSRmat * A_nk
Matrix data for near kernal.
Definition: fasp_block.h:232
Mumps_data mumps
data for MUMPS
Definition: fasp_block.h:245
REAL ** near_kernel_basis
basis of near kernel space for SAMG
Definition: fasp_block.h:226
void * Numeric
pointer to the numerical dactorization from UMFPACK
Definition: fasp_block.h:176
INT num_levels
number of levels in use <= max_levels
Definition: fasp_block.h:152
dCSRmat * R_nk
Resriction for near kernal.
Definition: fasp_block.h:238
INT max_levels
max number of levels
Definition: fasp_block.h:149
dCSRmat * P_nk
Prolongation for near kernal.
Definition: fasp_block.h:235
REAL * sw
pointer to the auxiliary vectors for saturation block
Definition: fasp_block.h:205
Data for AMG methods.
Definition: fasp.h:804
INT near_kernel_dim
dimension of the near kernel for SAMG
Definition: fasp.h:849
INT cycle_type
cycle type
Definition: fasp.h:869
Mumps_data mumps
data for MUMPS
Definition: fasp.h:866
REAL ** near_kernel_basis
basis of near kernel space for SAMG
Definition: fasp.h:852
void * Numeric
pointer to the numerical factorization from UMFPACK
Definition: fasp.h:834
SHORT max_levels
max number of levels
Definition: fasp.h:809
SHORT num_levels
number of levels in use <= max_levels
Definition: fasp.h:812
Parameters for AMG methods.
Definition: fasp.h:455
REAL * amli_coef
coefficients of the polynomial used by AMLI cycle
Definition: fasp.h:509
SHORT coarse_solver
coarse solver type
Definition: fasp.h:500
SHORT cycle_type
type of AMG cycle
Definition: fasp.h:476
Data for ILU setup.
Definition: fasp.h:651
INT * ijlu
integer array of row pointers and column indexes, the size is nzlu
Definition: fasp.h:669
REAL * luval
nonzero entries of LU
Definition: fasp.h:672
INT col
column of matrix LU, n
Definition: fasp.h:663
INT * jlevU
mapping from row to color for upper triangle
Definition: fasp.h:716
INT nlevU
number of colors for upper triangle
Definition: fasp.h:704
INT nwork
work space size
Definition: fasp.h:678
INT nb
block size for BSR type only
Definition: fasp.h:675
INT row
row number of matrix LU, m
Definition: fasp.h:660
INT nlevL
number of colors for lower triangle
Definition: fasp.h:701
INT type
type of ILUdata
Definition: fasp.h:657
INT * iperm
permutation arrays for ILUtp
Definition: fasp.h:684
INT nzlu
number of nonzero entries
Definition: fasp.h:666
INT * jlevL
mapping from row to color for lower triangle
Definition: fasp.h:713
REAL * work
work space
Definition: fasp.h:681
INT * ilevL
number of vertices in each color for lower triangle
Definition: fasp.h:707
dCSRmat * A
pointer to the original coefficient matrix
Definition: fasp.h:654
INT * ilevU
number of vertices in each color for upper triangle
Definition: fasp.h:710
INT job
work for MUMPS
Definition: fasp.h:615
Data for Schwarz methods.
Definition: fasp.h:726
INT memt
working space size
Definition: fasp.h:766
INT * mask
mask
Definition: fasp.h:769
dCSRmat A
pointer to the original coefficient matrix
Definition: fasp.h:731
dvector rhsloc1
local right hand side
Definition: fasp.h:748
dvector xloc1
local solution
Definition: fasp.h:751
INT nblk
number of blocks
Definition: fasp.h:736
dCSRmat * blk_data
matrix for each partition
Definition: fasp.h:778
INT * jblock
column index of blocks
Definition: fasp.h:742
Mumps_data * mumps
param for MUMPS
Definition: fasp.h:791
INT * maxa
maxa
Definition: fasp.h:775
INT * iblock
row index of blocks
Definition: fasp.h:739
INT nnz
number of nonzero entries
Definition: fasp.h:160
INT * JA
integer array of column indexes, the size is nnz
Definition: fasp.h:166
Data for preconditioners.
Definition: fasp.h:894
SHORT print_level
print level in AMG preconditioner
Definition: fasp.h:900
SHORT coarsening_type
switch of scaling of the coarse grid correction
Definition: fasp.h:933
SHORT nl_amli_krylov_type
type of Krylov method used by Nonlinear AMLI cycle
Definition: fasp.h:945
SHORT coarse_scaling
switch of scaling of the coarse grid correction
Definition: fasp.h:939
SHORT AMG_type
type of AMG method
Definition: fasp.h:897
REAL tol
tolerance for AMG preconditioner
Definition: fasp.h:909
REAL relaxation
relaxation parameter for SOR smoother
Definition: fasp.h:927
SHORT smoother
AMG smoother type.
Definition: fasp.h:915
SHORT cycle_type
AMG cycle type.
Definition: fasp.h:912
SHORT amli_degree
degree of the polynomial used by AMLI cycle
Definition: fasp.h:942
SHORT postsmooth_iter
number of postsmoothing
Definition: fasp.h:924
SHORT max_levels
max number of AMG levels
Definition: fasp.h:906
SHORT presmooth_iter
number of presmoothing
Definition: fasp.h:921
INT maxit
max number of iterations of AMG preconditioner
Definition: fasp.h:903
SHORT smooth_order
AMG smoother ordering.
Definition: fasp.h:918