libode
Easy to compile, fast ODE integrators as C++ classes
Loading...
Searching...
No Matches
ode_newton.h
Go to the documentation of this file.
1#ifndef ODE_NEWTON_H_
2#define ODE_NEWTON_H_
3
5
6#include <cmath>
7#include <cstdio>
8#include <cstdlib>
9
10#include "ode_linalg.h"
11
12namespace ode {
13
15
18class OdeNewton {
19
20 public:
22
25 OdeNewton (unsigned long n);
27 virtual ~OdeNewton ();
28
29 //-------------------
30 //getters and setters
31
33 unsigned long get_n () { return(n_); }
35 double get_tol_Newton () { return(tol_Newton_); }
37 unsigned long get_iter_Newton () { return(iter_Newton_); }
39 int get_iJLU () { return(iJLU_); }
41 unsigned long get_nJLU () { return(nJLU_); }
43 unsigned long get_n_solve_LU () { return(n_solve_LU_); }
45 bool get_modified () { return(modified_); }
47 bool get_ignore_JLU () { return(ignore_JLU_); }
48
50 void set_tol_Newton (double tol_Newton) { tol_Newton_ = tol_Newton; }
52 void set_iter_Newton (unsigned long iter_Newton) { iter_Newton_ = iter_Newton; }
54 void set_iJLU (int iJLU) { iJLU_ = iJLU; }
56 void set_modified (bool modified) { modified_ = modified; }
58 void set_ignore_JLU (bool ignore_JLU) { ignore_JLU_ = ignore_JLU; }
59
61
68 int solve_Newton (double *x);
69
70 protected:
72
76 virtual void f_Newton (double *x, double *f) = 0;
78
82 virtual void J_Newton (double *x, double **J) = 0;
83
84 private:
85 //size of system
86 unsigned long n_;
87 //whether to use only a single evaluation and LU decomposition of Jac
88 bool modified_;
89 //whether to do no JLU updates at all
90 bool ignore_JLU_;
91 //error tolerance
92 double tol_Newton_;
93 //iteration tolerance
94 unsigned long iter_Newton_;
95 //number of iterations after which the Jacobian is updated and redecomposed
96 int iJLU_;
97 //number of times Jac has been updated
98 unsigned long nJLU_;
99 //number of times the LU decomposed matrix has been used to solve a matrix eq
100 unsigned long n_solve_LU_;
101 //iteration interval for checking solution integrity
102 unsigned long icheck_;
103 //current evaluation of F
104 double *f_;
105 //current evaluation of J
106 double **J_;
107 //update array
108 double *delx_;
109 //permutation array
110 int *p_;
111 //finds the infinity norm of the update vector delx and of y
112 void err (double *errx, double *erry);
113 //recomputes the Jacobian and crout LU decomposes it
114 void JLU (double *x);
115 //wrapper around LU solving routine for counting solves
116 void solve_LU_(double **LU, int *p, double *b, int n, double *out);
117 //function for checking solution integrity (can't have NAN or INFINITY)
118 int check_integrity (double *x);
119};
120
121} // namespace ode
122
123#endif
Newton's method for nonlinear systems of equations.
Definition ode_newton.h:18
void set_modified(bool modified)
sets whether modified Newtion's is being used
Definition ode_newton.h:56
virtual void J_Newton(double *x, double **J)=0
evaluates the Jacobian matrix of the function being zeroed
int solve_Newton(double *x)
Solve the system of equations.
Definition ode_newton.cc:84
OdeNewton(unsigned long n)
constructs
Definition ode_newton.cc:7
bool get_modified()
gets whether modified Newtion's is being used
Definition ode_newton.h:45
unsigned long get_iter_Newton()
gets iteration counter
Definition ode_newton.h:37
int get_iJLU()
gets the LU decomposition interval
Definition ode_newton.h:39
virtual ~OdeNewton()
destructs
Definition ode_newton.cc:38
void set_iJLU(int iJLU)
sets the LU decomposition interval
Definition ode_newton.h:54
void set_tol_Newton(double tol_Newton)
sets the L infinity tolerance
Definition ode_newton.h:50
unsigned long get_nJLU()
gets the LU decomposition counter
Definition ode_newton.h:41
virtual void f_Newton(double *x, double *f)=0
evaluates the function being zeroed
void set_iter_Newton(unsigned long iter_Newton)
sets the iteration counter
Definition ode_newton.h:52
unsigned long get_n_solve_LU()
gets the LU solve counter
Definition ode_newton.h:43
unsigned long get_n()
gets the size of the system
Definition ode_newton.h:33
bool get_ignore_JLU()
gets whether no LU decompositions should be done
Definition ode_newton.h:47
double get_tol_Newton()
gets the L infinity tolerance
Definition ode_newton.h:35
void set_ignore_JLU(bool ignore_JLU)
sets whether no LU decompositions should be done
Definition ode_newton.h:58