erizmr / taichi_sph

A Taichi implementation of WCSPH
14 stars 5 forks source link

Maybe three little mistakes in file 'particle_system.py' #2

Closed Rabmelon closed 2 years ago

Rabmelon commented 2 years ago

I am learning this program to finish my taichiCourse01 final project. And I found three confused lines in file 'particle_system.py':

  1. in line 179, I think it should be 'particle_diameter' but not 'self.particle_radius'. I guess this also leads to an overlap while drawing, so you used 'radius=ps.particle_radius / 1.5 ...' in 'demo.py'.
  2. in line 178, I think there should be a tiny number added after 'lower_corner[i] + cube_size[i]', so you won't lose the particles in the top row and the right colume.
  3. in line 120, I think it should be 'continue' but not 'break', because a break there will lead to a lack of neighbour search. But after I change it to continue, the para 'offset' won't update. As to say, for a para 'center_cell' = [0, 1], para 'cell' should be [-1, 0] then [-1, 1] then ... But actually, para 'cell' will loop as [-1, 0] and won't update to [-1, 1], so this caused an endless loop. Besides, I created a code as follows for test and it went well. I am confused what's the problem and will really appreciate your solution.
import taichi as ti
ti.init(arch=ti.cpu)

dim = 2

center_cell = ti.Vector.field(2, dtype=ti.i32, shape=2)
center_cell[0] = ti.Vector([0, 1])
center_cell[1] = ti.Vector([2, 2])

@ti.func
def is_valid_cell(cell):
    flag = True
    for d in ti.static(range(dim)):
        flag = flag and (0 <= cell[d] < 3)
    return flag

@ti.kernel
def func_test():
    for i in range(2):
        print(center_cell[i], ';')
        for offset in ti.grouped(ti.ndrange(*((-1, 2),) * dim)):
            cell = center_cell[i] + offset
            print(cell, end=', ')
            if not is_valid_cell(cell):
                print('kill', end='! ')
                continue
        print()

func_test()

with an output: [0, 1] ; [-1, 0], kill! [-1, 1], kill! [-1, 2], kill! [0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 2] ; [1, 1], [1, 2], [1, 3], kill! [2, 1], [2, 2], [2, 3], kill! [3, 1], kill! [3, 2], kill! [3, 3], kill!

environment: [Taichi] version 0.8.1, llvm 10.0.0, commit cc2dd342, win, python 3.8.1

erizmr commented 2 years ago

Thanks for reporting this. I will take a look and come back to you.

erizmr commented 2 years ago

Hi, I have check the problems you mentioned.

Rabmelon commented 2 years ago

Thank you for the reply.

Again thank you for your time and help!