eitcom / pyEIT

Python based toolkit for Electrical Impedance Tomography
Other
169 stars 96 forks source link

Rectangle mesh creation #103

Open saintnever opened 2 months ago

saintnever commented 2 months ago

Hi,

I am trying to generate a square mesh for EIT reconstruction, but not sure how to do that. I am generating the pts and passing to the mesh.create function like this

    p1 = np.array([0, 0])  # bottom-left
    p2 = np.array([5, 5]) # top-right

    # Generate a grid of points within this rectangle
    x = np.linspace(p1[0], p2[0], num=50)  # 20 points along x
    y = np.linspace(p1[1], p2[1], num=50)  # 10 points along y
    xx, yy = np.meshgrid(x, y)
    pts_r = np.c_[xx.ravel(), yy.ravel()]

    rect = rectangle0(pts_r)
    mesh_obj = mesh.create(n_electrodes, fd=rect)  

however, I get the following error: Exception has occurred: ValueError The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

thanks

liubenyuan commented 2 months ago

You may refer to the mesh examples. In order to use rectangle mesh, you need to allocate electrodes around the boundary.

BTW, you may check the issues, there might be one who use EIT in intelligent skin simulation. There is accompanied code in that issue.

FUIGUIMURONG commented 1 month ago

I have the same question, but I do not know how to solve it. I run the mesh example, but I want to generate the square mesh like in the MATLAB using EIDORS.

微信图片_20240523135311

I use the code ` class Mesh: def init(self, nodes, elements, perm): self.node = nodes self.element = elements self.perm = perm

def create_square_mesh(N=40, n_el=16):
    x = np.linspace(-1, 1, N+1)
    y = np.linspace(-1, 1, N+1)
    xx, yy = np.meshgrid(x, y)
    nodes = np.column_stack([xx.ravel(), yy.ravel()])

    triangles = []
    triangle_count = 0
    for i in range(N):
        for j in range(N):
            triangles.append([i*(N+1)+j, (i+1)*(N+1)+j, i*(N+1)+j+1])
            triangles.append([i*(N+1)+j+1, (i+1)*(N+1)+j, (i+1)*(N+1)+j+1])
            triangle_count += 2  # 记录小三角形的数量

    el_pos = np.arange(n_el)
    triangles = np.array(triangles)

    perm = np.ones(triangles.shape[0], dtype=float)

    mesh = Mesh(nodes, triangles, perm)
    return mesh, el_pos, triangle_count

`

to generate the above mesh. However I don not know how to allocate electrodes around the boundary. Can you give me some advice, I would appreciate it a lot.