Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cell state not preserved with negative cell sizes #345

Open
domfournier opened this issue Dec 14, 2023 · 3 comments
Open

Cell state not preserved with negative cell sizes #345

domfournier opened this issue Dec 14, 2023 · 3 comments

Comments

@domfournier
Copy link
Contributor

domfournier commented Dec 14, 2023

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

@jcapriot
Copy link
Member

Interesting, there must be some missing logic wrapping around negative levels when not all cell width arrays have the same length.

@jcapriot
Copy link
Member

Also… why are you using negative cell widths?

We should probably make the meshes error on this case due to undefined behavior.

@domfournier
Copy link
Contributor Author

Came about while testing the conversion between the octrees stored in geoh5 from and to discretize. GA can deal with either positive or negative cell sizes , so it made sense to check.

I can just block the conversion if it happens for now - no big deal. Just thought I would flat it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants