From 24f704849419e4544531f3a7d5dcc9c52975bfd7 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 4 Sep 2019 16:32:50 -0500 Subject: [PATCH 01/14] Update pincell python example --- examples/python/pincell/build-xml.py | 99 +++++++++++----------------- openmc/settings.py | 4 -- 2 files changed, 38 insertions(+), 65 deletions(-) diff --git a/examples/python/pincell/build-xml.py b/examples/python/pincell/build-xml.py index 072cc911f0..dc6df91631 100644 --- a/examples/python/pincell/build-xml.py +++ b/examples/python/pincell/build-xml.py @@ -16,23 +16,23 @@ particles = 1000 # Instantiate some Materials and register the appropriate Nuclides -uo2 = openmc.Material(material_id=1, name='UO2 fuel at 2.4% wt enrichment') +uo2 = openmc.Material(name='UO2 fuel at 2.4% wt enrichment') uo2.set_density('g/cm3', 10.29769) uo2.add_element('U', 1., enrichment=2.4) uo2.add_element('O', 2.) -helium = openmc.Material(material_id=2, name='Helium for gap') +helium = openmc.Material(name='Helium for gap') helium.set_density('g/cm3', 0.001598) helium.add_element('He', 2.4044e-4) -zircaloy = openmc.Material(material_id=3, name='Zircaloy 4') +zircaloy = openmc.Material(name='Zircaloy 4') zircaloy.set_density('g/cm3', 6.55) zircaloy.add_element('Sn', 0.014 , 'wo') zircaloy.add_element('Fe', 0.00165, 'wo') zircaloy.add_element('Cr', 0.001 , 'wo') zircaloy.add_element('Zr', 0.98335, 'wo') -borated_water = openmc.Material(material_id=4, name='Borated water') +borated_water = openmc.Material(name='Borated water') borated_water.set_density('g/cm3', 0.740582) borated_water.add_element('B', 4.0e-5) borated_water.add_element('H', 5.0e-2) @@ -40,54 +40,31 @@ borated_water.add_element('O', 2.4e-2) borated_water.add_s_alpha_beta('c_H_in_H2O') # Instantiate a Materials collection and export to XML -materials_file = openmc.Materials([uo2, helium, zircaloy, borated_water]) -materials_file.export_to_xml() +materials = openmc.Materials([uo2, helium, zircaloy, borated_water]) +materials.export_to_xml() ############################################################################### # Exporting to OpenMC geometry.xml file ############################################################################### -# Instantiate ZCylinder surfaces -fuel_or = openmc.ZCylinder(surface_id=1, x0=0, y0=0, r=0.39218, name='Fuel OR') -clad_ir = openmc.ZCylinder(surface_id=2, x0=0, y0=0, r=0.40005, name='Clad IR') -clad_or = openmc.ZCylinder(surface_id=3, x0=0, y0=0, r=0.45720, name='Clad OR') -left = openmc.XPlane(surface_id=4, x0=-0.62992, name='left') -right = openmc.XPlane(surface_id=5, x0=0.62992, name='right') -bottom = openmc.YPlane(surface_id=6, y0=-0.62992, name='bottom') -top = openmc.YPlane(surface_id=7, y0=0.62992, name='top') +# Create cylindrical surfaces +fuel_or = openmc.ZCylinder(r=0.39218, name='Fuel OR') +clad_ir = openmc.ZCylinder(r=0.40005, name='Clad IR') +clad_or = openmc.ZCylinder(r=0.45720, name='Clad OR') -left.boundary_type = 'reflective' -right.boundary_type = 'reflective' -top.boundary_type = 'reflective' -bottom.boundary_type = 'reflective' +# Create a region represented as the inside of a rectangular prism +pitch = 1.25984 +box = openmc.rectangular_prism(pitch, pitch, boundary_type='reflective') -# Instantiate Cells -fuel = openmc.Cell(cell_id=1, name='cell 1') -gap = openmc.Cell(cell_id=2, name='cell 2') -clad = openmc.Cell(cell_id=3, name='cell 3') -water = openmc.Cell(cell_id=4, name='cell 4') +# Create cells, mapping materials to regions +fuel = openmc.Cell(fill=uo2, region=-fuel_or) +gap = openmc.Cell(fill=helium, region=+fuel_or & -clad_ir) +clad = openmc.Cell(fill=zircaloy, region=+clad_ir & -clad_or) +water = openmc.Cell(fill=borated_water, region=+clad_or & box) -# Use surface half-spaces to define regions -fuel.region = -fuel_or -gap.region = +fuel_or & -clad_ir -clad.region = +clad_ir & -clad_or -water.region = +clad_or & +left & -right & +bottom & -top - -# Register Materials with Cells -fuel.fill = uo2 -gap.fill = helium -clad.fill = zircaloy -water.fill = borated_water - -# Instantiate Universe -root = openmc.Universe(universe_id=0, name='root universe') - -# Register Cells with Universe -root.add_cells([fuel, gap, clad, water]) - -# Instantiate a Geometry, register the root Universe, and export to XML -geometry = openmc.Geometry(root) +# Create a geometry and export to XML +geometry = openmc.Geometry([fuel, gap, clad, water]) geometry.export_to_xml() @@ -96,22 +73,22 @@ geometry.export_to_xml() ############################################################################### # Instantiate a Settings object, set all runtime parameters, and export to XML -settings_file = openmc.Settings() -settings_file.batches = batches -settings_file.inactive = inactive -settings_file.particles = particles +settings = openmc.Settings() +settings.batches = batches +settings.inactive = inactive +settings.particles = particles # Create an initial uniform spatial source distribution over fissionable zones -bounds = [-0.62992, -0.62992, -1, 0.62992, 0.62992, 1] +bounds = [-pitch/2, -pitch/2, -1, pitch/2, pitch/2, 1] uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:], only_fissionable=True) -settings_file.source = openmc.source.Source(space=uniform_dist) +settings.source = openmc.source.Source(space=uniform_dist) entropy_mesh = openmc.RegularMesh() -entropy_mesh.lower_left = [-0.39218, -0.39218, -1.e50] -entropy_mesh.upper_right = [0.39218, 0.39218, 1.e50] -entropy_mesh.dimension = [10, 10, 1] -settings_file.entropy_mesh = entropy_mesh -settings_file.export_to_xml() +entropy_mesh.lower_left = (-fuel_or.r, -fuel_or.r) +entropy_mesh.upper_right = (fuel_or.r, fuel_or.r) +entropy_mesh.dimension = (10, 10) +settings.entropy_mesh = entropy_mesh +settings.export_to_xml() ############################################################################### @@ -120,19 +97,19 @@ settings_file.export_to_xml() # Instantiate a tally mesh mesh = openmc.RegularMesh() -mesh.dimension = [100, 100, 1] -mesh.lower_left = [-0.62992, -0.62992, -1.e50] -mesh.upper_right = [0.62992, 0.62992, 1.e50] +mesh.dimension = (100, 100) +mesh.lower_left = (-pitch/2, -pitch/2) +mesh.upper_right = (pitch/2, pitch/2) # Instantiate some tally Filters -energy_filter = openmc.EnergyFilter([0., 4., 20.e6]) +energy_filter = openmc.EnergyFilter((0., 4., 20.e6)) mesh_filter = openmc.MeshFilter(mesh) # Instantiate the Tally -tally = openmc.Tally(tally_id=1, name='tally 1') +tally = openmc.Tally() tally.filters = [energy_filter, mesh_filter] tally.scores = ['flux', 'fission', 'nu-fission'] # Instantiate a Tallies collection and export to XML -tallies_file = openmc.Tallies([tally]) -tallies_file.export_to_xml() +tallies = openmc.Tallies([tally]) +tallies.export_to_xml() diff --git a/openmc/settings.py b/openmc/settings.py index 794c97b618..cddef9255f 100644 --- a/openmc/settings.py +++ b/openmc/settings.py @@ -612,10 +612,6 @@ class Settings(object): @entropy_mesh.setter def entropy_mesh(self, entropy): cv.check_type('entropy mesh', entropy, RegularMesh) - if entropy.dimension: - cv.check_length('entropy mesh dimension', entropy.dimension, 3) - cv.check_length('entropy mesh lower-left corner', entropy.lower_left, 3) - cv.check_length('entropy mesh upper-right corner', entropy.upper_right, 3) self._entropy_mesh = entropy @trigger_active.setter From eeb7925376dda670e2ed2e301c63c7bce9014a8e Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Sat, 15 Feb 2020 11:40:25 -0600 Subject: [PATCH 02/14] Remove basic and boxes examples --- examples/python/basic/build-xml.py | 121 ---------------------------- examples/python/boxes/build-xml.py | 125 ----------------------------- examples/xml/basic/geometry.xml | 15 ---- examples/xml/basic/materials.xml | 16 ---- examples/xml/basic/settings.xml | 16 ---- examples/xml/basic/tallies.xml | 31 ------- examples/xml/boxes/geometry.xml | 39 --------- examples/xml/boxes/materials.xml | 21 ----- examples/xml/boxes/plots.xml | 9 --- examples/xml/boxes/settings.xml | 15 ---- 10 files changed, 408 deletions(-) delete mode 100644 examples/python/basic/build-xml.py delete mode 100644 examples/python/boxes/build-xml.py delete mode 100644 examples/xml/basic/geometry.xml delete mode 100644 examples/xml/basic/materials.xml delete mode 100644 examples/xml/basic/settings.xml delete mode 100644 examples/xml/basic/tallies.xml delete mode 100644 examples/xml/boxes/geometry.xml delete mode 100644 examples/xml/boxes/materials.xml delete mode 100644 examples/xml/boxes/plots.xml delete mode 100644 examples/xml/boxes/settings.xml diff --git a/examples/python/basic/build-xml.py b/examples/python/basic/build-xml.py deleted file mode 100644 index 5caed28104..0000000000 --- a/examples/python/basic/build-xml.py +++ /dev/null @@ -1,121 +0,0 @@ -import openmc - - -############################################################################### -# Simulation Input File Parameters -############################################################################### - -# OpenMC simulation parameters -batches = 15 -inactive = 5 -particles = 10000 - - -############################################################################### -# Exporting to OpenMC materials.xml file -############################################################################### - -# Instantiate some Materials and register the appropriate Nuclides -moderator = openmc.Material(material_id=41, name='moderator') -moderator.set_density('g/cc', 1.0) -moderator.add_element('H', 2.) -moderator.add_element('O', 1.) -moderator.add_s_alpha_beta('c_H_in_H2O') - -fuel = openmc.Material(material_id=40, name='fuel') -fuel.set_density('g/cc', 4.5) -fuel.add_nuclide('U235', 1.) - -# Instantiate a Materials collection and export to XML -materials_file = openmc.Materials([moderator, fuel]) -materials_file.export_to_xml() - - -############################################################################### -# Exporting to OpenMC geometry.xml file -############################################################################### - -# Instantiate ZCylinder surfaces -surf1 = openmc.ZCylinder(surface_id=1, x0=0, y0=0, r=7, name='surf 1') -surf2 = openmc.ZCylinder(surface_id=2, x0=0, y0=0, r=9, name='surf 2') -surf3 = openmc.ZCylinder(surface_id=3, x0=0, y0=0, r=11, name='surf 3') -surf3.boundary_type = 'vacuum' - -# Instantiate Cells -cell1 = openmc.Cell(cell_id=1, name='cell 1') -cell2 = openmc.Cell(cell_id=100, name='cell 2') -cell3 = openmc.Cell(cell_id=101, name='cell 3') -cell4 = openmc.Cell(cell_id=2, name='cell 4') - -# Use surface half-spaces to define regions -cell1.region = -surf2 -cell2.region = -surf1 -cell3.region = +surf1 -cell4.region = +surf2 & -surf3 - -# Register Materials with Cells -cell2.fill = fuel -cell3.fill = moderator -cell4.fill = moderator - -# Instantiate Universes -universe1 = openmc.Universe(universe_id=37) -root = openmc.Universe(universe_id=0, name='root universe') -cell1.fill = universe1 - -# Register Cells with Universes -universe1.add_cells([cell2, cell3]) -root.add_cells([cell1, cell4]) - -# Instantiate a Geometry, register the root Universe, and export to XML -geometry = openmc.Geometry(root) -geometry.export_to_xml() - - -############################################################################### -# Exporting to OpenMC settings.xml file -############################################################################### - -# Instantiate a Settings object, set all runtime parameters, and export to XML -settings_file = openmc.Settings() -settings_file.batches = batches -settings_file.inactive = inactive -settings_file.particles = particles - -# Create an initial uniform spatial source distribution over fissionable zones -bounds = [-4., -4., -4., 4., 4., 4.] -uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:], only_fissionable=True) -settings_file.source = openmc.source.Source(space=uniform_dist) - -settings_file.export_to_xml() - - -############################################################################### -# Exporting to OpenMC tallies.xml file -############################################################################### - -# Instantiate some tally Filters -cell_filter = openmc.CellFilter(cell2) -energy_filter = openmc.EnergyFilter([0., 20.e6]) -energyout_filter = openmc.EnergyoutFilter([0., 20.e6]) - -# Instantiate the first Tally -first_tally = openmc.Tally(tally_id=1, name='first tally') -first_tally.filters = [cell_filter] -scores = ['total', 'scatter', 'nu-scatter', - 'absorption', 'fission', 'nu-fission'] -first_tally.scores = scores - -# Instantiate the second Tally -second_tally = openmc.Tally(tally_id=2, name='second tally') -second_tally.filters = [cell_filter, energy_filter] -second_tally.scores = scores - -# Instantiate the third Tally -third_tally = openmc.Tally(tally_id=3, name='third tally') -third_tally.filters = [cell_filter, energy_filter, energyout_filter] -third_tally.scores = ['scatter', 'nu-scatter', 'nu-fission'] - -# Instantiate a Tallies collection and export to XML -tallies_file = openmc.Tallies((first_tally, second_tally, third_tally)) -tallies_file.export_to_xml() diff --git a/examples/python/boxes/build-xml.py b/examples/python/boxes/build-xml.py deleted file mode 100644 index d04f0f67a3..0000000000 --- a/examples/python/boxes/build-xml.py +++ /dev/null @@ -1,125 +0,0 @@ -import numpy as np -import openmc - -############################################################################### -# Simulation Input File Parameters -############################################################################### - -# OpenMC simulation parameters -batches = 15 -inactive = 5 -particles = 10000 - - -############################################################################### -# Exporting to OpenMC materials.xml File -############################################################################### - -# Instantiate some Materials and register the appropriate Nuclides -fuel1 = openmc.Material(material_id=1, name='fuel') -fuel1.set_density('g/cc', 4.5) -fuel1.add_nuclide('U235', 1.) - -fuel2 = openmc.Material(material_id=2, name='depleted fuel') -fuel2.set_density('g/cc', 4.5) -fuel2.add_nuclide('U238', 1.) - -moderator = openmc.Material(material_id=3, name='moderator') -moderator.set_density('g/cc', 1.0) -moderator.add_element('H', 2.) -moderator.add_element('O', 1.) -moderator.add_s_alpha_beta('c_H_in_H2O') - -# Instantiate a Materials collection and export to XML -materials_file = openmc.Materials([fuel1, fuel2, moderator]) -materials_file.export_to_xml() - - -############################################################################### -# Exporting to OpenMC geometry.xml file -############################################################################### - -# Instantiate planar surfaces -x1 = openmc.XPlane(surface_id=1, x0=-10) -x2 = openmc.XPlane(surface_id=2, x0=-7) -x3 = openmc.XPlane(surface_id=3, x0=-4) -x4 = openmc.XPlane(surface_id=4, x0=4) -x5 = openmc.XPlane(surface_id=5, x0=7) -x6 = openmc.XPlane(surface_id=6, x0=10) -y1 = openmc.YPlane(surface_id=11, y0=-10) -y2 = openmc.YPlane(surface_id=12, y0=-7) -y3 = openmc.YPlane(surface_id=13, y0=-4) -y4 = openmc.YPlane(surface_id=14, y0=4) -y5 = openmc.YPlane(surface_id=15, y0=7) -y6 = openmc.YPlane(surface_id=16, y0=10) -z1 = openmc.ZPlane(surface_id=21, z0=-10) -z2 = openmc.ZPlane(surface_id=22, z0=-7) -z3 = openmc.ZPlane(surface_id=23, z0=-4) -z4 = openmc.ZPlane(surface_id=24, z0=4) -z5 = openmc.ZPlane(surface_id=25, z0=7) -z6 = openmc.ZPlane(surface_id=26, z0=10) - -# Set vacuum boundary conditions on outside -for surface in [x1, x6, y1, y6, z1, z6]: - surface.boundary_type = 'vacuum' - -# Instantiate Cells -inner_box = openmc.Cell(cell_id=1, name='inner box') -middle_box = openmc.Cell(cell_id=2, name='middle box') -outer_box = openmc.Cell(cell_id=3, name='outer box') - -# Use each set of six planes to create solid cube regions. We can then use these -# to create cubic shells. -inner_cube = +x3 & -x4 & +y3 & -y4 & +z3 & -z4 -middle_cube = +x2 & -x5 & +y2 & -y5 & +z2 & -z5 -outer_cube = +x1 & -x6 & +y1 & -y6 & +z1 & -z6 -outside_inner_cube = -x3 | +x4 | -y3 | +y4 | -z3 | +z4 - -# Use surface half-spaces to define regions -inner_box.region = inner_cube -middle_box.region = middle_cube & outside_inner_cube -outer_box.region = outer_cube & ~middle_cube - -# Register Materials with Cells -inner_box.fill = fuel1 -middle_box.fill = fuel2 -outer_box.fill = moderator - -# Instantiate root universe -root = openmc.Universe(universe_id=0, name='root universe') -root.add_cells([inner_box, middle_box, outer_box]) - -# Instantiate a Geometry, register the root Universe, and export to XML -geometry = openmc.Geometry(root) -geometry.export_to_xml() - - -############################################################################### -# Exporting to OpenMC settings.xml File -############################################################################### - -# Instantiate a Settings object, set all runtime parameters, and export to XML -settings_file = openmc.Settings() -settings_file.batches = batches -settings_file.inactive = inactive -settings_file.particles = particles - -# Create an initial uniform spatial source distribution over fissionable zones -uniform_dist = openmc.stats.Box(*outer_cube.bounding_box, only_fissionable=True) -settings_file.source = openmc.source.Source(space=uniform_dist) - -settings_file.export_to_xml() - -############################################################################### -# Exporting to OpenMC plots.xml File -############################################################################### - -plot = openmc.Plot(plot_id=1) -plot.origin = [0, 0, 0] -plot.width = [20, 20] -plot.pixels = [200, 200] -plot.color_by = 'cell' - -# Instantiate a Plots collection and export to XML -plot_file = openmc.Plots([plot]) -plot_file.export_to_xml() diff --git a/examples/xml/basic/geometry.xml b/examples/xml/basic/geometry.xml deleted file mode 100644 index b30884f8ca..0000000000 --- a/examples/xml/basic/geometry.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/examples/xml/basic/materials.xml b/examples/xml/basic/materials.xml deleted file mode 100644 index 606c676df8..0000000000 --- a/examples/xml/basic/materials.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/examples/xml/basic/settings.xml b/examples/xml/basic/settings.xml deleted file mode 100644 index 6e622b6cef..0000000000 --- a/examples/xml/basic/settings.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - eigenvalue - 15 - 5 - 10000 - - - - - -4 -4 -4 4 4 4 - - - - diff --git a/examples/xml/basic/tallies.xml b/examples/xml/basic/tallies.xml deleted file mode 100644 index a125e9ca2a..0000000000 --- a/examples/xml/basic/tallies.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - 100 - - - - 0 20.0e6 - - - - 0 20.0e6 - - - - 1 - total scatter nu-scatter absorption fission nu-fission - - - - 1 2 - total scatter nu-scatter absorption fission nu-fission - - - - 1 2 3 - scatter nu-scatter nu-fission - - - diff --git a/examples/xml/boxes/geometry.xml b/examples/xml/boxes/geometry.xml deleted file mode 100644 index abe4924e66..0000000000 --- a/examples/xml/boxes/geometry.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/xml/boxes/materials.xml b/examples/xml/boxes/materials.xml deleted file mode 100644 index 1d0ab4a1ca..0000000000 --- a/examples/xml/boxes/materials.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/xml/boxes/plots.xml b/examples/xml/boxes/plots.xml deleted file mode 100644 index 0a75f574eb..0000000000 --- a/examples/xml/boxes/plots.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - cell - 0. 0. 0. - 20. 20. - 200 200 - - diff --git a/examples/xml/boxes/settings.xml b/examples/xml/boxes/settings.xml deleted file mode 100644 index 9007a12c59..0000000000 --- a/examples/xml/boxes/settings.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - eigenvalue - 15 - 5 - 10000 - - - - - - - From e77ce2c0df97100afe59a04c6dc57820316f1925 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Sat, 15 Feb 2020 16:36:33 -0600 Subject: [PATCH 03/14] Add jezebel example --- examples/python/jezebel/jezebel.py | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 examples/python/jezebel/jezebel.py diff --git a/examples/python/jezebel/jezebel.py b/examples/python/jezebel/jezebel.py new file mode 100644 index 0000000000..5114ac714d --- /dev/null +++ b/examples/python/jezebel/jezebel.py @@ -0,0 +1,33 @@ +import openmc + +# Create plutonium metal material +pu = openmc.Material() +pu.set_density('sum') +pu.add_nuclide('Pu239', 3.7047e-02) +pu.add_nuclide('Pu240', 1.7512e-03) +pu.add_nuclide('Pu241', 1.1674e-04) +pu.add_element('Ga', 1.3752e-03) +mats = openmc.Materials([pu]) +mats.export_to_xml() + +# Create a single cell filled with the Pu metal +sphere = openmc.Sphere(r=6.3849, boundary_type='vacuum') +cell = openmc.Cell(fill=pu, region=-sphere) +geom = openmc.Geometry([cell]) +geom.export_to_xml() + +# Finally, define some run settings +settings = openmc.Settings() +settings.batches = 200 +settings.inactive = 10 +settings.particles = 10000 +settings.export_to_xml() + +# Run the simulation +openmc.run() + +# Get the resulting k-effective value +n = settings.batches +with openmc.StatePoint(f'statepoint.{n}.h5') as sp: + keff = sp.k_combined + print(f'Final k-effective = {keff}') From 241c359f80498d334eefdf8b6cbb647c6fee0f3a Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 13 Mar 2020 13:59:15 -0500 Subject: [PATCH 04/14] Update pincell example adding flux spectrum tally and associated plotting script --- examples/python/pincell/build-xml.py | 73 ++++++++++++------------ examples/python/pincell/plot_spectrum.py | 23 ++++++++ 2 files changed, 58 insertions(+), 38 deletions(-) create mode 100644 examples/python/pincell/plot_spectrum.py diff --git a/examples/python/pincell/build-xml.py b/examples/python/pincell/build-xml.py index dc6df91631..c5d614ea90 100644 --- a/examples/python/pincell/build-xml.py +++ b/examples/python/pincell/build-xml.py @@ -1,21 +1,11 @@ +from math import log10 + +import numpy as np import openmc ############################################################################### -# Simulation Input File Parameters -############################################################################### +# Create materials for the problem -# OpenMC simulation parameters -batches = 100 -inactive = 10 -particles = 1000 - - -############################################################################### -# Exporting to OpenMC materials.xml file -############################################################################### - - -# Instantiate some Materials and register the appropriate Nuclides uo2 = openmc.Material(name='UO2 fuel at 2.4% wt enrichment') uo2.set_density('g/cm3', 10.29769) uo2.add_element('U', 1., enrichment=2.4) @@ -39,14 +29,12 @@ borated_water.add_element('H', 5.0e-2) borated_water.add_element('O', 2.4e-2) borated_water.add_s_alpha_beta('c_H_in_H2O') -# Instantiate a Materials collection and export to XML +# Collect the materials together and export to XML materials = openmc.Materials([uo2, helium, zircaloy, borated_water]) materials.export_to_xml() - -############################################################################### -# Exporting to OpenMC geometry.xml file ############################################################################### +# Define problem geometry # Create cylindrical surfaces fuel_or = openmc.ZCylinder(r=0.39218, name='Fuel OR') @@ -67,22 +55,23 @@ water = openmc.Cell(fill=borated_water, region=+clad_or & box) geometry = openmc.Geometry([fuel, gap, clad, water]) geometry.export_to_xml() - -############################################################################### -# Exporting to OpenMC settings.xml file ############################################################################### +# Define problem settings -# Instantiate a Settings object, set all runtime parameters, and export to XML +# Indicate how many particles to run settings = openmc.Settings() -settings.batches = batches -settings.inactive = inactive -settings.particles = particles +settings.batches = 100 +settings.inactive = 10 +settings.particles = 1000 # Create an initial uniform spatial source distribution over fissionable zones -bounds = [-pitch/2, -pitch/2, -1, pitch/2, pitch/2, 1] -uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:], only_fissionable=True) +lower_left = (-pitch/2, -pitch/2, -1) +upper_right = (pitch/2, pitch/2, 1) +uniform_dist = openmc.stats.Box(lower_left, upper_right, only_fissionable=True) settings.source = openmc.source.Source(space=uniform_dist) +# For source convergence checks, add a mesh that can be used to calculate the +# Shannon entropy entropy_mesh = openmc.RegularMesh() entropy_mesh.lower_left = (-fuel_or.r, -fuel_or.r) entropy_mesh.upper_right = (fuel_or.r, fuel_or.r) @@ -90,26 +79,34 @@ entropy_mesh.dimension = (10, 10) settings.entropy_mesh = entropy_mesh settings.export_to_xml() - -############################################################################### -# Exporting to OpenMC tallies.xml file ############################################################################### +# Define tallies -# Instantiate a tally mesh +# Create a mesh that will be used for tallying mesh = openmc.RegularMesh() mesh.dimension = (100, 100) mesh.lower_left = (-pitch/2, -pitch/2) mesh.upper_right = (pitch/2, pitch/2) -# Instantiate some tally Filters -energy_filter = openmc.EnergyFilter((0., 4., 20.e6)) +# Create a mesh filter that can be used in a tally mesh_filter = openmc.MeshFilter(mesh) -# Instantiate the Tally -tally = openmc.Tally() -tally.filters = [energy_filter, mesh_filter] -tally.scores = ['flux', 'fission', 'nu-fission'] +# Now use the mesh filter in a tally and indicate what scores are desired +mesh_tally = openmc.Tally(name="Mesh tally") +mesh_tally.filters = [mesh_filter] +mesh_tally.scores = ['flux', 'fission', 'nu-fission'] + +# Let's also create a tally to get the flux energy spectrum. We start by +# creating an energy filter +e_min, e_max = 1e-5, 20.0e6 +groups = 500 +energies = np.logspace(log10(e_min), log10(e_max), groups + 1) +energy_filter = openmc.EnergyFilter(energies) + +spectrum_tally = openmc.Tally(name="Flux spectrum") +spectrum_tally.filters = [energy_filter] +spectrum_tally.scores = ['flux'] # Instantiate a Tallies collection and export to XML -tallies = openmc.Tallies([tally]) +tallies = openmc.Tallies([mesh_tally, spectrum_tally]) tallies.export_to_xml() diff --git a/examples/python/pincell/plot_spectrum.py b/examples/python/pincell/plot_spectrum.py new file mode 100644 index 0000000000..d88a6de433 --- /dev/null +++ b/examples/python/pincell/plot_spectrum.py @@ -0,0 +1,23 @@ +import matplotlib.pyplot as plt +import openmc + + +# Get results from statepoint +with openmc.StatePoint('statepoint.100.h5') as sp: + t = sp.get_tally(name="Flux spectrum") + + # Get the energies from the energy filter + energy_filter = t.filters[0] + energies = energy_filter.bins[:, 0] + + # Get the flux values + mean = t.get_values(value='mean').ravel() + uncertainty = t.get_values(value='std_dev').ravel() + +# Plot flux spectrum +fix, ax = plt.subplots() +ax.loglog(energies, mean, drawstyle='steps-post') +ax.set_xlabel('Energy [eV]') +ax.set_ylabel('Flux') +ax.grid(True, which='both') +plt.show() From 03a349916de7267a69936266737c58578cc31256 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 13 Mar 2020 14:01:07 -0500 Subject: [PATCH 05/14] Remove reflective example --- examples/python/reflective/build-xml.py | 82 ------------------------- examples/xml/reflective/geometry.xml | 19 ------ examples/xml/reflective/materials.xml | 9 --- examples/xml/reflective/settings.xml | 17 ----- 4 files changed, 127 deletions(-) delete mode 100644 examples/python/reflective/build-xml.py delete mode 100644 examples/xml/reflective/geometry.xml delete mode 100644 examples/xml/reflective/materials.xml delete mode 100644 examples/xml/reflective/settings.xml diff --git a/examples/python/reflective/build-xml.py b/examples/python/reflective/build-xml.py deleted file mode 100644 index 09fa026263..0000000000 --- a/examples/python/reflective/build-xml.py +++ /dev/null @@ -1,82 +0,0 @@ -import numpy as np -import openmc - -############################################################################### -# Simulation Input File Parameters -############################################################################### - -# OpenMC simulation parameters -batches = 500 -inactive = 10 -particles = 10000 - - -############################################################################### -# Exporting to OpenMC materials.xml file -############################################################################### - -# Instantiate a Material and register the Nuclide -fuel = openmc.Material(material_id=1, name='fuel') -fuel.set_density('g/cc', 4.5) -fuel.add_nuclide('U235', 1.) - -# Instantiate a Materials collection and export to XML -materials_file = openmc.Materials([fuel]) -materials_file.export_to_xml() - - -############################################################################### -# Exporting to OpenMC geometry.xml file -############################################################################### - -# Instantiate Surfaces -surf1 = openmc.XPlane(surface_id=1, x0=-1, name='surf 1') -surf2 = openmc.XPlane(surface_id=2, x0=+1, name='surf 2') -surf3 = openmc.YPlane(surface_id=3, y0=-1, name='surf 3') -surf4 = openmc.YPlane(surface_id=4, y0=+1, name='surf 4') -surf5 = openmc.ZPlane(surface_id=5, z0=-1, name='surf 5') -surf6 = openmc.ZPlane(surface_id=6, z0=+1, name='surf 6') - -surf1.boundary_type = 'vacuum' -surf2.boundary_type = 'vacuum' -surf3.boundary_type = 'reflective' -surf4.boundary_type = 'reflective' -surf5.boundary_type = 'reflective' -surf6.boundary_type = 'reflective' - -# Instantiate Cell -cell = openmc.Cell(cell_id=1, name='cell 1') - -# Use surface half-spaces to define region -cell.region = +surf1 & -surf2 & +surf3 & -surf4 & +surf5 & -surf6 - -# Register Material with Cell -cell.fill = fuel - -# Instantiate Universes -root = openmc.Universe(universe_id=0, name='root universe') - -# Register Cell with Universe -root.add_cell(cell) - -# Instantiate a Geometry, register the root Universe, and export to XML -geometry = openmc.Geometry(root) -geometry.export_to_xml() - - -############################################################################### -# Exporting to OpenMC settings.xml file -############################################################################### - -# Instantiate a Settings object, set all runtime parameters, and export to XML -settings_file = openmc.Settings() -settings_file.batches = batches -settings_file.inactive = inactive -settings_file.particles = particles - -# Create an initial uniform spatial source distribution over fissionable zones -uniform_dist = openmc.stats.Box(*cell.region.bounding_box, - only_fissionable=True) -settings_file.source = openmc.source.Source(space=uniform_dist) - -settings_file.export_to_xml() diff --git a/examples/xml/reflective/geometry.xml b/examples/xml/reflective/geometry.xml deleted file mode 100644 index 51cdf1ecb0..0000000000 --- a/examples/xml/reflective/geometry.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - 0 - 1 - 1 -2 3 -4 5 -6 - - - - - - - - - - - diff --git a/examples/xml/reflective/materials.xml b/examples/xml/reflective/materials.xml deleted file mode 100644 index 2472a74717..0000000000 --- a/examples/xml/reflective/materials.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/examples/xml/reflective/settings.xml b/examples/xml/reflective/settings.xml deleted file mode 100644 index 0ae6e5623b..0000000000 --- a/examples/xml/reflective/settings.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - eigenvalue - 500 - 10 - 10000 - - - - - -1 -1 -1 1 1 1 - - - - From ad269469ac5ff77e075e2ab0c599a4e219a4e783 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 13 Mar 2020 14:10:59 -0500 Subject: [PATCH 06/14] Update multigroup example --- .../python/pincell_multigroup/build-xml.py | 131 +++++++----------- 1 file changed, 53 insertions(+), 78 deletions(-) diff --git a/examples/python/pincell_multigroup/build-xml.py b/examples/python/pincell_multigroup/build-xml.py index bb9fc78606..1f34683919 100644 --- a/examples/python/pincell_multigroup/build-xml.py +++ b/examples/python/pincell_multigroup/build-xml.py @@ -1,20 +1,12 @@ +from math import log10 + import numpy as np import openmc import openmc.mgxs ############################################################################### -# Simulation Input File Parameters -############################################################################### - -# OpenMC simulation parameters -batches = 100 -inactive = 10 -particles = 1000 - -############################################################################### -# Exporting to OpenMC mgxs.h5 file -############################################################################### +# Create multigroup data # Instantiate the energy group data groups = openmc.mgxs.EnergyGroups(group_edges=[ @@ -69,107 +61,90 @@ mg_cross_sections_file = openmc.MGXSLibrary(groups) mg_cross_sections_file.add_xsdatas([uo2_xsdata, h2o_xsdata]) mg_cross_sections_file.export_to_hdf5() - -############################################################################### -# Exporting to OpenMC materials.xml file ############################################################################### +# Create materials for the problem # Instantiate some Macroscopic Data uo2_data = openmc.Macroscopic('UO2') h2o_data = openmc.Macroscopic('LWTR') # Instantiate some Materials and register the appropriate Macroscopic objects -uo2 = openmc.Material(material_id=1, name='UO2 fuel') +uo2 = openmc.Material(name='UO2 fuel') uo2.set_density('macro', 1.0) uo2.add_macroscopic(uo2_data) -water = openmc.Material(material_id=2, name='Water') +water = openmc.Material(name='Water') water.set_density('macro', 1.0) water.add_macroscopic(h2o_data) # Instantiate a Materials collection and export to XML materials_file = openmc.Materials([uo2, water]) -materials_file.cross_sections = "./mgxs.h5" +materials_file.cross_sections = "mgxs.h5" materials_file.export_to_xml() - -############################################################################### -# Exporting to OpenMC geometry.xml file ############################################################################### +# Define problem geometry -# Instantiate ZCylinder surfaces -fuel_or = openmc.ZCylinder(surface_id=1, x0=0, y0=0, r=0.54, name='Fuel OR') -left = openmc.XPlane(surface_id=4, x0=-0.63, name='left') -right = openmc.XPlane(surface_id=5, x0=0.63, name='right') -bottom = openmc.YPlane(surface_id=6, y0=-0.63, name='bottom') -top = openmc.YPlane(surface_id=7, y0=0.63, name='top') +# Create a surface for the fuel outer radius +fuel_or = openmc.ZCylinder(r=0.54, name='Fuel OR') -left.boundary_type = 'reflective' -right.boundary_type = 'reflective' -top.boundary_type = 'reflective' -bottom.boundary_type = 'reflective' +# Create a region represented as the inside of a rectangular prism +pitch = 1.26 +box = openmc.rectangular_prism(pitch, pitch, boundary_type='reflective') # Instantiate Cells -fuel = openmc.Cell(cell_id=1, name='cell 1') -moderator = openmc.Cell(cell_id=2, name='cell 2') +fuel = openmc.Cell(fill=uo2, region=-fuel_or, name='fuel') +moderator = openmc.Cell(fill=water, region=+fuel_or & box, name='moderator') -# Use surface half-spaces to define regions -fuel.region = -fuel_or -moderator.region = +fuel_or & +left & -right & +bottom & -top - -# Register Materials with Cells -fuel.fill = uo2 -moderator.fill = water - -# Instantiate Universe -root = openmc.Universe(universe_id=0, name='root universe') - -# Register Cells with Universe -root.add_cells([fuel, moderator]) - -# Instantiate a Geometry, register the root Universe, and export to XML -geometry = openmc.Geometry(root) +# Create a geometry with the two cells and export to XML +geometry = openmc.Geometry([fuel, moderator]) geometry.export_to_xml() - -############################################################################### -# Exporting to OpenMC settings.xml file ############################################################################### +# Define problem settings # Instantiate a Settings object, set all runtime parameters, and export to XML -settings_file = openmc.Settings() -settings_file.energy_mode = "multi-group" -settings_file.batches = batches -settings_file.inactive = inactive -settings_file.particles = particles +settings = openmc.Settings() +settings.energy_mode = "multi-group" +settings.batches = 100 +settings.inactive = 10 +settings.particles = 1000 # Create an initial uniform spatial source distribution over fissionable zones -bounds = [-0.63, -0.63, -1, 0.63, 0.63, 1] -uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:]) -settings_file.source = openmc.source.Source(space=uniform_dist) - -settings_file.export_to_xml() +lower_left = (-pitch/2, -pitch/2, -1) +upper_right = (pitch/2, pitch/2, 1) +uniform_dist = openmc.stats.Box(lower_left, upper_right, only_fissionable=True) +settings.source = openmc.source.Source(space=uniform_dist) +settings.export_to_xml() ############################################################################### -# Exporting to OpenMC tallies.xml file -############################################################################### +# Define tallies -# Instantiate a tally mesh -mesh = openmc.RegularMesh(mesh_id=1) -mesh.dimension = [100, 100, 1] -mesh.lower_left = [-0.63, -0.63, -1.e50] -mesh.upper_right = [0.63, 0.63, 1.e50] +# Create a mesh that will be used for tallying +mesh = openmc.RegularMesh() +mesh.dimension = (100, 100) +mesh.lower_left = (-pitch/2, -pitch/2) +mesh.upper_right = (pitch/2, pitch/2) -# Instantiate some tally Filters -energy_filter = openmc.EnergyFilter([1e-5, 0.0635, 10.0, 1.0e2, 1.0e3, 0.5e6, - 1.0e6, 20.0e6]) +# Create a mesh filter that can be used in a tally mesh_filter = openmc.MeshFilter(mesh) -# Instantiate the Tally -tally = openmc.Tally(tally_id=1, name='tally 1') -tally.filters = [energy_filter, mesh_filter] -tally.scores = ['flux', 'fission', 'nu-fission'] +# Now use the mesh filter in a tally and indicate what scores are desired +mesh_tally = openmc.Tally(name="Mesh tally") +mesh_tally.filters = [mesh_filter] +mesh_tally.scores = ['flux', 'fission', 'nu-fission'] -# Instantiate a Tallies collection, register all Tallies, and export to XML -tallies_file = openmc.Tallies([tally]) -tallies_file.export_to_xml() +# Let's also create a tally to get the flux energy spectrum. We start by +# creating an energy filter +e_min, e_max = 1e-5, 20.0e6 +groups = 500 +energies = np.logspace(log10(e_min), log10(e_max), groups + 1) +energy_filter = openmc.EnergyFilter(energies) + +spectrum_tally = openmc.Tally(name="Flux spectrum") +spectrum_tally.filters = [energy_filter] +spectrum_tally.scores = ['flux'] + +# Instantiate a Tallies collection and export to XML +tallies = openmc.Tallies([mesh_tally, spectrum_tally]) +tallies.export_to_xml() From aba1c4a16d7d9df1ec454c6aa8cc357727524fd3 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 13 Mar 2020 16:13:53 -0500 Subject: [PATCH 07/14] Add Python version of custom_source --- examples/python/custom_source/CMakeLists.txt | 8 +++++ examples/python/custom_source/build_xml.py | 36 +++++++++++++++++++ examples/python/custom_source/show_flux.py | 18 ++++++++++ examples/python/custom_source/source_ring.cpp | 26 ++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 examples/python/custom_source/CMakeLists.txt create mode 100644 examples/python/custom_source/build_xml.py create mode 100644 examples/python/custom_source/show_flux.py create mode 100644 examples/python/custom_source/source_ring.cpp diff --git a/examples/python/custom_source/CMakeLists.txt b/examples/python/custom_source/CMakeLists.txt new file mode 100644 index 0000000000..9498176944 --- /dev/null +++ b/examples/python/custom_source/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.3 FATAL_ERROR) +project(openmc_sources CXX) +add_library(source SHARED source_ring.cpp) +find_package(OpenMC REQUIRED) +if (OpenMC_FOUND) + message(STATUS "Found OpenMC: ${OpenMC_DIR}") +endif() +target_link_libraries(source OpenMC::libopenmc) diff --git a/examples/python/custom_source/build_xml.py b/examples/python/custom_source/build_xml.py new file mode 100644 index 0000000000..a0817d4223 --- /dev/null +++ b/examples/python/custom_source/build_xml.py @@ -0,0 +1,36 @@ +import openmc + +# Create a single material +iron = openmc.Material() +iron.set_density('g/cm3', 5.0) +iron.add_element('Fe', 1.0) +mats = openmc.Materials([iron]) +mats.export_to_xml() + +# Create a 5 cm x 5 cm box filled with iron +box = openmc.model.rectangular_prism(10.0, 10.0, boundary_type='vacuum') +cell = openmc.Cell(fill=iron, region=box) +geometry = openmc.Geometry([cell]) +geometry.export_to_xml() + +# Tell OpenMC we're going to use our custom source +settings = openmc.Settings() +settings.run_mode = 'fixed source' +settings.batches = 10 +settings.particles = 1000 +source = openmc.Source() +source.library = 'build/libsource.so' +settings.source = source +settings.export_to_xml() + +# Finally, define a mesh tally so that we can see the resulting flux +mesh = openmc.RegularMesh() +mesh.lower_left = (-5.0, -5.0) +mesh.upper_right = (5.0, 5.0) +mesh.dimension = (50, 50) + +tally = openmc.Tally() +tally.filters = [openmc.MeshFilter(mesh)] +tally.scores = ['flux'] +tallies = openmc.Tallies([tally]) +tallies.export_to_xml() diff --git a/examples/python/custom_source/show_flux.py b/examples/python/custom_source/show_flux.py new file mode 100644 index 0000000000..9c49e1978c --- /dev/null +++ b/examples/python/custom_source/show_flux.py @@ -0,0 +1,18 @@ +import matplotlib.pyplot as plt +import openmc + +# Get the flux from the statepoint +with openmc.StatePoint('statepoint.10.h5') as sp: + flux = sp.tallies[1].mean + flux.shape = (50, 50) + +# Plot the flux +fig, ax = plt.subplots() +ax.imshow(flux, origin='lower', extent=(-5.0, 5.0, -5.0, 5.0)) +ax.set_xlabel('x [cm]') +ax.set_ylabel('y [cm]') +plt.show() + +# If all worked well, you should see a ring "imprint" as well as a higher flux +# to the right side (since the custom source has all particles moving in the +# positive x direction)) diff --git a/examples/python/custom_source/source_ring.cpp b/examples/python/custom_source/source_ring.cpp new file mode 100644 index 0000000000..d68122dd75 --- /dev/null +++ b/examples/python/custom_source/source_ring.cpp @@ -0,0 +1,26 @@ +#include // for M_PI + +#include "openmc/random_lcg.h" +#include "openmc/source.h" +#include "openmc/particle.h" + +// you must have external C linkage here otherwise +// dlopen will not find the file +extern "C" openmc::Particle::Bank sample_source(uint64_t* seed) +{ + openmc::Particle::Bank particle; + // wgt + particle.particle = openmc::Particle::Type::neutron; + particle.wgt = 1.0; + // position + double angle = 2. * M_PI * openmc::prn(seed); + double radius = 3.0; + particle.r.x = radius * std::cos(angle); + particle.r.y = radius * std::sin(angle); + particle.r.z = 0.0; + // angle + particle.u = {1.0, 0.0, 0.0}; + particle.E = 14.08e6; + particle.delayed_group = 0; + return particle; +} From 58c5130eb5e60f5b46fd4a3c30aed2da11da6236 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 13 Mar 2020 16:14:40 -0500 Subject: [PATCH 08/14] Remove examples/xml/ --- examples/xml/custom_source/CMakeLists.txt | 8 --- examples/xml/custom_source/geometry.xml | 15 ---- examples/xml/custom_source/materials.xml | 16 ----- examples/xml/custom_source/settings.xml | 14 ---- examples/xml/custom_source/source_ring.cpp | 26 ------- examples/xml/custom_source/tallies.xml | 17 ----- examples/xml/lattice/nested/geometry.xml | 43 ----------- examples/xml/lattice/nested/materials.xml | 17 ----- examples/xml/lattice/nested/plots.xml | 10 --- examples/xml/lattice/nested/settings.xml | 17 ----- examples/xml/lattice/nested/tallies.xml | 20 ------ examples/xml/lattice/simple/geometry.xml | 32 --------- examples/xml/lattice/simple/materials.xml | 17 ----- examples/xml/lattice/simple/plots.xml | 10 --- examples/xml/lattice/simple/settings.xml | 17 ----- examples/xml/lattice/simple/tallies.xml | 20 ------ examples/xml/pincell/geometry.xml | 27 ------- examples/xml/pincell/materials.xml | 67 ------------------ examples/xml/pincell/settings.xml | 32 --------- examples/xml/pincell/tallies.xml | 23 ------ examples/xml/pincell_multigroup/geometry.xml | 10 --- examples/xml/pincell_multigroup/materials.xml | 12 ---- examples/xml/pincell_multigroup/mgxs.h5 | Bin 16832 -> 0 bytes examples/xml/pincell_multigroup/plots.xml | 28 -------- examples/xml/pincell_multigroup/settings.xml | 13 ---- examples/xml/pincell_multigroup/tallies.xml | 18 ----- 26 files changed, 529 deletions(-) delete mode 100644 examples/xml/custom_source/CMakeLists.txt delete mode 100644 examples/xml/custom_source/geometry.xml delete mode 100644 examples/xml/custom_source/materials.xml delete mode 100644 examples/xml/custom_source/settings.xml delete mode 100644 examples/xml/custom_source/source_ring.cpp delete mode 100644 examples/xml/custom_source/tallies.xml delete mode 100644 examples/xml/lattice/nested/geometry.xml delete mode 100644 examples/xml/lattice/nested/materials.xml delete mode 100644 examples/xml/lattice/nested/plots.xml delete mode 100644 examples/xml/lattice/nested/settings.xml delete mode 100644 examples/xml/lattice/nested/tallies.xml delete mode 100644 examples/xml/lattice/simple/geometry.xml delete mode 100644 examples/xml/lattice/simple/materials.xml delete mode 100644 examples/xml/lattice/simple/plots.xml delete mode 100644 examples/xml/lattice/simple/settings.xml delete mode 100644 examples/xml/lattice/simple/tallies.xml delete mode 100644 examples/xml/pincell/geometry.xml delete mode 100644 examples/xml/pincell/materials.xml delete mode 100644 examples/xml/pincell/settings.xml delete mode 100644 examples/xml/pincell/tallies.xml delete mode 100644 examples/xml/pincell_multigroup/geometry.xml delete mode 100644 examples/xml/pincell_multigroup/materials.xml delete mode 100644 examples/xml/pincell_multigroup/mgxs.h5 delete mode 100644 examples/xml/pincell_multigroup/plots.xml delete mode 100644 examples/xml/pincell_multigroup/settings.xml delete mode 100644 examples/xml/pincell_multigroup/tallies.xml diff --git a/examples/xml/custom_source/CMakeLists.txt b/examples/xml/custom_source/CMakeLists.txt deleted file mode 100644 index 9498176944..0000000000 --- a/examples/xml/custom_source/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -cmake_minimum_required(VERSION 3.3 FATAL_ERROR) -project(openmc_sources CXX) -add_library(source SHARED source_ring.cpp) -find_package(OpenMC REQUIRED) -if (OpenMC_FOUND) - message(STATUS "Found OpenMC: ${OpenMC_DIR}") -endif() -target_link_libraries(source OpenMC::libopenmc) diff --git a/examples/xml/custom_source/geometry.xml b/examples/xml/custom_source/geometry.xml deleted file mode 100644 index b30884f8ca..0000000000 --- a/examples/xml/custom_source/geometry.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/examples/xml/custom_source/materials.xml b/examples/xml/custom_source/materials.xml deleted file mode 100644 index 606c676df8..0000000000 --- a/examples/xml/custom_source/materials.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/examples/xml/custom_source/settings.xml b/examples/xml/custom_source/settings.xml deleted file mode 100644 index f935ed685e..0000000000 --- a/examples/xml/custom_source/settings.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - fixed source - 10 - 0 - 100000 - - - - build/libsource.so - - - diff --git a/examples/xml/custom_source/source_ring.cpp b/examples/xml/custom_source/source_ring.cpp deleted file mode 100644 index d68122dd75..0000000000 --- a/examples/xml/custom_source/source_ring.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include // for M_PI - -#include "openmc/random_lcg.h" -#include "openmc/source.h" -#include "openmc/particle.h" - -// you must have external C linkage here otherwise -// dlopen will not find the file -extern "C" openmc::Particle::Bank sample_source(uint64_t* seed) -{ - openmc::Particle::Bank particle; - // wgt - particle.particle = openmc::Particle::Type::neutron; - particle.wgt = 1.0; - // position - double angle = 2. * M_PI * openmc::prn(seed); - double radius = 3.0; - particle.r.x = radius * std::cos(angle); - particle.r.y = radius * std::sin(angle); - particle.r.z = 0.0; - // angle - particle.u = {1.0, 0.0, 0.0}; - particle.E = 14.08e6; - particle.delayed_group = 0; - return particle; -} diff --git a/examples/xml/custom_source/tallies.xml b/examples/xml/custom_source/tallies.xml deleted file mode 100644 index 7f6f299261..0000000000 --- a/examples/xml/custom_source/tallies.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - 100 - - - - 0 20.0e6 - - - - 1 2 - flux - - - diff --git a/examples/xml/lattice/nested/geometry.xml b/examples/xml/lattice/nested/geometry.xml deleted file mode 100644 index 324f71cb36..0000000000 --- a/examples/xml/lattice/nested/geometry.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - 2 2 - -1.0 -1.0 - 1.0 1.0 - - 1 2 - 2 3 - - - - - - 2 2 - -2.0 -2.0 - 2.0 2.0 - - 5 5 - 5 5 - - - - - - - - - - - - diff --git a/examples/xml/lattice/nested/materials.xml b/examples/xml/lattice/nested/materials.xml deleted file mode 100644 index 2222721959..0000000000 --- a/examples/xml/lattice/nested/materials.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/examples/xml/lattice/nested/plots.xml b/examples/xml/lattice/nested/plots.xml deleted file mode 100644 index 0f92e06211..0000000000 --- a/examples/xml/lattice/nested/plots.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - 0. 0. 0. - 4.0 4.0 - 400 400 - - - diff --git a/examples/xml/lattice/nested/settings.xml b/examples/xml/lattice/nested/settings.xml deleted file mode 100644 index 879173d1b3..0000000000 --- a/examples/xml/lattice/nested/settings.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - eigenvalue - 20 - 10 - 10000 - - - - - -1 -1 -1 1 1 1 - - - - diff --git a/examples/xml/lattice/nested/tallies.xml b/examples/xml/lattice/nested/tallies.xml deleted file mode 100644 index d342174a99..0000000000 --- a/examples/xml/lattice/nested/tallies.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - regular - 4 4 - -2.0 -2.0 - 1.0 1.0 - - - - 1 - - - - 1 - total - - - diff --git a/examples/xml/lattice/simple/geometry.xml b/examples/xml/lattice/simple/geometry.xml deleted file mode 100644 index bda7246c79..0000000000 --- a/examples/xml/lattice/simple/geometry.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - 4 4 - -2.0 -2.0 - 1.0 1.0 - - 1 2 1 2 - 2 3 2 3 - 1 2 1 2 - 2 3 2 3 - - - - - - - - - - - - diff --git a/examples/xml/lattice/simple/materials.xml b/examples/xml/lattice/simple/materials.xml deleted file mode 100644 index 2222721959..0000000000 --- a/examples/xml/lattice/simple/materials.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/examples/xml/lattice/simple/plots.xml b/examples/xml/lattice/simple/plots.xml deleted file mode 100644 index 0f92e06211..0000000000 --- a/examples/xml/lattice/simple/plots.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - 0. 0. 0. - 4.0 4.0 - 400 400 - - - diff --git a/examples/xml/lattice/simple/settings.xml b/examples/xml/lattice/simple/settings.xml deleted file mode 100644 index 879173d1b3..0000000000 --- a/examples/xml/lattice/simple/settings.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - eigenvalue - 20 - 10 - 10000 - - - - - -1 -1 -1 1 1 1 - - - - diff --git a/examples/xml/lattice/simple/tallies.xml b/examples/xml/lattice/simple/tallies.xml deleted file mode 100644 index d342174a99..0000000000 --- a/examples/xml/lattice/simple/tallies.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - regular - 4 4 - -2.0 -2.0 - 1.0 1.0 - - - - 1 - - - - 1 - total - - - diff --git a/examples/xml/pincell/geometry.xml b/examples/xml/pincell/geometry.xml deleted file mode 100644 index f67f9e74c2..0000000000 --- a/examples/xml/pincell/geometry.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/xml/pincell/materials.xml b/examples/xml/pincell/materials.xml deleted file mode 100644 index 9f9afa3843..0000000000 --- a/examples/xml/pincell/materials.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/xml/pincell/settings.xml b/examples/xml/pincell/settings.xml deleted file mode 100644 index 5845898c8d..0000000000 --- a/examples/xml/pincell/settings.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - eigenvalue - 100 - 10 - 1000 - - - - - - -0.62992 -0.62992 -1. - 0.62992 0.62992 1. - - - - - - - -0.39218 -0.39218 -1.e50 - 0.39218 0.39218 1.e50 - 10 10 1 - - 1 - - diff --git a/examples/xml/pincell/tallies.xml b/examples/xml/pincell/tallies.xml deleted file mode 100644 index 7e1e0dafe4..0000000000 --- a/examples/xml/pincell/tallies.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - 100 100 1 - -0.62992 -0.62992 -1.e50 - 0.62992 0.62992 1.e50 - - - - 2 - - - - 0. 4. 20.0e6 - - - - 1 2 - flux fission nu-fission - - - diff --git a/examples/xml/pincell_multigroup/geometry.xml b/examples/xml/pincell_multigroup/geometry.xml deleted file mode 100644 index a1df07a9ec..0000000000 --- a/examples/xml/pincell_multigroup/geometry.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/examples/xml/pincell_multigroup/materials.xml b/examples/xml/pincell_multigroup/materials.xml deleted file mode 100644 index f0225b1009..0000000000 --- a/examples/xml/pincell_multigroup/materials.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - ./mgxs.h5 - - - - - - - - - diff --git a/examples/xml/pincell_multigroup/mgxs.h5 b/examples/xml/pincell_multigroup/mgxs.h5 deleted file mode 100644 index dbcda859da0060c21f6615feda75459062b1c384..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16832 zcmeHOdsLLi6(2y!q9_Z-W^H1E0!l1_O(3`!;DQCA;)4oQln{1><#B+8>@JF?>PAgn zbD9QU#7ZQfmTnSTH}s&`6DVyAl7mJRW6{t=QPHMNG$u{;@-^@k#!)28s^4RZ> zz4N;BxbvHP?>u%xY}BkVqkcS!@Sj9NMi8kG#Gjk&Ylx&N7{`1i3pg-pWYpwH0}ez& z_&ga)m$LdjooGT6V@zBS9Zk5BSU*z6MobUUkOUL#bXZ9sHaaq%A8;}oHR7p>;S7b5 zH2)bPIA>wv0zQDaj1W@q{l}f*Rg7y_BIni$U%v~7a0$uG$y4i>7pk#^aa_YRpQhwz z73=trD~V<45-uzwOVwIkPJxCUNtic3%7Hj`pv+AaT9QXqx{Oo6ybO7LNM$J@vm)mtM00703zB#uWT2dp z-mYJHJE2txaK(WR^OdbKu9 zm#q?v4bMOJHvW{D)RdU1sVVcd8ES1R&yRM>&4NF(K%1}9)Ao6+V1M(}S!zv&R(*@l zS+ENQe0^LwTlV0Vr^f~$A`Vj$5 zP(DtahTy~2{Kt`8c|PCK(NSQLFpc8mV07c_L2sId3GukCeog3+WI~LXH6UoHf7(Y` zU;h>^@An%&>QE!>9>4C5S04QYR&J9``D6WOkb0y1Ps+Np;GSDr_}aIv5cf_>NB-58{Ty50M!nC-n;?>Omp7#(n-^Y`mDH6(Y0Ba; z8(w-JTHpF1)_uZpczb2~j*M4VLZIU~Lv!0~_*rZ8-gh-C;OfHsT~&^oAs|_~Dm8Qy zd_P9hcrdaCqNNwlj;LyekOQAr`nGhyS2J}xW-UGqr`E20^Cd+vn2-9A37b}jTNCQV zmgkDMzq$pU`q=DPQl^A}%iDdP8(#u{IJq%&#^m3_p&K!0zLHmg$FqKwKlThg#qe>$L~USu zJGf_h|Jr<24Qn3TB5(b!9VYFX`$Y5MrBHAF*O3?UJVCyuan8;cj)9{7yThBvD-gEr zfZ7j|K)Zf!MyKO3c-Lp*1!eF?$O!OhFEYFgzl@r*!F$CqKz!nUjBRHG-+>=9bGHa{ zFF2Ib56dC7Ru0`Vq=<`yyIp+#p*#rADWgZoG^Zh9d#B;pxeoaL`TP%WRCj>#Ld)b& zuXn=9N;nnb@hy~(s=atUaAZW>wacTgzxPwP>=sy^`TCXcrVn!c%4ES%=Qn-HvgR~+ zvAn|R<#o#-+k2*0TkUTk%n-fm2k9<&WZ9Ab9Qv>dG7hK4H9b@ZnuizV`qsq2o@rmK zF}oZMkKOzJ_N#wi5nk%)Rq;3Xd@hc0O@_ah~p$ zGC0_YT>^Fq*d@><0qR$x7eq)gzp1l-_bdTx`%AH3Zfk#8@fd9y{r7wBh@D|jO91zm zW;P1p@_`Fq@}>#a&XY~-{LR1|3u}1v^{4g3%2@-9bl(@z4JDqJi~Wq=?~_W{K1pHG zf$saHVvGF#j!?bm+;#4GX=2Yk@MYN&&z{R+_O-`*E{D@2o78i;2$t_o5Q&vS!ww>+;tgGRa{g!`{m1` zedfb=^XUupsywcsYKg8uTS)KVc)rXW;l7WgXXgmjXo{Y~Bq5Id$x!K4d;;2crI6eA zKeqI-J8KeY@BKg%(?3RwK@3bk(200rFQ3G~ovDl^UzvL6d`v|>w9N-ohBmc@tM2;? zsepCyy|4BA7deBZ!a|VU@no>be^8P8FOTd&B@bKnyMZZOTsIGD-t6r@7zv2&H|p7V zcJ6__>g)GU_)bLp&Z)28?O^|Jy}P0BW`_H_9b0-q7Dy#$*9(ZC;YG!IfjN~VTjZeM z@Ao*$AS!qC&y6f@3bw?jQuKb(+Ij47nZ@pY5M9YA$KLNRDwzLcsTsQagT?_RYVm!X zg#N8yK=pAjbjI5Khj?AuvM+MBov=jFV32^lk9{Elv3)_a(!}&Swqfmj$J+UgFEU!8 z-Sr~%c>Df7&UBai#9}Kw?Vn_-7oG4@gA|AK+^#3fHqM{{v?pd3ZwaO8xUM~?Gln5f z`VUuU1_iFH*$FXDY}tuq_VN_*G{j+KAD&18VmpEQ{R-1FSRCy^U)?X*TF>}w0cr33 zX_*Hd!zCPwK)d_X1H(>uvR;}aSilOQR+W$n_K#01#n>x;LSn - - - - 1 - mat - material - 0 0 0 - 1.26 1.26 - slice - 1000 1000 - - - - - - - - 2 - cell - cell - 0 0 0 - 1.26 1.26 - slice - 1000 1000 - - - diff --git a/examples/xml/pincell_multigroup/settings.xml b/examples/xml/pincell_multigroup/settings.xml deleted file mode 100644 index 6966d02b7b..0000000000 --- a/examples/xml/pincell_multigroup/settings.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - eigenvalue - 1000 - 100 - 10 - - - -0.63 -0.63 -1 0.63 0.63 1 - - - multi-group - diff --git a/examples/xml/pincell_multigroup/tallies.xml b/examples/xml/pincell_multigroup/tallies.xml deleted file mode 100644 index d84e129f2f..0000000000 --- a/examples/xml/pincell_multigroup/tallies.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - 100 100 1 - -0.63 -0.63 -1e+50 - 0.63 0.63 1e+50 - - - 1e-05 0.0635 10.0 100.0 1000.0 500000.0 1000000.0 20000000.0 - - - 1 - - - 1 2 - flux fission nu-fission - - From 4525e3879712264b8af12e0f99ffb41e704a9d95 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 13 Mar 2020 16:15:35 -0500 Subject: [PATCH 09/14] Move Python examples into subdirectory --- examples/{python => }/custom_source/CMakeLists.txt | 0 examples/{python => }/custom_source/build_xml.py | 0 examples/{python => }/custom_source/show_flux.py | 0 examples/{python => }/custom_source/source_ring.cpp | 0 examples/{python => }/jezebel/jezebel.py | 0 examples/{python => }/lattice/hexagonal/build-xml.py | 0 examples/{python => }/lattice/nested/build-xml.py | 0 examples/{python => }/lattice/simple/build-xml.py | 0 examples/{python => }/pincell/build-xml.py | 0 examples/{python => }/pincell/plot_spectrum.py | 0 examples/{python => }/pincell_depletion/chain_simple.xml | 0 examples/{python => }/pincell_depletion/restart_depletion.py | 0 examples/{python => }/pincell_depletion/run_depletion.py | 0 examples/{python => }/pincell_multigroup/build-xml.py | 0 14 files changed, 0 insertions(+), 0 deletions(-) rename examples/{python => }/custom_source/CMakeLists.txt (100%) rename examples/{python => }/custom_source/build_xml.py (100%) rename examples/{python => }/custom_source/show_flux.py (100%) rename examples/{python => }/custom_source/source_ring.cpp (100%) rename examples/{python => }/jezebel/jezebel.py (100%) rename examples/{python => }/lattice/hexagonal/build-xml.py (100%) rename examples/{python => }/lattice/nested/build-xml.py (100%) rename examples/{python => }/lattice/simple/build-xml.py (100%) rename examples/{python => }/pincell/build-xml.py (100%) rename examples/{python => }/pincell/plot_spectrum.py (100%) rename examples/{python => }/pincell_depletion/chain_simple.xml (100%) rename examples/{python => }/pincell_depletion/restart_depletion.py (100%) rename examples/{python => }/pincell_depletion/run_depletion.py (100%) rename examples/{python => }/pincell_multigroup/build-xml.py (100%) diff --git a/examples/python/custom_source/CMakeLists.txt b/examples/custom_source/CMakeLists.txt similarity index 100% rename from examples/python/custom_source/CMakeLists.txt rename to examples/custom_source/CMakeLists.txt diff --git a/examples/python/custom_source/build_xml.py b/examples/custom_source/build_xml.py similarity index 100% rename from examples/python/custom_source/build_xml.py rename to examples/custom_source/build_xml.py diff --git a/examples/python/custom_source/show_flux.py b/examples/custom_source/show_flux.py similarity index 100% rename from examples/python/custom_source/show_flux.py rename to examples/custom_source/show_flux.py diff --git a/examples/python/custom_source/source_ring.cpp b/examples/custom_source/source_ring.cpp similarity index 100% rename from examples/python/custom_source/source_ring.cpp rename to examples/custom_source/source_ring.cpp diff --git a/examples/python/jezebel/jezebel.py b/examples/jezebel/jezebel.py similarity index 100% rename from examples/python/jezebel/jezebel.py rename to examples/jezebel/jezebel.py diff --git a/examples/python/lattice/hexagonal/build-xml.py b/examples/lattice/hexagonal/build-xml.py similarity index 100% rename from examples/python/lattice/hexagonal/build-xml.py rename to examples/lattice/hexagonal/build-xml.py diff --git a/examples/python/lattice/nested/build-xml.py b/examples/lattice/nested/build-xml.py similarity index 100% rename from examples/python/lattice/nested/build-xml.py rename to examples/lattice/nested/build-xml.py diff --git a/examples/python/lattice/simple/build-xml.py b/examples/lattice/simple/build-xml.py similarity index 100% rename from examples/python/lattice/simple/build-xml.py rename to examples/lattice/simple/build-xml.py diff --git a/examples/python/pincell/build-xml.py b/examples/pincell/build-xml.py similarity index 100% rename from examples/python/pincell/build-xml.py rename to examples/pincell/build-xml.py diff --git a/examples/python/pincell/plot_spectrum.py b/examples/pincell/plot_spectrum.py similarity index 100% rename from examples/python/pincell/plot_spectrum.py rename to examples/pincell/plot_spectrum.py diff --git a/examples/python/pincell_depletion/chain_simple.xml b/examples/pincell_depletion/chain_simple.xml similarity index 100% rename from examples/python/pincell_depletion/chain_simple.xml rename to examples/pincell_depletion/chain_simple.xml diff --git a/examples/python/pincell_depletion/restart_depletion.py b/examples/pincell_depletion/restart_depletion.py similarity index 100% rename from examples/python/pincell_depletion/restart_depletion.py rename to examples/pincell_depletion/restart_depletion.py diff --git a/examples/python/pincell_depletion/run_depletion.py b/examples/pincell_depletion/run_depletion.py similarity index 100% rename from examples/python/pincell_depletion/run_depletion.py rename to examples/pincell_depletion/run_depletion.py diff --git a/examples/python/pincell_multigroup/build-xml.py b/examples/pincell_multigroup/build-xml.py similarity index 100% rename from examples/python/pincell_multigroup/build-xml.py rename to examples/pincell_multigroup/build-xml.py From 282001803b750ffb9008ee79dce7d18f36870565 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 13 Mar 2020 16:17:55 -0500 Subject: [PATCH 10/14] Use consistent naming on example scripts --- examples/lattice/hexagonal/{build-xml.py => build_xml.py} | 0 examples/lattice/nested/{build-xml.py => build_xml.py} | 0 examples/lattice/simple/{build-xml.py => build_xml.py} | 0 examples/pincell/{build-xml.py => build_xml.py} | 0 examples/pincell_multigroup/{build-xml.py => build_xml.py} | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename examples/lattice/hexagonal/{build-xml.py => build_xml.py} (100%) rename examples/lattice/nested/{build-xml.py => build_xml.py} (100%) rename examples/lattice/simple/{build-xml.py => build_xml.py} (100%) rename examples/pincell/{build-xml.py => build_xml.py} (100%) rename examples/pincell_multigroup/{build-xml.py => build_xml.py} (100%) diff --git a/examples/lattice/hexagonal/build-xml.py b/examples/lattice/hexagonal/build_xml.py similarity index 100% rename from examples/lattice/hexagonal/build-xml.py rename to examples/lattice/hexagonal/build_xml.py diff --git a/examples/lattice/nested/build-xml.py b/examples/lattice/nested/build_xml.py similarity index 100% rename from examples/lattice/nested/build-xml.py rename to examples/lattice/nested/build_xml.py diff --git a/examples/lattice/simple/build-xml.py b/examples/lattice/simple/build_xml.py similarity index 100% rename from examples/lattice/simple/build-xml.py rename to examples/lattice/simple/build_xml.py diff --git a/examples/pincell/build-xml.py b/examples/pincell/build_xml.py similarity index 100% rename from examples/pincell/build-xml.py rename to examples/pincell/build_xml.py diff --git a/examples/pincell_multigroup/build-xml.py b/examples/pincell_multigroup/build_xml.py similarity index 100% rename from examples/pincell_multigroup/build-xml.py rename to examples/pincell_multigroup/build_xml.py From 0d70d0ef4c8d5d1d78960b4df2e93067ffa29679 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 16 Mar 2020 10:15:16 -0500 Subject: [PATCH 11/14] Add single assembly example model --- examples/assembly/assembly.py | 140 ++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 examples/assembly/assembly.py diff --git a/examples/assembly/assembly.py b/examples/assembly/assembly.py new file mode 100644 index 0000000000..d4c8fe5b96 --- /dev/null +++ b/examples/assembly/assembly.py @@ -0,0 +1,140 @@ +""" +This script builds a single PWR assembly and is a slightly more advanced +demonstration of model building using Python. The creation of two universes for +fuel pins and guide tube pins has been separated into functions, and then the +overall model is built by an `assembly` function. This script also demonstrates +the use of the `Model` class, which provides some extra convenience over using +`Geometry`, `Materials`, and `Settings` classes directly. Finally, the script +takes two command-line flags that indicate whether to build and/or run the +model. + +""" + +import argparse +from math import log10 + +import numpy as np +import openmc + +# Define surfaces +fuel_or = openmc.ZCylinder(r=0.39218, name='Fuel OR') +clad_or = openmc.ZCylinder(r=0.45720, name='Clad OR') + +# Define materials +fuel = openmc.Material(name='Fuel') +fuel.set_density('g/cm3', 10.29769) +fuel.add_nuclide('U234', 4.4843e-6) +fuel.add_nuclide('U235', 5.5815e-4) +fuel.add_nuclide('U238', 2.2408e-2) +fuel.add_nuclide('O16', 4.5829e-2) + +clad = openmc.Material(name='Cladding') +clad.set_density('g/cm3', 6.55) +clad.add_nuclide('Zr90', 2.1827e-2) +clad.add_nuclide('Zr91', 4.7600e-3) +clad.add_nuclide('Zr92', 7.2758e-3) +clad.add_nuclide('Zr94', 7.3734e-3) +clad.add_nuclide('Zr96', 1.1879e-3) + +hot_water = openmc.Material(name='Hot borated water') +hot_water.set_density('g/cm3', 0.740582) +hot_water.add_nuclide('H1', 4.9457e-2) +hot_water.add_nuclide('O16', 2.4672e-2) +hot_water.add_nuclide('B10', 8.0042e-6) +hot_water.add_nuclide('B11', 3.2218e-5) +hot_water.add_s_alpha_beta('c_H_in_H2O') + + +def fuel_pin(): + """Returns a fuel pin universe.""" + + fuel_cell = openmc.Cell(fill=fuel, region=-fuel_or) + clad_cell = openmc.Cell(fill=clad, region=+fuel_or & -clad_or) + hot_water_cell = openmc.Cell(fill=hot_water, region=+clad_or) + + univ = openmc.Universe(name='Fuel Pin') + univ.add_cells([fuel_cell, clad_cell, hot_water_cell]) + return univ + + +def guide_tube_pin(): + """Returns a control rode guide tube pin universe""" + + gt_inner_cell = openmc.Cell(fill=hot_water, region=-fuel_or) + gt_clad_cell = openmc.Cell(fill=clad, region=+fuel_or & -clad_or) + gt_outer_cell = openmc.Cell(fill=hot_water, region=+clad_or) + + univ = openmc.Universe(name='Guide Tube') + univ.add_cells([gt_inner_cell, gt_clad_cell, gt_outer_cell]) + return univ + + +def assembly_model(): + """Returns a single PWR fuel assembly.""" + + model = openmc.model.Model() + + # Create fuel assembly Lattice + pitch = 21.42 + assembly = openmc.RectLattice(name='Fuel Assembly') + assembly.pitch = (pitch/17, pitch/17) + assembly.lower_left = (-pitch/2, -pitch/2) + + # Create array indices for guide tube locations in lattice + gt_pos = np.array([ + [2, 5], [2, 8], [2, 11], + [3, 3], [3, 13], + [5, 2], [5, 5], [5, 8], [5, 11], [5, 14], + [8, 2], [8, 5], [8, 8], [8, 11], [8, 14], + [11, 2], [11, 5], [11, 8], [11, 11], [11, 14], + [13, 3], [13, 13], + [14, 5], [14, 8], [14, 11] + ]) + + # Create 17x17 array of universes. First we create a 17x17 array all filled + # with the fuel pin universe. Then, we replace the guide tube positions with + # the guide tube pin universe (note the use of numpy fancy indexing to + # achieve this). + assembly.universes = np.full((17, 17), fuel_pin()) + assembly.universes[gt_pos[:, 0], gt_pos[:, 1]] = guide_tube_pin() + + # Create outer boundary of the geometry to surround the lattice + outer_boundary = openmc.model.rectangular_prism( + pitch, pitch, boundary_type='reflective') + + # Create a cell filled with the lattice + main_cell = openmc.Cell(fill=assembly, region=outer_boundary) + + # Finally, create geometry by giving a list of cells filling the root + # universe + model.geometry = openmc.Geometry([main_cell]) + + model.settings.batches = 150 + model.settings.inactive = 50 + model.settings.particles = 1000 + model.settings.source = openmc.Source(space=openmc.stats.Box( + (-pitch/2, -pitch/2, -1), + (pitch/2, pitch/2, 1), + only_fissionable=True + )) + + # NOTE: We never actually created a Materials object. When you export/run + # using the Model object, if no materials were assigned it will look through + # the Geometry object and automatically export any materials that are + # necessary to build the model. + return model + + +if __name__ == '__main__': + # Set up command-line arguments for generating/running the model + parser = argparse.ArgumentParser() + parser.add_argument('--generate', action='store_true') + parser.add_argument('--run', action='store_true') + args = parser.parse_args() + + if args.generate or args.run: + model = assembly_model() + if args.generate: + model.export_to_xml() + if args.run: + model.run() From c3ffc2f4172c50be1bd37a73b5c7d39ea952f7f5 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 17 Mar 2020 16:49:53 -0500 Subject: [PATCH 12/14] Apply @pshriwise suggestions from code review Co-Authored-By: Patrick Shriwise --- examples/assembly/assembly.py | 4 ++-- examples/custom_source/show_flux.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/assembly/assembly.py b/examples/assembly/assembly.py index d4c8fe5b96..31984543a6 100644 --- a/examples/assembly/assembly.py +++ b/examples/assembly/assembly.py @@ -58,7 +58,7 @@ def fuel_pin(): def guide_tube_pin(): - """Returns a control rode guide tube pin universe""" + """Returns a control rod guide tube universe.""" gt_inner_cell = openmc.Cell(fill=hot_water, region=-fuel_or) gt_clad_cell = openmc.Cell(fill=clad, region=+fuel_or & -clad_or) @@ -105,7 +105,7 @@ def assembly_model(): # Create a cell filled with the lattice main_cell = openmc.Cell(fill=assembly, region=outer_boundary) - # Finally, create geometry by giving a list of cells filling the root + # Finally, create geometry by providing a list of cells that fill the root # universe model.geometry = openmc.Geometry([main_cell]) diff --git a/examples/custom_source/show_flux.py b/examples/custom_source/show_flux.py index 9c49e1978c..bf8ee4f813 100644 --- a/examples/custom_source/show_flux.py +++ b/examples/custom_source/show_flux.py @@ -15,4 +15,4 @@ plt.show() # If all worked well, you should see a ring "imprint" as well as a higher flux # to the right side (since the custom source has all particles moving in the -# positive x direction)) +# positive x direction) From 32f5fd8854fbd9ddcc85eda37248c943d1e7f04f Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 19 Mar 2020 07:07:32 -0500 Subject: [PATCH 13/14] Add README to custom source example --- examples/custom_source/README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 examples/custom_source/README.md diff --git a/examples/custom_source/README.md b/examples/custom_source/README.md new file mode 100644 index 0000000000..9a22171ae4 --- /dev/null +++ b/examples/custom_source/README.md @@ -0,0 +1,14 @@ +# Building a Custom Source + +To run this example, you first need to compile the custom source library, which +requires headers from OpenMC. A CMakeLists.txt file has been set up for you that +will search for OpenMC and build the custom library. To build the source +library, you can run: + + mkdir build && cd build + OPENMC_ROOT= cmake .. + make + +After this, you can build the model by running `python build_xml.py`. In the XML +files that are created, you should see a reference to build/libsource.so, the +custom source library that was built by CMake. From 1e411cad525cac24b0bc646568d0920ad365a6a0 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 19 Mar 2020 13:34:49 -0500 Subject: [PATCH 14/14] Update README for custom source example, moving comment from show_flux.py --- examples/custom_source/README.md | 7 ++++++- examples/custom_source/show_flux.py | 4 ---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/custom_source/README.md b/examples/custom_source/README.md index 9a22171ae4..94db705264 100644 --- a/examples/custom_source/README.md +++ b/examples/custom_source/README.md @@ -11,4 +11,9 @@ library, you can run: After this, you can build the model by running `python build_xml.py`. In the XML files that are created, you should see a reference to build/libsource.so, the -custom source library that was built by CMake. +custom source library that was built by CMake. The model is also set up with a +mesh tally of the flux, so once you run `openmc`, you will get a statepoint file +with the tally results in it. Running `python show_flux.py` will pull in the +results from the statepoint file and display them. If all worked well, you +should see a ring "imprint" as well as a higher flux to the right side (since +the custom source has all particles moving in the positive x direction). diff --git a/examples/custom_source/show_flux.py b/examples/custom_source/show_flux.py index bf8ee4f813..6f54943018 100644 --- a/examples/custom_source/show_flux.py +++ b/examples/custom_source/show_flux.py @@ -12,7 +12,3 @@ ax.imshow(flux, origin='lower', extent=(-5.0, 5.0, -5.0, 5.0)) ax.set_xlabel('x [cm]') ax.set_ylabel('y [cm]') plt.show() - -# If all worked well, you should see a ring "imprint" as well as a higher flux -# to the right side (since the custom source has all particles moving in the -# positive x direction)