ecp-benchmarks/smr/build-assembly.py
Paul Romano 2e1761c6fb Squashed commit of the following:
commit fea65f02928ed7b65b0aa88e16af0e9f308dc28e
Author: Paul Romano <paul.k.romano@gmail.com>
Date:   Mon Feb 5 09:20:20 2018 -0600

    Remove XML files and old models

commit 423b3ade32be620dab7ba6fe9c292a6ee4758e9e
Author: Paul Romano <paul.k.romano@gmail.com>
Date:   Mon Feb 5 09:10:54 2018 -0600

    Fix bug in ring generation

commit f5a3acd3d6d0eba7edf4b0c94e76aebdcaa2cd62
Author: Paul Romano <paul.k.romano@gmail.com>
Date:   Mon Feb 5 09:05:51 2018 -0600

    Add option to specify output directory

commit 0c4bca51b38bbb94fffe1d13157f693bee4dea03
Author: Paul Romano <paul.k.romano@gmail.com>
Date:   Tue Jan 23 14:50:09 2018 -0600

    Add plots for assembly

commit 2813d95ea694259bd50ae7fa19087f8652fc0bc5
Author: Paul Romano <paul.k.romano@gmail.com>
Date:   Sun Jan 21 16:08:45 2018 -0600

    Shared compositions when building assembly

commit 5ee50611df13f5df03144266d2c08f2890fdaf72
Author: Paul Romano <paul.k.romano@gmail.com>
Date:   Sun Jan 21 15:32:48 2018 -0600

    Fix build-core-fresh

commit e375ad22a7fb05def86664f5be8411ee822e23a2
Author: Paul Romano <paul.k.romano@gmail.com>
Date:   Fri Jan 19 15:51:51 2018 -0600

    Use pathlib in build-assembly and move assembly directory

commit 53d38a3b3711b44dd75313132c4122f2192df16c
Author: Paul Romano <paul.k.romano@gmail.com>
Date:   Fri Jan 19 14:39:09 2018 -0600

    Add an option to use depleted materials

commit 9c52f82bd0cd989b10938c85586caba331efa1f4
Author: Paul Romano <paul.k.romano@gmail.com>
Date:   Wed Jan 17 14:02:27 2018 -0600

    Add SMR assembly model

commit 82f60acfb3b8889d812e03eb4ee2007b2a5a501e
Author: Paul Romano <paul.k.romano@gmail.com>
Date:   Wed Jan 17 12:34:35 2018 -0600

    Add docstrings here and there

commit a957d442a8
Author: Paul Romano <paul.k.romano@gmail.com>
Date:   Wed Jan 17 12:18:11 2018 -0600

    Special treatment for a single radial/axial region in fuel pins

commit dac1af47ad
Author: Paul Romano <paul.k.romano@gmail.com>
Date:   Wed Jan 17 06:54:24 2018 -0600

    Add number of rings/axial segments as command-line options

commit c1082420e4
Author: Paul Romano <paul.k.romano@gmail.com>
Date:   Wed Jan 17 06:47:03 2018 -0600

    Use argparse in build-fresh.py

commit a20d15c0cb
Author: Paul Romano <paul.k.romano@gmail.com>
Date:   Wed Jan 17 06:27:01 2018 -0600

    Make number of rings configurable

commit 96b1ae8513
Author: Paul Romano <paul.k.romano@gmail.com>
Date:   Tue Jan 16 22:44:15 2018 -0600

    Generate pin universes within function

commit 0b1965e27f
Author: Paul Romano <paul.k.romano@gmail.com>
Date:   Tue Jan 16 22:28:44 2018 -0600

    Put geometry and reflector/assembly universes in functions

commit 337d4cff69
Author: Paul Romano <paul.k.romano@gmail.com>
Date:   Wed Nov 22 12:22:17 2017 -0600

    Make sure sleeve appears on fifth grid spacer

commit 46e379e169
Author: Paul Romano <paul.k.romano@gmail.com>
Date:   Tue Nov 14 14:54:14 2017 -0600

    Don't break up fuel region over multiple universes in z direction

commit 7e735bec85
Author: Paul Romano <paul.k.romano@gmail.com>
Date:   Fri Nov 10 11:49:36 2017 -0600

    Fix number of pellets in SMR

commit 186c525c8a
Author: Paul Romano <paul.k.romano@gmail.com>
Date:   Thu Nov 2 23:27:48 2017 -0500

    Add axial subdivision of fuel pins

commit 6762ab0237
Author: Paul Romano <paul.k.romano@gmail.com>
Date:   Fri Oct 20 07:54:57 2017 -0400

    Add ten rings in fuel
2018-02-05 09:26:05 -06:00

142 lines
5 KiB
Python

#!/usr/bin/env python3
import argparse
import copy
from pathlib import Path
import numpy as np
from tqdm import tqdm
import openmc
from smr.materials import materials
from smr.surfaces import surfs, lattice_pitch, bottom_fuel_stack, top_active_core
from smr.assemblies import assembly_universes
from smr.plots import assembly_plots
# Define command-line options
parser = argparse.ArgumentParser()
parser.add_argument('-m', '--multipole', action='store_true',
help='Whether to use multipole cross sections')
parser.add_argument('-t', '--tallies', choices=('cell', 'mat'), default='mat',
help='Whether to use distribmats or distribcells for tallies')
parser.add_argument('-r', '--rings', type=int, default=10,
help='Number of annular regions in fuel')
parser.add_argument('-a', '--axial', type=int, default=196,
help='Number of axial subdivisions in fuel')
parser.add_argument('-d', '--depleted', action='store_true',
help='Whether UO2 compositions should represent depleted fuel')
parser.add_argument('-o', '--output-dir', type=Path, default=None)
args = parser.parse_args()
# Make directory for inputs
if args.output_dir is None:
if args.depleted:
directory = Path('assembly-depleted')
else:
directory = Path('assembly-fresh')
else:
directory = args.output_dir
directory.mkdir(exist_ok=True)
# Define geometry with a single assembly
assembly = assembly_universes(args.rings, args.axial, args.depleted)
lattice_sides = openmc.model.get_rectangular_prism(lattice_pitch, lattice_pitch,
boundary_type='reflective')
main_cell = openmc.Cell(
fill=assembly['Assembly (3.1%) 16BA'],
region=lattice_sides & +surfs['lower bound'] & -surfs['upper bound']
)
root_univ = openmc.Universe(cells=[main_cell])
geometry = openmc.Geometry(root_univ)
def clone(material):
"""Perform copy of material but share nuclide densities"""
shared_mat = copy.copy(material)
shared_mat.id = None
return shared_mat
#### "Differentiate" the geometry if using distribmats
if args.tallies == 'mat':
# Count the number of instances for each cell and material
geometry.determine_paths(instances_only=True)
# Extract all cells filled by a fuel material
fuel_mats = {m for m in materials if 'UO2 Fuel' in m.name}
for cell in tqdm(geometry.get_all_material_cells().values(),
desc='Differentiating materials'):
if cell.fill in fuel_mats:
# Fill cell with list of "differentiated" materials
cell.fill = [clone(cell.fill) for i in range(cell.num_instances)]
#### Create OpenMC "materials.xml" file
print('Getting materials...')
all_materials = geometry.get_all_materials()
print('Creating materials collection...')
materials = openmc.Materials(all_materials.values())
print('Exporting materials to XML...')
materials.export_to_xml(str(directory / 'materials.xml'))
#### Create OpenMC "geometry.xml" file
geometry.export_to_xml(str(directory / 'geometry.xml'))
#### Create OpenMC "settings.xml" file
# Construct uniform initial source distribution over fissionable zones
lower_left = (-lattice_pitch/2, -lattice_pitch/2, bottom_fuel_stack)
upper_right = (lattice_pitch/2, lattice_pitch/2, top_active_core)
source = openmc.source.Source(space=openmc.stats.Box(lower_left, upper_right))
source.space.only_fissionable = True
settings = openmc.Settings()
settings.batches = 200
settings.inactive = 100
settings.particles = 10000
settings.output = {'tallies': False, 'summary': False}
settings.source = source
settings.sourcepoint_write = False
if args.multipole:
settings.temperature = {'multipole': True, 'tolerance': 1000}
settings.export_to_xml(str(directory / 'settings.xml'))
#### Create OpenMC "tallies.xml" file
tallies = openmc.Tallies()
# Extract all fuel materials
materials = geometry.get_materials_by_name(name='Fuel', matching=False)
# If using distribcells, create distribcell tally needed for depletion
if args.tallies == 'cell':
# Extract all cells filled by a fuel material
fuel_cells = []
for cell in geometry.get_all_cells().values():
if cell.fill in materials:
tally = openmc.Tally(name='depletion tally')
tally.scores = ['(n,p)', '(n,a)', '(n,gamma)',
'fission', '(n,2n)', '(n,3n)', '(n,4n)']
tally.nuclides = cell.fill.get_nuclides()
tally.filters.append(openmc.DistribcellFilter([cell]))
tallies.append(tally)
# If using distribmats, create material tally needed for depletion
elif args.tallies == 'mat':
tally = openmc.Tally(name='depletion tally')
tally.scores = ['(n,p)', '(n,a)', '(n,gamma)',
'fission', '(n,2n)', '(n,3n)', '(n,4n)']
tally.nuclides = materials[0].get_nuclides()
tally.filters = [openmc.MaterialFilter(materials)]
tallies.append(tally)
tallies.export_to_xml(str(directory / 'tallies.xml'))
# Create plots
plots = assembly_plots(main_cell.fill)
plots.export_to_xml(str(directory / 'plots.xml'))