Skip to content

Add FluidSimulation2D example - #71

Closed
ttnghia wants to merge 1 commit into
mosra:masterfrom
ttnghia:fluidsimulation2d
Closed

Add FluidSimulation2D example#71
ttnghia wants to merge 1 commit into
mosra:masterfrom
ttnghia:fluidsimulation2d

Conversation

@ttnghia

@ttnghia ttnghia commented Nov 13, 2019

Copy link
Copy Markdown
Contributor

Hi there!

Another magnum example: FluidSimulation2D. This example has a different simulation model (APIC) than the previous FluidSimulation3D example (SPH), and run with just a single thread.

Again, you're free to modify it as you want. I have tried to tightly follow magnum coding convention.
You can write a short description for this example as "A 2D fluid simulation using Affine Particle-in-Cell (APIC) method".

image

@ttnghia

ttnghia commented Nov 13, 2019

Copy link
Copy Markdown
Contributor Author

Here is the video for this example: https://vimeo.com/372790124

@mosra mosra added this to the 2019.1c milestone Nov 13, 2019

@mosra mosra left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh my. This ... this is art. And also a ton of work. Thank you. 😍

I'll try to convert this one to a web version first as it's single-threaded compared to the 3D version and thus should be simpler :)

const auto tx = T(1) - std::abs(d.x() * hInv);
const auto ty = T(1) - std::abs(d.y() * hInv);
return Math::max(tx * ty, T(0));
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These look like they could be great additions to the core math lib itself -- I'll see where these could fit.

Comment thread src/fluidsimulation2d/DataStructures/SparseMatrix.h

namespace Magnum { namespace Examples {
template<class T>
class Array2X {

@ttnghia ttnghia Nov 17, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really want to make Array1X/2X/3X be part of magnum. Currently, Array1D/2D/3D in mangum only have fixed size (1-2-3 elements). Dynamic size arrays are more useful.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I finally got around to merge this, hopefully finishing later today -- sorry for the long and demotivating delay.)

Re Array -- I'd say there's two different use cases and I don't think combining those two (like Eigen does) makes sense. The matrices and vectors in Math have compile-time size (2, 4, 17, ... elements) and are suited for basic geometry work where you don't want any allocations or uncontrolled memory access patterns, but definitely not for anything huge -- you don't want to use algorithms that perform well on a 4x4 matrix on a 100-element matrix, and vice versa.

For dynamic multidimensional arrays there's StridedArrayView and the way forward I see is providing a set of algorithms operating on it. Very few things are already in Math/FunctionsBatch.h, and the MeshTools provides an increasing set of mesh-oriented algos operating on top of this data structure. And with mosra/magnum#306 I'm aiming to have all those SIMD-accelerated.

The most time-consuming about all this is not the code itself, but ensuring it's all well-documented, thoroughly tested and with a consistent interface that isn't annoying to use :)

@mosra

mosra commented Dec 12, 2019

Copy link
Copy Markdown
Owner

Merged as f7c060f, thanks a billion and sorry again for the extreme demotivating delay from my side.

Docs online at https://doc.magnum.graphics/magnum/examples-fluidsimulation2d.html, I also managed to do an initial port to Emscripten, but need to tune the perf a bit until I can publish :)

@mosra mosra closed this Dec 12, 2019
@ttnghia
ttnghia deleted the fluidsimulation2d branch January 27, 2020 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants