@@ -22,6 +22,30 @@ def rgba_to_hex(rgba):
2222 b = int (rgba [2 ]* 255.0 )
2323 return '#{:02X}{:02X}{:02X}' .format (r , g , b )
2424
25+ def get_analytic_profile (x_coord , time , problo , probhi ,
26+ geometry , dimension ):
27+
28+ if geometry == "spherical" :
29+ exponent = 1.5
30+ center = 0.0
31+ elif dimension == 2 and geometry == "cylindrical" :
32+ exponent = 1.5
33+ center = 0.5 * (problo [1 ] + probhi [1 ])
34+ else :
35+ exponent = dimension / 2.0
36+ center = 0.5 * (problo [0 ] + probhi [0 ])
37+
38+ dist2 = (x_coord - float (center ))** 2
39+ T1 = 1.0
40+ T2 = 2.0
41+ t_0 = 0.001
42+ diff_coeff = 1.0
43+ temp = T1 + (T2 - T1 ) * (t_0 / (time + t_0 ))** exponent * \
44+ np .exp (- 0.25 * dist2 / (diff_coeff * (time + t_0 )))
45+
46+ return temp
47+
48+
2549def get_T_profile (plotfile ):
2650
2751 ds = CastroDataset (plotfile )
@@ -32,17 +56,23 @@ def get_T_profile(plotfile):
3256 # Sort the ray values by 'x' so there are no discontinuities
3357 # in the line plot
3458
59+ dimension = ds .dimensionality
3560 coords = {"cartesian" :"x" ,
3661 "cylindrical" :"z" ,
3762 "spherical" :"r" }
3863
3964 coord = coords [ds .geometry ]
4065
66+ problo = ds .domain_left_edge
67+ probhi = ds .domain_right_edge
68+
4169 srt = np .argsort (ad [coord ])
4270 x_coord = np .array (ad [coord ][srt ])
4371 temp = np .array (ad ['Temp' ][srt ])
72+ analytic_temp = get_analytic_profile (x_coord , time , problo , probhi ,
73+ ds .geometry , dimension )
4474
45- return time , x_coord , temp
75+ return time , x_coord , temp , analytic_temp
4676
4777
4878def doit (prefix , nums , skip , limitlabels , xmin , xmax ):
@@ -52,12 +82,9 @@ def doit(prefix, nums, skip, limitlabels, xmin, xmax):
5282
5383 ax_T = f .add_subplot (111 )
5484
55- # Get set of colors to use and apply to plot
56- numplots = int (len (nums ) / skip )
57- cm = plt .get_cmap ('nipy_spectral' )
58- clist = [cm (0.95 * i / numplots ) for i in range (numplots + 1 )]
59- hexclist = [rgba_to_hex (ci ) for ci in clist ]
60- ax_T .set_prop_cycle (cycler ('color' , hexclist ))
85+ # Get colors
86+ numplots = len (range (0 , len (nums ), skip ))
87+ colors = plt .cm .nipy_spectral (np .linspace (0 , 1 , numplots ))
6188
6289 if limitlabels > 1 :
6390 skiplabels = int (numplots / limitlabels )
@@ -69,17 +96,18 @@ def doit(prefix, nums, skip, limitlabels, xmin, xmax):
6996 index = 0
7097
7198 for n in range (0 , len (nums ), skip ):
72-
7399 pfile = "{}{}" .format (prefix , nums [n ])
74-
75- time , x , T = get_T_profile (pfile )
100+ i = int ( n / skip )
101+ time , x , T , analytic_T = get_T_profile (pfile )
76102
77103 if index % skiplabels == 0 :
78- ax_T .plot (x , T , label = "t = {:7.5f} s" .format (time ))
104+ ax_T .plot (x , T , "-" , color = colors [i ], label = "simulation: t = {:7.5f} s" .format (time ))
105+ ax_T .plot (x , analytic_T , "--" , color = colors [i ], label = "analytic: t = {:7.5f} s" .format (time ))
79106 else :
80- ax_T .plot (x , T )
107+ ax_T .plot (x , T , "-" , color = colors [i ])
108+ ax_T .plot (x , analytic_T , "--" , color = colors [i ])
81109
82- index = index + 1
110+ index += 1
83111
84112 ax_T .legend (frameon = False )
85113 ax_T .set_ylabel ("T (K)" )
0 commit comments