diff --git a/conda/meta.yaml b/conda/meta.yaml index 378a7922b..49fa83b90 100644 --- a/conda/meta.yaml +++ b/conda/meta.yaml @@ -22,7 +22,7 @@ requirements: - mpmath - plasmaboundaries >=0.1.8 - plotly - - brep_part_finder >=0.4.1 # [not win] + - brep_part_finder >=0.4.4 # [not win] - brep_to_h5m >=0.3.1 # [not win] - moab * nompi_tempest_* # - jupyter-cadquery not available on conda diff --git a/paramak/utils.py b/paramak/utils.py index a231e071c..6f335618e 100644 --- a/paramak/utils.py +++ b/paramak/utils.py @@ -16,28 +16,18 @@ import OCP -def export_solids_to_brep( +def export_solids_to_brep_object( solids: Iterable, - filename: str = "reactor.brep", ): - """Exports a brep file for the Reactor.solid. + """Returns a brep object from a iterable of solids with merged surfaces. Args: solids: a list of cadquery solids - filename: the filename of exported the brep file. Returns: - filename of the brep created + brep cadquery object """ - path_filename = Path(filename) - - if path_filename.suffix != ".brep": - msg = "When exporting a brep file the filename must end with .brep" - raise ValueError(msg) - - path_filename.parents[0].mkdir(parents=True, exist_ok=True) - # TODO bring non merge capability back # if not merge: # geometry_to_save = cq.Compound.makeCompound([self.solid, self.graveyard.solid.val()]) @@ -46,8 +36,7 @@ def export_solids_to_brep( bldr = OCP.BOPAlgo.BOPAlgo_Splitter() if len(solids) == 1: - solids[0].val().exportBrep(str(path_filename)) - return str(path_filename) + return solids[0].val() for solid in solids: # checks if solid is a compound as .val() is not needed for compounds @@ -64,6 +53,33 @@ def export_solids_to_brep( merged_solid = cq.Compound(bldr.Shape()) + return merged_solid + + +def export_solids_to_brep( + solids: Iterable, + filename: str = "reactor.brep", +): + """Exports a brep file for the Reactor.solid. + + Args: + solids: a list of cadquery solids + filename: the filename of exported the brep file. + + Returns: + filename of the brep created + """ + + path_filename = Path(filename) + + if path_filename.suffix != ".brep": + msg = "When exporting a brep file the filename must end with .brep" + raise ValueError(msg) + + path_filename.parents[0].mkdir(parents=True, exist_ok=True) + + merged_solid = export_solids_to_brep_object(solids) + merged_solid.exportBrep(str(path_filename)) return str(path_filename) @@ -92,13 +108,10 @@ def export_solids_to_dagmc_h5m( from brep_to_h5m import brep_to_h5m import brep_part_finder as bpf - tmp_brep_filename = mkstemp(suffix=".brep", prefix="paramak_")[1] - # saves the reactor as a Brep file with merged surfaces - export_solids_to_brep(solids=solids, filename=tmp_brep_filename) + brep_shape = export_solids_to_brep_object(solids=solids) - # brep file is imported - brep_file_part_properties = bpf.get_brep_part_properties(tmp_brep_filename) + brep_file_part_properties = bpf.get_brep_part_properties_from_shape(brep_shape) if verbose: print("brep_file_part_properties", brep_file_part_properties) @@ -146,6 +159,10 @@ def export_solids_to_dagmc_h5m( if verbose: print(f"key_and_part_id={key_and_part_id}") + # gmsh requires an actual brep file to load + tmp_brep_filename = mkstemp(suffix=".brep", prefix="paramak_")[1] + brep_shape.exportBrep(tmp_brep_filename) + brep_to_h5m( brep_filename=tmp_brep_filename, volumes_with_tags=key_and_part_id, diff --git a/setup.cfg b/setup.cfg index 97e4ec444..c7e0d6e02 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,7 +35,7 @@ install_requires= plasmaboundaries >= 0.1.8 jupyter-client < 7 jupyter-cadquery >= 3.2.0 - brep_part_finder >= 0.4.1 + brep_part_finder >= 0.4.4 brep_to_h5m >= 0.3.1 setuptools_scm