def tally_derivatives(self): if not self._derivs_read: # Populate the dictionary if any derivatives are present. if 'derivatives' in self._f['tallies']: # Read the derivative ids. base = 'tallies/derivatives' deriv_ids = [int(k.split(' ')[1]) for k in self._f[base]] # Create each derivative object and add it to the dictionary. for d_id in deriv_ids: group = self._f['tallies/derivatives/derivative {}'.format( d_id)] deriv = openmc.TallyDerivative(derivative_id=d_id) deriv.variable = group['independent variable'][()].decode() if deriv.variable == 'density': deriv.material = group['material'][()] elif deriv.variable == 'nuclide_density': deriv.material = group['material'][()] deriv.nuclide = group['nuclide'][()].decode() elif deriv.variable == 'temperature': deriv.material = group['material'][()] self._derivs[d_id] = deriv self._derivs_read = True return self._derivs
def test_xml_roundtrip(run_in_tmpdir): # Create a tally with all possible gizmos mesh = openmc.RegularMesh() mesh.lower_left = (-10., -10., -10.) mesh.upper_right = ( 10., 10., 10., ) mesh.dimension = (5, 5, 5) mesh_filter = openmc.MeshFilter(mesh) tally = openmc.Tally() tally.filters = [mesh_filter] tally.nuclides = ['U235', 'I135', 'Li6'] tally.scores = ['total', 'fission', 'heating'] tally.derivative = openmc.TallyDerivative(variable='nuclide_density', material=1, nuclide='Li6') tally.triggers = [openmc.Trigger('rel_err', 0.025)] tally.triggers[0].scores = ['total', 'fission'] tallies = openmc.Tallies([tally]) # Roundtrip through XML and make sure we get what we started with tallies.export_to_xml() new_tallies = openmc.Tallies.from_xml() assert len(new_tallies) == 1 new_tally = new_tallies[0] assert new_tally.id == tally.id assert len(new_tally.filters) == 1 assert isinstance(new_tally.filters[0], openmc.MeshFilter) assert np.allclose(new_tally.filters[0].mesh.lower_left, mesh.lower_left) assert new_tally.nuclides == tally.nuclides assert new_tally.scores == tally.scores assert new_tally.derivative.variable == tally.derivative.variable assert new_tally.derivative.material == tally.derivative.material assert new_tally.derivative.nuclide == tally.derivative.nuclide assert len(new_tally.triggers) == 1 assert new_tally.triggers[0].trigger_type == tally.triggers[0].trigger_type assert new_tally.triggers[0].threshold == tally.triggers[0].threshold assert new_tally.triggers[0].scores == tally.triggers[0].scores
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Set settings explicitly self._model.settings.batches = 3 self._model.settings.inactive = 0 self._model.settings.particles = 100 self._model.settings.source = openmc.Source( space=openmc.stats.Box([-160, -160, -183], [160, 160, 183])) self._model.settings.temperature['multipole'] = True filt_mats = openmc.MaterialFilter((1, 3)) filt_eout = openmc.EnergyoutFilter((0.0, 0.625, 20.0e6)) # We want density derivatives for both water and fuel to get coverage # for both fissile and non-fissile materials. d1 = openmc.TallyDerivative(derivative_id=1) d1.variable = 'density' d1.material = 3 d2 = openmc.TallyDerivative(derivative_id=2) d2.variable = 'density' d2.material = 1 # O-16 is a good nuclide to test against because it is present in both # water and fuel. Some routines need to recognize that they have the # perturbed nuclide but not the perturbed material. d3 = openmc.TallyDerivative(derivative_id=3) d3.variable = 'nuclide_density' d3.material = 1 d3.nuclide = 'O16' # A fissile nuclide, just for good measure. d4 = openmc.TallyDerivative(derivative_id=4) d4.variable = 'nuclide_density' d4.material = 1 d4.nuclide = 'U235' # Temperature derivatives. d5 = openmc.TallyDerivative(derivative_id=5) d5.variable = 'temperature' d5.material = 1 derivs = [d1, d2, d3, d4, d5] # Cover the flux score. for i in range(5): t = openmc.Tally() t.scores = ['flux'] t.filters = [filt_mats] t.derivative = derivs[i] self._model.tallies.append(t) # Cover supported scores with a collision estimator. for i in range(5): t = openmc.Tally() t.scores = [ 'total', 'absorption', 'scatter', 'fission', 'nu-fission' ] t.filters = [filt_mats] t.nuclides = ['total', 'U235'] t.derivative = derivs[i] self._model.tallies.append(t) # Cover an analog estimator. for i in range(5): t = openmc.Tally() t.scores = ['absorption'] t.filters = [filt_mats] t.estimator = 'analog' t.derivative = derivs[i] self._model.tallies.append(t) # Energyout filter and total nuclide for the density derivatives. for i in range(2): t = openmc.Tally() t.scores = ['nu-fission', 'scatter'] t.filters = [filt_mats, filt_eout] t.nuclides = ['total', 'U235'] t.derivative = derivs[i] self._model.tallies.append(t) # Energyout filter without total nuclide for other derivatives. for i in range(2, 5): t = openmc.Tally() t.scores = ['nu-fission', 'scatter'] t.filters = [filt_mats, filt_eout] t.nuclides = ['U235'] t.derivative = derivs[i] self._model.tallies.append(t)