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

[Feature] add particle free in MPM #263

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions genesis/engine/entities/mpm_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,27 @@ def set_muscle(self, muscle_group=None, muscle_direction=None):

self.set_muscle_direction(muscle_direction)

def set_free(self, free):
self._assert_active()

self.solver._kernel_set_free(
self._particle_start,
self._n_particles,
free,
)

def get_free(self):
self._assert_active()

free = gs.zeros((self._n_particles,), dtype=int, requires_grad=False, scene=self._scene)
self.solver._kernel_get_free(
self._particle_start,
self._n_particles,
free,
)

return free

@ti.kernel
def clear_grad(self, f: ti.i32):
for i in range(self.n_particles):
Expand Down
27 changes: 27 additions & 0 deletions genesis/engine/solvers/mpm_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def init_particle_fields(self):
mat_idx=gs.ti_int,
mass=gs.ti_float,
default_Jp=gs.ti_float,
free=gs.ti_int,
# for muscle
muscle_group=gs.ti_int,
muscle_direction=gs.ti_vec3,
Expand Down Expand Up @@ -384,6 +385,9 @@ def p2g(self, f: ti.i32):
)
self.grid[f, base - self._grid_offset + offset].mass += weight * self.particles_info[i].mass

if self.particles_info[i].free == 0: # non-free particles behave as boundary conditions
self.grid[f, base - self._grid_offset + offset].vel_in = ti.Vector.zero(gs.ti_float, 3)

@ti.kernel
def g2p(self, f: ti.i32):
for i in range(self._n_particles):
Expand Down Expand Up @@ -658,6 +662,7 @@ def _kernel_add_particles(
self.particles_info[i_global].mat_idx = mat_idx
self.particles_info[i_global].default_Jp = mat_default_Jp
self.particles_info[i_global].mass = self._p_vol * mat_rho
self.particles_info[i_global].free = 1
self.particles_info[i_global].muscle_group = 0
self.particles_info[i_global].muscle_direction = ti.Vector([0.0, 0.0, 1.0], dt=gs.ti_float)

Expand Down Expand Up @@ -816,6 +821,28 @@ def _kernel_set_muscle_direction(
for j in ti.static(range(3)):
self.particles_info[i_global].muscle_direction[j] = muscle_direction[i, j]

@ti.kernel
def _kernel_set_free(
self,
particle_start: ti.i32,
n_particles: ti.i32,
free: ti.types.ndarray(),
):
for i in range(n_particles):
i_global = i + particle_start
self.particles_info[i_global].free = free[i]

@ti.kernel
def _kernel_get_free(
self,
particle_start: ti.i32,
n_particles: ti.i32,
free: ti.types.ndarray(),
):
for i in range(n_particles):
i_global = i + particle_start
free[i] = self.particles_info[i_global].free

@ti.kernel
def _kernel_get_state(
self,
Expand Down