프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / HYTOS / HYTOS / Calculation.py @ d71e102a

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

1
# coding: utf-8
2
"""
3
    This is calculation module
4
"""
5
import sys
6
import os
7
from AppDocData import *
8
import math
9
from App import App
10
from EngineeringConnectorItem import QEngineeringConnectorItem
11
from SymbolSvgItem import SymbolSvgItem
12

    
13

    
14
class Conversion:
15
    def __init__(self, decimal):
16
        self._decimal = decimal
17

    
18
        self.pre_units = {}
19
        self.cur_units = {}
20

    
21
        self.getCurrentUnits()
22
        self.getPreviousUnits()
23

    
24
        self.convert_HMB()
25
        self.convert_Nozzle()
26

    
27
    def convert_HMB(self):
28
        from Drawing import Drawing
29
        from Calculation import Conversion
30

    
31
        try:
32
            app_doc_data = AppDocData.instance()
33
            drawing = app_doc_data.activeDrawing
34

    
35
            hmbs = drawing.hmbTable._hmbs
36
            if hmbs is not None:
37
                for hmb in hmbs:
38
                    if hmb.flowrate_mass:
39
                        hmb.flowrate_mass = self.convert_flowrate_mass(hmb.flowrate_mass)
40
                    if hmb.flowrate_volume:
41
                        hmb.flowrate_volume = self.convert_flowrate_volume(hmb.flowrate_volume)
42
                    if hmb.density:
43
                        hmb.density = self.convert_density(hmb.density)
44
                    if hmb.viscosity:
45
                        hmb.viscosity = self.convert_viscosity(hmb.viscosity)
46
                    if hmb.temperature:
47
                        hmb.temperature = self.convert_temperature(hmb.temperature)
48
                    if hmb.nominal_pipe_size:
49
                        hmb.nominal_pipe_size = self.convert_pipe_diameter(hmb.nominal_pipe_size)
50
                    if hmb.inside_pipe_size:
51
                        hmb.inside_pipe_size = self.convert_pipe_diameter(hmb.inside_pipe_size)
52
                    if hmb.straight_length:
53
                        hmb.straight_length = self.convert_length(hmb.straight_length)
54
                    if hmb.equivalent_length:
55
                        hmb.equivalent_length = self.convert_length(hmb.equivalent_length)
56
                    if hmb.straight_length:
57
                        hmb.straight_length = self.convert_length(hmb.straight_length)
58
                    if hmb.equivalent_length_input:
59
                        hmb.equivalent_length_input = self.convert_length(hmb.equivalent_length_input)
60
                    if hmb.fitting_length:
61
                        hmb.fitting_length = self.convert_length(hmb.fitting_length)
62
                    if hmb.equivalent_length_cal:
63
                        hmb.equivalent_length_cal = self.convert_length(hmb.equivalent_length_cal)
64
                    if hmb.roughness:
65
                        hmb.roughness = self.convert_roughness(hmb.roughness)
66
                    if hmb.limitation_velocity:
67
                        hmb.limitation_velocity = self.convert_velocity(hmb.limitation_velocity)
68
                    if hmb.limitation_pressure_drop:
69
                        hmb.limitation_pressure_drop = self.convert_pressure(hmb.limitation_pressure_drop)
70
                    if hmb.velocity:
71
                        hmb.velocity = self.convert_velocity(hmb.velocity)
72
                    if hmb.pressure_drop:
73
                        hmb.pressure_drop = self.convert_pressure(hmb.pressure_drop)
74
                    if hmb.pressure_drop_friction:
75
                        hmb.pressure_drop_friction = self.convert_pressure(hmb.pressure_drop_friction)
76
                    if hmb.pressure_drop_static:
77
                        hmb.pressure_drop_static = self.convert_pressure(hmb.pressure_drop_static)
78
                    if hmb.pressure_pipe_end_point:
79
                        hmb.pressure_pipe_end_point = self.convert_pressure(hmb.pressure_pipe_end_point)
80
                    if hmb.power:
81
                        hmb.power = self.convert_power(hmb.power)
82

    
83
        except Exception as ex:
84
            from App import App
85
            from AppDocData import MessageType
86

    
87
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
88
                                                           sys.exc_info()[-1].tb_lineno)
89
            App.mainWnd().addMessage.emit(MessageType.Error, message)
90

    
91
    def convert_flowrate_mass(self, value):
92
        pre_unit = self.pre_units['Flowrate_Mass']
93
        cur_unit = self.cur_units['Flowrate_Mass']
94

    
95
        if pre_unit == cur_unit:
96
            return value
97

    
98
        if pre_unit == 'kg/h':
99
            if cur_unit == 'g/min':
100
                convert_factor = 16.6667
101
            elif cur_unit == 'lb/h':
102
                convert_factor = 2.2046
103
            elif cur_unit == 't/h':
104
                convert_factor = 0.001
105
        elif pre_unit == 'g/min':
106
            if cur_unit == 'kg/h':
107
                convert_factor = 1 / 16.6667
108
            elif cur_unit == 'lb/h':
109
                convert_factor = 0.132277
110
            elif cur_unit == 't/h':
111
                convert_factor = 0.00006
112
        elif pre_unit == 'lb/h':
113
            if cur_unit == 'kg/h':
114
                convert_factor = 1 / 2.2046
115
            elif cur_unit == 'g/min':
116
                convert_factor = 1 / 0.132277
117
            elif cur_unit == 't/h':
118
                convert_factor = 0.0004536
119
        elif pre_unit == 't/h':
120
            if cur_unit == 'kg/h':
121
                convert_factor = 1 / 0.001
122
            elif cur_unit == 'g/min':
123
                convert_factor = 1 / 0.00006
124
            elif cur_unit == 'lb/h':
125
                convert_factor = 1 / 0.0004536
126

    
127
        return round(value * convert_factor, self._decimal)
128

    
129
    def convert_flowrate_volume(self, value):
130
        pre_unit = self.pre_units['Flowrate_Volume']
131
        cur_unit = self.cur_units['Flowrate_Volume']
132

    
133
        if pre_unit == cur_unit:
134
            return value
135

    
136
        if pre_unit == 'm3/h':
137
            if cur_unit == 'l/min':
138
                convert_factor = 16.6667
139
            elif cur_unit == 'ft3/h':
140
                convert_factor = 35.31466
141
            elif cur_unit == 'USgpm':
142
                convert_factor = 4.402867
143
            elif cur_unit == 'BPSD':
144
                convert_factor = 150.955464
145
        elif pre_unit == 'l/min':
146
            if cur_unit == 'm3/h':
147
                convert_factor = 1 / 16.6667
148
            elif cur_unit == 'ft3/h':
149
                convert_factor = 2.1188796
150
            elif cur_unit == 'USgpm':
151
                convert_factor = 0.264172
152
            elif cur_unit == 'BPSD':
153
                convert_factor = 9.05732784
154
        elif pre_unit == 'ft3/h':
155
            if cur_unit == 'm3/h':
156
                convert_factor = 1 / 35.31466
157
            elif cur_unit == 'l/min':
158
                convert_factor = 1 / 2.1188796
159
            elif cur_unit == 'USgpm':
160
                convert_factor = 0.124675333
161
            elif cur_unit == 'BPSD':
162
                convert_factor = 9.05732784
163
        elif pre_unit == 'USgpm':
164
            if cur_unit == 'm3/h':
165
                convert_factor = 1 / 4.402867
166
            elif cur_unit == 'l/min':
167
                convert_factor = 1 / 0.264172
168
            elif cur_unit == 'ft3/h':
169
                convert_factor = 1 / 0.124675333
170
            elif cur_unit == 'BPSD':
171
                convert_factor = 34.2857088
172
        elif pre_unit == 'BPSD':
173
            if cur_unit == 'm3/h':
174
                convert_factor = 1 / 150.955464
175
            elif cur_unit == 'l/min':
176
                convert_factor = 1 / 9.05732784
177
            elif cur_unit == 'ft3/h':
178
                convert_factor = 1 / 4.2745824
179
            elif cur_unit == 'USgpm':
180
                convert_factor = 1 / 34.2857088
181

    
182
        return round(value * convert_factor, self._decimal)
183

    
184
    def convert_density(self, value):
185
        pre_unit = self.pre_units['Density']
186
        cur_unit = self.cur_units['Density']
187

    
188
        if pre_unit == cur_unit:
189
            return value
190

    
191
        if pre_unit == 'kg/m3':
192
            if cur_unit == 'lb/ft3': convert_factor = 0.06242797
193
        elif pre_unit == 'lb/ft3':
194
            if cur_unit == 'kg/m3': convert_factor = 1 / 0.06242797
195

    
196
        return round(value * convert_factor, self._decimal)
197

    
198
    def convert_viscosity(self, value):
199
        pre_unit = self.pre_units['Viscosity']
200
        cur_unit = self.cur_units['Viscosity']
201

    
202
        if pre_unit == cur_unit:
203
            return value
204

    
205
        if pre_unit == 'cP':
206
            if cur_unit == 'kg/m.sec':
207
                convert_factor = 0.001
208
            elif cur_unit == 'kg/m.h':
209
                convert_factor = 3.6
210
            elif cur_unit == 'lb/ft.sec':
211
                convert_factor = 0.000671969
212
        elif pre_unit == 'kg/m.sec':
213
            if cur_unit == 'cP':
214
                convert_factor = 1 / 0.001
215
            elif cur_unit == 'kg/m.h':
216
                convert_factor = 3600
217
            elif cur_unit == 'lb/ft.sec':
218
                convert_factor = 0.671969
219
        elif pre_unit == 'kg/m.h':
220
            if cur_unit == 'cP':
221
                convert_factor = 1 / 3.6
222
            elif cur_unit == 'kg/m.sec':
223
                convert_factor = 1 / 3600
224
            elif cur_unit == 'lb/ft.sec':
225
                convert_factor = 0.000186658
226
        elif pre_unit == 'lb/ft.sec':
227
            if cur_unit == 'cP':
228
                convert_factor = 1 / 0.000671969
229
            elif cur_unit == 'kg/m.sec':
230
                convert_factor = 1 / 0.671969
231
            elif cur_unit == 'kg/m.h':
232
                convert_factor = 1 / 0.000186658
233

    
234
        return round(value * convert_factor, self._decimal)
235

    
236
    def convert_temperature(self, value):
237
        pre_unit = self.pre_units['Temperature']
238
        cur_unit = self.cur_units['Temperature']
239

    
240
        if pre_unit == cur_unit:
241
            return value
242

    
243
        if cur_unit == '':
244
            return round(1.8 * value + 32, self._decimal)
245
        elif cur_unit == '':
246
            return round((value - 32) / 1.8, self._decimal)
247

    
248
    def convert_pipe_diameter(self, value):
249
        pre_unit = self.pre_units['Pipe_Diameter']
250
        cur_unit = self.cur_units['Pipe_Diameter']
251

    
252
        if pre_unit == cur_unit:
253
            return value
254

    
255
        if pre_unit == 'in':
256
            if cur_unit == 'mm': convert_factor = 25.4
257
        elif pre_unit == 'mm':
258
            if cur_unit == 'in': convert_factor = 1 / 25.4
259

    
260
        return round(value * convert_factor, self._decimal)
261

    
262
    def convert_length(self, value):
263
        pre_unit = self.pre_units['Length']
264
        cur_unit = self.cur_units['Length']
265

    
266
        if pre_unit == cur_unit:
267
            return value
268

    
269
        if pre_unit == 'in':
270
            if cur_unit == 'm':
271
                convert_factor = 0.0254
272
            elif cur_unit == 'ft':
273
                convert_factor = 0.083333
274
            elif cur_unit == 'yd':
275
                convert_factor = 0.0277778
276
            elif cur_unit == 'mile':
277
                convert_factor = 0.00001578283
278
            elif cur_unit == 'mm':
279
                convert_factor = 25.4
280
        elif pre_unit == 'm':
281
            if cur_unit == 'in':
282
                convert_factor = 1 / 0.0254
283
            elif cur_unit == 'ft':
284
                convert_factor = 3.28084
285
            elif cur_unit == 'yd':
286
                convert_factor = 1.093613
287
            elif cur_unit == 'mile':
288
                convert_factor = 0.000621371
289
            elif cur_unit == 'mm':
290
                convert_factor = 1000
291
        elif pre_unit == 'ft':
292
            if cur_unit == 'in':
293
                convert_factor = 1 / 0.083333
294
            elif cur_unit == 'm':
295
                convert_factor = 1 / 3.28084
296
            elif cur_unit == 'yd':
297
                convert_factor = 0.33333
298
            elif cur_unit == 'mile':
299
                convert_factor = 0.000189394
300
            elif cur_unit == 'mm':
301
                convert_factor = 304.8
302
        elif pre_unit == 'yd':
303
            if cur_unit == 'in':
304
                convert_factor = 1 / 0.277778
305
            elif cur_unit == 'm':
306
                convert_factor = 1 / 1.093613
307
            elif cur_unit == 'ft':
308
                convert_factor = 1 / 0.33333
309
            elif cur_unit == 'mile':
310
                convert_factor = 0.000568182
311
            elif cur_unit == 'mm':
312
                convert_factor = 914.4
313
        elif pre_unit == 'mile':
314
            if cur_unit == 'in':
315
                convert_factor = 1 / 0.00001578283
316
            elif cur_unit == 'm':
317
                convert_factor = 1 / 0.000621371
318
            elif cur_unit == 'ft':
319
                convert_factor = 1 / 0.000189394
320
            elif cur_unit == 'yd':
321
                convert_factor = 1 / 0.000568182
322
            elif cur_unit == 'mm':
323
                convert_factor = 1609344
324
        elif pre_unit == 'mm':
325
            if cur_unit == 'in':
326
                convert_factor = 1 / 25.4
327
            elif cur_unit == 'm':
328
                convert_factor = 1 / 1000
329
            elif cur_unit == 'ft':
330
                convert_factor = 1 / 304.8
331
            elif cur_unit == 'yd':
332
                convert_factor = 1 / 914.4
333
            elif cur_unit == 'mile':
334
                convert_factor = 1 / 1609344
335

    
336
        return round(value * convert_factor, self._decimal)
337

    
338
    def convert_roughness(self, value):
339
        pre_unit = self.pre_units['Roughness']
340
        cur_unit = self.cur_units['Roughness']
341

    
342
        if pre_unit == cur_unit:
343
            return value
344

    
345
        if pre_unit == 'in':
346
            if cur_unit == 'm':
347
                convert_factor = 0.0254
348
            elif cur_unit == 'ft':
349
                convert_factor = 0.083333
350
            elif cur_unit == 'mm':
351
                convert_factor = 25.4
352
        elif pre_unit == 'm':
353
            if cur_unit == 'in':
354
                convert_factor = 1 / 0.0254
355
            elif cur_unit == 'ft':
356
                convert_factor = 3.28084
357
            elif cur_unit == 'mm':
358
                convert_factor = 1000
359
        elif pre_unit == 'ft':
360
            if cur_unit == 'in':
361
                convert_factor = 1 / 0.083333
362
            elif cur_unit == 'm':
363
                convert_factor = 1 / 3.28084
364
            elif cur_unit == 'mm':
365
                convert_factor = 304.8
366
        elif pre_unit == 'mm':
367
            if cur_unit == 'in':
368
                convert_factor = 1 / 25.4
369
            elif cur_unit == 'm':
370
                convert_factor = 1 / 1000
371
            elif cur_unit == 'ft':
372
                convert_factor = 1 / 304.8
373

    
374
        return round(value * convert_factor, self._decimal)
375

    
376
    def convert_velocity(self, value):
377
        pre_unit = self.pre_units['Velocity']
378
        cur_unit = self.cur_units['Velocity']
379

    
380
        if pre_unit == cur_unit:
381
            return value
382

    
383
        if pre_unit == 'm/s':
384
            if cur_unit == 'ft/s': convert_factor = 3.28084
385
        elif pre_unit == 'ft/s':
386
            if cur_unit == 'm/s': convert_factor = 1 / 3.28084
387

    
388
        return round(value * convert_factor, self._decimal)
389

    
390
    def convert_pressure(self, value):
391
        pre_unit = self.pre_units['Pressure']
392
        cur_unit = self.cur_units['Pressure']
393

    
394
        if pre_unit == cur_unit:
395
            return value
396

    
397
        if pre_unit == 'kg/cm2':
398
            if cur_unit == 'psi':
399
                convert_factor = 14.22334
400
            elif cur_unit == 'atm':
401
                convert_factor = 0.9678411
402
            elif cur_unit == 'bar':
403
                convert_factor = 0.980665
404
            elif cur_unit == 'mmHg':
405
                convert_factor = 735.5591
406
            elif cur_unit == 'kPa':
407
                convert_factor = 98.0665
408
            elif cur_unit == 'MPa':
409
                convert_factor = 0.0980665
410
        elif pre_unit == 'psi':
411
            if cur_unit == 'kg/cm2':
412
                convert_factor = 1 / 14.22334
413
            elif cur_unit == 'atm':
414
                convert_factor = 0.06804596
415
            elif cur_unit == 'bar':
416
                convert_factor = 0.06894757
417
            elif cur_unit == 'mmHg':
418
                convert_factor = 51.71492
419
            elif cur_unit == 'kPa':
420
                convert_factor = 6.894757
421
            elif cur_unit == 'MPa':
422
                convert_factor = 0.006894757
423
        elif pre_unit == 'atm':
424
            if cur_unit == 'kg/cm2':
425
                convert_factor = 1 / 0.9678411
426
            elif cur_unit == 'psi':
427
                convert_factor = 1 / 0.06804596
428
            elif cur_unit == 'bar':
429
                convert_factor = 1.01325
430
            elif cur_unit == 'mmHg':
431
                convert_factor = 759.9998
432
            elif cur_unit == 'kPa':
433
                convert_factor = 101.325
434
            elif cur_unit == 'MPa':
435
                convert_factor = 0.101325
436
        elif pre_unit == 'bar':
437
            if cur_unit == 'kg/cm2':
438
                convert_factor = 1 / 0.980665
439
            elif cur_unit == 'psi':
440
                convert_factor = 1 / 0.06894757
441
            elif cur_unit == 'atm':
442
                convert_factor = 1 / 1.01325
443
            elif cur_unit == 'mmHg':
444
                convert_factor = 750.0615
445
            elif cur_unit == 'kPa':
446
                convert_factor = 100
447
            elif cur_unit == 'MPa':
448
                convert_factor = 0.1
449
        elif pre_unit == 'mmHg':
450
            if cur_unit == 'kg/cm2':
451
                convert_factor = 1 / 735.5591
452
            elif cur_unit == 'psi':
453
                convert_factor = 1 / 51.71492
454
            elif cur_unit == 'atm':
455
                convert_factor = 1 / 759.9998
456
            elif cur_unit == 'bar':
457
                convert_factor = 1 / 750.0615
458
            elif cur_unit == 'kPa':
459
                convert_factor = 0.1333224
460
            elif cur_unit == 'MPa':
461
                convert_factor = 0.0001333224
462
        elif pre_unit == 'kPa':
463
            if cur_unit == 'kg/cm2':
464
                convert_factor = 1 / 98.0665
465
            elif cur_unit == 'psi':
466
                convert_factor = 1 / 6.894757
467
            elif cur_unit == 'atm':
468
                convert_factor = 1 / 101.325
469
            elif cur_unit == 'bar':
470
                convert_factor = 1 / 100
471
            elif cur_unit == 'mmHg':
472
                convert_factor = 1 / 0.1333224
473
            elif cur_unit == 'MPa':
474
                convert_factor = 1 / 1000
475
        elif pre_unit == 'MPa':
476
            if cur_unit == 'kg/cm2':
477
                convert_factor = 1 / 98.0665 * 1000
478
            elif cur_unit == 'psi':
479
                convert_factor = 1 / 6.894757 * 1000
480
            elif cur_unit == 'atm':
481
                convert_factor = 1 / 101.325 * 1000
482
            elif cur_unit == 'bar':
483
                convert_factor = 1 / 100 * 1000
484
            elif cur_unit == 'mmHg':
485
                convert_factor = 1 / 0.1333224 * 1000
486
            elif cur_unit == 'kPa':
487
                convert_factor = 1  # 기존 소스에 없음
488

    
489
        return round(value * convert_factor, self._decimal)
490

    
491
    def convert_power(self, value):
492
        pre_unit = self.pre_units['Power']
493
        cur_unit = self.cur_units['Power']
494

    
495
        if pre_unit == cur_unit:
496
            return value
497

    
498
        if pre_unit == 'kW':
499
            if cur_unit == 'kcal/h':
500
                convert_factor = 860.4207
501
            elif cur_unit == 'btu/h':
502
                convert_factor = 3414.425
503
            elif cur_unit == 'Hp':
504
                convert_factor = 1.359622
505
            elif cur_unit == 'kg.m/sec':
506
                convert_factor = 101.9716
507
            elif cur_unit == 'ft.lb/sec':
508
                convert_factor = 737.5621
509
        elif pre_unit == 'kcal/h':
510
            if cur_unit == 'kW':
511
                convert_factor = 1 / 860.4207
512
            elif cur_unit == 'btu/h':
513
                convert_factor = 3.96832
514
            elif cur_unit == 'Hp':
515
                convert_factor = 0.001580182
516
            elif cur_unit == 'kg.m/sec':
517
                convert_factor = 0.1185137
518
            elif cur_unit == 'ft.lb/sec':
519
                convert_factor = 0.857211
520
        elif pre_unit == 'btu/h':
521
            if cur_unit == 'kW':
522
                convert_factor = 1 / 3414.425
523
            elif cur_unit == 'kcal/h':
524
                convert_factor = 1 / 3.96832
525
            elif cur_unit == 'Hp':
526
                convert_factor = 0.000398199
527
            elif cur_unit == 'kg.m/sec':
528
                convert_factor = 0.02986495
529
            elif cur_unit == 'ft.lb/sec':
530
                convert_factor = 0.2160136
531
        elif pre_unit == 'Hp':
532
            if cur_unit == 'kW':
533
                convert_factor = 11 / 1.359622
534
            elif cur_unit == 'kcal/h':
535
                convert_factor = 1 / 0.001580182
536
            elif cur_unit == 'btu/h':
537
                convert_factor = 1 / 0.000398199
538
            elif cur_unit == 'kg.m/sec':
539
                convert_factor = 75.00001
540
            elif cur_unit == 'ft.lb/sec':
541
                convert_factor = 542.4761
542
        elif pre_unit == 'kg.m/sec':
543
            if cur_unit == 'kW':
544
                convert_factor = 1 / 101.9716
545
            elif cur_unit == 'kcal/h':
546
                convert_factor = 1 / 0.1185137
547
            elif cur_unit == 'btu/h':
548
                convert_factor = 1 / 0.02986495
549
            elif cur_unit == 'Hp':
550
                convert_factor = 1 / 75.00001
551
            elif cur_unit == 'ft.lb/sec':
552
                convert_factor = 7.233014
553
        elif pre_unit == 'ft.lb/sec':
554
            if cur_unit == 'kW':
555
                convert_factor = 1 / 737.5621
556
            elif cur_unit == 'kcal/h':
557
                convert_factor = 1 / 0.857211
558
            elif cur_unit == 'btu/h':
559
                convert_factor = 1 / 0.2160136
560
            elif cur_unit == 'Hp':
561
                convert_factor = 1 / 542.4761
562
            elif cur_unit == 'kg.m/sec':
563
                convert_factor = 1 / 7.233014
564

    
565
        return round(value * convert_factor, self._decimal)
566

    
567
    def convert_Nozzle(self):
568
        from App import App
569
        try:
570
            self.graphicsView = App.mainWnd().graphicsView
571

    
572
            items = [item for item in self.graphicsView.scene.items() if type(item) is SymbolSvgItem]
573
            for item in items:
574
                for connector in item.connectors:
575
                    if connector.data.pressure:
576
                        connector.data.pressure = self.convert_pressure(connector.data.pressure)
577
                    if connector.data.pressure_drop:
578
                        connector.data.pressure_drop = self.convert_pressure(connector.data.pressure_drop)
579
                    if connector.data.elevation:
580
                        connector.data.elevation = self.convert_length(connector.data.elevation)
581
        except Exception as ex:
582
            from App import App
583
            from AppDocData import MessageType
584

    
585
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
586
                                                           sys.exc_info()[-1].tb_lineno)
587
            App.mainWnd().addMessage.emit(MessageType.Error, message)
588

    
589
    def getCurrentUnits(self):
590
        from AppDocData import AppDocData
591
        try:
592
            curUnitsList = AppDocData.instance().getConfigs('Units')
593
            for curUnit in curUnitsList:
594
                self.cur_units[curUnit.key] = curUnit.value
595

    
596
        except Exception as ex:
597
            from App import App
598
            from AppDocData import MessageType
599

    
600
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
601
                                                           sys.exc_info()[-1].tb_lineno)
602
            App.mainWnd().addMessage.emit(MessageType.Error, message)
603

    
604
    def getPreviousUnits(self):
605
        from AppDocData import AppDocData
606
        try:
607
            activeDrawing = AppDocData.instance().activeDrawing
608

    
609
            for attr in activeDrawing.attrs:
610
                if attr[0] == 'Units':
611
                    self.pre_units = attr[1]
612

    
613
        except Exception as ex:
614
            from App import App
615
            from AppDocData import MessageType
616

    
617
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
618
                                                           sys.exc_info()[-1].tb_lineno)
619
            App.mainWnd().addMessage.emit(MessageType.Error, message)
620

    
621

    
622
def is_not_blank(s):
623
    return bool(s and s.strip())
624

    
625

    
626
class Calculation_2Phase:
627
    def __init__(self, item, process, geometry):
628
        self.item = item
629
        self.process = process
630
        self.geometry = geometry
631
        self.units = {}
632

    
633
        self.calculated_variable = {}
634
        self.init_units()
635

    
636
        self.no = None
637
        self.element = {}
638
        self.inside_diameter = {}
639
        self.length = {}
640
        self.angle = {}
641
        self.k = {}
642
        self.pressure = {}
643
        self.void = {}
644
        self.quality = {}
645
        self.mean_den = {}
646
        self.v_density = {}
647
        self.homo_vel = {}
648
        self.max_vel = {}
649
        self.ero_vel = {}
650
        self.x = {}
651
        self.y = {}
652
        self.regime = {}
653
        self.dp_fric = {}
654
        self.dp_stat = {}
655
        self.dp_momen = {}
656
        self.total_length = {}
657

    
658
        self.tp_cal()
659

    
660
    def init_units(self):
661
        try:
662
            app_doc_data = AppDocData.instance()
663
            self.units = [attr[1] for attr in app_doc_data.activeDrawing.attrs if attr[0] == 'Units'][0]
664
        except Exception as ex:
665
            from App import App
666
            from AppDocData import MessageType
667

    
668
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
669
                                                           sys.exc_info()[-1].tb_lineno)
670
            App.mainWnd().addMessage.emit(MessageType.Error, message)
671

    
672
    def get_barometric_pressure(self):
673
        try:
674
            unit = self.units['Pressure']
675
            if unit == 'kg/cm2':
676
                barometric_pressure = 1.033
677
            elif unit == 'bar':
678
                barometric_pressure = 1.01325
679
            elif unit == 'psi':
680
                barometric_pressure = 14.7
681
            elif unit == 'mmHg':
682
                barometric_pressure = 760
683
            elif unit == 'kPa':
684
                barometric_pressure = 101.325
685
            elif unit == 'MPa':
686
                barometric_pressure = 0.101325
687

    
688
            return barometric_pressure
689
        except Exception as ex:
690
            from App import App
691
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
692
                                                           sys.exc_info()[-1].tb_lineno)
693
            App.mainWnd().addMessage.emit(MessageType.Error, message)
694

    
695
    def tp_geo_check(self, row):
696
        element = self.geometry.item(row, 0).text()
697

    
698
        if element == 'Pipe':
699
            inside_diameter = self.geometry.item(row, 3).text()
700
            roughness = self.geometry.item(row, 4).text()
701
            length = self.geometry.item(row, 5).text()
702
            if is_not_blank(inside_diameter) and is_not_blank(roughness) and is_not_blank(length):
703
                return False
704
        elif element == 'Bend':
705
            inside_diameter = self.geometry.item(row, 3).text()
706
            roughness = self.geometry.item(row, 4).text()
707
            angle = self.geometry.item(row, 6).text()
708
            rpd = self.geometry.item(row, 7).text()
709
            if is_not_blank(inside_diameter) and is_not_blank(roughness) and is_not_blank(angle) and is_not_blank(rpd):
710
                return False
711
        elif element == 'Nozzle In' or element == 'Nozzle Out' or element == 'Check Valve' or element == 'Ball Valve' or element == 'Gate Valve' or element == 'Globe Valve' or element == 'Butterfly Valve':
712
            inside_diameter = self.geometry.item(row, 3).text()
713
            roughness = self.geometry.item(row, 4).text()
714
            if is_not_blank(inside_diameter) and is_not_blank(roughness):
715
                return False
716
        elif element == 'Reducer' or element == 'Expander':
717
            inside_diameter = self.geometry.item(row, 3).text()
718
            roughness = self.geometry.item(row, 4).text()
719
            angle = self.geometry.item(row, 6).text()
720
            d1_d2 = self.geometry.item(row, 8).text()
721
            if is_not_blank(inside_diameter) and is_not_blank(roughness) and is_not_blank(angle) and is_not_blank(
722
                    d1_d2):
723
                return False
724

    
725
        return True
726

    
727
    def tp_c_cal(self):
728
        try:
729
            tp_massflux = self.calculated_variable['tp_massflux']
730
            if tp_massflux >= 300:
731
                tp_massflux_c = tp_massflux
732
            else:
733
                tp_massflux_c = 300 + ((300 - tp_massflux) ** 2 / 40)
734

    
735
            lambda1 = self.calculated_variable['lambda1']
736
            l_density = self.calculated_variable['l_density']
737
            v_density = self.calculated_variable['v_density']
738
            tp_quality = self.calculated_variable['tp_quality']
739

    
740
            tp_c1 = 2 + (32 * (1 - 0.16 * (2.5 + lambda1) ** 2) ** 3) / (1 + 0.005664 * tp_massflux_c ** 0.8)
741
            tp_c2 = (v_density / l_density) ** 0.5 + (l_density / v_density) ** 0.5
742
            tp_c3 = ((l_density / v_density) ** 0.125) / (
743
                    (tp_quality + (1 - tp_quality) * (v_density / l_density)) ** 0.5)
744

    
745
            if tp_c1 > tp_c2:
746
                tp_c_prime = tp_c1
747
            else:
748
                # (5) 최종 판별
749
                if tp_c3 > tp_c2 > tp_c1:
750
                    tp_c_prime = tp_c2
751
                elif tp_c2 > tp_c3 > tp_c1:
752
                    tp_c_prime = tp_c3
753
                elif tp_c2 > tp_c1 > tp_c3:
754
                    tp_c_prime = tp_c1
755

    
756
            tp_rea_rough = self.calculated_variable['tp_rea_rough']
757
            tp_C = tp_c_prime * ((1 + 10 ** (-200 * tp_rea_rough)) / 2)
758

    
759
            self.calculated_variable['tp_C'] = tp_C
760
        except Exception as ex:
761
            from App import App
762
            from AppDocData import MessageType
763

    
764
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
765
                                                           sys.exc_info()[-1].tb_lineno)
766
            App.mainWnd().addMessage.emit(MessageType.Error, message)
767

    
768
    def tp_fric(self, row):
769
        try:
770
            tp_massflux = self.calculated_variable['tp_massflux']
771
            tp_quality = self.calculated_variable['tp_quality']
772
            tp_id = self.calculated_variable['tp_id']
773
            l_visco = self.calculated_variable['l_viscosity']
774
            v_visco = self.calculated_variable['v_viscosity']
775

    
776
            l_rey = tp_massflux * (1 - tp_quality) * tp_id / l_visco
777
            v_rey = tp_massflux * tp_quality * tp_id / v_visco
778

    
779
            roughness_unit = self.units['Roughness']
780
            tp_rough = float(self.geometry.item(row, 4).text())
781
            if roughness_unit == 'm':
782
                tp_rough = tp_rough
783
            elif roughness_unit == 'ft':
784
                tp_rough = tp_rough * 0.3048
785
            elif roughness_unit == 'in':
786
                tp_rough = tp_rough * 0.0254
787
            elif roughness_unit == 'mm':
788
                tp_rough = tp_rough * 0.001
789

    
790
            tp_rea_rough = tp_rough / tp_id
791
            self.calculated_variable['tp_rea_rough'] = tp_rea_rough
792

    
793
            if l_rey <= 2100:
794
                l_f = 16 / l_rey
795
            else:
796
                l_f = (-4 * (math.log(tp_rough / 3.7 / tp_id - 5.02 / l_rey * (
797
                        math.log(tp_rough / tp_id / 3.7 + (6.7 / l_rey) ** 0.9) / math.log(10))) / math.log(10))) ** (
798
                          -2)
799

    
800
            if v_rey <= 2100:
801
                v_f = 16 / v_rey
802
            else:
803
                v_f = (-4 * (math.log(tp_rough / 3.7 / tp_id - 5.02 / v_rey * (
804
                        math.log(tp_rough / tp_id / 3.7 + (6.7 / v_rey) ** 0.9) / math.log(10))) / math.log(10))) ** (
805
                          -2)
806

    
807
            tp_flow = self.calculated_variable['tp_flow']
808
            l_density = self.calculated_variable['l_density']
809
            v_density = self.calculated_variable['v_density']
810

    
811
            # 이 f 값들은 현재 moody friction factor들임
812
            l_vel = tp_flow * (1 - tp_quality) / l_density / tp_id ** 2 / 3.1415 * 4
813
            v_vel = tp_flow * tp_quality / v_density / tp_id ** 2 / 3.1415 * 4
814

    
815
            self.calculated_variable['l_vel'] = l_vel
816
            self.calculated_variable['v_vel'] = v_vel
817

    
818
            l_dp_fric = 2 * l_f * 1 * tp_massflux ** 2 * (1 - tp_quality) ** 2 / tp_id / l_density / 101325 * 1.033
819
            v_dp_fric = 2 * v_f * 1 * tp_massflux ** 2 * tp_quality ** 2 / tp_id / v_density / 101325 * 1.033
820
            self.calculated_variable['l_dp_fric'] = l_dp_fric
821
            self.calculated_variable['v_dp_fric'] = v_dp_fric
822

    
823
            self.tp_c_cal()
824

    
825
            tp_C = self.calculated_variable['tp_C']
826
            tp_dp_fric = l_dp_fric + tp_C * (l_dp_fric * v_dp_fric) ** 0.5 + v_dp_fric
827

    
828
            self.calculated_variable['tp_dp_fric'] = tp_dp_fric
829

    
830
        except Exception as ex:
831
            from App import App
832
            from AppDocData import MessageType
833

    
834
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
835
                                                           sys.exc_info()[-1].tb_lineno)
836
            App.mainWnd().addMessage.emit(MessageType.Error, message)
837

    
838
    def tp_stat(self, row):
839
        try:
840
            tp_angle = self.geometry.item(row, 6).text()
841
            if is_not_blank(tp_angle):
842
                tp_angle = float(tp_angle)
843
            else:
844
                tp_angle = 0
845
            self.calculated_variable['tp_angle'] = tp_angle
846

    
847
            tp_mean_den = self.calculated_variable['tp_mean_den']
848
            tp_dp_stat = tp_mean_den * 9.81 * 1 * math.sin(tp_angle / 180 * 3.1415) / 101325 * 1.033
849

    
850
            self.calculated_variable['tp_dp_stat'] = tp_dp_stat
851
        except Exception as ex:
852
            from App import App
853
            from AppDocData import MessageType
854

    
855
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
856
                                                           sys.exc_info()[-1].tb_lineno)
857
            App.mainWnd().addMessage.emit(MessageType.Error, message)
858

    
859
    def momen(self):
860
        try:
861
            tp_dp_fric = self.calculated_variable['tp_dp_fric']
862
            tp_dp_stat = self.calculated_variable['tp_dp_stat']
863
            tp_massflux = self.calculated_variable['tp_massflux']
864
            tp_quality = self.calculated_variable['tp_quality']
865
            tp_pressure = self.calculated_variable['tp_pressure']
866
            v_density = self.calculated_variable['v_density']
867

    
868
            tp_pipe_total_drop = (tp_dp_fric + tp_dp_stat) / (
869
                (1 - (tp_massflux ** 2 * tp_quality / (tp_pressure / 1.033 * 101325) / v_density)))
870

    
871
            self.calculated_variable['tp_pipe_total_drop'] = tp_pipe_total_drop
872
            tp_dp_momen = tp_pipe_total_drop - tp_dp_fric - tp_dp_stat
873

    
874
            self.calculated_variable['tp_dp_momen'] = tp_dp_momen
875

    
876
        except Exception as ex:
877
            from App import App
878
            from AppDocData import MessageType
879

    
880
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
881
                                                           sys.exc_info()[-1].tb_lineno)
882
            App.mainWnd().addMessage.emit(MessageType.Error, message)
883

    
884
    def tp_dp_input(self):
885
        try:
886
            tp_dp_fric = self.calculated_variable['tp_dp_fric']
887
            tp_dp_stat = self.calculated_variable['tp_dp_stat']
888
            tp_dp_momen = self.calculated_variable['tp_dp_momen']
889

    
890
            # 현재 kg/cm2/m
891
            pressure_unit = self.units['Pressure']
892
            if pressure_unit == 'kg/cm2':
893
                tp_dp_fric = tp_dp_fric
894
                tp_dp_stat = tp_dp_stat
895
                tp_dp_momen = tp_dp_momen
896
            elif pressure_unit == 'psi':
897
                tp_dp_fric = tp_dp_fric / 1.033 * 14.7
898
                tp_dp_stat = tp_dp_stat / 1.033 * 14.7
899
                tp_dp_momen = tp_dp_momen / 1.033 * 14.7
900
            elif pressure_unit == 'atm':
901
                tp_dp_fric = tp_dp_fric / 1.033
902
                tp_dp_stat = tp_dp_stat / 1.033
903
                tp_dp_momen = tp_dp_momen / 1.033
904
            elif pressure_unit == 'bar':
905
                tp_dp_fric = tp_dp_fric / 1.033 * 1.033
906
                tp_dp_stat = tp_dp_stat / 1.033 * 1.033
907
                tp_dp_momen = tp_dp_momen / 1.033 * 1.033
908
            elif pressure_unit == 'mmHg':
909
                tp_dp_fric = tp_dp_fric / 1.033 * 760
910
                tp_dp_stat = tp_dp_stat / 1.033 * 760
911
                tp_dp_momen = tp_dp_momen / 1.033 * 760
912
            elif pressure_unit == 'kPa':
913
                tp_dp_fric = tp_dp_fric / 1.033 * 101.325
914
                tp_dp_stat = tp_dp_stat / 1.033 * 101.325
915
                tp_dp_momen = tp_dp_momen / 1.033 * 101.325
916
            elif pressure_unit == 'MPa':
917
                tp_dp_fric = tp_dp_fric / 1.033 * 0.101325
918
                tp_dp_stat = tp_dp_stat / 1.033 * 0.101325
919
                tp_dp_momen = tp_dp_momen / 1.033 * 0.101325
920

    
921
            length_unit = self.units['Length']
922
            if length_unit == 'm':
923
                tp_dp_fric = tp_dp_fric
924
                tp_dp_stat = tp_dp_stat
925
                tp_dp_momen = tp_dp_momen
926
            elif length_unit == 'in':
927
                tp_dp_fric = tp_dp_fric / 39.3701
928
                tp_dp_stat = tp_dp_stat / 39.3701
929
                tp_dp_momen = tp_dp_momen / 39.3701
930
            elif length_unit == 'ft':
931
                tp_dp_fric = tp_dp_fric / 3.28084
932
                tp_dp_stat = tp_dp_stat / 3.28084
933
                tp_dp_momen = tp_dp_momen / 3.28084
934
            elif length_unit == 'yd':
935
                tp_dp_fric = tp_dp_fric / 1.09361
936
                tp_dp_stat = tp_dp_stat / 1.09361
937
                tp_dp_momen = tp_dp_momen / 1.09361
938
            elif length_unit == 'mile':
939
                tp_dp_fric = tp_dp_fric / 0.000621371
940
                tp_dp_stat = tp_dp_stat / 0.000621371
941
                tp_dp_momen = tp_dp_momen / 0.000621371
942
            elif length_unit == 'mm':
943
                tp_dp_fric = tp_dp_fric / 1000
944
                tp_dp_stat = tp_dp_stat / 1000
945
                tp_dp_momen = tp_dp_momen / 1000
946

    
947
            f = tp_dp_fric
948
            g = tp_dp_stat
949
            m = tp_dp_momen
950

    
951
            self.dp_fric[self.no] = f
952
            self.dp_stat[self.no] = g
953
            self.dp_momen[self.no] = m
954

    
955
            self.calculated_variable['tp_dp_fric'] = tp_dp_fric
956
            self.calculated_variable['tp_dp_stat'] = tp_dp_stat
957
            self.calculated_variable['tp_dp_momen'] = tp_dp_momen
958

    
959
            # ToDo
960
            # 2_DB 시트에 값 입력
961
        except Exception as ex:
962
            from App import App
963
            from AppDocData import MessageType
964

    
965
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
966
                                                           sys.exc_info()[-1].tb_lineno)
967
            App.mainWnd().addMessage.emit(MessageType.Error, message)
968

    
969
    def tp_v_density_cal(self):
970
        try:
971
            tp_pressure_ratio = self.calculated_variable['tp_pressure_ratio']
972

    
973
            # (1) vapor 를 kg/m3로 맞춤
974
            if is_not_blank(self.process['v_density']):
975
                density_unit = self.units['Density']
976
                if density_unit == 'kg/m3':
977
                    v_density = self.calculated_variable['v_density'] * tp_pressure_ratio  # float(self.process['v_density']) * tp_pressure_ratio
978
                elif density_unit == 'lb/ft3':
979
                    v_density = self.calculated_variable['v_density'] * 16.0185 * tp_pressure_ratio # float(self.process['v_density']) * 16.0185 * tp_pressure_ratio
980
            else:
981
                temperature_unit = self.units['Temperature']
982
                if temperature_unit == '':
983
                    v_temp = float(self.process['v_temp']) + 273.15
984
                elif temperature_unit == '':
985
                    v_temp = (float(self.process['v_temp']) - 32) / 1.8 + 273.15
986

    
987
                self.calculated_variable['v_temp'] = v_temp
988

    
989
                v_mw = float(self.process['v_mw'])
990

    
991
                v_z = float(self.process['v_z'])
992

    
993
                v_density = self.calculated_variable['tp_pressure'] * v_mw / 0.08206 / v_temp / v_z / 1.033
994

    
995
            self.calculated_variable['v_density'] = v_density
996

    
997
        except Exception as ex:
998
            from App import App
999
            from AppDocData import MessageType
1000

    
1001
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1002
                                                           sys.exc_info()[-1].tb_lineno)
1003
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1004

    
1005
    def regime_input(self, xx, yy, regime):
1006
        try:
1007
            self.x[self.no] = xx
1008
            self.y[self.no] = yy
1009
            self.regime[self.no] = regime
1010
        except Exception as ex:
1011
            from App import App
1012
            from AppDocData import MessageType
1013

    
1014
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1015
                                                           sys.exc_info()[-1].tb_lineno)
1016
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1017

    
1018
    def tp_ho_regime(self):
1019
        try:
1020
            l_dp_fric = self.calculated_variable['l_dp_fric']
1021
            v_dp_fric = self.calculated_variable['v_dp_fric']
1022

    
1023
            hoX = (l_dp_fric / v_dp_fric) ** 0.5
1024

    
1025
            tp_massflux = self.calculated_variable['tp_massflux']
1026
            tp_quality = self.calculated_variable['tp_quality']
1027
            l_density = self.calculated_variable['l_density']
1028
            v_density = self.calculated_variable['v_density']
1029
            tp_id = self.calculated_variable['tp_id']
1030
            l_visco = self.calculated_variable['l_viscosity']
1031
            v_visco = self.calculated_variable['v_viscosity']
1032

    
1033
            hoFr = (tp_massflux * tp_quality / v_density) * (
1034
                    v_density / ((l_density - v_density) * tp_id * 9.81)) ** 0.5
1035
            hoFr1 = 1 / ((hoX ** 1.76) + 2 * (hoX ** 0.5) + 0.45)
1036

    
1037
            hoK = hoFr * (tp_massflux * (1 - tp_quality) * tp_id / l_visco) ** 0.5
1038
            hoK1 = (0.13 * hoX ** -0.39 + 0.21 * hoX ** 0.39) ** -1.67
1039

    
1040
            hoT = ((l_dp_fric / 1.033 * 101325) / (9.81 * (l_density - v_density))) ** 0.5
1041
            hoT1 = (0.72 + 0.05 * hoX ** 0.8) ** -0.5
1042

    
1043
            if hoFr1 > hoFr:
1044
                # K와 X의 비교
1045
                if hoK1 > hoK:
1046
                    regime = 'Stratified'
1047
                elif hoK1 < hoK:
1048
                    regime = 'Wavy'
1049
                YY = hoK / 1000
1050
            elif hoFr1 < hoFr:
1051
                if hoX < 1.6:
1052
                    regime = 'Annular'
1053
                    YY = hoFr
1054
                else:
1055
                    if hoT > hoT1:
1056
                        regime = 'Bubble'
1057
                        YY = hoT
1058
                        if hoT < hoFr1:
1059
                            YY = hoFr1
1060
                    elif hoT < hoT1:
1061
                        regime = 'Slug / Plug'
1062
                        YY = hoT
1063
                        if hoT < hoFr1:
1064
                            YY = hoFr1
1065

    
1066
            xx = hoX
1067

    
1068
            self.regime_input(xx, YY, regime)
1069

    
1070
        except Exception as ex:
1071
            from App import App
1072
            from AppDocData import MessageType
1073

    
1074
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1075
                                                           sys.exc_info()[-1].tb_lineno)
1076
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1077

    
1078
    def tp_vd_regime(self):
1079
        try:
1080
            l_vel = self.calculated_variable['l_vel']
1081
            v_vel = self.calculated_variable['v_vel']
1082

    
1083
            a_o = 1.2903 * l_vel - 0.25806
1084
            o_p = 0.984375 * l_vel - 0.39375
1085

    
1086
            if v_vel > o_p:
1087
                regime = 'Annular'
1088
            else:
1089
                if v_vel > o_p:
1090
                    regime = 'Oscillary'
1091
                else:
1092
                    regime = 'Bubble'
1093

    
1094
            XX = l_vel
1095
            YY = v_vel
1096

    
1097
            self.regime_input(XX, YY, regime)
1098
        except Exception as ex:
1099
            from App import App
1100
            from AppDocData import MessageType
1101

    
1102
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1103
                                                           sys.exc_info()[-1].tb_lineno)
1104
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1105

    
1106
    def tp_vu_regime(self):
1107
        try:
1108
            l_density = self.calculated_variable['l_density']
1109
            v_density = self.calculated_variable['v_density']
1110
            l_vel = self.calculated_variable['l_vel']
1111
            v_vel = self.calculated_variable['v_vel']
1112

    
1113
            xx = l_density * l_vel ** 2
1114
            YY = v_density * v_vel ** 2
1115

    
1116
            xbub = 32000 * (YY / 1.15) ** -1.4175
1117
            ybub = 7500 * (YY / 3.2) ** -0.3214
1118

    
1119
            # bubble
1120
            if YY < 3.2 and xx > xbub:
1121
                regime = 'Bubble'
1122
                self.regime_input(xx, YY, regime)
1123
                return
1124

    
1125
            if 10 > YY > 3.2 and xx > ybub:
1126
                regime = 'Bubble'
1127
                self.regime_input(xx, YY, regime)
1128
                return
1129

    
1130
            if 10 < YY < 100 and xx > 5200:
1131
                regime = 'Bubble'
1132
                self.regime_input(xx, YY, regime)
1133
                return
1134

    
1135
            # churn
1136
            churn1 = 6.5 * (YY / 0.1) ** 0.4375
1137
            churn2 = 17.8 * (YY / 1) ** 0.7496
1138
            churn3 = 100 * (YY / 10) ** 1.4256
1139
            churn4 = 525 * (YY / 32) ** 3.9719
1140
            churn5 = 10 * (YY / 100) ** -2.5129
1141

    
1142
            if YY > 100 and xx < 10 and xx < churn5:
1143
                regime = 'Churn'
1144
                self.regime_input(xx, YY, regime)
1145
                return
1146

    
1147
            if YY < 1 and xx < churn1:
1148
                regime = 'Churn'
1149
                self.regime_input(xx, YY, regime)
1150
                return
1151

    
1152
            if YY < 10 and xx < churn2:
1153
                regime = 'Churn'
1154
                self.regime_input(xx, YY, regime)
1155
                return
1156

    
1157
            if YY < 32 and xx < churn3:
1158
                regime = 'Churn'
1159
                self.regime_input(xx, YY, regime)
1160
                return
1161

    
1162
            if YY < 57 and xx < churn4:
1163
                regime = 'Churn'
1164
                self.regime_input(xx, YY, regime)
1165
                return
1166

    
1167
            if YY < 100 and xx < 5200 and xx < churn4:
1168
                regime = 'Churn'
1169
                self.regime_input(xx, YY, regime)
1170
                return
1171

    
1172
            # Wispy Annular
1173
            wisa1 = 1150 * (YY / 1000) ** 0.2704
1174
            wisa2 = 1575 * (YY / 3200) ** 0.9016
1175

    
1176
            if 100 < YY < 1000 and xx > 1150:
1177
                regime = 'Wispy Annular'
1178
                self.regime_input(xx, YY, regime)
1179
                return
1180

    
1181
            if 10000 < YY < 3200 and xx > wisa1:
1182
                regime = 'Wispy Annular'
1183
                self.regime_input(xx, YY, regime)
1184
                return
1185

    
1186
            if YY > 3200 and xx > wisa2:
1187
                regime = 'Wispy Annular'
1188
                self.regime_input(xx, YY, regime)
1189
                return
1190

    
1191
            # Annular
1192
            ann1 = 1150 * (YY / 1000) ** 0.2704
1193
            ann2 = 1575 * (YY / 3200) ** 0.9016
1194
            ann3 = 10 * (YY / 100) ** -2.5129
1195

    
1196
            if 100 < YY < 1000 and 10 < xx < 1150:
1197
                regime = 'Annular'
1198
                self.regime_input(xx, YY, regime)
1199
                return
1200

    
1201
            if 1000 < YY < 3200 and xx < ann1:
1202
                regime = 'Annular'
1203
                self.regime_input(xx, YY, regime)
1204
                return
1205

    
1206
            if YY > 3200 and xx < ann2:
1207
                regime = 'Annular'
1208
                self.regime_input(xx, YY, regime)
1209
                return
1210

    
1211
            if 10 > xx > ann3 and YY > 100:
1212
                regime = 'Annular'
1213
                self.regime_input(xx, YY, regime)
1214
                return
1215

    
1216
            # Bubbly Plug
1217
            bslug1 = 6.5 * (YY / 0.1) ** 0.4375
1218
            bslug2 = 17.8 * (YY / 1) ** 0.7496
1219
            bslug3 = 100 * (YY / 10) ** 1.4256
1220
            bslug4 = 525 * (YY / 32) ** 3.9719
1221
            bslug5 = 32000 * (YY / 1.15) ** -1.4175
1222
            bslug6 = 7500 * (YY / 3.2) ** -0.3214
1223

    
1224
            if YY < 1 and bslug1 < xx < bslug5:
1225
                if xx > 1000:
1226
                    regime = 'Bubbly Plug'
1227
                elif xx < 1000:
1228
                    regime = 'Plug'
1229
                self.regime_input(xx, YY, regime)
1230
                return
1231

    
1232
            if YY < 3.2 and bslug1 < xx < bslug5:
1233
                if xx > 1000:
1234
                    regime = 'Bubbly Plug'
1235
                elif xx < 1000:
1236
                    regime = 'Plug'
1237
                self.regime_input(xx, YY, regime)
1238
                return
1239

    
1240
            if YY < 10 and bslug2 < xx < bslug6:
1241
                if xx > 1000:
1242
                    regime = 'Bubbly Plug'
1243
                elif xx < 1000:
1244
                    regime = 'Plug'
1245
                self.regime_input(xx, YY, regime)
1246
                return
1247

    
1248
            if YY < 32 and bslug3 < xx < 5200:
1249
                if xx > 1000:
1250
                    regime = 'Bubbly Plug'
1251
                elif xx < 1000:
1252
                    regime = 'Plug'
1253
                self.regime_input(xx, YY, regime)
1254
                return
1255

    
1256
            if YY < 57 and bslug4 < xx < 5200:
1257
                if xx > 1000:
1258
                    regime = 'Bubbly Plug'
1259
                elif xx < 1000:
1260
                    regime = 'Plug'
1261
                self.regime_input(xx, YY, regime)
1262
                return
1263

    
1264
        except Exception as ex:
1265
            from App import App
1266
            from AppDocData import MessageType
1267

    
1268
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1269
                                                           sys.exc_info()[-1].tb_lineno)
1270
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1271

    
1272
    def tp_regime(self, row):
1273
        try:
1274
            tp_angle = self.geometry.item(row, 6).text()
1275
            if is_not_blank(tp_angle):
1276
                tp_angle = float(tp_angle)
1277
            else:
1278
                tp_angle = 0
1279

    
1280
            self.calculated_variable['tp_angle'] = tp_angle
1281

    
1282
            if tp_angle == 0:
1283
                self.tp_ho_regime()
1284
            elif tp_angle < 0:
1285
                self.tp_vd_regime()
1286
            elif tp_angle > 0:
1287
                self.tp_vu_regime()
1288

    
1289
        except Exception as ex:
1290
            from App import App
1291
            from AppDocData import MessageType
1292

    
1293
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1294
                                                           sys.exc_info()[-1].tb_lineno)
1295
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1296

    
1297
    def tp_calc_end(self, row):
1298
        try:
1299
            # ToDo
1300
            # 2_DB 시트에 값 입력
1301

    
1302
            element = self.geometry.item(row, 0).text()
1303
            if element == 'Pipe':
1304
                tp_pressure = self.calculated_variable['tp_pressure']
1305
                tp_length = self.calculated_variable['tp_length']
1306
                tp_pipe_total_drop = self.calculated_variable['tp_pipe_total_drop']
1307

    
1308
                tp_pressure_ratio = (tp_pressure - tp_length * tp_pipe_total_drop) / tp_pressure
1309
                tp_pressure = tp_pressure - tp_length * tp_pipe_total_drop
1310

    
1311
                # 현재 length = m
1312
                length_unit = self.units['Length']
1313
                if length_unit == 'm':
1314
                    t = tp_length
1315
                elif length_unit == 'in':
1316
                    t = tp_length * 39.3701
1317
                elif length_unit == 'ft':
1318
                    t = tp_length * 3.28084
1319
                elif length_unit == 'yd':
1320
                    t = tp_length * 1.09361
1321
                elif length_unit == 'mile':
1322
                    t = tp_length * 0.000621371
1323
                elif length_unit == 'mm':
1324
                    t = tp_length * 1000
1325

    
1326
                # 현재 kg/cm2/m
1327
                pressure_unit = self.units['Pressure']
1328
                if pressure_unit == 'kg/cm2':
1329
                    t = t * tp_pipe_total_drop
1330
                elif pressure_unit == 'psi':
1331
                    t = t * tp_pipe_total_drop / 1.033 * 14.7
1332
                elif pressure_unit == 'atm':
1333
                    t = t * tp_pipe_total_drop / 1.033
1334
                elif pressure_unit == 'bar':
1335
                    t = t * tp_pipe_total_drop / 1.033 * 1.033
1336
                elif pressure_unit == 'mmHg':
1337
                    t = t * tp_pipe_total_drop / 1.033 * 760
1338
                elif pressure_unit == 'kPa':
1339
                    t = t * tp_pipe_total_drop / 1.033 * 101.325
1340
                elif pressure_unit == 'MPa':
1341
                    t = t * tp_pipe_total_drop / 1.033 * 0.101325
1342

    
1343
                if length_unit == 'm':
1344
                    t = t
1345
                elif length_unit == 'in':
1346
                    t = t / 39.3701
1347
                elif length_unit == 'ft':
1348
                    t = t / 3.28084
1349
                elif length_unit == 'yd':
1350
                    t = t / 1.09361
1351
                elif length_unit == 'mile':
1352
                    t = t / 0.000621371
1353
                elif length_unit == 'mm':
1354
                    t = t / 1000
1355
            else:
1356
                tp_pressure = self.calculated_variable['tp_pressure']
1357
                tp_element_dp = self.calculated_variable['tp_element_dp']
1358

    
1359
                tp_pressure_ratio = (tp_pressure - tp_element_dp) / tp_pressure
1360
                tp_pressure = tp_pressure - tp_element_dp
1361

    
1362
                # 현재 kg/cm2/m
1363
                pressure_unit = self.units['Pressure']
1364
                if pressure_unit == 'kg/cm2':
1365
                    t = tp_element_dp
1366
                elif pressure_unit == 'psi':
1367
                    t = tp_element_dp / 1.033 * 14.7
1368
                elif pressure_unit == 'atm':
1369
                    t = tp_element_dp / 1.033
1370
                elif pressure_unit == 'bar':
1371
                    t = tp_element_dp / 1.033 * 1.033
1372
                elif pressure_unit == 'mmHg':
1373
                    t = tp_element_dp / 1.033 * 760
1374
                elif pressure_unit == 'kPa':
1375
                    t = tp_element_dp / 1.033 * 101.325
1376
                elif pressure_unit == 'MPa':
1377
                    t = tp_element_dp / 1.033 * 0.101325
1378

    
1379
            self.total_length[self.no] = t
1380

    
1381
            self.calculated_variable['tp_pressure'] = tp_pressure
1382
            self.calculated_variable['tp_pressure_ratio'] = tp_pressure_ratio
1383

    
1384
            self.tp_v_density_cal()
1385
            self.void_frac(row)
1386
            self.tp_property_input(row)
1387
            if element == 'Pipe':
1388
                self.tp_regime(row)
1389

    
1390
        except Exception as ex:
1391
            from App import App
1392
            from AppDocData import MessageType
1393

    
1394
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1395
                                                           sys.exc_info()[-1].tb_lineno)
1396
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1397

    
1398
    def decision_length(self, row):
1399
        try:
1400
            length_unit = self.units['Length']
1401
            tp_length = float(self.geometry.item(row, 5).text())
1402
            if length_unit == 'm':
1403
                tp_length = tp_length
1404
            elif length_unit == 'in':
1405
                tp_length = tp_length * 0.0254
1406
            elif length_unit == 'ft':
1407
                tp_length = tp_length * 0.3048
1408
            elif length_unit == 'yd':
1409
                tp_length = tp_length * 0.9144
1410
            elif length_unit == 'mile':
1411
                tp_length = tp_length * 1609.344
1412
            elif length_unit == 'mm':
1413
                tp_length = tp_length * 0.001
1414

    
1415
            self.calculated_variable['tp_length'] = tp_length
1416

    
1417
            # '5% 분기점
1418
            tp_pressure = self.calculated_variable['tp_pressure']
1419
            calc_factor = 0.95
1420

    
1421
            tp_pressure_est = tp_pressure * calc_factor
1422
            tp_pipe_total_drop = self.calculated_variable['tp_pipe_total_drop']
1423

    
1424
            if (tp_pressure - tp_pressure_est) > (tp_length * tp_pipe_total_drop):
1425
                self.tp_calc_end(row)
1426
            elif (tp_pressure - tp_pressure_est) < (tp_length * tp_pipe_total_drop):
1427
                # 이 안에다 for 문들 다시 만들어야 함 모자란 길이 반복 계산
1428
                tp_remain_length = tp_length - (tp_pressure - tp_pressure_est) / tp_pipe_total_drop
1429
                tp_length = (tp_pressure - tp_pressure_est) / tp_pipe_total_drop
1430
                self.calculated_variable['tp_length'] = tp_length
1431
                tp_total_length = tp_remain_length + tp_length
1432

    
1433
                # 무조건 처음에 한번은 해야할것 (tp_calc_end와 동일)
1434
                self.tp_calc_end(row)
1435

    
1436
                self.no += 1
1437

    
1438
                tp_trial_length = 0
1439
                for tp_trial in range(1, 100):
1440
                    tp_trial_length += tp_length
1441
                    self.tp_fric(row)
1442
                    self.tp_stat(row)
1443
                    self.momen()
1444

    
1445
                    tp_pressure = self.calculated_variable['tp_pressure']
1446
                    tp_pipe_total_drop = self.calculated_variable['tp_pipe_total_drop']
1447
                    tp_pressure_est = tp_pressure * calc_factor
1448
                    tp_remain_length = tp_total_length - tp_trial_length - (tp_pressure - tp_pressure_est) / tp_pipe_total_drop
1449

    
1450
                    # tp_length 재정의
1451
                    if tp_remain_length < 0:
1452
                        # 계산이 끝나는 시점
1453
                        tp_length = tp_total_length - tp_trial_length
1454
                        self.calculated_variable['tp_length'] = tp_length
1455
                        self.tp_dp_input()
1456
                        self.tp_calc_end(row)
1457
                        break
1458
                    elif tp_remain_length > 0:
1459
                        tp_length = (tp_pressure - tp_pressure_est) / tp_pipe_total_drop
1460
                        self.calculated_variable['tp_length'] = tp_length
1461
                        self.tp_dp_input()
1462
                        self.tp_calc_end(row)
1463
                        self.no += 1
1464
        except Exception as ex:
1465
            from App import App
1466
            from AppDocData import MessageType
1467

    
1468
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1469
                                                           sys.exc_info()[-1].tb_lineno)
1470
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1471

    
1472
    def tp_pipe_cal(self, row):
1473
        try:
1474
            self.tp_fric(row)
1475
            self.tp_stat(row)
1476
            self.momen()
1477
            self.tp_dp_input()
1478
            self.decision_length(row)
1479
        except Exception as ex:
1480
            from App import App
1481
            from AppDocData import MessageType
1482

    
1483
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1484
                                                           sys.exc_info()[-1].tb_lineno)
1485
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1486

    
1487
    def tp_bend_cal(self, row):
1488
        try:
1489
            tp_rperd = float(self.geometry.item(row, 7).text())
1490

    
1491
            kval = self.geometry.item(row, 9).text()
1492
            if is_not_blank(kval):
1493
                kval = float(kval)
1494
            else:
1495
                roughness_unit = self.units['Roughness']
1496
                tp_rough = float(self.geometry.item(row, 4).text())
1497
                if roughness_unit == 'm':
1498
                    tp_rough = tp_rough
1499
                elif roughness_unit == 'ft':
1500
                    tp_rough = tp_rough * 0.3048
1501
                elif roughness_unit == 'in':
1502
                    tp_rough = tp_rough * 0.0254
1503
                elif roughness_unit == 'mm':
1504
                    tp_rough = tp_rough * 0.001
1505

    
1506
                pipe_diameter_unit = self.units['Pipe_Diameter']
1507
                tp_id = float(self.geometry.item(row, 3).text())
1508
                if pipe_diameter_unit == 'in':
1509
                    tp_id = tp_id * 0.0254
1510
                elif pipe_diameter_unit == 'mm':
1511
                    tp_id = tp_id / 1000
1512

    
1513
                self.calculated_variable['tp_id'] = tp_id
1514

    
1515
                tp_angle = float(self.geometry.item(row, 6).text())
1516
                tp_rea_rough = tp_rough / tp_id
1517

    
1518
                tp_angle = 3.141593 * tp_angle / 180
1519

    
1520
                tp_massflux = self.calculated_variable['tp_massflux']
1521
                l_visco = self.calculated_variable['l_viscosity']
1522

    
1523
                rey = tp_massflux * tp_id / l_visco
1524
                if rey <= 2100:
1525
                    f = 16 / rey
1526
                else:
1527
                    f = (-2 * (math.log(tp_rough / 3.7 / tp_id - 5.02 / rey * (
1528
                            math.log(tp_rough / tp_id / 3.7 + (6.7 / rey) ** 0.9) / math.log(10))) / math.log(10))) ** (
1529
                            -2)
1530

    
1531
                kf = f * tp_rperd * tp_angle
1532

    
1533
                if tp_rea_rough < 3 * 10 ** -5:
1534
                    fed = 0.027
1535
                else:
1536
                    fed = 0.153 + (0.0121 * math.log(tp_rea_rough))
1537

    
1538
                if rey < 10 ** 4:
1539
                    fre = 0.8854
1540
                elif rey > 3.5 * 10 ** 5:
1541
                    fre = 0.667
1542
                else:
1543
                    fre = 1.45 - 0.0613 * math.log(rey)
1544

    
1545
                kb1 = 2 * tp_angle / 3.141593 * tp_rperd ** 0.5
1546
                kb = kb1 * fed + math.exp(-tp_rperd) * fre
1547

    
1548
                kval = kf + kb
1549

    
1550
            bpara = 1 + 2.2 / (kval * (2 + tp_rperd))
1551

    
1552
            l_density = self.calculated_variable['l_density']
1553
            v_density = self.calculated_variable['v_density']
1554
            tp_quality = self.calculated_variable['tp_quality']
1555
            tp_massflux = self.calculated_variable['tp_massflux']
1556

    
1557
            pilo = 1 + (l_density / v_density - 1) * (bpara * tp_quality * (1 - tp_quality) + tp_quality ** 2)
1558

    
1559
            tp_bend_dp = kval * (tp_massflux ** 2 / 2 / l_density) * pilo / 101325 * 1.033
1560

    
1561
            kval = round(kval, 2)
1562
            self.calculated_variable['kval'] = kval
1563

    
1564
            tp_element_dp = tp_bend_dp
1565
            self.calculated_variable['tp_element_dp'] = tp_element_dp
1566

    
1567
            self.tp_calc_end(row)
1568

    
1569
        except Exception as ex:
1570
            from App import App
1571
            from AppDocData import MessageType
1572

    
1573
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1574
                                                           sys.exc_info()[-1].tb_lineno)
1575
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1576

    
1577
    def tp_nozzl_cal(self, row):
1578
        try:
1579
            kval = self.geometry.item(row, 9).text()
1580
            if is_not_blank(kval):
1581
                kval = float(kval)
1582
            else:
1583
                element = self.geometry.item(row, 0).text()
1584
                if element == 'Nozzle In':
1585
                    kval = 1
1586
                elif element == 'Nozzle Out':
1587
                    kval = 0.5
1588

    
1589
            self.calculated_variable['kval'] = kval
1590
            l_density = self.calculated_variable['l_density']
1591
            v_density = self.calculated_variable['v_density']
1592
            tp_quality = self.calculated_variable['tp_quality']
1593

    
1594
            rat = l_density / v_density
1595
            rho = (v_density * l_density) / (tp_quality * (l_density - v_density) + v_density)
1596
            rath = (l_density / rho) ** 0.5
1597
            braca = (tp_quality * rat) + (rath * (1 - tp_quality))
1598
            bracb = 1 + (rath - 1) ** 2 / (rat ** 0.5 - 1)
1599
            bracb = bracb * (1 - tp_quality) / rath + tp_quality
1600
            pilo = braca * bracb
1601

    
1602
            # kg/cm2의 단위로 되어있음
1603
            tp_massflux = self.calculated_variable['tp_massflux']
1604
            tp_nozzl_total_dp = (kval * tp_massflux ** 2 / 2 / l_density) * pilo / 101325 * 1.033
1605

    
1606
            tp_element_dp = tp_nozzl_total_dp
1607

    
1608
            self.calculated_variable['tp_element_dp'] = tp_element_dp
1609
            self.tp_calc_end(row)
1610

    
1611
        except Exception as ex:
1612
            from App import App
1613
            from AppDocData import MessageType
1614

    
1615
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1616
                                                           sys.exc_info()[-1].tb_lineno)
1617
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1618

    
1619
    def tp_expander_cal(self, row):
1620
        try:
1621
            rod = float(self.geometry.item(row, 8).text())
1622
            rod = 1 / rod  # '이부분, d1/d2 정책으로 인하여 변경되었음
1623

    
1624
            kval = self.geometry.item(row, 9).text()
1625
            if is_not_blank(kval):
1626
                kval = float(kval)
1627
            else:
1628
                angle = float(self.geometry.item(row, 6).text())
1629
                if angle <= 22.5:
1630
                    kval = 2.6 * (1 - rod ** 2) ** 2 / rod ** 4 * math.sin(3.141593 / 180)
1631
                else:
1632
                    kval = (1 - rod ** 2) ** 2 / rod ** 4
1633

    
1634
            self.calculated_variable['kval'] = kval
1635

    
1636
            sigma = rod ** 2
1637

    
1638
            tp_quality = self.calculated_variable['tp_quality']
1639
            tp_void = self.calculated_variable['tp_void']
1640
            l_density = self.calculated_variable['l_density']
1641
            v_density = self.calculated_variable['v_density']
1642
            tp_massflux = self.calculated_variable['tp_massflux']
1643

    
1644
            flsq = (1 - tp_quality) ** 2
1645
            pilo = (tp_quality ** 2 / tp_void) * (l_density / v_density) + flsq / (1 - tp_void)
1646

    
1647
            tp_expander_total_dp = ((
1648
                                            kval - 1 + 1 / sigma ** 2) * tp_massflux ** 2 / 2 / l_density) * pilo / 10 ** 5 / 1.013 * 1.033
1649

    
1650
            tp_element_dp = tp_expander_total_dp
1651
            self.calculated_variable['tp_element_dp'] = tp_element_dp
1652

    
1653
            self.tp_calc_end(row)
1654

    
1655
        except Exception as ex:
1656
            from App import App
1657
            from AppDocData import MessageType
1658

    
1659
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1660
                                                           sys.exc_info()[-1].tb_lineno)
1661
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1662

    
1663
    def tp_reducer_cal(self, row):
1664
        try:
1665
            ang = float(self.geometry.item(row, 6).text())
1666
            rod = float(self.geometry.item(row, 8).text())
1667
            tp_id = float(self.geometry.item(row, 3).text())
1668
            pipe_diameter_unit = self.units['Pipe_Diameter']
1669
            if pipe_diameter_unit == 'in':
1670
                tp_id = tp_id * 0.0254
1671
            elif pipe_diameter_unit == 'mm':
1672
                tp_id = tp_id / 1000
1673

    
1674
            self.calculated_variable['tp_id'] = tp_id
1675

    
1676
            sigma = rod ** 2
1677
            dcube = sigma + rod
1678
            dfive = sigma ** 2 * rod
1679
            ak1 = (8.54038 * dfive) - (19.2214 * sigma ** 2)
1680
            ak2 = (14.24265 * dcube) - (4.53854 * sigma)
1681
            ak3 = (0.39543 * rod) + 0.57806
1682
            kval = ak1 + ak2 + ak3
1683

    
1684
            if ang < 90:
1685
                theta = float(self.geometry.item(row, 6).text()) / 90
1686
                c1 = 0.01791 * math.exp(-9.624 * theta)
1687
                c2 = theta * (1 + theta)
1688
                c3 = 0.03614 * c2 ** 4.79082
1689
                cc = (c1 + c3) ** 0.25
1690

    
1691
                kval = kval * cc
1692

    
1693
            if is_not_blank(self.geometry.item(row, 9).text()):
1694
                kval = float(self.geometry.item(row, 9).text())
1695

    
1696
            self.calculated_variable['kval'] = kval
1697

    
1698
            # fric 구하기
1699
            tp_massflux = self.calculated_variable['tp_massflux']
1700
            tp_quality = self.calculated_variable['tp_quality']
1701
            l_visco = self.calculated_variable['l_viscosity']
1702
            v_visco = self.calculated_variable['v_viscosity']
1703

    
1704
            l_rey = tp_massflux * (1 - tp_quality) * tp_id / l_visco
1705
            v_rey = tp_massflux * tp_quality * tp_id / v_visco
1706

    
1707
            roughness_unit = self.units['Roughness']
1708
            tp_rough = float(self.geometry.item(row, 4).text())
1709
            if roughness_unit == 'm':
1710
                tp_rough = tp_rough
1711
            elif roughness_unit == 'ft':
1712
                tp_rough = tp_rough * 0.3048
1713
            elif roughness_unit == 'in':
1714
                tp_rough = tp_rough * 0.0254
1715
            elif roughness_unit == 'mm':
1716
                tp_rough = tp_rough * 0.001
1717

    
1718
            tp_rea_rough = tp_rough / tp_id
1719
            self.calculated_variable['tp_rea_rough'] = tp_rea_rough
1720

    
1721
            if l_rey <= 2100:
1722
                l_f = 16 / l_rey
1723
            else:
1724
                l_f = (-4 * (math.log(tp_rough / 3.7 / tp_id - 5.02 / l_rey * (
1725
                        math.log(tp_rough / tp_id / 3.7 + (6.7 / l_rey) ** 0.9) / math.log(10))) / math.log(10))) ** (
1726
                          -2)
1727

    
1728
            if v_rey <= 2100:
1729
                v_f = 16 / v_rey
1730
            else:
1731
                v_f = (-4 * (math.log(tp_rough / 3.7 / tp_id - 5.02 / v_rey * (
1732
                        math.log(tp_rough / tp_id / 3.7 + (6.7 / v_rey) ** 0.9) / math.log(10))) / math.log(10))) ** (
1733
                          -2)
1734

    
1735
            # dmvel 정의
1736
            l_flowrate = float(self.process['l_flowrate'])
1737
            v_flowrate = float(self.process['v_flowrate'])
1738

    
1739
            ddia = (rod * tp_id)
1740
            dmvel = (l_flowrate + v_flowrate) / 3600 / (3.141592 / 4 * ddia ** 2)
1741

    
1742
            l_density = self.calculated_variable['l_density']
1743
            v_density = self.calculated_variable['v_density']
1744

    
1745
            drat = l_density / v_density
1746
            ratff = (l_f * v_density) / (v_f * l_density)
1747
            xlm = ratff ** 0.5 * (1 - tp_quality) / tp_quality
1748
            rxlm = 1 / xlm
1749
            flsq = (1 - tp_quality) ** 2
1750
            alm = rxlm * (l_f / v_f) ** 0.5
1751
            alms = alm ** 2
1752
            coff = drat ** 0.5 + (1 / drat) ** 0.5
1753
            phisq = 1 + coff * alm + alms
1754
            tpfm = phisq * flsq
1755

    
1756
            # kg/cm2
1757
            tp_reducer_total_dp = ((
1758
                                           kval + 1 - sigma ** 2) * dmvel ** 2 / 2 / l_density) * tpfm / 10 ** 5 / 1.013 * 1.033
1759
            tp_element_dp = tp_reducer_total_dp
1760
            self.calculated_variable['tp_element_dp'] = tp_element_dp
1761

    
1762
            self.tp_calc_end(row)
1763
        except Exception as ex:
1764
            from App import App
1765
            from AppDocData import MessageType
1766

    
1767
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1768
                                                           sys.exc_info()[-1].tb_lineno)
1769
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1770

    
1771
    def tp_valve_cal(self, row):
1772
        try:
1773
            kval = self.geometry.item(row, 9).text()
1774
            if is_not_blank(kval):
1775
                kval = float(kval)
1776
            else:
1777
                element = self.geometry.item(row, 0).text()
1778
                if element == 'Check Valve':
1779
                    kval = 7
1780
                elif element == 'Ball Valve':
1781
                    kval = 0.1
1782
                elif element == 'Gate Valve':
1783
                    kval = 0.2
1784
                elif element == 'Globe Valve':
1785
                    kval = 0.2
1786
                elif element == 'Butterfly Valve':
1787
                    inside_diameter = float(self.geometry.item(row, 3).text())
1788
                    if inside_diameter < 8.5:
1789
                        kval = 0.76
1790
                    elif 9 < inside_diameter < 15:
1791
                        kval = 0.49
1792
                    elif 15 < inside_diameter < 25:
1793
                        kval = 0.33
1794
                    else:
1795
                        kval = 0.25
1796

    
1797
            self.calculated_variable['kval'] = kval
1798

    
1799
            l_density = self.calculated_variable['l_density']
1800
            v_density = self.calculated_variable['v_density']
1801
            tp_quality = self.calculated_variable['tp_quality']
1802

    
1803
            rat = l_density / v_density
1804
            rho = (v_density * l_density) / (tp_quality * (l_density - v_density) + v_density)
1805
            rath = (l_density / rho) ** 0.5
1806
            braca = (tp_quality * rat) + (rath * (1 - tp_quality))
1807
            bracb = 1 + (rath - 1) ** 2 / (rat ** 0.5 - 1)
1808
            bracb = bracb * (1 - tp_quality) / rath + tp_quality
1809
            pilo = braca * bracb
1810

    
1811
            # kg/cm2의 단위로 되어있음
1812
            tp_massflux = self.calculated_variable['tp_massflux']
1813
            tp_valve_total_dp = (kval * tp_massflux ** 2 / 2 / l_density) * pilo / 101325 * 1.033
1814

    
1815
            tp_element_dp = tp_valve_total_dp
1816
            self.calculated_variable['tp_element_dp'] = tp_element_dp
1817

    
1818
            self.tp_calc_end(row)
1819

    
1820
        except Exception as ex:
1821
            from App import App
1822
            from AppDocData import MessageType
1823

    
1824
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1825
                                                           sys.exc_info()[-1].tb_lineno)
1826
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1827

    
1828
    def get_equivalent_length(self):
1829
        equivalent_length = 0
1830

    
1831
        for row in range(self.geometry.rowCount()):
1832
            if is_not_blank(self.geometry.item(row, 5).text()):
1833
                length = float(self.geometry.item(row, 5).text())
1834
                if length:
1835
                    equivalent_length += length
1836

    
1837
        return equivalent_length
1838

    
1839
    def tp_result_input(self):
1840
        from AppDocData import AppDocData
1841
        try:
1842
            drawing = AppDocData.instance().activeDrawing
1843
            if drawing:
1844
                values = {}
1845
                values['Phase_Type'] = 'Mixed'
1846
                values['Vapor_Flowrate_Mass'] = self.process['v_flowrate']
1847
                values['Vapor_Density'] = self.process['v_density']
1848
                values['Vapor_Viscosity'] = self.process['v_viscosity']
1849
                values['Vapor_Pressure'] = self.process['tp_pressure']
1850
                values['Vapor_Temperature'] = self.process['v_temp']
1851
                values['Vapor_Molecular_Weight'] = self.process['v_mw']
1852
                values['Vapor_Compress_Factor'] = self.process['v_z']
1853
                values['Liquid_Flowrate_Mass'] = self.process['l_flowrate']
1854
                values['Liquid_Density'] = self.process['l_density']
1855
                values['Liquid_Viscosity'] = self.process['l_viscosity']
1856
                values['Flowrate_Mass'] = float(self.process['v_flowrate']) + float(self.process['l_flowrate'])
1857
                values['Viscosity'] = 'Mixed'
1858
                values['Temperature'] = self.process['v_temp']
1859
                values['Molecular_Weight'] = self.process['v_mw']
1860
                values['Specific_Heat_Ratio'] = 'Mixed'
1861
                values['Compress_Factor'] = self.process['v_z']
1862
                values['Limitation_Velocity'] = 'Mixed'
1863
                values['Limitation_Pressure_Drop'] = 'Mixed'
1864
                values['Reynolds'] = 'Mixed'
1865
                values['Friction_Factor'] = 'Mixed'
1866
                values['Pressure_Drop'] = 'Mixed'
1867
                values['Nominal_Pipe_Size'] = self.geometry.item(0, 1).text()
1868
                values['Schedule_No'] = self.geometry.item(0, 2).text()
1869
                values['Inside_Pipe_Size'] = self.geometry.item(0, 3).text()
1870
                values['Straight_Length'] = 'Mixed'
1871
                equivalent_length = self.get_equivalent_length()
1872
                values['Equivalent_Length'] = equivalent_length
1873
                values['Equivalent_Length_Cal'] = equivalent_length
1874
                values['Roughness'] = self.geometry.item(0, 4).text()
1875

    
1876
                # 이하는 계산 결과 값
1877

    
1878
                stat_result = 0
1879
                fric_result = 0
1880

    
1881
                # gravity
1882
                for no in range(self.no):
1883
                    if no in self.total_length:
1884
                        dp_stat = self.dp_stat[no] if no in self.dp_stat else 0
1885
                        length = self.length[no] if no in self.length else 0
1886
                        stat_result = stat_result + dp_stat * length
1887

    
1888
                        # stat_result = stat_result + self.dp_stat[no] * self.length[no]
1889

    
1890
                # friction
1891
                for no in range(self.no):
1892
                    if no in self.total_length:
1893
                        if no in self.length:
1894
                            total_length = self.total_length[no] if no in self.total_length else 0
1895
                            dp_stat = self.dp_stat[no] if no in self.dp_stat else 0
1896
                            length = self.length[no] if no in self.length else 0
1897
                            fric_result = fric_result + total_length - dp_stat * length
1898
                        else:
1899
                            total_length = self.total_length[no] if no in self.total_length else 0
1900
                            fric_result = fric_result + total_length
1901

    
1902
                values['Pressure_Drop_Friction'] = round(fric_result, 3)
1903
                values['Pressure_Drop_Static'] = round(stat_result, 3)
1904
                values['Velocity'] = self.homo_vel[1]
1905
                values['Density'] = self.mean_den[0]
1906

    
1907
                # 부피유량 계산
1908
                tp_flow = self.calculated_variable['tp_flow']
1909
                tp_mean_den = self.calculated_variable['tp_mean_den']
1910

    
1911
                tp_volume = tp_flow / tp_mean_den * 3600
1912
                # 현재 tp_volume은 m3/h임.부피유량 단위에 맞춰 뿌려줌
1913
                flowrate_volume_unit = self.units['Flowrate_Volume']
1914
                if flowrate_volume_unit == 'm3/h':
1915
                    tp_volume = round(tp_volume, 3)
1916
                elif flowrate_volume_unit == 'l/min':
1917
                    tp_volume = round(tp_volume / 60 * 1000, 3)
1918
                elif flowrate_volume_unit == 'ft3/h':
1919
                    tp_volume = round(tp_volume * 35.3147, 3)
1920
                elif flowrate_volume_unit == 'USgpm':
1921
                    tp_volume = round(tp_volume * 4.40287, 3)
1922
                elif flowrate_volume_unit == 'BPSD':
1923
                    tp_volume = round(tp_volume * 150.955, 3)
1924

    
1925
                values['Flowrate_Volume'] = tp_volume
1926

    
1927
                drawing.hmbTable.updateByUID(self.item.uid, values)
1928
        except Exception as ex:
1929
            from App import App
1930
            from AppDocData import MessageType
1931

    
1932
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1933
                                                           sys.exc_info()[-1].tb_lineno)
1934
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1935

    
1936
    def tp_cal(self):
1937
        try:
1938
            self.no = 0
1939

    
1940
            Ref_baro = self.get_barometric_pressure()
1941
            calc_factor = 0.95
1942

    
1943
            # (1) fixed property
1944
            # mass flowrate
1945
            l_flowrate = float(self.process['l_flowrate'])
1946
            v_flowrate = float(self.process['v_flowrate'])
1947

    
1948
            # mass flowrate를 kg/s로 맞춘다
1949
            flowrate_mass_unit = self.units['Flowrate_Mass']
1950
            if flowrate_mass_unit == 'kg/h':
1951
                tp_flow = (l_flowrate + v_flowrate) / 3600
1952
            elif flowrate_mass_unit == 'g/min':
1953
                tp_flow = (l_flowrate + v_flowrate) / 60 / 1000
1954
            elif flowrate_mass_unit == 'lb/h':
1955
                tp_flow = (l_flowrate + v_flowrate) * 0.000125998
1956
            elif flowrate_mass_unit == 't/h':
1957
                tp_flow = (l_flowrate + v_flowrate) * 0.277778
1958

    
1959
            self.calculated_variable['tp_flow'] = tp_flow
1960

    
1961
            # liquid density
1962
            density_unit = self.units['Density']
1963
            if density_unit == 'kg/m3':
1964
                l_density = float(self.process['l_density'])
1965
            elif density_unit == 'lb/ft3':
1966
                l_density = float(self.process['l_density']) * 16.0185
1967

    
1968
            self.calculated_variable['l_density'] = l_density
1969

    
1970
            # viscosity
1971
            viscosity_unit = self.units['Viscosity']
1972
            if viscosity_unit == 'kg/m.sec':
1973
                l_viscosity = float(self.process['l_viscosity'])
1974
                v_viscosity = float(self.process['v_viscosity'])
1975
            elif viscosity_unit == 'cP':
1976
                l_viscosity = float(self.process['l_viscosity']) * 0.001
1977
                v_viscosity = float(self.process['v_viscosity']) * 0.001
1978
            elif viscosity_unit == 'kg/m.h':
1979
                l_viscosity = float(self.process['l_viscosity']) / 3600
1980
                v_viscosity = float(self.process['v_viscosity']) / 3600
1981
            elif viscosity_unit == 'lb/ft.s':
1982
                l_viscosity = float(self.process['l_viscosity']) * 47.8803
1983
                v_viscosity = float(self.process['v_viscosity']) * 47.8803
1984

    
1985
            self.calculated_variable['l_viscosity'] = l_viscosity
1986
            self.calculated_variable['v_viscosity'] = v_viscosity
1987

    
1988
            # quality 구하기
1989
            tp_quality = v_flowrate / (l_flowrate + v_flowrate)
1990
            self.calculated_variable['tp_quality'] = tp_quality
1991

    
1992
            # (2) initial pressure and property
1993
            # set initial point pressure
1994
            tp_pressure = float(self.process['tp_pressure'])
1995

    
1996
            # pressure를 k/g.a로 맞춘다
1997
            pressure_unit = self.units['Pressure']
1998
            if pressure_unit == 'kg/cm2':
1999
                tp_pressure = tp_pressure + Ref_baro
2000
            elif pressure_unit == 'psi':
2001
                tp_pressure = tp_pressure / 14.7 * 1.033 + Ref_baro
2002
            elif pressure_unit == 'atm':
2003
                tp_pressure = tp_pressure * 1.033 + Ref_baro
2004
            elif pressure_unit == 'bar':
2005
                tp_pressure = tp_pressure / 1.013 * 1.033 + Ref_baro
2006
            elif pressure_unit == 'mmHg':
2007
                tp_pressure = tp_pressure / 760 * 1.033 + Ref_baro
2008
            elif pressure_unit == 'kPa':
2009
                tp_pressure = tp_pressure / 101.325 * 1.033 + Ref_baro
2010
            elif pressure_unit == 'MPa':
2011
                tp_pressure = tp_pressure / 0.101325 * 1.033 + Ref_baro
2012

    
2013
            self.calculated_variable['tp_pressure'] = tp_pressure
2014

    
2015
            self.tp_property(0)
2016
            self.tp_property_input()
2017

    
2018
            self.no += 1
2019

    
2020
            row_count = self.geometry.rowCount()
2021
            for row in range(row_count):
2022
                if self.tp_geo_check(row):
2023
                    break
2024

    
2025
                element = self.geometry.item(row, 0).text()
2026
                if element == 'Pipe':
2027
                    self.tp_pipe_cal(row)
2028
                elif element == 'Bend':
2029
                    self.tp_bend_cal(row)
2030
                elif element == 'Nozzle In':
2031
                    self.tp_nozzl_cal(row)
2032
                elif element == 'Nozzle Out':
2033
                    self.tp_nozzl_cal(row)
2034
                elif element == 'Check Valve':
2035
                    self.tp_valve_cal(row)
2036
                elif element == 'Ball Valve':
2037
                    self.tp_valve_cal(row)
2038
                elif element == 'Gate Valve':
2039
                    self.tp_valve_cal(row)
2040
                elif element == 'Globe Valve':
2041
                    self.tp_valve_cal(row)
2042
                elif element == 'Butterfly Valve':
2043
                    self.tp_valve_cal(row)
2044
                elif element == 'Reducer':
2045
                    self.tp_reducer_cal(row)
2046
                elif element == 'Expander':
2047
                    self.tp_expander_cal(row)
2048

    
2049
                self.no += 1
2050

    
2051
            self.tp_result_input()
2052
        except Exception as ex:
2053
            from App import App
2054
            from AppDocData import MessageType
2055

    
2056
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
2057
                                                           sys.exc_info()[-1].tb_lineno)
2058
            App.mainWnd().addMessage.emit(MessageType.Error, message)
2059

    
2060
    def tp_property_input(self, row=None):
2061
        try:
2062
            baro_P = self.get_barometric_pressure()
2063

    
2064
            # 처음 이면
2065
            if row is not None:
2066
                element = 'Element.{}_{}'.format(str(row), self.geometry.item(row, 0).text())
2067
            else:
2068
                element = 'Start Point'
2069

    
2070
            self.element[self.no] = element
2071

    
2072
            # pressure (현재 kga)
2073
            tp_pressure = self.calculated_variable['tp_pressure']
2074
            pressure_unit = self.units['Pressure']
2075
            if pressure_unit == 'kg/cm2':
2076
                p = tp_pressure - baro_P
2077
            elif pressure_unit == 'psi':
2078
                p = tp_pressure / 1.033 * 14.7 - baro_P
2079
            elif pressure_unit == 'atm':
2080
                p = tp_pressure / 1.033
2081
            elif pressure_unit == 'bar':
2082
                p = tp_pressure / 1.033 * 1.033 - baro_P
2083
            elif pressure_unit == 'mmHg':
2084
                p = tp_pressure / 1.033 * 760 - baro_P
2085
            elif pressure_unit == 'kPa':
2086
                p = tp_pressure / 1.033 * 101.325 - baro_P
2087
            elif pressure_unit == 'MPa':
2088
                p = tp_pressure / 1.033 * 0.101325 - baro_P
2089

    
2090
            self.pressure[self.no] = p
2091

    
2092
            # density (현재 kg/m3)
2093
            density_unit = self.units['Density']
2094
            if density_unit == 'kg/m3':
2095
                d = self.calculated_variable['tp_mean_den']
2096
                vd = self.calculated_variable['v_density']
2097
            else:
2098
                d = self.calculated_variable['tp_mean_den'] * 0.062428
2099
                vd = self.calculated_variable['v_density'] * 0.062428
2100

    
2101
            self.mean_den[self.no] = d
2102
            self.v_density[self.no] = vd
2103

    
2104
            # velocity (m/s)
2105
            velocity_unit = self.units['Velocity']
2106
            if velocity_unit == 'm/s':
2107
                av = self.calculated_variable['tp_homo_vel']
2108
                mv = self.calculated_variable['tp_max_vel']
2109
                ev = self.calculated_variable['tp_ero_vel']
2110
            elif velocity_unit == 'ft/s':
2111
                av = self.calculated_variable['tp_homo_vel'] * 3.28084
2112
                mv = self.calculated_variable['tp_max_vel'] * 3.28084
2113
                ev = self.calculated_variable['tp_ero_vel'] * 3.28084
2114

    
2115
            self.homo_vel[self.no] = av
2116
            self.max_vel[self.no] = mv
2117
            self.ero_vel[self.no] = ev
2118

    
2119
            # dimensionless
2120
            v = self.calculated_variable['tp_void']
2121
            q = self.calculated_variable['tp_quality']
2122

    
2123
            self.void[self.no] = v
2124
            self.quality[self.no] = q
2125

    
2126
            if element != 'Start Point':
2127
                # dia (현재 m)
2128
                pipe_diameter_unit = self.units['Pipe_Diameter']
2129
                if pipe_diameter_unit == 'in':
2130
                    id = self.calculated_variable['tp_id'] / 0.0254
2131
                elif pipe_diameter_unit == 'mm':
2132
                    id = self.calculated_variable['tp_id'] * 1000
2133

    
2134
                self.inside_diameter[self.no] = id
2135

    
2136
                if element.find('Pipe') == -1:
2137
                    self.angle[self.no] = None
2138
                else:
2139
                    # Element가 Pipe인 경우만 l가 있음
2140
                    length_unit = self.units['Length']
2141
                    if length_unit == 'm':
2142
                        l = self.calculated_variable['tp_length']
2143
                    elif length_unit == 'in':
2144
                        l = self.calculated_variable['tp_length'] * 39.3701
2145
                    elif length_unit == 'ft':
2146
                        l = self.calculated_variable['tp_length'] * 3.28084
2147
                    elif length_unit == 'yd':
2148
                        l = self.calculated_variable['tp_length'] * 1.09361
2149
                    elif length_unit == 'mile':
2150
                        l = self.calculated_variable['tp_length'] * 0.000621371
2151
                    elif length_unit == 'mm':
2152
                        l = self.calculated_variable['tp_length'] * 1000
2153

    
2154
                    self.length[self.no] = l
2155

    
2156
                if element.find('Valve') > -1:
2157
                    self.angle[self.no] = None
2158
                else:
2159
                    # Element가 Valve가 아닌경우에만 있음
2160
                    a = self.calculated_variable['tp_angle']
2161
                    self.angle[self.no] = a
2162

    
2163
                if element.find('Pipe') == -1:
2164
                    # Element가 Pipe가 아닌경우에는 k가 있음
2165
                    k = self.calculated_variable['kval']
2166
                    self.k[self.no] = k
2167

    
2168
            # ToDo
2169
            # 2_DB 시트에 값 입력
2170
        except Exception as ex:
2171
            from App import App
2172
            from AppDocData import MessageType
2173

    
2174
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
2175
                                                           sys.exc_info()[-1].tb_lineno)
2176
            App.mainWnd().addMessage.emit(MessageType.Error, message)
2177

    
2178
    def tp_property(self, row):
2179
        try:
2180
            # (0) density calculation
2181

    
2182
            # vapor
2183
            self.tp_v_density_cal_initial()
2184
            self.void_frac(row)
2185

    
2186
        except Exception as ex:
2187
            from App import App
2188
            from AppDocData import MessageType
2189

    
2190
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
2191
                                                           sys.exc_info()[-1].tb_lineno)
2192
            App.mainWnd().addMessage.emit(MessageType.Error, message)
2193

    
2194
    def void_frac(self, row):
2195
        try:
2196
            tp_id = self.geometry.item(row, 3).text()
2197
            if is_not_blank(tp_id):
2198
                # diameter를 m로 맞춘다
2199
                pipe_diameter_unit = self.units['Pipe_Diameter']
2200
                if pipe_diameter_unit == 'in':
2201
                    tp_id = float(tp_id) * 0.0254
2202
                elif pipe_diameter_unit == 'mm':
2203
                    tp_id = float(tp_id) / 1000
2204

    
2205
                self.calculated_variable['tp_id'] = tp_id
2206
                # massflux 구한다 (kg/m^2s) 현재 tp_flow = kg/s, tp_id = m
2207
                tp_flow = self.calculated_variable['tp_flow']
2208
                tp_massflux = tp_flow / ((3.1415 / 4) * (tp_id ** 2))
2209

    
2210
                self.calculated_variable['tp_massflux'] = tp_massflux
2211

    
2212
                tp_angle = self.geometry.item(row, 6).text()
2213
                if is_not_blank(tp_angle):
2214
                    tp_angle = float(tp_angle)
2215
                else:
2216
                    tp_angle = 0
2217
                self.calculated_variable['tp_angle'] = tp_angle
2218

    
2219
                # (2) void frac
2220
                tp_quality = self.calculated_variable['tp_quality']
2221
                l_density = self.calculated_variable['l_density']
2222
                v_density = self.calculated_variable['v_density']
2223

    
2224
                tp_vr1 = tp_quality / (1 - tp_quality) * l_density / v_density
2225
                tp_vr = math.log(tp_vr1) / math.log(10)
2226
                tp_g = math.log(tp_massflux) / math.log(10)
2227

    
2228
                if 0 < tp_angle < 90:
2229
                    tp_a = 1.667 - 0.00206 * tp_angle + 0.247 * math.sin(2 * tp_angle * 3.1415 / 180)
2230
                elif 0 > tp_angle > -90:
2231
                    tp_a = 1.667 + 0.00652 * tp_angle + 0.772 * math.sin(2 * tp_angle * 3.1415 / 180)
2232
                elif tp_angle == 90:
2233
                    tp_a = 1.482
2234
                elif tp_angle == 0:
2235
                    tp_a = 1.667
2236
                elif tp_angle == -90:
2237
                    tp_a = 1.081
2238

    
2239
                l_visco = self.calculated_variable['l_viscosity']
2240
                v_visco = self.calculated_variable['v_viscosity']
2241

    
2242
                baroczy = (v_density / l_density) * (l_visco / v_visco) ** 0.2
2243
                if baroczy < 0.00316:
2244
                    baroczy = 0.00316
2245

    
2246
                lambda1 = math.log(baroczy) / math.log(10)
2247
                self.calculated_variable['lambda1'] = lambda1
2248

    
2249
                tp_logK = (-tp_a * lambda1) / (tp_g + 0.7563) * (1 + 0.1292 * lambda1 * (1 - 0.3792 * tp_vr) * (
2250
                        lambda1 + 4.007) * (1 + 0.1377 * tp_g))
2251

    
2252
                tp_K = 10 ** tp_logK
2253
                if tp_K < 1:
2254
                    tp_K = 1
2255

    
2256
                tp_void = 1 / (1 + tp_K / tp_vr1)
2257
                self.calculated_variable['tp_void'] = tp_void
2258

    
2259
                # mean density 계산 (kg/m3)
2260
                tp_mean_den = l_density * (1 - tp_void) + v_density * tp_void
2261

    
2262
                self.calculated_variable['tp_mean_den'] = tp_mean_den
2263

    
2264
                # homogeneous density 계산 (kg/m3)
2265
                l_flowrate = float(self.process['l_flowrate'])
2266
                v_flowrate = float(self.process['v_flowrate'])
2267

    
2268
                tp_homo_den = l_density * (1 - ((v_flowrate / v_density) / (
2269
                        (v_flowrate / v_density) + (l_flowrate / l_density)))) + v_density * (
2270
                                      (v_flowrate / v_density) / (
2271
                                      (v_flowrate / v_density) + (l_flowrate / l_density)))
2272

    
2273
                # homogeneous vel (m/s)
2274
                tp_homo_vel = tp_massflux * tp_quality / v_density + tp_massflux * (1 - tp_quality) / l_density
2275
                self.calculated_variable['tp_homo_vel'] = tp_homo_vel
2276

    
2277
                # max velocity (m/s)
2278
                tp_max_vel = 122 / (tp_homo_den ** 0.5)
2279
                self.calculated_variable['tp_max_vel'] = tp_max_vel
2280

    
2281
                # erosion velocity (m/s)
2282
                tp_ero_vel = 195 / (tp_homo_den ** 0.5)
2283
                self.calculated_variable['tp_ero_vel'] = tp_ero_vel
2284
            else:
2285
                return
2286
        except Exception as ex:
2287
            from App import App
2288
            from AppDocData import MessageType
2289

    
2290
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
2291
                                                           sys.exc_info()[-1].tb_lineno)
2292
            App.mainWnd().addMessage.emit(MessageType.Error, message)
2293

    
2294
    def tp_v_density_cal_initial(self):
2295
        try:
2296
            # (1) vapor 를 kg/m3로 맞춤
2297
            if is_not_blank(self.process['v_density']):
2298
                density_unit = self.units['Density']
2299
                if density_unit == 'kg/m3':
2300
                    v_density = float(self.process['v_density'])
2301
                elif density_unit == 'lb/ft3':
2302
                    v_density = float(self.process['v_density']) * 16.0185
2303
            else:
2304
                temperature_unit = self.units['Temperature']
2305
                if temperature_unit == '':
2306
                    v_temp = float(self.process['v_temp']) + 273.15
2307
                elif temperature_unit == '':
2308
                    v_temp = (float(self.process['v_temp']) - 32) / 1.8 + 273.15
2309

    
2310
                self.calculated_variable['v_temp'] = v_temp
2311

    
2312
                v_mw = float(self.process['v_mw'])
2313

    
2314
                v_z = float(self.process['v_z'])
2315

    
2316
                v_density = self.calculated_variable['tp_pressure'] * v_mw / 0.08206 / v_temp / v_z / 1.033
2317

    
2318
            self.calculated_variable['v_density'] = v_density
2319

    
2320
        except Exception as ex:
2321
            from App import App
2322
            from AppDocData import MessageType
2323

    
2324
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
2325
                                                           sys.exc_info()[-1].tb_lineno)
2326
            App.mainWnd().addMessage.emit(MessageType.Error, message)
2327

    
2328

    
2329
class Calculation:
2330
    def __init__(self, hmb):
2331
        self._hmb = hmb
2332
        self.units = {}
2333

    
2334
        self.init_units()
2335

    
2336
        if self._hmb.phase_type == 'Liquid':
2337
            if self.validation_check_Liquid():
2338
                self.calculation_Liquid()
2339

    
2340
        '''    
2341
        if self._hmb.phase_type == 'Vapor':
2342
            if self.validation_check_vapor():
2343
                self.calculation_Vapor()
2344
        elif self._hmb.phase_type == 'Liquid':
2345
            if self.validation_check_Liquid():
2346
                self.calculation_Liquid()
2347
        elif self._hmb.phase_type == 'Mixed':
2348
            self.calculation_Mixed()
2349
        '''
2350

    
2351
    def validation_check_vapor(self):
2352
        result = False
2353

    
2354
        if self._hmb.inside_pipe_size is None:
2355
            message = 'You have to input the ID of stream <{}>.'.format(self._hmb.stream_no)
2356
            App.mainWnd().addMessage.emit(MessageType.Information, message)
2357
            return result
2358

    
2359
        if self._hmb.flowrate_mass is None:
2360
            message = 'You have to input mass flowrate of stream <{}>.'.format(self._hmb.stream_no)
2361
            App.mainWnd().addMessage.emit(MessageType.Information, message)
2362
            return result
2363

    
2364
        if self._hmb.specific_heat_ratio is None:
2365
            message = 'You have to input the specific heat ratio of stream <{}>.'.format(self._hmb.stream_no)
2366
            App.mainWnd().addMessage.emit(MessageType.Information, message)
2367
            return result
2368

    
2369
        if self._hmb.viscosity is None:
2370
            message = 'You have to input the viscosity of stream <{}>.'.format(self._hmb.stream_no)
2371
            App.mainWnd().addMessage.emit(MessageType.Information, message)
2372
            return result
2373

    
2374
        if self._hmb.roughness is None:
2375
            message = 'You have to input the roughness of stream <{}>.'.format(self._hmb.stream_no)
2376
            App.mainWnd().addMessage.emit(MessageType.Information, message)
2377
            return result
2378

    
2379
        return True
2380

    
2381
    def validation_check_Liquid(self):
2382
        from App import App
2383
        from AppDocData import MessageType
2384

    
2385
        result = False
2386

    
2387
        # 1.  Equivalent Length
2388
        if self._hmb.equivalent_length is None:
2389
            message = 'The equivalent length of stream <{}> is not inputted.'.format(self._hmb.stream_no)
2390
            App.mainWnd().addMessage.emit(MessageType.Information, message)
2391
            return result
2392

    
2393
        if self._hmb.flowrate_mass is None and self._hmb.flowrate_volume is None:
2394
            message = 'You have to input mass or volume flowrate of stream <{}>.'.format(self._hmb.stream_no)
2395
            App.mainWnd().addMessage.emit(MessageType.Information, message)
2396
            return result
2397

    
2398
        if self._hmb.density is None:
2399
            message = 'You have to input the density of stream <{}>.'.format(self._hmb.stream_no)
2400
            App.mainWnd().addMessage.emit(MessageType.Information, message)
2401
            return result
2402

    
2403
        if self._hmb.inside_pipe_size is None:
2404
            message = 'You have to input the ID of stream <{}>.'.format(self._hmb.stream_no)
2405
            App.mainWnd().addMessage.emit(MessageType.Information, message)
2406
            return result
2407

    
2408
        if self._hmb.viscosity is None:
2409
            message = 'You have to input the viscosity of stream <{}>.'.format(self._hmb.stream_no)
2410
            App.mainWnd().addMessage.emit(MessageType.Information, message)
2411
            return result
2412

    
2413
        if self._hmb.roughness is None:
2414
            message = 'You have to input the roughness of stream <{}>.'.format(self._hmb.stream_no)
2415
            App.mainWnd().addMessage.emit(MessageType.Information, message)
2416
            return result
2417

    
2418
        return True
2419

    
2420
    def init_units(self):
2421
        try:
2422
            app_doc_data = AppDocData.instance()
2423
            self.units = [attr[1] for attr in app_doc_data.activeDrawing.attrs if attr[0] == 'Units'][0]
2424
        except Exception as ex:
2425
            from App import App
2426
            from AppDocData import MessageType
2427

    
2428
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
2429
                                                           sys.exc_info()[-1].tb_lineno)
2430
            App.mainWnd().addMessage.emit(MessageType.Error, message)
2431

    
2432
    def get_barometric_pressure(self):
2433
        pressure_unit = self.units['Pressure']
2434

    
2435
        if pressure_unit == 'kg/cm2':
2436
            barometric_pressure = 1.033
2437
        elif pressure_unit == 'bar':
2438
            barometric_pressure = 1.01325
2439
        elif pressure_unit == 'psi':
2440
            barometric_pressure = 14.7
2441
        elif pressure_unit == 'mmHg':
2442
            barometric_pressure = 760
2443
        elif pressure_unit == 'kPa':
2444
            barometric_pressure = 101.325
2445
        elif pressure_unit == 'MPa':
2446
            barometric_pressure = 0.101325
2447

    
2448
        return barometric_pressure
2449

    
2450
    def getLiquid_Drop_Method(self):
2451
        appDocData = AppDocData.instance()
2452

    
2453
        # Calculation
2454
        liquid_dp_method = appDocData.getConfigs('Calculation', 'Liquid_Drop_Method')
2455

    
2456
        if len(liquid_dp_method) == 1:
2457
            return liquid_dp_method[0].value
2458
        else:
2459
            return 'darcy'
2460

    
2461
    def calculation_Liquid(self):
2462
        try:
2463
            liquid_dp_method = self.getLiquid_Drop_Method()
2464

    
2465
            if liquid_dp_method == 'darcy':
2466
                self.liquid_calc_darcy()
2467
            elif liquid_dp_method == 'hagen':
2468
                self.liquid_calc_hagen()
2469

    
2470
        except Exception as ex:
2471
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
2472
                                                           sys.exc_info()[-1].tb_lineno)
2473
            App.mainWnd().addMessage.emit(MessageType.Error, message)
2474

    
2475
    def liquid_calc_darcy(self):
2476
        from App import App
2477
        from AppDocData import MessageType
2478

    
2479
        try:
2480
            '''
2481
            Incompressible Line 계산
2482
    
2483
            **********************************************************************************
2484
            참고사항 :
2485
            유닛의 기준 : 유량 (kg/h, m3/h), 밀도 (kg/m3), 지름 (m), 점도 (kg/m/s), 속도 (m/s), 압력강하 (kg/cm2/100m)
2486
            **********************************************************************************
2487
            '''
2488

    
2489
            # ********** 1. Flowrate 구하기 ***********
2490
            # (1)질량만 적혀있는경우
2491
            if self._hmb.flowrate_mass and self._hmb.flowrate_volume is None:
2492
                density = self._hmb.density
2493

    
2494
                # '질량유량을 kg/h로 변환.
2495
                flowrate_mass_unit = self.units['Flowrate_Mass']
2496
                if flowrate_mass_unit == 'kg/h':
2497
                    mass = self._hmb.flowrate_mass
2498
                elif flowrate_mass_unit == 'g/min':
2499
                    mass = self._hmb.flowrate_mass * 60 / 1000
2500
                elif flowrate_mass_unit == 'lb/h':
2501
                    mass = self._hmb.flowrate_mass * 0.453592
2502
                elif flowrate_mass_unit == 't/h':
2503
                    mass = self._hmb.flowrate_mass * 1000
2504

    
2505
                # 'density case에 따라 volume rate (m3/h) 계산
2506
                density_unit = self.units['Density']
2507
                if density_unit == 'kg/m3':
2508
                    volume = mass / density
2509
                elif density_unit == 'lb/ft3':
2510
                    volume = mass / (density * 16.0185)
2511

    
2512
                # '부피 유닛에 맞춰서 뿌려줌
2513
                flowrate_volume_unit = self.units['Flowrate_Volume']
2514
                if flowrate_volume_unit == 'm3/h':
2515
                    self._hmb.flowrate_volume = round(volume, 3)
2516
                elif flowrate_volume_unit == 'l/min':
2517
                    self._hmb.flowrate_volume = round(volume / 60 * 1000, 3)
2518
                elif flowrate_volume_unit == 'ft3/h':
2519
                    self._hmb.flowrate_volume = round(volume * 35.3147, 3)
2520
                elif flowrate_volume_unit == 'USgpm':
2521
                    self._hmb.flowrate_volume = round(volume * 4.40287, 3)
2522
                elif flowrate_volume_unit == 'BPSD':
2523
                    self._hmb.flowrate_volume = round(volume * 150.955, 3)
2524

    
2525
            elif self._hmb.flowrate_mass is None and self._hmb.flowrate_volume:  # (2)부피만 적혀있는경우
2526
                density = self._hmb.density
2527

    
2528
                # '부피유량을 m3/h로 변환.
2529
                flowrate_volume_unit = self.units['Flowrate_Volume']
2530
                if flowrate_volume_unit == 'm3/h':
2531
                    volume = self._hmb.flowrate_volume
2532
                elif flowrate_volume_unit == 'l/min':
2533
                    volume = self._hmb.flowrate_volume * 60 / 1000
2534
                elif flowrate_volume_unit == 'ft3/h':
2535
                    volume = self._hmb.flowrate_volume / 35.3147
2536
                elif flowrate_volume_unit == 'USgpm':
2537
                    volume = self._hmb.flowrate_volume / 4.40287
2538
                elif flowrate_volume_unit == 'BPSD':
2539
                    volume = self._hmb.flowrate_volume / 150.955
2540

    
2541
                # 'density case에 따라 mass rate (kg/h) 계산
2542
                density_unit = self.units['Density']
2543
                if density_unit == 'kg/m3':
2544
                    mass = volume * density
2545
                elif density_unit == 'lb/ft3':
2546
                    mass = volume * (density * 16.0185)
2547

    
2548
                # '질량 유닛에 맞춰서 뿌려줌
2549
                flowrate_mass_unit = self.units['Flowrate_Mass']
2550
                if flowrate_mass_unit == 'kg/h':
2551
                    self._hmb.flowrate_mass = round(mass, 3)
2552
                elif flowrate_mass_unit == 'g/min':
2553
                    self._hmb.flowrate_mass = round(mass / 60 * 1000, 3)
2554
                elif flowrate_mass_unit == 'lb/h':
2555
                    self._hmb.flowrate_mass = round(mass * 2.20462, 3)
2556
                elif flowrate_mass_unit == 't/h':
2557
                    self._hmb.flowrate_mass = round(mass * 1000, 3)
2558
            else:
2559
                # (5-3) 둘다 적힌 경우
2560
                density = self._hmb.density
2561

    
2562
                # '질량유량을 kg/h로 변환.
2563
                flowrate_mass_unit = self.units['Flowrate_Mass']
2564
                if flowrate_mass_unit == 'kg/h':
2565
                    mass = self._hmb.flowrate_mass
2566
                elif flowrate_mass_unit == 'g/min':
2567
                    mass = self._hmb.flowrate_mass * 60 / 1000
2568
                elif flowrate_mass_unit == 'lb/h':
2569
                    mass = self._hmb.flowrate_mass * 0.453592
2570
                elif flowrate_mass_unit == 't/h':
2571
                    mass = self._hmb.flowrate_mass * 1000
2572

    
2573
                # 'density case에 따라 volume rate (m3/h) 계산
2574
                density_unit = self.units['Density']
2575
                if density_unit == 'kg/m3':
2576
                    volume = mass / density
2577
                elif density_unit == 'lb/ft3':
2578
                    volume = mass / (density * 16.0185)
2579

    
2580
                # '부피 유닛에 맞춰서 뿌려줌
2581
                flowrate_volume_unit = self.units['Flowrate_Volume']
2582
                if flowrate_volume_unit == 'm3/h':
2583
                    self._hmb.flowrate_volume = round(volume, 3)
2584
                elif flowrate_volume_unit == 'l/min':
2585
                    self._hmb.flowrate_volume = round(volume / 60 * 1000, 3)
2586
                elif flowrate_volume_unit == 'ft3/h':
2587
                    self._hmb.flowrate_volume = round(volume * 35.3147, 3)
2588
                elif flowrate_volume_unit == 'USgpm':
2589
                    self._hmb.flowrate_volume = round(volume * 4.40287, 3)
2590
                elif flowrate_volume_unit == 'BPSD':
2591
                    self._hmb.flowrate_volume = round(volume * 150.955, 3)
2592

    
2593
            # ********** 2. Velocity 구하기 ***********
2594
            # '지름을 m로 변환
2595
            pipe_diameter_unit = self.units['Pipe_Diameter']
2596
            if pipe_diameter_unit == 'in':
2597
                ida = self._hmb.inside_pipe_size * 0.0254
2598
            elif pipe_diameter_unit == 'mm':
2599
                ida = self._hmb.inside_pipe_size / 1000
2600

    
2601
            # '속도 계산 (m/s)
2602
            velocity = 4 * volume / 3.1415 / ida ** 2 / 3600
2603

    
2604
            # '속도 유닛에 맞춰서 뿌려줌
2605
            velocity_unit = self.units['Velocity']
2606
            if velocity_unit == 'm/s':
2607
                self._hmb.velocity = round(velocity, 3)
2608
            elif velocity_unit == 'ft/s':
2609
                self._hmb.velocity = round(velocity * 3.28084, 3)
2610

    
2611
            # ********** 3. Reynolds 수 구하기 ***********
2612

    
2613
            # ' viscosity 유닛 변환 (모두 kg/m.s로 바꿀것임)
2614
            viscosity_unit = self.units['Viscosity']
2615
            if viscosity_unit == 'kg/m.sec':
2616
                viscosity = self._hmb.viscosity
2617
            elif viscosity_unit == 'cP':
2618
                viscosity = self._hmb.viscosity * 0.001
2619
            elif viscosity_unit == 'kg/m.h':
2620
                viscosity = self._hmb.viscosity / 3600
2621
            elif viscosity_unit == 'lb/ft.s':
2622
                viscosity = self._hmb.viscosity * 1.48816
2623

    
2624
            # 'density case에 따라 re계산
2625
            density_unit = self.units['Density']
2626
            if density_unit == 'kg/m3':
2627
                reynolds = ida * velocity * density / viscosity
2628
            elif density_unit == 'lb/ft3':
2629
                reynolds = ida * velocity * (density * 16.0185) / viscosity
2630

    
2631
            # 'MACH 넘버 자리이므로 미입력 처리
2632
            self._hmb.reynolds = '-'
2633

    
2634
            # ********** 4. Friction Factor 구하기 ***********
2635
            # 'roughness 를 m로 바꿔줌
2636
            roughness_unit = self.units['Roughness']
2637
            if roughness_unit == 'm':
2638
                rough = self._hmb.roughness
2639
            elif roughness_unit == 'ft':
2640
                rough = self._hmb.roughness * 0.3048
2641
            elif roughness_unit == 'in':
2642
                rough = self._hmb.roughness * 0.0254
2643
            elif roughness_unit == 'mm':
2644
                rough = self._hmb.roughness * 0.001
2645

    
2646
            # ' reynolds수에 따라 Fanning/Chen friction factor 계산
2647
            if reynolds <= 2100:
2648
                f = 4 * 16 / reynolds
2649
            else:
2650
                a = math.log(rough / ida / 3.7 + (6.7 / reynolds) ** 0.9) / math.log(10)
2651
                f = (-2 * (math.log(rough / 3.7 / ida - 5.02 / reynolds * a) / math.log(10))) ** (-2)
2652

    
2653
            # '뿌려줌
2654
            self._hmb.friction_factor = round(f, 3)
2655

    
2656
            # ********** 5. pressure Drop 구하기 ***********
2657
            # '100m 당 압력강하를 kg/cm2 단위로 구한 후, 설정된 유닛에 맞춰서 conversion후 기입해줌.
2658
            density_unit = self.units['Density']
2659
            if density_unit == 'kg/m3':
2660
                # 100m 당 압력강하
2661
                dp = f * density * (velocity ** 2) / 2 / ida / 9.8066 / 10000 * 100
2662
            elif density_unit == 'lb/ft3':
2663
                # 100m 당 압력강하
2664
                dp = f * (density * 16.0185) * (velocity ** 2) / 2 / ida / 9.8066 / 10000 * 100
2665

    
2666
            pressure_unit = self.units['Pressure']
2667
            if pressure_unit == 'psi':
2668
                dp = dp / 1.033 * 14.7
2669
            elif pressure_unit == 'atm':
2670
                dp = dp / 1.033
2671
            elif pressure_unit == 'bar':
2672
                dp = dp / 1.033 * 1.013
2673
            elif pressure_unit == 'mmHg':
2674
                dp = dp / 1.033 * 760
2675
            elif pressure_unit == 'kPa':
2676
                dp = dp / 1.033 * 101.325
2677
            elif pressure_unit == 'MPa':
2678
                dp = dp / 1.033 * 0.101325
2679

    
2680
            length_unit = self.units['Length']
2681
            if length_unit == 'm':
2682
                self._hmb.pressure_drop = round(dp, 3)
2683
            elif length_unit == 'in':
2684
                self._hmb.pressure_drop = round(dp / 39.3701, 3)
2685
            elif length_unit == 'ft':
2686
                self._hmb.pressure_drop = round(dp / 3.28084, 3)
2687
            elif length_unit == 'yd':
2688
                self._hmb.pressure_drop = round(dp / 1.09361, 3)
2689
            elif length_unit == 'mile':
2690
                self._hmb.pressure_drop = round(dp / 0.000621371, 3)
2691
            elif length_unit == 'mm':
2692
                self._hmb.pressure_drop = round(dp / 1000, 3)
2693

    
2694
            # '100m 당 압력강하를 상당길이에 맞춰서 전체 압력강하로 넣어줌 ..
2695
            self._hmb.pressure_drop_friction = round(self._hmb.pressure_drop / 100 * self._hmb.equivalent_length, 3)
2696

    
2697
        except Exception as ex:
2698

    
2699
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
2700
                                                           sys.exc_info()[-1].tb_lineno)
2701
            App.mainWnd().addMessage.emit(MessageType.Error, message)
2702

    
2703
    def liquid_calc_hagen(self):
2704
        '''
2705
        **************************************************************
2706
          Hagen-Williams 모드에서 사용할 지배식은 다음과 같다.
2707
          h[m] = 10.67 / C^1.85 * Q[m3/s]^1.85 / dia[m]^4.87
2708
          dP[k/g/1m] = h[m] * S.G / 10
2709
        **************************************************************
2710
        '''
2711

    
2712
        # ********** 1. Flowrate 구하기 ***********
2713
        if self._hmb.flowrate_mass and self._hmb.flowrate_volume is None:  # (1)질량만 적혀있는경우
2714
            density = self._hmb.density
2715

    
2716
            # '질량유량을 kg/h로 변환.
2717
            flowrate_mass_unit = self.units['Flowrate_Mass']
2718
            if flowrate_mass_unit == 'kg/h':
2719
                mass = self._hmb.flowrate_mass
2720
            elif flowrate_mass_unit == 'g/min':
2721
                mass = self._hmb.flowrate_mass * 60 / 1000
2722
            elif flowrate_mass_unit == 'lb/h':
2723
                mass = self._hmb.flowrate_mass * 0.453592
2724
            elif flowrate_mass_unit == 't/h':
2725
                mass = self._hmb.flowrate_mass * 1000
2726

    
2727
            # 'density case에 따라 volume rate (m3/h) 계산
2728
            density_unit = self.units['Density']
2729
            if density_unit == 'kg/m3':
2730
                volume = mass / density
2731
            elif density_unit == 'lb/ft3':
2732
                volume = mass / (density * 16.0185)
2733

    
2734
            # '부피 유닛에 맞춰서 뿌려줌
2735
            flowrate_volume_unit = self.units['Flowrate_Volume']
2736
            if flowrate_volume_unit == 'm3/h':
2737
                self._hmb.flowrate_volume = round(volume, 3)
2738
            elif flowrate_volume_unit == 'l/min':
2739
                self._hmb.flowrate_volume = round(volume / 60 * 1000, 3)
2740
            elif flowrate_volume_unit == 'ft3/h':
2741
                self._hmb.flowrate_volume = round(volume * 35.3147, 3)
2742
            elif flowrate_volume_unit == 'USgpm':
2743
                self._hmb.flowrate_volume = round(volume * 4.40287, 3)
2744
            elif flowrate_volume_unit == 'BPSD':
2745
                self._hmb.flowrate_volume = round(volume * 150.955, 3)
2746

    
2747
        elif self._hmb.flowrate_mass is None and self._hmb.flowrate_volume:  # (2)부피만 적혀있는경우
2748
            density = self._hmb.density
2749

    
2750
            # '부피유량을 m3/h로 변환.
2751
            flowrate_volume_unit = self.units['Flowrate_Volume']
2752
            if flowrate_volume_unit == 'm3/h':
2753
                volume = self._hmb.flowrate_volume
2754
            elif flowrate_volume_unit == 'l/min':
2755
                volume = self._hmb.flowrate_volume * 60 / 1000
2756
            elif flowrate_volume_unit == 'ft3/h':
2757
                volume = self._hmb.flowrate_volume / 35.3147
2758
            elif flowrate_volume_unit == 'USgpm':
2759
                volume = self._hmb.flowrate_volume / 4.40287
2760
            elif flowrate_volume_unit == 'BPSD':
2761
                volume = self._hmb.flowrate_volume / 150.955
2762

    
2763
            # 'density case에 따라 mass rate (kg/h) 계산
2764
            density_unit = self.units['Density']
2765
            if density_unit == 'kg/m3':
2766
                mass = volume * density
2767
            elif density_unit == 'lb/ft3':
2768
                mass = volume * (density * 16.0185)
2769

    
2770
            # '질량 유닛에 맞춰서 뿌려줌
2771
            flowrate_mass_unit = self.units['Flowrate_Mass']
2772
            if flowrate_mass_unit == 'kg/h':
2773
                self._hmb.flowrate_mass = round(mass, 3)
2774
            elif flowrate_mass_unit == 'g/min':
2775
                self._hmb.flowrate_mass = round(mass / 60 * 1000, 3)
2776
            elif flowrate_mass_unit == 'lb/h':
2777
                self._hmb.flowrate_mass = round(mass * 2.20462, 3)
2778
            elif flowrate_mass_unit == 't/h':
2779
                self._hmb.flowrate_mass = round(mass * 1000, 3)
2780

    
2781
        else:
2782
            # '(5-3) 둘다 적힌 경우
2783
            density = self._hmb.density
2784

    
2785
            # '질량유량을 kg/h로 변환.
2786
            flowrate_mass_unit = self.units['Flowrate_Mass']
2787
            if flowrate_mass_unit == 'kg/h':
2788
                mass = self._hmb.flowrate_mass
2789
            elif flowrate_mass_unit == 'g/min':
2790
                mass = self._hmb.flowrate_mass * 60 / 1000
2791
            elif flowrate_mass_unit == 'lb/h':
2792
                mass = self._hmb.flowrate_mass * 0.453592
2793
            elif flowrate_mass_unit == 't/h':
2794
                mass = self._hmb.flowrate_mass * 1000
2795

    
2796
            # 'density case에 따라 volume rate (m3/h) 계산
2797
            density_unit = self.units['Density']
2798
            if density_unit == 'kg/m3':
2799
                volume = mass / density
2800
            elif density_unit == 'lb/ft3':
2801
                volume = mass / (density * 16.0185)
2802

    
2803
            # '부피 유닛에 맞춰서 뿌려줌
2804
            flowrate_volume_unit = self.units['Flowrate_Volume']
2805
            if flowrate_volume_unit == 'm3/h':
2806
                self._hmb.flowrate_volume = round(volume, 3)
2807
            elif flowrate_volume_unit == 'l/min':
2808
                self._hmb.flowrate_volume = round(volume / 60 * 1000, 3)
2809
            elif flowrate_volume_unit == 'ft3/h':
2810
                self._hmb.flowrate_volume = round(volume * 35.3147, 3)
2811
            elif flowrate_volume_unit == 'USgpm':
2812
                self._hmb.flowrate_volume = round(volume * 4.40287, 3)
2813
            elif flowrate_volume_unit == 'BPSD':
2814
                self._hmb.flowrate_volume = round(volume * 150.955, 3)
2815

    
2816
        # ****************** 2. 지름 구하기 ****************** ******************
2817

    
2818
        # '지름을 m로 변환
2819
        pipe_diameter_unit = self.units['Pipe_Diameter']
2820
        if pipe_diameter_unit == 'in':
2821
            ida = self._hmb.inside_pipe_size * 0.0254
2822
        elif pipe_diameter_unit == 'mm':
2823
            ida = self._hmb.inside_pipe_size / 1000
2824

    
2825
        # '속도 계산 (m/s)
2826
        velocity = 4 * volume / 3.1415 / ida ** 2 / 3600
2827

    
2828
        # '속도 유닛에 맞춰서 뿌려줌
2829
        velocity_unit = self.units['Velocity']
2830
        if velocity_unit == 'm/s':
2831
            self._hmb.velocity = round(velocity, 3)
2832
        elif velocity_unit == 'ft/s':
2833
            self._hmb.velocity = round(velocity * 3.28084, 3)
2834

    
2835
        # ' viscosity 유닛 변환 (모두 kg/m.s로 바꿀것임)
2836
        viscosity_unit = self.units['Viscosity']
2837
        if viscosity_unit == 'kg/m.sec':
2838
            viscosity = self._hmb.viscosity
2839
        elif viscosity_unit == 'cP':
2840
            viscosity = self._hmb.viscosity * 0.001
2841
        elif viscosity_unit == 'kg/m.h':
2842
            viscosity = self._hmb.viscosity / 3600
2843
        elif viscosity_unit == 'lb/ft.s':
2844
            viscosity = self._hmb.viscosity * 1.48816
2845

    
2846
        # 'density case에 따라 re계산
2847
        density_unit = self.units['Density']
2848
        if density_unit == 'kg/m3':
2849
            reynolds = ida * velocity * density / viscosity
2850
        elif density_unit == 'lb/ft3':
2851
            reynolds = ida * velocity * (density * 16.0185) / viscosity
2852

    
2853
        # 'MACH 넘버 자리이므로 미입력 처리
2854
        self._hmb.reynolds = '-'
2855

    
2856
        # ''****************** 3. roughness 가져오기 ****************** ******************
2857
        rough = self._hmb.roughness  # '무차원 상수이다
2858

    
2859
        # ' ********** 4. pressure Drop 구하기 ***********
2860

    
2861
        volume = volume / 3600
2862
        # '현재 volume은 m3/s
2863

    
2864
        # '본격 계산 '단위 [m]
2865
        dp = 10.67 / (rough ** 1.85) * (volume ** 1.85) / (ida ** 4.87)
2866

    
2867
        # 'density case에 따라 dp계산 '단위 [k/g/1m]
2868
        density_unit = self.units['Density']
2869
        if density_unit == 'kg/m3':
2870
            dp = dp * (density / 1000) / 10
2871
        elif density_unit == 'lb/ft3':
2872
            dp = dp * ((density * 16.0185) / 1000) / 10
2873

    
2874
        dp = dp * 100
2875

    
2876
        # '현재 100m 당으로 산출되었다
2877
        pressure_unit = self.units['Pressure']
2878
        if pressure_unit == 'psi':
2879
            dp = dp / 1.033 * 14.7
2880
        elif pressure_unit == 'atm':
2881
            dp = dp / 1.033
2882
        elif pressure_unit == 'bar':
2883
            dp = dp / 1.033 * 1.013
2884
        elif pressure_unit == 'mmHg':
2885
            dp = dp / 1.033 * 760
2886
        elif pressure_unit == 'kPa':
2887
            dp = dp / 1.033 * 101.325
2888
        elif pressure_unit == 'MPa':
2889
            dp = dp / 1.033 * 0.101325
2890

    
2891
        length_unit = self.units['Length']
2892
        if length_unit == 'm':
2893
            self._hmb.pressure_drop = round(dp, 3)
2894
        elif length_unit == 'in':
2895
            self._hmb.pressure_drop = round(dp / 39.3701, 3)
2896
        elif length_unit == 'ft':
2897
            self._hmb.pressure_drop = round(dp / 3.28084, 3)
2898
        elif length_unit == 'yd':
2899
            self._hmb.pressure_drop = round(dp / 1.09361, 3)
2900
        elif length_unit == 'mile':
2901
            self._hmb.pressure_drop = round(dp / 0.000621371, 3)
2902
        elif length_unit == 'mm':
2903
            self._hmb.pressure_drop = round(dp / 1000, 3)
2904

    
2905
        # '100m 당 압력강하를 상당길이에 맞춰서 전체 압력강하로 넣어줌 ..
2906
        self._hmb.pressure_drop_friction = round(self._hmb.pressure_drop / 100 * self._hmb.equivalent_length, 3)
2907

    
2908
        # 'friction factor는 필요없음
2909
        self._hmb.friction_factor = None
2910

    
2911
    def calculation_Mixed(self):
2912
        self._hmb.velocity = 2.889
클립보드 이미지 추가 (최대 크기: 500 MB)