Skip to content
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

Open
MineCake147E opened this issue Aug 6, 2019 · 9 comments
Open

Biased Air simulation? #668

MineCake147E opened this issue Aug 6, 2019 · 9 comments
Labels
Simulation oddity that shouldn't happen

Comments

@MineCake147E
Copy link

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 save

@LBPHacker
Copy link
Member

Yep, air simulation is weird. #580 #622

@LBPHacker LBPHacker added the Simulation oddity that shouldn't happen label Aug 6, 2019
@moonheart08
Copy link
Contributor

moonheart08 commented Aug 6, 2019

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.
This means that it'll end up using new air values to update old air values.

@jacob1
Copy link
Member

jacob1 commented Aug 6, 2019

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)

@MineCake147E
Copy link
Author

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.

@wisecase2
Copy link

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

@jacob1
Copy link
Member

jacob1 commented Oct 19, 2019

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.

@wisecase2
Copy link

Code: https://github.com/wisecase2/TPT-RealisticPhysiscsMod/blob/master/src/simulation/Air.cpp
On line 188 "clear some velocities near walls", I removed the speeds on and around the blockair.
In 212 "pressure adjustments from velocity" I added the differences to the right and up, ignoring the edges to avoid reflection, and then removed the pressure if it's on the blockair.
In 238 "velocity adjustments from pressure" Differences were added and ignoring the edges, removing the speed on and around the blockair, I modified it to make it also down and to the left of the blockair and ignoring the edges.
At 356 to 371 "pressure / velocity caps" I made the speed limitation in a circular way, this solves the problem of airflow dominating at high speed diagonals.
At 147 to 186 "decreasing pressure / velocity on the edges every frame" I modified it to reduce edge reflection.

@jacob1
Copy link
Member

jacob1 commented Oct 19, 2019

"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.

@wisecase2
Copy link

I updated the code now.
At line 221 "pressure adjustments from velocity" and 237 "velocity adjustments from pressure" the code has been optimized.
From line 325 at "Trying to take speed from far away, check whether there is an intervening wall. Step..." I fixed the symmetry problem.
At lines 70, 79, 168 and 182 under "decrease pressure/velocity...", I optimized the code and put it in for loop, which makes it easy to change values using the boundary_coeffs[] variable which is defined in the make_kernel() method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Simulation oddity that shouldn't happen
Projects
None yet
Development

No branches or pull requests

5 participants