Skip to content

Commit

Permalink
Merge pull request #178 from svalinn/94-add-support-for-meshing-inves…
Browse files Browse the repository at this point in the history
…sel-components

Adds support for meshing in-vessel components
  • Loading branch information
connoramoreno authored Nov 27, 2024
2 parents 69fb5b6 + ed1ee4e commit ae1d1ff
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 3 deletions.
11 changes: 11 additions & 0 deletions parastell/cubit_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ def init_cubit():
initialized = True


def create_new_cubit_instance():
"""Creates new cubit instance checking if Cubit has been already
initialized.
"""
if initialized:
cubit.cmd("new")
else:
init_cubit()


def import_step_cubit(filename, import_dir):
"""Imports STEP file into Coreform Cubit.
Expand Down
27 changes: 27 additions & 0 deletions parastell/invessel_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,33 @@ def export_cad_to_dagmc(self, dagmc_filename="dagmc", export_dir=""):

model.export_dagmc_h5m_file(filename=str(export_path))

def export_component_mesh(
self, components, mesh_size=5, import_dir="", export_dir=""
):
"""Creates a tetrahedral mesh of an in-vessel component volume
via Coreform Cubit and exports it as H5M file.
Arguments:
components (array of strings): array containing the name
of the in-vessel components to be meshed.
mesh_size (int): controls the size of the mesh. Takes values
between 1 (finer) and 10 (coarser) (optional, defaults to 5).
import_dir (str): directory containing the STEP file of
the in-vessel component (optional, defaults to empty string).
export_dir (str): directory to which to export the h5m
output file (optional, defaults to empty string).
"""
for component in components:
vol_id = cubit_io.import_step_cubit(component, import_dir)
cubit.cmd(f"volume {vol_id} scheme tetmesh")
cubit.cmd(f"volume {vol_id} size auto factor {mesh_size}")
cubit.cmd(f"mesh volume {vol_id}")
cubit_io.export_mesh_cubit(
filename=component,
export_dir=export_dir,
delete_upon_export=True,
)


class Surface(object):
"""An object representing a surface formed by lofting across a set of
Expand Down
21 changes: 21 additions & 0 deletions parastell/parastell.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,27 @@ def export_invessel_build(
dagmc_filename=dagmc_filename, export_dir=export_dir
)

def export_invessel_component_mesh(
self, components, mesh_size=5, import_dir="", export_dir=""
):
"""Creates a tetrahedral mesh of an in-vessel component volume
via Coreform Cubit and exports it as H5M file.
Arguments:
components (array of strings): array containing the name
of the in-vessel components to be meshed.
mesh_size (int): controls the size of the mesh. Takes values
between 1 (finer) and 10 (coarser) (optional, defaults to 5).
import_dir (str): directory containing the STEP file of
the in-vessel component (optional, defaults to empty string).
export_dir (str): directory to which to export the h5m
output file (optional, defaults to empty string).
"""
self._logger.info("Exporting in-vessel components mesh...")
self.invessel_build.export_component_mesh(
components, mesh_size, import_dir, export_dir
)

def construct_magnets(
self, coils_file, width, thickness, toroidal_extent, **kwargs
):
Expand Down
5 changes: 4 additions & 1 deletion tests/test_invessel_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# import this before read_vmec to deal with conflicting
# dependencies correctly
import parastell.invessel_build as ivb
from parastell.cubit_io import create_new_cubit_instance

import pystell.read_vmec as read_vmec

Expand Down Expand Up @@ -118,15 +119,17 @@ def test_ivb_construction(invessel_build):
def test_ivb_exports(invessel_build):

remove_files()

create_new_cubit_instance()
invessel_build.populate_surfaces()
invessel_build.calculate_loci()
invessel_build.generate_components()
invessel_build.export_step()
invessel_build.export_cad_to_dagmc()
invessel_build.export_component_mesh(components=["component"])

assert Path("chamber.step").exists()
assert Path("component.step").exists()
assert Path("dagmc.h5m").exists()
assert Path("component.h5m").exists()

remove_files()
3 changes: 2 additions & 1 deletion tests/test_magnet_coils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np

import parastell.magnet_coils as magnet_coils
from parastell.cubit_io import create_new_cubit_instance


def remove_files():
Expand Down Expand Up @@ -70,7 +71,7 @@ def test_magnet_exports(coil_set):
volume_ids_exp = list(range(1, 2))

remove_files()

create_new_cubit_instance()
coil_set.populate_magnet_coils()
coil_set.build_magnet_coils()
coil_set.export_step()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_parastell.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

import parastell.parastell as ps
from parastell.cubit_io import create_new_cubit_instance


def remove_files():
Expand Down Expand Up @@ -45,7 +46,7 @@ def stellarator():
def test_parastell(stellarator):

remove_files()

create_new_cubit_instance()
# In-Vessel Build

toroidal_angles = [0.0, 5.0, 10.0, 15.0]
Expand Down

0 comments on commit ae1d1ff

Please sign in to comment.