How do i implement advection on 2d grid

Started by
5 comments, last by fais 7 years, 4 months ago

I ran into bunch of problems during implementation, maybe someone could explain me what should i do in order to transfer one data cell into another

so we have 2d grid of cells which consist (density and velocity vector)

each timestep (dt), we use advection

that would be simple if i could just transfer one velocity to another cell each frame, but unfortunatetly that doesnt work that way, it can transfer some part of density and velocity to other cell or even do not transfer anything at all, i was searching for references but ended up with navier stoakes equations etc. which don't say anything to me, to be honest its a bunch of gibberish called math that normal person doesn't understand.

anyway maybe someone knows the implementation of this so an average person could understand that.

i dont need equations/code but explenation what to do.

cheers.

Advertisement

Have you checked out Jos Stam's Stable Fluids and Real-Time Fluid Dynamics for Games? There is a C code, including an advect function (in solver.c): http://www.dgp.toronto.edu/people/stam/reality/Research/zip/CDROM_GDC03.zip

yes i saw that code, but its a total mess, not to mention variable names and swap, poject functions etc. real pain to read it, lets say i dont speak chinese.

This just a code without any good explanation (i saw the article too),

i need to understand steps beghind it to write that in GLSL

Semi lagrangian method (Jos Stam's work). If fidelity is important, google BFECC advection and and MacCormack advection.
The semi lagrangian method is actually quite simple. If you have an (x,y) coordinate and a (dx/dt, dy/dt) velocity vector, then a plausible assumption is that the velocity vector flowing outward is the same as the velocity vector flowing inward at that coordinate. Thus, you can do the following

dx = cell_prev( x, y ).velocity.x * dt;
dy = cell_prev( x, y ).velocity.y * dt;
cell_new( x, y ) = cell_prev( x - dx, y - dy );

The reason you want to work backwards is because if the integrated distance doesn't fall on a cell boundary, you can interpolate values from the neighboring cells.

Edit: I should add that will this produces decent results, it also adds a lot of artificial diffusion because of the linear interpolation. Which is where the BFECC and MacCormack algorithms come into play.

thats the main reason i am asking because:

Usdd.png

yeah but it doesnt work when we move further than one cell. Well it would work if i wasnt trying to accomplish that on gles 2 which supports only fragment and vertex shaders,

i forgot what i wanted to say so ill leave this post now.

thats the main reason i am asking because:
Usdd.png
yeah but it doesnt work when we move further than one cell. Well it would work if i wasnt trying to accomplish that on gles 2 which supports only fragment and vertex shaders,


i forgot what i wanted to say so ill leave this post now.

So, implementing a numerical advection model is not a trivial task. To the contrary, So much research has been poured into this one particular topic (from various different disciplines including oceanography/coastal engineering, plasma physics, meteorology/atmospheric science and modeling, fluid mechanics, linear algebra) that one can easily become overwhelmed. There is a reason why video games sacrifice fidelity/accuracy for speed and stability when it comes to simulating fluids. (Especially numerical stability, which can be a b***h!)

Before you can jump into creating your own/implement an existing an advection model, check out this articles the two fundamental approaches to fluid mechanics ( lagrangian vs eulerian) and you may begin to see why such a simple scheme that I outlined earlier is called "semi" lagrangian:

https://www.quora.com/What-is-the-difference-between-lagrangian-and-Eulerian-approach

If you've taken any calculus classes and you have a basic grasp on derivatives, then I also encourage you to look st material derivatives

https://en.m.wikipedia.org/wiki/Material_derivative

Heck, it took me a longer than I care to admit grasping the difference between D(x)/Dt and d(x)/dt and how it relates to lagrangian vs eulerian integration.

This topic is closed to new replies.

Advertisement