adding tordoidal simulator and drawing
This commit is contained in:
26
model.py
26
model.py
@@ -1,5 +1,6 @@
|
||||
from dataclasses import dataclass, field
|
||||
from typing import List, Tuple, Optional, Dict
|
||||
from core import core_loss_Pv
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -18,6 +19,9 @@ class TransformerModel:
|
||||
# Turn counts (total)
|
||||
Np_total: int
|
||||
Ns_total: int
|
||||
# Core loss model parameters (optional)
|
||||
Ve_mm3: float = 0.0 # effective core volume in mm^3 (for core loss calculation)
|
||||
use_core_loss_model: bool = False # if True, calculate core loss from B and f
|
||||
# Tap positions in turns counted from a common reference (e.g. one end of the bobbin)
|
||||
# Must include 0 and total turns if you want to be able to use full winding.
|
||||
primary_taps: List[int] = field(default_factory=lambda: [0])
|
||||
@@ -173,8 +177,26 @@ class TransformerModel:
|
||||
# Output power (resistive load)
|
||||
P_out = Vs_rms_ideal**2 / load_ohms
|
||||
|
||||
# Core loss calculation
|
||||
if self.use_core_loss_model and self.Ve_mm3 > 0:
|
||||
# Calculate core loss from B and f using the model
|
||||
# Convert volume to m^3
|
||||
Ve_m3 = self.Ve_mm3 * 1e-9 # mm^3 to m^3
|
||||
|
||||
# Get core loss density in kW/m^3
|
||||
try:
|
||||
Pv_kW_m3 = core_loss_Pv(B_peak_T, freq_hz)
|
||||
# Convert to watts
|
||||
core_loss_calculated = Pv_kW_m3 * Ve_m3 * 1000 # kW/m^3 * m^3 * 1000 = W
|
||||
except (ValueError, Exception) as e:
|
||||
# If core loss model fails (e.g., B or f out of range), fall back to provided value
|
||||
core_loss_calculated = core_loss_W
|
||||
else:
|
||||
# Use provided core loss value
|
||||
core_loss_calculated = core_loss_W
|
||||
|
||||
# Total input power (approx)
|
||||
P_in = P_out + P_cu_total + core_loss_W
|
||||
P_in = P_out + P_cu_total + core_loss_calculated
|
||||
|
||||
efficiency = P_out / P_in if P_in > 0 else 1.0
|
||||
|
||||
@@ -191,7 +213,7 @@ class TransformerModel:
|
||||
"P_cu_W": P_cu_total,
|
||||
"P_cu_primary_W": P_cu_p,
|
||||
"P_cu_secondary_W": P_cu_s,
|
||||
"P_core_W": core_loss_W,
|
||||
"P_core_W": core_loss_calculated,
|
||||
"P_in_W": P_in,
|
||||
"efficiency": efficiency,
|
||||
"primary_tap": primary_tap,
|
||||
|
||||
Reference in New Issue
Block a user