This commit is contained in:
Navid Sassan 2025-12-09 23:34:01 +01:00
parent d1c2f57891
commit 101c7f2058

View File

@ -416,56 +416,32 @@ local function calculateOutputRate()
result = math.floor(generationRate * 0.8)
reason = state .. " - 80% of generation"
else
-- Normal operation with temperature and saturation targeting
local targetTemp = CONFIG.target_temperature
-- Normal operation: SATURATION is primary driver, TEMPERATURE is safety limit
local targetSat = CONFIG.target_saturation
local limitingFactor = "OPTIMAL"
-- Temperature factor: controls output based on temp vs target
local tempFactor = 1.0
local tempCritical = false
if temp > CONFIG.critical_temperature then
-- Above critical: reduce output significantly for safety
local overTemp = temp - CONFIG.critical_temperature
local tempRange = CONFIG.max_temperature - CONFIG.critical_temperature
tempFactor = 1.0 - (overTemp / tempRange) * 0.8
tempCritical = true
limitingFactor = "TEMP_CRITICAL"
elseif temp > targetTemp then
-- Above target but below critical: increase output to cool down
local overTarget = temp - targetTemp
local targetRange = CONFIG.critical_temperature - targetTemp
tempFactor = 1.0 + (overTarget / targetRange) * 0.5 -- Up to 1.5x
limitingFactor = "TEMP_HIGH"
elseif temp < targetTemp * 0.8 then
-- Well below target: reduce output to let temp rise
local underTarget = targetTemp - temp
tempFactor = 0.5 + (temp / targetTemp) * 0.5 -- 0.5x to 1.0x
limitingFactor = "TEMP_LOW"
end
-- Saturation-based output adjustment (more aggressive: 0.3x to 2.0x)
-- Saturation-based output: high sat = drain more, low sat = drain less
local satError = saturation - targetSat -- positive = too high, negative = too low
local satFactor = 1.0 + satError * 3.0 -- More aggressive: 3x multiplier
satFactor = math.max(0.3, math.min(2.5, satFactor)) -- Clamp to 30%-250%
-- Quadratic scaling for more aggressive response when far from target
local satFactor = 1.0 + satError * 2.0
satFactor = math.max(0.3, math.min(2.0, satFactor)) -- Clamp to 30%-200%
-- Track if saturation is the limiting factor
if satError > 0.1 and limitingFactor == "OPTIMAL" then
if satError > 0.1 then
limitingFactor = "SAT_HIGH"
elseif satError < -0.1 and limitingFactor == "OPTIMAL" then
elseif satError < -0.1 then
limitingFactor = "SAT_LOW"
end
-- SAFETY: If temperature is critical, don't increase output
if tempCritical and satFactor > 1.0 then
satFactor = 1.0
end
-- SAFETY: If temp is low, don't increase output even if sat is high
if temp < targetTemp * 0.8 and satFactor > 1.0 then
satFactor = 1.0
-- Temperature is ONLY a safety limiter (reduces output when too hot)
local tempFactor = 1.0
if temp > CONFIG.critical_temperature then
-- Above critical: reduce output for safety
local overTemp = temp - CONFIG.critical_temperature
local tempRange = CONFIG.max_temperature - CONFIG.critical_temperature
tempFactor = 1.0 - (overTemp / tempRange) * 0.8
tempFactor = math.max(0.2, tempFactor) -- Never go below 20%
limitingFactor = "TEMP_CRITICAL"
-- Also cap saturation factor when temp critical
satFactor = math.min(satFactor, 1.0)
end
local outputRate = generationRate * tempFactor * satFactor