-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRK45_lang.py
51 lines (38 loc) · 1.14 KB
/
RK45_lang.py
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
from scipy.integrate import RK45
from scipy.integrate._ivp.rk import rk_step
import numpy as np
class RK45_lang(RK45):
""" Solve RK with fixed time step. Needed when using random number generators
Use nskip to do internally some steps instead of keep calling the function.
"""
def set_nskip(self, nskip):
self.ncalls = 0
self.nskip = nskip
def set_step(self, h):
self.h = h
self.h_abs = np.abs(h)
def _step_impl(self):
t0 = self.t
y0 = self.y
h_abs = self.h_abs
h = self.h
nskip = self.nskip
step_accepted = False
step_rejected = False
t = t0
y = y0
f = self.f
for ii in range(nskip):
y, f = rk_step(self.fun, t, y, f, h, self.A,
self.B, self.C, self.K)
#y, f = rk_step(self.fun, t, y, f, h)
t += h
self.ncalls += 1
step_accepted = True # Cannot fail, is fix step.
self.h_previous = h
self.y_old = y0
self.t = t
self.y = y
self.h_abs = h_abs
self.f = f
return True, None