Skip to content

Each call of tv.v.noise(tv.p, 0) leads to update of position based on current velocity #52

Open
@karegeo

Description

@karegeo

Good day!
It might be not a bug, but it looks very suspicious.

In tolvera/src/tolvera/vera

/forces.py

@ti.kernel
def noise(particles: ti.template(), weight: ti.f32):
    """Add noise to the particles.

    Args:
        particles (ti.template): Particles.
        weight (ti.f32): Noise weight.
    """
    for i in range(particles.field.shape[0]):
        p = particles.field[i]
        if p.active == 0:
            continue
        particles.field[i].vel += (ti.Vector([ti.random() - 0.5, ti.random() - 0.5]) * weight)
        particles.field[i].pos += p.vel * p.speed * p.active # <-- This line

This is strange, because usually only ti.move directly update positions. That means that each call of noise is updating positions again, based on velocities (+noise) from other vera, effectively speeding up everything.

Usually it does not lead to significant problems, however, if you set noise weight to 0, it looks strange.
And each additional call of noise kernel make situation worse.

If you start simulation with no vera except noise with weight 0, particles will moved in straight line according to initial velocities.

Minimal example is this:

from tolvera import Tolvera, run

def main(**kwargs):
  tv = Tolvera(**kwargs)
  @tv.render
  def _():
    tv.px.clear()
    #tv.v.flock(tv.p)
    tv.v.noise(tv.p, 0)
    #tv.v.noise(tv.p, 0)
    #tv.v.noise(tv.p, 0)
    tv.px.particles(tv.p, tv.s.species())
    return tv.px



if __name__ == "__main__":
    run(main)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions