Skip to content

Commit

Permalink
Merge pull request #108 from upb-lea/stacked_core_study
Browse files Browse the repository at this point in the history
pycodestyle python 3.12 update
  • Loading branch information
gituser789 authored May 17, 2024
2 parents 975a761 + 1f077cc commit 0b68937
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 70 deletions.
12 changes: 6 additions & 6 deletions femmt/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ def get_single_complex_permeability(self):
complex_permeability = mu_0 * mdb.MaterialDatabase(
self.verbosity == Verbosity.Silent).get_material_attribute(material_name=self.core.material,
attribute="initial_permeability")
self.femmt_print(f"{complex_permeability = }")
self.femmt_print(f"{complex_permeability=}")
if self.core.permeability_type == PermeabilityType.FixedLossAngle:
complex_permeability = mu_0 * self.core.mu_r_abs * complex(np.cos(np.deg2rad(self.core.phi_mu_deg)),
np.sin(np.deg2rad(self.core.phi_mu_deg)))
Expand Down Expand Up @@ -613,9 +613,9 @@ def check_model_mqs_condition(self) -> None:

complex_permittivity = epsilon_0 * epsilon_r * complex(np.cos(np.deg2rad(epsilon_phi_deg)),
np.sin(np.deg2rad(epsilon_phi_deg)))
self.femmt_print(f"{complex_permittivity = }\n"
f"{epsilon_r = }\n"
f"{epsilon_phi_deg = }")
self.femmt_print(f"{complex_permittivity=}\n"
f"{epsilon_r=}\n"
f"{epsilon_phi_deg=}")

ff.check_mqs_condition(radius=self.core.core_inner_diameter / 2, frequency=self.frequency,
complex_permeability=self.get_single_complex_permeability(),
Expand Down Expand Up @@ -1120,8 +1120,8 @@ def excitation_time_domain(self, current_list: List[List[float]], time_list: Lis
self.initial_time = 0 # defined 0
self.step_time = time_list[1] # convention!!! for fixed time steps
self.time_period = time_list[-1]
print(f"{1/self.frequency = }")
print(f"{time_list[-1] = }")
print(f"{1/self.frequency=}")
print(f"{time_list[-1]=}")
self.nb_steps_per_period = len(time_list)
self.max_time = number_of_periods * (self.time_period + self.step_time)
# current excitation
Expand Down
4 changes: 2 additions & 2 deletions femmt/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,8 +1236,8 @@ def check_number_of_drawn_conductors(self):
drawn_number_of_turns += int(self.p_conductor[winding.winding_number].shape[0] / 5) # rectangular conductors

if drawn_number_of_turns != needed_number_of_turns:
self.femmt_print(f"{drawn_number_of_turns = }")
self.femmt_print(f"{needed_number_of_turns = }")
self.femmt_print(f"{drawn_number_of_turns=}")
self.femmt_print(f"{needed_number_of_turns=}")
raise Exception("Winding mismatch. Probably too many turns that do not fit in the winding window")

def draw_region_single(self):
Expand Down
16 changes: 8 additions & 8 deletions femmt/examples/inductor_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def load_fem_simulation_results(working_directory: str):
labels = []
fem_simulation_results_directory = os.path.join(working_directory, 'fem_simulation_results')
print("##########################")
print(f"{fem_simulation_results_directory =}")
print(f"{fem_simulation_results_directory=}")
print("##########################")
file_names = [f for f in os.listdir(fem_simulation_results_directory) if os.path.isfile(os.path.join(fem_simulation_results_directory, f))]

Expand Down Expand Up @@ -882,7 +882,7 @@ def pareto_front_from_data_matrix(self, data_matrix):
x_pareto_vec.append(core_2daxi_total_volume_vec[count_mask])
y_pareto_vec.append(total_loss_vec[count_mask])

print(f"{len(x_pareto_vec) = }")
print(f"{len(x_pareto_vec)=}")

vector_to_sort = np.array([x_pareto_vec, y_pareto_vec])

Expand All @@ -900,11 +900,11 @@ def filter_reluctance_pareto_front_tolerance(self, data_matrix, factor_min_dc_lo
total_volume_vec = data_matrix[:, self.param["total_volume"]]

min_total_loss = np.min(total_loss_vec)
print(f"{min_total_loss = }")
print(f"{min_total_loss=}")

pareto_x_vec, pareto_y_vec = self.pareto_front_from_data_matrix(data_matrix)
print(f"{pareto_x_vec = }")
print(f"{pareto_y_vec = }")
print(f"{pareto_x_vec=}")
print(f"{pareto_y_vec=}")

loss_offset = factor_min_dc_losses * min_total_loss

Expand Down Expand Up @@ -1021,9 +1021,9 @@ def fem_simulation(self):
time_difference_seconds = end_time - start_time
time_difference_minutes = time_difference_seconds / 60
time_difference_hours = time_difference_minutes / 60
print(f"{time_difference_seconds = }")
print(f"{time_difference_minutes = }")
print(f"{time_difference_hours = }")
print(f"{time_difference_seconds=}")
print(f"{time_difference_minutes=}")
print(f"{time_difference_hours=}")

except Exception as e:
print(f"next iteration due to {e}")
Expand Down
18 changes: 9 additions & 9 deletions femmt/examples/ito_brute_force_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@
elif task == 'load_reluctance_and_filter':
# load all calculated and valid reluctance model calculations
valid_reluctance_model_designs = fmt.IntegratedTransformerOptimization.ReluctanceModel.load_unfiltered_results(dab_transformer_config.working_directory)
print(f"{len(valid_reluctance_model_designs) = }")
print(f"{len(valid_reluctance_model_designs)=}")

# filter air gaps
filtered_air_gaps_dto_list = fmt.IntegratedTransformerOptimization.ReluctanceModel.filter_min_air_gap_length(valid_reluctance_model_designs)
print(f"{len(filtered_air_gaps_dto_list) = }")
print(f"{len(filtered_air_gaps_dto_list)=}")

# filter for Pareto front
pareto_reluctance_dto_list = fmt.IntegratedTransformerOptimization.ReluctanceModel.filter_loss_list(filtered_air_gaps_dto_list, factor_min_dc_losses=0.5)
print(f"{len(pareto_reluctance_dto_list) = }")
print(f"{len(pareto_reluctance_dto_list)=}")

# save results
fmt.IntegratedTransformerOptimization.ReluctanceModel.save_dto_list(pareto_reluctance_dto_list, os.path.join(dab_transformer_config.working_directory,
Expand All @@ -79,7 +79,7 @@

# load filtered reluctance models
pareto_reluctance_dto_list = fmt.IntegratedTransformerOptimization.ReluctanceModel.load_filtered_results(dab_transformer_config.working_directory)
print(f"{len(pareto_reluctance_dto_list) = }")
print(f"{len(pareto_reluctance_dto_list)=}")

# start FEM simulation
fmt.IntegratedTransformerOptimization.FemSimulation.simulate(config_dto=dab_transformer_config,
Expand All @@ -89,14 +89,14 @@

# load unfiltered results
unfiltered_fem_results = fmt.IntegratedTransformerOptimization.FemSimulation.load_unfiltered_results(dab_transformer_config.working_directory)
print(f"{len(unfiltered_fem_results) = }")
print(f"{len(unfiltered_fem_results)=}")

# plot unfiltered results
fmt.IntegratedTransformerOptimization.FemSimulation.plot(unfiltered_fem_results)

# filter results
filtered_fem_results = fmt.IntegratedTransformerOptimization.FemSimulation.filter_loss_list(unfiltered_fem_results, factor_min_dc_losses=0.1)
print(f"{len(filtered_fem_results) = }")
print(f"{len(filtered_fem_results)=}")

# save filtered results
# fmt.IntegratedTransformerOptimization.FemSimulation.save_filtered_results(filtered_fem_results, dab_transformer_config.working_directory)
Expand All @@ -116,11 +116,11 @@
# load thermal simulation results
unfiltered_thermal_fem_results = fmt.IntegratedTransformerOptimization.ThermalSimulation.load_unfiltered_simulations(
dab_transformer_config.working_directory)
print(f"{len(unfiltered_thermal_fem_results) = }")
print(f"{len(unfiltered_thermal_fem_results)=}")

# filter thermal FEM simulations
filtered_thermal_fem_results = fmt.IntegratedTransformerOptimization.ThermalSimulation.filter_max_temperature(unfiltered_thermal_fem_results, 125, 125)
print(f"{len(filtered_thermal_fem_results) = }")
print(f"{len(filtered_thermal_fem_results)=}")

# load filtered FEM simulation results
unfiltered_fem_simulation_results = fmt.IntegratedTransformerOptimization.FemSimulation.load_unfiltered_results(
Expand All @@ -131,7 +131,7 @@
# to be removed in loss vs. volume plane.
valid_thermal_simulations = fmt.IntegratedTransformerOptimization.ThermalSimulation.find_common_cases(
unfiltered_fem_simulation_results, filtered_thermal_fem_results)
print(f"{len(valid_thermal_simulations) = }")
print(f"{len(valid_thermal_simulations)=}")

# plot all thermal simulation results, and plot
fmt.IntegratedTransformerOptimization.FemSimulation.plot(unfiltered_thermal_fem_results)
Expand Down
10 changes: 5 additions & 5 deletions femmt/examples/ito_optuna_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@
elif task == 'filter_reluctance_model':
# load trials from reluctance model
reluctance_result_list = fmt.IntegratedTransformerOptimization.ReluctanceModel.NSGAII.load_study_to_dto(study_name, dab_transformer_config)
print(f"{len(reluctance_result_list) = }")
print(f"{len(reluctance_result_list)=}")

# filter air gaps
filtered_air_gaps_dto_list = fmt.IntegratedTransformerOptimization.ReluctanceModel.filter_min_air_gap_length(reluctance_result_list)
print(f"{len(filtered_air_gaps_dto_list) = }")
print(f"{len(filtered_air_gaps_dto_list)=}")

# filter for Pareto front
pareto_reluctance_dto_list = fmt.IntegratedTransformerOptimization.ReluctanceModel.filter_loss_list(
filtered_air_gaps_dto_list, factor_min_dc_losses=0.5)
print(f"{len(pareto_reluctance_dto_list) = }")
print(f"{len(pareto_reluctance_dto_list)=}")

fmt.IntegratedTransformerOptimization.plot(reluctance_result_list)
fmt.IntegratedTransformerOptimization.plot(pareto_reluctance_dto_list)
Expand All @@ -77,7 +77,7 @@
elif task == 'fem_simulation_from_filtered_reluctance_model_results':
# load filtered reluctance models
pareto_reluctance_dto_list = fmt.IntegratedTransformerOptimization.ReluctanceModel.load_filtered_results(dab_transformer_config.working_directory)
print(f"{len(pareto_reluctance_dto_list) = }")
print(f"{len(pareto_reluctance_dto_list)=}")

# start FEM simulation
fmt.IntegratedTransformerOptimization.FemSimulation.simulate(config_dto=dab_transformer_config,
Expand All @@ -89,4 +89,4 @@
time_stop = datetime.datetime.now()

time_difference = time_stop - time_start
print(f"{time_difference = }")
print(f"{time_difference=}")
14 changes: 7 additions & 7 deletions femmt/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,11 +755,11 @@ def fft(period_vector_t_i: npt.ArrayLike, sample_factor: int = 1000, plot: str =
f"filter_type '{filter_value_harmonic}' not available: Must be 'factor','harmonic' or 'disabled ")

if plot != 'no' and plot is not False:
print(f"{title = }")
print(f"{t[-1] = }")
print(f"{f0 = }")
print(f"{Fs = }")
print(f"{sample_factor = }")
print(f"{title=}")
print(f"{t[-1]=}")
print(f"{f0=}")
print(f"{Fs=}")
print(f"{sample_factor=}")
print(f"f_out = {np.around(f_out, decimals=0)}")
print(f"x_out = {np.around(x_out, decimals=3)}")
print(f"phi_rad_out = {np.around(phi_rad_out, decimals=3)}")
Expand Down Expand Up @@ -977,9 +977,9 @@ def find_common_frequencies(frequency_list_1: List, amplitude_list_1: List, phas
common_phases_list_2 = []

common_frequency_list = list(set(frequency_list_1).intersection(frequency_list_2))
print(f"{common_frequency_list = }")
print(f"{common_frequency_list=}")
common_frequency_list.sort()
print(f"{common_frequency_list = }")
print(f"{common_frequency_list=}")

# Delete the corresponding phases and amplitudes
if isinstance(amplitude_list_1, List):
Expand Down
14 changes: 7 additions & 7 deletions femmt/functions_reluctance.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,12 +542,12 @@ def r_air_gap_round_round(air_gap_total_height, core_inner_diameter, core_height
sigma = sigma_round(r_equivalent_round_round, air_gap_radius, air_gap_total_height)
if np.any(sigma > 1):
raise Exception(f"Failure in calculating reluctance. Sigma was calculated to >1. Check input parameters!\n"
f"\t{air_gap_total_height = }\n"
f"\t{core_inner_diameter = }\n"
f"\t{core_height_upper = }\n"
f"\t{core_height_lower = }\n"
f"\t{r_equivalent_round_round = }\n"
f"\t{air_gap_radius = }")
f"\t{air_gap_total_height=}\n"
f"\t{core_inner_diameter=}\n"
f"\t{core_height_upper=}\n"
f"\t{core_height_lower=}\n"
f"\t{r_equivalent_round_round=}\n"
f"\t{air_gap_radius=}")

r_air_gap_ideal = air_gap_total_height / mu_0 / np.pi / (air_gap_radius ** 2)
r_air_gap = sigma ** 2 * r_air_gap_ideal
Expand Down Expand Up @@ -612,7 +612,7 @@ def r_basic_tablet_cyl(tablet_height, air_gap_basic_height, tablet_radius):
:return: basic reluctance for tablet - cylinder structure
"""
if air_gap_basic_height == 0:
raise ZeroDivisionError(f"Division by zero: {air_gap_basic_height = }")
raise ZeroDivisionError(f"Division by zero: {air_gap_basic_height=}")

conductance_basic = mu_0 * (tablet_height / 2 / air_gap_basic_height + 2 / \
np.pi * (1 + np.log(np.pi * tablet_radius / 4 / air_gap_basic_height)))
Expand Down
2 changes: 1 addition & 1 deletion femmt/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def update_sigma(self, frequency: bool) -> None:
def update_core_material_pro_file(self, frequency, electro_magnetic_folder, plot_interpolation: bool = False):
"""Update the pro file for the solver depending on the frequency of the upcoming simulation."""
if self.mdb_verbosity == Verbosity.ToConsole:
print(f"{self.permeability['datasource'] = }")
print(f"{self.permeability['datasource']=}")
self.material_database.permeability_data_to_pro_file(temperature=self.temperature, frequency=frequency,
material_name=self.material,
datasource=self.permeability["datasource"],
Expand Down
4 changes: 2 additions & 2 deletions femmt/optimization/functions_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def pareto_front_from_dtos(dto_list: List[ItoSingleResultFile]) -> tuple:
x_pareto_vec.append(x_vec[count_mask])
y_pareto_vec.append(y_vec[count_mask])

print(f"{len(x_pareto_vec) = }")
print(f"{len(x_pareto_vec)=}")

return np.array(x_pareto_vec), np.array(y_pareto_vec)

Expand Down Expand Up @@ -220,6 +220,6 @@ def pareto_front_from_result_dicts(result_dict_list: List[Dict]) -> tuple:
x_pareto_vec.append(x_vec[count_mask])
y_pareto_vec.append(y_vec[count_mask])

print(f"{len(x_pareto_vec) = }")
print(f"{len(x_pareto_vec)=}")

return np.array(x_pareto_vec), np.array(y_pareto_vec)
4 changes: 2 additions & 2 deletions femmt/optimization/ito.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def brute_force_calculation(config_file: ItoSingleInputConfig):
time_extracted, current_extracted_2_vec = fr.time_vec_current_vec_from_time_current_vec(
sweep_dto.time_current_2_vec)
fundamental_frequency = np.around(1 / time_extracted[-1], decimals=0)
print(f"{fundamental_frequency = }")
print(f"{fundamental_frequency=}")

i_rms_1 = fr.i_rms(sweep_dto.time_current_1_vec)
i_rms_2 = fr.i_rms(sweep_dto.time_current_2_vec)
Expand Down Expand Up @@ -271,7 +271,7 @@ def brute_force_calculation(config_file: ItoSingleInputConfig):
# print(f"{simulation_progress_percent} simulation_progress_percent")
# geometry_simulation_counter += 1
simulation_progress_percent = count_geometry / number_of_geometry_simulations * 100
print(f"{simulation_progress_percent = } %")
print(f"{simulation_progress_percent=} %")

# print(geometry_simulation_counter)

Expand Down
Loading

0 comments on commit 0b68937

Please sign in to comment.