Add surface conditions to DAGMC geometry

I just began working on modeling CAD in OpenMC using DAGMC, but I run into an issue when modeling. I am currently downloading STP files and converting to h5m for use in OpenMC, and do not know how to assign a value for boundary type.

As of right now, I get the error: no boundary conditions were assigned to any surface

Have not found a way to fix it yet, any help greatly appreciated.

You might find this approach useful, it builds the bounding surface and assigns the boundary type automatically to surround the dagmc geometry

bound_dag_univ = openmc.DAGMCUniverse(filename='dagmc.h5m').bounded_universe()
my_geometry = openmc.Geometry(root=bound_dag_univ)

HI Shimwell,

That approach sounds interesting. Is the bounded universe able to fit exactly to the geometry or “only” as spehere or box shape? Eg, could one add several step/dagmc-files each representing a component in your aseembly, separately to the geometry and use the bounded_universe() to be able to get a cell-tally for each component?

Hey thank you for the quick reply. When I do this, it almost seems like my DAGMC geometry disappears as I can no longer plot it.

When I use this format:
dagmc_univ = openmc.DAGMCUniverse(filename=“dagmc.h5m”)
dagmc_univ.bounding_region(bounded_type = ‘box’,boundary_type=‘vacuum’)
geometry = openmc.Geometry(root=dagmc_univ)
geometry.export_to_xml()

I still get the same error as before, and I do not see any bounding region in the plot. It seems like this way doesn’t actually register a bounding box with any surface

Hi @bhelpling1 the dagmc geometry is still there it is just inside a box of 6 surfaces. You might need to slice the geometry in the middle of the geometry to see the DAGMC parts. On that topic I have a little plotting app that I just upgraded to accept DAGMC geometry and it defaults to slicing through the middle of the bounding box.

You can of course do the combined universe in the manner you are describing, I was just trying to save you a few lines.

longer method

# makes use of the dagmc geometry
dag_univ = openmc.DAGMCUniverse("dagmc.h5m")

# creates an edge of universe boundary at a large radius
vac_surf = openmc.Sphere(r=10000, surface_id=9999, boundary_type="vacuum")

# specifies the region as below the universe boundary
region = -vac_surf

# creates a cell from the region and fills the cell with the dagmc geometry
containing_cell = openmc.Cell(cell_id=9999, region=region, fill=dag_univ)

model = openmc.Model()
model.geometry = openmc.Geometry(root=[containing_cell])

shorter method

# loads up dagmc file and automatically bounds the geometry with a vacuum surface
bound_dag_univ= openmc.DAGMCUniverse("dagmc.h5m").bounded_universe()

model = openmc.Model()
model.geometry = openmc.Geometry(root=bound_dag_univ)

Thank you very much, @Shimwell I will see if this helps. I also have one more question that likely just comes down to me having a limited knowledge of the topic. So is the dagmc.h5m file meant to be a mesh file or is it ok to generate it directly from a solid CAD geometry? I know that I can make a mesh from CAD using Cubit, but what actually is the difference between the two in this application?

Edit: The code you provided fixed my problem and I am now able to run the sim.
RuntimeError: Maximum number of lost particles has been reached. WARNING: No intersection found with DAGMC cell 1, material 1

I am still not sure exactly where this comes from. It seems that the cad_to_dagmc package is capable of meshing the structure itself, but maybe it is running into issues with this shape as it is quite detailed. Any recommendations or thoughts?

Attached below is what I have so far, aside from my source which is just a simple neutron point source.

Aluminum = openmc.Material(name='aluminum') 
Aluminum.add_element('Al', 1, percent_type='ao')
Aluminum.set_density('g/cm3', 2.7)

air = openmc.Material(name='air')
air.set_density('g/cc', 0.001205)
air.add_element('N', 0.784431)
air.add_element('O', 0.210748)
air.add_element('Ar',0.0046)

mats = openmc.Materials()
mats.append(Aluminum)
mats.append(air)
mats.export_to_xml()

my_model = CadToDagmc();
my_model.add_stp_file("DP5 Vertical Mount_V8.STEP", material_tags=['aluminum']);
my_model.export_dagmc_h5m_file();

dag_univ = openmc.DAGMCUniverse(filename = 'dagmc.h5m')

# creates an edge of universe boundary at a large radius
vac_surf = openmc.Sphere(r=10000, surface_id=9999, boundary_type="vacuum")

# specifies the region as below the universe boundary
region = -vac_surf

# creates a cell from the region and fills the cell with the dagmc geometry
containing_cell = openmc.Cell(cell_id=9999, region=region, fill=dag_univ)

model = openmc.Model()
model.geometry = openmc.Geometry(root=[containing_cell])
model.geometry.export_to_xml()

mesh = openmc.RegularMesh().from_domain(
    model.geometry, # the corners of the mesh are being set automatically to surround the geometry
    dimension=[100, 100, 100] 
)

tallies = openmc.Tallies()
# Create mesh filter for tally
mesh_filter = openmc.MeshFilter(mesh)

# Create mesh tally to score neutron absorption
mesh_tally_1 = openmc.Tally(name='absorption')
mesh_tally_1.filters = [mesh_filter]
mesh_tally_1.scores = ['absorption']
tallies.append(mesh_tally_1)

# Create mesh tally to score scattering
mesh_tally_2 = openmc.Tally(name='scattering')
mesh_tally_2.filters = [mesh_filter]
mesh_tally_2.scores = ['scatter']
tallies.append(mesh_tally_2)
tallies.export_to_xml()

mesh_tally_3 = openmc.Tally(name='flux')
mesh_tally_3.filters = [mesh_filter]
mesh_tally_3.scores = ['flux']
tallies.append(mesh_tally_3)
tallies.export_to_xml()


p = openmc.Plot()
p.width = (300.0, 300.0)
p.origin = (10,0,0)
p.pixels = (400, 400)
p.basis = 'yz'
openmc.plot_inline(p)

image

@maarten

The approach puts a sphere or box around the DAGMC bounding box. So it would fit around a single DAGMC geometry.

This sort of error could be a bug with the meshing step like you say. It could also be caused by the CAD geometry not being “clean”. One of the tricky parts of the DAGMC workflow is cleaning the cad to remove any geometry errors. I’m not sure where your CAD came from but it might require some manual fixing.

The DAGMC group might have tips for you