Skip to content

Commit

Permalink
add tests for pydagmc workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Edgar-21 committed Feb 3, 2025
1 parent 52fd1c0 commit d258f14
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 27 deletions.
File renamed without changes.
6 changes: 6 additions & 0 deletions parastell/invessel_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ def generate_pymoab_verts(self):
]

def generate_components(self):
if self.use_pydagmc:
self.generate_components_pydagmc()
else:
self.generate_components_cadquery()

def generate_components_cadquery(self):
"""Constructs a CAD solid for each component specified in the radial
build by cutting the interior surface solid from the outer surface
solid for a given component.
Expand Down
2 changes: 1 addition & 1 deletion parastell/parastell.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def build_cad_to_dagmc_model(self):

self.dagmc_model = cad_to_dagmc.CadToDagmc()

if self.invessel_build:
if self.invessel_build and not self.use_pydagmc:
for solid, mat_tag in zip(
*self.invessel_build.extract_solids_and_mat_tags()
):
Expand Down
7 changes: 4 additions & 3 deletions parastell/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import math
from scipy.ndimage import gaussian_filter
from pymoab import core, types
import dagmc


m2cm = 100
Expand Down Expand Up @@ -294,8 +295,8 @@ def merge_dagmc_files(models_to_merge):
models_to_merge (list of PyMOAB core): List of dagmc models to be
merged.
Returns:
merged_mbc (PyMOAB Core): PyMOAB core instance containing the merged
DAGMC models.
merged_model (dagmc.DAGModel): Single DAGMC model containing each
individual model.
"""
temp_files = []
max_ids = {dim: 0 for dim in range(5)}
Expand All @@ -315,4 +316,4 @@ def merge_dagmc_files(models_to_merge):
merged_mbc.load_file(file)

Path.unlink(temp_filename)
return merged_mbc
return dagmc.DAGModel(merged_mbc)
13 changes: 13 additions & 0 deletions tests/test_invessel_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ def test_ivb_construction(invessel_build):
remove_files()


def test_ivb_pydagmc_construction(invessel_build):
num_volumes_exp = 1
num_surfaces_exp = 4

invessel_build.use_pydagmc = True
invessel_build.populate_surfaces()
invessel_build.calculate_loci()
invessel_build.generate_components()

assert num_surfaces_exp == len(invessel_build.dag_model.surfaces)
assert num_volumes_exp == len(invessel_build.dag_model.volumes)


def test_ivb_exports(invessel_build):

remove_files()
Expand Down
67 changes: 44 additions & 23 deletions tests/test_parastell.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,25 @@
import parastell.parastell as ps
from parastell.cubit_io import create_new_cubit_instance

files_to_remove = [
"chamber.step",
"component.step",
"magnet_set.step",
"magnet_mesh.exo",
"magnet_mesh.h5m",
"dagmc.h5m",
"dagmc.cub5",
"source_mesh.h5m",
"stellarator.log",
"step_import.log",
"step_export.log",
]

def remove_files():

if Path("chamber.step").exists():
Path.unlink("chamber.step")
if Path("component.step").exists():
Path.unlink("component.step")
if Path("magnet_set.step").exists():
Path.unlink("magnet_set.step")
if Path("magnet_mesh.exo").exists():
Path.unlink("magnet_mesh.exo")
if Path("magnet_mesh.h5m").exists():
Path.unlink("magnet_mesh.h5m")
if Path("dagmc.h5m").exists():
Path.unlink("dagmc.h5m")
if Path("dagmc.cub5").exists():
Path.unlink("dagmc.cub5")
if Path("source_mesh.h5m").exists():
Path.unlink("source_mesh.h5m")
if Path("stellarator.log").exists():
Path.unlink("stellarator.log")
if Path("step_import.log").exists():
Path.unlink("step_import.log")
if Path("step_export.log").exists():
Path.unlink("step_export.log")
def remove_files():
for file in files_to_remove:
if Path(file).exists():
Path.unlink(file)


@pytest.fixture
Expand Down Expand Up @@ -196,3 +190,30 @@ def test_parastell(stellarator):
assert Path(filename_exp).with_suffix(".h5m").exists()

remove_files()

# Test pydagmc model generation

num_surfaces_exp = 8
num_volumes_exp = 2

stellarator.construct_invessel_build(
toroidal_angles,
poloidal_angles,
wall_s,
radial_build_dict,
num_ribs=num_ribs,
use_pydagmc=True,
)

stellarator.build_cubit_model()
stellarator.export_cubit_dagmc()
stellarator.merge_magnet_and_ivb_dagmc_models()

assert len(stellarator.merged_model.surfaces) == num_surfaces_exp
assert len(stellarator.merged_model.volumes) == num_volumes_exp

stellarator.merged_model.write_file("dagmc.h5m")

assert Path("dagmc.h5m").exists()

remove_files()

0 comments on commit d258f14

Please sign in to comment.