You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a TreeMesh, if we access the cell_centers attribute before we finalize the mesh we end up getting an invalid mesh with an empty array for the cell_centers after we do finalize it.
The following example works as expected and a valid mesh is created:
importnumpyasnpimportdiscretize# Minimum cell widthsdx, dy=5, 5# Mesh lengths along each directionx_length, y_length=300.0, 300.0# Compute number of base mesh cells required in x and ynbcx=2**int(np.round(np.log2(x_length/dx)))
nbcy=2**int(np.round(np.log2(y_length/dy)))
# Define the base meshhx= [(dx, nbcx)]
hy= [(dy, nbcy)]
mesh=discretize.TreeMesh([hx, hy], x0="CC")
# Refine near pointsxx=np.array([0.0, 10.0, 0.0, -10.0])
yy=np.array([-20.0, -10.0, 0.0, -10])
pts=np.c_[discretize.utils.mkvc(xx), discretize.utils.mkvc(yy)]
mesh=discretize.utils.refine_tree_xyz(
mesh, pts, octree_levels=[2, 2], method="radial", finalize=False
)
mesh.finalize()
print(mesh)
print("\nSize of cell_centers:", mesh.cell_centers.size)
QuadTreeMesh: 4.64% filled
Level : Number of cells Mesh Extent Cell Widths
----------------------- min , max min , max
2 : 4 --------------------------- --------------------
3 : 34 x: -160.0 , 160.0 5.0 , 80.0
4 : 36 y: -160.0 , 160.0 5.0 , 80.0
5 : 68
6 : 48
-----------------------
Total : 190
Size of cell_centers: 380
But if we access mesh.cell_centers before running mesh.finalize(), the mesh.cell_centers array is empty, making impossible to use this mesh in any further step (inversion, plotting, etc).
importnumpyasnpimportdiscretize# Minimum cell widthsdx, dy=5, 5# Mesh lengths along each directionx_length, y_length=300.0, 300.0# Compute number of base mesh cells required in x and ynbcx=2**int(np.round(np.log2(x_length/dx)))
nbcy=2**int(np.round(np.log2(y_length/dy)))
# Define the base meshhx= [(dx, nbcx)]
hy= [(dy, nbcy)]
mesh=discretize.TreeMesh([hx, hy], x0="CC")
# Refine near pointsxx=np.array([0.0, 10.0, 0.0, -10.0])
yy=np.array([-20.0, -10.0, 0.0, -10])
pts=np.c_[discretize.utils.mkvc(xx), discretize.utils.mkvc(yy)]
mesh=discretize.utils.refine_tree_xyz(
mesh, pts, octree_levels=[2, 2], method="radial", finalize=False
)
print(mesh.cell_centers)
mesh.finalize()
print(mesh)
print("\nSize of cell_centers:", mesh.cell_centers.size)
[]
QuadTreeMesh: 4.64% filled
Level : Number of cells Mesh Extent Cell Widths
----------------------- min , max min , max
2 : 4 --------------------------- --------------------
3 : 34 x: -160.0 , 160.0 5.0 , 80.0
4 : 36 y: -160.0 , 160.0 5.0 , 80.0
5 : 68
6 : 48
-----------------------
Total : 190
Size of cell_centers: 0
When creating a
TreeMesh
, if we access thecell_centers
attribute before we finalize the mesh we end up getting an invalid mesh with an empty array for thecell_centers
after we do finalize it.The following example works as expected and a valid mesh is created:
But if we access
mesh.cell_centers
before runningmesh.finalize()
, themesh.cell_centers
array is empty, making impossible to use this mesh in any further step (inversion, plotting, etc).cc @lheagy
The text was updated successfully, but these errors were encountered: