Hello everyone,
I have just started familiarising myself with SimPEG and looking at its FDEM forward modelling capabilities. I have been exploring examples that use a cylindrical mesh for such problems (thank you for those!). I am now looking at using tree meshes because it seems to provide greater flexibility in mesh structure. I came across the function ‘mesh_builder_xyz’ in the discretize utils package, which builds a tensor mesh based on the input points. When I change the mesh_type to ‘tree’, it throws an error. I realised this error occurred because the resulting mesh has no cell centres or cell faces (when printing mesh.nC
and mesh.nF
). Would anyone be able to shed some light on what the reason could be?
Thank you!
Code:
import discretize
import matplotlib.pyplot as plt
import numpy as np
xyLoc = np.random.randn(8,2)
mesh = discretize.utils.meshutils.mesh_builder_xyz(
xyLoc, [0.1, 0.1], depth_core=0.5,
padding_distance=[[1,2], [1,0]],
mesh_type='tree',
)
print(mesh.nC,mesh.nF)
axs = plt.subplot()
mesh.plotImage(mesh.vol, grid=True, ax=axs)
axs.scatter(xyLoc[:,0], xyLoc[:,1], 15, c='w', zorder=3)
axs.set_aspect('equal')
plt.show()
Kind regards,
Radhika
I do not know about the bahavior of the mesh_builder_xyz
with TreeMesh
. But if you have not already, you can check the tutorials on Mesh Generation available in the documentation for help: http://discretize.simpeg.xyz/en/master/tutorials/mesh_generation/index.html
Hi @RadhikaF,
Sorry for the late reply.
Tree meshes require to be refined in order to have cells.
You either refine globally using the mesh.refine(int(value))
, or with more advanced options using: http://discretize.simpeg.xyz/en/master/api/generated/discretize.utils.refine_tree_xyz.html?highlight=refine_tree_xyz#discretize-utils-refine-tree-xyz
Here is your example with the refine call added:
xyLoc = np.random.randn(8,2)
mesh = discretize.utils.meshutils.mesh_builder_xyz(
xyLoc, [0.1, 0.1], depth_core=0.5,
padding_distance=[[1,2], [1,0]],
mesh_type='tree',
)
mesh = discretize.utils.refine_tree_xyz(mesh, xyLoc, finalize=True)
print(mesh.nC,mesh.nF)
axs = plt.subplot()
mesh.plotImage(mesh.vol, grid=True, ax=axs)
axs.scatter(xyLoc[:,0], xyLoc[:,1], 15, c='w', zorder=3)
axs.set_aspect('equal')
plt.show()
!! IMPORTANT !!
You can refine the mesh mulitple times, but the finalize
call must only be called ONCE at the end.
Best.
1 Like
Thank you very much @domfournier and @thibaut.astic!
I wasn’t aware of that requirement so thank you for the clarification. Also, apologies for the late reply; I have been away for the past couple of weeks.
Best regards,
Radhika
1 Like