Open rowanc1 opened 7 years ago
A gotcha would be the pointer code if you are not on the lowest level.
Should error in the M._cc2i
lookup if the cell does not exist.
you will have to step by the gap in ptr_ij = [ptr[0] + nx, ptr[1] + ny, ptr[2]]
line
You could change the enumerate(range(MT.nCy*level_from_bottom)[::level_from_bottom])
as a quick hack.
i.e. level from bottom in this case is 1
I am sure @jcapriot will have a better trick, but this would avoid looping and using built-in C functions:
hc = [h[0] for h in mesh.h]
core_cells = mesh.cell_volumes == mesh.cell_volumes.min()
min_locs = np.min(mesh.cell_centers[core_cells, :], axis=0)
max_locs = np.max(mesh.cell_centers[core_cells, :], axis=0)
nc = ((max_locs - min_locs) / hc + 1).astype(int) # Could always add option to bufffer out
tensor = TensorMesh(
[np.ones(c)*h for c, h in zip(nc, hc)],
x0=min_locs - hc/2
)
ind = mesh._get_containing_cell_indexes(tensor.cell_centers)
Here is my own take at this, I interpolate to the base tensor mesh and use the extract_core_mesh
utils.
from discretize import TensorMesh, TreeMesh
from discretize import utils as dsutils
import numpy as np
# original tree mesh
mesh = TreeMesh.read_UBC('./mesh.msh')
recovered_model = np.load('./recovered_model.npy')
#define core area
xyzlim = np.c_[
[-200,+200],
[-200,+200],
[-100,+100],
].T
# create base tensormesh
tensormesh = TensorMesh(mesh.h)
tensormesh.x0 = mesh.x0
#extract core mesh
actcore, meshcore = dsutils.extract_core_mesh(xyzlim,tensormesh)
# interpolate tree mesh model to tensormesh
Fmodel = NearestNDInterpolator(mesh.gridCC,recovered_model)
modelcore = Fmodel(meshcore.gridCC)
The plotting for an octree is insanely slow. There is also some times that you want to work with a core mesh as a tensor mesh. This requires you to extract pieces and use those.
A quick sketch of the algorithm in 2D is something like:
And then you can plot it:
Would need a bunch of error checking, and extensions to 3D to make this robust.
cc @micmitch