Use argparse in build-fresh.py

This commit is contained in:
Paul Romano 2018-01-17 06:47:03 -06:00
parent a20d15c0cb
commit c1082420e4

View file

@ -3,6 +3,7 @@
import os
import shutil
import copy
import argparse
import numpy as np
@ -13,24 +14,19 @@ from smr.surfaces import lattice_pitch, bottom_fuel_stack, top_active_core
from smr.core import core_geometry
#### Query the user for options
# 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='cell',
help='Whether to use distribmats or distribcells for tallies')
args = parser.parse_args()
# Query the user on whether to use multipole cross sections
multipole = input('Use multipole cross sections? (y/n): ').lower()
multipole = (multipole == 'y')
# Query the user on whether to use distribmats or distribcells
# If using distribmats, the geometry must be "differentiated" with unique
# material instances for each instance of a fuel cell
distrib = input('Use distribmat or distribcells? [mat/cell]: ').lower()
if distrib not in ['cell', 'mat']:
raise InputError('Distrib type "{}" is unsupported'.format(distrib))
geometry = core_geometry()
#### "Differentiate" the geometry if using distribmats
if distrib == 'mat':
if args.tallies == 'mat':
# Count the number of instances for each cell and material
geometry.determine_paths(instances_only=True)
@ -68,7 +64,7 @@ settings.output = {'tallies': False}
settings.source = source
settings.sourcepoint_write = False
if multipole:
if args.multipole:
settings.temperature = {'multipole': True, 'tolerance': 1000}
settings.export_to_xml()
@ -85,7 +81,7 @@ tallies = openmc.Tallies()
materials = geometry.get_materials_by_name(name='Fuel', matching=False)
# If using distribcells, create distribcell tally needed for depletion
if distrib == 'cell':
if args.tallies == 'cell':
# Extract all cells filled by a fuel material
fuel_cells = []
for cell in geometry.get_all_cells().values():
@ -98,7 +94,7 @@ if distrib == 'cell':
tallies.append(tally)
# If using distribmats, create material tally needed for depletion
elif distrib == 'mat':
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)']