Line_Gas.py

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# Applied Python PRISM
# (PRISM) PaRametrIc System Model
#
# Written by Charlie Taylor <cet@appliedpython.com> 
# Feb 14, 2006 (Valentines Day)


from math import *
import sys

#from prism.props.refprop7.n23_fluid import n_fluid
from prism.props.refprop7.n_dll_fluid import n_fluid

from prism.MassItem import MassItem
from prism.props import Materials
from prism.Summary import Summary
from prism.props import Inc_liquid
from prism.fortran import orifice

class Line_Gas( MassItem ):
    '''    
       outlet properties are in "self.gasObj.dup" object
    '''
    
    def __init__(self, name="gas line", gasSymbol='O2',  matlName="Ti", 
        calcVelFromDiamInp=1, DiamInp=1.0, thkWallInp=0,
        wdot=0.1, velFPS=20.0, TgasDegR=530.0, designWithVout=1,
        usePinlet=0, PgasOutlet=400.0, PgasInlet=400.0, 
        len_inches=50.0, Kfactors=2.0,  Number=1,
        sf=4.0, cxw=1.25, roughness=5.0E-6, mass_lbm=0.0 ):
            
        # default roughness (5.0E-6) is for drawn tubing
        
        MassItem.__init__(self, name, type="inert", mass_lbm=mass_lbm)
        
        if gasSymbol[-3:].lower() == "(g)": gasSymbol=gasSymbol[:-3]
        self.gasObj = n_fluid(gasSymbol,child=1)
        
        self.Number = Number
        self.matlName = matlName
        self.rho, self.sy, self.e, self.tming = Materials.getMatlProps(matlName)
        
        if self.tming < 0.035:
            self.tming = 0.035  # i.e. tube wall min is probably more like 0.035
        
        self.velFPS = velFPS
        self.designWithVout = designWithVout
        
        self.calcVelFromDiamInp=calcVelFromDiamInp
        self.DiamInp=DiamInp
        self.thkWallInp = thkWallInp
        self.wdot = wdot
        self.Kfactors = Kfactors
        self.roughness = roughness
        self.PgasInlet = PgasInlet
        self.PgasOutlet = PgasOutlet
        self.usePinlet = usePinlet  # flag to indicate whether inlet or outlet P is the input
        self.TgasDegR = TgasDegR
        self.len_inches = len_inches
        self.sf = sf
        self.cxw = cxw
        
        self.reCalc()
        
    def getTPoutlet(self):
        return self.gasObj.dup.T,self.gasObj.dup.P
        #NOT... return self.gasObj.T,self.gasObj.P

    def reCalc(self, autoCalc=1):
        self.autoCalc = autoCalc

        # use inlet (or outlet) properties to make 1st estimate of dpLine
        if self.usePinlet:
            self.gasObj.setTP( T=self.TgasDegR, P=self.PgasInlet )   
            self.gasObj.dup.setTP( T=self.TgasDegR, P=self.PgasInlet )   
        else:
            self.gasObj.setTP( T=self.TgasDegR, P=self.PgasOutlet )
            self.gasObj.dup.setTP( T=self.TgasDegR, P=self.PgasOutlet )
            
        self.Pave = -999.0 # initialize average pressure in line
        
        # use 1st loop to estimate dpLine
        for loop in range(2):
            
            # use average properties for Reynolds number, dP calc., etc.
            rhoAve = (self.gasObj.dup.rho + self.gasObj.rho) / 2.0
            Dave = (self.gasObj.dup.D + self.gasObj.D) / 2.0
            ViscAve = (self.gasObj.dup.Visc + self.gasObj.Visc) / 2.0
            
            # make volumetric flow either outlet flow OR average flow
            if self.designWithVout:
                self.volFlow = self.wdot / self.gasObj.dup.rho
            else:
                self.volFlow = self.wdot / rhoAve  # dup holds outlet properties
            
            if self.calcVelFromDiamInp:
                # Need to subtract thickness from the Tube OD
                thkEst = max(self.tming, self.sf * self.PgasInlet * self.DiamInp / self.sy / 2.0)
                if self.thkWallInp:
                    thkEst = self.thkWallInp
                rinsidEst = self.DiamInp/2.0 - thkEst
                self.Ac = pi * rinsidEst**2
                self.velFPS = self.volFlow / self.Ac / 12.0
            else:
                self.Ac = self.volFlow / (self.velFPS * 12.0)
                
            self.rinsid = sqrt( self.Ac / pi )
            self.dinsid = self.rinsid * 2.0
        
            self.ReNum= Dave * self.velFPS * \
                (self.dinsid/12.0) / (ViscAve * 1.0E-5)
        
            self.volLine = pi * self.rinsid**2 * self.len_inches
        
            if self.thkWallInp:
                self.thkLine = self.thkWallInp
            else:
                self.thkLine = max(self.tming, self.sf * self.PgasInlet * self.dinsid / self.sy / 2.0)
        
            self.dpLine = orifice.calcturbulenttubedp(self.len_inches ,\
                self.Kfactors, self.dinsid, self.wdot, Dave, self.roughness,
                self.ReNum)
                
            self.fricfact = orifice.ffactr(self.ReNum,self.roughness,self.dinsid)
        
            if loop == 0:
                if self.usePinlet:
                    # GOON up the logic in case dpLine is TOO BIG
                    # catch the error on the output page also
                    if self.dpLine > self.PgasInlet:
                        self.dpLine = self.PgasInlet * (self.PgasInlet/self.dpLine)
                        print 'WARNING... dpLine is too large in Line_Gas.py'
                    self.Pave = self.PgasInlet - self.dpLine/2.0
                    self.PgasOutlet = self.PgasInlet - self.dpLine
                    self.gasObj.dup.setTP( T=self.TgasDegR, P=self.PgasOutlet )
                else:
                    self.Pave = self.PgasOutlet + self.dpLine/2.0
                    self.PgasInlet = self.PgasOutlet + self.dpLine
                    self.gasObj.setTP( T=self.TgasDegR, P=self.PgasInlet )
        
                #self.gasObj.setTP( T=self.TgasDegR, P=self.Pave )   
        
        self.mass_lbm = pi * ((self.rinsid+self.thkLine)**2 - self.rinsid**2) *\
            self.len_inches * self.rho * self.cxw * self.Number
            
        if self.usePinlet:
            self.PgasOutlet = self.PgasInlet - self.dpLine
        else:
            self.PgasInlet = self.PgasOutlet + self.dpLine
            
        self.dPoverPin = self.dpLine/self.PgasInlet
        
        self.gasObj.setTP( T=self.TgasDegR, P=self.PgasInlet )
        self.gasObj.dup.setPH( H=self.gasObj.H, P=self.PgasOutlet )
        
        self.xMach = self.velFPS/self.gasObj.sonicV
        
        self.velHead = self.gasObj.D * self.velFPS**2 / 2.0 / 32.174 / 144.0

    
    def minGaugeStr(self, t):
        if t<= self.tming:
            return 'Min Gauge'
        else:
            return ''
        
    def buildSummary(self):
        
        summ = Summary(  summName='Gas Line',
        componentName=self.name, mass_lbm=self.mass_lbm, type=self.type)
        
        if self.dPoverPin>0.1:
            summ.addAssumption( 'WARNING... dP/Pin = %g : should be <= 0.1'%self.dPoverPin )
        
        summ.addAssumption( "In: "+self.gasObj.getStrTPDphase() )
        summ.addAssumption( "Out:"+self.gasObj.dup.getStrTPDphase() )
        
        summ.addAssumption( 'fluid : ' + self.gasObj.symbol )
        summ.addAssumption( 'Structural Material : ' + self.matlName )
        summ.addAssumption( 'Allow Non-Standard wall thickness' )
        if self.usePinlet:
            summ.addAssumption( 'Using Pinlet to design line' )
        else:
            summ.addAssumption( 'Using Poutlet to design line' )
            
        if self.calcVelFromDiamInp:
            summ.addAssumption( 'Line Diameter is an Input (vel is output)' )
        else:
            summ.addAssumption( 'Line Velocity is an Input (diam is output)' )
            
        if self.Number>1:
            summ.addAssumption( 'Mass is for %i lines total'%self.Number )
        
        # add inputs
        summ.addInput('wdot', self.wdot, 'lbm/sec', '%g')
        if self.calcVelFromDiamInp:
            summ.addInput('DiamInp', self.DiamInp, 'in', '%.3f')
        else:
            summ.addInput('velFPS', self.velFPS, 'ft/sec', '%g')
            
        if self.thkWallInp:
            summ.addInput('thkWallInp', self.thkWallInp, 'in', '%.3f')
            
        summ.addInput('len_inches', self.len_inches, 'in', '%g')
        summ.addInput('Kfactors', self.Kfactors, 'vel heads', '%g')
        summ.addInput('roughness', self.roughness, 'in', '%g')
        if self.usePinlet:
            summ.addInput('PgasInlet', self.PgasInlet, 'psia', '%.1f')
        else:
            summ.addInput('PgasOutlet', self.PgasOutlet, 'psia', '%.1f')
        summ.addInput('sf', self.sf, '', '%g')
        summ.addInput('cxw', self.cxw, '', '%g')
        summ.addInput('# Lines', self.Number, '', '%i')
        
        # add outputs

        if  not self.usePinlet:
            summ.addOutput('PgasInlet', self.PgasInlet, 'psia', '%.1f')
        else:
            summ.addOutput('PgasOutlet', self.PgasOutlet, 'psia', '%.1f')
        if self.calcVelFromDiamInp:
            summ.addOutput('velFPS', self.velFPS, 'ft/sec', '%g')
            
        summ.addOutput( 'velHead',self.velHead , 'psi', '%.3f')
        summ.addOutput( 'dpLine', self.dpLine, 'psig', '%.2f' )

        Kline = self.fricfact * self.len_inches/self.dinsid 
        fdpLine = Kline / (Kline + self.Kfactors)
        summ.addOutput( 'dp due to Line', self.dpLine*fdpLine, 'psig', '%.2f' )
        summ.addOutput( 'dp due to Ks', self.dpLine*(1.0-fdpLine), 'psig', '%.2f' )

        summ.addOutput( 'dp/Pinlet', self.dPoverPin, '', '%g' )
        summ.addOutput( 'ReNum', self.ReNum, '', '%E' )
        summ.addOutput( 'fricfact',self.fricfact, '', '%g')
        summ.addOutput( 'thkLine', self.thkLine, 'in', '%.3f' )
        summ.addOutput( 'rinsid', self.rinsid, 'in', '%.3f' )
        summ.addOutput( 'dinsid', self.dinsid, 'in', '%.3f' )
        summ.addOutput( 'volLine', self.volLine, 'cuin', '%g' )
        summ.addOutput( 'rho', self.rho, 'lbm/cuin', '%g' )
        summ.addOutput( 'sy', self.sy, 'psi', '%g' )
        #summ.addOutput( 'e', self.e, 'psi', '%g' )
        summ.addOutput( 'tming', self.tming, 'in', '%.3f' )
        summ.addOutput( 'fluid dens', self.gasObj.D, 'lbm/cuft', '%g' )
        summ.addOutput( 'fluid visc', self.gasObj.Visc*1.0E-5, 'lb/ft-sec', '%g' )
        summ.addOutput( 'fluid sonicV', self.gasObj.sonicV, 'ft/sec', '%g' )
        summ.addOutput( 'fluid Mach', self.xMach, '', '%g' )
        if self.Number>1:
            summ.addOutput( 'wt/Line', self.mass_lbm/self.Number, 'lbm', '%.3f' )

        return summ


if __name__ == "__main__":  #self test
    
    h = Line_Gas(name="Ox Line",wdot=1.0, matlName="Ti", thkWallInp=0.083,
        usePinlet=1, velFPS=20.0, PgasInlet=4000.0,
        gasSymbol='O2', Number=10, Kfactors=2.0)
    print h.getMassStr()
    print
    print h.getSummary()