|
| 1 | +import numpy as np |
| 2 | + |
| 3 | +import projects.node_failure.emulate_hard_faults as ft |
| 4 | +from projects.node_failure.allinclusive_classic_nonMPI_hard_faults import allinclusive_classic_nonMPI_hard_faults |
| 5 | +from pySDC.helpers.stats_helper import filter_stats, sort_stats |
| 6 | +from pySDC.implementations.collocation_classes.gauss_radau_right import CollGaussRadau_Right |
| 7 | +from pySDC.implementations.sweeper_classes.generic_LU import generic_LU |
| 8 | +from pySDC.implementations.datatype_classes.fenics_mesh import fenics_mesh |
| 9 | +from pySDC.implementations.transfer_classes.TransferFenicsMesh import mesh_to_mesh_fenics |
| 10 | +from pySDC.implementations.problem_classes.GrayScott_1D_FEniCS_implicit import fenics_grayscott |
| 11 | + |
| 12 | + |
| 13 | +# noinspection PyShadowingNames,PyShadowingBuiltins |
| 14 | +def main(ft_strategies): |
| 15 | + """ |
| 16 | + This routine generates the heatmaps showing the residual for node failures at different steps and iterations |
| 17 | + """ |
| 18 | + |
| 19 | + num_procs = 32 |
| 20 | + |
| 21 | + # setup parameters "in time" |
| 22 | + t0 = 0 |
| 23 | + dt = 2.0 |
| 24 | + Tend = 1280.0 |
| 25 | + Nsteps = int((Tend-t0)/dt) |
| 26 | + |
| 27 | + # initialize level parameters |
| 28 | + level_params = dict() |
| 29 | + level_params['restol'] = 1E-07 |
| 30 | + level_params['dt'] = dt |
| 31 | + |
| 32 | + # initialize step parameters |
| 33 | + step_params = dict() |
| 34 | + step_params['maxiter'] = 50 |
| 35 | + |
| 36 | + # initialize space transfer parameters |
| 37 | + space_transfer_params = dict() |
| 38 | + space_transfer_params['finter'] = True |
| 39 | + |
| 40 | + # initialize sweeper parameters |
| 41 | + sweeper_params = dict() |
| 42 | + sweeper_params['collocation_class'] = CollGaussRadau_Right |
| 43 | + sweeper_params['num_nodes'] = [3] |
| 44 | + sweeper_params['QI'] = 'LU' |
| 45 | + |
| 46 | + # initialize controller parameters |
| 47 | + controller_params = dict() |
| 48 | + controller_params['logger_level'] = 20 |
| 49 | + |
| 50 | + # initialize problem parameters |
| 51 | + problem_params = dict() |
| 52 | + # problem_params['Du'] = 1.0 |
| 53 | + # problem_params['Dv'] = 0.01 |
| 54 | + # problem_params['A'] = 0.01 |
| 55 | + # problem_params['B'] = 0.10 |
| 56 | + # splitting pulses until steady state |
| 57 | + # problem_params['Du'] = 1.0 |
| 58 | + # problem_params['Dv'] = 0.01 |
| 59 | + # problem_params['A'] = 0.02 |
| 60 | + # problem_params['B'] = 0.079 |
| 61 | + # splitting pulses until steady state |
| 62 | + problem_params['Du'] = 1.0 |
| 63 | + problem_params['Dv'] = 0.01 |
| 64 | + problem_params['A'] = 0.09 |
| 65 | + problem_params['B'] = 0.086 |
| 66 | + |
| 67 | + problem_params['t0'] = t0 # ugly, but necessary to set up ProblemClass |
| 68 | + problem_params['c_nvars'] = [256] |
| 69 | + problem_params['family'] = 'CG' |
| 70 | + problem_params['order'] = [4] |
| 71 | + problem_params['refinements'] = [1, 0] |
| 72 | + |
| 73 | + # fill description dictionary for easy step instantiation |
| 74 | + description = dict() |
| 75 | + description['problem_class'] = fenics_grayscott # pass problem class |
| 76 | + description['problem_params'] = problem_params # pass problem parameters |
| 77 | + description['dtype_u'] = fenics_mesh # pass data type for u |
| 78 | + description['dtype_f'] = fenics_mesh # pass data type for f |
| 79 | + description['sweeper_class'] = generic_LU # pass sweeper (see part B) |
| 80 | + description['sweeper_params'] = sweeper_params # pass sweeper parameters |
| 81 | + description['level_params'] = level_params # pass level parameters |
| 82 | + description['step_params'] = step_params # pass step parameters |
| 83 | + description['space_transfer_class'] = mesh_to_mesh_fenics # pass spatial transfer class |
| 84 | + description['space_transfer_params'] = space_transfer_params # pass paramters for spatial transfer |
| 85 | + |
| 86 | + ft.hard_random = 0.03 |
| 87 | + |
| 88 | + controller = allinclusive_classic_nonMPI_hard_faults(num_procs=num_procs, |
| 89 | + controller_params=controller_params, |
| 90 | + description=description) |
| 91 | + |
| 92 | + # get initial values on finest level |
| 93 | + P = controller.MS[0].levels[0].prob |
| 94 | + uinit = P.u_exact(t0) |
| 95 | + |
| 96 | + for strategy in ft_strategies: |
| 97 | + |
| 98 | + print('------------------------------------------ working on strategy ', strategy) |
| 99 | + ft.strategy = strategy |
| 100 | + |
| 101 | + # read in reference data from clean run, will provide reproducable locations for faults |
| 102 | + if strategy is not 'NOFAULT': |
| 103 | + reffile = np.load('data/PFASST_GRAYSCOTT_stats_hf_NOFAULT_P16.npz') |
| 104 | + ft.refdata = reffile['hard_stats'] |
| 105 | + |
| 106 | + # call main function to get things done... |
| 107 | + uend, stats = controller.run(u0=uinit, t0=t0, Tend=Tend) |
| 108 | + |
| 109 | + # get residuals of the run |
| 110 | + extract_stats = filter_stats(stats, type='residual_post_iteration') |
| 111 | + |
| 112 | + # find boundaries for x-,y- and c-axis as well as arrays |
| 113 | + maxprocs = 0 |
| 114 | + maxiter = 0 |
| 115 | + minres = 0 |
| 116 | + maxres = -99 |
| 117 | + for k, v in extract_stats.items(): |
| 118 | + maxprocs = max(maxprocs, getattr(k, 'process')) |
| 119 | + maxiter = max(maxiter, getattr(k, 'iter')) |
| 120 | + minres = min(minres, np.log10(v)) |
| 121 | + maxres = max(maxres, np.log10(v)) |
| 122 | + |
| 123 | + # grep residuals and put into array |
| 124 | + residual = np.zeros((maxiter, maxprocs + 1)) |
| 125 | + residual[:] = -99 |
| 126 | + for k, v in extract_stats.items(): |
| 127 | + step = getattr(k, 'process') |
| 128 | + iter = getattr(k, 'iter') |
| 129 | + if iter is not -1: |
| 130 | + residual[iter - 1, step] = np.log10(v) |
| 131 | + |
| 132 | + # stats magic: get niter (probably redundant with maxiter) |
| 133 | + extract_stats = filter_stats(stats, level=-1, type='niter') |
| 134 | + sortedlist_stats = sort_stats(extract_stats, sortby='process') |
| 135 | + iter_count = np.zeros(Nsteps) |
| 136 | + for item in sortedlist_stats: |
| 137 | + iter_count[item[0]] = item[1] |
| 138 | + print(iter_count) |
| 139 | + |
| 140 | + np.savez('data/PFASST_GRAYSCOTT_stats_hf_' + ft.strategy + '_P' + str(num_procs), residual=residual, |
| 141 | + iter_count=iter_count, hard_stats=ft.hard_stats) |
| 142 | + |
| 143 | + |
| 144 | +if __name__ == "__main__": |
| 145 | + # ft_strategies = ['SPREAD', 'SPREAD_PREDICT', 'INTERP', 'INTERP_PREDICT'] |
| 146 | + ft_strategies = ['NOFAULT'] |
| 147 | + |
| 148 | + main(ft_strategies=ft_strategies) |
0 commit comments