Coverage for rocketcea\blends.py : 84%

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
#!/usr/bin/env python # -*- coding: ascii -*-
Handle propellant blends. Make new input cards for various ox and fuel blends. """
"""If all members of nameL are keys in D, then return True, otherwise False."""
'''::
#: Return the name of the blend defined by "Name". (string or list of strings) #: Might be a defined blend such as MON25 or FLOX80. #: Might be in the library such as "MMH" or "CLF5" #: Might need to create a long name from percentages Name=["N2H4","NH3"], PcentL=[90,10] #: (if new name, add card to oxCards, fuelCards or propCards) '''
raise Exception('Blend Components NOT Recognized: Name=%s, PcentL=%s'%(str(Name), str(PcentL)))
return None else: return Name return Name return Name if isFLOX_Ox_Blend( Name ): return Name
print('WARNING... Blend Name NOT Recognized "%s"'%str(Name)) return Name
""" check if name is for a blend of N2H4 and undissociated Ammonia (UA) HYD40 is in standard deck, however can make HYD30, HYD50 etc. "on-the-fly" """
""" Add new N2H4 + undissociated Ammonia (UA) Blend to the CEA_Obj.cea_deck. Use name like "HYD30" to represent hydrazine with 30% dissociated ammonia. """ except: raise Exception('N2H4 un-dissociated Ammonia Blend NOT Recognized: %s'%name)
" h,cal=12094. t(k)=298.15 rho,g/cc = 1.004 ", " ", " name = water H 2.0 O 1.0 wt%=0.5 ", " h,cal=-68308. t(k)=298.15 rho,g/cc = 0.9998 ", " ! THIS IS %g%% AMMONIA DISSOCIATION "%(100.0*x,), " omit NH3 "]
cardL[0] = " name = diss H 4 N 2 wt%%= 99.5 " cardL.pop() cardL.pop() else: raise Exception('N2H4 un-dissociated Ammonia Blend NOT Recognized: %s'%name)
# put cardL into propCards dictionary #print(cardL)
# name will be in propCards # --------------------------------------------------------------------------
""" check if name is for a blend of peroxide and water. Peroxide98 and Peroxide90 are in standard deck, however can make Peroxide95 etc. "on-the-fly" """ else:
""" Add new Peroxide Blend to the CEA_Obj.cea_deck. Use name like Peroxide95 to represent 95% Peroxide and 5% water. """
else:
# need to cover both naming conventions for the blend
# blendName will be in oxCards # --------------------------------------------------------------------------
# check for an MMH + N2H4 blend """ check if name is for a blend of MMH + N2H4 M20 is in standard deck, however can make M10, M30 etc. "on-the-fly" """
""" Add new MMH + N2H4 Blend to the CEA_Obj.cea_deck Use name like M10 to represent 10% MMH and 90% N2H4 """
else: raise Exception('MMH + N2H4 Blend NOT Recognized: %s'%fuelName)
# need to cover both naming conventions for the blend
# blendName will be in fuelCards
# --------------------------------------------------------------------------
""" check for MON oxidizer (MON1 to MON40) 48% is theoretical max MON15 and MON25 are in standard deck, however can make MON20, MON30 etc. "on-the-fly" """
""" Add new MON oxidizer Blend to the CEA_Obj.cea_deck MON15 and MON25 are in standard deck, however can make MON20, MON30 etc. "on-the-fly" """
except: raise Exception('MON Ox Blend NOT Recognized: %s'%oxName)
else: raise Exception('MON Ox Blend NOT Recognized: %s'%oxName)
# need to cover both naming conventions for the blend
# blendName will be in oxCards # --------------------------------------------------------------------------
""" check for FLOX oxidizer (e.g. FLOX70 or FLOX82.5) No FLOX blends are in standard deck, however can make FLOX70, FLOX82.5 etc. "on-the-fly" """
# add FLOX oxidizer (e.g. FLOX70 or FLOX82.5) """ Add new add FLOX oxidizer to the CEA_Obj.cea_deck FLOX70, for example, represents 70% F2 and 30% LOX """
except: raise Exception('FLOX Ox Blend NOT Recognized: %s'%oxName)
else: blendName = 'O2'
# need to cover both naming conventions for the blend
# blendName will be in oxCards
# --------------------------------------------------------------------------
"""make sure there's no spaces around equal signs."""
"""Change the values of "h,cal" and "t(k)" on propellant cards. """ else:
"""set the value of mass percentage (wt%) on propellant card.""" else:
#print( 'cNew =',cNew )
''' create ox blends such as MON25 given the oxidizer names and weight percentages. e.g. oxL=["N2O4","N2O3"], oxPcentL=[36.67,63.33] ''' if 1:#try:
#newCardL.extend( cardL )
#print( 'new cards for newName=',newName ) #for card in newCardL: # print( card ) #print()
else:#except: raise Exception('ERROR... in newOxBlend')
''' create fuel blends such as M20 given the fuel names and weight percentages. e.g. fuelL=["MMH","N2H4"], fuelPcentL=[20,80] ''' if 1:#try:
raise Exception('ERROR... can NOT specify Fuel Blend for multi propellant card= '+ name)
#newCardL.extend( cardL )
#print( 'new cards for newName=',newName ) #for card in newCardL: # print( card ) #print()
else:#except: raise Exception('ERROR... in newFuelBlend')
''' Take name as it exists in fuelCards or oxCards and change Hf and Tref to be the input values newHfCalPerMole and newTrefDegR '''
raise Exception('ERROR... can NOT specify new Hf, Tref for multi propellant card: '+ name) #return name
except:
raise Exception('ERROR... in newPropWithNewState')
''' Take name as it exists in fuelCards and change Hf and Tref to be the input values newHfCalPerMole and newTrefDegR '''
''' Take name as it exists in oxCards and change Hf and Tref to be the input values newHfCalPerMole and newTrefDegR '''
"""turn the card list into one long list of tokens"""
"""Get the float value of the desired token. (e.g. 't(k)' )""" #print( tokenL ) except: return None return None
"""Get the fuel float value of the reference temperature 't(k)'""" except: return None
"""Get the propellant float value of the reference temperature 't(k)'""" try: cardL = propCards[ name ] return getFloatTokenFromCards( cardL, 't(k)' ) except: return None
"""Get the oxidizer float value of the reference temperature 't(k)'""" except: return None
"""Get the fuel float value of the reference temperature 'h,cal'""" except: return None
"""Get the ox float value of the reference temperature 'h,cal'""" except: raise Exception('Could NOT find "h,cal" in getOxHfCalPerMole for %s'%name)
"""Get the propellant float value of the reference temperature 'h,cal'""" except: return None
""" Create a new propellant card that reflects a change in temperature of the propellant from the original reference temperature on the original card to the new input value of temperature, newTdegR.
CpAve = BTU/lbm degR """
cardD = oxCards prop_type = 'ox' elif ceaName in propCards: cardD = propCards prop_type = 'prop' else: raise Exception('Could NOT find ceaName=%s in makeCardForNewTemperature'%ceaName)
# find Hf and Tref on card #print( cardL )
# make one big line and look for Hf and Tref
raise Exception('Did NOT find Heat of Formation and/or Reference Temperature in makeCardForNewTemperature')
#print( 'Hf=',Hf,' TrefR=',TrefR )
#print( 'HrefCalPerMole=',HrefCalPerMole )
#print( 'deltaH=',deltaH,' delCALperMOLE=',delCALperMOLE )
#print( 'HfNew=',HfNew )
elif prop_type=='ox': newName = newOxWithNewState(ceaName, HfNew, newTdegR) elif prop_type=='prop': newName = newPropWithNewState(ceaName, HfNew, newTdegR) else: # should never get here raise Exception('Could NOT find prop_type of ceaName=%s in makeCardForNewTemperature'%ceaName)
'''Look for "h,cal OR "t(k)"" in name. If present, then create new modified name and create new card in cardDict if necessary
for example to tweak LH2 run might look like: "LH2 h,cal=-2155.0 t(k)=21.0" '''
# w/o any equals sign, assume that the name is unchanged
#check for extra entries #print('tightenUpEquals( name )',n) ' Should be: "LH2 h,cal=-2155.0 t(k)=21.0"' #return name
' Should be: "LH2 h,cal=-2155.0 t(k)=21.0"' #return name
# if all else fails, simply return input name return name
|