jalberse / feriphys

Physics simulations for computer graphics, in Rust
GNU General Public License v3.0
2 stars 0 forks source link

Add SPH #61

Closed jalberse closed 1 year ago

jalberse commented 2 years ago

Add SPH and demo.

jalberse commented 2 years ago

A possibly-difficult part of SPH implementation is the calculation of the initial pressure. For the sake of development, we might put that in the config for now with some reasonable default, rather than calculating it directly.

jalberse commented 1 year ago

Performance contraints are limiting number of particles.

Profiling shows the time sinks in the step() function are the collision detection and the from_state_vector call in the integration due to allocations.

I'd really like to increase the number of particles to show fluid flow, so maybe instead of allowing arbitrary collisions we just do a bounding box of the sim to start with.

As for the integration, I know Particles-cpu did not have this issue when it did not use the State representation. It also can update particles independently; we'd have to allocate a new vector of Particles since they depend on each other. But to save that allocation, we could use a swapping buffer pattern.

jalberse commented 1 year ago

It occurs to me we could also have the Stateful::from_state_vector() take a consuming Iterator on f32, not a Vec itself. That way it can consume straight out of the State vector for the whole system, rather than us having to chop it up ourselves and making intermediate small state vectors for each element.

It could return None rather than Self if the iterator is empty. So when we call it after processing the last element's floats, we know we're done.

With this approach, we'd only be allocating space for the new State (which we need to do for higher order integration anyways), and we'd allocate once for each element. But I think that's the best you can get.

So, maybe do that? Or just go the simple route and just hand-implement with basic Euler integration rather than using my fancy abstraction.

jalberse commented 1 year ago

I tried a kd tree, it seems pretty slow to construct each frame. A spatial grid may be better.