fusion-energy / openmc-dagmc-wrapper

A Python package that extends OpenMC base classes to provide convenience features and standardized tallies when simulating DAGMC geometry with OpenMC.
https://openmc-dagmc-wrapper.readthedocs.io/
MIT License
7 stars 2 forks source link

MeshTally2D.mesh_resolution order is reversed #68

Closed RemDelaporteMathurin closed 2 years ago

RemDelaporteMathurin commented 2 years ago

https://github.com/fusion-energy/openmc-dagmc-wrapper/blob/f0908be8d708f416ec5e1c02c1dad84bdda2b329/openmc_dagmc_wrapper/Tally.py#L329-L349

It would make more sense if the order in mesh_resolution was the same as in plane ('xz', 'xy', or 'yz')

RemDelaporteMathurin commented 2 years ago

To reproduce:

import openmc
import openmc_dagmc_wrapper as odw
import openmc_plasma_source as ops
from dagmc_bounding_box import DagmcBoundingBox
from openmc_mesh_tally_to_vtk import write_mesh_tally_to_vtk

# could set to dagmc.h5m if the imprinted and merged geometry is preferred
my_h5m_filename = "dagmc.h5m"

material_tag_to_material_dict = {
    "mat1": "copper"
}

materials = odw.Materials(
    h5m_filename=my_h5m_filename,
    correspondence_dict=material_tag_to_material_dict,
)

geometry = odw.Geometry(h5m_filename=my_h5m_filename)

tally1 = odw.MeshTally2D(
    mesh_resolution=(10, 20),
    bounding_box=DagmcBoundingBox(my_h5m_filename).corners(),
    tally_type="(n,Xa)",
    plane="xy"
)

settings = odw.FusionSettings()
settings.batches = 4
settings.particles = 10000
# assigns a ring source of DT energy neutrons to the source using the
# openmc_plasma_source package
settings.source = ops.FusionRingSource(fuel="DT", radius=350)

my_model = openmc.Model(
    materials=materials, geometry=geometry, settings=settings, tallies=[tally1]
)

# starts the simulation
statepoint_file = my_model.run()

print(f'neutronics results are saved in {statepoint_file}')

statepoint = openmc.StatePoint(filepath="statepoint.4.h5")

# assumes the statepoint file has a RegularMesh tally with a certain name
my_tally = statepoint.get_tally(name=tally1.name)

# converts the tally result into a VTK file
write_mesh_tally_to_vtk(
    tally=my_tally,
    filename="vtk_file_from_openmc_mesh.vtk",
)

dagmc.zip

RemDelaporteMathurin commented 2 years ago

The code above produces: image

On the image, the high resolution is in the X direction whereas the tally resolution is (10, 20).

shimwell commented 2 years ago

Oh nice find, i think I have suffered from this bug without realizing. Perhaps we can add a test to check for this. I assume OpenMC orientation and Paraview orientation match up

RemDelaporteMathurin commented 2 years ago

I've added a test that checks the mesh.dimension attribute. See #93