doyubkim/fluid-engine-dev

LevelSetLiquidSolver3 reset air velocity in grid

kentbarber opened this issue · 7 comments

Hi Doyub,

I have a LevelSetLiquidSolver3 where it has multiple emitters in a GridEmitterSet3. When the emitters are enabled midway during a simulation they are getting affected immediately by what I believe to be the air velocity of the cells. Is there any way you can think of to avoid this? Perhaps reset the velocity of newly emitted cells?

levelsetissue

Thanks again for all your work.

Best Regards,
Kent

Actually you can ignore this. I think I should be able to make them colliders first, then disable the colliders and emit. I will close this thread now.

Reopening this again. It doesn’t look like I can disable a collider. Would this be possible to do?

Thank you for finding this bug, @kentbarber! I think there's a bug when the emitter injects the SDF where it doesn't update the velocity field properly. I will look into this.

Hi @kentbarber,

So I think this is more like an API bug/issue where adding emitter for grid-based solvers is not consistent with particle-based solver. Before I explain further, you should try the following.

In your code, I guess you are adding an emitter like this:

solver->setEmitter(emitter);
emitter->addSignedDistanceTarget(solver->signedDistanceField());

The code above only adds an SDF geometry, but doesn't specify the velocity field (not even zero). So in your case where the emitter should add zero-velocity object to the scene, you should add additional emitter target such as:

solver->setEmitter(emitter);
emitter->addSignedDistanceTarget(solver->signedDistanceField());
emitter->addTarget(
    solver->velocity(),
    [](double sdf, const Vector3D& pt, const Vector3D& oldVal) {
        if (sdf < 0.0) {
            return Vector3D(0, 0, 0);
        } else {
            return Vector3D(oldVal);
        }
    });

The code above explicitly tell the emitter how to handle velocity field. Can you try it and see if it addresses your issue?

I know the emitter APIs in general (including the particle ones) are far from ideal and hoping to address this in the next version. If the code above works for you, I will post a new issue to specifically track this grid emitter API problem.

Hi @doyubkim,

That worked perfectly. Thank you.

I was also wondering if it is possible to add new emitters to the emitterset during the simulation? Since these steps outlined here are all performed before the solver->update method is called. I will try this later this week and if I see problems I will open a new issue.

Cheers,
Kent

Emitters and colliders should be updated every frame before it actually advances a fluid-sim time-step. (More specifically, when beginAdvanceTimeStep is called internally.) So setting a new emitter at random frame should work:

solver->setEmitter(emitter);
emitter->addSignedDistanceTarget(solver->signedDistanceField());
emitter->addTarget(
    solver->velocity(),
    [](double sdf, const Vector3D& pt, const Vector3D& oldVal) {
        if (sdf < 0.0) {
            return Vector3D(0, 0, 0);
        } else {
            return Vector3D(oldVal);
        }
    });

So basically you are throwing away old emitter which is completely fine.

If not, please open a new issue! :)

Great. I will give it a try. I am going to see if I can get it working with the MoGraph system in C4D to dynamically add fluid to a sim.