Coverage for pySDC/tutorial/step_2/C_using_pySDCs_frontend.py: 100%
43 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-20 14:51 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-20 14:51 +0000
1from pathlib import Path
4from pySDC.implementations.controller_classes.controller_nonMPI import controller_nonMPI
5from pySDC.implementations.problem_classes.HeatEquation_ND_FD import heatNd_forced
6from pySDC.implementations.sweeper_classes.imex_1st_order import imex_1st_order
9def main():
10 """
11 A simple test program to run IMEX SDC for a single time step
12 """
13 # initialize level parameters
14 level_params = dict()
15 level_params['restol'] = 1e-10
16 level_params['dt'] = 0.1
18 # initialize sweeper parameters
19 sweeper_params = dict()
20 sweeper_params['quad_type'] = 'RADAU-RIGHT'
21 sweeper_params['num_nodes'] = 3
23 # initialize problem parameters
24 problem_params = dict()
25 problem_params['nu'] = 0.1 # diffusion coefficient
26 problem_params['freq'] = 4 # frequency for the test value
27 problem_params['nvars'] = 1023 # number of degrees of freedom
28 problem_params['bc'] = 'dirichlet-zero' # boundary conditions
30 # initialize step parameters
31 step_params = dict()
32 step_params['maxiter'] = 20
34 # initialize controller parameters
35 controller_params = dict()
36 controller_params['log_to_file'] = True
37 controller_params['fname'] = 'data/step_2_C_out.txt'
39 # Fill description dictionary for easy hierarchy creation
40 description = dict()
41 description['problem_class'] = heatNd_forced
42 description['problem_params'] = problem_params
43 description['sweeper_class'] = imex_1st_order
44 description['sweeper_params'] = sweeper_params
45 description['level_params'] = level_params
46 description['step_params'] = step_params
48 Path("data").mkdir(parents=True, exist_ok=True)
50 # instantiate the controller
51 controller = controller_nonMPI(num_procs=1, controller_params=controller_params, description=description)
53 # set time parameters
54 t0 = 0.1
55 Tend = 0.3 # note that we are requesting 2 time steps here (dt is 0.1)
57 # get initial values on finest level
58 P = controller.MS[0].levels[0].prob
59 uinit = P.u_exact(t0)
61 # call main function to get things done...
62 uend, stats = controller.run(u0=uinit, t0=t0, Tend=Tend)
64 # compute exact solution and compare
65 uex = P.u_exact(Tend)
66 err = abs(uex - uend)
68 f = open('data/step_2_C_out.txt', 'a')
69 out = 'Error after SDC iterations: %8.6e' % err
70 f.write(out)
71 print(out)
72 f.close()
74 assert err <= 2e-5, "ERROR: controller doing IMEX SDC iteration did not reduce the error enough, got %s" % err
77if __name__ == "__main__":
78 main()