Implement gas blender - Mobile by fnightfox · Pull Request #4649 · subsurface/subsurface

So, can you describe the problem you are actually trying to solve here? You have more than three sources of gas (as in He, O2 and air), say some additional trimix of some sort, so there is more than one "solution" to the filling problem. And then you assign a cost per volume to all these gases and try to find the cheapest option? And how do you decide what is the limited amount, do you assume you have a booster pump so you can bring any gas to any pressure is the limit achieved when you equilibrate two cylinders?

I am assuming I have at least an air compressor (unlimited, 21/0) and boosted O2 and He(in my case I treated these as unlimited, but it is a fair point to add BOOSTED as an option for limited blends, but this is besides the point). This means that I know that a blend is possible for any realistic blend (there is a triangle from pure nitrogen to pure helium to air that is not possible, but that is not a blend I have ever heard of anyone desiring). I also am thinking about a case where I have a tank of trimix with some gas left over, or a rich O2 mix that has leftover gas in it. Reusing these gases would be cheaper than filling the tank using the pure He/O2 mixes because I have already paid for these mixes. If you would like numbers, assume the following scenario:

  1. Unlimited Air
  2. (Functionally) unlimited O2 and He, from boosted bank bottles, with costs of $.15/cuft for O2 and $1.75/cuft Helium
  3. An HP100 at 1500 PSI of 18/45
  4. Another HP100 at 1200 PSI of 30/30

I am targeting an AL80 currently empty to 3000PSI and 21/18.
The simple solution is to blend from the three boosted bottles, giving a cost of 24.74 and removing the ability to reuse anything from the other bottles. Using the blender proposed here, you can use 14.55cuft of 30/30 (dropping that source to ~700PSI), 10.54cuft of 18/45 (dropping that source to ~1100 PSI), and only have a cost of 8.25.

And how realistic is this scenario (as in: is it worth considering the finiteness of the available gases or do people pretty much always more gas in their storage cylinders than what is needed for this fill)?

I believe that if you are always using bank bottles, you probably have enough. The use of this is to allow the reuse of already blended tanks to reduce wasted gas.

Can you give me a concrete, real world example with numbers that you would like the app to provide the solution for?

See above for a scenario with numbers. I came up with this one just off the top of my head, but it seems like a reasonable thing to want to reuse as much gas as you can.

I think even with more than three gas sources, the problem has an analytic solution: You have linear equations and linear inequalities and a linear price function. Then you know the minimum is always in one of the corners of the allowed solution space.

I agree with this. The triangle solution is used to construct that solution space, with the corners being the blends calculated and compared for cost. The programming to have a generalized solver for the linear equations seemed more complicated than finding the barycentric weighting of the three points of the triangle, so I elected to implement a barycentric weighting approach to solving the problem, since the result for this application appeared to be the same.