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

export to STL format capability added #176

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
14 changes: 9 additions & 5 deletions parastell/invessel_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,20 +299,24 @@ def import_step_cubit(self):
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.
def export_components(self, filetype="step", export_dir=""):
"""Export CAD solids as STEP or STL files via CadQuery.
Comment on lines +302 to +303
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a good idea to include some kind of check on filetype input, unless we want to rely on CadQuery to issue an error if an incorrect filetype is supplied.


Arguments:
export_dir (str): directory to which to export the STEP output files
filetype (str): file extension, excluding '.', to which solids are exported
(defaults to STEP).
export_dir (str): directory to which to export the output files
(optional, defaults to empty string).
"""
self._logger.info("Exporting STEP files for in-vessel components...")
self._logger.info(
f"Exporting {filetype.upper()} files for in-vessel components..."
)

self.export_dir = export_dir

for name, component in self.Components.items():
export_path = Path(self.export_dir) / Path(name).with_suffix(
".step"
f".{filetype}"
)
cq.exporters.export(component, str(export_path))

Expand Down
26 changes: 16 additions & 10 deletions parastell/magnet_coils.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,23 +250,29 @@ def import_step_cubit(self):

self.volume_ids = list(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.
def export_components(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of calling this export_components, since there's only one component being exported, maybe we should call this something like export_cad, and do the same with the in-vessel build for consistency.

self, filetype="step", filename="magnet_set", export_dir=""
):
Comment on lines +253 to +255
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to combine filename and filetype into a single input argument? This would deviate from our established convention.

"""Export CAD solids as a STEP or STL file via CadQuery.

Arguments:
step_filename (str): name of STEP output file, excluding '.step'
extension (optional, defaults to 'magnet_set').
export_dir (str): directory to which to export the STEP output file
filetype (str): extension, excluding '.', to which to export the output file
(defaults to STEP).
filename (str): name of output file, excluding extension
(optional, defaults to 'magnet_set').
export_dir (str): directory to which to export the output file
(optional, defaults to empty string).
"""
self._logger.info("Exporting STEP file for magnet coils...")
self._logger.info(
f"Exporting {filetype.upper()} file for magnet coils..."
)

self.export_dir = export_dir
self.step_filename = step_filename
self.filename = filename

export_path = Path(self.export_dir) / Path(
self.step_filename
).with_suffix(".step")
export_path = Path(self.export_dir) / Path(self.filename).with_suffix(
f".{filetype}"
)

coil_set = cq.Compound.makeCompound(
[coil.solid for coil in self.magnet_coils]
Expand Down
28 changes: 19 additions & 9 deletions parastell/parastell.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,18 @@ def construct_invessel_build(
self.invessel_build.generate_components()

def export_invessel_build(
self, export_cad_to_dagmc=False, dagmc_filename="dagmc", export_dir=""
self,
filetype="step",
export_cad_to_dagmc=False,
dagmc_filename="dagmc",
export_dir="",
):
"""Exports InVesselBuild component STEP files and, optionally, a DAGMC
"""Exports InVesselBuild component STEP or STL files and, optionally, a DAGMC
neutronics H5M file of in-vessel components via CAD-to-DAGMC.

Arguments:
filetype (str): file extension, excluding '.', to which solids are
exported (defaults to STEP).
export_cad_to_dagmc (bool): export DAGMC neutronics H5M file of
in-vessel components via CAD-to-DAGMC (optional, defaults to
False).
Expand All @@ -184,7 +190,9 @@ def export_invessel_build(
export_dir (str): directory to which to export the output files
(optional, defaults to empty string).
"""
self.invessel_build.export_step(export_dir=export_dir)
self.invessel_build.export_components(
filetype=filetype, export_dir=export_dir
)

if export_cad_to_dagmc:
self.invessel_build.export_cad_to_dagmc(
Expand Down Expand Up @@ -228,7 +236,8 @@ def construct_magnets(

def export_magnets(
self,
step_filename="magnet_set",
filetype="step",
filename="magnet_set",
export_mesh=False,
mesh_filename="magnet_mesh",
export_dir="",
Expand All @@ -237,9 +246,10 @@ def export_magnets(
"""Export magnet components.

Arguments:
step_filename (str): name of STEP export output file, excluding
'.step' extension (optional, optional, defaults to
'magnet_set').
filetype (str): file extension, excluding '.', to which solids are
exported (defaults to STEP).
filename (str): name of output file, excluding extension
(optional, defaults to 'magnet_set').
export_mesh (bool): flag to indicate tetrahedral mesh generation
for magnet volumes (optional, defaults to False).
mesh_filename (str): name of tetrahedral mesh H5M file, excluding
Expand All @@ -255,8 +265,8 @@ def export_magnets(
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
self.magnet_set.export_components(
filetype=filetype, filename=filename, export_dir=export_dir
)

if export_mesh:
Expand Down
Loading