From c9a5d0cdf8d3e8662b68c584898779a902c60322 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 20 May 2021 16:26:55 +0100 Subject: [PATCH 1/2] added nuclides split for tallies --- .../parametric_neutronics/neutronics_model.py | 63 +++++++++++++------ 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/paramak/parametric_neutronics/neutronics_model.py b/paramak/parametric_neutronics/neutronics_model.py index 10f50ecd..c6dcf12e 100644 --- a/paramak/parametric_neutronics/neutronics_model.py +++ b/paramak/parametric_neutronics/neutronics_model.py @@ -75,6 +75,15 @@ class NeutronicsModel(): fusion_power: the power in watts emitted by the fusion reaction recalling that each DT fusion reaction emitts 17.6 MeV or 2.819831e-12 Joules + photon_transport: Allows the option of turning photon transport off. + This will speed up the simulation but no longer transport photons. + Tallies like heating and photon spectra need photons to be left on. + If TBR is the only tally that you are interested in then photons + can be turned off in most cases. Defaults to True. + nuclides: split the integrated tallies per material to include results + for each per nuclide. + max_lost_particles: Specify the acceptable number of lost particles in + the simulation. """ def __init__( @@ -95,6 +104,7 @@ def __init__( float], Tuple[float, float, float]]] = None, fusion_power: Optional[float] = 1e9, photon_transport: Optional[bool] = True, + nuclides: Optional[bool] = False, # convert from watts to activity source_activity max_lost_particles: Optional[int] = 10, ): @@ -114,6 +124,7 @@ def __init__( self.mesh_2d_corners = mesh_2d_corners self.mesh_3d_corners = mesh_3d_corners self.photon_transport = photon_transport + self.nuclides = nuclides self.fusion_power = fusion_power self.model = None @@ -539,36 +550,44 @@ def export_xml( for standard_tally in self.cell_tallies: if standard_tally == 'TBR': score = '(n,Xt)' # where X is a wild card - sufix = 'TBR' + suffix = 'TBR' tally = openmc.Tally(name='TBR') tally.scores = [score] self.tallies.append(tally) - self._add_tally_for_every_material(sufix, score) + self._add_tally_for_every_material( + suffix=suffix, + score=score, + nuclides=self.nuclides+['total'] + ) elif standard_tally == 'spectra': energy_bins = openmc.mgxs.GROUP_STRUCTURES['CCFE-709'] energy_filter = openmc.EnergyFilter(energy_bins) - neutron_particle_filter = openmc.ParticleFilter([ - 'neutron']) + neutron_particle_filter = openmc.ParticleFilter(['neutron']) self._add_tally_for_every_material( - 'neutron_spectra', - 'flux', - [neutron_particle_filter, energy_filter] + suffix='neutron_spectra', + score='flux', + nuclides=False, + additional_filters=[neutron_particle_filter, energy_filter] ) if self.photon_transport is True: - photon_particle_filter = openmc.ParticleFilter([ - 'photon']) + photon_particle_filter = openmc.ParticleFilter(['photon']) self._add_tally_for_every_material( - 'photon_spectra', - 'flux', - [photon_particle_filter, energy_filter] + suffix='photon_spectra', + score='flux', + nuclides=False, + additional_filters=[photon_particle_filter, energy_filter] ) else: score = standard_tally - sufix = standard_tally - self._add_tally_for_every_material(sufix, score) + suffix = standard_tally + self._add_tally_for_every_material( + suffix=suffix, + score=score, + nuclides=self.nuclides + ) # make the model from geometry, materials, settings and tallies model = openmc.model.Model( @@ -581,13 +600,19 @@ def export_xml( self.model = model return model - def _add_tally_for_every_material(self, sufix: str, score: str, - additional_filters: List = None) -> None: + def _add_tally_for_every_material( + self, + suffix: str, + score: str, + nuclides: bool, + additional_filters: List = None + ) -> None: """Adds a tally to self.tallies for every material. Arguments: - sufix: the string to append to the end of the tally name to help + suffix: the string to append to the end of the tally name to help identify the tally later. + nuclides: bool, score: the openmc.Tally().scores value that contribute to the tally """ if additional_filters is None: @@ -595,9 +620,11 @@ def _add_tally_for_every_material(self, sufix: str, score: str, for key, value in self.openmc_materials.items(): if key != 'DT_plasma': material_filter = openmc.MaterialFilter(value) - tally = openmc.Tally(name=key + '_' + sufix) + tally = openmc.Tally(name=key + '_' + suffix) tally.filters = [material_filter] + additional_filters tally.scores = [score] + if nuclides: + tally.nuclides = [nuc.name for nuc in value.nuclides] self.tallies.append(tally) def simulate( From 638c82104e44d417ac2717bb77db318641995313 Mon Sep 17 00:00:00 2001 From: autopep8 Date: Thu, 20 May 2021 20:48:54 +0000 Subject: [PATCH 2/2] Automated autopep8 fixes --- .../parametric_neutronics/neutronics_model.py | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/paramak/parametric_neutronics/neutronics_model.py b/paramak/parametric_neutronics/neutronics_model.py index c6dcf12e..aa08a322 100644 --- a/paramak/parametric_neutronics/neutronics_model.py +++ b/paramak/parametric_neutronics/neutronics_model.py @@ -557,7 +557,7 @@ def export_xml( self._add_tally_for_every_material( suffix=suffix, score=score, - nuclides=self.nuclides+['total'] + nuclides=self.nuclides + ['total'] ) elif standard_tally == 'spectra': @@ -565,21 +565,17 @@ def export_xml( energy_bins = openmc.mgxs.GROUP_STRUCTURES['CCFE-709'] energy_filter = openmc.EnergyFilter(energy_bins) - neutron_particle_filter = openmc.ParticleFilter(['neutron']) + neutron_particle_filter = openmc.ParticleFilter([ + 'neutron']) self._add_tally_for_every_material( - suffix='neutron_spectra', - score='flux', - nuclides=False, - additional_filters=[neutron_particle_filter, energy_filter] - ) + suffix='neutron_spectra', score='flux', nuclides=False, additional_filters=[ + neutron_particle_filter, energy_filter]) if self.photon_transport is True: - photon_particle_filter = openmc.ParticleFilter(['photon']) + photon_particle_filter = openmc.ParticleFilter([ + 'photon']) self._add_tally_for_every_material( - suffix='photon_spectra', - score='flux', - nuclides=False, - additional_filters=[photon_particle_filter, energy_filter] - ) + suffix='photon_spectra', score='flux', nuclides=False, additional_filters=[ + photon_particle_filter, energy_filter]) else: score = standard_tally suffix = standard_tally