Gas_Regulator.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
# 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_Regulator( MassItem ):
    '''    
       initial outlet properties are in "self.gasObjInit.dup" object
       final   outlet properties are in "self.gasObjFinal.dup" object
    '''
    def __init__(self, name="gas regulator", gasSymbol='O2',  matlName="Ti", 
        wdot=0.1, TgasInit=530.0, TgasFinal=400.0,
        PgasOutlet=400.0, PgasInit=4000.0,  PgasFinal=800.0,
        Number=1, CdASF=1.5,
        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.gasObjInit = n_fluid(gasSymbol,child=1)
        self.gasObjFinal = n_fluid(gasSymbol,child=1)
        
        # calculate density for SCFM
        self.gasObjInit.setTP( T=530.0, P=14.7 )
        self.Dscf = self.gasObjInit.D 
        
        self.Number = Number
        self.matlName = matlName
        self.rho, self.sy, self.e, self.tming = Materials.getMatlProps(matlName)
        
        self.wdot = wdot
        self.PgasInit = PgasInit
        self.PgasFinal = PgasFinal
        self.PgasOutlet = PgasOutlet
        self.TgasInit = TgasInit
        self.TgasFinal = TgasFinal
        self.sf = sf
        self.CdASF = CdASF # multiplier on baseline CdA for margin
        self.cxw = cxw
        
        self.reCalc()
        
    def getTPoutletInit(self):
        return self.gasObjInit.dup.T,self.gasObjInit.dup.P
        
    def getTPoutletFinal(self):
        return self.gasObjFinal.dup.T,self.gasObjFinal.dup.P
        
    def reCalc(self, autoCalc=1):
        self.autoCalc = autoCalc

        # Size for initial conditions
        self.gasObjInit.setTP( T=self.TgasInit, P=self.PgasInit )
        self.gasObjInit.dup.setPH( H=self.gasObjInit.H, P=self.PgasOutlet )
            
        self.CdAInit, self.ImSonic = orifice.solveorificecda(self.wdot,self.PgasInit,self.TgasInit,
            self.PgasOutlet,self.gasObjInit.gamma(),self.gasObjInit.WtMol)
            
        # Size for final conditions
        self.gasObjFinal.setTP( T=self.TgasFinal, P=self.PgasFinal )
        self.gasObjFinal.dup.setPH( H=self.gasObjFinal.H, P=self.PgasOutlet )
            
        self.CdAFinal, self.ImSonic = orifice.solveorificecda(self.wdot,self.PgasFinal,self.TgasFinal,
            self.PgasOutlet,self.gasObjFinal.gamma(),self.gasObjFinal.WtMol)
                
        self.dpRegulator = self.PgasFinal - self.PgasOutlet
        self.dPoverPin = self.dpRegulator/self.PgasFinal

        self.CdA = max( self.CdAInit, self.CdAFinal, 1.0E-6) * self.CdASF

        self.rinsid = sqrt( self.CdA / pi )
        self.dinsid = self.rinsid * 2.0
        
        
        self.mass_lbm = 15.0 * self.dinsid**3 * (self.rho/0.28) * self.cxw 
        if self.mass_lbm < 0.1:
            self.mass_lbm = 0.1
        
        self.mass_lbm *=  self.Number

        self.SCFM = self.wdot * 60.0 / self.Dscf # standard cuft per minute

        

    
    def buildSummary(self):
        
        summ = Summary(  summName='Gas Regulator',
        componentName=self.name, mass_lbm=self.mass_lbm, type=self.type)
        
        summ.addAssumption( 'Initial:' )
        summ.addAssumption( "In: "+self.gasObjInit.getStrTPDphase() )
        summ.addAssumption( "Out:"+self.gasObjInit.dup.getStrTPDphase() )
        
        summ.addAssumption( 'Final:' )
        summ.addAssumption( "In: "+self.gasObjFinal.getStrTPDphase() )
        summ.addAssumption( "Out:"+self.gasObjFinal.dup.getStrTPDphase() )
        
        summ.addAssumption( 'fluid : ' + self.gasObjInit.symbol )
        summ.addAssumption( 'Structural Material : ' + self.matlName )
        summ.addAssumption( 'Allow Non-Standard wall thickness' )
            
        if self.ImSonic:
            summ.addAssumption( 'Final condition is SONIC' )
        else:
            summ.addAssumption( 'Final condition is SUB-SONIC' )
            
            
        if self.Number>1:
            summ.addAssumption( 'Mass is for %i Regulators total'%self.Number )
        
        # add inputs
        summ.addInput('wdot', self.wdot, 'lbm/sec', '%g')
        summ.addInput('SCFM', self.SCFM, 'SCFM', '%g')
            
        summ.addInput('TgasInit', self.TgasInit, 'degR', '%.1f')
        summ.addInput('PgasInit', self.PgasInit, 'psia', '%.1f')
        summ.addInput('TgasFinal', self.TgasFinal, 'degR', '%.1f')
        summ.addInput('PgasFinal', self.PgasFinal, 'psia', '%.1f')
        summ.addInput('PgasOutlet', self.PgasOutlet, 'psia', '%.1f')
        summ.addInput('CdASF', self.CdASF, '', '%g')
        summ.addInput('sf', self.sf, '', '%g')
        
        summ.addInput('cxw', self.cxw, '', '%g')
        summ.addInput('# Regs', self.Number, '', '%i')
        
        # add outputs

        summ.addOutput('CdAInit', self.CdAInit, 'sqin', '%.4f')
        summ.addOutput('CdAFinal', self.CdAFinal, 'sqin', '%.4f')
        summ.addOutput('CdA', self.CdA, 'sqin', '%.4f')
            
        summ.addOutput( 'dpRegulator', self.dpRegulator, 'psig', '%.2f' )
        summ.addOutput( 'dp/Pinlet', self.dPoverPin, '', '%g' )
        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.gasObjInit.D, 'lbm/cuft', '%g' )
        summ.addOutput( 'fluid visc', self.gasObjInit.Visc*1.0E-5, 'lb/ft-sec', '%g' )
        summ.addOutput( 'fluid sonicV', self.gasObjInit.sonicV, 'ft/sec', '%g' )
        if self.Number>1:
            summ.addOutput( 'wt/Regulator', self.mass_lbm/self.Number, 'lbm', '%.3f' )

        return summ


if __name__ == "__main__":  #self test
    
    h = Gas_Regulator(name="Fuel Regulator",wdot=1.0, matlName="Ti", 
        PgasInit=4000.0, PgasFinal=600.0,  PgasOutlet=400.0,
        gasSymbol='O2', Number=10)
    print h.getMassStr()
    print
    print h.getSummary()