Skip to content

Cell state not preserved with negative cell sizes #345

@domfournier

Description

@domfournier

This minimal example demonstrates the issue. The cell state appears not preserved if the cell size is negative.

image

from discretize import TreeMesh
import numpy as np

point = [0, 0, 0]

# All positive cell sizes
mesh = TreeMesh([[10] * 16, [10] * 4, [10] * 8], [0, 0, 0])
mesh.insert_cells(point, [3], finalize=True)

# New mesh using state of first
mesh2 = TreeMesh([[10] * 16, [10] * 4, [10] * 8], [0, 0, 0])
mesh2.__setstate__((mesh.cell_state['indexes'], mesh.cell_state['levels']))

assert np.all(mesh.cell_centers == mesh2.cell_centers)  # Both meshes are equal

# Repeat with negative z cell size
mesh = TreeMesh([[10] * 16, [10] * 4, [-10] * 8], [0, 0, 0])
mesh.insert_cells(point, [3], finalize=True)

# New mesh using state of first
mesh2 = TreeMesh([[10] * 16, [10] * 4, [-10] * 8], [0, 0, 0])
mesh2.__setstate__((mesh.cell_state['indexes'], mesh.cell_state['levels']))

assert np.all(mesh.cell_centers == mesh2.cell_centers)  # Not equal

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions