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

Contents of /trunk/paso/src/Preconditioner.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4873 - (show annotations)
Wed Apr 16 06:38:51 2014 UTC (5 years, 5 months ago) by caltinay
File size: 5139 byte(s)
whitespace only changes.

1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2014 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 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16
17
18 /****************************************************************************
19
20 * Paso: preconditioner set up
21
22 ****************************************************************************/
23
24 /* Author: Lutz Gross, l.gross@uq.edu.au */
25
26 /****************************************************************************/
27
28 #include "Paso.h"
29 #include "SystemMatrix.h"
30 #include "PasoUtil.h"
31 #include "Preconditioner.h"
32
33 namespace paso {
34
35 void Preconditioner_free(Preconditioner* in)
36 {
37 if (in!=NULL) {
38 Preconditioner_Smoother_free(in->jacobi);
39 Preconditioner_Smoother_free(in->gs);
40 Preconditioner_AMG_Root_free(in->amg);
41 Solver_ILU_free(in->ilu);
42 Solver_RILU_free(in->rilu);
43 delete in;
44 }
45 }
46
47 Preconditioner* Preconditioner_alloc(SystemMatrix_ptr A, Options* options)
48 {
49 Preconditioner* prec = new Preconditioner;
50 prec->type=UNKNOWN;
51 prec->jacobi=NULL;
52 prec->gs=NULL;
53 prec->amg=NULL;
54 prec->rilu=NULL;
55 prec->ilu=NULL;
56
57 if (options->verbose && options->use_local_preconditioner)
58 printf("Paso: Applying preconditioner locally only.\n");
59
60 switch (options->preconditioner) {
61 default:
62 case PASO_JACOBI:
63 if (options->verbose) {
64 if (options->sweeps >0 ) {
65 printf("Preconditioner: Jacobi(%d) preconditioner is used.\n",options->sweeps);
66 } else {
67 printf("Preconditioner: Jacobi preconditioner is used.\n");
68 }
69 }
70 prec->jacobi=Preconditioner_Smoother_alloc(A, true, options->use_local_preconditioner, options->verbose);
71 prec->type=PASO_JACOBI;
72 prec->sweeps=options->sweeps;
73 break;
74
75 case PASO_GS:
76 if (options->verbose) {
77 if (options->sweeps >0) {
78 printf("Preconditioner: Gauss-Seidel(%d) preconditioner is used.\n",options->sweeps);
79 } else {
80 printf("Preconditioner: Gauss-Seidel preconditioner is used.\n");
81 }
82 }
83 prec->gs = Preconditioner_Smoother_alloc(A, false, options->use_local_preconditioner, options->verbose);
84 prec->type = PASO_GS;
85 prec->sweeps = options->sweeps;
86 break;
87
88 case PASO_BOOMERAMG:
89 case PASO_AMLI:
90 case PASO_AMG:
91 prec->amg = Preconditioner_AMG_Root_alloc(A, options);
92 prec->type = PASO_AMG;
93 break;
94
95 case PASO_ILU0:
96 if (options->verbose)
97 printf("Preconditioner: ILU preconditioner is used.\n");
98 prec->ilu = Solver_getILU(A->mainBlock, options->verbose);
99 prec->type = PASO_ILU0;
100 Esys_MPIInfo_noError(A->mpi_info);
101 break;
102
103 case PASO_RILU:
104 if (options->verbose)
105 printf("Preconditioner: RILU preconditioner is used.\n");
106 prec->rilu = Solver_getRILU(A->mainBlock,options->verbose);
107 Esys_MPIInfo_noError(A->mpi_info);
108 prec->type=PASO_RILU;
109 break;
110
111 case PASO_NO_PRECONDITIONER:
112 if (options->verbose)
113 printf("Preconditioner: no preconditioner is applied.\n");
114 prec->type=PASO_NO_PRECONDITIONER;
115 break;
116 }
117 if (!Esys_noError()) {
118 Preconditioner_free(prec);
119 return NULL;
120 }
121 return prec;
122 }
123
124 /* Applies the preconditioner. */
125 /* Has to be called within a parallel region. */
126 /* Barrier synchronization is performed before the evaluation to make sure that the input vector is available */
127 void Preconditioner_solve(Preconditioner* prec, SystemMatrix_ptr A,
128 double* x, double* b)
129 {
130 dim_t n=0;
131
132 switch (prec->type) {
133 default:
134 case PASO_JACOBI:
135 Preconditioner_Smoother_solve(A, prec->jacobi, x, b, prec->sweeps, false);
136 break;
137 case PASO_GS:
138 Preconditioner_Smoother_solve(A, prec->gs, x, b, prec->sweeps, false);
139 break;
140 case PASO_AMG:
141 Preconditioner_AMG_Root_solve(A, prec->amg, x, b);
142 break;
143 case PASO_ILU0:
144 Solver_solveILU(A->mainBlock, prec->ilu, x, b);
145 break;
146 case PASO_RILU:
147 Solver_solveRILU(prec->rilu, x, b);
148 break;
149 case PASO_NO_PRECONDITIONER:
150 n = std::min(A->getTotalNumCols(), A->getTotalNumRows());
151 util::copy(n,x,b);
152 break;
153 }
154 }
155
156 } // namespace paso
157

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision
svn:mergeinfo /branches/amg_from_3530/paso/src/Preconditioner.cpp:3531-3826 /branches/lapack2681/paso/src/Preconditioner.cpp:2682-2741 /branches/pasowrap/paso/src/Preconditioner.cpp:3661-3674 /branches/py3_attempt2/paso/src/Preconditioner.cpp:3871-3891 /branches/restext/paso/src/Preconditioner.cpp:2610-2624 /branches/ripleygmg_from_3668/paso/src/Preconditioner.cpp:3669-3791 /branches/stage3.0/paso/src/Preconditioner.cpp:2569-2590 /branches/symbolic_from_3470/paso/src/Preconditioner.cpp:3471-3974 /branches/symbolic_from_3470/ripley/test/python/paso/src/Preconditioner.cpp:3517-3974 /release/3.0/paso/src/Preconditioner.cpp:2591-2601 /trunk/paso/src/Preconditioner.cpp:4257-4344 /trunk/ripley/test/python/paso/src/Preconditioner.cpp:3480-3515

  ViewVC Help
Powered by ViewVC 1.1.26