mrvn wrote: Wed Oct 20, 2021 11:34 am
foamy wrote: Mon Feb 22, 2021 9:39 pm
Monitoring the buffer is a bit trickier, but can again be done in constant-space, and has some benefits over using tanks to do so to boot. It keys on the fact that all turbines on the same grid will experience the same proportional draw, so if you can measure the flow rate into
one you know exactly what the loading is on all of them. And from there you can work out how much of a fuel cell's worth of energy has been consumed since the last one was inserted, and whether a new one needs to be added.
Because of this, you can insert fuel cells
while all your heat exchangers are still producing and cut response lag to demand increases to the absolute minimum. This means that a sudden drop to null draw
could result in some waste, since you're not actually fully draining the buffer, so some additional circuitry to catch that event and account for it in the buffer math is a good idea. But that's an unusual event in an actual working reactor; here's a half-hour's worth of tracking in a 1kSPM factory that the array (doubled) is powering. There's some supplemental solar and a lot of power-switching to disable beacons, so it's swingier than some people's just-run-everything-all-the-time approaches would be, even:
I just had a long argument about this on another thread and no, you can't do that reliable.
While, assuming the same steam pressure, all turbines on the same grid will experience the same proportional draw you can't measure that exactly. Circuit logic only works on integers so there will be errors in your measurement. Computations use floating point values which are imprecise and rounding happens. So some power might be gained or lost in tiny increments over time. So if you start your reactor at 750°C and only refuel based on steam throughput then the temperature will go up and down randomly ever so slightly. Eventually it will overheat (waste fuel) or cool down too much (brownout). And once you have even the tiniest bit of brownout your steam measurement will think you are using less steam. So it will refuel less. It's a death spiral from that point forward.
The issue isn't with integers or floating point. The circuitry is absolutely reliable in that sense: it actually
correctly converts the floating point fluids into integer circuit signals by accumulating them over a (usually fairly short) time interval.
The flow meter is a negative-edge-detection setup hooked into a single steam tank on a
separate steam source from the nuclear complex(es). It's got a pump on either end of it -- one filling it from an unclocked steam tank that a heat exchanger/boiler can happily dump into, one emptying from it into the turbine/steam engine. Those signals are then fed into a memory cell.
The pumps are used to both valve the measurement tank so that it is only filling or only emptying. The fill rate of a pumped-tank-to-tank connection is 200 fluid/tick (at least when it's going from a near-full tank to near-empty, as here), and the drain at continuous max consumption hovers at 1 fluid/tick (1 steam turbine or 2 steam engines).
What happens when that consumption is, say, 0.25 fluid/tick (representing about 25% draw)?
Tick 1: Measure tank goes from 1200 to 1199.75. This gets truncated to 1199 by the circuit system, so the edge detection fires, so a signal of 1 gets stored in the memory cell.
Tick 2: Measure tank goes from 1199.75 to 1199.50. No signal generated, so the memory cell stays at 1.
Tick 3: Measure tank goes from 1199.50 to 1199.25. No signal generated, so the memory cell stays at 1.
Tick 4: Measure tank goes from 1199.25 to 1199.00. No signal generated, so the memory cell stays at 1.
At this point, the memory cell is exactly accurate to the steam consumed. It will drift again the next time it drops below an integer value in the steam tank, but recover again. Thus, while it will basically always be out by some fraction of a single steam unit to the
actual steam consumed, it will never be out by
more than one steam unit.
(Note: This is also why you can shut off the drain when you refill it. The steam turbine/engines have a small internal buffer, which they will consume from. Once the fill is complete, that buffer will be refilled from the measurement tank, which will then report how much was required to do so.)
From there there's a bit of math to determine exactly what the value in the memory cell represents in terms of your particular plant's layout. The trick here is that what you want to know is how long, in ticks, it would take all your turbines running at 100% capacity, to fully consume a set of fuel cells being inserted.
This is
reactor output / turbine output * 12000. The reactor output encodes the overall efficiency of the array for you (i.e. how much energy you get from inserting cells, including edge dropoff; it's just divided by 200 seconds as a power number). You just need to convert back to ticks (hence the multiplication by 12000) because that's what your incoming measurement is in.
In most reactor designs this number will hover fairly close to, but slightly under, 12000. You can hand-calculate it or feed it in from a combinator setup if you like, although if you do the latter take care to do the multiplication before the division.
So, consider a 2x2 reactor with 480MW output on the reactors, and an oversized array of turbines that can draw 582 MW. Multiply 480 by 12000 and then divide by 582 (all integers!), and you get a result of 9896(.9) ticks for the turbines to remove all the heat of a fuelling cycle. For my 2x14 tileable, you get 4320 MW reactor output and 4656 MW turbine, for a result of 11134(.0).
As long as you truncate this result, as the Factorio combinators do, this guards against freezing. You will insert cells, by the consumption measurement, one or two ticks ahead of schedule. This will cause a consistent (but very slow) drift towards additional energy being in the system. However, once fuel cell energy starts being lost from overfilling the heat pipe buffer, it will immediately stabilize. It will take an enormous amount of time for this loss to amount to even a single additional swing.
This also ensures you always have full production available from your heat exchangers in response to demand surges following a period of low activity.
The one
absolutely critical requirement is that there has to be enough buffer space
in the heat pipes to avoid
unaccounted for buffer spill. If there isn't, what will happen is that the draw numbers are accurate but the production ones will be low (because of the lost heat), which will make the buffer draw down because a fuelling cycle won't be triggered when it should be.
To some extent this is desirable behaviour as it self-corrects, as above, a slightly overfull buffer back down to an efficient one, but in large amounts -- a reactor idled during a fuelling cycle because of significant expansion, or because it's cogenerating with solar, or a power line was cut, or whatever -- it becomes a problem. It isn't a death spiral, as such, because it will recover on the next fuel insertion, but it means that in the tail end of that cycle the reactor may not be supplying power to the grid when the circuits think it is.
A reliable solution to that problem (outside of sizing the heat pipe buffer to be large enough) is one I don't have a simple solution for yet. In principle, with a buffer of known (but potentially insufficient) size, you should also be able to track specifically power use over the course of the reactor burning fuel, and then work out if heat_added - heat_removed > buffer working capacity, and if so by how much, and add that to your energy-consumed calculation. However determining the working actual buffer capacity of heat pipes and reactors is a non-trivial task.
Eventually it will overheat (waste fuel) or cool down too much (brownout). And once you have even the tiniest bit of brownout your steam measurement will think you are using less steam. So it will refuel less. It's a death spiral from that point forward.
This, however, is a non-issue. Because the measurement system
is separate from the main reactor, it cannot read low. It will report accurately no matter what the main is doing (usual caveats about the measurement system needing a UPS and such). That means that if, for example, the main reactor cools off and for that reason isn't generating as much steam as it should to power the turbines, the measurement system will tell it to insert cells as if the turbines were working at their nominal draw.
In other words, it will tell the main reactor add heat
faster than it gets removed, which will thus reheat the mains and cause a recovery to nominal operation. This prevents the death spiral you're discussing, which I
believe is predicated on the idea that you're measuring the flows inside the main reactor complex proper.
Measuring the output of a heat exchanger is an interesting idea, but I'm not certain it's feasible. The mechanics of measuring an input flow are much more complex than measuring a drain.