def test_ionmix_read_write(): # Verify the writeIonmixFile function abar = 1.0 zmax = 1.0 fh = opp.OpacIonmix(reference_file, abar / opp.NA, twot=True, man=True, verbose=False) fracs = (1.0, ) tmp_file = os.path.join(BASE_DIR, 'imx_sample_tmp.cn4') try: pars = {key: getattr(fh, key) for key in fields} opp.writeIonmixFile(tmp_file, (zmax, ), fracs, **pars) # Open generated file to check there are no errors. fh_new = opp.OpacIonmix(tmp_file, abar / opp.NA, twot=True, man=True, verbose=False) for key in fields: yield assert_allclose, getattr(fh, key), getattr(fh_new, key) except: raise finally: if os.path.exists(tmp_file): os.remove(tmp_file)
def eosDict_toIonmix(self): # These are the naming conventions translated to ionmix arguments. imx_conv = {'Znum':'zvals', 'Xnum':'fracs', 'idens':'numDens', 'temp':'temps', 'Zf_DT':'zbar', 'Pi_DT':'pion', 'Pec_DT':'pele', 'Ui_DT':'eion', 'Uec_DT':'eele', 'groups':'opac_bounds', 'opr_mg':'rosseland', 'opp_mg':'planck_absorb', 'emp_mg':'planck_emiss'} # Initialize ionmix argument dictionary. imx_dict = {} # Translating the keys over. for key in imx_conv.keys(): if key in self.eos_dict.keys(): imx_dict[imx_conv[key]] = self.eos_dict[key] # Set ngroups if opacity bounds are present. if 'opac_bounds' in imx_dict: imx_dict['ngroups'] = len(self.eos_dict['groups']) - 1 # For verbose flag. if self.args.verbose: verb_conv = {'zvals':'Atomic numbers', 'fracs':'Element fractions', 'numDens':'Ion number densities', 'temps':'Temperatures', 'zbar':'Average ionizations', 'pion':'Ion pressure', 'pele':'Electron pressure', 'eion':'Ion internal energy', 'eele':'Electron internal energy', 'opac_bounds':'Opacity bounds', 'rosseland':'Rosseland mean opacity', 'planck_absorb':'Absorption Planck mean opacity', 'planck_emiss':'Emission Planck mean opacity', 'ngroups':'Number of opacity groups'} verb_str = 'Wrote the following data to IONMIX file:\n' i = 0 for key in imx_dict.keys(): i = i + 1 if i == len(imx_dict.keys()): verb_str = verb_str + '{}. {}'.format(i, verb_conv[key]) else: verb_str = verb_str + '{}. {} \n'.format(i, verb_conv[key]) print(verb_str) # Write the ionmix file based on what data is stored in imx_dict. opp.writeIonmixFile(self.args.outname + '.cn4', **imx_dict)
def test_writeIonmixFile(self): try: pars = {key: getattr(self.eos_data, key) for key in self.fields} opp.writeIonmixFile(self.tmp_file, (self.zmax,), self.fracs, **pars) # Open generated file to check there are no errors. self.eos_data_new = opp.OpacIonmix(self.tmp_file, self.abar/opp.NA, twot=True, man=True, verbose=False) for key in self.fields: np.testing.assert_array_equal(getattr(self.eos_data, key), getattr(self.eos_data_new, key)) except: raise finally: if os.path.exists(self.tmp_file): os.remove(self.tmp_file)
def test_ionmix_read_write(): # Verify the writeIonmixFile function abar = 1.0 zmax = 1.0 fh = opp.OpacIonmix(reference_file, abar/opp.NA, twot=True, man=True, verbose=False) fracs = (1.0,) tmp_file = os.path.join(BASE_DIR, 'imx_sample_tmp.cn4') try: pars = {key: getattr(fh, key) for key in fields} opp.writeIonmixFile(tmp_file, (zmax,), fracs, **pars) # Open generated file to check there are no errors. fh_new = opp.OpacIonmix(tmp_file, abar/opp.NA, twot=True, man=True, verbose=False) for key in fields: yield assert_allclose, getattr(fh, key), getattr(fh_new, key) except: raise finally: if os.path.exists(tmp_file): os.remove(tmp_file)
ax.grid(which='major') # <codecell> plot_eos_field(eos_data, 'ioncc', 'pres') # <codecell> plot_eos_field(eos_data, 'ioncc', 'pres', grad='rho') # <codecell> fracs = (1.0,) filename = 'al-ses-3717.cn4' numDens = opp.NA * eos_data['ele_dens'] / eos_data["abar"] opp.writeIonmixFile(filename, (eos_data['zmax'],), fracs, numDens=numDens, temps=eos_data['ele_temps'], eion=np.fmax(eos_data["ioncc_eint"],1e-10), eele=eos_data["ele_eint"], pion=eos_data["ioncc_pres"], pele=eos_data["ele_pres"], zbar=np.fmax(zbar2,1e-3)) ionmix = opp.OpacIonmix(filename, eos_data["abar"]/opp.NA, twot=True, man=True, verbose=False) # <codecell>
# <codecell> plot_eos_field(eos_data, 'ioncc', 'pres') # <codecell> plot_eos_field(eos_data, 'ioncc', 'pres', grad='rho') # <codecell> fracs = (1.0, ) filename = 'al-ses-3717.cn4' numDens = opp.NA * eos_data['ele_dens'] / eos_data["abar"] opp.writeIonmixFile(filename, (eos_data['zmax'], ), fracs, numDens=numDens, temps=eos_data['ele_temps'], eion=np.fmax(eos_data["ioncc_eint"], 1e-10), eele=eos_data["ele_eint"], pion=eos_data["ioncc_pres"], pele=eos_data["ele_pres"], zbar=np.fmax(zbar2, 1e-3)) ionmix = opp.OpacIonmix(filename, eos_data["abar"] / opp.NA, twot=True, man=True, verbose=False) # <codecell>
cond_data_i["zbar_temps"], denss[jd], temps[jt], bctmin=opp.BC_EXTRAP_ZERO) opp.plot_zbar(denss, temps, zbar, cond_data_i['zmax'], plt.figure()) # <codecell> # write ionmix file with fracs = (1.0,) filename = 'al-ses.cn4' numDens = opp.NA * eos_data['ele_dens'] / eos_data["abar"] opp.writeIonmixFile(filename, (eos_data['zmax'],), fracs, numDens=numDens, temps=eos_data['ele_temps'], eion=eos_data["ioncc_eint"], eele=eos_data["ele_eint"], pion=eos_data["ioncc_pres"], pele=eos_data["ele_pres"]) opp.writeIonmixFile(filename, (eos_data['zmax'],), fracs, numDens=numDens, temps=eos_data['ele_temps']) ionmix = opp.OpacIonmix(filename, eos_data["abar"]/opp.NA, twot=True, man=True, verbose=False) # <codecell> # <codecell>
print 'Pressure [Bar]: {0:.3e} {1:.3e}'.format( *[eos_o[el+'_pres'][rho0_idx, temps0_idx]*1e-6 for el in ['ele', 'ioncc']]) print 'Eint [erg] : {0:.3e} {1:.3e}'.format( *[eos_o[el+'_eint'][rho0_idx, temps0_idx] for el in ['ele', 'ioncc']]) print 'Zbar : {0:.3f}'.format(zbar_tf[rho0_idx, temps0_idx]) print 'A: {0} / {1} Z: {2} / {3}'.format(mat_dict.A, eos_o['abar'], mat_dict.Z, eos_w['zmax']) print u'dens[0]: {0} g.cm⁻³, temps[0]: {1} eV'.format(eos_o['ele_dens'][0], eos_o['ele_temps'][0]) print eos_o['ioncc_eint'][0,0] # writing everything to files numDens = opp.NA * eos_o['ele_dens'] / eos_o['abar'] #print mat_dict.snop.z, mat_dict.snop.fraction opp.writeIonmixFile(filename, mat_dict.snop.z, mat_dict.snop.fraction, numDens=numDens, temps=eos_o['ele_temps'], eion=eos_o["ioncc_eint"], eele=eos_o["ele_eint"], pion=eos_o["ioncc_pres"], pele=eos_o["ele_pres"], zbar=zbar_tf) # rereading the output ionmix = opp.OpacIonmix(filename, eos_o['abar']/opp.NA, twot=True, man=True, verbose=False) test_dict = {'temps': 'ele_temps', 'dens': 'ele_dens', 'pele': 'ele_pres', 'pion': 'ioncc_pres', 'eele': 'ele_eint', 'eion': 'ioncc_eint'} print 'Checking: ', for attr, key in test_dict.iteritems(): print attr,'...', np.testing.assert_allclose(getattr(ionmix, attr), eos_o[key], atol=1e-5, rtol=1e-5)
def main(): parser = argparse.ArgumentParser(description= """ This script is used to automate EoS/opacity tables generation for FLASH. """) parser.add_argument('-d','--dbdir', action="store", type=str, default = os.path.abspath(os.curdir), help='Path to the database. Default: current directory.') parser.add_argument('-t','--dbtype', action="store", type=str, default='sesame', help='Database type. Default: sesame.') parser.add_argument('-n','--tablenum', action="store", type=int, help='Table id', required=True) parser.add_argument('-o','--out', action="store", type=str, help='Ouput filename', default=None) args = parser.parse_args() if args.out is None: args.out = '{0}-eos-{1}'.format(args.dbtype, args.tablenum) else: args.out = os.path.splitext(args.out)[0] if args.dbtype == 'sesame': print "Parsing sesame input files." eos_sesame = opp.OpgSesame(os.path.join(args.dbdir, "xsesame_ascii"), opp.OpgSesame.SINGLE, verbose=False) cond_sesame = opp.OpgSesame(os.path.join(args.dbdir, "sescu_ascii"), opp.OpgSesame.DOUBLE, verbose=False) eos_data_i = eos_sesame.data[args.tablenum] cond_keys = sorted([key for key, val in cond_sesame.data.iteritems()\ if val['zmax'] == eos_data_i['zmax']]) # by default select the last (i.e. newest) table avalable cond_data_i = cond_sesame.data[cond_keys[-1]] print 'Presets for sesame table', args.tablenum, # Merging ele and ion grids if args.tablenum in opp.presets.SESAME: eos_data = opp.adapt.EosMergeGrids(eos_data_i, **opp.presets.SESAME[args.tablenum]['merge']) fracs = opp.presets.SESAME[args.tablenum]['fracs'] print 'found' else: eos_data = opp.adapt.EosMergeGrids(eos_data_i, filter_dens=lambda x: x>0, filter_temps=lambda x: x>0) fracs = (1.0,) print 'not found' output_file = args.out+'.cn4' print 'Generating IONMIX file: {0}'.format(output_file) numDens = opp.NA * eos_data['ele_dens'] / eos_data["abar"] print 'Warning: for now zbar is set to 0.' opp.writeIonmixFile(output_file, (eos_data['zmax'],), fracs, numDens=numDens, temps=eos_data['ele_temps'], eion=eos_data["ion_eint"], eele=eos_data["ele_eint"], pion=eos_data["ion_pres"], pele=eos_data["ele_pres"]) print 'Trying to read if back... ', try: ionmix = opp.OpacIonmix(output_file, eos_data["abar"]/opp.NA, twot=True, man=True, verbose=False) print '[ok]' except: print '[failed]'
rho_min = 0.2*state[1]['rho'] rho_max = 5*state[0]['rho'] temp_min = 0.2*state[1]['temp'] temp_max = 20*state[0]['temp'] rho = np.logspace(np.log10(rho_min), np.log10(rho_max),200) temp = np.logspace(np.log10(temp_min), np.log10(temp_max), 328) D, T = np.meshgrid(rho, temp, indices='ij') pres = tab.Pt_DT(D,T) eint = tab.Ut_DT(D,T) print(abar, zbar) numDens = opp.NA * rho / abar for filename in ['simulations/DavisEos/eos-vdv-davis.cn4', 'setup/eos-vdv-davis.cn4']: opp.writeIonmixFile(filename, [zbar], [1.0], numDens=numDens, temps=temp/eV2K_cst, eion=0.5*eint.T, eele=0.5*eint.T, pion=0.5*pres.T, pele=0.5*pres.T, zbar=zbar*np.ones(pres.shape)) # rereading the output ionmix = opp.OpacIonmix(filename, abar/opp.NA, twot=True, man=True, verbose=False)
# Parse the input file, this part is file dependent. # For OPAC file format the parser might be opacplot2/opg_tabop.py # otherwise it would have to be implemented. print dir(opp.OpgSesame) eos_data = opp.OpgSesame("../../../eos/sesame/xsesame_ascii", opp.OpgSesame.SINGLE, verbose=False).data[5761] # Write EoS/Opacity data, see opg_ionmix.py for writeIonmixFile class # definion. When writing EoS file in 3T one has to provide eion, eele, # pion, pele, zbar arguments. For a IONMIX file containing opacity data, # following arguments have to be provided: ngroups, opac_bounds, rosseland, # planck_absorb, planck_emiss. See FLASH4 manual for expected units in # the IONMIX format. fracs = (1.0,) filename = 'he-ses-5761.cn4' numDens = opp.NA * eos_data['ele_dens'] / eos_data["abar"] # convert from g.cm⁻³ to cm⁻³. opp.writeIonmixFile(filename, (eos_data['zmax'],), fracs, numDens=numDens, temps=eos_data['ele_temps'], eion=eos_data["ioncc_eint"], eele=eos_data["ele_eint"], pion=eos_data["ioncc_pres"], pele=eos_data["ele_pres"], zbar=np.ones(eos_data["ele_pres"].shape)*2 # full ionization, just as an exemple ) # Open generated file to check there are no errors. ionmix = opp.OpacIonmix(filename, eos_data["abar"]/opp.NA, twot=True, man=True, verbose=False)
def opac_hdf2table(): parser = argparse.ArgumentParser(description=""" This script is used to browse various EoS/Opacity tables formats """) parser.add_argument('-t', '--ftype', action="store", type=str, choices=avalable_formats, default='multi', help='Output filetype. Default: multi') parser.add_argument('-o', '--outfile', action="store", type=str, help='Output file base name/path') parser.add_argument('input_file', action="store", type=str, help='Path to the input hdf5 file') args = parser.parse_args() basedir, filename = os.path.split(os.path.abspath(args.input_file)) basename_in, _ = os.path.splitext(filename) if args.outfile is not None: filename_out = args.outfile else: filename_out = os.path.join(basedir, basename_in) op = OpgHdf5.open_file(os.path.abspath(args.input_file)) # ====================== Writing to output format ==================== if args.ftype == 'multi': from ..opg_multi import OpgMulti, MULTI_EXT_FMT op = OpgMulti(**op) op.set_id(3717) # just a random number, shouldn't matter op.write(os.path.join(basedir, filename_out), floor=None) elif args.ftype == 'ascii': outfile = os.path.join(basedir, filename_out) + '.txt' def repr_grid(arr, label): out = [] out += ['=' * 80] out += [' {0}: {1} points'.format(label, len(arr))] out += ['=' * 80] out = '\n'.join(out) return out + '\n' + np.array2string(arr, precision=3, separator='') print(repr_grid(op['dens'][:], "Density grid [g/cc]")) print(repr_grid(op['temp'][:], 'Temperature grid [eV]')) print(repr_grid(op['idens'][:], "Ionic density grid [1/cc]")) #print repr_grid(op['groups'][:], "Photon energy groups [eV]") nu = op['groups'][:] nu = 0.5 * (nu[1:] + nu[:-1]) out_op = np.array([nu] + [ op[key + '_mg'][0, 0] * op['dens'][0] for key in ['opp', 'opr', 'emp'] ]) np.set_printoptions(threshold=1e9) print( repr_grid(out_op.T, 'Opacity: nu [eV], opp [1/cm], opr[1/cm], emp [??]')) elif args.ftype == 'vtk': outfile = os.path.join(basedir, filename_out) from ..opg_vtk import opg_op2vtk f = opg_op2vtk(op, outfile) elif args.ftype == 'ionmix': outfile = os.path.join(basedir, filename_out) opp.writeIonmixFile(outfile, op['Znum'], op['Xnum'], numDens=op['idens'][:], temps=op['temp'][:], ngroups=op.Ng, opac_bounds=op['groups'][:], planck_absorb=op['opp_mg'][:], rosseland=op['opr_mg'][:], planck_emiss=op['emp_mg'][:]) # check that we can read the file back ionmix = opp.OpacIonmix(outfile, op["Abar"] / opp.NA, twot=True, man=True, verbose=False) else: print('Error: {0} ftype not known!'.format(args.ftype))
print 'Pressure [Bar]: {0:.3e} {1:.3e}'.format( *[eos_o[el+'_pres'][rho0_idx, temps0_idx]*1e-6 for el in ['ele', 'ioncc']]) print 'Eint [erg] : {0:.3e} {1:.3e}'.format( *[eos_o[el+'_eint'][rho0_idx, temps0_idx] for el in ['ele', 'ioncc']]) print 'Zbar : {0:.3f}'.format(zbar_tf[rho0_idx, temps0_idx]) print 'A: {0} / {1} Z: {2} / {3}'.format(mat_dict.A, eos_o['abar'], mat_dict.Z, eos_w['zmax']) print u'dens[0]: {0} g.cm⁻³, temps[0]: {1} eV'.format(eos_o['ele_dens'][0], eos_o['ele_temps'][0]) print eos_o['ioncc_eint'][0,0] # writing everything to files numDens = opp.NA * eos_o['ele_dens'] / eos_o['abar'] #print mat_dict.snop.z, mat_dict.snop.fraction opp.writeIonmixFile(filename, mat_dict.snop.z, mat_dict.snop.fraction, numDens=numDens, temps=eos_o['ele_temps'], eion=eos_o["ioncc_eint"], eele=eos_o["ele_eint"], pion=eos_o["ioncc_pres"], pele=eos_o["ele_pres"], zbar=zbar_tf) # rereading the output ionmix = opp.OpacIonmix(filename, eos_o['abar']/opp.NA, twot=True, man=True, verbose=False) test_dict = {'temps': 'ele_temps', 'dens': 'ele_dens', 'pele': 'ele_pres', 'pion': 'ion_pres', 'eele': 'ele_eint', 'eion': 'ion_eint'} print 'Checking that file was correctly written: ', for attr, key in test_dict.iteritems(): print attr,'...', try:
def opac_hdf2table(): parser = argparse.ArgumentParser(description= """ This script is used to browse various EoS/Opacity tables formats """) parser.add_argument('-t','--ftype', action="store", type=str, choices=avalable_formats, default='multi', help='Output filetype. Default: multi') parser.add_argument('-o', '--outfile', action="store", type=str, help='Output file base name/path') parser.add_argument('input_file', action="store", type=str, help='Path to the input hdf5 file') args = parser.parse_args() basedir, filename = os.path.split(os.path.abspath(args.input_file)) basename_in, _ = os.path.splitext(filename) if args.outfile is not None: filename_out = args.outfile else: filename_out = os.path.join(basedir, basename_in) op = OpgHdf5.open_file(os.path.abspath(args.input_file)) # ====================== Writing to output format ==================== if args.ftype == 'multi': from ..opg_multi import OpgMulti, MULTI_EXT_FMT op = OpgMulti(**op) op.set_id(3717) # just a random number, shouldn't matter op.write(os.path.join(basedir, filename_out), floor=None) elif args.ftype == 'ascii': outfile = os.path.join(basedir, filename_out)+'.txt' def repr_grid(arr, label): out = [] out += ['='*80] out += [' {0}: {1} points'.format(label, len(arr))] out += ['='*80] out = '\n'.join(out) return out + '\n'+ np.array2string(arr, precision=3, separator='') print( repr_grid(op['dens'][:], "Density grid [g/cc]") ) print( repr_grid(op['temp'][:], 'Temperature grid [eV]') ) print( repr_grid(op['idens'][:], "Ionic density grid [1/cc]") ) #print repr_grid(op['groups'][:], "Photon energy groups [eV]") nu = op['groups'][:] nu = 0.5*(nu[1:]+nu[:-1]) out_op = np.array([nu]+[op[key+'_mg'][0,0]*op['dens'][0] for key in ['opp', 'opr', 'emp']]) np.set_printoptions(threshold=1e9) print( repr_grid(out_op.T, 'Opacity: nu [eV], opp [1/cm], opr[1/cm], emp [??]') ) elif args.ftype == 'vtk': outfile = os.path.join(basedir, filename_out) from ..opg_vtk import opg_op2vtk f = opg_op2vtk(op, outfile) elif args.ftype == 'ionmix': outfile = os.path.join(basedir, filename_out) opp.writeIonmixFile(outfile, op['Znum'], op['Xnum'], numDens=op['idens'][:], temps=op['temp'][:], ngroups=op.Ng, opac_bounds=op['groups'][:], planck_absorb=op['opp_mg'][:], rosseland=op['opr_mg'][:], planck_emiss=op['emp_mg'][:]) # check that we can read the file back ionmix = opp.OpacIonmix(outfile, op["Abar"]/opp.NA, twot=True, man=True, verbose=False) else: print( 'Error: {0} ftype not known!'.format(args.ftype) )
def main(): parser = argparse.ArgumentParser(description=""" This script is used to automate EoS/opacity tables generation for FLASH. """) parser.add_argument( '-d', '--dbdir', action="store", type=str, default=os.path.abspath(os.curdir), help='Path to the database. Default: current directory.') parser.add_argument('-t', '--dbtype', action="store", type=str, default='sesame', help='Database type. Default: sesame.') parser.add_argument('-n', '--tablenum', action="store", type=int, help='Table id', required=True) parser.add_argument('-o', '--out', action="store", type=str, help='Ouput filename', default=None) args = parser.parse_args() if args.out is None: args.out = '{0}-eos-{1}'.format(args.dbtype, args.tablenum) else: args.out = os.path.splitext(args.out)[0] if args.dbtype == 'sesame': print("Parsing sesame input files.") eos_sesame = opp.OpgSesame(os.path.join(args.dbdir, "xsesame_ascii"), opp.OpgSesame.SINGLE, verbose=False) cond_sesame = opp.OpgSesame(os.path.join(args.dbdir, "sescu_ascii"), opp.OpgSesame.DOUBLE, verbose=False) eos_data_i = eos_sesame.data[args.tablenum] cond_keys = sorted([key for key, val in cond_sesame.data.iteritems()\ if val['zmax'] == eos_data_i['zmax']]) # by default select the last (i.e. newest) table avalable cond_data_i = cond_sesame.data[cond_keys[-1]] print('Presets for sesame table', args.tablenum, end='') # Merging ele and ion grids if args.tablenum in opp.presets.SESAME: eos_data = opp.adapt.EosMergeGrids( eos_data_i, **opp.presets.SESAME[args.tablenum]['merge']) fracs = opp.presets.SESAME[args.tablenum]['fracs'] print('found') else: eos_data = opp.adapt.EosMergeGrids(eos_data_i, filter_dens=lambda x: x > 0, filter_temps=lambda x: x > 0) fracs = (1.0, ) print('not found') output_file = args.out + '.cn4' print('Generating IONMIX file: {0}'.format(output_file)) numDens = opp.NA * eos_data['ele_dens'] / eos_data["abar"] print('Warning: for now zbar is set to 0.') opp.writeIonmixFile(output_file, (eos_data['zmax'], ), fracs, numDens=numDens, temps=eos_data['ele_temps'], eion=eos_data["ion_eint"], eele=eos_data["ele_eint"], pion=eos_data["ion_pres"], pele=eos_data["ele_pres"]) print('Trying to read if back... ', end='') try: ionmix = opp.OpacIonmix(output_file, eos_data["abar"] / opp.NA, twot=True, man=True, verbose=False) print('[ok]') except: print('[failed]')
# Write EoS/Opacity data, see opg_ionmix.py for writeIonmixFile class # definion. When writing EoS file in 3T one has to provide eion, eele, # pion, pele, zbar arguments. For a IONMIX file containing opacity data, # following arguments have to be provided: ngroups, opac_bounds, rosseland, # planck_absorb, planck_emiss. See FLASH4 manual for expected units in # the IONMIX format. fracs = (1.0, ) filename = 'he-ses-5761.cn4' numDens = opp.NA * eos_data['ele_dens'] / eos_data[ "abar"] # convert from g.cm⁻³ to cm⁻³. opp.writeIonmixFile( filename, (eos_data['zmax'], ), fracs, numDens=numDens, temps=eos_data['ele_temps'], eion=eos_data["ioncc_eint"], eele=eos_data["ele_eint"], pion=eos_data["ioncc_pres"], pele=eos_data["ele_pres"], zbar=np.ones(eos_data["ele_pres"].shape) * 2 # full ionization, just as an exemple ) # Open generated file to check there are no errors. ionmix = opp.OpacIonmix(filename, eos_data["abar"] / opp.NA, twot=True, man=True, verbose=False)
for jni, nion in enumerate(nions): for jt, temp in enumerate(temps): zbar[jni, jt] = z pion[jni, jt] = nion * opp.KB * temp pele[jni, jt] = z * pion[jni, jt] eion[jni, jt] = 1.5 * opp.KB * temp / mpi eele[jni, jt] = z * eion[jni, jt] # Compute specific electron entropy as given by the # Sackur-Tetrode equation: sele[jni,jt] = (opp.KB * opp.NA * z/a) * \ ( 1.5 * log(opp.KB * temp * opp.ME / (opp.PLANCK * opp.HBAR)) - log(z*mpi*nion/a) + 5.0/2.0 ) # Write the EOS data out to a file: "al-idealgas-001.cn6": opp.writeIonmixFile("al-idealgas-001.cn6", (z,), (1.0,), nions, temps, zbar=zbar, pion=pion, pele=pele, eion=eion, eele=eele, sele=sele) # Read the EOS data back in: opg_imx = opp.OpacIonmix("al-idealgas-001.cn6", mpi, twot=True, man=True, hassele=True) for jni, nion in enumerate(nions): for jt, temp in enumerate(temps): print "%6i %6i %15.6e %15.6e %15.6e" % (jni, jt, nion, temp, opg_imx.sele[jni,jt])
rho = np.logspace(np.log10(rho_min), np.log10(rho_max), 200) temp = np.logspace(np.log10(temp_min), np.log10(temp_max), 328) D, T = np.meshgrid(rho, temp, indices='ij') pres = tab.Pt_DT(D, T) eint = tab.Ut_DT(D, T) print(abar, zbar) numDens = opp.NA * rho / abar for filename in [ 'simulations/DavisEos/eos-vdv-davis.cn4', 'setup/eos-vdv-davis.cn4' ]: opp.writeIonmixFile(filename, [zbar], [1.0], numDens=numDens, temps=temp / eV2K_cst, eion=0.5 * eint.T, eele=0.5 * eint.T, pion=0.5 * pres.T, pele=0.5 * pres.T, zbar=zbar * np.ones(pres.shape)) # rereading the output ionmix = opp.OpacIonmix(filename, abar / opp.NA, twot=True, man=True, verbose=False)