TheYeast wrote: ↑Mon Sep 17, 2018 8:57 pm
That's it for me, as I'm on vacation the coming week. I will check the thread when I return.
I improved my previous simulation to support junctions and multiple physics models.
https://jsfiddle.net/TheYeast/c9d2azjo/show/
Feel free to fiddle the source at
https://jsfiddle.net/TheYeast/c9d2azjo
The simulation supports pipes, sources, sinks, and tanks.
- Blue bar = fluid content
- Orange bar = production cycle progress
- Pink bar = internal buffer
- Green bar = flow direction
Sources and sinks can be configured:
Cycle duration is the number of frames (60 in a second) a source/sink needs to complete a batch.
Production and
Consumption per batch can also be set.
(Not all systems/browsers can manage 60 UPS)
As Bauer correctly noted:
Bauer wrote: ↑Tue Sep 18, 2018 12:59 pm
I'm only a little bit worried though that the "unphysical" behaviour of liquid production and consumption (delta-functions) will lead to artifacts in complex networks that will be difficult to understand by the player. Assume a ring-tube with non-symetrical producers and consumers. The flow direction will be quite random and confusing because the speed waves following the delta-peak will travel in both directions of the ring and will not cancel out due to the missing symmetry. Or am I wrong?
This is completely true. Whether the waves caused by this are aesthetically pleasing or confusing depends on the player. To compensate for this, there is a global option
Smooth source output/sink input over time to gradually release/consume fluids. The logic simply tries to empty/fill the source/sink buffer in the time remaining to complete a production cycle. As a middle ground, the logic could try to do this in half the remaining time, so there would be
some waves, but not as much as with the delta-peaks.
Supported pressure models:
Wave Equation: the model as I proposed in earlier posts.
C-Squared and
Friction can be configured.
Wave Equation, Non-Linear Pressure: same, but after filling a pipe over 60%, pressure increases more sharply.
Fixed Acceleration: a proposal by quinor to use a fixed acceleration in the direction of lower fluid level.
Acceleration and
Inertia can be configured. (@quinor please correct me if I made a mistake

)
Non of these models suffer from update order artefacts because the flow calculation and actual fluid transfer are performed in separate passes.
Supported clamp models:
Quarter Limit: as described in previous posts, limit the in/out flow to 1/4 of the remaining space/content so even with 4 connections, the pipe cannot over-/underflow.
Connection Count Limit: as above, but instead of always using 1/4, count the actual connections. For a non-junction pipe the limit will thus be 1/2.
Both
min and
max clamping can be disabled (though disabling min clamping will usually cause negative fluid content).
I did
not (yet) add the very clever clamp model proposed by quinor (which as I understand distributes contested available fluid/space fairly over all connections). I think this method is the best I've seen, but it is also a bit more computationally expensive. If there would be a need to maximise throughput without increasing pipe volume, this seems to be the way to do it. The reason for not adding it yet is mostly that it is less trivial to implement
Tank behaviour is different than currently in Factorio: when the fluid level in a pipe connected to a tank is above 50, the tank will take in fluid, otherwise it will output fluid as if the level in the tank were 50. This allows a tank to maintain some pressure when releasing fluid even if it is only partly filled up.
The simulation does not use the artificially lower pressure in sinks or higher pressure in sources, for the reason I explained in an earlier post.
I tried to write the simulator in such a way that new models can easily be added. Feel free to fork and add your own.
The Yeast