New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Biased Air simulation? #668
Comments
EDIT: This comment has been proven incorrect. Leaving it for context only. The bias is probably caused due to the fact the air sim doesn't try and separate old state from the existing state. |
That's not actually true. It does separate old state from existing state. The main loop at the bottom puts values in ovx/ovy/opv, then at the end copies them into the real maps (vx/vy/pv). There is some code above this that modifies vx/vy/pv directly without the o maps, but it's fine because it doesn't use the values of nearby cells in any of those calculations. It's all based off the current cell (reducing pressure/velocity by a fixed amount), or based off the values of other maps entirely (recalculating pressure based on velocity, and velocity based on pressure) |
I found the code in air.cpp for (y=1; y<YRES/CELL; y++) //pressure adjustments from velocity
for (x=1; x<XRES/CELL; x++)
{
dp = 0.0f;
dp += vx[y][x-1] - vx[y][x];
dp += vy[y-1][x] - vy[y][x];
pv[y][x] *= AIR_PLOSS;
pv[y][x] += dp*AIR_TSTEPP;
} I thought that it can cause an oddity because it refers only 3 cells(itself, up, and left) instead of 5 cells(diamond neighbors) or 9 cells(square neighbors). I'm afraid that I have no access to my PC right now. So, I'll try to fix it later. |
I solved this problem in my mod The Realistic Physics, here I have the code showing how I did it: https://github.com/wisecase2/TPT-RealisticPhysiscsMod/blob/master/src/simulation/Air.cpp |
Can you clarify what you changed that fixed it? The only relevant commit I can find in your mod's source code is this one: wisecase2/TPT-RealisticPhysiscsMod@073c02f#diff-0c4569b7a5fe2a550c144fcd24647658 It seems like it modifies the handling of pressure / velocity on the edges, to not reduce it as much as vanilla TPT does. |
Code: https://github.com/wisecase2/TPT-RealisticPhysiscsMod/blob/master/src/simulation/Air.cpp |
"clear velocities near walls": I never really understood why we do the -1 thing, but your change may be nice in that it keeps things consistent (handle blocks at x/y=0). But this change is probably irrelevant. "pressure adjustments from velocity" / "velocity adjustments from pressure": hmm, seems like a good change because it keeps things consistent again, and doesn't only look at -1 (also looks at +1 now). Would need to look at how much it changes the air sim though, since this is a logic change and may affect how fast air / velocity flow across the simulation. "removed the pressure if it's on the blockair": probably a good thing, does it prevent pressure from leaking into walls? I always thought it was strange how it did that, but it seemed to not matter much. Making this change would affect TTAN, which is something to consider (if you're doing what I think you are doing, it makes TTAN better though). Changes to avoid reflection are good, I never liked the reflection on the edges so anything to try avoiding them is a good idea. pressure / velocity caps: interesting change. Would only matter when velocity gets really high, but I think you're onto something here Anyway, I will play around with the changes if I have time, and maybe merge them into the official version. These changes look pretty good. |
I updated the code now. |
Sorry for suddenly submitting the issue!
The velocity simulation seems to be a little bit "biased" to top and left.
The save 2450148 shows you what happens.
You will notice that the STREAMLINEs are bent asymmetrically.
The text was updated successfully, but these errors were encountered: