Skip to content

Commit

Permalink
bugfix in timestep
Browse files Browse the repository at this point in the history
  • Loading branch information
vlakir committed Oct 21, 2021
1 parent 4a5621d commit 7ddd645
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions cleanode/ode_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,17 @@ def solve(self, print_benchmark=False, benchmark_name='') -> Tuple[np.ndarray, n
# noinspection PyTypeChecker
u_next1 = self._do_step(self.u, self.f, i, self.t, self.dt, self.a, self.b1, self.c)

real_tolerance = (abs(u_next - u_next1).sum())
real_tolerance = max(abs(u_next - u_next1))

# the way from [Hairer, Norsett, Wanner: Solving Ordinary Differential Equations I]
order = len(self.a)
self.dt *= 0.8 * (self.tolerance / real_tolerance) ** (1 / (order + 1))
fact_max = 1.5
if real_tolerance != 0:
fact_real = (self.tolerance / real_tolerance) ** (1 / (order + 1))
else:
fact_real = fact_max * 2
fact = min([fact_max, fact_real])
self.dt *= 0.8 * fact

self.t = np.append(self.t, self.t[-1] + dt_current)
else:
Expand Down
2 changes: 1 addition & 1 deletion system_ode_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def exact_f(t):
tmax = np.longdouble(10 * math.pi)
dt0 = np.longdouble(0.01)

tolerance = 1e-4
tolerance = 1e-5
is_adaptive_step = True

# initial conditions:
Expand Down

0 comments on commit 7ddd645

Please sign in to comment.