44from scipy import integrate
55
66
7- def get_pySDC_data (Ra , RK = False , res = - 1 , dt = - 1 ):
7+ def get_pySDC_data (Ra , RK = False , res = - 1 , dt = - 1 , config_name = 'RBC3DG4' ):
88 assert type (Ra ) == str
99
1010 base_path = 'data/RBC_time_averaged'
1111
12- config_name = 'RBC3DG4RK' if RK else 'RBC3DG4'
12+ if RK :
13+ config_name = f'{ config_name } RK'
1314
1415 path = f'{ base_path } /{ config_name } Ra{ Ra } -res{ res } -dt{ dt :.0e} .pickle'
1516 with open (path , 'rb' ) as file :
@@ -93,12 +94,13 @@ def get_Nek5000_Data(Ra):
9394
9495
9596def plot_Ra_Nusselt_scaling ():
96- fig , axs = plt .subplots (1 , 3 , figsize = (10 , 3 ))
97+ fig , axs = plt .subplots (1 , 4 , figsize = (13 , 3 ))
9798 NuRa_ax = axs [0 ]
9899 prof_ax = axs [1 ]
99100 rms_ax = axs [2 ]
101+ spectrum_ax = axs [3 ]
100102
101- for Ra , Ra_str in zip ([1e5 , 1e6 , 1e7 ], ['1e5' , '1e6' , '1e7' , '1e8' ]):
103+ for Ra , Ra_str in zip ([1e5 , 1e6 , 1e7 , 1e8 ], ['1e5' , '1e6' , '1e7' , '1e8' ]):
102104 data_pySDC = get_pySDC_data (Ra_str )
103105 data_Nek5000 = get_Nek5000_Data (Ra_str )
104106
@@ -112,11 +114,19 @@ def plot_Ra_Nusselt_scaling():
112114 rms_ax .plot (data_Nek5000 ['rms_profile_T' ], data_Nek5000 ['z' ], label = f'Nek5000 Ra={ Ra :.0e} ' )
113115 # rms_ax.axhline(data_Nek5000['z'][np.argmax(data_Nek5000['rms_profile_T'][:int(len(data_Nek5000['z'])/2)])])
114116
115- # rms_ax.scatter(data_pySDC['rms_profile_T']*1.2, data_pySDC['z'], label=f'pySDC Ra={Ra:.0e}')
116- rms_ax .scatter (data_pySDC ['rms_profile_T' ] * 1.0 , data_pySDC ['z' ], label = f'pySDC Ra={ Ra :.0e} ' )
117+ rms_ax .scatter (data_pySDC ['rms_profile_T' ], data_pySDC ['z' ], label = f'pySDC Ra={ Ra :.0e} ' )
117118 # shift = int(len(data_pySDC['z']) / 2)
118119 # rms_ax.axhline(data_pySDC['z'][shift + np.argmax(data_pySDC['rms_profile_T'][shift:])], ls='--', color='red')
119120
121+ k = data_pySDC ['k' ] + 1
122+ spectrum = np .array (data_pySDC ['spectrum' ])
123+ u_spectrum = np .mean (spectrum , axis = 0 )[1 ]
124+ idx = data_pySDC ['res_in_boundary_layer' ]
125+ _s = u_spectrum [idx ]
126+ spectrum_ax .loglog (
127+ k [_s > 1e-16 ], _s [_s > 1e-16 ] # , color=last_line.get_color(), ls=last_line.get_linestyle(), label=label
128+ )
129+
120130 NuRa_ax .errorbar ([], [], color = 'red' , fmt = '.' , label = 'pySDC' )
121131 NuRa_ax .scatter ([], [], color = 'black' , label = 'Nek5000' )
122132 NuRa_ax .legend (frameon = False )
@@ -128,25 +138,29 @@ def plot_Ra_Nusselt_scaling():
128138 prof_ax .set_xlabel ('T' )
129139 prof_ax .set_ylabel ('z' )
130140 prof_ax .set_xlim ((0.47 , 1.03 ))
131- prof_ax .set_ylim ((- 0.03 , 0.53 ))
141+ prof_ax .set_ylim ((- 0.01 , 0.30 ))
132142
133143 rms_ax .set_xlabel (r'$T_\text{rms}$' )
134144 rms_ax .set_ylabel ('z' )
135- rms_ax .set_xlim ((- 0.03 , 0.18 ))
136- rms_ax .set_ylim ((- 0.03 , 0.53 ))
145+ rms_ax .set_xlim ((- 0.01 , 0.177 ))
146+ rms_ax .set_ylim ((- 0.01 , 0.23 ))
137147
138148 NuRa_ax .set_xlabel ('Ra' )
139149 NuRa_ax .set_ylabel ('Nu' )
140150 NuRa_ax .set_yscale ('log' )
141151 NuRa_ax .set_xscale ('log' )
152+
153+ spectrum_ax .set_xlabel ('$k$' )
154+ spectrum_ax .set_ylabel (r'$\|\hat{u}_x\|$' )
155+
142156 for ax in axs :
143157 ax .set_box_aspect (1 )
144158
145159 fig .tight_layout ()
146160 fig .savefig ('./data/RBC_time_averaged/Nek5000_pySDC_comparison.pdf' )
147161
148162
149- def compare_Nusselt_over_time1e7 ():
163+ def compare_Nusselt_over_time1e7_old ():
150164 fig , ax = plt .subplots ()
151165 Ra = '1e7'
152166
@@ -254,9 +268,23 @@ def compare_Nusselt_over_time1e5():
254268 axs [1 ].set_ylabel ('Error in Nu' )
255269
256270
271+ def interpolate_NuV_to_reference_times (data , reference_data , order = 12 ):
272+ from qmat .lagrange import getSparseInterpolationMatrix
273+
274+ t_in = np .array (data ['t' ])
275+ t_out = np .array ([me for me in reference_data ['t' ] if me <= max (t_in )])
276+
277+ interpolation_matrix = getSparseInterpolationMatrix (t_in , t_out , order = order )
278+ return interpolation_matrix @ t_in , interpolation_matrix @ data ['Nu' ]['V' ]
279+
280+
257281def compare_Nusselt_over_time1e6 ():
258- fig , ax = plt .subplots (1 , 1 )
259- _fig , _ax = plt .subplots ()
282+ fig , Nu_ax = plt .subplots ()
283+ _ , axs = plt .subplots (1 , 3 , figsize = (10 , 3 ))
284+ prof_ax = axs [0 ]
285+ rms_ax = axs [1 ]
286+ spectrum_ax = axs [2 ]
287+
260288 Ra = '1e6'
261289 res = 48
262290
@@ -268,7 +296,7 @@ def compare_Nusselt_over_time1e6():
268296
269297 for dt in [0.04 , 0.02 , 0.01 , 0.005 , 0.002 ]:
270298 data .append (get_pySDC_data (Ra , res = res , dt = dt ))
271- labels .append (f'SDC, dt={ dt :.3f } ' )
299+ labels .append (f'SDC, dt={ dt :.4f } ' )
272300 linestyles .append ('-' )
273301
274302 # # ----------------- RK ------------------------
@@ -278,12 +306,89 @@ def compare_Nusselt_over_time1e6():
278306 labels .append (f'RK, dt={ dt :.3f} ' )
279307 linestyles .append ('--' )
280308
309+ data .append (get_pySDC_data (Ra , res = res , dt = 0.02 , config_name = 'RBC3DG4R4' ))
310+ labels .append (f'SDC, R4, dt={ 0.02 :.4f} ' )
311+ linestyles .append (':' )
312+
313+ for dat , label , linestyle in zip (data , labels , linestyles ):
314+ Nu = np .array (dat ['Nu' ]['V' ])
315+ t = dat ['t' ]
316+ Nu_ref = np .array (ref_data ['Nu' ]['V' ])
317+ t_i , Nu_i = interpolate_NuV_to_reference_times (dat , ref_data )
318+ Nu_ax .plot (t , Nu , label = label , ls = linestyle )
319+
320+ error = np .maximum .accumulate (np .abs (Nu_ref [: Nu_i .shape [0 ]] - Nu_i ) / np .abs (Nu_ref [: Nu_i .shape [0 ]]))
321+
322+ # compute mean Nu
323+ mask = np .logical_and (t >= 20 , t <= 200 )
324+ Nu_mean = np .mean (Nu [mask ])
325+ Nu_std = np .std (Nu [mask ])
326+
327+ last_line = Nu_ax .get_lines ()[- 1 ]
328+ if any (error > 1e-2 ):
329+ deviates = min (t_i [error > 1e-2 ])
330+ Nu_ax .axvline (deviates , color = last_line .get_color (), ls = last_line .get_linestyle ())
331+ print (f'{ label } Nu={ Nu_mean :.3f} +={ Nu_std :.3f} , deviates more than 1% from t={ deviates :.2f} ' )
332+ else :
333+ print (f'{ label } Nu={ Nu_mean :.3f} +={ Nu_std :.3f} ' )
334+
335+ k = dat ['k' ]
336+ spectrum = np .array (dat ['spectrum' ])
337+ u_spectrum = np .mean (spectrum , axis = 0 )[1 ]
338+ idx = dat ['res_in_boundary_layer' ]
339+ _s = u_spectrum [idx ]
340+ spectrum_ax .loglog (
341+ k [_s > 1e-16 ], _s [_s > 1e-16 ], color = last_line .get_color (), ls = last_line .get_linestyle (), label = label
342+ )
343+
344+ prof_ax .plot (dat ['profile_T' ], dat ['z' ], color = last_line .get_color (), ls = last_line .get_linestyle (), label = label )
345+ rms_ax .plot (
346+ dat ['rms_profile_T' ], dat ['z' ], color = last_line .get_color (), ls = last_line .get_linestyle (), label = label
347+ )
348+
349+ Nu_ax .legend (frameon = True )
350+ Nu_ax .set_xlabel ('t' )
351+ Nu_ax .set_ylabel ('Nu' )
352+
353+ spectrum_ax .legend (frameon = False )
354+ spectrum_ax .set_xlabel ('$k$' )
355+ spectrum_ax .set_ylabel (r'$\|\hat{u}_x\|$' )
356+
357+
358+ def compare_Nusselt_over_time1e7 ():
359+ fig , Nu_ax = plt .subplots ()
360+ _ , axs = plt .subplots (1 , 3 , figsize = (10 , 3 ))
361+ prof_ax = axs [0 ]
362+ rms_ax = axs [1 ]
363+ spectrum_ax = axs [2 ]
364+
365+ Ra = '1e7'
366+ res = 96
367+
368+ data = []
369+ labels = []
370+ linestyles = []
371+
372+ ref_data = get_pySDC_data (Ra , res = res , dt = 0.009 )
373+
374+ for dt in [0.01 , 0.009 ]:
375+ data .append (get_pySDC_data (Ra , res = res , dt = dt ))
376+ labels .append (f'SDC, dt={ dt :.4f} ' )
377+ linestyles .append ('-' )
378+
379+ # # ----------------- RK ------------------------
380+
381+ for dt in [0.008 , 0.006 , 0.003 ]:
382+ data .append (get_pySDC_data (Ra , res = res , dt = dt , RK = True ))
383+ labels .append (f'RK, dt={ dt :.3f} ' )
384+ linestyles .append ('--' )
385+
281386 for dat , label , linestyle in zip (data , labels , linestyles ):
282387 Nu = np .array (dat ['Nu' ]['V' ])
283388 t = dat ['t' ]
284389 Nu_ref = np .array (ref_data ['Nu' ]['V' ])
285390 t_i , Nu_i = interpolate_NuV_to_reference_times (dat , ref_data )
286- ax .plot (t , Nu , label = label , ls = linestyle )
391+ Nu_ax .plot (t , Nu , label = label , ls = linestyle )
287392
288393 error = np .maximum .accumulate (np .abs (Nu_ref [: Nu_i .shape [0 ]] - Nu_i ) / np .abs (Nu_ref [: Nu_i .shape [0 ]]))
289394
@@ -292,43 +397,151 @@ def compare_Nusselt_over_time1e6():
292397 Nu_mean = np .mean (Nu [mask ])
293398 Nu_std = np .std (Nu [mask ])
294399
295- last_line = ax .get_lines ()[- 1 ]
400+ last_line = Nu_ax .get_lines ()[- 1 ]
296401 if any (error > 1e-2 ):
297402 deviates = min (t_i [error > 1e-2 ])
298- ax .axvline (deviates , color = last_line .get_color (), ls = last_line .get_linestyle ())
403+ Nu_ax .axvline (deviates , color = last_line .get_color (), ls = last_line .get_linestyle ())
299404 print (f'{ label } Nu={ Nu_mean :.3f} +={ Nu_std :.3f} , deviates more than 1% from t={ deviates :.2f} ' )
300405 else :
301406 print (f'{ label } Nu={ Nu_mean :.3f} +={ Nu_std :.3f} ' )
302407
303- if 'res_in_boundary_layer' in dat . keys ():
304- k = dat ['k' ]
305- spectrum = np . array ( dat [ 'spectrum' ])
408+ k = dat [ 'k' ]
409+ spectrum = np . array ( dat ['spectrum' ])
410+ try :
306411 u_spectrum = np .mean (spectrum , axis = 0 )[1 ]
412+ # u_spectrum = spectrum[0][1]
307413 idx = dat ['res_in_boundary_layer' ]
308414 _s = u_spectrum [idx ]
309- _ax .loglog (
415+ spectrum_ax .loglog (
310416 k [_s > 1e-16 ], _s [_s > 1e-16 ], color = last_line .get_color (), ls = last_line .get_linestyle (), label = label
311417 )
312- _ax .legend (frameon = False )
313- _ax .set_xlabel ('$k$' )
314- _ax .set_ylabel (r'$\|\hat{u}_x\|$' )
418+ except :
419+ pass
315420
316- ax .legend (frameon = True )
317- ax .set_xlabel ('t' )
318- ax .set_ylabel ('Nu' )
421+ prof_ax .plot (dat ['profile_T' ], dat ['z' ], color = last_line .get_color (), ls = last_line .get_linestyle (), label = label )
422+ rms_ax .plot (
423+ dat ['rms_profile_T' ], dat ['z' ], color = last_line .get_color (), ls = last_line .get_linestyle (), label = label
424+ )
319425
426+ Nu_ax .legend (frameon = True )
427+ Nu_ax .set_xlabel ('t' )
428+ Nu_ax .set_ylabel ('Nu' )
320429
321- def interpolate_NuV_to_reference_times (data , reference_data , order = 12 ):
322- from qmat .lagrange import getSparseInterpolationMatrix
430+ spectrum_ax .legend (frameon = False )
431+ spectrum_ax .set_xlabel ('$k$' )
432+ spectrum_ax .set_ylabel (r'$\|\hat{u}_x\|$' )
323433
324- t_in = np .array (data ['t' ])
325- t_out = np .array ([me for me in reference_data ['t' ] if me <= max (t_in )])
326434
327- interpolation_matrix = getSparseInterpolationMatrix (t_in , t_out , order = order )
328- return interpolation_matrix @ t_in , interpolation_matrix @ data ['Nu' ]['V' ]
435+ def compare_Nusselt_over_time1e8 ():
436+ fig , axs = plt .subplots (1 , 4 , figsize = (13 , 3 ))
437+ Nu_ax = axs [0 ]
438+ prof_ax = axs [1 ]
439+ rms_ax = axs [2 ]
440+ spectrum_ax = axs [3 ]
441+
442+ Ra = '1e8'
443+ res = 96
444+
445+ data = []
446+ labels = []
447+ linestyles = []
448+
449+ ref_data = get_pySDC_data (Ra , res = res , dt = 6e-3 )
450+
451+ for dt in [6e-3 ]:
452+ data .append (get_pySDC_data (Ra , res = res , dt = dt ))
453+ labels .append (f'SDC, dt={ dt :.4f} ' )
454+ linestyles .append ('-' )
455+
456+ # # ----------------- RK ------------------------
457+
458+ for dt in [0.005 ]:
459+ data .append (get_pySDC_data (Ra , res = res , dt = dt , RK = True ))
460+ labels .append (f'RK, dt={ dt :.3f} ' )
461+ linestyles .append ('--' )
462+
463+ for dat , label , linestyle in zip (data , labels , linestyles ):
464+ Nu = np .array (dat ['Nu' ]['V' ])
465+ t = dat ['t' ]
466+ Nu_ref = np .array (ref_data ['Nu' ]['V' ])
467+ t_i , Nu_i = interpolate_NuV_to_reference_times (dat , ref_data )
468+ Nu_ax .plot (t , Nu , label = label , ls = linestyle )
469+
470+ error = np .maximum .accumulate (np .abs (Nu_ref [: Nu_i .shape [0 ]] - Nu_i ) / np .abs (Nu_ref [: Nu_i .shape [0 ]]))
329471
472+ # compute mean Nu
473+ mask = np .logical_and (t >= 20 , t <= 200 )
474+ Nu_mean = np .mean (Nu [mask ])
475+ Nu_std = np .std (Nu [mask ])
476+
477+ last_line = Nu_ax .get_lines ()[- 1 ]
478+ if any (error > 1e-2 ):
479+ deviates = min (t_i [error > 1e-2 ])
480+ Nu_ax .axvline (deviates , color = last_line .get_color (), ls = last_line .get_linestyle ())
481+ print (f'{ label } Nu={ Nu_mean :.3f} +={ Nu_std :.3f} , deviates more than 1% from t={ deviates :.2f} ' )
482+ else :
483+ print (f'{ label } Nu={ Nu_mean :.3f} +={ Nu_std :.3f} ' )
330484
331- # def compare_accross_Ra():
485+ k = dat ['k' ]
486+ spectrum = np .array (dat ['spectrum' ])
487+ u_spectrum = np .mean (spectrum , axis = 0 )[1 ]
488+ # u_spectrum = spectrum[0, 0, :]
489+ idx = dat ['res_in_boundary_layer' ]
490+ _s = u_spectrum [idx ]
491+ spectrum_ax .loglog (
492+ k [_s > 1e-16 ], _s [_s > 1e-16 ], color = last_line .get_color (), ls = last_line .get_linestyle (), label = label
493+ )
494+
495+ prof_ax .plot (dat ['profile_T' ], dat ['z' ], color = last_line .get_color (), ls = last_line .get_linestyle (), label = label )
496+ rms_ax .plot (
497+ dat ['rms_profile_T' ], dat ['z' ], color = last_line .get_color (), ls = last_line .get_linestyle (), label = label
498+ )
499+
500+ Nu_ax .legend (frameon = True )
501+ Nu_ax .set_xlabel ('t' )
502+ Nu_ax .set_ylabel ('Nu' )
503+
504+ spectrum_ax .legend (frameon = False )
505+ spectrum_ax .set_xlabel ('$k$' )
506+ spectrum_ax .set_ylabel (r'$\|\hat{u}_x\|$' )
507+
508+
509+ def plot_thibaut_stuff ():
510+ fig , ax = plt .subplots ()
511+
512+ data = get_pySDC_data ('1e7' , res = 96 , dt = 0.009 )
513+
514+ Nu = data ['Nu' ]['V' ]
515+ t = data ['t' ]
516+ avg_Nu = np .array ([np .mean (Nu [40 : 40 + i + 1 ]) for i in range (len (Nu [40 :]))])
517+ Delta_Nu = np .array ([abs (avg_Nu [i + 1 ] - avg_Nu [i ]) for i in range (len (avg_Nu ) - 1 )])
518+ # ax.plot(data['t'][40:-1], Delta_Nu / avg_Nu[:-1])
519+ # ax.plot(data['t'], np.abs(avg_Nu - avg_Nu[-1]) / avg_Nu[-1])
520+ ax .plot (t [40 :], avg_Nu )
521+ ax .plot (t [40 :], Nu [40 :])
522+ ax .set_xlabel ('t' )
523+ # ax.set_ylabel('Delta Nu / Nu')
524+
525+
526+ def plot_spectrum_over_time1e6R4 ():
527+ fig , ax = plt .subplots ()
528+
529+ # data = get_pySDC_data('1e6', res=48, dt=0.02, config_name='RBC3DG4')
530+ # data = get_pySDC_data('1e7', res=96, dt=0.009, config_name='RBC3DG4')
531+ data = get_pySDC_data ('1e7' , res = 64 , dt = 0.005 , config_name = 'RBC3DG4R4' )
532+
533+ s = data ['spectrum' ]
534+ t = data ['t' ]
535+ k = data ['k' ]
536+
537+ # for i in range(len(s)):
538+ # for i in [0, 3, 10, 20, 40, 80, -1]:
539+ for i in [0 , 3 , 10 , - 1 ]:
540+ print (i , t [i ])
541+ _s = s [i ][0 , data ['res_in_boundary_layer' ]]
542+ _s = np .max (s [i ][0 ], axis = 0 )
543+ ax .loglog (k [_s > 1e-20 ], _s [_s > 1e-20 ], label = f't={ t [i ]:.1f} ' )
544+ ax .legend (frameon = False )
332545
333546
334547if __name__ == '__main__' :
@@ -337,5 +550,8 @@ def interpolate_NuV_to_reference_times(data, reference_data, order=12):
337550 # compare_Nusselt_over_time1e5()
338551 # compare_Nusselt_over_time1e6()
339552 # compare_Nusselt_over_time1e7()
553+ # compare_Nusselt_over_time1e8()
554+ # plot_thibaut_stuff()
555+ plot_spectrum_over_time1e6R4 ()
340556
341557 plt .show ()
0 commit comments