ipc-toolkit: CCD high memory usage (bad allocation)

Hi,

Firstly, thank you for making IPC available to us all! I tried integrating IPC Toolkit (version 1.2.0) in a Python elastic simulation script, and thought to try it on a simple example first to check that it works. The example is basically 2 beam models, one fixed on the bottom, and another one, free falling from the top. I’m using a basic Newton PCG loop and the beam models are pretty coarse, and the example is not very contact rich, especially compared to what I know IPC is able to achieve. However, the CCD step (ipctk.compute_collision_free_stepsize) hogs up crazy amounts of memory on my 64GB of RAM desktop, and the program crashes after a bad allocation exception.

Here is the code. I provide the beam mesh model that I am using, and a requirements.txt file to install all versioned Python dependencies that I am using locally. You can run the script and get the polyscope GUI showing the example scenario. I know the script might not be the “minimum” reproducible code snippet, but I find that it is helpful to have the visuals without modification to the code and to reproduce my setup exactly. I am using Python 3.12.

I also unit scale the models, so the CCD trajectories should not be that long, not too sure what is consuming so much memory. I hope you find the time to investigate this issue. This might just be a misunderstanding about how to use the IPC Toolkit correctly too.

Thank you!

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

P.S. this bug would be caught if you run in debug mode (i.e, assert(vertices.rows() == mesh.num_vertices());), but the Python bindings compile in release (i.e., no asserts) by default.

Thank you for checking those. From looking at your code, I have one idea of what might be going on.

You have variables X/V which are the vertex positions of your tet mesh and C which are the tetrahedral elements as an index matrix into X/V.

You then get the boundary faces F = igl.boundary_facets(C) and the edges of the boundary faces as E = ipctk.edges(F).

You construct a collision mesh as cmesh = ipctk.CollisionMesh.build_from_full_mesh(V, E, F). This is correct because V is the full mesh’s vertex positions (i.e., includes internal nodes) and E/F index into the full vertices.

However, later you do

cconstraints.build(cmesh, X, dhat, dmin=dmin)
gradB = cconstraints.compute_potential_gradient(cmesh, X, dhat)
gradB = cmesh.to_full_dof(gradB)

but every method in the toolkit expects the input vertices will be only the surface vertices. I think this is the problem. Instead what you should be doing is

boundary_X = cmesh.vertices(X)
cconstraints.build(cmesh, boundary_X, dhat, dmin=dmin)
gradB = cconstraints.compute_potential_gradient(cmesh, boundary_X, dhat)
gradB = cmesh.to_full_dof(gradB)

Try making this change (and changing other instances where you use X instead of boundary_X) and see if that fixes your issue.