diff --git a/femmt/optimization/io.py b/femmt/optimization/io.py index a1098625..03e095c0 100644 --- a/femmt/optimization/io.py +++ b/femmt/optimization/io.py @@ -889,33 +889,33 @@ def full_simulation(df_geometry: pd.DataFrame, current_waveform: List, inductor_ working_directory = os.path.join( target_and_fix_parameters.working_directories.fem_working_directory, f"process_{process_number}") - fem_input = FemInput( - # general parameters - working_directory=working_directory, - simulation_name='xx', - - # material and geometry parameters - material_name=df_geometry['params_material_name'][index], - litz_wire_name=df_geometry['params_litz_wire_name'][index], - core_inner_diameter=core_inner_diameter, - window_w=window_w, - window_h=df_geometry["params_window_h"][index], - air_gap_length=df_geometry['user_attrs_l_air_gap'][index], - turns=int(df_geometry['params_turns'][index].item()), - insulations=local_config.insulations, - - # data sources - material_data_sources=local_config.material_data_sources, - - # operating point conditions - temperature=local_config.temperature, - fundamental_frequency=target_and_fix_parameters.fundamental_frequency, - fft_frequency_list=target_and_fix_parameters.fft_frequency_list, - fft_amplitude_list=target_and_fix_parameters.fft_amplitude_list, - fft_phases_list=target_and_fix_parameters.fft_phases_list - ) - - fem_output = InductorOptimization.FemSimulation.single_fem_simulation(fem_input, False) + # fem_input = FemInput( + # # general parameters + # working_directory=working_directory, + # simulation_name='xx', + + # # material and geometry parameters + # material_name=df_geometry['params_material_name'][index], + # litz_wire_name=df_geometry['params_litz_wire_name'][index], + # core_inner_diameter=core_inner_diameter, + # window_w=window_w, + # window_h=df_geometry["params_window_h"][index], + # air_gap_length=df_geometry['user_attrs_l_air_gap'][index], + # turns=int(df_geometry['params_turns'][index].item()), + # insulations=local_config.insulations, + + # # data sources + # material_data_sources=local_config.material_data_sources, + + # # operating point conditions + # temperature=local_config.temperature, + # fundamental_frequency=target_and_fix_parameters.fundamental_frequency, + # fft_frequency_list=target_and_fix_parameters.fft_frequency_list, + # fft_amplitude_list=target_and_fix_parameters.fft_amplitude_list, + # fft_phases_list=target_and_fix_parameters.fft_phases_list + # ) + + # fem_output = InductorOptimization.FemSimulation.single_fem_simulation(fem_input, False) litz_wire = ff.litz_database()[df_geometry['params_litz_wire_name'][index]] litz_wire_diameter = 2 * litz_wire["conductor_radii"] @@ -951,23 +951,25 @@ def full_simulation(df_geometry: pd.DataFrame, current_waveform: List, inductor_ reluctance_output: ReluctanceModelOutput = InductorOptimization.ReluctanceModel.single_reluctance_model_simulation(reluctance_model_input) - p_core = reluctance_output.p_hyst + fem_output.fem_eddy_core + fem_output.fem_p_loss_winding - - if print_derivations: - print(f"Inductance reluctance: {local_config.target_inductance}") - print(f"Inductance FEM: {fem_output.fem_inductance}") - print(f"Inductance derivation: {(fem_output.fem_inductance - local_config.target_inductance) / local_config.target_inductance * 100} %") - print(f"Volume reluctance: {reluctance_output.volume}") - print(f"Volume FEM: {fem_output.volume}") - print(f"Volume derivation: {(reluctance_output.volume - fem_output.volume) / reluctance_output.volume * 100} %") - print(f"P_winding reluctance: {reluctance_output.p_winding}") - print(f"P_winding FEM: {fem_output.fem_p_loss_winding}") - print(f"P_winding derivation: {(fem_output.fem_p_loss_winding - reluctance_output.p_winding) / fem_output.fem_p_loss_winding * 100}") - print(f"P_hyst reluctance: {reluctance_output.p_hyst}") - print(f"P_hyst FEM: {fem_output.fem_core_total}") - print(f"P_hyst derivation: {(reluctance_output.p_hyst - fem_output.fem_core_total) / reluctance_output.p_hyst * 100}") - - return reluctance_output.volume, p_core, reluctance_output.area_to_heat_sink + # p_total = reluctance_output.p_hyst + fem_output.fem_eddy_core + fem_output.fem_p_loss_winding + # workaround + p_total = reluctance_output.p_loss_total + + # if print_derivations: + # print(f"Inductance reluctance: {local_config.target_inductance}") + # print(f"Inductance FEM: {fem_output.fem_inductance}") + # print(f"Inductance derivation: {(fem_output.fem_inductance - local_config.target_inductance) / local_config.target_inductance * 100} %") + # print(f"Volume reluctance: {reluctance_output.volume}") + # print(f"Volume FEM: {fem_output.volume}") + # print(f"Volume derivation: {(reluctance_output.volume - fem_output.volume) / reluctance_output.volume * 100} %") + # print(f"P_winding reluctance: {reluctance_output.p_winding}") + # print(f"P_winding FEM: {fem_output.fem_p_loss_winding}") + # print(f"P_winding derivation: {(fem_output.fem_p_loss_winding - reluctance_output.p_winding) / fem_output.fem_p_loss_winding * 100}") + # print(f"P_hyst reluctance: {reluctance_output.p_hyst}") + # print(f"P_hyst FEM: {fem_output.fem_core_total}") + # print(f"P_hyst derivation: {(reluctance_output.p_hyst - fem_output.fem_core_total) / reluctance_output.p_hyst * 100}") + + return reluctance_output.volume, p_total, reluctance_output.area_to_heat_sink @staticmethod def filter_combined_loss_list_df(df: pd.DataFrame, factor_min_dc_losses: float = 1.2, factor_max_dc_losses: float = 10) -> pd.DataFrame: diff --git a/femmt/optimization/sto.py b/femmt/optimization/sto.py index 117e3cf1..f67875ef 100644 --- a/femmt/optimization/sto.py +++ b/femmt/optimization/sto.py @@ -475,7 +475,7 @@ def single_reluctance_model_simulation(reluctance_input: ReluctanceModelInput) - p_winding_2 += proximity_factor_assumption_2 * secondary_resistance * reluctance_input.fft_amplitude_list_2[count] ** 2 - p_loss = p_hyst + p_winding_1_top + p_winding_1_bot + p_winding_2 + p_loss_total = p_hyst + p_winding_1_top + p_winding_1_bot + p_winding_2 area_to_heat_sink = r_outer ** 2 * np.pi @@ -494,7 +494,7 @@ def single_reluctance_model_simulation(reluctance_input: ReluctanceModelInput) - l_bot_air_gap=l_bot_air_gap, volume=volume, area_to_heat_sink=area_to_heat_sink, - p_loss=p_loss, + p_loss=p_loss_total, ) return reluctance_output @@ -1030,7 +1030,8 @@ def fem_logs_to_df(reluctance_df: pd.DataFrame, fem_results_folder_path: str) -> index = int(file.replace("case_", "").replace(".json", "")) reluctance_df.at[index, 'fem_inductance'] = scanned_log_dict['single_sweeps'][0]['winding1']['flux_over_current'][0] - reluctance_df.at[index, 'fem_p_loss_winding'] = scanned_log_dict['total_losses']['winding1']['total'] + reluctance_df.at[index, 'fem_p_loss_winding'] = ( + scanned_log_dict['total_losses']['winding1']['total'] + scanned_log_dict['total_losses']['winding2']['total']) reluctance_df.at[index, 'fem_eddy_core'] = scanned_log_dict['total_losses']['eddy_core'] reluctance_df.at[index, 'fem_core'] = scanned_log_dict['total_losses']['core'] @@ -1041,7 +1042,7 @@ def fem_logs_to_df(reluctance_df: pd.DataFrame, fem_results_folder_path: str) -> @staticmethod def full_simulation(df_geometry: pd.DataFrame, current_waveform: List, stacked_transformer_config_filepath: str, process_number: int = 1, - show_visual_outputs: bool = False): + show_visual_outputs: bool = False, print_derivations: bool = False): """ Reluctance model (hysteresis losses) and FEM simulation (winding losses and eddy current losses) for geometries from df_geometry. @@ -1055,6 +1056,8 @@ def full_simulation(df_geometry: pd.DataFrame, current_waveform: List, stacked_t :type process_number: int :param show_visual_outputs: True to show visual outpus (geometries) :type show_visual_outputs: bool + :param print_derivations: True to print derivation from FEM simulaton to reluctance model + :type print_derivations: bool """ for index, _ in df_geometry.iterrows(): @@ -1080,39 +1083,38 @@ def full_simulation(df_geometry: pd.DataFrame, current_waveform: List, stacked_t working_directory = os.path.join( target_and_fix_parameters.working_directories.fem_working_directory, f"process_{process_number}") - fem_input = FemInput( - # general parameters - working_directory=working_directory, - simulation_name="xx", - - # material and geometry parameters - material_name=df_geometry['params_material_name'][index], - primary_litz_wire_name=df_geometry['params_primary_litz_name'][index], - secondary_litz_wire_name=df_geometry['params_secondary_litz_name'][index], - core_inner_diameter=core_inner_diameter, - window_w=window_w, - window_h_top=df_geometry["user_attrs_window_h_top"][index].item(), - window_h_bot=df_geometry["params_window_h_bot"][index].item(), - air_gap_length_top=df_geometry["user_attrs_l_top_air_gap"][index].item(), - air_gap_length_bot=df_geometry["user_attrs_l_bot_air_gap"][index].item(), - turns_primary_top=int(df_geometry["params_n_p_top"][index].item()), - turns_primary_bot=int(df_geometry["params_n_p_bot"][index].item()), - turns_secondary_bot=int(df_geometry["params_n_s_bot"][index].item()), - insulations=local_config.insulations, - - # data sources - material_data_sources=local_config.material_data_sources, - - # operating point conditions - temperature=local_config.temperature, - fundamental_frequency=target_and_fix_parameters.fundamental_frequency, - time_current_1_vec=[list(target_and_fix_parameters.time_extracted_vec), list(target_and_fix_parameters.current_extracted_1_vec)], - time_current_2_vec=[list(target_and_fix_parameters.time_extracted_vec), list(target_and_fix_parameters.current_extracted_2_vec)] - ) - - pd.read_csv("~/Downloads/Pandas_trial.csv", header=0, index_col=0, delimiter=';') - - fem_output = StackedTransformerOptimization.FemSimulation.single_fem_simulation(fem_input, show_visual_outputs) + # fem_input = FemInput( + # # general parameters + # working_directory=working_directory, + # simulation_name="xx", + + # # material and geometry parameters + # material_name=df_geometry['params_material_name'][index], + # primary_litz_wire_name=df_geometry['params_primary_litz_name'][index], + # secondary_litz_wire_name=df_geometry['params_secondary_litz_name'][index], + # core_inner_diameter=core_inner_diameter, + # window_w=window_w, + # window_h_top=df_geometry["user_attrs_window_h_top"][index].item(), + # window_h_bot=df_geometry["params_window_h_bot"][index].item(), + # air_gap_length_top=df_geometry["user_attrs_l_top_air_gap"][index].item(), + # air_gap_length_bot=df_geometry["user_attrs_l_bot_air_gap"][index].item(), + # turns_primary_top=int(df_geometry["params_n_p_top"][index].item()), + # turns_primary_bot=int(df_geometry["params_n_p_bot"][index].item()), + # turns_secondary_bot=int(df_geometry["params_n_s_bot"][index].item()), + # insulations=local_config.insulations, + + # # data sources + # material_data_sources=local_config.material_data_sources, + + # # operating point conditions + # temperature=local_config.temperature, + # fundamental_frequency=target_and_fix_parameters.fundamental_frequency, + # time_current_1_vec=[list(target_and_fix_parameters.time_extracted_vec), list(target_and_fix_parameters.current_extracted_1_vec)], + # time_current_2_vec=[list(target_and_fix_parameters.time_extracted_vec), list(target_and_fix_parameters.current_extracted_2_vec)] + # ) + + # pd.read_csv("~/Downloads/Pandas_trial.csv", header=0, index_col=0, delimiter=';') + # fem_output = StackedTransformerOptimization.FemSimulation.single_fem_simulation(fem_input, show_visual_outputs) litz_wire_primary_dict = ff.litz_database()[df_geometry['params_primary_litz_name'][index]] litz_wire_diameter_primary = 2 * litz_wire_primary_dict["conductor_radii"] @@ -1172,27 +1174,29 @@ def full_simulation(df_geometry: pd.DataFrame, current_waveform: List, stacked_t reluctance_output: ReluctanceModelOutput = StackedTransformerOptimization.ReluctanceModel.single_reluctance_model_simulation( reluctance_model_input) - p_total = reluctance_output.p_hyst + fem_output.eddy_core + fem_output.p_loss_winding_1 + fem_output.p_loss_winding_2 - - print(f"Inductance l_h reluctance: {local_config.l_h_target}") - print(f"Inductance l_h FEM: {fem_output.l_h_conc}") - print(f"Inductance l_h derivation: {(fem_output.l_h_conc - local_config.l_h_target) / local_config.l_h_target * 100} %") - print(f"Inductance l_s reluctance: {local_config.l_s12_target}") - print(f"Inductance l_s FEM: {fem_output.l_s_conc}") - print(f"Inductance l_s derivation: {(fem_output.l_s_conc - local_config.l_s12_target) / local_config.l_s12_target * 100} %") - print(f"Volume reluctance: {reluctance_output.volume}") - print(f"Volume FEM: {fem_output.volume}") - print(f"Volume derivation: {(reluctance_output.volume - fem_output.volume) / reluctance_output.volume * 100} %") - - print(f"P_winding_both reluctance: {reluctance_output.winding_1_loss + reluctance_output.winding_2_loss}") - print(f"P_winding_both FEM: {fem_output.p_loss_winding_1 + fem_output.p_loss_winding_2}") - winding_derivation = ((fem_output.p_loss_winding_1 + fem_output.p_loss_winding_2 - \ - (reluctance_output.winding_1_loss + reluctance_output.winding_2_loss)) / \ - (fem_output.p_loss_winding_1 + fem_output.p_loss_winding_2) * 100) - print(f"P_winding_both derivation: " - f"{winding_derivation}") - print(f"P_hyst reluctance: {reluctance_output.p_hyst}") - print(f"P_hyst FEM: {fem_output.core}") - print(f"P_hyst derivation: {(reluctance_output.p_hyst - fem_output.core) / reluctance_output.p_hyst * 100}") + # p_total = reluctance_output.p_hyst + fem_output.eddy_core + fem_output.p_loss_winding_1 + fem_output.p_loss_winding_2 + p_total = reluctance_output.p_loss + + # if print_derivations: + # print(f"Inductance l_h reluctance: {local_config.l_h_target}") + # print(f"Inductance l_h FEM: {fem_output.l_h_conc}") + # print(f"Inductance l_h derivation: {(fem_output.l_h_conc - local_config.l_h_target) / local_config.l_h_target * 100} %") + # print(f"Inductance l_s reluctance: {local_config.l_s12_target}") + # print(f"Inductance l_s FEM: {fem_output.l_s_conc}") + # print(f"Inductance l_s derivation: {(fem_output.l_s_conc - local_config.l_s12_target) / local_config.l_s12_target * 100} %") + # print(f"Volume reluctance: {reluctance_output.volume}") + # print(f"Volume FEM: {fem_output.volume}") + # print(f"Volume derivation: {(reluctance_output.volume - fem_output.volume) / reluctance_output.volume * 100} %") + + # print(f"P_winding_both reluctance: {reluctance_output.winding_1_loss + reluctance_output.winding_2_loss}") + # print(f"P_winding_both FEM: {fem_output.p_loss_winding_1 + fem_output.p_loss_winding_2}") + # winding_derivation = ((fem_output.p_loss_winding_1 + fem_output.p_loss_winding_2 - \ + # (reluctance_output.winding_1_loss + reluctance_output.winding_2_loss)) / \ + # (fem_output.p_loss_winding_1 + fem_output.p_loss_winding_2) * 100) + # print(f"P_winding_both derivation: " + # f"{winding_derivation}") + # print(f"P_hyst reluctance: {reluctance_output.p_hyst}") + # print(f"P_hyst FEM: {fem_output.core}") + # print(f"P_hyst derivation: {(reluctance_output.p_hyst - fem_output.core) / reluctance_output.p_hyst * 100}") return reluctance_output.volume, p_total, reluctance_output.area_to_heat_sink