Gas_Orifice.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
# Applied Python PRISM
# (PRISM) PaRametrIc System Model
#
# Written by Charlie Taylor <cet@appliedpython.com> 
# Feb 14, 2006 (Valentines Day)

import sys
from math import *

from prism.MassItem import MassItem
from prism.Summary import Summary
from prism.props import Materials
from prism.props.refprop7.n_dll_fluid import n_fluid
from prism.utils import n_orifice
from prism.fortran import orifice



class Gas_Orifice( MassItem ):
    '''    
       outlet properties are in "self.gasObj.dup" object
    '''
    def __init__(self, name="gas orifice", gasSymbol='O2',  matlName="Ti", 
        CdAInp=1.0,
        wdot=0.1, TgasDegR=530.0,
        usePinlet=0, PgasOutlet=400.0, PgasInlet=400.0, 
        Number=1,
        sf=4.0, cxw=1.25, mass_lbm=0.0 ):
            
        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)
        
        # calculate density for SCFM
        self.gasObj.setTP( T=530.0, P=14.7 )
        self.Dscf = self.gasObj.D 
        
        self.orifObj = n_orifice.g_orifice(self.gasObj, name=name, Pin=PgasInlet, Tin=TgasDegR, 
            Pout=PgasOutlet, CdA=CdAInp)
        
        self.Number = Number
        self.matlName = matlName
        self.rho, self.sy, self.e, self.tming = Materials.getMatlProps(matlName)
        
        self.CdAInp=CdAInp
        self.wdot = wdot
        self.PgasInlet = PgasInlet
        self.PgasOutlet = PgasOutlet
        self.usePinlet = usePinlet  # flag to indicate whether inlet or outlet P is the input
        self.TgasDegR = TgasDegR
        self.sf = sf
        self.cxw = cxw
        
        self.reCalc()
        
    def getTPoutlet(self):
        return self.gasObj.dup.T,self.gasObj.dup.P
        
    def reCalc(self, autoCalc=1):
        self.autoCalc = autoCalc

        # use inlet (or outlet) properties to make 1st estimate of dpOrifice
        if self.usePinlet:
            self.gasObj.setTP( T=self.TgasDegR, P=self.PgasInlet )   
            self.PgasOutlet, self.dpOrifice,  self.ImSonic, self.wdShortFall, self.xMach\
                = orifice.solveorificedp(self.CdAInp,self.PgasInlet,
                    self.TgasDegR,self.wdot,self.gasObj.gamma(),self.gasObj.WtMol)
        else:
            # assume just sonic for 1st pass
            self.gasObj.setTP( T=self.TgasDegR, P=self.PgasOutlet*2.0 )
            
            self.PgasInlet, self.dpOrifice, self.ImSonic, self.xMach = orifice.solveorificedpin(self.CdAInp,self.PgasOutlet,
                self.TgasDegR,self.wdot,self.gasObj.gamma(),self.gasObj.WtMol, 15000.0)
                
            # now simply use the results from above to set the Pinlet value to improve the estimate of gamma
            self.gasObj.setTP( T=self.TgasDegR, P=self.PgasInlet ) 

            # and repeat the calc
            self.PgasInlet, self.dpOrifice, self.ImSonic, self.xMach = orifice.solveorificedpin(self.CdAInp,self.PgasOutlet,
                self.TgasDegR,self.wdot,self.gasObj.gamma(),self.gasObj.WtMol, 15000.0)
                
        # finalize the inlet properties and outlet properties
        self.gasObj.setTP( T=self.TgasDegR, P=self.PgasInlet ) 
        self.gasObj.dup.setPH( H=self.gasObj.H, P=self.PgasOutlet )
            
        maxRho = max(self.gasObj.rho, 1.0E-10)
        #print self.name, "self.wdot, maxRho",self.wdot, maxRho
        self.Q = self.wdot / maxRho
            
        self.orifObj.newPress( Pin=self.PgasInlet, Pout=14.7)
        self.velFPS = self.Q / self.CdAInp / 12.0
                
        self.rinsid = sqrt( self.CdAInp / pi )
        self.dinsid = self.rinsid * 2.0
        
        
        self.thkWall = max(self.tming, self.sf * self.PgasInlet * self.dinsid / self.sy / 2.0)
        
        if self.usePinlet:
            # GOON up the logic in case dpOrifice is TOO BIG
            # catch the error on the output page also
            if self.dpOrifice > self.PgasInlet:
                self.dpOrifice = self.PgasInlet * (self.PgasInlet/self.dpOrifice)
                print 'WARNING... dpOrifice is too large in Gas_Orifice.py'
        
        self.mass_lbm = pi * ((self.rinsid+self.thkWall)**2 - self.rinsid**2) *\
            self.rho * self.cxw * self.Number * self.dinsid
            
            
        self.dPoverPin = self.dpOrifice/self.PgasInlet
        
        try:
            self.xMach = self.velFPS/self.gasObj.sonicV
        except:
            self.xMach = -1.0
        
        
        self.SCFM = self.wdot * 60.0 / self.Dscf # standard cuft per minute

    
    def minGaugeStr(self, t):
        if t<= self.tming:
            return 'Min Gauge'
        else:
            return ''
        
    def buildSummary(self):
        
        summ = Summary(  summName='Gas Orifice',
        componentName=self.name, mass_lbm=self.mass_lbm, type=self.type)
        
        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 Orifice' )
        else:
            summ.addAssumption( 'Using Poutlet to design Orifice' )
            
        summ.addAssumption( 'Orifice CdA is an Input' )
        if self.ImSonic:
            summ.addAssumption( 'Orifice is SONIC' )
        else:
            summ.addAssumption( 'Orifice is SUB-SONIC' )
            
            
        if self.Number>1:
            summ.addAssumption( 'Mass is for %i Orifices total'%self.Number )
        
        # add inputs
        summ.addInput('wdot', self.wdot, 'lbm/sec', '%g')
        summ.addInput('SCFM', self.SCFM, 'SCFM', '%g')
        summ.addInput('CdAInp', self.CdAInp, '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('# Orifices', self.Number, '', '%i')
        
        # add outputs

        if  not self.usePinlet:
            summ.addOutput('PgasInlet', self.PgasInlet, 'psia', '%.1f')
        else:
            summ.addOutput('PgasOutlet', self.PgasOutlet, 'psia', '%.1f')
        summ.addOutput('velFPS', self.velFPS, 'ft/sec', '%g')
            
        summ.addOutput( 'dpOrifice', self.dpOrifice, 'psid', '%.2f' )
        summ.addOutput( 'dp/Pinlet', self.dPoverPin, '', '%g' )
        summ.addOutput( 'thkWall', self.thkWall, 'in', '%.3f' )
        summ.addOutput( 'rinsid', self.rinsid, 'in', '%.3f' )
        summ.addOutput( 'dinsid', self.dinsid, 'in', '%.3f' )
        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/Orifice', self.mass_lbm/self.Number, 'lbm', '%.3f' )

        return summ


if __name__ == "__main__":  #self test
    
    CdA = 0.0003
    CdA = 0.0189
    
    h = Gas_Orifice(name="Fuel Orifice",wdot=0.0001826, matlName="Ti", 
        usePinlet=1, PgasInlet=590.0, CdAInp=CdA,
        gasSymbol='HE', Number=10)
    print h.getMassStr()
    print
    print h.getSummary()
        
    
    h = Gas_Orifice(name="Fuel Orifice",wdot=0.00136, matlName="Ti", 
        usePinlet=1, PgasInlet=350.0, CdAInp=CdA,
        TgasDegR=530.0,
        gasSymbol='HE', Number=10)
    print h.getMassStr()
    print
    print h.getSummary()