# Coverage for rocketcea\Isp.py : 93%

## 96 statements 89 run 7 missing 0 excluded

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

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 | from math import sqrt from rocketcea.Goal import Goal def CalcPCoPE(gam,eps): Pc = 100.0 #! just for reference pick a value for Pc Pthrt = Pc * (2./(gam+1.))**(gam/(gam-1.)) PeMax = Pthrt PeMin = 1.0E-20 g1=((gam+1.0)/2.0) ** (1.0/(gam-1.0)) g2=(gam+1.0)/(gam-1.0) g3=(1.0/gam) g4=((gam-1.0)/gam) for _I in range(54): # in FORTRAN use 25 for single precision Pe = (PeMax + PeMin) / 2.0 PCoPE = Pc / Pe PEoPC = Pe / Pc #print( 'trying Pe=',Pe) p1=PEoPC**g3 p2=1.0-PEoPC**g4 epsCalc=1.0/(g1*p1*(g2*p2)**0.5) if epsCalc <= eps: PeMax = Pe else: PeMin = Pe Pe = (PeMax + PeMin) / 2.0 PCoPE = Pc / Pe if abs((epsCalc-eps)/eps) > 0.0001 : print('================= WARNING ==========================') print( ' Bad Solution in CalcPCoPE') print( ' (desired Area Ratio=',eps,' actual=',epsCalc,')') print( ' input gam=',gam,' eps=',eps) print('================= WARNING ==========================') return PCoPE def CalcEps(gam,PCoPE): #PEoPC=1.0/PCoPE if(PCoPE > 1.0): g1=((gam+1.0)/2.0) ** (1.0/(gam-1.0)) p1=PCoPE**(-1.0/gam) g2=(gam+1.0)/(gam-1.0) p2=1.0-PCoPE**(-(gam-1.0)/gam) eps=1.0/(g1*p1*(g2*p2)**0.5) else: eps=1.0 return eps def solvePCoPE(gam, eps): def getEpsForPEoPC( _PEoPC ): return CalcEps(gam,1./_PEoPC)-eps PToPC = (2./(gam+1.))**(gam/(gam-1.)) G = Goal(goalVal=0.0, minX=1.0E-12, maxX=PToPC, funcOfX=getEpsForPEoPC, tolerance=1.0E-12, maxLoops=40, failValue=None) PEoPC, ierror = G() return 1./PEoPC def CalcCFvac(GamInp,PCoPE): #c calculate separation pressure for nozzle if (GamInp < 1.0001): gam = 1.0001 else: gam = GamInp eps = CalcEps(gam,PCoPE) g1=2*gam**2/(gam-1.0) g2=(2.0/(gam+1.0))**((gam+1.0)/(gam-1.0)) g3=1.0-(1.0/PCoPE)**((gam-1.0)/gam) CFvac=0.0 if(g3 > 0.0):CFvac=sqrt(g1*g2*g3) + eps/PCoPE if(g3 <= 0.0 or CFvac<0.001):CFvac=0.001 return CFvac def CalcCstar(Gam,Temp,WtMol): bot=Gam*((2.0/(Gam+1.0))**((Gam+1.0)/(Gam-1.0)))**0.5 top= ( Gam * 1545.0 * 32.174 * Temp / WtMol ) ** 0.5 cstar=top/bot return cstar def CalcIdealIsVac(Gam,Temp,WtMol,eps): cstar = CalcCstar(Gam,Temp,WtMol) pcope = CalcPCoPE(Gam,eps) Cfvac = CalcCFvac(Gam,pcope) IspVac=cstar * Cfvac / 32.174 return IspVac if __name__ == "__main__": def testme(): gam=1.25 eps=2.0 Temp=5000.0 WtMol=20.0 Pc=250.0 Pamb=0.0 print( 'for gam=%g and eps=%g'%(gam,eps)) print( ) pcope = solvePCoPE(gam, eps) print( 'solvePCoPE(%g,%g)='%(gam,eps),pcope) print( 'CalcEps(gam,PCoPE)=',CalcEps(gam,pcope)) print( ) pcope = CalcPCoPE(gam,eps) print( 'CalcPCoPE(%g,%g)='%(gam,eps),pcope,' Pe/Pc=',1./pcope) print( 'CalcEps(gam,PCoPE)=',CalcEps(gam,pcope)) print( 'CalcCFvac(gam,PCoPE)',CalcCFvac(gam,pcope)) print( 'for T=%g degR and WtMol=%g lbm/lbmole'%(Temp, WtMol)) print( 'CalcCstar(Gam,Temp,WtMol)',CalcCstar(gam,Temp,WtMol)) print( 'for Pc=%g and Pamb=%g'%(Pc,Pamb)) print( 'CalcIdealIsVac(Gam,Temp,WtMol,eps)',CalcIdealIsVac(gam,Temp,WtMol,eps)) print( ) grayLambda = 0.985 #cos(10.*pi/180.) print( 'CalcCFvac(gam,PCoPE)',CalcCFvac(gam,pcope),' in gray book=',grayLambda*CalcCFvac(gam,pcope)) print( 'CalcCstar(Gam,Temp,WtMol)',CalcCstar(gam,Temp,WtMol)) testme()