@@ -202,15 +202,23 @@ def compare_imex_full(plotting=False):
202202 plotting (bool): Plot the solution or not
203203 """
204204 from pySDC .implementations .convergence_controller_classes .adaptivity import Adaptivity
205+ from pySDC .implementations .hooks .log_work import LogWork
206+
207+ maxiter = 5
208+ num_nodes = 3
209+ newton_iter_max = 20
205210
206211 res = {}
207212
208213 custom_description = {}
209214 custom_description ['problem_params' ] = {
210215 'newton_tol' : 1e-10 ,
211- 'newton_iter' : 20 ,
216+ 'newton_iter' : newton_iter_max ,
212217 'nvars' : 2 ** 9 ,
213218 }
219+ custom_description ['step_params' ] = {'maxiter' : maxiter }
220+ custom_description ['sweeper_params' ] = {'num_nodes' : num_nodes }
221+
214222 custom_controller_params = {'logger_level' : 30 }
215223 for imex in [False , True ]:
216224 custom_description ['convergence_controllers' ] = {Adaptivity : {'e_tol' : 1e-6 , 'dt_max' : 1e2 }}
@@ -219,9 +227,16 @@ def compare_imex_full(plotting=False):
219227 custom_controller_params = custom_controller_params ,
220228 imex = imex ,
221229 Tend = 5e2 ,
230+ hook_class = LogWork ,
222231 )
223232
224233 res [imex ] = get_sorted (stats , type = 'u' )[- 1 ][1 ]
234+ newton_iter = [me [1 ] for me in get_sorted (stats , type = 'work_newton' )]
235+
236+ if imex :
237+ assert all ([me == 0 for me in newton_iter ]), f"IMEX is not supposed to do Newton iterations!"
238+ else :
239+ assert max (newton_iter )/ num_nodes / maxiter <= newton_iter_max , "Took more Newton iterations than allowed!"
225240 if plotting : # pragma no cover
226241 plot_solution (stats , controller )
227242
@@ -236,100 +251,6 @@ def compare_imex_full(plotting=False):
236251 ), f"Expected runaway to happen, but maximum temperature is { max (res [True ]):.2e} < u_max={ prob .params .u_max :.2e} !"
237252
238253
239- def compare_dirk ():
240- from pySDC .implementations .convergence_controller_classes .adaptivity import Adaptivity , AdaptivityRK
241- from pySDC .implementations .sweeper_classes .Runge_Kutta import DIRK34
242- from pySDC .projects .Resilience .hook import hook_collection , LogNewtonIter , LogData , LogSpaceIter
243- from pySDC .helpers .plot_helper import figsize_by_journal , setup_mpl
244- from pySDC .implementations .hooks .log_work import LogWork
245-
246- setup_mpl (reset = True )
247- fig , axs = plt .subplots (2 , 2 , figsize = figsize_by_journal ('Springer_Numerical_Algorithms' , 1 , 0.82 ), sharex = True )
248-
249- problem_params = {}
250- problem_params ['direct_solver' ] = False
251-
252- description = {}
253- description ['step_params' ] = {'maxiter' : 4 }
254- description ['convergence_controllers' ] = {Adaptivity : {'e_tol' : 1e-5 , 'dt_max' : 50.0 }}
255-
256- description_RK = {}
257- description_RK ['convergence_controllers' ] = {AdaptivityRK : {'e_tol' : 1e-5 , 'dt_max' : 5e1 , 'update_order' : 4 }}
258- description_RK ['sweeper_class' ] = DIRK34
259- description_RK ['step_params' ] = {'maxiter' : 1 }
260-
261- description_res = {}
262- description_res ['step_params' ] = {'maxiter' : 99 }
263- description_res ['level_params' ] = {'restol' : 1e-10 }
264-
265- controller_params = {}
266- controller_params ['hook_class' ] = hook_collection + [LogNewtonIter , LogData , LogSpaceIter , LogWork ]
267- controller_params ['logger_level' ] = 30
268- Tend = 500
269-
270- stats_fixed , _ , _ = run_leaky_superconductor (
271- custom_description = description_res ,
272- imex = False ,
273- Tend = Tend ,
274- custom_controller_params = controller_params ,
275- custom_problem_params = problem_params ,
276- )
277- stats , _ , _ = run_leaky_superconductor (
278- custom_description = description ,
279- imex = False ,
280- Tend = Tend ,
281- custom_controller_params = controller_params ,
282- custom_problem_params = problem_params ,
283- )
284- stats_RK , _ , _ = run_leaky_superconductor (
285- custom_description = description_RK ,
286- imex = False ,
287- Tend = Tend ,
288- custom_controller_params = controller_params ,
289- custom_problem_params = problem_params ,
290- )
291-
292- labels = {
293- 0 : 'SDC+adaptivity' ,
294- 1 : 'DIRK4(3)' ,
295- 2 : 'SDC' ,
296- }
297- ls = {
298- 0 : '-' ,
299- 1 : '--' ,
300- 2 : ':' ,
301- }
302- S = [stats , stats_RK , stats_fixed ]
303- for i in range (len (S )):
304- newton_iter = get_sorted (S [i ], type = 'work_newton' )
305- axs [0 , 0 ].plot (
306- [me [0 ] for me in newton_iter ], np .cumsum ([me [1 ] for me in newton_iter ]), label = labels [i ], ls = ls [i ]
307- )
308-
309- space_iter = get_sorted (S [i ], type = 'work_linear' )
310- axs [1 , 1 ].plot ([me [0 ] for me in space_iter ], np .cumsum ([me [1 ] for me in space_iter ]), ls = ls [i ])
311-
312- dt = get_sorted (S [i ], type = 'dt' )
313- axs [0 , 1 ].plot ([me [0 ] for me in dt ], [me [1 ] for me in dt ], ls = ls [i ])
314-
315- # u = get_sorted(S[i], type='u', recomputed=False)
316- # axs[1,1].plot([me[0] for me in u], [max(me[1]) for me in u], ls=ls[i])
317-
318- k = get_sorted (S [i ], type = 'sweeps' , recomputed = None )
319- axs [1 , 0 ].plot ([me [0 ] for me in k ], np .cumsum ([me [1 ] for me in k ]), ls = ls [i ])
320- axs [0 , 0 ].set_yscale ('log' )
321- axs [1 , 1 ].set_yscale ('log' )
322- axs [0 , 0 ].legend (frameon = False )
323- axs [0 , 0 ].set_ylabel ('cumulative Newton iterations' )
324- axs [1 , 0 ].set_ylabel ('cumulative SDC iterations' )
325- axs [1 , 0 ].set_xlabel ('$t$' )
326- axs [0 , 1 ].set_ylabel (r'$\Delta t$' )
327- axs [1 , 1 ].set_ylabel ('cumulative GMRES iterations' )
328- fig .tight_layout ()
329- fig .savefig ('data/quench_newton.pdf' )
330-
331-
332254if __name__ == '__main__' :
333- compare_dirk ()
334- # compare_imex_full(plotting=True)
255+ compare_imex_full (plotting = True )
335256 plt .show ()
0 commit comments