Improving fluid system by removing pipe volume

Post your ideas and suggestions how to improve the game.

Moderator: ickputzdirwech

Post Reply
PsychoticLime
Burner Inserter
Burner Inserter
Posts: 9
Joined: Thu Jul 19, 2018 4:53 pm
Contact:

Improving fluid system by removing pipe volume

Post by PsychoticLime »

TL;DR
Instead of having a fluid system made of vessels of different size linked together, this proposal centers around the idea that pipes are just connectors and do not have a volume of their own.
In detail?
My idea is to have the fluid system more representative of real-life flow models and incidentally also simpler to use.

Right now the fluid system works by treating every object in the network as a vessel, and equalising the level between them: if a tank is filled to 50% capacity, then every pipe connected to that tank is also filled to 50% capacity.

My proposal is to remove pipe volume entirely: a pipe cannot store fluid. When connecting two tanks or buildings together, the pipes simply act as a link between them, they do not store fluid but simply allow it to flow. The flow rate is dependent on the difference between levels in the tanks as it is now (being highest when the difference is greatest and zero when the levels are equal), but also on a friction coefficient that includes the length of the pipeline, to preserve the mechanic that long pipelines require pumping to work.

The reason for this change would be:
  • -No more waste of fluids when deconstructing pipes
    -You can more easily see how much fluid you have because the only places that store it are tanks and buildings
    -It's, at least in my opinion, more streamlined and understandable than the current system
    -It may be more easy to optimize for performance

mrvn
Smart Inserter
Smart Inserter
Posts: 5686
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Improving fluid system by removing pipe volume

Post by mrvn »

And how do you propose to solve the NP hard problem of having multiple tanks connected by pipes and figuring out the flow through each pipe?

PsychoticLime
Burner Inserter
Burner Inserter
Posts: 9
Joined: Thu Jul 19, 2018 4:53 pm
Contact:

Re: Improving fluid system by removing pipe volume

Post by PsychoticLime »

Since my idea is based in real-life pipe flow models, I thought to apply the same solving methods to the system as well. The original post initially had a section which explained the model and mathematical assumptions but I cut it to avoid getting sidetracked.

The short version is:
-Every vessel in the system has an energy value associated with it (for real fluid systems, this is the height the fluid reaches inside a tank, or the height the fluid would reach if you drew a pipe straight up).
-Whenever there is a node in the pipe system, meaning a point where three or more pipes are connected together, the continuity equation for incompressible fluids applies, which basically says that "as much flow gets out as it gets in".
-Pumps have an energy value as well, it's called prevalence and it's basically "how many meters does the pump add to the energy level?" (turbines also have prevalence but it's negative, and it's how much energy it is subtracted instead of added).

With these basic rules, you can work with pretty much any number of tanks and nodes. I don't know how this idea could work with the architecture the game is built on since I have no idea what that is, but it seems close enough to the current system to be at least feasible.

mrvn
Smart Inserter
Smart Inserter
Posts: 5686
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Improving fluid system by removing pipe volume

Post by mrvn »

So if you have a million tanks on one side that are full and a million tanks on the other side that are empty and pipes connecting them all then fluid flows afrom the full to the empty tank.

Consider the the flow if every tank has a straight pipe to an empty tank so they are all paired.

Now consider if all the full tanks are connected by pipes and all the empty tanks are connected by pipes and then there is a single pipe connecting the two sides.

Should the tanks fill at the same speed? At what speed should the tanks fill? The amount of fluid that can flow trough a pipe is limited so you need to know how much will flow through each pipe for the game to catch the bottleneck and slow down he flow.

PsychoticLime
Burner Inserter
Burner Inserter
Posts: 9
Joined: Thu Jul 19, 2018 4:53 pm
Contact:

Re: Improving fluid system by removing pipe volume

Post by PsychoticLime »

Actually, you just named the bottleneck: it's the single pipe. Since the fluid is incompressible, and the energy levels are the same in the tanks, the fluid flows through at exactly the same speed as it would if there were just two tanks, which is quite the definition of a bottleneck. To increase throughput, one could either put down more pipes to increase the total area in which the water can flow through, or install a pump to raise the energy level and consequently increase flow rate.

To answer your question, no, the tanks should not fill at the same speed in both cases: if there are n tanks, then in the second case the flow rate (which dictates how fast the tanks fill) will be n times smaller than in the first case.



If you're interested, here's the formula to calculate energy dissipation through a pipe (assuming certain conditions are met, which in this case they are).

http://www.HostMath.com/Show.aspx?Code= ... 5E%7B2%7DL

Where ΔE is energy dissipation, Q is flow rate, k is the so-called friction coefficient ("Gauckler-Strickler coefficient" if you live in Europe, "Manning coefficient" if you live in the US), R is hydraulic radius (known), A is area of the cross section (known), and L is length of the pipeline. Since the ΔE is known (it's the difference between starting and ending levels) and all the other data are properties of the pipe which are of course known a well, it is easy to solve for flow.
The calculations become more difficult if you have lots of nodes clumped together, as in your example with the pipes that connect each tank, but in that case it is reasonable to assume that dissipation is negligible and ignore the whole formula entirely, avoiding unnecessary calculations.

mrvn
Smart Inserter
Smart Inserter
Posts: 5686
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Improving fluid system by removing pipe volume

Post by mrvn »

The problem is finding the one pipe where everything has to flow through. Or 2 or 3 or N pipes. The pipe system between tanks can be complex to the point where finding the pipe or pipes that is the bottleneck takes exponential time.

And maybe my description of the pipe layout was unclear. Here is the example:

Code: Select all

T| |T
T| |T
T|-|T
T| |T
T| |T
T| |T
Fluid flows from all full tanks at the same time. The tanks aren't connected in series but parallel.

PsychoticLime
Burner Inserter
Burner Inserter
Posts: 9
Joined: Thu Jul 19, 2018 4:53 pm
Contact:

Re: Improving fluid system by removing pipe volume

Post by PsychoticLime »

Your description was clear, maybe it was my reply that was a little fuzzy. What I meant is that, since all of the "paths" that connect the tanks together pass through the one pipe, that pipe is the bottleneck because it determines the flow. In all the other pipes, flow is slower and determined by calculating the continuity equation at nodes ("as much gets in as it gets out"). But you're right in the sense that this is the weakest part of my proposal.

If the system implemented some sort of pathfinding algorithm to determine the length of a certain pipeline is from A to B, then it would be relatively easy to determine where the flow is constricted because it would be represented by the pipe segments in which a lot of different paths stack together. Pathfinding may be computationally hard, but it would only need to happen once, and then the paths would remain the same until some physical change to the network is applied.

mrvn
Smart Inserter
Smart Inserter
Posts: 5686
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Improving fluid system by removing pipe volume

Post by mrvn »

The path finding is NP hard. And you know how people love to build mega factories.

On the other hand you can solve the problem iteratively. Doing a bit of work every tick. And each pipe is a node in the graph and has a pressure value and a flow direction from the past iteration.

Oh, wait. That's what the game is doing.

PsychoticLime
Burner Inserter
Burner Inserter
Posts: 9
Joined: Thu Jul 19, 2018 4:53 pm
Contact:

Re: Improving fluid system by removing pipe volume

Post by PsychoticLime »

Yes, except for the fact that:
  • 1. There is no actual fluid in the pipes, they are simply connectors.
    2. Flow rate on long pipelines is more intuitively modelled
Which, if you remember, where two of the points I made in the original post.

mrvn
Smart Inserter
Smart Inserter
Posts: 5686
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Improving fluid system by removing pipe volume

Post by mrvn »

Fluid in the pipes is a big annoying, if it is the wrong fluid. :(

And combining stretches of single pipes to be modeled as just one piece of pipe between 2 nodes could certainly optimize the fluid model. I mentioned that part before myself. Even with the existing model you can do that. The fluid level of each pipe is basically linear between the 2 nodes so it can be calculated when needed instead of simulating it every tick.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7351
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Improving fluid system by removing pipe volume

Post by bobingabout »

Wasn't the idea for pipes just to consider everything of the same size (Pipe vs Tank) the same big pipe entity? so you have a stretch of 50 pipes, that's just considered 1 pipe with 50x the capacity.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

mrvn
Smart Inserter
Smart Inserter
Posts: 5686
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Improving fluid system by removing pipe volume

Post by mrvn »

bobingabout wrote:Wasn't the idea for pipes just to consider everything of the same size (Pipe vs Tank) the same big pipe entity? so you have a stretch of 50 pipes, that's just considered 1 pipe with 50x the capacity.
That's what I said. Except you can still show a different level for each pipe segment when the player hovers over a pipe.

Post Reply

Return to “Ideas and Suggestions”