From 8784a2ba8906caf87033bf972ac16b290452cbfb Mon Sep 17 00:00:00 2001 From: Jeff MacKinnon Date: Sun, 15 Dec 2024 20:19:11 -0400 Subject: [PATCH] Adding parallel circuits to calculate conductors --- example_notebook.ipynb | 41 +++++++++++++++- jepl/jepl_circuits.py | 104 +++++++++++++++++++++++++++++++++++++---- jepl/jeplinit.py | 4 +- jepl/jeplpv.py | 2 +- 4 files changed, 136 insertions(+), 15 deletions(-) diff --git a/example_notebook.ipynb b/example_notebook.ipynb index 9c9c296..15d8e90 100644 --- a/example_notebook.ipynb +++ b/example_notebook.ipynb @@ -114,6 +114,43 @@ "jmk.voltage_drop(240, 100, '2/0', material='al', num_runs=4)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Calculate conductors for specified voltage drop\n", + "\n", + "This next function will specify the conductor size based on the specified:\n", + "\n", + "- System voltage\n", + "- Load in Amps\n", + "- Distance in meters\n", + "- Voltage drop percent (default 3%)\n", + "- Number of parallel runs (default 1 run)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "unsupported operand type(s) for /: 'function' and 'int'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Input \u001b[1;32mIn [5]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mjmk\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mvoltage_drop_conductors\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m120\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m200\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m100\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43mv_drop_percent\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m0.03\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43mruns\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m)\u001b[49m\n", + "File \u001b[1;32mc:\\Business\\JMKEngineering\\Engineering\\Active\\TEP Group\\24xx_TEP_Shubie-tower-project\\eng\\resources\\JEPL\\jepl\\jepl_circuits.py:124\u001b[0m, in \u001b[0;36mvoltage_drop_conductors\u001b[1;34m(voltage, current, distance, v_drop_percent, runs, material)\u001b[0m\n\u001b[0;32m 96\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m'''\u001b[39;00m\n\u001b[0;32m 97\u001b[0m \u001b[38;5;124;03m Calculates the minimum conductor size to accomodate for voltage drop based on:\u001b[39;00m\n\u001b[0;32m 98\u001b[0m \n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 119\u001b[0m \n\u001b[0;32m 120\u001b[0m \u001b[38;5;124;03m'''\u001b[39;00m\n\u001b[0;32m 123\u001b[0m \u001b[38;5;66;03m# Determine the resistivity needed in ohms/km\u001b[39;00m\n\u001b[1;32m--> 124\u001b[0m resistivity \u001b[38;5;241m=\u001b[39m ((\u001b[43mvd\u001b[49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[43mcurrent\u001b[49m)\u001b[38;5;241m/\u001b[39mruns)\u001b[38;5;241m/\u001b[39m((\u001b[38;5;241m2\u001b[39m \u001b[38;5;241m*\u001b[39m distance)\u001b[38;5;241m/\u001b[39m\u001b[38;5;241m1000\u001b[39m)\n\u001b[0;32m 125\u001b[0m \u001b[38;5;28mprint\u001b[39m(resistivity)\n\u001b[0;32m 127\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mos\u001b[39;00m\n", + "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for /: 'function' and 'int'" + ] + } + ], + "source": [ + "jmk.voltage_drop_conductors(120,200,100)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -132,7 +169,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -159,7 +196,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [ { diff --git a/jepl/jepl_circuits.py b/jepl/jepl_circuits.py index 152fd06..ce56bf7 100644 --- a/jepl/jepl_circuits.py +++ b/jepl/jepl_circuits.py @@ -13,9 +13,20 @@ import math import sqlite3 -def vd(current,length,resistance): +def vd(current,length,resistance,runs=1): - vd=2*current*length*resistance/1000 + ''' + Calculates the voltage drop across the conductor length. + + If there are parallel runs we assume that they are approximately the same length. + Therefore from the general equation of: + + 1/Req = 1/R1 + 1/R2 ... and all R1-Rn are the same. + Req = R/n or in the equation below r = resistance / runs. + ''' + + r = (length*resistance/1000) / runs + vd=round(2*current*r,8) return vd def percentvd(vd,nominal): @@ -24,7 +35,7 @@ def percentvd(vd,nominal): return percent -def voltage_drop(nominal_voltage, current, conductor_size, material ='cu', code = 'CEC'): +def voltage_drop(nominal_voltage, current, conductor_size, material ='cu', num_runs = 1, code = 'CEC'): ''' This function will return the drop in voltage and in percent of the supply. @@ -53,19 +64,21 @@ def voltage_drop(nominal_voltage, current, conductor_size, material ='cu', code if (material == 'al'): try: - with sqlite3.connect("cable.db") as con: + with sqlite3.connect("jepl-cable.db") as con: cur = con.cursor() - cur.execute('SELECT "AC Resistance" FROM "SW-Spec 25055" WHERE "Conductor Size"=?', (conductor_size,)) + cur.execute('SELECT "AC Resistance" FROM "SW-Spec 25051" WHERE "Conductor Number" = 3 AND "Conductor Size"=?', (conductor_size,)) resistance = cur.fetchone()[0] + + #print(resistance) except sqlite3.OperationalError as e: print(e) elif (material == 'cu'): try: - with sqlite3.connect("cable.db") as con: + with sqlite3.connect("jepl-cable.db") as con: cur = con.cursor() - cur.execute('SELECT "AC Resistance" FROM "SW-Spec 25051" WHERE "Conductor Number=3" AND "Conductor Size"=?', (conductor_size,)) + cur.execute('SELECT "AC Resistance" FROM "SW-Spec 25055" WHERE "Conductor Number" = 3 AND "Conductor Size"=?', (conductor_size,)) resistance = cur.fetchone()[0] except sqlite3.OperationalError as e: @@ -74,16 +87,87 @@ def voltage_drop(nominal_voltage, current, conductor_size, material ='cu', code else: return (print("error, choose material as cu or al")) - voltage = vd(nominal_voltage,current,resistance) + voltage = vd(nominal_voltage,current,resistance,num_runs) percent = percentvd(voltage,nominal_voltage) return [voltage, percent] +# +# voltage_drop_conductors is wrong +# +# +def voltage_drop_conductors(voltage,current,distance,v_drop_percent = 0.03,runs = 1,material='cu'): + ''' + Calculates the minimum conductor size to accomodate for voltage drop based on: + voltage -> system nominal voltage + current -> the peak/design load for the circuit + distance -> meters + v_drop_percent -> The design voltage drop (default 0.03 or 3%) + runs -> number of parallel runs (default 1) + material -> the conductor material, either 'al' or 'cu'. (default 'cu') + First we calculate the necessary resistivity: + resistivity = ohms/km + but the distance is 2x (there and back) + resistivity = ohms/[(2 * distance)/1000] {ohms/km} + ohms = v/I or v_drop_percent/current + + resistivity = (v_drop_percent/current)/[(2 * distance)/1000] + + This works for 1 run, but for parallel runs Rtot = R/n where n is the number of runs. + in this equation we are looking for R, not Rtot, so we multiply the top by the number of runs. + + therefore: + resistivity = [(v_drop_percent/current)*runs]/[(2 * distance)/1000] + + ''' + + # Determine the resistivity needed in ohms/km + resistivity = ((v_drop_percent/current)*runs)/((2 * distance)/1000) + if resistivity < 0.1214: + print("add parallel runs") + print(resistivity) + else: + print(resistivity) + + import os + import sys + if os.path.isfile('jepl-cable.db') == False: + return (print("Run init. \nCopy jeplinit.py to the same folder as this file and add \n%run jeplinit.py jepl/folder/location/\nto the notebook. Make sure there is a trailing slash.")) + + # Lookup the conductor size that meets this resistivity. + + if (material == 'al'): + + try: + with sqlite3.connect("jepl-cable.db") as con: + cur = con.cursor() + cur.execute('SELECT "Conductor Size" FROM "SW-Spec 25055" WHERE "Conductor Number" = 3 AND "AC Resistance"