프로젝트

일반

사용자정보

개정판 2ccb1c69

ID2ccb1c69244182f0c173c67ef1a07acc24e538a9
상위 ad1cd883
하위 181ce52d

백흠경이(가) 5년 이상 전에 추가함

issue #1202: calculate press drop(45%)

Change-Id: I9baaf5db6b8cc2a4537629b022866ddfe4c5c0d8

차이점 보기:

HYTOS/HYTOS/MainWindow.py
36 36
from EngineeringLineNoTextItem import QEngineeringLineNoTextItem
37 37
from QEngineeringSizeTextItem import QEngineeringSizeTextItem
38 38
from EngineeringErrorItem import QEngineeringErrorItem
39
from EngineeringStreamlineItem import QEngineeringStreamlineItem
39 40
from AppDocData import *
40 41
import SymbolTreeWidget
41
import SymbolEditorDialog
42
from UserInputAttribute import UserInputAttribute
43
from TextItemFactory import TextItemFactory
44 42
import uuid
45 43

  
46 44
class MainWindow(QMainWindow, MainWindow_UI.Ui_MainWindow, SingletonInstane):
......
1030 1028
            count = len(self.actionLine.tag.streamline._vertices)
1031 1029
            if count > 1:                            
1032 1030
                self.add_hmb_data(self.actionLine.tag.streamline)
1033
                self.actionLine.tag.streamline.transfer.onRemoved.connect(self.on_stream_line_deleted)
1031
                self.actionLine.tag.streamline.transfer.onRemoved.connect(self.on_item_removed)
1034 1032
                self.load_HMB()
1035 1033
        finally:
1036 1034
            self.actionLine.tag.reset()
......
1176 1174
        @date       2018.05.25
1177 1175
        @author     Jeongwoo
1178 1176
    '''
1179
    def itemRemoved(self, item):
1177
    def on_item_removed(self, item):
1180 1178
        try:
1181 1179
            matches = [_item for _item in self.graphicsView.scene.items() if hasattr(_item, 'connectors') and \
1182 1180
            [connector for connector in _item.connectors if connector.connectedItem is not None and connector.connectedItem.parentItem() is item]]
1183 1181
            for match in matches:
1184 1182
                for connector in match.connectors:
1185
                    if connector.connectedItem.parentItem() is item: connector.connect(None)
1186

  
1187
            matches = [_item for _item in self.graphicsView.scene.items() if type(_item) is QEngineeringLineNoTextItem]
1188
            for match in matches:
1189
                if item is match.prop('From'):
1190
                    match.set_property('From', None)
1191
                elif item is match.prop('To'):
1192
                    match.set_property('To', None)
1193

  
1194
                for run in match.runs:
1195
                    if item in run.items:
1196
                        index = run.items.index(item)
1197
                        run.items.pop(index)
1183
                    if connector.connectedItem is item: connector.connect(None)
1198 1184

  
1199 1185
            matches = [_item for _item in self.graphicsView.scene.items() if hasattr(_item, 'owner')]
1200 1186
            for match in matches:
......
1216 1202
                        break
1217 1203
                if done: break
1218 1204

  
1205
            if type(item) is QEngineeringStreamlineItem:
1206
                self.on_stream_line_deleted(item)
1207

  
1219 1208
            if item.scene() is not None:
1220 1209
                item.scene().removeItem(item)
1221 1210
                del item
1222 1211
        except Exception as ex:
1223
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
1212
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
1224 1213
            self.addMessage.emit(MessageType.Error, message)
1225 1214

  
1226 1215
    '''
......
1246 1235
                    if category == 'Stream Line':
1247 1236
                        item = QEngineeringStreamlineItem.fromDatabase(componentInfos) 
1248 1237
                        if item is not None:
1249
                            item.transfer.onRemoved.connect(self.itemRemoved)
1238
                            item.transfer.onRemoved.connect(self.on_item_removed)
1250 1239
                            self.graphicsView.scene.addItem(item)                   
1251 1240
                    else:
1252 1241
                        item = SymbolSvgItem.fromDatabase(componentInfos)
1253 1242
                        if item is not None:
1254
                            item.transfer.onRemoved.connect(self.itemRemoved)
1243
                            item.transfer.onRemoved.connect(self.on_item_removed)
1255 1244
                            app_doc_data.symbols.append(item)
1256 1245
                            self.addSvgItemToScene(item)
1257 1246

  
HYTOS/HYTOS/Shapes/EngineeringConnectorItem.py
88 88

  
89 89
    def __repr__(self):
90 90
        """ return string represent parent item and connector index """
91
        return '{}_N{}'.format(self.parentItem().name, self._conn_index)
91
        return '{}_{}_N{}'.format(self.parentItem().name, self.parentItem().index, self._conn_index)
92 92

  
93 93
    @staticmethod
94 94
    def find_connector(uid):
HYTOS/HYTOS/Shapes/EngineeringLoopItem.py
2 2
import os.path
3 3
import copy
4 4
import sys
5

  
5 6
try:
6 7
    from PyQt5.QtCore import Qt, QPointF, QRectF, pyqtSignal, QObject, QT_VERSION_STR, QRect
7 8
    from PyQt5.QtGui import QImage, QPixmap, QPainterPath, QBrush, QPen, QTransform, QFont, QColor
8
    from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QGraphicsItem, QAbstractGraphicsShapeItem, QGraphicsTextItem, QGraphicsRectItem
9
    from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QGraphicsItem, QAbstractGraphicsShapeItem, \
10
        QGraphicsTextItem, QGraphicsRectItem
9 11
except ImportError:
10 12
    try:
11 13
        from PyQt4.QtCore import Qt, QRectF, pyqtSignal, QRect, QObject, QT_VERSION_STR
......
16 18
from EngineeringAbstractItem import QEngineeringAbstractItem
17 19
from AppDocData import *
18 20

  
21

  
19 22
class QEngineeringLoopItem(QEngineeringAbstractItem):
20 23
    """ This is QEngineeringLoopItem class """
21
    
24

  
22 25
    def __init__(self, _items):
23
        """ constructure """
26
        """ constructor """
24 27
        import uuid
25 28

  
26 29
        QEngineeringAbstractItem.__init__(self)
......
33 36
        self.pressure_drops = {}
34 37
        self.density_elevations = {}
35 38
        self.extras = {}
36
 
39

  
40
        self.total_device_loss = None
41
        self.suction_line_friction_loss = None
42
        self.discharge_line_friction_loss = None
43
        self.line_total_friction_loss = None
44

  
37 45
    def __repr__(self):
38 46
        """ return string represent loop item """
39 47
        return '{}'.format(self.items)
......
51 59
        from AppDocData import AppDocData
52 60

  
53 61
        try:
54
            #(1) 기기들의 del.p, p, el을 넣음
62
            # (1) 기기들의 del.p, p, el을 넣음
55 63
            self.p_eq_input()
56 64

  
57
            #(3) 계산 시작
65
            # (3) 계산 시작
58 66
            self.discharge_cal()
59
            if not self.items[1] in self.pressures or not self.pressures[self.items[1]]: self.suction_cal()
67
            if not self.items[1] in self.pressures or not self.pressures[self.items[1]]:
68
                self.suction_cal()
69

  
70
            # Hole Calculation
71
            # cv와 pump가 다 없을때 (Hole Case)
72
            matches = [i for i in range(len(self.items)) if not self.items[i] in self.pressures]
73
            if matches:
74
                hole_start, hole_end = min(matches), max(matches)
75
                if hole_end - hole_start > 3:
76
                    self.hole_calc(hole_start, hole_end)
77
                    self.loss_input()
78
                    self.cv_dp_cal()
79
                    self.hole_recalc(hole_start, hole_end)
80

  
81
                    name = str(self.items[hole_start+1])[:3]
82
                    if name == 'CV_':
83
                        self.pressure_drops[self.item[hole_start + 1]] = self.pressures[self.item[hole_start+1]] - \
84
                                                                         self.pressures[self.item[hole_start+2]]
85
                    elif name == 'R_P' or name == 'L_P' or name == 'V_P' or name == 'L_K':
86
                        self.pressure_drops[self.item[hole_start + 1]] = self.pressures[self.item[hole_start + 2]] - \
87
                                                                         self.pressures[self.item[hole_start + 1]]
88
        except Exception as ex:
89
            from App import App
90
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
91
                                                           sys.exc_info()[-1].tb_lineno)
92
            App.mainWnd().addMessage.emit(MessageType.Error, message)
93

  
94
    def hole_calc(self, hole_start, hole_end):
95
        try:
96
            self.pressures[self.items[hole_end]] = self.pressures[self.items[hole_end + 1]]
97
            for i in range(hole_end - 1, hole_start + 3, -3):
98
                # (1) density 입력
99
                self.discharge_den(i)
100

  
101
                # (2) static P를 계산
102
                self.discharge_static_cal(i)
103

  
104
                # (3) pressure drop 계산
105
                if self.items[i].data.phase_type == 'Liquid' or self.items[i].data.phase_type == 'Mixed':
106
                    self.pressure_drops[self.items[i]] = self.items[i].data.pressure_drop_friction
107
                    res = self.hole_p_cal(i)
108
                    if res == 0:
109
                        break
110
                elif self.items[i].phase_type == 'Vapor':
111
                    pass  # TODO:
112
        except Exception as ex:
113
            from App import App
114
            message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename,
115
                                                           sys.exc_info()[-1].tb_lineno)
116
            App.mainWnd().addMessage.emit(MessageType.Error, message)
117

  
118
    def hole_recalc(self, hole_start, hole_end):
119
        try:
120
            self.pressures[self.items[hole_end]] = self.pressures[self.items[hole_end + 1]]
121
            for i in range(hole_end - 1, hole_start + 3, -3):
122
                # (1) density 입력
123
                self.discharge_den(i)
124

  
125
                # (2) static P를 계산
126
                self.discharge_static_cal(i)
127

  
128
                # (3) pressure drop 계산
129
                if self.items[i].data.phase_type == 'Liquid' or self.items[i].data.phase_type == 'Mixed':
130
                    self.pressure_drops[self.items[i]] = self.items[i].data.pressure_drop_friction
131
                    res = self.hole_p_cal(i)
132
                    if res == 0:
133
                        break
134
                elif self.items[i].phase_type == 'Vapor':
135
                    pass  # TODO:
136
        except Exception as ex:
137
            from App import App
138
            message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename,
139
                                                           sys.exc_info()[-1].tb_lineno)
140
            App.mainWnd().addMessage.emit(MessageType.Error, message)
141

  
142
    def cv_dp_cal(self):
143
        try:
144
            acv = [item for item in self.items if not (item in self.pressure_drops and self.pressure_drops[item]) and
145
                   str(item)[:3] == 'CV_']
146
            if acv:
147
                pf = (self.total_device_loss if self.total_device_loss else 0) + (self.line_total_friction_loss if self.line_total_friction_loss else 0)
148
                method = 'bd'  # TODO:
149
                if method == 'bd':
150
                    self.bd_cal(pf, acv[0])
151
                elif method == 'lummus':
152
                    pass
153
                elif method == 'mixed':
154
                    pass
155
                elif method == 'aramco':
156
                    pass
157
                else:
158
                    pass
159
        except Exception as ex:
160
            from App import App
161
            message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename,
162
                                                           sys.exc_info()[-1].tb_lineno)
163
            App.mainWnd().addMessage.emit(MessageType.Error, message)
164

  
165
    def bd_cal(self, pf, acv):
166
        from AppDocData import AppDocData
167

  
168
        try:
169
            bdcvdp = [None, None, None]
170

  
171
            bdcvdp[0] = ((1.1135 * ((self.extras[acv] if self.extras[acv] else 0) / 100 + 1)) ** 2 - 1) * pf
172
            bdcvdp[1] = pf / 3
173

  
174
            app_doc_data = AppDocData.instance()
175
            units = [attr[1] for attr in app_doc_data.activeDrawing.attrs if attr[0] == 'Units'][0]
176
            unit = units['Pressure']
177
            if unit == 'kg/cm2':
178
                bdcvdp[2] = 0.7
179
            elif unit == 'psi':
180
                bdcvdp[2] = 0.7 / 1.033 * 14.7
181
            elif unit == 'bar':
182
                bdcvdp[2] = 0.7 / 1.033 * 1.013
183
            elif unit == 'mmHg':
184
                bdcvdp[2] = 0.7 / 1.033 * 760
185
            elif unit == 'kPa':
186
                bdcvdp[2] = 0.7 / 1.033 * 101.325
187
            elif unit == 'MPa':
188
                bdcvdp[2] = 0.7 / 1.033 * 0.101325
189

  
190
            if bdcvdp[0] > bdcvdp[1]:
191
                maxdp = bdcvdp[0]
192
            elif bdcvdp[0] < bdcvdp[1]:
193
                maxdp = bdcvdp[1]
194

  
195
            if maxdp < bdcvdp[2]:
196
                maxdp = bdcvdp[2]
197

  
198
            self.pressure_drops[acv] = maxdp
60 199
        except Exception as ex:
61
            from App import App 
62
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
200
            from App import App
201
            message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename,
202
                                                           sys.exc_info()[-1].tb_lineno)
203
            App.mainWnd().addMessage.emit(MessageType.Error, message)
204

  
205
    def loss_input(self):
206
        try:
207
            matches = [i for i in range(len(self.items)) if not self.items[i] in self.pressures]
208
            if matches:
209
                hole_start, hole_end = min(matches), max(matches)
210

  
211
                line_loss = 0
212
                # 라인(suc)
213
                for i in range(1, hole_start, 3):
214
                    line_loss = line_loss + self.pressure_drops[self.items[i]]
215
                self.suction_line_friction_loss = line_loss
216

  
217
                line_loss = 0
218
                for i in range(len(self.items) - 2, hole_start, -3):
219
                    if i == 3:
220
                        break
221
                    if self.items[i] in self.pressure_drops and self.pressure_drops[self.items[i]]:
222
                        line_loss += self.pressure_drops[self.items[i]]
223
                self.discharge_line_friction_loss = line_loss
224

  
225
                line_loss = 0
226
                self.line_total_friction_loss = self.suction_line_friction_loss + self.discharge_line_friction_loss
227

  
228
                # 기기(suc)
229
                # for a in range(2, hole_start)
230

  
231
                # 기기(dis)
232
        except Exception as ex:
233
            from App import App
234
            message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename,
235
                                                           sys.exc_info()[-1].tb_lineno)
63 236
            App.mainWnd().addMessage.emit(MessageType.Error, message)
64 237

  
65 238
    def discharge_cal(self):
66 239
        try:
67
            for i in range(len(self.items) - 2, 0, -3): # backward
68
                self.discharge_den(i)           #(1) density 입력
69
                self.discharge_static_cal(i)    #(2) static P를 계산
240
            for i in range(len(self.items) - 2, 1, -3):  # backward
241
                self.discharge_den(i)  # (1) density 입력
242
                self.discharge_static_cal(i)  # (2) static P를 계산
70 243

  
71
                #(3) pressure drop 계산
72
                #liquid 인 경우 stream 시트로부터 del.P를 입력해줌.
73
                #vapor인 경우 압력강하를 계산해주고 넣어주는 모듈
244
                # (3) pressure drop 계산
245
                # liquid 인 경우 stream 시트로부터 del.P를 입력해줌.
246
                # vapor인 경우 압력강하를 계산해주고 넣어주는 모듈
74 247
                if self.items[i].data.phase_type == 'Liquid' or self.items[i].data.phase_type == 'Mixed':
75
                    self.pressure_drops[self.items[i]] = self.items[i].press_drop
248
                    self.pressure_drops[self.items[i]] = self.items[i].data.pressure_drop_friction
76 249
                    asd = self.discharge_p_cal(i)
77
                    if asd == 0: break
250
                    if asd == 0:
251
                        break
78 252
                elif self.items[i].phase_type == 'Vapor':
79
                    pass #TODO: 
253
                    pass  # TODO:
80 254
        except Exception as ex:
81
            from App import App 
82
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
255
            from App import App
256
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
257
                                                          sys.exc_info()[-1].tb_lineno)
83 258
            App.mainWnd().addMessage.emit(MessageType.Error, message)
84 259

  
85 260
    def suction_cal(self):
86 261
        try:
87 262
            for i in range(1, len(self.items) - 1, 3):
88 263
                self.suction_find_line(i)
89
                self.suction_static_cal(i) #static P를 계산해줌
264
                self.suction_static_cal(i)  # static P를 계산해줌
90 265

  
91
                #라인이 liqiud 인지 vapor인지 판별
266
                # 라인이 liqiud 인지 vapor인지 판별
92 267
                if self.items[i].data.phase_type == 'Liquid' or self.items[i].data.phase_type == 'Mixed':
93
                    #liquid 인 경우 stream 데이타로부터 del.P를 입력해줌.
268
                    # liquid 인 경우 stream 데이타로부터 del.P를 입력해줌.
94 269
                    self.pressure_drops[self.items[i]] = self.items[i].data.pressure_drop_friction
95 270
                    res = self.suction_p_cal(i)
96
                    if res == 0: break
271
                    if res == 0:
272
                        break
97 273
                elif self.items[i].data.phase_type == 'Vapor':
98
                    pass #TODO:
274
                    pass  # TODO:
99 275
        except Exception as ex:
100
            from App import App 
101
            message = 'error occured({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
276
            from App import App
277
            message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename,
278
                                                          sys.exc_info()[-1].tb_lineno)
102 279
            App.mainWnd().addMessage.emit(MessageType.Error, message)
103 280

  
104 281
    def suction_find_line(self, i):
......
107 284
        elif self.items[i].data.phase_type == 'Vapor':
108 285
            self.suction_vapor_density(i)
109 286
        else:
110
            raise ValueError('You have to input the properties of stream <{}>\nCalculation will be terminated !'.format(self.items[i].data.stream_no))
287
            raise ValueError('You have to input the properties of stream <{}>\nCalculation will be terminated !'.format(
288
                self.items[i].data.stream_no))
111 289

  
112 290
    def suction_vapor_density(self, i):
113 291
        pass
......
115 293
    def suction_static_cal(self, i):
116 294
        try:
117 295
            if self.items[i].data.phase_type == 'Mixed':
118
                pass    #TODO:
296
                pass  # TODO:
119 297
            else:
120 298
                app_doc_data = AppDocData.instance()
121 299
                units = [attr[1] for attr in app_doc_data.activeDrawing.attrs if attr[0] == 'Units'][0]
122 300
                if units['Density'] == 'kg/m3':
123 301
                    density2 = self.density_elevations[self.items[i]]
124 302
                else:
125
                    density2 = self.density_elevations[self.items[i]] * 16.0185 #lb/ft3
303
                    density2 = self.density_elevations[self.items[i]] * 16.0185  # lb/ft3
126 304

  
127
                #2 elevation 받음
305
                # 2 elevation 받음
128 306
                if units['Length'] == 'm':
129
                    el1 = self.density_elevations[self.items[i-1]]
130
                    el2 = self.density_elevations[self.items[i+1]]
307
                    el1 = self.density_elevations[self.items[i - 1]]
308
                    el2 = self.density_elevations[self.items[i + 1]]
131 309
                elif units['Length'] == 'in':
132
                    el1 = self.density_elevations[self.items[i-1]] * 0.0254
133
                    el2 = self.density_elevations[self.items[i+1]] * 0.0254
310
                    el1 = self.density_elevations[self.items[i - 1]] * 0.0254
311
                    el2 = self.density_elevations[self.items[i + 1]] * 0.0254
134 312
                elif units['Length'] == 'ft':
135
                    el1 = self.density_elevations[self.items[i-1]] * 0.3048 
136
                    el2 = self.density_elevations[self.items[i+1]] * 0.3048
313
                    el1 = self.density_elevations[self.items[i - 1]] * 0.3048
314
                    el2 = self.density_elevations[self.items[i + 1]] * 0.3048
137 315
                elif units['Length'] == 'yd':
138
                    el1 = self.density_elevations[self.items[i-1]] * 0.9144
139
                    el2 = self.density_elevations[self.items[i+1]] * 0.9144
316
                    el1 = self.density_elevations[self.items[i - 1]] * 0.9144
317
                    el2 = self.density_elevations[self.items[i + 1]] * 0.9144
140 318
                elif units['Length'] == 'mm':
141
                    el1 = self.density_elevations[self.items[i-1]] * 0.001
142
                    el2 = self.density_elevations[self.items[i+1]] * 0.001
143
                else:    #mile
144
                    el1 = self.density_elevations[self.items[i-1]] * 1609.34
145
                    el2 = self.density_elevations[self.items[i+1]] * 1609.34
319
                    el1 = self.density_elevations[self.items[i - 1]] * 0.001
320
                    el2 = self.density_elevations[self.items[i + 1]] * 0.001
321
                else:  # mile
322
                    el1 = self.density_elevations[self.items[i - 1]] * 1609.34
323
                    el2 = self.density_elevations[self.items[i + 1]] * 1609.34
146 324

  
147
                #3. static head 계산
148
                stat_dp = (el2 - el1) * density2 / 1000 * 9.80665 / 101.325 #atm으로 계산된 dp
325
                # 3. static head 계산
326
                stat_dp = (el2 - el1) * density2 / 1000 * 9.80665 / 101.325  # atm으로 계산된 dp
149 327

  
150
                #4. 압력 유닛에 맞춰 뿌리기
328
                # 4. 압력 유닛에 맞춰 뿌리기
151 329
                if units['Pressure'] == 'kg/cm2':
152 330
                    self.pressure_drops[self.items[i - 1]] = stat_dp * 1.033
153 331
                elif units['Pressure'] == 'psi':
......
163 341
                elif units['Pressure'] == 'MPa':
164 342
                    self.pressure_drops[self.items[i - 1]] = stat_dp * 0.101325
165 343
        except Exception as ex:
166
            from App import App 
167
            message = 'error occured({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
344
            from App import App
345
            message = 'error occured({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename,
346
                                                          sys.exc_info()[-1].tb_lineno)
168 347
            App.mainWnd().addMessage.emit(MessageType.Error, message)
169 348

  
170 349
    def p_eq_input(self):
......
175 354
            self.pressures[self.items[-1]] = self.items[-1].data.pressure
176 355
            self.density_elevations[self.items[-1]] = self.items[-1].data.elevation
177 356

  
178
            for i in range(2, len(self.items) - 2, 3):
357
            for i in range(2, len(self.items) - 3, 3):
179 358
                dp_eq = str(self.items[i])[:3]
180
                if dp_eq == 'HEX' or dp_eq == 'M_D' or dp_eq == 'M_R': dp_eq = str(self.items[i])[:3]
359
                if dp_eq == 'HEX' or dp_eq == 'M_D' or dp_eq == 'M_R':
360
                    dp_eq = str(self.items[i])[:3]
181 361

  
182
                #pressure drop
183
                self.pressure_drops[self.items[i]] = self.items[i].data.pressure_drop
362
                # pressure drop
363
                if self.items[i].data.pressure_drop:
364
                    self.pressure_drops[self.items[i]] = self.items[i].data.pressure_drop
184 365
                if not self.items[i].data.pressure_drop:
185 366
                    pass
186 367

  
187
                #elevation
368
                # elevation
188 369
                if dp_eq[:3] == 'M_R':
189 370
                    self.density_elevations[self.items[i]] = self.items[i].data.elevation
190
                    self.density_elevations[self.items[i+1]] = self.items[i+1].data.elevation
371
                    self.density_elevations[self.items[i + 1]] = self.items[i + 1].data.elevation
191 372
                else:
192 373
                    self.density_elevations[self.items[i]] = self.items[i].data.elevation
193
                    self.density_elevations[self.items[i+1]] = self.items[i+1].data.elevation
374
                    self.density_elevations[self.items[i + 1]] = self.items[i + 1].data.elevation
194 375

  
195 376
                if dp_eq[:3] == 'L_P' or dp_eq[:3] == 'R_P' or dp_eq[:3] == 'V_P' or dp_eq[:3] == 'R_K':
196 377
                    self.extras[self.items[i]] = self.items[i].data.over_design_cv
197 378
                elif dp_eq[:3] == 'CV_':
198 379
                    self.extras[self.items[i]] = self.items[i].data.over_design_cv
199
                    self.extras[self.items[i+1]] = None #TODO:
380
                    self.extras[self.items[i + 1]] = None  # TODO:
200 381
        except Exception as ex:
201
            from App import App 
202
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
382
            from App import App
383
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
384
                                                          sys.exc_info()[-1].tb_lineno)
203 385
            App.mainWnd().addMessage.emit(MessageType.Error, message)
204 386

  
205 387
    def discharge_den(self, i):
......
207 389
            app_doc_data = AppDocData.instance()
208 390
            units = [attr[1] for attr in app_doc_data.activeDrawing.attrs if attr[0] == 'Units'][0]
209 391

  
210
            #1. density 받음
392
            # 1. density 받음
211 393
            if self.items[i].data.phase_type == 'Liquid' or self.items[i].data.phase_type == 'Mixed':
212 394
                self.density_elevations[self.items[i]] = self.items[i].density
213 395
            elif self.items[i].data.phase_type == 'Vapor':
214 396
                self.discharge_vapor_density(i)
215 397
        except Exception as ex:
216
            from App import App 
217
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
398
            from App import App
399
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
400
                                                          sys.exc_info()[-1].tb_lineno)
218 401
            App.mainWnd().addMessage.emit(MessageType.Error, message)
219 402

  
220 403
    def discharge_vapor_density(self, i):
......
227 410
            app_doc_data = AppDocData.instance()
228 411
            units = [attr[1] for attr in app_doc_data.activeDrawing.attrs if attr[0] == 'Units'][0]
229 412

  
230
            #1. density 받음
413
            # 1. density 받음
231 414
            if self.items[i].data.phase_type == 'Mixed':
232
                pass    #TODO: 
415
                pass  # TODO:
233 416
            else:
234 417
                if units['Density'] == 'kg/m3':
235 418
                    density2 = self.density_elevations[self.items[i]]
236 419
                else:
237
                    density2 = self.density_elevations[self.items[i]] * 16.0185 #lb/ft3
420
                    density2 = self.density_elevations[self.items[i]] * 16.0185  # lb/ft3
238 421

  
239
            #2 elevation 받음
422
            # 2 elevation 받음
240 423
            if units['Length'] == 'm':
241
                el1 = self.density_elevations[self.items[i-1]]
242
                el2 = self.density_elevations[self.items[i+1]]
424
                el1 = self.density_elevations[self.items[i - 1]]
425
                el2 = self.density_elevations[self.items[i + 1]]
243 426
            elif units['Length'] == 'in':
244
                el1 = self.density_elevations[self.items[i-1]] * 0.0254
245
                el2 = self.density_elevations[self.items[i+1]] * 0.0254
427
                el1 = self.density_elevations[self.items[i - 1]] * 0.0254
428
                el2 = self.density_elevations[self.items[i + 1]] * 0.0254
246 429
            elif units['Length'] == 'ft':
247
                el1 = self.density_elevations[self.items[i-1]] * 0.3048 
248
                el2 = self.density_elevations[self.items[i+1]] * 0.3048
430
                el1 = self.density_elevations[self.items[i - 1]] * 0.3048
431
                el2 = self.density_elevations[self.items[i + 1]] * 0.3048
249 432
            elif units['Length'] == 'yd':
250
                el1 = self.density_elevations[self.items[i-1]] * 0.9144
251
                el2 = self.density_elevations[self.items[i+1]] * 0.9144
433
                el1 = self.density_elevations[self.items[i - 1]] * 0.9144
434
                el2 = self.density_elevations[self.items[i + 1]] * 0.9144
252 435
            elif units['Length'] == 'mm':
253
                el1 = self.density_elevations[self.items[i-1]] * 0.001
254
                el2 = self.density_elevations[self.items[i+1]] * 0.001
255
            else:    #mile
256
                el1 = self.density_elevations[self.items[i-1]] * 1609.34
257
                el2 = self.density_elevations[self.items[i+1]] * 1609.34
436
                el1 = self.density_elevations[self.items[i - 1]] * 0.001
437
                el2 = self.density_elevations[self.items[i + 1]] * 0.001
438
            else:  # mile
439
                el1 = self.density_elevations[self.items[i - 1]] * 1609.34
440
                el2 = self.density_elevations[self.items[i + 1]] * 1609.34
258 441

  
259
            #3. static head 계산
260
            stat_dp = (el2 - el1) * density2 / 1000 * 9.80665 / 101.325 #atm으로 계산된 dp
442
            # 3. static head 계산
443
            stat_dp = (el2 - el1) * density2 / 1000 * 9.80665 / 101.325  # atm으로 계산된 dp
261 444

  
262
            #4. 압력 유닛에 맞춰 뿌리기
445
            # 4. 압력 유닛에 맞춰 뿌리기
263 446
            if units['Pressure'] == 'kg/cm2':
264 447
                self.pressure_drops[self.items[i - 1]] = stat_dp * 1.033
265 448
            elif units['Pressure'] == 'psi':
......
275 458
            elif units['Pressure'] == 'MPa':
276 459
                self.pressure_drops[self.items[i - 1]] = stat_dp * 0.101325
277 460
        except Exception as ex:
278
            from App import App 
279
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
461
            from App import App
462
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
463
                                                          sys.exc_info()[-1].tb_lineno)
280 464
            App.mainWnd().addMessage.emit(MessageType.Error, message)
281 465

  
282 466
    def suction_p_cal(self, i):
......
328 512
                    if pabsolute < 0:
329 513
                        raise ValueError('The absolute pressure of {} is below 0.'.format(self.items[i + 1]))
330 514

  
331
                name = str(self.items[i + 1])[:3]
332
                if not self.pressure_drops[self.items[i + 1]]:
333
                    res = 0
334
                elif name == 'L_P' or name == 'R_P' or name == 'V_P' or name == 'R_K' or name == 'L_K':
335
                    self.pressures[self.items[i + 2]] = self.pressures[self.items[i + 1]] + self.pressure_drops[self.items[i + 1]]
515
                if self.items[i + 1] in self.pressure_drops and self.pressure_drops[self.items[i + 1]]:
516
                    name = str(self.items[i + 1])[:3]
517
                    if name == 'L_P' or name == 'R_P' or name == 'V_P' or name == 'R_K' or name == 'L_K':
518
                        self.pressures[self.items[i + 2]] = self.pressures[self.items[i + 1]] + \
519
                                                            self.pressure_drops[self.items[i + 1]]
520
                    else:
521
                        self.pressures[self.items[i + 2]] = self.pressures[self.items[i + 1]] - \
522
                                                            self.pressure_drops[self.items[i + 1]]
336 523
                else:
337
                    self.pressures[self.items[i + 2]] = self.pressures[self.items[i + 1]] - self.pressure_drops[self.items[i + 1]]
524
                    res = 0
338 525
        except Exception as ex:
339
            from App import App 
340
            message = 'error occured({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
526
            from App import App
527
            message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename,
528
                                                          sys.exc_info()[-1].tb_lineno)
341 529
            App.mainWnd().addMessage.emit(MessageType.Error, message)
342 530

  
343 531
        return res
344 532

  
345
    def discharge_p_cal(self, i):
533
    def hole_p_cal(self, i):
346 534
        res = 1
347 535

  
348 536
        try:
349
            self.pressures[self.items[i]] = self.pressures[self.items[i + 1]] + self.pressure_drops[self.items[i]]
537
            self.pressures[self.items[i]] = self.pressures[self.items[i + 1]] + self.pressure_drops[self.items[i]] \
538
                if self.pressure_drops[self.items[i]] else 0
350 539
            index = str(self.items[i - 2])[:3]
351 540
            if i > 0:
352
                self.pressures[self.items[i - 1]] = self.pressures[self.items[i]] + self.pressure_drops[self.items[i - 1]]
541
                self.pressures[self.items[i - 1]] = self.pressures[self.items[i]] + self.pressure_drops[
542
                    self.items[i - 1]]
353 543

  
354
                if self.pressure_drops[self.items[i - 2]]:
544
                if self.items[i - 2] in self.pressure_drops and self.pressure_drops[self.items[i - 2]]:
355 545
                    if index == 'L_P' or index == 'R_P' or index == 'V_P' or index == 'R_K' or index == 'L_K':
356
                        self.pressures[self.items[i - 2]] = self.pressures[self.items[i - 1]] + self.pressure_drops[self.items[i - 2]]
546
                        self.pressures[self.items[i - 2]] = self.pressures[self.items[i - 1]] - \
547
                                                            self.pressure_drops[self.items[i - 2]]
548
                    else:
549
                        self.pressures[self.items[i - 2]] = self.pressures[self.items[i - 1]] + \
550
                                                            self.pressure_drops[self.items[i - 2]]
551
                else:
552
                    # 여기에 그 루프는 그만 하는 로직을 넣어줘야함
553
                    res = 0
554
        except Exception as ex:
555
            from App import App
556
            message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename,
557
                                                          sys.exc_info()[-1].tb_lineno)
558
            App.mainWnd().addMessage.emit(MessageType.Error, message)
559

  
560
        return res
561

  
562
    def discharge_p_cal(self, i):
563
        res = 1
564

  
565
        try:
566
            self.pressures[self.items[i]] = self.pressures[self.items[i + 1]] + self.pressure_drops[self.items[i]]
567
            name = str(self.items[i - 2])[:3]
568
            if i > 1:
569
                self.pressures[self.items[i - 1]] = self.pressures[self.items[i]] + \
570
                                                    self.pressure_drops[self.items[i - 1]]
571

  
572
                if self.items[i - 2] in self.pressure_drops and self.pressure_drops[self.items[i - 2]]:
573
                    if name == 'L_P' or name == 'R_P' or name == 'V_P' or name == 'R_K' or name == 'L_K':
574
                        self.pressures[self.items[i - 2]] = self.pressures[self.items[i - 1]] - self.pressure_drops[
575
                            self.items[i - 2]]
357 576
                    else:
358
                        self.pressures[self.items[i - 2]] = self.pressures[self.items[i - 1]] + self.pressure_drops[self.items[i - 2]]
577
                        self.pressures[self.items[i - 2]] = self.pressures[self.items[i - 1]] + self.pressure_drops[
578
                            self.items[i - 2]]
359 579
                else:
360
                    #여기에 그 루프는 그만 하는 로직을 넣어줘야함
580
                    # 여기에 그 루프는 그만 하는 로직을 넣어줘야함
361 581
                    res = 0
362 582
        except Exception as ex:
363
            from App import App 
364
            message = 'error occured({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
583
            from App import App
584
            message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename,
585
                                                          sys.exc_info()[-1].tb_lineno)
365 586
            App.mainWnd().addMessage.emit(MessageType.Error, message)
366 587

  
367 588
        return res
368 589

  
590

  
369 591
class Transfer(QObject):
370 592
    onRemoved = pyqtSignal(QGraphicsItem)
371 593

  
372
    def __init__(self, parent = None):
594
    def __init__(self, parent=None):
373 595
        QObject.__init__(self, parent)
HYTOS/HYTOS/Shapes/EngineeringStreamlineItem.py
347 347
            self.setColor(color)
348 348
            QGraphicsPathItem.paint(self, painter, option, widget)
349 349
        
350
    def on_item_removed(self, item): 
351
        """ remove item from scene and then delete it """
352
        if item is self:
353
            for conn in item.connectors:
354
                if conn.connectedItem is not None: conn.connectedItem.connect(None)                
355

  
356
            self.scene().removeItem(item)
357
            del item
358

  
359 350
    '''
360 351
        @brief      Return real item position
361 352
        @authro     Jeongwoo
......
423 414

  
424 415
        if event.key() == Qt.Key_Delete: 
425 416
            self.transfer.onRemoved.emit(self)
426
            self.on_item_removed(self)
427 417
        elif event.key() == Qt.Key_QuoteLeft:
428 418
            self.mouseDoubleClickEvent(event)    
429 419
           
HYTOS/HYTOS/Shapes/SymbolSvgItem.py
231 231
    '''
232 232
    def buildItem(self, name, _type, angle, scale, loc, origin, connPts, dbUid=None, pointsUids=None):
233 233
        try:
234
            if not hasattr(self, 'counters'): self.counters = {}
235
            if name in self.counters:
236
                self.counters[name] += 1
237
            else: self.counters[name] = 1
238

  
234 239
            self.name = name
240
            self.index = self.counters[name]
235 241
            self.type = _type     
236 242
            self.angle = angle     
237 243
            self._scale = scale

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)