Skip to content

Commit

Permalink
Merge pull request #57 from fusion-energy/adding_3d_mesh_export_option
Browse files Browse the repository at this point in the history
allowing export_gmsh_mesh_file to support 3d volume mesh exporting
  • Loading branch information
shimwell authored Mar 14, 2024
2 parents 9ab88da + b94261f commit 3cb0144
Show file tree
Hide file tree
Showing 19 changed files with 325 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_with_benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
sudo apt-get upgrade -y
sudo apt-get install -y libgl1-mesa-glx libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev libosmesa6 libosmesa6-dev libgles2-mesa-dev libarchive-dev libpangocairo-1.0-0
mamba activate
mamba install -y -c cadquery -c conda-forge moab gmsh python-gmsh cadquery=master "openmc=0.13.3=dagmc*nompi*"
mamba install -y -c conda-forge moab gmsh python-gmsh cadquery=2.4.0 "openmc=0.14.0=dagmc*nompi*"
python -m pip install --upgrade pip
python -m pip install cad_to_dagmc openmc_data_downloader
openmc_data_downloader -l ENDFB-7.1-NNDC -i Fe56 Be9
Expand Down
14 changes: 6 additions & 8 deletions .github/workflows/ci_with_install.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@

# This CI will launch a Docker image that contains all the dependencies required
# within that image the pytest test suite is run
# container:
# image: continuumio/miniconda3:23.3.1-0

name: CI with install

on:
Expand Down Expand Up @@ -40,11 +35,13 @@ jobs:
sudo apt-get upgrade -y
sudo apt-get install -y libgl1-mesa-glx libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev libosmesa6 libosmesa6-dev libgles2-mesa-dev libarchive-dev libpangocairo-1.0-0
mamba activate
mamba install -y -c cadquery -c conda-forge moab gmsh python-gmsh cadquery=master
mamba create --name cad_to_dagmc python=3.12
mamba activate cad_to_dagmc
mamba install -y -c conda-forge moab gmsh python-gmsh ocp=7.7.2.0 cadquery=2.4.0
python -m pip install --upgrade pip
python -m pip install .
python -c "import cad_to_dagmc"
mamba install -y -c conda-forge "openmc=0.13.3=dagmc*nompi*"
mamba install -y -c conda-forge "openmc=0.14.0=dagmc*nompi*"
python -m pip install .[tests]
pytest tests -v
cd examples
Expand All @@ -53,7 +50,8 @@ jobs:
python cadquery_compound.py
python cadquery_object_and_stp_file.py
python cadquery_text.py
python curved_cadquery_object.py
python curved_cadquery_object_to_dagmc_surface_mesh.py
python curved_cadquery_object_to_dagmc_volume_mesh.py
python multiple_cadquery_objects.py
python multiple_stp_files.py
python single_stp_file_multiple_volumes.py
Expand Down
57 changes: 57 additions & 0 deletions .github/workflows/ci_with_pip_install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

name: CI with pip install

on:
pull_request:
branches:
- main
paths-ignore:
- 'docs/**'
- '.gitignore'
- '*.md'
- 'CITATION.cff'
- 'LICENSE.txt'
- 'readthedocs.yml'
push:
branches:
- main

jobs:
testing:
runs-on: ubuntu-latest
container:
image: openmc/openmc:develop-dagmc
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: install non pypi dependencies
shell: bash
run: |
apt-get --allow-releaseinfo-change update
apt-get update -y
apt-get upgrade -y
apt-get install -y libgl1-mesa-glx libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev libosmesa6 libosmesa6-dev libgles2-mesa-dev libarchive-dev libpangocairo-1.0-0 libxcursor-dev libxft2 libxinerama-dev
apt install python3
apt install python3-pip
python -m pip install --upgrade pip
python -m pip install gmsh
python -m pip install cadquery-ocp==7.7.2
python -m pip install cadquery==2.4.0
python -m pip install .
python -c "import cad_to_dagmc"
python -m pip install .[tests]
pytest tests -v
cd examples
python create_stp_files_for_examples.py
python cadquery_assembly.py
python cadquery_compound.py
python cadquery_object_and_stp_file.py
python cadquery_text.py
python curved_cadquery_object_to_dagmc_surface_mesh.py
python curved_cadquery_object_to_dagmc_volume_mesh.py
python multiple_cadquery_objects.py
python multiple_stp_files.py
python single_stp_file_multiple_volumes.py
python single_cadquery_object.py
python single_stp_file.py
4 changes: 2 additions & 2 deletions examples/cadquery_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
assembly.add(result2)

my_model = CadToDagmc()
my_model.add_cadquery_object(assembly, material_tags=["mat1", "mat2"])
my_model.export_dagmc_h5m_file(min_mesh_size=0.5, max_mesh_size=1.0)
my_model.add_cadquery_object(assembly)
my_model.export_dagmc_h5m_file(min_mesh_size=0.5, max_mesh_size=1.0, material_tags=["mat1", "mat2"])
4 changes: 2 additions & 2 deletions examples/cadquery_compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
compound_of_shapes = cq.Compound.makeCompound([cq_shape_1.val(), cq_shape_2.val()])

my_model = CadToDagmc()
my_model.add_cadquery_object(object=compound_of_shapes, material_tags=["mat1", "mat2"])
my_model.export_dagmc_h5m_file(max_mesh_size=0.2, min_mesh_size=0.1)
my_model.add_cadquery_object(object=compound_of_shapes)
my_model.export_dagmc_h5m_file(max_mesh_size=0.2, min_mesh_size=0.1, material_tags=["mat1", "mat2"])
13 changes: 10 additions & 3 deletions examples/cadquery_object_and_stp_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
result = cq.Workplane("XY").moveTo(10, 0).box(3, 3, 0.5).edges("|Z").fillet(0.125)

my_model = CadToDagmc()
my_model.add_cadquery_object(object=result, material_tags=["mat1"])
my_model.add_stp_file(filename="single_cube.stp", material_tags=["mat2"], scale_factor=0.1)
my_model.export_dagmc_h5m_file(max_mesh_size=0.2, min_mesh_size=0.1)

my_model.add_cadquery_object(result)

my_model.add_stp_file(filename="single_cube.stp", scale_factor=0.1)

my_model.export_dagmc_h5m_file(
max_mesh_size=0.2,
min_mesh_size=0.1,
material_tags=["mat1", "mat2"],
)
10 changes: 6 additions & 4 deletions examples/cadquery_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@


my_model = CadToDagmc()
my_model.add_cadquery_object(
object=text,
my_model.add_cadquery_object(object=text)

my_model.export_dagmc_h5m_file(
filename="cadquery_text.h5m",
max_mesh_size=0.2,
min_mesh_size=0.1,
material_tags=[
"mat1",
"mat2",
Expand All @@ -15,5 +19,3 @@
"mat5",
], # 5 volumes one for each letter
)

my_model.export_dagmc_h5m_file(filename="cadquery_text.h5m", max_mesh_size=0.2, min_mesh_size=0.1)
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ def gear(t, r1=4, r2=1):

my_model = CadToDagmc()

my_model.add_cadquery_object(
result,
material_tags=["mat1"],
)
my_model.add_cadquery_object(result)

my_model.export_dagmc_h5m_file(
filename="cadquery_objects_and_stp_files.h5m", max_mesh_size=1, min_mesh_size=0.1
filename="cadquery_objects_and_stp_files.h5m",
max_mesh_size=1,
min_mesh_size=0.1,
material_tags=["mat1"],
)
6 changes: 3 additions & 3 deletions examples/multiple_cadquery_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
box_with_round_corners = cq.Workplane("XY").box(2, 1, 1)

my_model = CadToDagmc()
my_model.add_cadquery_object(box, material_tags=["mat1"])
my_model.add_cadquery_object(box_with_round_corners, material_tags=["mat2"])
my_model.export_dagmc_h5m_file()
my_model.add_cadquery_object(box)
my_model.add_cadquery_object(box_with_round_corners)
my_model.export_dagmc_h5m_file(material_tags=["mat1", "mat2"])
9 changes: 6 additions & 3 deletions examples/multiple_stp_files.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from cad_to_dagmc import CadToDagmc

my_model = CadToDagmc()
my_model.add_stp_file("two_connected_cubes.stp", material_tags=["mat1", "mat2"])
my_model.add_stp_file("single_sphere.stp", material_tags=["mat3"])
my_model.add_stp_file("two_connected_cubes.stp")
my_model.add_stp_file("single_sphere.stp")

my_model.export_dagmc_h5m_file(
max_mesh_size=1, min_mesh_size=0.5, implicit_complement_material_tag="air"
max_mesh_size=1,
min_mesh_size=0.5,
implicit_complement_material_tag="air",
material_tags=["mat1", "mat2", "mat3"],
)
4 changes: 2 additions & 2 deletions examples/single_cadquery_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
result = sphere = cq.Workplane().moveTo(100, 0).sphere(5)

my_model = CadToDagmc()
my_model.add_cadquery_object(result, material_tags=["mat1"])
my_model.export_dagmc_h5m_file()
my_model.add_cadquery_object(result)
my_model.export_dagmc_h5m_file(material_tags=["mat1"])
4 changes: 2 additions & 2 deletions examples/single_stp_file.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from cad_to_dagmc import CadToDagmc

my_model = CadToDagmc()
my_model.add_stp_file("spline_extrude.stp", material_tags=["mat1"])
my_model.export_dagmc_h5m_file()
my_model.add_stp_file("spline_extrude.stp")
my_model.export_dagmc_h5m_file(material_tags=["mat1"])
4 changes: 2 additions & 2 deletions examples/single_stp_file_multiple_volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

my_model = CadToDagmc()
# the d and c from the word dagmc would be tagged with one material and the agm are tagged with another material
my_model.add_stp_file("text_dagmc.stp", material_tags=["mat1", "mat2", "mat2", "mat2", "mat1"])
my_model.export_dagmc_h5m_file()
my_model.add_stp_file("text_dagmc.stp")
my_model.export_dagmc_h5m_file(material_tags=["mat1", "mat2", "mat2", "mat2", "mat1"])
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from cad_to_dagmc import CadToDagmc
import cadquery as cq
from math import sin, cos, pi, floor


# define the generating function
def hypocycloid(t, r1, r2):
return (
(r1 - r2) * cos(t) + r2 * cos(r1 / r2 * t - t),
(r1 - r2) * sin(t) + r2 * sin(-(r1 / r2 * t - t)),
)


def epicycloid(t, r1, r2):
return (
(r1 + r2) * cos(t) - r2 * cos(r1 / r2 * t + t),
(r1 + r2) * sin(t) - r2 * sin(r1 / r2 * t + t),
)


def gear(t, r1=4, r2=1):
if (-1) ** (1 + floor(t / 2 / pi * (r1 / r2))) < 0:
return epicycloid(t, r1, r2)
else:
return hypocycloid(t, r1, r2)


# create the gear profile and extrude it
result = (
cq.Workplane("XY")
.parametricCurve(lambda t: gear(t * 2 * pi, 6, 1))
.twistExtrude(15, 90)
.faces(">Z")
.workplane()
.circle(2)
.cutThruAll()
)
assembly = cq.Assembly()
assembly.add(result)
assembly.save("twist.step")

s = cq.Workplane("XY")
sPnts = [
(2.75, 1.5),
(2.5, 1.75),
(2.0, 1.5),
(1.5, 1.0),
(1.0, 1.25),
(0.5, 1.0),
(0, 1.0),
]
r = s.lineTo(3.0, 0).lineTo(3.0, 1.0).spline(sPnts, includeCurrent=True).close()
result2 = r.extrude(-20)
assembly.add(result2)
assembly.save("twist_and_extrude.step")

my_model = CadToDagmc()

my_model.add_cadquery_object(result)
my_model.add_cadquery_object(result2)

my_model.export_unstructured_mesh_file(filename="umesh.h5m", max_mesh_size=1, min_mesh_size=0.1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# script assumes that "umesh.h5m" has been created by
# curved_cadquery_object_to_dagmc_volume_mesh.py has been

import openmc

umesh = openmc.UnstructuredMesh("umesh.h5m", library="moab")
mesh_filter = openmc.MeshFilter(umesh)
tally = openmc.Tally(name="t1")
tally.filters = [mesh_filter]
tally.scores = ["flux"]
tally.estimator = "tracklength"
my_tallies = openmc.Tallies([tally])


mat1 = openmc.Material()
mat1.add_element("Pb", 84.2, percent_type="ao")
mat1.add_element(
"Li",
15.8,
percent_type="ao",
enrichment=50.0,
enrichment_target="Li6",
enrichment_type="ao",
)
mat1.set_density("g/cm3", 11)
my_materials = openmc.Materials([mat1])

surf1 = openmc.Sphere(r=500, boundary_type="vacuum")
region1 = -surf1

cell1 = openmc.Cell(region=region1)
cell1.fill = mat1

my_geometry = openmc.Geometry([cell1])


my_settings = openmc.Settings()
my_settings.batches = 10
my_settings.inactive = 0
my_settings.particles = 5000
my_settings.run_mode = "fixed source"

# Create a DT point source
my_source = openmc.Source()
# my_source = openmc.IndependentSource()
my_source.space = openmc.stats.Point((0, 0, 0))
my_source.angle = openmc.stats.Isotropic()
my_source.energy = openmc.stats.Discrete([14e6], [1])
my_settings.source = my_source

model = openmc.model.Model(my_geometry, my_materials, my_settings, my_tallies)
sp_filename = model.run()

sp = openmc.StatePoint(sp_filename)

tally_result = sp.get_tally(name="t1")


# umesh = tally_result.find_filter(openmc.MeshFilter)
umesh_from_sp = sp.meshes[1]

centroids = umesh_from_sp.centroids
mesh_vols = umesh_from_sp.volumes

flux_mean = tally_result.get_values(scores=["flux"], value="mean").reshape(umesh_from_sp.dimension)
umesh_from_sp.write_data_to_vtk(filename="tally.vtk", datasets={"mean": flux_mean})
Loading

0 comments on commit 3cb0144

Please sign in to comment.