ColdGasACS.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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# Applied Python PRISM
# (PRISM) PaRametrIc System Model
#
# Written by Charlie Taylor <cet@appliedpython.com> 
# Feb 4, 2008

from prism.props.refprop7.n_dll_fluid import n_fluid
from prism.isp import Nozzle_Eff
from math import *
from prism.press.blowdownTfinal import Bottle
from prism.isp import isp
from prism.MassItem import MassItem
from prism.Summary import Summary


#C THIS ROUTINE CALCULATES COLD GAS ACS Isp and Total Impulse
#C
#C Assume that the gas is regulated to some Pc value
#C

class ColdGasACS( MassItem ):

    def __init__(self, name="Cold Gas ACS", gasSymbol='N2',  mass_lbm=0.0, 
        MEOP=5000., Pamb=0.0, AreaRatio=8., ThrustAmb=1.0,
        Vbottle=1000.0,PcRegulated=350.0, dPregFinal=150.0,
        TminR=500.0,TmaxR=550.0, fracIsentropic=None,
        gammaPolyMin=1.0, ItotGoal=None,
        tAction=100., isBell=0, pcentBell=80.0, halfAngDeg=15.0, etaNozInp=None,
        hcBottleInp=None):
        
        MassItem.__init__(self, name, type="pressurant")
        
        self.Vbottle=Vbottle
        self.ItotGoal = ItotGoal  # if input, then set Vbottle from total impulse desired
        self.ThrustAmb = ThrustAmb
        
        self.dPregFinal=dPregFinal
        self.MEOP = MEOP
        self.Pamb = Pamb
        self.AreaRatio = AreaRatio
        self.PcRegulated=PcRegulated
        
        self.TminR=TminR
        self.TmaxR=TmaxR
        self.fracIsentropic=fracIsentropic
        self.gammaPolyMin=gammaPolyMin
        self.symbol = gasSymbol

        self.gasObj = n_fluid(gasSymbol,T=TmaxR,P=MEOP, child=1)
        
        self.gammaIsen=self.gasObj.gamma()

        # initialize Tfinal bottle calc
        self.bottle = None
        self.tAction = tAction
        
        self.isBell = isBell
        self.pcentBell = pcentBell
        self.halfAngDeg = halfAngDeg
        self.etaNozInp = etaNozInp
        self.hcBottleInp = hcBottleInp
                
        self.reCalc()

        
    def buildSummary(self):
        
        summ = Summary(  summName='Cold Gas %s(%s) ACS'%(self.gasObj.name,self.symbol) ,
        componentName=self.name, mass_lbm=self.mass_lbm, type=self.type)
        
        if self.fracIsentropic == None:
            summ.addAssumption( 'Integrate Blow-Down Temperatures')
        elif self.fracIsentropic >= 1.0:
            summ.addAssumption( 'Isentropic Blow-Down')
        elif self.fracIsentropic <= 0.0:
            summ.addAssumption( 'Iso-Thermal Blow-Down')
        else:
            summ.addAssumption( '%g%% Isentropic from Isothermal Blow-Down'%(100.0*self.fracIsentropic,))

        if self.isBell:
            summ.addAssumption( 'Bell Nozzle with Percent Bell = %g'%self.pcentBell)
        else:
            summ.addAssumption( 'Conical Nozzle with Half Angle = %g deg'%self.halfAngDeg )

        # add inputs
        if self.ItotGoal==None:
            summ.addInput( 'Vbottle', self.Vbottle, 'cuin', '%g' )
        else:
            summ.addInput( 'ItotGoal', self.ItotGoal, 'lbf-sec', '%g' )
        summ.addInput( 'dPregFinal', self.dPregFinal, 'psid', '%.3f' )
        summ.addInput( 'MEOP', self.MEOP, 'psia', '%g' )
        summ.addInput( 'PcRegulated', self.PcRegulated, 'psia', '%g' )
        summ.addInput( 'ThrustAmb', self.ThrustAmb, 'lbf', '%.2f' )
        
        summ.addInput( 'Pamb', self.Pamb, 'psia', '%g' )
        summ.addInput( 'AreaRatio', self.AreaRatio, '', '%g' )
        
        summ.addInput( 'TminR', self.TminR, 'degR', '%.1f' )
        summ.addInput( 'TmaxR', self.TmaxR, 'degR', '%.1f' )
        
        if type(self.fracIsentropic)==type(1.1):
            summ.addInput( 'fracIsentropic', self.fracIsentropic, '', '%g' )
        summ.addInput( 'gammaPolyMin', self.gammaPolyMin, '', '%g' )
        
        
        # add outputs
        if self.ItotGoal!=None:
            summ.addOutput( 'Vbottle', self.Vbottle, 'cuin', '%g' )
        summ.addOutput( 'PinitMin', self.PinitMin, 'psia', '%g' )
        summ.addOutput( 'Pfinal', self.Pfinal, 'psia', '%g' )
        summ.addOutput( 'WtGasLoaded', self.WtGasLoaded, 'lbm', '%g' )
        summ.addOutput( 'WtGasExpelled', self.WtGasExpelled, 'lbm', '%g' )
        summ.addOutput( 'densInit', self.densInit, 'lbm/cuft', '%g' )
        summ.addOutput( 'densFinal', self.densFinal, 'lbm/cuft', '%g' )
        summ.addOutput( 'WtMol',self.gasObj.WtMol,'lbm/lbmole','%.3f')
        summ.addOutput( 'compressInit', self.compressInit, '(aka Z)', '%g' )
        
        summ.addOutput( 'gammaIsen', self.gammaIsen, '', '%g' )
        summ.addOutput( 'gammaPoly', self.gammaPoly, '', '%g' )
        
        if self.fracIsentropicCalc:
            summ.addOutput( 'fracIsentropic', self.fracIsentropicCalc, '', '%g' )
        

        summ.addOutput( 'TfinalIsen', self.TfinalIsen, 'degR', '%.1f' )
        summ.addOutput( 'TfinalGas', self.Tfinal, 'degR', '%.1f' )
        
        summ.addOutput( 'TregInit', self.TregInit, 'degR', '%.1f' )
        summ.addOutput( 'TregFinal', self.TregFinal, 'degR', '%.1f' )
        summ.addOutput( 'TregAve', self.TregAve, 'degR', '%.1f' )
        
        summ.addOutput( 'Cstar(@TregAve)', self.Cstar, 'ft/sec', '%.1f' )
        summ.addOutput( 'At', self.At, 'sqin', '%g' )
        summ.addOutput( 'wdot', self.wdot, 'lbm/sec', '%g' )
        
        
        summ.addOutput( 'etaNoz', self.etaNoz, '', '%g' )
        summ.addOutput( 'IspAmb(@TregAve)', self.IspAmb, 'sec', '%.1f' )
        summ.addOutput( 'ItotVac', self.ItotVac, 'lbf-sec', '%g' )
        
        summ.addOutput( '', '', '', '%s' )
        self.gasObj.setTD(T=self.TminR,D=self.rhoLoaded*1728.0)
        #summ.addOutput( 'Initial', self.gasObj.getStrTPD(), '', '%s' )
        summ.addOutput( 'Initial', self.gasObj.Qdescription(), '', '%s' )
        self.gasObj.setTD(T=self.Tfinal,D=self.rhoFinal*1728.0)
        #summ.addOutput( 'Final', self.gasObj.getStrTPD(), '', '%s' )
        summ.addOutput( 'Final', self.gasObj.Qdescription(), '', '%s' )
        

        return summ

    def reCalc(self):

        self.gasObj.setTP(T=self.TmaxR,P=self.MEOP)
        self.rhoLoaded = self.gasObj.rho
        self.gasObj.setTD(T=self.TminR,D=self.rhoLoaded*1728.0)

        self.PinitMin=  self.gasObj.P
        self.Pfinal = self.dPregFinal + self.PcRegulated
        
        self.gammaIsen=self.gasObj.gamma()
        
        self.compressInit = self.gasObj.compressibility()
        
        
        #C  CALCULATE POLYTROPIC GAMMA
        WtMolGas = self.gasObj.WtMol
        pratio = self.Pfinal / self.PinitMin

        self.TfinalIsen = self.TminR*(pratio)**(1.-1./self.gammaIsen)

        if self.etaNozInp==None:
            if self.isBell:
                isConical=0
            else:
                isConical=1
                
            self.etaBL,self.etaDiv,self.etaKin, etaCf = \
                Nozzle_Eff.calcNozzleEfficiency(Pc=self.PcRegulated, Fvac=self.ThrustAmb, eps=self.AreaRatio, At=None,
                epsAtt=self.AreaRatio, isConical=isConical, pcentBell=self.pcentBell, halfAngleDeg=self.halfAngDeg,
                iprop='coldgas', mr=1.0, etaKinInp=1.0,
                adjBL=1.0, adjKin=1.0, adjDiv=1.0, isRegenCham=0, isRegenNoz=0 )
            
            #print 'etaBL,etaDiv,etaKin',self.etaBL,self.etaDiv,self.etaKin
            
            self.etaNoz = etaCf
        else:
            self.etaNoz = self.etaNozInp


        if self.fracIsentropic==None:
            if self.ItotGoal==None:
                self.bottle = Bottle( name="Cold Gas Bottle", gasSymbol=self.symbol,  tAction=self.tAction,
                    Pinit=self.PinitMin, Vbottle=self.Vbottle, Pfinal=self.Pfinal, Tinit=self.TminR, adiabatic=0,
                    AccGees=1.0, ellBottle=1.7, Nbottle=1, 
                    MEOP=self.MEOP, LcylOvDBottle=1.0, PVoW_Bottle=500000., Cp_effBottle=0.15,
                    TbottleMatlConst=None, QexternalIntoBottle=0.0, PregOut=self.PcRegulated,
                    hcBottleInp=self.hcBottleInp)
            else:
                self.gasObj.setTP(T=self.TminR, P=self.Pfinal)
                gam = self.gasObj.gamma()
                
                IspEst = isp.calcidealis(gam,self.TminR,WtMolGas,self.AreaRatio,self.PcRegulated,self.Pamb)
                
                TfEst = self.TfinalIsen
                
                self.gasObj.setTP(T=TfEst, P=self.Pfinal)
                rhoFinalEst = self.gasObj.rho
                WtGasExpelledEst = self.ItotGoal / IspEst
                
                VbottleEst = WtGasExpelledEst / (self.rhoLoaded-rhoFinalEst)
                
                self.bottle = Bottle( name="Cold Gas Bottle", gasSymbol=self.symbol,  tAction=self.tAction,
                    Pinit=self.PinitMin, Vbottle=VbottleEst, Pfinal=self.Pfinal, Tinit=self.TminR, adiabatic=0,
                    AccGees=1.0, ellBottle=1.7, Nbottle=1,
                    MEOP=self.MEOP, LcylOvDBottle=1.0, PVoW_Bottle=500000., Cp_effBottle=0.15,
                    TbottleMatlConst=None, QexternalIntoBottle=0.0, PregOut=self.PcRegulated,
                    hcBottleInp=self.hcBottleInp)
                
            gammaPoly = self.bottle.gammaPoly
            
            self.fracIsentropicCalc = (gammaPoly-self.gammaPolyMin) / (self.gammaIsen - self.gammaPolyMin)
        else:
            gammaPoly = self.gammaPolyMin + self.fracIsentropic * (self.gammaIsen - self.gammaPolyMin)
            self.fracIsentropicCalc = None
        
        #C  FINAL PRESSURE
        PF = self.Pfinal
        #C  ASSUME MINIMUM TEMPERATURE FOR INITIAL PRESSURE CONDITION
      
        #c... Get starting pressure assuming minimum temperature
        

        gammaExp=1.-1./gammaPoly
        if gammaExp > 10.0:gammaExp=10.0
        if gammaExp < -10.0:gammaExp=-10.0

        self.Tfinal=self.TminR*(pratio)**gammaExp
        
        self.gasObj.setTP(T=self.Tfinal,P=self.Pfinal)
        self.rhoFinal = self.gasObj.rho
        
        # make sure that final density is less than initial density
        if self.rhoFinal >= self.rhoLoaded:
            print 'WARNING in ColdGasACS, final density is >= initial density'
            print '  Probably a phase change issue (see fluid properties in next line)'
            print self.gasObj.getStrTPDphase()
            self.rhoFinal = 0.999 * self.rhoLoaded
            self.gasObj.setPD(P=self.Pfinal,D=self.rhoFinal*1728.0)
            self.Tfinal=self.gasObj.T
        
        
        self.densInit = 1728.0 * self.rhoLoaded
        self.densFinal = 1728.0 * self.rhoFinal
        self.gammaPoly = gammaPoly
        
        # estimate regulator outlet temperature
        self.gasObj.dup.setTP(T=self.TminR,P=self.PinitMin)
        self.gasObj.dup.constH_newP( self.PcRegulated )
        # ignore heat transfer, just use Joule Thomson effect
        self.TregInit = self.gasObj.dup.T

        self.gasObj.dup.setTP( T=self.Tfinal, P=self.Pfinal )
        self.gasObj.dup.constH_newP( self.PcRegulated )
        self.TregFinal = self.gasObj.dup.T
        
        # now use average Treg outlet to calc Isp
        self.TregAve = (self.TregInit + self.TregFinal) / 2.0
        
        self.gasObj.setTP(T=self.TregAve, P=self.Pfinal)
        gam = self.gasObj.gamma()
        
        self.IspAmb = self.etaNoz * isp.calcidealis(gam,self.TregAve,WtMolGas,self.AreaRatio,self.PcRegulated,self.Pamb)
        self.Cstar = isp.calccstar(gam,self.TregAve,WtMolGas)
        
        self.wdot = self.ThrustAmb / self.IspAmb
        self.At = self.wdot * self.Cstar / 32.174 / self.PcRegulated
        
        if self.ItotGoal==None:
            self.WtGasExpelled =  self.Vbottle * (self.rhoLoaded-self.rhoFinal)
        else:
            self.WtGasExpelled = self.ItotGoal / self.IspAmb
            self.Vbottle = self.WtGasExpelled / (self.rhoLoaded-self.rhoFinal)
            
        self.WtGasLoaded = self.Vbottle * self.rhoLoaded
        self.ItotVac = self.IspAmb * self.WtGasExpelled
        
        self.mass_lbm = self.WtGasLoaded
    

if __name__ == "__main__":  #self test

    
    h = ColdGasACS(name="Cold Gas ACS",gasSymbol='HE', AreaRatio=10.,
        MEOP=5000.,
        Vbottle=862.0, PcRegulated=220.0, dPregFinal=120.,fracIsentropic=None,
        TminR=505.0,TmaxR=550.0, ItotGoal=190.036)
        
    print h.getMassStr()
    print
    print h.getSummary()
    
    if h.bottle:
        h.bottle.makeExcelPlots( title='')

    if 0:
        h = ColdGasACS(name="Nitrogen ACS",gasSymbol='HE', 
            Vbottle=6766.7*1.03*252./238., PcRegulated=109.0, dPregFinal=100.0,
            TminR=510.0,TmaxR=550.0)
            
        print h.getMassStr()
        print
        print h.getSummary()