From 0e8e0fae0242f77ecc433eea04fa38b60da8769e Mon Sep 17 00:00:00 2001 From: David Sosa sanchez Date: Wed, 13 Nov 2024 14:36:23 -0600 Subject: [PATCH] export_step and export_stl merged into a single function --- parastell/invessel_build.py | 28 +++++++++------------------- parastell/magnet_coils.py | 14 ++++++++++++-- parastell/parastell.py | 36 ++++++++++++++---------------------- 3 files changed, 35 insertions(+), 43 deletions(-) diff --git a/parastell/invessel_build.py b/parastell/invessel_build.py index 097ff73..6a2a023 100644 --- a/parastell/invessel_build.py +++ b/parastell/invessel_build.py @@ -293,6 +293,7 @@ def merge_layer_surfaces(self): ) prev_outer_surface_id = outer_surface_id +<<<<<<< HEAD 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(): @@ -301,35 +302,24 @@ def import_step_cubit(self): 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. +>>>>>>> 666c81c (export_step and export_stl merged into a single function) Arguments: + filetype (str): file extension to which solids are exported + (defaults to STEP). export_dir (str): directory to which to export the STEP 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" - ) - 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" + f".{filetype}" ) cq.exporters.export(component, str(export_path)) diff --git a/parastell/magnet_coils.py b/parastell/magnet_coils.py index 2f06189..bcf7200 100644 --- a/parastell/magnet_coils.py +++ b/parastell/magnet_coils.py @@ -238,6 +238,7 @@ def build_magnet_coils(self): self._cut_magnets() +<<<<<<< HEAD def import_step_cubit(self): """Import STEP file for magnet set into Coreform Cubit.""" first_vol_id = 1 @@ -252,6 +253,10 @@ def import_step_cubit(self): def export_step(self, step_filename="magnet_set", export_dir=""): """Export CAD solids as a STEP file via CadQuery. +======= + def export_components(self, filetype="step", filename="magnet_set", export_dir=""): + """Export CAD solids as a STEP or STL file via CadQuery. +>>>>>>> 666c81c (export_step and export_stl merged into a single function) Arguments: step_filename (str): name of STEP output file, excluding '.step' @@ -259,12 +264,13 @@ def export_step(self, step_filename="magnet_set", export_dir=""): export_dir (str): directory to which to export the STEP 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( +<<<<<<< HEAD self.step_filename ).with_suffix(".step") @@ -294,6 +300,10 @@ def export_stl(self, stl_filename="magnet_set", export_dir=""): export_path = Path(self.export_dir) / Path( self.stl_filename ).with_suffix(".stl") +======= + self.filename + ).with_suffix(f".{filetype}") +>>>>>>> 666c81c (export_step and export_stl merged into a single function) coil_set = cq.Compound.makeCompound( [coil.solid for coil in self.magnet_coils] diff --git a/parastell/parastell.py b/parastell/parastell.py index 3e3dadb..1398ccf 100644 --- a/parastell/parastell.py +++ b/parastell/parastell.py @@ -170,14 +170,15 @@ def construct_invessel_build( self.invessel_build.generate_components() def export_invessel_build( - self, export_to_stl=False, 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, to STL files and 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: - export_to_stl (bool): export in-vessel components to STL format - (optional, defaults to False) + filetype (str): file extension 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). @@ -186,10 +187,7 @@ 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) - - if export_to_stl: - self.invessel_build.export_stl(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( @@ -233,8 +231,8 @@ def construct_magnets( def export_magnets( self, - step_filename="magnet_set", - export_stl=False, + filetype="step", + filename="magnet_set", export_mesh=False, mesh_filename="magnet_mesh", export_dir="", @@ -243,11 +241,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'). - export_stl (bool): export magnet components in STL format. File name - is the same as step_filename (optional, defaults to False) + filetype (str): filetype (str): file extension to which solids are + exported (defaults to STEP). + filename (str): name of export 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 @@ -263,15 +260,10 @@ 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_stl: - self.magnet_set.export_stl( - stl_filename=step_filename, export_dir=export_dir - ) - if export_mesh: self.magnet_set.mesh_magnets(**kwargs) self.magnet_set.export_mesh(