[0.15.34] Energy input flow limit not respected by providers

This subforum contains all the issues which we already resolved.
Post Reply
Raeon
Burner Inserter
Burner Inserter
Posts: 16
Joined: Wed Jun 22, 2016 8:55 am
Contact:

[0.15.34] Energy input flow limit not respected by providers

Post by Raeon »

Context
I'm writing a mod called Induction Charging. This mod allows you to insert Induction Coils into your power armor, which allow you to charge your equipment batteries by standing in range of a power network. It accomplishes this by using an invisible electric-energy-interface at the players position.

The total throughput in Watts for the player is determined based on the amount and positioning of the coils in the players power armor. This throughput is only calculated when the grid layout is modified, and stored for use during updates. My mod uses a relatively low update rate to prevent having a noticable UPS impact (once per 15 ticks).

Every update, the shadow entity is updated to see how much energy we received and update the requested energy based on how much we actually need (remaining space in equipment batteries), capped by the throughput we calculated earlier. However, it wasn't before long that I noticed that I was receiving more energy than [tickrate] * [electric_input_flow_limit] per [tickrate] ticks. I've posted about this in the Modding help subforum, but that was before we concluded that this was a bug: viewtopic.php?f=25&t=52451.
Observations
IronCartographer and I have been able to narrow the behaviour down to the following example, after about a week of trying to discern where this behaviour comes from.
In the examples below, variables are referred to using square brackets.

Setup
Consider the following power network:
  • Solar panels producing 2MW
  • Accumulators capable of producing 10MW (storage capacity is irrelevant here, just assume they are always full)
Scenario A
If we add a single electric-energy-interface with:
  • [buffer] = 10MW (10x as much as theoretically needed)
  • [electric_input_flow_limit] = 1MW / 60
then after 60 ticks we can expect to see the [energy] level to be at 1MJ. This works as expected.

Scenario B
However, this doesn't always hold up. If (continuing from Scenario A) we instead set
  • [buffer] = 30MW (still 10x)
  • [electric_input_flow_limit] = 3MW / 60 (which exceeds the primary power providers production, thus causing us to also take power from a secondary source)
we will see that the [energy] level after 60 ticks is suddenly 5MJ instead of the expected 3MJ.
Expectations
I expect that when I set the [electric_input_flow_limit] field for an electric-energy-interface to (for example) 5000, I receive at most 5000J in one tick.
Reproduction
Although the above scenario is quite simple, it is not easy to reproduce by hand. In order to reproduce this behaviour, please download and install the attached attached Test mod. With only the Test mod enabled, please start a new game and wait at least 24 seconds whilst the mod alternates between Scenario A and Scenario B.

During this time you are free to move your character. You can click on the power pole to see the current network statistics. The default time before switching scenario is 8 seconds (hence wait 24 seconds for a reasonable sample size), which is chosen so you can easily check the power graph (since 5 seconds is the smallest timeframe) with a reasonable time to spare in order to read the data. Type any message in chat to make a small CSV data dump, saved to /script-output/csv/test.csv.
Additional notes
Additional notes
I hope this post is of use to you! Thanks for the awesome game. I'm looking forward to seeing this issue resolved :D
Attachments
factorio-current.log
(14.45 KiB) Downloaded 80 times
Test_0.0.1.zip
(29.94 KiB) Downloaded 75 times

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [0.15.34] Energy input flow limit not respected by providers

Post by kovarex »

By a weird accident, I simplified and optimized the electric network transfer logic (for 0.16) just today, and it should also fix the problem you described (The limit only applied to one combination of input type and output type transfer).

IronCartographer
Filter Inserter
Filter Inserter
Posts: 455
Joined: Tue Jun 28, 2016 2:07 pm
Contact:

Re: [0.15.34] Energy input flow limit not respected by providers

Post by IronCartographer »

For the record, optimization removed the ability to do the desired control of electric flow without an on_tick event adjusting the electric buffer size.

The bug may have been resolved, but it was by amputation, and at the expense of modded electricity handling efficiency. :|

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [0.15.34] Energy input flow limit not respected by providers

Post by Klonan »

IronCartographer wrote:
Fri May 22, 2020 5:03 pm
For the record, optimization removed the ability to do the desired control of electric flow without an on_tick event adjusting the electric buffer size.

The bug may have been resolved, but it was by amputation, and at the expense of modded electricity handling efficiency. :|
You can set the input flow in the prototype

IronCartographer
Filter Inserter
Filter Inserter
Posts: 455
Joined: Tue Jun 28, 2016 2:07 pm
Contact:

Re: [0.15.34] Energy input flow limit not respected by providers

Post by IronCartographer »

It used to be writable per-entity at runtime, not just at the data stage. I apologize for necroing this topic; it was prompted by https://mods.factorio.com/mod/Induction ... 000b3f48e4

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [0.15.34] Energy input flow limit not respected by providers

Post by Klonan »

IronCartographer wrote:
Fri May 22, 2020 5:34 pm
It used to be writable per-entity at runtime, not just at the data stage. I apologize for necroing this topic; it was prompted by https://mods.factorio.com/mod/Induction ... 000b3f48e4
Sure... I mean you are shooting yourself...

Just have a fixed input flow limit like every other entity in the game?

IronCartographer
Filter Inserter
Filter Inserter
Posts: 455
Joined: Tue Jun 28, 2016 2:07 pm
Contact:

Re: [0.15.34] Energy input flow limit not respected by providers

Post by IronCartographer »

The base game's mechanics do change the flow rate of entities, with module effects and the special behaviors of the rocket silo for example.

Interesting. A way to get around this limitation would be to "consume" energy with an invisible, arbitrarily moduled crafting machine and tracking recipe progress.

Unfortunately, the more complex the setup, the longer the spacing between handlers has to be to overcome the increased overhead. Similar logic applies to creating an array of binary-encoding energy taps for 1kW, 2kW, 4kW, etc.

It is not so simple as saying that there should be a single input flow rate, because the mod has to combine multiple equipment grid entities into a physical electrical grid connection regardless. Depending on the equipment grid investment, this resulting link will vary, so it might as well be able to vary with research for scaling.

Post Reply

Return to “Resolved Problems and Bugs”