Coverage for pySDC/projects/RDC/vanderpol_MLSDC_PFASST_test.py: 100%
63 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
1import numpy as np
3from pySDC.helpers.stats_helper import get_sorted
4from pySDC.implementations.controller_classes.controller_nonMPI import controller_nonMPI
5from pySDC.implementations.problem_classes.Van_der_Pol_implicit import vanderpol
6from pySDC.implementations.sweeper_classes.generic_implicit import generic_implicit
7from pySDC.implementations.transfer_classes.TransferMesh_NoCoarse import mesh_to_mesh
8from pySDC.projects.RDC.equidistant_RDC import Equidistant_RDC
11def run_RDC(cwd=''):
12 """
13 Van der Pol's oscillator with RDC, MLRDC and PFASST
15 Args:
16 cwd (string): current working directory
18 Returns:
19 list: list of errors and mean number of iterations (for testing)
20 """
22 # set time parameters
23 t0 = 0.0
24 Tend = 10.0
26 # initialize level parameters
27 level_params = dict()
28 level_params['restol'] = 1e-10
29 level_params['dt'] = 0.25
31 # initialize sweeper parameters
32 sweeper_params = dict()
33 sweeper_params['collocation_class'] = Equidistant_RDC
34 sweeper_params['num_nodes'] = 20
35 sweeper_params['QI'] = 'IE'
37 # initialize problem parameters
38 problem_params = dict()
39 problem_params['newton_tol'] = 1e-12
40 problem_params['newton_maxiter'] = 50
41 problem_params['mu'] = 10
42 problem_params['u0'] = (2.0, 0)
44 # initialize step parameters
45 step_params = dict()
46 step_params['maxiter'] = 50
48 # initialize controller parameters
49 controller_params = dict()
50 controller_params['logger_level'] = 50
52 base_transfer_params = dict()
53 # base_transfer_params['finter'] = True
54 # base_transfer_params['coll_iorder'] = 2
55 # base_transfer_params['coll_rorder'] = 2
57 # Fill description dictionary for easy hierarchy creation
58 description = dict()
59 description['problem_class'] = vanderpol
60 description['problem_params'] = problem_params
61 description['sweeper_class'] = generic_implicit
62 description['sweeper_params'] = sweeper_params
63 description['level_params'] = level_params
64 description['step_params'] = step_params
65 description['space_transfer_class'] = mesh_to_mesh
66 description['base_transfer_params'] = base_transfer_params
68 results = []
69 ref_sol = np.load(cwd + 'data/vdp_ref.npy')
71 # instantiate the controller
72 controller_rdc = controller_nonMPI(num_procs=1, controller_params=controller_params, description=description)
74 # get initial values on finest level
75 P = controller_rdc.MS[0].levels[0].prob
76 uinit = P.u_exact(t0)
78 # call main function to get things done...
79 uend_rdc, stats_rdc = controller_rdc.run(u0=uinit, t0=t0, Tend=Tend)
81 # filter statistics by type (number of iterations)
82 iter_counts = get_sorted(stats_rdc, type='niter', sortby='time')
83 mean_niter = np.mean(np.array([item[1] for item in iter_counts]))
85 err = np.linalg.norm(uend_rdc - ref_sol, np.inf) / np.linalg.norm(ref_sol, np.inf)
86 print('RDC : Mean number of iterations: %6.3f -- Error: %8.4e' % (mean_niter, err))
87 results.append((err, mean_niter))
89 sweeper_params['num_nodes'] = [sweeper_params['num_nodes'], 10]
90 controller_mlrdc = controller_nonMPI(num_procs=1, controller_params=controller_params, description=description)
92 uend_mlrdc, stats_mlrdc = controller_mlrdc.run(u0=uinit, t0=t0, Tend=Tend)
94 # filter statistics by type (number of iterations)
95 iter_counts = get_sorted(stats_mlrdc, type='niter', sortby='time')
96 mean_niter = np.mean(np.array([item[1] for item in iter_counts]))
98 err = np.linalg.norm(uend_mlrdc - ref_sol, np.inf) / np.linalg.norm(ref_sol, np.inf)
99 print('MLRDC : Mean number of iterations: %6.3f -- Error: %8.4e' % (mean_niter, err))
100 results.append((err, mean_niter))
102 controller_pfasst = controller_nonMPI(num_procs=10, controller_params=controller_params, description=description)
104 uend_pfasst, stats_pfasst = controller_pfasst.run(u0=uinit, t0=t0, Tend=Tend)
106 # filter statistics by type (number of iterations)
107 iter_counts = get_sorted(stats_pfasst, type='niter', sortby='time')
108 mean_niter = np.mean(np.array([item[1] for item in iter_counts]))
110 err = np.linalg.norm(uend_pfasst - ref_sol, np.inf) / np.linalg.norm(ref_sol, np.inf)
111 print('PFASST(10): Mean number of iterations: %6.3f -- Error: %8.4e' % (mean_niter, err))
112 results.append((err, mean_niter))
114 return results
117if __name__ == "__main__":
118 results = run_RDC()