Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/openmc_mcnp_adapter/openmc_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def rotation_matrix(v1, v2):
return I + K * sin_angle + (K @ K) * (1 - cos_angle)


def get_openmc_materials(materials):
def get_openmc_materials(materials, expand_elements: bool = True):
"""Get OpenMC materials from MCNP materials

Parameters
Expand All @@ -130,12 +130,12 @@ def get_openmc_materials(materials):
zaid = nuclide
name, element, Z, A, metastable = get_metadata(int(zaid), 'mcnp')
if percent < 0:
if A > 0:
if (A > 0) or (not expand_elements):
material.add_nuclide(name, abs(percent), 'wo')
else:
material.add_element(element, abs(percent), 'wo')
else:
if A > 0:
if (A > 0) or (not expand_elements):
material.add_nuclide(name, percent, 'ao')
else:
material.add_element(element, percent, 'ao')
Expand Down Expand Up @@ -863,7 +863,7 @@ def replace_complement(region, cells):
return universes


def mcnp_to_model(filename, merge_surfaces: bool = True) -> openmc.Model:
def mcnp_to_model(filename, merge_surfaces: bool = True, expand_elements: bool = True) -> openmc.Model:
"""Convert MCNP input to OpenMC model

Parameters
Expand All @@ -882,7 +882,7 @@ def mcnp_to_model(filename, merge_surfaces: bool = True) -> openmc.Model:

cells, surfaces, data = parse(filename)

openmc_materials = get_openmc_materials(data['materials'])
openmc_materials = get_openmc_materials(data['materials'], expand_elements)
openmc_surfaces = get_openmc_surfaces(surfaces, data)
openmc_universes = get_openmc_universes(cells, openmc_surfaces,
openmc_materials, data)
Expand Down Expand Up @@ -933,14 +933,19 @@ def mcnp_to_openmc():
help='Remove redundant surfaces when exporting XML')
parser.add_argument('--no-merge-surfaces', dest='merge_surfaces', action='store_false',
help='Do not remove redundant surfaces when exporting XML')
parser.add_argument('--expand-elements', action='store_true',
help='Expand elements to their constituent isotopes')
parser.add_argument('--no-expand-elements', dest='expand_elements', action='store_false',
help='Do not expand elements to their constituent isotopes')
parser.add_argument('-o', '--output', default='model.xml',
help='Name for the OpenMC model XML file')
parser.add_argument('-s', '--separate-xml', action='store_true',
help='Write separate XML files')
parser.set_defaults(merge_surfaces=True)
parser.set_defaults(expand_elements=True)
args = parser.parse_args()

model = mcnp_to_model(args.mcnp_filename, args.merge_surfaces)
model = mcnp_to_model(args.mcnp_filename, args.merge_surfaces, args.expand_elements)
if args.separate_xml:
model.export_to_xml()
else:
Expand Down