How does PowderToy calculate air?

  • Videogamer555
    17th Jan 2018 Member 0 Permalink
    I mean the classic version of the calculation, before ambient heat was introduced. I'm trying to write my own accoustic wave simulator, but I don't know the algorithm that TPT is using. I know it needs to use the air pressure from the current (and neighboring) pixels in order to calculate the velocity at the current pixel. Likewise, I know it uses the air velocity from the current (and neighboring) pixels in order to calculate pressure at the current pixel. Ok, technically it's 4x4 blocks of pixels, but within the air array itself, it can be thought of as a single pixel. I need to know how these pressure and velocity calculations are done. Any help would be much appreciated. Maybe a code snippet posted here would be good (particularly if you have a copy of the old version of the source code, before ambient heat and other effects were introduced that effect the pressure and velocity). I have tried looking at the recent version the air portion of TPT's source code and it really is just so complicated that I have no idea what calculations are actually being done, but I vaguely remember looking at an older version of the code a while ago, and wish I had kept that, because I remember it was a lot easier to understand.
  • zaccybot2
    23rd Jan 2018 Member 0 Permalink

    You can find any version of the source code on the game's GitHub page (here). The air calculation is in src\simulation\Air.cpp  under the function update_air.

  • Videogamer555
    26th Jun 2018 Member 0 Permalink

    zaccybot2:

    You can find any version of the source code on the game's GitHub page (here). The air calculation is in src\simulation\Air.cpp  under the function update_air.



    Trying to figure out the "//update velocity and pressure" part of this. The "//pressure adjustments from velocity" and "//velocity adjustments from pressure" make sense. However, I'm not understanding what the 3rd step does, where it simultaneously updates both pressure and velocity.
    Edited once by Videogamer555. Last: 26th Jun 2018
  • moonheart08
    26th Jun 2018 Member 0 Permalink

    @Videogamer555 (View Post)

     I know this isn't very helpful but: Good luck. Even the devs have a little trouble understanding exactly what it does :P

  • tptquantum
    26th Jun 2018 Member 0 Permalink

    Videogamer555:

    zaccybot2:

    You can find any version of the source code on the game's GitHub page (here). The air calculation is in src\simulation\Air.cpp  under the function update_air.



    Trying to figure out the "//update velocity and pressure" part of this. The "//pressure adjustments from velocity" and "//velocity adjustments from pressure" make sense. However, I'm not understanding what the 3rd step does, where it simultaneously updates both pressure and velocity.

     Try to comment it out and try running the code, you could have an idea of its use, I guess.

  • Videogamer555
    26th Jun 2018 Member 0 Permalink

    moonheart08:

    @Videogamer555 (View Post)


     I know this isn't very helpful but: Good luck. Even the devs have a little trouble understanding exactly what it does :P


    So the devs at Powder Toy basically copied and pasted some wave simulation code from some other site, and really don't understand how it works?
  • jacob2
    26th Jun 2018 Member 0 Permalink
    @Videogamer555 (View Post)
    He means that the dev that wrote the air code stopped developing tpt. Don't make those kind of assumptions ...

    I understand a bit of it, but generally don't modify the code because it has always worked well enough. I could try to answer some of your questions (when I'm not at work) or ask the person who originally wrote the air code.
  • mniip
    26th Jun 2018 Developer 3 Permalink
    @Videogamer555 (View Post)
    The person who wrote this is Skylark who's like super proficient at physics and numeric analysis unlike pretty much all other devs. The code always worked so no one had any reason to investicate why or how it works.
  • moonheart08
    27th Jun 2018 Member 0 Permalink

    @Videogamer555 (View Post)

     Yea, i'm saying the guy who wrote the code doesn't dev TPT anymore. and well yea jacob1 and mniip explained what i ment.

  • ALark
    27th Jun 2018 Member 0 Permalink

    The model is not particularly physically accurate, because that's not the goal. (The goal is to look really good.) However, it's not completely divorced from the underlying physics. The third step does a few things:

    • models viscosity of air by smoothing between neighboring cells using a simple kernel,
    • models inertia of air by adding an amount (AIR_VADV) of velocity and pressure from a cell at [x-vx*F,y-vy*F] to a cell at [x,y], where [vx,vy] is velocity at [x,y]; note that the sampler used is bilinearly interpolated so [vx*F,vy*F] can be fractional.

    Overall, those two operations are responsible for vorticity in TPT.