Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

made plasma optional for export h5m with pymoab #828

Merged
merged 3 commits into from
May 3, 2021
Merged
Show file tree
Hide file tree
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
36 changes: 28 additions & 8 deletions paramak/reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ def neutronics_description(
interaction with neutrons. However, it can be added if the
include_plasma argument is set to True.

Args:
include_plasma: Should the plasma material be included in the JSON
returned.

Returns:
dictionary: a dictionary of materials and filenames for the reactor
"""
Expand Down Expand Up @@ -692,6 +696,7 @@ def export_h5m(
self,
filename: Optional[str] = 'dagmc.h5m',
include_graveyard: Optional[bool] = True,
include_plasma: Optional[bool] = False,
method: Optional[str] = None,
merge_tolerance: Optional[float] = None,
faceting_tolerance: Optional[float] = None,
Expand Down Expand Up @@ -740,12 +745,14 @@ def export_h5m(
filename=filename,
merge_tolerance=merge_tolerance,
faceting_tolerance=faceting_tolerance,
include_plasma=include_plasma,
)
elif method == 'pymoab':
output_filename = self.export_h5m_with_pymoab(
filename=filename,
include_graveyard=include_graveyard,
faceting_tolerance=faceting_tolerance
faceting_tolerance=faceting_tolerance,
include_plasma=include_plasma,
)

else:
Expand Down Expand Up @@ -823,6 +830,7 @@ def export_h5m_with_trelis(
filename: Optional[str] = 'dagmc.h5m',
merge_tolerance: Optional[float] = None,
faceting_tolerance: Optional[float] = None,
include_plasma: Optional[bool] = False,
) -> str:
"""Produces a dagmc.h5m neutronics file compatable with DAGMC
simulations using Coreform Trelis.
Expand Down Expand Up @@ -853,7 +861,7 @@ def export_h5m_with_trelis(
self.export_neutronics_description(
include_graveyard=True,
include_sector_wedge=True,
include_plasma=False,
include_plasma=include_plasma,
)
self.export_stp(
include_graveyard=True,
Expand Down Expand Up @@ -887,7 +895,8 @@ def export_h5m_with_pymoab(
self,
filename: Optional[str] = 'dagmc.h5m',
include_graveyard: Optional[bool] = True,
faceting_tolerance: Optional[float] = None
faceting_tolerance: Optional[float] = None,
include_plasma: Optional[bool] = False,
) -> str:
"""Converts stl files into DAGMC compatible h5m file using PyMOAB. The
DAGMC file produced has not been imprinted and merged unlike the other
Expand All @@ -902,10 +911,13 @@ def export_h5m_with_pymoab(
using Reactor.graveyard_size and Reactor.graveyard_offset
attribute values.
faceting_tolerance: the precision of the faceting.
include_plasma: Should the plasma material be included in the h5m
file.

Returns:
The filename of the DAGMC file created
"""

if faceting_tolerance is None:
faceting_tolerance = self.faceting_tolerance

Expand All @@ -922,18 +934,26 @@ def export_h5m_with_pymoab(
volume_id = 1

if isinstance(self.shapes_and_components, list):
for item in self.shapes_and_components:
for entry in self.shapes_and_components:

if include_plasma is False and (
isinstance(
entry,
(paramak.Plasma,
paramak.PlasmaFromPoints,
paramak.PlasmaBoundaries)) is True or entry.name == 'plasma'):
continue

item.export_stl(
item.stl_filename,
entry.export_stl(
entry.stl_filename,
tolerance=faceting_tolerance)
moab_core = add_stl_to_moab_core(
moab_core,
surface_id,
volume_id,
item.material_tag,
entry.material_tag,
moab_tags,
item.stl_filename)
entry.stl_filename)
volume_id += 1
surface_id += 1
else:
Expand Down
37 changes: 31 additions & 6 deletions tests/test_Reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,30 @@ def test_export_h5m_with_pymoab_without_faceting_tolerance(self):
my_reactor.faceting_tolerance = 1e-2
my_reactor.export_h5m_with_pymoab(faceting_tolerance=None)

def test_export_h5m_with_pymoab_without_plasma(self):
"""exports a h5m file with pymoab without the plasma"""

os.system('rm *.stl')

test_shape1 = paramak.RotateStraightShape(
points=[(0, 0), (0, 20), (20, 20)],
stl_filename='RotateStraightShape.stl'
)
test_shape2 = paramak.Plasma(
stl_filename='plasma.stl'
)

my_reactor = paramak.Reactor([test_shape1, test_shape2])
my_reactor.export_h5m_with_pymoab(include_plasma=False, filename='no_plasma.h5m')

assert Path('RotateStraightShape.stl').is_file()
assert Path('plasma.stl').is_file() is False
my_reactor.export_h5m_with_pymoab(include_plasma=True, filename='with_plasma.h5m')
assert Path('plasma.stl').is_file()

assert Path('with_plasma.h5m').stat().st_size > Path('no_plasma.h5m').stat().st_size


def test_export_h5m_with_pymoab_from_manifest_file(self):
"""exports a h5m file when shapes_and_components is set to a string"""

Expand All @@ -1221,7 +1245,7 @@ def check_correct_error_is_rasied():
test_shape.export_neutronics_description('manifest.json')
my_reactor = paramak.Reactor('manifest.json')
my_reactor.export_h5m_with_pymoab()
assert Path('dagmc.h5m').is_file
assert Path('dagmc.h5m').is_file()

self.assertRaises(NotImplementedError, check_correct_error_is_rasied)

Expand All @@ -1233,16 +1257,17 @@ def test_export_vtk(self):
assert self.test_reactor.h5m_filename is None
self.test_reactor.export_h5m_with_pymoab()
self.test_reactor.export_vtk()
assert Path('dagmc.h5m').is_file
assert Path('dagmc.vtk').is_file
assert Path('dagmc_no_graveyard.vtk').is_file
assert Path('dagmc.h5m').is_file()
assert Path('dagmc.vtk').is_file()
self.test_reactor.export_vtk(include_graveyard=False, filename='dagmc_no_graveyard.vtk')
assert Path('dagmc_no_graveyard.vtk').is_file()
assert self.test_reactor.h5m_filename == 'dagmc.h5m'

self.test_reactor.export_vtk(filename='custom_filename.vtk')
assert Path('custom_filename.vtk').is_file
assert Path('custom_filename.vtk').is_file()

self.test_reactor.export_vtk(filename='suffixless_filename')
assert Path('suffixless_filename.vtk').is_file
assert Path('suffixless_filename.vtk').is_file()

def test_export_vtk_without_h5m_raises_error(self):
"""exports a h5m file when shapes_and_components is set to a string"""
Expand Down