프로젝트

일반

사용자정보

통계
| 개정판:

hytos / HYTOS / HYTOS / Calculation.py @ c746da3d

이력 | 보기 | 이력해설 | 다운로드 (49.6 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.straight_length:
55
                        hmb.straight_length = self.convert_length(hmb.straight_length)
56
                    if hmb.equivalent_length_input:
57
                        hmb.equivalent_length_input = self.convert_length(hmb.equivalent_length_input)
58
                    if hmb.fitting_length:
59
                        hmb.fitting_length = self.convert_length(hmb.fitting_length)
60
                    if hmb.equivalent_length_cal:
61
                        hmb.equivalent_length_cal = self.convert_length(hmb.equivalent_length_cal)
62
                    if hmb.roughness:
63
                        hmb.roughness = self.convert_roughness(hmb.roughness)
64
                    if hmb.limitation_velocity:
65
                        hmb.limitation_velocity = self.convert_velocity(hmb.limitation_velocity)
66
                    if hmb.limitation_pressure_drop:
67
                        hmb.limitation_pressure_drop = self.convert_pressure(hmb.limitation_pressure_drop)
68
                    if hmb.velocity:
69
                        hmb.velocity = self.convert_velocity(hmb.velocity)
70
                    if hmb.pressure_drop:
71
                        hmb.pressure_drop = self.convert_pressure(hmb.pressure_drop)
72
                    if hmb.pressure_drop_friction:
73
                        hmb.pressure_drop_friction = self.convert_pressure(hmb.pressure_drop_friction)
74
                    if hmb.pressure_drop_static:
75
                        hmb.pressure_drop_static = self.convert_pressure(hmb.pressure_drop_static)
76
                    if hmb.pressure_pipe_end_point:
77
                        hmb.pressure_pipe_end_point = self.convert_pressure(hmb.pressure_pipe_end_point)
78
                    if hmb.power:
79
                        hmb.power = self.convert_power(hmb.power)
80

    
81
        except Exception as ex:
82
            from App import App
83
            from AppDocData import MessageType
84

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

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

    
93
        if pre_unit == cur_unit:
94
            return value
95

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

    
125
        return round(value * convert_factor, self._decimal)
126

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

    
131
        if pre_unit == cur_unit:
132
            return value
133

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

    
180
        return round(value * convert_factor, self._decimal)
181

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

    
186
        if pre_unit == cur_unit:
187
            return value
188

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

    
194
        return round(value * convert_factor, self._decimal)
195

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

    
200
        if pre_unit == cur_unit:
201
            return value
202

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

    
232
        return round(value * convert_factor, self._decimal)
233

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

    
238
        if pre_unit == cur_unit:
239
            return value
240

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

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

    
250
        if pre_unit == cur_unit:
251
            return value
252

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

    
258
        return round(value * convert_factor, self._decimal)
259

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

    
264
        if pre_unit == cur_unit:
265
            return value
266

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

    
334
        return round(value * convert_factor, self._decimal)
335

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

    
340
        if pre_unit == cur_unit:
341
            return value
342

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

    
372
        return round(value * convert_factor, self._decimal)
373

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

    
378
        if pre_unit == cur_unit:
379
            return value
380

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

    
386
        return round(value * convert_factor, self._decimal)
387

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

    
392
        if pre_unit == cur_unit:
393
            return value
394

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

    
487
        return round(value * convert_factor, self._decimal)
488

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

    
493
        if pre_unit == cur_unit:
494
            return value
495

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

    
563
        return round(value * convert_factor, self._decimal)
564

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

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

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

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

    
594
        except Exception as ex:
595
            from App import App
596
            from AppDocData import MessageType
597

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

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

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

    
611
        except Exception as ex:
612
            from App import App
613
            from AppDocData import MessageType
614

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

    
619

    
620
class Calculation:
621
    def __init__(self, hmb):
622
        self._hmb = hmb
623
        self.units = {}
624

    
625
        self.init_units()
626

    
627
        if self._hmb.phase_type == 'Liquid':
628
            if self.validation_check_Liquid():
629
                self.calculation_Liquid()
630

    
631
        '''    
632
        if self._hmb.phase_type == 'Vapor':
633
            if self.validation_check_vapor():
634
                self.calculation_Vapor()
635
        elif self._hmb.phase_type == 'Liquid':
636
            if self.validation_check_Liquid():
637
                self.calculation_Liquid()
638
        elif self._hmb.phase_type == 'Mixed':
639
            self.calculation_Mixed()
640
        '''
641

    
642
    def get_equivalent_length(self):
643
        if self._hmb.equivalent_length_input:
644
            return self._hmb.equivalent_length_input
645
        else:
646
            return self._hmb.equivalent_length_cal
647

    
648
    def validation_check_vapor(self):
649
        result = False
650

    
651
        if self._hmb.inside_pipe_size is None:
652
            message = 'You have to input the ID of stream <{}>.'.format(self._hmb.stream_no)
653
            App.mainWnd().addMessage.emit(MessageType.Information, message)
654
            return result
655

    
656
        if self._hmb.flowrate_mass is None:
657
            message = 'You have to input mass flowrate of stream <{}>.'.format(self._hmb.stream_no)
658
            App.mainWnd().addMessage.emit(MessageType.Information, message)
659
            return result
660

    
661
        if self._hmb.specific_heat_ratio is None:
662
            message = 'You have to input the specific heat ratio of stream <{}>.'.format(self._hmb.stream_no)
663
            App.mainWnd().addMessage.emit(MessageType.Information, message)
664
            return result
665

    
666
        if self._hmb.viscosity is None:
667
            message = 'You have to input the viscosity of stream <{}>.'.format(self._hmb.stream_no)
668
            App.mainWnd().addMessage.emit(MessageType.Information, message)
669
            return result
670

    
671
        if self._hmb.roughness is None:
672
            message = 'You have to input the roughness of stream <{}>.'.format(self._hmb.stream_no)
673
            App.mainWnd().addMessage.emit(MessageType.Information, message)
674
            return result
675

    
676
        return True
677

    
678
    def validation_check_Liquid(self):
679
        from App import App
680
        from AppDocData import MessageType
681

    
682
        result = False
683

    
684
        # 1.  Equivalent Length
685
        equivalent_length = self.get_equivalent_length()
686
        if equivalent_length is None:
687
            message = 'The equivalent length of stream <{}> is not inputted.'.format(self._hmb.stream_no)
688
            App.mainWnd().addMessage.emit(MessageType.Information, message)
689
            return result
690

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

    
696
        if self._hmb.density is None:
697
            message = 'You have to input the density of stream <{}>.'.format(self._hmb.stream_no)
698
            App.mainWnd().addMessage.emit(MessageType.Information, message)
699
            return result
700

    
701
        if self._hmb.inside_pipe_size is None:
702
            message = 'You have to input the ID of stream <{}>.'.format(self._hmb.stream_no)
703
            App.mainWnd().addMessage.emit(MessageType.Information, message)
704
            return result
705

    
706
        if self._hmb.viscosity is None:
707
            message = 'You have to input the viscosity of stream <{}>.'.format(self._hmb.stream_no)
708
            App.mainWnd().addMessage.emit(MessageType.Information, message)
709
            return result
710

    
711
        if self._hmb.roughness is None:
712
            message = 'You have to input the roughness of stream <{}>.'.format(self._hmb.stream_no)
713
            App.mainWnd().addMessage.emit(MessageType.Information, message)
714
            return result
715

    
716
        return True
717

    
718
    def init_units(self):
719
        try:
720
            app_doc_data = AppDocData.instance()
721
            self.units = [attr[1] for attr in app_doc_data.activeDrawing.attrs if attr[0] == 'Units'][0]
722

    
723
            '''
724
            for attr in app_doc_data.attrs:
725
                if attr[0] == 'Units':
726
                    self.flowrate_mass_unit = attr[1]['Flowrate_Mass']
727
                    self.flowrate_volume_unit = attr[1]['Flowrate_Volume']
728
                    self.density_unit = attr[1]['Density']
729
                    self.viscosity_unit = attr[1]['Viscosity']
730
                    self.velocity_unit = attr[1]['Velocity']
731
                    self.pressure_unit = attr[1]['Pressure']
732
                    self.length_unit = attr[1]['Length']
733
                    self.pipe_diameter_unit = attr[1]['Pipe_Diameter']
734
                    self.roughness_unit = attr[1]['Roughness']
735
                    self.temperature_unit = attr[1]['Temperature']
736
            '''
737
        except Exception as ex:
738
            from App import App
739
            from AppDocData import MessageType
740

    
741
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
742
                                                           sys.exc_info()[-1].tb_lineno)
743
            App.mainWnd().addMessage.emit(MessageType.Error, message)
744

    
745
    def getBarometricPressure(self):
746
        pressure_unit = self.units['Pressure']
747

    
748
        if pressure_unit == 'kg/cm2':
749
            barometric_pressure = 1.033
750
        elif pressure_unit == 'bar':
751
            barometric_pressure = 1.01325
752
        elif pressure_unit == 'psi':
753
            barometric_pressure = 14.7
754
        elif pressure_unit == 'mmHg':
755
            barometric_pressure = 760
756
        elif pressure_unit == 'kPa':
757
            barometric_pressure = 101.325
758
        elif pressure_unit == 'MPa':
759
            barometric_pressure = 0.101325
760

    
761
        return barometric_pressure
762

    
763
    def getLiquid_Drop_Method(self):
764
        appDocData = AppDocData.instance()
765

    
766
        # Calculation
767
        liquid_dp_method = appDocData.getConfigs('Calculation', 'Liquid_Drop_Method')
768

    
769
        if len(liquid_dp_method) == 1:
770
            return liquid_dp_method[0].value
771
        else:
772
            return 'darcy'
773

    
774
    def calculation_Liquid(self):
775
        try:
776
            liquid_dp_method = self.getLiquid_Drop_Method()
777

    
778
            if liquid_dp_method == 'darcy':
779
                self.liquid_calc_darcy()
780
            elif liquid_dp_method == 'hagen':
781
                self.liquid_calc_hagen()
782

    
783
        except Exception as ex:
784
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
785
                                                           sys.exc_info()[-1].tb_lineno)
786
            App.mainWnd().addMessage.emit(MessageType.Error, message)
787

    
788
    def liquid_calc_darcy(self):
789
        from App import App
790
        from AppDocData import MessageType
791

    
792
        try:
793
            '''
794
            Incompressible Line 계산
795
    
796
            **********************************************************************************
797
            참고사항 :
798
            유닛의 기준 : 유량 (kg/h, m3/h), 밀도 (kg/m3), 지름 (m), 점도 (kg/m/s), 속도 (m/s), 압력강하 (kg/cm2/100m)
799
            **********************************************************************************
800
            '''
801

    
802
            # ********** 1. Flowrate 구하기 ***********
803
            # (1)질량만 적혀있는경우
804
            if self._hmb.flowrate_mass and self._hmb.flowrate_volume is None:
805
                density = self._hmb.density
806

    
807
                # '질량유량을 kg/h로 변환.
808
                flowrate_mass_unit = self.units['Flowrate_Mass']
809
                if flowrate_mass_unit == 'kg/h':
810
                    mass = self._hmb.flowrate_mass
811
                elif flowrate_mass_unit == 'g/min':
812
                    mass = self._hmb.flowrate_mass * 60 / 1000
813
                elif flowrate_mass_unit == 'lb/h':
814
                    mass = self._hmb.flowrate_mass * 0.453592
815
                elif flowrate_mass_unit == 't/h':
816
                    mass = self._hmb.flowrate_mass * 1000
817

    
818
                # 'density case에 따라 volume rate (m3/h) 계산
819
                density_unit = self.units['Density']
820
                if density_unit == 'kg/m3':
821
                    volume = mass / density
822
                elif density_unit == 'lb/ft3':
823
                    volume = mass / (density * 16.0185)
824

    
825
                # '부피 유닛에 맞춰서 뿌려줌
826
                flowrate_volume_unit = self.units['Flowrate_Volume']
827
                if flowrate_volume_unit == 'm3/h':
828
                    self._hmb.flowrate_volume = round(volume, 3)
829
                elif flowrate_volume_unit == 'l/min':
830
                    self._hmb.flowrate_volume = round(volume / 60 * 1000, 3)
831
                elif flowrate_volume_unit == 'ft3/h':
832
                    self._hmb.flowrate_volume = round(volume * 35.3147, 3)
833
                elif flowrate_volume_unit == 'USgpm':
834
                    self._hmb.flowrate_volume = round(volume * 4.40287, 3)
835
                elif flowrate_volume_unit == 'BPSD':
836
                    self._hmb.flowrate_volume = round(volume * 150.955, 3)
837

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

    
841
                # '부피유량을 m3/h로 변환.
842
                flowrate_volume_unit = self.units['Flowrate_Volume']
843
                if flowrate_volume_unit == 'm3/h':
844
                    volume = self._hmb.flowrate_volume
845
                elif flowrate_volume_unit == 'l/min':
846
                    volume = self._hmb.flowrate_volume * 60 / 1000
847
                elif flowrate_volume_unit == 'ft3/h':
848
                    volume = self._hmb.flowrate_volume / 35.3147
849
                elif flowrate_volume_unit == 'USgpm':
850
                    volume = self._hmb.flowrate_volume / 4.40287
851
                elif flowrate_volume_unit == 'BPSD':
852
                    volume = self._hmb.flowrate_volume / 150.955
853

    
854
                # 'density case에 따라 mass rate (kg/h) 계산
855
                density_unit = self.units['Density']
856
                if density_unit == 'kg/m3':
857
                    mass = volume * density
858
                elif density_unit == 'lb/ft3':
859
                    mass = volume * (density * 16.0185)
860

    
861
                # '질량 유닛에 맞춰서 뿌려줌
862
                flowrate_mass_unit = self.units['Flowrate_Mass']
863
                if flowrate_mass_unit == 'kg/h':
864
                    self._hmb.flowrate_mass = round(mass, 3)
865
                elif flowrate_mass_unit == 'g/min':
866
                    self._hmb.flowrate_mass = round(mass / 60 * 1000, 3)
867
                elif flowrate_mass_unit == 'lb/h':
868
                    self._hmb.flowrate_mass = round(mass * 2.20462, 3)
869
                elif flowrate_mass_unit == 't/h':
870
                    self._hmb.flowrate_mass = round(mass * 1000, 3)
871
            else:
872
                # (5-3) 둘다 적힌 경우
873
                density = self._hmb.density
874

    
875
                # '질량유량을 kg/h로 변환.
876
                flowrate_mass_unit = self.units['Flowrate_Mass']
877
                if flowrate_mass_unit == 'kg/h':
878
                    mass = self._hmb.flowrate_mass
879
                elif flowrate_mass_unit == 'g/min':
880
                    mass = self._hmb.flowrate_mass * 60 / 1000
881
                elif flowrate_mass_unit == 'lb/h':
882
                    mass = self._hmb.flowrate_mass * 0.453592
883
                elif flowrate_mass_unit == 't/h':
884
                    mass = self._hmb.flowrate_mass * 1000
885

    
886
                # 'density case에 따라 volume rate (m3/h) 계산
887
                density_unit = self.units['Density']
888
                if density_unit == 'kg/m3':
889
                    volume = mass / density
890
                elif density_unit == 'lb/ft3':
891
                    volume = mass / (density * 16.0185)
892

    
893
                # '부피 유닛에 맞춰서 뿌려줌
894
                flowrate_volume_unit = self.units['Flowrate_Volume']
895
                if flowrate_volume_unit == 'm3/h':
896
                    self._hmb.flowrate_volume = round(volume, 3)
897
                elif flowrate_volume_unit == 'l/min':
898
                    self._hmb.flowrate_volume = round(volume / 60 * 1000, 3)
899
                elif flowrate_volume_unit == 'ft3/h':
900
                    self._hmb.flowrate_volume = round(volume * 35.3147, 3)
901
                elif flowrate_volume_unit == 'USgpm':
902
                    self._hmb.flowrate_volume = round(volume * 4.40287, 3)
903
                elif flowrate_volume_unit == 'BPSD':
904
                    self._hmb.flowrate_volume = round(volume * 150.955, 3)
905

    
906
            # ********** 2. Velocity 구하기 ***********
907
            # '지름을 m로 변환
908
            pipe_diameter_unit = self.units['Pipe_Diameter']
909
            if pipe_diameter_unit == 'in':
910
                ida = self._hmb.inside_pipe_size * 0.0254
911
            elif pipe_diameter_unit == 'mm':
912
                ida = self._hmb.inside_pipe_size / 1000
913

    
914
            # '속도 계산 (m/s)
915
            velocity = 4 * volume / 3.1415 / ida ** 2 / 3600
916

    
917
            # '속도 유닛에 맞춰서 뿌려줌
918
            velocity_unit = self.units['Velocity']
919
            if velocity_unit == 'm/s':
920
                self._hmb.velocity = round(velocity, 3)
921
            elif velocity_unit == 'ft/s':
922
                self._hmb.velocity = round(velocity * 3.28084, 3)
923

    
924
            # ********** 3. Reynolds 수 구하기 ***********
925

    
926
            # ' viscosity 유닛 변환 (모두 kg/m.s로 바꿀것임)
927
            viscosity_unit = self.units['Viscosity']
928
            if viscosity_unit == 'kg/m.sec':
929
                viscosity = self._hmb.viscosity
930
            elif viscosity_unit == 'cP':
931
                viscosity = self._hmb.viscosity * 0.001
932
            elif viscosity_unit == 'kg/m.h':
933
                viscosity = self._hmb.viscosity / 3600
934
            elif viscosity_unit == 'lb/ft.s':
935
                viscosity = self._hmb.viscosity * 1.48816
936

    
937
            # 'density case에 따라 re계산
938
            density_unit = self.units['Density']
939
            if density_unit == 'kg/m3':
940
                reynolds = ida * velocity * density / viscosity
941
            elif density_unit == 'lb/ft3':
942
                reynolds = ida * velocity * (density * 16.0185) / viscosity
943

    
944
            # 'MACH 넘버 자리이므로 미입력 처리
945
            self._hmb.reynolds = None
946

    
947
            # ********** 4. Friction Factor 구하기 ***********
948
            # 'roughness 를 m로 바꿔줌
949
            roughness_unit = self.units['Roughness']
950
            if roughness_unit == 'm':
951
                rough = self._hmb.roughness
952
            elif roughness_unit == 'ft':
953
                rough = self._hmb.roughness * 0.3048
954
            elif roughness_unit == 'in':
955
                rough = self._hmb.roughness * 0.0254
956
            elif roughness_unit == 'mm':
957
                rough = self._hmb.roughness * 0.001
958

    
959
            # ' reynolds수에 따라 Fanning/Chen friction factor 계산
960
            if reynolds <= 2100:
961
                f = 4 * 16 / reynolds
962
            else:
963
                a = math.log(rough / ida / 3.7 + (6.7 / reynolds) ** 0.9) / math.log(10)
964
                f = (-2 * (math.log(rough / 3.7 / ida - 5.02 / reynolds * a) / math.log(10))) ** (-2)
965

    
966
            # '뿌려줌
967
            self._hmb.friction_factor = round(f, 3)
968

    
969
            # ********** 5. pressure Drop 구하기 ***********
970
            # '100m 당 압력강하를 kg/cm2 단위로 구한 후, 설정된 유닛에 맞춰서 conversion후 기입해줌.
971
            density_unit = self.units['Density']
972
            if density_unit == 'kg/m3':
973
                # 100m 당 압력강하
974
                dp = f * density * (velocity ** 2) / 2 / ida / 9.8066 / 10000 * 100
975
            elif density_unit == 'lb/ft3':
976
                # 100m 당 압력강하
977
                dp = f * (density * 16.0185) * (velocity ** 2) / 2 / ida / 9.8066 / 10000 * 100
978

    
979
            pressure_unit = self.units['Pressure']
980
            if pressure_unit == 'psi':
981
                dp = dp / 1.033 * 14.7
982
            elif pressure_unit == 'atm':
983
                dp = dp / 1.033
984
            elif pressure_unit == 'bar':
985
                dp = dp / 1.033 * 1.013
986
            elif pressure_unit == 'mmHg':
987
                dp = dp / 1.033 * 760
988
            elif pressure_unit == 'kPa':
989
                dp = dp / 1.033 * 101.325
990
            elif pressure_unit == 'MPa':
991
                dp = dp / 1.033 * 0.101325
992

    
993
            length_unit = self.units['Length']
994
            if length_unit == 'm':
995
                self._hmb.pressure_drop = round(dp, 3)
996
            elif length_unit == 'in':
997
                self._hmb.pressure_drop = round(dp / 39.3701, 3)
998
            elif length_unit == 'ft':
999
                self._hmb.pressure_drop = round(dp / 3.28084, 3)
1000
            elif length_unit == 'yd':
1001
                self._hmb.pressure_drop = round(dp / 1.09361, 3)
1002
            elif length_unit == 'mile':
1003
                self._hmb.pressure_drop = round(dp / 0.000621371, 3)
1004
            elif length_unit == 'mm':
1005
                self._hmb.pressure_drop = round(dp / 1000, 3)
1006

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

    
1011
        except Exception as ex:
1012

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

    
1017
    def liquid_calc_hagen(self):
1018
        '''
1019
        **************************************************************
1020
          Hagen-Williams 모드에서 사용할 지배식은 다음과 같다.
1021
          h[m] = 10.67 / C^1.85 * Q[m3/s]^1.85 / dia[m]^4.87
1022
          dP[k/g/1m] = h[m] * S.G / 10
1023
        **************************************************************
1024
        '''
1025

    
1026
        # ********** 1. Flowrate 구하기 ***********
1027
        if self._hmb.flowrate_mass and self._hmb.flowrate_volume is None:  # (1)질량만 적혀있는경우
1028
            density = self._hmb.density
1029

    
1030
            # '질량유량을 kg/h로 변환.
1031
            flowrate_mass_unit = self.units['Flowrate_Mass']
1032
            if flowrate_mass_unit == 'kg/h':
1033
                mass = self._hmb.flowrate_mass
1034
            elif flowrate_mass_unit == 'g/min':
1035
                mass = self._hmb.flowrate_mass * 60 / 1000
1036
            elif flowrate_mass_unit == 'lb/h':
1037
                mass = self._hmb.flowrate_mass * 0.453592
1038
            elif flowrate_mass_unit == 't/h':
1039
                mass = self._hmb.flowrate_mass * 1000
1040

    
1041
            # 'density case에 따라 volume rate (m3/h) 계산
1042
            density_unit = self.units['Density']
1043
            if density_unit == 'kg/m3':
1044
                volume = mass / density
1045
            elif density_unit == 'lb/ft3':
1046
                volume = mass / (density * 16.0185)
1047

    
1048
            # '부피 유닛에 맞춰서 뿌려줌
1049
            flowrate_volume_unit = self.units['Flowrate_Volume']
1050
            if flowrate_volume_unit == 'm3/h':
1051
                self._hmb.flowrate_volume = round(volume, 3)
1052
            elif flowrate_volume_unit == 'l/min':
1053
                self._hmb.flowrate_volume = round(volume / 60 * 1000, 3)
1054
            elif flowrate_volume_unit == 'ft3/h':
1055
                self._hmb.flowrate_volume = round(volume * 35.3147, 3)
1056
            elif flowrate_volume_unit == 'USgpm':
1057
                self._hmb.flowrate_volume = round(volume * 4.40287, 3)
1058
            elif flowrate_volume_unit == 'BPSD':
1059
                self._hmb.flowrate_volume = round(volume * 150.955, 3)
1060

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

    
1064
            # '부피유량을 m3/h로 변환.
1065
            flowrate_volume_unit = self.units['Flowrate_Volume']
1066
            if flowrate_volume_unit == 'm3/h':
1067
                volume = self._hmb.flowrate_volume
1068
            elif flowrate_volume_unit == 'l/min':
1069
                volume = self._hmb.flowrate_volume * 60 / 1000
1070
            elif flowrate_volume_unit == 'ft3/h':
1071
                volume = self._hmb.flowrate_volume / 35.3147
1072
            elif flowrate_volume_unit == 'USgpm':
1073
                volume = self._hmb.flowrate_volume / 4.40287
1074
            elif flowrate_volume_unit == 'BPSD':
1075
                volume = self._hmb.flowrate_volume / 150.955
1076

    
1077
            # 'density case에 따라 mass rate (kg/h) 계산
1078
            density_unit = self.units['Density']
1079
            if density_unit == 'kg/m3':
1080
                mass = volume * density
1081
            elif density_unit == 'lb/ft3':
1082
                mass = volume * (density * 16.0185)
1083

    
1084
            # '질량 유닛에 맞춰서 뿌려줌
1085
            flowrate_mass_unit = self.units['Flowrate_Mass']
1086
            if flowrate_mass_unit == 'kg/h':
1087
                self._hmb.flowrate_mass = round(mass, 3)
1088
            elif flowrate_mass_unit == 'g/min':
1089
                self._hmb.flowrate_mass = round(mass / 60 * 1000, 3)
1090
            elif flowrate_mass_unit == 'lb/h':
1091
                self._hmb.flowrate_mass = round(mass * 2.20462, 3)
1092
            elif flowrate_mass_unit == 't/h':
1093
                self._hmb.flowrate_mass = round(mass * 1000, 3)
1094

    
1095
        else:
1096
            # '(5-3) 둘다 적힌 경우
1097
            density = self._hmb.density
1098

    
1099
            # '질량유량을 kg/h로 변환.
1100
            flowrate_mass_unit = self.units['Flowrate_Mass']
1101
            if flowrate_mass_unit == 'kg/h':
1102
                mass = self._hmb.flowrate_mass
1103
            elif flowrate_mass_unit == 'g/min':
1104
                mass = self._hmb.flowrate_mass * 60 / 1000
1105
            elif flowrate_mass_unit == 'lb/h':
1106
                mass = self._hmb.flowrate_mass * 0.453592
1107
            elif flowrate_mass_unit == 't/h':
1108
                mass = self._hmb.flowrate_mass * 1000
1109

    
1110
            # 'density case에 따라 volume rate (m3/h) 계산
1111
            density_unit = self.units['Density']
1112
            if density_unit == 'kg/m3':
1113
                volume = mass / density
1114
            elif density_unit == 'lb/ft3':
1115
                volume = mass / (density * 16.0185)
1116

    
1117
            # '부피 유닛에 맞춰서 뿌려줌
1118
            flowrate_volume_unit = self.units['Flowrate_Volume']
1119
            if flowrate_volume_unit == 'm3/h':
1120
                self._hmb.flowrate_volume = round(volume, 3)
1121
            elif flowrate_volume_unit == 'l/min':
1122
                self._hmb.flowrate_volume = round(volume / 60 * 1000, 3)
1123
            elif flowrate_volume_unit == 'ft3/h':
1124
                self._hmb.flowrate_volume = round(volume * 35.3147, 3)
1125
            elif flowrate_volume_unit == 'USgpm':
1126
                self._hmb.flowrate_volume = round(volume * 4.40287, 3)
1127
            elif flowrate_volume_unit == 'BPSD':
1128
                self._hmb.flowrate_volume = round(volume * 150.955, 3)
1129

    
1130
        # ****************** 2. 지름 구하기 ****************** ******************
1131

    
1132
        # '지름을 m로 변환
1133
        pipe_diameter_unit = self.units['Pipe_Diameter']
1134
        if pipe_diameter_unit == 'in':
1135
            ida = self._hmb.inside_pipe_size * 0.0254
1136
        elif pipe_diameter_unit == 'mm':
1137
            ida = self._hmb.inside_pipe_size / 1000
1138

    
1139
        # '속도 계산 (m/s)
1140
        velocity = 4 * volume / 3.1415 / ida ** 2 / 3600
1141

    
1142
        # '속도 유닛에 맞춰서 뿌려줌
1143
        velocity_unit = self.units['Velocity']
1144
        if velocity_unit == 'm/s':
1145
            self._hmb.velocity = round(velocity, 3)
1146
        elif velocity_unit == 'ft/s':
1147
            self._hmb.velocity = round(velocity * 3.28084, 3)
1148

    
1149
        # ' viscosity 유닛 변환 (모두 kg/m.s로 바꿀것임)
1150
        viscosity_unit = self.units['Viscosity']
1151
        if viscosity_unit == 'kg/m.sec':
1152
            viscosity = self._hmb.viscosity
1153
        elif viscosity_unit == 'cP':
1154
            viscosity = self._hmb.viscosity * 0.001
1155
        elif viscosity_unit == 'kg/m.h':
1156
            viscosity = self._hmb.viscosity / 3600
1157
        elif viscosity_unit == 'lb/ft.s':
1158
            viscosity = self._hmb.viscosity * 1.48816
1159

    
1160
        # 'density case에 따라 re계산
1161
        density_unit = self.units['Density']
1162
        if density_unit == 'kg/m3':
1163
            reynolds = ida * velocity * density / viscosity
1164
        elif density_unit == 'lb/ft3':
1165
            reynolds = ida * velocity * (density * 16.0185) / viscosity
1166

    
1167
        # 'MACH 넘버 자리이므로 미입력 처리
1168
        self._hmb.reynolds = None
1169

    
1170
        # ''****************** 3. roughness 가져오기 ****************** ******************
1171
        rough = self._hmb.roughness  # '무차원 상수이다
1172

    
1173
        # ' ********** 4. pressure Drop 구하기 ***********
1174

    
1175
        volume = volume / 3600
1176
        # '현재 volume은 m3/s
1177

    
1178
        # '본격 계산 '단위 [m]
1179
        dp = 10.67 / (rough ** 1.85) * (volume ** 1.85) / (ida ** 4.87)
1180

    
1181
        # 'density case에 따라 dp계산 '단위 [k/g/1m]
1182
        density_unit = self.units['Density']
1183
        if density_unit == 'kg/m3':
1184
            dp = dp * (density / 1000) / 10
1185
        elif density_unit == 'lb/ft3':
1186
            dp = dp * ((density * 16.0185) / 1000) / 10
1187

    
1188
        dp = dp * 100
1189

    
1190
        # '현재 100m 당으로 산출되었다
1191
        pressure_unit = self.units['Pressure']
1192
        if pressure_unit == 'psi':
1193
            dp = dp / 1.033 * 14.7
1194
        elif pressure_unit == 'atm':
1195
            dp = dp / 1.033
1196
        elif pressure_unit == 'bar':
1197
            dp = dp / 1.033 * 1.013
1198
        elif pressure_unit == 'mmHg':
1199
            dp = dp / 1.033 * 760
1200
        elif pressure_unit == 'kPa':
1201
            dp = dp / 1.033 * 101.325
1202
        elif pressure_unit == 'MPa':
1203
            dp = dp / 1.033 * 0.101325
1204

    
1205
        length_unit = self.units['Length']
1206
        if length_unit == 'm':
1207
            self._hmb.pressure_drop = round(dp, 3)
1208
        elif length_unit == 'in':
1209
            self._hmb.pressure_drop = round(dp / 39.3701, 3)
1210
        elif length_unit == 'ft':
1211
            self._hmb.pressure_drop = round(dp / 3.28084, 3)
1212
        elif length_unit == 'yd':
1213
            self._hmb.pressure_drop = round(dp / 1.09361, 3)
1214
        elif length_unit == 'mile':
1215
            self._hmb.pressure_drop = round(dp / 0.000621371, 3)
1216
        elif length_unit == 'mm':
1217
            self._hmb.pressure_drop = round(dp / 1000, 3)
1218

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

    
1223
        # 'friction factor는 필요없음
1224
        self._hmb.friction_factor = None
1225

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