Testing Sod tube with Godunov#

CI test for Sod tube with Godunov

 8 import os
 9
10 import matplotlib.pyplot as plt
11 import numpy as np
12 from shamrock.model_ramses import HLL
13
14 import shamrock

Setup params

19 multx = 4
20 multy = 1
21 multz = 1
22
23 sz = 1 << 1
24 base = 32
25 gamma = 1.4

Init model

31 ctx = shamrock.Context()
32 ctx.pdata_layout_new()
33
34 model = shamrock.get_Model_Ramses(context=ctx, vector_type="f64_3", grid_repr="i64_3")

Init config

39 cfg = model.gen_default_config()
40 scale_fact = 2 / (sz * base * multx)
41 cfg.set_scale_factor(scale_fact)
42
43 cfg.set_eos_gamma(gamma)
44 # cfg.set_riemann_solver(Rusanov)
45 cfg.set_riemann_solver(HLL)
46
47 # cfg.set_slope_lim_none()
48 # cfg.set_slope_lim_vanleer_f()
49 # cfg.set_slope_lim_vanleer_std()
50 # cfg.set_slope_lim_vanleer_sym()
51 cfg.set_slope_lim_minmod()
52 cfg.set_face_time_interpolation(True)
53 model.set_solver_config(cfg)

Init scheduler and grid

 59 model.init_scheduler(int(1e7), 1)
 60 model.make_base_grid((0, 0, 0), (sz, sz, sz), (base * multx, base * multy, base * multz))
 61
 62
 63 # without face time interpolation
 64 # 0.07979993131348424 (0.17970690984930585, 0.0, 0.0) 0.12628776652228088
 65
 66 # with face time interpolation
 67 # 0.07894793711859852 (0.17754462339166546, 0.0, 0.0) 0.12498304725061045
 68
 69
 70 kx, ky, kz = 2 * np.pi, 0, 0
 71 delta_rho = 1e-2
 72
 73
 74 def rho_map(rmin, rmax):
 75     x, y, z = rmin
 76     if x < 1:
 77         return 1
 78     else:
 79         return 0.125
 80
 81
 82 etot_L = 1.0 / (gamma - 1)
 83 etot_R = 0.1 / (gamma - 1)
 84
 85
 86 def rhoetot_map(rmin, rmax):
 87     rho = rho_map(rmin, rmax)
 88
 89     x, y, z = rmin
 90     if x < 1:
 91         return etot_L
 92     else:
 93         return etot_R
 94
 95
 96 def rhovel_map(rmin, rmax):
 97     rho = rho_map(rmin, rmax)
 98
 99     return (0, 0, 0)
100
101
102 model.set_field_value_lambda_f64("rho", rho_map)
103 model.set_field_value_lambda_f64("rhoetot", rhoetot_map)
104 model.set_field_value_lambda_f64_3("rhovel", rhovel_map)
105
106 t_target = 0.245
107
108 model.evolve_until(t_target)
109
110 # model.evolve_once()
111 xref = 1.0
112 xrange = 0.5
113 sod = shamrock.phys.SodTube(gamma=gamma, rho_1=1, P_1=1, rho_5=0.125, P_5=0.1)
114 sodanalysis = model.make_analysis_sodtube(sod, (1, 0, 0), t_target, xref, -xrange, xrange)
115
116
117 #################
118 ### Plot
119 #################
120 # do plot or not
121 if False:
122
123     def convert_to_cell_coords(dic):
124         cmin = dic["cell_min"]
125         cmax = dic["cell_max"]
126
127         xmin = []
128         ymin = []
129         zmin = []
130         xmax = []
131         ymax = []
132         zmax = []
133
134         for i in range(len(cmin)):
135             m, M = cmin[i], cmax[i]
136
137             mx, my, mz = m
138             Mx, My, Mz = M
139
140             for j in range(8):
141                 a, b = model.get_cell_coords(((mx, my, mz), (Mx, My, Mz)), j)
142
143                 x, y, z = a
144                 xmin.append(x)
145                 ymin.append(y)
146                 zmin.append(z)
147
148                 x, y, z = b
149                 xmax.append(x)
150                 ymax.append(y)
151                 zmax.append(z)
152
153         dic["xmin"] = np.array(xmin)
154         dic["ymin"] = np.array(ymin)
155         dic["zmin"] = np.array(zmin)
156         dic["xmax"] = np.array(xmax)
157         dic["ymax"] = np.array(ymax)
158         dic["zmax"] = np.array(zmax)
159
160         return dic
161
162     dic = convert_to_cell_coords(ctx.collect_data())
163
164     X = []
165     rho = []
166     rhovelx = []
167     rhoetot = []
168
169     for i in range(len(dic["xmin"])):
170         X.append(dic["xmin"][i])
171         rho.append(dic["rho"][i])
172         rhovelx.append(dic["rhovel"][i][0])
173         rhoetot.append(dic["rhoetot"][i])
174
175     X = np.array(X)
176     rho = np.array(rho)
177     rhovelx = np.array(rhovelx)
178     rhoetot = np.array(rhoetot)
179
180     vx = rhovelx / rho
181
182     fig, axs = plt.subplots(nrows=1, ncols=1, figsize=(9, 6), dpi=125)
183
184     plt.scatter(X, rho, rasterized=True, label="rho")
185     plt.scatter(X, vx, rasterized=True, label="v")
186     plt.scatter(X, (rhoetot - 0.5 * rho * (vx**2)) * (gamma - 1), rasterized=True, label="P")
187     # plt.scatter(X,rhoetot, rasterized=True,label="rhoetot")
188     plt.legend()
189     plt.grid()
190
191     #### add analytical soluce
192     arr_x = np.linspace(xref - xrange, xref + xrange, 1000)
193
194     arr_rho = []
195     arr_P = []
196     arr_vx = []
197
198     for i in range(len(arr_x)):
199         x_ = arr_x[i] - xref
200
201         _rho, _vx, _P = sod.get_value(t_target, x_)
202         arr_rho.append(_rho)
203         arr_vx.append(_vx)
204         arr_P.append(_P)
205
206     plt.plot(arr_x, arr_rho, color="black", label="analytic")
207     plt.plot(arr_x, arr_vx, color="black")
208     plt.plot(arr_x, arr_P, color="black")
209     plt.ylim(-0.1, 1.1)
210     plt.xlim(0.5, 1.5)
211     #######
212     plt.show()
213
214 #################
215 ### Test CD
216 #################
217 rho, v, P = sodanalysis.compute_L2_dist()
218 print(rho, v, P)
219 vx, vy, vz = v
220
221 # normally :
222 # rho 0.07979993131348424
223 # v (0.17970690984930585, 0.0, 0.0)
224 # P 0.12628776652228088
225
226 test_pass = True
227 pass_rho = 0.07979993131348424 + 1e-7
228 pass_vx = 0.17970690984930585 + 1e-7
229 pass_vy = 1e-09
230 pass_vz = 1e-09
231 pass_P = 0.12628776652228088 + 1e-7
232
233 err_log = ""
234
235 if rho > pass_rho:
236     err_log += ("error on rho is too high " + str(rho) + ">" + str(pass_rho)) + "\n"
237     test_pass = False
238 if vx > pass_vx:
239     err_log += ("error on vx is too high " + str(vx) + ">" + str(pass_vx)) + "\n"
240     test_pass = False
241 if vy > pass_vy:
242     err_log += ("error on vy is too high " + str(vy) + ">" + str(pass_vy)) + "\n"
243     test_pass = False
244 if vz > pass_vz:
245     err_log += ("error on vz is too high " + str(vz) + ">" + str(pass_vz)) + "\n"
246     test_pass = False
247 if P > pass_P:
248     err_log += ("error on P is too high " + str(P) + ">" + str(pass_P)) + "\n"
249     test_pass = False
250
251 if test_pass == False:
252     exit("Test did not pass L2 margins : \n" + err_log)

Estimated memory usage: 0 MB

Gallery generated by Sphinx-Gallery