Hide keyboard shortcuts

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

 

class MRrange: 

 

def __init__(self, ispObj, Pc=500., eps=20., 

edge_frac=0.97): 

 

self.Pc = Pc 

self.eps = eps 

self.edge_frac = edge_frac 

self.ispObj = ispObj 

self.MRstoic = self.ispObj.getMRforER( ERr=1.0 ) 

self.MRstep = max( self.MRstoic/30.0, 0.01 ) 

#print('MRstoic=',self.MRstoic, ' MRstep =',self.MRstep) 

 

IspVac = self.ispObj.get_Isp( Pc=Pc, MR=self.MRstoic, eps=eps) 

self.dataL = [(self.MRstoic, IspVac)] 

 

self.peakIsp = IspVac 

self.peakMR = self.MRstoic 

 

self.mr_min = self.MRstoic - self.MRstep 

self.mr_max = self.MRstoic + self.MRstep 

 

self.IspAtMRmin = self.add_mr( self.mr_min ) 

self.IspAtMRmax = self.add_mr( self.mr_max ) 

 

for _ in range(1000): 

mr = self.mr_min - self.MRstep 

if mr <= 0.0: 

break 

IspVac = self.add_mr( mr ) 

if IspVac / self.peakIsp < self.edge_frac: 

break 

#print('Min MR=',self.mr_min,' IspAtMRmin=', self.IspAtMRmin) 

 

# find MR max 

for _ in range(1000): 

mr = self.mr_max + self.MRstep 

IspVac = self.add_mr( mr ) 

 

if IspVac / self.peakIsp < self.edge_frac: 

break 

#print('Max MR=',self.mr_max,' IspAtMRmax=', self.IspAtMRmax) 

#print('Peak MR=',self.peakMR,' peakIsp=', self.peakIsp) 

 

self.dataL.sort() # sort in MR order 

 

# prune list to single overhang values on each end. 

new_dataL = [] 

IspCutoff = self.edge_frac * self.peakIsp 

def is_keeper( i ): 

if i==0: 

mrp1, Ispp1 = self.dataL[i+1] 

if Ispp1 >= IspCutoff: 

return True 

 

elif i==len( self.dataL ) - 1: 

mrm1, Ispm1 = self.dataL[i-1] 

if Ispm1 >= IspCutoff: 

return True 

else: 

mr, Isp = self.dataL[i] 

if Isp >= IspCutoff: 

return True 

mrp1, Ispp1 = self.dataL[i+1] 

if Ispp1 >= IspCutoff: 

return True 

mrm1, Ispm1 = self.dataL[i-1] 

if Ispm1 >= IspCutoff: 

return True 

return False 

 

for i,(mr, IspVac) in enumerate(self.dataL): 

if is_keeper( i ): 

new_dataL.append( (mr, IspVac) ) 

 

# approximate MR of both ends with linear interpolation 

mr1, Is1 = new_dataL[0] 

mr2, Is2 = new_dataL[1] 

mr = mr1 + (mr2-mr1)*(IspCutoff-Is1)/(Is2-Is1) 

new_dataL[0] = (mr, self.ispObj.get_Isp( Pc=self.Pc, MR=mr, eps=self.eps)) 

 

mr1, Is1 = new_dataL[-2] 

mr2, Is2 = new_dataL[-1] 

mr = mr1 + (mr2-mr1)*(IspCutoff-Is1)/(Is2-Is1) 

new_dataL[-1] = (mr, self.ispObj.get_Isp( Pc=self.Pc, MR=mr, eps=self.eps)) 

 

 

# set dataL to just the keepers 

self.dataL = new_dataL 

 

def get_mr_range(self): 

return self.dataL[0][0], self.dataL[-1][0] 

 

def get_mr_list(self): 

return [mr for mr,_ in self.dataL] 

 

def add_mr(self, mr): 

 

IspVac = self.ispObj.get_Isp( Pc=self.Pc, MR=mr, eps=self.eps) 

if mr<self.mr_min: 

self.mr_min = mr 

self.IspAtMRmin = IspVac 

if mr>self.mr_max: 

self.mr_max = mr 

self.IspAtMRmax = IspVac 

 

if IspVac > self.peakIsp: 

self.peakIsp = IspVac 

self.peakMR = mr 

 

self.dataL.append( (mr, IspVac) ) 

 

return IspVac 

 

if __name__ == "__main__": 

from rocketcea.cea_obj import CEA_Obj 

 

#ispObj = ispObj = CEA_Obj( oxName='LOX', fuelName='LH2') 

ispObj = ispObj = CEA_Obj( oxName='N2O4', fuelName='MMH') 

#ispObj = ispObj = CEA_Obj( oxName='N2O4', fuelName='N2H4') 

 

mrr = MRrange(ispObj, Pc=500., eps=20.) 

 

for mr,IspVac in mrr.dataL: 

print( 'MR=%6.2f Isp=%8.3f'%(mr, IspVac), '%9.5f'%(IspVac/mrr.peakIsp,) ) 

 

 

print('MR List:', mrr.get_mr_list())