# -*- coding: utf-8 -*-
"""
Created on Sun Mar 16 15:27:04 2025

@author: Vincents Laptop
"""

import femmt as fmt
import materialdatabase as mdb

geo = fmt.MagneticComponent(simulation_type=fmt.SimulationType.FreqDomain, 
                            component_type=fmt.ComponentType.Transformer,
                            working_directory=r"C:\Users\Vincents Laptop\OneDrive\Dokumente\TU Berlin\Fasttube\Electronics\DCDC\Konzept\PSFB\Trafo\FEMMT",
                            verbosity=fmt.Verbosity.ToConsole)

core_dimensions = fmt.dtos.SingleCoreDimensions(core_inner_diameter=0.0156, window_w=0.0141, window_h=0.02805, core_h=0.0156)
core = fmt.Core(core_type=fmt.CoreType.Single,
                core_dimensions=core_dimensions,
                detailed_core_model=False,
                material=mdb.Material.N95, temperature=50, frequency=1000,
                permeability_datasource=fmt.MaterialDataSource.Measurement,
                permeability_datatype=fmt.MeasurementDataType.ComplexPermeability,
                permeability_measurement_setup=mdb.MeasurementSetup.LEA_LK,
                permittivity_datasource=fmt.MaterialDataSource.Measurement,
                permittivity_datatype=fmt.MeasurementDataType.ComplexPermittivity,
                permittivity_measurement_setup=mdb.MeasurementSetup.LEA_LK, 
                mdb_verbosity=fmt.Verbosity.Silent)
geo.set_core(core)

insulation = fmt.Insulation(flag_insulation=True)
insulation.add_core_insulations(0.001, 0.001, 0.001, 0.001)
insulation.add_winding_insulations([[0.0001, 0.001], [0.0001, 0.001]])
geo.set_insulation(insulation)

winding_window = fmt.WindingWindow(core, insulation)
vww = winding_window.split_window(fmt.WindingWindowSplit.NoSplit)

winding1 = fmt.Conductor(winding_number=0, conductivity=fmt.Conductivity.Copper)
winding1.set_litz_round_conductor(conductor_radius=None, number_strands=100, strand_radius=0.0001007/2,
                                  fill_factor=0.7, conductor_arrangement=fmt.ConductorArrangement.Square)

vww.set_winding(winding1, 38, None, fmt.Align.CenterOnHorizontalAxis, 
                placing_strategy=fmt.ConductorDistribution.VerticalDownward_HorizontalRightward,
                zigzag=False)
geo.set_winding_windows([winding_window])

geo.create_model(freq=100000, pre_visualize_geometry=True, save_png=False)
geo.single_simulation(freq=100000, current=[4.5], phi_deg=[0],
                      plot_interpolation=False, show_fem_simulation_results=True)




