hytos / HYTOS / HYTOS / DiameterEstimation_Liquid.py @ a3da2d97
이력 | 보기 | 이력해설 | 다운로드 (25.2 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
|
3 |
# Form implementation generated from reading ui file 'ProjectDialog.ui'
|
4 |
#
|
5 |
# Created by: PyQt5 UI code generator 5.6
|
6 |
#
|
7 |
# WARNING! All changes made in this file will be lost!
|
8 |
import sys |
9 |
from PyQt5.QtCore import * |
10 |
from PyQt5.QtGui import * |
11 |
from PyQt5.QtWidgets import * |
12 |
from PyQt5 import QtCore, QtGui, QtWidgets |
13 |
from PyQt5.QtWidgets import * |
14 |
import os |
15 |
from AppDocData import AppDocData |
16 |
import DiameterEstimation_Liquid_UI |
17 |
import math |
18 |
|
19 |
|
20 |
def set_table_widget_item_properties(name, alignment, color=None): |
21 |
if name is None: |
22 |
name = ''
|
23 |
|
24 |
item = QTableWidgetItem(str(name))
|
25 |
item.setTextAlignment(alignment) |
26 |
if color:
|
27 |
item.setBackground(color) |
28 |
|
29 |
return item
|
30 |
|
31 |
|
32 |
def is_not_blank(s): |
33 |
return bool(s and s.strip()) |
34 |
|
35 |
|
36 |
def is_blank(s): |
37 |
return not (s and s.strip()) |
38 |
|
39 |
|
40 |
class QDiameterEstimation_Liquid(QDialog): |
41 |
def __init__(self): |
42 |
QDialog.__init__(self)
|
43 |
|
44 |
self.ui = DiameterEstimation_Liquid_UI.Ui_Dialog()
|
45 |
|
46 |
self.ui.setupUi(self) |
47 |
|
48 |
self.velocity = 0 |
49 |
self.pressure_drop = 0 |
50 |
self.process_data = {}
|
51 |
self.isAccepted = False |
52 |
self.units = {}
|
53 |
self.ui.tableWidget.cellDoubleClicked.connect(self.double_clicked) |
54 |
|
55 |
def show_dialog(self, velocity, pressure_drop, process_data): |
56 |
self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint) |
57 |
|
58 |
self.velocity = '' if velocity == '-' else velocity |
59 |
self.pressure_drop = '' if pressure_drop == '-' else pressure_drop |
60 |
self.process_data = process_data
|
61 |
|
62 |
self.init_units()
|
63 |
self.init_pipe_diameter_estimation()
|
64 |
self.initialize()
|
65 |
|
66 |
self.exec_()
|
67 |
|
68 |
return self.isAccepted, self.ui.tableWidget.item(self.ui.tableWidget.currentRow(), 0).text() |
69 |
|
70 |
def init_units(self): |
71 |
app_doc_data = AppDocData.instance() |
72 |
active_drawing = app_doc_data.activeDrawing |
73 |
|
74 |
for attr in active_drawing.attrs: |
75 |
if attr[0] == 'Units': |
76 |
self.units = attr[1] |
77 |
|
78 |
def initialize(self): |
79 |
try:
|
80 |
self.ui.lineEdit_Velocity.setText(self.velocity) |
81 |
self.ui.lineEdit_Pressure_Drop.setText(self.pressure_drop) |
82 |
|
83 |
self.ui.label_Velocity_Unit.setText(self.units['Velocity']) |
84 |
self.ui.label_Pressure_Drop_Unit.setText('{}/100{}'.format(self.units['Pressure'], self.units['Length'])) |
85 |
|
86 |
self.calc_pde_l()
|
87 |
|
88 |
va = 100000000000 if is_blank(self.velocity) else float(self.velocity) |
89 |
dpa = 100000000000 if is_blank(self.pressure_drop) else float(self.pressure_drop) |
90 |
|
91 |
for row in range(self.ui.tableWidget.rowCount()): |
92 |
validation = False
|
93 |
velocity = float(self.ui.tableWidget.item(row, 1).text()) |
94 |
if velocity > va:
|
95 |
self.ui.tableWidget.item(row, 1).setForeground(QBrush(QColor(255, 0, 0))) |
96 |
validation = True
|
97 |
|
98 |
pressure_drop = float(self.ui.tableWidget.item(row, 2).text()) |
99 |
if pressure_drop > dpa:
|
100 |
self.ui.tableWidget.item(row, 2).setForeground(QBrush(QColor(255, 0, 0))) |
101 |
validation = True
|
102 |
|
103 |
if validation:
|
104 |
self.ui.tableWidget.item(row, 0).setForeground(QBrush(QColor(255, 0, 0))) |
105 |
|
106 |
except Exception as ex: |
107 |
from App import App |
108 |
from AppDocData import MessageType |
109 |
|
110 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
111 |
sys.exc_info()[-1].tb_lineno)
|
112 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
113 |
|
114 |
def get_std_nd(self, mass, density, goal): |
115 |
std_nd = 0
|
116 |
d125 = mass / density |
117 |
b125 = (d125 / math.pi * (std_nd / 2 * 0.0254) ** 2) / 3600 |
118 |
|
119 |
return 0 |
120 |
|
121 |
def calc_pde_l2(self, mass, density, viscosity, volume): |
122 |
try:
|
123 |
length_unit = self.units['Length'] |
124 |
if length_unit == 'm': |
125 |
ccdp = float(self.pressure_drop) |
126 |
elif length_unit == 'in': |
127 |
ccdp = float(self.pressure_drop) / 0.0254 |
128 |
elif length_unit == 'ft': |
129 |
ccdp = float(self.pressure_drop) / 0.3048 |
130 |
elif length_unit == 'yd': |
131 |
ccdp = float(self.pressure_drop) / 0.9144 |
132 |
elif length_unit == 'mile': |
133 |
ccdp = float(self.pressure_drop) / 1609.34 |
134 |
elif length_unit == 'mm': |
135 |
ccdp = float(self.pressure_drop) / 0.001 |
136 |
|
137 |
pressure_unit = self.units['Pressure'] |
138 |
if pressure_unit == 'kg/cm2': |
139 |
ccdp = ccdp |
140 |
elif pressure_unit == 'psi': |
141 |
ccdp = ccdp * 1.033 / 14.7 |
142 |
elif pressure_unit == 'bar': |
143 |
ccdp = ccdp * 1.033 / 1.013 |
144 |
elif pressure_unit == 'mmHg': |
145 |
ccdp = ccdp * 1.033 / 760 |
146 |
elif pressure_unit == 'kPa': |
147 |
ccdp = ccdp * 1.033 / 101.325 |
148 |
elif pressure_unit == 'MPa': |
149 |
ccdp = ccdp * 1.033 / 0.101325 |
150 |
|
151 |
# ************************1. sheet2의 calculator에 값들 입력 ***********************
|
152 |
# 압력강하 기준 입력
|
153 |
goal = ccdp |
154 |
|
155 |
roughness = float(self.process_data['Roughness']) |
156 |
roughness_unit = self.units['Roughness'] |
157 |
if roughness_unit == 'm': |
158 |
rough = roughness |
159 |
elif roughness_unit == 'ft': |
160 |
rough = roughness * 0.3048
|
161 |
elif roughness_unit == 'in': |
162 |
rough = roughness * 0.0254
|
163 |
elif roughness_unit == 'mm': |
164 |
rough = roughness * 0.001
|
165 |
|
166 |
pass
|
167 |
# ToDo..
|
168 |
# 기준 Dia를 구해야함
|
169 |
# *********************** 2. 목표값 찾기 (기준 Dia 구함) ***********************
|
170 |
# 기준 Dia 구함 (in)
|
171 |
std_nd = self.get_std_nd(mass, density, goal)
|
172 |
nd_unit = self.units['Pipe_Diameter'] |
173 |
row_id = self.get_row_id(std_nd, nd_unit)
|
174 |
|
175 |
if std_nd > 36: |
176 |
selected_nd = math.ceil(std_nd) |
177 |
else:
|
178 |
selected_nd = self.get_selected_nd(row_id + 1, nd_unit) |
179 |
|
180 |
nd = [] |
181 |
cvelocity = [] |
182 |
creynolds = [] |
183 |
ca = [] |
184 |
cf = [] |
185 |
cdp = [] |
186 |
|
187 |
if std_nd > 36: |
188 |
nd.append(selected_nd - 4)
|
189 |
nd.append(selected_nd - 2)
|
190 |
nd.append(selected_nd) |
191 |
else:
|
192 |
nd.append(self.get_selected_nd(row_id - 1, nd_unit)) |
193 |
nd.append(self.get_selected_nd(row_id, nd_unit))
|
194 |
nd.append(selected_nd) |
195 |
|
196 |
if std_nd > 34: |
197 |
nd.append(selected_nd + 2)
|
198 |
else:
|
199 |
nd.append(self.get_selected_nd(row_id + 2, nd_unit)) |
200 |
|
201 |
if std_nd > 30: |
202 |
nd.append(selected_nd + 4)
|
203 |
else:
|
204 |
nd.append(self.get_selected_nd(row_id + 3, nd_unit)) |
205 |
|
206 |
density_unit = self.units['Density'] |
207 |
for i in range(5): |
208 |
cvelocity.append(4 * volume / 3.1415 / ((nd[i] * 0.0254) ** 2) / 3600) # ND 마다 속도 구함 |
209 |
creynolds.append((nd[i] * 0.0254) * cvelocity[i] * density / viscosity) # ND 마다 레이놀즈 넘버 구함 |
210 |
# '마찰계수 산출
|
211 |
ca.append(math.log(rough / (nd[i] * 0.0254) / 3.7 + (6.7 / creynolds[i]) ** 0.9) / math.log(10)) |
212 |
cf.append( |
213 |
(-2 * (math.log(rough / 3.7 / (nd[i] * 0.0254) - 5.02 / creynolds[i] * ca[i]) / math.log(10))) ** ( |
214 |
-2))
|
215 |
# 100m 당 압력강하 산출 (kg/cm2)
|
216 |
if density_unit == 'kg/m3': |
217 |
cdp.append(cf[i] * density * (cvelocity[i] ** 2) / 2 / (nd[i] * 0.0254) / 9.8066 / 10000 * 100) |
218 |
elif density_unit == 'lb/ft3': |
219 |
cdp.append( |
220 |
cf[i] * (density * 16.0185) * (cvelocity[i] ** 2) / 2 / (nd[i] * 0.0254) / 9.8066 / 10000 * 100) |
221 |
|
222 |
# unit case에 따라 창에 입력.
|
223 |
pipe_diameter_unit = self.units['Pipe_Diameter'] |
224 |
if pipe_diameter_unit == 'mm': |
225 |
for i in range(5): |
226 |
nd[i] = nd[i] * 25
|
227 |
|
228 |
velocity_unit = self.units['Velocity'] |
229 |
if velocity_unit == 'm/s': |
230 |
for i in range(5): |
231 |
cvelocity[i] = round(cvelocity[i], 5) |
232 |
elif velocity_unit == 'ft/s': |
233 |
for i in range(5): |
234 |
cvelocity[i] = round(cvelocity[i] * 3.28084, 5) |
235 |
|
236 |
# reynolds
|
237 |
for i in range(5): |
238 |
creynolds[i] = round(creynolds[i], 0) |
239 |
|
240 |
# friction factor
|
241 |
for i in range(5): |
242 |
cf[i] = round(cf[i], 5) |
243 |
|
244 |
# pressure drop
|
245 |
pressure_unit = self.units['Pressure'] |
246 |
if pressure_unit == 'kg/cm2': |
247 |
for i in range(5): |
248 |
cdp[i] = cdp[i] |
249 |
elif pressure_unit == 'psi': |
250 |
for i in range(5): |
251 |
cdp[i] = cdp[i] / 1.033 * 14.7 |
252 |
elif pressure_unit == 'bar': |
253 |
for i in range(5): |
254 |
cdp[i] = cdp[i] / 1.033 * 1.013 |
255 |
elif pressure_unit == 'mmHg': |
256 |
for i in range(5): |
257 |
cdp[i] = cdp[i] / 1.033 * 760 |
258 |
elif pressure_unit == 'kPa': |
259 |
for i in range(5): |
260 |
cdp[i] = cdp[i] / 1.033 * 101.325 |
261 |
elif pressure_unit == 'MPa': |
262 |
for i in range(5): |
263 |
cdp[i] = cdp[i] / 1.033 * 0.101325 |
264 |
|
265 |
length_unit = self.units['Length'] |
266 |
if length_unit == 'm': |
267 |
for i in range(5): |
268 |
cdp[i] = round(cdp[i], 5) |
269 |
elif length_unit == 'in': |
270 |
for i in range(5): |
271 |
cdp[i] = round(cdp[i] / 39.3701, 5) |
272 |
elif length_unit == 'ft': |
273 |
for i in range(5): |
274 |
cdp[i] = round(cdp[i] / 3.28084, 5) |
275 |
elif length_unit == 'yd': |
276 |
for i in range(5): |
277 |
cdp[i] = round(cdp[i] / 1.09361, 5) |
278 |
elif length_unit == 'mile': |
279 |
for i in range(5): |
280 |
cdp[i] = round(cdp[i] / 0.000621371, 5) |
281 |
elif length_unit == 'mm': |
282 |
for i in range(5): |
283 |
cdp[i] = round(cdp[i] / 1000, 5) |
284 |
|
285 |
for i in range(5): |
286 |
self.add_data(nd[i], cvelocity[i], cdp[i], creynolds[i], cf[i])
|
287 |
|
288 |
except Exception as ex: |
289 |
from App import App |
290 |
from AppDocData import MessageType |
291 |
|
292 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
293 |
sys.exc_info()[-1].tb_lineno)
|
294 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
295 |
|
296 |
def calc_pde_l(self): |
297 |
try:
|
298 |
# 속도가 나와있는 경우의 liquid 모듈
|
299 |
# **********************************************************************************
|
300 |
# 참고사항 :
|
301 |
# 유닛의 기준 : 유량 (kg/h, m3/h), 밀도 (kg/m3), 지름 (m), 점도 (kg/m/s), 속도 (m/s), 압력강하 (kg/cm2/100m)
|
302 |
# **********************************************************************************
|
303 |
|
304 |
# ********** 1. Flowrate 구하기 ***********
|
305 |
# (1)질량만 적혀있는경우
|
306 |
if is_not_blank(self.process_data['Flowrate_Mass']) and is_blank(self.process_data['Flowrate_Volume']): |
307 |
flowrate_mass = float(self.process_data['Flowrate_Mass']) |
308 |
density = float(self.process_data['Density']) |
309 |
|
310 |
# '질량유량을 kg/h로 변환.
|
311 |
flowrate_mass_unit = self.units['Flowrate_Mass'] |
312 |
if flowrate_mass_unit == 'kg/h': |
313 |
mass = flowrate_mass |
314 |
elif flowrate_mass_unit == 'g/min': |
315 |
mass = flowrate_mass * 60 / 1000 |
316 |
elif flowrate_mass_unit == 'lb/h': |
317 |
mass = flowrate_mass * 0.453592
|
318 |
elif flowrate_mass_unit == 't/h': |
319 |
mass = flowrate_mass * 1000
|
320 |
|
321 |
# 'density case에 따라 volume rate (m3/h) 계산
|
322 |
density_unit = self.units['Density'] |
323 |
if density_unit == 'kg/m3': |
324 |
volume = mass / density |
325 |
elif density_unit == 'lb/ft3': |
326 |
volume = mass / (density * 16.0185)
|
327 |
elif is_blank(self.process_data['Flowrate_Mass']) and is_not_blank(self.process_data['Flowrate_Volume']): |
328 |
# (2)부피만 적혀있는경우
|
329 |
flowrate_volume = float(self.process_data['Flowrate_Volume']) |
330 |
density = float(self.process_data['Density']) |
331 |
|
332 |
# '부피유량을 m3/h로 변환.
|
333 |
flowrate_volume_unit = self.units['Flowrate_Volume'] |
334 |
if flowrate_volume_unit == 'm3/h': |
335 |
volume = flowrate_volume |
336 |
elif flowrate_volume_unit == 'l/min': |
337 |
volume = flowrate_volume * 60 / 1000 |
338 |
elif flowrate_volume_unit == 'ft3/h': |
339 |
volume = flowrate_volume / 35.3147
|
340 |
elif flowrate_volume_unit == 'USgpm': |
341 |
volume = flowrate_volume / 4.40287
|
342 |
elif flowrate_volume_unit == 'BPSD': |
343 |
volume = flowrate_volume / 150.955
|
344 |
|
345 |
# 'density case에 따라 mass rate (kg/h) 계산
|
346 |
density_unit = self.units['Density'] |
347 |
if density_unit == 'kg/m3': |
348 |
mass = volume * density |
349 |
elif density_unit == 'lb/ft3': |
350 |
mass = volume * (density * 16.0185)
|
351 |
elif is_not_blank(self.process_data['Flowrate_Mass']) and is_not_blank( |
352 |
self.process_data['Flowrate_Volume']): |
353 |
# (3) 둘다 적힌 경우 (mass를 가지고 한다)
|
354 |
flowrate_mass = float(self.process_data['Flowrate_Mass']) |
355 |
density = float(self.process_data['Density']) |
356 |
|
357 |
# '질량유량을 kg/h로 변환.
|
358 |
flowrate_mass_unit = self.units['Flowrate_Mass'] |
359 |
if flowrate_mass_unit == 'kg/h': |
360 |
mass = flowrate_mass |
361 |
elif flowrate_mass_unit == 'g/min': |
362 |
mass = flowrate_mass * 60 / 1000 |
363 |
elif flowrate_mass_unit == 'lb/h': |
364 |
mass = flowrate_mass * 0.453592
|
365 |
elif flowrate_mass_unit == 't/h': |
366 |
mass = flowrate_mass * 1000
|
367 |
|
368 |
# 'density case에 따라 volume rate (m3/h) 계산
|
369 |
density_unit = self.units['Density'] |
370 |
if density_unit == 'kg/m3': |
371 |
volume = mass / density |
372 |
elif density_unit == 'lb/ft3': |
373 |
volume = mass / (density * 16.0185)
|
374 |
|
375 |
# ********** 2. viscosity 구하기
|
376 |
viscosity = float(self.process_data['Viscosity']) |
377 |
viscosity_unit = self.units['Viscosity'] |
378 |
if viscosity_unit == 'kg/m.sec': |
379 |
viscosity = viscosity |
380 |
elif viscosity_unit == 'cP': |
381 |
viscosity = viscosity * 0.001
|
382 |
elif viscosity_unit == 'kg/m.h': |
383 |
viscosity = viscosity / 3600
|
384 |
elif viscosity_unit == 'lb/ft.s': |
385 |
viscosity = viscosity * 1.48816
|
386 |
|
387 |
# ********** 3. ND, 속도, 압력강하 5개 구함
|
388 |
velocity_unit = self.units['Velocity'] |
389 |
if velocity_unit == 'm/s': |
390 |
cvel = float(self.velocity) |
391 |
elif velocity_unit == 'ft/s': |
392 |
cvel = float(self.velocity) * 3.28084 |
393 |
|
394 |
# ★★★★★★★★★속도 / 압력강하 분기점★★★★★★★★★★
|
395 |
if cvel == 0 and float(self.pressure_drop) > 0: |
396 |
self.calc_pde_l2(mass, density, viscosity, volume)
|
397 |
return
|
398 |
|
399 |
roughness = float(self.process_data['Roughness']) |
400 |
roughness_unit = self.units['Roughness'] |
401 |
if roughness_unit == 'm': |
402 |
rough = roughness |
403 |
elif roughness_unit == 'ft': |
404 |
rough = roughness * 0.3048
|
405 |
elif roughness_unit == 'in': |
406 |
rough = roughness * 0.0254
|
407 |
elif roughness_unit == 'mm': |
408 |
rough = roughness * 0.001
|
409 |
|
410 |
# 기준 Dia 구함 (in)
|
411 |
std_nd = ((4 * volume / cvel / 3.1415 / 3600) ** 0.5) / 0.0254 |
412 |
nd_unit = self.units['Pipe_Diameter'] |
413 |
row_id = self.get_row_id(std_nd, nd_unit)
|
414 |
|
415 |
if std_nd > 36: |
416 |
selected_nd = math.ceil(std_nd) |
417 |
else:
|
418 |
selected_nd = self.get_selected_nd(row_id + 1, nd_unit) |
419 |
|
420 |
nd = [] |
421 |
cvelocity = [] |
422 |
creynolds = [] |
423 |
ca = [] |
424 |
cf = [] |
425 |
cdp = [] |
426 |
|
427 |
if std_nd > 36: |
428 |
nd.append(selected_nd - 2)
|
429 |
nd.append(selected_nd) |
430 |
else:
|
431 |
nd.append(self.get_selected_nd(row_id, nd_unit))
|
432 |
nd.append(selected_nd) |
433 |
|
434 |
if std_nd > 34: |
435 |
nd.append(selected_nd + 2)
|
436 |
else:
|
437 |
nd.append(self.get_selected_nd(row_id + 2, nd_unit)) |
438 |
|
439 |
if std_nd > 30: |
440 |
nd.append(selected_nd + 4)
|
441 |
nd.append(selected_nd + 6)
|
442 |
else:
|
443 |
nd.append(self.get_selected_nd(row_id + 3, nd_unit)) |
444 |
nd.append(self.get_selected_nd(row_id + 4, nd_unit)) |
445 |
|
446 |
density_unit = self.units['Density'] |
447 |
for i in range(5): |
448 |
cvelocity.append(4 * volume / 3.1415 / ((nd[i] * 0.0254) ** 2) / 3600) # ND 마다 속도 구함 |
449 |
creynolds.append((nd[i] * 0.0254) * cvelocity[i] * density / viscosity) # ND 마다 레이놀즈 넘버 구함 |
450 |
# '마찰계수 산출
|
451 |
ca.append(math.log(rough / (nd[i] * 0.0254) / 3.7 + (6.7 / creynolds[i]) ** 0.9) / math.log(10)) |
452 |
cf.append((-2 * (math.log(rough / 3.7 / (nd[i] * 0.0254) - 5.02 / creynolds[i] * ca[i]) / math.log(10))) ** (-2)) |
453 |
# 100m 당 압력강하 산출 (kg/cm2)
|
454 |
if density_unit == 'kg/m3': |
455 |
cdp.append(cf[i] * density * (cvelocity[i] ** 2) / 2 / (nd[i] * 0.0254) / 9.8066 / 10000 * 100) |
456 |
elif density_unit == 'lb/ft3': |
457 |
cdp.append(cf[i] * (density * 16.0185) * (cvelocity[i] ** 2) / 2 / (nd[i] * 0.0254) / 9.8066 / 10000 * 100) |
458 |
|
459 |
# unit case에 따라 창에 입력.
|
460 |
pipe_diameter_unit = self.units['Pipe_Diameter'] |
461 |
if pipe_diameter_unit == 'mm': |
462 |
for i in range(5): |
463 |
nd[i] = nd[i] * 25
|
464 |
|
465 |
velocity_unit = self.units['Velocity'] |
466 |
if velocity_unit == 'm/s': |
467 |
for i in range(5): |
468 |
cvelocity[i] = round(cvelocity[i], 5) |
469 |
elif velocity_unit == 'ft/s': |
470 |
for i in range(5): |
471 |
cvelocity[i] = round(cvelocity[i] * 3.28084, 5) |
472 |
|
473 |
# reynolds
|
474 |
for i in range(5): |
475 |
creynolds[i] = round(creynolds[i], 0) |
476 |
|
477 |
# friction factor
|
478 |
for i in range(5): |
479 |
cf[i] = round(cf[i], 5) |
480 |
|
481 |
# pressure drop
|
482 |
pressure_unit = self.units['Pressure'] |
483 |
if pressure_unit == 'kg/cm2': |
484 |
for i in range(5): |
485 |
cdp[i] = cdp[i] |
486 |
elif pressure_unit == 'psi': |
487 |
for i in range(5): |
488 |
cdp[i] = cdp[i] / 1.033 * 14.7 |
489 |
elif pressure_unit == 'bar': |
490 |
for i in range(5): |
491 |
cdp[i] = cdp[i] / 1.033 * 1.013 |
492 |
elif pressure_unit == 'mmHg': |
493 |
for i in range(5): |
494 |
cdp[i] = cdp[i] / 1.033 * 760 |
495 |
elif pressure_unit == 'kPa': |
496 |
for i in range(5): |
497 |
cdp[i] = cdp[i] / 1.033 * 101.325 |
498 |
elif pressure_unit == 'MPa': |
499 |
for i in range(5): |
500 |
cdp[i] = cdp[i] / 1.033 * 0.101325 |
501 |
|
502 |
length_unit = self.units['Length'] |
503 |
if length_unit == 'm': |
504 |
for i in range(5): |
505 |
cdp[i] = round(cdp[i], 5) |
506 |
elif length_unit == 'in': |
507 |
for i in range(5): |
508 |
cdp[i] = round(cdp[i] / 39.3701, 5) |
509 |
elif length_unit == 'ft': |
510 |
for i in range(5): |
511 |
cdp[i] = round(cdp[i] / 3.28084, 5) |
512 |
elif length_unit == 'yd': |
513 |
for i in range(5): |
514 |
cdp[i] = round(cdp[i] / 1.09361, 5) |
515 |
elif length_unit == 'mile': |
516 |
for i in range(5): |
517 |
cdp[i] = round(cdp[i] / 0.000621371, 5) |
518 |
elif length_unit == 'mm': |
519 |
for i in range(5): |
520 |
cdp[i] = round(cdp[i] / 1000, 5) |
521 |
|
522 |
for i in range(5): |
523 |
self.add_data(nd[i], cvelocity[i], cdp[i], creynolds[i], cf[i])
|
524 |
|
525 |
except Exception as ex: |
526 |
from App import App |
527 |
from AppDocData import MessageType |
528 |
|
529 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
530 |
sys.exc_info()[-1].tb_lineno)
|
531 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
532 |
|
533 |
def get_selected_nd(self, row_id, nd_unit): |
534 |
try:
|
535 |
return AppDocData.instance().get_selected_nd(row_id, nd_unit)
|
536 |
|
537 |
except Exception as ex: |
538 |
from App import App |
539 |
from AppDocData import MessageType |
540 |
|
541 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
542 |
sys.exc_info()[-1].tb_lineno)
|
543 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
544 |
|
545 |
def get_row_id(self, std_nd, nd_unit): |
546 |
try:
|
547 |
return AppDocData.instance().get_row_id(std_nd, nd_unit)
|
548 |
|
549 |
except Exception as ex: |
550 |
from App import App |
551 |
from AppDocData import MessageType |
552 |
|
553 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
554 |
sys.exc_info()[-1].tb_lineno)
|
555 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
556 |
|
557 |
def init_pipe_diameter_estimation(self): |
558 |
self.ui.tableWidget.setColumnCount(5) |
559 |
|
560 |
'ND ({})'.format(self.units['Pipe_Diameter']) |
561 |
self.ui.tableWidget.setHorizontalHeaderLabels(['ND ({})'.format(self.units['Pipe_Diameter']), |
562 |
'Velocity ({})'.format(self.units['Velocity']), |
563 |
'Pressure Drop ({}/100{})'.format(self.units['Pressure'], |
564 |
self.units['Length']), |
565 |
'Reynolds',
|
566 |
'Friction'])
|
567 |
self.ui.tableWidget.verticalHeader().setVisible(False) |
568 |
self.ui.tableWidget.setSelectionMode(QAbstractItemView.SingleSelection)
|
569 |
self.ui.tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)
|
570 |
self.ui.tableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
|
571 |
self.ui.tableWidget.horizontalHeaderItem(0).setSizeHint(QSize(70, 30)) |
572 |
self.ui.tableWidget.horizontalHeaderItem(1).setSizeHint(QSize(110, 30)) |
573 |
self.ui.tableWidget.horizontalHeaderItem(2).setSizeHint(QSize(200, 30)) |
574 |
self.ui.tableWidget.horizontalHeaderItem(3).setSizeHint(QSize(80, 30)) |
575 |
self.ui.tableWidget.horizontalHeader().setStretchLastSection(True) |
576 |
|
577 |
self.ui.tableWidget.resizeColumnsToContents()
|
578 |
self.ui.tableWidget.resizeRowsToContents()
|
579 |
|
580 |
def add_data(self, nd, velocity, pressure_drop, reynolds, friction): |
581 |
row = self.ui.tableWidget.rowCount()
|
582 |
self.ui.tableWidget.setRowCount(row + 1) |
583 |
|
584 |
self.ui.tableWidget.setItem(row, 0, set_table_widget_item_properties(nd, |
585 |
Qt.AlignHCenter | Qt.AlignVCenter)) |
586 |
self.ui.tableWidget.setItem(row, 1, set_table_widget_item_properties(velocity, |
587 |
Qt.AlignHCenter | Qt.AlignVCenter)) |
588 |
self.ui.tableWidget.setItem(row, 2, set_table_widget_item_properties(pressure_drop, |
589 |
Qt.AlignHCenter | Qt.AlignVCenter)) |
590 |
self.ui.tableWidget.setItem(row, 3, set_table_widget_item_properties(reynolds, |
591 |
Qt.AlignHCenter | Qt.AlignVCenter)) |
592 |
self.ui.tableWidget.setItem(row, 4, set_table_widget_item_properties(friction, |
593 |
Qt.AlignHCenter | Qt.AlignVCenter)) |
594 |
|
595 |
self.ui.tableWidget.resizeRowsToContents()
|
596 |
self.ui.tableWidget.resizeColumnsToContents()
|
597 |
|
598 |
def double_clicked(self, row): |
599 |
self.isAccepted = True |
600 |
QDialog.accept(self)
|
601 |
|
602 |
def accept(self): |
603 |
self.isAccepted = True |
604 |
QDialog.accept(self)
|
605 |
|
606 |
def reject(self): |
607 |
self.isAccepted = False |
608 |
QDialog.reject(self)
|