-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from fusion-energy/adding_3d_mesh_export_option
allowing export_gmsh_mesh_file to support 3d volume mesh exporting
- Loading branch information
Showing
19 changed files
with
325 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
examples/unsructured_volume_mesh/curved_cadquery_object_to_dagmc_volume_mesh.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
66 changes: 66 additions & 0 deletions
66
examples/unsructured_volume_mesh/simulate_unstrucutred_volume_mesh_with_openmc.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
Oops, something went wrong.