From c1082420e488b8c28c207d31e8b72f3b5221a1f3 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 17 Jan 2018 06:47:03 -0600 Subject: [PATCH] Use argparse in build-fresh.py --- smr/build-fresh.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/smr/build-fresh.py b/smr/build-fresh.py index 026bec5..5819516 100644 --- a/smr/build-fresh.py +++ b/smr/build-fresh.py @@ -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)']