프로젝트

일반

사용자정보

개정판 04879434

ID04879434c4156d3c921ad34e375e764b891fdea4
상위 db3c79f0
하위 b513fbd1

김연진이(가) 약 5년 전에 추가함

issue #1254 DiameterEstimation_Liquid

Change-Id: I86c140a1663a9fab1fe9934f83ff553823873cef

차이점 보기:

HYTOS/HYTOS/DiameterEstimation_Liquid.py
55 55
    def show_dialog(self, velocity, pressure_drop, process_data):
56 56
        self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint)
57 57

  
58
        self.velocity = '' if velocity == '-' else velocity
59
        self.pressure_drop = '' if pressure_drop == '-' else pressure_drop
58
        self.velocity = str(0) if velocity == '-' or is_blank(velocity) else velocity
59
        self.pressure_drop = str(0) if pressure_drop == '-' or is_blank(pressure_drop) else pressure_drop
60 60
        self.process_data = process_data
61 61

  
62 62
        self.init_units()
......
77 77

  
78 78
    def initialize(self):
79 79
        try:
80
            self.ui.lineEdit_Velocity.setText(self.velocity)
81
            self.ui.lineEdit_Pressure_Drop.setText(self.pressure_drop)
80
            self.ui.lineEdit_Velocity.setText(str(self.velocity))
81
            self.ui.lineEdit_Pressure_Drop.setText(str(self.pressure_drop))
82 82

  
83 83
            self.ui.label_Velocity_Unit.setText(self.units['Velocity'])
84 84
            self.ui.label_Pressure_Drop_Unit.setText('{}/100{}'.format(self.units['Pressure'], self.units['Length']))
......
113 113

  
114 114
    def f(self, inner_dia):
115 115
        try:
116
            e = 680  # Density
116
            e = float(self.process_data['Density'])  #680  # Density
117 117
            j = inner_dia
118
            l = 0.000046  # Roughness
119
            k = 0.7  # Viscosity
120
            i = 123456  # Flowrate_Mass
118
            l = float(self.process_data['Roughness'])  # Roughness
119
            k = float(self.process_data['Viscosity'])  # Viscosity
120
            i = float(self.process_data['Flowrate_Mass'])  # Flowrate_Mass
121 121
            d = i / e
122 122
            b = (d / (math.pi * (j / 2 * 0.0254) ** 2)) / 3600
123 123
            f = b * 0.0254 * j * e / (k * 0.001)
124 124
            g = ((l / (j * 0.0254)) ** 1.1098) / 2.8257 + (7.149 / f) ** 0.8981
125
            h = (2 * math.log(l / (j * 0.0254) / 3.7065 - 5.0452 * math.log(g) / f) * (-1)) ** (-2)
125
            h = (2 * math.log10(l / (j * 0.0254) / 3.7065 - 5.0452 * math.log10(g) / f) * (-1)) ** (-2)
126 126

  
127 127
            return (h / (j * 0.0254) * b ** 2 / 2 / 9.8066 * e / 10000) * 100
128 128

  
......
141 141
            # (ii)  Define the goal (result)
142 142

  
143 143
            # (iii) Define a starting point
144
            x0 = 0.5
145

  
146
            inner_dia = GoalSeek(self.f, goal, x0)
144
            x0 = 10
147 145

  
146
            inner_dia = GoalSeek(self.f, goal, x0, 0, 100)
147
            # inner_dia = 6.70118159
148 148
            return inner_dia
149

  
149 150
        except Exception as ex:
150 151
            from App import App
151 152
            from AppDocData import MessageType
HYTOS/HYTOS/WhatIfAnalysis.py
1 1
import numpy as np
2 2

  
3
def GoalSeek(fun,goal,x0,fTol=0.0001,MaxIter=1000):
3
def GoalSeek(fun,goal,x0, left, right, fTol=0.0001):
4 4
    # Goal Seek function of Excel
5 5
    #   via use of Line Search and Bisection Methods
6 6

  
......
10 10
    #   x0      : Initial estimate/Starting point
11 11

  
12 12
    # Initial check
13
    if fun(x0)==goal:
14
        print('Exact solution found')
13
    if fun(x0) == goal:
15 14
        return x0
16 15

  
17
    # Line Search Method
18
    step_sizes=np.logspace(-1,4,6)
19
    scopes=np.logspace(1,5,5)
16
    toler = 1
17
    while toler > fTol:
18
        calc = fun(x0)
19
        toler = abs(goal - calc)
20
        if toler < fTol: break
21
        if goal > calc:
22
            right = x0
23
            x0 = (left + x0)*0.5
24
        elif goal < calc:
25
            left = x0
26
            x0 = (x0 + right) * 0.5
20 27

  
21
    vFun=np.vectorize(fun)
28
    return x0
22 29

  
23
    for scope in scopes:
24
        break_nested=False
25
        for step_size in step_sizes:
26

  
27
            cApos=np.linspace(x0,x0+step_size*scope,int(scope))
28
            cAneg=np.linspace(x0,x0-step_size*scope,int(scope))
29

  
30
            cA=np.concatenate((cAneg[::-1],cApos[1:]),axis=0)
31

  
32
            fA=vFun(cA)-goal
33

  
34
            if np.any(np.diff(np.sign(fA))):
35

  
36
                index_lb=np.nonzero(np.diff(np.sign(fA)))
37

  
38
                if len(index_lb[0])==1:
39

  
40
                    index_ub=index_lb+np.array([1])
41

  
42
                    x_lb=np.asscalar(np.array(cA)[index_lb][0])
43
                    x_ub=np.asscalar(np.array(cA)[index_ub][0])
44
                    break_nested=True
45
                    break
46
                else: # Two or more roots possible
47

  
48
                    index_ub=index_lb+np.array([1])
49

  
50
                    print('Other solution possible at around, x0 = ', np.array(cA)[index_lb[0][1]])
51

  
52
                    x_lb=np.asscalar(np.array(cA)[index_lb[0][0]])
53
                    x_ub=np.asscalar(np.array(cA)[index_ub[0][0]])
54
                    break_nested=True
55
                    break
56

  
57
        if break_nested:
58
            break
59
    if not x_lb or not x_ub:
60
        print('No Solution Found')
61
        return
62

  
63
    # Bisection Method
64
    iter_num=0
65
    error=10
66

  
67
    while iter_num<MaxIter and fTol<error:
68
        
69
        x_m=(x_lb+x_ub)/2
70
        f_m=fun(x_m)-goal
71

  
72
        error=abs(f_m)
73

  
74
        if (fun(x_lb)-goal)*(f_m)<0:
75
            x_ub=x_m
76
        elif (fun(x_ub)-goal)*(f_m)<0:
77
            x_lb=x_m
78
        elif f_m==0:
79
            print('Exact spolution found')
80
            return x_m
81
        else:
82
            print('Failure in Bisection Method')
83
        
84
        iter_num+=1
85

  
86
    return x_m
87 30

  
88 31

  

내보내기 Unified diff

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