def der_plot(step, der_index, f, ax1, ax2, ax3): np_filenames = [] locations = [] for idx in range(99): np_filenames.append("tube_pt_ppank_" + str(idx) + ".npy") locations.append(idx / 100.0) data_der = [] for np_filename in np_filenames: arr_t, arr_der = load_from_np("./result/" + np_filename, der_index) data_der.append(arr_der[step]) # shift locations so we could input it in analytic coordination. locations_aly = [] for location in locations: location_aly = location - 0.5 locations_aly.append(location_aly) analytic_solver = analytic.Solver() analytic_solution = analytic_solver.get_analytic_solution(locations_aly, t=arr_t[step]) data_der_analytic = [] for location_idx in range(len(locations)): if der_index == 1: title = 'RHO' elif der_index == 2: title = 'M' elif der_index == 3: title = 'PRESSURE' else: title = 'UNKNOWN' data_der_analytic.append(analytic_solution[location_idx][der_index]) data_der_deviation = [] for idx in range(len(data_der)): data_der_deviation.append(data_der[idx] - data_der_analytic[idx]) ax1.set_title('3D - ' + title) ax1.scatter(locations, data_der, s=10, c='b', marker='s') ax2.set_title('1D - ' + title) ax2.scatter(locations, data_der_analytic, s=10, c='b', marker='8') ax3.set_title('DEVIATION') ax3.scatter(locations, data_der_deviation, s=10, c='b', marker='o') return str(arr_t[step])
def load_from_analytic(location, arr_time): # load analytic solution data of 1D tube # note the coordination of analytic solution is different from the one that # SOLVCON used. mesh_1d = (location, ) analytic_solver = analytic.Solver() vals = list() for t_step in arr_time: solution_analytic = analytic_solver.get_analytic_solution(mesh_1d, t=t_step) # refer to gas probe.py:Probe::__call__ vlist = [t_step, solution_analytic[0][1], solution_analytic[0][3]] vals.append(vlist) arr_aly = np.array(vals, dtype='float64') arr_aly_t = arr_time arr_aly_rho = arr_aly[:, 1] arr_aly_p = arr_aly[:, 2] return arr_aly_t, arr_aly_rho, arr_aly_p
def load_from_analytic(location, arr_time, arr_idx_der): # load analytic solution data of 1D tube # note the coordination of analytic solution is different from # the one that SOLVCON used. mesh_1d = (location, ) analytic_solver = analytic.Solver() # parse the analytic data object to be arr type data object vals = list() for t_step in arr_time: solution_analytic = analytic_solver.get_analytic_solution(mesh_1d, t=t_step) # refer to gas probe.py:Probe::__call__ vlist = [t_step, solution_analytic[0][1], solution_analytic[0][3]] vals.append(vlist) arr_aly = np.array(vals, dtype='float64') # parsed. arr_aly_t = arr_time arr_aly_der = arr_aly[:, arr_idx_der] return arr_aly_t, arr_aly_der
# Description: # An example to show how to use sodtube1d class # solvers import sodtube1d.generator_mesh as gmesh import sodtube1d.solver_analytic as analytic import sodtube1d.solver_cese as cese import sodtube1d.solver_porting as solver_porting # helper handlers import sodtube1d.handler_data as hd import sodtube1d.handler_plot as hp generator_mesh = gmesh.Mesher() generator_mesh.gen_mesh() mesh = generator_mesh.get_mesh() analytic_solver = analytic.Solver() solution_analytic = analytic_solver.get_analytic_solution(mesh) solver_cese = cese.Solver() solver_cese.run_cese_iteration() solution_cese = solver_cese.get_cese_solution() solution_porting = solver_porting.get_specific_solution_for_unit_test_high_precision( ) dm = hd.DataManager() pm = hp.PlotManager() #solution_deviation = dm.get_deviation(solution_analytic, solution_cese_porting) solution_deviation = dm.get_deviation(solution_porting, solution_cese) #solution_deviation_percent = dm.get_deviation_percent(solution_analytic, solution_cese_porting)
def der_plot(step, der_index, base_subplot_idx): """Plot one plot of a derived quantity. Parameters ---------- step : int nth step der_index : int index to indicate which derived quantity it means base_subplot_idx : int index to indicate which row this subplot should locate Returns ------- tuples several attributes to compose of a subplot """ np_filenames = [] locations = [] for idx in range(99): np_filenames.append("tube_pt_ppank_" + str(idx) + ".npy") locations.append(idx / 100.0) data_der = [] for np_filename in np_filenames: arr_t, arr_der = load_from_np( "../sod-tube-working/result/" + np_filename, der_index) data_der.append(arr_der[step]) # shift locations so we could input it in analytic coordination. locations_aly = [] for location in locations: location_aly = location - 0.5 locations_aly.append(location_aly) analytic_solver = analytic.Solver() analytic_solution = analytic_solver.get_analytic_solution(locations_aly, t=arr_t[step]) data_der_analytic = [] for location_idx in range(len(locations)): if der_index == 1: title = 'RHO' elif der_index == 2: title = 'V-magnitude' elif der_index == 3: title = 'PRESSURE' else: title = 'UNKNOWN' data_der_analytic.append(analytic_solution[location_idx][der_index]) data_der_deviation = [] for idx in range(len(data_der)): data_der_deviation.append(data_der[idx] - data_der_analytic[idx]) time_label = f"{arr_t[step]:.4f}" # 331 means index 1 position of a 3x3 matrix subplot_idx = 330 + base_subplot_idx ax1 = plt.subplot(subplot_idx, title='3D - ' + title) artist_3d = plt.scatter(locations, data_der, s=10, c='b', marker='s') text1 = plt.text(0.1, 0.08, "Time: " + time_label, transform=ax1.transAxes) subplot_idx = 330 + base_subplot_idx + 3 ax2 = plt.subplot(subplot_idx, title='1D - ' + title) artist_1d = plt.scatter(locations, data_der_analytic, s=10, c='b', marker='8') text2 = plt.text(0.1, 0.08, "Time: " + time_label, transform=ax2.transAxes) subplot_idx = 330 + base_subplot_idx + 6 ax3 = plt.subplot(subplot_idx, title='DEVIATION - ' + title) artist_dev = plt.scatter(locations, data_der_deviation, s=10, c='b', marker='o') text3 = plt.text(0.1, 0.08, "Time: " + time_label, transform=ax3.transAxes) return artist_3d, artist_1d, artist_dev, text1, text2, text3
def der_plot(step, der_index, base_subplot_idx): np_filenames = [] locations = [] for idx in range(99): np_filenames.append("tube_pt_ppank_" + str(idx) + ".npy") locations.append(idx / 100.0) data_der = [] for np_filename in np_filenames: arr_t, arr_der = load_from_np("./result/" + np_filename, der_index) data_der.append(arr_der[step]) # shift locations so we could input it in analytic coordination. locations_aly = [] for location in locations: location_aly = location - 0.5 locations_aly.append(location_aly) analytic_solver = analytic.Solver() analytic_solution = analytic_solver.get_analytic_solution(locations_aly, t=arr_t[step]) data_der_analytic = [] for location_idx in range(len(locations)): if der_index == 1: title = 'RHO' elif der_index == 2: title = 'V-magnitude' elif der_index == 3: title = 'PRESSURE' else: title = 'UNKNOWN' data_der_analytic.append(analytic_solution[location_idx][der_index]) data_der_deviation = [] for idx in range(len(data_der)): data_der_deviation.append(data_der[idx] - data_der_analytic[idx]) subplot_idx = 330 + base_subplot_idx ax1 = plt.subplot(subplot_idx, title='3D - ' + title) artist_3d = plt.scatter(locations, data_der, s=10, c='b', marker='s') text1 = plt.text(0.1, 0.08, "Time: " + str(arr_t[step]), transform=ax1.transAxes) subplot_idx = 330 + base_subplot_idx + 3 ax2 = plt.subplot(subplot_idx, title='1D - ' + title) artist_1d = plt.scatter(locations, data_der_analytic, s=10, c='b', marker='8') text2 = plt.text(0.1, 0.08, "Time: " + str(arr_t[step]), transform=ax2.transAxes) subplot_idx = 330 + base_subplot_idx + 6 ax3 = plt.subplot(subplot_idx, title='DEVIATION - ' + title) artist_dev = plt.scatter(locations, data_der_deviation, s=10, c='b', marker='o') text3 = plt.text(0.1, 0.08, "Time: " + str(arr_t[step]), transform=ax3.transAxes) return artist_3d, artist_1d, artist_dev, text1, text2, text3