taichi-dev / taichi_elements

High-performance multi-material continuum physics engine in Taichi
MIT License
483 stars 69 forks source link

Eliminating particles with clear_particles kernel #96

Closed you-found-tomasz closed 2 years ago

you-found-tomasz commented 2 years ago

Hi Taichi community,

I was trying to iteratively eliminate particles in a mpm simulation. with the clear_particle kernel: https://github.com/taichi-dev/taichi_elements/blob/f41d5decb4884c524a4d0f1e4d5dc4646f193b02/engine/mpm_solver.py#L1191

with the following code:

ti.init(arch=ti.cpu, kernel_profiler = True, debug=True)
mpm = MPMSolver(res=(64, 64, 64), size=10, max_num_particles=2 ** 15, use_ggui=False, use_g2p2g=False)
mpm.add_cube(lower_corner=[2, 6, 3], cube_size=[1, 1, 3], material=MPMSolver.material_elastic)`
for frame in range(1):
            mpm.step(4e-3, print_stat=False)
            mpm.clear_particles()

but I get the following error messages: For: [Taichi] version 0.8.11, latest version 0.9.1, llvm 10.0.0, commit 9d0973e5, linux, python 3.7.11:

Traceback (most recent call last):
  File "/home/tomasz/anaconda3/envs/taichi/lib/python3.7/site-packages/taichi/lang/kernel_impl.py", line 461, in taichi_ast_generator
    transform_tree(tree, ctx)
  File "/home/tomasz/anaconda3/envs/taichi/lib/python3.7/site-packages/taichi/lang/ast/transform.py", line 6, in transform_tree
    ASTTransformer()(ctx, tree)
  File "/home/tomasz/anaconda3/envs/taichi/lib/python3.7/site-packages/taichi/lang/ast/ast_transformer_utils.py", line 27, in __call__
    raise e.with_traceback(None)
taichi.lang.exception.TaichiCompilationError: On line 1230 of file "/home/tomasz/Documents/Master_thesis/rl-taichi/rl-taichi/engine/mpm_solver.py":
        ti.deactivate(self.x.loop_range().parent().snode(), [])
Traceback (most recent call last):
  File "/home/tomasz/anaconda3/envs/taichi/lib/python3.7/site-packages/taichi/lang/ast/ast_transformer_utils.py", line 24, in __call__
    return method(ctx, node)
  File "/home/tomasz/anaconda3/envs/taichi/lib/python3.7/site-packages/taichi/lang/ast/ast_transformer.py", line 521, in build_Attribute
    node.ptr = getattr(node.value.ptr, node.attr)
AttributeError: 'taichi._lib.core.taichi_core.Expr' object has no attribute 'parent'

For: [Taichi] version 0.9.1, latest version 0.9.1, llvm 10.0.0, commit 9d0973e5, linux, python 3.7.11:

Traceback (most recent call last):
  File "/home/tomasz/anaconda3/envs/taichi/lib/python3.7/site-packages/taichi/lang/kernel_impl.py", line 477, in taichi_ast_generator
    transform_tree(tree, ctx)
  File "/home/tomasz/anaconda3/envs/taichi/lib/python3.7/site-packages/taichi/lang/ast/transform.py", line 6, in transform_tree
    ASTTransformer()(ctx, tree)
  File "/home/tomasz/anaconda3/envs/taichi/lib/python3.7/site-packages/taichi/lang/ast/ast_transformer_utils.py", line 23, in __call__
    raise e.with_traceback(None)
taichi.lang.exception.TaichiCompilationError: On line 1230 of file "/home/tomasz/Documents/Master_thesis/rl-taichi/rl-taichi/engine/mpm_solver.py", in clear_particles:
        ti.deactivate(self.x.loop_range().parent().snode(), [])
Traceback (most recent call last):
  File "/home/tomasz/anaconda3/envs/taichi/lib/python3.7/site-packages/taichi/lang/ast/ast_transformer_utils.py", line 20, in __call__
    return method(ctx, node)
  File "/home/tomasz/anaconda3/envs/taichi/lib/python3.7/site-packages/taichi/lang/ast/ast_transformer.py", line 578, in build_Attribute
    node.ptr = getattr(node.value.ptr, node.attr)
AttributeError: 'MatrixField' object has no attribute 'loop_range'

I tried to delete the particles manually, and a new cube:

ti.init(arch=ti.cpu, kernel_profiler = True, debug=True)
mpm = MPMSolver(res=(64, 64, 64), size=10, max_num_particles=2 ** 15, use_ggui=False, use_g2p2g=False)
mpm.add_cube(lower_corner=[2, 6, 3], cube_size=[1, 1, 3], material=MPMSolver.material_elastic)`
for frame in range(2):
            mpm.step(4e-3, print_stat=False)
            mpm.n_particles[None] = 0
            mpm.x.snode.deactivate_all()
            mpm.add_cube(lower_corner=[2, 6, 3], cube_size=[1, 1, 3], material=MPMSolver.material_elastic)`

but then I probably eliminate something too much of it since it crushes:

corrupted double-linked list
[E 03/17/22 13:51:48.432 45622] Received signal 6 (Aborted)

If anybody has an idea, thank you kindly in advance!

you-found-tomasz commented 2 years ago

I resolved it by deactivating the parent of x:

mpm.x.parent().deactivate_all()