/[escript]/trunk/paso/src/Preconditioner.c
ViewVC logotype

Annotation of /trunk/paso/src/Preconditioner.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3312 - (hide annotations)
Tue Oct 26 07:54:58 2010 UTC (8 years, 10 months ago) by gross
File MIME type: text/plain
File size: 5714 byte(s)
last step for a clean up version of the AMG
1 ksteube 1312
2     /*******************************************************
3 ksteube 1811 *
4 jfenwick 2881 * Copyright (c) 2003-2010 by University of Queensland
5 ksteube 1811 * Earth Systems Science Computational Center (ESSCC)
6     * http://www.uq.edu.au/esscc
7     *
8     * Primary Business: Queensland, Australia
9     * Licensed under the Open Software License version 3.0
10     * http://www.opensource.org/licenses/osl-3.0.php
11     *
12     *******************************************************/
13 dhawcroft 631
14 ksteube 1811
15 jgs 150 /**************************************************************/
16    
17     /* Paso: SystemMatrix: sets-up the preconditioner */
18    
19     /**************************************************************/
20    
21     /* Copyrights by ACcESS Australia 2003/04 */
22 jfenwick 2608 /* Author: Lutz Gross, l.gross@uq.edu.au */
23 jgs 150
24     /**************************************************************/
25    
26 gross 700 #include "Paso.h"
27     #include "SystemMatrix.h"
28 lgao 3051 #include "PasoUtil.h"
29 gross 3120 #include "Preconditioner.h"
30 jgs 150
31     /***********************************************************************************/
32    
33     /* free space */
34    
35 gross 3193 void Paso_Preconditioner_free(Paso_Preconditioner* in) {
36 jgs 150 if (in!=NULL) {
37 gross 3158 Paso_Preconditioner_Smoother_free(in->jacobi);
38     Paso_Preconditioner_Smoother_free(in->gs);
39 gross 3193 Paso_Preconditioner_LocalAMG_free(in->localamg);
40 gross 3283 Paso_Preconditioner_LocalSmoother_free(in->localamgsubstitute);
41 gross 3193 /*********************************/
42 jgs 150 Paso_Solver_ILU_free(in->ilu);
43 gross 430 Paso_Solver_RILU_free(in->rilu);
44 gross 3193 /*********************************/
45    
46 jgs 150 MEMFREE(in);
47     }
48     }
49 gross 3005
50 gross 3193 Paso_Preconditioner* Paso_Preconditioner_alloc(Paso_SystemMatrix* A,Paso_Options* options) {
51 gross 3005
52 gross 3193 Paso_Preconditioner* prec=NULL;
53 gross 3005
54 gross 3193 prec=MEMALLOC(1,Paso_Preconditioner);
55 gross 3120
56 jfenwick 3259 if (! Esys_checkPtr(prec)) {
57 artak 2760
58 jgs 150 prec->type=UNKNOWN;
59 gross 3193
60    
61     prec->jacobi=NULL;
62     prec->gs=NULL;
63     prec->localamg=NULL;
64 gross 3283 prec->localamgsubstitute=NULL;
65    
66 gross 3193 /*********************************/
67 gross 430 prec->rilu=NULL;
68 jgs 150 prec->ilu=NULL;
69 gross 3193 /*********************************/
70    
71 gross 3283 if (options->verbose && options->use_local_preconditioner) printf("Paso: Apply preconditioner locally only.\n");
72 artak 2662
73 jgs 150 switch (options->preconditioner) {
74     default:
75     case PASO_JACOBI:
76 gross 3283 if (options->verbose) printf("Paso: Jacobi(%d) preconditioner is used.\n",options->sweeps);
77 gross 3158 prec->jacobi=Paso_Preconditioner_Smoother_alloc(A, TRUE, options->use_local_preconditioner, options->verbose);
78 jgs 150 prec->type=PASO_JACOBI;
79 gross 3158 prec->sweeps=options->sweeps;
80 jgs 150 break;
81 gross 3094 case PASO_GS:
82 gross 3283 if (options->verbose) printf("Paso: Gauss-Seidel(%d) preconditioner is used.\n",options->sweeps);
83 gross 3158 prec->gs=Paso_Preconditioner_Smoother_alloc(A, FALSE, options->use_local_preconditioner, options->verbose);
84     prec->type=PASO_GS;
85     prec->sweeps=options->sweeps;
86 gross 3094 break;
87 gross 3283 case PASO_AMLI:
88 gross 3193 case PASO_AMG:
89 gross 3283 if (options->verbose) printf("Paso: AMG preconditioner is used.\n");
90     prec->localamg=Paso_Preconditioner_LocalAMG_alloc(A->mainBlock,1,options);
91     prec->sweeps=options->sweeps;
92     /* if NULL is returned (and no error) no AMG has been constructed because the system is too small or not big enough
93     we now use the Smoother as a preconditioner */
94     if ( (Esys_noError()) && (prec->localamg == NULL) ) {
95     if (options->verbose) {
96     if (options->smoother == PASO_JACOBI) {
97     printf("Paso: Jacobi(%d) preconditioner is used.\n",prec->sweeps);
98     } else {
99     printf("Paso: Gauss-Seidel(%d) preconditioner is used.\n",prec->sweeps);
100     }
101     }
102     prec->localamgsubstitute=Paso_Preconditioner_LocalSmoother_alloc(A->mainBlock, (options->smoother == PASO_JACOBI), options->verbose);
103     }
104     prec->type=PASO_AMG;
105 jfenwick 3259 Esys_MPIInfo_noError(A->mpi_info);
106 gross 3193 break;
107    
108 gross 3094 /***************************************************************************************/
109 jgs 150 case PASO_ILU0:
110 gross 3283 if (options->verbose) printf("Paso: ILU preconditioner is used.\n");
111 ksteube 1312 prec->ilu=Paso_Solver_getILU(A->mainBlock,options->verbose);
112 jgs 150 prec->type=PASO_ILU0;
113 jfenwick 3259 Esys_MPIInfo_noError(A->mpi_info);
114 jgs 150 break;
115 gross 430 case PASO_RILU:
116 gross 3283 if (options->verbose) printf("Paso: RILU preconditioner is used.\n");
117 ksteube 1312 prec->rilu=Paso_Solver_getRILU(A->mainBlock,options->verbose);
118 jfenwick 3259 Esys_MPIInfo_noError(A->mpi_info);
119 gross 430 prec->type=PASO_RILU;
120     break;
121 jgs 150 }
122     }
123 jfenwick 3259 if (! Esys_MPIInfo_noError(A->mpi_info ) ){
124 gross 3120 Paso_Preconditioner_free(prec);
125     return NULL;
126     } else {
127     return prec;
128     }
129 jgs 150 }
130    
131     /* applies the preconditioner */
132     /* has to be called within a parallel reqion */
133     /* barrier synchronization is performed before the evaluation to make sure that the input vector is available */
134 gross 3193 void Paso_Preconditioner_solve(Paso_Preconditioner* prec, Paso_SystemMatrix* A,double* x,double* b){
135 gross 3283
136 jgs 150 switch (prec->type) {
137     default:
138     case PASO_JACOBI:
139 gross 3159 Paso_Preconditioner_Smoother_solve(A, prec->jacobi,x,b,prec->sweeps, FALSE);
140 gross 3125 break;
141 gross 3094 case PASO_GS:
142 gross 3159 Paso_Preconditioner_Smoother_solve(A, prec->gs,x,b,prec->sweeps, FALSE);
143 gross 3193 break;
144     case PASO_AMG:
145 gross 3283 if (prec->localamg == NULL) {
146     Paso_Preconditioner_LocalSmoother_solve(A->mainBlock, prec->localamgsubstitute,x,b,prec->sweeps, FALSE);
147     } else {
148     Paso_Preconditioner_LocalAMG_solve(A->mainBlock, prec->localamg,x,b);
149     }
150 gross 3193 break;
151    
152     /*=========================================================*/
153 jgs 150 case PASO_ILU0:
154 gross 3094 Paso_Solver_solveILU(A->mainBlock, prec->ilu,x,b);
155 jgs 150 break;
156 gross 430 case PASO_RILU:
157 gross 3094 Paso_Solver_solveRILU(prec->rilu,x,b);
158 gross 430 break;
159 gross 3094
160 jgs 150 }
161 gross 3094
162 jgs 150 }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26