Coverage for pySDC/projects/AllenCahn_Bayreuth/run_temp_forcing_benchmark.py: 0%

78 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2024-11-16 14:51 +0000

1from argparse import ArgumentParser 

2import numpy as np 

3from mpi4py import MPI 

4 

5from pySDC.helpers.stats_helper import get_sorted 

6 

7from pySDC.implementations.controller_classes.controller_MPI import controller_MPI 

8from pySDC.implementations.sweeper_classes.imex_1st_order import imex_1st_order 

9from pySDC.implementations.problem_classes.AllenCahn_Temp_MPIFFT import allencahn_temp_imex 

10from pySDC.implementations.transfer_classes.TransferMesh_MPIFFT import fft_to_fft 

11 

12from pySDC.projects.AllenCahn_Bayreuth.AllenCahn_dump import dump 

13 

14 

15def run_simulation(name=None, nprocs_space=None): 

16 """ 

17 A simple test program to do PFASST runs for the AC equation 

18 """ 

19 

20 # set MPI communicator 

21 comm = MPI.COMM_WORLD 

22 

23 world_rank = comm.Get_rank() 

24 world_size = comm.Get_size() 

25 

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() 

34 

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() 

43 

44 # initialize level parameters 

45 level_params = dict() 

46 level_params['restol'] = 1e-08 

47 level_params['dt'] = 1e-03 

48 level_params['nsweeps'] = [3, 1] 

49 

50 # initialize sweeper parameters 

51 sweeper_params = dict() 

52 sweeper_params['quad_type'] = 'RADAU-RIGHT' 

53 sweeper_params['num_nodes'] = [3] 

54 sweeper_params['QI'] = ['LU'] # For the IMEX sweeper, the LU-trick can be activated for the implicit part 

55 sweeper_params['initial_guess'] = 'zero' 

56 

57 # initialize problem parameters 

58 problem_params = dict() 

59 problem_params['L'] = 16.0 

60 problem_params['nvars'] = [(48 * 48, 48 * 48), (8 * 48, 8 * 48)] 

61 problem_params['eps'] = [0.04] 

62 problem_params['radius'] = 0.25 

63 problem_params['TM'] = 1.0 

64 problem_params['D'] = 1.0 

65 problem_params['dw'] = [300.0] 

66 problem_params['comm'] = space_comm 

67 problem_params['init_type'] = 'circle_rand' 

68 problem_params['spectral'] = True 

69 

70 # initialize step parameters 

71 step_params = dict() 

72 step_params['maxiter'] = 50 

73 

74 # initialize controller parameters 

75 controller_params = dict() 

76 controller_params['logger_level'] = 20 if space_rank == 0 else 99 # set level depending on rank 

77 controller_params['hook_class'] = dump 

78 controller_params['predict_type'] = 'fine_only' 

79 

80 # fill description dictionary for easy step instantiation 

81 description = dict() 

82 description['problem_params'] = problem_params # pass problem parameters 

83 description['sweeper_class'] = imex_1st_order 

84 description['sweeper_params'] = sweeper_params # pass sweeper parameters 

85 description['level_params'] = level_params # pass level parameters 

86 description['step_params'] = step_params # pass step parameters 

87 description['space_transfer_class'] = fft_to_fft 

88 description['problem_class'] = allencahn_temp_imex 

89 

90 # set time parameters 

91 t0 = 0.0 

92 Tend = 100 * 0.001 

93 

94 if space_rank == 0 and time_rank == 0: 

95 out = f'---------> Running {name} with {time_size} process(es) in time and {space_size} process(es) in space...' 

96 print(out) 

97 

98 # instantiate controller 

99 controller = controller_MPI(controller_params=controller_params, description=description, comm=time_comm) 

100 

101 # get initial values on finest level 

102 P = controller.S.levels[0].prob 

103 uinit = P.u_exact(t0) 

104 

105 # call main function to get things done... 

106 uend, stats = controller.run(u0=uinit, t0=t0, Tend=Tend) 

107 

108 if space_rank == 0: 

109 print() 

110 

111 # convert filtered statistics to list of iterations count, sorted by time 

112 iter_counts = get_sorted(stats, type='niter', sortby='time') 

113 

114 niters = np.array([item[1] for item in iter_counts]) 

115 out = f'Mean number of iterations on rank {time_rank}: {np.mean(niters):.4f}' 

116 print(out) 

117 

118 timing = get_sorted(stats, type='timing_setup', sortby='time') 

119 out = f'Setup time on rank {time_rank}: {timing[0][1]:.4f} sec.' 

120 print(out) 

121 

122 timing = get_sorted(stats, type='timing_run', sortby='time') 

123 out = f'Time to solution on rank {time_rank}: {timing[0][1]:.4f} sec.' 

124 print(out) 

125 

126 space_comm.Free() 

127 time_comm.Free() 

128 

129 

130if __name__ == "__main__": 

131 # Add parser to get number of processors in space and setup (have to do this here to enable automatic testing) 

132 parser = ArgumentParser() 

133 parser.add_argument("-n", "--nprocs_space", help='Specifies the number of processors in space', type=int) 

134 args = parser.parse_args() 

135 

136 name = 'AC-bench-tempforce' 

137 run_simulation(name=name, nprocs_space=args.nprocs_space)