Example #1
0
mesh = TreeMesh([h, h])

# Define corner points for rectangular box
xp, yp = np.meshgrid([120., 240.], [80., 160.])
xy = np.c_[mkvc(xp), mkvc(yp)]  # mkvc creates vectors

# Discretize to finest cell size within rectangular box
mesh = refine_tree_xyz(mesh,
                       xy,
                       octree_levels=[2, 2],
                       method='box',
                       finalize=False)

mesh.finalize()  # Must finalize tree mesh before use

mesh.plotGrid(show_it=True)

###############################################
# Intermediate Example and Plotting
# ---------------------------------
#
# The widths of the base mesh cells do not need to be the same in x and y.
# However the number of base mesh cells in x and y each needs to be a power of 2.
#
# Here we show topography-based mesh refinement and refinement about a
# set of points. We also show some aspect of customizing plots. We use the
# keyword argument *octree_levels* to define the rate of cell width increase
# relative to our surface and the set of discrete points about which we are
# refining.
#
Example #2
0
# Compute number of base mesh cells required in x and y
nbcx = 2**int(np.round(np.log(x_length / dx) / np.log(2.)))
nbcy = 2**int(np.round(np.log(y_length / dy) / np.log(2.)))

# Define the base mesh
hx = [(dx, nbcx)]
hy = [(dy, nbcy)]
M = TreeMesh([hx, hy], x0='CC')

# Refine mesh near points
xx = np.linspace(-10000, 10000, 3000)
yy = 400 * np.sin((2 * xx * np.pi) / 1000)
pts = np.c_[mkvc(xx), mkvc(yy)]
M = refine_tree_xyz(M,
                    pts,
                    octree_levels=[2, 2],
                    method='radial',
                    finalize=False)

M.finalize()
print("\n the mesh has {} cells".format(M))
ccMesh = M.gridCC
print('indices:', np.size(ccMesh))

# We can apply the plotGrid method and output to a specified axes object
fig = plt.figure(figsize=(6, 6))
ax = fig.add_subplot(111)
M.plotGrid(ax=ax)
ax.set_xbound(M.x0[0], M.x0[0] + np.sum(M.hx))
ax.set_ybound(M.x0[1], M.x0[1] + np.sum(M.hy))
ax.set_title('QuadTree Mesh')