GithubHelp home page GithubHelp logo

sph's Introduction

Fluid simulator Smoothed Particle Hydrodynamics

An implementation of SPH fluid simulator.

Dependencies

Code compiles with Visual Studio 2013/2015; proper project file is in this repository (z-index sort.vcxproj). I've never tried to run it on linux or compile it with GCC (but I suspect that there wouldn't be any major problem for it to work).

Introduction to the code

All simulating takes place in Simulation.cpp, in Simulation::run(float dt) method. Briefly:

// simulation loop
void Simulation::run(float dt)
{
    // init
    emit_particles();

    // cache optimization
    grid.clear_grid();
    particle_system.insert_sort_particles_by_indices();
    bin_particles_in_grid();

    // simulation <- all SPH stuff is here
    compute_density();
    compute_forces();
    resolve_collisions();
    advance();
    
    // rendering
    distance_field.generate_field_from_surface_particles(extract_surface_particles());
    particle_system.update_buffers();
}

In main simulation loop also appear methods responsible for placing every particle into correct cube in grid (ParticleSystem class; see 'z-index neighbour search' in reference 2.) and for rendering (DistanceField class; see 'Distance Field Generation' and 'GPU Raycasting' also in reference 2.).

Painting objects (i.e. calling drawing functions) is constructed via a Visitor pattern. Every Object which is to be drawn, derives from Drawable class and it's reference is held in Application::_paintables vector. Then in every iteration a Application::paint() method is called which calls paint() method for every Object in that _paintables vector, which in turn (through the Object) calls Painter::paint(Object &) method.

For additional information about code structure see tutorial_pl (in polish).

References

  1. Matthias Müller, David Charypar, and Markus Gross. “Particle-Based Fluid Simulation for Interactive Applications”

  2. Prashant Goswami et al. “Interactive SPH Simulation and Rendering on the GPU”

  3. Micky Kelager. “Lagrangian Fluid Dynamics Using Smoothed Particle Hydrodynamics”

  4. Markus Ihmsen et al. “SPH Fluids in Computer Graphics – State of the Art Report”

sph's People

Contributors

filu005 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.