Coverage for pySDC/projects/PinTSimE/discontinuous_test_ODE.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2024-11-16 14:51 +0000

1import numpy as np 

2from pathlib import Path 

3 

4from pySDC.helpers.stats_helper import get_sorted 

5from pySDC.implementations.problem_classes.DiscontinuousTestODE import DiscontinuousTestODE 

6from pySDC.implementations.sweeper_classes.generic_implicit import generic_implicit 

7from pySDC.projects.PinTSimE.battery_model import runSimulation 

8 

9import pySDC.helpers.plot_helper as plt_helper 

10 

11from pySDC.core.hooks import Hooks 

12from pySDC.implementations.hooks.log_errors import LogGlobalErrorPostStep 

13from pySDC.implementations.hooks.log_solution import LogSolution 

14 

15 

16class LogEventDiscontinuousTestODE(Hooks): 

17 """ 

18 Logs the problem dependent state function of the discontinuous test ODE. 

19 """ 

20 

21 def post_step(self, step, level_number): 

22 super().post_step(step, level_number) 

23 

24 L = step.levels[level_number] 

25 

26 L.sweep.compute_end_point() 

27 

28 self.add_to_stats( 

29 process=step.status.slot, 

30 time=L.time + L.dt, 

31 level=L.level_index, 

32 iter=0, 

33 sweep=L.status.sweep, 

34 type='state_function', 

35 value=L.uend[0] - 5, 

36 ) 

37 

38 

39def main(): 

40 r""" 

41 Executes the simulation. 

42 

43 Note 

44 ---- 

45 Hardcoded solutions for battery models in `pySDC.projects.PinTSimE.hardcoded_solutions` are only computed for 

46 ``dt_list=[1e-2, 1e-3]`` and ``M_fix=4``. Hence changing ``dt_list`` and ``M_fix`` to different values could arise 

47 an ``AssertionError``. 

48 """ 

49 

50 # --- defines parameters for the problem class ---- 

51 problem_params = { 

52 'newton_maxiter': 50, 

53 'newton_tol': 1e-11, 

54 } 

55 

56 # --- defines parameters for sweeper ---- 

57 M_fix = 3 

58 sweeper_params = { 

59 'num_nodes': M_fix, 

60 'quad_type': 'LOBATTO', 

61 'QI': 'IE', 

62 } 

63 

64 # --- defines parameters for event detection ---- 

65 handling_params = { 

66 'restol': 1e-13, 

67 'maxiter': 8, 

68 'max_restarts': 50, 

69 'recomputed': False, 

70 'tol_event': 1e-12, 

71 'alpha': 0.96, 

72 'exact_event_time_avail': True, 

73 'typeFD': 'backward', 

74 } 

75 

76 # ---- all parameters are stored in this dictionary ---- 

77 all_params = { 

78 'problem_params': problem_params, 

79 'sweeper_params': sweeper_params, 

80 'handling_params': handling_params, 

81 } 

82 

83 hook_class = [LogEventDiscontinuousTestODE, LogSolution, LogGlobalErrorPostStep] 

84 

85 use_detection = [True, False] 

86 use_adaptivity = [False] 

87 

88 _ = runSimulation( 

89 problem=DiscontinuousTestODE, 

90 sweeper=generic_implicit, 

91 all_params=all_params, 

92 use_adaptivity=use_adaptivity, 

93 use_detection=use_detection, 

94 hook_class=hook_class, 

95 interval=(1.0, 2.0), 

96 dt_list=[1e-2, 1e-3], 

97 nnodes=[M_fix], 

98 ) 

99 

100 

101if __name__ == "__main__": 

102 main()