Skip to content

Commit

Permalink
Merge pull request svalinn#182 from svalinn/magnets_from_custom_geometry
Browse files Browse the repository at this point in the history
split MagnetSet and MagnetCoil
  • Loading branch information
connoramoreno authored Jan 31, 2025
2 parents 52ca52b + f53be7b commit 552801c
Show file tree
Hide file tree
Showing 12 changed files with 2,150 additions and 306 deletions.
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# PRoject specific
# Project specific
*.csv
*.step
*.h5m
Expand All @@ -12,12 +12,15 @@
*.cub5
*.h5
*.exo
!wout_vmec.nc
.vscode
*.yaml
!config.yaml
*.lic

# Exceptions for tests
!magnet_geom.step
!config.yaml
!wout_vmec.nc

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
2 changes: 1 addition & 1 deletion Examples/parastell_cad_to_dagmc_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
thickness = 50.0
toroidal_extent = 90.0
# Construct magnets
stellarator.construct_magnets(
stellarator.construct_magnets_from_filaments(
coils_file, width, thickness, toroidal_extent, sample_mod=6
)
# Export magnet files
Expand Down
2 changes: 1 addition & 1 deletion Examples/parastell_cubit_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
thickness = 50.0
toroidal_extent = 90.0
# Construct magnets
stellarator.construct_magnets(
stellarator.construct_magnets_from_filaments(
coils_file, width, thickness, toroidal_extent, sample_mod=6
)
# Export magnet files
Expand Down
2 changes: 1 addition & 1 deletion Examples/radial_distance_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
stellarator.export_invessel_build()

# Construct magnets
stellarator.construct_magnets(
stellarator.construct_magnets_from_filaments(
coils_file, width, thickness, toroidal_extent, sample_mod=6
)
# Export magnet files
Expand Down
35 changes: 35 additions & 0 deletions parastell/cubit_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ def export_step_cubit(filename, export_dir=""):
cubit.cmd(f'export step "{export_path}" overwrite')


def import_cub5_cubit(filename, import_dir):
"""Imports cub5 file with Coreform Cubit with default import settings.
Arguments:
filename (str): name of cub5 input file.
import_dir (str): directory from which to import cub5 file.
Returns:
vol_id (int): Cubit volume ID of imported CAD solid.
"""
init_cubit()
import_path = Path(import_dir) / Path(filename).with_suffix(".cub5")
cubit.cmd(
f'import cubit "{import_path}" nofreesurfaces attributes_on separate_bodies'
)
vol_id = cubit.get_last_id("volume")
return vol_id


def export_cub5(filename, export_dir=""):
"""Export cub5 representation of model (native Cubit format).
Expand Down Expand Up @@ -161,3 +178,21 @@ def export_dagmc_cubit(
# exports
if delete_upon_export:
cubit.cmd(f"delete mesh volume all propagate")


def import_geom_to_cubit(filename, import_dir=""):
"""Attempts to open a geometry file with the appropriate cubit_io function,
based on file extension
Arguments:
filename (path): name of the file to import, including the suffix
import_dir (str): directory from which to import the file.
Returns:
vol_id (int): Cubit volume ID of imported CAD solid.
"""
importers = {
".step": import_step_cubit,
".cub5": import_cub5_cubit,
}
filename = Path(filename)
vol_id = importers[filename.suffix](filename, import_dir)
return vol_id
4 changes: 2 additions & 2 deletions parastell/invessel_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ def export_step(self, export_dir=""):
cq.exporters.export(component, str(export_path))

def extract_solids_and_mat_tags(self):
"""Appends in-vessel component CadQuery solid objects and material
tags to corresponding input lists.
"""Get a list of all cadquery solids, and a corresponding list of
the respective material tags.
Returns:
solids (list): list of in-vessel component CadQuery solid objects.
Expand Down
Loading

0 comments on commit 552801c

Please sign in to comment.