From 2d908acc0a5dc520db8c08ce043030d8f48bf9d7 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 6 Apr 2017 13:14:23 -0500 Subject: [PATCH 01/22] Make -O2 default for gcc. --- CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index abb900592a..208da7b41c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,8 +108,8 @@ if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU) endif() # GCC compiler options - list(APPEND f90flags -cpp -std=f2008 -fbacktrace) - list(APPEND cflags -cpp -std=c99) + list(APPEND f90flags -cpp -std=f2008 -fbacktrace -O2) + list(APPEND cflags -cpp -std=c99 -O2) if(debug) list(APPEND f90flags -g -Wall -pedantic -fbounds-check -ffpe-trap=invalid,overflow,underflow) @@ -122,6 +122,8 @@ if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU) list(APPEND ldflags -pg) endif() if(optimize) + list(REMOVE_ITEM f90flags -O2) + list(REMOVE_ITEM cflags -O2) list(APPEND f90flags -O3) list(APPEND cflags -O3) endif() @@ -190,6 +192,7 @@ elseif(CMAKE_Fortran_COMPILER_ID STREQUAL XL) list(APPEND ldflags -p) endif() if(optimize) + list(REMOVE_ITEM f90flags -O2) list(APPEND f90flags -O3) endif() if(openmp) From ef66d9a43aea981ce5d63e58d65cf4099e327dab Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 7 Apr 2017 12:08:10 -0500 Subject: [PATCH 02/22] Make sure debug mode uses -O0 --- CMakeLists.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 208da7b41c..ddb55dcbed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,6 +111,8 @@ if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU) list(APPEND f90flags -cpp -std=f2008 -fbacktrace -O2) list(APPEND cflags -cpp -std=c99 -O2) if(debug) + list(REMOVE_ITEM f90flags -O2) + list(REMOVE_ITEM cflags -O2) list(APPEND f90flags -g -Wall -pedantic -fbounds-check -ffpe-trap=invalid,overflow,underflow) list(APPEND cflags -g -Wall -pedantic -fbounds-check) @@ -144,8 +146,8 @@ elseif(CMAKE_Fortran_COMPILER_ID STREQUAL Intel) list(APPEND cflags -std=c99) if(debug) list(APPEND f90flags -g -warn -ftrapuv -fp-stack-check - "-check all" -fpe0) - list(APPEND cflags -g -w3 -ftrapuv -fp-stack-check) + "-check all" -fpe0 -O0) + list(APPEND cflags -g -w3 -ftrapuv -fp-stack-check -O0) list(APPEND ldflags -g) endif() if(profile) @@ -184,7 +186,8 @@ elseif(CMAKE_Fortran_COMPILER_ID STREQUAL XL) list(APPEND f90flags -O2) add_definitions(-DNO_F2008) if(debug) - list(APPEND f90flags -g -C -qflag=i:i -u) + list(REMOVE_ITEM f90flags -O2) + list(APPEND f90flags -g -C -qflag=i:i -u -O0) list(APPEND ldflags -g) endif() if(profile) From fc0c90703044daf781b16daafd50d4bed9d5a3e7 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 6 Apr 2017 21:20:29 -0500 Subject: [PATCH 03/22] 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 0000000000..2a3ebbd8e9 --- /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 c66401e245..5492f362df 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 0000000000..6e2a04f7f6 --- /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 7716cae97b..36621ed4f9 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 ce5e3d5bc6..0000000000 --- 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 6d36fe439e..6684087bc3 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 84aa181568..9343e59138 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 fd36e320c4..7d8b884ec7 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 1d9d6ac5c2..75c6dcc416 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 a37f5cfe5b..d9caf9d951 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 b60daea117..60b5bc2dee 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 1a49ee8a82..35b9c47d3a 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 a16912c5db..3db74a824c 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 8c7948a323..6a3db3aa5e 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 b94af258f2..a0adfb0236 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 61b7381a47..2fefee21d6 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 580eb60c3f..cdd3a90f59 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 343a48a833..c296e39882 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 087e7a07b5..bfa612e4e8 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 9ab7548fa8..71b7b43780 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 3c657981b0..219ba4c0f0 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 7f67afd659..c52a23153f 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 aaad7d32b2..fdd05bb655 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 83d0ba05e4..d5c3665ff4 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 2efea5d3a6..b41068f8e8 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 8223b8d6a2..041221cb66 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 012c2fb73e..cb98b53fa1 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 4ade94e938..f98d4480df 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 6f2d2a248a..6fcbb15a8a 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 27b7046c51..624624a153 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 12dd4e7a64..35d2675cc1 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 eafe3206b3..0000000000 --- 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 352022b260..71e72edbd9 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) From f4d3ee7de576662e555da75f5f697ccfc8237d11 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 7 Apr 2017 09:52:29 -0500 Subject: [PATCH 04/22] Make StatePoint a context manager --- openmc/statepoint.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/openmc/statepoint.py b/openmc/statepoint.py index 3eec9a20e5..28f35ba7de 100644 --- a/openmc/statepoint.py +++ b/openmc/statepoint.py @@ -138,6 +138,12 @@ class StatePoint(object): vol = openmc.VolumeCalculation.from_hdf5(path_i) self.add_volume_information(vol) + def __enter__(self): + return self + + def __exit__(self, *exc): + self._f.close() + @property def cmfd_on(self): return self._f.attrs['cmfd_on'] > 0 From c3aa90314609706025b47d7b51d354e19f4c8b1b Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 7 Apr 2017 10:25:24 -0500 Subject: [PATCH 05/22] Get rid of tallies_present argument for test harness classes --- .../test_asymmetric_lattice.py | 2 +- tests/test_cmfd_feed/test_cmfd_feed.py | 2 +- tests/test_cmfd_nofeed/test_cmfd_nofeed.py | 2 +- tests/test_complex_cell/test_complex_cell.py | 2 +- .../test_confidence_intervals.py | 2 +- .../test_create_fission_neutrons.py | 2 +- tests/test_density/test_density.py | 2 +- tests/test_diff_tally/test_diff_tally.py | 2 +- tests/test_distribmat/inputs_true.dat | 3 - tests/test_distribmat/test_distribmat.py | 75 ++++++----------- .../test_eigenvalue_genperbatch.py | 2 +- .../test_eigenvalue_no_inactive.py | 2 +- .../test_energy_cutoff/test_energy_cutoff.py | 2 +- tests/test_energy_grid/test_energy_grid.py | 2 +- tests/test_energy_laws/test_energy_laws.py | 2 +- tests/test_entropy/test_entropy.py | 22 +++-- .../test_filter_distribcell.py | 6 +- .../test_filter_energyfun.py | 2 +- tests/test_filter_mesh/test_filter_mesh.py | 2 +- tests/test_fixed_source/test_fixed_source.py | 24 +++--- .../test_infinite_cell/test_infinite_cell.py | 2 +- tests/test_lattice/test_lattice.py | 2 +- tests/test_lattice_hex/test_lattice_hex.py | 2 +- .../test_lattice_mixed/test_lattice_mixed.py | 2 +- .../test_lattice_multiple.py | 2 +- tests/test_mg_basic/test_mg_basic.py | 2 +- tests/test_mg_convert/test_mg_convert.py | 2 +- tests/test_mg_legendre/test_mg_legendre.py | 2 +- tests/test_mg_max_order/test_mg_max_order.py | 2 +- tests/test_mg_nuclide/test_mg_nuclide.py | 2 +- .../test_mg_survival_biasing.py | 2 +- tests/test_mg_tallies/test_mg_tallies.py | 2 +- .../test_mgxs_library_ce_to_mg.py | 2 +- .../test_mgxs_library_condense.py | 2 +- .../test_mgxs_library_distribcell.py | 2 +- .../test_mgxs_library_hdf5.py | 2 +- .../test_mgxs_library_mesh.py | 2 +- .../test_mgxs_library_no_nuclides.py | 2 +- .../test_mgxs_library_nuclides.py | 2 +- tests/test_multipole/inputs_true.dat | 3 - tests/test_multipole/test_multipole.py | 47 ++++------- tests/test_output/test_output.py | 2 +- tests/test_plot/test_plot.py | 2 +- tests/test_ptables_off/test_ptables_off.py | 2 +- .../test_quadric_surfaces.py | 2 +- .../test_reflective_plane.py | 2 +- tests/test_rotation/test_rotation.py | 2 +- tests/test_salphabeta/test_salphabeta.py | 2 +- .../test_score_current/test_score_current.py | 2 +- tests/test_seed/test_seed.py | 2 +- tests/test_source_file/test_source_file.py | 2 +- .../test_sourcepoint_batch.py | 19 ++--- .../test_sourcepoint_latest.py | 2 +- .../test_sourcepoint_restart.py | 2 +- .../test_statepoint_batch.py | 6 +- .../test_statepoint_restart.py | 7 +- .../test_statepoint_sourcesep.py | 2 +- .../test_survival_biasing.py | 2 +- tests/test_tallies/test_tallies.py | 2 +- .../test_tally_aggregation.py | 2 +- .../test_tally_arithmetic.py | 2 +- .../test_tally_assumesep.py | 2 +- .../test_tally_nuclides.py | 2 +- .../test_tally_slice_merge.py | 2 +- tests/test_trace/test_trace.py | 2 +- tests/test_track_output/test_track_output.py | 2 +- tests/test_translation/test_translation.py | 2 +- .../test_trigger_batch_interval.py | 2 +- .../test_trigger_no_batch_interval.py | 2 +- .../test_trigger_no_status.py | 2 +- .../test_trigger_tallies.py | 2 +- tests/test_uniform_fs/test_uniform_fs.py | 2 +- tests/test_universe/test_universe.py | 2 +- tests/test_void/test_void.py | 2 +- tests/testing_harness.py | 83 +++++++++---------- 75 files changed, 185 insertions(+), 238 deletions(-) diff --git a/tests/test_asymmetric_lattice/test_asymmetric_lattice.py b/tests/test_asymmetric_lattice/test_asymmetric_lattice.py index 6684087bc3..58c1b22ab5 100644 --- a/tests/test_asymmetric_lattice/test_asymmetric_lattice.py +++ b/tests/test_asymmetric_lattice/test_asymmetric_lattice.py @@ -91,5 +91,5 @@ class AsymmetricLatticeTestHarness(PyAPITestHarness): if __name__ == '__main__': - harness = AsymmetricLatticeTestHarness('statepoint.10.h5', True) + harness = AsymmetricLatticeTestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_cmfd_feed/test_cmfd_feed.py b/tests/test_cmfd_feed/test_cmfd_feed.py index 3bc5f61743..17bebf68c0 100644 --- a/tests/test_cmfd_feed/test_cmfd_feed.py +++ b/tests/test_cmfd_feed/test_cmfd_feed.py @@ -7,5 +7,5 @@ from testing_harness import CMFDTestHarness if __name__ == '__main__': - harness = CMFDTestHarness('statepoint.20.*', True) + harness = CMFDTestHarness('statepoint.20.h5') harness.main() diff --git a/tests/test_cmfd_nofeed/test_cmfd_nofeed.py b/tests/test_cmfd_nofeed/test_cmfd_nofeed.py index 3bc5f61743..17bebf68c0 100644 --- a/tests/test_cmfd_nofeed/test_cmfd_nofeed.py +++ b/tests/test_cmfd_nofeed/test_cmfd_nofeed.py @@ -7,5 +7,5 @@ from testing_harness import CMFDTestHarness if __name__ == '__main__': - harness = CMFDTestHarness('statepoint.20.*', True) + harness = CMFDTestHarness('statepoint.20.h5') harness.main() diff --git a/tests/test_complex_cell/test_complex_cell.py b/tests/test_complex_cell/test_complex_cell.py index 1777db993e..0669165e25 100755 --- a/tests/test_complex_cell/test_complex_cell.py +++ b/tests/test_complex_cell/test_complex_cell.py @@ -6,5 +6,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*', True) + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_confidence_intervals/test_confidence_intervals.py b/tests/test_confidence_intervals/test_confidence_intervals.py index ed6addec45..b04fcc6eba 100755 --- a/tests/test_confidence_intervals/test_confidence_intervals.py +++ b/tests/test_confidence_intervals/test_confidence_intervals.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*', True) + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_create_fission_neutrons/test_create_fission_neutrons.py b/tests/test_create_fission_neutrons/test_create_fission_neutrons.py index 4434502d67..87abeda7fe 100755 --- a/tests/test_create_fission_neutrons/test_create_fission_neutrons.py +++ b/tests/test_create_fission_neutrons/test_create_fission_neutrons.py @@ -70,5 +70,5 @@ class CreateFissionNeutronsTestHarness(PyAPITestHarness): if __name__ == '__main__': - harness = CreateFissionNeutronsTestHarness('statepoint.10.h5', True) + harness = CreateFissionNeutronsTestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_density/test_density.py b/tests/test_density/test_density.py index 2a595f3e66..b04fcc6eba 100644 --- a/tests/test_density/test_density.py +++ b/tests/test_density/test_density.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_diff_tally/test_diff_tally.py b/tests/test_diff_tally/test_diff_tally.py index 9343e59138..02798e70e0 100644 --- a/tests/test_diff_tally/test_diff_tally.py +++ b/tests/test_diff_tally/test_diff_tally.py @@ -126,5 +126,5 @@ class DiffTallyTestHarness(PyAPITestHarness): if __name__ == '__main__': - harness = DiffTallyTestHarness('statepoint.3.h5', True) + harness = DiffTallyTestHarness('statepoint.3.h5') harness.main() diff --git a/tests/test_distribmat/inputs_true.dat b/tests/test_distribmat/inputs_true.dat index 2d3e39a65d..cd26a0e7ce 100644 --- a/tests/test_distribmat/inputs_true.dat +++ b/tests/test_distribmat/inputs_true.dat @@ -46,9 +46,6 @@ -1 -1 -1 1 1 1 - - true - diff --git a/tests/test_distribmat/test_distribmat.py b/tests/test_distribmat/test_distribmat.py index 2816bbfbc3..9dd5d319a2 100644 --- a/tests/test_distribmat/test_distribmat.py +++ b/tests/test_distribmat/test_distribmat.py @@ -5,8 +5,6 @@ import sys sys.path.insert(0, os.pardir) from testing_harness import TestHarness, PyAPITestHarness import openmc -from openmc.stats import Box -from openmc.source import Source class DistribmatTestHarness(PyAPITestHarness): @@ -31,25 +29,18 @@ class DistribmatTestHarness(PyAPITestHarness): mats_file = openmc.Materials([moderator, dense_fuel, light_fuel]) mats_file.export_to_xml() - #################### # Geometry #################### - c1 = openmc.Cell(cell_id=1) - c1.fill = moderator - mod_univ = openmc.Universe(universe_id=1) - mod_univ.add_cell(c1) + c1 = openmc.Cell(cell_id=1, fill=moderator) + mod_univ = openmc.Universe(universe_id=1, cells=[c1]) r0 = openmc.ZCylinder(R=0.3) - c11 = openmc.Cell(cell_id=11) - c11.region = -r0 + c11 = openmc.Cell(cell_id=11, region=-r0) c11.fill = [dense_fuel, light_fuel, None, dense_fuel] - c12 = openmc.Cell(cell_id=12) - c12.region = +r0 - c12.fill = moderator - fuel_univ = openmc.Universe(universe_id=11) - fuel_univ.add_cells((c11, c12)) + c12 = openmc.Cell(cell_id=12, region=+r0, fill=moderator) + fuel_univ = openmc.Universe(universe_id=11, cells=[c11, c12]) lat = openmc.RectLattice(lattice_id=101) lat.lower_left = [-2.0, -2.0] @@ -63,17 +54,13 @@ class DistribmatTestHarness(PyAPITestHarness): y1 = openmc.YPlane(y0=3.0) for s in [x0, x1, y0, y1]: s.boundary_type = 'reflective' - c101 = openmc.Cell(cell_id=101) + c101 = openmc.Cell(cell_id=101, fill=lat) c101.region = +x0 & -x1 & +y0 & -y1 - c101.fill = lat - root_univ = openmc.Universe(universe_id=0) - root_univ.add_cell(c101) + root_univ = openmc.Universe(universe_id=0, cells=[c101]) - geometry = openmc.Geometry() - geometry.root_universe = root_univ + geometry = openmc.Geometry(root_univ) geometry.export_to_xml() - #################### # Settings #################### @@ -82,36 +69,32 @@ class DistribmatTestHarness(PyAPITestHarness): sets_file.batches = 5 sets_file.inactive = 0 sets_file.particles = 1000 - sets_file.source = Source(space=Box([-1, -1, -1], [1, 1, 1])) - sets_file.output = {'summary': True} + sets_file.source = openmc.Source(space=openmc.stats.Box( + [-1, -1, -1], [1, 1, 1])) sets_file.export_to_xml() - #################### # Plots #################### - plots_file = openmc.Plots() + plot1 = openmc.Plot(plot_id=1) + plot1.basis = 'xy' + plot1.color_by = 'cell' + plot1.filename = 'cellplot' + plot1.origin = (0, 0, 0) + plot1.width = (7, 7) + plot1.pixels = (400, 400) - plot = openmc.Plot(plot_id=1) - plot.basis = 'xy' - plot.color_by = 'cell' - plot.filename = 'cellplot' - plot.origin = (0, 0, 0) - plot.width = (7, 7) - plot.pixels = (400, 400) - plots_file.add_plot(plot) + plot2 = openmc.Plot(plot_id=2) + plot2.basis = 'xy' + plot2.color_by = 'material' + plot2.filename = 'matplot' + plot2.origin = (0, 0, 0) + plot2.width = (7, 7) + plot2.pixels = (400, 400) - plot = openmc.Plot(plot_id=2) - plot.basis = 'xy' - plot.color_by = 'material' - plot.filename = 'matplot' - plot.origin = (0, 0, 0) - plot.width = (7, 7) - plot.pixels = (400, 400) - plots_file.add_plot(plot) - - plots_file.export_to_xml() + plots = openmc.Plots([plot1, plot2]) + plots.export_to_xml() def _get_results(self): outstr = super(DistribmatTestHarness, self)._get_results() @@ -119,12 +102,6 @@ class DistribmatTestHarness(PyAPITestHarness): outstr += str(su.geometry.get_all_cells()[11]) return outstr - def _cleanup(self): - f = os.path.join(os.getcwd(), 'plots.xml') - if os.path.exists(f): - os.remove(f) - super(DistribmatTestHarness, self)._cleanup() - if __name__ == '__main__': harness = DistribmatTestHarness('statepoint.5.h5') diff --git a/tests/test_eigenvalue_genperbatch/test_eigenvalue_genperbatch.py b/tests/test_eigenvalue_genperbatch/test_eigenvalue_genperbatch.py index d6f69fdbb5..59a60b63a4 100644 --- a/tests/test_eigenvalue_genperbatch/test_eigenvalue_genperbatch.py +++ b/tests/test_eigenvalue_genperbatch/test_eigenvalue_genperbatch.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.7.*') + harness = TestHarness('statepoint.7.h5') harness.main() diff --git a/tests/test_eigenvalue_no_inactive/test_eigenvalue_no_inactive.py b/tests/test_eigenvalue_no_inactive/test_eigenvalue_no_inactive.py index 2a595f3e66..b04fcc6eba 100644 --- a/tests/test_eigenvalue_no_inactive/test_eigenvalue_no_inactive.py +++ b/tests/test_eigenvalue_no_inactive/test_eigenvalue_no_inactive.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_energy_cutoff/test_energy_cutoff.py b/tests/test_energy_cutoff/test_energy_cutoff.py index 064e5c4d32..3aa3400c7a 100755 --- a/tests/test_energy_cutoff/test_energy_cutoff.py +++ b/tests/test_energy_cutoff/test_energy_cutoff.py @@ -74,5 +74,5 @@ class EnergyCutoffTestHarness(PyAPITestHarness): if __name__ == '__main__': - harness = EnergyCutoffTestHarness('statepoint.10.h5', True) + harness = EnergyCutoffTestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_energy_grid/test_energy_grid.py b/tests/test_energy_grid/test_energy_grid.py index 2a595f3e66..b04fcc6eba 100644 --- a/tests/test_energy_grid/test_energy_grid.py +++ b/tests/test_energy_grid/test_energy_grid.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_energy_laws/test_energy_laws.py b/tests/test_energy_laws/test_energy_laws.py index 0e593876fc..254126ff30 100644 --- a/tests/test_energy_laws/test_energy_laws.py +++ b/tests/test_energy_laws/test_energy_laws.py @@ -26,5 +26,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_entropy/test_entropy.py b/tests/test_entropy/test_entropy.py index 113cafcb27..36e2170af8 100644 --- a/tests/test_entropy/test_entropy.py +++ b/tests/test_entropy/test_entropy.py @@ -5,7 +5,7 @@ import os import sys sys.path.insert(0, os.pardir) from testing_harness import TestHarness -from openmc.statepoint import StatePoint +from openmc import StatePoint class EntropyTestHarness(TestHarness): @@ -13,21 +13,19 @@ class EntropyTestHarness(TestHarness): """Digest info in the statepoint and return as a string.""" # Read the statepoint file. statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))[0] - sp = StatePoint(statepoint) + with StatePoint(statepoint) as sp: + # Write out k-combined. + outstr = 'k-combined:\n' + outstr += '{0:12.6E} {1:12.6E}\n'.format(*sp.k_combined) - # Write out k-combined. - outstr = 'k-combined:\n' - form = '{0:12.6E} {1:12.6E}\n' - outstr += form.format(sp.k_combined[0], sp.k_combined[1]) - - # Write out entropy data. - outstr += 'entropy:\n' - results = ['{0:12.6E}'.format(x) for x in sp.entropy] - outstr += '\n'.join(results) + '\n' + # Write out entropy data. + outstr += 'entropy:\n' + results = ['{0:12.6E}'.format(x) for x in sp.entropy] + outstr += '\n'.join(results) + '\n' return outstr if __name__ == '__main__': - harness = EntropyTestHarness('statepoint.10.*') + harness = EntropyTestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_filter_distribcell/test_filter_distribcell.py b/tests/test_filter_distribcell/test_filter_distribcell.py index 3a145832cc..f0fc270399 100644 --- a/tests/test_filter_distribcell/test_filter_distribcell.py +++ b/tests/test_filter_distribcell/test_filter_distribcell.py @@ -10,7 +10,7 @@ from testing_harness import * class DistribcellTestHarness(TestHarness): def __init__(self): - super(DistribcellTestHarness, self).__init__(None, True) + super(DistribcellTestHarness, self).__init__(None) def execute_test(self): """Run OpenMC with the appropriate arguments and check the outputs.""" @@ -41,8 +41,8 @@ class DistribcellTestHarness(TestHarness): base_dir = os.getcwd() try: dirs = ('case-1', '../case-2', '../case-3', '../case-4') - sps = ('statepoint.1.*', 'statepoint.1.*', 'statepoint.3.*', - 'statepoint.1.*') + sps = ('statepoint.1.h5', 'statepoint.1.h5', 'statepoint.3.h5', + 'statepoint.1.h5') tallies_out_present = (True, True, False, True) hash_out = (False, False, True, False) for i in range(len(dirs)): diff --git a/tests/test_filter_energyfun/test_filter_energyfun.py b/tests/test_filter_energyfun/test_filter_energyfun.py index 7d8b884ec7..07ae993a9e 100644 --- a/tests/test_filter_energyfun/test_filter_energyfun.py +++ b/tests/test_filter_energyfun/test_filter_energyfun.py @@ -49,5 +49,5 @@ class FilterEnergyFunHarness(PyAPITestHarness): if __name__ == '__main__': - harness = FilterEnergyFunHarness('statepoint.10.h5', True) + harness = FilterEnergyFunHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_filter_mesh/test_filter_mesh.py b/tests/test_filter_mesh/test_filter_mesh.py index d9caf9d951..7b9e8bd16b 100644 --- a/tests/test_filter_mesh/test_filter_mesh.py +++ b/tests/test_filter_mesh/test_filter_mesh.py @@ -68,5 +68,5 @@ class FilterMeshTestHarness(HashedPyAPITestHarness): if __name__ == '__main__': - harness = FilterMeshTestHarness('statepoint.10.h5', True) + harness = FilterMeshTestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_fixed_source/test_fixed_source.py b/tests/test_fixed_source/test_fixed_source.py index 12dbb8d769..8d61a46d0a 100644 --- a/tests/test_fixed_source/test_fixed_source.py +++ b/tests/test_fixed_source/test_fixed_source.py @@ -6,7 +6,7 @@ import sys import numpy as np sys.path.insert(0, os.pardir) from testing_harness import TestHarness -from openmc.statepoint import StatePoint +from openmc import StatePoint class FixedSourceTestHarness(TestHarness): @@ -14,31 +14,27 @@ class FixedSourceTestHarness(TestHarness): """Digest info in the statepoint and return as a string.""" # Read the statepoint file. statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))[0] - sp = StatePoint(statepoint) - - # Write out tally data. outstr = '' - if self._tallies: - tally_num = 1 - for tally_ind in sp.tallies: + with StatePoint(statepoint) as sp: + # Write out tally data. + for i, tally_ind in enumerate(sp.tallies): tally = sp.tallies[tally_ind] results = np.zeros((tally.sum.size*2, )) results[0::2] = tally.sum.ravel() results[1::2] = tally.sum_sq.ravel() results = ['{0:12.6E}'.format(x) for x in results] - outstr += 'tally ' + str(tally_num) + ':\n' + outstr += 'tally ' + str(i + 1) + ':\n' outstr += '\n'.join(results) + '\n' - tally_num += 1 - gt = sp.global_tallies - outstr += 'leakage:\n' - outstr += '{0:12.6E}'.format(gt[gt['name'] == b'leakage'][0]['sum']) + '\n' - outstr += '{0:12.6E}'.format(gt[gt['name'] == b'leakage'][0]['sum_sq']) + '\n' + gt = sp.global_tallies + outstr += 'leakage:\n' + outstr += '{0:12.6E}'.format(gt[gt['name'] == b'leakage'][0]['sum']) + '\n' + outstr += '{0:12.6E}'.format(gt[gt['name'] == b'leakage'][0]['sum_sq']) + '\n' return outstr if __name__ == '__main__': - harness = FixedSourceTestHarness('statepoint.10.*', True) + harness = FixedSourceTestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_infinite_cell/test_infinite_cell.py b/tests/test_infinite_cell/test_infinite_cell.py index 2a595f3e66..b04fcc6eba 100644 --- a/tests/test_infinite_cell/test_infinite_cell.py +++ b/tests/test_infinite_cell/test_infinite_cell.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_lattice/test_lattice.py b/tests/test_lattice/test_lattice.py index 2a595f3e66..b04fcc6eba 100644 --- a/tests/test_lattice/test_lattice.py +++ b/tests/test_lattice/test_lattice.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_lattice_hex/test_lattice_hex.py b/tests/test_lattice_hex/test_lattice_hex.py index 2a595f3e66..b04fcc6eba 100644 --- a/tests/test_lattice_hex/test_lattice_hex.py +++ b/tests/test_lattice_hex/test_lattice_hex.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_lattice_mixed/test_lattice_mixed.py b/tests/test_lattice_mixed/test_lattice_mixed.py index 2a595f3e66..b04fcc6eba 100644 --- a/tests/test_lattice_mixed/test_lattice_mixed.py +++ b/tests/test_lattice_mixed/test_lattice_mixed.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_lattice_multiple/test_lattice_multiple.py b/tests/test_lattice_multiple/test_lattice_multiple.py index 2a595f3e66..b04fcc6eba 100644 --- a/tests/test_lattice_multiple/test_lattice_multiple.py +++ b/tests/test_lattice_multiple/test_lattice_multiple.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_mg_basic/test_mg_basic.py b/tests/test_mg_basic/test_mg_basic.py index 35b9c47d3a..21871efd72 100644 --- a/tests/test_mg_basic/test_mg_basic.py +++ b/tests/test_mg_basic/test_mg_basic.py @@ -9,5 +9,5 @@ from openmc.examples import slab_mg if __name__ == '__main__': model = slab_mg() - harness = PyAPITestHarness('statepoint.10.h5', False, model) + harness = PyAPITestHarness('statepoint.10.h5', model) harness.main() diff --git a/tests/test_mg_convert/test_mg_convert.py b/tests/test_mg_convert/test_mg_convert.py index 45e703b0e3..9d13714580 100755 --- a/tests/test_mg_convert/test_mg_convert.py +++ b/tests/test_mg_convert/test_mg_convert.py @@ -206,5 +206,5 @@ class MGXSTestHarness(PyAPITestHarness): if __name__ == '__main__': - harness = MGXSTestHarness('statepoint.10.*', False) + harness = MGXSTestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_mg_legendre/test_mg_legendre.py b/tests/test_mg_legendre/test_mg_legendre.py index 3db74a824c..eee0f0800f 100644 --- a/tests/test_mg_legendre/test_mg_legendre.py +++ b/tests/test_mg_legendre/test_mg_legendre.py @@ -12,5 +12,5 @@ if __name__ == '__main__': model = slab_mg(reps=['iso']) model.settings.tabular_legendre = {'enable': False} - harness = PyAPITestHarness('statepoint.10.h5', False, model) + harness = PyAPITestHarness('statepoint.10.h5', 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 6a3db3aa5e..8ac0f58785 100644 --- a/tests/test_mg_max_order/test_mg_max_order.py +++ b/tests/test_mg_max_order/test_mg_max_order.py @@ -11,5 +11,5 @@ from openmc.examples import slab_mg if __name__ == '__main__': model = slab_mg(reps=['iso']) model.settings.max_order = 1 - harness = PyAPITestHarness('statepoint.10.h5', False, model) + harness = PyAPITestHarness('statepoint.10.h5', model) harness.main() diff --git a/tests/test_mg_nuclide/test_mg_nuclide.py b/tests/test_mg_nuclide/test_mg_nuclide.py index a0adfb0236..0f3c9dd6d7 100644 --- a/tests/test_mg_nuclide/test_mg_nuclide.py +++ b/tests/test_mg_nuclide/test_mg_nuclide.py @@ -10,5 +10,5 @@ from openmc.examples import slab_mg if __name__ == '__main__': model = slab_mg(as_macro=False) - harness = PyAPITestHarness('statepoint.10.h5', False, model) + harness = PyAPITestHarness('statepoint.10.h5', 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 2fefee21d6..9886ad3e49 100644 --- a/tests/test_mg_survival_biasing/test_mg_survival_biasing.py +++ b/tests/test_mg_survival_biasing/test_mg_survival_biasing.py @@ -10,5 +10,5 @@ from openmc.examples import slab_mg if __name__ == '__main__': model = slab_mg() model.settings.survival_biasing = True - harness = PyAPITestHarness('statepoint.10.h5', False, model) + harness = PyAPITestHarness('statepoint.10.h5', model) harness.main() diff --git a/tests/test_mg_tallies/test_mg_tallies.py b/tests/test_mg_tallies/test_mg_tallies.py index cdd3a90f59..7024a48749 100644 --- a/tests/test_mg_tallies/test_mg_tallies.py +++ b/tests/test_mg_tallies/test_mg_tallies.py @@ -92,5 +92,5 @@ if __name__ == '__main__': t.nuclides = nuclides model.tallies.append(t) - harness = HashedPyAPITestHarness('statepoint.10.h5', True, model) + harness = HashedPyAPITestHarness('statepoint.10.h5', 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 c296e39882..aaa83a70db 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 @@ -89,5 +89,5 @@ if __name__ == '__main__': # Set the input set to use the pincell model model = pwr_pin_cell() - harness = MGXSTestHarness('statepoint.10.h5', False, model) + harness = MGXSTestHarness('statepoint.10.h5', 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 bfa612e4e8..127980da6e 100644 --- a/tests/test_mgxs_library_condense/test_mgxs_library_condense.py +++ b/tests/test_mgxs_library_condense/test_mgxs_library_condense.py @@ -68,5 +68,5 @@ class MGXSTestHarness(PyAPITestHarness): if __name__ == '__main__': # Use the pincell model model = pwr_pin_cell() - harness = MGXSTestHarness('statepoint.10.h5', True, model) + harness = MGXSTestHarness('statepoint.10.h5', 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 71b7b43780..38f16c5884 100644 --- a/tests/test_mgxs_library_distribcell/test_mgxs_library_distribcell.py +++ b/tests/test_mgxs_library_distribcell/test_mgxs_library_distribcell.py @@ -71,5 +71,5 @@ class MGXSTestHarness(PyAPITestHarness): if __name__ == '__main__': model = pwr_assembly() - harness = MGXSTestHarness('statepoint.10.h5', True, model) + harness = MGXSTestHarness('statepoint.10.h5', 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 219ba4c0f0..31a9d96126 100644 --- a/tests/test_mgxs_library_hdf5/test_mgxs_library_hdf5.py +++ b/tests/test_mgxs_library_hdf5/test_mgxs_library_hdf5.py @@ -84,5 +84,5 @@ class MGXSTestHarness(PyAPITestHarness): if __name__ == '__main__': model = pwr_pin_cell() - harness = MGXSTestHarness('statepoint.10.*', True, model) + harness = MGXSTestHarness('statepoint.10.h5', 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 c52a23153f..e0a3307bc3 100644 --- a/tests/test_mgxs_library_mesh/test_mgxs_library_mesh.py +++ b/tests/test_mgxs_library_mesh/test_mgxs_library_mesh.py @@ -71,5 +71,5 @@ class MGXSTestHarness(PyAPITestHarness): if __name__ == '__main__': - harness = MGXSTestHarness('statepoint.10.h5', True) + harness = MGXSTestHarness('statepoint.10.h5') harness.main() 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 fdd05bb655..793cfc7146 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 @@ -64,5 +64,5 @@ class MGXSTestHarness(PyAPITestHarness): if __name__ == '__main__': model = pwr_pin_cell() - harness = MGXSTestHarness('statepoint.10.h5', True, model) + harness = MGXSTestHarness('statepoint.10.h5', 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 d5c3665ff4..9e54e1bb6b 100644 --- a/tests/test_mgxs_library_nuclides/test_mgxs_library_nuclides.py +++ b/tests/test_mgxs_library_nuclides/test_mgxs_library_nuclides.py @@ -60,5 +60,5 @@ class MGXSTestHarness(PyAPITestHarness): if __name__ == '__main__': model = pwr_pin_cell() - harness = MGXSTestHarness('statepoint.10.h5', True, model) + harness = MGXSTestHarness('statepoint.10.h5', model) harness.main() diff --git a/tests/test_multipole/inputs_true.dat b/tests/test_multipole/inputs_true.dat index ee1ba636e2..4163a00e3c 100644 --- a/tests/test_multipole/inputs_true.dat +++ b/tests/test_multipole/inputs_true.dat @@ -43,9 +43,6 @@ -1 -1 -1 1 1 1 - - true - True 1000 diff --git a/tests/test_multipole/test_multipole.py b/tests/test_multipole/test_multipole.py index 33a9295dbc..1ab22f6e69 100644 --- a/tests/test_multipole/test_multipole.py +++ b/tests/test_multipole/test_multipole.py @@ -4,8 +4,6 @@ import sys sys.path.insert(0, os.pardir) from testing_harness import TestHarness, PyAPITestHarness import openmc -from openmc.stats import Box -from openmc.source import Source class MultipoleTestHarness(PyAPITestHarness): def _build_inputs(self): @@ -66,8 +64,8 @@ class MultipoleTestHarness(PyAPITestHarness): sets_file.batches = 5 sets_file.inactive = 0 sets_file.particles = 1000 - sets_file.source = Source(space=Box([-1, -1, -1], [1, 1, 1])) - sets_file.output = {'summary': True} + sets_file.source = openmc.Source(space=openmc.stats.Box( + [-1, -1, -1], [1, 1, 1])) sets_file.temperature = {'tolerance': 1000, 'multipole': True} sets_file.export_to_xml() @@ -75,27 +73,24 @@ class MultipoleTestHarness(PyAPITestHarness): # Plots #################### - plots_file = openmc.Plots() + plot1 = openmc.Plot(plot_id=1) + plot1.basis = 'xy' + plot1.color_by = 'cell' + plot1.filename = 'cellplot' + plot1.origin = (0, 0, 0) + plot1.width = (7, 7) + plot1.pixels = (400, 400) - plot = openmc.Plot(plot_id=1) - plot.basis = 'xy' - plot.color_by = 'cell' - plot.filename = 'cellplot' - plot.origin = (0, 0, 0) - plot.width = (7, 7) - plot.pixels = (400, 400) - plots_file.append(plot) + plot2 = openmc.Plot(plot_id=2) + plot2.basis = 'xy' + plot2.color_by = 'material' + plot2.filename = 'matplot' + plot2.origin = (0, 0, 0) + plot2.width = (7, 7) + plot2.pixels = (400, 400) - plot = openmc.Plot(plot_id=2) - plot.basis = 'xy' - plot.color_by = 'material' - plot.filename = 'matplot' - plot.origin = (0, 0, 0) - plot.width = (7, 7) - plot.pixels = (400, 400) - plots_file.append(plot) - - plots_file.export_to_xml() + plots = openmc.Plots([plot1, plot2]) + plots.export_to_xml() def execute_test(self): if not 'OPENMC_MULTIPOLE_LIBRARY' in os.environ: @@ -110,12 +105,6 @@ class MultipoleTestHarness(PyAPITestHarness): outstr += str(su.geometry.get_all_cells()[11]) return outstr - def _cleanup(self): - f = os.path.join(os.getcwd(), 'plots.xml') - if os.path.exists(f): - os.remove(f) - super(MultipoleTestHarness, self)._cleanup() - if __name__ == '__main__': harness = MultipoleTestHarness('statepoint.5.h5') diff --git a/tests/test_output/test_output.py b/tests/test_output/test_output.py index 81f8f42c8a..475b3e9f02 100644 --- a/tests/test_output/test_output.py +++ b/tests/test_output/test_output.py @@ -29,5 +29,5 @@ class OutputTestHarness(TestHarness): if __name__ == '__main__': - harness = OutputTestHarness('statepoint.10.*') + harness = OutputTestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_plot/test_plot.py b/tests/test_plot/test_plot.py index b21e1aada8..d484925cb4 100644 --- a/tests/test_plot/test_plot.py +++ b/tests/test_plot/test_plot.py @@ -15,7 +15,7 @@ import openmc class PlotTestHarness(TestHarness): """Specialized TestHarness for running OpenMC plotting tests.""" def __init__(self, plot_names): - super(PlotTestHarness, self).__init__(None, False) + super(PlotTestHarness, self).__init__(None) self._plot_names = plot_names def _run_openmc(self): diff --git a/tests/test_ptables_off/test_ptables_off.py b/tests/test_ptables_off/test_ptables_off.py index 2a595f3e66..b04fcc6eba 100644 --- a/tests/test_ptables_off/test_ptables_off.py +++ b/tests/test_ptables_off/test_ptables_off.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_quadric_surfaces/test_quadric_surfaces.py b/tests/test_quadric_surfaces/test_quadric_surfaces.py index 2a595f3e66..b04fcc6eba 100755 --- a/tests/test_quadric_surfaces/test_quadric_surfaces.py +++ b/tests/test_quadric_surfaces/test_quadric_surfaces.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_reflective_plane/test_reflective_plane.py b/tests/test_reflective_plane/test_reflective_plane.py index 2a595f3e66..b04fcc6eba 100644 --- a/tests/test_reflective_plane/test_reflective_plane.py +++ b/tests/test_reflective_plane/test_reflective_plane.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_rotation/test_rotation.py b/tests/test_rotation/test_rotation.py index 2a595f3e66..b04fcc6eba 100644 --- a/tests/test_rotation/test_rotation.py +++ b/tests/test_rotation/test_rotation.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_salphabeta/test_salphabeta.py b/tests/test_salphabeta/test_salphabeta.py index 2a595f3e66..b04fcc6eba 100644 --- a/tests/test_salphabeta/test_salphabeta.py +++ b/tests/test_salphabeta/test_salphabeta.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_score_current/test_score_current.py b/tests/test_score_current/test_score_current.py index 99c2981c2a..ea5886a639 100644 --- a/tests/test_score_current/test_score_current.py +++ b/tests/test_score_current/test_score_current.py @@ -7,5 +7,5 @@ from testing_harness import HashedTestHarness if __name__ == '__main__': - harness = HashedTestHarness('statepoint.10.*', True) + harness = HashedTestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_seed/test_seed.py b/tests/test_seed/test_seed.py index 2a595f3e66..b04fcc6eba 100644 --- a/tests/test_seed/test_seed.py +++ b/tests/test_seed/test_seed.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_source_file/test_source_file.py b/tests/test_source_file/test_source_file.py index 6f76438c2a..5631814b4c 100644 --- a/tests/test_source_file/test_source_file.py +++ b/tests/test_source_file/test_source_file.py @@ -98,5 +98,5 @@ class SourceFileTestHarness(TestHarness): if __name__ == '__main__': - harness = SourceFileTestHarness('statepoint.10.*') + harness = SourceFileTestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_sourcepoint_batch/test_sourcepoint_batch.py b/tests/test_sourcepoint_batch/test_sourcepoint_batch.py index 5db0541344..d5ea0e48b2 100644 --- a/tests/test_sourcepoint_batch/test_sourcepoint_batch.py +++ b/tests/test_sourcepoint_batch/test_sourcepoint_batch.py @@ -5,7 +5,7 @@ import os import sys sys.path.insert(0, os.pardir) from testing_harness import TestHarness -from openmc.statepoint import StatePoint +from openmc import StatePoint class SourcepointTestHarness(TestHarness): @@ -18,21 +18,20 @@ class SourcepointTestHarness(TestHarness): def _get_results(self): """Digest info in the statepoint and return as a string.""" - # Read the statepoint file. - statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))[0] - sp = StatePoint(statepoint) - # Get the eigenvalue information. outstr = TestHarness._get_results(self) - # Add the source information. - xyz = sp.source[0]['xyz'] - outstr += ' '.join(['{0:12.6E}'.format(x) for x in xyz]) - outstr += "\n" + # Read the statepoint file. + statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))[0] + with StatePoint(statepoint) as sp: + # Add the source information. + xyz = sp.source[0]['xyz'] + outstr += ' '.join(['{0:12.6E}'.format(x) for x in xyz]) + outstr += "\n" return outstr if __name__ == '__main__': - harness = SourcepointTestHarness('statepoint.08.*') + harness = SourcepointTestHarness('statepoint.08.h5') harness.main() diff --git a/tests/test_sourcepoint_latest/test_sourcepoint_latest.py b/tests/test_sourcepoint_latest/test_sourcepoint_latest.py index 724a88fa65..c64cc20cc7 100644 --- a/tests/test_sourcepoint_latest/test_sourcepoint_latest.py +++ b/tests/test_sourcepoint_latest/test_sourcepoint_latest.py @@ -18,5 +18,5 @@ class SourcepointTestHarness(TestHarness): if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_sourcepoint_restart/test_sourcepoint_restart.py b/tests/test_sourcepoint_restart/test_sourcepoint_restart.py index ed6addec45..b04fcc6eba 100644 --- a/tests/test_sourcepoint_restart/test_sourcepoint_restart.py +++ b/tests/test_sourcepoint_restart/test_sourcepoint_restart.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*', True) + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_statepoint_batch/test_statepoint_batch.py b/tests/test_statepoint_batch/test_statepoint_batch.py index c8da1c9adc..e3e2391ba1 100644 --- a/tests/test_statepoint_batch/test_statepoint_batch.py +++ b/tests/test_statepoint_batch/test_statepoint_batch.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python import os import sys @@ -8,11 +8,11 @@ from testing_harness import TestHarness class StatepointTestHarness(TestHarness): def __init__(self): - super(StatepointTestHarness, self).__init__(None, False) + super(StatepointTestHarness, self).__init__(None) def _test_output_created(self): """Make sure statepoint files have been created.""" - sps = ('statepoint.03.*', 'statepoint.06.*', 'statepoint.09.*') + sps = ('statepoint.03.h5', 'statepoint.06.h5', 'statepoint.09.h5') for sp in sps: self._sp_name = sp TestHarness._test_output_created(self) diff --git a/tests/test_statepoint_restart/test_statepoint_restart.py b/tests/test_statepoint_restart/test_statepoint_restart.py index 61522ee051..2c1c444958 100644 --- a/tests/test_statepoint_restart/test_statepoint_restart.py +++ b/tests/test_statepoint_restart/test_statepoint_restart.py @@ -9,9 +9,8 @@ import openmc class StatepointRestartTestHarness(TestHarness): - def __init__(self, final_sp, restart_sp, tallies_present=False): - super(StatepointRestartTestHarness, self).__init__(final_sp, - tallies_present) + def __init__(self, final_sp, restart_sp): + super(StatepointRestartTestHarness, self).__init__(final_sp) self._restart_sp = restart_sp def execute_test(self): @@ -63,5 +62,5 @@ class StatepointRestartTestHarness(TestHarness): if __name__ == '__main__': harness = StatepointRestartTestHarness('statepoint.10.h5', - 'statepoint.07.h5', True) + 'statepoint.07.h5') harness.main() diff --git a/tests/test_statepoint_sourcesep/test_statepoint_sourcesep.py b/tests/test_statepoint_sourcesep/test_statepoint_sourcesep.py index 00ded42ec2..f4bdcfb7b3 100644 --- a/tests/test_statepoint_sourcesep/test_statepoint_sourcesep.py +++ b/tests/test_statepoint_sourcesep/test_statepoint_sourcesep.py @@ -26,5 +26,5 @@ class SourcepointTestHarness(TestHarness): if __name__ == '__main__': - harness = SourcepointTestHarness('statepoint.10.*') + harness = SourcepointTestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_survival_biasing/test_survival_biasing.py b/tests/test_survival_biasing/test_survival_biasing.py index ed6addec45..b04fcc6eba 100644 --- a/tests/test_survival_biasing/test_survival_biasing.py +++ b/tests/test_survival_biasing/test_survival_biasing.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*', True) + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_tallies/test_tallies.py b/tests/test_tallies/test_tallies.py index b41068f8e8..315a5b6be2 100644 --- a/tests/test_tallies/test_tallies.py +++ b/tests/test_tallies/test_tallies.py @@ -10,7 +10,7 @@ from openmc import Mesh, Tally, Tallies if __name__ == '__main__': - harness = HashedPyAPITestHarness('statepoint.5.h5', True) + harness = HashedPyAPITestHarness('statepoint.5.h5') model = harness._model # Set settings explicitly diff --git a/tests/test_tally_aggregation/test_tally_aggregation.py b/tests/test_tally_aggregation/test_tally_aggregation.py index cb98b53fa1..cf291e0266 100644 --- a/tests/test_tally_aggregation/test_tally_aggregation.py +++ b/tests/test_tally_aggregation/test_tally_aggregation.py @@ -67,5 +67,5 @@ class TallyAggregationTestHarness(PyAPITestHarness): if __name__ == '__main__': - harness = TallyAggregationTestHarness('statepoint.10.h5', True) + harness = TallyAggregationTestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_tally_arithmetic/test_tally_arithmetic.py b/tests/test_tally_arithmetic/test_tally_arithmetic.py index 6fcbb15a8a..593a0a2917 100644 --- a/tests/test_tally_arithmetic/test_tally_arithmetic.py +++ b/tests/test_tally_arithmetic/test_tally_arithmetic.py @@ -81,5 +81,5 @@ class TallyArithmeticTestHarness(PyAPITestHarness): if __name__ == '__main__': - harness = TallyArithmeticTestHarness('statepoint.10.h5', True) + harness = TallyArithmeticTestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_tally_assumesep/test_tally_assumesep.py b/tests/test_tally_assumesep/test_tally_assumesep.py index ed6addec45..b04fcc6eba 100644 --- a/tests/test_tally_assumesep/test_tally_assumesep.py +++ b/tests/test_tally_assumesep/test_tally_assumesep.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*', True) + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_tally_nuclides/test_tally_nuclides.py b/tests/test_tally_nuclides/test_tally_nuclides.py index ed6addec45..b04fcc6eba 100644 --- a/tests/test_tally_nuclides/test_tally_nuclides.py +++ b/tests/test_tally_nuclides/test_tally_nuclides.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*', True) + harness = TestHarness('statepoint.10.h5') harness.main() 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 624624a153..d917d2dadb 100644 --- a/tests/test_tally_slice_merge/test_tally_slice_merge.py +++ b/tests/test_tally_slice_merge/test_tally_slice_merge.py @@ -172,5 +172,5 @@ class TallySliceMergeTestHarness(PyAPITestHarness): if __name__ == '__main__': - harness = TallySliceMergeTestHarness('statepoint.10.h5', True) + harness = TallySliceMergeTestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_trace/test_trace.py b/tests/test_trace/test_trace.py index 2a595f3e66..b04fcc6eba 100644 --- a/tests/test_trace/test_trace.py +++ b/tests/test_trace/test_trace.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_track_output/test_track_output.py b/tests/test_track_output/test_track_output.py index 9e9ce87adb..231f25a0de 100644 --- a/tests/test_track_output/test_track_output.py +++ b/tests/test_track_output/test_track_output.py @@ -54,5 +54,5 @@ if __name__ == '__main__': print('----------------Skipping test-------------') shutil.copy('results_true.dat', 'results_test.dat') exit() - harness = TrackTestHarness('statepoint.2.*') + harness = TrackTestHarness('statepoint.2.h5') harness.main() diff --git a/tests/test_translation/test_translation.py b/tests/test_translation/test_translation.py index 2a595f3e66..b04fcc6eba 100644 --- a/tests/test_translation/test_translation.py +++ b/tests/test_translation/test_translation.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_trigger_batch_interval/test_trigger_batch_interval.py b/tests/test_trigger_batch_interval/test_trigger_batch_interval.py index a0b2119dea..fb88ada001 100644 --- a/tests/test_trigger_batch_interval/test_trigger_batch_interval.py +++ b/tests/test_trigger_batch_interval/test_trigger_batch_interval.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.15.*', True) + harness = TestHarness('statepoint.15.h5') harness.main() diff --git a/tests/test_trigger_no_batch_interval/test_trigger_no_batch_interval.py b/tests/test_trigger_no_batch_interval/test_trigger_no_batch_interval.py index a0b2119dea..fb88ada001 100644 --- a/tests/test_trigger_no_batch_interval/test_trigger_no_batch_interval.py +++ b/tests/test_trigger_no_batch_interval/test_trigger_no_batch_interval.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.15.*', True) + harness = TestHarness('statepoint.15.h5') harness.main() diff --git a/tests/test_trigger_no_status/test_trigger_no_status.py b/tests/test_trigger_no_status/test_trigger_no_status.py index ed6addec45..b04fcc6eba 100644 --- a/tests/test_trigger_no_status/test_trigger_no_status.py +++ b/tests/test_trigger_no_status/test_trigger_no_status.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*', True) + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_trigger_tallies/test_trigger_tallies.py b/tests/test_trigger_tallies/test_trigger_tallies.py index a0b2119dea..fb88ada001 100644 --- a/tests/test_trigger_tallies/test_trigger_tallies.py +++ b/tests/test_trigger_tallies/test_trigger_tallies.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.15.*', True) + harness = TestHarness('statepoint.15.h5') harness.main() diff --git a/tests/test_uniform_fs/test_uniform_fs.py b/tests/test_uniform_fs/test_uniform_fs.py index 2a595f3e66..b04fcc6eba 100644 --- a/tests/test_uniform_fs/test_uniform_fs.py +++ b/tests/test_uniform_fs/test_uniform_fs.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_universe/test_universe.py b/tests/test_universe/test_universe.py index 2a595f3e66..b04fcc6eba 100644 --- a/tests/test_universe/test_universe.py +++ b/tests/test_universe/test_universe.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/test_void/test_void.py b/tests/test_void/test_void.py index 2a595f3e66..b04fcc6eba 100644 --- a/tests/test_void/test_void.py +++ b/tests/test_void/test_void.py @@ -7,5 +7,5 @@ from testing_harness import TestHarness if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') + harness = TestHarness('statepoint.10.h5') harness.main() diff --git a/tests/testing_harness.py b/tests/testing_harness.py index 71e72edbd9..428bf5c4b7 100644 --- a/tests/testing_harness.py +++ b/tests/testing_harness.py @@ -1,5 +1,6 @@ from __future__ import print_function +from difflib import unified_diff import filecmp import glob import hashlib @@ -12,15 +13,14 @@ import numpy as np sys.path.insert(0, os.path.join(os.pardir, os.pardir)) import openmc -from openmc.examples import pwr_core, slab_mg +from openmc.examples import pwr_core class TestHarness(object): """General class for running OpenMC regression tests.""" - def __init__(self, statepoint_name, tallies_present=False): + def __init__(self, statepoint_name): self._sp_name = statepoint_name - self._tallies = tallies_present self.parser = OptionParser() self.parser.add_option('--exe', dest='exe', default='openmc') self.parser.add_option('--mpi_exec', dest='mpi_exec', default=None) @@ -78,7 +78,7 @@ class TestHarness(object): ' exist.' assert statepoint[0].endswith('h5'), \ 'Statepoint file is not a HDF5 file.' - if self._tallies: + if os.path.exists('tallies.xml'): assert os.path.exists('tallies.out'), \ 'Tally output file does not exist.' @@ -86,26 +86,22 @@ class TestHarness(object): """Digest info in the statepoint and return as a string.""" # Read the statepoint file. statepoint = glob.glob(self._sp_name)[0] - sp = openmc.StatePoint(statepoint) + with openmc.StatePoint(statepoint) as sp: + # Write out k-combined. + outstr = 'k-combined:\n' + form = '{0:12.6E} {1:12.6E}\n' + outstr += form.format(sp.k_combined[0], sp.k_combined[1]) - # Write out k-combined. - outstr = 'k-combined:\n' - form = '{0:12.6E} {1:12.6E}\n' - outstr += form.format(sp.k_combined[0], sp.k_combined[1]) - - # Write out tally data. - if self._tallies: - tally_num = 1 - for tally_ind in sp.tallies: + # Write out tally data. + for i, tally_ind in enumerate(sp.tallies): tally = sp.tallies[tally_ind] results = np.zeros((tally.sum.size * 2, )) results[0::2] = tally.sum.ravel() results[1::2] = tally.sum_sq.ravel() results = ['{0:12.6E}'.format(x) for x in results] - outstr += 'tally ' + str(tally_num) + ':\n' + outstr += 'tally {}:\n'.format(i + 1) outstr += '\n'.join(results) + '\n' - tally_num += 1 # Hash the results if necessary. if hash_output: @@ -154,31 +150,31 @@ class CMFDTestHarness(TestHarness): def _get_results(self): """Digest info in the statepoint and return as a string.""" - # Read the statepoint file. - statepoint = glob.glob(self._sp_name)[0] - sp = openmc.StatePoint(statepoint) # Write out the eigenvalue and tallies. outstr = super(CMFDTestHarness, self)._get_results() - # Write out CMFD data. - outstr += 'cmfd indices\n' - outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp.cmfd_indices]) - outstr += '\nk cmfd\n' - outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp.k_cmfd]) - outstr += '\ncmfd entropy\n' - outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp.cmfd_entropy]) - outstr += '\ncmfd balance\n' - outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp.cmfd_balance]) - outstr += '\ncmfd dominance ratio\n' - outstr += '\n'.join(['{0:10.3E}'.format(x) for x in sp.cmfd_dominance]) - outstr += '\ncmfd openmc source comparison\n' - outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp.cmfd_srccmp]) - outstr += '\ncmfd source\n' - cmfdsrc = np.reshape(sp.cmfd_src, np.product(sp.cmfd_indices), - order='F') - outstr += '\n'.join(['{0:12.6E}'.format(x) for x in cmfdsrc]) - outstr += '\n' + # Read the statepoint file. + statepoint = glob.glob(self._sp_name)[0] + with openmc.StatePoint(statepoint) as sp: + # Write out CMFD data. + outstr += 'cmfd indices\n' + outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp.cmfd_indices]) + outstr += '\nk cmfd\n' + outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp.k_cmfd]) + outstr += '\ncmfd entropy\n' + outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp.cmfd_entropy]) + outstr += '\ncmfd balance\n' + outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp.cmfd_balance]) + outstr += '\ncmfd dominance ratio\n' + outstr += '\n'.join(['{0:10.3E}'.format(x) for x in sp.cmfd_dominance]) + outstr += '\ncmfd openmc source comparison\n' + outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp.cmfd_srccmp]) + outstr += '\ncmfd source\n' + cmfdsrc = np.reshape(sp.cmfd_src, np.product(sp.cmfd_indices), + order='F') + outstr += '\n'.join(['{0:12.6E}'.format(x) for x in cmfdsrc]) + outstr += '\n' return outstr @@ -240,9 +236,8 @@ class ParticleRestartTestHarness(TestHarness): class PyAPITestHarness(TestHarness): - def __init__(self, statepoint_name, tallies_present=False, model=None): - super(PyAPITestHarness, self).__init__( - statepoint_name, tallies_present) + def __init__(self, statepoint_name, model=None): + super(PyAPITestHarness, self).__init__(statepoint_name) self.parser.add_option('-b', '--build-inputs', dest='build_only', action='store_true', default=False) if model is None: @@ -316,11 +311,11 @@ class PyAPITestHarness(TestHarness): """Make sure the current inputs agree with the _true standard.""" compare = filecmp.cmp('inputs_test.dat', 'inputs_true.dat') if not compare: - f = open('inputs_test.dat') - for line in f.readlines(): - print(line) - f.close() os.rename('inputs_test.dat', 'inputs_error.dat') + for line in unified_diff(open('inputs_true.dat', 'r').readlines(), + open('inputs_error.dat', 'r').readlines(), + 'inputs_true.dat', 'inputs_error.dat'): + print(line, end='') assert compare, 'Input files are broken.' def _cleanup(self): From 1099d8bd9d5d4aa272225d5b0fb4b5275379cb48 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 7 Apr 2017 10:41:20 -0500 Subject: [PATCH 06/22] Use StatePoint context manager for keff search --- openmc/model/model.py | 24 ++++++------------------ openmc/search.py | 4 ---- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/openmc/model/model.py b/openmc/model/model.py index 36621ed4f9..b68e1582d6 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -65,8 +65,6 @@ class Model(object): if plots is not None: self.plots = plots - self.sp = None - @property def geometry(self): return self._geometry @@ -161,7 +159,7 @@ class Model(object): self.plots.export_to_xml() def run(self, **kwargs): - """Creates the XML files, runs OpenMC, and loads the statepoint. + """Creates the XML files, runs OpenMC, and returns k-effective Parameters ---------- @@ -171,29 +169,19 @@ class Model(object): Returns ------- 2-tuple of float - k_combined from the statepoint + Combined estimator of k-effective from the statepoint """ - self.export_to_xml() return_code = openmc.run(**kwargs) assert (return_code == 0), "OpenMC did not execute successfully" - statepoint_batches = self.settings.batches + n = self.settings.batches 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)) + n = self.settings.statepoint['batches'][-1] - return self.sp.k_combined - - def close(self): - """Close the statepoint and summary files - """ - - if self.sp is not None: - self.sp._f.close() - self.sp.summary._f.close() + with openmc.StatePoint('statepoint.{}.h5'.format(n)) as sp: + return sp.k_combined diff --git a/openmc/search.py b/openmc/search.py index dd2c4345af..128a725d97 100644 --- a/openmc/search.py +++ b/openmc/search.py @@ -51,10 +51,6 @@ def _search_keff(guess, target, model_builder, model_args, print_iterations, # Run the model and obtain keff keff = model.run(output=print_output) - # Close the model to ensure HDF5 will allow access during the next - # OpenMC execution - model.close() - # Record the history guesses.append(guess) results.append(keff) From 44949016b5ce737b9bea26ca4f7d11b9b4041dd9 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 7 Apr 2017 17:11:03 -0500 Subject: [PATCH 07/22] Use del a[:] instead of a.clear() for lists (latter doesn't work in Py2) --- openmc/model/model.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openmc/model/model.py b/openmc/model/model.py index b68e1582d6..ec8ec54064 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -100,7 +100,7 @@ class Model(object): if isinstance(materials, openmc.Materials): self._materials = materials else: - self._materials.clear() + del self._materials[:] for mat in materials: self._materials.append(mat) @@ -115,7 +115,7 @@ class Model(object): if isinstance(tallies, openmc.Tallies): self._tallies = tallies else: - self._tallies.clear() + del self._tallies[:] for tally in tallies: self._tallies.append(tally) @@ -130,7 +130,7 @@ class Model(object): if isinstance(plots, openmc.Plots): self._plots = plots else: - self._plots.clear() + del self._plots[:] for plot in plots: self._plots.append(plot) From 3e7bca49a8d02ec96bbff7c38e78ef8b77472a50 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 7 Apr 2017 17:26:58 -0500 Subject: [PATCH 08/22] Fix openmc-track-to-vtk and track test --- scripts/openmc-track-to-vtk | 4 ++-- tests/test_track_output/test_track_output.py | 18 ++++++------------ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/scripts/openmc-track-to-vtk b/scripts/openmc-track-to-vtk index d190ac662f..1dd632f9dd 100755 --- a/scripts/openmc-track-to-vtk +++ b/scripts/openmc-track-to-vtk @@ -42,8 +42,8 @@ def main(): for fname in args.input: # Write coordinate values to points array. track = h5py.File(fname) - n_particles = track['n_particles'].value - n_coords = track['n_coords'] + n_particles = track.attrs['n_particles'] + n_coords = track.attrs['n_coords'] coords = [] for i in range(n_particles): coords.append(track['coordinates_' + str(i + 1)].value) diff --git a/tests/test_track_output/test_track_output.py b/tests/test_track_output/test_track_output.py index 231f25a0de..0357aae19e 100644 --- a/tests/test_track_output/test_track_output.py +++ b/tests/test_track_output/test_track_output.py @@ -14,32 +14,26 @@ class TrackTestHarness(TestHarness): """Make sure statepoint.* and track* have been created.""" TestHarness._test_output_created(self) - outputs = [glob.glob(''.join((os.getcwd(), '/track_1_1_1.*')))] - outputs.append(glob.glob(''.join((os.getcwd(), '/track_1_1_2.*')))) - for files in outputs: - assert len(files) == 1, 'Multiple or no track files detected.' - assert files[0].endswith('h5'),\ - 'Track files are not HDF5 files' + outputs = glob.glob('track_1_1_*.h5') + assert len(outputs) == 2, 'Expected two track files.' def _get_results(self): """Digest info in the statepoint and return as a string.""" # Run the track-to-vtk conversion script. call(['../../scripts/openmc-track-to-vtk', '-o', 'poly'] + - glob.glob(''.join((os.getcwd(), '/track*')))) + glob.glob('track_1_1_*.h5')) # Make sure the vtk file was created then return it's contents. - poly = os.path.join(os.getcwd(), 'poly.pvtp') - assert os.path.isfile(poly), 'poly.pvtp file not found.' + assert os.path.isfile('poly.pvtp'), 'poly.pvtp file not found.' - with open(poly) as fin: + with open('poly.pvtp', 'r') as fin: outstr = fin.read() return outstr def _cleanup(self): TestHarness._cleanup(self) - output = glob.glob(os.path.join(os.getcwd(), 'track*')) - output += glob.glob(os.path.join(os.getcwd(), 'poly*')) + output = glob.glob('track*') + glob.glob('poly*') for f in output: if os.path.exists(f): os.remove(f) From f658bf85ebdc379d157757b5807fa529cbe49750 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Sat, 8 Apr 2017 14:30:28 -0500 Subject: [PATCH 09/22] Show error message if 0K scattering not present --- src/input_xml.F90 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/input_xml.F90 b/src/input_xml.F90 index bf981e9f5f..a58cd3af84 100644 --- a/src/input_xml.F90 +++ b/src/input_xml.F90 @@ -5303,6 +5303,13 @@ contains do i = 1, size(res_scat_nuclides) if (nuc % name == res_scat_nuclides(i)) then + ! Make sure nuclide has 0K data + if (.not. allocated(nuc % energy_0K)) then + call fatal_error("Cannot treat " // trim(nuc % name) // " as a & + &resonant scatterer because 0 K elastic scattering data is not & + &present.") + end if + ! Set nuclide to be resonant nuc % resonant = .true. From 7156d7cd986106973e57366c9c6815b73344085c Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Sat, 8 Apr 2017 15:48:20 -0500 Subject: [PATCH 10/22] Respond to @nelsonag comments on #852 --- docs/source/devguide/workflow.rst | 17 ++++++++++------ docs/source/usersguide/cross_sections.rst | 24 +++++++++++++++++++++++ openmc/examples.py | 21 +++++++++++++++++--- openmc/model/model.py | 10 ++++++---- 4 files changed, 59 insertions(+), 13 deletions(-) diff --git a/docs/source/devguide/workflow.rst b/docs/source/devguide/workflow.rst index 7a303f45e9..942cee55be 100644 --- a/docs/source/devguide/workflow.rst +++ b/docs/source/devguide/workflow.rst @@ -105,15 +105,20 @@ in the tests directory. We recommend to developers to test their branches before submitting a formal pull request using gfortran and Intel compilers if available. -The test suite is designed to integrate with cmake using ctest_. -It is configured to run with cross sections from NNDC_. To -download these cross sections please do the following: +The test suite is designed to integrate with cmake using ctest_. It is +configured to run with cross sections from NNDC_ augmented with 0 K elastic +scattering data for select nuclides as well as multipole data. To download the +proper data, run the following commands: .. code-block:: sh - cd ../scripts - ./openmc-get-nndc-data - export OPENMC_CROSS_SECTIONS=/nndc_hdf5/cross_sections.xml + wget -O nndc_hdf5.tar.xz $(cat /.travis.yml | grep anl.box | awk '{print $2}') + tar xJvf nndc_hdf5.tar.xz + export OPENMC_CROSS_SECTIONS=$(pwd)/nndc_hdf5/cross_sections.xml + + git clone --branch=master git://github.com/smharper/windowed_multipole_library.git wmp_lib + tar xzvf wmp_lib/multipole_lib.tar.gz + export OPENMC_MULTIPOLE_LIBRARY=$(pwd)/multipole_lib The test suite can be run on an already existing build using: diff --git a/docs/source/usersguide/cross_sections.rst b/docs/source/usersguide/cross_sections.rst index 25bb1e5d83..fa61045c6c 100644 --- a/docs/source/usersguide/cross_sections.rst +++ b/docs/source/usersguide/cross_sections.rst @@ -199,6 +199,30 @@ OpenMC. etc. For a more thorough overview of the capabilities of this class, see the :ref:`notebook_nuclear_data` example notebook. +Enabling Resonance Scattering Treatments +---------------------------------------- + +In order for OpenMC to correctly treat elastic scattering in heavy nuclides +where low-lying resonances might be present (see +:ref:`energy_dependent_xs_model`), the elastic scattering cross section at 0 K +must be present. To add the 0 K elastic scattering cross section to existing +:class:`IncidentNeutron` instance, you can use the +:meth:`IncidentNeutron.add_elastic_0K_from_endf` method which requires an ENDF +file for the nuclide you are modifying:: + + u238 = openmc.data.IncidentNeutron.from_hdf5('U238.h5') + u238.add_elastic_0K_from_endf('n-092_U_238.endf') + u238.export_to_hdf5('U238_with_0K.h5') + +With 0 K elastic scattering data present, you can turn on a resonance scattering +method using :attr:`Settings.resonance_scattering`. + +.. note:: The process of reconstructing resonances and generating tabulated 0 K + cross sections can be computationally expensive, especially for + nuclides like U-238 where thousands of resonances are present. Thus, + running the :meth:`IncidentNeutron.add_elastic_0K_from_endf` method + may take several minutes to complete. + ----------------------- Windowed Multipole Data ----------------------- diff --git a/openmc/examples.py b/openmc/examples.py index 6e2a04f7f6..0e17747fc3 100644 --- a/openmc/examples.py +++ b/openmc/examples.py @@ -7,6 +7,11 @@ import openmc.model def pwr_pin_cell(): """Create a PWR pin-cell model. + This model is a single fuel pin with 2.4 w/o enriched UO2 corresponding to a + beginning-of-cycle condition and borated water. The specifications are from + the `BEAVRS `_ benchmark. Note that the + number of particles/batches is initially set very low for testing purposes. + Returns ------- model : openmc.model.Model @@ -85,7 +90,8 @@ def pwr_core(): This model is the OECD/NEA Monte Carlo Performance benchmark which is a grossly simplified pressurized water reactor (PWR) with 241 fuel - assemblies. + assemblies. Note that the number of particles/batches is initially set very + low for testing purposes. Returns ------- @@ -428,6 +434,11 @@ def pwr_core(): def pwr_assembly(): """Create a PWR assembly model. + This model is a reflected 17x17 fuel assembly from the the `BEAVRS + `_ benchmark. The fuel is 2.4 w/o + enriched UO2 corresponding to a beginning-of-cycle condition. Note that the + number of particles/batches is initially set very low for testing purposes. + Returns ------- model : openmc.model.Model @@ -538,8 +549,12 @@ def slab_mg(reps=None, as_macro=True): Parameters ---------- reps : list, optional - List of angular representations. Items can be 'ang', 'ang_mu', 'iso', or - 'iso_mu'. + List of angular representations. Each item corresponds to materials and + dictates the angular representation of the multi-group cross + sections---isotropic ('iso') or angle-dependent ('ang'), and if Legendre + scattering or tabular scattering ('mu') is used. Thus, items can be + 'ang', 'ang_mu', 'iso', or 'iso_mu'. + as_macro : bool, optional Whether :class:`openmc.Macroscopic` is used diff --git a/openmc/model/model.py b/openmc/model/model.py index ec8ec54064..17de6fc2e6 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -10,7 +10,10 @@ class Model(object): 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. + thus making a complete model. The :meth:`Model.export_to_xml` method will + export XML files for all attributes that have been set. If the + :meth:`Model.materials` attribute is not set, it will attempt to create a + ``materials.xml`` file based on all materials appearing in the geometry. Parameters ---------- @@ -50,9 +53,8 @@ class Model(object): self.materials = openmc.Materials() self.settings = openmc.Settings() self.cmfd = cmfd - - self._tallies = openmc.Tallies() - self._plots = openmc.Plots() + self.tallies = openmc.Tallies() + self.plots = openmc.Plots() if geometry is not None: self.geometry = geometry From 06a918c1b579b3a5a373fa55ed891e706d2dde08 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Sun, 9 Apr 2017 16:30:33 -0400 Subject: [PATCH 11/22] First stab at implementing clone() methods for geometric and material primitives --- openmc/cell.py | 14 ++++++++++++++ openmc/lattice.py | 19 +++++++++++++++++++ openmc/material.py | 7 +++++++ openmc/region.py | 31 +++++++++++++++++++++++++++++++ openmc/surface.py | 16 ++++++++++++++++ openmc/universe.py | 14 ++++++++++++++ 6 files changed, 101 insertions(+) diff --git a/openmc/cell.py b/openmc/cell.py index 9993175efd..ba7a41435b 100644 --- a/openmc/cell.py +++ b/openmc/cell.py @@ -504,6 +504,20 @@ class Cell(object): return universes + def clone(self): + """Create a copy of this cell with a new unique ID, and clones + the cell's region and fill.""" + + clone = copy.deepcopy(self) + clone.id = None + + if self.region is not None: + clone.region = self.region.clone() + if self.fill is not None: + clone.fill = self.fill.clone() + + return clone + def create_xml_subelement(self, xml_element): element = ET.Element("cell") element.set("id", str(self.id)) diff --git a/openmc/lattice.py b/openmc/lattice.py index 08ca24a192..9f3f303859 100644 --- a/openmc/lattice.py +++ b/openmc/lattice.py @@ -414,6 +414,25 @@ class Lattice(object): return [] return [(self, idx)] + u.find(p) + def clone(self): + """Create a copy of this lattice with a new unique ID, and clones + all universes within this lattice.""" + + clone = copy.deepcopy(self) + clone.id = None + + # Clone all unique universes in the lattice + univ_clones = self.get_unique_universes() + for univ_id in univ_clones: + univ_clones[univ_id] = univ_clones[univ_id].clone() + + # Assign universe clones to the lattice clone + for index in self.indices: + univ_id = self.universe[index].id + clone.universes[index] = univ_clones[univ_id] + + return clone + class RectLattice(Lattice): """A lattice consisting of rectangular prisms. diff --git a/openmc/material.py b/openmc/material.py index 26b1bce8fc..cb1482b8e0 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -1100,6 +1100,13 @@ class Materials(cv.CheckedList): for material in self: material.make_isotropic_in_lab() + def clone(self): + """Create a copy of this material with a new unique ID.""" + + clone = copy.deepcopy(self) + clone.id = None + return clone + def _create_material_subelements(self, root_element): for material in self: root_element.append(material.to_xml_element(self.cross_sections)) diff --git a/openmc/region.py b/openmc/region.py index a2a92c15a3..1ac4d8c948 100644 --- a/openmc/region.py +++ b/openmc/region.py @@ -221,6 +221,12 @@ class Region(object): # at the end return output[0] + @abstractmethod + def clone(self): + """Create a copy of this region - each of the surfaces in the + region's nodes will be cloned and will have new unique IDs.""" + return False + class Intersection(Region): r"""Intersection of two or more regions. @@ -300,6 +306,15 @@ class Intersection(Region): check_type('nodes', nodes, Iterable, Region) self._nodes = nodes + @abstractmethod + def clone(self): + """Create a copy of this region - each of the surfaces in the + intersection's nodes will be cloned and will have new unique IDs.""" + + clone = copy.deepcopy(self) + clone.nodes = [n.clone() for n in self.nodes] + return clone + class Union(Region): r"""Union of two or more regions. @@ -377,6 +392,14 @@ class Union(Region): check_type('nodes', nodes, Iterable, Region) self._nodes = nodes + def clone(self): + """Create a copy of this region - each of the surfaces in the + union's nodes will be cloned and will have new unique IDs.""" + + clone = copy.deepcopy(self) + clone.nodes = [n.clone() for n in self.nodes] + return clone + class Complement(Region): """Complement of a region. @@ -473,3 +496,11 @@ class Complement(Region): for region in self.node: surfaces = region.get_surfaces(surfaces) return surfaces + + def clone(self): + """Create a copy of this region - each of the surfaces in the + complement's node will be cloned and will have new unique IDs.""" + + clone = copy.deepcopy(self) + clone.node = self.node.clone() + return clone diff --git a/openmc/surface.py b/openmc/surface.py index 9c6be78a77..b0aa250c03 100644 --- a/openmc/surface.py +++ b/openmc/surface.py @@ -171,6 +171,13 @@ class Surface(object): return (np.array([-np.inf, -np.inf, -np.inf]), np.array([np.inf, np.inf, np.inf])) + def clone(self): + """Create a copy of this surface with a new unique ID.""" + + clone = copy.deepcopy(self) + clone.id = None + return clone + def to_xml_element(self): """Return XML representation of the surface @@ -1822,6 +1829,15 @@ class Halfspace(Region): self.surface = surface self.side = side + @abstractmethod + def clone(self): + """Create a copy of this halfspace, with a cloned surface with a + unique ID.""" + + clone = copy.deepcopy(self) + clone.surface = self.surface.clone() + return clone + def __and__(self, other): if isinstance(other, Intersection): return Intersection(self, *other.nodes) diff --git a/openmc/universe.py b/openmc/universe.py index 1c631e7e07..0f5e2da140 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -517,6 +517,20 @@ class Universe(object): return universes + def clone(self): + """Create a copy of this universe with a new unique ID, and clones + all cells within this universe.""" + + clone = copy.deepcopy(self) + clone.id = None + + # Clone all cells for the universe clone + clone._cells = OrderedDict() + for cell in self._cells.values(): + clone.add_cell(cell.clone()) + + return clone + def create_xml_subelement(self, xml_element): # Iterate over all Cells for cell_id, cell in self._cells.items(): From 45af8a29379b9398565afdea751f67933ac47682 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Sun, 9 Apr 2017 22:23:49 -0400 Subject: [PATCH 12/22] Tested geometry cloning with examples and fixed a few bugs --- openmc/cell.py | 3 ++- openmc/lattice.py | 17 +++++++++++++---- openmc/material.py | 14 +++++++------- openmc/region.py | 4 ++-- openmc/surface.py | 20 ++++++++++---------- openmc/universe.py | 4 ++-- 6 files changed, 36 insertions(+), 26 deletions(-) diff --git a/openmc/cell.py b/openmc/cell.py index ba7a41435b..522f9ab5d3 100644 --- a/openmc/cell.py +++ b/openmc/cell.py @@ -1,4 +1,5 @@ from collections import OrderedDict, Iterable +from copy import deepcopy from math import cos, sin, pi from numbers import Real, Integral from xml.etree import ElementTree as ET @@ -508,7 +509,7 @@ class Cell(object): """Create a copy of this cell with a new unique ID, and clones the cell's region and fill.""" - clone = copy.deepcopy(self) + clone = deepcopy(self) clone.id = None if self.region is not None: diff --git a/openmc/lattice.py b/openmc/lattice.py index 9f3f303859..b98ef00877 100644 --- a/openmc/lattice.py +++ b/openmc/lattice.py @@ -2,6 +2,7 @@ from __future__ import division from abc import ABCMeta from collections import OrderedDict, Iterable +from copy import deepcopy from math import sqrt, floor from numbers import Real, Integral from xml.etree import ElementTree as ET @@ -418,7 +419,7 @@ class Lattice(object): """Create a copy of this lattice with a new unique ID, and clones all universes within this lattice.""" - clone = copy.deepcopy(self) + clone = deepcopy(self) clone.id = None # Clone all unique universes in the lattice @@ -427,9 +428,17 @@ class Lattice(object): univ_clones[univ_id] = univ_clones[univ_id].clone() # Assign universe clones to the lattice clone - for index in self.indices: - univ_id = self.universe[index].id - clone.universes[index] = univ_clones[univ_id] + for i in self.indices: + if isinstance(self, RectLattice): + univ_id = self.universes[i].id + clone.universes[i] = univ_clones[univ_id] + else: + if self.ndim == 2: + univ_id = self.universes[i[0]][i[1]].id + clone.universes[i[0]][i[1]] = univ_clones[univ_id] + else: + univ_id = self.universes[i[0]][i[1]][i[2]].id + clone.universes[i[0]][i[1]][i[2]] = univ_clones[univ_id] return clone diff --git a/openmc/material.py b/openmc/material.py index cb1482b8e0..be13d619fe 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -799,6 +799,13 @@ class Material(object): return nuclides + def clone(self): + """Create a copy of this material with a new unique ID.""" + + clone = deepcopy(self) + clone.id = None + return clone + def _get_nuclide_xml(self, nuclide, distrib=False): xml_element = ET.Element("nuclide") xml_element.set("name", nuclide[0].name) @@ -1100,13 +1107,6 @@ class Materials(cv.CheckedList): for material in self: material.make_isotropic_in_lab() - def clone(self): - """Create a copy of this material with a new unique ID.""" - - clone = copy.deepcopy(self) - clone.id = None - return clone - def _create_material_subelements(self, root_element): for material in self: root_element.append(material.to_xml_element(self.cross_sections)) diff --git a/openmc/region.py b/openmc/region.py index 1ac4d8c948..b93d305fea 100644 --- a/openmc/region.py +++ b/openmc/region.py @@ -1,5 +1,6 @@ from abc import ABCMeta, abstractmethod from collections import Iterable, OrderedDict +from copy import deepcopy from six import add_metaclass import numpy as np @@ -306,12 +307,11 @@ class Intersection(Region): check_type('nodes', nodes, Iterable, Region) self._nodes = nodes - @abstractmethod def clone(self): """Create a copy of this region - each of the surfaces in the intersection's nodes will be cloned and will have new unique IDs.""" - clone = copy.deepcopy(self) + clone = deepcopy(self) clone.nodes = [n.clone() for n in self.nodes] return clone diff --git a/openmc/surface.py b/openmc/surface.py index b0aa250c03..866a9e2b98 100644 --- a/openmc/surface.py +++ b/openmc/surface.py @@ -1,5 +1,6 @@ from abc import ABCMeta from collections import Iterable, OrderedDict +from copy import deepcopy from numbers import Real, Integral from xml.etree import ElementTree as ET from math import sqrt @@ -174,7 +175,7 @@ class Surface(object): def clone(self): """Create a copy of this surface with a new unique ID.""" - clone = copy.deepcopy(self) + clone = deepcopy(self) clone.id = None return clone @@ -1828,15 +1829,6 @@ class Halfspace(Region): def __init__(self, surface, side): self.surface = surface self.side = side - - @abstractmethod - def clone(self): - """Create a copy of this halfspace, with a cloned surface with a - unique ID.""" - - clone = copy.deepcopy(self) - clone.surface = self.surface.clone() - return clone def __and__(self, other): if isinstance(other, Intersection): @@ -1918,6 +1910,14 @@ class Halfspace(Region): surfaces[self.surface.id] = self.surface return surfaces + def clone(self): + """Create a copy of this halfspace, with a cloned surface with a + unique ID.""" + + clone = deepcopy(self) + clone.surface = self.surface.clone() + return clone + def get_rectangular_prism(width, height, axis='z', origin=(0., 0.), boundary_type='transmission'): diff --git a/openmc/universe.py b/openmc/universe.py index 0f5e2da140..a2157f1d78 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -1,6 +1,6 @@ from __future__ import division -from copy import copy from collections import OrderedDict, Iterable +from copy import copy, deepcopy from numbers import Integral, Real import random import sys @@ -521,7 +521,7 @@ class Universe(object): """Create a copy of this universe with a new unique ID, and clones all cells within this universe.""" - clone = copy.deepcopy(self) + clone = deepcopy(self) clone.id = None # Clone all cells for the universe clone From c4fe563395b2cd471163fc876112535d5983babc Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Sun, 9 Apr 2017 22:26:09 -0400 Subject: [PATCH 13/22] Added clone method to Geometry class --- openmc/geometry.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/openmc/geometry.py b/openmc/geometry.py index ce7d47d9e2..424a7053e5 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -1,4 +1,5 @@ from collections import OrderedDict, Iterable +from copy import deepcopy from xml.etree import ElementTree as ET from six import string_types @@ -497,3 +498,11 @@ class Geometry(object): # Recursively traverse the CSG tree to count all cell instances self.root_universe._determine_paths() + + def clone(self): + """Create a copy of this geometry with new unique IDs for all of its + enclosed materials, surfaces, cells, universes and lattices.""" + + clone = deepcopy(self) + clone.root_universe = deepcopy(self.root_universe) + return clone From ad2e1cc1b4c174fb89e2453642ca579d034ddb4b Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 10 Apr 2017 07:16:17 -0500 Subject: [PATCH 14/22] Respond to @wbinventor comments on #852 --- docs/source/pythonapi/examples.rst | 2 +- openmc/examples.py | 43 ++++++++----------- tests/test_asymmetric_lattice/inputs_true.dat | 6 +-- tests/test_diff_tally/inputs_true.dat | 6 +-- tests/test_filter_energyfun/inputs_true.dat | 6 +-- tests/test_filter_mesh/inputs_true.dat | 6 +-- tests/test_iso_in_lab/inputs_true.dat | 6 +-- tests/test_mg_basic/inputs_true.dat | 24 +++++------ tests/test_mg_legendre/inputs_true.dat | 6 +-- tests/test_mg_max_order/inputs_true.dat | 6 +-- tests/test_mg_nuclide/inputs_true.dat | 24 +++++------ .../test_mg_survival_biasing/inputs_true.dat | 24 +++++------ tests/test_mg_tallies/inputs_true.dat | 24 +++++------ .../inputs_true.dat | 10 ++--- .../inputs_true.dat | 10 ++--- .../inputs_true.dat | 2 +- tests/test_mgxs_library_hdf5/inputs_true.dat | 10 ++--- tests/test_mgxs_library_mesh/inputs_true.dat | 6 +-- .../inputs_true.dat | 10 ++--- .../inputs_true.dat | 10 ++--- tests/test_tallies/inputs_true.dat | 6 +-- tests/test_tally_aggregation/inputs_true.dat | 6 +-- tests/test_tally_arithmetic/inputs_true.dat | 6 +-- tests/test_tally_slice_merge/inputs_true.dat | 6 +-- 24 files changed, 130 insertions(+), 135 deletions(-) diff --git a/docs/source/pythonapi/examples.rst b/docs/source/pythonapi/examples.rst index 2a3ebbd8e9..e7ef523c0e 100644 --- a/docs/source/pythonapi/examples.rst +++ b/docs/source/pythonapi/examples.rst @@ -20,6 +20,6 @@ Reactor Models :nosignatures: :template: myfunction.rst + openmc.examples.pwr_pin_cell openmc.examples.pwr_assembly openmc.examples.pwr_core - openmc.examples.pwr_pin_cell diff --git a/openmc/examples.py b/openmc/examples.py index 0e17747fc3..4eeae7799e 100644 --- a/openmc/examples.py +++ b/openmc/examples.py @@ -21,14 +21,14 @@ def pwr_pin_cell(): model = openmc.model.Model() # Define materials. - fuel = openmc.Material(name='Fuel') + fuel = openmc.Material(name='UO2 (2.4%)') 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 = openmc.Material(name='Zircaloy') clad.set_density('g/cm3', 6.55) clad.add_nuclide("Zr90", 2.1827e-2) clad.add_nuclide("Zr91", 4.7600e-3) @@ -58,9 +58,9 @@ def pwr_pin_cell(): 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) + fuel_pin = openmc.Cell(name='Fuel', fill=fuel) + cladding = openmc.Cell(name='Cladding', fill=clad) + water = openmc.Cell(name='Water', fill=hot_water) # Use surface half-spaces to define regions fuel_pin.region = -fuel_or @@ -102,7 +102,7 @@ def pwr_core(): model = openmc.model.Model() # Define materials. - fuel = openmc.Material(name='Fuel', material_id=1) + fuel = openmc.Material(1, name='UOX fuel') fuel.set_density('g/cm3', 10.062) fuel.add_nuclide("U234", 4.9476e-6) fuel.add_nuclide("U235", 4.8218e-4) @@ -110,7 +110,7 @@ def pwr_core(): fuel.add_nuclide("Xe135", 1.0801e-8) fuel.add_nuclide("O16", 4.5737e-2) - clad = openmc.Material(name='Cladding', material_id=2) + clad = openmc.Material(2, name='Zircaloy') clad.set_density('g/cm3', 5.77) clad.add_nuclide("Zr90", 0.5145) clad.add_nuclide("Zr91", 0.1122) @@ -118,7 +118,7 @@ def pwr_core(): 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 = openmc.Material(3, name='Cold borated water') cold_water.set_density('atom/b-cm', 0.07416) cold_water.add_nuclide("H1", 2.0) cold_water.add_nuclide("O16", 1.0) @@ -126,7 +126,7 @@ def pwr_core(): 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 = openmc.Material(4, name='Hot borated water') hot_water.set_density('atom/b-cm', 0.06614) hot_water.add_nuclide("H1", 2.0) hot_water.add_nuclide("O16", 1.0) @@ -134,8 +134,7 @@ def pwr_core(): 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 = openmc.Material(5, name='Reactor pressure vessel steel') rpv_steel.set_density('g/cm3', 7.9) rpv_steel.add_nuclide("Fe54", 0.05437098, 'wo') rpv_steel.add_nuclide("Fe56", 0.88500663, 'wo') @@ -148,8 +147,7 @@ def pwr_core(): 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 = openmc.Material(6, name='Lower radial reflector') 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') @@ -164,8 +162,7 @@ def pwr_core(): 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 = openmc.Material(7, name='Upper radial reflector / Top plate region') 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') @@ -180,7 +177,7 @@ def pwr_core(): 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 = openmc.Material(8, name='Bottom plate region') bot_plate.set_density('g/cm3', 7.184) bot_plate.add_nuclide("H1", 0.0011505, 'wo') bot_plate.add_nuclide("O16", 0.0091296, 'wo') @@ -195,8 +192,7 @@ def pwr_core(): 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 = openmc.Material(9, name='Bottom nozzle region') bot_nozzle.set_density('g/cm3', 2.53) bot_nozzle.add_nuclide("H1", 0.0245014, 'wo') bot_nozzle.add_nuclide("O16", 0.1944274, 'wo') @@ -211,7 +207,7 @@ def pwr_core(): 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 = openmc.Material(10, name='Top nozzle region') top_nozzle.set_density('g/cm3', 1.746) top_nozzle.add_nuclide("H1", 0.0358870, 'wo') top_nozzle.add_nuclide("O16", 0.2847761, 'wo') @@ -226,7 +222,7 @@ def pwr_core(): 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 = openmc.Material(11, name='Top of fuel assemblies') top_fa.set_density('g/cm3', 3.044) top_fa.add_nuclide("H1", 0.0162913, 'wo') top_fa.add_nuclide("O16", 0.1292776, 'wo') @@ -239,8 +235,7 @@ def pwr_core(): 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 = openmc.Material(12, name='Bottom of fuel assemblies') bot_fa.set_density('g/cm3', 1.762) bot_fa.add_nuclide("H1", 0.0292856, 'wo') bot_fa.add_nuclide("O16", 0.2323919, 'wo') @@ -524,7 +519,7 @@ def pwr_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 = openmc.Universe(name='root universe') model.geometry.root_universe.add_cell(root_cell) model.settings.batches = 10 @@ -609,7 +604,7 @@ def slab_mg(reps=None, as_macro=True): 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') + model.geometry.root_universe = openmc.Universe(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]) diff --git a/tests/test_asymmetric_lattice/inputs_true.dat b/tests/test_asymmetric_lattice/inputs_true.dat index 32745dad1e..e5ecbee270 100644 --- a/tests/test_asymmetric_lattice/inputs_true.dat +++ b/tests/test_asymmetric_lattice/inputs_true.dat @@ -56,7 +56,7 @@ - + @@ -105,7 +105,7 @@ - + @@ -157,7 +157,7 @@ - + diff --git a/tests/test_diff_tally/inputs_true.dat b/tests/test_diff_tally/inputs_true.dat index 0d75e48c6f..5667969957 100644 --- a/tests/test_diff_tally/inputs_true.dat +++ b/tests/test_diff_tally/inputs_true.dat @@ -148,7 +148,7 @@ - + @@ -197,7 +197,7 @@ - + @@ -249,7 +249,7 @@ - + diff --git a/tests/test_filter_energyfun/inputs_true.dat b/tests/test_filter_energyfun/inputs_true.dat index 48f6c5033e..1593c51131 100644 --- a/tests/test_filter_energyfun/inputs_true.dat +++ b/tests/test_filter_energyfun/inputs_true.dat @@ -148,7 +148,7 @@ - + @@ -197,7 +197,7 @@ - + @@ -250,7 +250,7 @@ - + diff --git a/tests/test_filter_mesh/inputs_true.dat b/tests/test_filter_mesh/inputs_true.dat index 75c6dcc416..32700c0988 100644 --- a/tests/test_filter_mesh/inputs_true.dat +++ b/tests/test_filter_mesh/inputs_true.dat @@ -148,7 +148,7 @@ - + @@ -197,7 +197,7 @@ - + @@ -249,7 +249,7 @@ - + diff --git a/tests/test_iso_in_lab/inputs_true.dat b/tests/test_iso_in_lab/inputs_true.dat index 682f8020f6..9eee57672e 100644 --- a/tests/test_iso_in_lab/inputs_true.dat +++ b/tests/test_iso_in_lab/inputs_true.dat @@ -148,7 +148,7 @@ - + @@ -197,7 +197,7 @@ - + @@ -249,7 +249,7 @@ - + diff --git a/tests/test_mg_basic/inputs_true.dat b/tests/test_mg_basic/inputs_true.dat index 7141e57dd4..9e722493ac 100644 --- a/tests/test_mg_basic/inputs_true.dat +++ b/tests/test_mg_basic/inputs_true.dat @@ -1,17 +1,17 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/tests/test_mg_legendre/inputs_true.dat b/tests/test_mg_legendre/inputs_true.dat index ca24a0dcf7..05614b279d 100644 --- a/tests/test_mg_legendre/inputs_true.dat +++ b/tests/test_mg_legendre/inputs_true.dat @@ -1,8 +1,8 @@ - - - + + + diff --git a/tests/test_mg_max_order/inputs_true.dat b/tests/test_mg_max_order/inputs_true.dat index a5feed722d..07725dd318 100644 --- a/tests/test_mg_max_order/inputs_true.dat +++ b/tests/test_mg_max_order/inputs_true.dat @@ -1,8 +1,8 @@ - - - + + + diff --git a/tests/test_mg_nuclide/inputs_true.dat b/tests/test_mg_nuclide/inputs_true.dat index b5cb31b59c..4225f7571a 100644 --- a/tests/test_mg_nuclide/inputs_true.dat +++ b/tests/test_mg_nuclide/inputs_true.dat @@ -1,17 +1,17 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/tests/test_mg_survival_biasing/inputs_true.dat b/tests/test_mg_survival_biasing/inputs_true.dat index be2e6b2d92..de6e04644e 100644 --- a/tests/test_mg_survival_biasing/inputs_true.dat +++ b/tests/test_mg_survival_biasing/inputs_true.dat @@ -1,17 +1,17 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/tests/test_mg_tallies/inputs_true.dat b/tests/test_mg_tallies/inputs_true.dat index 8120c8681e..e2d09ac365 100644 --- a/tests/test_mg_tallies/inputs_true.dat +++ b/tests/test_mg_tallies/inputs_true.dat @@ -1,17 +1,17 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/tests/test_mgxs_library_ce_to_mg/inputs_true.dat b/tests/test_mgxs_library_ce_to_mg/inputs_true.dat index e31ee4d049..0ca4e0873b 100644 --- a/tests/test_mgxs_library_ce_to_mg/inputs_true.dat +++ b/tests/test_mgxs_library_ce_to_mg/inputs_true.dat @@ -1,8 +1,8 @@ - - - + + + @@ -12,14 +12,14 @@ - + - + diff --git a/tests/test_mgxs_library_condense/inputs_true.dat b/tests/test_mgxs_library_condense/inputs_true.dat index 79c7ea0492..8059122b0d 100644 --- a/tests/test_mgxs_library_condense/inputs_true.dat +++ b/tests/test_mgxs_library_condense/inputs_true.dat @@ -1,8 +1,8 @@ - - - + + + @@ -12,14 +12,14 @@ - + - + diff --git a/tests/test_mgxs_library_distribcell/inputs_true.dat b/tests/test_mgxs_library_distribcell/inputs_true.dat index 79862b8bc1..20b70b8605 100644 --- a/tests/test_mgxs_library_distribcell/inputs_true.dat +++ b/tests/test_mgxs_library_distribcell/inputs_true.dat @@ -6,7 +6,7 @@ - + 1.26 1.26 17 17 diff --git a/tests/test_mgxs_library_hdf5/inputs_true.dat b/tests/test_mgxs_library_hdf5/inputs_true.dat index 79c7ea0492..8059122b0d 100644 --- a/tests/test_mgxs_library_hdf5/inputs_true.dat +++ b/tests/test_mgxs_library_hdf5/inputs_true.dat @@ -1,8 +1,8 @@ - - - + + + @@ -12,14 +12,14 @@ - + - + diff --git a/tests/test_mgxs_library_mesh/inputs_true.dat b/tests/test_mgxs_library_mesh/inputs_true.dat index b0db8a9c4f..33bab8d54e 100644 --- a/tests/test_mgxs_library_mesh/inputs_true.dat +++ b/tests/test_mgxs_library_mesh/inputs_true.dat @@ -148,7 +148,7 @@ - + @@ -197,7 +197,7 @@ - + @@ -249,7 +249,7 @@ - + diff --git a/tests/test_mgxs_library_no_nuclides/inputs_true.dat b/tests/test_mgxs_library_no_nuclides/inputs_true.dat index 79c7ea0492..8059122b0d 100644 --- a/tests/test_mgxs_library_no_nuclides/inputs_true.dat +++ b/tests/test_mgxs_library_no_nuclides/inputs_true.dat @@ -1,8 +1,8 @@ - - - + + + @@ -12,14 +12,14 @@ - + - + diff --git a/tests/test_mgxs_library_nuclides/inputs_true.dat b/tests/test_mgxs_library_nuclides/inputs_true.dat index 89541b4d5b..ec9ff4f1be 100644 --- a/tests/test_mgxs_library_nuclides/inputs_true.dat +++ b/tests/test_mgxs_library_nuclides/inputs_true.dat @@ -1,8 +1,8 @@ - - - + + + @@ -12,14 +12,14 @@ - + - + diff --git a/tests/test_tallies/inputs_true.dat b/tests/test_tallies/inputs_true.dat index 88ff72f9bb..3123aedaf1 100644 --- a/tests/test_tallies/inputs_true.dat +++ b/tests/test_tallies/inputs_true.dat @@ -148,7 +148,7 @@ - + @@ -197,7 +197,7 @@ - + @@ -249,7 +249,7 @@ - + diff --git a/tests/test_tally_aggregation/inputs_true.dat b/tests/test_tally_aggregation/inputs_true.dat index 041221cb66..a48d240ea5 100644 --- a/tests/test_tally_aggregation/inputs_true.dat +++ b/tests/test_tally_aggregation/inputs_true.dat @@ -148,7 +148,7 @@ - + @@ -197,7 +197,7 @@ - + @@ -249,7 +249,7 @@ - + diff --git a/tests/test_tally_arithmetic/inputs_true.dat b/tests/test_tally_arithmetic/inputs_true.dat index f98d4480df..9bacec1a16 100644 --- a/tests/test_tally_arithmetic/inputs_true.dat +++ b/tests/test_tally_arithmetic/inputs_true.dat @@ -148,7 +148,7 @@ - + @@ -197,7 +197,7 @@ - + @@ -249,7 +249,7 @@ - + diff --git a/tests/test_tally_slice_merge/inputs_true.dat b/tests/test_tally_slice_merge/inputs_true.dat index 93b4af5cd9..4decaa81cd 100644 --- a/tests/test_tally_slice_merge/inputs_true.dat +++ b/tests/test_tally_slice_merge/inputs_true.dat @@ -148,7 +148,7 @@ - + @@ -197,7 +197,7 @@ - + @@ -249,7 +249,7 @@ - + From c494ed69d700085aec3a2bf6565702cf845db333 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 10 Apr 2017 07:26:48 -0500 Subject: [PATCH 15/22] Show compile flags when cmake is run --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ddb55dcbed..d453890b21 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -213,6 +213,11 @@ elseif(CMAKE_Fortran_COMPILER_ID STREQUAL Cray) endif() +# Show flags being used +message(STATUS "Fortran flags: ${f90flags}") +message(STATUS "C flags: ${cflags}") +message(STATUS "Linker flags: ${ldflags}") + #=============================================================================== # git SHA1 hash #=============================================================================== From 2660c5918f00fcff758a7f2a504ca8fb665f1d03 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 10 Apr 2017 07:32:51 -0500 Subject: [PATCH 16/22] Turn on OpenMP by default --- CMakeLists.txt | 3 +-- docs/source/usersguide/install.rst | 2 +- tests/run_tests.py | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d453890b21..2dc30a21d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,14 +25,13 @@ endif() # Command line options #=============================================================================== -option(openmp "Enable shared-memory parallelism with OpenMP" OFF) +option(openmp "Enable shared-memory parallelism with OpenMP" ON) option(profile "Compile with profiling flags" OFF) option(debug "Compile with debug flags" OFF) option(optimize "Turn on all compiler optimization flags" OFF) option(coverage "Compile with coverage analysis flags" OFF) option(mpif08 "Use Fortran 2008 MPI interface" OFF) - # Maximum number of nested coordinates levels set(maxcoord 10 CACHE STRING "Maximum number of nested coordinate levels") add_definitions(-DMAX_COORD=${maxcoord}) diff --git a/docs/source/usersguide/install.rst b/docs/source/usersguide/install.rst index e980407084..a065c904a9 100644 --- a/docs/source/usersguide/install.rst +++ b/docs/source/usersguide/install.rst @@ -225,7 +225,7 @@ optimize openmp Enables shared-memory parallelism using the OpenMP API. The Fortran compiler - being used must support OpenMP. + being used must support OpenMP. (Default: on) coverage Compile and link code instrumented for coverage analysis. This is typically diff --git a/tests/run_tests.py b/tests/run_tests.py index f0ecd82916..2d9112e92e 100755 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -184,8 +184,8 @@ class Test(object): build_str += "-Ddebug=ON " if self.optimize: build_str += "-Doptimize=ON " - if self.openmp: - build_str += "-Dopenmp=ON " + if not self.openmp: + build_str += "-Dopenmp=OFF " if self.coverage: build_str += "-Dcoverage=ON " self.build_opts = build_str From 364543b96771b36926ac978b1d632ff6056836e9 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Mon, 10 Apr 2017 10:06:32 -0400 Subject: [PATCH 17/22] Now use memoization for geometry and materials cloning --- openmc/cell.py | 28 ++++++++++++++++++--------- openmc/geometry.py | 2 +- openmc/lattice.py | 48 +++++++++++++++++++++++++++------------------- openmc/material.py | 19 +++++++++++++----- openmc/region.py | 28 ++++++++++++++++++--------- openmc/surface.py | 26 ++++++++++++++++++------- openmc/universe.py | 23 +++++++++++++--------- 7 files changed, 114 insertions(+), 60 deletions(-) diff --git a/openmc/cell.py b/openmc/cell.py index 522f9ab5d3..46da0c45d9 100644 --- a/openmc/cell.py +++ b/openmc/cell.py @@ -1,4 +1,4 @@ -from collections import OrderedDict, Iterable +from collections import OrderedDict, Iterable, defaultdict from copy import deepcopy from math import cos, sin, pi from numbers import Real, Integral @@ -505,19 +505,29 @@ class Cell(object): return universes - def clone(self): + def clone(self, memoize=None): """Create a copy of this cell with a new unique ID, and clones the cell's region and fill.""" - clone = deepcopy(self) - clone.id = None + if memoize is None: + memoize = defaultdict(dict) - if self.region is not None: - clone.region = self.region.clone() - if self.fill is not None: - clone.fill = self.fill.clone() + # If no nemoize'd clone exists, instantiate one + if self.id not in memoize['cells']: + clone = deepcopy(self) + clone.id = None + if self.region is not None: + clone.region = self.region.clone(memoize) + if self.fill is not None: + if self.fill_type == 'distribmat': + clone.fill = [fill.clone(memoize) for fill in self.fill] + else: + clone.fill = self.fill.clone(memoize) - return clone + # Memoize the clone + memoize['cells'][self.id] = clone + + return memoize['cells'][self.id] def create_xml_subelement(self, xml_element): element = ET.Element("cell") diff --git a/openmc/geometry.py b/openmc/geometry.py index 424a7053e5..27fee65739 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -504,5 +504,5 @@ class Geometry(object): enclosed materials, surfaces, cells, universes and lattices.""" clone = deepcopy(self) - clone.root_universe = deepcopy(self.root_universe) + clone.root_universe = self.root_universe.clone() return clone diff --git a/openmc/lattice.py b/openmc/lattice.py index b98ef00877..d92753ae3c 100644 --- a/openmc/lattice.py +++ b/openmc/lattice.py @@ -1,7 +1,7 @@ from __future__ import division from abc import ABCMeta -from collections import OrderedDict, Iterable +from collections import OrderedDict, Iterable, defaultdict from copy import deepcopy from math import sqrt, floor from numbers import Real, Integral @@ -415,32 +415,40 @@ class Lattice(object): return [] return [(self, idx)] + u.find(p) - def clone(self): + def clone(self, memoize=None): """Create a copy of this lattice with a new unique ID, and clones all universes within this lattice.""" - clone = deepcopy(self) - clone.id = None + if memoize is None: + memoize = defaultdict(dict) - # Clone all unique universes in the lattice - univ_clones = self.get_unique_universes() - for univ_id in univ_clones: - univ_clones[univ_id] = univ_clones[univ_id].clone() + # If no nemoize'd clone exists, instantiate one + if self.id not in memoize['lattices']: + clone = deepcopy(self) + clone.id = None - # Assign universe clones to the lattice clone - for i in self.indices: - if isinstance(self, RectLattice): - univ_id = self.universes[i].id - clone.universes[i] = univ_clones[univ_id] - else: - if self.ndim == 2: - univ_id = self.universes[i[0]][i[1]].id - clone.universes[i[0]][i[1]] = univ_clones[univ_id] + # Clone all unique universes in the lattice + univ_clones = self.get_unique_universes() + for univ_id in univ_clones: + univ_clones[univ_id] = univ_clones[univ_id].clone(memoize) + + # Assign universe clones to the lattice clone + for i in self.indices: + if isinstance(self, RectLattice): + univ_id = self.universes[i].id + clone.universes[i] = univ_clones[univ_id] else: - univ_id = self.universes[i[0]][i[1]][i[2]].id - clone.universes[i[0]][i[1]][i[2]] = univ_clones[univ_id] + if self.ndim == 2: + univ_id = self.universes[i[0]][i[1]].id + clone.universes[i[0]][i[1]] = univ_clones[univ_id] + else: + univ_id = self.universes[i[0]][i[1]][i[2]].id + clone.universes[i[0]][i[1]][i[2]] = univ_clones[univ_id] - return clone + # Memoize the clone + memoize['lattices'][self.id] = clone + + return memoize['lattices'][self.id] class RectLattice(Lattice): diff --git a/openmc/material.py b/openmc/material.py index be13d619fe..06ba41ddf1 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -1,4 +1,4 @@ -from collections import OrderedDict +from collections import OrderedDict, defaultdict from copy import deepcopy from numbers import Real, Integral import warnings @@ -799,12 +799,21 @@ class Material(object): return nuclides - def clone(self): + def clone(self, memoize=None): """Create a copy of this material with a new unique ID.""" - clone = deepcopy(self) - clone.id = None - return clone + if memoize is None: + memoize = defaultdict(dict) + + # If no nemoize'd clone exists, instantiate one + if self.id not in memoize['materials']: + clone = deepcopy(self) + clone.id = None + + # Memoize the clone + memoize['materials'][self.id] = clone + + return memoize['materials'][self.id] def _get_nuclide_xml(self, nuclide, distrib=False): xml_element = ET.Element("nuclide") diff --git a/openmc/region.py b/openmc/region.py index b93d305fea..8c9c4e59d2 100644 --- a/openmc/region.py +++ b/openmc/region.py @@ -1,5 +1,5 @@ from abc import ABCMeta, abstractmethod -from collections import Iterable, OrderedDict +from collections import Iterable, OrderedDict, defaultdict from copy import deepcopy from six import add_metaclass @@ -223,10 +223,11 @@ class Region(object): return output[0] @abstractmethod - def clone(self): + def clone(self, memoize=None): """Create a copy of this region - each of the surfaces in the region's nodes will be cloned and will have new unique IDs.""" - return False + raise NotImplementedError('The clone method is not implemented for ' + 'the abstract region class.') class Intersection(Region): @@ -307,12 +308,15 @@ class Intersection(Region): check_type('nodes', nodes, Iterable, Region) self._nodes = nodes - def clone(self): + def clone(self, memoize=None): """Create a copy of this region - each of the surfaces in the intersection's nodes will be cloned and will have new unique IDs.""" + if memoize is None: + memoize = defaultdict(dict) + clone = deepcopy(self) - clone.nodes = [n.clone() for n in self.nodes] + clone.nodes = [n.clone(memoize) for n in self.nodes] return clone @@ -392,12 +396,15 @@ class Union(Region): check_type('nodes', nodes, Iterable, Region) self._nodes = nodes - def clone(self): + def clone(self, memoize=None): """Create a copy of this region - each of the surfaces in the union's nodes will be cloned and will have new unique IDs.""" + if memoize is None: + memoize = defaultdict(dict) + clone = copy.deepcopy(self) - clone.nodes = [n.clone() for n in self.nodes] + clone.nodes = [n.clone(memoize) for n in self.nodes] return clone @@ -497,10 +504,13 @@ class Complement(Region): surfaces = region.get_surfaces(surfaces) return surfaces - def clone(self): + def clone(self, memoize=None): """Create a copy of this region - each of the surfaces in the complement's node will be cloned and will have new unique IDs.""" + if memoize is None: + memoize = defaultdict(dict) + clone = copy.deepcopy(self) - clone.node = self.node.clone() + clone.node = self.node.clone(memoize) return clone diff --git a/openmc/surface.py b/openmc/surface.py index 866a9e2b98..14c1692d0e 100644 --- a/openmc/surface.py +++ b/openmc/surface.py @@ -1,5 +1,5 @@ from abc import ABCMeta -from collections import Iterable, OrderedDict +from collections import Iterable, OrderedDict, defaultdict from copy import deepcopy from numbers import Real, Integral from xml.etree import ElementTree as ET @@ -172,12 +172,21 @@ class Surface(object): return (np.array([-np.inf, -np.inf, -np.inf]), np.array([np.inf, np.inf, np.inf])) - def clone(self): + def clone(self, memoize=None): """Create a copy of this surface with a new unique ID.""" - clone = deepcopy(self) - clone.id = None - return clone + if memoize is None: + memoize = defaultdict(dict) + + # If no nemoize'd clone exists, instantiate one + if self.id not in memoize['surfaces']: + clone = deepcopy(self) + clone.id = None + + # Memoize the clone + memoize['surfaces'][self.id] = clone + + return memoize['surfaces'][self.id] def to_xml_element(self): """Return XML representation of the surface @@ -1910,12 +1919,15 @@ class Halfspace(Region): surfaces[self.surface.id] = self.surface return surfaces - def clone(self): + def clone(self, memoize=None): """Create a copy of this halfspace, with a cloned surface with a unique ID.""" + if memoize is None: + memoize = defaultdict(dict) + clone = deepcopy(self) - clone.surface = self.surface.clone() + clone.surface = self.surface.clone(memoize) return clone diff --git a/openmc/universe.py b/openmc/universe.py index a2157f1d78..5f272c6e56 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -1,5 +1,5 @@ from __future__ import division -from collections import OrderedDict, Iterable +from collections import OrderedDict, Iterable, defaultdict from copy import copy, deepcopy from numbers import Integral, Real import random @@ -517,19 +517,24 @@ class Universe(object): return universes - def clone(self): + def clone(self, memoize=None): """Create a copy of this universe with a new unique ID, and clones all cells within this universe.""" - clone = deepcopy(self) - clone.id = None + if memoize is None: + memoize = defaultdict(dict) - # Clone all cells for the universe clone - clone._cells = OrderedDict() - for cell in self._cells.values(): - clone.add_cell(cell.clone()) + # If no nemoize'd clone exists, instantiate one + if self.id not in memoize['universes']: + memoize['universes'][self.id] = deepcopy(self) + memoize['universes'][self.id].id = None - return clone + # Clone all cells for the universe clone + memoize['universes'][self.id]._cells = OrderedDict() + for cell in self._cells.values(): + memoize['universes'][self.id].add_cell(cell.clone(memoize)) + + return memoize['universes'][self.id] def create_xml_subelement(self, xml_element): # Iterate over all Cells From 12a0e00305c881c9bbaa1626a725372e14e2e96c Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Mon, 10 Apr 2017 10:13:59 -0400 Subject: [PATCH 18/22] Expanded docstrings for all clone methods --- openmc/cell.py | 15 ++++++++++- openmc/lattice.py | 15 ++++++++++- openmc/material.py | 15 ++++++++++- openmc/region.py | 65 +++++++++++++++++++++++++++++++++++++++++++--- openmc/surface.py | 30 +++++++++++++++++++-- openmc/universe.py | 15 ++++++++++- 6 files changed, 145 insertions(+), 10 deletions(-) diff --git a/openmc/cell.py b/openmc/cell.py index 46da0c45d9..61690e98c3 100644 --- a/openmc/cell.py +++ b/openmc/cell.py @@ -507,7 +507,20 @@ class Cell(object): def clone(self, memoize=None): """Create a copy of this cell with a new unique ID, and clones - the cell's region and fill.""" + the cell's region and fill. + + Parameters + ---------- + memoize : defaultdict(dict) or None + A nested dictionary of previously cloned objects. This parameter + is used internally and should not be specified by the user. + + Returns + ------- + clone : openmc.Cell + The clone of this cell + + """ if memoize is None: memoize = defaultdict(dict) diff --git a/openmc/lattice.py b/openmc/lattice.py index d92753ae3c..26eadbe7ff 100644 --- a/openmc/lattice.py +++ b/openmc/lattice.py @@ -417,7 +417,20 @@ class Lattice(object): def clone(self, memoize=None): """Create a copy of this lattice with a new unique ID, and clones - all universes within this lattice.""" + all universes within this lattice. + + Parameters + ---------- + memoize : defaultdict(dict) or None + A nested dictionary of previously cloned objects. This parameter + is used internally and should not be specified by the user. + + Returns + ------- + clone : openmc.Lattice + The clone of this lattice + + """ if memoize is None: memoize = defaultdict(dict) diff --git a/openmc/material.py b/openmc/material.py index 06ba41ddf1..75c31f37c8 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -800,7 +800,20 @@ class Material(object): return nuclides def clone(self, memoize=None): - """Create a copy of this material with a new unique ID.""" + """Create a copy of this material with a new unique ID. + + Parameters + ---------- + memoize : defaultdict(dict) or None + A nested dictionary of previously cloned objects. This parameter + is used internally and should not be specified by the user. + + Returns + ------- + clone : openmc.Material + The clone of this material + + """ if memoize is None: memoize = defaultdict(dict) diff --git a/openmc/region.py b/openmc/region.py index 8c9c4e59d2..37078eda85 100644 --- a/openmc/region.py +++ b/openmc/region.py @@ -225,7 +225,25 @@ class Region(object): @abstractmethod def clone(self, memoize=None): """Create a copy of this region - each of the surfaces in the - region's nodes will be cloned and will have new unique IDs.""" + region's nodes will be cloned and will have new unique IDs. + + Parameters + ---------- + memoize : defaultdict(dict) or None + A nested dictionary of previously cloned objects. This parameter + is used internally and should not be specified by the user. + + Returns + ------- + clone : openmc.Region + The clone of this region + + Raises + ------ + NotImplementedError + This method is not implemented for the abstract region class. + + """ raise NotImplementedError('The clone method is not implemented for ' 'the abstract region class.') @@ -310,7 +328,20 @@ class Intersection(Region): def clone(self, memoize=None): """Create a copy of this region - each of the surfaces in the - intersection's nodes will be cloned and will have new unique IDs.""" + intersection's nodes will be cloned and will have new unique IDs. + + Parameters + ---------- + memoize : defaultdict(dict) or None + A nested dictionary of previously cloned objects. This parameter + is used internally and should not be specified by the user. + + Returns + ------- + clone : openmc.Intersection + The clone of this intersection + + """ if memoize is None: memoize = defaultdict(dict) @@ -398,7 +429,20 @@ class Union(Region): def clone(self, memoize=None): """Create a copy of this region - each of the surfaces in the - union's nodes will be cloned and will have new unique IDs.""" + union's nodes will be cloned and will have new unique IDs. + + Parameters + ---------- + memoize : defaultdict(dict) or None + A nested dictionary of previously cloned objects. This parameter + is used internally and should not be specified by the user. + + Returns + ------- + clone : openmc.Union + The clone of this union + + """ if memoize is None: memoize = defaultdict(dict) @@ -506,7 +550,20 @@ class Complement(Region): def clone(self, memoize=None): """Create a copy of this region - each of the surfaces in the - complement's node will be cloned and will have new unique IDs.""" + complement's node will be cloned and will have new unique IDs. + + Parameters + ---------- + memoize : defaultdict(dict) or None + A nested dictionary of previously cloned objects. This parameter + is used internally and should not be specified by the user. + + Returns + ------- + clone : openmc.Complement + The clone of this complement + + """ if memoize is None: memoize = defaultdict(dict) diff --git a/openmc/surface.py b/openmc/surface.py index 14c1692d0e..1eb69d2db6 100644 --- a/openmc/surface.py +++ b/openmc/surface.py @@ -173,7 +173,20 @@ class Surface(object): np.array([np.inf, np.inf, np.inf])) def clone(self, memoize=None): - """Create a copy of this surface with a new unique ID.""" + """Create a copy of this surface with a new unique ID. + + Parameters + ---------- + memoize : defaultdict(dict) or None + A nested dictionary of previously cloned objects. This parameter + is used internally and should not be specified by the user. + + Returns + ------- + clone : openmc.Surface + The clone of this surface + + """ if memoize is None: memoize = defaultdict(dict) @@ -1921,7 +1934,20 @@ class Halfspace(Region): def clone(self, memoize=None): """Create a copy of this halfspace, with a cloned surface with a - unique ID.""" + unique ID. + + Parameters + ---------- + memoize : defaultdict(dict) or None + A nested dictionary of previously cloned objects. This parameter + is used internally and should not be specified by the user. + + Returns + ------- + clone : openmc.Halfspace + The clone of this halfspace + + """ if memoize is None: memoize = defaultdict(dict) diff --git a/openmc/universe.py b/openmc/universe.py index 5f272c6e56..9453dfb11a 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -519,7 +519,20 @@ class Universe(object): def clone(self, memoize=None): """Create a copy of this universe with a new unique ID, and clones - all cells within this universe.""" + all cells within this universe. + + Parameters + ---------- + memoize : defaultdict(dict) or None + A nested dictionary of previously cloned objects. This parameter + is used internally and should not be specified by the user. + + Returns + ------- + clone : openmc.Universe + The clone of this universe + + """ if memoize is None: memoize = defaultdict(dict) From 120dca77035e5c6989e6f4bffe19c9e67bee743f Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Mon, 10 Apr 2017 12:10:34 -0400 Subject: [PATCH 19/22] Renamed clone memoize param as memo per request by @paulromano --- openmc/cell.py | 21 +++++++++++---------- openmc/lattice.py | 19 +++++++++++-------- openmc/material.py | 14 +++++++------- openmc/region.py | 34 +++++++++++++++++----------------- openmc/surface.py | 24 ++++++++++++------------ openmc/universe.py | 23 +++++++++++++---------- 6 files changed, 71 insertions(+), 64 deletions(-) diff --git a/openmc/cell.py b/openmc/cell.py index 61690e98c3..b0847fc047 100644 --- a/openmc/cell.py +++ b/openmc/cell.py @@ -505,13 +505,13 @@ class Cell(object): return universes - def clone(self, memoize=None): + def clone(self, memo=None): """Create a copy of this cell with a new unique ID, and clones the cell's region and fill. Parameters ---------- - memoize : defaultdict(dict) or None + memo : defaultdict(dict) or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -522,25 +522,26 @@ class Cell(object): """ - if memoize is None: - memoize = defaultdict(dict) + if memo is None: + memo = defaultdict(dict) # If no nemoize'd clone exists, instantiate one - if self.id not in memoize['cells']: + if self.id not in memo['cells']: clone = deepcopy(self) clone.id = None if self.region is not None: - clone.region = self.region.clone(memoize) + clone.region = self.region.clone(memo) if self.fill is not None: if self.fill_type == 'distribmat': - clone.fill = [fill.clone(memoize) for fill in self.fill] + clone.fill = [fill.clone(memo) if fill is not None else None + for fill in self.fill] else: - clone.fill = self.fill.clone(memoize) + clone.fill = self.fill.clone(memo) # Memoize the clone - memoize['cells'][self.id] = clone + memo['cells'][self.id] = clone - return memoize['cells'][self.id] + return memo['cells'][self.id] def create_xml_subelement(self, xml_element): element = ET.Element("cell") diff --git a/openmc/lattice.py b/openmc/lattice.py index 26eadbe7ff..f9fa63331a 100644 --- a/openmc/lattice.py +++ b/openmc/lattice.py @@ -415,13 +415,13 @@ class Lattice(object): return [] return [(self, idx)] + u.find(p) - def clone(self, memoize=None): + def clone(self, memo=None): """Create a copy of this lattice with a new unique ID, and clones all universes within this lattice. Parameters ---------- - memoize : defaultdict(dict) or None + memo : defaultdict(dict) or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -432,18 +432,21 @@ class Lattice(object): """ - if memoize is None: - memoize = defaultdict(dict) + if memo is None: + memo = defaultdict(dict) # If no nemoize'd clone exists, instantiate one - if self.id not in memoize['lattices']: + if self.id not in memo['lattices']: clone = deepcopy(self) clone.id = None + if self.outer is not None: + clone.outer = self.outer.clone() + # Clone all unique universes in the lattice univ_clones = self.get_unique_universes() for univ_id in univ_clones: - univ_clones[univ_id] = univ_clones[univ_id].clone(memoize) + univ_clones[univ_id] = univ_clones[univ_id].clone(memo) # Assign universe clones to the lattice clone for i in self.indices: @@ -459,9 +462,9 @@ class Lattice(object): clone.universes[i[0]][i[1]][i[2]] = univ_clones[univ_id] # Memoize the clone - memoize['lattices'][self.id] = clone + memo['lattices'][self.id] = clone - return memoize['lattices'][self.id] + return memo['lattices'][self.id] class RectLattice(Lattice): diff --git a/openmc/material.py b/openmc/material.py index 75c31f37c8..cdb82da03d 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -799,12 +799,12 @@ class Material(object): return nuclides - def clone(self, memoize=None): + def clone(self, memo=None): """Create a copy of this material with a new unique ID. Parameters ---------- - memoize : defaultdict(dict) or None + memo : defaultdict(dict) or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -815,18 +815,18 @@ class Material(object): """ - if memoize is None: - memoize = defaultdict(dict) + if memo is None: + memo = defaultdict(dict) # If no nemoize'd clone exists, instantiate one - if self.id not in memoize['materials']: + if self.id not in memo['materials']: clone = deepcopy(self) clone.id = None # Memoize the clone - memoize['materials'][self.id] = clone + memo['materials'][self.id] = clone - return memoize['materials'][self.id] + return memo['materials'][self.id] def _get_nuclide_xml(self, nuclide, distrib=False): xml_element = ET.Element("nuclide") diff --git a/openmc/region.py b/openmc/region.py index 37078eda85..0b1f970840 100644 --- a/openmc/region.py +++ b/openmc/region.py @@ -223,13 +223,13 @@ class Region(object): return output[0] @abstractmethod - def clone(self, memoize=None): + def clone(self, memo=None): """Create a copy of this region - each of the surfaces in the region's nodes will be cloned and will have new unique IDs. Parameters ---------- - memoize : defaultdict(dict) or None + memo : defaultdict(dict) or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -326,13 +326,13 @@ class Intersection(Region): check_type('nodes', nodes, Iterable, Region) self._nodes = nodes - def clone(self, memoize=None): + def clone(self, memo=None): """Create a copy of this region - each of the surfaces in the intersection's nodes will be cloned and will have new unique IDs. Parameters ---------- - memoize : defaultdict(dict) or None + memo : defaultdict(dict) or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -343,11 +343,11 @@ class Intersection(Region): """ - if memoize is None: - memoize = defaultdict(dict) + if memo is None: + memo = defaultdict(dict) clone = deepcopy(self) - clone.nodes = [n.clone(memoize) for n in self.nodes] + clone.nodes = [n.clone(memo) for n in self.nodes] return clone @@ -427,13 +427,13 @@ class Union(Region): check_type('nodes', nodes, Iterable, Region) self._nodes = nodes - def clone(self, memoize=None): + def clone(self, memo=None): """Create a copy of this region - each of the surfaces in the union's nodes will be cloned and will have new unique IDs. Parameters ---------- - memoize : defaultdict(dict) or None + memo : defaultdict(dict) or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -444,11 +444,11 @@ class Union(Region): """ - if memoize is None: - memoize = defaultdict(dict) + if memo is None: + memo = defaultdict(dict) clone = copy.deepcopy(self) - clone.nodes = [n.clone(memoize) for n in self.nodes] + clone.nodes = [n.clone(memo) for n in self.nodes] return clone @@ -548,13 +548,13 @@ class Complement(Region): surfaces = region.get_surfaces(surfaces) return surfaces - def clone(self, memoize=None): + def clone(self, memo=None): """Create a copy of this region - each of the surfaces in the complement's node will be cloned and will have new unique IDs. Parameters ---------- - memoize : defaultdict(dict) or None + memo : defaultdict(dict) or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -565,9 +565,9 @@ class Complement(Region): """ - if memoize is None: - memoize = defaultdict(dict) + if memo is None: + memo = defaultdict(dict) clone = copy.deepcopy(self) - clone.node = self.node.clone(memoize) + clone.node = self.node.clone(memo) return clone diff --git a/openmc/surface.py b/openmc/surface.py index 1eb69d2db6..1edae2cae7 100644 --- a/openmc/surface.py +++ b/openmc/surface.py @@ -172,12 +172,12 @@ class Surface(object): return (np.array([-np.inf, -np.inf, -np.inf]), np.array([np.inf, np.inf, np.inf])) - def clone(self, memoize=None): + def clone(self, memo=None): """Create a copy of this surface with a new unique ID. Parameters ---------- - memoize : defaultdict(dict) or None + memo : defaultdict(dict) or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -188,18 +188,18 @@ class Surface(object): """ - if memoize is None: - memoize = defaultdict(dict) + if memo is None: + memo = defaultdict(dict) # If no nemoize'd clone exists, instantiate one - if self.id not in memoize['surfaces']: + if self.id not in memo['surfaces']: clone = deepcopy(self) clone.id = None # Memoize the clone - memoize['surfaces'][self.id] = clone + memo['surfaces'][self.id] = clone - return memoize['surfaces'][self.id] + return memo['surfaces'][self.id] def to_xml_element(self): """Return XML representation of the surface @@ -1932,13 +1932,13 @@ class Halfspace(Region): surfaces[self.surface.id] = self.surface return surfaces - def clone(self, memoize=None): + def clone(self, memo=None): """Create a copy of this halfspace, with a cloned surface with a unique ID. Parameters ---------- - memoize : defaultdict(dict) or None + memo : defaultdict(dict) or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -1949,11 +1949,11 @@ class Halfspace(Region): """ - if memoize is None: - memoize = defaultdict(dict) + if memo is None: + memo = defaultdict(dict) clone = deepcopy(self) - clone.surface = self.surface.clone(memoize) + clone.surface = self.surface.clone(memo) return clone diff --git a/openmc/universe.py b/openmc/universe.py index 9453dfb11a..1fefa2372c 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -517,13 +517,13 @@ class Universe(object): return universes - def clone(self, memoize=None): + def clone(self, memo=None): """Create a copy of this universe with a new unique ID, and clones all cells within this universe. Parameters ---------- - memoize : defaultdict(dict) or None + memo : defaultdict(dict) or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -534,20 +534,23 @@ class Universe(object): """ - if memoize is None: - memoize = defaultdict(dict) + if memo is None: + memo = defaultdict(dict) # If no nemoize'd clone exists, instantiate one - if self.id not in memoize['universes']: - memoize['universes'][self.id] = deepcopy(self) - memoize['universes'][self.id].id = None + if self.id not in memo['universes']: + clone = deepcopy(self) + clone.id = None # Clone all cells for the universe clone - memoize['universes'][self.id]._cells = OrderedDict() + clone._cells = OrderedDict() for cell in self._cells.values(): - memoize['universes'][self.id].add_cell(cell.clone(memoize)) + clone.add_cell(cell.clone(memo)) - return memoize['universes'][self.id] + # Memoize the clone + memo['universes'][self.id] = clone + + return memo['universes'][self.id] def create_xml_subelement(self, xml_element): # Iterate over all Cells From 400b5e2c1df2a00f6d5da39353466bb16316dae0 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Mon, 10 Apr 2017 17:17:17 -0400 Subject: [PATCH 20/22] Added __hash__ method to Surface class; revised clone methods memo param to use objects as keys --- openmc/cell.py | 12 ++++++------ openmc/lattice.py | 14 +++++++------- openmc/material.py | 12 ++++++------ openmc/region.py | 16 ++++++++-------- openmc/surface.py | 19 +++++++++++-------- openmc/universe.py | 12 ++++++------ 6 files changed, 44 insertions(+), 41 deletions(-) diff --git a/openmc/cell.py b/openmc/cell.py index b0847fc047..4496062f7f 100644 --- a/openmc/cell.py +++ b/openmc/cell.py @@ -1,4 +1,4 @@ -from collections import OrderedDict, Iterable, defaultdict +from collections import OrderedDict, Iterable from copy import deepcopy from math import cos, sin, pi from numbers import Real, Integral @@ -511,7 +511,7 @@ class Cell(object): Parameters ---------- - memo : defaultdict(dict) or None + memo : dict or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -523,10 +523,10 @@ class Cell(object): """ if memo is None: - memo = defaultdict(dict) + memo = {} # If no nemoize'd clone exists, instantiate one - if self.id not in memo['cells']: + if self not in memo: clone = deepcopy(self) clone.id = None if self.region is not None: @@ -539,9 +539,9 @@ class Cell(object): clone.fill = self.fill.clone(memo) # Memoize the clone - memo['cells'][self.id] = clone + memo[self] = clone - return memo['cells'][self.id] + return memo[self] def create_xml_subelement(self, xml_element): element = ET.Element("cell") diff --git a/openmc/lattice.py b/openmc/lattice.py index f9fa63331a..0fbd74f28e 100644 --- a/openmc/lattice.py +++ b/openmc/lattice.py @@ -1,7 +1,7 @@ from __future__ import division from abc import ABCMeta -from collections import OrderedDict, Iterable, defaultdict +from collections import OrderedDict, Iterable from copy import deepcopy from math import sqrt, floor from numbers import Real, Integral @@ -421,7 +421,7 @@ class Lattice(object): Parameters ---------- - memo : defaultdict(dict) or None + memo : dict or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -433,15 +433,15 @@ class Lattice(object): """ if memo is None: - memo = defaultdict(dict) + memo = {} # If no nemoize'd clone exists, instantiate one - if self.id not in memo['lattices']: + if self not in memo: clone = deepcopy(self) clone.id = None if self.outer is not None: - clone.outer = self.outer.clone() + clone.outer = self.outer.clone(memo) # Clone all unique universes in the lattice univ_clones = self.get_unique_universes() @@ -462,9 +462,9 @@ class Lattice(object): clone.universes[i[0]][i[1]][i[2]] = univ_clones[univ_id] # Memoize the clone - memo['lattices'][self.id] = clone + memo[self] = clone - return memo['lattices'][self.id] + return memo[self] class RectLattice(Lattice): diff --git a/openmc/material.py b/openmc/material.py index cdb82da03d..762337659a 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -1,4 +1,4 @@ -from collections import OrderedDict, defaultdict +from collections import OrderedDict from copy import deepcopy from numbers import Real, Integral import warnings @@ -804,7 +804,7 @@ class Material(object): Parameters ---------- - memo : defaultdict(dict) or None + memo : dict or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -816,17 +816,17 @@ class Material(object): """ if memo is None: - memo = defaultdict(dict) + memo = dict # If no nemoize'd clone exists, instantiate one - if self.id not in memo['materials']: + if self not in memo: clone = deepcopy(self) clone.id = None # Memoize the clone - memo['materials'][self.id] = clone + memo[self] = clone - return memo['materials'][self.id] + return memo[self] def _get_nuclide_xml(self, nuclide, distrib=False): xml_element = ET.Element("nuclide") diff --git a/openmc/region.py b/openmc/region.py index 0b1f970840..854852ba41 100644 --- a/openmc/region.py +++ b/openmc/region.py @@ -1,5 +1,5 @@ from abc import ABCMeta, abstractmethod -from collections import Iterable, OrderedDict, defaultdict +from collections import Iterable, OrderedDict from copy import deepcopy from six import add_metaclass @@ -229,7 +229,7 @@ class Region(object): Parameters ---------- - memo : defaultdict(dict) or None + memo : dict or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -332,7 +332,7 @@ class Intersection(Region): Parameters ---------- - memo : defaultdict(dict) or None + memo : dict or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -344,7 +344,7 @@ class Intersection(Region): """ if memo is None: - memo = defaultdict(dict) + memo = {} clone = deepcopy(self) clone.nodes = [n.clone(memo) for n in self.nodes] @@ -433,7 +433,7 @@ class Union(Region): Parameters ---------- - memo : defaultdict(dict) or None + memo : dict or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -445,7 +445,7 @@ class Union(Region): """ if memo is None: - memo = defaultdict(dict) + memo = {} clone = copy.deepcopy(self) clone.nodes = [n.clone(memo) for n in self.nodes] @@ -554,7 +554,7 @@ class Complement(Region): Parameters ---------- - memo : defaultdict(dict) or None + memo : dict or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -566,7 +566,7 @@ class Complement(Region): """ if memo is None: - memo = defaultdict(dict) + memo = {} clone = copy.deepcopy(self) clone.node = self.node.clone(memo) diff --git a/openmc/surface.py b/openmc/surface.py index 1edae2cae7..5db15138d4 100644 --- a/openmc/surface.py +++ b/openmc/surface.py @@ -1,5 +1,5 @@ from abc import ABCMeta -from collections import Iterable, OrderedDict, defaultdict +from collections import Iterable, OrderedDict from copy import deepcopy from numbers import Real, Integral from xml.etree import ElementTree as ET @@ -83,6 +83,9 @@ class Surface(object): def __pos__(self): return Halfspace(self, '+') + def __hash__(self): + return hash(repr(self)) + def __repr__(self): string = 'Surface\n' string += '{0: <16}{1}{2}\n'.format('\tID', '=\t', self._id) @@ -177,7 +180,7 @@ class Surface(object): Parameters ---------- - memo : defaultdict(dict) or None + memo : dict or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -189,17 +192,17 @@ class Surface(object): """ if memo is None: - memo = defaultdict(dict) + memo = {} # If no nemoize'd clone exists, instantiate one - if self.id not in memo['surfaces']: + if self not in memo: clone = deepcopy(self) clone.id = None # Memoize the clone - memo['surfaces'][self.id] = clone + memo[self] = clone - return memo['surfaces'][self.id] + return memo[self] def to_xml_element(self): """Return XML representation of the surface @@ -1938,7 +1941,7 @@ class Halfspace(Region): Parameters ---------- - memo : defaultdict(dict) or None + memo : dict or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -1950,7 +1953,7 @@ class Halfspace(Region): """ if memo is None: - memo = defaultdict(dict) + memo = dict clone = deepcopy(self) clone.surface = self.surface.clone(memo) diff --git a/openmc/universe.py b/openmc/universe.py index 1fefa2372c..c955934f2a 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -1,5 +1,5 @@ from __future__ import division -from collections import OrderedDict, Iterable, defaultdict +from collections import OrderedDict, Iterable from copy import copy, deepcopy from numbers import Integral, Real import random @@ -523,7 +523,7 @@ class Universe(object): Parameters ---------- - memo : defaultdict(dict) or None + memo : dict or None A nested dictionary of previously cloned objects. This parameter is used internally and should not be specified by the user. @@ -535,10 +535,10 @@ class Universe(object): """ if memo is None: - memo = defaultdict(dict) + memo = {} # If no nemoize'd clone exists, instantiate one - if self.id not in memo['universes']: + if self not in memo: clone = deepcopy(self) clone.id = None @@ -548,9 +548,9 @@ class Universe(object): clone.add_cell(cell.clone(memo)) # Memoize the clone - memo['universes'][self.id] = clone + memo[self] = clone - return memo['universes'][self.id] + return memo[self] def create_xml_subelement(self, xml_element): # Iterate over all Cells From d0f871e7db07ed83494bdc466aa1c999175cc1c1 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Tue, 11 Apr 2017 07:36:00 -0400 Subject: [PATCH 21/22] Simplified universe cloning in lattice clone method --- openmc/lattice.py | 16 +++++----------- openmc/material.py | 2 +- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/openmc/lattice.py b/openmc/lattice.py index 0fbd74f28e..b78b8b9e46 100644 --- a/openmc/lattice.py +++ b/openmc/lattice.py @@ -443,23 +443,17 @@ class Lattice(object): if self.outer is not None: clone.outer = self.outer.clone(memo) - # Clone all unique universes in the lattice - univ_clones = self.get_unique_universes() - for univ_id in univ_clones: - univ_clones[univ_id] = univ_clones[univ_id].clone(memo) - # Assign universe clones to the lattice clone for i in self.indices: if isinstance(self, RectLattice): - univ_id = self.universes[i].id - clone.universes[i] = univ_clones[univ_id] + clone.universes[i] = self.universes[i].clone() else: if self.ndim == 2: - univ_id = self.universes[i[0]][i[1]].id - clone.universes[i[0]][i[1]] = univ_clones[univ_id] + clone.universes[i[0]][i[1]] = \ + self.universes[i[0]][i[1]].clone() else: - univ_id = self.universes[i[0]][i[1]][i[2]].id - clone.universes[i[0]][i[1]][i[2]] = univ_clones[univ_id] + clone.universes[i[0]][i[1]][i[2]] = \ + self.universes[i[0]][i[1]][i[2]].clone() # Memoize the clone memo[self] = clone diff --git a/openmc/material.py b/openmc/material.py index 762337659a..87cc6befaa 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -816,7 +816,7 @@ class Material(object): """ if memo is None: - memo = dict + memo = {} # If no nemoize'd clone exists, instantiate one if self not in memo: From 398635c84a5ed87c9b480989110df05ae12038ec Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Tue, 11 Apr 2017 07:36:49 -0400 Subject: [PATCH 22/22] Added memo param to universe cloning in lattice clone method --- openmc/lattice.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openmc/lattice.py b/openmc/lattice.py index b78b8b9e46..3bb6e825e1 100644 --- a/openmc/lattice.py +++ b/openmc/lattice.py @@ -446,14 +446,14 @@ class Lattice(object): # Assign universe clones to the lattice clone for i in self.indices: if isinstance(self, RectLattice): - clone.universes[i] = self.universes[i].clone() + clone.universes[i] = self.universes[i].clone(memo) else: if self.ndim == 2: clone.universes[i[0]][i[1]] = \ - self.universes[i[0]][i[1]].clone() + self.universes[i[0]][i[1]].clone(memo) else: clone.universes[i[0]][i[1]][i[2]] = \ - self.universes[i[0]][i[1]][i[2]].clone() + self.universes[i[0]][i[1]][i[2]].clone(memo) # Memoize the clone memo[self] = clone