Commit 7fc3c9c4 authored by Thomas Baumann's avatar Thomas Baumann
Browse files

Adaptivity will no go to Tend-dt_initial and then perform a last step with the...

Adaptivity will no go to Tend-dt_initial and then perform a last step with the initial step size to get to the same final time as a fixed step scheme would
parent 42b90185
......@@ -5,6 +5,7 @@ from pySDC.helpers.pysdc_helper import FrozenClass
class _Pars(FrozenClass):
def __init__(self, params):
self.dt = None
self.dt_initial = None
self.restol = 0.0
self.nsweeps = 1
self.residual_type = 'full_abs'
......@@ -13,6 +14,8 @@ class _Pars(FrozenClass):
# freeze class, no further attributes allowed from this point
self._freeze()
self.dt_initial = self.dt * 1.
# short helper class to bundle all status variables
class _Status(FrozenClass):
......
......@@ -202,7 +202,7 @@ s to have a constant order in time for adaptivity. Setting restol=0')
uend = self.MS[active_slots[-1]].levels[0].uend
time[active_slots[0]] = time[active_slots[-1]] + self.MS[active_slots[-1]].dt
self.update_step_sizes(active_slots)
self.update_step_sizes(active_slots, time, Tend)
# setup the times of the steps for the next block
for i in range(1, len(active_slots)):
......@@ -823,7 +823,7 @@ ing adaptivity!'
if L.status.error_embedded_estimate >= L.params.e_tol:
S.status.restart = True
def update_step_sizes(self, active_slots):
def update_step_sizes(self, active_slots, time, Tend):
"""
Update the step sizes computed in adaptivity or wherever here, since this can get arbitrarily elaborate
"""
......@@ -834,11 +834,17 @@ ing adaptivity!'
else:
restart_at = len(restarts) - 1
# record the step sizes to restart with
# Compute the maximum allowed step size based on Tend. The final step will be computed with the original
# step size to reach the same final time regardless of step size control
dt_max = (Tend-self.MS[restart_at].levels[0].params.dt_initial - time[0]) / len(active_slots)
# record the step sizes to restart with from all the levels of the step
new_steps = [None] * len(self.MS[restart_at].levels)
for i in range(len(self.MS[restart_at].levels)):
l = self.MS[restart_at].levels[i]
new_steps[i] = l.status.dt_new if l.status.dt_new is not None else l.params.dt
# overrule the step size control to reach Tend if needed
new_steps[i] = min([l.status.dt_new if l.status.dt_new is not None else l.params.dt,
max([dt_max, l.params.dt_initial])])
# spread the step sizes to all levels
for j in range(len(active_slots)):
......
......@@ -126,61 +126,69 @@ def plot(stats, use_adaptivity, num_procs, generate_reference=False):
if use_adaptivity and num_procs == 1:
error_msg = 'Error when using adaptivity in serial:'
expected = {
'v1': 83.88240785649039,
'v2': 80.62744370831926,
'p3': 16.137248067563256,
'e_em': 6.236525251779312e-08,
'e_ex': 6.33675177461887e-08,
'dt': 0.09607389421085785,
'v1': 83.88400120208927,
'v2': 80.62656174446846,
'p3': 16.134850636244856,
'e_em': 9.535710887575988e-09,
'e_ex': 5.203249735635934e-08,
'dt': 0.0587195170595578,
'restarts': 1.0,
'sweeps': 2416.0,
't': 19.95,
}
elif use_adaptivity and num_procs == 4:
error_msg = 'Error when using adaptivity in parallel:'
expected = {
'v1': 83.88317481237193,
'v2': 80.62700122995363,
'p3': 16.136136147445036,
'e_em': 2.9095385656319195e-08,
'e_ex': 5.666752074991754e-08,
'dt': 0.09347348421862582,
'v1': 83.88400085600999,
'v2': 80.62656228348706,
'p3': 16.134850343534808,
'e_em': 1.5352657811718018e-08,
'e_ex': 5.685289098759357e-08,
'dt': 0.07015581329617149,
'restarts': 8.0,
'sweeps': 2400.0,
'sweeps': 2404.0,
't': 19.95,
}
elif not use_adaptivity and num_procs == 4:
error_msg = 'Error with fixed step size in parallel:'
expected = {
'v1': 83.88400149770143,
'v2': 80.62656173487008,
'p3': 16.134849851184736,
'e_em': 4.977994905175365e-09,
'e_ex': 5.048084913047097e-09,
'v1': 83.88400128006428,
'v2': 80.62656202423844,
'p3': 16.134849781053525,
'e_em': 4.7536339309317555e-09,
'e_ex': 5.372188915941894e-09,
'dt': 0.05,
'restarts': 0.0,
'sweeps': 1600.0,
't': 19.95000000000015,
}
elif not use_adaptivity and num_procs == 1:
error_msg = 'Error with fixed step size in serial:'
expected = {
'v1': 83.88400149770143,
'v2': 80.62656173487008,
'p3': 16.134849851184736,
'e_em': 4.977994905175365e-09,
'e_ex': 5.048084913047097e-09,
'e_em': 5.034856087604567e-09,
'e_ex': 5.114154137212804e-09,
'dt': 0.05,
'restarts': 0.0,
'sweeps': 1600.0,
't': 19.95000000000015,
}
got = {
'v1': v1[-1],
'v2': v2[-1],
'p3': p3[-1],
'e_em': e_em[-1],
'e_ex': e_ex[e_ex != [None]][-1],
'dt': dt[-1],
'e_em': e_em[-2],
'e_ex': e_ex[e_ex != [None]][-2],
'dt': dt[-2],
'restarts': restarts.sum(),
'sweeps': sweeps.sum(),
't': t[-1],
}
if generate_reference:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment