AreebaSattar/Cable-Sizing-Calculator
1
1import gradio as gr2 3def cable_sizing(power_kw, voltage, pf, length, v_drop, material, phase, 4 ambient_temp, short_circuit_time, growth_factor, load_type,5 duty_cycle, tray_type, laying_method, grouping_factor,6 soil_resistivity, depth, ventilation, busbar_type, busbar_current):7 8 # Step 1: Base current calculation9 if phase == "Single Phase":10 current = (power_kw * 1000) / (voltage * pf)11 else:12 current = (power_kw * 1000) / (voltage * pf * (3**0.5))13 14 # Step 2: Apply growth factor (future demand)15 current *= (1 + growth_factor/100)16 17 # Step 3: Temperature derating (very simplified example)18 temp_correction = 1.019 if ambient_temp > 30:20 temp_correction = max(0.7, 1 - (ambient_temp - 30) * 0.01)21 current /= temp_correction22 23 # Step 4: Grouping correction24 grouping_correction = 1 / grouping_factor if grouping_factor > 1 else 125 current /= grouping_correction26 27 # Step 5: Voltage drop check28 resistivity = {"Copper": 0.018, "Aluminium": 0.028}29 vd = (current * resistivity[material] * length) / 100030 vd_percent = (vd / voltage) * 10031 if vd_percent > v_drop:32 vdrop_msg = f"⚠ Voltage drop {vd_percent:.2f}% exceeds limit ({v_drop}%)."33 else:34 vdrop_msg = f"Voltage drop {vd_percent:.2f}% is within limit."35 36 # Step 6: Suggest cable size (dummy table)37 if current <= 20:38 cable_size = "2.5 mm²"39 elif current <= 40:40 cable_size = "6 mm²"41 elif current <= 70:42 cable_size = "16 mm²"43 elif current <= 150:44 cable_size = "35 mm²"45 else:46 cable_size = "Check IEC/NEC table for larger sizes."47 48 # Step 7: Busbar sizing (very simplified Cu example)49 if busbar_type == "Rigid (Cu)":50 busbar_area = busbar_current / 1.2 # assuming 1.2 A/mm²51 busbar_suggestion = f"Required busbar area ≈ {busbar_area:.0f} mm²"52 else:53 busbar_suggestion = "Flexible busbar selected (ACSR/AAAC). Size depends on strands."54 55 return f"""56 --- Cable Sizing Results ---57 Load Current: {current:.2f} A58 {vdrop_msg}59 Recommended Cable Size: {cable_size}60 61 --- Busbar Sizing ---62 Busbar Type: {busbar_type}63 {busbar_suggestion}64 """65 66# Gradio Interface67iface = gr.Interface(68 fn=cable_sizing,69 inputs=[70 gr.Number(label="Load Power (kW)"),71 gr.Number(label="Voltage (V)"),72 gr.Number(label="Power Factor"),73 gr.Number(label="Cable Length (m)"),74 gr.Number(label="Allowable Voltage Drop (%)"),75 gr.Dropdown(["Copper", "Aluminium"], label="Cable Material"),76 gr.Dropdown(["Single Phase", "Three Phase"], label="Phase"),77 gr.Number(label="Ambient Temperature (°C)", value=30),78 gr.Number(label="Short Circuit Time (s)", value=1),79 gr.Number(label="Growth Factor (%)", value=10),80 gr.Dropdown(["Heating", "HVACR", "Motor", "Lighting", "Electronics", "Welding"], label="Load Type"),81 gr.Dropdown(["Continuous", "Intermittent"], label="Duty Cycle"),82 gr.Dropdown(["Perforated", "Solid Bottom", "Ladder", "Clipped Directly", "Free Air"], label="Cable Tray"),83 gr.Dropdown(["Open Air", "Conduits", "Pipes", "Trenches", "Buried Underground"], label="Laying Method"),84 gr.Number(label="Grouping Factor", value=1),85 gr.Number(label="Soil Thermal Resistivity (K.m/W)", value=1.5),86 gr.Number(label="Depth (m)", value=1),87 gr.Dropdown(["Good", "Poor"], label="Ventilation"),88 gr.Dropdown(["Flexible (ACSR/AAAC)", "Rigid (Cu)", "Rigid (Al)", "Rigid (Ag)"], label="Busbar Type"),89 gr.Number(label="Busbar Current (A)", value=1000),90 ],91 outputs="text",92 title="Advanced Cable & Busbar Sizing Calculator",93 description="Considers load, environment, installation, and IEC/NEC factors."94)95 96iface.launch()97 