Coverage for pySDC/projects/Resilience/heat.py: 26%
35 statements
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-16 14:51 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-16 14:51 +0000
1# script to run a simple heat problem
3from pySDC.implementations.problem_classes.HeatEquation_ND_FD import heatNd_unforced
4from pySDC.implementations.sweeper_classes.generic_implicit import generic_implicit
5from pySDC.implementations.controller_classes.controller_nonMPI import controller_nonMPI
6from pySDC.core.hooks import Hooks
7from pySDC.helpers.stats_helper import get_sorted
8from pySDC.projects.Resilience.hook import hook_collection, LogData
9import numpy as np
10from pySDC.projects.Resilience.strategies import merge_descriptions
13def run_heat(
14 custom_description=None,
15 num_procs=1,
16 Tend=2e-1,
17 hook_class=LogData,
18 fault_stuff=None,
19 custom_controller_params=None,
20):
21 """
22 Run a heat problem with default parameters.
24 Args:
25 custom_description (dict): Overwrite presets
26 num_procs (int): Number of steps for MSSDC
27 Tend (float): Time to integrate to
28 hook_class (pySDC.Hook): A hook to store data
29 fault_stuff (dict): A dictionary with information on how to add faults
30 custom_controller_params (dict): Overwrite presets
32 Returns:
33 dict: The stats object
34 controller: The controller
35 Tend: The time that was supposed to be integrated to
36 """
38 # initialize level parameters
39 level_params = dict()
40 level_params['dt'] = 0.05
42 # initialize sweeper parameters
43 sweeper_params = dict()
44 sweeper_params['quad_type'] = 'RADAU-RIGHT'
45 sweeper_params['num_nodes'] = 3
46 sweeper_params['QI'] = 'IE'
48 problem_params = {
49 'freq': 2,
50 'nvars': 2**9,
51 'nu': 1.0,
52 'stencil_type': 'center',
53 'order': 6,
54 'bc': 'periodic',
55 'solver_type': 'direct',
56 'lintol': None,
57 'liniter': None,
58 }
60 # initialize step parameters
61 step_params = dict()
62 step_params['maxiter'] = 5
64 # initialize controller parameters
65 controller_params = dict()
66 controller_params['logger_level'] = 30
67 controller_params['hook_class'] = hook_collection + (hook_class if type(hook_class) == list else [hook_class])
68 controller_params['mssdc_jac'] = False
70 if custom_controller_params is not None:
71 controller_params = {**controller_params, **custom_controller_params}
73 # fill description dictionary for easy step instantiation
74 description = dict()
75 description['problem_class'] = heatNd_unforced # pass problem class
76 description['problem_params'] = problem_params # pass problem parameters
77 description['sweeper_class'] = generic_implicit # pass sweeper
78 description['sweeper_params'] = sweeper_params # pass sweeper parameters
79 description['level_params'] = level_params # pass level parameters
80 description['step_params'] = step_params
82 if custom_description is not None:
83 description = merge_descriptions(description, custom_description)
85 # set time parameters
86 t0 = 0.0
88 # instantiate controller
89 controller = controller_nonMPI(num_procs=num_procs, controller_params=controller_params, description=description)
91 # insert faults
92 if fault_stuff is not None:
93 raise NotImplementedError("The parameters have not been adapted to this equation yet!")
95 # get initial values on finest level
96 P = controller.MS[0].levels[0].prob
97 uinit = P.u_exact(t0)
99 # call main function to get things done...
100 uend, stats = controller.run(u0=uinit, t0=t0, Tend=Tend)
101 return stats, controller, Tend
104if __name__ == '__main__':
105 run_heat()