Skip to content

Commit

Permalink
workaround for fast full_simulations
Browse files Browse the repository at this point in the history
  • Loading branch information
gituser789 committed Oct 10, 2024
1 parent 326228d commit eb234e4
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 103 deletions.
90 changes: 46 additions & 44 deletions femmt/optimization/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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:
Expand Down
122 changes: 63 additions & 59 deletions femmt/optimization/sto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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']

Expand All @@ -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.
Expand All @@ -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():

Expand All @@ -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"]
Expand Down Expand Up @@ -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

0 comments on commit eb234e4

Please sign in to comment.