Coverage for pySDC/tutorial/step_4/B_multilevel_hierarchy.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
3from pySDC.core.step import Step
5from pySDC.implementations.problem_classes.HeatEquation_ND_FD import heatNd_unforced
6from pySDC.implementations.sweeper_classes.generic_implicit import generic_implicit
7from pySDC.implementations.transfer_classes.TransferMesh import mesh_to_mesh
10def main():
11 """
12 A simple test program to set up a full step hierarchy
13 """
15 # initialize level parameters
16 level_params = dict()
17 level_params['restol'] = 1e-10
18 level_params['dt'] = 0.1
20 # initialize sweeper parameters
21 sweeper_params = dict()
22 sweeper_params['quad_type'] = 'RADAU-RIGHT'
23 sweeper_params['num_nodes'] = [5, 3]
24 sweeper_params['QI'] = 'LU'
26 # initialize problem parameters
27 problem_params = dict()
28 problem_params['nu'] = 0.1 # diffusion coefficient
29 problem_params['freq'] = 4 # frequency for the test value
30 problem_params['nvars'] = [31, 15, 7] # number of degrees of freedom for each level
31 problem_params['bc'] = 'dirichlet-zero' # boundary conditions
33 # initialize step parameters
34 step_params = dict()
35 step_params['maxiter'] = 20
37 # initialize space transfer parameters
38 space_transfer_params = dict()
39 space_transfer_params['rorder'] = 2
40 space_transfer_params['iorder'] = 2
42 # fill description dictionary for easy step instantiation
43 description = dict()
44 description['problem_class'] = heatNd_unforced
45 description['problem_params'] = problem_params
46 description['sweeper_class'] = generic_implicit
47 description['sweeper_params'] = sweeper_params
48 description['level_params'] = level_params
49 description['step_params'] = step_params
50 description['space_transfer_class'] = mesh_to_mesh
51 description['space_transfer_params'] = space_transfer_params
53 # now the description contains more or less everything we need to create a step with multiple levels
54 S = Step(description=description)
56 # print out and check
57 Path("data").mkdir(parents=True, exist_ok=True)
58 f = open('data/step_4_B_out.txt', 'w')
59 for l in range(len(S.levels)):
60 L = S.levels[l]
61 out = 'Level %2i: nvars = %4i -- nnodes = %2i' % (l, L.prob.nvars[0], L.sweep.coll.num_nodes)
62 f.write(out + '\n')
63 print(out)
64 assert L.prob.nvars[0] == problem_params['nvars'][min(l, len(problem_params['nvars']) - 1)], (
65 "ERROR: number of DOFs is not correct on this level, got %s" % L.prob.nvars
66 )
67 assert L.sweep.coll.num_nodes == sweeper_params['num_nodes'][min(l, len(sweeper_params['num_nodes']) - 1)], (
68 "ERROR: number of nodes is not correct on this level, got %s" % L.sweep.coll.num_nodes
69 )
70 f.close()
73if __name__ == "__main__":
74 main()