Transformer Design Bot
Transformer Design Bot
app = Flask(__name__)
# Core Calculations
E = math.sqrt(kVA * 1000 / 3) / 40
Ai = E / (4.44 * 50 * 1.7) * 1e6
d = math.ceil(math.sqrt(4 * Ai / (Ki * Ks * math.pi)))
Ai = Ki * Ks * (math.pi / 4) * d**2
Bm = E / (4.44 * 50 * Ai) # Bm in Tesla
Aw = kVA / (3.33 * Ai * Kw * del_ * Bm * 50 * 1e-3)
# Window dimensions
dw = 1 * 250 # window width (can change)
hw = math.ceil(Aw / dw)
hww = hw # Window height
yoke = 17 # Clearance to yoke (can change)
wA = dw * hww
dc = d
Wc = 0.95 * dc
D = dw + Wc # Distance between adjacent limbs
hwwy = hww + yoke
Wt = 2 * D + Wc # Total window width
Ht = hwwy + 2 * Wc # Total window height
# LV and HV winding
Vp = 415 / math.sqrt(3)
Tpl = math.ceil(Vp / E) # LV
Tph = math.ceil((11 * 1e3) / E) # HV
Tph = math.ceil(Tph + Tph * 0.05) # Tapping 5%
# LV winding
Ipl = round(kVA * 1e3 / (math.sqrt(3) * 415))
a2 = Ipl / del_
T = 14.39
W = 18 # Cross-section dimensions
# HV winding
Iph = round(kVA * 1e3 / (3 * 11 * 1e3))
a1 = Iph / del_
d = math.ceil(math.sqrt(4 * a1 / math.pi))
a1 = math.pi * d**2 / 4
Acw = 2 * (a1 * Tph + a2 * Tpl)
Kwr = Acw / Aw # Should be near 0.29
# LV coil
a=2
tp = math.ceil(Tpl / a)
i = (W + 0.25) * (T + 0.25)
l = (T + 0.25) * 2
Cdw = l * a
hwlv = math.ceil(tp * (W + 0.25))
tc = l * a
dcl = 3.5 # Distance between coil and LV
Id = dc + (2 * dcl) # Inside diameter
Od = Id + (2 * Cdw) # Outside diameter
Md = Id + Cdw # Mean diameter
Tlv = math.pi * Md # Mean length
# HV coil
a1h = 15
c=4
Dl = 12 # Distance between LV and HV
Id1 = Od + Dl * 2 # Inside diameter
tch = math.ceil(Tph / c)
tp1 = math.ceil(tch / a1h)
h = math.ceil(tp1 * (d + 0.25))
tc1 = (d + 0.25) * a1h
Od1 = Id1 + (2 * tc1)
Md1 = Id1 + tc1
Thv = math.pi * Md1
hwhv = (h * c) + 8 + 8 + 8
HW = hwhv + 26 * 2
# Percentage impedance
Z = math.sqrt(R**2 + X**2)
# Losses
V = (Wt * 2 + hwwy * 3) * Ai
WcI = (V * 7.85) / (1e6) # Weight of iron
Cl = WcI * Bm * 0.736 * 1e6 # Core loss
VAkg = 10
VA = VAkg * WcI
Wlv = (8.89 * a2 * Tpl * Tlv) / (1e6) # Weight of LV coil
Whv = (8.89 * a1 * Tph * Thv) / (1e6) # Weight of HV coil
WT = 3 * (Wlv + Whv)
CL = 3 * (r1 + r2 * rT**2) * Iph**2
LL = CL * 1.27 # Load loss
TL = Cl + LL
# Loss percentages
load_loss = ((LL * 1e-3) / kVA) * 100
total_loss = ((TL * 1e-3) / kVA) * 100
copper_loss = ((CL * 1e-3) / kVA) * 100
stray_loss = (((LL - CL) * 1e-3) / kVA) * 100
no_load_loss = ((Cl * 1e-3) / kVA) * 100
Z = Z * 100
# Outputs
result = {
"Window width": dw,
"Window height": hww,
"Core diameter": dc,
"Largest core": Wc,
"Total window width": Wt,
"Total window height": Ht,
"Percentage impedance": Z,
"Load loss percentage": load_loss,
"Total loss percentage": total_loss,
"Copper loss percentage": copper_loss,
"Stray loss percentage": stray_loss,
"No load loss percentage": no_load_loss,
}
except Exception as e:
result = {"error": str(e)}
For template,
template = """
<!doctype html>
<html lang="en">
<head>
<title>Transformer Calculations</title>
</head>
<body>
<h1>Transformer Calculations</h1>
<form method="post">
kVA: <input type="text" name="kVA" required><br>
Ki: <input type="text" name="Ki" required><br>
Ks: <input type="text" name="Ks" required><br>
Kw: <input type="text" name="Kw" required><br>
del_: <input type="text" name="del_" required><br>
<button type="submit">Calculate</button>
</form>
{% if result %}
<h2>Results:</h2>
<ul>
{% for key, value in result.items() %}
<li>{{ key }}: {{ value }}</li>
{% endfor %}
</ul>
{% endif %}
</body>
</html>
"""
if __name__ == '__main__':
app.run(debug=True)