Skip to content

Commit

Permalink
no need to write vtk and convert to h5
Browse files Browse the repository at this point in the history
  • Loading branch information
shimwell authored Nov 27, 2024
1 parent 61ddaf2 commit e9ce7c7
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions src/cad_to_dagmc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,45 @@ def add_cadquery_object(

def export_unstructured_mesh_file(
self,
filename: str = "umesh.h5m",
filename: str = "umesh.vtk",
min_mesh_size: float = 1,
max_mesh_size: float = 5,
mesh_algorithm: int = 1,
method: str = "file",
scale_factor: float = 1.0,
):
"""
Exports an unstructured mesh file in VTK format for use with openmc.UnstructuredMesh.
Compatible with the MOAB unstrucutred mesh library. Example useage
openmc.UnstructuredMesh(filename="umesh.vtk", library="moab")
Parameters:
-----------
filename : str, optional
The name of the output file. Default is "umesh.vtk".
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)
mesh_algorithm: The Gmsh mesh algorithm number to use. Passed into
gmsh.option.setNumber("Mesh.Algorithm", mesh_algorithm)
method: the method to use to import the geometry into gmsh. Options
are 'file' or 'in memory'. 'file' is the default and will write
the geometry to a temporary file before importing it into gmsh.
'in memory' will import the geometry directly into gmsh but
requires the version of OpenCASCADE used to build gmsh to be
the same as the version used by CadQuery. This is possible to
ensure when installing the package with Conda but harder when
installing from PyPI.
scale_factor: a scaling factor to apply to the geometry that can be
used to enlarge or shrink the geometry. Useful when converting
Useful when converting the geometry to cm for use in neutronics
Returns:
--------
gmsh : gmsh
The gmsh object after finalizing the mesh.
"""

assembly = cq.Assembly()
for part in self.parts:
Expand All @@ -510,12 +542,9 @@ def export_unstructured_mesh_file(
dimensions=3,
)

# gmesh writes out a vtk file that is converted by pymoab into a h5 file
gmsh.write(filename + ".vtk")

moab_core = core.Core()
moab_core.load_file(filename + ".vtk")
moab_core.write_file(filename)
# gmesh writes out a vtk file that is accepted by openmc.UnstructuredMesh
# The library argument must be set to "moab"
gmsh.write(filename)

gmsh.finalize()

Expand Down

0 comments on commit e9ce7c7

Please sign in to comment.