Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Team-68-Project-2/Team_68_Project_2_Model.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
287 lines (206 sloc)
10.5 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Authors: | |
Dominic Keeler, keeler0@purdue.edu | |
Noah Strawhacker, nstrawha@purdue.edu | |
Eddie Sun, sun1271@purdue.edu | |
Sam Norwood, snorwoo@purdue.edu | |
Description: | |
The following code determines the optimal combination of parts for use in a given | |
model by iterating through each reasonable combination and determining the combination | |
with the lowest price. | |
""" | |
"""--------------- Imports ---------------""" | |
from Data_Functions import * | |
from Energy_and_Mass_Functions import * | |
from Calculation_Functions import * | |
"""--------------- Model parameters ---------------""" | |
# Given | |
flowIn = 0.007505 | |
# flowIn = 0.142 | |
buildingCost = 1500000 + 2500000 | |
maxHeight = 30 # ft | |
ethanolEnergyDensity = 80.1 * 1000000 # J/gal | |
# Piping | |
pipeLengths = [5, 30, 30, 20] # ft, from end to start | |
numValves = 8 | |
numWastePumps = 3 | |
numBends = 2 | |
bendAngles = 90 # deg | |
requiredOutFlowRate = 100000 # gal/day | |
# Conversions | |
maxHeight = 30 / 3.281 # m | |
pipeLengths = [(length / 3.281) for length in pipeLengths] # m | |
requiredOutFlowRate = 100000 / (2.282 * 10**7) # m^3/s | |
"""--------------- Part Specifications ---------------""" | |
# pumps | |
pumpEff = 0.92 # chosen previously | |
pumpEPR = 12.0 # m, from maxHeight above | |
# pipes | |
pipeDFF = 0.002 # chosen previously | |
pipeValveBendDiam = 0.10 # m | |
# valves | |
valveFlowCoeff = 500 # chosen previously | |
# bends | |
bendAngles = bendAngles # from above | |
bendLossCoeff = 0.3 | |
# ductwork | |
ductworkDiam = 1.0 # m | |
ductworkLength = 1.524 # m | |
"""--------------- Functions ---------------""" | |
def getAllData(): | |
# get energy data listing | |
pumpsData = getPumpsData() | |
pipesData = getPipesData() | |
valvesData = getValvesData() | |
bendsData = getBendsData() | |
# get mass data listing | |
fermentersData = getFermentersData() | |
ductworkData = getDuctworkData() | |
filtsAndDHsData = getFiltsAndDHsData() | |
distillersData = getDistillersData() | |
return(pumpsData, pipesData, valvesData, bendsData, fermentersData, ductworkData, | |
filtsAndDHsData, distillersData) | |
def getBestUnitCombo(fermentersData, filtsAndDHsData, distillersData): | |
# initialize empty lists | |
combosList = [] | |
priceList = [] | |
# run through each unit combination | |
for a in range(len(fermentersData)): | |
for b in range(len(filtsAndDHsData)): | |
for c in range(len(distillersData)): | |
for d in range(len(filtsAndDHsData)): | |
# determine the ethanol concentration and price for the current combination | |
ethConc, finalMass = getEthConc(1, fermentersData[a][1], filtsAndDHsData[b][1], distillersData[c][1], filtsAndDHsData[d][1]) | |
price = fermentersData[a][2] + filtsAndDHsData[b][2] + distillersData[c][2] + filtsAndDHsData[d][2] | |
# check to see if ethanol concentration fulfills requirements | |
if ethConc >= 0.98: | |
# append successful combinations and their prices to lists | |
combosList.append([a, b, c, d]) | |
priceList.append(price) | |
# find the minumum price and corresponding combination | |
minPrice = min(priceList) | |
minPriceIndex = priceList.index(minPrice) | |
bestCombo = combosList[minPriceIndex] | |
return(bestCombo) | |
def getEnergyReturn(pumpEff, ethConc, flowIn, pipeLengths, pipeDFF, bendLossCoeff, diam, valveCoeff, fermE, filtE, distE, dehyE, fermEff, filtEff, distEff, dehyEff): | |
totalEPerS = getTotalENeeded(flowIn, pumpEff, diam, fermE, filtE, distE, dehyE, fermEff, filtEff, distEff, dehyEff) | |
flowOut, flowThroughFerm, flowThroughFilt, flowThroughDist, flowThroughDehy, eLostValvesFerm, eLostValvesFilt, eLostValvesDist, eLostValvesDehy = getFlowRates(flowIn, pipeLengths, pipeDFF, bendLossCoeff, diam, valveCoeff, fermEff, filtEff, distEff, dehyEff) | |
flowOut *= 264.172 # gal/s | |
energyOut = ethConc * flowOut * ethanolEnergyDensity # J/s | |
energyReturnRatio = energyOut / (eLostValvesFerm + eLostValvesFilt + eLostValvesDist + eLostValvesDehy + totalEPerS) | |
return(energyReturnRatio) | |
def getCapCost(pipeLengths, pipeDFF, numBends, bendAngle, numValves, valveCoeff, ductworkLength, diam, ductworkDiam, pipesData, valvesData, bendsData, ductworkData): | |
# find the list corresponding to the used pipes | |
for part in pipesData: | |
if pipeDFF in part and diam in part: | |
pipeCostPerM = part[-1] | |
break | |
# find the total cost of pipes | |
totalM = 0 | |
for length in pipeLengths: | |
totalM += length | |
pipesCost = totalM * pipeCostPerM | |
# find the list corresponding to the used bends | |
for part in bendsData: | |
if float(bendAngle) in part and diam in part: | |
costPerBend = part[-1] | |
break | |
# find the total cost of bends | |
bendsCost = numBends * costPerBend | |
# find the list corresponding to the used valves | |
for part in valvesData: | |
if float(valveCoeff) in part and diam in part: | |
costPerValve = part[-1] | |
break | |
# find the total cost of valves | |
valvesCost = numValves * costPerValve | |
# find the list corresponding to the used ductwork | |
for part in ductworkData: | |
if ductworkDiam in part: | |
ductCostPerM = part[-1] | |
break | |
# find the total cost of ductwork | |
ductCost = ductworkLength * ductCostPerM | |
pipingCost = pipesCost + bendsCost + valvesCost + ductCost | |
return(pipingCost) | |
def outputProductionResults(bestFermenter, bestFilter, bestDistiller, bestDehydrator): | |
print("Production units used:") | |
print("Fermentation unit in the format [kWh/day, % of sugar converted, $ per m^3/sec of flow]:") | |
print(f" {bestFermenter} \n") | |
print("Filtration unit in the format [kWh/day, % by mass of fiber removed, $ per m^3/sec of flow]:") | |
print(f" {bestFilter} \n") | |
print("Distillation unit in the format [kWh/day, % of alcohol in exit stream, $ per m^3/sec of flow]:") | |
print(f" {bestDistiller} \n") | |
print("Dehydration unit in the format [kWh/day, % by mass of water removed, $ per m^3/sec of flow]:") | |
print(f" {bestDehydrator} \n") | |
return() | |
def outputPipingResults(pipeLength, numValves, numBends, diam, DFF, bendAngles, valveFlowCoeff, ductworkLength, ductworkDiam): | |
print(f"Piping system used: \n") | |
print(f" Piping system diameter: {diam}") | |
print(f" Total pipe length and DFF: {pipeLength:.2f} m of pipes, friction factor {DFF}") | |
print(f" Number and angle of bends: {numBends} at {bendAngles} degrees") | |
print(f" Number of valves: {numValves}") | |
print(f" Valve flow coeff.: {valveFlowCoeff}") | |
print(f" Ductwork length: {ductworkLength}") | |
print(f" Ductwork diameter: {ductworkDiam} \n") | |
return() | |
def outputFlowResults(pipingCapCost, totalE, energyReturnRatio, ethConc, fermEff, filtEff, distEff, dehyEff): | |
flowOut, flowThroughFerm, flowThroughFilt, flowThroughDist, flowThroughDehy, eLostValvesFerm, eLostValvesFilt, eLostValvesDist, eLostValvesDehy = getFlowRates(flowIn, pipeLengths, pipeDFF, bendLossCoeff, pipeValveBendDiam, valveFlowCoeff, fermEff, filtEff, distEff, dehyEff) | |
print(flowThroughFerm) | |
print(flowThroughFilt) | |
print(flowThroughDist) | |
print(flowThroughDehy) | |
print(f"The total capital cost of the facility and rebuilt housing is ${buildingCost:,.2f}.") | |
print(f"The total capital cost of the piping system is ${pipingCapCost:,.2f}. \n") | |
print(f"The energy needed to fun the facility in one day is {totalE:,.0f} kWh. \n") | |
print(f"The resulting ethanol concentration in the output flow is {ethConc:.3f}.") | |
print(f"The energy output/input ratio is {energyReturnRatio:.2f}.") | |
print(f"The facility must be supplied with {100000 / (0.2 * 0.98):,.0f} gallons of slurry per day.") | |
"""--------------- Main function ---------------""" | |
def main(): | |
# get all data | |
pumpsData, pipesData, valvesData, bendsData, fermentersData, ductworkData, filtsAndDHsData, distillersData = getAllData() | |
# find the cheapest combination of ethanol production units | |
bestCombo = getBestUnitCombo(fermentersData, filtsAndDHsData, distillersData) | |
bestFermenter = fermentersData[bestCombo[0]] | |
bestFilter = filtsAndDHsData[bestCombo[1]] | |
bestDistiller = distillersData[bestCombo[2]] | |
bestDehydrator = filtsAndDHsData[bestCombo[3]] | |
# get efficiences of units | |
fermEff = bestFermenter[1] | |
filtEff = bestFilter[1] | |
distEff = bestDistiller[1] | |
dehyEff = bestDehydrator[1] | |
# get energy use of units | |
fermE = bestFermenter[0] | |
filtE = bestFilter[0] | |
distE = bestDistiller[0] | |
dehyE = bestDehydrator[0] | |
# find total pipe length | |
totalPipeLength = 0 | |
for length in pipeLengths: | |
totalPipeLength += length | |
# find the resulting concentration of ethanol with the cheapest combination of units | |
ethConc, totalMass = getEthConc(1, fermentersData[bestCombo[0]][1], filtsAndDHsData[bestCombo[1]][1], | |
distillersData[bestCombo[2]][1], filtsAndDHsData[bestCombo[3]][1]) | |
# find the capital cost of the piping system | |
pipingCapCost = getCapCost(pipeLengths, pipeDFF, numBends, bendAngles, numValves, | |
valveFlowCoeff, ductworkLength, pipeValveBendDiam, ductworkDiam, | |
pipesData, valvesData, bendsData, ductworkData) | |
# find the energy needed to run the facility for one second | |
totalE = getTotalENeeded(flowIn, pumpEff, wastePumpsEff, pipeValveBendDiam, fermE, filtE, | |
distE, dehyE, fermEff, filtEff, distEff, dehyEff) | |
# find the energy output/input ratio | |
energyReturnRatio = getEnergyReturn(pumpEff, ethConc, flowIn, pipeLengths, | |
pipeDFF, bendLossCoeff, pipeValveBendDiam, | |
valveFlowCoeff, fermE, filtE, distE, dehyE, | |
fermEff, filtEff, distEff, dehyEff) | |
# output the results of the facility to the user | |
outputProductionResults(bestFermenter, bestFilter, bestDistiller, bestDehydrator) | |
outputPipingResults(totalPipeLength, numValves, numBends, pipeValveBendDiam, | |
pipeDFF, bendAngles, valveFlowCoeff, ductworkLength, ductworkDiam) | |
outputFlowResults(pipingCapCost, totalE, energyReturnRatio, ethConc, fermEff, filtEff, | |
distEff, dehyEff) | |
return() | |
if __name__ == "__main__": | |
main() |