Skip to content

Commit

Permalink
Set no diagonal balance when reading UBC tree meshes
Browse files Browse the repository at this point in the history
Set `diagonal_balance=False` when creating a TreeMesh after reading
a UBC file in `read_UBC`. This prevents raising the future warning
related to the default value of `diagonal_balance`. Add test that checks
that no warning is being raised by that method.
  • Loading branch information
santisoler committed Nov 20, 2024
1 parent 8d780d2 commit fee12b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion discretize/mixins/mesh_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def read_UBC(TreeMesh, file_name, directory=None):
else:
max_level = min(ls) + 1

mesh = TreeMesh(hs, origin=origin)
mesh = TreeMesh(hs, origin=origin, diagonal_balance=False)
levels = indArr[:, -1]
indArr = indArr[:, :-1]

Expand Down
14 changes: 14 additions & 0 deletions tests/tree/test_tree_io.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
import numpy as np
import discretize
import pickle
Expand Down Expand Up @@ -49,6 +50,19 @@ def test_UBCfiles(mesh, tmp_path):
np.testing.assert_array_equal(vec, vecUBC2)


def test_ubc_files_no_warning_diagonal_balance(mesh, tmp_path):
"""
Test that reading UBC files don't trigger the diagonal balance warning.
"""
# Save the sample mesh into a UBC file
fname = tmp_path / "temp.msh"
mesh.write_UBC(fname)
# Make sure that no warning is raised when reading the mesh
with warnings.catch_warnings():
warnings.simplefilter("error")
discretize.TreeMesh.read_UBC(fname)


if has_vtk:

def test_write_VTU_files(mesh, tmp_path):
Expand Down

0 comments on commit fee12b5

Please sign in to comment.