inducer / meshpy

2D/3D simplicial mesh generator interface for Python (Triangle, TetGen, gmsh)
http://mathema.tician.de/software/meshpy
Other
517 stars 108 forks source link

Refine tetrahedral mesh #60

Open RubenZubrov opened 3 years ago

RubenZubrov commented 3 years ago

Hi, Thanks for such a good package. I'm using windows10:MeshPy‑2020.1 I'm trying to refine existing tetrahedral mesh by inserting additional points ('-i'). In https://documen.tician.de/meshpy/tri-tet.html it is said that paramteter insert_points – a MeshInfo object specifying additional points to be inserted. However, using the insert_point parameter does not give the expected result (the number of points in the grid does not change).

I use the following code:

import meshpy.tet as tet
import numpy as np

facets = [[0, 4, 5], [0, 3, 4], [0, 1, 3], [1, 2, 3], [1, 2, 8], [1, 7, 8], [2, 3, 9], [2, 8, 9],
          [3, 4, 10], [3, 9, 10], [4, 5, 11], [4, 10, 11], [0, 5, 11], [0, 6, 11], [0, 1, 6], [1, 6, 7],
          [6, 10, 11], [6, 9, 10], [6, 7, 9], [7, 8, 9]]

nodes = [[0., 0., 0.], [4., 0., 0.], [4., 2., 0.], [2., 2., 0.], [2., 6., 0.], [0., 6., 0.],
         [0., 0., 2.], [4., 0., 2.], [4., 2., 2.], [2., 2., 2.], [2., 6., 2.], [0., 6., 2.]]

inp_mesh = tet.MeshInfo()
inp_mesh.set_points(nodes)
inp_mesh.set_facets(facets)

mesh = tet.build(inp_mesh, options=tet.Options("pq"))

addin = tet.MeshInfo()
addin.set_points(np.array([[1., 1., 1.]]))

refined_mesh = tet.build(mesh, options=tet.Options("ri"), insert_points=addin)

print(mesh.points.__len__()) # 14
print(mesh.elements.__len__()) # 15

old_points = np.array(mesh.points)
old_elements = np.array(mesh.elements)
old_faces = np.array(mesh.faces)

print(refined_mesh.points.__len__()) # 14
print(refined_mesh.elements.__len__()) # 18

new_points = np.array(refined_mesh.points)
new_elements = np.array(refined_mesh.elements)
new_faces = np.array(refined_mesh.faces)

print((old_points == new_points).all()) # True

print('done')

What I'm doing wrong? Thanks in advance

inducer commented 3 years ago

FYI: Fixed the formatting on your comment.

Can you perform this operation using command-line tetgen? If so, how does command-line tetgen do this?

RubenZubrov commented 3 years ago

I saved mesh.points and mesh.elements to L.node and L.ele files. I also created an L.a.node file that contains three additional points:

3 3 0 0 0 1.1.1.1. 1 3.1.5 2 1. 4. 0.1

Then I ran the following command: tetgen -ri L

inducer commented 3 years ago

Were you able to investigate how command-line tetgen drives the backend in a way that's different from meshpy?

KMountris commented 2 years ago

Hello,

I am new user of meshpy and I find it great, but I have some issues with the tetrahedral refinement. Is it implemented the refiniment with a mesh size function stored in an mtr file? If yes, is it available any example on how to proceed? Thank you in advance.

ihsienlee commented 2 years ago

I use the "load_mtr" to set mesh size function and refine mesh.