Skip to content

Commit

Permalink
Merge pull request #69 from upb-lea/core_loss_split
Browse files Browse the repository at this point in the history
Make sure that update_spacial_data runs before every simulation.
  • Loading branch information
gituser789 authored Nov 27, 2023
2 parents b652fc5 + 8cc740a commit 9d6ad0f
Show file tree
Hide file tree
Showing 30 changed files with 2,022 additions and 665 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,32 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: check linting using pycodestyle
run: |
pip install pycodestyle
# code
pycodestyle femmt/constants.py
pycodestyle femmt/logparser.py
pycodestyle femmt/enumerations.py
pycodestyle femmt/dtos.py
# example files
pycodestyle femmt/examples/advanced_inductor_sweep.py
pycodestyle femmt/examples/advanced_sto.py
pycodestyle femmt/examples/basic_inductor.py
pycodestyle femmt/examples/basic_inductor_foil_vertical.py
pycodestyle femmt/examples/basic_transformer.py
pycodestyle femmt/examples/basic_transformer_5_windings.py
pycodestyle femmt/examples/basic_transformer_center_tapped.py
pycodestyle femmt/examples/basic_transformer_integrated.py
pycodestyle femmt/examples/basic_transformer_interleaved.py
pycodestyle femmt/examples/basic_transformer_n_winding.py
pycodestyle femmt/examples/basic_transformer_stacked.py
pycodestyle femmt/examples/basic_transformer_stacked_center_tapped.py
pycodestyle femmt/examples/basic_transformer_three_winding.py
pycodestyle tests/integration/test_femmt.py
- name: install femmt package
run: |
sudo apt-get update
Expand Down
1 change: 0 additions & 1 deletion femmt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@
from femmt.functions_model import *
from femmt.functions_topologies import *
from femmt.hpc import *
from femmt.examples import *
66 changes: 23 additions & 43 deletions femmt/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ def __init__(self, component_type: ComponentType = ComponentType.Inductor, worki
:type component_type: ComponentType
:param working_directory: Sets the working directory
:type working_directory: string
:param silent: True to reduce onelab simulation outputs in command line. False to see full command line output.
:type silent: bool
:param is_gui: Asks at first startup for onelab-path. Distinction between GUI and command line. Defaults to 'False' in command-line-mode.
:type is_gui: bool
:param simulation_name: name without any effect. Will just be displayed in the result-log file
Expand Down Expand Up @@ -365,6 +363,9 @@ def high_level_geo_gen(self, frequency: float = None, skin_mesh_factor: float =
:param skin_mesh_factor: Used in the mesh density, defaults to None
:type skin_mesh_factor: float, optional
"""
# Default values for global_accuracy and padding
self.mesh_data.update_spatial_data(self.core.core_inner_diameter, self.core.window_w, self.windings)

# Update mesh data
self.mesh_data.update_data(frequency, skin_mesh_factor)

Expand Down Expand Up @@ -435,8 +436,6 @@ def set_winding_windows(self, winding_windows: List[WindingWindow]):
:param winding_windows: List of WindingWindow objects
:type winding_windows: List[WindingWindow]
:param mesh_accuracy: a mesh_accuracy of 0.5 is recommended. Do not change this parameter, except performing thousands of simulations, e.g. a Pareto optimization. In this case, the value can be set e.g. to 0.8
:type mesh_accuracy: float
"""
self.winding_windows = winding_windows
windings = []
Expand Down Expand Up @@ -480,8 +479,6 @@ def set_winding_windows(self, winding_windows: List[WindingWindow]):
for i in range(0, zeros_to_append):
vww.turns.append(0)

# Default values for global_accuracy and padding
self.mesh_data.update_spatial_data(self.core.core_inner_diameter, self.core.window_w, self.windings)

def set_core(self, core: Core):
"""Adds the core to the model
Expand Down Expand Up @@ -639,9 +636,9 @@ def calculate_core_volume(self) -> float:
width = 0

if leg_position == AirGapLegPosition.LeftLeg.value:
# left leg
# TODO this is wrong since the air gap is not centered on the y axis
width = core_width - self.core.r_inner
# left leg
# TODO this is wrong since the air gap is not centered on the y axis
width = core_width - self.core.r_inner
elif leg_position == AirGapLegPosition.CenterLeg.value:
# center leg
width = inner_leg_width
Expand Down Expand Up @@ -694,7 +691,6 @@ def get_width(part_number):

# For single core and more than one core_part, volume for every core part is calculated


# core_part_1 is divided into subparts cores
# # subpart1: bottom left subpart
subpart1_1_height = bottommost_airgap_position + self.core.window_h / 2 - bottommost_airgap_height / 2
Expand All @@ -706,14 +702,13 @@ def get_width(part_number):
subpart1_2_width = self.core.r_outer
subpart1_2_volume = np.pi * subpart1_2_width ** 2 * subpart1_2_height


# subpart3: right subpart
subpart1_3_height = self.core.window_h
subpart1_3_width = self.core.r_outer
subpart1_3_volume = np.pi * subpart1_3_width ** 2 * subpart1_3_height - (
np.pi * (self.core.window_w + self.core.core_inner_diameter / 2) ** 2 * self.core.window_h)

# subpart4: top mid subpart
# subpart4: top mid-subpart
subpart1_4_height = self.core.core_inner_diameter / 4
subpart1_4_width = self.core.r_outer
subpart1_4_volume = np.pi * subpart1_4_width ** 2 * subpart1_4_height
Expand Down Expand Up @@ -749,7 +744,7 @@ def get_width(part_number):
# For stacked core types, the volume is divided into different core * parts, each of which is further
# divided into subparts to calculate the total volume of each core part.

# core_part_2 : core part between the bottom airgap and subpart_1 of core_part_1
# core_part_2 : core part between the bottom air gap and subpart_1 of core_part_1
core_part_1_height = self.core.window_h_bot / 2 - heights[0] / 2
core_part_1_width = self.core.core_inner_diameter / 2
core_part_1_volume = np.pi * core_part_1_width ** 2 * core_part_1_height
Expand Down Expand Up @@ -844,8 +839,6 @@ def calculate_core_weight(self) -> float:
return self.calculate_core_volume() * volumetric_mass_density




def get_wire_distances(self) -> List[List[float]]:
"""Helper function which returns the distance (radius) of each conductor to the y-axis
Expand Down Expand Up @@ -878,14 +871,6 @@ def get_wire_distances(self) -> List[List[float]]:
return wire_distance










def calculate_wire_lengths(self) -> List[float]:
distances = self.get_wire_distances()
lengths = []
Expand Down Expand Up @@ -1309,14 +1294,14 @@ def excitation_sweep(self, frequency_list: List, current_list_list: List, phi_de
save_png=save_png)
self.mesh.generate_electro_magnetic_mesh()

check_model_mqs_condition_already_performerd = False
check_model_mqs_condition_already_performed = False
for count_frequency, value_frequency in enumerate(range(0, len(frequency_list))):
self.excitation(frequency=frequency_list[count_frequency],
amplitude_list=current_list_list[count_frequency],
phase_deg_list=phi_deg_list_list[count_frequency]) # frequency and current
if value_frequency != 0 and not check_model_mqs_condition_already_performerd:
if value_frequency != 0 and not check_model_mqs_condition_already_performed:
self.check_model_mqs_condition()
check_model_mqs_condition_already_performerd = True
check_model_mqs_condition_already_performed = True
self.write_simulation_parameters_to_pro_files()
self.generate_load_litz_approximation_parameters()
self.simulate()
Expand Down Expand Up @@ -1378,7 +1363,8 @@ def component_study(self, time_current_vectors: List[List[List[float]]], fft_fil
# calculate hysteresis losses
# use a single simulation
self.generate_load_litz_approximation_parameters()
self.excitation(frequency=hyst_frequency, amplitude_list=hyst_loss_amplitudes, phase_deg_list=hyst_loss_phases_deg, plot_interpolation=False) # frequency and current
self.excitation(frequency=hyst_frequency, amplitude_list=hyst_loss_amplitudes,
phase_deg_list=hyst_loss_phases_deg, plot_interpolation=False) # frequency and current
self.check_model_mqs_condition()
self.write_simulation_parameters_to_pro_files()
self.generate_load_litz_approximation_parameters()
Expand Down Expand Up @@ -1785,7 +1771,7 @@ def get_inductances(self, I0: float, op_frequency: float = 0, skin_mesh_factor:
# l_h = self.M * n
# self.femmt_print(f"\n"
# f"T-ECD (primary side transformed):\n"
# f"[Underdetermined System: 'Transformation Ratio' := 'Turns Ratio']\n"
# f"[Under-determined System: 'Transformation Ratio' := 'Turns Ratio']\n"
# f" - Transformation Ratio: n\n"
# f" - Primary Side Stray Inductance: L_s1\n"
# f" - Secondary Side Stray Inductance: L_s2\n"
Expand All @@ -1803,7 +1789,7 @@ def get_inductances(self, I0: float, op_frequency: float = 0, skin_mesh_factor:

self.femmt_print(f"\n"
f"T-ECD (primary side concentrated):\n"
f"[Underdetermined System: n := M / L_2_2 --> L_s2 = L_2_2 - M / n = 0]\n"
f"[Under-determined System: n := M / L_2_2 --> L_s2 = L_2_2 - M / n = 0]\n"
f" - Transformation Ratio: n\n"
f" - (Primary) Stray Inductance: L_s1\n"
f" - Primary Side Main Inductance: L_h\n"
Expand Down Expand Up @@ -3458,24 +3444,22 @@ def decode_settings_from_log(log_file_path: str, working_directory: str = None,

settings["core"]["loss_approach"] = LossApproach[settings["core"]["loss_approach"]]
core_type = settings["core"]["core_type"]
#print(core_type)
if core_type == CoreType.Single:
core_dimensions = SingleCoreDimensions(core_inner_diameter=settings["core"]["core_inner_diameter"],
window_w=settings["core"]["window_w"],
window_h=settings["core"]["window_h"],
core_h=settings["core"]["core_h"])
window_w=settings["core"]["window_w"],
window_h=settings["core"]["window_h"],
core_h=settings["core"]["core_h"])

elif core_type == CoreType.Stacked:
core_dimensions = StackedCoreDimensions(core_inner_diameter=settings["core"]["core_inner_diameter"],
window_w=settings["core"]["window_w"],
window_h_bot=settings["core"]["window_h_bot"],
window_h_top=settings["core"]["window_h_top"])
#ToDo: core_h not implemented yet.
#core_h=settings["core"]["core_h"])
window_w=settings["core"]["window_w"],
window_h_bot=settings["core"]["window_h_bot"],
window_h_top=settings["core"]["window_h_top"])
# ToDo: core_h not implemented yet.
# core_h=settings["core"]["core_h"])
else:
raise ValueError("unknown core_type for decoding from result_log.")


if isinstance(settings["core"]["sigma"], List):
# in case of sigma is a complex number, it is given as a list and needs to translated to complex.
settings["core"]["sigma"] = complex(settings["core"]["sigma"][0], settings["core"]["sigma"][1])
Expand Down Expand Up @@ -3561,7 +3545,3 @@ def decode_settings_from_log(log_file_path: str, working_directory: str = None,
return geo

raise Exception(f"Couldn't extract settings from file {log_file_path}")




21 changes: 12 additions & 9 deletions femmt/dtos.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from dataclasses import dataclass
from femmt.enumerations import *
from typing import Optional


@dataclass
Expand All @@ -21,10 +22,10 @@ class StackedCoreDimensions:
@dataclass
class ConductorRow:
number_of_conds_per_winding: int
number_of_conds_per_row: int
row_height: float
number_of_conds_per_row: Optional[int]
row_height: Optional[float]
winding_tag: WindingTag
number_of_rows: int
number_of_rows: Optional[int]
additional_bobbin: float


Expand All @@ -43,17 +44,17 @@ class ThreeWindingIsolation:

@dataclass
class CenterTappedGroup:
primary_number_of_rows: int
secondary_number_of_rows: int
primary_rest: int
secondary_rest: int
primary_number_of_rows: Optional[int]
secondary_number_of_rows: Optional[int]
primary_rest: Optional[int]
secondary_rest: Optional[int]
stack: [WindingTag]


@dataclass
class ConductorStack:
number_of_groups: int
number_of_single_rows: int
number_of_single_rows: Optional[int]
order: [int]


Expand All @@ -71,6 +72,7 @@ class WireMaterial:
thermal_conductivity: float
volumetric_mass_density: float


@dataclass
class TransformerInductance:
l_h_conc: float
Expand All @@ -80,6 +82,7 @@ class TransformerInductance:
L_1_1: float
L_2_2: float


@dataclass
class ThreeWindingTransformerInductance:
M_12: float
Expand All @@ -94,4 +97,4 @@ class ThreeWindingTransformerInductance:
n_23: float
L_s12: float
L_s13: float
L_s23: float
L_s23: float
Loading

0 comments on commit 9d6ad0f

Please sign in to comment.