g-amador / incremental-fluids-java

A port to Java, resorting to Apache Commons Math, with some minor changes of the C++ simple, single-file fluid solvers for learning purposes.
https://github.com/tunabrain/incremental-fluids
GNU General Public License v3.0
0 stars 3 forks source link

On TunaBrains code, i just noticed, rotating and or translating the paddle in the test does not move the Body, and then the solver fails... #2

Open damian-666 opened 8 years ago

damian-666 commented 8 years ago

Just wondering if you implemented it and if it is stable enough to use...

I was thinking to apply drag, from thw wikipedia drag equation , then push the fluid away from the normals of the immersed thing. but i'd rather do it that way CBatty did.. i have some of that some... i can put the link.. its on a big page on Variational methods.. it gives away 2d code for gas ( with 3 circles... i could move those.. and it pushes away the liquid.. with a one frame delay, it seems.. but the shape is nice, and it does not miss any of the fluid... I see code that mentions forward Eulear.. so i was hoping you know something about it.. .. I will report to Tunabrain as well...I think the temperature gradients is the focus of this code.....

g-amador commented 8 years ago

Not sure what you mean!? English appears to have been written to much in a rush...

This code examples use forward explicit Euler. Implicit Euler commonly know as stable fluids from Jos Stam is something different. If you mean viscous drag, viscosity is a parameter so I guess you can alter it to simulate viscous drag. If you mean you want to handle moving solids instead of static ones than the problem that velocities have a different behavior with moving vs static objects: I couldn't find a more simple article (I know I saw once about 7 years ago) but this thesis fairly overviews the boundary conditions: https://www.nada.kth.se/utbildning/grukth/exjobb/rapportlistor/2007/rapporter07/bongart_robert_07018.pdf

damian-666 commented 8 years ago

Sorry i have been doing CFD research non stop for 5 months. I am porting your code that your ported from Incremental fluiids, to c#. but before i implement it , I was wondering if the Body ( immersed bodies) can rotate and or move... and push the matter out of the way.. and if you had any issues with it. I could help fix the issues maybe.. I see your version of rotate on a body is different than tunabrains version. thast version does not move the paddle in the example at all, and then the solver fails. I tried a simple angular velocity of 0.1 on the body, in sample 6.. or any sample witha body. ill show you your code to refresh your memory, it is different than the c version...

damian-666 commented 8 years ago

Well , it looks like you modified the distance normal.. that could push away stuff. , if I put a angular velocity, i hope that the box pushes the markers and ink around in a vortex... Since it is Euler, I guess i would need to limit how fast i move it. So i think i wlll try it.. unless you tell me it never worked or was too unstable..

@Override public Vector2D closestSurfacePoint(double x, double y) { x -= _posX; y -= _posY; Vector2D result = rotate(x, y, -_theta); x = result.getX(); y = result.getY(); double dx = abs(x) - _scaleX * 0.5; double dy = abs(y) - _scaleY * 0.5; if (dx > dy) { x = nsgn(x) * 0.5 * _scaleX; } else { y = nsgn(y) * 0.5 * _scaleY; } result = rotate(x, y, _theta); x = result.getX() + _posX; y = result.getY() + _posY; return new Vector2D(x, y); } @Override public Vector2D distanceNormal(double nx, double ny, double x, double y) { x -= _posX; y -= _posY; Vector2D result = rotate(x, y, -_theta); x = result.getX(); y = result.getY(); if (abs(x) - _scaleX * 0.5 > abs(y) - _scaleY * 0.5) { nx = nsgn(x); ny = 0.0; } else { nx = 0.0; ny = nsgn(y); } return rotate(nx, ny, _theta); }

On Mon, Sep 12, 2016 at 12:49 AM, Gonçalo Amador notifications@github.com wrote:

Not sure what you mean!? English appears to have been written to much in a rush...

This code examples use forward explicit Euler. Implicit Euler commonly know as stable fluids from Jos Stam is something different. If you mean viscous drag, viscosity is a parameter so I guess you can alter it to simulate viscous drag. If you mean you want to handle moving solids instead of static ones than the problem that velocities have a different behavior with moving vs static objects: I couldn't find a more simple article (I know I saw once about 7 years ago) but this thesis fairly overviews the boundary conditions: https://www.nada.kth.se/utbildning/grukth/exjobb/rapportlistor/2007/ rapporter07/bongart_robert_07018.pdf

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/noSoulApophis/incremental-fluids-java/issues/2#issuecomment-246190282, or mute the thread https://github.com/notifications/unsubscribe-auth/AP_LmWUJSCmAL9EULtWoqd6-QMjXkMECks5qpDEfgaJpZM4J56kt .

g-amador commented 8 years ago

I just ported the c++ code honestly never attempted to modify it (wanted to port to 3D but haven't got the time since finishing the PhD).

I have prior knowledge with backward Euler in stable fluids from the Masters.

I assume its not just a matter of adding/replacing velocity honestly, it appears it will filter wanted effects.

I would suggest trying to couple two fluids instead, where (the moving solids) density would be tweaked to remain a solid, or if you prefer at each fluid update ignore diffusion of the fluid (solid moving objects).

You could also try to alter locally the velocity in the border cells of the moving object, i.e., the moving obstacle velocity plus the velocity in nearby grid cells, or all together replace the velocity of the cells in the solid border be replaced by the moving obstacle velocity.

g-amador commented 8 years ago

You might also require to add artificial vorticity for this around the moving obstacle.

damian-666 commented 8 years ago

i guess by question is... does this code handle moving or rotating boxes. ? it looks different there...more promising..

On Mon, Sep 12, 2016 at 2:36 AM, Damian Hallbauer < damian.hallbauer@gmail.com> wrote:

Well , it looks like you modified the distance normal.. that could push away stuff. , if I put a angular velocity, i hope that the box pushes the markers and ink around in a vortex... Since it is Euler, I guess i would need to limit how fast i move it. So i think i wlll try it.. unless you tell me it never worked or was too unstable..

@Override public Vector2D closestSurfacePoint(double x, double y) { x -= _posX; y -= _posY; Vector2D result = rotate(x, y, -_theta); x = result.getX(); y = result.getY(); double dx = abs(x) - _scaleX * 0.5; double dy = abs(y) - _scaleY * 0.5; if (dx > dy) { x = nsgn(x) * 0.5 * _scaleX; } else { y = nsgn(y) * 0.5 * _scaleY; } result = rotate(x, y, _theta); x = result.getX() + _posX; y = result.getY() + _posY; return new Vector2D(x, y); } @Override public Vector2D distanceNormal(double nx, double ny, double x, double y) { x -= _posX; y -= _posY; Vector2D result = rotate(x, y, -_theta); x = result.getX(); y = result.getY(); if (abs(x) - _scaleX * 0.5 > abs(y) - _scaleY * 0.5) { nx = nsgn(x); ny = 0.0; } else { nx = 0.0; ny = nsgn(y); } return rotate(nx, ny, _theta); }

On Mon, Sep 12, 2016 at 12:49 AM, Gonçalo Amador <notifications@github.com

wrote:

Not sure what you mean!? English appears to have been written to much in a rush...

This code examples use forward explicit Euler. Implicit Euler commonly know as stable fluids from Jos Stam is something different. If you mean viscous drag, viscosity is a parameter so I guess you can alter it to simulate viscous drag. If you mean you want to handle moving solids instead of static ones than the problem that velocities have a different behavior with moving vs static objects: I couldn't find a more simple article (I know I saw once about 7 years ago) but this thesis fairly overviews the boundary conditions: https://www.nada.kth.se/utbildning/grukth/exjobb/rapportlist or/2007/rapporter07/bongart_robert_07018.pdf

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/noSoulApophis/incremental-fluids-java/issues/2#issuecomment-246190282, or mute the thread https://github.com/notifications/unsubscribe-auth/AP_LmWUJSCmAL9EULtWoqd6-QMjXkMECks5qpDEfgaJpZM4J56kt .

damian-666 commented 8 years ago

thanks.. that is my plan... i tried it with C Batty variational liquid 2d code ( cant find it now)...andi could push the particles..i will have to interpolate i guess... and see how C Batty code worked.. unless i use flip , then just push the particle...

On Mon, Sep 12, 2016 at 3:08 AM, Gonçalo Amador notifications@github.com wrote:

I just ported the c++ code honestly never attempted to modify it (wanted to port to 3D but haven't got the time since finishing the Ph.D..

I have prior knowledge with backward Euler in stable fluids from the Masters.

I assume its not just a matter of adding velocity honestly. As far as I know I would suggest trying to couple two fluids instead, where (the moving solids) density would be tweaked to remain a solid, or if you prefer at each fluid update ignore diffusion of the fluid (solid moving objects).

You could also try to alter locally the velocity in the border cells of the moving object, i.e., the moving obstacle velocity plus the velocity in nearby grid cells, or all together replace the velocity of the cells in the solid border be replaced by the moving obstacle velocity.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/noSoulApophis/incremental-fluids-java/issues/2#issuecomment-246197951, or mute the thread https://github.com/notifications/unsubscribe-auth/AP_LmTo346xHNZbjmroakApgOr3E30wsks5qpFHBgaJpZM4J56kt .

damian-666 commented 8 years ago

but what trobules me is how the c++ code didnt solve if i put a 0.001 velocity on the box... are you sure you didnt fix it? i woulld not know how to fix this if it happen.. i guess i should test it... i dont even have java working...

On Mon, Sep 12, 2016 at 3:15 AM, Damian Hallbauer < damian.hallbauer@gmail.com> wrote:

thanks.. that is my plan... i tried it with C Batty variational liquid 2d code ( cant find it now)...andi could push the particles..i will have to interpolate i guess... and see how C Batty code worked.. unless i use flip , then just push the particle...

On Mon, Sep 12, 2016 at 3:08 AM, Gonçalo Amador notifications@github.com wrote:

I just ported the c++ code honestly never attempted to modify it (wanted to port to 3D but haven't got the time since finishing the Ph.D..

I have prior knowledge with backward Euler in stable fluids from the Masters.

I assume its not just a matter of adding velocity honestly. As far as I know I would suggest trying to couple two fluids instead, where (the moving solids) density would be tweaked to remain a solid, or if you prefer at each fluid update ignore diffusion of the fluid (solid moving objects).

You could also try to alter locally the velocity in the border cells of the moving object, i.e., the moving obstacle velocity plus the velocity in nearby grid cells, or all together replace the velocity of the cells in the solid border be replaced by the moving obstacle velocity.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/noSoulApophis/incremental-fluids-java/issues/2#issuecomment-246197951, or mute the thread https://github.com/notifications/unsubscribe-auth/AP_LmTo346xHNZbjmroakApgOr3E30wsks5qpFHBgaJpZM4J56kt .

damian-666 commented 8 years ago

with the tunabrain code.. i at a angular vel of 0.01 and it blows up .. never converges..

On Mon, Sep 12, 2016 at 3:16 AM, Damian Hallbauer < damian.hallbauer@gmail.com> wrote:

but what trobules me is how the c++ code didnt solve if i put a 0.001 velocity on the box... are you sure you didnt fix it? i woulld not know how to fix this if it happen.. i guess i should test it... i dont even have java working...

On Mon, Sep 12, 2016 at 3:15 AM, Damian Hallbauer < damian.hallbauer@gmail.com> wrote:

thanks.. that is my plan... i tried it with C Batty variational liquid 2d code ( cant find it now)...andi could push the particles..i will have to interpolate i guess... and see how C Batty code worked.. unless i use flip , then just push the particle...

On Mon, Sep 12, 2016 at 3:08 AM, Gonçalo Amador <notifications@github.com

wrote:

I just ported the c++ code honestly never attempted to modify it (wanted to port to 3D but haven't got the time since finishing the Ph.D..

I have prior knowledge with backward Euler in stable fluids from the Masters.

I assume its not just a matter of adding velocity honestly. As far as I know I would suggest trying to couple two fluids instead, where (the moving solids) density would be tweaked to remain a solid, or if you prefer at each fluid update ignore diffusion of the fluid (solid moving objects).

You could also try to alter locally the velocity in the border cells of the moving object, i.e., the moving obstacle velocity plus the velocity in nearby grid cells, or all together replace the velocity of the cells in the solid border be replaced by the moving obstacle velocity.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/noSoulApophis/incremental-fluids-java/issues/2#issuecomment-246197951, or mute the thread https://github.com/notifications/unsubscribe-auth/AP_LmTo346xHNZbjmroakApgOr3E30wsks5qpFHBgaJpZM4J56kt .

g-amador commented 8 years ago

For forward Euler you can use this code from the "Fluid Simulation for Computer Graphics"

For forward with obstacles you will need Stable Fluids modified to use obstacles http://www.intpowertechcorp.com/GDC03.pdf

Another old alternative would be using http://www.gamasutra.com/view/feature/1549/practical_fluid_dynamics_part_1.php?print=1

g-amador commented 8 years ago

The only difference I handled in the code was that I had to make sure the right values appeared in some cases because c++ handles out of bound (representable numbers) differently from Java so I slightly altered that in the source code.

I literally tested visually and numerical the C++ vs Java code to address this.

g-amador commented 8 years ago

The C++ code slightly cheats using C++ behavior common in C++ programming but in Java or C# might be a problem with ports sometimes.

g-amador commented 8 years ago

If that code considers rotating or moving obstacles: No!

Moving and rotating obstacles velocity requires you to: 1-Identify the cells in which their borders are within the grid (rough aproximation), e.g.:


| || || || S || || || | | || || S || S || S || || | | || S || S || S || S || S || | | || || S || S || S || || | | || || || S || || || | | || || || || || ||__ |

g-amador commented 8 years ago

The object must be within the cells but not all cells are entirely engulfed by the objects in this case accuracy would state use the percentage of the cell occupied (more processing time). Instead use the mean between the cell old velocity and the moving object velocity at the cell (might work).

damian-666 commented 8 years ago

thanks... i just went over your thesis.. its in 3d.. very ambitious.. im staying with 2d.. i hope that heat will stir up stuff.. i also have some IB peskin like code... i have seens the stam.. and now i might do the FFT way. after 5 months the FFT way is as good as any multigrid... i use panel an a estimated drag .. and i guess i push the stuff.. .. i may use FLIP scheme after all...i just thikn this one is too slow... but the rest is great... up to mixed density... i hope for stratified dust.... in the air from a volcano... using this solver, with4 types of particles .. ash sand dust... and something.. and with the heat...

On Mon, Sep 12, 2016 at 3:22 AM, Gonçalo Amador notifications@github.com wrote:

For forward Euler you can use this code from the "Fluid Simulation for Computer Graphics"

For forward with obstacles you will need Stable Fluids modified to use obstacles http://www.intpowertechcorp.com/GDC03.pdf

Another old alternative would be using http://www.gamasutra.com/view/feature/1549/practical_fluid_ dynamics_part_1.php?print=1

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/noSoulApophis/incremental-fluids-java/issues/2#issuecomment-246198758, or mute the thread https://github.com/notifications/unsubscribe-auth/AP_Lmc-s_bP8ldjLA7-N4nKwgQWd8ziPks5qpFTegaJpZM4J56kt .

g-amador commented 8 years ago

FFT does not allow moving or either type of obstacles !!!!!

damian-666 commented 8 years ago

if i want to run your code.. what is the best way , processing? sorry i never used java outside a browser and now it wont let me..

On Mon, Sep 12, 2016 at 3:31 AM, Damian Hallbauer < damian.hallbauer@gmail.com> wrote:

thanks... i just went over your thesis.. its in 3d.. very ambitious.. im staying with 2d.. i hope that heat will stir up stuff.. i also have some IB peskin like code... i have seens the stam.. and now i might do the FFT way. after 5 months the FFT way is as good as any multigrid... i use panel an a estimated drag .. and i guess i push the stuff.. .. i may use FLIP scheme after all...i just thikn this one is too slow... but the rest is great... up to mixed density... i hope for stratified dust.... in the air from a volcano... using this solver, with4 types of particles .. ash sand dust... and something.. and with the heat...

On Mon, Sep 12, 2016 at 3:22 AM, Gonçalo Amador notifications@github.com wrote:

For forward Euler you can use this code from the "Fluid Simulation for Computer Graphics"

For forward with obstacles you will need Stable Fluids modified to use obstacles http://www.intpowertechcorp.com/GDC03.pdf

Another old alternative would be using http://www.gamasutra.com/view/feature/1549/practical_fluid_d ynamics_part_1.php?print=1

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/noSoulApophis/incremental-fluids-java/issues/2#issuecomment-246198758, or mute the thread https://github.com/notifications/unsubscribe-auth/AP_Lmc-s_bP8ldjLA7-N4nKwgQWd8ziPks5qpFTegaJpZM4J56kt .

g-amador commented 8 years ago

Once in the fourier domain there is no turning back :/ That's why so many posterior works over Stam attempt to use Gauss-Seidel Jacobi or Conjugate Gradient.

g-amador commented 8 years ago

The source I provide is a Netbeans project just open an in each file with a main run individually. It will then generate the set of frames you can instead draw the triangles.

g-amador commented 8 years ago

Also cheek if you have not already the "Fluid Simulation for Computer Graphics" its free.

and the incomplete article

http://cg.informatik.uni-freiburg.de/intern/seminar/gridFluids_fluid_flow_for_the_rest_of_us.pdf

damian-666 commented 8 years ago

I know what you mean.. its a trick... 1024 x1024 grids .... are too good to be true.. but i found a few papers that say it can be done... as long as the screen is one wave or less... and the borders fake the periodicity. the FFT is used only for the pressure solve. i dont konw how big can the bodies be and i am surprised if its possible then why is AMG still being used... i will have to stuff the papers.. now i am using AMG... and chimera grids... i dont can about accuracy too much..

On Mon, Sep 12, 2016 at 3:34 AM, Gonçalo Amador notifications@github.com wrote:

The source I provide is a Netbeans project just open an in each file with a main run individually. It will then generate the set of frames you can instead draw the triangles.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/noSoulApophis/incremental-fluids-java/issues/2#issuecomment-246199474, or mute the thread https://github.com/notifications/unsubscribe-auth/AP_LmfKMeJ3WJS3aYhrK7YasGPFiys5Hks5qpFe6gaJpZM4J56kt .

damian-666 commented 8 years ago

sorry about my typos... I am not 100% sure FFT can be used , but i have read 3 papers that tell how to do it. and it is for one cycle only... so, 1024 might be doable... wich is more than i get from AMG... are you still doing CFD?

On Mon, Sep 12, 2016 at 3:39 AM, Damian Hallbauer < damian.hallbauer@gmail.com> wrote:

I know what you mean.. its a trick... 1024 x1024 grids .... are too good to be true.. but i found a few papers that say it can be done... as long as the screen is one wave or less... and the borders fake the periodicity. the FFT is used only for the pressure solve. i dont konw how big can the bodies be and i am surprised if its possible then why is AMG still being used... i will have to stuff the papers.. now i am using AMG... and chimera grids... i dont can about accuracy too much..

On Mon, Sep 12, 2016 at 3:34 AM, Gonçalo Amador notifications@github.com wrote:

The source I provide is a Netbeans project just open an in each file with a main run individually. It will then generate the set of frames you can instead draw the triangles.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/noSoulApophis/incremental-fluids-java/issues/2#issuecomment-246199474, or mute the thread https://github.com/notifications/unsubscribe-auth/AP_LmfKMeJ3WJS3aYhrK7YasGPFiys5Hks5qpFe6gaJpZM4J56kt .

damian-666 commented 8 years ago

yes.. Peskin himself has mentioned FFT for pressure solv in an immersed boudary paper.. he said any fast poisson solver will work , but he choose to use an FFT based one.. the paper was on... blood flow i have not tried it and he was not specific. i didnt know if the Immersed items needed to be symmetrical .. but i think no... but it must have both sides periodic. and you put boudardies in the off screen area.. or move stuff in the Y direction ... but first i want to see if your box can move the dust... i like tunabrains smoke... with the heat... and i hate c++.. c# has a good math lib now..

On Mon, Sep 12, 2016 at 3:42 AM, Damian Hallbauer < damian.hallbauer@gmail.com> wrote:

sorry about my typos... I am not 100% sure FFT can be used , but i have read 3 papers that tell how to do it. and it is for one cycle only... so, 1024 might be doable... wich is more than i get from AMG... are you still doing CFD?

On Mon, Sep 12, 2016 at 3:39 AM, Damian Hallbauer < damian.hallbauer@gmail.com> wrote:

I know what you mean.. its a trick... 1024 x1024 grids .... are too good to be true.. but i found a few papers that say it can be done... as long as the screen is one wave or less... and the borders fake the periodicity. the FFT is used only for the pressure solve. i dont konw how big can the bodies be and i am surprised if its possible then why is AMG still being used... i will have to stuff the papers.. now i am using AMG... and chimera grids... i dont can about accuracy too much..

On Mon, Sep 12, 2016 at 3:34 AM, Gonçalo Amador <notifications@github.com

wrote:

The source I provide is a Netbeans project just open an in each file with a main run individually. It will then generate the set of frames you can instead draw the triangles.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/noSoulApophis/incremental-fluids-java/issues/2#issuecomment-246199474, or mute the thread https://github.com/notifications/unsubscribe-auth/AP_LmfKMeJ3WJS3aYhrK7YasGPFiys5Hks5qpFe6gaJpZM4J56kt .

damian-666 commented 8 years ago

thanks... i wil see how you did it :) .. with distance normal.. i have CBattys variational 2d sample.. and i could do a GPU shader based collision all my particles can be checked it they pass through something thin, from the prior pixel... using a line drawn.. and a hittest shader. 1 bit buffer..... wow sorry about my typos, im very tired. this fluid stuff got too much.. im am looking at japanese 6D code.. i went insane...

On Mon, Sep 12, 2016 at 3:31 AM, Gonçalo Amador notifications@github.com wrote:

The object must be within the cells but not all cells are entirely engulfed by the objects in this case accuracy would state use the percentage of the cell occupied (more processing time). Instead use the mean between the cell old velocity and the moving object velocity at the cell (might work).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/noSoulApophis/incremental-fluids-java/issues/2#issuecomment-246199321, or mute the thread https://github.com/notifications/unsubscribe-auth/AP_LmeoTTa0_ARS-9oaXA9UFp2XC-aI-ks5qpFcTgaJpZM4J56kt .

g-amador commented 8 years ago

Case you didn't figure it out Euler solvers history for CG not for other fields (aeronautics) fluid simulation:

90's there was explicit fluids solvers but could not calculate faster that a 0.001s simulation second, i.e., for a 1 second simulation you needed to do off-line priorly 1000 runs of the fluids solver.

late 90's and initial 2000 Stam said assume the fluid is incompressible, and that it keeps as in particules moving the last direction it went and correct the error to ensure incompressibility and filter numerical error. He first gave FFT (a domain technique) that replaces calculations in R by calculations in the fourier domain, the problem in the fourier domain calculation is way faster but as soon as you are in the FFT you cannot change anything, i.e., no obstacles static or moving. Latter he suggested using successive over relaxation using GS.

Latter some experimented with GPU using shaders or CUDA using Jacabi, Red-black Gauss Seidel, multigrid or Conjugate gradient. These allow obstacles but you have to change velocities per case.

2D will often work for larger reso

g-amador commented 8 years ago

I ended the Masters in 2007/2009 ported code to Java to integrate in a Game Engine I made for the PhD not available yet. I attempted to incorporate either this code as my own and expect to port all to OpenCL or CUDA latter on when I'm working as an hobby.

But not doing any CFD now no time. I have SWE and LBM and particles code working but mostly is 2D and never had the time to report to 3D.

damian-666 commented 8 years ago

i love the stam and implicit solve and the shader solvers... im starting to learn the reinmain , weno... and astro code.... everything is connected... but here is the trick .. for FFT you use a twin for each IB you put in.. I am not sure if i can use that trick.. i put it here if you are curious..* it is in bold search this *>>>>>>>>>>>>

Penalty Immersed Boundary Method for an Elastic Boundary with Mass

Yongsam Kim∗ Charles S. Peskin Courant Institute of Mathematical Sciences, New York University, 251 Mercer Street, New York, NY 10012 USA. Preprint submitted to Elsevier Science 26 August 2005 Abstract The immersed boundary (IB) method has been widely applied to problems involv ing a moving elastic boundary that is immersed in fluid and interacting with it. But most of the previous applications of the IB method have involved a massless elastic boundary and used efficient Fourier transform methods for the numerical solutions. Extending the method to cover the case of a massive boundary has required spread ing the boundary mass out onto the fluid grid and then solving the Navier-Stokes equations with a variable mass density. The variable mass density of this previous approach makes Fourier transform methods inapplicable, and requires a multigrid solver. Here we propose a new and simple way to give mass to the elastic boundary and show that the new method can be applied to many problems for which the boundary mass is important. The new method does not spread mass to the fluid grid, retains the use of Fourier transform methodology, and is easy to implement in the context of an existing IB method code for the massless case. Key words: immersed boundary method, penalty method, massive elastic boundary, filament, windsock, flag, inflow velocity, FFT 1991 MSC: 65-04, 65M06, 76D05, 76M20 ∗ Corresponding author. Present address: ICES, University of Texas at Austin, Austin, TX 78712, USA. Email addresses: kimy@ices.utexas.edu (Yongsam Kim), peskin@cims.nyu.edu (Charles S. Peskin). 2 1 Introduction The purpose of this paper is to propose a simple way to extend the immersed boundary (IB) method to a situation in which an elastic moving boundary has mass that cannot be neglected and to show several examples of the application of this new methodology. In the examples chosen, the boundary mass plays a crucial dynamical role. This is in contrast to most previous applications of the IB method, in which the immersed boundary was either massless or neutrally buoyant in the ambient fluid. The IB method was developed to study flow patterns around heart valves, and is a generally useful method for problems in which elastic materials interact with a viscous incompressible fluid. In the IB formulation, the influence of the elastic material immersed in the fluid appears as a localized body force acting on the fluid. This body force arises from the elastic stresses of the material. Moreover, the immersed material is required to move at the local fluid velocity as a consequence of the no-slip condition. The central idea of the IB method is that the Navier-Stokes solver does not need to know anything about the complicated time-dependent geometry of the elastic boundary, and that therefore we can escape from the difficulties caused by the interaction between the elastic boundary and the fluid flow. This whole approach has been applied successfully to problems of blood flow in the heart [18,20–23,25], wave propagation in the cochlea [3,6], platelet aggregation during blood clotting [5], and several other problems [2,8,9,11,13]. In these applications, however, the elastic boundaries have no mass. (In the case of a thick “boundary” like the muscular heart wall, the corresponding 3 assumption is that the boundary is neutrally buoyant, so that the mass of the volume occupied by the boundary is the same as if it were occupied by fluid.) The massless assumption appears in one version of the mathematical derivation of the IB method [19,21,23], see however [7,28], and can be applied when the mass of the moving boundary is too small to have a significant effect on the overall motions of the fluid and the elastic material. With the massless assumption, however, we cannot approach many other problems for which the boundary mass is important. Consider, for example, the simulation of a flapping filament in a flowing soap film as studied by Zhu and Peskin [27,28], who have shown that a massless filament does not flap at all, and that filament mass is essential for the sustained flapping that is seen not only in simulations with mass but also in laboratory experiments [26]. Subsequent experiments (J.Zhang, personal communication) have shown as predicted that an extremely fine filament fails to flap under the same conditions in which flapping of a more massive filament had been seen. Many other examples, in which the massless assumption is not reasonable arise in aerodynamics. Since air is such a light fluid, it is usually the case that elastic boundaries immersed in air have mass that cannot be neglected. Not only the inertial effect of the boundary mass but also the effect of gravity on the boundary mass are important. We study several such examples in this paper. In [7,28], the method used to handle boundary mass was to spread that mass out onto the fluid grid, in much the same manner as boundary force is conven tionally applied to the fluid grid in the IB computations. When this is done, a variable density ρ(x,t) appears in the Navier-Stokes equations, and this com plicates the numerical solver of those equations. Specifically, it makes Fourier methods inapplicable and requires that an iterative method like Multigrid be 4 used instead. This introduces the question of what stopping criterion to use for the iterative solver, i.e., how to optimize the tradeoff between accurate solution of the difference equations at each time step and the computational cost of doing more iterations per time step, a question which does not arise when a direct solution method is available. >>>>>>>>>>>>>>>>>> Our current approach stays much closer to the IB method for the massless case. In particular, it does not spread mass to the fluid and so it requires the same constant-density Navier-Stokes solver as is used in the massless case. The key idea is to introduce a massive boundary point as a twin of each immersed boundary marker where mass is needed. We assume that the massive boundary thus introduced does not interact directly with the fluid and that the original immersed boundary, which will play the same role as in the original IB method, has no mass. The two boundaries are supposed to be the same, and when they move apart, a strong restoring force arises to pull them back together. This is done with a collection of stiff springs connecting the two boundaries. The massive boundary moves according to Newton’s law (F = ma) in which the only forces acting are the forces of the stiff springs and the gravitational force. Meanwhile, at the other end of each spring, the massless boundary marker is moving at the local fluid velocity and spreading force locally to the fluid grid. Among the forces that it spreads is the force on the boundary marker due to the stiff spring (equal and opposite to the force acting on the massive boundary). Because the spring is stiff, the massive boundary point stays close to its twin immersed boundary marker, and the overall effect is that the boundary has mass. Even though the two boundaries (which we call massive and massless bound aries) are supposed to coincide, we allow them to separate by an amount that 5 depends inversely on the stiffness of the spring connecting them. The stiffness parameter of this spring is analogous to a penalty parameter in a constrained optimization problem, which is why we call this new mass-handling idea the penalty immersed boundary (pIB) method. We shall see later that, in the limit of infinite spring stiffness, the two boundaries coincide, and the results obtained by the pIB method approach those of the version of the IB method used by Zhu and Peskin [27,28] for the massive case. 2 Equations of Motion We begin by stating the mathematical formulation of the equations of the motion for a system comprised of a three-dimensional viscous incompressible fluid containing an immersed, elastic boundary with mass [19]. ρ( ∂u ∂t

On Mon, Sep 12, 2016 at 4:05 AM, Gonçalo Amador notifications@github.com wrote:

Case you didn't figure it out Euler solvers history for CG not for other fields (aeronautics) fluid simulation:

90's there was explicit fluids solvers but could not calculate faster that a 0.001s simulation second, i.e., for a 1 second simulation you needed to do off-line priorly 1000 runs of the fluids solver.

late 90's and initial 2000 Stam said assume the fluid is incompressible, and that it keeps as in particules moving the last direction it went and correct the error to ensure incompressibility and filter numerical error. He first gave FFT (a domain technique) that replaces calculations in R by calculations in the fourier domain, the problem in the fourier domain calculation is way faster but as soon as you are in the FFT you cannot change anything, i.e., no obstacles static or moving. Latter he suggested using successive over relaxation using GS.

Latter some experimented with GPU using shaders or CUDA using Jacabi, Red-black Gauss Seidel, multigrid or Conjugate gradient. These allow obstacles but you have to change velocities per case.

2D will often work for larger reso

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/noSoulApophis/incremental-fluids-java/issues/2#issuecomment-246201283, or mute the thread https://github.com/notifications/unsubscribe-auth/AP_LmSFQh66gqRj2-PDrRtJ4QHJ8Do-Dks5qpF8jgaJpZM4J56kt .

damian-666 commented 8 years ago

i am looking at the CIP method.. a japanese guy made a 6D method 20 years ago.. this is for details on the surface flow.. and accurate waves in 2d.. and 3d.. im exhausted though.. adaptive mesh is also the new think.. every week i learn a new scheme and i never get to the bottom.

On Mon, Sep 12, 2016 at 4:08 AM, Gonçalo Amador notifications@github.com wrote:

I ended the Masters in 2007/2009 ported code to Java to integrate in a Game Engine I made for the PhD not available yet. I attempted to incorporate either this code as my own and expect to port all to OpenCL or CUDA latter on when I'm working as an hobby.

But not doing any CFD now no time. I have SWE and LBM and particles code working but mostly is 2D and never had the time to report to 3D.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/noSoulApophis/incremental-fluids-java/issues/2#issuecomment-246201390, or mute the thread https://github.com/notifications/unsubscribe-auth/AP_LmfPth_FrTzf3aJCm6REN8GEtlHegks5qpF-rgaJpZM4J56kt .

damian-666 commented 8 years ago

you might like IVOCK code it will help put the code in the size hat fits in WARP.. it can do cuda and open cl i think..

and people say copy datat to the gpu is costly.. so then they do everything on GPU or use compressed grids and WARP sizes or streams... IVOCK is on github..its a vorton method tho..

On Mon, Sep 12, 2016 at 4:08 AM, Gonçalo Amador notifications@github.com wrote:

I ended the Masters in 2007/2009 ported code to Java to integrate in a Game Engine I made for the PhD not available yet. I attempted to incorporate either this code as my own and expect to port all to OpenCL or CUDA latter on when I'm working as an hobby.

But not doing any CFD now no time. I have SWE and LBM and particles code working but mostly is 2D and never had the time to report to 3D.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/noSoulApophis/incremental-fluids-java/issues/2#issuecomment-246201390, or mute the thread https://github.com/notifications/unsubscribe-auth/AP_LmfPth_FrTzf3aJCm6REN8GEtlHegks5qpF-rgaJpZM4J56kt .

g-amador commented 8 years ago

Used GPU before with CUDA and OpenCL the times in the thesis actually can be way faster.

damian-666 commented 8 years ago

20x faster? or 4x... i read for the fast FFT it doesnt matter.. better do it on the CPU. or where ever the data is ... visual studio update has some texture compression stuff .. and i read if its 64k i think.. its fits in one warp.... i might try Cudaify.. .. i was doing almost realtime mandelbrot at full resolution...with an opencl demo.. so im planning ot use some 1 bit.. 2 bit .. paletted bitmaps..if i have to pass them around.

i would love if openCL finds the processor in skylake, and if the is an AMD or nvidia ,,the we could use them both on newer machines.. skylake GPU on the chip is almost good enough,, not quite ... so alot of systems will have two powerful gpus. i cant seem to query my intel one..but i think its too old..

im still thinkingo of the FFT solv.. there are alot of tricks.. here are a few more papers.. if its just for pressure solv in air...the presence of one small 2d character, would not ruin it..just not be perfectly accurate? the FFT region might just be the sky ... then using some other grids in chimera style....

i guess its pretty easy to try them... for a side scoller game.. the boundaries are often good enough..

http://ms.mcmaster.ca/~bprotas/MATH745c/spectr_01.pdf

http://ufrmeca.univ-lyon1.fr/~buffat/FDMIF/articleIBM.pdf

.https://people.eecs.berkeley.edu/~demmel/cs267_Spr05/Lectur es/Lecture26/Lecture_26_AMR_part2_PhilColella_05.pdf

On Mon, Sep 12, 2016 at 5:06 AM, Gonçalo Amador notifications@github.com wrote:

Used GPU before with CUDA and OpenCL the times in the thesis actually can be way faster.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/noSoulApophis/incremental-fluids-java/issues/2#issuecomment-246204629, or mute the thread https://github.com/notifications/unsubscribe-auth/AP_LmaSlxuQrAmU6MHvW0vp0Sgat3H8Fks5qpG1RgaJpZM4J56kt .

damian-666 commented 8 years ago

Hello again. I have compared your code and yes it appears there is is basically a straight port from tunabrain.

thanks for porting it .. i think i might giveit a port to c# unless you know a better way to do multiple density gas with immersed boundary. I have tried stuff and play to try more with this code and solver. So just letting you know my plan and about a few more things i read about that might interest you.

I have found some but the license is GPL... i dont think a port to c# will clear me. I dont want to show my creature code just because they swim in someone elses fluids..

I think i am going to try it.. i like what i see so far. I do wan air over water eventually.. and definitely Adaptive grids..

but the results for multiple density are good.. when the object is hot.

I dont get convergence on the second pass and so I tried to set the velocity only after the entire solve This is a very weak coupling. Then as you suggested , i move the fluid around the object using a direct setting of the fluid velocity ( will need to be careful of the maximum change or flux allowed) . and apply panel drag to my IB based on the density near the panel.

because my immersed object is small compared to the gas, ( in air) and speed is far more important than accuracy, I tried this with fair results. the gass seems pushed out of the way if the box is thick enough.

It seems, why should the solver need to know the velocity of the IB if it will simply be one frame late? by then it will be reflected in the fluid using a direct forcing as the initial conditions.

-solve pressure. ( without the velociy of IB objects)

-draw

-apply drag.

-apply direct forcing . repeat

I dont know exactly why it didnt converge, i think that the velocity needed to be multipled by DT in some places. However, it still didnt solve.

I find good enough results using the panel method, adding a drag = 1/ vel * vel x panel length normal to the relative flow , at two points on each panel that is a loose body. skipping all small panels.

Ghost matter might be needed to "thicken" panels, or use collision detection for each particle.. if i use shaders to manage the particles and detect collisions using graphics AND code

I dont feel i was to use vorton methods are there are tons..

So, the solver there seems good enough if the grid is less that 256 x256 I will look for a shader version. Or i will try to Cudaify it...

But herer is another IB method i havent explored...

https://github.com/barbagroup/petrbf

I have FLIP code from Martin Quay that uses a graphics Guassian Splat to determine the density graphically. For 2d there are many tricky and "visual" ways to solve for pressure, and some are begging for an all shader solution. for the collision, for the density , the retendering, and the fluid dynamics. I get about 200,000 particles... but its too slow... no temperature.. no level sets...not adaptive grid...

But i am still wondering about using a 1024x1024 grid for the entire atmosphere..

a google for Spectral methods on incompressible fluids shows many ways.

periodic meaning inflow on one end, equal outflow of mass on the other ( and hidden stuff in the margins)

For a two phase free boundary i am not sure. Perhaps two solvers entirely: one for air, using the water surface as an IB.. and taking its velocity in the normal direction at as affecting the fluid velocity near the interface, and vice versa to a different extent based on the mass ratio.

I do see FFT on GPU solutions. https://slashdot.org/story/06/05/29/1424213/high-performance-fft-on-gpus

in python there are many ways to do IB. but i hate python.. i could use Ironpython since it compiles... or .net..

and i find many papers on using th e FFT for a pressure solve.

48x thats what i like. i even see 1000x when using Jacobi free Krylov methods..

http://www.nvidia.com/content/new_cudawmfg/cudabrowser/ assets/data/applications.xml

its really easy to just read and read and read...

just sharing some stuff.

On Mon, Sep 12, 2016 at 9:27 AM, Damian Hallbauer < damian.hallbauer@gmail.com> wrote:

20x faster? or 4x... i read for the fast FFT it doesnt matter.. better do it on the CPU. or where ever the data is ... visual studio update has some texture compression stuff .. and i read if its 64k i think.. its fits in one warp.... i might try Cudaify.. .. i was doing almost realtime mandelbrot at full resolution...with an opencl demo.. so im planning ot use some 1 bit.. 2 bit .. paletted bitmaps..if i have to pass them around.

i would love if openCL finds the processor in skylake, and if the is an AMD or nvidia ,,the we could use them both on newer machines.. skylake GPU on the chip is almost good enough,, not quite ... so alot of systems will have two powerful gpus. i cant seem to query my intel one..but i think its too old..

im still thinkingo of the FFT solv.. there are alot of tricks.. here are a few more papers.. if its just for pressure solv in air...the presence of one small 2d character, would not ruin it..just not be perfectly accurate? the FFT region might just be the sky ... then using some other grids in chimera style....

i guess its pretty easy to try them... for a side scoller game.. the boundaries are often good enough..

http://ms.mcmaster.ca/~bprotas/MATH745c/spectr_01.pdf

http://ufrmeca.univ-lyon1.fr/~buffat/FDMIF/articleIBM.pdf

.https://people.eecs.berkeley.edu/~demmel/cs267_Spr05/Lectur es/Lecture26/Lecture_26_AMR_part2_PhilColella_05.pdf

On Mon, Sep 12, 2016 at 5:06 AM, Gonçalo Amador notifications@github.com wrote:

Used GPU before with CUDA and OpenCL the times in the thesis actually can be way faster.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/noSoulApophis/incremental-fluids-java/issues/2#issuecomment-246204629, or mute the thread https://github.com/notifications/unsubscribe-auth/AP_LmaSlxuQrAmU6MHvW0vp0Sgat3H8Fks5qpG1RgaJpZM4J56kt .

damian-666 commented 8 years ago

just ignore these if they make no sense i am still learning. and i am only interested in 2d physics for my project.​

BTW .. if you havent seen this .. its MIT GPU + java + processing... https://github.com/diwi/PixelFlow im going to try it but it might suit you more than me.. http://thomasdiewald.com/blog/

i sent this because you didnt like the FFT method with IB .. and i have a hard time also to believe, since its is so much faster on large grids than others which we see normally used .. the MG.. the preconditioners.. the CG.. the interative solvers... but i find here a nice paper again..​ and it makes sense. the idea is the BC must be periodic at left and right and top and bottom not sure.. but we can hide that in the margin of the viewport. if the flow leaves the viewport.. we can force it in the Y direction so that it doesnt resemble what left... for my top and bottom i would put a margin.. and have a "jet stream" or fast wind with low shear. for my bottom i would have an ocean flow or some simply decribed sine shaped hills ( easiest for the solver)

One can use the liquid surfaces as an Immersed boundaries as well. use a level set represent it..advence that level set and use a rough grid to the bottom or maybe the shallow equations.. or... solve a separate grid for the water..

A ​nd here is the central idea.. in the 2015​

​IMERSPECMETHODOLOGYFORTWO-PHASEFLOW

​The Fourier pseudospectral method, is a methodology of high rate of numerical convergence and has high accuracy and low computational cost when compared with other methodologies of high accuracy due to the use of the algorithm namedFastFourierTransform(FFT).ItisalsoobservedthatfortheNavier-Stokesequations,consideringincompressible 1The term accuracy is used in this report as the difference between the numerical solution and real solution.

flow in spectral space, the projection method can be used to eliminate the pressure gradient term, leading to uncoupling of the pressure-velocity fields without the need to solve the Poisson equation for pressure. The major limitation of this methodology is in the boundary conditions, which must be periodical in order to apply the Fourier spectral method, (Canuto et al., 2007). However, Mariano et al. (2010) overcame this limitation by coupling the Fourier pseudospectral method with the immersed boundary method, which allowed to simulate non-periodic problems, using pseudospectral method. The search ​ which allowed to simulate non-periodic problems, using pseudospectral method. The search for more accurate and low computational cost for the simulation of two-phase flow methods is of great interest for industry, since they require information from the flows with higher level of accuracy. This justifies financial support and technical cooperation of Petrobras in the present work. Thus, the purpose of the present paper is to show a proposition of a new mathematical and computational methodology to solve two-phase flows gas-liquid, liquid-liquid or gas-gas problems which provides at the same time, high computational efficiency and high accuracy. For this we used Fourier pseudospectral method (FSM) coupled with immersed boundary (IB) and with the Front-Tracking method (FTM). Results obtained by analysis through numerical experiment of rising bubbles show that the proposed method can be considered validated and very promising.

  1. MATHEMATICALMODELINGFORTWOPHASEFLOWS The present work is based on the merging FSM, IB and FTM method. As shown in Fig. 1, the fluid as a whole is representedby Ω = Ω1∪Ω2 domain. Theinterface Γ iscalledLagrangian,whichcanmoveanddeform. Thesubdomains Ω1 and Ω2 represents the outside and inside of the interface Γ, respectively. Variables with uppercase letter are related to Lagrangian domain and variables with lowercase letter are related to Eulerian field.