From b0535dbf314717d30143a2185d3b5e420e315a40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikolas=20F=C3=B6rster?= Date: Mon, 23 Oct 2023 08:57:43 +0200 Subject: [PATCH 1/3] fix 'load_from_file' for inductor --- femmt/component.py | 13 ++- femmt/examples/example_log.json | 141 ++++++++++++++++++-------------- femmt/model.py | 1 + femmt/optimization/sto.py | 2 + 4 files changed, 87 insertions(+), 70 deletions(-) diff --git a/femmt/component.py b/femmt/component.py index be606499..683ddfad 100644 --- a/femmt/component.py +++ b/femmt/component.py @@ -3037,7 +3037,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. @@ -3060,12 +3060,14 @@ 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"]) + window_h=settings["core"]["window_h"], + core_h=settings["core"]["core_h"]) core = Core(core_dimensions=core_dimensions, **settings["core"]) geo.set_core(core) @@ -3079,7 +3081,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: @@ -3125,9 +3127,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}") diff --git a/femmt/examples/example_log.json b/femmt/examples/example_log.json index 6a3f1976..098b966e 100644 --- a/femmt/examples/example_log.json +++ b/femmt/examples/example_log.json @@ -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, @@ -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 ] } ], @@ -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": { diff --git a/femmt/model.py b/femmt/model.py index 852cf6e7..733800d3 100644 --- a/femmt/model.py +++ b/femmt/model.py @@ -412,6 +412,7 @@ def to_dict(self): if self.core_type == CoreType.Single: return { "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, diff --git a/femmt/optimization/sto.py b/femmt/optimization/sto.py index 898e4282..7447ec3e 100644 --- a/femmt/optimization/sto.py +++ b/femmt/optimization/sto.py @@ -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) From 2d5768a25805c1f413001bca2ace50be51acb6af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikolas=20F=C3=B6rster?= Date: Mon, 23 Oct 2023 10:15:03 +0200 Subject: [PATCH 2/3] fix 'load_from_file' for transformer --- femmt/component.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/femmt/component.py b/femmt/component.py index 683ddfad..d67c0f37 100644 --- a/femmt/component.py +++ b/femmt/component.py @@ -3070,6 +3070,7 @@ def decode_settings_from_log(log_file_path: str, working_directory: str = None, core_h=settings["core"]["core_h"]) core = Core(core_dimensions=core_dimensions, **settings["core"]) + core.sigma = complex(core.sigma[0], core.sigma[1]) geo.set_core(core) if "air_gaps" in settings: @@ -3096,6 +3097,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: @@ -3116,7 +3118,8 @@ def decode_settings_from_log(log_file_path: str, working_directory: str = None, if winding_type == WindingType.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"]], vww["winding_insulation"]) else: From 3cc4bc9e4277b6a66797c74c8dfe75a91bd1c722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikolas=20F=C3=B6rster?= Date: Tue, 24 Oct 2023 08:56:11 +0200 Subject: [PATCH 3/3] fix load from file for inductor and transformer --- femmt/component.py | 39 ++++++++++++++++++++++++++++++++++----- femmt/model.py | 2 ++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/femmt/component.py b/femmt/component.py index d67c0f37..e1525830 100644 --- a/femmt/component.py +++ b/femmt/component.py @@ -3064,13 +3064,41 @@ def decode_settings_from_log(log_file_path: str, working_directory: str = None, 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_h=settings["core"]["core_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"]) - core.sigma = complex(core.sigma[0], core.sigma[1]) geo.set_core(core) if "air_gaps" in settings: @@ -3116,6 +3144,7 @@ def decode_settings_from_log(log_file_path: str, working_directory: str = None, new_vww = VirtualWindingWindow(vww["bot_bound"], vww["top_bound"], vww["left_bound"], vww["right_bound"]) winding_type = WindingType[vww["winding_type"]] if winding_type == WindingType.Single: + 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[winding_number], winding_scheme, wrap_para_type) diff --git a/femmt/model.py b/femmt/model.py index 733800d3..03de302d 100644 --- a/femmt/model.py +++ b/femmt/model.py @@ -411,6 +411,7 @@ 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, @@ -433,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,