프로젝트

일반

사용자정보

통계
| 개정판:

hytos / HYTOS / HYTOS / Commands / HydroCalculationCommand.py @ 928be99b

이력 | 보기 | 이력해설 | 다운로드 (26.9 KB)

1
import os.path
2
import sys
3
import AbstractCommand
4

    
5
try:
6
    from PyQt5.QtCore import *
7
    from PyQt5.QtGui import *
8
    from PyQt5.QtWidgets import *
9
except ImportError:
10
    try:
11
        from PyQt4.QtCore import Qt, QPoint, QPointF, QRectF, pyqtSignal, QT_VERSION_STR, QMimeData
12
        from PyQt4.QtGui import QGraphicsView, QGraphicsScene, QImage, QPixmap, QPainterPath, QFileDialog, QColor, QPen, \
13
            QBrush, QCursor
14
    except ImportError:
15
        raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.")
16

    
17

    
18
class HydroCalculationCommand(AbstractCommand.AbstractCommand):
19
    """ Hydro Calculation class """
20

    
21
    onSuccess = pyqtSignal(QGraphicsItem)
22

    
23
    def __init__(self, imageViewer):
24
        super(HydroCalculationCommand, self).__init__(imageViewer)
25
        self.name = 'HydroCalculation'
26

    
27
        self.units = {}
28
        self.loops = []
29

    
30
    def is_loop_start_item(self, item):
31
        """check given item is possible of start of loop"""
32

    
33
        if self.is_loop_end_item(item):
34
            matches = [conn for conn in item.connectors if
35
                       conn.connectedItem and int(conn.connectedItem._conn_index) == 1]
36
            if matches:
37
                return True
38

    
39
        return False
40

    
41
    def final_loss_input(self):
42
        pass
43

    
44
    def init_units(self):
45
        from AppDocData import AppDocData
46
        try:
47
            app_doc_data = AppDocData.instance()
48
            self.units = [attr[1] for attr in app_doc_data.activeDrawing.attrs if attr[0] == 'Units'][0]
49
        except Exception as ex:
50
            from App import App
51
            from AppDocData import MessageType
52
            message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename,
53
                                                           sys.exc_info()[-1].tb_lineno)
54
            App.mainWnd().addMessage.emit(MessageType.Error, message)
55

    
56
    def is_loop_end_item(self, item):
57
        """check given item is possible of end of loop"""
58

    
59
        return item.category == 'Equipment - [ Pressurized ]' or (item.name == 'R_Comp' or item.name == 'L_Comp')
60

    
61
    def del_p_cal(self):
62
        for loop in self.loops:
63
            matches = [item for item in loop.items if item != loop.items[0] and item != loop.items[-1]]
64
            if matches:
65
                for i in range(len(matches)):
66
                    loop.pressures[matches[i]] = 0
67

    
68
            '''
69
            items = loop.items
70
            for item in items:
71
                if item == items[0] or item == items[-1]:
72
                    continue
73
                loop.pressures[item] = 0
74
            '''
75

    
76
    def search_cv_calc(self):
77

    
78
        control_valves = []
79
        for loop in self.loops:
80
            for item in loop.items:
81
                parent = item.parent
82
                if parent:
83
                    if str(item)[:3] == 'CV_':
84
                        name = str(item).replace('_{}'.format(str(item).split('_')[len(str(item).split('_')) - 1]), '')
85
                        if name in control_valves:
86
                            continue
87
                        control_valves.append(name)
88

    
89
        for control_valve in control_valves:
90
            cvdp = []
91
            cvdp.append(100000000)
92

    
93
            for loop in self.loops:
94
                for i in range(1, len(loop.items) - 1, 3):
95
                    name = str(loop.items[i + 1]).replace(
96
                        '_{}'.format(str(loop.items[i + 1]).split('_')[len(str(loop.items[i + 1]).split('_')) - 1]), '')
97
                    if control_valve == name:
98
                        if loop.items[i + 1] in loop.pressure_drops:
99
                            cvdp.append(loop.pressure_drops[loop.items[i + 1]])
100

    
101
            cvdp_final = min(cvdp)
102

    
103
            for loop in self.loops:
104
                for i in range(1, len(loop.items) - 1, 3):
105
                    name = str(loop.items[i + 1]).replace(
106
                        '_{}'.format(str(loop.items[i + 1]).split('_')[len(str(loop.items[i + 1]).split('_')) - 1]), '')
107
                    if control_valve == name:
108
                        loop.pressure_drops[loop.items[i + 1]] = cvdp_final
109
                        loop.extras[loop.items[i + 2]] = cvdp_final / (
110
                                cvdp_final + loop.total_device_loss + loop.line_total_friction_loss)
111

    
112
    def search_pump_calc(self):
113

    
114
        pumps = []
115
        for loop in self.loops:
116
            for item in loop.items:
117
                parent = item.parent
118
                if parent:
119
                    if str(item)[:3] == 'R_P' or str(item)[:3] == 'L_P' or str(item)[:3] == 'V_P' or str(item)[
120
                                                                                                     :3] == 'R_K' or str(
121
                            item)[:3] == 'L_P':
122
                        name = str(item).replace('_{}'.format(str(item).split('_')[len(str(item).split('_')) - 1]), '')
123
                        if name in pumps:
124
                            continue
125
                        pumps.append(name)
126

    
127
        for pump in pumps:
128
            pumpdp = []
129
            pumpdp.append(0.00000001)
130

    
131
            # (1) 펌프 헤드 결정
132
            for loop in self.loops:
133
                for i in range(1, len(loop.items) - 1, 3):
134
                    name = str(loop.items[i + 1]).replace(
135
                        '_{}'.format(str(loop.items[i + 1]).split('_')[len(str(loop.items[i + 1]).split('_')) - 1]), '')
136
                    if pump == name:
137
                        if loop.items[i + 1] in loop.pressure_drops:
138
                            pumpdp.append(loop.pressure_drops[loop.items[i + 1]])
139

    
140
            pumpdp_final = max(pumpdp)
141

    
142
            # (2) 펌프 헤드를 각 루프에 새로 씀
143
            for loop in self.loops:
144
                for i in range(1, len(loop.items) - 1, 3):
145
                    name = str(loop.items[i + 1]).replace(
146
                        '_{}'.format(str(loop.items[i + 1]).split('_')[len(str(loop.items[i + 1]).split('_')) - 1]), '')
147
                    if pump == name:
148
                        loop.pressure_drops[loop.items[i + 1]] = pumpdp_final
149

    
150
        if len(pumps) > 0:
151
            for loop in self.loops:
152
                if loop.fill_end - loop.fill_start != 3:
153
                    loop.suction_cal(2)
154
                    loop.discharge_cal(2)
155

    
156
    def execute_second(self, param):
157

    
158
        # 라인 계산된 것을 지운다
159
        self.del_p_cal()
160

    
161
        # 펌프 먼저
162
        self.search_pump_calc()
163

    
164
        # CV decision
165
        self.search_cv_calc()
166

    
167
        # 계산 마무리
168
        for loop in self.loops:
169
            for i in range(1, len(loop.items) - 1, 3):
170
                loop.suction_p_cal(i)
171
                loop.final_loss_input()
172

    
173
            items_count = len(loop.items)
174

    
175
            deviation = loop.pressures[loop.items[items_count - 2]] - loop.pressures[loop.items[items_count - 1]] - \
176
                        loop.pressure_drops[loop.items[items_count - 2]]
177

    
178
            loop.deviation = deviation
179
            self.final_loss_input()
180

    
181
        self.init_units()
182
        self.loop_result()
183

    
184
    def execute(self, param):
185
        """ execute hydro calculation """
186

    
187
        from SymbolSvgItem import SymbolSvgItem
188
        from EngineeringLoopItem import QEngineeringLoopItem
189

    
190
        queue = []
191
        try:
192
            pressurized = [item for item in self.imageViewer.scene.items() if type(item) is SymbolSvgItem and
193
                           self.is_loop_end_item(item)]
194

    
195
            for item in pressurized:
196
                matches = [conn for conn in item.connectors if
197
                           conn.connectedItem and int(conn.connectedItem._conn_index) == 1]
198
                for match in matches:
199
                    queue.append(QEngineeringLoopItem([match]))
200

    
201
            while queue:
202
                loop = queue.pop(0)
203
                queue.extend(self.make_loop(loop))
204

    
205
            for loop in self.loops:
206
                loop.calculate()
207
                # update pressure and pressure drop
208
                for item in loop.items:
209
                    if item in loop.pressures:
210
                        item.pressure = loop.pressures[item]
211
                    if item in loop.pressure_drops:
212
                        item.pressure_drop = loop.pressure_drops[item]
213

    
214
            # self.init_units()
215
            # self.loop_result()
216

    
217
        except Exception as ex:
218
            from App import App
219
            from AppDocData import MessageType
220

    
221
            message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename,
222
                                                           sys.exc_info()[-1].tb_lineno)
223
            App.mainWnd().addMessage.emit(MessageType.Error, message)
224

    
225
    def loop_result(self):
226
        self.loop_streams_hy()
227
        self.loop_pumps_hy()
228
        self.loop_comps_hy()
229
        self.loop_cv_hy()
230

    
231
        self.stream_input()  # static 및 end.p 값 입력
232

    
233
    def get_govern_loop(self):
234
        govern_loop = None
235
        max_deviation = None
236
        for loop in self.loops:
237
            if max_deviation is None:
238
                max_deviation = loop.deviation
239
                govern_loop = loop
240
                continue
241

    
242
            if max_deviation > loop.deviation:
243
                max_deviation = loop.deviation
244
                govern_loop = loop
245

    
246
        return govern_loop
247

    
248
    def stream_input(self):
249
        from AppDocData import AppDocData
250
        try:
251
            """ update pressure drop and pressure of stream data """
252

    
253
            govern_loop = self.get_govern_loop()
254

    
255
            app_doc_data = AppDocData.instance()
256
            for hmb in app_doc_data.activeDrawing.hmbTable._hmbs:
257
                matches = [loop for loop in self.loops if
258
                           [item for item in loop.items if str(item.uid) == str(hmb.components_uid)]]
259
                if matches:
260
                    indices = [index for index in range(len(matches[0].items)) if
261
                               str(matches[0].items[index].uid) == str(hmb.components_uid)]
262
                    if indices:
263
                        hmb.pressure_drop_static = matches[0].pressure_drops[matches[0].items[indices[0] - 1]]
264

    
265
                        if len(matches) > 1:
266
                            if matches[0].items[indices[0] + 1] in govern_loop.pressures:
267
                                hmb.pressure_pipe_end_point = govern_loop.pressures[matches[0].items[indices[0] + 1]]
268
                            else:
269
                                hmb.pressure_pipe_end_point = matches[0].pressures[matches[0].items[indices[0] + 1]]
270
                        else:
271
                            hmb.pressure_pipe_end_point = matches[0].pressures[matches[0].items[indices[0] + 1]]
272

    
273
                        if hmb.phase_type == 'Vapor':
274
                            hmb.pressure_drop_friction = matches[0].pressure_drops[matches[0].items[indices[0]]]
275
                            hmb.density = matches[0].density_elevations[matches[0].items[indices[0]]]
276
                            hmb.pressure_drop = matches[0].pressure_drops[
277
                                                    matches[0].items[indices[0]]] / hmb.equivalent_length * 100
278

    
279
        except Exception as ex:
280
            from App import App
281
            from AppDocData import MessageType
282

    
283
            message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename,
284
                                                           sys.exc_info()[-1].tb_lineno)
285
            App.mainWnd().addMessage.emit(MessageType.Error, message)
286

    
287
    def loop_comps_hy(self):
288
        if self.loops:
289
            tag_nos = []
290
            for loop in self.loops:
291
                indices = [index for index in range(len(loop.items)) if
292
                           str(loop.items[index])[:3] == 'R_K' or str(loop.items[index])[:3] == 'L_K']
293
                attribute = {}
294
                if indices:
295
                    for i in range(len(indices)):
296
                        tag_no = loop.items[indices[i]].parent.tag_no
297
                        if tag_no in tag_nos:
298
                            continue
299

    
300
                        tag_nos.append(tag_no)
301
                        suct_p = loop.pressures[loop.items[indices[i]]]
302
                        disc_p = loop.pressures[loop.items[indices[i + 1]]]
303
                        diff_p = disc_p - suct_p
304

    
305
                        flowrate_mass = loop.items[indices[i] - 1].data.flowrate_mass
306
                        density = loop.density_elevations[loop.items[indices[i] - 1]]
307
                        hhp = self.comp_hydp_hy(flowrate_mass, density, round(diff_p, 3))
308

    
309
                        attribute['Tag_No'] = tag_no
310
                        attribute['Suct.P'] = suct_p
311
                        attribute['Disc.P'] = disc_p
312
                        attribute['Diff.P'] = diff_p
313
                        attribute['HHP'] = hhp
314

    
315
                        loop.items[indices[i]].parent.attribute = attribute
316

    
317
    def loop_cv_hy(self):
318
        if self.loops:
319
            tag_nos = []
320
            for loop in self.loops:
321
                indices = [index for index in range(len(loop.items)) if str(loop.items[index])[:3] == 'CV_']
322
                if indices:
323
                    for i in range(len(indices)):
324
                        tag_no = loop.items[indices[i]].parent.tag_no
325
                        if tag_no in tag_nos:
326
                            continue
327

    
328
                        tag_nos.append(tag_no)
329
                        suct_p = loop.pressures[loop.items[indices[i]]]
330
                        disc_p = loop.pressures[loop.items[indices[i + 1]]]
331
                        diff_p = loop.pressure_drops[loop.items[indices[i]]]
332
                        dp_ratio = loop.extras[loop.items[indices[i + 1]]] if not loop.extras[
333
                                                                                  loop.items[indices[i + 1]]] is None else 0
334

    
335
                        attribute = {}
336
                        attribute['Tag_No'] = tag_no
337
                        attribute['Suct.P'] = suct_p
338
                        attribute['Disc.P'] = disc_p
339
                        attribute['Diff.P'] = diff_p
340
                        attribute['dP Ratio'] = dp_ratio
341

    
342
                        loop.items[indices[i]].parent.attribute = attribute
343

    
344
    def loop_pumps_hy(self):
345
        if self.loops:
346
            tag_nos = []
347
            for loop in self.loops:
348
                indices = [index for index in range(len(loop.items)) if
349
                           str(loop.items[index])[:3] == 'R_P' or str(loop.items[index])[:3] == 'L_P' or str(
350
                               loop.items[index])[:3] == 'V_P']
351
                if indices:
352
                    for i in range(len(indices)):
353
                        tag_no = loop.items[indices[i]].parent.tag_no
354
                        if tag_no in tag_nos:
355
                            continue
356

    
357
                        tag_nos.append(tag_no)
358
                        suct_p = loop.pressures[loop.items[indices[i]]]
359
                        disc_p = loop.pressures[loop.items[indices[i + 1]]]
360
                        diff_p = disc_p - suct_p
361
                        vapr_p = loop.extras[loop.items[indices[i]]]
362

    
363
                        flowrate_mass = loop.items[indices[i] - 1].data.flowrate_mass
364
                        density = loop.density_elevations[loop.items[indices[i] - 1]]
365

    
366
                        npsha = self.npsha_cal_hy(suct_p, vapr_p, density)
367
                        head = self.pump_head_cal(diff_p, density)
368
                        hhp = self.pump_hydp_hy(flowrate_mass, density, head)
369

    
370
                        attribute = {}
371

    
372
                        attribute['Tag_No'] = tag_no
373
                        attribute['Suct.P'] = suct_p
374
                        attribute['Disc.P'] = disc_p
375
                        attribute['Diff.P'] = diff_p
376
                        attribute['Head'] = head
377
                        attribute['NPSHa'] = npsha
378
                        attribute['Vap. P'] = vapr_p
379
                        attribute['HHP'] = hhp
380
                        loop.items[indices[i]].parent.attribute = attribute
381

    
382
                        '''
383
                        if len(loop.items[indices[i]].parent.attribute) == 0:
384
                            attribute['Tag_No'] = tag_no
385
                            attribute['Suct.P'] = suct_p
386
                            attribute['Disc.P'] = disc_p
387
                            attribute['Diff.P'] = diff_p
388
                            attribute['Head'] = head
389
                            attribute['NPSHa'] = npsha
390
                            attribute['Vap. P'] = vapr_p
391
                            attribute['HHP'] = hhp
392
                            loop.items[indices[i]].parent.attribute = attribute
393
                        elif tag_no != loop.items[indices[i]].parent.attribute['Tag_No']:
394
                            attribute['Tag_No'] = tag_no
395
                            attribute['Suct.P'] = suct_p
396
                            attribute['Disc.P'] = disc_p
397
                            attribute['Diff.P'] = diff_p
398
                            attribute['Head'] = head
399
                            attribute['NPSHa'] = npsha
400
                            attribute['Vap. P'] = vapr_p
401
                            attribute['HHP'] = hhp
402
                            loop.items[indices[i]].parent.attribute = attribute
403
                        '''
404

    
405
    def get_barometric_pressure(self):
406
        pressure_unit = self.units['Pressure']
407
        if pressure_unit == 'kg/cm2':
408
            barometric_pressure = 1.033
409
        elif pressure_unit == 'bar':
410
            barometric_pressure = 1.01325
411
        elif pressure_unit == 'psi':
412
            barometric_pressure = 14.7
413
        elif pressure_unit == 'mmHg':
414
            barometric_pressure = 760
415
        elif pressure_unit == 'kPa':
416
            barometric_pressure = 101.325
417
        elif pressure_unit == 'MPa':
418
            barometric_pressure = 0.101325
419

    
420
        return barometric_pressure
421

    
422
    def pump_head_cal(self, header, density):
423
        density_unit = self.units['Density']
424
        if density_unit == 'kg/m3':
425
            sg = density / 1000
426
        elif density_unit == 'lb/ft3':
427
            sg = density * 16.0185 / 1000
428

    
429
        pressure_unit = self.units['Pressure']
430
        if pressure_unit == 'kg/cm2':
431
            header = header
432
        elif pressure_unit == 'psi':
433
            header = header / 14.7 * 1.033
434
        elif pressure_unit == 'bar':
435
            header = header / 1.013 * 1.033
436
        elif pressure_unit == 'mmHg':
437
            header = header / 760 * 1.033
438
        elif pressure_unit == 'kPa':
439
            header = header / 101.325 * 1.033
440
        elif pressure_unit == 'MPa':
441
            header = header / 0.101325 * 1.033
442

    
443
        # 현재 head는 kg/cm2으로 통일되어있음
444
        header = header * 10 / sg
445

    
446
        # 현재 head는 m로 표시되어있음
447
        length_unit = self.units['Length']
448
        if length_unit == 'm':
449
            header = header
450
        elif length_unit == 'in':
451
            header = header * 39.3701
452
        elif length_unit == 'ft':
453
            header = header * 3.28084
454
        elif length_unit == 'yd':
455
            header = header * 1.09361
456
        elif length_unit == 'mile':
457
            header = header * 0.000621371
458
        elif length_unit == 'mm':
459
            header = header * 1000
460

    
461
        return header
462

    
463
    def npsha_cal_hy(self, suct_p, vapo_p, density):
464
        ref_baro = self.get_barometric_pressure()
465

    
466
        density_unit = self.units['Density']
467
        if density_unit == 'kg/m3':
468
            sg = density / 1000
469
        elif density_unit == 'lb/ft3':
470
            sg = density * 16.0185 / 1000
471

    
472
        npsha = suct_p - vapo_p
473

    
474
        pressure_unit = self.units['Pressure']
475
        if pressure_unit == 'kg/cm2':
476
            npsha = npsha
477
        elif pressure_unit == 'psi':
478
            npsha = npsha / 14.7 * 1.033
479
        elif pressure_unit == 'bar':
480
            npsha = npsha / 1.013 * 1.033
481
        elif pressure_unit == 'mmHg':
482
            npsha = npsha / 760 * 1.033
483
        elif pressure_unit == 'kPa':
484
            npsha = npsha / 101.325 * 1.033
485
        elif pressure_unit == 'MPa':
486
            npsha = npsha / 0.101325 * 1.033
487

    
488
        npsha = npsha + ref_baro
489
        # 현재 npsha는 kg/cm2으로 통일되어있음
490

    
491
        npsha = npsha * 10 / sg
492
        # 현재 npsha는 딱 m로 표시되어있음
493

    
494
        length_unit = self.units['Length']
495
        if length_unit == 'm':
496
            npsha = npsha
497
        elif length_unit == 'in':
498
            npsha = npsha * 39.3701
499
        elif length_unit == 'ft':
500
            npsha = npsha * 3.28084
501
        elif length_unit == 'yd':
502
            npsha = npsha * 1.09361
503
        elif length_unit == 'mile':
504
            npsha = npsha * 0.000621371
505
        elif length_unit == 'mm':
506
            npsha = npsha * 1000
507

    
508
        return npsha
509

    
510
    def pump_hydp_hy(self, flowrate_mass, density, head):
511
        hydp_den = density
512

    
513
        # 질량유량은 모두 kg/min으로 맞춰야 함
514
        flowrate_mass_unit = self.units['Flowrate_Mass']
515
        if flowrate_mass_unit == 'kg/h':
516
            mass_4_hydp = flowrate_mass / 60
517
        elif flowrate_mass_unit == 'g/min':
518
            mass_4_hydp = flowrate_mass / 1000
519
        elif flowrate_mass_unit == 'lb/h':
520
            mass_4_hydp = flowrate_mass / 60 * 2.20462
521
        elif flowrate_mass_unit == 't/h':
522
            mass_4_hydp = flowrate_mass / 60 * 1000
523

    
524
        density_unit = self.units['Density']
525
        if density_unit == 'kg/m3':
526
            sg = hydp_den / 1000
527
            q = mass_4_hydp / hydp_den
528
        elif density_unit == 'lb/ft3':
529
            sg = hydp_den * 16.0185 / 1000
530
            q = mass_4_hydp / hydp_den * 2.20462 / 3.28 ** 3
531

    
532
        # 현재 hydp는 kW 임
533
        hydp = 0.163 * sg * q * head
534

    
535
        # 현재는 압력의 단위로 표시되어있음
536
        power_unit = self.units['Power']
537
        if power_unit == 'kW':
538
            hydp = hydp
539
        elif power_unit == 'kcal/h':
540
            hydp = hydp * 860.421
541
        elif power_unit == 'btu/h':
542
            hydp = hydp * 3412.14
543
        elif power_unit == 'Hp':
544
            hydp = hydp * 1.34041
545
        elif power_unit == 'kg.m/sec':
546
            hydp = hydp * 737.562 / 3.28 / 2.20462
547
        elif power_unit == 'ft.lb/sec':
548
            hydp = hydp * 737.562
549

    
550
        return hydp
551

    
552
    def comp_hydp_hy(self, flowrate_mass, density, diff_p):
553
        hydp_den = density
554

    
555
        # 질량유량은 모두 kg/min으로 맞춰야 함
556
        flowrate_mass_unit = self.units['Flowrate_Mass']
557
        if flowrate_mass_unit == 'kg/h':
558
            mass_4_hydp = flowrate_mass / 60
559
        elif flowrate_mass_unit == 'g/min':
560
            mass_4_hydp = flowrate_mass / 1000
561
        elif flowrate_mass_unit == 'lb/h':
562
            mass_4_hydp = flowrate_mass / 60 * 2.20462
563
        elif flowrate_mass_unit == 't/h':
564
            mass_4_hydp = flowrate_mass / 60 * 1000
565

    
566
        density_unit = self.units['Density']
567
        if density_unit == 'kg/m3':
568
            com_q = mass_4_hydp / hydp_den
569
        elif density_unit == 'lb/ft3':
570
            com_q = mass_4_hydp / hydp_den * 2.20462 / 3.28 ** 3
571

    
572
        density_unit = self.units['Density']
573
        if density_unit == 'kg/m3':
574
            com_sg = density / 1000
575
        elif density_unit == 'lb/ft3':
576
            com_sg = density * 16.0185 / 1000
577

    
578
        com_head = diff_p
579

    
580
        # 현재는 압력의 단위로 표시되어 있음
581
        pressure_unit = self.units['Pressure']
582
        if pressure_unit == 'kg/cm2':
583
            com_head = com_head
584
        elif pressure_unit == 'psi':
585
            com_head = com_head / 14.7 * 1.033
586
        elif pressure_unit == 'bar':
587
            com_head = com_head / 1.013 * 1.033
588
        elif pressure_unit == 'mmHg':
589
            com_head = com_head / 760 * 1.033
590
        elif pressure_unit == 'kPa':
591
            com_head = com_head / 101.325 * 1.033
592
        elif pressure_unit == 'MPa':
593
            com_head = com_head / 0.101325 * 1.033
594

    
595
        # 현재 head는 kg/cm2으로 통일되어있음
596
        com_head = com_head * 10 / com_sg
597

    
598
        hydp = 0.163 * com_sg * com_q * com_head
599
        # 현재 hydp는 kW 임
600

    
601
        # 현재는 압력의 단위로 표시되어있음
602
        power_unit = self.units['Power']
603
        if power_unit == 'kW':
604
            hydp = hydp
605
        elif power_unit == 'kcal/h':
606
            hydp = hydp * 860.421
607
        elif power_unit == 'btu/h':
608
            hydp = hydp * 3412.14
609
        elif power_unit == 'Hp':
610
            hydp = hydp * 1.34041
611
        elif power_unit == 'kg.m/sec':
612
            hydp = hydp * 737.562 / 3.28 / 2.20462
613
        elif power_unit == 'ft.lb/sec':
614
            hydp = hydp * 737.562
615

    
616
        return hydp
617

    
618
    def loop_streams_hy(self):
619
        pass
620

    
621
    def make_loop(self, loop):
622
        """ make a loop """
623
        from EngineeringConnectorItem import QEngineeringConnectorItem
624
        from SymbolSvgItem import SymbolSvgItem
625
        from EngineeringStreamlineItem import QEngineeringStreamlineItem
626
        from EngineeringLoopItem import QEngineeringLoopItem
627

    
628
        res = []
629

    
630
        try:
631
            while 1:
632
                if type(loop.items[-1]) is QEngineeringConnectorItem and \
633
                        (type(loop.items[-1].parentItem()) is SymbolSvgItem):
634
                    # start at connector
635
                    if loop.items[-1].connectedItem and int(loop.items[-1].connectedItem._conn_index) == 1:
636
                        loop.items.append(loop.items[-1].connectedItem.parentItem())  # it should be streamline
637
                        if type(loop.items[-1]) is QEngineeringStreamlineItem:
638
                            matches = [conn.connectedItem for conn in loop.items[-1].connectors if
639
                                       int(conn._conn_index) == 2 and conn.connectedItem]
640
                            if matches:
641
                                loop.items.append(matches[0])
642
                                if self.is_loop_end_item(matches[0].parentItem()):
643
                                    break
644
                            else:
645
                                break
646
                    # end at connector
647
                    elif loop.items[-1].connectedItem and int(loop.items[-1].connectedItem._conn_index) == 2:
648
                        matches = [conn for conn in loop.items[-1].parentItem().connectors if
649
                                   (not conn in loop.items) and conn.connectedItem and
650
                                   int(conn.connectedItem._conn_index) == 1]
651
                        if matches:
652
                            # sort by nozzle no
653
                            matches.sort(key=lambda conn: conn._conn_index) # .connectedItem.parentItem().stream_no)
654
                            for match in matches[1:]:
655
                                res.append(QEngineeringLoopItem(loop.items + [match]))
656
                            loop.items.append(matches[0])
657
                        else:
658
                            break
659
        except Exception as ex:
660
            from App import App
661
            from AppDocData import MessageType
662

    
663
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
664
                                                           sys.exc_info()[-1].tb_lineno)
665
            App.mainWnd().addMessage.emit(MessageType.Error, message)
666
        finally:
667
            loop.name = 'Loop{}'.format(len(self.loops) + 1)
668
            self.loops.append(loop)
669

    
670
        return res
671

    
672
    def undo(self):
673
        pass
674

    
675
    def redo(self):
676
        pass
클립보드 이미지 추가 (최대 크기: 500 MB)