-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtablealgorithm.py
More file actions
68 lines (64 loc) · 2.08 KB
/
tablealgorithm.py
File metadata and controls
68 lines (64 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from tabulate import tabulate
# Stream format [Supply Temp (Ts), Target Temp (Tt), DH, CP, Cold(0)/Hot(1) {, Ts shift, Tt shift}]
def file_len(fname):
with open(fname) as f:
for i, l in enumerate(f):
pass
return i + 1
length=file_len('streams')
lc=1
stream=[]
with open('streams') as f:
while lc<=length:
l=[]
for i in f.readline().split():
l.append(float(i))
stream.append(l)
lc+=1
Tshift=[]
DTmin=float(input('DTmin - Minimum approach temperature (oC)= '))
n=len(stream) # Number of streams
for i in range(0,n):
if stream[i][4]==0:
stream[i].append(stream[i][0]+(DTmin/2))
stream[i].append(stream[i][1]+(DTmin/2))
Tshift.append(stream[i][0]+(DTmin/2))
Tshift.append(stream[i][1]+(DTmin/2))
else:
stream[i].append(stream[i][0]-(DTmin/2))
stream[i].append(stream[i][1]-(DTmin/2))
Tshift.append(stream[i][0]-(DTmin/2))
Tshift.append(stream[i][1]-(DTmin/2))
Tshift.sort()
streamshift=[]
for x in range(1,len(Tshift)):
CP=0
for i in range(0,n):
if stream[i][4]==0:
if stream[i][5]<=Tshift[x-1] and stream[i][6]>=Tshift[x]:
CP+=stream[i][3]
else:
if stream[i][6]<=Tshift[x-1] and stream[i][5]>=Tshift[x]:
CP-=stream[i][3]
streamshift.append([CP*(Tshift[x]-Tshift[x-1]),Tshift[x-1]])
streamshift.reverse()
heatflow=[]
heat=0
for i in range(0,len(streamshift)):
heat-=streamshift[i][0]
heatflow.append([heat,streamshift[i][1]])
lowest=heatflow[0][0]
pinch=heatflow[0][1]
for i in range(0,len(heatflow)):
if heatflow[i][0]<lowest:
lowest=heatflow[i][0]
pinch=heatflow[i][1]
res=open('.qcmin','w')
results=open('results','w')
phot= pinch+DTmin/2
pcold=pinch-DTmin/2
qhmin=-lowest
qcmin=heatflow[len(heatflow)-1][0]-lowest
res.write(str(qcmin))
results.write(tabulate([['QCmin',qcmin,'kW'],['QHmin',qhmin,'kW'],['Pinch (Shifted)',pinch,'oC'],['Pinch (Hot streams)',phot,'oC'],['Pinch (Cold streams)',pcold,'oC']]))
print('Results stored in results file')