-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnewton_krylov.h
54 lines (40 loc) · 995 Bytes
/
newton_krylov.h
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
#ifndef NEWTON_KRYLOV_H
#define NEWTON_KRYLOV_H
#include <limits>
#include "types.h"
const double INF = std::numeric_limits<double>::max();
const double mEPS = 2.2204460492503131e-16;
class KrylovJacobian
{
VecFunc func;
int maxiter;
int inner_m;
unsigned int outer_k;
Vec x0;
Vec f0;
double rdiff;
double omega;
std::vector<Vec> outer_v;
Mat M;
public:
void update_diff_step();
KrylovJacobian(Vecr x, Vecr f, VecFunc F);
Vec matvec(Vec v);
Vec psolve(Vec v);
Vec solve(Vecr rhs, double tol);
void update(Vecr x, Vecr f);
};
class TerminationCondition
{
double f_tol;
double f_rtol;
double x_tol;
double x_rtol;
double f0_norm;
public:
TerminationCondition(double ftol, double frtol, double xtol, double xrtol);
int check(Vecr f, Vecr x, Vecr dx);
};
Vec nonlin_solve(VecFunc F, Vecr x,
double f_tol, double f_rtol, double x_tol, double x_rtol);
#endif // NEWTON_KRYLOV_H