Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix load_from_file() for inductor and transformer, update tests accordingly #59

Merged
merged 4 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 42 additions & 13 deletions femmt/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -3341,7 +3341,7 @@ def encode_settings(o) -> Dict:
return content

@staticmethod
def decode_settings_from_log(log_file_path: str, working_directory: str = None, silent: bool = False):
def decode_settings_from_log(log_file_path: str, working_directory: str = None, verbosity: bool = False):
"""
Reads the given log and returns the magnetic component from th elog.

Expand All @@ -3364,12 +3364,43 @@ def decode_settings_from_log(log_file_path: str, working_directory: str = None,

if settings is not None:
cwd = working_directory if working_directory is not None else settings["working_directory"]
geo = MagneticComponent(component_type=ComponentType[settings["component_type"]], working_directory=cwd)
geo = MagneticComponent(component_type=ComponentType[settings["component_type"]], working_directory=cwd,
verbosity = 2)

settings["core"]["loss_approach"] = LossApproach[settings["core"]["loss_approach"]]
core_dimensions = SingleCoreDimensions(core_inner_diameter=settings["core"]["core_inner_diameter"],
window_w=settings["core"]["window_w"],
window_h=settings["core"]["window_h"])
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"])

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"])
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])

if settings["core"]["material"] != 'custom':
# a custom core does not need a material, measurement_setup and _datatype
settings["core"]["material"] = Material(settings["core"]["material"])
settings["core"]["permeability_measurement_setup"] = MeasurementSetup(settings["core"]["permeability_measurement_setup"])
settings["core"]["permeability_datatype"] = MeasurementDataType(settings["core"]["permeability_datatype"])
settings["core"]["permittivity_measurement_setup"] = MeasurementSetup(settings["core"]["permittivity_measurement_setup"])
settings["core"]["permittivity_datatype"] = MeasurementDataType(settings["core"]["permittivity_datatype"])

settings["core"]["permeability_datasource"] = MaterialDataSource(settings["core"]["permeability_datasource"])
settings["core"]["permittivity_datasource"] = MaterialDataSource(settings["core"]["permittivity_datasource"])

core = Core(core_dimensions=core_dimensions, **settings["core"])
geo.set_core(core)
Expand All @@ -3384,8 +3415,7 @@ def decode_settings_from_log(log_file_path: str, working_directory: str = None,
if "insulation" in settings:
insulation = Insulation()
insulation.add_core_insulations(*settings["insulation"]["core_insulations"])
insulation.add_winding_insulations(settings["insulation"]["inner_winding_insulations"],
settings["insulation"]["vww_insulation"])
insulation.add_winding_insulations(settings["insulation"]["inner_winding_insulations"])
geo.set_insulation(insulation)

if "stray_path" in settings:
Expand All @@ -3400,6 +3430,7 @@ def decode_settings_from_log(log_file_path: str, working_directory: str = None,
turns = vww["turns"]
conductors = []
for winding in vww["windings"]:
winding_number = winding["winding_number"]
conductor = Conductor(winding["winding_number"], Conductivity[winding["conductivity"]])
conductor_type = ConductorType[winding["conductor_type"]]
if conductor_type == ConductorType.RectangularSolid:
Expand All @@ -3421,10 +3452,11 @@ def decode_settings_from_log(log_file_path: str, working_directory: str = None,
vww["right_bound"])
winding_type = WindingType[vww["winding_type"]]
if winding_type == WindingType.Single:
winding_scheme = WindingScheme[vww["winding_scheme"]] if vww[
"winding_scheme"] is not None else None
print(f"Winding Type Single")
winding_scheme = WindingScheme[vww["winding_scheme"]] if vww["winding_scheme"] is not None else None
wrap_para_type = WrapParaType[vww["wrap_para"]] if vww["wrap_para"] is not None else None
new_vww.set_winding(conductors[0], turns[0], winding_scheme, wrap_para_type)
new_vww.set_winding(conductors[0], turns[winding_number], winding_scheme, wrap_para_type)
print(turns[0])
elif winding_type == WindingType.TwoInterleaved:
new_vww.set_interleaved_winding(conductors[0], turns[0], conductors[1], turns[1],
InterleavedWindingScheme[vww["winding_scheme"]],
Expand All @@ -3437,9 +3469,6 @@ def decode_settings_from_log(log_file_path: str, working_directory: str = None,
winding_window.virtual_winding_windows = new_virtual_winding_windows
geo.set_winding_windows([winding_window])

# Variable to set silent mode
ff.set_silent_status(silent)

return geo

raise Exception(f"Couldn't extract settings from file {log_file_path}")
Expand Down
141 changes: 78 additions & 63 deletions femmt/examples/example_log.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,76 +4,82 @@
"f": 270000,
"winding1": {
"turn_losses": [
0.01572450142098344,
0.04060216687433737,
0.08703666775793217,
0.1305243047987942,
0.1706799224223017,
0.1292934563819182,
0.08587629127087776,
0.04014514012124071,
0.01561550422443131
0.01637417018532403,
0.04213418539882433,
0.09030212330680248,
0.1352355234435239,
0.1771066126349231,
0.1343666190381891,
0.08913720733624464,
0.04168024641206344,
0.01626603133741059
],
"flux": [
0.00015825721753042428,
-4.423273819935796e-07
0.0001581267296681432,
-4.429012312508354e-07
],
"self_inductance": [
3.516827056231651e-05,
-9.829497377635101e-08
"flux_over_current": [
3.513926604371122e-05,
-9.980970274558075e-08
],
"V": [
0.7503907250264232,
268.4770444644171
0.7619542722330689,
268.2556219347689
],
"number_turns": 9,
"I": [
4.5,
0.0
],
"winding_losses": 0.7154979552728182,
"P": 1.6883791313094523,
"Q": 604.0733500449385,
"S": 604.0757095419463
"winding_losses": 0.7426027190933082,
"P": 1.714397112524405,
"Q": 603.57514935323,
"S": 603.5775841383056
},
"core_eddy_losses": 0.1655232295969782,
"core_hyst_losses": 6.629502956195709,
"all_winding_losses": 0.7154979552728182
"core_eddy_losses": 0.1658650568994096,
"core_hyst_losses": 6.610022786316285,
"all_winding_losses": 0.7426027190933082
}
],
"total_losses": {
"winding1": {
"total": 0.7154979552728167,
"total": 0.7426027190933057,
"turns": [
0.01572450142098344,
0.04060216687433737,
0.08703666775793217,
0.1305243047987942,
0.1706799224223017,
0.1292934563819182,
0.08587629127087776,
0.04014514012124071,
0.01561550422443131
0.01637417018532403,
0.04213418539882433,
0.09030212330680248,
0.1352355234435239,
0.1771066126349231,
0.1343666190381891,
0.08913720733624464,
0.04168024641206344,
0.01626603133741059
]
},
"all_windings": 0.7154979552728182,
"eddy_core": 0.1655232295969782,
"hyst_core_fundamental_freq": 6.629502956195709,
"core": 6.795026185792687
"all_windings": 0.7426027190933082,
"eddy_core": 0.1658650568994096,
"hyst_core_fundamental_freq": 6.610022786316285,
"core": 6.775887843215695,
"total_losses": 7.518490562309003
},
"simulation_settings": {
"date": "2023-03-28 16:12:35",
"simulation_name": null,
"date": "2023-10-23 08:40:57",
"component_type": "Inductor",
"working_directory": "/home/nikolasf/Dokumente/01_git/30_Python/FEMMT/femmt/examples/example_results/inductor",
"core": {
"core_inner_diameter": 0.0149,
"core_h": 0.03695,
"window_w": 0.01105,
"window_h": 0.0295,
"material": "N49",
"loss_approach": "LossAngle",
"mu_r_abs": 1500,
"phi_mu_deg": null,
"sigma": 0.23873221241433593,
"sigma": [
0.23873221241433593,
0.5494703175282039
],
"non_linear": false,
"correct_outer_leg": false,
"temperature": 45,
Expand All @@ -84,30 +90,38 @@
"permittivity_measurement_setup": "LEA_LK",
"permittivity_datatype": "complex_permittivity"
},
"virtual_winding_windows": [
"winding_windows": [
{
"bot_bound": -0.013749999999999998,
"top_bound": 0.013749999999999998,
"left_bound": 0.01145,
"right_bound": 0.0175,
"winding_type": "Single",
"winding_scheme": null,
"wrap_para": null,
"windings": [
"max_bot_bound": -0.013749999999999998,
"max_top_bound": 0.013749999999999998,
"max_left_bound": 0.01145,
"max_right_bound": 0.0175,
"virtual_winding_windows": [
{
"winding_number": 0,
"conductivity": "Copper",
"conductor_type": "RoundSolid",
"thickness": null,
"conductor_radius": 0.0013,
"conductor_arrangement": "Square",
"number_strands": 0,
"strand_radius": null,
"fill_factor": null
"bot_bound": -0.013749999999999998,
"top_bound": 0.013749999999999998,
"left_bound": 0.01145,
"right_bound": 0.0175,
"winding_type": "Single",
"winding_scheme": null,
"wrap_para": null,
"windings": [
{
"winding_number": 0,
"conductivity": "Copper",
"conductor_type": "RoundSolid",
"thickness": null,
"conductor_radius": 0.0013,
"conductor_arrangement": "Square",
"number_strands": 0,
"strand_radius": null,
"fill_factor": null
}
],
"turns": [
9
]
}
],
"turns": [
9
]
}
],
Expand All @@ -125,15 +139,16 @@
},
"insulation": {
"inner_winding_insulations": [
0.0005
[
0.0005
]
],
"core_insulations": [
0.001,
0.001,
0.004,
0.001
],
"vww_insulation": 0.0001
]
}
},
"misc": {
Expand Down
3 changes: 3 additions & 0 deletions femmt/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,9 @@ def to_dict(self):
# TODO: mdb
if self.core_type == CoreType.Single:
return {
"core_type": self.core_type,
"core_inner_diameter": self.core_inner_diameter,
"core_h": self.core_h,
"window_w": self.window_w,
"window_h": self.window_h,
"material": self.material,
Expand All @@ -432,6 +434,7 @@ def to_dict(self):

elif self.core_type == CoreType.Stacked:
return {
"core_type": self.core_type,
"core_inner_diameter": self.core_inner_diameter,
"window_w": self.window_w,
"window_h_bot": self.window_h_bot,
Expand Down
2 changes: 2 additions & 0 deletions femmt/optimization/sto.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,8 @@ def re_simulate_single_result(study_name: str, config: StoSingleInputConfig, num
:type fft_filter_value_factor: float
: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
:param storage: storage of the study
:type storage: str
"""
target_and_fixed_parameters = femmt.optimization.StackedTransformerOptimization.calculate_fix_parameters(config)

Expand Down
Loading
Loading