Unstructured mesh source#
This example makes use of a DAGMC unstructured tet mesh to produce a source with a MeshSpatial distribution.
import openmc
from pathlib import Path
from cad_to_dagmc import CadToDagmc
from openmc_source_plotter import plot_source_position
# Setting the cross section path to the correct location in the docker image.
# If you are running this outside the docker image you will have to change this path to your local cross section path.
openmc.config['cross_sections'] = Path.home() / 'nuclear_data' / 'cross_sections.xml'
# allows notebook rendering of plotly plots in the HTML made by jupyter-book
import plotly.offline as pyo
pyo.init_notebook_mode(connected=True)
/opt/hostedtoolcache/Python/3.12.11/x64/lib/python3.12/site-packages/openmc_source_plotter/core.py:12: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
import pkg_resources
This section loads a CAD step file and creates an unstrucutred DAGMC tet mesh
The resulting mesh file (umesh.mesh) is already included in the repo
So this creation from step file is included for completeness but can be skipped
cad = CadToDagmc()
cad.add_stp_file('plasma_simplified_180.step')
cad.export_unstructured_mesh_file(filename="umesh.vtk", max_mesh_size=100, min_mesh_size=10)
# Setting the cross section path to the correct location in the docker image.
# If you are running this outside the docker image you will have to change this path to your local cross section path.
openmc.config['cross_sections'] = Path.home() / 'nuclear_data' / 'cross_sections.xml'
umesh = openmc.UnstructuredMesh(filename="umesh.vtk",library='moab')
surf1 = openmc.Sphere(r=50000, boundary_type="vacuum")
region1 = -surf1
cell1 = openmc.Cell(region=region1)
my_geometry = openmc.Geometry([cell1])
my_source = openmc.IndependentSource()
my_source.angle = openmc.stats.Isotropic()
my_source.energy = openmc.stats.Discrete([14e6], [1])
# link to docs for MeshSpatial
# https://docs.openmc.org/en/latest/pythonapi/generated/openmc.stats.MeshSpatial.html
# allows us to apply the same source to each element in the mesh. The source can be varied in terms of strength
my_source.space = openmc.stats.MeshSpatial(
mesh=umesh,
#we set the strengths to sum to 1 to make post processing easier.
# in a more accurate plasma source the strength could be adjusted based on the source position.
strengths=[1/1104]*1104,
volume_normalized=False
)
my_settings = openmc.Settings()
my_settings.batches = 10
my_settings.particles = 1000
my_settings.run_mode = "fixed source"
my_settings.source = my_source
model = openmc.model.Model(my_geometry, None, my_settings )
model.run()
# plotting the mesh source
plot = plot_source_position([my_source], n_samples=10000)
plot.show()
Info : Meshing 1D...
Info : [ 0%] Meshing curve 2 (BSpline)
Info : [ 0%] Meshing curve 1 (Circle)
Info : [ 0%] Meshing curve 3 (BSpline)
Info : Done meshing 1D (Wall 0.017366s, CPU 0.050845s)
Info : Meshing 2D...
Info : [ 0%] Meshing surface 1 (Surface of Revolution, MeshAdapt)
Info : [ 0%] Meshing surface 3 (Plane, MeshAdapt)
Info : [ 0%] Meshing surface 2 (Plane, MeshAdapt)
Info : Done meshing 2D (Wall 0.66587s, CPU 0.687939s)
Info : Meshing 3D...
Info : 3D Meshing 1 volume with 1 connected component
Info : Tetrahedrizing 308 nodes...
Info : Done tetrahedrizing 316 nodes (Wall 0.00440903s, CPU 0.018586s)
Info : Reconstructing mesh...
Info : - Creating surface mesh
Info : - Identifying boundary edges
Info : - Recovering boundary
Info : Done reconstructing mesh (Wall 0.0150432s, CPU 0.026683s)
Info : Found volume 1
Info : It. 0 - 0 nodes created - worst tet radius 1.62031 (nodes removed 0 0)
Info : 3D refinement terminated (356 nodes total):
Info : - 0 Delaunay cavities modified for star shapeness
Info : - 0 nodes could not be inserted
Info : - 1132 tetrahedra created in 0.00353091 sec. (320596 tets/s)
Info : 0 node relocations
Info : Done meshing 3D (Wall 0.0324507s, CPU 0.042469s)
Info : Optimizing mesh...
Info : Optimizing volume 1
Info : Optimization starts (volume = 1.78813e+08) with worst = 0.0368935 / average = 0.73221:
Info : 0.00 < quality < 0.10 : 7 elements
Info : 0.10 < quality < 0.20 : 13 elements
Info : 0.20 < quality < 0.30 : 13 elements
Info : 0.30 < quality < 0.40 : 17 elements
Info : 0.40 < quality < 0.50 : 31 elements
Info : 0.50 < quality < 0.60 : 85 elements
Info : 0.60 < quality < 0.70 : 187 elements
Info : 0.70 < quality < 0.80 : 380 elements
Info : 0.80 < quality < 0.90 : 301 elements
Info : 0.90 < quality < 1.00 : 98 elements
Info : 30 edge swaps, 0 node relocations (volume = 1.78813e+08): worst = 0.231078 / average = 0.748829 (Wall 0.000957333s, CPU 0s)
Info : No ill-shaped tets in the mesh :-)
Info : 0.00 < quality < 0.10 : 0 elements
Info : 0.10 < quality < 0.20 : 0 elements
Info : 0.20 < quality < 0.30 : 1 elements
Info : 0.30 < quality < 0.40 : 17 elements
Info : 0.40 < quality < 0.50 : 27 elements
Info : 0.50 < quality < 0.60 : 87 elements
Info : 0.60 < quality < 0.70 : 194 elements
Info : 0.70 < quality < 0.80 : 377 elements
Info : 0.80 < quality < 0.90 : 303 elements
Info : 0.90 < quality < 1.00 : 98 elements
Info : Done optimizing mesh (Wall 0.00254671s, CPU 0.000787s)
Info : 356 nodes 1767 elements
Info : Writing 'umesh.vtk'...
Info : Done writing 'umesh.vtk'
%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
############### %%%%%%%%%%%%%%%%%%%%%%%%
################## %%%%%%%%%%%%%%%%%%%%%%%
################### %%%%%%%%%%%%%%%%%%%%%%%
#################### %%%%%%%%%%%%%%%%%%%%%%
##################### %%%%%%%%%%%%%%%%%%%%%
###################### %%%%%%%%%%%%%%%%%%%%
####################### %%%%%%%%%%%%%%%%%%
####################### %%%%%%%%%%%%%%%%%
###################### %%%%%%%%%%%%%%%%%
#################### %%%%%%%%%%%%%%%%%
################# %%%%%%%%%%%%%%%%%
############### %%%%%%%%%%%%%%%%
############ %%%%%%%%%%%%%%%
######## %%%%%%%%%%%%%%
%%%%%%%%%%%
| The OpenMC Monte Carlo Code
Copyright | 2011-2025 MIT, UChicago Argonne LLC, and contributors
License | https://docs.openmc.org/en/latest/license.html
Version | 0.15.3-dev233
Commit Hash | 6cf0eac20578463a6d5aea3be55774488015211e
Date/Time | 2025-08-02 09:10:34
OpenMP Threads | 4
Reading model XML file 'model.xml' ...
Reading cross sections XML file...
Minimum neutron data temperature: 1.7976931348623157e+308 K
Maximum neutron data temperature: 0.0 K
Preparing distributed cell instances...
Writing summary.h5 file...
===============> FIXED SOURCE TRANSPORT SIMULATION <===============
Simulating batch 1
Simulating batch 2
Simulating batch 3
Simulating batch 4
Simulating batch 5
Simulating batch 6
Simulating batch 7
Simulating batch 8
Simulating batch 9
Simulating batch 10
Creating state point statepoint.10.h5...
=======================> TIMING STATISTICS <=======================
Total time for initialization = 1.1334e-02 seconds
Reading cross sections = 1.7022e-05 seconds
Total time in simulation = 1.2005e-02 seconds
Time in transport only = 5.6661e-03 seconds
Time in active batches = 1.2005e-02 seconds
Time accumulating tallies = 1.8550e-06 seconds
Time writing statepoints = 5.9965e-03 seconds
Total time for finalization = 9.7200e-07 seconds
Total time elapsed = 2.3481e-02 seconds
Calculation Rate (active) = 832986.0 particles/second
============================> RESULTS <============================
Leakage Fraction = 1.00000 +/- 0.00000