Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rectangle mesh creation #103

Open
saintnever opened this issue Apr 9, 2024 · 2 comments
Open

Rectangle mesh creation #103

saintnever opened this issue Apr 9, 2024 · 2 comments

Comments

@saintnever
Copy link

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
Copy link
Collaborator

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
Copy link

FUIGUIMURONG commented May 23, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants