Skip to content

Commit

Permalink
Include all files in PR
Browse files Browse the repository at this point in the history
  • Loading branch information
connoramoreno committed Oct 9, 2024
1 parent 3cad25a commit b88e59d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 37 deletions.
7 changes: 7 additions & 0 deletions parastell/invessel_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pystell.read_vmec as read_vmec

from . import log
from . import cubit_io
from .utils import (
normalize,
expand_list,
Expand Down Expand Up @@ -292,6 +293,12 @@ def merge_layer_surfaces(self):
)
prev_outer_surface_id = outer_surface_id

def import_step_cubit(self):
"""Imports STEP files from in-vessel build into Coreform Cubit."""
for name, data in self.radial_build.radial_build.items():
vol_id = cubit_io.import_step_cubit(name, self.export_dir)
data["vol_id"] = vol_id

def export_step(self, export_dir=""):
"""Export CAD solids as STEP files via CadQuery.
Expand Down
46 changes: 36 additions & 10 deletions parastell/magnet_coils.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,19 @@ def build_magnet_coils(self):

self._cut_magnets()

def import_step_cubit(self):
"""Import STEP file for magnet set into Coreform Cubit."""
if cubit_io.initialized:
first_vol_id = cubit.get_last_id("volume") + 1
else:
first_vol_id = 1

last_vol_id = cubit_io.import_step_cubit(
self.step_filename, self.export_dir
)

self.volume_ids = range(first_vol_id, last_vol_id + 1)

def export_step(self, step_filename="magnet_set", export_dir=""):
"""Export CAD solids as a STEP file via CadQuery.
Expand All @@ -261,19 +274,28 @@ def export_step(self, step_filename="magnet_set", export_dir=""):
)
cq.exporters.export(coil_set, str(export_path))

def mesh_magnets(self):
"""Creates tetrahedral mesh of magnet volumes via Coreform Cubit."""
self._logger.info("Generating tetrahedral mesh of magnet coils...")
def mesh_magnets(self, min_size=20.0, max_size=50.0, max_gradient=1.5):
"""Creates tetrahedral mesh of magnet volumes via Coreform Cubit.
last_vol_id = cubit_io.import_step_cubit(
self.step_filename, self.export_dir
)
Arguments:
min_size (float): minimum size of mesh elements (defaults to 20.0).
max_size (float): maximum size of mesh elements (defaults to 50.0).
max_gradient (float): maximum transition in mesh element size
(defaults to 1.5).
"""
self._logger.info("Generating tetrahedral mesh of magnet coils...")

self.volume_ids = range(1, last_vol_id + 1)
if not hasattr(self, "volume_ids"):
self.import_step_cubit()

for vol in self.volume_ids:
cubit.cmd(f"volume {vol} scheme tetmesh")
cubit.cmd(f"mesh volume {vol}")
volume_ids_str = " ".join(str(id) for id in self.volume_ids)
cubit.cmd(f"volume {volume_ids_str} scheme tetmesh")
cubit.cmd(
f"volume {volume_ids_str} sizing function type skeleton min_size "
f"{min_size} max_size {max_size} max_gradient {max_gradient} "
"min_num_layers_3d 1 min_num_layers_2d 1 min_num_layers_1d 1"
)
cubit.cmd(f"mesh volume {volume_ids_str}")

def export_mesh(self, mesh_filename="magnet_mesh", export_dir=""):
"""Creates tetrahedral mesh of magnet volumes and exports H5M format
Expand All @@ -291,6 +313,10 @@ def export_mesh(self, mesh_filename="magnet_mesh", export_dir=""):
filename=mesh_filename, export_dir=export_dir
)

# Delete magnet mesh to prevent inclusion in future Cubit mesh exports
volume_ids_str = " ".join(str(id) for id in self.volume_ids)
cubit.cmd(f"delete mesh volume {volume_ids_str} propagate")

def sort_coils_toroidally(self):
"""Reorders list of coils by toroidal angle on range [-pi, pi].
Expand Down
40 changes: 13 additions & 27 deletions parastell/parastell.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import pystell.read_vmec as read_vmec

from . import log

from . import invessel_build as ivb
from . import magnet_coils as mc
from . import source_mesh as sm
Expand Down Expand Up @@ -233,6 +232,7 @@ def export_magnets(
export_mesh=False,
mesh_filename="magnet_mesh",
export_dir="",
**kwargs,
):
"""Export magnet components.
Expand All @@ -246,13 +246,21 @@ def export_magnets(
'.h5m' extension (optional, defaults to 'magnet_mesh').
export_dir (str): directory to which to export output files
(optional, defaults to empty string).
Optional attributes:
min_size (float): minimum size of magnet mesh elements (defaults to
20.0).
max_size (float): maximum size of magnet mesh elements (defaults to
50.0).
max_gradient (float): maximum transition in magnet mesh element
size (defaults to 1.5).
"""
self.magnet_set.export_step(
step_filename=step_filename, export_dir=export_dir
)

if export_mesh:
self.magnet_set.mesh_magnets()
self.magnet_set.mesh_magnets(**kwargs)
self.magnet_set.export_mesh(
mesh_filename=mesh_filename, export_dir=export_dir
)
Expand Down Expand Up @@ -304,29 +312,6 @@ def export_source_mesh(self, filename="source_mesh", export_dir=""):
"""
self.source_mesh.export_mesh(filename=filename, export_dir=export_dir)

def _import_ivb_step(self):
"""Imports STEP files from in-vessel build into Coreform Cubit.
(Internal function not intended to be called externally)
"""
for (
name,
data,
) in self.invessel_build.radial_build.radial_build.items():
vol_id = cubit_io.import_step_cubit(
name, self.invessel_build.export_dir
)
data["vol_id"] = vol_id

def _import_magnets_step(self):
"""Import STEP file for magnet set into Coreform Cubit.
(Internal function not intended to be called externally)
"""
last_vol_id = cubit_io.import_step_cubit(
self.magnet_set.step_filename, self.magnet_set.export_dir
)

self.magnet_set.volume_ids = range(1, last_vol_id + 1)

def _tag_materials_legacy(self):
"""Applies material tags to corresponding CAD volumes for legacy DAGMC
neutronics model export.
Expand Down Expand Up @@ -382,16 +367,17 @@ def build_cubit_model(self, skip_imprint=False, legacy_faceting=True):
"Building DAGMC neutronics model via Coreform Cubit..."
)

# Ensure fresh Cubit instance
if cubit_io.initialized:
cubit.cmd("new")
else:
cubit_io.init_cubit()

if self.invessel_build:
self._import_ivb_step()
self.invessel_build.import_step_cubit()

if self.magnet_set:
self._import_magnets_step()
self.magnet_set.import_step_cubit()

if skip_imprint:
self.invessel_build.merge_layer_surfaces()
Expand Down

0 comments on commit b88e59d

Please sign in to comment.