-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscvodew.h
132 lines (98 loc) · 3.26 KB
/
scvodew.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
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
#ifndef _SCVODEW_H_
#define _SCVODEW_H_
#include <cvode/cvode.h>
#define STIFF_INTEGRATOR CV_BDF
#define NONSTIFF_INTEGRATOR CV_ADAMS
/* This library is a wrapper of CVODE that hides integration details
* that might not be of interest of someone that is new to CVODE. For
* more general use of CVODE, we recommend using directly the library
* itself.
* */
typedef struct cvode_solver {
void *cvode_mem;
SUNLinearSolver LS;
SUNMatrix J;
N_Vector y0;
} SimpleCVODESolver;
/*
This function creates a CVODE solver of type SimpleCVODESolver and
returns a pointer to it.
Arguments
lmm: specifies the linear multistep method and it must be either
CV_ADAMS (for non-stiff problems) or CV_BDF (for stiff
problems).
Returns a pointer to the newly created object. Returns NULL if failed
to create such object.
*/
SimpleCVODESolver *new_cvode_solver(int lmm);
/* This function allows the user to set the initial values for variables
of the system of ODEs.
Arguments
solver: a pointer to the solver object;
f: a function that defines the system of ODEs. This function must
have the signature f(realtype t, N_Vector y, N_Vector ydot,
void *f_data);
t0: the starting time of integration;
y0: a pointer to a list of initial values;
n: the size of the list y0.
Returns 0 if success.
*/
int init_solver(SimpleCVODESolver *solver, int (*f)(realtype,
N_Vector, N_Vector, void *), float t0, float *y0, int n);
/*
This function sets the tolerances for the integrator.
Arguments
solver: a pointer to the solver object;
abstol: absolute error tolerance;
reltol: relative error tolerance.
Returns 0 if success.
*/
int set_tolerance(SimpleCVODESolver *solver, float abstol,
float reltol);
/*
This function sets the max number of steps in an integration call.
*/
int set_max_step(SimpleCVODESolver *solver, int mxsteps);
/*
Prepares the solver for integration.
Arguments
solver: a pointer to the solver object.
Returns 0 if success.
*/
int prepare_solver(SimpleCVODESolver *solver);
/*
This function allows the user to define data that will be passed to f,
during integration.
Arguments
solver: a pointer to the solver object;
data: a pointer to the data.
Returns 0 if success.
*/
int set_system_data(SimpleCVODESolver *solver, void *data);
/*
Integrates the system.
Arguments
solver: the solver being used;
t: a list with times for which integration values should be stored;
m: the size of the t.
Returns a matrix containing the integrated values of the function on the
specified times. This matrix has size mxn, where m is the number of
times specified, and n is the number of components of the integrated
function.
*/
float ** integrate(SimpleCVODESolver *solver, float *t, int m);
/*
Resets the integrator.
Arguments
solver: the solver that needs to be restarted;
t0: the starting point to which the integrator should be reset;
y0: the initial conditions to which the system should be reset.
Returns 0 if success.
Note: y0 should be of same dimension as set before, in init_solver().
*/
int reset_solver(SimpleCVODESolver *solver, float t0, float *y0);
/*
Frees the memory used by a SimpleCVODESolver object.
*/
void delete_solver(SimpleCVODESolver *solver);
#endif