Coverage for pySDC/projects/AllenCahn_Bayreuth/run_simple_forcing_benchmark.py: 0%
80 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
1from argparse import ArgumentParser
2import warnings
3import numpy as np
4from mpi4py import MPI
6warnings.filterwarnings("ignore")
7from pySDC.helpers.stats_helper import get_sorted
9from pySDC.implementations.controller_classes.controller_MPI import controller_MPI
10from pySDC.implementations.sweeper_classes.imex_1st_order import imex_1st_order
11from pySDC.implementations.problem_classes.AllenCahn_MPIFFT import allencahn_imex, allencahn_imex_timeforcing
12from pySDC.implementations.transfer_classes.TransferMesh_MPIFFT import fft_to_fft
15def run_simulation(name=None, nprocs_space=None):
16 """
17 A simple test program to do PFASST runs for the AC equation
18 """
20 # set MPI communicator
21 comm = MPI.COMM_WORLD
23 world_rank = comm.Get_rank()
24 world_size = comm.Get_size()
26 # split world communicator to create space-communicators
27 if nprocs_space is not None:
28 color = int(world_rank / nprocs_space)
29 else:
30 color = int(world_rank / 1)
31 space_comm = comm.Split(color=color)
32 space_size = space_comm.Get_size()
33 space_rank = space_comm.Get_rank()
35 # split world communicator to create time-communicators
36 if nprocs_space is not None:
37 color = int(world_rank % nprocs_space)
38 else:
39 color = int(world_rank / world_size)
40 time_comm = comm.Split(color=color)
41 time_size = time_comm.Get_size()
42 time_rank = time_comm.Get_rank()
44 # print(time_size, space_size, world_size)
46 # initialize level parameters
47 level_params = dict()
48 level_params['restol'] = 1e-08
49 level_params['dt'] = 1e-03
50 level_params['nsweeps'] = [3, 1]
52 # initialize sweeper parameters
53 sweeper_params = dict()
54 sweeper_params['quad_type'] = 'RADAU-RIGHT'
55 sweeper_params['num_nodes'] = [3]
56 sweeper_params['QI'] = ['LU'] # For the IMEX sweeper, the LU-trick can be activated for the implicit part
57 sweeper_params['initial_guess'] = 'zero'
59 # initialize problem parameters
60 problem_params = dict()
61 problem_params['L'] = 4.0
62 # problem_params['L'] = 16.0
63 problem_params['nvars'] = [(48 * 12, 48 * 12), (8 * 12, 8 * 12)]
64 # problem_params['nvars'] = [(48 * 48, 48 * 48), (8 * 48, 8 * 48)]
65 problem_params['eps'] = [0.04]
66 problem_params['radius'] = 0.25
67 problem_params['comm'] = space_comm
68 problem_params['init_type'] = 'circle_rand'
69 problem_params['spectral'] = False
71 if name == 'AC-bench-constforce':
72 problem_params['dw'] = [-23.59]
74 # initialize step parameters
75 step_params = dict()
76 step_params['maxiter'] = 50
78 # initialize controller parameters
79 controller_params = dict()
80 controller_params['logger_level'] = 20 if space_rank == 0 else 99 # set level depending on rank
81 controller_params['predict_type'] = 'fine_only'
83 # fill description dictionary for easy step instantiation
84 description = dict()
85 description['problem_params'] = problem_params # pass problem parameters
86 description['sweeper_class'] = imex_1st_order
87 description['sweeper_params'] = sweeper_params # pass sweeper parameters
88 description['level_params'] = level_params # pass level parameters
89 description['step_params'] = step_params # pass step parameters
90 description['space_transfer_class'] = fft_to_fft
92 if name == 'AC-bench-noforce' or name == 'AC-bench-constforce':
93 description['problem_class'] = allencahn_imex
94 elif name == 'AC-bench-timeforce':
95 description['problem_class'] = allencahn_imex_timeforcing
96 else:
97 raise NotImplementedError(f'{name} is not implemented')
99 # set time parameters
100 t0 = 0.0
101 Tend = 12 * 0.001
103 if space_rank == 0 and time_rank == 0:
104 out = f'---------> Running {name} with {time_size} process(es) in time and {space_size} process(es) in space...'
105 print(out)
107 # instantiate controller
108 controller = controller_MPI(controller_params=controller_params, description=description, comm=time_comm)
110 # get initial values on finest level
111 P = controller.S.levels[0].prob
112 uinit = P.u_exact(t0)
114 # call main function to get things done...
115 uend, stats = controller.run(u0=uinit, t0=t0, Tend=Tend)
117 if space_rank == 0:
118 print()
120 # convert filtered statistics to list of iterations count, sorted by time
121 iter_counts = get_sorted(stats, type='niter', sortby='time')
123 niters = np.array([item[1] for item in iter_counts])
124 out = f'Mean number of iterations on rank {time_rank}: {np.mean(niters):.4f}'
125 print(out)
127 timing = get_sorted(stats, type='timing_setup', sortby='time')
128 out = f'Setup time on rank {time_rank}: {timing[0][1]:.4f} sec.'
129 print(out)
131 timing = get_sorted(stats, type='timing_run', sortby='time')
132 out = f'Time to solution on rank {time_rank}: {timing[0][1]:.4f} sec.'
133 print(out)
135 space_comm.Free()
136 time_comm.Free()
139if __name__ == "__main__":
140 # Add parser to get number of processors in space and setup (have to do this here to enable automatic testing)
141 parser = ArgumentParser()
142 parser.add_argument(
143 "-s",
144 "--setup",
145 help='Specifies the setup',
146 type=str,
147 default='AC-bench-noforce',
148 choices=['AC-bench-noforce', 'AC-bench-constforce', 'AC-bench-timeforce'],
149 )
150 parser.add_argument("-n", "--nprocs_space", help='Specifies the number of processors in space', type=int)
151 args = parser.parse_args()
153 run_simulation(name=args.setup, nprocs_space=args.nprocs_space)