def _parse_statepoint(self, statepoint, tally_id=1): """Parses a statepoint file and reads in the relevant fluxes, assigns them to the DataSources or the XSCache, and returns k, phi_g, and E_g. Parameters ---------- statepoint : xsgen.statepoint.StatePoint An OpenMC StatePoint. tally_id : int The tally id we wish to read group flux from. Returns ------- k : float Neutron multiplication factor. phi_g : list of floats Group flux. e_g : list of floats Group structure. """ sp = StatePoint(statepoint) sp.read_results() # compute group fluxes for data sources for tally, ds in zip(sp.tallies[1:3], (self.eafds, self.omcds)): ds.src_phi_g = tally.results[::-1, :, 0].flatten() ds.src_phi_g /= ds.src_phi_g.sum() # compute return values k, kerr = sp.k_combined tally = sp.tallies[tally_id - 1] phi_g = tally.results[::-1, :, 0].flatten() phi_g /= phi_g.sum() e_g = tally.filters["energyin"].bins return k, phi_g, e_g
def _parse_statepoint(self, statepoint): """Parses a statepoint file and reads in the relevant fluxes, assigns them to the DataSources or the XSCache, and returns k and phi_g. """ sp = StatePoint(statepoint) sp.read_results() # compute group fluxes for data sources for tally, ds in zip(sp.tallies[1:4], (self.cinderds, self.eafds, self.omcds)): ds.src_phi_g = tally.results[::-1, :, 0].flatten() ds.src_phi_g /= ds.src_phi_g.sum() # compute return values k, kerr = sp.k_combined t_flux = sp.tallies[0] phi_g = t_flux.results[::-1, :, 0].flatten() phi_g /= phi_g.sum() return k, phi_g
'Fuel-2.4wo-16BA-grid-56', \ 'Fuel-3.1wo-instr-16BA-grid-17'] # Loop over assemblies for assembly in assemblies: print 'Exporting ' + assembly # Create an HDF5 group for this assembly in our 'targets.h5' file assembly_group = f.create_group(assembly) high_energy = assembly_group.create_group('High Energy') low_energy = assembly_group.create_group('Low Energy') # Import the OpenMC results for this assembly sp = StatePoint('../openmc-input/'+assembly+'/pinwise/statepoint.1250.h5') sp.read_results() # Extract 2D numpy arrays of the batch means for each type of tally flux = sp.extract_results(1, 'flux')['mean'] tot_rxn_rate = sp.extract_results(1, 'total')['mean'] abs_rxn_rate = sp.extract_results(1, 'absorption')['mean'] fiss_rxn_rate = sp.extract_results(1, 'fission')['mean'] nufiss_rxn_rate = sp.extract_results(1, 'nu-fission')['mean'] # Reshape to grid with energy group as third index flux = np.reshape(flux, (x, y, groups)) tot_rxn_rate = np.reshape(tot_rxn_rate, (x, y, groups)) abs_rxn_rate = np.reshape(abs_rxn_rate, (x, y, groups)) fiss_rxn_rate = np.reshape(fiss_rxn_rate, (x, y, groups)) nufiss_rxn_rate = np.reshape(nufiss_rxn_rate, (x, y, groups))
batches = np.linspace(260,1240,99) rms_file.create_dataset('Batches', data=batches-250) # Loop over each assembly type for assembly in assemblies: print 'Exporting ' + assembly # Create a group in the HDF5 file for this assembly assembly_group = rms_file.create_group(assembly) # Read in the converged tally results for this assembly directory = '../openmc-input/' + assembly + '/pinwise/' filename = 'statepoint.1250.h5' conv_sp = StatePoint(directory + filename) conv_sp.read_results() # Extract 2D numpy arrays of the batch means for each type of tally conv_flux = conv_sp.extract_results(1, 'flux')['mean'] conv_tot_rxn_rate = conv_sp.extract_results(1, 'total')['mean'] conv_abs_rxn_rate = conv_sp.extract_results(1, 'absorption')['mean'] conv_fiss_rxn_rate = conv_sp.extract_results(1, 'fission')['mean'] conv_nufiss_rxn_rate = conv_sp.extract_results(1, 'nu-fission')['mean'] # Reshape to grid with energy group as third index conv_flux = np.reshape(conv_flux, (x, y, groups)) conv_tot_rxn_rate = np.reshape(conv_tot_rxn_rate, (x, y, groups)) conv_abs_rxn_rate = np.reshape(conv_abs_rxn_rate, (x, y, groups)) conv_fiss_rxn_rate = np.reshape(conv_fiss_rxn_rate, (x, y, groups)) conv_nufiss_rxn_rate = np.reshape(conv_nufiss_rxn_rate, (x, y, groups))
def main(file_, o): """Main program""" sp = StatePoint(file_) sp.read_results() validate_options(sp, o) if o.list: print_available(sp) return if o.vtk: if not o.output[-4:] == ".vtm": o.output += ".vtm" else: if not o.output[-5:] == ".silo": o.output += ".silo" if o.vtk: try: import vtk except: print('The vtk python bindings do not appear to be installed properly.\n' 'On Ubuntu: sudo apt-get install python-vtk\n' 'See: http://www.vtk.org/') return else: try: import silomesh except: print('The silomesh package does not appear to be installed properly.\n' 'See: https://github.com/nhorelik/silomesh/') return if o.vtk: blocks = vtk.vtkMultiBlockDataSet() blocks.SetNumberOfBlocks(5) block_idx = 0 else: silomesh.init_silo(o.output) # Tally loop ################################################################# for tally in sp.tallies: # skip non-mesh tallies or non-user-specified tallies if o.tallies and not tally.id in o.tallies: continue if not 'mesh' in tally.filters: continue print("Processing Tally {}...".format(tally.id)) # extract filter options and mesh parameters for this tally filtercombos = get_filter_combos(tally) meshparms = get_mesh_parms(sp, tally) nx,ny,nz = meshparms[:3] ll = meshparms[3:6] ur = meshparms[6:9] if o.vtk: ww = [(u-l)/n for u,l,n in zip(ur,ll,(nx,ny,nz))] grid = grid = vtk.vtkImageData() grid.SetDimensions(nx+1,ny+1,nz+1) grid.SetOrigin(*ll) grid.SetSpacing(*ww) else: silomesh.init_mesh('Tally_{}'.format(tally.id), *meshparms) # Score loop ############################################################### for sid,score in enumerate(tally.scores): # skip non-user-specified scrores for this tally if o.scores and tally.id in o.scores and not sid in o.scores[tally.id]: continue # Filter loop ############################################################ for filterspec in filtercombos: # skip non-user-specified filter bins skip = False if o.filters and tally.id in o.filters: for filter_,bin in filterspec[1:]: if filter_ in o.filters[tally.id] and \ not bin in o.filters[tally.id][filter_]: skip = True break if skip: continue # find and sanitize the variable name for this score varname = get_sanitized_filterspec_name(tally, score, filterspec) if o.vtk: vtkdata = vtk.vtkDoubleArray() vtkdata.SetName(varname) dataforvtk = {} else: silomesh.init_var(varname) lbl = "\t Score {}.{} {}:\t\t{}".format(tally.id, sid+1, score, varname) # Mesh fill loop ####################################################### for x in range(1,nx+1): sys.stdout.write(lbl+" {0}%\r".format(int(x/nx*100))) sys.stdout.flush() for y in range(1,ny+1): for z in range(1,nz+1): filterspec[0][1] = (x,y,z) val = sp.get_value(tally.id-1, filterspec, sid)[o.valerr] if o.vtk: # vtk cells go z, y, x, so we store it now and enter it later i = (z-1)*nx*ny + (y-1)*nx + x-1 dataforvtk[i] = float(val) else: silomesh.set_value(float(val), x, y, z) # end mesh fill loop print() if o.vtk: for i in range(nx*ny*nz): vtkdata.InsertNextValue(dataforvtk[i]) grid.GetCellData().AddArray(vtkdata) del vtkdata else: silomesh.finalize_var() # end filter loop # end score loop if o.vtk: blocks.SetBlock(block_idx, grid) block_idx += 1 else: silomesh.finalize_mesh() # end tally loop if o.vtk: writer = vtk.vtkXMLMultiBlockDataWriter() writer.SetFileName(o.output) writer.SetInput(blocks) writer.Write() else: silomesh.finalize_silo()
def main(file_, o): """Main program""" sp = StatePoint(file_) sp.read_results() validate_options(sp, o) if o.list: print_available(sp) return silomesh.init_silo(o.output) # Tally loop ################################################################# for tally in sp.tallies: # skip non-mesh tallies or non-user-specified tallies if o.tallies and not tally.id in o.tallies: continue if not 'mesh' in tally.filters: continue print "Processing Tally {}...".format(tally.id) # extract filter options and mesh parameters for this tally filtercombos = get_filter_combos(tally) meshparms = get_mesh_parms(sp, tally) nx, ny, nz = meshparms[0], meshparms[1], meshparms[2] silomesh.init_mesh('Tally_{}'.format(tally.id), *meshparms) # Score loop ############################################################### for sid, score in enumerate(tally.scores): # skip non-user-specified scrores for this tally if o.scores and tally.id in o.scores and not sid in o.scores[ tally.id]: continue # Filter loop ############################################################ for filterspec in filtercombos: # skip non-user-specified filter bins skip = False if o.filters and tally.id in o.filters: for filter_, bin in filterspec[1:]: if filter_ in o.filters[tally.id] and \ not bin in o.filters[tally.id][filter_]: skip = True break if skip: continue # find and sanitize the variable name for this score varname = get_sanitized_filterspec_name( tally, score, filterspec) silomesh.init_var(varname) print "\t Score {}.{} {}:\t\t{}".format( tally.id, sid + 1, score, varname) # Mesh fill loop ####################################################### for x in range(1, nx + 1): for y in range(1, ny + 1): for z in range(1, nz + 1): filterspec[0][1] = (x, y, z) val = sp.get_value(tally.id - 1, filterspec, sid)[o.valerr] silomesh.set_value(float(val), x, y, z) # end mesh fill loop silomesh.finalize_var() # end filter loop # end score loop silomesh.finalize_mesh() # end tally loop silomesh.finalize_silo()
from numpy.testing import assert_allclose, assert_equal from statepoint import StatePoint if len(sys.argv) > 2: path1 = sys.argv[1] path2 = sys.argv[2] else: raise # Create StatePoint objects sp1 = StatePoint(path1) sp2 = StatePoint(path2) # Read tally results sp1.read_results() sp2.read_results() # Compare header information assert sp1.revision == sp2.revision assert sp1.version == sp2.version assert sp1.seed == sp2.seed assert sp1.run_mode == sp2.run_mode assert sp1.n_particles == sp2.n_particles assert sp1.n_batches == sp2.n_batches if sp1.run_mode == 2: # Compare criticality information assert sp1.n_inactive == sp2.n_inactive assert sp1.gen_per_batch == sp2.gen_per_batch assert sp1.current_batch == sp2.current_batch
def main(file_, o): """Main program""" sp = StatePoint(file_) sp.read_results() validate_options(sp, o) if o.list: print_available(sp) return silomesh.init_silo(o.output) # Tally loop ################################################################# for tally in sp.tallies: # skip non-mesh tallies or non-user-specified tallies if o.tallies and not tally.id in o.tallies: continue if not 'mesh' in tally.filters: continue print "Processing Tally {}...".format(tally.id) # extract filter options and mesh parameters for this tally filtercombos = get_filter_combos(tally) meshparms = get_mesh_parms(sp, tally) nx,ny,nz = meshparms[0], meshparms[1], meshparms[2] silomesh.init_mesh('Tally_{}'.format(tally.id), *meshparms) # Score loop ############################################################### for sid,score in enumerate(tally.scores): # skip non-user-specified scrores for this tally if o.scores and tally.id in o.scores and not sid in o.scores[tally.id]: continue # Filter loop ############################################################ for filterspec in filtercombos: # skip non-user-specified filter bins skip = False if o.filters and tally.id in o.filters: for filter_,bin in filterspec[1:]: if filter_ in o.filters[tally.id] and \ not bin in o.filters[tally.id][filter_]: skip = True break if skip: continue # find and sanitize the variable name for this score varname = get_sanitized_filterspec_name(tally, score, filterspec) silomesh.init_var(varname) print "\t Score {}.{} {}:\t\t{}".format(tally.id, sid+1, score, varname) # Mesh fill loop ####################################################### for x in range(1,nx+1): for y in range(1,ny+1): for z in range(1,nz+1): filterspec[0][1] = (x,y,z) val = sp.get_value(tally.id-1, filterspec, sid)[o.valerr] silomesh.set_value(float(val), x, y, z) # end mesh fill loop silomesh.finalize_var() # end filter loop # end score loop silomesh.finalize_mesh() # end tally loop silomesh.finalize_silo()