From b8d21a2bfe6f0c71861bd32edb58a8c24bbf4f63 Mon Sep 17 00:00:00 2001 From: David Sosa sanchez Date: Fri, 8 Nov 2024 15:07:01 -0600 Subject: [PATCH] export to STL format capability added --- parastell/invessel_build.py | 17 +++++++++++++++++ parastell/magnet_coils.py | 23 +++++++++++++++++++++++ parastell/parastell.py | 17 +++++++++++++++-- 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/parastell/invessel_build.py b/parastell/invessel_build.py index 1d535ece..235e94cf 100644 --- a/parastell/invessel_build.py +++ b/parastell/invessel_build.py @@ -309,6 +309,23 @@ def export_step(self, export_dir=""): ) cq.exporters.export(component, str(export_path)) + def export_stl(self, export_dir=""): + """Export CAD solids as STL files via CadQuery. + + Arguments: + export_dir (str): directory to which to export the STL output files + (optional, defaults to empty string). + """ + self._logger.info("Exporting STL 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( + ".stl" + ) + cq.exporters.export(component, str(export_path)) + def export_cad_to_dagmc(self, dagmc_filename="dagmc", export_dir=""): """Exports DAGMC neutronics H5M file of ParaStell in-vessel components via CAD-to-DAGMC. diff --git a/parastell/magnet_coils.py b/parastell/magnet_coils.py index 2be72f1d..1ee39672 100644 --- a/parastell/magnet_coils.py +++ b/parastell/magnet_coils.py @@ -269,6 +269,29 @@ def export_step(self, step_filename="magnet_set", export_dir=""): ) cq.exporters.export(coil_set, str(export_path)) + def export_stl(self, stl_filename="magnet_set", export_dir=""): + """Export CAD solids as a STL file via CadQuery. + + Arguments: + stl_filename (str): name of STL output file, excluding '.stl' + extension (optional, defaults to 'magnet_set'). + export_dir (str): directory to which to export the STL output file + (optional, defaults to empty string). + """ + self._logger.info("Exporting STL file for magnet coils...") + + self.export_dir = export_dir + self.stl_filename = stl_filename + + export_path = Path(self.export_dir) / Path( + self.stl_filename + ).with_suffix(".stl") + + coil_set = cq.Compound.makeCompound( + [coil.solid for coil in self.magnet_coils] + ) + 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...") diff --git a/parastell/parastell.py b/parastell/parastell.py index df57874c..b8f7aae0 100644 --- a/parastell/parastell.py +++ b/parastell/parastell.py @@ -171,12 +171,14 @@ 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, export_to_stl=False, export_cad_to_dagmc=False, dagmc_filename="dagmc", export_dir="" ): - """Exports InVesselBuild component STEP files and, optionally, a DAGMC + """Exports InVesselBuild component STEP files and, optionally, to STL files and a DAGMC neutronics H5M file of in-vessel components via CAD-to-DAGMC. Arguments: + export_to_stl (bool): export in-vessel components to STL format + (optional, defaults to False) export_cad_to_dagmc (bool): export DAGMC neutronics H5M file of in-vessel components via CAD-to-DAGMC (optional, defaults to False). @@ -187,6 +189,9 @@ def export_invessel_build( """ self.invessel_build.export_step(export_dir=export_dir) + if export_to_stl: + self.invessel_build.export_stl(export_dir=export_dir) + if export_cad_to_dagmc: self.invessel_build.export_cad_to_dagmc( dagmc_filename=dagmc_filename, export_dir=export_dir @@ -230,6 +235,7 @@ def construct_magnets( def export_magnets( self, step_filename="magnet_set", + export_stl=False, export_mesh=False, mesh_filename="magnet_mesh", export_dir="", @@ -240,6 +246,8 @@ def export_magnets( step_filename (str): name of STEP export output file, excluding '.step' extension (optional, optional, defaults to 'magnet_set'). + export_stl (bool): export magnet components in STL format. File name + is the same as step_filename (optional, defaults to False) 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 @@ -251,6 +259,11 @@ def export_magnets( step_filename=step_filename, export_dir=export_dir ) + if export_stl: + self.magnet_set.export_stl( + stl_filename=step_filename, export_dir=export_dir + ) + if export_mesh: self.magnet_set.mesh_magnets() self.magnet_set.export_mesh(