Skip to content

Commit

Permalink
lib
Browse files Browse the repository at this point in the history
  • Loading branch information
shimwell committed Mar 29, 2024
1 parent fa7c52c commit 50211d4
Showing 1 changed file with 38 additions and 58 deletions.
96 changes: 38 additions & 58 deletions tasks/task_04_make_sources/6_unstructured_mesh_source.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# from cad_to_dagmc import CadToDagmc
from cad_to_dagmc import CadToDagmc

# my_model = CadToDagmc()
my_model = CadToDagmc()

# my_model.add_stp_file('plasma_simplified_180.step')
my_model.add_stp_file('plasma_simplified_180.step')
# import gmsh
# gmsh.initialize()

# my_model.export_unstructured_mesh_file(filename="umesh.h5m", max_mesh_size=100, min_mesh_size=10)
gmshm = my_model.export_unstructured_mesh_file(filename="umesh.h5m", max_mesh_size=100, min_mesh_size=10)

# perhaps trimesh can get volumes
# import trimesh
Expand All @@ -13,82 +15,60 @@


import openmc
import openmc.lib

openmc.config['cross_sections'] = '/home/j/endf-b8.0-hdf5/endfb-viii.0-hdf5/cross_sections.xml'

umesh = openmc.UnstructuredMesh(filename="umesh.h5m",library='moab')

####

mesh_filter = openmc.MeshFilter(umesh)
tally = openmc.Tally(name="unstrucutred_mesh_tally")
tally.filters = [mesh_filter]
tally.scores = ["flux"]
tally.estimator = "tracklength"
my_tallies = openmc.Tallies([tally])

mat1 = openmc.Material()
mat1.add_nuclide("H1", 1, percent_type="ao")
mat1.set_density("g/cm3", 0.001)
my_materials = openmc.Materials([mat1])

surf1 = openmc.Sphere(r=50000, 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 = 1
my_settings.inactive = 0
my_settings.particles = 1
my_settings.run_mode = "fixed source"

# Create a DT point 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)
all_sources = [my_source] * 1767
mesh_source = openmc.MeshSource(
mesh=umesh,
sources=all_sources,
)

tally_result = sp.get_tally(name="unstrucutred_mesh_tally")
my_settings = openmc.Settings()
my_settings.batches = 1
my_settings.particles = 1
my_settings.run_mode = "fixed source"
my_settings.source = mesh_source

# normally with regular meshes I would get the mesh from the tally
# but with unstrucutred meshes the tally does not contain the mesh
# however we can get it from the statepoint file
# umesh = tally_result.find_filter(openmc.MeshFilter)
umesh_from_sp = sp.meshes[1]
model = openmc.model.Model(my_geometry, None, my_settings )
model.export_to_model_xml()

# these trigger internal code in the mesh object so that its centroids and volumes become known.
# centroids and volumes are needed for the get_values and write_data_to_vtk steps
centroids = umesh_from_sp.centroids
mesh_vols = umesh_from_sp.volumes
openmc.lib.init()
# umesh_full = openmc.lib.meshes[umesh.id]
# openmc.lib.UnstructuredMesh()

#### end of code needed due to umesh not loading

all_sources = []
all_strengths = []
for volume, centroid in zip(centroids, mesh_vols):
my_source = openmc.IndependentSource()
my_source.angle = openmc.stats.Isotropic()
# the energy could be based on location of centroid
my_source.energy = openmc.stats.Discrete([14e6], [1])
# the energy could be based on location of centroid and volume
my_source.strength=1
all_strengths.append(mesh_vols)
# all_sources = []
# all_strengths = []
# for volume, centroid in zip(centroids, mesh_vols):
# my_source = openmc.IndependentSource()
# my_source.angle = openmc.stats.Isotropic()
# # the energy could be based on location of centroid
# my_source.energy = openmc.stats.Discrete([14e6], [1])
# # the energy could be based on location of centroid and volume
# my_source.strength=1
# all_strengths.append(mesh_vols)

mesh_source = openmc.MeshSource(
mesh=umesh,
sources=all_sources,
)
# mesh_source = openmc.MeshSource(
# mesh=umesh,
# sources=all_sources,
# )

mesh_source.normalize_source_strengths()
# mesh_source.normalize_source_strengths()

# https://github.com/fusion-energy/cad_to_dagmc/blob/main/examples/unstrucutred_volume_mesh/simulate_unstrucutred_volume_mesh_with_openmc.py
# # https://github.com/fusion-energy/cad_to_dagmc/blob/main/examples/unstrucutred_volume_mesh/simulate_unstrucutred_volume_mesh_with_openmc.py

0 comments on commit 50211d4

Please sign in to comment.