Skip to content

Commit

Permalink
Merge pull request #262 from fusion-energy/avoid_writing_intermediate…
Browse files Browse the repository at this point in the history
…_brep_file_on_h5m_export

saved time by not writting brep file
  • Loading branch information
shimwell authored Sep 8, 2022
2 parents 8539e63 + aac9a1e commit e9513ec
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
2 changes: 1 addition & 1 deletion conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 37 additions & 20 deletions paramak/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()])
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e9513ec

Please sign in to comment.