|
11 | 11 | from pySDC.projects.PinTSimE.piline_model import setup_mpl |
12 | 12 | from pySDC.projects.PinTSimE.battery_model import get_recomputed, log_data, proof_assertions_description |
13 | 13 | import pySDC.helpers.plot_helper as plt_helper |
| 14 | +from pySDC.core.Hooks import hooks |
14 | 15 |
|
15 | 16 | from pySDC.projects.PinTSimE.switch_estimator import SwitchEstimator |
16 | 17 | from pySDC.implementations.convergence_controller_classes.adaptivity import Adaptivity |
17 | 18 | from pySDC.implementations.convergence_controller_classes.estimate_embedded_error import EstimateEmbeddedErrorNonMPI |
18 | 19 |
|
19 | 20 |
|
| 21 | +class log_data_adaptivity(hooks): |
| 22 | + def post_step(self, step, level_number): |
| 23 | + |
| 24 | + super(log_data_adaptivity, self).post_step(step, level_number) |
| 25 | + |
| 26 | + # some abbreviations |
| 27 | + L = step.levels[level_number] |
| 28 | + |
| 29 | + L.sweep.compute_end_point() |
| 30 | + |
| 31 | + self.add_to_stats( |
| 32 | + process=step.status.slot, |
| 33 | + time=L.time + L.dt, |
| 34 | + level=L.level_index, |
| 35 | + iter=0, |
| 36 | + sweep=L.status.sweep, |
| 37 | + type='current L', |
| 38 | + value=L.uend[0], |
| 39 | + ) |
| 40 | + self.add_to_stats( |
| 41 | + process=step.status.slot, |
| 42 | + time=L.time + L.dt, |
| 43 | + level=L.level_index, |
| 44 | + iter=0, |
| 45 | + sweep=L.status.sweep, |
| 46 | + type='voltage C', |
| 47 | + value=L.uend[1], |
| 48 | + ) |
| 49 | + self.add_to_stats( |
| 50 | + process=step.status.slot, |
| 51 | + time=L.time, |
| 52 | + level=L.level_index, |
| 53 | + iter=0, |
| 54 | + sweep=L.status.sweep, |
| 55 | + type='restart', |
| 56 | + value=int(step.status.get('restart')), |
| 57 | + ) |
| 58 | + self.add_to_stats( |
| 59 | + process=step.status.slot, |
| 60 | + time=L.time + L.dt, |
| 61 | + level=L.level_index, |
| 62 | + iter=0, |
| 63 | + sweep=L.status.sweep, |
| 64 | + type='dt', |
| 65 | + value=L.dt, |
| 66 | + ) |
| 67 | + self.add_to_stats( |
| 68 | + process=step.status.slot, |
| 69 | + time=L.time + L.dt, |
| 70 | + level=L.level_index, |
| 71 | + iter=0, |
| 72 | + sweep=L.status.sweep, |
| 73 | + type='e_embedded', |
| 74 | + value=L.status.error_embedded_estimate, |
| 75 | + ) |
| 76 | + |
| 77 | + |
20 | 78 | def run(dt, problem, sweeper, use_switch_estimator, use_adaptivity, V_ref): |
21 | 79 | """ |
22 | 80 | A simple test program to do SDC/PFASST runs for the battery drain model |
@@ -63,7 +121,10 @@ def run(dt, problem, sweeper, use_switch_estimator, use_adaptivity, V_ref): |
63 | 121 | # initialize controller parameters |
64 | 122 | controller_params = dict() |
65 | 123 | controller_params['logger_level'] = 15 |
66 | | - controller_params['hook_class'] = log_data |
| 124 | + if use_adaptivity: |
| 125 | + controller_params['hook_class'] = log_data_adaptivity |
| 126 | + else: |
| 127 | + controller_params['hook_class'] = log_data |
67 | 128 | controller_params['mssdc_jac'] = False |
68 | 129 |
|
69 | 130 | # convergence controllers |
@@ -158,7 +219,8 @@ def check(cwd='./'): |
158 | 219 | V_ref=V_ref, |
159 | 220 | ) |
160 | 221 |
|
161 | | - assert len(get_recomputed(stats, type='switch', sortby='time')) >= 1, 'No switches found!' |
| 222 | + if use_SE: |
| 223 | + assert len(get_recomputed(stats, type='switch', sortby='time')) >= 1, 'No switches found for dt={}!'.format(dt_item) |
162 | 224 |
|
163 | 225 | fname = 'data/battery_dt{}_USE{}_USA{}_{}.dat'.format(dt_item, use_SE, use_A, sweeper.__name__) |
164 | 226 | f = open(fname, 'wb') |
|
0 commit comments