Updated circuits to use database for information.

This commit is contained in:
Jeff 2024-12-15 22:25:12 -04:00
parent 8784a2ba89
commit 84181df2a2
2 changed files with 275 additions and 58 deletions

View file

@ -48,7 +48,7 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"[12.96, 5.4]" "[24.96, 10.4]"
] ]
}, },
"execution_count": 2, "execution_count": 2,
@ -75,7 +75,7 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"[24.96, 10.4]" "[12.96, 5.4]"
] ]
}, },
"execution_count": 3, "execution_count": 3,
@ -102,7 +102,7 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"[6.24, 2.6]" "[3.24, 1.35]"
] ]
}, },
"execution_count": 4, "execution_count": 4,
@ -126,29 +126,116 @@
"- Load in Amps\n", "- Load in Amps\n",
"- Distance in meters\n", "- Distance in meters\n",
"- Voltage drop percent (default 3%)\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", "cell_type": "code",
"execution_count": null, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"ename": "TypeError", "data": {
"evalue": "unsupported operand type(s) for /: 'function' and 'int'", "text/plain": [
"output_type": "error", "'350'"
"traceback": [ ]
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", },
"\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", "execution_count": 5,
"Input \u001b[1;32mIn [5]\u001b[0m, in \u001b[0;36m<cell line: 1>\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", "metadata": {},
"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", "output_type": "execute_result"
"\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for /: 'function' and 'int'"
]
} }
], ],
"source": [ "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", "cell_type": "code",
"execution_count": null, "execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -178,7 +265,7 @@
"37" "37"
] ]
}, },
"execution_count": 5, "execution_count": 10,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -196,7 +283,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -205,7 +292,7 @@
"33" "33"
] ]
}, },
"execution_count": 6, "execution_count": 11,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -231,7 +318,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.10.1" "version": "3.11.2"
} }
}, },
"nbformat": 4, "nbformat": 4,

View file

@ -108,28 +108,33 @@ def voltage_drop_conductors(voltage,current,distance,v_drop_percent = 0.03,runs
First we calculate the necessary resistivity: First we calculate the necessary resistivity:
resistivity = ohms/km resistivity = ohms/km
but the distance is 2x (there and back) but the distance is 2x (there and back)
resistivity = ohms/[(2 * distance)/1000] {ohms/km} 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. 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. in this equation we are looking for R, not Rtot, so we multiply the top by the number of runs.
therefore: 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 # 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: if resistivity < 0.1214:
print("add parallel runs") print("add parallel runs")
print(resistivity)
else:
print(resistivity)
import os import os
import sys 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"<?', (resistivity,)) cur.execute('SELECT "Conductor Size" FROM "SW-Spec 25055" WHERE "Conductor Number" = 3 AND "AC Resistance"<?', (resistivity,))
conductor = cur.fetchone()[0] conductor = cur.fetchone()[0]
print(conductor) #print(conductor)
except sqlite3.OperationalError as e: except sqlite3.OperationalError as e:
print(e) print(e)
@ -158,7 +163,7 @@ def voltage_drop_conductors(voltage,current,distance,v_drop_percent = 0.03,runs
cur.execute('SELECT "Conductor Size" FROM "SW-Spec 25051" WHERE "Conductor Number" = 3 AND "AC Resistance"<?', (resistivity,)) cur.execute('SELECT "Conductor Size" FROM "SW-Spec 25051" WHERE "Conductor Number" = 3 AND "AC Resistance"<?', (resistivity,))
conductor = cur.fetchone()[0] conductor = cur.fetchone()[0]
print(conductor) #print(conductor)
except sqlite3.OperationalError as e: except sqlite3.OperationalError as e:
print(e) print(e)
@ -170,8 +175,19 @@ def voltage_drop_conductors(voltage,current,distance,v_drop_percent = 0.03,runs
# These functions need to be re-written with the databases. # These functions need to be re-written with the databases.
'''
''' def current_for_lookup(current,max_current):
'''
This is a helper function for conductor_size. It is used to calculate the number of parallel runs needed,
and the conductor current for those runs.
'''
num_parallel = math.ceil(current / max_current)
con_current = current / num_parallel
return (con_current,num_parallel)
def conductor_size(current, temp = 75, material = 'cu', code = 'CEC', raceway = True, ambient = 30, max = 500): def conductor_size(current, temp = 75, material = 'cu', code = 'CEC', raceway = True, ambient = 30, max = 500):
''' '''
@ -201,15 +217,146 @@ def conductor_size(current, temp = 75, material = 'cu', code = 'CEC', raceway =
if material not in valid_material: if material not in valid_material:
return print(material + " is not a valid material. I should be 'al' or 'cu'.") return print(material + " is not a valid material. I should be 'al' or 'cu'.")
if temp == 90:
conductor_current_index = 3
elif temp == 75:
conductor_current_index = 2
else:
conductor_current_index = 1
# select the correct code table # select the correct code table
if (code == 'CEC') & (material == 'CU') & (raceway == False): if (code == 'CEC') & (material == 'CU') & (raceway == False): # CEC Table 1
code_table = CEC_table1 try:
elif (code == 'CEC') & (material == 'CU') & (raceway == True): with sqlite3.connect("jepl-cec21.db") as con:
code_table = CEC_table2 cur = con.cursor()
elif (code =='CEC') & (material =='AL') & (raceway == False): cur.execute('SELECT * FROM "Table1" WHERE "size" = ? ', (max,))
code_table = CEC_table3 max_conductor_current = cur.fetchone()
elif (code =='CEC') & (material =='AL') & (raceway == True): max_current = max_conductor_current[conductor_current_index]
code_table = CEC_table4
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 "Table1" WHERE "90" > ? ', (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'): elif (code =='NEC') & (material =='CU'):
return (' I haven\'t created this table yet') return (' I haven\'t created this table yet')
elif (code =='NEC') & (material =='AL'): elif (code =='NEC') & (material =='AL'):
@ -217,24 +364,7 @@ def conductor_size(current, temp = 75, material = 'cu', code = 'CEC', raceway =
else: else:
return ('The variables were\'t right, but I\'m a loss to why.') return ('The variables were\'t right, but I\'m a loss to why.')
temp = str(temp) return [conductor_size,num_parallel]
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.
'''
'''