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

No deformation at all in using problem class. #15

Open
PoutineSyropErable opened this issue Aug 5, 2024 · 0 comments
Open

No deformation at all in using problem class. #15

PoutineSyropErable opened this issue Aug 5, 2024 · 0 comments

Comments

@PoutineSyropErable
Copy link

I tried a lot of much simpler cases, but again, none of them shows any deformation. Is the problem class incapable of showing deformation?

Code to create a simple square grid:

import numpy as np
import meshio
import polyscope as ps

# Define grid dimensions
n = 10

# Create vertices for a grid of (n x n) squares
vertices = []
for i in range(n + 1):
    for j in range(n + 1):
        vertices.append([i / n, j / n, 0])

vertices = np.array(vertices, dtype=np.float32)

# Create faces (triangles) for each square
faces = []
k = 0
for i in range(n):
    for j in range(n):
        # Indices of the vertices for the current square
        v0 = i * (n + 1) + j
        v1 = v0 + 1
        v2 = v0 + (n + 1)
        v3 = v2 + 1
        center = (vertices[v0]+vertices[v1]+vertices[v2]+vertices[v3])/4
        
        print(k, center)
                
        
        # First triangle
        faces.append([v0, v1, v2])
        # Second triangle
        faces.append([v1, v3, v2])
        k+=2



faces = np.array(faces, dtype=np.int32)

# Save to OBJ file using meshio
mesh = meshio.Mesh(points=vertices, cells=[("triangle", faces)])
meshio.write("grid_mesh.obj", mesh)

# Initialize Polyscope
ps.init()

# Load the mesh from the OBJ file
mesh = meshio.read("grid_mesh.obj")

# Extract vertices and faces
vertices = mesh.points
faces = mesh.cells_dict["triangle"]

# Register the mesh with Polyscope
ps_mesh = ps.register_surface_mesh("2D Grid", vertices, faces)

# Show the mesh
ps.show()

Polyfem Code:

import numpy as np
import meshio
import polyscope as ps

# Define grid dimensions
n = 10

# Create vertices for a grid of (n x n) squares
vertices = []
for i in range(n + 1):
    for j in range(n + 1):
        vertices.append([i / n, j / n, 0])

vertices = np.array(vertices, dtype=np.float32)

# Create faces (triangles) for each square
faces = []
k = 0
for i in range(n):
    for j in range(n):
        # Indices of the vertices for the current square
        v0 = i * (n + 1) + j
        v1 = v0 + 1
        v2 = v0 + (n + 1)
        v3 = v2 + 1
        center = (vertices[v0]+vertices[v1]+vertices[v2]+vertices[v3])/4
        
        print(k, center)
                
        
        # First triangle
        faces.append([v0, v1, v2])
        # Second triangle
        faces.append([v1, v3, v2])
        k+=2



faces = np.array(faces, dtype=np.int32)

# Save to OBJ file using meshio
mesh = meshio.Mesh(points=vertices, cells=[("triangle", faces)])
meshio.write("grid_mesh.obj", mesh)

# Initialize Polyscope
ps.init()

# Load the mesh from the OBJ file
mesh = meshio.read("grid_mesh.obj")

# Extract vertices and faces
vertices = mesh.points
faces = mesh.cells_dict["triangle"]

# Register the mesh with Polyscope
ps_mesh = ps.register_surface_mesh("2D Grid", vertices, faces)

# Show the mesh
ps.show()

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

1 participant