[posila] [1.0.0] Nonlinear fluid usage with scale_fluid_usage=true

This subforum contains all the issues which we already resolved.
Kaktusbot
Burner Inserter
Burner Inserter
Posts: 15
Joined: Sun Jun 04, 2017 6:54 pm
Contact:

[posila] [1.0.0] Nonlinear fluid usage with scale_fluid_usage=true

Post by Kaktusbot »

Mods: krastorio-2 (1.0.3), Creative Mod (1.5.1)(for testing purposes, bug appears without it too)
Krastorio have gas-power-station, it burns petroleum gas and biomethanol to produce energy.
Lets burn some biomethanol, which have 750kJ fuel value.
When gas-power-station producing max of it power output (4.5MW) it consumes max of it fluid consumption (6/s)
But when load is lower, 15 laser turrets with 100kW drain each for example (1.5MW, 1/3 of it's max), it is expected to fluid consumption to be 2/s proportionally, but instead we have 0.7/s consumption. Btw pollution scales linearly to 1/3 of it's max.
Image
Setting scale_fluid_usage = false for gas-power-stations makes scaling linear and it consumes expected 2/s of fluid under 1.5MW load.

EDIT:
Reproduced in almost vanilla with test mod:

Code: Select all

data.raw.fluid["water"].fuel_value = "1000KJ"

data.raw.generator["steam-engine"].fluid_box.filter = "water"
data.raw.generator["steam-engine"].fluid_box.minimum_temperature = 15.0
data.raw.generator["steam-engine"].maximum_temperature = 15
data.raw.generator["steam-engine"].burns_fluid = true
data.raw.generator["steam-engine"].scale_fluid_usage = true
Image
9MW out of 30MW = 0.3, 0.3^2 = 0.09, 30 * 0.09 = 2.7 fluid/second as is on screenshot.
With scale_fluid_usage = false it consumes 9 fluid/second.

I don't know why you need this:
factorio-current.log
(6.2 KiB) Downloaded 161 times
Test mod:
nonlinear_fluid_usage_test_0.1.0.zip
(1.15 KiB) Downloaded 140 times
Save:
nonlinear_fluid_usage_test.zip
(1.77 MiB) Downloaded 154 times
Last edited by Kaktusbot on Thu Aug 20, 2020 12:40 pm, edited 1 time in total.
Kaktusbot
Burner Inserter
Burner Inserter
Posts: 15
Joined: Sun Jun 04, 2017 6:54 pm
Contact:

Re: [1.0.0] Nonlinear fluid usage with scale_fluid_usage=true

Post by Kaktusbot »

I experimented some more and it seems that proportion is squared.
For example 1/4 of power output means (1/4)^2=1/16 of fluid consumption.
I think this is a bug because scale_fluid_usage as I understand it should prevent wasting of fuel value by capping power output and reducing fluid consumption with more valuable fuel. But for now it makes fuel value more than it should when generator runs at lower power output.
Maybe it's realistic that generators have more efficiency when running not in "red" zone of their performance but in factorio things always have been linear.
Kaktusbot
Burner Inserter
Burner Inserter
Posts: 15
Joined: Sun Jun 04, 2017 6:54 pm
Contact:

Re: [1.0.0] Nonlinear fluid usage with scale_fluid_usage=true

Post by Kaktusbot »

Reproduced this outside of Krastorio2, edited topic post with info, please look.
robot256
Filter Inserter
Filter Inserter
Posts: 995
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: [1.0.0] Nonlinear fluid usage with scale_fluid_usage=true

Post by robot256 »

Kaktusbot wrote: Wed Aug 19, 2020 2:14 pm Maybe it's realistic that generators have more efficiency when running not in "red" zone of their performance but in factorio things always have been linear.
I was expecting the opposite effect. Normally generators are most efficient at full rated power. (Constant power losses are a smaller percentage of the output.)
Kaktusbot
Burner Inserter
Burner Inserter
Posts: 15
Joined: Sun Jun 04, 2017 6:54 pm
Contact:

Re: [1.0.0] Nonlinear fluid usage with scale_fluid_usage=true

Post by Kaktusbot »

I really know nothing about engines but after playing Automation Car Company and all its graphs with rpm and torque I remember that engines have a large drop in performance in "red" zone. Well, maybe it's because of failures or something, as I said I don't really know.
However I'm sure that this is not quadratic/square ratio(?) (sorry, math terms in different languages are very different, I don't know how to say it right in English).

At least I hope this is really a bug and I'm not an idiot who mistakenly took this obvious intended behavior as a bug.
Because silence from devs make me think exactly that.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14594
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [1.0.0] Nonlinear fluid usage with scale_fluid_usage=true

Post by Rseding91 »

The scale fluid usage feature was added by someone with source access and as such I have no idea how they intended for it to work. I can see in the code it's doing this:

Code: Select all

    // Scale the fluid to consume down to the energy we generate per tick
    if (this->prototype->scaleFluidUsage)
      amountToConsume *= (energyToUse / availableEnergy);
If you want to get ahold of me I'm almost always on Discord.
Kaktusbot
Burner Inserter
Burner Inserter
Posts: 15
Joined: Sun Jun 04, 2017 6:54 pm
Contact:

Re: [1.0.0] Nonlinear fluid usage with scale_fluid_usage=true

Post by Kaktusbot »

The scale fluid usage feature was added by someone with source access and as such I have no idea how they intended for it to work.
Unbelievable...

Well, I don't have access to the source so I can't really understand what this variables represent.
Multiplication assignment looks very suspicious to the squaring problem but if this variables represent different kind of things it can be alright.
And about how it intended to work... for me it's kinda obvious that this should not allow you to generate 9MW of energy out of 2.7 units of fluid with 1MJ fuel value. 2.7 units of fluid with 1MJ value should generate 2.7MW of power, not 9MW.

I tried doing other things and this all actually are more complicated.
Example:
Fuel A value = 0.5 MJ
Fuel B value = 1MJ
Fuel C value = 2MJ
fluid_usage_per_tick = 0.5 (30/s)
max_power_output = 30MW
Network load = 15MW

Fluid consumption with scale_fluid_usage = false
A: = 30/s - makes sense, 30/s * 0.5MJ = 15MW
B: = 15/s - makes sense, 15/s * 1MJ = 15MW
C: = 15/s - well... 15/s * 2MJ = 30MW but our load is just 15MW. Seems like without `scale_fluid_usage = true` generator entity wastes all fuel value that is more than it's `max_power_output
=30
/ (fluid_usage_per_tick
=0.5
* 60)`
=1
. So our generator wastes fuel value more than 1MJ. Okay, we are not scaling fluid usage yet, acceptable.

Fluid consumption with scale_fluid_usage = true
A: = 30/s - ok
B: = 7.5/s - ... 7.5/s * 1MJ = 7.5MW, not out 15MW of load, we are generating more energy than consume, hooray! Obviously it's square, 0.5*0.5*30 = 7.5
C: = 3.75/s - ... 3.75 * 2MJ = 7.5MW again, no comments

What are my thoughts about this and your provided line of code.
#1. I assume that this is the only line which is affected by the `scale_fluid_usage`
#2. I assume that `amountToConsume` is number of fluid units to consume in the `scale_fluid_usage = false` path of code.
#3. I assume that `energyToUse` is network load
= 15MW in our case

#4. I assume that `availableEnergy` is `fuel_value * fluid_usage_per_tick * 60`
Lets use this numbers and check
A: amountToConsume=30 *= (energyToUse=15 / availableEnergy=15) = 30
B: amountToConsume=15 *= (energyToUse=15 / availableEnergy=30) = 7.5
C: amountToConsume=15 *= (energyToUse=15 / availableEnergy=60) = 3.75
Yes, numbers are correct for my assumptions. Sadly this is just assumptions. And I don't know what happens in reality.

And what common sense tells me fluid consumption should be?
And even this comment line `Scale the fluid to consume down to the energy we generate per tick` is about it and not about weird squares
A: 30/s - we burn 30/s 0.5MJ fuel to generate 15MW of energy
B: 15/s - 15/s * 1MJ = 15MW
C: 7.5/s - 7.5/s * 2MJ = 15MW
So we burn exactly needed fluid amount based on its fuel value.

I can guess that person responsible for your provided line of code was assuming that generators always work at their max, because in that case generators are actually burning as I expect, as my common sense tells me.
However my assumption #4 is mostly suspicious for me but `fuel_value` must be affecting some of this variables and I didn't find better place for it.

It's very hard to guess what other code do seeing one only line.
Yeah, I may seem begging to share more source code with me, but I understand that this is not possible and all my assumptions and thoughts are complete junk. But this whole situation driving me nuts. I can't believe that Factorio have piece of code with no known intention. I can't believe that so perfectly polished game have such a bug.

Ah, and with my assumptions this line of code should be something like this, fuel_value multiplied by 60 because of code probably works in ticks everywhere, and if fuel_value stored in Joules(W*s) then we should convert it to Watts*ticks

Code: Select all

if (this->prototype->scaleFluidUsage)
    amountToConsume = min(energyToUse / (fuel_value * 60), fluid_usage_per_tick);
posila
Factorio Staff
Factorio Staff
Posts: 5408
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [posila] [1.0.0] Nonlinear fluid usage with scale_fluid_usage=true

Post by posila »

Thanks for the report.
It should be fixed for 1.1.0
Post Reply

Return to “Resolved Problems and Bugs”