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

Adding export h5m using brep gmsh method #157

Merged
merged 37 commits into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e29ba27
added basic export h5m function
shimwell Jan 21, 2022
9426b79
added doc string for export_dagmc_h5m
shimwell Jan 22, 2022
030daf0
including packages required for h5m export
shimwell Jan 22, 2022
0fa0596
[skip ci] Apply formatting changes
shimwell Jan 22, 2022
6d57fde
updated conda install scripts
shimwell Jan 23, 2022
20a9360
added shape.export_dagmc_h5m method
shimwell Jan 23, 2022
ea8f72c
[skip ci] added missing quote mark
shimwell Jan 23, 2022
f0a6aaf
[skip ci] added missing import
shimwell Jan 23, 2022
c36e6f9
[skip ci] added missing import
shimwell Jan 23, 2022
dbd685c
[skip ci] using exclude instead of names not included for arg
shimwell Jan 23, 2022
35a57f5
added tempory try except for distances kwarg
shimwell Jan 24, 2022
44987b8
[skip ci] Apply formatting changes
shimwell Jan 24, 2022
5546815
added default filename of export_h5m
shimwell Jan 24, 2022
400211b
[skip ci] Apply formatting changes
shimwell Jan 24, 2022
570e2af
tmp stl files are deleted
shimwell Jan 25, 2022
446c5b7
Merge branch 'develop' into adding_export_h5m_using_brep_gmsh_method
shimwell Jan 25, 2022
6ebf18b
added ability to export multi volume shapes to h5m
shimwell Jan 26, 2022
bcc5a46
Merge branch 'adding_export_h5m_using_brep_gmsh_method' of github.com…
shimwell Jan 26, 2022
251e70c
[skip ci] Apply formatting changes
shimwell Jan 26, 2022
d417ae6
[skip ci] code inspector comments
shimwell Jan 26, 2022
96a0cbf
Merge branch 'adding_export_h5m_using_brep_gmsh_method' of github.com…
shimwell Jan 26, 2022
d98f497
removed surface_reflectivity=True arg
shimwell Jan 28, 2022
419cc84
merged conflict
shimwell Jan 31, 2022
71e9517
[skip ci] Apply formatting changes
shimwell Jan 31, 2022
3325abb
commented out cq2.2 incompatible tests
shimwell Feb 1, 2022
5898fff
changed to 180 rotation to check side edges
shimwell Feb 1, 2022
8ea81bc
[skip ci] Apply formatting changes
shimwell Feb 1, 2022
bc91999
changed reactors to 180 degree models by default
shimwell Feb 2, 2022
4d205de
Merge branch 'adding_export_h5m_using_brep_gmsh_method' of github.com…
shimwell Feb 2, 2022
666205f
moved moab into conda section
shimwell Feb 2, 2022
ed2ca45
avoiding dagmc export tests for cq version 2.1
shimwell Feb 3, 2022
4394eec
[skip ci] Apply formatting changes
shimwell Feb 3, 2022
9fe8311
Merge branch 'develop' into adding_export_h5m_using_brep_gmsh_method
shimwell Feb 3, 2022
ae9d8e9
[skip ci] Apply formatting changes
shimwell Feb 3, 2022
ada9335
Merge branch 'develop_temp' into adding_export_h5m_using_brep_gmsh_me…
shimwell Feb 6, 2022
09e3446
removing check for cq 2.1
shimwell Feb 6, 2022
74eb300
[skip ci] Apply formatting changes
shimwell Feb 6, 2022
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
4 changes: 3 additions & 1 deletion conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ requirements:
- setuptools
run:
- cadquery
- gmsh
- moab # not available on windows
- matplotlib
- mpmath
- numpy
Expand All @@ -30,7 +32,7 @@ requirements:
- nbformat
- nbconvert
- ipywidgets
# - jupyter-cadquery not availalbe on conda
# - jupyter-cadquery not available on conda

test:
imports:
Expand Down
5 changes: 3 additions & 2 deletions conda_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ rm -rf /tmp/conda-build


# VERSION=$(echo $GITHUB_REF | sed 's#.*/v##')
VERSION=0.6.4
VERSION=0.7.0
PLACEHOLDER='version="develop"'
VERSION_FILE='setup.py'
# Grep checks that the placeholder is in the file. If grep doesn't find
Expand All @@ -37,7 +37,8 @@ conda-build conda/ -c cadquery -c conda-forge --croot /tmp/conda-build
# conda convert /tmp/conda-build/linux-64/*.tar.bz2 --platform all -o /tmp/conda-build

# option for converting package to specified platforms
platforms=( osx-64 linux-64 win-64 )
# platforms=( osx-64 linux-64 win-64 ) windows does not have moab
platforms=( osx-64 linux-64 )
find /tmp/conda-build/linux-64/ -name *.tar.bz2 | while read file
do
echo $file
Expand Down
8 changes: 5 additions & 3 deletions conda_build_config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
python:
- 3.8
- 3.7
- 3.6
# - 3.7
# - 3.6
cadquery:
- 2.1
- master
moab:
- 5.3.1
12 changes: 11 additions & 1 deletion docs/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Then install the Paramak.
Now you should be ready to import paramak from your new python environment.



Install (conda + pip)
---------------------

Expand All @@ -65,7 +66,16 @@ Then install the CadQuery.

.. code-block:: bash

conda install -c cadquery -c conda-forge cadquery=2.1
conda install -c cadquery -c conda-forge cadquery=2.2

MOAB and PyMoab are required for the export_dagmc_h5m() feature to work. The
MOAB Conda install does not currently support Windows and therefore Windows
users will have to compile MOAB. If the export_dagmc_h5m() feature is not
needed then this stage can be skipped.

.. code-block:: bash

conda install -c cadquery -c conda-forge moab=5.3.0

Then pip install the Paramak.

Expand Down
5 changes: 4 additions & 1 deletion paramak/parametric_shapes/extruded_mixed_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ def create_solid(self):

self.wire = wire

solid = wire.extrude(distance=extrusion_distance, both=self.extrude_both)
try: # CQ version 2.2
solid = wire.extrude(until=extrusion_distance, both=self.extrude_both)
except: # CQ version 2.1
solid = wire.extrude(distance=extrusion_distance, both=self.extrude_both)

# filleting rectangular port cutter edges
# must be done before azimuthal placement
Expand Down
92 changes: 87 additions & 5 deletions paramak/reactor.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import collections
import json
from collections import Counter
import os
import tempfile

from collections.abc import Iterable
from pathlib import Path
from typing import List, Optional, Tuple, Union
import warnings

import brep_part_finder as bpf
import cadquery as cq
import matplotlib.pyplot as plt
from cadquery import Compound, exporters
from brep_to_h5m import brep_to_h5m
from cadquery import exporters

import paramak
from paramak.utils import _replace, get_hash
Expand Down Expand Up @@ -233,6 +236,86 @@ def show(self, default_edgecolor: Tuple[float, float, float] = (0, 0, 0)):

return show(PartGroup(parts), default_edgecolor=scaled_edge_color)

def export_dagmc_h5m(
self,
filename: str = "dagmc.h5m",
min_mesh_size: float = 10,
max_mesh_size: float = 20,
exclude: List[str] = None,
) -> str:
"""Export a DAGMC compatible h5m file for use in neutronics simulations.
This method makes use of Gmsh to create a surface mesh of the geometry.
MOAB is used to convert the meshed geometry into a h5m with parts tagged by
using the reactor.shape_and_components.name properties. You will need
Gmsh installed and MOAB installed to use this function.

Args:
filename: the filename of the DAGMC h5m file to write
min_mesh_size: the minimum mesh element size to use in Gmsh. Passed
into gmsh.option.setNumber("Mesh.MeshSizeMin", min_mesh_size)
max_mesh_size: the maximum mesh element size to use in Gmsh. Passed
into gmsh.option.setNumber("Mesh.MeshSizeMax", max_mesh_size)
exclude: A list of shape names to not include in the exported
geometry. 'plasma' is often excluded as not many neutron
interactions occur within a low density plasma.
"""

tmp_brep_filename = tempfile.mkstemp(suffix=".brep", prefix="paramak_")[1]

# saves the reactor as a Brep file with merged surfaces
self.export_brep(tmp_brep_filename)

# brep file is imported
brep_file_part_properties = bpf.get_brep_part_properties(tmp_brep_filename)

shape_properties = {}
for shape_or_compound in self.shapes_and_components:
sub_solid_descriptions = []
for sub_solid in shape_or_compound.solid.val().Solids():
part_bb = sub_solid.BoundingBox()
part_center = sub_solid.Center()
sub_solid_description = {
"volume": sub_solid.Volume(),
"center": (part_center.x, part_center.y, part_center.z),
"bounding_box": (
(part_bb.xmin, part_bb.ymin, part_bb.zmin),
(part_bb.xmax, part_bb.ymax, part_bb.zmax),
),
}
sub_solid_descriptions.append(sub_solid_description)
shape_properties[shape_or_compound.name] = sub_solid_descriptions

# request to find part ids that are mixed up in the Brep file
# using the volume, center, bounding box that we know about when creating the
# CAD geometry in the first place
key_and_part_id = bpf.get_dict_of_part_ids(
brep_part_properties=brep_file_part_properties,
shape_properties=shape_properties,
)

# allows components like the plasma to be removed
if isinstance(exclude, Iterable):
for name_to_remove in exclude:
key_and_part_id = {
key: val
for key, val in key_and_part_id.items()
if val != name_to_remove
}

brep_to_h5m(
brep_filename=tmp_brep_filename,
volumes_with_tags=key_and_part_id,
h5m_filename=filename,
min_mesh_size=min_mesh_size,
max_mesh_size=max_mesh_size,
delete_intermediate_stl_files=True,
)

# temporary brep is deleted
os.remove(tmp_brep_filename)

return filename

def export_stp(
self,
filename: Union[List[str], str] = None,
Expand Down Expand Up @@ -477,7 +560,6 @@ def make_sector_wedge(
height=height,
radius=radius,
rotation_angle=360 - rotation_angle,
surface_reflectivity=True,
azimuth_placement_angle=rotation_angle,
)

Expand Down
44 changes: 42 additions & 2 deletions paramak/shape.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import json
import numbers
import warnings
import os
import tempfile
from collections.abc import Iterable
from pathlib import Path
from typing import List, Optional, Tuple, Union

import brep_part_finder as bpf
import matplotlib.pyplot as plt
from brep_to_h5m import brep_to_h5m
from cadquery import Assembly, Color, Compound, Plane, Workplane, exporters, importers
from cadquery.occ_impl import shapes
from matplotlib.collections import PatchCollection
Expand Down Expand Up @@ -847,6 +849,44 @@ def export_brep(self, filename):

return str(path_filename)

def export_dagmc_h5m(
self,
filename: str = "dagmc.h5m",
min_mesh_size: float = 10,
max_mesh_size: float = 20,
) -> str:
"""Export a DAGMC compatible h5m file for use in neutronics simulations.
This method makes use of Gmsh to create a surface mesh of the geometry.
MOAB is used to convert the meshed geometry into a h5m with parts tagged by
using the reactor.shape_and_components.name properties. You will need
Gmsh installed and MOAB installed to use this function.

Args:
filename: the filename of the DAGMC h5m file to write
min_mesh_size: the minimum mesh element size to use in Gmsh. Passed
into gmsh.option.setNumber("Mesh.MeshSizeMin", min_mesh_size)
max_mesh_size: the maximum mesh element size to use in Gmsh. Passed
into gmsh.option.setNumber("Mesh.MeshSizeMax", max_mesh_size)
"""

tmp_brep_filename = tempfile.mkstemp(suffix=".brep", prefix=f"paramak_")[1]

# saves the reactor as a Brep file with merged surfaces
self.export_brep(tmp_brep_filename)

brep_to_h5m(
brep_filename=tmp_brep_filename,
volumes_with_tags={1: f"mat_{self.name}"},
h5m_filename=filename,
min_mesh_size=min_mesh_size,
max_mesh_size=max_mesh_size,
)

# temporary brep is deleted
os.remove(tmp_brep_filename)

return filename

def export_stp(
self,
filename: str,
Expand Down