def test_renamePropIfNewHfOrTrefInName(self): """ test call to def test_renamePropIfNewHfOrTrefInName(self): """ ans = blends.renamePropIfNewHfOrTrefInName(propCards, 'N2H4') self.assertEqual(ans, 'N2H4') ans = blends.renamePropIfNewHfOrTrefInName( fuelCards, "LH2 h,cal=-2155.0 t(k)=21.0") self.assertEqual(ans, 'LH2_m2155_21') with self.assertRaises(Exception): ans = blends.renamePropIfNewHfOrTrefInName(fuelCards, "LH2 h,cal=-2155.0 ") with self.assertRaises(Exception): ans = blends.renamePropIfNewHfOrTrefInName( fuelCards, "LH2 h,cal=-x.0 t(k)=21.0")
def __init__(self, propName='', oxName='', fuelName='', useFastLookup=0, makeOutput=0): """ #: Create the base CEA wrapper object. #: Fast Lookup is being reviewed. """ self.makeOutput = makeOutput # makes "f.out" oxName = renamePropIfNewHfOrTrefInName(oxCards, oxName) fuelName = renamePropIfNewHfOrTrefInName(fuelCards, fuelName) propName = renamePropIfNewHfOrTrefInName(propCards, propName) oxName = oxName.replace('(g)', '(G)') fuelName = fuelName.replace('(g)', '(G)') propName = propName.replace('(g)', '(G)') # do NOT allow "-" or "+" as part of the name oxName = oxName.replace('-', '_') fuelName = fuelName.replace('-', '_') propName = propName.replace('-', '_') oxName = oxName.replace('+', '_') fuelName = fuelName.replace('+', '_') propName = propName.replace('+', '_') if oxName[-3:] == '(G)': oxName = 'G' + oxName[:-3] print('Ox name changed to', oxName) if fuelName[-3:] == '(G)': fuelName = 'G' + fuelName[:-3] print('Fuel name changed to', fuelName) if propName[-3:] == '(G)': propName = 'G' + propName[:-3] print('Propellant name changed to', propName) # may want to interpolate tables of CEA runs for speed self.useFastLookup = useFastLookup self.readDatafileOnce = 0 #check for propellant (mono or solid) vs. fuel and ox self.cea_deck = ["reac"] self.desc = '' self.useMR = 1 self.propName = propName if len(propName) > 0: # can be in propCards, fuelCards, or oxCards if propName in propCards: self.cea_deck.append(propCards[propName]) self.desc += ' ' + propName elif is_HYD_Ammonia_Blend(propName): #HYD40 will be caught above addHYD_AmmoniaBlend(propName, self.cea_deck) # e.g. HYD30, HYD25.5 self.desc += propName elif propName in fuelCards: tempList = fuelCards[propName] if type(tempList) == type(''): tempList = [tempList] propList = [] for p in tempList: propList.append(p.replace(' fuel ', ' name ')) self.cea_deck.append(propList) self.desc += ' ' + propName print("fuel Cards converted into prop Cards") for card in self.cea_deck: if type(card) == type(''): print(card) else: for c in card: print(c) elif propName in oxCards: tempList = oxCards[propName] if type(tempList) == type(''): tempList = [tempList] propList = [] for p in tempList: propList.append(p.replace(' oxid ', ' name ')) self.cea_deck.append(propList) self.desc += ' ' + propName print("ox Cards converted into prop Cards") for card in self.cea_deck: if type(card) == type(''): print(card) else: for c in card: print(c) else: print('ERROR... bad propellant name (%s) in cea_obj.py' % propName) self.useMR = 0 #check for fuel self.fuelName = fuelName if len(fuelName) > 0: if fuelName in fuelCards: self.cea_deck.append(fuelCards[fuelName]) self.desc += fuelName elif isAnMMH_N2H4_Blend(fuelName): #M20 will be caught above addMMH_N2H4_Blend(fuelName, self.cea_deck) # e.g. M10, M15, M23.789 self.desc += fuelName else: print('ERROR... bad fuel name (%s) in cea_obj.py' % fuelName) raise Exception('ERROR... bad fuel name (%s) in cea_obj.py' % fuelName) #check for oxidizer self.oxName = oxName if len(oxName) > 0: if oxName in oxCards: self.cea_deck.append(oxCards[oxName]) self.desc = oxName + ' / ' + self.desc elif isAPeroxide_Blend(oxName): addPeroxideBlend(oxName, self.cea_deck) self.desc = oxName + ' / ' + self.desc elif isMON_Ox_Blend(oxName): addMON_Blend(oxName, self.cea_deck) self.desc = oxName + ' / ' + self.desc elif isFLOX_Ox_Blend(oxName): addFLOX_Blend(oxName, self.cea_deck) self.desc = oxName + ' / ' + self.desc else: print('ERROR... bad oxidizer name (%s) in cea_obj.py' % oxName) raise Exception( 'ERROR... bad oxidizer name (%s) in cea_obj.py' % oxName) #thisPath = py_cea.__file__ #print('py_cea.__file__ =' + py_cea.__file__) #print('here =' + here) #dataPath = os.path.dirname( thisPath ) #sp = dataPath.split('\\') #dataPath = '/'.join( sp ) + '/ ' # be sure to leave extra space self.pathPrefix = here + os.sep + ' ' # be sure to leave extra space # dataPath #self.pathPrefix = self.pathPrefix.replace('\\','/') #print( "self.pathPrefix",self.pathPrefix ) # make a cache object for this propellant combo if it does not already exist try: cacheObj = _CacheObjDict[self.desc] except: _CacheObjDict[self.desc] = CEA_Cache(maxCache=10000, propName=self.desc) #print( self.cea_deck ) if self.useFastLookup: if self.useMR: self.fastModuleName = "cea_fit_" + self.oxName.replace( '-', '_') + '_' + self.fuelName.replace('-', '_') else: self.fastModuleName = "cea_fit_" + self.propName.replace( '-', '_') fp = None try: pathList = [ os.path.dirname(os.path.abspath(sys.argv[0])[:]), self.pathPrefix[:-1] ] #print( 'pathList',pathList ) fp, pathname, description = imp.find_module( self.fastModuleName, pathList) self.fastModule = imp.load_module(self.fastModuleName, fp, pathname, description) except: # Since we may exit via an exception, close fp explicitly. self.useFastLookup = 0 print("WARNING... Fast Module", self.fastModuleName, "failed to load") print( " Will call CEA code instead (slower but more accurate)") print(traceback.print_exc()) if fp: fp.close()