/[escript]/branches/doubleplusgood/paso/src/AMG_Root.cpp
ViewVC logotype

Contents of /branches/doubleplusgood/paso/src/AMG_Root.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4280 - (show annotations)
Wed Mar 6 06:45:32 2013 UTC (6 years, 1 month ago) by jfenwick
File size: 5505 byte(s)
some memory management replacement
1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15
16
17 /************************************************************************************/
18
19 /* Paso: AMG set-ups */
20
21 /************************************************************************************/
22
23 /* Author: Lutz Gross, l.gross@uq.edu.au */
24
25 /************************************************************************************/
26
27 #include "Paso.h"
28 #include "Preconditioner.h"
29 #include "BOOMERAMG.h"
30
31 /*********************************************************************************************************/
32
33 /* free space */
34
35 void Paso_Preconditioner_AMG_Root_free(Paso_Preconditioner_AMG_Root* in) {
36 if (in!=NULL) {
37 Paso_Preconditioner_AMG_free(in->amg);
38 Paso_Preconditioner_LocalAMG_free(in->localamg);
39 Paso_Preconditioner_BoomerAMG_free(in->boomeramg);
40 Paso_Preconditioner_Smoother_free(in->amgsubstitute);
41 delete in;
42 }
43 }
44
45 Paso_Preconditioner_AMG_Root* Paso_Preconditioner_AMG_Root_alloc(Paso_SystemMatrix* A,Paso_Options* options) {
46 Paso_Preconditioner_AMG_Root* prec=new Paso_Preconditioner_AMG_Root;
47
48 if (! Esys_checkPtr(prec)) {
49
50 prec->amg=NULL;
51 prec->localamg=NULL;
52 prec->amgsubstitute=NULL;
53 prec->boomeramg=NULL;
54 if (options->preconditioner == PASO_BOOMERAMG){
55 prec->boomeramg = Paso_Preconditioner_BoomerAMG_alloc(A,options);
56 } else {
57 prec->is_local=( A->mpi_info->size == 1 ) | options->use_local_preconditioner;
58
59 if (prec->is_local) {
60 prec->localamg=Paso_Preconditioner_LocalAMG_alloc(A->mainBlock,1,options);
61 Esys_MPIInfo_noError(A->mpi_info);
62 } else {
63 prec->amg=Paso_Preconditioner_AMG_alloc(A,1,options);
64 }
65 }
66 if ( Esys_noError() ) {
67 if (options->verbose) {
68 if ( (prec->localamg != NULL) || ( prec->amg != NULL) ||
69 (prec->boomeramg != NULL) ) {
70 printf("Paso_Preconditioner_AMG_Root: Smoother is ");
71 if (options->smoother == PASO_JACOBI) {
72 printf("Jacobi");
73 } else {
74 printf("Gauss-Seidel");
75 }
76 printf(" with %d/%d pre/post sweeps",options->pre_sweeps, options->post_sweeps);
77 if (options->interpolation_method == PASO_CLASSIC_INTERPOLATION) {
78 printf( " and classical interpolation.\n");
79 } else if (options->interpolation_method == PASO_CLASSIC_INTERPOLATION_WITH_FF_COUPLING) {
80 printf( " and classical interpolation with enforced FF coupling.\n");
81 } else {
82 printf( " and direct interpolation.\n");
83 }
84 } else {
85 printf("Paso_Preconditioner_AMG_Root: no coarsening constructed.\n");
86 }
87 }
88
89 if (prec->localamg != NULL) {
90 options->num_level=Paso_Preconditioner_LocalAMG_getMaxLevel(prec->localamg);
91 options->coarse_level_sparsity=Paso_Preconditioner_LocalAMG_getCoarseLevelSparsity(prec->localamg);
92 options->num_coarse_unknowns=Paso_Preconditioner_LocalAMG_getNumCoarseUnknwons(prec->localamg);
93 } else if ( prec->amg != NULL) {
94 options->num_level=Paso_Preconditioner_AMG_getMaxLevel(prec->amg);
95 options->coarse_level_sparsity=Paso_Preconditioner_AMG_getCoarseLevelSparsity(prec->amg);
96 options->num_coarse_unknowns=Paso_Preconditioner_AMG_getNumCoarseUnknwons(prec->amg);
97 } else if (prec->boomeramg == NULL) {
98 prec->sweeps=options->sweeps;
99 prec->amgsubstitute=Paso_Preconditioner_Smoother_alloc(A, (options->smoother == PASO_JACOBI), prec->is_local, options->verbose);
100 options->num_level=0;
101 if (options->verbose) {
102 if (options->smoother == PASO_JACOBI) {
103 printf("Paso_Preconditioner: Jacobi(%d) preconditioner is used.\n",prec->sweeps);
104 } else {
105 printf("Paso_Preconditioner: Gauss-Seidel(%d) preconditioner is used.\n",prec->sweeps);
106 }
107 }
108 }
109 }
110 }
111 if (! Esys_noError() ){
112 Paso_Preconditioner_AMG_Root_free(prec);
113 return NULL;
114 } else {
115 return prec;
116 }
117 }
118
119 /* Applies the preconditioner. */
120 /* Has to be called within a parallel region. */
121 /* Barrier synchronization is performed before the evaluation to make sure that the input vector is available */
122 void Paso_Preconditioner_AMG_Root_solve(Paso_SystemMatrix* A, Paso_Preconditioner_AMG_Root* prec, double* x,double* b)
123 {
124 if (prec->localamg != NULL) {
125 Paso_Preconditioner_LocalAMG_solve(A->mainBlock, prec->localamg,x,b);
126 } else if ( prec->amg != NULL) {
127 Paso_Preconditioner_AMG_solve(A, prec->amg,x,b);
128 } else if ( prec->boomeramg != NULL) {
129 Paso_Preconditioner_BoomerAMG_solve(A, prec->boomeramg,x,b);
130 } else {
131 Paso_Preconditioner_Smoother_solve(A, prec->amgsubstitute,x,b,prec->sweeps,FALSE);
132 }
133 }
134

  ViewVC Help
Powered by ViewVC 1.1.26