# Null's Math Problem for 6 Months



## Null (Dec 13, 2020)

I last asked this question 6 months ago and I want to know the answer.




Cube A and Cube B are complex mixtures of gasses (possibly one, more than one, possibly incongruous in both chemical makeup and amounts, sometimes one is even a vacuum). When they are adjacent to each other with no barrier between them at all, I need to be able to take a delta time and say "this much content has moved from System A to System B" or vice versa.

i.e. I know everything about the cubes dimensions, I know everything about the cubes contents, I have precise information about the particles (moles, molar mass, kinetic diameter, heat capacity, etc). I just need to be able to say "0.3 seconds have passed, and now I am subtracting contents from Cube B and adding them to Cube A."


----------



## Arm Pit Cream (Dec 13, 2020)

You have autism


----------



## Marissa Moira (Dec 13, 2020)

Zero, with that mixture they dissipate


----------



## Null (Dec 13, 2020)

Marissa Moira said:


> Zero, with that mixture they dissipate


they're in fucking boxes they're not going anywhere


----------



## Marissa Moira (Dec 13, 2020)

Null said:


> they're in fucking boxes they're not going anywhere


They didn't say the boxes had tops


----------



## kosher bath salts (Dec 13, 2020)

Can't you just cook amphetamines like a normal human being?


----------



## The Cunting Death (Dec 13, 2020)

Why do you want to know this


----------



## Jimmy Durante's Ballsack (Dec 13, 2020)

Josh are you making a bomb you can tell us it's okay.


----------



## Fascist Frederick (Dec 13, 2020)

kosher bath salts said:


> Can't you just cook amphetamines like a normal human being?


My first thought was something SS13 related but you may be onto something here.


----------



## Alrakkan (Dec 13, 2020)

Ill get on this, nigga's got some work to do for uni tonight then I'll look through available literature.


----------



## kosher bath salts (Dec 13, 2020)

Jokes aside, keep us informed if you find the solution.
I'm extremely interested, why? Because I have autism, yes sir.
But perhaps the first step, before obtaining delta time, is translating 20C and 40C into Kelvin, because Celsius degrees don't tell you jack shit.
And then it's computing if this is a closed system or not, because it's an open system the atmospheric preasure will have an effect on fluid behavior and friction.
Other than that, I have no fucking idea how you model entropy in a system with regards to time.


----------



## Ruin (Dec 13, 2020)

The answer is obviously niggers.


----------



## Exigent Circumcisions (Dec 13, 2020)

Is this about the gas chambers during the Holocaust?


----------



## EryngiumLostHisKeys (Dec 13, 2020)

Soon it will all be clean.


----------



## Jones McCann (Dec 13, 2020)

It would help to know why you need a solution. Is it for SS13? Homework? Curiosity?


----------



## MrTroll (Dec 13, 2020)

Anyone who uses this site and can answer advanced mathematical questions like this should be on an FBI watchlist.


----------



## LMFAOForgotPw (Dec 13, 2020)

can i assume boxes are just slammed together with no possible loss? And just to be clear you want to know the answer for a vacuumed chamber and I assume sealevel? gimme that and I’ll try doing some math.


----------



## Rusty Crab (Dec 13, 2020)

Could you just get a fluid dynamics simulator and plug in the numbers? Are you looking for a more general equation/algorithm? Is this for a game or...?


----------



## Cowboy Boot (Dec 13, 2020)

Wouldn't this also be affected by temperature?
Edit: I'm blind.


----------



## LMFAOForgotPw (Dec 13, 2020)

Cowboy Boot said:


> Wouldn't this also be affected by temperature?


Temp is box a is 20C (293.15 Kelvin) box b is 40C (313.15 Kelvin)


----------



## Pampered Degenerate (Dec 13, 2020)

I don't know the answer, but this looks like a good place to start:



			https://en.m.wikipedia.org/wiki/Fick%27s_laws_of_diffusion


----------



## Yotsubaaa (Dec 13, 2020)

Null if this is for your game then I stand by the answer I had in the previous thread: just use really basic rate equations or something for this, don't worry about it being thermodynamically perfect. At best it'll just be a lot of complicated equation solving for something barely anyone is going to appreciate, and _at worst_ you'll end up with the "Reality is Unrealistic!" case: where your users will _think_ the equations are fucked because the system doesn't react the way they expect a _video game heat system_ to react.

If you still want the 'proper' solution anyway, a lot of the Kiwis in that original thread did some solid work. (e.g. here, here, here (using  simple rate equations, go figure), here...)


----------



## Rusty Crab (Dec 13, 2020)

IF this is for a game, and you need a somewhat more general equation, then you could use FD software to simulate many different situations and then linearly interpolate between the results as needed. Again though, I don't know what it's for, the parameter range ect...

If it's as straightforward as what you describe, then you could just simulate and take several "snapshots" as time goes on, then blend between them. That should be good enough for just about any purpose as far as presentation is concerned.

What if this is some kind of weird psychological test Null is doing on us.


----------



## Stoneheart (Dec 13, 2020)

this is just ugly math...
12mol gas with 20 °C and 13 mol with 40°  
thats 0.2924 bar and 0.3384 bar

now there is a problem, i have no idea how you determine the speed of the pressure reaching equilibrium.


----------



## Hitman One (Dec 13, 2020)

Math hard, make grug brain sore like when grug fall on rock. 

That is unironically how these threads make me feel. Mathbros, how do you do it?


----------



## Null (Dec 13, 2020)

Stoneheart said:


> now there is a problem, i have no idea how you determine the speed of the pressure reaching equilibrium.


that's not _a_ problem. that's _the_ problem. I have everything else sorted.


----------



## Bob Chipman's Podiatrist (Dec 13, 2020)

Chemical engineer here. This is an interesting mass transfer problem that's actually quite complex. You would have to use the diffusion equation because there is time dependence.

Because this is a 3D problem, an analytical solution would be somewhat difficult to get unless some dimensionality assumptions were made, so below is the numerical solution:

The diffusion coefficient of gases is very low, on the order of 1 x 10^-5, but changes with temperature. I couldn't be bothered to find the exact numbers, as it wouldn't have a big impact on the solution, especially in the timeframe asked for in the problem. There is no change in nitrogen or oxygen amount at all times. For chlorine however, there is movement from box B to box A.

0.2 sec:






1 sec.





5 sec.





Solution:





Edit: The reversed arc length refers the distance along the centerline of box B from where the boxes are joined.


----------



## Rusty Crab (Dec 13, 2020)

Rob from the Kinoplex said:


> Math hard, make grug brain sore like when grug fall on rock.
> 
> That is unironically how these threads make me feel. Mathbros, how do you do it?


Well, don't feel bad about anything involving fluid dynamics at least. That's a highly specialized and difficult field that people spend years in school for and make bank for doing successfully. I've learned that's the case with a lot of things, and often solving it 'properly' is not worth the effort. You can get equally good results by just asking an oracle and cheesing the rest. It's not cheating if it's not against the rules.



Bob Chipman's Podiatrist said:


> Edit: The reversed arc length refers the distance along the centerline of box B from where the boxes are joined.


Thank you for clarifying that.


----------



## Dyn (Dec 13, 2020)

Null said:


> that's not _a_ problem. that's _the_ problem. I have everything else sorted.


The biggest problem I see is you're using chlorine instead of phosgene. Most of the feds and bankers will survive this.


----------



## Alexander Clamilton (Dec 13, 2020)

Null said:


> they're in fucking boxes they're not going anywhere




Jesus this is gay. Fuck your gay ass question you fucking faggot. God get a life.


----------



## Bob Chipman's Podiatrist (Dec 13, 2020)

Stoneheart said:


> this is just ugly math...
> 12mol gas with 20 °C and 13 mol with 40°
> thats 0.2924 bar and 0.3384 bar
> 
> now there is a problem, i have no idea how you determine the speed of the pressure reaching equilibrium.


Equilibrium is reached after ~35 hours.


----------



## Null (Dec 13, 2020)

Bob Chipman's Podiatrist said:


> Equilibrium is reached after ~35 hours.


Really? It's that slow?

Why does it feel like if you're standing in a big room and open a jar containing a ton of some gas (like Chlorine), you'd probably see it spread around pretty fast? Is that just the energy in the air or what?


----------



## Rusty Crab (Dec 13, 2020)

Null said:


> Really? It's that slow?
> 
> Why does it feel like if you're standing in a big room and open a jar containing a ton of some gas (like Chlorine), you'd probably see it spread around pretty fast? Is that just the energy in the air or what?


I'm not an expert, but in any realistic situation, you'd probably have a door or curtain opening and that would probably create a lot of air disturbance, causing it to spread much quicker. There also isn't that much of a pressure differential in this case.


----------



## Bob Chipman's Podiatrist (Dec 13, 2020)

Null said:


> Really? It's that slow?
> 
> Why does it feel like if you're standing in a big room and open a jar containing a ton of some gas (like Chlorine), you'd probably see it spread around pretty fast? Is that just the energy in the air or what?


Two things:

1. The simulation assumes that *only diffusion is present*. When gas moves, it can move in two different ways: convection, which is the gas being carried by another fluid (think mixing cream into coffee) and diffusion, which is the movement of gas based on the random movement of gas atoms by Brownian motion. In a real room, you would likely have air moving within it.

2. The plot is based on the average concentration in the entire box. In other words, it would take ~35 hours for the chlorine concentration at every point in Box *B* to equal the chlorine concentration of every point in Box A.

Edit: Also, in this case, you can see that as you get closer to equilibrium, the equilibration rate is slower. 15-20 hours is probably enough for all practical purposes.


----------



## Stoneheart (Dec 13, 2020)

Null said:


> that's not _a_ problem. that's _the_ problem. I have everything else sorted.


that shouldnt be to complex, but i have no idea how to find the right formula...




Bob Chipman's Podiatrist said:


> Chemical engineer here. This is an interesting mass transfer problem that's actually quite complex. You would have to use the diffusion equation because there is time dependence.


thats more complex than needed, the change in pressure should be the main factor.




Bob Chipman's Podiatrist said:


> Equilibrium is reached after ~35 hours.


what? im pretty sure thats wrong.  or you mean chlorine concentration, not pressure...

we dont need that, the pressure difference is the main factor. 
Navier-stokes is the right equation to look for, but i have no idea how to get the right formula for our problem.


----------



## Rusty Crab (Dec 13, 2020)

Bob Chipman's Podiatrist said:


> Two things:
> 
> 1. The simulation assumes that *only diffusion is present*. When gas moves, it can move in two different ways: convection, which is the gas being carried by another fluid (think mixing cream into coffee) and diffusion, which is the movement of gas based on the random movement of gas atoms by Brownian motion. In a real room, you would likely have air moving within it.
> 
> ...


Is there a fluid dynamics software that you'd recommend which is reasonably beginner friendly + doesn't cost multiple arms and legs?


----------



## LMFAOForgotPw (Dec 13, 2020)

Null said:


> Really? It's that slow?
> 
> Why does it feel like if you're standing in a big room and open a jar containing a ton of some gas (like Chlorine), you'd probably see it spread around pretty fast? Is that just the energy in the air or what?


That gas is most likely under pressure. Also, if you cracked an oxygen tank open in a chamber with slightly lower pressure you wouldn’t see the same effect.


----------



## Null (Dec 13, 2020)

Bob Chipman's Podiatrist said:


> Edit: Also, in this case, you can see that as you get closer to equilibrium, the equilibration rate is slower. 15-20 hours is probably enough for all practical purposes.


In my simulation I want things to move enough that people are able to work with gasses in real time. Before I had it so that the adjacent cubes would interact with each other as quickly as possible (i.e. a cube and its 6 adjacent neighbors would equalize 30 times per second, or as fast as the framerate could allow), which _works_, but then you have an issue where something is added to the air and then suddenly the room is just completely contaminated before you can even react.

I'm really trying to keep things simple, so I'm reluctant to say "okay I need to keep track of kinetic energy in each cube as well" - especially because there are going to be tens of thousands of these if things get bigger.

In SS13, I think gas just spreads at a fixed rate, which creates odd situations where a hull breach leaves only the neighboring tiles in an 8 block radius low pressure and things like 1 tile wide doorways effectively halt depressurization for 10 minutes before it spreads out of that room.


----------



## kosher bath salts (Dec 13, 2020)

So it was a SS13 thing, what a fucking gay thread.


----------



## Rusty Crab (Dec 13, 2020)

Null said:


> In my simulation I want things to move enough that people are able to work with gasses in real time. Before I had it so that the adjacent cubes would interact with each other as quickly as possible (i.e. a cube and its 6 adjacent neighbors would equalize 30 times per second, or as fast as the framerate could allow), which _works_, but then you have an issue where something is added to the air and then suddenly the room is just completely contaminated before you can even react.
> 
> I'm really trying to keep things simple, so I'm reluctant to say "okay I need to keep track of kinetic energy in each cube as well" - especially because there are going to be tens of thousands of these if things get bigger.
> 
> In SS13, I think gas just spreads at a fixed rate, which creates odd situations where a hull breach leaves only the neighboring tiles in an 8 block radius low pressure and things like 1 tile wide doorways effectively halt depressurization for 10 minutes before it spreads out of that room.


Could you use a fluid solver library and adjust the viscosity of the air/gas? It could be more resistant to disturbance while maintaining it's ability to spread at a slow-ish rate through doorways. For dealing with the amount of cells in the scene, could you partition the scene into larger blocks that turn on/off their simulation as needed? Maybe level of detail or a simplified algorithm could also apply if complex geometry was not involved in that room.

So for instance, if a room is entirely filled with gas, there's no need to simulate it anymore right? Similarly, if the gas has not reached the room yet, you also don't need to simulate it. So that just leaves the rooms that are currently being filled to be simulated, which should be significantly less, if I had to guess.


----------



## CatParty (Dec 13, 2020)

Why not get a calculator


----------



## Bob Chipman's Podiatrist (Dec 13, 2020)

Stoneheart said:


> that shouldnt be to complex, but i have no idea how to find the right formula...
> 
> 
> 
> ...



I was referring to chlorine concentration.

Navier-Stokes solves for an unknown velocity field of a fluid. This is useful for convective flow, but again, I assumed diffusion only.

To get a good estimate of pressure, use the data I provided along with an equation of state (ideal gas law, Redlich-Kwong, Peng-Robinson etc.). Ideal gas law is by far the easiest here because there are multiple gases.


Rusty Crab said:


> Is there a fluid dynamics software that you'd recommend which is reasonably beginner friendly + doesn't cost multiple arms and legs?



Consider Simscale.com. It has somewhat limited mass transfer capabilities, but great as a free option for fluid dynamics. You do have to run the simulation on a cloud server which is really fucking annoying, but it has a very easy to use interface.



Null said:


> In my simulation I want things to move enough that people are able to work with gasses in real time. Before I had it so that the adjacent cubes would interact with each other as quickly as possible (i.e. a cube and its 6 adjacent neighbors would equalize 30 times per second, or as fast as the framerate could allow), which _works_, but then you have an issue where something is added to the air and then suddenly the room is just completely contaminated before you can even react.
> 
> I'm really trying to keep things simple, so I'm reluctant to say "okay I need to keep track of kinetic energy in each cube as well" - especially because there are going to be tens of thousands of these if things get bigger.
> 
> In SS13, I think gas just spreads at a fixed rate, which creates odd situations where a hull breach leaves only the neighboring tiles in an 8 block radius low pressure and things like 1 tile wide doorways effectively halt depressurization for 10 minutes before it spreads out of that room.


There are a couple of options here. The equilibration rate should increase with increasing concentrations of gas (which will result in a higher starting pressure in Box B), so you could increase the chlorine concentration. Convection can also be added (windows, fans etc). I apologize if this isn't helpful.


----------



## Null (Dec 13, 2020)

Bob Chipman's Podiatrist said:


> Convection


How much more complicated is the math when you add in simple airflow? like if a 3x3x3 space is broken up into 27 cubes, how easy is calculating the convections of that room if there's a in and out vent port?


----------



## Bob Chipman's Podiatrist (Dec 13, 2020)

Null said:


> How much more complicated is the math when you add in simple airflow? like if a 3x3x3 space is broken up into 27 cubes, how easy is calculating the convections of that room if there's a in and out vent port?


I can give it a shot. Can you re-draw the figure with the *location of the inlet and outlet*, along with it's *dimensions* (if its a circle, the radius/diameter is fine) and the *inlet air speed and composition*? I will have to make some assumptions about the fluid viscosity, density etc.


----------



## Null (Dec 13, 2020)

Bob Chipman's Podiatrist said:


> I can give it a shot. Can you re-draw the figure with the *location of the inlet and outlet*, along with it's *dimensions* (if its a circle, the radius/diameter is fine) and the *inlet air speed and composition*? I will have to make some assumptions about the fluid viscosity, density etc.


Don't think of it like that.






It's a grid. 3x3. Each tile is 1x1x3, with 3 cubes of atmosphere per meter, so 27 per tile, 243 for the entire room. The input vent top-right adds air to the bottom 9 cubes of the 3x3x9 stack. The input on the bottom left removes them by pulling down. Do not account for radius, just do cubes.

_How complicated is the math_ for dealing with kinetic force with gasses with this kind of set up?


----------



## Bob Chipman's Podiatrist (Dec 13, 2020)

Null said:


> Don't think of it like that.
> 
> View attachment 1786767
> 
> ...


I am a little confused by the "3 cubes of atmosphere per meter" 

The math here (at least the numerical calculations) are not difficult, especially if it can be reduced to a 2D problem. I can create a 3x3 sketch, and consider the cube in the top right to be the inflow and the bottom left cube to be the outflow. Would this be satisfactory?


----------



## Bob Barker (Dec 13, 2020)

Null said:


> How much more complicated is the math when you add in simple airflow? like if a 3x3x3 space is broken up into 27 cubes, how easy is calculating the convections of that room if there's a in and out vent port?


Honestly if you aren't looking to make a scientifically accurate simulator just play around with formulas until you get something that feels right and is fun.


----------



## Null (Dec 13, 2020)

Bob Chipman's Podiatrist said:


> I am a little confused by the "3 cubes of atmosphere per meter"
> 
> The math here (at least the numerical calculations) are not difficult, especially if it can be reduced to a 2D problem. I can create a 3x3 sketch, and consider the cube in the top right to be the inflow and the bottom left cube to be the outflow. Would this be satisfactory?


It's more than 2D.

Imagine a rubicks cube that is 1m^3. Each cube component of this (the 9 individual cubes that make up a rubicks cube) is a 'gas jar' that represents a part of the atmosphere for the purposes of the simulation. A tile 1m wide and 3m tall, so imagine 3 of those rubicks cubes on top of each other. That's the 27 atmosphere cubes that make up a single tile.

A room that is 3x3 has 9 of these tiles, with 27 atmosphere cubes each, so that 3x3 room has 81 atmosphere cubes that are diffusing into each other. If I add kinetic force to gas, then they also have to deal with direction and force.


----------



## Stoneheart (Dec 13, 2020)

Bob Chipman's Podiatrist said:


> To get a good estimate of pressure, use the data I provided along with an equation of state (ideal gas law, Redlich-Kwong, Peng-Robinson etc.). Ideal gas law is by far the easiest here because there are multiple gases.


yeah i have no idea how to do that...
i can get to the pressure difference by using the ideal gas law and i can get to the new pressure after mixing, but i have no idea how to get the speed of the mixing.



Null said:


> In my simulation I want things to move enough that people are able to work with gasses in real time. Before I had it so that the adjacent cubes would interact with each other as quickly as possible (i.e. a cube and its 6 adjacent neighbors would equalize 30 times per second, or as fast as the framerate could allow), which _works_, but then you have an issue where something is added to the air and then suddenly the room is just completely contaminated before you can even react.


you should focus on the pressure differences.
you can solve your added gas problem with it.



Null said:


> _How complicated is the math_ for dealing with kinetic force with gasses?


yes



Null said:


> A room that is 3x3 has 9 of these tiles, with 27 atmosphere cubes each, so that 3x3 room has 81 atmosphere cubes that are diffusing into each other. If I add kinetic force to gas, then they also have to deal with direction and force.


that will kill the framerate pretty fast^^

just play with a formula for pressure differences till you are happy with it and than use that formula for each gas in the mix.


----------



## Bob Chipman's Podiatrist (Dec 13, 2020)

Null said:


> It's more than 2D.
> 
> Imagine a rubicks cube that is 1m^3. Each cube component of this (the 9 individual cubes that make up a rubicks cube) is a 'gas jar' that represents a part of the atmosphere for the purposes of the simulation. A tile 1m wide and 3m tall, so imagine 3 of those rubicks cubes on top of each other. That's the 27 atmosphere cubes that make up a single tile.
> 
> A room that is 3x3 has 9 of these tiles, with 27 atmosphere cubes each, so that 3x3 room has 81 atmosphere cubes that are diffusing into each other. If I add kinetic force to gas, then they also have to deal with direction and force.


So how I am interpreting this is one component is  a rubix cube of 3x1x1 boxes like so





I may have to fuse some of the boxes to simplify the calculation, but this could work.


----------



## Mr. Skeltal (Dec 13, 2020)

The important bits of information are 1 mol chlorine gas at 40°C in one cubic meter. The other gases, 1:5 mol O2:N2 (essentially air) are of the same composition thus can be ignored. Any pressure differential present should be accounted for by the one dissimilar gas - chlorine - as it diffuses into the new system.

First we need to do conversions and note known values:
T = 40°C = 313.15K
VCl= 1 m^3
VSystem= 2 m^3
N (Avagadro's Number) = 6.02 × 10^23 1/mol
k (Boltzmann's Constant)= 1.38066 x 10^-23 J/K

Looking at the _PV=NkT_ form of the Ideal Gas Law and our knowns we can now see that pressure (P) is unknown. Using basic algebra we can solve for P.

_P=(NkT)/V_
As V=1m^3 it can be ignored in calculation (dividing by one equals the numerator; retain a token 1/m^3 for unit conversion) thus:
_P=NkT_
Now put in the rest of the known values:
_P= (6.02 × 10^23 1/mol) * (1.38066 x 10^-23 J/K) * (313.15K)_
We get 2601.64 J/mol/m^3. As we have one mole of chlorine, this rectifies to 2601.64J/m^3 or 2601.64 Pa (0.026 atm).

This would be the head pressure (for lack of a better term) of the chlorine in System B as it interfaces with System A through a 1 m^2 aperture.

I was no math whiz in school and it's been a while since I took physics, so please feel free to correct me if I botched the math or process.


----------



## Rusty Crab (Dec 13, 2020)

Not suggesting this as a solution, per say, but back when I was working with fluid simulations, I found this paper incredibly helpful when trying to build an understanding fluid forces. It takes it away from the abstract and puts it into more understandable actions. 



			https://developer.nvidia.com/gpugems/gpugems/part-vi-beyond-triangles/chapter-38-fast-fluid-dynamics-simulation-gpu


----------



## Null (Dec 13, 2020)

Bob Chipman's Podiatrist said:


> So how I am interpreting this is one component is a rubix cube of 3x1x1 boxes like so


CUBES.


----------



## Bob Chipman's Podiatrist (Dec 13, 2020)

Null said:


> CUBES.
> View attachment 1786850


Okay, so another 9 of these forms the complete cube?


----------



## Stoneheart (Dec 13, 2020)

you also should use some way to not calculate everything at the same time...

check difference of every even  cube row with the row above it in one frame, than with with the row below in the next frame, same for the sides. 
its not perfect but should help with performance.


cube 1 2pressure gas a100100pressure gas b100total pressure  110100

the next step is to find a formula to use for the change in pressure.   lets say change the difference by 1 every tick so new the we have(thats not the formula you should use!)


cube12pressure gas a100100pressure gas b91total pressure109101

you can use that system for mixtures of gas AND for pressure.


----------



## Rusty Crab (Dec 13, 2020)

Stoneheart said:


> you also should use some way to not calculate everything at the same time...
> 
> check difference of every even  cube row with the row above it in one frame, than with with the row below in the next frame, same for the sides.
> its not perfect but should help with performance.
> ...


The real shitbitch with fluid dynamics solvers is numerical stability. I wouldn't attempt to try to wing that... they have a tendency to explode really easily and at unpredictable times when kinetic forces get involved.


----------



## Stoneheart (Dec 13, 2020)

Rusty Crab said:


> The real shitbitch with fluid dynamics solvers is numerical stability. I wouldn't attempt to try to wing that... they have a tendency to explode really easily and at unpredictable times.


thats why he should do it as simple as possible, it just has to feel good and fit what people think is real(very few people have a clear idea how it works in reality so matching the feel is more important),
the change by 1 was just an example to make things easyer to understand, it should be a bit more complex than that.


----------



## Rusty Crab (Dec 13, 2020)

Stoneheart said:


> thats why he should do it as simple as possible, it just has to feel good and fit what people think is real(very few people have a clear idea how it works in reality so matching the feel is more important),
> the change by 1 was just an example to make things easyer to understand, it should be a bit more complex than that.


Yeah, the problem I'm struggling with here is that I don't know exactly how interactive these gasses need to be. There's talk of kinetic forces, but that simulation resolution is so low that they probably can't do anything interesting. At that kind of granularity, really all you can do is slowly move gasses as a block in a particular direction with wind force. 

If that's the case, why bother with a real simulation at all? Why not just precompute some movement paths and blend between them for different airflow directions? That would be dirt cheap to run in realtime and would give you roughly the same result.


----------



## Mr. Skeltal (Dec 13, 2020)

Stoneheart said:


> thats why he should do it as simple as possible, it just has to feel good and fit what people think is real(very few people have a clear idea how it works in reality so matching the feel is more important),
> the change by 1 was just an example to make things easyer to understand, it should be a bit more complex than that.


Science is best described as the process by which lazy mathematicians winnow away complexity from a system until they are left with an easily digestible "good enough" model. 
Unless it's absolutely necessary, simple systems work best. Using Dear Feeder's 6 Month Question, why bother modeling and calculating out every vortex and turbulence in this system instead of presuming basic diffusion in one direction? The flow regieme is never specified and the presented total system is alread textbook simple, why needlessly complicate it? Null wants to put two cubes together and know how fast the chlorine in one takes to fill the conjoined system.


----------



## Stoneheart (Dec 13, 2020)

Rusty Crab said:


> Yeah, the problem I'm struggling with here is that I don't know exactly how interactive these gasses need to be. There's talk of kinetic forces, but that simulation resolution is so low that they probably can't do anything interesting. At that kind of granularity, really all you can do is slowly move gasses as a block in a particular direction with wind force.


thats why pressure is so elegant, it solves most problems well enough.  
you need the ideal gas law and some good enough model for the change in pressure over time.

@Bob Chipman's Podiatrist do you have some idea what formula to use for the speed of pressure change between 2 cubes?  



Mr. Skeltal said:


> Using Dear Feeder's 6 Month Question, why bother modeling and calculating out every vortex and turbulence in this system instead of presuming basic diffusion in one direction?


from high to low pressure.  you can even use it as basis for some weather model if you go big enough.


----------



## Papa Adolfo's Take'n'Bake (Dec 13, 2020)

Working on it and posting to save a spot (Will prolly post when my kid finally decides to conk out.) but also say this:


Y'all niggas need to learn what the Soret effect is.
The basics of how I understand the problem presentaed are two discrete volumes in a cubic configuration meet, and thus form a square plane across which the gas diffuses as the temperature, approaching equilibrium forms a gradient. This leads to a momentary point in the first split second where the heat and mass transport are coupled and the diffusion thus has a bit of a head start. The last term (Which I *might* not include is a minor pressure difference between the two volumes that leads to a small momentum impulse, further speeding diffusion up by a few microseconds. After this split second though, it might as well be normal diffusion as everything reaches equilibrium.

I'll post my math soon


----------



## Stoneheart (Dec 13, 2020)

Papa Adolfo's Take'n'Bake said:


> The last term (Which I *might* not include is a minor pressure difference between the two volumes that leads to a small momentum impulse, further speeding diffusion up by a few microseconds. After this split second though, it might as well be normal diffusion as everything reaches equilibrium.


do you have a formula for the pressure difference? 
also what are you working with? ideal gases`?


----------



## Papa Adolfo's Take'n'Bake (Dec 13, 2020)

Stoneheart said:


> do you have a formula for the pressure difference?
> also what are you working with? ideal gases`?


Based on Van Der Waal's EOS the system has a 0.046 bar difference , which with equilibrium prolly being at ~.30 bar still seems like it won't be that big of a deal.

Who uses ideal gases?


----------



## Sped Xing (Dec 13, 2020)

I thought this was going to be about how to eat on 23 cents a day to keep the site running another 6 months


----------



## Stoneheart (Dec 13, 2020)

Papa Adolfo's Take'n'Bake said:


> Who uses ideal gases?


me, but i never said that i was very smert.


----------



## Papa Adolfo's Take'n'Bake (Dec 13, 2020)

Stoneheart said:


> me, but i never said that i was very smert.


For Learning:

Ideal Gas law only applies at extremely high temperatures, low Pressures, Low molecular volumes AND low reactivity conditions. This is because PV-nRT=0 treats all associated molecules as hard point masses (no volume), with perfectly elastic collisions, No intermolecular foirces, and No reactivities. This post made by the "I spent WAYYY too much time studying Thermodynamics" gang.


----------



## Stoneheart (Dec 13, 2020)

Papa Adolfo's Take'n'Bake said:


> Ideal Gas law only applies at extremely high temperatures, low Pressures, Low molecular volumes AND low reactivity conditions. This is because PV-nRT=0 treats all associated molecules as hard point masses (no volume), with perfectly elastic collisions, No intermolecular foirces, and No reactivities. This post made by the "I spent WAYYY too much time studying Thermodynamics" gang.


I studied killing and dissecting small animals and plants so ideal gas law hard enough.
i also came pretty close to your pressure numbers and i still think that just using pressure and ideal gases is the best way to get a working system for a game.


----------



## TurdFondler (Dec 13, 2020)

This way lies madness. You will absolutely positively crash your server trying to compute kinetic forces in gas. 

I think the kinetic forces should be based on a lookup table, like a curve or something. X gas at Y volume has Z force. Forces would be cumulative at the exit/entrance. That way you simulate the increase in pressure at exit points. So all you need to know is what gases are in which tile and add the movement data to the next tile. 

Diffusion speed across tiles, make it up. Use the theoretical weight of the gases and pick a baseline. Heavier gas gets -1 speed per unit of weight while lighter gases get +.


----------



## Mr. Skeltal (Dec 13, 2020)

Papa Adolfo's Take'n'Bake said:


> For Learning:
> 
> Ideal Gas law only applies at extremely high temperatures, low Pressures, Low molecular volumes AND low reactivity conditions. This is because PV-nRT=0 treats all associated molecules as hard point masses (no volume), with perfectly elastic collisions, No intermolecular foirces, and No reactivities. This post made by the "I spent WAYYY too much time studying Thermodynamics" gang.


I studied rocks and rock accessories. Ideal gas law was the most I learned about fluid dynamics aside from the Reynolds' number when describing the point at which a fluid transitions from laminar to turbulent flow.

The fact that I remember ideal gas law is enough for me.


----------



## XYZpdq (Dec 14, 2020)

whoever answers the riddle correctly receives the curse of running the farms


----------



## TurdFondler (Dec 14, 2020)

I'm not sure if it's implicit in my post but the crux of gas diffusion and kinetics in my mind would be vector data. Gases continue on a vector until hitting an immovable/impenetrable object. The vector gets changed by 90 degrees on impact. Any impact would reduce the total kinetic force in the square, and each gas should have a hard coded limit as to kinetic longevity: ie. After existing for X minutes kinetic energy will move to 0 as you assume gas occupies the entire area equally.


----------



## Sage In All Fields (Dec 14, 2020)

Lol nerds just determine this experimentally


----------



## Oyster (Dec 14, 2020)

Didn't ask Didn't read


----------



## Null (Dec 14, 2020)

TurdFondler said:


> I'm not sure if it's implicit in my post but the crux of gas diffusion and kinetics in my mind would be vector data. Gases continue on a vector until hitting an immovable/impenetrable object. The vector gets changed by 90 degrees on impact. Any impact would reduce the total kinetic force in the square, and each gas should have a hard coded limit as to kinetic longevity: ie. After existing for X minutes kinetic energy will move to 0 as you assume gas occupies the entire area equally.


That seems like much simpler math than the diffusion shit though. I don't see why I can't just calculate these vectors.

Guessing force just seems messy and stupid.


----------



## TurdFondler (Dec 14, 2020)

If you figured out the problem your way you'd be on your way to a Nobel prize. It's one of the major hangups in weather modeling. There's just SO MUCH to calculate. You'd probably need a second server just for atmo calculations. 

I think this problem is similar to fuel injection in cars. It could be very complicated as you want to know how much fuel to put into a cylinder of constantly varying volume, pressure and temp but they just hard code a "good enough" fuel curve into the ECU and then it reads a few cuck sensors to find its place in the curve.


----------



## Null (Dec 14, 2020)

TurdFondler said:


> If you figured out the problem your way you'd be on your way to a Nobel prize. It's one of the major hangups in weather modeling. There's just SO MUCH to calculate. You'd probably need a second server just for atmo calculations.





			https://www.dummies.com/education/science/physics/how-to-calculate-force-based-on-pressure/
		


Why can't I just say "this cube has N pressure because of its content, and the neighboring cube has N2pressure because of its contents, so therefore we can add X,Y,Z to the force vector"


----------



## TurdFondler (Dec 14, 2020)

Why not? I was thinking keep it integer based. Cubes have modifiers based on pressure and will move towards the biggest negative difference. 0 is equilibrium and space is like - 2, for example. 

So oxygen at regular pressure of +2 will move towards an adjacent space cube of - 2, leaving a cube of - 1 or something in its spots. That would start a cascade as each cube moves towards space. The next 02 cube to touch the first would add its kinetic vector to the first and so on. That way a blow out of 3 wall blocks would vent quicker but create less kinetic force as cubes don't all have to go through the same spot, so fewer cubes transfer kinetic energy. 

I'll try to model it graphically when I get home.


----------



## TurdFondler (Dec 14, 2020)

I'm going to double post.


A treatise on using unsigned integers in vectors and numerical gradients to simulate gas dissipation, submitted by T. Fondler, B.Sc in Theoretical Retardology.


Introduction
Assumptions
Mechanics
Vectors
Demonstration 1: 3 tile breach
1 tile breach
Demonstration 3: re-pressurizing
Timers
Gameplay Balance Issues
Conclusion

*Introduction:*

I think I have a simple, neat and scaleable solution to implementing improved gas physics and simulating kinetic energy within gases by using unsigned integers. I am a professional retard and have little experience with the BYOND engine but from my observations it should be possible to implement this system over top of the existing gas physics in game. This solution will keep the spirit of already implemented phenomena and conveniently not require any knowledge of fluid dynamics or physics, which is great because those things are bullshit.


*Assumptions:*

I will treat each in-game square as a container. I understand the squares may already be used as gas containers, but those (and their subsequent parameters) can be imagined as contained within this new container.
Gas pressure gradient values may transfer to vectors, but not vice-versa.
Vectors will contain a direction and a kinetic energy amount. Both will be on an unsigned integer scale.
Each container will be able to confer gradient data to the gas contained within
Existing pressure and temperature values will impact vector values.
Gases will move towards lower pressure gradients, always.
For the purpose of this explanation and to demonstrate my model I will be signing my integers because it’s easier to visualize the pressure gradient that way.

*Mechanics:*

Gases will start with a gradient value of 1 and a predetermined vector value.
The tile/container accumulates gradient values
Gradient values will impact vector values. All gases within a tile will have their vector value impacted by the tile’s gradient value.
Gases will always move to a lower gradient value
Upon encountering an impenetrable tile, gases will adjust their vector by 90 degrees
A tile can contain all types of gases
Gases are assumed to move through one another, if their vector value is below 2
At high enough gradient values gases will begin to act upon other gases
When a gas with a gradient value of 1 encounters a tile containing a gas with a gradient value of 1, the gradient will not be added.
Space tiles will have hard-coded and immutable negative gradient value. For the purpose of this model, we will use -2.
Space tiles will have increasing negative gradient as the distance from the station increases, until the gradient limit is reached. In this model the limit is -5.
Space tiles will accumulate vectors as regular tiles do, but with a negative modifier. The modifier increases as distance into space increases.
Maximum gradient space tiles destroy gas and reset vector
*Vectors*

Each gas will have a Vector, containing direction and force. Since each tile can be adjacent with 8 other tiles, it’s only necessary to have 8 vector values. Gases are assumed to be “spawned” at a canister or a vent/pump, their vector can be randomly determined when they are spawned in an area. Force of a gas (the kinetic energy it imparts) will be determined by the pressure and amount of gas, which are already decided in-game. The kinetic energy scale will consist of unsigned integers but the creation of the scale is outside the scope of this retardocument.






Demonstration 1: 3 tile breach
This demonstration will show how a 3-tile breach causes realistic gas interactions using the above rules. The model consists of a room 3 tiles by 7 tiles, surrounded by a 1-tile wall and with an airlock marked in orange. The room starts off full of airmix with a gradient value of 1.
Granted, I’m a little drunk and my numbers are off but I think the model is pretty clear.



An intact room




A breach of 3 tiles



02 exits via breach, gradient values accumulate near exit and decrease as gases leave tiles









As you can see, the gradient values which impart vector values increase near the exit point. It's assumed in the next image the gases in furthest space tiles will have been destroyed.


*1 Tile breach*

I’m not going to bother modeling it, but with the above graphics in mind, a 1 tile breach would necessarily produce much higher vectors at the exit point as all gases must transfer their vector value to a lesser amount of tiles adjacent to space tiles.

*Repressurizing*

For the sake of simplicity, I’m not delving into gas diffusion timing. I’m assuming gas diffuses at 1 tick, whether that be tied to real time clock values or existing in game tick values is irrelevant.
It’s assumed the room being repressurized has its walls intact and the gases within have reached equilibrium at 0 gradient value.
It’s assumed that the tile containing the pump will always contain the gas being pumped.
Gas enters the room with a gradient value of 1 with a predetermined vector. RNG could be used to give the gas a direction with a minimum value of kinetic energy.
In this model, the room has been repressurized via pump for a number of ticks. We are focusing on one gas. It can be assumed each tile is a discrete container for individual gases, ie. nitrogen entering a tile containing oxygen but no nitrogen encounters a gradient value of 1, but a 0% of nitrogen.
If a gas encounters a tile containing any value of its own type, it will enter an adjacent tile of 0% value of its own type. Once all possible tiles are populated with gas, the % of gas within a tile will increase but the vector values will not, given consistent predictable entry via pump.




*Timers*

To prevent inheritance issues which would cause increasing gas vectors in sealed rooms, I propose each tile have a timer with regards to gradient. If a tile does not obtain new values in 2 real time seconds, the gradient resets to 1 if gases present or 0 if gases absent

*Gameplay balance Issues*

New gas phenomena would impact the way hull breaches affect players. Currently there is little incentive to expediently repair hull breaches, as internals are plentiful and breaches do not significantly impact gameplay. The new gas mechanics would render breaches more serious, but at the benefit of creating “fun”, a little understood phenomena in current TG code. As a counter, I propose that the following mechanics be added if this gas model is implemented:

Smart Metal Foam Grenades contain a “smart” component. If a grenade encounters a gradient exceeding 2, it detonates regardless of timer. It would allow the user to seal breaches that would otherwise suck the grenade into space. The Smart Metal Foam is unaffected by gas gradient and kinetic energy. 
Members of Security, Command and Engineering be given standard issue boots containing a single-use battery powering a magnetic element. Boots would turn into magboots for 15 seconds of real time, at the expense of player movement.
The “pull” mechanic working on immovable objects. If a player selects “pull” on a secured table, chair or other object, they will resist the kinetic gas forces until a certain threshold is passed, wherein they release.
*Conclusion:*

I have autism please laugh at me.


----------



## Null (Dec 15, 2020)

This isn't for SS13 specifically, just something I'm doing, but your diagrams are useful. I disagree that you need 8 adjacent tiles however. I think 6 works for a cube. The diagonal adjacents aren't important.

Going on a train ride today. Going to pick up a book on this and try to cram some in.


----------



## TurdFondler (Dec 15, 2020)

In SS13 specifically diagonal adjacents would add more unpredictability in depressurization events and would ensure gases don't always end up perpendicular to walls they hit.

That's the only reason I've included them, but otherwise yeah they're not important. 

Also, in SS13 specifically I would model gases 2 dimensionally only to cut down on processing. It wouldn't meaningfully impact player experience I don't think. 

Keep us updated on your weather control machine progress, Null.


----------



## Papa Adolfo's Take'n'Bake (Dec 15, 2020)

Time for Thermodynamics Sperging (a personal favorite.) I am assuming you want an at-least realistic description of what happens when these two volumes are suddenly contacted across a discrete plane made up of one face a piece of these cubes described in the problem.



Spoiler: I ain't reading all this *Quite possibly retarded* shit, you spastic.



Perfectly understandable.

3 things happen right off the bat

1. because of the greater mass, temperature, and thus pressure, there is immediately a movement towards momentum equilibrium. With a difference in Pressure of 0.05 bar, this kicks off the process of the system going to equilibrium with an impulse of momentum from Cube B to Cube A as these discrete volumes contact. This is done within microseconds and due to the chemical nature of diatomic gases, is really a minor event. Some work is done on Cube A's volume by cube B, but as we are assuming that the volume remains constant  in the combined system the overall this work is negligible. Much of the Pressure change which describes the work done to equilibrium, however, is more the result of temperature change and mass transfer than the adiabatic compression comprising the work term resulting from the higher pressure. This is justified by the change in molar volume from intial state to equilibrium state being about 4% in total, indicating that compression of the gases is not a significant contributor. Thus, I am focusing on the heat transfer, which is coupled with the mass transfer.

2. Going along with the theme of a system moving towards equilibrium, heat and mass then immediately migrate from cube B to cube A. This happens simultaneously and the motion of both the heat and mass are linked together. This regime dominates everything that the problem cares about until thermal equilibrium is achieved in the system.

3. After thermal equilibrium is established, there will be some more mass diffusion that will then occur, soon achieving equilibrium with regards to mass as well

Papa Adolfo done sperged out calculating out what happens with 2 & 3 because event one is pretty minor. The

 TL : DR answer to the question is that primarily, heat and mass are exchanged between the discrete volumes A&B until equilibrium is achieved. Chlorine, being the only component unique to B will be the primary species whose mass transfer actually matters, evrerything else is essentially just a transfer of heat and momentum. This particular sperg thus mostly focused his calculations on Chlorine and how it acts in the system.



I wrote a python script that does these calculations out for me because I am a lazy engineer who is shit at actual Computer coding but uses it to get his mathematics done for him. 

Assumptions: Using Van Der Waal's Equation will account for molecular forces in a manner sufficient to assume ideality in the behavior of chemical potential. 
no reactions
final Volume is fixed
Cube A, Cube B, and the equilibrium state are well mixed.



Spoiler: Define Properties



Any even halfway decent thermodyunamics calculation has a stupid number of inputs. this is no exception. This part of the code defines basic state properties of the system, including Van Der Waal's EOS coefficients, number of moles, mole fractions, Volume (in Liters because that makes a lot of the chemical potential calcs easier,) and, of course, Temperature in Kelvin. Also, minor calculations were performed here to determine specific heat capacities  of the components and the mixtures A and B.

The calculations done herein seem petty but will be important for later discussion: Calculation of the mixture VDW coefficients. I used Van Der Waal's EOS because this accounts for the majority of intermolecular interactions that we need to care about in a scenario like this one where we have diatomic gases with reasonably similar dipole moments, and reactivities. This allows for the core of this calculation to say that it treats the gasses in a realistic and not ideal manner. 

Next, The heat characteristics that I give a shit about are calculated in the script.  Namely, these include system enthalpies, which will define the heat transport occurring in this conceptual process. After Enthalpy, it is relatively straight forward to calculate out the equilibrium temperature. This temperature is, in effect the end point for the more complicated process of coupled transport of heat and mass that is calculated out and discussed in section 1. Also calculated is a rough number for heat transfer coefficient assuming that the plane across which this transport occurs is a discrete square that can be thought of as a Plate of infinitesimal thickness and is not an impediment to mass transfer.  

After I define what I care about in heat quantification, I need to calculate out the basics of chemical potential of the system. This is in particular because,  despite the many MANY other implications of chemical potential, it represents the thermodynamic change in energy from the addition of some discrete mass to a system at constant volume and Entropy. This means it is an intrinsic property that is not accounted for in the heat or mass balances and thus plays a role in the diffusion question central to the problem. (Author's note; Don't think this is all Chemical Potential entails. People have written many PhD theses on what the fuck chemical potential actually is and what it represents. This is just for entry level calculating coupled transport by a bachelor degree chemical engineer with some time on his hands.)  In this section, I alter the literature values for chemical potential with regard to temperature. The difference in Pressure is assumed to be adequately quantified in the VDW EOS calculated out earlier because it is at a lower Pressure than the literature value

from the python script comments: 
"
## Calculations focus only on the Chlorine, for time and illustration purposes
## this is, in part because Cl2 is the only unique species undergoing mass 
## diffusion

## the part where PDE's would come in, are herein. for my first iteration,
## I will show an approximation for the del(mu)/del(x) term in the soret effect
## the primary justification for this is that the system is low pressure, and
## High Volume in a medium temp range. These conditions mean that the Van Der
## Waal's EOS used initially can reasonably be assumed to account for most of
## the deviation from ideality of the real gas
"

Thus the real crazy shit hits the fan. the Quantitative method I will use for the Soret Calculation includes a particularly nasty little term for its calculation. In the denominator of the Thermal diffusivity factor, is the partial derivative of the function between chemical potential and molar fraction. This being done in full would require the derivation of what would undoubtedly be a multi-variate, non-linear partial differential equation using the Gibbs-Duhem equation. I'm not going to do that herein because that would honestly be the better part of a month to do properly, and it is not necessary. The reason it is not necessary herein is because we can use ideal approximations from here on out and get a reasonable result that would  demonstrate conceptually what happens with this problem. Thus, I initially have done the full-retard thing of assuming a linear/step change situation that discretely homogenizes to a value after mixing. One can also very likely fit an exponential decay relationship to get a more realistic relationship between the chemical potential and mol fraction but I am lazy and have spent enough time on this to be perfectly honest.





Spoiler: the Soret Effect Calculation.



The method used herein is outlined by L.J.T.M. Kempers (RIP in Power) in "A comprehensive thermodynamic theory of the Soret effect in a multicomponent gas, liquid, or solid" 2001

The spooky part of this method is calculating a thermal diffusivity constant used in a simple relation which describes the change in molar fraction of a component (herein, Chlorine) which is resulting from the Soret Effect. The Soret effect terminates at thermal equilibrium, thus we can assume it dominates up until the system reaches relaxation time with regard to thermal equilibrium. Given that we are talking about elemental, diatomic gases, the components can be assumed to be Newtonian fluids whose relaxation time is described by Newton's Law of cooling.

Going along with the "This is just sperging, not grad school level work" theme, I am treating the N2/O2 mixture of Cube A as a binary component in the Soret effect calculations

The Results indicate that the Soret effect dominates the mass transport for ~7% of the diffusive action towards equilibrium.

This takes approximately, according to newton's law, 16 seconds



So, in short, it's about 16 second before thermal equilibrium, thus all that happens with regard to the questions in OP is that heat and mass are exchanged. Within that kind of time frame, not much really gets accomplished, with the molar fraction of Cl2 reaching something on the order of 0.003, on its way to 0.04 It will then probably take something like a few hours to reach compositional equilibrium

There might be a reason you've been waiting 6 months, @Null.


----------



## Null (Dec 15, 2020)

Papa Adolfo's Take'n'Bake said:


> So, in short, it's about 16 second before thermal equilibrium, thus all that happens with regard to the questions in OP is that heat and mass are exchanged. Within that kind of time frame, not much really gets accomplished, with the molar fraction of Cl2 reaching something on the order of 0.003, on its way to 0.04 It will then probably take something like a few hours to reach compositional equilibrium


Okay, so this is my big take away:

I have to calculate heat exchange and mass exchange differently and I was under the impression I did not.


----------

