From fc0c90703044daf781b16daafd50d4bed9d5a3e7 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 6 Apr 2017 21:20:29 -0500 Subject: [PATCH] Add openmc.examples module that replaces input_set.py from tests --- docs/source/pythonapi/examples.rst | 25 + docs/source/pythonapi/index.rst | 1 + openmc/examples.py | 619 ++++++++++++++ openmc/model/model.py | 117 ++- tests/input_set.py | 798 ------------------ .../test_asymmetric_lattice.py | 28 +- tests/test_diff_tally/test_diff_tally.py | 29 +- .../test_filter_energyfun.py | 14 +- tests/test_filter_mesh/inputs_true.dat | 3 - tests/test_filter_mesh/test_filter_mesh.py | 33 +- tests/test_iso_in_lab/test_iso_in_lab.py | 19 +- tests/test_mg_basic/test_mg_basic.py | 12 +- tests/test_mg_legendre/test_mg_legendre.py | 22 +- tests/test_mg_max_order/test_mg_max_order.py | 21 +- tests/test_mg_nuclide/test_mg_nuclide.py | 17 +- .../test_mg_survival_biasing.py | 17 +- tests/test_mg_tallies/test_mg_tallies.py | 178 ++-- .../test_mgxs_library_ce_to_mg.py | 37 +- .../test_mgxs_library_condense.py | 22 +- .../test_mgxs_library_distribcell.py | 21 +- .../test_mgxs_library_hdf5.py | 48 +- .../test_mgxs_library_mesh.py | 13 +- .../test_mgxs_library_no_nuclides.py | 20 +- .../test_mgxs_library_nuclides.py | 21 +- tests/test_tallies/test_tallies.py | 330 ++++---- tests/test_tally_aggregation/inputs_true.dat | 3 - .../test_tally_aggregation.py | 19 +- tests/test_tally_arithmetic/inputs_true.dat | 3 - .../test_tally_arithmetic.py | 26 +- .../test_tally_slice_merge.py | 24 +- tests/test_triso/inputs_true.dat | 6 - tests/test_triso/plots.xml | 6 - tests/testing_harness.py | 25 +- 33 files changed, 1130 insertions(+), 1447 deletions(-) create mode 100644 docs/source/pythonapi/examples.rst create mode 100644 openmc/examples.py delete mode 100644 tests/input_set.py delete mode 100644 tests/test_triso/plots.xml diff --git a/docs/source/pythonapi/examples.rst b/docs/source/pythonapi/examples.rst new file mode 100644 index 000000000..2a3ebbd8e --- /dev/null +++ b/docs/source/pythonapi/examples.rst @@ -0,0 +1,25 @@ +---------------------------------------- +:mod:`openmc.examples` -- Example Models +---------------------------------------- + +Simple Models +------------- + +.. autosummary:: + :toctree: generated + :nosignatures: + :template: myfunction.rst + + openmc.examples.slab_mg + +Reactor Models +-------------- + +.. autosummary:: + :toctree: generated + :nosignatures: + :template: myfunction.rst + + openmc.examples.pwr_assembly + openmc.examples.pwr_core + openmc.examples.pwr_pin_cell diff --git a/docs/source/pythonapi/index.rst b/docs/source/pythonapi/index.rst index c66401e24..5492f362d 100644 --- a/docs/source/pythonapi/index.rst +++ b/docs/source/pythonapi/index.rst @@ -47,4 +47,5 @@ Modules mgxs model data + examples openmoc diff --git a/openmc/examples.py b/openmc/examples.py new file mode 100644 index 000000000..6e2a04f7f --- /dev/null +++ b/openmc/examples.py @@ -0,0 +1,619 @@ +import numpy as np + +import openmc +import openmc.model + + +def pwr_pin_cell(): + """Create a PWR pin-cell model. + + Returns + ------- + model : openmc.model.Model + A PWR pin-cell model + + """ + model = openmc.model.Model() + + # 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') + + # Define the materials file. + model.materials = (fuel, clad, hot_water) + + # Instantiate ZCylinder surfaces + pitch = 1.26 + fuel_or = openmc.ZCylinder(x0=0, y0=0, R=0.39218, name='Fuel OR') + clad_or = openmc.ZCylinder(x0=0, y0=0, R=0.45720, name='Clad OR') + left = openmc.XPlane(x0=-pitch/2, name='left', boundary_type='reflective') + right = openmc.XPlane(x0=pitch/2, name='right', boundary_type='reflective') + bottom = openmc.YPlane(y0=-pitch/2, name='bottom', + boundary_type='reflective') + top = openmc.YPlane(y0=pitch/2, name='top', boundary_type='reflective') + + # Instantiate Cells + fuel_pin = openmc.Cell(name='cell 1', fill=fuel) + cladding = openmc.Cell(name='cell 3', fill=clad) + water = openmc.Cell(name='cell 2', fill=hot_water) + + # Use surface half-spaces to define regions + fuel_pin.region = -fuel_or + cladding.region = +fuel_or & -clad_or + water.region = +clad_or & +left & -right & +bottom & -top + + # Create root universe + model.geometry.root_universe = openmc.Universe(0, name='root universe') + model.geometry.root_universe.add_cells([fuel_pin, cladding, water]) + + model.settings.batches = 10 + model.settings.inactive = 5 + model.settings.particles = 100 + model.settings.source = openmc.Source(space=openmc.stats.Box( + [-pitch/2, -pitch/2, -1], [pitch/2, pitch/2, 1], only_fissionable=True)) + + plot = openmc.Plot.from_geometry(model.geometry) + plot.pixels = (300, 300) + plot.color_by = 'material' + model.plots.append(plot) + + return model + + +def pwr_core(): + """Create a PWR full-core model. + + This model is the OECD/NEA Monte Carlo Performance benchmark which is a + grossly simplified pressurized water reactor (PWR) with 241 fuel + assemblies. + + Returns + ------- + model : openmc.model.Model + Full-core PWR model + + """ + model = openmc.model.Model() + + # Define materials. + fuel = openmc.Material(name='Fuel', material_id=1) + fuel.set_density('g/cm3', 10.062) + fuel.add_nuclide("U234", 4.9476e-6) + fuel.add_nuclide("U235", 4.8218e-4) + fuel.add_nuclide("U238", 2.1504e-2) + fuel.add_nuclide("Xe135", 1.0801e-8) + fuel.add_nuclide("O16", 4.5737e-2) + + clad = openmc.Material(name='Cladding', material_id=2) + clad.set_density('g/cm3', 5.77) + clad.add_nuclide("Zr90", 0.5145) + clad.add_nuclide("Zr91", 0.1122) + clad.add_nuclide("Zr92", 0.1715) + clad.add_nuclide("Zr94", 0.1738) + clad.add_nuclide("Zr96", 0.0280) + + cold_water = openmc.Material(name='Cold borated water', material_id=3) + cold_water.set_density('atom/b-cm', 0.07416) + cold_water.add_nuclide("H1", 2.0) + cold_water.add_nuclide("O16", 1.0) + cold_water.add_nuclide("B10", 6.490e-4) + cold_water.add_nuclide("B11", 2.689e-3) + cold_water.add_s_alpha_beta('c_H_in_H2O') + + hot_water = openmc.Material(name='Hot borated water', material_id=4) + hot_water.set_density('atom/b-cm', 0.06614) + hot_water.add_nuclide("H1", 2.0) + hot_water.add_nuclide("O16", 1.0) + hot_water.add_nuclide("B10", 6.490e-4) + hot_water.add_nuclide("B11", 2.689e-3) + hot_water.add_s_alpha_beta('c_H_in_H2O') + + rpv_steel = openmc.Material(name='Reactor pressure vessel steel', + material_id=5) + rpv_steel.set_density('g/cm3', 7.9) + rpv_steel.add_nuclide("Fe54", 0.05437098, 'wo') + rpv_steel.add_nuclide("Fe56", 0.88500663, 'wo') + rpv_steel.add_nuclide("Fe57", 0.0208008, 'wo') + rpv_steel.add_nuclide("Fe58", 0.00282159, 'wo') + rpv_steel.add_nuclide("Ni58", 0.0067198, 'wo') + rpv_steel.add_nuclide("Ni60", 0.0026776, 'wo') + rpv_steel.add_nuclide("Mn55", 0.01, 'wo') + rpv_steel.add_nuclide("Cr52", 0.002092475, 'wo') + rpv_steel.add_nuclide("C0", 0.0025, 'wo') + rpv_steel.add_nuclide("Cu63", 0.0013696, 'wo') + + lower_rad_ref = openmc.Material(name='Lower radial reflector', + material_id=6) + lower_rad_ref.set_density('g/cm3', 4.32) + lower_rad_ref.add_nuclide("H1", 0.0095661, 'wo') + lower_rad_ref.add_nuclide("O16", 0.0759107, 'wo') + lower_rad_ref.add_nuclide("B10", 3.08409e-5, 'wo') + lower_rad_ref.add_nuclide("B11", 1.40499e-4, 'wo') + lower_rad_ref.add_nuclide("Fe54", 0.035620772088, 'wo') + lower_rad_ref.add_nuclide("Fe56", 0.579805982228, 'wo') + lower_rad_ref.add_nuclide("Fe57", 0.01362750048, 'wo') + lower_rad_ref.add_nuclide("Fe58", 0.001848545204, 'wo') + lower_rad_ref.add_nuclide("Ni58", 0.055298376566, 'wo') + lower_rad_ref.add_nuclide("Mn55", 0.0182870, 'wo') + lower_rad_ref.add_nuclide("Cr52", 0.145407678031, 'wo') + lower_rad_ref.add_s_alpha_beta('c_H_in_H2O') + + upper_rad_ref = openmc.Material(name='Upper radial reflector /' + 'Top plate region', material_id=7) + upper_rad_ref.set_density('g/cm3', 4.28) + upper_rad_ref.add_nuclide("H1", 0.0086117, 'wo') + upper_rad_ref.add_nuclide("O16", 0.0683369, 'wo') + upper_rad_ref.add_nuclide("B10", 2.77638e-5, 'wo') + upper_rad_ref.add_nuclide("B11", 1.26481e-4, 'wo') + upper_rad_ref.add_nuclide("Fe54", 0.035953677186, 'wo') + upper_rad_ref.add_nuclide("Fe56", 0.585224740891, 'wo') + upper_rad_ref.add_nuclide("Fe57", 0.01375486056, 'wo') + upper_rad_ref.add_nuclide("Fe58", 0.001865821363, 'wo') + upper_rad_ref.add_nuclide("Ni58", 0.055815129186, 'wo') + upper_rad_ref.add_nuclide("Mn55", 0.0184579, 'wo') + upper_rad_ref.add_nuclide("Cr52", 0.146766614995, 'wo') + upper_rad_ref.add_s_alpha_beta('c_H_in_H2O') + + bot_plate = openmc.Material(name='Bottom plate region', material_id=8) + bot_plate.set_density('g/cm3', 7.184) + bot_plate.add_nuclide("H1", 0.0011505, 'wo') + bot_plate.add_nuclide("O16", 0.0091296, 'wo') + bot_plate.add_nuclide("B10", 3.70915e-6, 'wo') + bot_plate.add_nuclide("B11", 1.68974e-5, 'wo') + bot_plate.add_nuclide("Fe54", 0.03855611055, 'wo') + bot_plate.add_nuclide("Fe56", 0.627585036425, 'wo') + bot_plate.add_nuclide("Fe57", 0.014750478, 'wo') + bot_plate.add_nuclide("Fe58", 0.002000875025, 'wo') + bot_plate.add_nuclide("Ni58", 0.059855207342, 'wo') + bot_plate.add_nuclide("Mn55", 0.0197940, 'wo') + bot_plate.add_nuclide("Cr52", 0.157390026871, 'wo') + bot_plate.add_s_alpha_beta('c_H_in_H2O') + + bot_nozzle = openmc.Material(name='Bottom nozzle region', + material_id=9) + bot_nozzle.set_density('g/cm3', 2.53) + bot_nozzle.add_nuclide("H1", 0.0245014, 'wo') + bot_nozzle.add_nuclide("O16", 0.1944274, 'wo') + bot_nozzle.add_nuclide("B10", 7.89917e-5, 'wo') + bot_nozzle.add_nuclide("B11", 3.59854e-4, 'wo') + bot_nozzle.add_nuclide("Fe54", 0.030411411144, 'wo') + bot_nozzle.add_nuclide("Fe56", 0.495012237964, 'wo') + bot_nozzle.add_nuclide("Fe57", 0.01163454624, 'wo') + bot_nozzle.add_nuclide("Fe58", 0.001578204652, 'wo') + bot_nozzle.add_nuclide("Ni58", 0.047211231662, 'wo') + bot_nozzle.add_nuclide("Mn55", 0.0156126, 'wo') + bot_nozzle.add_nuclide("Cr52", 0.124142524198, 'wo') + bot_nozzle.add_s_alpha_beta('c_H_in_H2O') + + top_nozzle = openmc.Material(name='Top nozzle region', material_id=10) + top_nozzle.set_density('g/cm3', 1.746) + top_nozzle.add_nuclide("H1", 0.0358870, 'wo') + top_nozzle.add_nuclide("O16", 0.2847761, 'wo') + top_nozzle.add_nuclide("B10", 1.15699e-4, 'wo') + top_nozzle.add_nuclide("B11", 5.27075e-4, 'wo') + top_nozzle.add_nuclide("Fe54", 0.02644016154, 'wo') + top_nozzle.add_nuclide("Fe56", 0.43037146399, 'wo') + top_nozzle.add_nuclide("Fe57", 0.0101152584, 'wo') + top_nozzle.add_nuclide("Fe58", 0.00137211607, 'wo') + top_nozzle.add_nuclide("Ni58", 0.04104621835, 'wo') + top_nozzle.add_nuclide("Mn55", 0.0135739, 'wo') + top_nozzle.add_nuclide("Cr52", 0.107931450781, 'wo') + top_nozzle.add_s_alpha_beta('c_H_in_H2O') + + top_fa = openmc.Material(name='Top of fuel assemblies', material_id=11) + top_fa.set_density('g/cm3', 3.044) + top_fa.add_nuclide("H1", 0.0162913, 'wo') + top_fa.add_nuclide("O16", 0.1292776, 'wo') + top_fa.add_nuclide("B10", 5.25228e-5, 'wo') + top_fa.add_nuclide("B11", 2.39272e-4, 'wo') + top_fa.add_nuclide("Zr90", 0.43313403903, 'wo') + top_fa.add_nuclide("Zr91", 0.09549277374, 'wo') + top_fa.add_nuclide("Zr92", 0.14759527104, 'wo') + top_fa.add_nuclide("Zr94", 0.15280552077, 'wo') + top_fa.add_nuclide("Zr96", 0.02511169542, 'wo') + top_fa.add_s_alpha_beta('c_H_in_H2O') + + bot_fa = openmc.Material(name='Bottom of fuel assemblies', + material_id=12) + bot_fa.set_density('g/cm3', 1.762) + bot_fa.add_nuclide("H1", 0.0292856, 'wo') + bot_fa.add_nuclide("O16", 0.2323919, 'wo') + bot_fa.add_nuclide("B10", 9.44159e-5, 'wo') + bot_fa.add_nuclide("B11", 4.30120e-4, 'wo') + bot_fa.add_nuclide("Zr90", 0.3741373658, 'wo') + bot_fa.add_nuclide("Zr91", 0.0824858164, 'wo') + bot_fa.add_nuclide("Zr92", 0.1274914944, 'wo') + bot_fa.add_nuclide("Zr94", 0.1319920622, 'wo') + bot_fa.add_nuclide("Zr96", 0.0216912612, 'wo') + bot_fa.add_s_alpha_beta('c_H_in_H2O') + + # Define the materials file. + model.materials = (fuel, clad, cold_water, hot_water, rpv_steel, + lower_rad_ref, upper_rad_ref, bot_plate, + bot_nozzle, top_nozzle, top_fa, bot_fa) + + # Define surfaces. + s1 = openmc.ZCylinder(R=0.41, surface_id=1) + s2 = openmc.ZCylinder(R=0.475, surface_id=2) + s3 = openmc.ZCylinder(R=0.56, surface_id=3) + s4 = openmc.ZCylinder(R=0.62, surface_id=4) + s5 = openmc.ZCylinder(R=187.6, surface_id=5) + s6 = openmc.ZCylinder(R=209.0, surface_id=6) + s7 = openmc.ZCylinder(R=229.0, surface_id=7) + s8 = openmc.ZCylinder(R=249.0, surface_id=8, boundary_type='vacuum') + + s31 = openmc.ZPlane(z0=-229.0, surface_id=31, boundary_type='vacuum') + s32 = openmc.ZPlane(z0=-199.0, surface_id=32) + s33 = openmc.ZPlane(z0=-193.0, surface_id=33) + s34 = openmc.ZPlane(z0=-183.0, surface_id=34) + s35 = openmc.ZPlane(z0=0.0, surface_id=35) + s36 = openmc.ZPlane(z0=183.0, surface_id=36) + s37 = openmc.ZPlane(z0=203.0, surface_id=37) + s38 = openmc.ZPlane(z0=215.0, surface_id=38) + s39 = openmc.ZPlane(z0=223.0, surface_id=39, boundary_type='vacuum') + + # Define pin cells. + fuel_cold = openmc.Universe(name='Fuel pin, cladding, cold water', + universe_id=1) + c21 = openmc.Cell(cell_id=21, fill=fuel, region=-s1) + c22 = openmc.Cell(cell_id=22, fill=clad, region=+s1 & -s2) + c23 = openmc.Cell(cell_id=23, fill=cold_water, region=+s2) + fuel_cold.add_cells((c21, c22, c23)) + + tube_cold = openmc.Universe(name='Instrumentation guide tube, ' + 'cold water', universe_id=2) + c24 = openmc.Cell(cell_id=24, fill=cold_water, region=-s3) + c25 = openmc.Cell(cell_id=25, fill=clad, region=+s3 & -s4) + c26 = openmc.Cell(cell_id=26, fill=cold_water, region=+s4) + tube_cold.add_cells((c24, c25, c26)) + + fuel_hot = openmc.Universe(name='Fuel pin, cladding, hot water', + universe_id=3) + c27 = openmc.Cell(cell_id=27, fill=fuel, region=-s1) + c28 = openmc.Cell(cell_id=28, fill=clad, region=+s1 & -s2) + c29 = openmc.Cell(cell_id=29, fill=hot_water, region=+s2) + fuel_hot.add_cells((c27, c28, c29)) + + tube_hot = openmc.Universe(name='Instrumentation guide tube, hot water', + universe_id=4) + c30 = openmc.Cell(cell_id=30, fill=hot_water, region=-s3) + c31 = openmc.Cell(cell_id=31, fill=clad, region=+s3 & -s4) + c32 = openmc.Cell(cell_id=32, fill=hot_water, region=+s4) + tube_hot.add_cells((c30, c31, c32)) + + # Set positions occupied by guide tubes + tube_x = np.array([5, 8, 11, 3, 13, 2, 5, 8, 11, 14, 2, 5, 8, 11, 14, + 2, 5, 8, 11, 14, 3, 13, 5, 8, 11]) + tube_y = np.array([2, 2, 2, 3, 3, 5, 5, 5, 5, 5, 8, 8, 8, 8, 8, + 11, 11, 11, 11, 11, 13, 13, 14, 14, 14]) + + # Define fuel lattices. + l100 = openmc.RectLattice(name='Fuel assembly (lower half)', lattice_id=100) + l100.lower_left = (-10.71, -10.71) + l100.pitch = (1.26, 1.26) + l100.universes = np.tile(fuel_cold, (17, 17)) + l100.universes[tube_x, tube_y] = tube_cold + + l101 = openmc.RectLattice(name='Fuel assembly (upper half)', lattice_id=101) + l101.lower_left = (-10.71, -10.71) + l101.pitch = (1.26, 1.26) + l101.universes = np.tile(fuel_hot, (17, 17)) + l101.universes[tube_x, tube_y] = tube_hot + + # Define assemblies. + fa_cw = openmc.Universe(name='Water assembly (cold)', universe_id=5) + c50 = openmc.Cell(cell_id=50, fill=cold_water, region=+s34 & -s35) + fa_cw.add_cell(c50) + + fa_hw = openmc.Universe(name='Water assembly (hot)', universe_id=7) + c70 = openmc.Cell(cell_id=70, fill=hot_water, region=+s35 & -s36) + fa_hw.add_cell(c70) + + fa_cold = openmc.Universe(name='Fuel assembly (cold)', universe_id=6) + c60 = openmc.Cell(cell_id=60, fill=l100, region=+s34 & -s35) + fa_cold.add_cell(c60) + + fa_hot = openmc.Universe(name='Fuel assembly (hot)', universe_id=8) + c80 = openmc.Cell(cell_id=80, fill=l101, region=+s35 & -s36) + fa_hot.add_cell(c80) + + # Define core lattices + l200 = openmc.RectLattice(name='Core lattice (lower half)', lattice_id=200) + l200.lower_left = (-224.91, -224.91) + l200.pitch = (21.42, 21.42) + l200.universes = [ + [fa_cw]*21, + [fa_cw]*21, + [fa_cw]*7 + [fa_cold]*7 + [fa_cw]*7, + [fa_cw]*5 + [fa_cold]*11 + [fa_cw]*5, + [fa_cw]*4 + [fa_cold]*13 + [fa_cw]*4, + [fa_cw]*3 + [fa_cold]*15 + [fa_cw]*3, + [fa_cw]*3 + [fa_cold]*15 + [fa_cw]*3, + [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2, + [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2, + [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2, + [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2, + [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2, + [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2, + [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2, + [fa_cw]*3 + [fa_cold]*15 + [fa_cw]*3, + [fa_cw]*3 + [fa_cold]*15 + [fa_cw]*3, + [fa_cw]*4 + [fa_cold]*13 + [fa_cw]*4, + [fa_cw]*5 + [fa_cold]*11 + [fa_cw]*5, + [fa_cw]*7 + [fa_cold]*7 + [fa_cw]*7, + [fa_cw]*21, + [fa_cw]*21] + + l201 = openmc.RectLattice(name='Core lattice (lower half)', lattice_id=201) + l201.lower_left = (-224.91, -224.91) + l201.pitch = (21.42, 21.42) + l201.universes = [ + [fa_hw]*21, + [fa_hw]*21, + [fa_hw]*7 + [fa_hot]*7 + [fa_hw]*7, + [fa_hw]*5 + [fa_hot]*11 + [fa_hw]*5, + [fa_hw]*4 + [fa_hot]*13 + [fa_hw]*4, + [fa_hw]*3 + [fa_hot]*15 + [fa_hw]*3, + [fa_hw]*3 + [fa_hot]*15 + [fa_hw]*3, + [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2, + [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2, + [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2, + [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2, + [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2, + [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2, + [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2, + [fa_hw]*3 + [fa_hot]*15 + [fa_hw]*3, + [fa_hw]*3 + [fa_hot]*15 + [fa_hw]*3, + [fa_hw]*4 + [fa_hot]*13 + [fa_hw]*4, + [fa_hw]*5 + [fa_hot]*11 + [fa_hw]*5, + [fa_hw]*7 + [fa_hot]*7 + [fa_hw]*7, + [fa_hw]*21, + [fa_hw]*21] + + # Define root universe. + root = openmc.Universe(universe_id=0, name='root universe') + c1 = openmc.Cell(cell_id=1, fill=l200, region=-s6 & +s34 & -s35) + c2 = openmc.Cell(cell_id=2, fill=l201, region=-s6 & +s35 & -s36) + c3 = openmc.Cell(cell_id=3, fill=bot_plate, region=-s7 & +s31 & -s32) + c4 = openmc.Cell(cell_id=4, fill=bot_nozzle, region=-s5 & +s32 & -s33) + c5 = openmc.Cell(cell_id=5, fill=bot_fa, region=-s5 & +s33 & -s34) + c6 = openmc.Cell(cell_id=6, fill=top_fa, region=-s5 & +s36 & -s37) + c7 = openmc.Cell(cell_id=7, fill=top_nozzle, region=-s5 & +s37 & -s38) + c8 = openmc.Cell(cell_id=8, fill=upper_rad_ref, region=-s7 & +s38 & -s39) + c9 = openmc.Cell(cell_id=9, fill=bot_nozzle, region=+s6 & -s7 & +s32 & -s38) + c10 = openmc.Cell(cell_id=10, fill=rpv_steel, region=+s7 & -s8 & +s31 & -s39) + c11 = openmc.Cell(cell_id=11, fill=lower_rad_ref, region=+s5 & -s6 & +s32 & -s34) + c12 = openmc.Cell(cell_id=12, fill=upper_rad_ref, region=+s5 & -s6 & +s36 & -s38) + root.add_cells((c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12)) + + # Assign root universe to geometry + model.geometry.root_universe = root + + model.settings.batches = 10 + model.settings.inactive = 5 + model.settings.particles = 100 + model.settings.source = openmc.Source(space=openmc.stats.Box( + [-160, -160, -183], [160, 160, 183])) + + plot = openmc.Plot() + plot.origin = (125, 125, 0) + plot.width = (250, 250) + plot.pixels = (3000, 3000) + plot.color_by = 'material' + model.plots.append(plot) + + return model + + +def pwr_assembly(): + """Create a PWR assembly model. + + Returns + ------- + model : openmc.model.Model + A PWR assembly model + + """ + + model = openmc.model.Model() + + # 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') + + # Define the materials file. + model.materials = (fuel, clad, hot_water) + + # Instantiate ZCylinder surfaces + fuel_or = openmc.ZCylinder(x0=0, y0=0, R=0.39218, name='Fuel OR') + clad_or = openmc.ZCylinder(x0=0, y0=0, R=0.45720, name='Clad OR') + + # Create boundary planes to surround the geometry + pitch = 21.42 + min_x = openmc.XPlane(x0=-pitch/2, boundary_type='reflective') + max_x = openmc.XPlane(x0=+pitch/2, boundary_type='reflective') + min_y = openmc.YPlane(y0=-pitch/2, boundary_type='reflective') + max_y = openmc.YPlane(y0=+pitch/2, boundary_type='reflective') + + # Create a fuel pin universe + fuel_pin_universe = openmc.Universe(name='Fuel Pin') + fuel_cell = openmc.Cell(name='fuel', fill=fuel, region=-fuel_or) + clad_cell = openmc.Cell(name='clad', fill=clad, region=+fuel_or & -clad_or) + hot_water_cell = openmc.Cell(name='hot water', fill=hot_water, region=+clad_or) + fuel_pin_universe.add_cells([fuel_cell, clad_cell, hot_water_cell]) + + + # Create a control rod guide tube universe + guide_tube_universe = openmc.Universe(name='Guide Tube') + gt_inner_cell = openmc.Cell(name='guide tube inner water', fill=hot_water, + region=-fuel_or) + gt_clad_cell = openmc.Cell(name='guide tube clad', fill=clad, + region=+fuel_or & -clad_or) + gt_outer_cell = openmc.Cell(name='guide tube outer water', fill=hot_water, + region=+clad_or) + guide_tube_universe.add_cells([gt_inner_cell, gt_clad_cell, gt_outer_cell]) + + # Create fuel assembly Lattice + 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 + template_x = np.array([5, 8, 11, 3, 13, 2, 5, 8, 11, 14, 2, 5, 8, + 11, 14, 2, 5, 8, 11, 14, 3, 13, 5, 8, 11]) + template_y = np.array([2, 2, 2, 3, 3, 5, 5, 5, 5, 5, 8, 8, 8, 8, + 8, 11, 11, 11, 11, 11, 13, 13, 14, 14, 14]) + + # Create 17x17 array of universes + assembly.universes = np.tile(fuel_pin_universe, (17, 17)) + assembly.universes[template_x, template_y] = guide_tube_universe + + # Create root Cell + root_cell = openmc.Cell(name='root cell', fill=assembly) + root_cell.region = +min_x & -max_x & +min_y & -max_y + + # Create root Universe + model.geometry.root_universe = openmc.Universe(universe_id=0, name='root universe') + model.geometry.root_universe.add_cell(root_cell) + + model.settings.batches = 10 + model.settings.inactive = 5 + model.settings.particles = 100 + model.settings.source = openmc.Source(space=openmc.stats.Box( + [-pitch/2, -pitch/2, -1], [pitch/2, pitch/2, 1], only_fissionable=True)) + + plot = openmc.Plot() + plot.origin = (0.0, 0.0, 0) + plot.width = (21.42, 21.42) + plot.pixels = (300, 300) + plot.color_by = 'material' + model.plots.append(plot) + + return model + + +def slab_mg(reps=None, as_macro=True): + """Create a one-group, 1D slab model. + + Parameters + ---------- + reps : list, optional + List of angular representations. Items can be 'ang', 'ang_mu', 'iso', or + 'iso_mu'. + as_macro : bool, optional + Whether :class:`openmc.Macroscopic` is used + + Returns + ------- + model : openmc.model.Model + One-group, 1D slab model + + """ + model = openmc.model.Model() + + # Define materials needed for 1D/1G slab problem + mat_names = ['uo2', 'clad', 'lwtr'] + mgxs_reps = ['ang', 'ang_mu', 'iso', 'iso_mu'] + + if reps is None: + reps = mgxs_reps + + xs = [] + i = 0 + for mat in mat_names: + for rep in reps: + i += 1 + if as_macro: + xs.append(openmc.Macroscopic(mat + '_' + rep)) + m = openmc.Material(name=str(i)) + m.set_density('macro', 1.) + m.add_macroscopic(xs[-1]) + else: + xs.append(openmc.Nuclide(mat + '_' + rep)) + m = openmc.Material(name=str(i)) + m.set_density('atom/b-cm', 1.) + m.add_nuclide(xs[-1].name, 1.0, 'ao') + model.materials.append(m) + + # Define the materials file + model.xs_data = xs + model.materials.cross_sections = "../1d_mgxs.h5" + + # Define surfaces. + # Assembly/Problem Boundary + left = openmc.XPlane(x0=0.0, boundary_type='reflective') + right = openmc.XPlane(x0=10.0, boundary_type='reflective') + bottom = openmc.YPlane(y0=0.0, boundary_type='reflective') + top = openmc.YPlane(y0=10.0, boundary_type='reflective') + + # for each material add a plane + planes = [openmc.ZPlane(z0=0.0, boundary_type='reflective')] + dz = round(5. / float(len(model.materials)), 4) + for i in range(len(model.materials) - 1): + planes.append(openmc.ZPlane(z0=dz * float(i + 1))) + planes.append(openmc.ZPlane(z0=5.0, boundary_type='reflective')) + + # Define cells for each material + model.geometry.root_universe = openmc.Universe(universe_id=0, name='root universe') + xy = +left & -right & +bottom & -top + for i, mat in enumerate(model.materials): + c = openmc.Cell(fill=mat, region=xy & +planes[i] & -planes[i + 1]) + model.geometry.root_universe.add_cell(c) + + model.settings.batches = 10 + model.settings.inactive = 5 + model.settings.particles = 100 + model.settings.source = openmc.Source(space=openmc.stats.Box( + [0.0, 0.0, 0.0], [10.0, 10.0, 5.])) + model.settings.energy_mode = "multi-group" + + plot = openmc.Plot() + plot.filename = 'mat' + plot.origin = (5.0, 5.0, 2.5) + plot.width = (2.5, 2.5) + plot.basis = 'xz' + plot.pixels = (3000, 3000) + plot.color_by = 'material' + model.plots.append(plot) + + return model diff --git a/openmc/model/model.py b/openmc/model/model.py index 7716cae97..36621ed4f 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -1,26 +1,31 @@ +from collections import Iterable + import openmc from openmc.checkvalue import check_type class Model(object): - """OpenMC model container for the openmc.Geometry, openmc.Materials, - openmc.Settings, openmc.Tallies, openmc.CMFD objects, and openmc.Plot - objects + """Model container. + + This class can be used to store instances of :class:`openmc.Geometry`, + :class:`openmc.Materials`, :class:`openmc.Settings`, + :class:`openmc.Tallies`, :class:`openmc.Plots`, and :class:`openmc.CMFD`, + thus making a complete model. Parameters ---------- - geometry : openmc.Geometry + geometry : openmc.Geometry, optional Geometry information - materials : openmc.Materials + materials : openmc.Materials, optional Materials information - settings : openmc.Settings + settings : openmc.Settings, optional Settings information - tallies : openmc.Tallies - Tallies information, optional - cmfd : openmc.CMFD - CMFD information, optional - plots : openmc.Plots - Plot information, optional + tallies : openmc.Tallies, optional + Tallies information + cmfd : openmc.CMFD, optional + CMFD information + plots : openmc.Plots, optional + Plot information Attributes ---------- @@ -39,23 +44,26 @@ class Model(object): """ - def __init__(self, geometry, materials, settings, tallies=None, cmfd=None, - plots=None): - self.geometry = geometry - self.materials = materials - self.settings = settings - if tallies: + def __init__(self, geometry=None, materials=None, settings=None, + tallies=None, cmfd=None, plots=None): + self.geometry = openmc.Geometry() + self.materials = openmc.Materials() + self.settings = openmc.Settings() + self.cmfd = cmfd + + self._tallies = openmc.Tallies() + self._plots = openmc.Plots() + + if geometry is not None: + self.geometry = geometry + if materials is not None: + self.materials = materials + if settings is not None: + self.settings = settings + if tallies is not None: self.tallies = tallies - else: - self._tallies = openmc.Tallies() - if cmfd: - self.cmfd = cmfd - else: - self._cmfd = None - if plots: + if plots is not None: self.plots = plots - else: - self.plots = openmc.Plots() self.sp = None @@ -90,8 +98,13 @@ class Model(object): @materials.setter def materials(self, materials): - check_type('materials', materials, openmc.Materials) - self._materials = materials + check_type('materials', materials, Iterable, openmc.Material) + if isinstance(materials, openmc.Materials): + self._materials = materials + else: + self._materials.clear() + for mat in materials: + self._materials.append(mat) @settings.setter def settings(self, settings): @@ -100,30 +113,52 @@ class Model(object): @tallies.setter def tallies(self, tallies): - check_type('tallies', tallies, openmc.Tallies) - self._tallies = tallies + check_type('tallies', tallies, Iterable, openmc.Tally) + if isinstance(tallies, openmc.Tallies): + self._tallies = tallies + else: + self._tallies.clear() + for tally in tallies: + self._tallies.append(tally) @cmfd.setter def cmfd(self, cmfd): - check_type('cmfd', cmfd, openmc.CMFD) + check_type('cmfd', cmfd, (openmc.CMFD, type(None))) self._cmfd = cmfd @plots.setter def plots(self, plots): - check_type('plots', plots, openmc.Plots) - self._plots = plots + check_type('plots', plots, Iterable, openmc.Plot) + if isinstance(plots, openmc.Plots): + self._plots = plots + else: + self._plots.clear() + for plot in plots: + self._plots.append(plot) def export_to_xml(self): - """Export model settings to XML files. + """Export model to XML files. """ - self.geometry.export_to_xml() - self.materials.export_to_xml() self.settings.export_to_xml() - self.tallies.export_to_xml() + self.geometry.export_to_xml() + + # If a materials collection was specified, export it. Otherwise, look + # for all materials in the geometry and use that to automatically build + # a collection. + if self.materials: + self.materials.export_to_xml() + else: + materials = openmc.Materials(self.geometry.get_all_materials() + .values()) + materials.export_to_xml() + + if self.tallies: + self.tallies.export_to_xml() if self.cmfd is not None: self.cmfd.export_to_xml() - self.plots.export_to_xml() + if self.plots: + self.plots.export_to_xml() def run(self, **kwargs): """Creates the XML files, runs OpenMC, and loads the statepoint. @@ -150,8 +185,8 @@ class Model(object): if self.settings.statepoint is not None: if 'batches' in self.settings.statepoint: statepoint_batches = self.settings.statepoint['batches'][-1] - self.sp = \ - openmc.StatePoint('statepoint.{}.h5'.format(statepoint_batches)) + self.sp = openmc.StatePoint('statepoint.{}.h5'.format( + statepoint_batches)) return self.sp.k_combined diff --git a/tests/input_set.py b/tests/input_set.py deleted file mode 100644 index ce5e3d5bc..000000000 --- a/tests/input_set.py +++ /dev/null @@ -1,798 +0,0 @@ -import numpy as np - -import openmc -from openmc.source import Source -from openmc.stats import Box - - -class InputSet(object): - def __init__(self): - self.settings = openmc.Settings() - self.materials = openmc.Materials() - self.geometry = openmc.Geometry() - self.tallies = None - self.plots = None - - def export(self): - self.settings.export_to_xml() - self.materials.export_to_xml() - self.geometry.export_to_xml() - if self.tallies is not None: - self.tallies.export_to_xml() - if self.plots is not None: - self.plots.export_to_xml() - - def build_default_materials_and_geometry(self): - # Define materials. - fuel = openmc.Material(name='Fuel', material_id=1) - fuel.set_density('g/cm3', 10.062) - fuel.add_nuclide("U234", 4.9476e-6) - fuel.add_nuclide("U235", 4.8218e-4) - fuel.add_nuclide("U238", 2.1504e-2) - fuel.add_nuclide("Xe135", 1.0801e-8) - fuel.add_nuclide("O16", 4.5737e-2) - - clad = openmc.Material(name='Cladding', material_id=2) - clad.set_density('g/cm3', 5.77) - clad.add_nuclide("Zr90", 0.5145) - clad.add_nuclide("Zr91", 0.1122) - clad.add_nuclide("Zr92", 0.1715) - clad.add_nuclide("Zr94", 0.1738) - clad.add_nuclide("Zr96", 0.0280) - - cold_water = openmc.Material(name='Cold borated water', material_id=3) - cold_water.set_density('atom/b-cm', 0.07416) - cold_water.add_nuclide("H1", 2.0) - cold_water.add_nuclide("O16", 1.0) - cold_water.add_nuclide("B10", 6.490e-4) - cold_water.add_nuclide("B11", 2.689e-3) - cold_water.add_s_alpha_beta('c_H_in_H2O') - - hot_water = openmc.Material(name='Hot borated water', material_id=4) - hot_water.set_density('atom/b-cm', 0.06614) - hot_water.add_nuclide("H1", 2.0) - hot_water.add_nuclide("O16", 1.0) - hot_water.add_nuclide("B10", 6.490e-4) - hot_water.add_nuclide("B11", 2.689e-3) - hot_water.add_s_alpha_beta('c_H_in_H2O') - - rpv_steel = openmc.Material(name='Reactor pressure vessel steel', - material_id=5) - rpv_steel.set_density('g/cm3', 7.9) - rpv_steel.add_nuclide("Fe54", 0.05437098, 'wo') - rpv_steel.add_nuclide("Fe56", 0.88500663, 'wo') - rpv_steel.add_nuclide("Fe57", 0.0208008, 'wo') - rpv_steel.add_nuclide("Fe58", 0.00282159, 'wo') - rpv_steel.add_nuclide("Ni58", 0.0067198, 'wo') - rpv_steel.add_nuclide("Ni60", 0.0026776, 'wo') - rpv_steel.add_nuclide("Mn55", 0.01, 'wo') - rpv_steel.add_nuclide("Cr52", 0.002092475, 'wo') - rpv_steel.add_nuclide("C0", 0.0025, 'wo') - rpv_steel.add_nuclide("Cu63", 0.0013696, 'wo') - - lower_rad_ref = openmc.Material(name='Lower radial reflector', - material_id=6) - lower_rad_ref.set_density('g/cm3', 4.32) - lower_rad_ref.add_nuclide("H1", 0.0095661, 'wo') - lower_rad_ref.add_nuclide("O16", 0.0759107, 'wo') - lower_rad_ref.add_nuclide("B10", 3.08409e-5, 'wo') - lower_rad_ref.add_nuclide("B11", 1.40499e-4, 'wo') - lower_rad_ref.add_nuclide("Fe54", 0.035620772088, 'wo') - lower_rad_ref.add_nuclide("Fe56", 0.579805982228, 'wo') - lower_rad_ref.add_nuclide("Fe57", 0.01362750048, 'wo') - lower_rad_ref.add_nuclide("Fe58", 0.001848545204, 'wo') - lower_rad_ref.add_nuclide("Ni58", 0.055298376566, 'wo') - lower_rad_ref.add_nuclide("Mn55", 0.0182870, 'wo') - lower_rad_ref.add_nuclide("Cr52", 0.145407678031, 'wo') - lower_rad_ref.add_s_alpha_beta('c_H_in_H2O') - - upper_rad_ref = openmc.Material(name='Upper radial reflector /' - 'Top plate region', material_id=7) - upper_rad_ref.set_density('g/cm3', 4.28) - upper_rad_ref.add_nuclide("H1", 0.0086117, 'wo') - upper_rad_ref.add_nuclide("O16", 0.0683369, 'wo') - upper_rad_ref.add_nuclide("B10", 2.77638e-5, 'wo') - upper_rad_ref.add_nuclide("B11", 1.26481e-4, 'wo') - upper_rad_ref.add_nuclide("Fe54", 0.035953677186, 'wo') - upper_rad_ref.add_nuclide("Fe56", 0.585224740891, 'wo') - upper_rad_ref.add_nuclide("Fe57", 0.01375486056, 'wo') - upper_rad_ref.add_nuclide("Fe58", 0.001865821363, 'wo') - upper_rad_ref.add_nuclide("Ni58", 0.055815129186, 'wo') - upper_rad_ref.add_nuclide("Mn55", 0.0184579, 'wo') - upper_rad_ref.add_nuclide("Cr52", 0.146766614995, 'wo') - upper_rad_ref.add_s_alpha_beta('c_H_in_H2O') - - bot_plate = openmc.Material(name='Bottom plate region', material_id=8) - bot_plate.set_density('g/cm3', 7.184) - bot_plate.add_nuclide("H1", 0.0011505, 'wo') - bot_plate.add_nuclide("O16", 0.0091296, 'wo') - bot_plate.add_nuclide("B10", 3.70915e-6, 'wo') - bot_plate.add_nuclide("B11", 1.68974e-5, 'wo') - bot_plate.add_nuclide("Fe54", 0.03855611055, 'wo') - bot_plate.add_nuclide("Fe56", 0.627585036425, 'wo') - bot_plate.add_nuclide("Fe57", 0.014750478, 'wo') - bot_plate.add_nuclide("Fe58", 0.002000875025, 'wo') - bot_plate.add_nuclide("Ni58", 0.059855207342, 'wo') - bot_plate.add_nuclide("Mn55", 0.0197940, 'wo') - bot_plate.add_nuclide("Cr52", 0.157390026871, 'wo') - bot_plate.add_s_alpha_beta('c_H_in_H2O') - - bot_nozzle = openmc.Material(name='Bottom nozzle region', - material_id=9) - bot_nozzle.set_density('g/cm3', 2.53) - bot_nozzle.add_nuclide("H1", 0.0245014, 'wo') - bot_nozzle.add_nuclide("O16", 0.1944274, 'wo') - bot_nozzle.add_nuclide("B10", 7.89917e-5, 'wo') - bot_nozzle.add_nuclide("B11", 3.59854e-4, 'wo') - bot_nozzle.add_nuclide("Fe54", 0.030411411144, 'wo') - bot_nozzle.add_nuclide("Fe56", 0.495012237964, 'wo') - bot_nozzle.add_nuclide("Fe57", 0.01163454624, 'wo') - bot_nozzle.add_nuclide("Fe58", 0.001578204652, 'wo') - bot_nozzle.add_nuclide("Ni58", 0.047211231662, 'wo') - bot_nozzle.add_nuclide("Mn55", 0.0156126, 'wo') - bot_nozzle.add_nuclide("Cr52", 0.124142524198, 'wo') - bot_nozzle.add_s_alpha_beta('c_H_in_H2O') - - top_nozzle = openmc.Material(name='Top nozzle region', material_id=10) - top_nozzle.set_density('g/cm3', 1.746) - top_nozzle.add_nuclide("H1", 0.0358870, 'wo') - top_nozzle.add_nuclide("O16", 0.2847761, 'wo') - top_nozzle.add_nuclide("B10", 1.15699e-4, 'wo') - top_nozzle.add_nuclide("B11", 5.27075e-4, 'wo') - top_nozzle.add_nuclide("Fe54", 0.02644016154, 'wo') - top_nozzle.add_nuclide("Fe56", 0.43037146399, 'wo') - top_nozzle.add_nuclide("Fe57", 0.0101152584, 'wo') - top_nozzle.add_nuclide("Fe58", 0.00137211607, 'wo') - top_nozzle.add_nuclide("Ni58", 0.04104621835, 'wo') - top_nozzle.add_nuclide("Mn55", 0.0135739, 'wo') - top_nozzle.add_nuclide("Cr52", 0.107931450781, 'wo') - top_nozzle.add_s_alpha_beta('c_H_in_H2O') - - top_fa = openmc.Material(name='Top of fuel assemblies', material_id=11) - top_fa.set_density('g/cm3', 3.044) - top_fa.add_nuclide("H1", 0.0162913, 'wo') - top_fa.add_nuclide("O16", 0.1292776, 'wo') - top_fa.add_nuclide("B10", 5.25228e-5, 'wo') - top_fa.add_nuclide("B11", 2.39272e-4, 'wo') - top_fa.add_nuclide("Zr90", 0.43313403903, 'wo') - top_fa.add_nuclide("Zr91", 0.09549277374, 'wo') - top_fa.add_nuclide("Zr92", 0.14759527104, 'wo') - top_fa.add_nuclide("Zr94", 0.15280552077, 'wo') - top_fa.add_nuclide("Zr96", 0.02511169542, 'wo') - top_fa.add_s_alpha_beta('c_H_in_H2O') - - bot_fa = openmc.Material(name='Bottom of fuel assemblies', - material_id=12) - bot_fa.set_density('g/cm3', 1.762) - bot_fa.add_nuclide("H1", 0.0292856, 'wo') - bot_fa.add_nuclide("O16", 0.2323919, 'wo') - bot_fa.add_nuclide("B10", 9.44159e-5, 'wo') - bot_fa.add_nuclide("B11", 4.30120e-4, 'wo') - bot_fa.add_nuclide("Zr90", 0.3741373658, 'wo') - bot_fa.add_nuclide("Zr91", 0.0824858164, 'wo') - bot_fa.add_nuclide("Zr92", 0.1274914944, 'wo') - bot_fa.add_nuclide("Zr94", 0.1319920622, 'wo') - bot_fa.add_nuclide("Zr96", 0.0216912612, 'wo') - bot_fa.add_s_alpha_beta('c_H_in_H2O') - - # Define the materials file. - self.materials += (fuel, clad, cold_water, hot_water, rpv_steel, - lower_rad_ref, upper_rad_ref, bot_plate, - bot_nozzle, top_nozzle, top_fa, bot_fa) - - # Define surfaces. - s1 = openmc.ZCylinder(R=0.41, surface_id=1) - s2 = openmc.ZCylinder(R=0.475, surface_id=2) - s3 = openmc.ZCylinder(R=0.56, surface_id=3) - s4 = openmc.ZCylinder(R=0.62, surface_id=4) - s5 = openmc.ZCylinder(R=187.6, surface_id=5) - s6 = openmc.ZCylinder(R=209.0, surface_id=6) - s7 = openmc.ZCylinder(R=229.0, surface_id=7) - s8 = openmc.ZCylinder(R=249.0, surface_id=8) - s8.boundary_type = 'vacuum' - - s31 = openmc.ZPlane(z0=-229.0, surface_id=31) - s31.boundary_type = 'vacuum' - s32 = openmc.ZPlane(z0=-199.0, surface_id=32) - s33 = openmc.ZPlane(z0=-193.0, surface_id=33) - s34 = openmc.ZPlane(z0=-183.0, surface_id=34) - s35 = openmc.ZPlane(z0=0.0, surface_id=35) - s36 = openmc.ZPlane(z0=183.0, surface_id=36) - s37 = openmc.ZPlane(z0=203.0, surface_id=37) - s38 = openmc.ZPlane(z0=215.0, surface_id=38) - s39 = openmc.ZPlane(z0=223.0, surface_id=39) - s39.boundary_type = 'vacuum' - - # Define pin cells. - fuel_cold = openmc.Universe(name='Fuel pin, cladding, cold water', - universe_id=1) - c21 = openmc.Cell(cell_id=21) - c21.region = -s1 - c21.fill = fuel - c22 = openmc.Cell(cell_id=22) - c22.region = +s1 & -s2 - c22.fill = clad - c23 = openmc.Cell(cell_id=23) - c23.region = +s2 - c23.fill = cold_water - fuel_cold.add_cells((c21, c22, c23)) - - tube_cold = openmc.Universe(name='Instrumentation guide tube, ' - 'cold water', universe_id=2) - c24 = openmc.Cell(cell_id=24) - c24.region = -s3 - c24.fill = cold_water - c25 = openmc.Cell(cell_id=25) - c25.region = +s3 & -s4 - c25.fill = clad - c26 = openmc.Cell(cell_id=26) - c26.region = +s4 - c26.fill = cold_water - tube_cold.add_cells((c24, c25, c26)) - - fuel_hot = openmc.Universe(name='Fuel pin, cladding, hot water', - universe_id=3) - c27 = openmc.Cell(cell_id=27) - c27.region = -s1 - c27.fill = fuel - c28 = openmc.Cell(cell_id=28) - c28.region = +s1 & -s2 - c28.fill = clad - c29 = openmc.Cell(cell_id=29) - c29.region = +s2 - c29.fill = hot_water - fuel_hot.add_cells((c27, c28, c29)) - - tube_hot = openmc.Universe(name='Instrumentation guide tube, hot water', - universe_id=4) - c30 = openmc.Cell(cell_id=30) - c30.region = -s3 - c30.fill = hot_water - c31 = openmc.Cell(cell_id=31) - c31.region = +s3 & -s4 - c31.fill = clad - c32 = openmc.Cell(cell_id=32) - c32.region = +s4 - c32.fill = hot_water - tube_hot.add_cells((c30, c31, c32)) - - # Define fuel lattices. - l100 = openmc.RectLattice(name='Fuel assembly (lower half)', - lattice_id=100) - l100.lower_left = (-10.71, -10.71) - l100.pitch = (1.26, 1.26) - l100.universes = [ - [fuel_cold]*17, - [fuel_cold]*17, - [fuel_cold]*5 + [tube_cold] + [fuel_cold]*2 + [tube_cold] - + [fuel_cold]*2 + [tube_cold] + [fuel_cold]*5, - [fuel_cold]*3 + [tube_cold] + [fuel_cold]*9 + [tube_cold] - + [fuel_cold]*3, - [fuel_cold]*17, - [fuel_cold]*2 + [tube_cold] + [fuel_cold]*2 + [tube_cold] - + [fuel_cold]*2 + [tube_cold] + [fuel_cold]*2 + [tube_cold] - + [fuel_cold]*2 + [tube_cold] + [fuel_cold]*2, - [fuel_cold]*17, - [fuel_cold]*17, - [fuel_cold]*2 + [tube_cold] + [fuel_cold]*2 + [tube_cold] - + [fuel_cold]*2 + [tube_cold] + [fuel_cold]*2 + [tube_cold] - + [fuel_cold]*2 + [tube_cold] + [fuel_cold]*2, - [fuel_cold]*17, - [fuel_cold]*17, - [fuel_cold]*2 + [tube_cold] + [fuel_cold]*2 + [tube_cold] - + [fuel_cold]*2 + [tube_cold] + [fuel_cold]*2 + [tube_cold] - + [fuel_cold]*2 + [tube_cold] + [fuel_cold]*2, - [fuel_cold]*17, - [fuel_cold]*3 + [tube_cold] + [fuel_cold]*9 + [tube_cold] - + [fuel_cold]*3, - [fuel_cold]*5 + [tube_cold] + [fuel_cold]*2 + [tube_cold] - + [fuel_cold]*2 + [tube_cold] + [fuel_cold]*5, - [fuel_cold]*17, - [fuel_cold]*17 ] - - l101 = openmc.RectLattice(name='Fuel assembly (upper half)', - lattice_id=101) - l101.lower_left = (-10.71, -10.71) - l101.pitch = (1.26, 1.26) - l101.universes = [ - [fuel_hot]*17, - [fuel_hot]*17, - [fuel_hot]*5 + [tube_hot] + [fuel_hot]*2 + [tube_hot] - + [fuel_hot]*2 + [tube_hot] + [fuel_hot]*5, - [fuel_hot]*3 + [tube_hot] + [fuel_hot]*9 + [tube_hot] - + [fuel_hot]*3, - [fuel_hot]*17, - [fuel_hot]*2 + [tube_hot] + [fuel_hot]*2 + [tube_hot] - + [fuel_hot]*2 + [tube_hot] + [fuel_hot]*2 + [tube_hot] - + [fuel_hot]*2 + [tube_hot] + [fuel_hot]*2, - [fuel_hot]*17, - [fuel_hot]*17, - [fuel_hot]*2 + [tube_hot] + [fuel_hot]*2 + [tube_hot] - + [fuel_hot]*2 + [tube_hot] + [fuel_hot]*2 + [tube_hot] - + [fuel_hot]*2 + [tube_hot] + [fuel_hot]*2, - [fuel_hot]*17, - [fuel_hot]*17, - [fuel_hot]*2 + [tube_hot] + [fuel_hot]*2 + [tube_hot] - + [fuel_hot]*2 + [tube_hot] + [fuel_hot]*2 + [tube_hot] - + [fuel_hot]*2 + [tube_hot] + [fuel_hot]*2, - [fuel_hot]*17, - [fuel_hot]*3 + [tube_hot] + [fuel_hot]*9 + [tube_hot] - + [fuel_hot]*3, - [fuel_hot]*5 + [tube_hot] + [fuel_hot]*2 + [tube_hot] - + [fuel_hot]*2 + [tube_hot] + [fuel_hot]*5, - [fuel_hot]*17, - [fuel_hot]*17 ] - - # Define assemblies. - fa_cw = openmc.Universe(name='Water assembly (cold)', universe_id=5) - c50 = openmc.Cell(cell_id=50) - c50.region = +s34 & -s35 - c50.fill = cold_water - fa_cw.add_cells((c50, )) - - fa_hw = openmc.Universe(name='Water assembly (hot)', universe_id=7) - c70 = openmc.Cell(cell_id=70) - c70.region = +s35 & -s36 - c70.fill = hot_water - fa_hw.add_cells((c70, )) - - fa_cold = openmc.Universe(name='Fuel assembly (cold)', universe_id=6) - c60 = openmc.Cell(cell_id=60) - c60.region = +s34 & -s35 - c60.fill = l100 - fa_cold.add_cells((c60, )) - - fa_hot = openmc.Universe(name='Fuel assembly (hot)', universe_id=8) - c80 = openmc.Cell(cell_id=80) - c80.region = +s35 & -s36 - c80.fill = l101 - fa_hot.add_cells((c80, )) - - # Define core lattices - l200 = openmc.RectLattice(name='Core lattice (lower half)', - lattice_id=200) - l200.lower_left = (-224.91, -224.91) - l200.pitch = (21.42, 21.42) - l200.universes = [ - [fa_cw]*21, - [fa_cw]*21, - [fa_cw]*7 + [fa_cold]*7 + [fa_cw]*7, - [fa_cw]*5 + [fa_cold]*11 + [fa_cw]*5, - [fa_cw]*4 + [fa_cold]*13 + [fa_cw]*4, - [fa_cw]*3 + [fa_cold]*15 + [fa_cw]*3, - [fa_cw]*3 + [fa_cold]*15 + [fa_cw]*3, - [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2, - [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2, - [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2, - [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2, - [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2, - [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2, - [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2, - [fa_cw]*3 + [fa_cold]*15 + [fa_cw]*3, - [fa_cw]*3 + [fa_cold]*15 + [fa_cw]*3, - [fa_cw]*4 + [fa_cold]*13 + [fa_cw]*4, - [fa_cw]*5 + [fa_cold]*11 + [fa_cw]*5, - [fa_cw]*7 + [fa_cold]*7 + [fa_cw]*7, - [fa_cw]*21, - [fa_cw]*21] - - l201 = openmc.RectLattice(name='Core lattice (lower half)', - lattice_id=201) - l201.lower_left = (-224.91, -224.91) - l201.pitch = (21.42, 21.42) - l201.universes = [ - [fa_hw]*21, - [fa_hw]*21, - [fa_hw]*7 + [fa_hot]*7 + [fa_hw]*7, - [fa_hw]*5 + [fa_hot]*11 + [fa_hw]*5, - [fa_hw]*4 + [fa_hot]*13 + [fa_hw]*4, - [fa_hw]*3 + [fa_hot]*15 + [fa_hw]*3, - [fa_hw]*3 + [fa_hot]*15 + [fa_hw]*3, - [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2, - [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2, - [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2, - [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2, - [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2, - [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2, - [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2, - [fa_hw]*3 + [fa_hot]*15 + [fa_hw]*3, - [fa_hw]*3 + [fa_hot]*15 + [fa_hw]*3, - [fa_hw]*4 + [fa_hot]*13 + [fa_hw]*4, - [fa_hw]*5 + [fa_hot]*11 + [fa_hw]*5, - [fa_hw]*7 + [fa_hot]*7 + [fa_hw]*7, - [fa_hw]*21, - [fa_hw]*21] - - # Define root universe. - root = openmc.Universe(universe_id=0, name='root universe') - c1 = openmc.Cell(cell_id=1) - c1.region = -s6 & +s34 & -s35 - c1.fill = l200 - - c2 = openmc.Cell(cell_id=2) - c2.region = -s6 & +s35 & -s36 - c2.fill = l201 - - c3 = openmc.Cell(cell_id=3) - c3.region = -s7 & +s31 & -s32 - c3.fill = bot_plate - - c4 = openmc.Cell(cell_id=4) - c4.region = -s5 & +s32 & -s33 - c4.fill = bot_nozzle - - c5 = openmc.Cell(cell_id=5) - c5.region = -s5 & +s33 & -s34 - c5.fill = bot_fa - - c6 = openmc.Cell(cell_id=6) - c6.region = -s5 & +s36 & -s37 - c6.fill = top_fa - - c7 = openmc.Cell(cell_id=7) - c7.region = -s5 & +s37 & -s38 - c7.fill = top_nozzle - - c8 = openmc.Cell(cell_id=8) - c8.region = -s7 & +s38 & -s39 - c8.fill = upper_rad_ref - - c9 = openmc.Cell(cell_id=9) - c9.region = +s6 & -s7 & +s32 & -s38 - c9.fill = bot_nozzle - - c10 = openmc.Cell(cell_id=10) - c10.region = +s7 & -s8 & +s31 & -s39 - c10.fill = rpv_steel - - c11 = openmc.Cell(cell_id=11) - c11.region = +s5 & -s6 & +s32 & -s34 - c11.fill = lower_rad_ref - - c12 = openmc.Cell(cell_id=12) - c12.region = +s5 & -s6 & +s36 & -s38 - c12.fill = upper_rad_ref - - root.add_cells((c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12)) - - # Assign root universe to geometry - self.geometry.root_universe = root - - def build_default_settings(self): - self.settings.batches = 10 - self.settings.inactive = 5 - self.settings.particles = 100 - self.settings.source = Source(space=Box( - [-160, -160, -183], [160, 160, 183])) - - def build_defualt_plots(self): - plot = openmc.Plot() - plot.filename = 'mat' - plot.origin = (125, 125, 0) - plot.width = (250, 250) - plot.pixels = (3000, 3000) - plot.color_by = 'material' - - self.plots.add_plot(plot) - - -class PinCellInputSet(object): - def __init__(self): - self.settings = openmc.Settings() - self.materials = openmc.Materials() - self.geometry = openmc.Geometry() - self.tallies = None - self.plots = None - - def export(self): - self.settings.export_to_xml() - self.materials.export_to_xml() - self.geometry.export_to_xml() - if self.tallies is not None: - self.tallies.export_to_xml() - if self.plots is not None: - self.plots.export_to_xml() - - def build_default_materials_and_geometry(self): - # 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') - - # Define the materials file. - self.materials += (fuel, clad, hot_water) - - # Instantiate ZCylinder surfaces - fuel_or = openmc.ZCylinder(x0=0, y0=0, R=0.39218, name='Fuel OR') - clad_or = openmc.ZCylinder(x0=0, y0=0, R=0.45720, name='Clad OR') - left = openmc.XPlane(x0=-0.63, name='left', boundary_type='reflective') - right = openmc.XPlane(x0=0.63, name='right', boundary_type='reflective') - bottom = openmc.YPlane(y0=-0.63, name='bottom', - boundary_type='reflective') - top = openmc.YPlane(y0=0.63, name='top', boundary_type='reflective') - - # Instantiate Cells - fuel_pin = openmc.Cell(name='cell 1', fill=fuel) - cladding = openmc.Cell(name='cell 3', fill=clad) - water = openmc.Cell(name='cell 2', fill=hot_water) - - # Use surface half-spaces to define regions - fuel_pin.region = -fuel_or - cladding.region = +fuel_or & -clad_or - water.region = +clad_or & +left & -right & +bottom & -top - - # Instantiate Universe - root = openmc.Universe(universe_id=0, name='root universe') - - # Register Cells with Universe - root.add_cells([fuel_pin, cladding, water]) - - # Instantiate a Geometry, register the root Universe, and export to XML - self.geometry.root_universe = root - - def build_default_settings(self): - self.settings.batches = 10 - self.settings.inactive = 5 - self.settings.particles = 100 - self.settings.source = Source(space=Box([-0.63, -0.63, -1], - [0.63, 0.63, 1], - only_fissionable=True)) - - def build_defualt_plots(self): - plot = openmc.Plot() - plot.filename = 'mat' - plot.origin = (0.0, 0.0, 0) - plot.width = (1.26, 1.26) - plot.pixels = (300, 300) - plot.color_by = 'material' - - self.plots.add_plot(plot) - - -class AssemblyInputSet(object): - def __init__(self): - self.settings = openmc.Settings() - self.materials = openmc.Materials() - self.geometry = openmc.Geometry() - self.tallies = None - self.plots = None - - def export(self): - self.settings.export_to_xml() - self.materials.export_to_xml() - self.geometry.export_to_xml() - if self.tallies is not None: - self.tallies.export_to_xml() - if self.plots is not None: - self.plots.export_to_xml() - - def build_default_materials_and_geometry(self): - # 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') - - # Define the materials file. - self.materials += (fuel, clad, hot_water) - - # Instantiate ZCylinder surfaces - fuel_or = openmc.ZCylinder(x0=0, y0=0, R=0.39218, name='Fuel OR') - clad_or = openmc.ZCylinder(x0=0, y0=0, R=0.45720, name='Clad OR') - - # Create boundary planes to surround the geometry - min_x = openmc.XPlane(x0=-10.71, boundary_type='reflective') - max_x = openmc.XPlane(x0=+10.71, boundary_type='reflective') - min_y = openmc.YPlane(y0=-10.71, boundary_type='reflective') - max_y = openmc.YPlane(y0=+10.71, boundary_type='reflective') - - # Create a Universe to encapsulate a fuel pin - fuel_pin_universe = openmc.Universe(name='Fuel Pin') - - # Create fuel Cell - fuel_cell = openmc.Cell(name='fuel') - fuel_cell.fill = fuel - fuel_cell.region = -fuel_or - fuel_pin_universe.add_cell(fuel_cell) - - # Create a clad Cell - clad_cell = openmc.Cell(name='clad') - clad_cell.fill = clad - clad_cell.region = +fuel_or & -clad_or - fuel_pin_universe.add_cell(clad_cell) - - # Create a moderator Cell - hot_water_cell = openmc.Cell(name='hot water') - hot_water_cell.fill = hot_water - hot_water_cell.region = +clad_or - fuel_pin_universe.add_cell(hot_water_cell) - - # Create a Universe to encapsulate a control rod guide tube - guide_tube_universe = openmc.Universe(name='Guide Tube') - - # Create guide tube inner Cell - gt_inner_cell = openmc.Cell(name='guide tube inner water') - gt_inner_cell.fill = hot_water - gt_inner_cell.region = -fuel_or - guide_tube_universe.add_cell(gt_inner_cell) - - # Create a clad Cell - gt_clad_cell = openmc.Cell(name='guide tube clad') - gt_clad_cell.fill = clad - gt_clad_cell.region = +fuel_or & -clad_or - guide_tube_universe.add_cell(gt_clad_cell) - - # Create a guide tube outer Cell - gt_outer_cell = openmc.Cell(name='guide tube outer water') - gt_outer_cell.fill = hot_water - gt_outer_cell.region = +clad_or - guide_tube_universe.add_cell(gt_outer_cell) - - # Create fuel assembly Lattice - assembly = openmc.RectLattice(name='Fuel Assembly') - assembly.pitch = (1.26, 1.26) - assembly.lower_left = [-1.26 * 17. / 2.0] * 2 - - # Create array indices for guide tube locations in lattice - template_x = np.array([5, 8, 11, 3, 13, 2, 5, 8, 11, 14, 2, 5, 8, - 11, 14, 2, 5, 8, 11, 14, 3, 13, 5, 8, 11]) - template_y = np.array([2, 2, 2, 3, 3, 5, 5, 5, 5, 5, 8, 8, 8, 8, - 8, 11, 11, 11, 11, 11, 13, 13, 14, 14, 14]) - - # Initialize an empty 17x17 array of the lattice universes - universes = np.empty((17, 17), dtype=openmc.Universe) - - # Fill the array with the fuel pin and guide tube universes - universes[:,:] = fuel_pin_universe - universes[template_x, template_y] = guide_tube_universe - - # Store the array of universes in the lattice - assembly.universes = universes - - # Create root Cell - root_cell = openmc.Cell(name='root cell') - root_cell.fill = assembly - - # Add boundary planes - root_cell.region = +min_x & -max_x & +min_y & -max_y - - # Create root Universe - root_universe = openmc.Universe(universe_id=0, name='root universe') - root_universe.add_cell(root_cell) - - # Instantiate a Geometry, register the root Universe, and export to XML - self.geometry.root_universe = root_universe - - def build_default_settings(self): - self.settings.batches = 10 - self.settings.inactive = 5 - self.settings.particles = 100 - self.settings.source = Source(space=Box([-10.71, -10.71, -1], - [10.71, 10.71, 1], - only_fissionable=True)) - - def build_defualt_plots(self): - plot = openmc.Plot() - plot.filename = 'mat' - plot.origin = (0.0, 0.0, 0) - plot.width = (21.42, 21.42) - plot.pixels = (300, 300) - plot.color_by = 'material' - - self.plots.add_plot(plot) - - -class MGInputSet(InputSet): - def build_default_materials_and_geometry(self, reps=None, as_macro=True): - # Define materials needed for 1D/1G slab problem - mat_names = ['uo2', 'clad', 'lwtr'] - mgxs_reps = ['ang', 'ang_mu', 'iso', 'iso_mu'] - - if reps is None: - reps = mgxs_reps - - xs = [] - mats = [] - i = 0 - for mat in mat_names: - for rep in reps: - i += 1 - if as_macro: - xs.append(openmc.Macroscopic(mat + '_' + rep)) - mats.append(openmc.Material(name=str(i))) - mats[-1].set_density('macro', 1.) - mats[-1].add_macroscopic(xs[-1]) - else: - xs.append(openmc.Nuclide(mat + '_' + rep)) - mats.append(openmc.Material(name=str(i))) - mats[-1].set_density('atom/b-cm', 1.) - mats[-1].add_nuclide(xs[-1].name, 1.0, 'ao') - - # Define the materials file - self.xs_data = xs - self.materials += mats - self.materials.cross_sections = "../1d_mgxs.h5" - - # Define surfaces. - # Assembly/Problem Boundary - left = openmc.XPlane(x0=0.0, boundary_type='reflective') - right = openmc.XPlane(x0=10.0, boundary_type='reflective') - bottom = openmc.YPlane(y0=0.0, boundary_type='reflective') - top = openmc.YPlane(y0=10.0, boundary_type='reflective') - # for each material add a plane - planes = [openmc.ZPlane(z0=0.0, boundary_type='reflective')] - dz = round(5. / float(len(mats)), 4) - for i in range(len(mats) - 1): - planes.append(openmc.ZPlane(z0=dz * float(i + 1))) - planes.append(openmc.ZPlane(z0=5.0, boundary_type='reflective')) - - # Define cells for each material - cells = [] - xy = +left & -right & +bottom & -top - for i, mat in enumerate(mats): - cells.append(openmc.Cell()) - cells[-1].region = xy & +planes[i] & -planes[i + 1] - cells[-1].fill = mat - - # Define root universe. - root = openmc.Universe(universe_id=0, name='root universe') - root.add_cells(cells) - - # Assign root universe to geometry - self.geometry.root_universe = root - - def build_default_settings(self): - self.settings.batches = 10 - self.settings.inactive = 5 - self.settings.particles = 100 - self.settings.source = Source(space=Box([0.0, 0.0, 0.0], - [10.0, 10.0, 5.])) - self.settings.energy_mode = "multi-group" - - def build_defualt_plots(self): - plot = openmc.Plot() - plot.filename = 'mat' - plot.origin = (5.0, 5.0, 2.5) - plot.width = (2.5, 2.5) - plot.basis = 'xz' - plot.pixels = (3000, 3000) - plot.color_by = 'material' - - self.plots.add_plot(plot) diff --git a/tests/test_asymmetric_lattice/test_asymmetric_lattice.py b/tests/test_asymmetric_lattice/test_asymmetric_lattice.py index 6d36fe439..6684087bc 100644 --- a/tests/test_asymmetric_lattice/test_asymmetric_lattice.py +++ b/tests/test_asymmetric_lattice/test_asymmetric_lattice.py @@ -10,15 +10,11 @@ import openmc class AsymmetricLatticeTestHarness(PyAPITestHarness): - - def _build_inputs(self): - """Build an axis-asymmetric lattice of fuel assemblies""" - - # Build full core geometry from underlying input set - self._input_set.build_default_materials_and_geometry() + def __init__(self, *args, **kwargs): + super(AsymmetricLatticeTestHarness, self).__init__(*args, **kwargs) # Extract universes encapsulating fuel and water assemblies - geometry = self._input_set.geometry + geometry = self._model.geometry water = geometry.get_universes_by_name('water assembly (hot)')[0] fuel = geometry.get_universes_by_name('fuel assembly (hot)')[0] @@ -46,7 +42,7 @@ class AsymmetricLatticeTestHarness(PyAPITestHarness): root_univ.add_cell(root_cell) # Over-ride geometry in the input set with this 3x3 lattice - self._input_set.geometry.root_universe = root_univ + self._model.geometry.root_universe = root_univ # Initialize a "distribcell" filter for the fuel pin cell distrib_filter = openmc.DistribcellFilter(27) @@ -56,22 +52,12 @@ class AsymmetricLatticeTestHarness(PyAPITestHarness): tally.filters.append(distrib_filter) tally.scores.append('nu-fission') - # Initialize the tallies file - tallies_file = openmc.Tallies([tally]) - # Assign the tallies file to the input set - self._input_set.tallies = tallies_file - - # Build default settings - self._input_set.build_default_settings() + self._model.tallies.append(tally) # Specify summary output and correct source sampling box - source = openmc.Source(space=openmc.stats.Box([-32, -32, 0], [32, 32, 32])) - source.space.only_fissionable = True - self._input_set.settings.source = source - - # Write input XML files - self._input_set.export() + self._model.settings.source = openmc.Source(space=openmc.stats.Box( + [-32, -32, 0], [32, 32, 32], only_fissionable = True)) def _get_results(self, hash_output=True): """Digest info in statepoint and summary and return as a string.""" diff --git a/tests/test_diff_tally/test_diff_tally.py b/tests/test_diff_tally/test_diff_tally.py index 84aa18156..9343e5913 100644 --- a/tests/test_diff_tally/test_diff_tally.py +++ b/tests/test_diff_tally/test_diff_tally.py @@ -11,19 +11,16 @@ from testing_harness import PyAPITestHarness import openmc class DiffTallyTestHarness(PyAPITestHarness): - def _build_inputs(self): - # Build default materials/geometry - self._input_set.build_default_materials_and_geometry() + def __init__(self, *args, **kwargs): + super(DiffTallyTestHarness, self).__init__(*args, **kwargs) # Set settings explicitly - self._input_set.settings.batches = 3 - self._input_set.settings.inactive = 0 - self._input_set.settings.particles = 100 - self._input_set.settings.source = openmc.Source(space=openmc.stats.Box( + 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._input_set.settings.temperature['multipole'] = True - - self._input_set.tallies = openmc.Tallies() + self._model.settings.temperature['multipole'] = True filt_mats = openmc.MaterialFilter((1, 3)) filt_eout = openmc.EnergyoutFilter((0.0, 0.625, 20.0e6)) @@ -64,7 +61,7 @@ class DiffTallyTestHarness(PyAPITestHarness): t.add_score('flux') t.add_filter(filt_mats) t.derivative = derivs[i] - self._input_set.tallies.append(t) + self._model.tallies.append(t) # Cover supported scores with a collision estimator. for i in range(5): @@ -78,7 +75,7 @@ class DiffTallyTestHarness(PyAPITestHarness): t.add_nuclide('total') t.add_nuclide('U235') t.derivative = derivs[i] - self._input_set.tallies.append(t) + self._model.tallies.append(t) # Cover an analog estimator. for i in range(5): @@ -87,7 +84,7 @@ class DiffTallyTestHarness(PyAPITestHarness): t.add_filter(filt_mats) t.estimator = 'analog' t.derivative = derivs[i] - self._input_set.tallies.append(t) + self._model.tallies.append(t) # Energyout filter and total nuclide for the density derivatives. for i in range(2): @@ -99,7 +96,7 @@ class DiffTallyTestHarness(PyAPITestHarness): t.add_nuclide('total') t.add_nuclide('U235') t.derivative = derivs[i] - self._input_set.tallies.append(t) + self._model.tallies.append(t) # Energyout filter without total nuclide for other derivatives. for i in range(2, 5): @@ -110,9 +107,7 @@ class DiffTallyTestHarness(PyAPITestHarness): t.add_filter(filt_eout) t.add_nuclide('U235') t.derivative = derivs[i] - self._input_set.tallies.append(t) - - self._input_set.export() + self._model.tallies.append(t) def _get_results(self): # Read the statepoint and summary files. diff --git a/tests/test_filter_energyfun/test_filter_energyfun.py b/tests/test_filter_energyfun/test_filter_energyfun.py index fd36e320c..7d8b884ec 100644 --- a/tests/test_filter_energyfun/test_filter_energyfun.py +++ b/tests/test_filter_energyfun/test_filter_energyfun.py @@ -3,20 +3,17 @@ import os import sys import glob -import hashlib sys.path.insert(0, os.pardir) from testing_harness import PyAPITestHarness import openmc class FilterEnergyFunHarness(PyAPITestHarness): - def _build_inputs(self): - # Build the default material, geometry, settings inputs. - self._input_set.build_default_materials_and_geometry() - self._input_set.build_default_settings() + def __init__(self, *args, **kwargs): + super(FilterEnergyFunHarness, self).__init__(*args, **kwargs) # Add Am241 to the fuel. - self._input_set.materials[1].add_nuclide('Am241', 1e-7) + self._model.materials[1].add_nuclide('Am241', 1e-7) # Define Am242m / Am242 branching ratio from ENDF/B-VII.1 data. x = [1e-5, 3.69e-1, 1e3, 1e5, 6e5, 1e6, 2e6, 4e6, 3e7] @@ -37,10 +34,7 @@ class FilterEnergyFunHarness(PyAPITestHarness): t.scores = ['(n,gamma)'] t.nuclides = ['Am241'] tallies[1].filters = [filt1] - self._input_set.tallies = openmc.Tallies(tallies) - - # Export inputs to xml. - self._input_set.export() + self._model.tallies = tallies def _get_results(self): # Read the statepoint file. diff --git a/tests/test_filter_mesh/inputs_true.dat b/tests/test_filter_mesh/inputs_true.dat index 1d9d6ac5c..75c6dcc41 100644 --- a/tests/test_filter_mesh/inputs_true.dat +++ b/tests/test_filter_mesh/inputs_true.dat @@ -306,9 +306,6 @@ -160 -160 -183 160 160 183 - - true - diff --git a/tests/test_filter_mesh/test_filter_mesh.py b/tests/test_filter_mesh/test_filter_mesh.py index a37f5cfe5..d9caf9d95 100644 --- a/tests/test_filter_mesh/test_filter_mesh.py +++ b/tests/test_filter_mesh/test_filter_mesh.py @@ -2,21 +2,14 @@ import os import sys -import glob -import hashlib sys.path.insert(0, os.pardir) from testing_harness import HashedPyAPITestHarness import openmc class FilterMeshTestHarness(HashedPyAPITestHarness): - def _build_inputs(self): - - # The summary.h5 file needs to be created to read in the tallies - self._input_set.settings.output = {'summary': True} - - # Initialize the tallies file - tallies_file = openmc.Tallies() + def __init__(self, *args, **kwargs): + super(FilterMeshTestHarness, self).__init__(*args, **kwargs) # Initialize Meshes mesh_1d = openmc.Mesh(mesh_id=1) @@ -38,44 +31,40 @@ class FilterMeshTestHarness(HashedPyAPITestHarness): mesh_3d.upper_right = [182.07, 182.07, 183.00] # Initialize the filters - mesh_1d_filter = openmc.MeshFilter(mesh_1d) - mesh_2d_filter = openmc.MeshFilter(mesh_2d) - mesh_3d_filter = openmc.MeshFilter(mesh_3d) + mesh_1d_filter = openmc.MeshFilter(mesh_1d) + mesh_2d_filter = openmc.MeshFilter(mesh_2d) + mesh_3d_filter = openmc.MeshFilter(mesh_3d) # Initialized the tallies tally = openmc.Tally(name='tally 1') tally.filters = [mesh_1d_filter] tally.scores = ['total'] - tallies_file.append(tally) + self._model.tallies.append(tally) tally = openmc.Tally(name='tally 2') tally.filters = [mesh_1d_filter] tally.scores = ['current'] - tallies_file.append(tally) + self._model.tallies.append(tally) tally = openmc.Tally(name='tally 3') tally.filters = [mesh_2d_filter] tally.scores = ['total'] - tallies_file.append(tally) + self._model.tallies.append(tally) tally = openmc.Tally(name='tally 4') tally.filters = [mesh_2d_filter] tally.scores = ['current'] - tallies_file.append(tally) + self._model.tallies.append(tally) tally = openmc.Tally(name='tally 5') tally.filters = [mesh_3d_filter] tally.scores = ['total'] - tallies_file.append(tally) + self._model.tallies.append(tally) tally = openmc.Tally(name='tally 6') tally.filters = [mesh_3d_filter] tally.scores = ['current'] - tallies_file.append(tally) - - # Export tallies to file - self._input_set.tallies = tallies_file - super(FilterMeshTestHarness, self)._build_inputs() + self._model.tallies.append(tally) if __name__ == '__main__': diff --git a/tests/test_iso_in_lab/test_iso_in_lab.py b/tests/test_iso_in_lab/test_iso_in_lab.py index b60daea11..60b5bc2de 100644 --- a/tests/test_iso_in_lab/test_iso_in_lab.py +++ b/tests/test_iso_in_lab/test_iso_in_lab.py @@ -2,25 +2,12 @@ import os import sys -import glob -import hashlib sys.path.insert(0, os.pardir) from testing_harness import PyAPITestHarness -import openmc -import openmc.mgxs - - -class IsoInLabTestHarness(PyAPITestHarness): - - def _build_inputs(self): - """Write input XML files with iso-in-lab scattering.""" - - self._input_set.build_default_materials_and_geometry() - self._input_set.build_default_settings() - self._input_set.materials.make_isotropic_in_lab() - self._input_set.export() if __name__ == '__main__': - harness = IsoInLabTestHarness('statepoint.10.*') + # Force iso-in-lab scattering. + harness = PyAPITestHarness('statepoint.10.h5') + harness._model.materials.make_isotropic_in_lab() harness.main() diff --git a/tests/test_mg_basic/test_mg_basic.py b/tests/test_mg_basic/test_mg_basic.py index 1a49ee8a8..35b9c47d3 100644 --- a/tests/test_mg_basic/test_mg_basic.py +++ b/tests/test_mg_basic/test_mg_basic.py @@ -3,15 +3,11 @@ import os import sys sys.path.insert(0, os.pardir) -from testing_harness import TestHarness, PyAPITestHarness -import openmc - - -class MGBasicTestHarness(PyAPITestHarness): - def _build_inputs(self): - super(MGBasicTestHarness, self)._build_inputs() +from testing_harness import PyAPITestHarness +from openmc.examples import slab_mg if __name__ == '__main__': - harness = MGBasicTestHarness('statepoint.10.*', False, mg=True) + model = slab_mg() + harness = PyAPITestHarness('statepoint.10.h5', False, model) harness.main() diff --git a/tests/test_mg_legendre/test_mg_legendre.py b/tests/test_mg_legendre/test_mg_legendre.py index a16912c5d..3db74a824 100644 --- a/tests/test_mg_legendre/test_mg_legendre.py +++ b/tests/test_mg_legendre/test_mg_legendre.py @@ -5,24 +5,12 @@ import sys sys.path.insert(0, os.pardir) from testing_harness import PyAPITestHarness -from input_set import MGInputSet - - -class MGMaxOrderTestHarness(PyAPITestHarness): - def __init__(self, statepoint_name, tallies_present, mg=False): - PyAPITestHarness.__init__(self, statepoint_name, tallies_present) - self._input_set = MGInputSet() - - def _build_inputs(self): - """Write input XML files.""" - reps = ['iso'] - self._input_set.build_default_materials_and_geometry(reps=reps) - self._input_set.build_default_settings() - # Enforce Legendre scattering - self._input_set.settings.tabular_legendre = {'enable': False} - self._input_set.export() +from openmc.examples import slab_mg if __name__ == '__main__': - harness = MGMaxOrderTestHarness('statepoint.10.*', False, mg=True) + model = slab_mg(reps=['iso']) + model.settings.tabular_legendre = {'enable': False} + + harness = PyAPITestHarness('statepoint.10.h5', False, model) harness.main() diff --git a/tests/test_mg_max_order/test_mg_max_order.py b/tests/test_mg_max_order/test_mg_max_order.py index 8c7948a32..6a3db3aa5 100644 --- a/tests/test_mg_max_order/test_mg_max_order.py +++ b/tests/test_mg_max_order/test_mg_max_order.py @@ -5,24 +5,11 @@ import sys sys.path.insert(0, os.pardir) from testing_harness import PyAPITestHarness -from input_set import MGInputSet - - -class MGMaxOrderTestHarness(PyAPITestHarness): - def __init__(self, statepoint_name, tallies_present, mg=False): - PyAPITestHarness.__init__(self, statepoint_name, tallies_present) - self._input_set = MGInputSet() - - def _build_inputs(self): - """Write input XML files.""" - reps = ['iso'] - self._input_set.build_default_materials_and_geometry(reps=reps) - self._input_set.build_default_settings() - # Set P1 scattering - self._input_set.settings.max_order = 1 - self._input_set.export() +from openmc.examples import slab_mg if __name__ == '__main__': - harness = MGMaxOrderTestHarness('statepoint.10.*', False, mg=True) + model = slab_mg(reps=['iso']) + model.settings.max_order = 1 + harness = PyAPITestHarness('statepoint.10.h5', False, model) harness.main() diff --git a/tests/test_mg_nuclide/test_mg_nuclide.py b/tests/test_mg_nuclide/test_mg_nuclide.py index b94af258f..a0adfb023 100644 --- a/tests/test_mg_nuclide/test_mg_nuclide.py +++ b/tests/test_mg_nuclide/test_mg_nuclide.py @@ -5,21 +5,10 @@ import sys sys.path.insert(0, os.pardir) from testing_harness import PyAPITestHarness -from input_set import MGInputSet - - -class MGNuclideTestHarness(PyAPITestHarness): - def __init__(self, statepoint_name, tallies_present, mg=False): - PyAPITestHarness.__init__(self, statepoint_name, tallies_present) - self._input_set = MGInputSet() - - def _build_inputs(self): - """Write input XML files.""" - self._input_set.build_default_materials_and_geometry(as_macro=False) - self._input_set.build_default_settings() - self._input_set.export() +from openmc.examples import slab_mg if __name__ == '__main__': - harness = MGNuclideTestHarness('statepoint.10.*', False, mg=True) + model = slab_mg(as_macro=False) + harness = PyAPITestHarness('statepoint.10.h5', False, model) harness.main() diff --git a/tests/test_mg_survival_biasing/test_mg_survival_biasing.py b/tests/test_mg_survival_biasing/test_mg_survival_biasing.py index 61b7381a4..2fefee21d 100644 --- a/tests/test_mg_survival_biasing/test_mg_survival_biasing.py +++ b/tests/test_mg_survival_biasing/test_mg_survival_biasing.py @@ -3,19 +3,12 @@ import os import sys sys.path.insert(0, os.pardir) -from testing_harness import TestHarness, PyAPITestHarness -import openmc - - -class MGBasicTestHarness(PyAPITestHarness): - def _build_inputs(self): - """Write input XML files.""" - self._input_set.build_default_materials_and_geometry() - self._input_set.build_default_settings() - self._input_set.settings.survival_biasing = True - self._input_set.export() +from testing_harness import PyAPITestHarness +from openmc.examples import slab_mg if __name__ == '__main__': - harness = MGBasicTestHarness('statepoint.10.h5', False, mg=True) + model = slab_mg() + model.settings.survival_biasing = True + harness = PyAPITestHarness('statepoint.10.h5', False, model) harness.main() diff --git a/tests/test_mg_tallies/test_mg_tallies.py b/tests/test_mg_tallies/test_mg_tallies.py index 580eb60c3..cdd3a90f5 100644 --- a/tests/test_mg_tallies/test_mg_tallies.py +++ b/tests/test_mg_tallies/test_mg_tallies.py @@ -5,100 +5,92 @@ import sys sys.path.insert(0, os.pardir) from testing_harness import HashedPyAPITestHarness import openmc - - -class MGTalliesTestHarness(HashedPyAPITestHarness): - def _build_inputs(self): - """Write input XML files.""" - self._input_set.build_default_materials_and_geometry(as_macro=False) - self._input_set.build_default_settings() - - # Instantiate a tally mesh - mesh = openmc.Mesh(mesh_id=1) - mesh.type = 'regular' - mesh.dimension = [1, 1, 10] - mesh.lower_left = [0.0, 0.0, 0.0] - mesh.upper_right = [10, 10, 5] - - # Instantiate some tally filters - energy_filter = openmc.EnergyFilter([0.0, 20.0e6]) - energyout_filter = openmc.EnergyoutFilter([0.0, 20.0e6]) - matching_energy_filter = openmc.EnergyFilter([1e-5, 0.0635, 10.0, - 1.0e2, 1.0e3, 0.5e6, - 1.0e6, 20.0e6]) - matching_eout_filter = openmc.EnergyoutFilter([1e-5, 0.0635, 10.0, - 1.0e2, 1.0e3, 0.5e6, - 1.0e6, 20.0e6]) - mesh_filter = openmc.MeshFilter(mesh) - - mat_ids = [mat.id for mat in self._input_set.materials] - mat_filter = openmc.MaterialFilter(mat_ids) - - nuclides = [xs.name for xs in self._input_set.xs_data] - - scores= {False: ['total', 'absorption', 'flux', 'fission', 'nu-fission'], - True: ['total', 'absorption', 'fission', 'nu-fission']} - - tallies = [] - - for do_nuclides in [False, True]: - tallies.append(openmc.Tally()) - tallies[-1].filters = [mesh_filter] - tallies[-1].estimator = 'analog' - tallies[-1].scores = scores[do_nuclides] - if do_nuclides: - tallies[-1].nuclides = nuclides - - tallies.append(openmc.Tally()) - tallies[-1].filters = [mesh_filter] - tallies[-1].estimator = 'tracklength' - tallies[-1].scores = scores[do_nuclides] - if do_nuclides: - tallies[-1].nuclides = nuclides - - # Impose energy bins that dont match the MG structure and those - # that do - for match_energy_bins in [False, True]: - if match_energy_bins: - e_filter = matching_energy_filter - eout_filter = matching_eout_filter - else: - e_filter = energy_filter - eout_filter = energyout_filter - - tallies.append(openmc.Tally()) - tallies[-1].filters = [mat_filter, e_filter] - tallies[-1].estimator = 'analog' - tallies[-1].scores = scores[do_nuclides] + ['scatter', - 'nu-scatter'] - if do_nuclides: - tallies[-1].nuclides = nuclides - - tallies.append(openmc.Tally()) - tallies[-1].filters = [mat_filter, e_filter] - tallies[-1].estimator = 'collision' - tallies[-1].scores = scores[do_nuclides] - if do_nuclides: - tallies[-1].nuclides = nuclides - - tallies.append(openmc.Tally()) - tallies[-1].filters = [mat_filter, e_filter] - tallies[-1].estimator = 'tracklength' - tallies[-1].scores = scores[do_nuclides] - if do_nuclides: - tallies[-1].nuclides = nuclides - - tallies.append(openmc.Tally()) - tallies[-1].filters = [mat_filter, e_filter, eout_filter] - tallies[-1].scores = ['scatter', 'nu-scatter', 'nu-fission'] - if do_nuclides: - tallies[-1].nuclides = nuclides - - self._input_set.tallies = openmc.Tallies(tallies) - - self._input_set.export() +from openmc.examples import slab_mg if __name__ == '__main__': - harness = MGTalliesTestHarness('statepoint.10.h5', True, mg=True) + model = slab_mg(as_macro=False) + + # Instantiate a tally mesh + mesh = openmc.Mesh(mesh_id=1) + mesh.type = 'regular' + mesh.dimension = [1, 1, 10] + mesh.lower_left = [0.0, 0.0, 0.0] + mesh.upper_right = [10, 10, 5] + + # Instantiate some tally filters + energy_filter = openmc.EnergyFilter([0.0, 20.0e6]) + energyout_filter = openmc.EnergyoutFilter([0.0, 20.0e6]) + energies = [1e-5, 0.0635, 10.0, 1.0e2, 1.0e3, 0.5e6, 1.0e6, 20.0e6] + matching_energy_filter = openmc.EnergyFilter(energies) + matching_eout_filter = openmc.EnergyoutFilter(energies) + mesh_filter = openmc.MeshFilter(mesh) + + mat_ids = [mat.id for mat in model.materials] + mat_filter = openmc.MaterialFilter(mat_ids) + + nuclides = [xs.name for xs in model.xs_data] + + scores= {False: ['total', 'absorption', 'flux', 'fission', 'nu-fission'], + True: ['total', 'absorption', 'fission', 'nu-fission']} + + for do_nuclides in [False, True]: + t = openmc.Tally() + t.filters = [mesh_filter] + t.estimator = 'analog' + t.scores = scores[do_nuclides] + if do_nuclides: + t.nuclides = nuclides + model.tallies.append(t) + + t = openmc.Tally() + t.filters = [mesh_filter] + t.estimator = 'tracklength' + t.scores = scores[do_nuclides] + if do_nuclides: + t.nuclides = nuclides + model.tallies.append(t) + + # Impose energy bins that dont match the MG structure and those + # that do + for match_energy_bins in [False, True]: + if match_energy_bins: + e_filter = matching_energy_filter + eout_filter = matching_eout_filter + else: + e_filter = energy_filter + eout_filter = energyout_filter + + t = openmc.Tally() + t.filters = [mat_filter, e_filter] + t.estimator = 'analog' + t.scores = scores[do_nuclides] + ['scatter', 'nu-scatter'] + if do_nuclides: + t.nuclides = nuclides + model.tallies.append(t) + + t = openmc.Tally() + t.filters = [mat_filter, e_filter] + t.estimator = 'collision' + t.scores = scores[do_nuclides] + if do_nuclides: + t.nuclides = nuclides + model.tallies.append(t) + + t = openmc.Tally() + t.filters = [mat_filter, e_filter] + t.estimator = 'tracklength' + t.scores = scores[do_nuclides] + if do_nuclides: + t.nuclides = nuclides + model.tallies.append(t) + + t = openmc.Tally() + t.filters = [mat_filter, e_filter, eout_filter] + t.scores = ['scatter', 'nu-scatter', 'nu-fission'] + if do_nuclides: + t.nuclides = nuclides + model.tallies.append(t) + + harness = HashedPyAPITestHarness('statepoint.10.h5', True, model) harness.main() diff --git a/tests/test_mgxs_library_ce_to_mg/test_mgxs_library_ce_to_mg.py b/tests/test_mgxs_library_ce_to_mg/test_mgxs_library_ce_to_mg.py index 343a48a83..c296e3988 100644 --- a/tests/test_mgxs_library_ce_to_mg/test_mgxs_library_ce_to_mg.py +++ b/tests/test_mgxs_library_ce_to_mg/test_mgxs_library_ce_to_mg.py @@ -3,27 +3,23 @@ import os import sys import glob -import hashlib sys.path.insert(0, os.pardir) from testing_harness import PyAPITestHarness -from input_set import PinCellInputSet import openmc import openmc.mgxs +from openmc.examples import pwr_pin_cell class MGXSTestHarness(PyAPITestHarness): - def _build_inputs(self): - # Set the input set to use the pincell model - self._input_set = PinCellInputSet() - + def __init__(self, *args, **kwargs): # Generate inputs using parent class routine - super(MGXSTestHarness, self)._build_inputs() + super(MGXSTestHarness, self).__init__(*args, **kwargs) # Initialize a two-group structure energy_groups = openmc.mgxs.EnergyGroups(group_edges=[0, 0.625, 20.e6]) # Initialize MGXS Library for a few cross section types - self.mgxs_lib = openmc.mgxs.Library(self._input_set.geometry) + self.mgxs_lib = openmc.mgxs.Library(self._model.geometry) self.mgxs_lib.by_nuclide = False self.mgxs_lib.mgxs_types = ['total', 'absorption', 'nu-fission matrix', 'nu-scatter matrix', 'multiplicity matrix'] @@ -34,9 +30,7 @@ class MGXSTestHarness(PyAPITestHarness): self.mgxs_lib.build_library() # Initialize a tallies file - self._input_set.tallies = openmc.Tallies() - self.mgxs_lib.add_to_tallies_file(self._input_set.tallies, merge=False) - self._input_set.tallies.export_to_xml() + self.mgxs_lib.add_to_tallies_file(self._model.tallies, merge=False) def _run_openmc(self): # Initial run @@ -55,18 +49,18 @@ class MGXSTestHarness(PyAPITestHarness): statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))[0] sp = openmc.StatePoint(statepoint) self.mgxs_lib.load_from_statepoint(sp) - self._input_set.mgxs_file, self._input_set.materials, \ - self._input_set.geometry = self.mgxs_lib.create_mg_mode() + self._model.mgxs_file, self._model.materials, \ + self._model.geometry = self.mgxs_lib.create_mg_mode() # Modify materials and settings so we can run in MG mode - self._input_set.materials.cross_sections = './mgxs.h5' - self._input_set.settings.energy_mode = 'multi-group' + self._model.materials.cross_sections = './mgxs.h5' + self._model.settings.energy_mode = 'multi-group' # Write modified input files - self._input_set.settings.export_to_xml() - self._input_set.geometry.export_to_xml() - self._input_set.materials.export_to_xml() - self._input_set.mgxs_file.export_to_hdf5() + self._model.settings.export_to_xml() + self._model.geometry.export_to_xml() + self._model.materials.export_to_xml() + self._model.mgxs_file.export_to_hdf5() # Dont need tallies.xml, so remove the file if os.path.exists('./tallies.xml'): os.remove('./tallies.xml') @@ -92,5 +86,8 @@ class MGXSTestHarness(PyAPITestHarness): if __name__ == '__main__': - harness = MGXSTestHarness('statepoint.10.*', False) + # Set the input set to use the pincell model + model = pwr_pin_cell() + + harness = MGXSTestHarness('statepoint.10.h5', False, model) harness.main() diff --git a/tests/test_mgxs_library_condense/test_mgxs_library_condense.py b/tests/test_mgxs_library_condense/test_mgxs_library_condense.py index 087e7a07b..bfa612e4e 100644 --- a/tests/test_mgxs_library_condense/test_mgxs_library_condense.py +++ b/tests/test_mgxs_library_condense/test_mgxs_library_condense.py @@ -6,24 +6,20 @@ import glob import hashlib sys.path.insert(0, os.pardir) from testing_harness import PyAPITestHarness -from input_set import PinCellInputSet import openmc import openmc.mgxs +from openmc.examples import pwr_pin_cell class MGXSTestHarness(PyAPITestHarness): - def _build_inputs(self): - # Set the input set to use the pincell model - self._input_set = PinCellInputSet() - - # Generate inputs using parent class routine - super(MGXSTestHarness, self)._build_inputs() + def __init__(self, *args, **kwargs): + super(MGXSTestHarness, self).__init__(*args, **kwargs) # Initialize a two-group structure energy_groups = openmc.mgxs.EnergyGroups(group_edges=[0, 0.625, 20.e6]) # Initialize MGXS Library for a few cross section types - self.mgxs_lib = openmc.mgxs.Library(self._input_set.geometry) + self.mgxs_lib = openmc.mgxs.Library(self._model.geometry) self.mgxs_lib.by_nuclide = False # Test all MGXS types @@ -35,10 +31,8 @@ class MGXSTestHarness(PyAPITestHarness): self.mgxs_lib.domain_type = 'material' self.mgxs_lib.build_library() - # Initialize a tallies file - self._input_set.tallies = openmc.Tallies() - self.mgxs_lib.add_to_tallies_file(self._input_set.tallies, merge=False) - self._input_set.tallies.export_to_xml() + # Add tallies + self.mgxs_lib.add_to_tallies_file(self._model.tallies, merge=False) def _get_results(self, hash_output=False): """Digest info in the statepoint and return as a string.""" @@ -72,5 +66,7 @@ class MGXSTestHarness(PyAPITestHarness): if __name__ == '__main__': - harness = MGXSTestHarness('statepoint.10.*', True) + # Use the pincell model + model = pwr_pin_cell() + harness = MGXSTestHarness('statepoint.10.h5', True, model) harness.main() diff --git a/tests/test_mgxs_library_distribcell/test_mgxs_library_distribcell.py b/tests/test_mgxs_library_distribcell/test_mgxs_library_distribcell.py index 9ab7548fa..71b7b4378 100644 --- a/tests/test_mgxs_library_distribcell/test_mgxs_library_distribcell.py +++ b/tests/test_mgxs_library_distribcell/test_mgxs_library_distribcell.py @@ -6,25 +6,22 @@ import glob import hashlib sys.path.insert(0, os.pardir) from testing_harness import PyAPITestHarness -from input_set import AssemblyInputSet import openmc import openmc.mgxs +from openmc.examples import pwr_assembly class MGXSTestHarness(PyAPITestHarness): - def _build_inputs(self): - # Set the input set to use the pincell model - self._input_set = AssemblyInputSet() - + def __init__(self, *args, **kwargs): # Generate inputs using parent class routine - super(MGXSTestHarness, self)._build_inputs() + super(MGXSTestHarness, self).__init__(*args, **kwargs) # Initialize a one-group structure energy_groups = openmc.mgxs.EnergyGroups(group_edges=[0, 20.e6]) # Initialize MGXS Library for a few cross section types # for one material-filled cell in the geometry - self.mgxs_lib = openmc.mgxs.Library(self._input_set.geometry) + self.mgxs_lib = openmc.mgxs.Library(self._model.geometry) self.mgxs_lib.by_nuclide = False # Test all MGXS types @@ -38,10 +35,9 @@ class MGXSTestHarness(PyAPITestHarness): self.mgxs_lib.domains = [c for c in cells if c.name == 'fuel'] self.mgxs_lib.build_library() - # Initialize a tallies file - self._input_set.tallies = openmc.Tallies() - self.mgxs_lib.add_to_tallies_file(self._input_set.tallies, merge=False) - self._input_set.tallies.export_to_xml() + # Add tallies + self.mgxs_lib.add_to_tallies_file(self._model.tallies, merge=False) + self._model.tallies.export_to_xml() def _get_results(self, hash_output=False): """Digest info in the statepoint and return as a string.""" @@ -74,5 +70,6 @@ class MGXSTestHarness(PyAPITestHarness): if __name__ == '__main__': - harness = MGXSTestHarness('statepoint.10.h5', True) + model = pwr_assembly() + harness = MGXSTestHarness('statepoint.10.h5', True, model) harness.main() diff --git a/tests/test_mgxs_library_hdf5/test_mgxs_library_hdf5.py b/tests/test_mgxs_library_hdf5/test_mgxs_library_hdf5.py index 3c657981b..219ba4c0f 100644 --- a/tests/test_mgxs_library_hdf5/test_mgxs_library_hdf5.py +++ b/tests/test_mgxs_library_hdf5/test_mgxs_library_hdf5.py @@ -10,27 +10,24 @@ import h5py sys.path.insert(0, os.pardir) from testing_harness import PyAPITestHarness -from input_set import PinCellInputSet import openmc import openmc.mgxs +from openmc.examples import pwr_pin_cell np.set_printoptions(formatter={'float_kind': '{:.8e}'.format}) class MGXSTestHarness(PyAPITestHarness): - def _build_inputs(self): - # Set the input set to use the pincell model - self._input_set = PinCellInputSet() - + def __init__(self, *args, **kwargs): # Generate inputs using parent class routine - super(MGXSTestHarness, self)._build_inputs() + super(MGXSTestHarness, self).__init__(*args, **kwargs) # Initialize a two-group structure energy_groups = openmc.mgxs.EnergyGroups(group_edges=[0, 0.625, 20.e6]) # Initialize MGXS Library for a few cross section types - self.mgxs_lib = openmc.mgxs.Library(self._input_set.geometry) + self.mgxs_lib = openmc.mgxs.Library(self._model.geometry) self.mgxs_lib.by_nuclide = False # Test all MGXS types @@ -42,10 +39,8 @@ class MGXSTestHarness(PyAPITestHarness): self.mgxs_lib.domain_type = 'material' self.mgxs_lib.build_library() - # Initialize a tallies file - self._input_set.tallies = openmc.Tallies() - self.mgxs_lib.add_to_tallies_file(self._input_set.tallies, merge=False) - self._input_set.tallies.export_to_xml() + # Add tallies + self.mgxs_lib.add_to_tallies_file(self._model.tallies, merge=False) def _get_results(self, hash_output=False): """Digest info in the statepoint and return as a string.""" @@ -59,21 +54,18 @@ class MGXSTestHarness(PyAPITestHarness): # Export the MGXS Library to an HDF5 file self.mgxs_lib.build_hdf5_store(directory='.') - + # Open the MGXS HDF5 file - f = h5py.File('mgxs.h5', 'r') + with h5py.File('mgxs.h5', 'r') as f: - # Build a string from the datasets in the HDF5 file - outstr = '' - for domain in self.mgxs_lib.domains: - for mgxs_type in self.mgxs_lib.mgxs_types: - outstr += 'domain={0} type={1}\n'.format(domain.id, mgxs_type) - avg_key = 'material/{0}/{1}/average'.format(domain.id, mgxs_type) - std_key = 'material/{0}/{1}/std. dev.'.format(domain.id, mgxs_type) - outstr += '{}\n{}\n'.format(f[avg_key][...], f[std_key][...]) - - # Close the MGXS HDF5 file - f.close() + # Build a string from the datasets in the HDF5 file + outstr = '' + for domain in self.mgxs_lib.domains: + for mgxs_type in self.mgxs_lib.mgxs_types: + outstr += 'domain={0} type={1}\n'.format(domain.id, mgxs_type) + avg_key = 'material/{0}/{1}/average'.format(domain.id, mgxs_type) + std_key = 'material/{0}/{1}/std. dev.'.format(domain.id, mgxs_type) + outstr += '{}\n{}\n'.format(f[avg_key][...], f[std_key][...]) # Hash the results if necessary if hash_output: @@ -85,12 +77,12 @@ class MGXSTestHarness(PyAPITestHarness): def _cleanup(self): super(MGXSTestHarness, self)._cleanup() - f = os.path.join(os.getcwd(), 'tallies.xml') - if os.path.exists(f): os.remove(f) f = os.path.join(os.getcwd(), 'mgxs.h5') - if os.path.exists(f): os.remove(f) + if os.path.exists(f): + os.remove(f) if __name__ == '__main__': - harness = MGXSTestHarness('statepoint.10.*', True) + model = pwr_pin_cell() + harness = MGXSTestHarness('statepoint.10.*', True, model) harness.main() diff --git a/tests/test_mgxs_library_mesh/test_mgxs_library_mesh.py b/tests/test_mgxs_library_mesh/test_mgxs_library_mesh.py index 7f67afd65..c52a23153 100644 --- a/tests/test_mgxs_library_mesh/test_mgxs_library_mesh.py +++ b/tests/test_mgxs_library_mesh/test_mgxs_library_mesh.py @@ -11,16 +11,15 @@ import openmc.mgxs class MGXSTestHarness(PyAPITestHarness): - def _build_inputs(self): - # Generate inputs using parent class routine - super(MGXSTestHarness, self)._build_inputs() + def __init__(self, *args, **kwargs): + super(MGXSTestHarness, self).__init__(*args, **kwargs) # Initialize a one-group structure energy_groups = openmc.mgxs.EnergyGroups(group_edges=[0, 20.e6]) # Initialize MGXS Library for a few cross section types # for one material-filled cell in the geometry - self.mgxs_lib = openmc.mgxs.Library(self._input_set.geometry) + self.mgxs_lib = openmc.mgxs.Library(self._model.geometry) self.mgxs_lib.by_nuclide = False # Test all MGXS types @@ -41,10 +40,8 @@ class MGXSTestHarness(PyAPITestHarness): self.mgxs_lib.domains = [mesh] self.mgxs_lib.build_library() - # Initialize a tallies file - self._input_set.tallies = openmc.Tallies() - self.mgxs_lib.add_to_tallies_file(self._input_set.tallies, merge=False) - self._input_set.tallies.export_to_xml() + # Add tallies + self.mgxs_lib.add_to_tallies_file(self._model.tallies, merge=False) def _get_results(self, hash_output=False): """Digest info in the statepoint and return as a string.""" diff --git a/tests/test_mgxs_library_no_nuclides/test_mgxs_library_no_nuclides.py b/tests/test_mgxs_library_no_nuclides/test_mgxs_library_no_nuclides.py index aaad7d32b..fdd05bb65 100644 --- a/tests/test_mgxs_library_no_nuclides/test_mgxs_library_no_nuclides.py +++ b/tests/test_mgxs_library_no_nuclides/test_mgxs_library_no_nuclides.py @@ -6,24 +6,21 @@ import glob import hashlib sys.path.insert(0, os.pardir) from testing_harness import PyAPITestHarness -from input_set import PinCellInputSet import openmc import openmc.mgxs +from openmc.examples import pwr_pin_cell class MGXSTestHarness(PyAPITestHarness): - def _build_inputs(self): - # Set the input set to use the pincell model - self._input_set = PinCellInputSet() - + def __init__(self, *args, **kwargs): # Generate inputs using parent class routine - super(MGXSTestHarness, self)._build_inputs() + super(MGXSTestHarness, self).__init__(*args, **kwargs) # Initialize a two-group structure energy_groups = openmc.mgxs.EnergyGroups(group_edges=[0, 0.625, 20.e6]) # Initialize MGXS Library for a few cross section types - self.mgxs_lib = openmc.mgxs.Library(self._input_set.geometry) + self.mgxs_lib = openmc.mgxs.Library(self._model.geometry) self.mgxs_lib.by_nuclide = False # Test all MGXS types @@ -35,10 +32,8 @@ class MGXSTestHarness(PyAPITestHarness): self.mgxs_lib.domain_type = 'material' self.mgxs_lib.build_library() - # Initialize a tallies file - self._input_set.tallies = openmc.Tallies() - self.mgxs_lib.add_to_tallies_file(self._input_set.tallies, merge=False) - self._input_set.tallies.export_to_xml() + # Add tallies + self.mgxs_lib.add_to_tallies_file(self._model.tallies, merge=False) def _get_results(self, hash_output=False): """Digest info in the statepoint and return as a string.""" @@ -68,5 +63,6 @@ class MGXSTestHarness(PyAPITestHarness): if __name__ == '__main__': - harness = MGXSTestHarness('statepoint.10.h5', True) + model = pwr_pin_cell() + harness = MGXSTestHarness('statepoint.10.h5', True, model) harness.main() diff --git a/tests/test_mgxs_library_nuclides/test_mgxs_library_nuclides.py b/tests/test_mgxs_library_nuclides/test_mgxs_library_nuclides.py index 83d0ba05e..d5c3665ff 100644 --- a/tests/test_mgxs_library_nuclides/test_mgxs_library_nuclides.py +++ b/tests/test_mgxs_library_nuclides/test_mgxs_library_nuclides.py @@ -6,24 +6,20 @@ import glob import hashlib sys.path.insert(0, os.pardir) from testing_harness import PyAPITestHarness -from input_set import PinCellInputSet import openmc import openmc.mgxs +from openmc.examples import pwr_pin_cell class MGXSTestHarness(PyAPITestHarness): - def _build_inputs(self): - # Set the input set to use the pincell model - self._input_set = PinCellInputSet() - - # Generate inputs using parent class routine - super(MGXSTestHarness, self)._build_inputs() + def __init__(self, *args, **kwargs): + super(MGXSTestHarness, self).__init__(*args, **kwargs) # Initialize a two-group structure energy_groups = openmc.mgxs.EnergyGroups(group_edges=[0, 0.625, 20.e6]) # Initialize MGXS Library for a few cross section types - self.mgxs_lib = openmc.mgxs.Library(self._input_set.geometry) + self.mgxs_lib = openmc.mgxs.Library(self._model.geometry) self.mgxs_lib.by_nuclide = True # Test all MGXS types self.mgxs_lib.mgxs_types = openmc.mgxs.MGXS_TYPES @@ -32,10 +28,8 @@ class MGXSTestHarness(PyAPITestHarness): self.mgxs_lib.domain_type = 'material' self.mgxs_lib.build_library() - # Initialize a tallies file - self._input_set.tallies = openmc.Tallies() - self.mgxs_lib.add_to_tallies_file(self._input_set.tallies, merge=False) - self._input_set.tallies.export_to_xml() + # Add tallies + self.mgxs_lib.add_to_tallies_file(self._model.tallies, merge=False) def _get_results(self, hash_output=True): """Digest info in the statepoint and return as a string.""" @@ -65,5 +59,6 @@ class MGXSTestHarness(PyAPITestHarness): if __name__ == '__main__': - harness = MGXSTestHarness('statepoint.10.h5', True) + model = pwr_pin_cell() + harness = MGXSTestHarness('statepoint.10.h5', True, model) harness.main() diff --git a/tests/test_tallies/test_tallies.py b/tests/test_tallies/test_tallies.py index 2efea5d3a..b41068f8e 100644 --- a/tests/test_tallies/test_tallies.py +++ b/tests/test_tallies/test_tallies.py @@ -4,180 +4,168 @@ import os import sys sys.path.insert(0, os.pardir) -from testing_harness import PyAPITestHarness +from testing_harness import HashedPyAPITestHarness from openmc.filter import * from openmc import Mesh, Tally, Tallies -from openmc.source import Source -from openmc.stats import Box - - -class TalliesTestHarness(PyAPITestHarness): - def _build_inputs(self): - # Build default materials/geometry - self._input_set.build_default_materials_and_geometry() - - # Set settings explicitly - self._input_set.settings.batches = 5 - self._input_set.settings.inactive = 0 - self._input_set.settings.particles = 400 - self._input_set.settings.source = Source(space=Box( - [-160, -160, -183], [160, 160, 183])) - - azimuthal_bins = (-3.14159, -1.8850, -0.6283, 0.6283, 1.8850, 3.14159) - azimuthal_filter = AzimuthalFilter(azimuthal_bins) - azimuthal_tally1 = Tally() - azimuthal_tally1.filters = [azimuthal_filter] - azimuthal_tally1.scores = ['flux'] - azimuthal_tally1.estimator = 'tracklength' - - azimuthal_tally2 = Tally() - azimuthal_tally2.filters = [azimuthal_filter] - azimuthal_tally2.scores = ['flux'] - azimuthal_tally2.estimator = 'analog' - - mesh_2x2 = Mesh(mesh_id=1) - mesh_2x2.lower_left = [-182.07, -182.07] - mesh_2x2.upper_right = [182.07, 182.07] - mesh_2x2.dimension = [2, 2] - mesh_filter = MeshFilter(mesh_2x2) - azimuthal_tally3 = Tally() - azimuthal_tally3.filters = [azimuthal_filter, mesh_filter] - azimuthal_tally3.scores = ['flux'] - azimuthal_tally3.estimator = 'tracklength' - - cellborn_tally = Tally() - cellborn_tally.filters = [CellbornFilter((10, 21, 22, 23))] - cellborn_tally.scores = ['total'] - - dg_tally = Tally() - dg_tally.filters = [DelayedGroupFilter((1, 2, 3, 4, 5, 6))] - dg_tally.scores = ['delayed-nu-fission'] - - four_groups = (0.0, 0.253, 1.0e3, 1.0e6, 20.0e6) - energy_filter = EnergyFilter(four_groups) - energy_tally = Tally() - energy_tally.filters = [energy_filter] - energy_tally.scores = ['total'] - - energyout_filter = EnergyoutFilter(four_groups) - energyout_tally = Tally() - energyout_tally.filters = [energyout_filter] - energyout_tally.scores = ['scatter'] - - transfer_tally = Tally() - transfer_tally.filters = [energy_filter, energyout_filter] - transfer_tally.scores = ['scatter', 'nu-fission'] - - material_tally = Tally() - material_tally.filters = [MaterialFilter((1, 2, 3, 4))] - material_tally.scores = ['total'] - - mu_bins = (-1.0, -0.5, 0.0, 0.5, 1.0) - mu_filter = MuFilter(mu_bins) - mu_tally1 = Tally() - mu_tally1.filters = [mu_filter] - mu_tally1.scores = ['scatter', 'nu-scatter'] - - mu_tally2 = Tally() - mu_tally2.filters = [mu_filter, mesh_filter] - mu_tally2.scores = ['scatter', 'nu-scatter'] - - polar_bins = (0.0, 0.6283, 1.2566, 1.8850, 2.5132, 3.14159) - polar_filter = PolarFilter(polar_bins) - polar_tally1 = Tally() - polar_tally1.filters = [polar_filter] - polar_tally1.scores = ['flux'] - polar_tally1.estimator = 'tracklength' - - polar_tally2 = Tally() - polar_tally2.filters = [polar_filter] - polar_tally2.scores = ['flux'] - polar_tally2.estimator = 'analog' - - polar_tally3 = Tally() - polar_tally3.filters = [polar_filter, mesh_filter] - polar_tally3.scores = ['flux'] - polar_tally3.estimator = 'tracklength' - - universe_tally = Tally() - universe_tally.filters = [UniverseFilter((1, 2, 3, 4, 6, 8))] - universe_tally.scores = ['total'] - - cell_filter = CellFilter((10, 21, 22, 23, 60)) - score_tallies = [Tally(), Tally(), Tally()] - for t in score_tallies: - t.filters = [cell_filter] - t.scores = ['absorption', 'delayed-nu-fission', 'events', 'fission', - 'inverse-velocity', 'kappa-fission', '(n,2n)', '(n,n1)', - '(n,gamma)', 'nu-fission', 'scatter', 'elastic', - 'total', 'prompt-nu-fission', 'fission-q-prompt', - 'fission-q-recoverable'] - score_tallies[0].estimator = 'tracklength' - score_tallies[1].estimator = 'analog' - score_tallies[2].estimator = 'collision' - - cell_filter2 = CellFilter((21, 22, 23, 27, 28, 29, 60)) - flux_tallies = [Tally() for i in range(4)] - for t in flux_tallies: - t.filters = [cell_filter2] - flux_tallies[0].scores = ['flux'] - for t in flux_tallies[1:]: - t.scores = ['flux-y5'] - flux_tallies[1].estimator = 'tracklength' - flux_tallies[2].estimator = 'analog' - flux_tallies[3].estimator = 'collision' - - scatter_tally1 = Tally() - scatter_tally1.filters = [cell_filter] - scatter_tally1.scores = ['scatter', 'scatter-1', 'scatter-2', 'scatter-3', - 'scatter-4', 'nu-scatter', 'nu-scatter-1', - 'nu-scatter-2', 'nu-scatter-3', 'nu-scatter-4'] - - scatter_tally2 = Tally() - scatter_tally2.filters = [cell_filter] - scatter_tally2.scores = ['scatter-p4', 'scatter-y4', 'nu-scatter-p4', - 'nu-scatter-y3'] - - total_tallies = [Tally() for i in range(4)] - for t in total_tallies: - t.filters = [cell_filter] - total_tallies[0].scores = ['total'] - for t in total_tallies[1:]: - t.scores = ['total-y4'] - t.nuclides = ['U235', 'total'] - total_tallies[1].estimator = 'tracklength' - total_tallies[2].estimator = 'analog' - total_tallies[3].estimator = 'collision' - - all_nuclide_tallies = [Tally() for i in range(4)] - for t in all_nuclide_tallies: - t.filters = [cell_filter] - t.estimator = 'tracklength' - t.nuclides = ['all'] - t.scores = ['total'] - all_nuclide_tallies[1].estimator = 'collision' - all_nuclide_tallies[2].filters = [mesh_filter] - all_nuclide_tallies[3].filters = [mesh_filter] - all_nuclide_tallies[3].nuclides = ['U235'] - - self._input_set.tallies = Tallies() - self._input_set.tallies += ( - [azimuthal_tally1, azimuthal_tally2, azimuthal_tally3, - cellborn_tally, dg_tally, energy_tally, energyout_tally, - transfer_tally, material_tally, mu_tally1, mu_tally2, - polar_tally1, polar_tally2, polar_tally3, universe_tally]) - self._input_set.tallies += score_tallies - self._input_set.tallies += flux_tallies - self._input_set.tallies += (scatter_tally1, scatter_tally2) - self._input_set.tallies += total_tallies - self._input_set.tallies += all_nuclide_tallies - - self._input_set.export() - - def _get_results(self): - return super(TalliesTestHarness, self)._get_results(hash_output=True) if __name__ == '__main__': - harness = TalliesTestHarness('statepoint.5.h5', True) + harness = HashedPyAPITestHarness('statepoint.5.h5', True) + model = harness._model + + # Set settings explicitly + model.settings.batches = 5 + model.settings.inactive = 0 + model.settings.particles = 400 + model.settings.source = openmc.Source(space=openmc.stats.Box( + [-160, -160, -183], [160, 160, 183])) + + azimuthal_bins = (-3.14159, -1.8850, -0.6283, 0.6283, 1.8850, 3.14159) + azimuthal_filter = AzimuthalFilter(azimuthal_bins) + azimuthal_tally1 = Tally() + azimuthal_tally1.filters = [azimuthal_filter] + azimuthal_tally1.scores = ['flux'] + azimuthal_tally1.estimator = 'tracklength' + + azimuthal_tally2 = Tally() + azimuthal_tally2.filters = [azimuthal_filter] + azimuthal_tally2.scores = ['flux'] + azimuthal_tally2.estimator = 'analog' + + mesh_2x2 = Mesh(mesh_id=1) + mesh_2x2.lower_left = [-182.07, -182.07] + mesh_2x2.upper_right = [182.07, 182.07] + mesh_2x2.dimension = [2, 2] + mesh_filter = MeshFilter(mesh_2x2) + azimuthal_tally3 = Tally() + azimuthal_tally3.filters = [azimuthal_filter, mesh_filter] + azimuthal_tally3.scores = ['flux'] + azimuthal_tally3.estimator = 'tracklength' + + cellborn_tally = Tally() + cellborn_tally.filters = [CellbornFilter((10, 21, 22, 23))] + cellborn_tally.scores = ['total'] + + dg_tally = Tally() + dg_tally.filters = [DelayedGroupFilter((1, 2, 3, 4, 5, 6))] + dg_tally.scores = ['delayed-nu-fission'] + + four_groups = (0.0, 0.253, 1.0e3, 1.0e6, 20.0e6) + energy_filter = EnergyFilter(four_groups) + energy_tally = Tally() + energy_tally.filters = [energy_filter] + energy_tally.scores = ['total'] + + energyout_filter = EnergyoutFilter(four_groups) + energyout_tally = Tally() + energyout_tally.filters = [energyout_filter] + energyout_tally.scores = ['scatter'] + + transfer_tally = Tally() + transfer_tally.filters = [energy_filter, energyout_filter] + transfer_tally.scores = ['scatter', 'nu-fission'] + + material_tally = Tally() + material_tally.filters = [MaterialFilter((1, 2, 3, 4))] + material_tally.scores = ['total'] + + mu_bins = (-1.0, -0.5, 0.0, 0.5, 1.0) + mu_filter = MuFilter(mu_bins) + mu_tally1 = Tally() + mu_tally1.filters = [mu_filter] + mu_tally1.scores = ['scatter', 'nu-scatter'] + + mu_tally2 = Tally() + mu_tally2.filters = [mu_filter, mesh_filter] + mu_tally2.scores = ['scatter', 'nu-scatter'] + + polar_bins = (0.0, 0.6283, 1.2566, 1.8850, 2.5132, 3.14159) + polar_filter = PolarFilter(polar_bins) + polar_tally1 = Tally() + polar_tally1.filters = [polar_filter] + polar_tally1.scores = ['flux'] + polar_tally1.estimator = 'tracklength' + + polar_tally2 = Tally() + polar_tally2.filters = [polar_filter] + polar_tally2.scores = ['flux'] + polar_tally2.estimator = 'analog' + + polar_tally3 = Tally() + polar_tally3.filters = [polar_filter, mesh_filter] + polar_tally3.scores = ['flux'] + polar_tally3.estimator = 'tracklength' + + universe_tally = Tally() + universe_tally.filters = [UniverseFilter((1, 2, 3, 4, 6, 8))] + universe_tally.scores = ['total'] + + cell_filter = CellFilter((10, 21, 22, 23, 60)) + score_tallies = [Tally(), Tally(), Tally()] + for t in score_tallies: + t.filters = [cell_filter] + t.scores = ['absorption', 'delayed-nu-fission', 'events', 'fission', + 'inverse-velocity', 'kappa-fission', '(n,2n)', '(n,n1)', + '(n,gamma)', 'nu-fission', 'scatter', 'elastic', + 'total', 'prompt-nu-fission', 'fission-q-prompt', + 'fission-q-recoverable'] + score_tallies[0].estimator = 'tracklength' + score_tallies[1].estimator = 'analog' + score_tallies[2].estimator = 'collision' + + cell_filter2 = CellFilter((21, 22, 23, 27, 28, 29, 60)) + flux_tallies = [Tally() for i in range(4)] + for t in flux_tallies: + t.filters = [cell_filter2] + flux_tallies[0].scores = ['flux'] + for t in flux_tallies[1:]: + t.scores = ['flux-y5'] + flux_tallies[1].estimator = 'tracklength' + flux_tallies[2].estimator = 'analog' + flux_tallies[3].estimator = 'collision' + + scatter_tally1 = Tally() + scatter_tally1.filters = [cell_filter] + scatter_tally1.scores = ['scatter', 'scatter-1', 'scatter-2', 'scatter-3', + 'scatter-4', 'nu-scatter', 'nu-scatter-1', + 'nu-scatter-2', 'nu-scatter-3', 'nu-scatter-4'] + + scatter_tally2 = Tally() + scatter_tally2.filters = [cell_filter] + scatter_tally2.scores = ['scatter-p4', 'scatter-y4', 'nu-scatter-p4', + 'nu-scatter-y3'] + + total_tallies = [Tally() for i in range(4)] + for t in total_tallies: + t.filters = [cell_filter] + total_tallies[0].scores = ['total'] + for t in total_tallies[1:]: + t.scores = ['total-y4'] + t.nuclides = ['U235', 'total'] + total_tallies[1].estimator = 'tracklength' + total_tallies[2].estimator = 'analog' + total_tallies[3].estimator = 'collision' + + all_nuclide_tallies = [Tally() for i in range(4)] + for t in all_nuclide_tallies: + t.filters = [cell_filter] + t.estimator = 'tracklength' + t.nuclides = ['all'] + t.scores = ['total'] + all_nuclide_tallies[1].estimator = 'collision' + all_nuclide_tallies[2].filters = [mesh_filter] + all_nuclide_tallies[3].filters = [mesh_filter] + all_nuclide_tallies[3].nuclides = ['U235'] + + model.tallies += [ + azimuthal_tally1, azimuthal_tally2, azimuthal_tally3, + cellborn_tally, dg_tally, energy_tally, energyout_tally, + transfer_tally, material_tally, mu_tally1, mu_tally2, + polar_tally1, polar_tally2, polar_tally3, universe_tally] + model.tallies += score_tallies + model.tallies += flux_tallies + model.tallies += (scatter_tally1, scatter_tally2) + model.tallies += total_tallies + model.tallies += all_nuclide_tallies + harness.main() diff --git a/tests/test_tally_aggregation/inputs_true.dat b/tests/test_tally_aggregation/inputs_true.dat index 8223b8d6a..041221cb6 100644 --- a/tests/test_tally_aggregation/inputs_true.dat +++ b/tests/test_tally_aggregation/inputs_true.dat @@ -306,9 +306,6 @@ -160 -160 -183 160 160 183 - - true - diff --git a/tests/test_tally_aggregation/test_tally_aggregation.py b/tests/test_tally_aggregation/test_tally_aggregation.py index 012c2fb73..cb98b53fa 100644 --- a/tests/test_tally_aggregation/test_tally_aggregation.py +++ b/tests/test_tally_aggregation/test_tally_aggregation.py @@ -10,15 +10,8 @@ import openmc class TallyAggregationTestHarness(PyAPITestHarness): - def _build_inputs(self): - - # The summary.h5 file needs to be created to read in the tallies - self._input_set.settings.output = {'summary': True} - - # Initialize the nuclides - u234 = openmc.Nuclide('U234') - u235 = openmc.Nuclide('U235') - u238 = openmc.Nuclide('U238') + def __init__(self, *args, **kwargs): + super(TallyAggregationTestHarness, self).__init__(*args, **kwargs) # Initialize the filters energy_filter = openmc.EnergyFilter([0.0, 0.253, 1.0e3, 1.0e6, 20.0e6]) @@ -28,12 +21,8 @@ class TallyAggregationTestHarness(PyAPITestHarness): tally = openmc.Tally(name='distribcell tally') tally.filters = [energy_filter, distrib_filter] tally.scores = ['nu-fission', 'total'] - tally.nuclides = [u234, u235, u238] - tallies_file = openmc.Tallies([tally]) - - # Export tallies to file - self._input_set.tallies = tallies_file - super(TallyAggregationTestHarness, self)._build_inputs() + tally.nuclides = ['U234', 'U235', 'U238'] + self._model.tallies.append(tally) def _get_results(self, hash_output=True): """Digest info in the statepoint and return as a string.""" diff --git a/tests/test_tally_arithmetic/inputs_true.dat b/tests/test_tally_arithmetic/inputs_true.dat index 4ade94e93..f98d4480d 100644 --- a/tests/test_tally_arithmetic/inputs_true.dat +++ b/tests/test_tally_arithmetic/inputs_true.dat @@ -306,9 +306,6 @@ -160 -160 -183 160 160 183 - - true - diff --git a/tests/test_tally_arithmetic/test_tally_arithmetic.py b/tests/test_tally_arithmetic/test_tally_arithmetic.py index 6f2d2a248..6fcbb15a8 100644 --- a/tests/test_tally_arithmetic/test_tally_arithmetic.py +++ b/tests/test_tally_arithmetic/test_tally_arithmetic.py @@ -10,18 +10,8 @@ import openmc class TallyArithmeticTestHarness(PyAPITestHarness): - def _build_inputs(self): - - # The summary.h5 file needs to be created to read in the tallies - self._input_set.settings.output = {'summary': True} - - # Initialize the tallies file - tallies_file = openmc.Tallies() - - # Initialize the nuclides - u234 = openmc.Nuclide('U234') - u235 = openmc.Nuclide('U235') - u238 = openmc.Nuclide('U238') + def __init__(self, *args, **kwargs): + super(TallyArithmeticTestHarness, self).__init__(*args, **kwargs) # Initialize Mesh mesh = openmc.Mesh(mesh_id=1) @@ -40,18 +30,14 @@ class TallyArithmeticTestHarness(PyAPITestHarness): tally = openmc.Tally(name='tally 1') tally.filters = [material_filter, energy_filter, distrib_filter] tally.scores = ['nu-fission', 'total'] - tally.nuclides = [u234, u235] - tallies_file.append(tally) + tally.nuclides = ['U234', 'U235'] + self._model.tallies.append(tally) tally = openmc.Tally(name='tally 2') tally.filters = [energy_filter, mesh_filter] tally.scores = ['total', 'fission'] - tally.nuclides = [u238, u235] - tallies_file.append(tally) - - # Export tallies to file - self._input_set.tallies = tallies_file - super(TallyArithmeticTestHarness, self)._build_inputs() + tally.nuclides = ['U238', 'U235'] + self._model.tallies.append(tally) def _get_results(self, hash_output=False): """Digest info in the statepoint and return as a string.""" diff --git a/tests/test_tally_slice_merge/test_tally_slice_merge.py b/tests/test_tally_slice_merge/test_tally_slice_merge.py index 27b7046c5..624624a15 100644 --- a/tests/test_tally_slice_merge/test_tally_slice_merge.py +++ b/tests/test_tally_slice_merge/test_tally_slice_merge.py @@ -13,9 +13,8 @@ import openmc class TallySliceMergeTestHarness(PyAPITestHarness): - def _build_inputs(self): - # Initialize the tallies file - tallies_file = openmc.Tallies() + def __init__(self, *args, **kwargs): + super(TallySliceMergeTestHarness, self).__init__(*args, **kwargs) # Define nuclides and scores to add to both tallies self.nuclides = ['U235', 'U238'] @@ -49,10 +48,10 @@ class TallySliceMergeTestHarness(PyAPITestHarness): for score in self.scores: tally = openmc.Tally() tally.estimator = 'tracklength' - tally.add_score(score) - tally.add_nuclide(nuclide) - tally.add_filter(cell_filter) - tally.add_filter(energy_filter) + tally.scores.append(score) + tally.nuclides.append(nuclide) + tally.filters.append(cell_filter) + tally.filters.append(energy_filter) tallies.append(tally) # Merge all cell tallies together @@ -69,9 +68,9 @@ class TallySliceMergeTestHarness(PyAPITestHarness): distribcell_tally.estimator = 'tracklength' distribcell_tally.filters = [distribcell_filter, merged_energies] for score in self.scores: - distribcell_tally.add_score(score) + distribcell_tally.scores.append(score) for nuclide in self.nuclides: - distribcell_tally.add_nuclide(nuclide) + distribcell_tally.nuclides.append(nuclide) mesh_tally = openmc.Tally(name='mesh tally') mesh_tally.estimator = 'tracklength' @@ -80,12 +79,7 @@ class TallySliceMergeTestHarness(PyAPITestHarness): mesh_tally.nuclides = self.nuclides # Add tallies to a Tallies object - tallies_file = openmc.Tallies((tallies[0], distribcell_tally, - mesh_tally)) - - # Export tallies to file - self._input_set.tallies = tallies_file - super(TallySliceMergeTestHarness, self)._build_inputs() + self._model.tallies = [tallies[0], distribcell_tally, mesh_tally] def _get_results(self, hash_output=False): """Digest info in the statepoint and return as a string.""" diff --git a/tests/test_triso/inputs_true.dat b/tests/test_triso/inputs_true.dat index 12dd4e7a6..35d2675cc 100644 --- a/tests/test_triso/inputs_true.dat +++ b/tests/test_triso/inputs_true.dat @@ -440,9 +440,3 @@ - - - - - diff --git a/tests/test_triso/plots.xml b/tests/test_triso/plots.xml deleted file mode 100644 index eafe3206b..000000000 --- a/tests/test_triso/plots.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - diff --git a/tests/testing_harness.py b/tests/testing_harness.py index 352022b26..71e72edbd 100644 --- a/tests/testing_harness.py +++ b/tests/testing_harness.py @@ -11,8 +11,8 @@ import sys import numpy as np sys.path.insert(0, os.path.join(os.pardir, os.pardir)) -from input_set import InputSet, MGInputSet import openmc +from openmc.examples import pwr_core, slab_mg class TestHarness(object): @@ -240,15 +240,17 @@ class ParticleRestartTestHarness(TestHarness): class PyAPITestHarness(TestHarness): - def __init__(self, statepoint_name, tallies_present=False, mg=False): - super(PyAPITestHarness, self).__init__(statepoint_name, - tallies_present) - self.parser.add_option('--build-inputs', dest='build_only', + def __init__(self, statepoint_name, tallies_present=False, model=None): + super(PyAPITestHarness, self).__init__( + statepoint_name, tallies_present) + self.parser.add_option('-b', '--build-inputs', dest='build_only', action='store_true', default=False) - if mg: - self._input_set = MGInputSet() + if model is None: + self._model = pwr_core() else: - self._input_set = InputSet() + self._model = model + self._model.plots = [] + def main(self): """Accept commandline arguments and either run or update tests.""" @@ -292,9 +294,7 @@ class PyAPITestHarness(TestHarness): def _build_inputs(self): """Write input XML files.""" - self._input_set.build_default_materials_and_geometry() - self._input_set.build_default_settings() - self._input_set.export() + self._model.export_to_xml() def _get_inputs(self): """Return a hash digest of the input XML files.""" @@ -327,14 +327,13 @@ class PyAPITestHarness(TestHarness): """Delete XMLs, statepoints, tally, and test files.""" super(PyAPITestHarness, self)._cleanup() output = ['materials.xml', 'geometry.xml', 'settings.xml', - 'tallies.xml', 'inputs_test.dat'] + 'tallies.xml', 'plots.xml', 'inputs_test.dat'] for f in output: if os.path.exists(f): os.remove(f) class HashedPyAPITestHarness(PyAPITestHarness): - def _get_results(self): """Digest info in the statepoint and return as a string.""" return super(HashedPyAPITestHarness, self)._get_results(True)