File size: 9,657 Bytes
db79a6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import matplotlib.pyplot as plt 

class PinchPlot:

    def drawTemperatureInterval(self, _temperatures, streams):
        fig, ax = plt.subplots()

        plt.title('Shifted Temperature Interval Diagram')
        plt.ylabel('Shifted Temperature S (degC)')
        ax.set_xticklabels([])

        xOffset = 50

        for temperature in _temperatures:
            plt.plot([0, xOffset * (streams.numberOf + 1)], [temperature, temperature], ':k', alpha=0.8)

        arrow_width = streams.numberOf * 0.05
        head_width = arrow_width * 15
        head_length = _temperatures[0] * 0.02
        i = 1
        for stream in streams:
            if stream['type'] == 'HOT':
                plt.text(xOffset, stream['ss'], str(i), bbox=dict(boxstyle='round', alpha=1, fc='tab:red', ec="k"))
                plt.arrow(xOffset, stream['ss'], 0, stream['st'] - stream['ss'], color='tab:red', ec='k', alpha=1,
                        length_includes_head=True, width=arrow_width, head_width=head_width, head_length=head_length)
            else:
                plt.text(xOffset, stream['ss'], str(i), bbox=dict(boxstyle='round', alpha=1, fc='tab:blue', ec="k"))
                plt.arrow(xOffset, stream['ss'], 0, stream['st'] - stream['ss'], color='tab:blue', ec='k', alpha=1,
                        length_includes_head=True, width=arrow_width, head_width=head_width, head_length=head_length)
            xOffset = xOffset + 50
            i = i + 1

    def drawProblemTable(self, problemTable, _temperatures):
        fig, ax = plt.subplots(figsize=(6, 6))
        ax.axis('tight')
        ax.axis('off')
        ax.set_title('Problem Table')

        colLabels = ['$Interval: S_i - S_{i+1}$', '$\\Delta T (\\degree C)$', '$\\Delta CP (kW / \\degree C)$', '$\\Delta H (kW)$', '']
        cellText = []

        i = 1
        for interval in problemTable:
            cellRow = []
            cellRow.extend(['{}: {} - {}'.format(i, _temperatures[i - 1], _temperatures[i]),
                interval['deltaS'], interval['deltaCP'], interval['deltaH']])

            if interval['deltaH'] > 0:
                cellRow.append('Surplus')
            elif interval['deltaH'] == 0:
                cellRow.append('-')
            else:
                cellRow.append('Deficit')
            cellText.append(cellRow)
            i = i + 1

        table = ax.table(cellText=cellText, colLabels=colLabels, loc='center')
        table.auto_set_column_width([0, 1, 2, 3, 4])
        table.scale(1.3, 1.3)


    def drawHeatCascade(self, unfeasibleHeatCascade, heatCascade, hotUtility):
        fig, axs = plt.subplots(1, 2, figsize=(10, 6))
        axs[0].axis('auto')
        axs[0].axis('off')
        axs[1].axis('auto')
        axs[1].axis('off')

        axs[0].set_title('Unfeasible Heat Cascade')
        axs[1].set_title('Feasible Heat Cascade')

        cellText = []
        cellText.append(['', '', 'Hot Utility: 0'])
        cellText.append(['Interval', '$\\Delta H (kW)$', 'Exit H (total kW)'])

        i = 1
        for interval in unfeasibleHeatCascade:
            cellText.append([str(i), interval['deltaH'], interval['exitH']])
            i = i + 1

        cellText.append(['', '', 'Cold Utility: {}'.format(unfeasibleHeatCascade[-1]['exitH'])])
        table = axs[0].table(cellText=cellText, loc='center')
        table.auto_set_column_width([0, 1, 2])
        table.scale(1.3, 1.3)

        cellText = []
        cellText.append(['', '', 'Hot Utility: {}'.format(hotUtility)])
        cellText.append(['Interval', '$\\Delta H (kW)$', 'Exit H (total kW)'])

        i = 1
        for interval in heatCascade:
            cellText.append([str(i), interval['deltaH'], interval['exitH']])
            i = i + 1

        cellText.append(['', '', 'Cold Utility: {}'.format(heatCascade[-1]['exitH'])])
        table = axs[1].table(cellText=cellText, loc='center')
        table.auto_set_column_width([0, 1, 2])
        table.scale(1.3, 1.3)


    def drawShiftedCompositeDiagram(self, shiftedCompositeDiagram, coldUtility, _temperatures, hotUtility, pinchTemperature, processdesignation, localisation):
        fig = plt.figure()
        plt.plot(shiftedCompositeDiagram['hot']['H'], shiftedCompositeDiagram['hot']['T'], 'tab:red')
        plt.plot(shiftedCompositeDiagram['cold']['H'], shiftedCompositeDiagram['cold']['T'], 'tab:blue')

        plt.plot(shiftedCompositeDiagram['hot']['H'], shiftedCompositeDiagram['hot']['T'], 'ro')
        plt.plot(shiftedCompositeDiagram['cold']['H'], shiftedCompositeDiagram['cold']['T'], 'bo')

        maxColdH = max(shiftedCompositeDiagram['cold']['H'])

        try:
            pinchIndex = shiftedCompositeDiagram['cold']['T'].index(pinchTemperature)
            pinchH = shiftedCompositeDiagram['cold']['H'][pinchIndex]
            plt.plot([pinchH, pinchH], [_temperatures[0], _temperatures[-1]], ':')
        except ValueError:
            pass

        a = plt.fill_between([coldUtility, shiftedCompositeDiagram['cold']['H'][0]-hotUtility], [shiftedCompositeDiagram['cold']['T'][0]])
        a.set_hatch('\\')
        a.set_facecolor('w')
        plt.grid(True)
        if localisation == 'DE':
            plt.title('Verschobene Verbundkurven ({})'.format(processdesignation))#plt.title('Shifted Temperature-Enthalpy Composite Diagram')
            plt.xlabel('Enthalpiestrom H in kW')
            plt.ylabel('Verschobene Temperatur in °C')
        elif localisation == 'EN':
            plt.title('Shifted Composite Diagram')
            plt.xlabel('Enthalpy H in kW')
            plt.ylabel('Shifted Temperature T in °C')

    def drawCompositeDiagram(self, compositeDiagram, shiftedCompositeDiagram, coldUtility, 
                             _temperatures, tmin, hotUtility, pinchTemperature, processdesignation, localisation):
        fig = plt.figure()
        plt.plot(compositeDiagram['hot']['H'], compositeDiagram['hot']['T'], 'tab:red')
        plt.plot(compositeDiagram['cold']['H'], compositeDiagram['cold']['T'], 'tab:blue')

        plt.plot(compositeDiagram['hot']['H'], compositeDiagram['hot']['T'], 'ro')
        plt.plot(compositeDiagram['cold']['H'], compositeDiagram['cold']['T'], 'bo')

        maxColdH = max(compositeDiagram['cold']['H'])

        try:
            pinchIndex = shiftedCompositeDiagram['cold']['T'].index(pinchTemperature)
            pinchH = shiftedCompositeDiagram['cold']['H'][pinchIndex]
            plt.plot([pinchH, pinchH], [_temperatures[0], _temperatures[-1]], ':')
        except ValueError:
            pass

        plt.grid(True)
        if localisation == 'DE':
            plt.title('Verbundkurven ({})'.format(processdesignation))#plt.title('Shifted Temperature-Enthalpy Composite Diagram')
            plt.xlabel('Enthalpiestrom H in kW')
            plt.ylabel('Temperatur in °C')
        elif localisation == 'EN':
            plt.title('Composite Diagram ({})'.format(processdesignation))
            plt.xlabel('Enthalpy H in kW')
            plt.ylabel('Temperature T in °C')


    def drawGrandCompositeCurve(self, processdesignation, heatCascade, grandCompositeCurve, _temperatures, pinchTemperature, localisation):
        fig = plt.figure(num='{}'.format(processdesignation))
        if heatCascade[0]['deltaH'] > 0:  
            plt.plot([grandCompositeCurve['H'][0],grandCompositeCurve['H'][1]], [grandCompositeCurve['T'][0],grandCompositeCurve['T'][1]], 'tab:red')
            plt.plot([grandCompositeCurve['H'][0],grandCompositeCurve['H'][1]], [grandCompositeCurve['T'][0],grandCompositeCurve['T'][1]], 'ro')
        elif heatCascade[0]['deltaH'] < 0:
            plt.plot([grandCompositeCurve['H'][0],grandCompositeCurve['H'][1]], [grandCompositeCurve['T'][0],grandCompositeCurve['T'][1]], 'tab:blue')
            plt.plot([grandCompositeCurve['H'][0],grandCompositeCurve['H'][1]], [grandCompositeCurve['T'][0],grandCompositeCurve['T'][1]], 'bo')

        for i in range(1, len(_temperatures)-1):
            if heatCascade[i]['deltaH'] > 0:
                plt.plot([grandCompositeCurve['H'][i],grandCompositeCurve['H'][i+1]], [grandCompositeCurve['T'][i],grandCompositeCurve['T'][i+1]], 'tab:red')
                plt.plot([grandCompositeCurve['H'][i],grandCompositeCurve['H'][i+1]], [grandCompositeCurve['T'][i],grandCompositeCurve['T'][i+1]], 'ro')
            elif heatCascade[i]['deltaH'] < 0:
                plt.plot([grandCompositeCurve['H'][i],grandCompositeCurve['H'][i+1]], [grandCompositeCurve['T'][i],grandCompositeCurve['T'][i+1]], 'tab:blue')
                plt.plot([grandCompositeCurve['H'][i],grandCompositeCurve['H'][i+1]], [grandCompositeCurve['T'][i],grandCompositeCurve['T'][i+1]], 'bo')
            elif heatCascade[i]['deltaH'] == 0 and grandCompositeCurve['H'][i]!=0:
                plt.plot([grandCompositeCurve['H'][i],grandCompositeCurve['H'][i+1]], [grandCompositeCurve['T'][i],grandCompositeCurve['T'][i+1]], 'tab:blue')
                plt.plot([grandCompositeCurve['H'][i],grandCompositeCurve['H'][i+1]], [grandCompositeCurve['T'][i],grandCompositeCurve['T'][i+1]], 'bo')

        plt.plot([0, grandCompositeCurve['H'][-1]], [pinchTemperature, pinchTemperature], ':')

        plt.grid(True)
        if localisation == 'DE':
            plt.title('Großverbundkurve ({})'.format(processdesignation))
            plt.xlabel('Nettoenthalpiestromänderung ∆H [kW]')
            plt.ylabel('Verschobene Temperatur [°C]')
        elif localisation == 'EN':
            plt.title('Grand Composite Diagram ({})'.format(processdesignation))
            plt.xlabel('Net Enthalpy Change ∆H in kW')
            plt.ylabel('Shifted Temperature T in °C')

    def showPlots():
        plt.show()