Coverage for pySDC/projects/AllenCahn_Bayreuth/run_temp_forcing_realistic.py: 0%
74 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 numpy as np
3from mpi4py import MPI
5from pySDC.helpers.stats_helper import get_sorted
7from pySDC.implementations.controller_classes.controller_nonMPI import controller_nonMPI
8from pySDC.implementations.sweeper_classes.imex_1st_order import imex_1st_order
9from pySDC.implementations.problem_classes.AllenCahn_Temp_MPIFFT import allencahn_temp_imex
11from pySDC.projects.AllenCahn_Bayreuth.AllenCahn_dump import dump
14def run_simulation(name='', spectral=None, nprocs_space=None):
15 """
16 A test program to create reference data for the AC equation with temporal forcing
17 Args:
18 name (str): name of the run, will be used to distinguish different setups
19 spectral (bool): run in real or spectral space
20 nprocs_space (int): number of processors in space (None if serial)
21 """
23 # set MPI communicator
24 comm = MPI.COMM_WORLD
26 world_rank = comm.Get_rank()
27 world_size = comm.Get_size()
29 # split world communicator to create space-communicators
30 if nprocs_space is not None:
31 color = int(world_rank / nprocs_space)
32 else:
33 color = int(world_rank / 1)
34 space_comm = comm.Split(color=color)
35 space_rank = space_comm.Get_rank()
36 space_size = space_comm.Get_size()
38 assert world_size == space_size, 'This script cannot run parallel-in-time with MPI, only spatial parallelism'
40 # initialize level parameters
41 level_params = dict()
42 level_params['restol'] = 1e-12
43 level_params['dt'] = 1e-03
44 level_params['nsweeps'] = [1]
46 # initialize sweeper parameters
47 sweeper_params = dict()
48 sweeper_params['quad_type'] = 'RADAU-RIGHT'
49 sweeper_params['num_nodes'] = [7]
50 sweeper_params['QI'] = ['LU'] # For the IMEX sweeper, the LU-trick can be activated for the implicit part
51 sweeper_params['initial_guess'] = 'spread'
53 # initialize problem parameters
54 problem_params = dict()
55 problem_params['L'] = 1.0
56 problem_params['nvars'] = [(128, 128)]
57 problem_params['eps'] = [0.03]
58 problem_params['radius'] = 0.35682
59 problem_params['TM'] = 1.0
60 problem_params['D'] = 10.0
61 problem_params['dw'] = [1.0]
62 problem_params['comm'] = space_comm
63 problem_params['init_type'] = 'circle'
64 problem_params['spectral'] = spectral
66 # initialize step parameters
67 step_params = dict()
68 step_params['maxiter'] = 50
70 # initialize controller parameters
71 controller_params = dict()
72 controller_params['logger_level'] = 20 if space_rank == 0 else 99 # set level depending on rank
73 controller_params['hook_class'] = dump
75 # fill description dictionary for easy step instantiation
76 description = dict()
77 description['problem_params'] = problem_params # pass problem parameters
78 description['sweeper_class'] = imex_1st_order
79 description['sweeper_params'] = sweeper_params # pass sweeper parameters
80 description['level_params'] = level_params # pass level parameters
81 description['step_params'] = step_params # pass step parameters
82 description['problem_class'] = allencahn_temp_imex
84 # set time parameters
85 t0 = 0.0
86 Tend = 100 * 0.001
88 if space_rank == 0:
89 out = f'---------> Running {name} with spectral={spectral} and {space_size} process(es) in space...'
90 print(out)
92 # instantiate controller
93 controller = controller_nonMPI(num_procs=1, controller_params=controller_params, description=description)
95 # get initial values on finest level
96 P = controller.MS[0].levels[0].prob
97 uinit = P.u_exact(t0)
99 # call main function to get things done...
100 uend, stats = controller.run(u0=uinit, t0=t0, Tend=Tend)
102 if space_rank == 0:
103 print()
105 # convert filtered statistics of iterations count, sorted by time
106 iter_counts = get_sorted(stats, type='niter', sortby='time')
107 niters = np.mean(np.array([item[1] for item in iter_counts]))
108 out = f'Mean number of iterations: {niters:.4f}'
109 print(out)
111 # get setup time
112 timing = get_sorted(stats, type='timing_setup', sortby='time')
113 out = f'Setup time: {timing[0][1]:.4f} sec.'
114 print(out)
116 # get running time
117 timing = get_sorted(stats, type='timing_run', sortby='time')
118 out = f'Time to solution: {timing[0][1]:.4f} sec.'
119 print(out)
121 out = '...Done <---------\n'
122 print(out)
124 space_comm.Free()
127def main(nprocs_space=None):
128 """
129 Little helper routine to run the whole thing
130 Args:
131 nprocs_space (int): number of processors in space (None if serial)
132 """
133 name = 'AC-realistic-tempforce'
134 run_simulation(name=name, spectral=False, nprocs_space=nprocs_space)
135 # run_simulation(name=name, spectral=True, nprocs_space=nprocs_space)
138if __name__ == "__main__":
139 # Add parser to get number of processors in space (have to do this here to enable automatic testing)
140 parser = ArgumentParser()
141 parser.add_argument("-n", "--nprocs_space", help='Specifies the number of processors in space', type=int)
142 args = parser.parse_args()
144 main(nprocs_space=args.nprocs_space)