1 |
/* $Id$ */ |
2 |
|
3 |
/**************************************************************/ |
4 |
|
5 |
/* Paso: SystemMatrix: sets-up the preconditioner */ |
6 |
|
7 |
/**************************************************************/ |
8 |
|
9 |
/* Copyrights by ACcESS Australia 2003/04 */ |
10 |
/* Author: gross@access.edu.au */ |
11 |
|
12 |
/**************************************************************/ |
13 |
|
14 |
#include "Paso.h" |
15 |
#include "SystemMatrix.h" |
16 |
#include "Solver.h" |
17 |
|
18 |
/***********************************************************************************/ |
19 |
|
20 |
/* free space */ |
21 |
|
22 |
void Paso_Preconditioner_free(Paso_Solver_Preconditioner* in) { |
23 |
if (in!=NULL) { |
24 |
Paso_Solver_ILU_free(in->ilu); |
25 |
Paso_Solver_RILU_free(in->rilu); |
26 |
Paso_Solver_Jacobi_free(in->jacobi); |
27 |
MEMFREE(in); |
28 |
} |
29 |
} |
30 |
/* call the iterative solver: */ |
31 |
|
32 |
void Paso_Solver_setPreconditioner(Paso_SystemMatrix* A,Paso_Options* options) { |
33 |
Paso_Solver_Preconditioner* prec=NULL; |
34 |
if (A->solver==NULL) { |
35 |
/* allocate structure to hold preconditioner */ |
36 |
prec=MEMALLOC(1,Paso_Solver_Preconditioner); |
37 |
if (Paso_checkPtr(prec)) return; |
38 |
prec->type=UNKNOWN; |
39 |
prec->rilu=NULL; |
40 |
prec->ilu=NULL; |
41 |
prec->jacobi=NULL; |
42 |
A->solver=prec; |
43 |
switch (options->preconditioner) { |
44 |
default: |
45 |
case PASO_JACOBI: |
46 |
if (options->verbose) printf("Jacobi preconditioner is used.\n"); |
47 |
prec->jacobi=Paso_Solver_getJacobi(A); |
48 |
prec->type=PASO_JACOBI; |
49 |
break; |
50 |
case PASO_ILU0: |
51 |
if (options->verbose) printf("ILU preconditioner is used.\n"); |
52 |
prec->ilu=Paso_Solver_getILU(A,options->verbose); |
53 |
prec->type=PASO_ILU0; |
54 |
break; |
55 |
case PASO_RILU: |
56 |
if (options->verbose) printf("RILU preconditioner is used.\n"); |
57 |
prec->rilu=Paso_Solver_getRILU(A,options->verbose); |
58 |
prec->type=PASO_RILU; |
59 |
break; |
60 |
} |
61 |
if (! Paso_noError()) { |
62 |
Paso_Preconditioner_free(prec); |
63 |
A->solver=NULL; |
64 |
} |
65 |
} |
66 |
} |
67 |
|
68 |
/* applies the preconditioner */ |
69 |
/* has to be called within a parallel reqion */ |
70 |
/* barrier synchronization is performed before the evaluation to make sure that the input vector is available */ |
71 |
void Paso_Solver_solvePreconditioner(Paso_SystemMatrix* A,double* x,double* b){ |
72 |
Paso_Solver_Preconditioner* prec=(Paso_Solver_Preconditioner*) A->solver; |
73 |
#pragma omp barrier |
74 |
switch (prec->type) { |
75 |
default: |
76 |
case PASO_JACOBI: |
77 |
Paso_Solver_solveJacobi(prec->jacobi,x,b); |
78 |
break; |
79 |
case PASO_ILU0: |
80 |
Paso_Solver_solveILU(prec->ilu,x,b); |
81 |
break; |
82 |
case PASO_RILU: |
83 |
Paso_Solver_solveRILU(prec->rilu,x,b); |
84 |
break; |
85 |
} |
86 |
} |
87 |
|
88 |
/* |
89 |
* $Log$ |
90 |
* Revision 1.2 2005/09/15 03:44:40 jgs |
91 |
* Merge of development branch dev-02 back to main trunk on 2005-09-15 |
92 |
* |
93 |
* Revision 1.1.2.2 2005/09/07 00:59:09 gross |
94 |
* some inconsistent renaming fixed to make the linking work. |
95 |
* |
96 |
* Revision 1.1.2.1 2005/09/05 06:29:50 gross |
97 |
* These files have been extracted from finley to define a stand alone libray for iterative |
98 |
* linear solvers on the ALTIX. main entry through Paso_solve. this version compiles but |
99 |
* has not been tested yet. |
100 |
* |
101 |
* |
102 |
*/ |