(不断更新)
文章目录
1 TypeError: unsupported operand type(s) for *: ‘float’ and ‘SNodeHostAccess’
报错
TypeError: unsupported operand type(s) for *: ‘float’ and ‘SNodeHostAccess’
源代码
原因
没有加@ti.kernel
用了taichi的field,以及其相乘的运算,但是不是在taichi-scope里面。
报错信息有误导性,实际上就是因为没有加@ti.kernel
解决
加@ti.kernel
2 AttributeError: ‘float’ object has no attribute ‘getitem’
报错
AttributeError: ‘float’ object has no attribute ‘getitem’
源代码
原因
mass是float,错当成了filed使用
解决
mass[None]改为mass
3 TypeError: must be real number, not Expr
源代码
原因
taichi域内要用taichi的cos函数
不能用math的
解决
改为ti.cos()
4 TaichiSyntaxError: cannot assign scalar expr to taichi … maybe you want to use a.fill(b)
instead?
报错
taichi.lang.exception.TaichiSyntaxError: cannot assign scalar expr to taichi class <class ‘taichi.lang.matrix.Matrix’>, maybe you want to use a.fill(b)
instead?
源代码
原因
velocityStar是个2维向量,不能用标量0赋值
解决
改为
velocityStar[i] = ti.Vector([0.0,0.0])
positionStar[i] = ti.Vector([0.0,0.0])