-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathConjGrad.hh
135 lines (118 loc) · 5.15 KB
/
ConjGrad.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**********************************************************************
* *
* File Name: ConjGrad.hh *
* *
* Class Name: ConjGrad *
* *
* Goal: This a conjugate gradient with incomplete Cholesky *
* preconditioner for sparse matrix *
* *
* Solve A*x=b with A[Nt][3][3] the local matrix *
* *
* Coort[Nt][3] has values between 0 and N-1, gives *
* the 3 vertices or the 3 nodes of each triangle *
* *
* b[N] is the left hand side, *
* *
* x[N] is in input a initialized vector, (if we rougthly know the *
* expected value) and the solution in output *
* *
* mask[N] int array, mask[i]=1 if we compute the ith value in x, =0 *
* if not. It is used for Diriclet conditions when we already know *
* the value. *
* *
* x=xD+x0, as we do not compute xD (Dirichlet), we have A*x=b *
* equivalent to A*x0=b-A*xD. *
* This is this last system that we compute. *
* *
* If the code crashes, first increase Nterm *
* This is the maximum number of non-0 values for a row *
* of the sparse matrix A *
* *
* Copyright (C) 04/2002 Arthur Moncorge *
* from Mats Nigam's Fortran code *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, *
* MA 02111-1307, USA. *
* *
*********************************************************************/
#ifndef _CLASS_CONJGRAD_HH_
#define _CLASS_CONJGRAD_HH_
#include<iostream>
#include<math.h>
#include"mylibrary.hh"
#include<stdio.h>
using namespace std;
class ConjGrad
{
public:
ConjGrad()
{
cout << "Class Conjugate Gradient" << endl;
}
~ConjGrad()
{
int i,j;
cout << "Destructor ConjGrad" << endl;
delete[] r;
delete[] w;
delete[] Aw;
delete[] q;
for (i=0; i<N; i++)
{
delete [] Aspar[i];
delete [] chol[i];
delete [] cholt[i];
delete [] indexA[i];
}
delete [] Aspar;
delete [] chol;
delete [] cholt;
delete [] indexA;
delete [] rowsize;
delete [] diag;
}
void init(int iN, int iNt, double itol, int** iCoort);
int solve(double*** A, double* b, int* mask, double* x);
void sparceA(double*** A, double** Aspar, int** indexA, int* diag, int* rowsize);
void cholesky_fact(double** Aspar, int** indexA, int* diag,
double** chol, double** cholt);
void lower(int N, int* diag, int** indexA,
double** chol, double* b, double* x);
void upper(int N, int* diag, int** indexA, int* rowsize,
double** cholt, double* b, double* x);
public:
// Constants
double tol;
int N;
int Nt;
int** Coort;
// private
// Working arrays
double* r;
double* w;
double* Aw;
double* q;
/* For the incomplete Cholesky preconditionner */
int Nterm; //=10;
double** Aspar;
double** chol;
double** cholt;
int** indexA;
int* rowsize;
int* diag;
};
#endif // End of _CLASS_CONJGRAD_HH_