95 lines
2.6 KiB
Python
95 lines
2.6 KiB
Python
from model import TransformerModel
|
|
from optimizer import TransformerOptimizer
|
|
|
|
# Example: Transformer with different wire gauges per segment
|
|
# Primary:
|
|
# - Segment 1 (0 to 50 turns): 22 AWG wire, lower resistance
|
|
# - Segment 2 (50 to 100 turns): 24 AWG wire, higher resistance
|
|
# Secondary:
|
|
# - Segment 1 (0 to 150 turns): 28 AWG wire
|
|
# - Segment 2 (150 to 300 turns): 30 AWG wire, higher resistance
|
|
|
|
primary_taps = [0, 75, 75]
|
|
secondary_taps = [0, 50, 150, 150, 200]
|
|
|
|
# Resistance per turn for each segment (example values in ohms/turn)
|
|
# These would be calculated based on wire gauge, length per turn, etc.
|
|
primary_Rp_per_turn = [
|
|
0.01,
|
|
0.01,
|
|
]
|
|
|
|
secondary_Rs_per_turn = [
|
|
0.004,
|
|
0.024,
|
|
0.024,
|
|
0.024,
|
|
]
|
|
|
|
tf = TransformerModel(
|
|
Ae_mm2=354.0,
|
|
Np_total=150,
|
|
Ns_total=550,
|
|
primary_taps=primary_taps,
|
|
secondary_taps=secondary_taps,
|
|
primary_Rp_per_turn=primary_Rp_per_turn,
|
|
secondary_Rs_per_turn=secondary_Rs_per_turn,
|
|
)
|
|
|
|
|
|
# Test different tap combinations to see resistance effects
|
|
test_cases = [
|
|
(1, 1, "Using only first segments (lower R wire)"),
|
|
(2, 2, "Using both segments (mixed wire gauges)"),
|
|
]
|
|
|
|
for p_tap, s_tap, description in test_cases:
|
|
result = tf.simulate(
|
|
primary_tap=p_tap,
|
|
secondary_tap=s_tap,
|
|
Vp_rms=12.0,
|
|
freq_hz=2000.0,
|
|
load_ohms=100.0,
|
|
core_loss_W=0.2,
|
|
)
|
|
|
|
print(f"{description}:")
|
|
print(f" Primary tap {p_tap}: {result['Np_eff']} turns")
|
|
print(f" Secondary tap {s_tap}: {result['Ns_eff']} turns")
|
|
print(f" Output power: {result['P_out_W']:.2f} W")
|
|
print(f" Copper loss: {result['P_cu_W']:.2f} W")
|
|
print(f" Efficiency: {result['efficiency']*100:.2f}%")
|
|
print()
|
|
|
|
# Run optimizer
|
|
print("=" * 70)
|
|
print("OPTIMIZER WITH PER-SEGMENT RESISTANCE")
|
|
print("=" * 70)
|
|
|
|
opt = TransformerOptimizer(tf)
|
|
|
|
result_opt = opt.optimize(
|
|
load_ohms=100.0,
|
|
target_power_W=10.0,
|
|
freq_hz=2000.0,
|
|
Vp_min=5.0,
|
|
Vp_max=30.0,
|
|
Vp_step=0.5,
|
|
B_max_T=0.3,
|
|
Vs_max=200.0,
|
|
core_loss_W=0.2,
|
|
power_tolerance_percent=2.0,
|
|
)
|
|
|
|
if result_opt:
|
|
print(f"Optimal configuration:")
|
|
print(f" Primary tap: {result_opt.primary_tap} ({result_opt.Np_eff} turns)")
|
|
print(f" Secondary tap: {result_opt.secondary_tap} ({result_opt.Ns_eff} turns)")
|
|
print(f" Input voltage: {result_opt.Vp_rms:.1f} V")
|
|
print(f" Output power: {result_opt.P_out_W:.2f} W")
|
|
print(f" Efficiency: {result_opt.efficiency*100:.2f}%")
|
|
print(f" Copper loss: {result_opt.P_cu_W:.2f} W")
|
|
print(f" Output voltage: {result_opt.Vs_rms:.1f} V")
|
|
else:
|
|
print("No valid configuration found!")
|