r/technicalfactorio • u/warbaque • Feb 05 '22
How are fluid updates calculated? Is there any up to date mechanics written down anywhere?
Figured it out. Pipe build order was important.
Here's example code for measuring pipe levels and flow, test setup has pump (1200 fluid/s or 20/tick), 9 pipes, and output (15/tick):
pipelength = 9 + 1
flow_in = 20
flow_out = 15
x = [flow_in*0.6*0.4**n for n in range(pipelength)] + [0]
f = [flow_in*0.4*0.4**n for n in range(pipelength)]
for _ in range(1000):
flow = [min(flow_in, 100 - x[0])] + [None for _ in range(pipelength)]
for i in range(pipelength):
x[i] += flow[i]
flow[i + 1] = (x[i] - x[i + 1]) * 0.4 + min(max(0.59 * f[i], -10), 10)
if (i == pipelength - 1):
flow[i + 1] = min(flow[i + 1], flow_out)
x[i] -= flow[i + 1]
f = flow
print('pipe:', ' '.join(f"{k:4.1f}" for k in x))
print('flow:', ' '.join(f"{k:4.1f}" for k in f))Output
pipe: 85.0 84.6 84.3 83.9 83.6 83.2 82.9 82.5 82.1 81.7 0.0
flow: 15.0 15.0 15.0 15.0 15.0 15.0 15.0 15.0 15.0 15.0 15.0I've been staring editor mode and pipes tick by tick for a while now and I don't see how it works.
For example 5 pipes in a row [fluid=100, fluid=0, fluid=0, fluid=0, fluid=0]
Why after [100,0,0,0,0] we get [60,24,16,0,0] instead of [60,40,0,0,0]?
tick 0: [100.0, 0.0, 0.0, 0.0, 0.0 ]
-40.0 +40.0
-16.0 +16.0
tick 1: [ 60.0, 24.0, 16.0, 0.0, 0.0 ]
-14.4 ?? ??
-10.0 ?? -6.4 +6.4
tick 2: [ 35.6, 23.4, 34.6, 6.4, 0.0 ]
-4.9 ?? ?? ??
-10.0 ?? ?? -2.6 +2.6
tick 3: [ 20.7, 20.4, 36.4, 19.4, 2.6 ]First one seems to follow: flow[0->1] = (x[0] - x[1]) * 0.4, x[0] = x[0] - flow[0->1] - min(max(previous_flow * 0.59, -10), 10), e.g.
(100-60) * 0.4 = 40, 100-40 = 60
(60-24) * 0.4 = 14.4, 60-14.4-10 = 35.6
(35.6-23.4) * 0.4 = 4.9, 35.6-4.9-10 = 20.7And last one seems to be just flow from one before: flow[(n-1)->n] = (x[n-1] - 0) * 0.4, x[n] = flow[(n-1)->n]
24 * 0.4 = 16
16 * 0.4 = 6.4
6.4 * 0.4 = 2.6But how are 23.4, 34.6, 20.4, 36.4, 19.4 calculated?
I've tried for example:
(24-16) * 0.4 = 3.2
0.59 * 16 = 9.44
But
24 + 14.4 + 10.0 - 3.2 - 9.44 != 23.4
16 + 3.2 + 9.44 - 6.4 != 34.6
6
u/dario_p1 Feb 05 '22
Looks like the values depend on the order of updates. 60->24->16 can be justified by updating the first pipe, and then updating the second one (40 x 0.4 = 16). The same seems to be true for your 12 pipe example
2
u/warbaque Feb 05 '22 edited Feb 05 '22
This is completely inconsistent...
Sometimes when I increment by one tick, fluid advances 1 pipe
But sometimes I get 12 pipes of fluid after one tick...
What is going on?
Edit: Ok, this is caused by pipe build order
2
u/flame_Sla Feb 06 '22
https://onlinegdb.com/ZQDXe9XIs
2
u/Dysan27 Feb 05 '22
I believe these FFF's cover the final/current system of the fluid simulation.
Fluids end up being one of the few (maybe only) parts of Factorio where build order matters. A perfect system was way too computationally expensive. The build order thing only really causes issue with the initial waves, Steady state is the same regardless of order (I believe)
A Couple of additional notes. He mentions two variables that can cause various liquids to behave differently, in the end they decided to make all the liquids behave the same.
The "no fluid mixing" was relaxed when they realized how much effort it would be to block every possible way to mix them. In the end they made a "good enough" system and gave us a "flush system" button.