def get_material_list(db_filename, first_id, last_id, interp_opt=None): """Return a list of TEProp classes. :param db_filename: database filename containing the thermoelectric material properties :param first_id: smallest id of a TEP. :param last_id: largest id of a TEP. :param interp_opt: interpolation option to be used in TEProp. :return: (list of materials, list of material ids). """ material_list = [None] * (last_id + 1) material_id_list = [] for id_num in range(first_id, last_id + 1): try: material = TEProp(db_filename=db_filename, id_num=id_num) except ValueError: pass else: if interp_opt is not None: material.set_interp_opt(interp_opt) material_list[id_num] = material material_id_list.append(id_num) return material_list, material_id_list
def main(num_cheb_nodes, noise_percent): RESULT_SUBDIR = "noise_{}%".format(noise_percent) RESULT_FILENAME_WO_PATH = "accuracy_cheb_{}_nodes_with_{}%_noise.csv".format( num_cheb_nodes, noise_percent) RESULT_FILENAME = os.path.join(RESULT_DIR, RESULT_SUBDIR, RESULT_FILENAME_WO_PATH) print("{} Chebyshev Nodes; {}% Noise; File = {}".format( num_cheb_nodes, noise_percent, RESULT_FILENAME)) info_df = pd.read_csv(INFO_FILENAME, index_col=0) result_df = pd.DataFrame(columns=RESULT_COLUMNS) result_df.index.name = 'id' for id_num in info_df.index: print("processing id={}...".format(id_num)) mat = TEProp(db_filename=DB_FILENAME, id_num=id_num) Seebeck_xy_data = np.asarray(mat.Seebeck.raw_data()) elec_resi_xy_data = np.asarray(mat.elec_resi.raw_data()) thrm_cond_xy_data = np.asarray(mat.thrm_cond.raw_data()) # make unique, sorted on temperature _, Seebeck_unique_indices = np.unique(Seebeck_xy_data[:, 0], return_index=True) Seebeck_xy_data = Seebeck_xy_data[Seebeck_unique_indices, :] _, elec_resi_unique_indices = np.unique(elec_resi_xy_data[:, 0], return_index=True) elec_resi_xy_data = elec_resi_xy_data[elec_resi_unique_indices, :] _, thrm_cond_unique_indices = np.unique(thrm_cond_xy_data[:, 0], return_index=True) thrm_cond_xy_data = thrm_cond_xy_data[thrm_cond_unique_indices, :] Seebeck_interp_func, Seebeck_exact_func, Seebeck_cheb_nodes = \ interpolate_barycentric_cheb_with_noise(Seebeck_xy_data[:, 0], Seebeck_xy_data[:, 1], num_cheb_nodes, spline_order=SEEBECK_SPLINE_ORDER, noise_percent=noise_percent) elec_resi_interp_func, elec_resi_exact_func, elec_resi_cheb_nodes = \ interpolate_barycentric_cheb_with_noise(elec_resi_xy_data[:, 0], elec_resi_xy_data[:, 1], num_cheb_nodes, spline_order=ELEC_RESI_SPLINE_ORDER, noise_percent=noise_percent) thrm_cond_interp_func, thrm_cond_exact_func, thrm_cond_cheb_nodes = \ interpolate_barycentric_cheb_with_noise(thrm_cond_xy_data[:, 0], thrm_cond_xy_data[:, 1], num_cheb_nodes, spline_order=THRM_COND_SPLINE_ORDER, noise_percent=noise_percent) # compute the curves Seebeck_T = np.linspace(Seebeck_xy_data[:, 0][0], Seebeck_xy_data[:, 0][-1], num=10000) elec_resi_T = np.linspace(elec_resi_xy_data[:, 0][0], elec_resi_xy_data[:, 0][-1], num=10000) thrm_cond_T = np.linspace(thrm_cond_xy_data[:, 0][0], thrm_cond_xy_data[:, 0][-1], num=10000) Seebeck_interp_curve = Seebeck_interp_func(Seebeck_T) Seebeck_exact_curve = Seebeck_exact_func(Seebeck_T) dSeebeck_dT_interp_curve = Seebeck_interp_func.derivative()(Seebeck_T) dSeebeck_dT_exact_curve = Seebeck_exact_func.derivative()(Seebeck_T) elec_resi_interp_curve = elec_resi_interp_func(elec_resi_T) elec_resi_exact_curve = elec_resi_exact_func(elec_resi_T) thrm_cond_interp_curve = thrm_cond_interp_func(thrm_cond_T) thrm_cond_exact_curve = thrm_cond_exact_func(thrm_cond_T) # RMAE (Relative Maximum Absolute Error), divided by maximum exact value Seebeck_RMAE = np.max( np.abs(Seebeck_interp_curve - Seebeck_exact_curve)) / np.max( np.abs(Seebeck_exact_curve)) dSeebeck_dT_RMAE = np.max( np.abs(dSeebeck_dT_interp_curve - dSeebeck_dT_exact_curve)) / np.max( np.abs(dSeebeck_dT_exact_curve)) elec_resi_RMAE = np.max( np.abs(elec_resi_interp_curve - elec_resi_exact_curve)) / np.max( np.abs(elec_resi_exact_curve)) thrm_cond_RMAE = np.max( np.abs(thrm_cond_interp_curve - thrm_cond_exact_curve)) / np.max( np.abs(thrm_cond_exact_curve)) # RL2E (Relative L^2-Error) Seebeck_RL2E = np.sqrt( np.trapz( (Seebeck_interp_curve - Seebeck_exact_curve)**2, Seebeck_T) / np.trapz(Seebeck_exact_curve**2, Seebeck_T)) dSeebeck_dT_RL2E = np.sqrt( np.trapz( (dSeebeck_dT_interp_curve - dSeebeck_dT_exact_curve)**2, Seebeck_T) / np.trapz(dSeebeck_dT_exact_curve**2, Seebeck_T)) elec_resi_RL2E = np.sqrt( np.trapz( (elec_resi_interp_curve - elec_resi_exact_curve)**2, elec_resi_T) / np.trapz(elec_resi_exact_curve**2, elec_resi_T)) thrm_cond_RL2E = np.sqrt( np.trapz( (thrm_cond_interp_curve - thrm_cond_exact_curve)**2, thrm_cond_T) / np.trapz(thrm_cond_exact_curve**2, thrm_cond_T)) # RL1E (Relative L^1-Error) Seebeck_RL1E = np.trapz( np.abs(Seebeck_interp_curve - Seebeck_exact_curve), Seebeck_T) / np.trapz(np.abs(Seebeck_exact_curve), Seebeck_T) dSeebeck_dT_RL1E = np.trapz( np.abs(dSeebeck_dT_interp_curve - dSeebeck_dT_exact_curve), Seebeck_T) / np.trapz(np.abs(dSeebeck_dT_exact_curve), Seebeck_T) elec_resi_RL1E = np.trapz( np.abs(elec_resi_interp_curve - elec_resi_exact_curve), elec_resi_T) / np.trapz(np.abs(elec_resi_exact_curve), elec_resi_T) thrm_cond_RL1E = np.trapz( np.abs(thrm_cond_interp_curve - thrm_cond_exact_curve), thrm_cond_T) / np.trapz(np.abs(thrm_cond_exact_curve), thrm_cond_T) # save the result result_df.loc[id_num] = [ Seebeck_RMAE, dSeebeck_dT_RMAE, elec_resi_RMAE, thrm_cond_RMAE, Seebeck_RL2E, dSeebeck_dT_RL2E, elec_resi_RL2E, thrm_cond_RL2E, Seebeck_RL1E, dSeebeck_dT_RL1E, elec_resi_RL1E, thrm_cond_RL1E ] result_df.to_csv(RESULT_FILENAME)
def main(num_cheb_nodes, noise_percent): result_subdir = "noise_{}%".format(noise_percent) result_filename_wo_path = "performance_cheb_{}_nodes_with_{}%_noise.csv".format(num_cheb_nodes, noise_percent) result_filename = os.path.join(RESULT_DIR, result_subdir, result_filename_wo_path) print("{} Chebyshev Nodes; {}% Noise; File = {}".format(num_cheb_nodes, noise_percent, result_filename)) info_df = pd.read_csv(INFO_FILENAME, index_col=0) result_df = pd.DataFrame(columns=RESULT_COLUMNS) result_df.index.name = 'id' for id_num in info_df.index: print("processing id={}...".format(id_num)) mat = TEProp(db_filename=DB_FILENAME, id_num=id_num) Tc = mat.min_raw_T Th = mat.max_raw_T Seebeck_xy_data = np.asarray(mat.Seebeck.raw_data()) elec_resi_xy_data = np.asarray(mat.elec_resi.raw_data()) thrm_cond_xy_data = np.asarray(mat.thrm_cond.raw_data()) # make unique on temperature _, Seebeck_unique_indices = np.unique(Seebeck_xy_data[:, 0], return_index=True) Seebeck_xy_data = Seebeck_xy_data[Seebeck_unique_indices, :] _, elec_resi_unique_indices = np.unique(elec_resi_xy_data[:, 0], return_index=True) elec_resi_xy_data = elec_resi_xy_data[elec_resi_unique_indices, :] _, thrm_cond_unique_indices = np.unique(thrm_cond_xy_data[:, 0], return_index=True) thrm_cond_xy_data = thrm_cond_xy_data[thrm_cond_unique_indices, :] num_Seebeck_samples = len(Seebeck_xy_data) num_elec_resi_samples = len(elec_resi_xy_data) num_thrm_cond_samples = len(thrm_cond_xy_data) Seebeck_interp_func, Seebeck_exact_func, Seebeck_cheb_nodes = \ interpolate_barycentric_cheb_with_noise(Seebeck_xy_data[:, 0], Seebeck_xy_data[:, 1], num_cheb_nodes, spline_order=SEEBECK_SPLINE_ORDER, noise_percent=noise_percent) elec_resi_interp_func, elec_resi_exact_func, elec_resi_cheb_nodes = \ interpolate_barycentric_cheb_with_noise(elec_resi_xy_data[:, 0], elec_resi_xy_data[:, 1], num_cheb_nodes, spline_order=ELEC_RESI_SPLINE_ORDER, noise_percent=noise_percent) thrm_cond_interp_func, thrm_cond_exact_func, thrm_cond_cheb_nodes = \ interpolate_barycentric_cheb_with_noise(thrm_cond_xy_data[:, 0], thrm_cond_xy_data[:, 1], num_cheb_nodes, spline_order=THRM_COND_SPLINE_ORDER, noise_percent=noise_percent) # compute the max zT T_grid = np.linspace(Tc, Th, num=10000) Seebeck_curve = Seebeck_interp_func(T_grid) elec_resi_curve = elec_resi_interp_func(T_grid) thrm_cond_curve = thrm_cond_interp_func(T_grid) zT_curve = Seebeck_curve ** 2 / elec_resi_curve / thrm_cond_curve * T_grid index_for_max_zT = np.argmax(zT_curve) max_zT = zT_curve[int(index_for_max_zT)] T_for_max_zT = T_grid[index_for_max_zT] # compute the maximum power density and efficiency solver = ThermoelctricEquationSolver(L, A) solver.set_bc(Tc, Th) solver.set_te_mat_func(thrm_cond_interp_func, elec_resi_interp_func, Seebeck_interp_func, Seebeck_interp_func.derivative()) res = solver.compute_max_power_density() if not res.success: print("computation of max. power density failed for id={}".format(id_num)) continue I_for_max_power_density = res.x max_power_density = -res.fun num_eval_for_max_power_density = res.nfev res = solver.compute_max_efficiency() if not res.success: print("computation of max. efficiency failed for id={}".format(id_num)) continue I_for_max_efficiency = res.x max_efficiency = -res.fun num_eval_for_max_efficiency = res.nfev # test the validity Carnot_efficiency = (Th - Tc) / Th * 100 assert (max_efficiency < Carnot_efficiency) print("\tmax. power density= {} [W/cm^2] at I= {} [A] (nfev={})".format(max_power_density, I_for_max_power_density, num_eval_for_max_power_density)) print("\tmax. efficiency= {} [%] at I= {} [A] (nfev={})".format(max_efficiency, I_for_max_efficiency, num_eval_for_max_efficiency)) # save the result result_df.loc[id_num] = [max_zT, T_for_max_zT, max_power_density, I_for_max_power_density, max_efficiency, I_for_max_efficiency, num_Seebeck_samples, num_elec_resi_samples, num_thrm_cond_samples, ] result_df = result_df.astype({"num_Seebeck_samples": "int32", "num_elec_resi_samples": "int32", "num_thrm_cond_samples": "int32"}) result_df.to_csv(result_filename)
"num_elec_resi_samples", "num_thrm_cond_samples", ] RESULT_FILENAME = os.path.join(RESULT_DIR, "performance_exact.csv") print("Performance for exact curves (splines); File = {}".format( RESULT_FILENAME)) info_df = pd.read_csv(INFO_FILENAME, index_col=0) result_df = pd.DataFrame(columns=RESULT_COLUMNS) result_df.index.name = 'id' for id_num in info_df.index: print("processing id={}...".format(id_num)) mat = TEProp(db_filename=DB_FILENAME, id_num=id_num) Tc = mat.min_raw_T Th = mat.max_raw_T Seebeck_xy_data = np.asarray(mat.Seebeck.raw_data()) elec_resi_xy_data = np.asarray(mat.elec_resi.raw_data()) thrm_cond_xy_data = np.asarray(mat.thrm_cond.raw_data()) # make unique on temperature _, Seebeck_unique_indices = np.unique(Seebeck_xy_data[:, 0], return_index=True) Seebeck_xy_data = Seebeck_xy_data[Seebeck_unique_indices, :] _, elec_resi_unique_indices = np.unique(elec_resi_xy_data[:, 0], return_index=True) elec_resi_xy_data = elec_resi_xy_data[elec_resi_unique_indices, :] _, thrm_cond_unique_indices = np.unique(thrm_cond_xy_data[:, 0],