Git Product home page Git Product logo

doyubkim / fluid-engine-dev Goto Github PK

View Code? Open in Web Editor NEW
1.8K 68.0 249.0 71.26 MB

Fluid simulation engine for computer graphics applications

Home Page: https://fluidenginedevelopment.org/

License: MIT License

Python 2.31% C++ 95.59% Shell 0.01% C 1.27% CMake 0.81% Dockerfile 0.01%
physics-engine fluid-simulation-engine computer-graphics computational-physics animation c-plus-plus computational-fluid-dynamics

fluid-engine-dev's Introduction

Fluid Engine Dev - Jet

License Windows Windows-MinGW Ubuntu macOS codecov

Jet framework is a fluid simulation engine SDK for computer graphics applications that was created by Doyub Kim as part of the book, "Fluid Engine Development". The code is built on C++11 and can be compiled with most of the commonly available compilers such as g++, clang++, or Microsoft Visual Studio. Jet currently supports macOS (10.10 or later), Ubuntu (14.04 or later), and Windows (Visual Studio 2015 or later). Other untested platforms that support C++11 also should be able to build Jet. The framework also provides Python API for faster prototyping.

The latest code is always available from the main branch. Since the code evolves over time, the latest from the main branch could be somewhat different from the code in the book. To find the version that is consistent with the book, check out the branch book-1st-edition.

Key Features

  • Basic math and geometry operations and data structures
  • Spatial query accelerators
  • SPH and PCISPH fluid simulators
  • Stable fluids-based smoke simulator
  • Level set-based liquid simulator
  • PIC, FLIP, and APIC fluid simulators
  • Upwind, ENO, and FMM level set solvers
  • Jacobi, Gauss-Seidel, SOR, MG, CG, ICCG, and MGPCG linear system solvers
  • Spherical, SPH, Zhu & Bridson, and Anisotropic kernel for points-to-surface converter
  • Converters between signed distance function and triangular mesh
  • C++ and Python API
  • Intel TBB, OpenMP, and C++11 multi-threading backends

Every simulator has both 2-D and 3-D implementations.

Quick Start

You will need CMake to build the code. If you're using Windows, you need Visual Studio 2015 or 2017 in addition to CMake.

First, clone the code:

git clone https://github.com/doyubkim/fluid-engine-dev.git --recursive
cd fluid-engine-dev

Python API

Build and install the package by running

pip install -U .

Now run some examples, such as:

python src/examples/python_examples/smoke_example01.py

C++ API

For macOS or Linux:

mkdir build && cd build && cmake .. && make

For Windows:

mkdir build
cd build
cmake .. -G"Visual Studio 14 2015 Win64"
MSBuild jet.sln /p:Configuration=Release

Now run some examples, such as:

bin/hybrid_liquid_sim

Docker

docker pull doyubkim/fluid-engine-dev:latest

Now run some examples, such as:

docker run -it doyubkim/fluid-engine-dev
[inside docker container]
/app/build/bin/hybrid_liquid_sim

More Instructions of Building the Code

To learn how to build, test, and install the SDK, please check out INSTALL.md.

Documentations

All the documentations for the framework can be found from the project website including the API reference.

Examples

Here are some of the example simulations generated using Jet framework. Corresponding example codes can be found under src/examples. All images are rendered using Mitsuba renderer and the Mitsuba scene files can be found from the demo repository. Find out more demos from the project website.

FLIP Simulation Example

FLIP Example

PIC Simulation Example

PIC Example

Level Set Example with Different Viscosity

Level Set Example

Smoke Simulation with Different Advection Methods

Cubic-smoke Example Linear-smoke Example

Point-to-Surface Examples

Point-to-Surface Example

Top-left: spherical, top-right: SPH blobby, bottom-left: Zhu and Bridson's method, and bottom-right: Anisotropic kernel

Developers

This repository is created and maintained by Doyub Kim (@doyubkim). Chris Ohk (@utilForever) is a co-developer of the framework since v1.3. Many other contributors also helped improving the codebase including Jefferson Amstutz (@jeffamstutz) who helped integrating Intel TBB and OpenMP backends.

License

Jet is under the MIT license. For more information, check out LICENSE.md. Jet also utilizes other open source codes. Checkout 3RD_PARTY.md for more details.

I am making my contributions/submissions to this project solely in my personal capacity and am not conveying any rights to any intellectual property of any third parties.

Acknowledgement

We would like to thank JetBrains for their support and allowing us to use their products for developing Jet Framework.

JetBrains

fluid-engine-dev's People

Contributors

burakbayramli avatar danielwinkler avatar doyubkim avatar erdk avatar ithacane avatar jeffamstutz avatar jehutymax avatar kentbarber avatar laurelkeys avatar marcelsan avatar pavelblend avatar ryanastout avatar surajsubudhi10 avatar syoyo avatar utilforever avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fluid-engine-dev's Issues

Fail unit test: GridSinglePhasePressureSolver2.SolveSinglePhaseWithMg

I found that unit tests failed intermittently on macOS High Sierra (utilforever/CubbyFlow#233). The error log looks like this: Can you check it?

/Users/utilforever/code/TestWorkSpace/fluid-engine-dev/src/tests/unit_tests/grid_single_phase_pressure_solver2_tests.cpp:330: Failure
The difference between 0.0 and vel.u(i, j) is 0.010890662978106036, which exceeds 0.01, where
0.0 evaluates to 0,
vel.u(i, j) evaluates to -0.010890662978106036, and 0.01 evaluates to 0.01.
[  FAILED  ] GridSinglePhasePressureSolver2.SolveSinglePhaseWithMg (48 ms)
[----------] 1 test from GridSinglePhasePressureSolver2 (48 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (48 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] GridSinglePhasePressureSolver2.SolveSinglePhaseWithMg

 1 FAILED TEST

/Users/utilforever/code/TestWorkSpace/fluid-engine-dev/src/tests/unit_tests/grid_single_phase_pressure_solver2_tests.cpp:336: Failure
The difference between 0.0 and vel.v(i, j) is 0.051521814726812387, which exceeds 0.05, where
0.0 evaluates to 0,
vel.v(i, j) evaluates to 0.051521814726812387, and 0.05 evaluates to 0.050000000000000003.
[  FAILED  ] GridSinglePhasePressureSolver2.SolveSinglePhaseWithMg (167 ms)
[----------] 1 test from GridSinglePhasePressureSolver2 (167 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (167 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] GridSinglePhasePressureSolver2.SolveSinglePhaseWithMg

 1 FAILED TEST

Libraries missing

Libraries like cnpy and googletest are missing. In order for this to compile, they need to be added manually.

Package manager support

At least PyPI should be supported. Debian APT/Homebrew/NuGet/vcpkg also can be considered.

Mitsuba renderings

The Mitsuba renderings in the examples video and the book look great.
Is it possible to add the Mitsuba project files and possibly scripts that were used to create these images?
Unfortunately I only see the volume export for smoke simulations in the source code.

Support rotating collider

Current collider only can take linear motion. Support rotation and add actual simulation examples.

Test Reporting Tool

The manual and perf tests need some (lightweight) test reporting tool that can:

  • Generate reports automatically
  • Track the history (especially for the perf tests)
  • Detect any regressions

This includes some refactoring work for the existing test result rendering scripts.

APIC Solver numerical dissipation?

I was going over the rotation manual tests, and while it seems the dissipation is less than PIC or FLIP as expected, I thought that the dissipation would be much less than it is since APIC is supposed to preserve angular momentum? Is this a bug or am I missing something conceptually?

[Question] Evaluating gradient at particle vs at point

Good morning, I got a question about sampling the gradient or more generically a field.
Let's take as an example the density gradient, the gradient can be sampled at every point, and the result will be the sum of the weighted densities of all nearby particles. Now that is all good if I am sampling in a generic way the gradient, but when I am sampling the gradient in order to update a value of particle I, particle I need not to be in the neighbor's list? Meaning to compute the value at that particle that particle itself is not included in the computation? I guess otherwise the field would be offsetted by "max value" at every particle point?

Basically enforcing

Here is an example of the density gradient, computed at every point, not for every particle:
image

To me makes sense that if I am sampling a point that is exactly on a particle, there I would expect a high density being near the peak of the kernel function. But my source of confusion is instead if I am evaluating the particles itself

Best regards
M.
PS: hope this is clear enough, if not let me know I can elaborate.

Higher-order FMM/FSM

Implement higher-order fast marching method (FMM) and fast sweeping method (FSM). Consider parallel implementation.

Student's problem about the implementation of custom implicit surface

Thanks for your code and book. I am a student learning fluid simulation, and I am a little confused about the implementation in custom_implicit_surface2(3).cpp

For instance, near line 125, function closestIntersectionLocal, file fluid-engine-dev/src/jet/custom_implicit_surface2.cpp:

double frac = fractionInsideSdf(prevPhi, newPhi);
double tSub = t + _resolution * frac;

result.isIntersecting = true;
result.distance = tSub;

As far as I know, the function "fractionInsideSdf" always returns a positive number in [0, 1]. Also, the "t" here gets "newPhi" SDF. So why "t" has to add a positive number " _resolution * frac" instead of minus?

Thanks for your attention to this matter.

More examples & demos

Jet come with several example simulations and there are some demo videos generated from the examples. It would be great if we can have better and broader set of examples. Below are my short wishlist:

  • FLIP or APIC simulation with complex boundary settings
  • Liquid (level set or hybrid) sim with high viscosity, maybe time varying
  • More smoke sim demos
  • Interactive demos (when viz and gpu branch is merged)

It would be also great if we can create something more creative than the existing demos that are too technical.

Better Examples

Current examples are computationally heavy. We need more like a "Hello, world" type of example.
At least make a short-cut to some selected manual tests, bound with simple visualization tool. Also, document these examples to the wiki page.

Python API and PEP 8

Current Python API follows corresponding C++ API naming convention which partially breaks PEP 8 (ex. function names). Other frameworks such as TensorFlow for instance, seems to follow language-specific guidelines. That would be ideal for Jet framework as well. However, changing the naming convention will break the API obviously, so it should target for v2.

SIMD Implementation

Better performance using SIMD implementation by either directly implementing SIMD operations or utilizing Intel ISPC.

clang-format

Consider migrating over to clang-format from cpplint. Also provide project-specific settings for VS Code or Sublime Text.

I/O for common data structures

Some existing data structures like arrays support serializations. However, not all the classes support I/O and we need more policy as well.

A couple of thoughts/requirements:

  • Common data structures (such as arrays, grids, particle systems, etc) should support serialization.
  • Serialization should support both human readable format (JSON?) as well as binaries (FlatBuffer? Protobuf? Or just simple binary chunk?).
  • Schema should be well-defined.
  • The design of some data structures (such as particle systems) needs to be revised. Owning a pointer of ABC makes it hard to reconstruct.

CI Improvements

CI should be improved overall including:

  • Include Ubuntu 16.04
  • Latest version of compilers (gcc and clang)
  • Revive macOS builds
  • Fix hanging branch build with AppVeyor

Implement Statically-sized MxN matrix implementation

Only 2x2, 3x3, 4x4 and FDM-based sparse matrices are currently implemented. For the completeness,

  • Add statically-sized MxN matrix implementation
  • Add dynamically-sized MxN matrix implementation (dense)
  • Add dynamically-sized MxN matrix implementation (sparse)

Implement dynamically-sized MxN matrix implementation (dense)

Only 2x2, 3x3, 4x4 and FDM-based sparse matrices are currently implemented. For the completeness,

  • Add statically-sized MxN matrix implementation
  • Add dynamically-sized MxN matrix implementation (dense)
  • Add dynamically-sized MxN matrix implementation (sparse)

"anisotropic_points_to_implicit3" problem

Hi,
It's me (#109) again 😸 . I find a problem with anisotropic point to implicit3.

What problem:

Here is a screenshot:
Image of hole
It seems not correct for a dambreak at frame 0.

How:

I just run a sph dambreak demo similar to sph_sim example 3, and here is the .pos file at frame 0 that I got.
frame_000000.pos

And then, I tried to reconstruct the surface using the anisotropic kernel.

./particles2obj -i frame_000000.pos -o frame_000000.obj -r 300,200,150 -g 0.01,0.01,0.01 -k 0.036

(kernal radius:0.036, resolution is 300 200 150, and the gridspacing is 0.01, 0.01, 0.01. sph example 3's domain is 3,2,1.5, so I think it is reasonable)

My goal is to get a surface as tight as possible to render. My sph particle radius is 0.02(and the kernel radius is 1.8 * radius) as default, so I chose 0.036 as reconstruction kernel radius. I'm not sure if it is appropriate. Finally, I get the .obj as the screenshot shows.

My opinion:

I looked into the source code and the original paper

I find that the code is a little bit different from what the paper describes. The main difference is in equation 15. Instead of using the magic number k_s = 1400, the code uses std::pow(relV, 1.0 / 3.0) at line 152 in "anisotropic_points_to_implicit3.cpp"

I do not understand why the code uses "pow 1/3", but I tried to use the magic number 1400 in the same way as the paper, and the problem is gone! Here is the screenshot using k_s = 1400.
Image of nohole
(Sorry for the light spot in the middle. It is the UI of Blender)

I've not tested the 2D version of the anisotropic kernel, maybe it suffers from the same problem.

That's all I found... I hope I describe the problem clearly. I will maintain the picture and the .pos file till this issue is closed.

Clean-up dependencies

Jet Framework depends on several other libraries, and some of them are outdated or not quite utilized from Jet.

Here’s the wishlist:

Need a null pointer check in ImplicitSurfaceSet3::closestPointLocal

If a ImplicitSurfaceSet3 is empty and has no surfaces, then the bvh will have no nodes. Calling the function ImplicitSurfaceSet3::closestPointLocal will then crash since the queryResults item is null.

const auto queryResult = _bvh.nearest(otherPoint, distanceFunc);
return (*queryResult.item)->closestPoint(otherPoint);

Builder pattern for complex types

For instance, creating a face-centered grid or volume particle emitter takes significant number of parameters for their constructor. Adopting a builder pattern would be nice. Grid family does have simple builders, it is not really the builder for that purpose.

Python API

Python binding will improve the productivity. The binding solution is not determined, yet. The candidates are Boost.Python, SWIG, and pybind11. Interoperating with NumPy and Matplotlib would be ideal.

Objective-C Binding

Providing Objective-C binding will enable better integration with iOS and OS X apps. Swift support is also desirable.

Implement dynamically-sized MxN matrix implementation (sparse)

Only 2x2, 3x3, 4x4 and FDM-based sparse matrices are currently implemented. For the completeness,

  • Add statically-sized MxN matrix implementation
  • Add dynamically-sized MxN matrix implementation (dense)
  • Add dynamically-sized MxN matrix implementation (sparse)

Crash building TriangleMesh BVH inside ParallelFor

I am building using JET_TASKING_CPP11THREADS.

If you create an emitter from a TriangleMesh3 and add it to a LevelSetLiquidSolver3 as an ImplicitSurface3 using SurfaceToImplicit3, then when you do the solver update it will crash in a ParallelFor since multiple threads are triggering the build of the bvh.

To work around this you can call updateQueryEngine() for each emitter.

However the above is obviously the wrong approach since if you use a ImplicitTriangleMesh3 the issue does not present itself. But I thought I would point it out in case another user hits the same bug when getting started.

Microsoft CLR/WinRT Binding

Expose the API through C++/CLI so that Jet supports .NET languages such as C#.

Binding with WinRT is also desirable which will enable the Windows Store App support.

Easier API for adding source/emitter

Current API is too complicated to use when users try to add sources or emitters to the system. Provide easier API for setting source/emitter, similar to the collider.

Visualize XYZ particles

Hello,

I ran the sph_sim example and it generated an output folder with a lot of .xyz files which i believe are the positions of particles for each frame. Is there any script to generate a .mp4 animation based on this .xyz files?

Thank you!

More TBB integration other than parallelFor

Currently we have a TBB backend for parallelFor calls, but parallelSort and parallelRangeFor still fall back to std::thread implementations. TBB support for those functions would be beneficial, not just for the performance but also for consistency.

Support common data output format

I've been asked about any possibility of using HDF5 or similar kinds of data format. While Jet is using FlatBuffers for its serialization solution, supporting commonly sharable/viewable data format also seems to make sense. However, I do not want to introduce too many library dependencies to jet since it is mainly for the book. If I can find a better solution for this (something like a plug-in model), I will consider integrating such formats.

Upgrade to C++14

Some features like constexpr, attribute, variable template, and better type deduction would make the code more cleaner. Should be very cautious, though. "Modern" != "Clean/Better"

This means we also want to upgrade the minimum build tool requirements. The out-of-the-box solution for any given OS should support C++14 (or the feature we need at least).

More language bindings

This is not an urgent issue, but having additional bindings, such as .NET, Obj-C, Go, Rust, etc, could be fun. Jet used to have some .NET and Obj-C bindings but deprecated due to the complexity of the binding code and negative impact on core Jet implementation. If someone can make contribution to this effort, it would be great.

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.