Skip to content

Commit 1b79563

Browse files
committed
Unified check_solution functions + renaming
1 parent 674d73a commit 1b79563

File tree

9 files changed

+314
-335
lines changed

9 files changed

+314
-335
lines changed

pySDC/implementations/problem_classes/Battery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def solve_system(self, rhs, factor, u0, t):
271271
return me
272272

273273

274-
class battery_n_condensators(ptype):
274+
class battery_n_capacitors(ptype):
275275
"""
276276
Example implementing the battery drain model with N capacitors, where N is an arbitrary integer greater than 0.
277277
Attributes:
@@ -299,7 +299,7 @@ def __init__(self, problem_params, dtype_u=mesh, dtype_f=imex_mesh):
299299
problem_params['nvars'] = n + 1
300300

301301
# invoke super init, passing number of dofs, dtype_u and dtype_f
302-
super(battery_n_condensators, self).__init__(
302+
super(battery_n_capacitors, self).__init__(
303303
init=(problem_params['nvars'], None, np.dtype('float64')),
304304
dtype_u=dtype_u,
305305
dtype_f=dtype_f,

pySDC/projects/PinTSimE/battery_2condensators_model.py renamed to pySDC/projects/PinTSimE/battery_2capacitors_model.py

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from pySDC.helpers.stats_helper import get_sorted
66
from pySDC.core.Collocation import CollBase as Collocation
7-
from pySDC.implementations.problem_classes.Battery import battery_n_condensators
7+
from pySDC.implementations.problem_classes.Battery import battery_n_capacitors
88
from pySDC.implementations.sweeper_classes.imex_1st_order import imex_1st_order
99
from pySDC.implementations.controller_classes.controller_nonMPI import controller_nonMPI
1010
from pySDC.projects.PinTSimE.battery_model import get_recomputed
@@ -116,7 +116,7 @@ def main(use_switch_estimator=True):
116116

117117
# fill description dictionary for easy step instantiation
118118
description = dict()
119-
description['problem_class'] = battery_n_condensators # pass problem class
119+
description['problem_class'] = battery_n_capacitors # pass problem class
120120
description['problem_params'] = problem_params # pass problem parameters
121121
description['sweeper_class'] = imex_1st_order # pass sweeper
122122
description['sweeper_params'] = sweeper_params # pass sweeper parameters
@@ -150,7 +150,7 @@ def main(use_switch_estimator=True):
150150

151151
recomputed = False
152152

153-
check_solution(stats, use_switch_estimator)
153+
check_solution(stats, level_params['dt'], use_switch_estimator)
154154

155155
plot_voltages(description, recomputed, use_switch_estimator)
156156

@@ -203,28 +203,60 @@ def plot_voltages(description, recomputed, use_switch_estimator, cwd='./'):
203203
plt_helper.plt.close(fig)
204204

205205

206-
def check_solution(stats, use_switch_estimator):
206+
def check_solution(stats, dt, use_switch_estimator):
207207
"""
208208
Function that checks the solution based on a hardcoded reference solution. Based on check_solution function from @brownbaerchen.
209209
210210
Args:
211211
stats (dict): Raw statistics from a controller run
212+
dt (float): initial time step
212213
use_switch_estimator (bool): flag if the switch estimator wants to be used or not
213214
"""
214215

215216
data = get_data_dict(stats, use_switch_estimator)
216217

217218
if use_switch_estimator:
218-
msg = 'Error when using the switch estimator for battery_2condensators:'
219-
expected = {
220-
'cL': 1.2065280755094876,
221-
'vC1': 1.0094825899806945,
222-
'vC2': 1.0050052828742688,
223-
'switch1': 1.6094379124373626,
224-
'switch2': 3.209437912457051,
225-
'restarts': 2.0,
226-
'sum_niters': 1568,
227-
}
219+
msg = f'Error when using the switch estimator for battery_2condensators for dt={dt:.1e}:'
220+
if dt == 1e-2:
221+
expected = {
222+
'cL': 1.2065280755094876,
223+
'vC1': 1.0094825899806945,
224+
'vC2': 1.0050052828742688,
225+
'switch1': 1.6094379124373626,
226+
'switch2': 3.209437912457051,
227+
'restarts': 2.0,
228+
'sum_niters': 1568,
229+
}
230+
elif dt == 4e-1:
231+
expected = {
232+
'cL': 1.1842780233981391,
233+
'vC1': 1.0094891393319418,
234+
'vC2': 1.00103823232433,
235+
'switch1': 1.6075867934844466,
236+
'switch2': 3.209437912436633,
237+
'restarts': 2.0,
238+
'sum_niters': 2000,
239+
}
240+
elif dt == 4e-2:
241+
expected = {
242+
'cL': 1.180493652021971,
243+
'vC1': 1.0094825917376264,
244+
'vC2': 1.0007713468084405,
245+
'switch1': 1.6094074085553605,
246+
'switch2': 3.209437912440314,
247+
'restarts': 2.0,
248+
'sum_niters': 2364,
249+
}
250+
elif dt == 4e-3:
251+
expected = {
252+
'cL': 1.1537529501025199,
253+
'vC1': 1.001438946726028,
254+
'vC2': 1.0004331625246141,
255+
'switch1': 1.6093728710270467,
256+
'switch2': 3.217437912434171,
257+
'restarts': 2.0,
258+
'sum_niters': 8920,
259+
}
228260

229261
got = {
230262
'cL': data['cL'][-1],

0 commit comments

Comments
 (0)