From 50211d4c8a2f659ef5b5c31c3efc529eaddc588a Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 29 Mar 2024 18:05:09 +0000 Subject: [PATCH] lib --- .../6_unstructured_mesh_source.py | 96 ++++++++----------- 1 file changed, 38 insertions(+), 58 deletions(-) diff --git a/tasks/task_04_make_sources/6_unstructured_mesh_source.py b/tasks/task_04_make_sources/6_unstructured_mesh_source.py index b42d7f2..bded620 100644 --- a/tasks/task_04_make_sources/6_unstructured_mesh_source.py +++ b/tasks/task_04_make_sources/6_unstructured_mesh_source.py @@ -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 @@ -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 \ No newline at end of file +# # https://github.com/fusion-energy/cad_to_dagmc/blob/main/examples/unstrucutred_volume_mesh/simulate_unstrucutred_volume_mesh_with_openmc.py \ No newline at end of file