Pressure and Temperature Simulation Hitch

Hey Folks! Unfortunately, slow day today. Doctor's appointment in the middle of the afternoon. And some paperwork catch-up in the morning.

However, I did manage to make a little progress on the room atmosphere simulator. In fact, I think I got it working just right when only two rooms were interacting. However, if a room had more than one open door in it (like a corridor or galley), things got weird. Like, pressure would ping-pong around the rooms, spike, and suddenly drop to negative or positive infinity.

Some of it was down to my code processing the same room multiple times in a simulation cycle, and that was pretty easy to fix. However, I think part of it has to do with my hacky attempt at mixing temperatures.

I'm not interested in doing complicated integrations or calculus for extremely accurate gas exchange. (At least, not here.) I just want rough approximations "good enough" to convince the player. Unfortunately, pressure is related to temperature for a gas. So is volume. And in the case where an airlock opens between two rooms with potentially different temperatures and pressures, we have all of those variables changing.

I think one of the ways to work out such a problem is to do things one step at a time. E.g. pressure first, then heat exchange. And I'm going to try that next. Though, probably a part of my problem is that I'm also not very realistic in my calculations, and I'm creating or destroying energy/matter in the process.

Anyway, I'll try again tomorrow to see if I can get something "good enough." Game jam mentality calls, after all!

Comments

danabnormal's picture
danabnormal

You've got me thinking about this problem now...

Would a quick and dirty way be to set a rooms 'influence priority' based on its size? So in your example the hangar would have a priority of 10, the closet a priority of 1, and this can be used in the calculation to figure out which area has the most influence on gas exchange/temperature etc. Space could have an influence of 10,000 which would mean a hull breach would vent any gases/temperature in to the void.

Just a thought!

Malacodor's picture
Malacodor

Sounds like pairwise equalization isn't the best way. I've never been good at thermodynamics, but can't you just add up the amounts of gas and the thermal energy of all connected rooms (since both should remain constant in total), then calculate the temperature and pressure of the combined volume and finally set each room's variables to these values?

Or just recalculate the room pressures and change the temperature by a random value for now. ;-)

Did you think of a way to handle holes in internal walls? They should act like open doors for atmosphere exchange, but like walls for pathfinding if too small to get through.

Ran around with a clown mask before it was cool

dcfedor's picture
dcfedor

@danabnormal, that's kind of how it works now. The rooms each have a volume set by their number of tiles. And these volumes are part of the equation that handles the gas exchange.

Technically, the amount of a gas (moles) and temperature (K) also figure in, because these tell us what pressure the gas is at. Then, once the pressure is figured out for each room, the one with higher pressure spills into the lower pressure at a rate proportional to their pressure difference.

And for the void of space, it's assumed to have a pressure and temperature of near zero, and it never changes. So any pressure inside the ship gets vented out no matter what.

@Malacodor, I ended up doing something sort of like that. In the end, the rooms exchange gas by mass, not pressure. (Since mass is a basic value, and pressure is a derived one.) But the pressure is still used to tell how much gas is exchanged and in which direction.

After that, temperature is figured out for each room pair. And in both values, the deltas are calculated for all rooms before they get applied.

I think I've solved the problem now by adjusting the temperature portion of the exchange to be limited in rate similar to the pressure. Before, I was trying things like averaging the room temperatures, weighting the averages by mass, etc.

But it turns out that the main issue was the temperature delta being too high at any one time, causing a cascade of fluctuations that got larger and larger. Simply going with the weighted (by mass) averaging of room temperatures and limiting the delta to ~1/8th the calculated value (approximating exposure only on one side of a square, and in one direction), the temperature stays stable and adjusts in an intuitive way.

"Good enough!" :)

Dan Fedor - Founder, Blue Bottle Games