From 84181df2a2c2b2f2d92d4333666110b7536a8331 Mon Sep 17 00:00:00 2001 From: Jeff Date: Sun, 15 Dec 2024 22:25:12 -0400 Subject: [PATCH] Updated circuits to use database for information. --- example_notebook.ipynb | 129 +++++++++++++++++++++----- jepl/jepl_circuits.py | 204 +++++++++++++++++++++++++++++++++-------- 2 files changed, 275 insertions(+), 58 deletions(-) diff --git a/example_notebook.ipynb b/example_notebook.ipynb index 15d8e90..2a0e3bd 100644 --- a/example_notebook.ipynb +++ b/example_notebook.ipynb @@ -48,7 +48,7 @@ { "data": { "text/plain": [ - "[12.96, 5.4]" + "[24.96, 10.4]" ] }, "execution_count": 2, @@ -75,7 +75,7 @@ { "data": { "text/plain": [ - "[24.96, 10.4]" + "[12.96, 5.4]" ] }, "execution_count": 3, @@ -102,7 +102,7 @@ { "data": { "text/plain": [ - "[6.24, 2.6]" + "[3.24, 1.35]" ] }, "execution_count": 4, @@ -126,29 +126,116 @@ "- Load in Amps\n", "- Distance in meters\n", "- Voltage drop percent (default 3%)\n", - "- Number of parallel runs (default 1 run)\n" + "- Number of parallel runs (default 1 run)\n", + "\n", + "The function returns a string that is either AWG or kcmil. AWG from 14AWG to 4/0 AWG and kcmil above that." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "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'" - ] + "data": { + "text/plain": [ + "'350'" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "jmk.voltage_drop_conductors(120,200,100)" + "jmk.voltage_drop_conductors(120,100,325,material='al',runs=4)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The conductor sizing currently only works for CEC and does not do derating, yet." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[350, 2]" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "jmk.conductor_size(1000, temp = 75, material = 'cu', code = 'CEC', raceway = False, ambient = 30, max = 500)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[400, 3]" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "jmk.conductor_size(1000, temp = 75, material = 'cu', code = 'CEC', raceway = True, ambient = 30, max = 500)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[400, 3]" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "jmk.conductor_size(1000, temp = 75, material = 'al', code = 'CEC', raceway = False, ambient = 30, max = 500)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[400, 3]" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "jmk.conductor_size(1000, temp = 75, material = 'al', code = 'CEC', raceway = True, ambient = 30, max = 500)\n" ] }, { @@ -169,7 +256,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -178,7 +265,7 @@ "37" ] }, - "execution_count": 5, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -196,7 +283,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -205,7 +292,7 @@ "33" ] }, - "execution_count": 6, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -231,7 +318,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.1" + "version": "3.11.2" } }, "nbformat": 4, diff --git a/jepl/jepl_circuits.py b/jepl/jepl_circuits.py index ce56bf7..cbaa393 100644 --- a/jepl/jepl_circuits.py +++ b/jepl/jepl_circuits.py @@ -108,28 +108,33 @@ def voltage_drop_conductors(voltage,current,distance,v_drop_percent = 0.03,runs 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 + ohms = v/I or (v_drop/voltage)/current - resistivity = (v_drop_percent/current)/[(2 * distance)/1000] + v_drop = v_drop_percent * voltage + + resistivity = (v_drop/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] + resistivity = [(v_drop/current)*runs]/[(2 * distance)/1000] ''' # Determine the resistivity needed in ohms/km - resistivity = ((v_drop_percent/current)*runs)/((2 * distance)/1000) + + v_drop = v_drop_percent * voltage + + resistivity = ((v_drop/current)*runs)/((2 * distance)/1000) + if resistivity < 0.1214: print("add parallel runs") - print(resistivity) - else: - print(resistivity) import os import sys @@ -146,7 +151,7 @@ def voltage_drop_conductors(voltage,current,distance,v_drop_percent = 0.03,runs cur.execute('SELECT "Conductor Size" FROM "SW-Spec 25055" WHERE "Conductor Number" = 3 AND "AC Resistance" ? ', (current,)) + + elif temp ==75: + cur.execute('SELECT size FROM "Table1" WHERE "75" > ? ', (current,)) + + else: + cur.execute('SELECT size FROM "Table1" WHERE "60" > ? ', (current,)) + conductor_size = cur.fetchone()[0] + + #print(conductor_size) + + except sqlite3.OperationalError as e: + print(e) + + elif (code == 'CEC') & (material == 'CU') & (raceway == True): # CEC Table 2 + try: + with sqlite3.connect("jepl-cec21.db") as con: + cur = con.cursor() + cur.execute('SELECT * FROM "Table2" WHERE "size" = ? ', (max,)) + max_conductor_current = cur.fetchone() + max_current = max_conductor_current[conductor_current_index] + + except sqlite3.OperationalError as e: + print(e) + + current_lookup = current_for_lookup(current,max_current) + current = current_lookup[0] + num_parallel = current_lookup[1] + + try: + with sqlite3.connect("jepl-cec21.db") as con: + cur = con.cursor() + if temp == 90: + cur.execute('SELECT size FROM "Table2" WHERE "90" > ? ', (current,)) + + elif temp ==75: + cur.execute('SELECT size FROM "Table2" WHERE "75" > ? ', (current,)) + + else: + cur.execute('SELECT size FROM "Table2" WHERE "60" > ? ', (current,)) + conductor_size = cur.fetchone()[0] + + #print(conductor_size) + + except sqlite3.OperationalError as e: + print(e) + elif (code =='CEC') & (material =='AL') & (raceway == False): # CEC Table 3 + try: + with sqlite3.connect("jepl-cec21.db") as con: + cur = con.cursor() + cur.execute('SELECT * FROM "Table3" WHERE "size" = ? ', (max,)) + max_conductor_current = cur.fetchone() + max_current = max_conductor_current[conductor_current_index] + + except sqlite3.OperationalError as e: + print(e) + + current_lookup = current_for_lookup(current,max_current) + current = current_lookup[0] + num_parallel = current_lookup[1] + + try: + with sqlite3.connect("jepl-cec21.db") as con: + cur = con.cursor() + if temp == 90: + cur.execute('SELECT size FROM "Table3" WHERE "90" > ? ', (current,)) + + elif temp ==75: + cur.execute('SELECT size FROM "Table3" WHERE "75" > ? ', (current,)) + + else: + cur.execute('SELECT size FROM "Table3" WHERE "60" > ? ', (current,)) + conductor_size = cur.fetchone()[0] + + #print(conductor_size) + + except sqlite3.OperationalError as e: + print(e) + + + elif (code =='CEC') & (material =='AL') & (raceway == True): # CEC Table 4 + try: + with sqlite3.connect("jepl-cec21.db") as con: + cur = con.cursor() + cur.execute('SELECT * FROM "Table4" WHERE "size" = ? ', (max,)) + max_conductor_current = cur.fetchone() + max_current = max_conductor_current[conductor_current_index] + + except sqlite3.OperationalError as e: + print(e) + + current_lookup = current_for_lookup(current,max_current) + current = current_lookup[0] + num_parallel = current_lookup[1] + + try: + with sqlite3.connect("jepl-cec21.db") as con: + cur = con.cursor() + if temp == 90: + cur.execute('SELECT size FROM "Table4" WHERE "90" > ? ', (current,)) + + elif temp ==75: + cur.execute('SELECT size FROM "Table4" WHERE "75" > ? ', (current,)) + + else: + cur.execute('SELECT size FROM "Table4" WHERE "60" > ? ', (current,)) + conductor_size = cur.fetchone()[0] + + #print(conductor_size) + + except sqlite3.OperationalError as e: + print(e) elif (code =='NEC') & (material =='CU'): return (' I haven\'t created this table yet') elif (code =='NEC') & (material =='AL'): return (' I haven\'t created this table yet') else: return ('The variables were\'t right, but I\'m a loss to why.') - - temp = str(temp) - - max_current_loc = code_table.loc[code_table['size'] == max][str(temp)] - max_current = max_current_loc.iloc[0] - num_parallel = math.ceil(current / max_current) - con_current = current / num_parallel - - size = code_table[code_table[temp].ge(con_current)]['size'].iloc[0] - - return [size,num_parallel] -''' -''' -# ^ -# These functions need to be re-written with the databases. - -''' -''' + return [conductor_size,num_parallel]