fusion-energy / openmc_regular_mesh_plotter

A Python package for plotting OpenMC regular mesh tally results with underlying geometry from neutronics simulations.
MIT License
9 stars 1 forks source link

Does this support openmc.CylindricalMesh filter? #29

Closed RemDelaporteMathurin closed 10 months ago

RemDelaporteMathurin commented 2 years ago

Please... Please...

Don't tell me we need a package called cylindrical_mesh_plotter

😭

shimwell commented 2 years ago

This package was made before CylindricalMesh exited so it doesn't support it.

CylindricalMesh could be added, I guess we should rename it openmc-mesh-plotter at that point but perhaps best to add the feature first and see how it goes.

RemDelaporteMathurin commented 2 years ago
def reshape_values_to_mesh_shape(tally, values):
    mesh_filter = tally.find_filter(filter_type=openmc.MeshFilter)
    # shape = mesh_filter.mesh.dimension.tolist()
    shape = [
        len(mesh_filter.mesh.r_grid) - 1,
        len(mesh_filter.mesh.phi_grid) - 1,
        len(mesh_filter.mesh.z_grid) - 1,
    ]
    # 2d mesh has a shape in the form [1, 400, 400]
    if 1 in shape:
        shape.remove(1)
    return values.reshape(shape)

def get_tally_extent(tally):

    for filter in tally.filters:
        if isinstance(filter, openmc.MeshFilter):
            mesh_filter = filter

    extent_x = (
        min(mesh_filter.mesh.r_grid),
        max(mesh_filter.mesh.r_grid),
    )
    extent_y = (
        min(mesh_filter.mesh.phi_grid),
        max(mesh_filter.mesh.phi_grid),
    )
    extent_z = (
        min(mesh_filter.mesh.z_grid),
        max(mesh_filter.mesh.z_grid),
    )
    shape = [
        len(mesh_filter.mesh.r_grid) - 1,
        len(mesh_filter.mesh.phi_grid) - 1,
        len(mesh_filter.mesh.z_grid) - 1,
    ]
    if 1 in shape:
        print("2d mesh tally")
        index_of_1d = shape.index(1)
        print("index", index_of_1d)
        if index_of_1d == 0:
            return extent_y + extent_z
        if index_of_1d == 1:
            return extent_x + extent_z
        if index_of_1d == 2:
            return extent_x + extent_y
    return None

@shimwell when dealing with a CylindricalMesh instead of a RegularMesh, these two functions need to be updated in order for the plot to work (tested locally)

shimwell commented 10 months ago

there is another package openmc-cylinderical-mesh-plotter that solves this