def pincell_model(): """Set up a model to test with and delete files when done""" openmc.reset_auto_ids() pincell = openmc.examples.pwr_pin_cell() pincell.settings.verbosity = 1 # Add a tally filter1 = openmc.MaterialFilter(pincell.materials) filter2 = openmc.EnergyFilter([0.0, 1.0, 1.0e3, 20.0e6]) mat_tally = openmc.Tally() mat_tally.filters = [filter1, filter2] mat_tally.nuclides = ['U235', 'U238'] mat_tally.scores = ['total', 'elastic', '(n,gamma)'] pincell.tallies.append(mat_tally) # Add an expansion tally zernike_tally = openmc.Tally() filter3 = openmc.ZernikeFilter(5, r=.63) cells = pincell.geometry.root_universe.cells filter4 = openmc.CellFilter(list(cells.values())) zernike_tally.filters = [filter3, filter4] zernike_tally.scores = ['fission'] pincell.tallies.append(zernike_tally) # Add an energy function tally energyfunc_tally = openmc.Tally() energyfunc_filter = openmc.EnergyFunctionFilter([0.0, 20e6], [0.0, 20e6]) energyfunc_tally.scores = ['fission'] energyfunc_tally.filters = [energyfunc_filter] pincell.tallies.append(energyfunc_tally) # Write XML files in tmpdir with cdtemp(): pincell.export_to_xml() yield
def test_zernike(): n = 4 f = openmc.ZernikeFilter(n, 0., 0., 1.) assert f.order == n assert f.bins[0] == 'Z0,0' assert f.bins[-1] == 'Z{0},{0}'.format(n) assert len(f.bins) == (n + 1) * (n + 2) // 2 # Make sure __repr__ works repr(f) # to_xml_element() elem = f.to_xml_element() assert elem.tag == 'filter' assert elem.attrib['type'] == 'zernike' assert elem.find('order').text == str(n)
def test_first_moment(run_in_tmpdir, box_model): plain_tally = openmc.Tally() plain_tally.scores = ['flux', 'scatter'] # Create tallies with expansion filters leg_tally = openmc.Tally() leg_tally.filters = [openmc.LegendreFilter(3)] leg_tally.scores = ['scatter'] leg_sptl_tally = openmc.Tally() leg_sptl_tally.filters = [openmc.SpatialLegendreFilter(3, 'x', -5., 5.)] leg_sptl_tally.scores = ['scatter'] sph_scat_filter = openmc.SphericalHarmonicsFilter(5) sph_scat_filter.cosine = 'scatter' sph_scat_tally = openmc.Tally() sph_scat_tally.filters = [sph_scat_filter] sph_scat_tally.scores = ['scatter'] sph_flux_filter = openmc.SphericalHarmonicsFilter(5) sph_flux_filter.cosine = 'particle' sph_flux_tally = openmc.Tally() sph_flux_tally.filters = [sph_flux_filter] sph_flux_tally.scores = ['flux'] zernike_tally = openmc.Tally() zernike_tally.filters = [openmc.ZernikeFilter(3, r=10.)] zernike_tally.scores = ['scatter'] # Add tallies to model and ensure they all use the same estimator box_model.tallies = [ plain_tally, leg_tally, leg_sptl_tally, sph_scat_tally, sph_flux_tally, zernike_tally ] for t in box_model.tallies: t.estimator = 'analog' sp_name = box_model.run() # Check that first moment matches the score from the plain tally with openmc.StatePoint(sp_name) as sp: # Get scores from tally without expansion filters flux, scatter = sp.tallies[plain_tally.id].mean.ravel() # Check that first moment matches first_score = lambda t: sp.tallies[t.id].mean.ravel()[0] assert first_score(leg_tally) == scatter assert first_score(leg_sptl_tally) == scatter assert first_score(sph_scat_tally) == scatter assert first_score(sph_flux_tally) == approx(flux) assert first_score(zernike_tally) == approx(scatter)
def generate_tallies(fuelcelllist, total_fuel_cell, zerk_order, flag): tallies_file = openmc.Tallies() cell_filter = openmc.CellFilter(fuelcelllist) total_fuel_cell_filter = openmc.CellFilter([total_fuel_cell]) if flag == 1: # choose flag 1, we use tradiational estimators tally3 = openmc.Tally(name='tracklength') tally3.filters.append(cell_filter) tally3.scores = ['nu-fission', 'absorption'] tally3.nuclides = ['U238'] tally3.estimator = 'tracklength' tallies_file.append(tally3) tally3 = openmc.Tally(name='collision') tally3.filters.append(cell_filter) tally3.scores = ['nu-fission', 'absorption'] tally3.nuclides = ['U238'] tally3.estimator = 'collision' tallies_file.append(tally3) tally3 = openmc.Tally(name='analog') tally3.filters.append(cell_filter) tally3.scores = ['nu-fission', 'absorption'] tally3.nuclides = ['U238'] tally3.estimator = 'analog' tallies_file.append(tally3) elif flag == 2: # we tally FET str1 = 'fet' strorder = str(zerk_order) name = str1 + strorder fet_tally = openmc.Tally(name=name) fet_tally.filters.append(total_fuel_cell_filter) fet_tally.scores = ['nu-fission', 'absorption'] fet_tally.nuclides = ['U238'] expand_filter = openmc.ZernikeFilter(zerk_order, x=0.0, y=0.0, r=0.392) fet_tally.filters.append(expand_filter) tallies_file.append(fet_tally) tallies_file.export_to_xml()
def test_zernike(): n = 4 f = openmc.ZernikeFilter(n, 0., 0., 1.) assert f.order == n assert f.bins[0] == 'Z0,0' assert f.bins[-1] == 'Z{0},{0}'.format(n) assert len(f.bins) == (n + 1) * (n + 2) // 2 # Make sure __repr__ works repr(f) # to_xml_element() elem = f.to_xml_element() assert elem.tag == 'filter' assert elem.attrib['type'] == 'zernike' assert elem.find('order').text == str(n) # from_xml_element() new_f = openmc.Filter.from_xml_element(elem) for attr in ('id', 'order', 'x', 'y', 'r'): assert getattr(new_f, attr) == getattr(f, attr)