2023-02-25 19:11:40 +00:00
|
|
|
local const = require("scada-common.constants")
|
|
|
|
local log = require("scada-common.log")
|
|
|
|
local rsio = require("scada-common.rsio")
|
|
|
|
local types = require("scada-common.types")
|
|
|
|
local util = require("scada-common.util")
|
2023-01-03 21:50:31 +00:00
|
|
|
|
2023-02-25 19:11:40 +00:00
|
|
|
local plc = require("supervisor.session.plc")
|
|
|
|
|
|
|
|
local qtypes = require("supervisor.session.rtu.qtypes")
|
2023-02-19 05:14:27 +00:00
|
|
|
|
2023-03-05 02:55:40 +00:00
|
|
|
local RPS_TRIP_CAUSE = types.RPS_TRIP_CAUSE
|
|
|
|
local TRI_FAIL = types.TRI_FAIL
|
2023-08-21 02:56:51 +00:00
|
|
|
local CONTAINER_MODE = types.CONTAINER_MODE
|
2023-03-05 02:55:40 +00:00
|
|
|
local DUMPING_MODE = types.DUMPING_MODE
|
|
|
|
local PRIO = types.ALARM_PRIORITY
|
|
|
|
local ALARM_STATE = types.ALARM_STATE
|
2023-02-25 04:36:16 +00:00
|
|
|
|
2023-02-25 19:11:40 +00:00
|
|
|
local TBV_RTU_S_DATA = qtypes.TBV_RTU_S_DATA
|
2023-08-21 02:56:51 +00:00
|
|
|
local DTV_RTU_S_DATA = qtypes.DTV_RTU_S_DATA
|
2023-02-25 19:11:40 +00:00
|
|
|
|
2023-02-16 00:52:28 +00:00
|
|
|
local IO = rsio.IO
|
|
|
|
|
2023-02-19 05:14:27 +00:00
|
|
|
local PLC_S_CMDS = plc.PLC_S_CMDS
|
|
|
|
|
2023-02-21 17:40:34 +00:00
|
|
|
local AISTATE_NAMES = {
|
2023-01-03 21:50:31 +00:00
|
|
|
"INACTIVE",
|
|
|
|
"TRIPPING",
|
|
|
|
"TRIPPED",
|
|
|
|
"ACKED",
|
|
|
|
"RING_BACK",
|
|
|
|
"RING_BACK_TRIPPING"
|
|
|
|
}
|
|
|
|
|
2023-02-25 07:25:35 +00:00
|
|
|
local FLOW_STABILITY_DELAY_MS = const.FLOW_STABILITY_DELAY_MS
|
|
|
|
|
|
|
|
local ANNUNC_LIMS = const.ANNUNCIATOR_LIMITS
|
|
|
|
local ALARM_LIMS = const.ALARM_LIMITS
|
2023-02-14 03:11:31 +00:00
|
|
|
|
2023-01-03 21:50:31 +00:00
|
|
|
---@class unit_logic_extension
|
|
|
|
local logic = {}
|
|
|
|
|
|
|
|
-- update the annunciator
|
|
|
|
---@param self _unit_self
|
|
|
|
function logic.update_annunciator(self)
|
|
|
|
local DT_KEYS = self.types.DT_KEYS
|
|
|
|
local _get_dt = self._get_dt
|
|
|
|
|
|
|
|
local num_boilers = self.num_boilers
|
|
|
|
local num_turbines = self.num_turbines
|
2023-11-06 15:21:42 +00:00
|
|
|
local annunc = self.db.annunciator
|
2023-01-03 21:50:31 +00:00
|
|
|
|
2023-11-06 15:21:42 +00:00
|
|
|
annunc.RCSFault = false
|
2023-02-16 00:52:28 +00:00
|
|
|
|
2023-01-03 21:50:31 +00:00
|
|
|
-- variables for boiler, or reactor if no boilers used
|
|
|
|
local total_boil_rate = 0.0
|
|
|
|
|
2024-03-06 02:47:14 +00:00
|
|
|
--#region Reactor
|
2023-01-03 21:50:31 +00:00
|
|
|
|
2023-11-06 15:21:42 +00:00
|
|
|
annunc.AutoControl = self.auto_engaged
|
2023-02-20 17:08:51 +00:00
|
|
|
|
2023-01-03 21:50:31 +00:00
|
|
|
-- check PLC status
|
2023-11-06 15:21:42 +00:00
|
|
|
annunc.PLCOnline = self.plc_i ~= nil
|
2023-01-03 21:50:31 +00:00
|
|
|
|
2023-11-06 15:21:42 +00:00
|
|
|
local plc_ready = annunc.PLCOnline
|
2023-02-03 03:58:51 +00:00
|
|
|
|
2023-11-06 15:21:42 +00:00
|
|
|
if plc_ready then
|
2023-01-03 21:50:31 +00:00
|
|
|
local plc_db = self.plc_i.get_db()
|
|
|
|
|
2023-02-03 03:58:51 +00:00
|
|
|
-- update ready state
|
|
|
|
-- - can't be tripped
|
|
|
|
-- - must have received status at least once
|
|
|
|
-- - must have received struct at least once
|
2023-02-11 01:26:25 +00:00
|
|
|
plc_ready = plc_db.formed and (not plc_db.no_reactor) and (not plc_db.rps_tripped) and
|
|
|
|
(next(self.plc_i.get_status()) ~= nil) and (next(self.plc_i.get_struct()) ~= nil)
|
2023-02-03 03:58:51 +00:00
|
|
|
|
2023-01-03 21:50:31 +00:00
|
|
|
-- update auto control limit
|
2023-10-14 21:57:50 +00:00
|
|
|
if (plc_db.mek_struct.max_burn > 0) and ((self.db.control.lim_br100 / 100) > plc_db.mek_struct.max_burn) then
|
2023-02-09 01:26:13 +00:00
|
|
|
self.db.control.lim_br100 = math.floor(plc_db.mek_struct.max_burn * 100)
|
2023-01-03 21:50:31 +00:00
|
|
|
end
|
|
|
|
|
2023-02-05 18:04:42 +00:00
|
|
|
-- some alarms wait until the burn rate has stabilized, so keep track of that
|
|
|
|
if math.abs(_get_dt(DT_KEYS.ReactorBurnR)) > 0 then
|
|
|
|
self.last_rate_change_ms = util.time_ms()
|
2023-01-03 21:50:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- record reactor stats
|
|
|
|
self.plc_cache.active = plc_db.mek_status.status
|
|
|
|
self.plc_cache.ok = not (plc_db.rps_status.fault or plc_db.rps_status.sys_fail or plc_db.rps_status.force_dis)
|
|
|
|
self.plc_cache.rps_trip = plc_db.rps_tripped
|
|
|
|
self.plc_cache.rps_status = plc_db.rps_status
|
|
|
|
self.plc_cache.damage = plc_db.mek_status.damage
|
|
|
|
self.plc_cache.temp = plc_db.mek_status.temp
|
|
|
|
self.plc_cache.waste = plc_db.mek_status.waste_fill
|
|
|
|
|
|
|
|
-- track damage
|
|
|
|
if plc_db.mek_status.damage > 0 then
|
|
|
|
if self.damage_start == 0 then
|
2023-03-04 18:38:41 +00:00
|
|
|
self.damage_decreasing = false
|
2023-01-03 21:50:31 +00:00
|
|
|
self.damage_start = util.time_s()
|
|
|
|
self.damage_initial = plc_db.mek_status.damage
|
|
|
|
end
|
|
|
|
else
|
2023-03-04 18:38:41 +00:00
|
|
|
self.damage_decreasing = false
|
2023-01-03 21:50:31 +00:00
|
|
|
self.damage_start = 0
|
|
|
|
self.damage_initial = 0
|
|
|
|
self.damage_last = 0
|
|
|
|
self.damage_est_last = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
-- heartbeat blink about every second
|
|
|
|
if self.last_heartbeat + 1000 < plc_db.last_status_update then
|
2023-11-06 15:21:42 +00:00
|
|
|
annunc.PLCHeartbeat = not annunc.PLCHeartbeat
|
2023-01-03 21:50:31 +00:00
|
|
|
self.last_heartbeat = plc_db.last_status_update
|
|
|
|
end
|
|
|
|
|
2023-03-05 02:19:35 +00:00
|
|
|
local flow_low = util.trinary(plc_db.mek_status.ccool_type == types.FLUID.SODIUM, ANNUNC_LIMS.RCSFlowLow_NA, ANNUNC_LIMS.RCSFlowLow_H2O)
|
|
|
|
|
2023-01-03 21:50:31 +00:00
|
|
|
-- update other annunciator fields
|
2023-11-06 15:21:42 +00:00
|
|
|
annunc.ReactorSCRAM = plc_db.rps_tripped
|
|
|
|
annunc.ManualReactorSCRAM = plc_db.rps_trip_cause == types.RPS_TRIP_CAUSE.MANUAL
|
|
|
|
annunc.AutoReactorSCRAM = plc_db.rps_trip_cause == types.RPS_TRIP_CAUSE.AUTOMATIC
|
|
|
|
annunc.RCPTrip = plc_db.rps_tripped and (plc_db.rps_status.ex_hcool or plc_db.rps_status.low_cool)
|
|
|
|
annunc.RCSFlowLow = _get_dt(DT_KEYS.ReactorCCool) < flow_low
|
|
|
|
annunc.CoolantLevelLow = plc_db.mek_status.ccool_fill < ANNUNC_LIMS.CoolantLevelLow
|
|
|
|
annunc.ReactorTempHigh = plc_db.mek_status.temp > ANNUNC_LIMS.ReactorTempHigh
|
|
|
|
annunc.ReactorHighDeltaT = _get_dt(DT_KEYS.ReactorTemp) > ANNUNC_LIMS.ReactorHighDeltaT
|
|
|
|
annunc.FuelInputRateLow = _get_dt(DT_KEYS.ReactorFuel) < -1.0 or plc_db.mek_status.fuel_fill <= ANNUNC_LIMS.FuelLevelLow
|
|
|
|
annunc.WasteLineOcclusion = _get_dt(DT_KEYS.ReactorWaste) > 1.0 or plc_db.mek_status.waste_fill >= ANNUNC_LIMS.WasteLevelHigh
|
2023-02-19 17:20:16 +00:00
|
|
|
|
2023-02-21 16:32:56 +00:00
|
|
|
local heating_rate_conv = util.trinary(plc_db.mek_status.ccool_type == types.FLUID.SODIUM, 200000, 20000)
|
2023-04-09 16:29:29 +00:00
|
|
|
local high_rate = plc_db.mek_status.burn_rate >= (plc_db.mek_status.ccool_amnt * 0.27 / heating_rate_conv)
|
|
|
|
-- this advisory applies when no coolant is buffered (which we can't easily determine)<br>
|
|
|
|
-- it's a rough estimation, see GitHub cc-mek-scada/wiki/High-Rate-Calculation
|
2023-11-06 15:21:42 +00:00
|
|
|
annunc.HighStartupRate = not plc_db.mek_status.status and high_rate
|
2023-01-03 21:50:31 +00:00
|
|
|
|
|
|
|
-- if no boilers, use reactor heating rate to check for boil rate mismatch
|
|
|
|
if num_boilers == 0 then
|
|
|
|
total_boil_rate = plc_db.mek_status.heating_rate
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self.plc_cache.ok = false
|
|
|
|
end
|
|
|
|
|
2024-03-06 02:47:14 +00:00
|
|
|
--#endregion
|
|
|
|
|
|
|
|
--#region Misc RTUs
|
2023-02-16 00:52:28 +00:00
|
|
|
|
2023-11-06 15:21:42 +00:00
|
|
|
local max_rad, any_faulted = 0, false
|
|
|
|
|
2023-02-16 00:52:28 +00:00
|
|
|
for i = 1, #self.envd do
|
2023-11-06 15:21:42 +00:00
|
|
|
local envd = self.envd[i] ---@type unit_session
|
|
|
|
local db = envd.get_db() ---@type envd_session_db
|
|
|
|
any_faulted = any_faulted or envd.is_faulted()
|
|
|
|
if db.radiation_raw > max_rad then max_rad = db.radiation_raw end
|
2023-02-16 00:52:28 +00:00
|
|
|
end
|
|
|
|
|
2023-11-06 15:21:42 +00:00
|
|
|
annunc.RadiationMonitor = util.trinary(#self.envd == 0, 1, util.trinary(any_faulted, 2, 3))
|
|
|
|
annunc.RadiationWarning = max_rad >= ANNUNC_LIMS.RadiationWarning
|
|
|
|
|
|
|
|
annunc.EmergencyCoolant = 1
|
|
|
|
|
2023-02-16 00:52:28 +00:00
|
|
|
for i = 1, #self.redstone do
|
2023-11-06 15:21:42 +00:00
|
|
|
local db = self.redstone[i].get_db() ---@type redstone_session_db
|
|
|
|
local io = db.io[IO.U_EMER_COOL] ---@type rs_db_dig_io|nil
|
2023-02-16 00:52:28 +00:00
|
|
|
if io ~= nil then
|
2023-11-06 15:21:42 +00:00
|
|
|
annunc.EmergencyCoolant = util.trinary(io.read(), 3, 2)
|
2023-02-16 00:52:28 +00:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-03-06 02:47:14 +00:00
|
|
|
--#endregion
|
|
|
|
|
|
|
|
--#region Boilers
|
2023-01-03 21:50:31 +00:00
|
|
|
|
2023-02-03 03:58:51 +00:00
|
|
|
local boilers_ready = num_boilers == #self.boilers
|
|
|
|
|
2023-01-03 21:50:31 +00:00
|
|
|
-- clear boiler online flags
|
2023-11-06 15:21:42 +00:00
|
|
|
for i = 1, num_boilers do annunc.BoilerOnline[i] = false end
|
2023-01-03 21:50:31 +00:00
|
|
|
|
|
|
|
-- aggregated statistics
|
|
|
|
local boiler_steam_dt_sum = 0.0
|
|
|
|
local boiler_water_dt_sum = 0.0
|
|
|
|
|
|
|
|
if num_boilers > 0 then
|
|
|
|
-- go through boilers for stats and online
|
|
|
|
for i = 1, #self.boilers do
|
|
|
|
local session = self.boilers[i] ---@type unit_session
|
|
|
|
local boiler = session.get_db() ---@type boilerv_session_db
|
2023-02-26 19:17:35 +00:00
|
|
|
local idx = session.get_device_idx()
|
2023-01-03 21:50:31 +00:00
|
|
|
|
2023-11-06 15:21:42 +00:00
|
|
|
annunc.RCSFault = annunc.RCSFault or (not boiler.formed) or session.is_faulted()
|
2023-02-16 00:52:28 +00:00
|
|
|
|
2023-02-03 03:58:51 +00:00
|
|
|
-- update ready state
|
|
|
|
-- - must be formed
|
|
|
|
-- - must have received build, state, and tanks at least once
|
|
|
|
boilers_ready = boilers_ready and boiler.formed and
|
|
|
|
(boiler.build.last_update > 0) and
|
|
|
|
(boiler.state.last_update > 0) and
|
|
|
|
(boiler.tanks.last_update > 0)
|
|
|
|
|
2023-01-03 21:50:31 +00:00
|
|
|
total_boil_rate = total_boil_rate + boiler.state.boil_rate
|
2023-02-26 19:17:35 +00:00
|
|
|
boiler_steam_dt_sum = _get_dt(DT_KEYS.BoilerSteam .. idx)
|
|
|
|
boiler_water_dt_sum = _get_dt(DT_KEYS.BoilerWater .. idx)
|
2023-01-03 21:50:31 +00:00
|
|
|
|
2023-11-06 15:21:42 +00:00
|
|
|
annunc.BoilerOnline[idx] = true
|
|
|
|
annunc.WaterLevelLow[idx] = boiler.tanks.water_fill < ANNUNC_LIMS.WaterLevelLow
|
2023-01-03 21:50:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- check heating rate low
|
|
|
|
if self.plc_i ~= nil and #self.boilers > 0 then
|
|
|
|
local r_db = self.plc_i.get_db()
|
|
|
|
|
|
|
|
-- check for inactive boilers while reactor is active
|
|
|
|
for i = 1, #self.boilers do
|
2023-11-06 15:21:42 +00:00
|
|
|
local boiler = self.boilers[i] ---@type unit_session
|
2023-01-03 21:50:31 +00:00
|
|
|
local idx = boiler.get_device_idx()
|
2023-11-06 15:21:42 +00:00
|
|
|
local db = boiler.get_db() ---@type boilerv_session_db
|
2023-01-03 21:50:31 +00:00
|
|
|
|
|
|
|
if r_db.mek_status.status then
|
2023-11-06 15:21:42 +00:00
|
|
|
annunc.HeatingRateLow[idx] = db.state.boil_rate == 0
|
2023-01-03 21:50:31 +00:00
|
|
|
else
|
2023-11-06 15:21:42 +00:00
|
|
|
annunc.HeatingRateLow[idx] = false
|
2023-01-03 21:50:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
boiler_steam_dt_sum = _get_dt(DT_KEYS.ReactorHCool)
|
|
|
|
boiler_water_dt_sum = _get_dt(DT_KEYS.ReactorCCool)
|
|
|
|
end
|
|
|
|
|
2024-03-06 02:47:14 +00:00
|
|
|
--#endregion
|
|
|
|
|
|
|
|
--#region Coolant Feed Mismatch
|
2023-01-03 21:50:31 +00:00
|
|
|
|
|
|
|
-- check coolant feed mismatch if using boilers, otherwise calculate with reactor
|
|
|
|
local cfmismatch = false
|
|
|
|
|
|
|
|
if num_boilers > 0 then
|
|
|
|
for i = 1, #self.boilers do
|
2023-11-06 15:21:42 +00:00
|
|
|
local boiler = self.boilers[i] ---@type unit_session
|
2023-01-03 21:50:31 +00:00
|
|
|
local idx = boiler.get_device_idx()
|
2023-11-06 15:21:42 +00:00
|
|
|
local db = boiler.get_db() ---@type boilerv_session_db
|
2023-01-03 21:50:31 +00:00
|
|
|
|
|
|
|
local gaining_hc = _get_dt(DT_KEYS.BoilerHCool .. idx) > 10.0 or db.tanks.hcool_fill == 1
|
|
|
|
|
|
|
|
-- gaining heated coolant
|
|
|
|
cfmismatch = cfmismatch or gaining_hc
|
|
|
|
-- losing cooled coolant
|
|
|
|
cfmismatch = cfmismatch or _get_dt(DT_KEYS.BoilerCCool .. idx) < -10.0 or (gaining_hc and db.tanks.ccool_fill == 0)
|
|
|
|
end
|
|
|
|
elseif self.plc_i ~= nil then
|
|
|
|
local r_db = self.plc_i.get_db()
|
|
|
|
|
|
|
|
local gaining_hc = _get_dt(DT_KEYS.ReactorHCool) > 10.0 or r_db.mek_status.hcool_fill == 1
|
|
|
|
|
|
|
|
-- gaining heated coolant (steam)
|
|
|
|
cfmismatch = cfmismatch or gaining_hc
|
|
|
|
-- losing cooled coolant (water)
|
|
|
|
cfmismatch = cfmismatch or _get_dt(DT_KEYS.ReactorCCool) < -10.0 or (gaining_hc and r_db.mek_status.ccool_fill == 0)
|
|
|
|
end
|
|
|
|
|
2023-11-06 15:21:42 +00:00
|
|
|
annunc.CoolantFeedMismatch = cfmismatch
|
2023-01-03 21:50:31 +00:00
|
|
|
|
2024-03-06 02:47:14 +00:00
|
|
|
--#endregion
|
|
|
|
|
|
|
|
--#region Turbines
|
2023-01-03 21:50:31 +00:00
|
|
|
|
2023-02-03 03:58:51 +00:00
|
|
|
local turbines_ready = num_turbines == #self.turbines
|
|
|
|
|
2023-01-03 21:50:31 +00:00
|
|
|
-- clear turbine online flags
|
2023-11-06 15:21:42 +00:00
|
|
|
for i = 1, num_turbines do annunc.TurbineOnline[i] = false end
|
2023-01-03 21:50:31 +00:00
|
|
|
|
|
|
|
-- aggregated statistics
|
|
|
|
local total_flow_rate = 0
|
|
|
|
local total_input_rate = 0
|
|
|
|
local max_water_return_rate = 0
|
|
|
|
|
|
|
|
-- recompute blade count on the chance that it may have changed
|
2023-02-02 02:55:02 +00:00
|
|
|
self.db.control.blade_count = 0
|
2023-01-03 21:50:31 +00:00
|
|
|
|
|
|
|
-- go through turbines for stats and online
|
|
|
|
for i = 1, #self.turbines do
|
2023-11-06 15:21:42 +00:00
|
|
|
local session = self.turbines[i] ---@type unit_session
|
|
|
|
local turbine = session.get_db() ---@type turbinev_session_db
|
2023-01-03 21:50:31 +00:00
|
|
|
|
2023-11-06 15:21:42 +00:00
|
|
|
annunc.RCSFault = annunc.RCSFault or (not turbine.formed) or session.is_faulted()
|
2023-02-16 00:52:28 +00:00
|
|
|
|
2023-02-03 03:58:51 +00:00
|
|
|
-- update ready state
|
|
|
|
-- - must be formed
|
|
|
|
-- - must have received build, state, and tanks at least once
|
|
|
|
turbines_ready = turbines_ready and turbine.formed and
|
|
|
|
(turbine.build.last_update > 0) and
|
|
|
|
(turbine.state.last_update > 0) and
|
|
|
|
(turbine.tanks.last_update > 0)
|
|
|
|
|
2023-01-03 21:50:31 +00:00
|
|
|
total_flow_rate = total_flow_rate + turbine.state.flow_rate
|
|
|
|
total_input_rate = total_input_rate + turbine.state.steam_input_rate
|
|
|
|
max_water_return_rate = max_water_return_rate + turbine.build.max_water_output
|
2023-02-02 02:55:02 +00:00
|
|
|
self.db.control.blade_count = self.db.control.blade_count + turbine.build.blades
|
2023-01-03 21:50:31 +00:00
|
|
|
|
2023-11-06 15:21:42 +00:00
|
|
|
annunc.TurbineOnline[session.get_device_idx()] = true
|
2023-01-03 21:50:31 +00:00
|
|
|
end
|
|
|
|
|
2023-02-05 18:04:42 +00:00
|
|
|
-- check for boil rate mismatch (> 4% error) either between reactor and turbine or boiler and turbine
|
2023-11-06 15:21:42 +00:00
|
|
|
annunc.BoilRateMismatch = math.abs(total_boil_rate - total_input_rate) > (0.04 * total_boil_rate)
|
2023-01-03 21:50:31 +00:00
|
|
|
|
|
|
|
-- check for steam feed mismatch and max return rate
|
2023-03-05 02:35:54 +00:00
|
|
|
local steam_dt_max = util.trinary(num_boilers == 0, ANNUNC_LIMS.SFM_MaxSteamDT_H20, ANNUNC_LIMS.SFM_MaxSteamDT_NA)
|
|
|
|
local water_dt_min = util.trinary(num_boilers == 0, ANNUNC_LIMS.SFM_MinWaterDT_H20, ANNUNC_LIMS.SFM_MinWaterDT_NA)
|
2023-02-25 07:25:35 +00:00
|
|
|
local sfmismatch = math.abs(total_flow_rate - total_input_rate) > ANNUNC_LIMS.SteamFeedMismatch
|
2023-03-05 02:19:35 +00:00
|
|
|
sfmismatch = sfmismatch or boiler_steam_dt_sum > steam_dt_max or boiler_water_dt_sum < water_dt_min
|
2023-11-06 15:21:42 +00:00
|
|
|
annunc.SteamFeedMismatch = sfmismatch
|
|
|
|
annunc.MaxWaterReturnFeed = max_water_return_rate == total_flow_rate and total_flow_rate ~= 0
|
2023-01-03 21:50:31 +00:00
|
|
|
|
2023-04-02 13:57:57 +00:00
|
|
|
-- turbine safety checks
|
2023-01-03 21:50:31 +00:00
|
|
|
for i = 1, #self.turbines do
|
2023-11-06 15:21:42 +00:00
|
|
|
local turbine = self.turbines[i] ---@type unit_session
|
|
|
|
local db = turbine.get_db() ---@type turbinev_session_db
|
2023-01-03 21:50:31 +00:00
|
|
|
local idx = turbine.get_device_idx()
|
|
|
|
|
2023-04-02 13:57:57 +00:00
|
|
|
-- check if steam dumps are open
|
2023-01-03 21:50:31 +00:00
|
|
|
if db.state.dumping_mode == DUMPING_MODE.IDLE then
|
2023-11-06 15:21:42 +00:00
|
|
|
annunc.SteamDumpOpen[idx] = TRI_FAIL.OK
|
2023-01-03 21:50:31 +00:00
|
|
|
elseif db.state.dumping_mode == DUMPING_MODE.DUMPING_EXCESS then
|
2023-11-06 15:21:42 +00:00
|
|
|
annunc.SteamDumpOpen[idx] = TRI_FAIL.PARTIAL
|
2023-01-03 21:50:31 +00:00
|
|
|
else
|
2023-11-06 15:21:42 +00:00
|
|
|
annunc.SteamDumpOpen[idx] = TRI_FAIL.FULL
|
2023-01-03 21:50:31 +00:00
|
|
|
end
|
|
|
|
|
2023-04-02 13:57:57 +00:00
|
|
|
-- check if turbines are at max speed but not keeping up
|
2023-11-06 15:21:42 +00:00
|
|
|
annunc.TurbineOverSpeed[idx] = (db.state.flow_rate == db.build.max_flow_rate) and (_get_dt(DT_KEYS.TurbineSteam .. idx) > 0.0)
|
|
|
|
|
|
|
|
-- see notes at cc-mek-scada/wiki/Annunciator-Panels#Generator-Trip
|
|
|
|
annunc.GeneratorTrip[idx] = (_get_dt(DT_KEYS.TurbinePower .. idx) > 0.0) and (db.tanks.energy_fill > 0.05)
|
|
|
|
|
|
|
|
-- see notes at cc-mek-scada/wiki/Annunciator-Panels#Turbine-Trip
|
2023-01-03 21:50:31 +00:00
|
|
|
local has_steam = db.state.steam_input_rate > 0 or db.tanks.steam_fill > 0.01
|
2023-11-06 15:21:42 +00:00
|
|
|
annunc.TurbineTrip[idx] = has_steam and db.state.flow_rate == 0
|
2023-01-03 21:50:31 +00:00
|
|
|
end
|
2023-02-03 03:58:51 +00:00
|
|
|
|
2024-03-06 02:47:14 +00:00
|
|
|
--#endregion
|
|
|
|
|
2023-02-03 03:58:51 +00:00
|
|
|
-- update auto control ready state for this unit
|
|
|
|
self.db.control.ready = plc_ready and boilers_ready and turbines_ready
|
2023-01-03 21:50:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- update an alarm state given conditions
|
|
|
|
---@param self _unit_self unit instance
|
|
|
|
---@param tripped boolean if the alarm condition is still active
|
|
|
|
---@param alarm alarm_def alarm table
|
2023-08-29 13:19:50 +00:00
|
|
|
---@return boolean new_trip if the alarm just changed to being tripped
|
2023-01-03 21:50:31 +00:00
|
|
|
local function _update_alarm_state(self, tripped, alarm)
|
|
|
|
local AISTATE = self.types.AISTATE
|
|
|
|
local int_state = alarm.state
|
|
|
|
local ext_state = self.db.alarm_states[alarm.id]
|
|
|
|
|
|
|
|
-- alarm inactive
|
|
|
|
if int_state == AISTATE.INACTIVE then
|
|
|
|
if tripped then
|
|
|
|
alarm.trip_time = util.time_ms()
|
|
|
|
if alarm.hold_time > 0 then
|
|
|
|
alarm.state = AISTATE.TRIPPING
|
|
|
|
self.db.alarm_states[alarm.id] = ALARM_STATE.INACTIVE
|
|
|
|
else
|
|
|
|
alarm.state = AISTATE.TRIPPED
|
|
|
|
self.db.alarm_states[alarm.id] = ALARM_STATE.TRIPPED
|
2023-02-21 15:31:05 +00:00
|
|
|
log.info(util.c("UNIT ", self.r_id, " ALARM ", alarm.id, " (", types.ALARM_NAMES[alarm.id], "): TRIPPED [PRIORITY ",
|
2023-02-21 17:40:34 +00:00
|
|
|
types.ALARM_PRIORITY_NAMES[alarm.tier],"]"))
|
2023-01-03 21:50:31 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
alarm.trip_time = util.time_ms()
|
|
|
|
self.db.alarm_states[alarm.id] = ALARM_STATE.INACTIVE
|
|
|
|
end
|
|
|
|
-- alarm condition met, but not yet for required hold time
|
|
|
|
elseif (int_state == AISTATE.TRIPPING) or (int_state == AISTATE.RING_BACK_TRIPPING) then
|
|
|
|
if tripped then
|
|
|
|
local elapsed = util.time_ms() - alarm.trip_time
|
|
|
|
if elapsed > (alarm.hold_time * 1000) then
|
|
|
|
alarm.state = AISTATE.TRIPPED
|
|
|
|
self.db.alarm_states[alarm.id] = ALARM_STATE.TRIPPED
|
2023-02-21 15:31:05 +00:00
|
|
|
log.info(util.c("UNIT ", self.r_id, " ALARM ", alarm.id, " (", types.ALARM_NAMES[alarm.id], "): TRIPPED [PRIORITY ",
|
2023-02-21 17:40:34 +00:00
|
|
|
types.ALARM_PRIORITY_NAMES[alarm.tier],"]"))
|
2023-01-03 21:50:31 +00:00
|
|
|
end
|
|
|
|
elseif int_state == AISTATE.RING_BACK_TRIPPING then
|
|
|
|
alarm.trip_time = 0
|
|
|
|
alarm.state = AISTATE.RING_BACK
|
|
|
|
self.db.alarm_states[alarm.id] = ALARM_STATE.RING_BACK
|
|
|
|
else
|
|
|
|
alarm.trip_time = 0
|
|
|
|
alarm.state = AISTATE.INACTIVE
|
|
|
|
self.db.alarm_states[alarm.id] = ALARM_STATE.INACTIVE
|
|
|
|
end
|
|
|
|
-- alarm tripped and alarming
|
|
|
|
elseif int_state == AISTATE.TRIPPED then
|
|
|
|
if tripped then
|
|
|
|
if ext_state == ALARM_STATE.ACKED then
|
|
|
|
-- was acked by coordinator
|
|
|
|
alarm.state = AISTATE.ACKED
|
|
|
|
end
|
|
|
|
else
|
|
|
|
alarm.state = AISTATE.RING_BACK
|
|
|
|
self.db.alarm_states[alarm.id] = ALARM_STATE.RING_BACK
|
|
|
|
end
|
|
|
|
-- alarm acknowledged but still tripped
|
|
|
|
elseif int_state == AISTATE.ACKED then
|
|
|
|
if not tripped then
|
|
|
|
alarm.state = AISTATE.RING_BACK
|
|
|
|
self.db.alarm_states[alarm.id] = ALARM_STATE.RING_BACK
|
|
|
|
end
|
|
|
|
-- alarm no longer tripped, operator must reset to clear
|
|
|
|
elseif int_state == AISTATE.RING_BACK then
|
|
|
|
if tripped then
|
|
|
|
alarm.trip_time = util.time_ms()
|
|
|
|
if alarm.hold_time > 0 then
|
|
|
|
alarm.state = AISTATE.RING_BACK_TRIPPING
|
|
|
|
else
|
|
|
|
alarm.state = AISTATE.TRIPPED
|
|
|
|
self.db.alarm_states[alarm.id] = ALARM_STATE.TRIPPED
|
|
|
|
end
|
|
|
|
elseif ext_state == ALARM_STATE.INACTIVE then
|
|
|
|
-- was reset by coordinator
|
|
|
|
alarm.state = AISTATE.INACTIVE
|
|
|
|
alarm.trip_time = 0
|
|
|
|
end
|
|
|
|
else
|
|
|
|
log.error(util.c("invalid alarm state for unit ", self.r_id, " alarm ", alarm.id), true)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- check for state change
|
|
|
|
if alarm.state ~= int_state then
|
2023-02-21 17:40:34 +00:00
|
|
|
local change_str = util.c(AISTATE_NAMES[int_state], " -> ", AISTATE_NAMES[alarm.state])
|
2023-02-21 15:31:05 +00:00
|
|
|
log.debug(util.c("UNIT ", self.r_id, " ALARM ", alarm.id, " (", types.ALARM_NAMES[alarm.id], "): ", change_str))
|
2023-08-29 13:19:50 +00:00
|
|
|
return alarm.state == AISTATE.TRIPPED
|
|
|
|
else return false end
|
2023-01-03 21:50:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- evaluate alarm conditions
|
|
|
|
---@param self _unit_self unit instance
|
|
|
|
function logic.update_alarms(self)
|
|
|
|
local annunc = self.db.annunciator
|
|
|
|
local plc_cache = self.plc_cache
|
|
|
|
|
|
|
|
-- Containment Breach
|
|
|
|
-- lost plc with critical damage (rip plc, you will be missed)
|
|
|
|
_update_alarm_state(self, (not plc_cache.ok) and (plc_cache.damage > 99), self.alarms.ContainmentBreach)
|
|
|
|
|
|
|
|
-- Containment Radiation
|
2023-02-14 03:11:31 +00:00
|
|
|
local rad_alarm = false
|
|
|
|
for i = 1, #self.envd do
|
2023-03-04 07:05:36 +00:00
|
|
|
self.last_radiation = self.envd[i].get_db().radiation_raw
|
|
|
|
rad_alarm = self.last_radiation >= ALARM_LIMS.HIGH_RADIATION
|
2023-02-14 03:11:31 +00:00
|
|
|
break
|
|
|
|
end
|
|
|
|
_update_alarm_state(self, rad_alarm, self.alarms.ContainmentRadiation)
|
2023-01-03 21:50:31 +00:00
|
|
|
|
|
|
|
-- Reactor Lost
|
|
|
|
_update_alarm_state(self, self.had_reactor and self.plc_i == nil, self.alarms.ReactorLost)
|
|
|
|
|
|
|
|
-- Critical Damage
|
|
|
|
_update_alarm_state(self, plc_cache.damage >= 100, self.alarms.CriticalDamage)
|
|
|
|
|
|
|
|
-- Reactor Damage
|
2023-03-05 03:32:13 +00:00
|
|
|
local rps_dmg_90 = plc_cache.rps_status.high_dmg and not self.last_rps_trips.high_dmg
|
2023-08-30 02:41:56 +00:00
|
|
|
if _update_alarm_state(self, (plc_cache.damage > 0) or rps_dmg_90, self.alarms.ReactorDamage) then
|
2023-08-30 02:34:30 +00:00
|
|
|
log.debug(util.c(">> Trip Detail Report for ", types.ALARM_NAMES[self.alarms.ReactorDamage.id]," <<"))
|
|
|
|
log.debug(util.c("| plc_cache.damage[", plc_cache.damage, "] rps_dmg_90[", rps_dmg_90, "]"))
|
2023-08-29 13:19:50 +00:00
|
|
|
end
|
2023-01-03 21:50:31 +00:00
|
|
|
|
|
|
|
-- Over-Temperature
|
2023-02-07 22:51:55 +00:00
|
|
|
local rps_high_temp = plc_cache.rps_status.high_temp and not self.last_rps_trips.high_temp
|
2023-08-30 02:41:56 +00:00
|
|
|
if _update_alarm_state(self, (plc_cache.temp >= 1200) or rps_high_temp, self.alarms.ReactorOverTemp) then
|
2023-08-30 02:34:30 +00:00
|
|
|
log.debug(util.c(">> Trip Detail Report for ", types.ALARM_NAMES[self.alarms.ReactorOverTemp.id]," <<"))
|
|
|
|
log.debug(util.c("| plc_cache.temp[", plc_cache.temp, "] rps_high_temp[", rps_high_temp, "]"))
|
2023-08-29 13:19:50 +00:00
|
|
|
end
|
2023-01-03 21:50:31 +00:00
|
|
|
|
|
|
|
-- High Temperature
|
2023-02-25 07:25:35 +00:00
|
|
|
_update_alarm_state(self, plc_cache.temp >= ALARM_LIMS.HIGH_TEMP, self.alarms.ReactorHighTemp)
|
2023-01-03 21:50:31 +00:00
|
|
|
|
|
|
|
-- Waste Leak
|
2023-02-25 07:25:35 +00:00
|
|
|
_update_alarm_state(self, plc_cache.waste >= 1.0, self.alarms.ReactorWasteLeak)
|
2023-01-03 21:50:31 +00:00
|
|
|
|
|
|
|
-- High Waste
|
2023-02-07 22:51:55 +00:00
|
|
|
local rps_high_waste = plc_cache.rps_status.ex_waste and not self.last_rps_trips.ex_waste
|
2023-08-30 02:41:56 +00:00
|
|
|
if _update_alarm_state(self, (plc_cache.waste > ALARM_LIMS.HIGH_WASTE) or rps_high_waste, self.alarms.ReactorHighWaste) then
|
2023-08-30 02:34:30 +00:00
|
|
|
log.debug(util.c(">> Trip Detail Report for ", types.ALARM_NAMES[self.alarms.ReactorHighWaste.id]," <<"))
|
|
|
|
log.debug(util.c("| plc_cache.waste[", plc_cache.waste, "] rps_high_waste[", rps_high_waste, "]"))
|
2023-08-29 13:19:50 +00:00
|
|
|
end
|
2023-01-03 21:50:31 +00:00
|
|
|
|
|
|
|
-- RPS Transient (excludes timeouts and manual trips)
|
|
|
|
local rps_alarm = false
|
|
|
|
if plc_cache.rps_status.manual ~= nil then
|
|
|
|
if plc_cache.rps_trip then
|
|
|
|
for key, val in pairs(plc_cache.rps_status) do
|
|
|
|
if key ~= "manual" and key ~= "timeout" then rps_alarm = rps_alarm or val end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
_update_alarm_state(self, rps_alarm, self.alarms.RPSTransient)
|
|
|
|
|
|
|
|
-- RCS Transient
|
|
|
|
local any_low = annunc.CoolantLevelLow
|
|
|
|
local any_over = false
|
2023-04-02 13:57:57 +00:00
|
|
|
local gen_trip = false
|
2023-01-03 21:50:31 +00:00
|
|
|
for i = 1, #annunc.WaterLevelLow do any_low = any_low or annunc.WaterLevelLow[i] end
|
|
|
|
for i = 1, #annunc.TurbineOverSpeed do any_over = any_over or annunc.TurbineOverSpeed[i] end
|
2023-04-02 13:57:57 +00:00
|
|
|
for i = 1, #annunc.GeneratorTrip do gen_trip = gen_trip or annunc.GeneratorTrip[i] end
|
2023-01-03 21:50:31 +00:00
|
|
|
|
2023-04-02 13:57:57 +00:00
|
|
|
local rcs_trans = any_low or any_over or gen_trip or annunc.RCPTrip or annunc.MaxWaterReturnFeed
|
2023-03-05 02:35:54 +00:00
|
|
|
|
2023-01-03 21:50:31 +00:00
|
|
|
-- annunciator indicators for these states may not indicate a real issue when:
|
|
|
|
-- > flow is ramping up right after reactor start
|
|
|
|
-- > flow is ramping down after reactor shutdown
|
2023-02-25 07:25:35 +00:00
|
|
|
if ((util.time_ms() - self.last_rate_change_ms) > FLOW_STABILITY_DELAY_MS) and plc_cache.active then
|
2023-03-05 02:35:54 +00:00
|
|
|
rcs_trans = rcs_trans or annunc.RCSFlowLow or annunc.BoilRateMismatch or annunc.CoolantFeedMismatch or annunc.SteamFeedMismatch
|
2023-01-03 21:50:31 +00:00
|
|
|
end
|
|
|
|
|
2023-08-30 02:41:56 +00:00
|
|
|
if _update_alarm_state(self, rcs_trans, self.alarms.RCSTransient) then
|
2023-08-30 02:34:30 +00:00
|
|
|
log.debug(util.c(">> Trip Detail Report for ", types.ALARM_NAMES[self.alarms.RCSTransient.id]," <<"))
|
|
|
|
log.debug(util.c("| any_low[", any_low, "] any_over[", any_over, "] gen_trip[", gen_trip, "]"))
|
|
|
|
log.debug(util.c("| RCPTrip[", annunc.RCPTrip, "] MaxWaterReturnFeed[", annunc.MaxWaterReturnFeed, "]"))
|
|
|
|
log.debug(util.c("| RCSFlowLow[", annunc.RCSFlowLow, "] BoilRateMismatch[", annunc.BoilRateMismatch,
|
2023-08-29 13:19:50 +00:00
|
|
|
"] CoolantFeedMismatch[", annunc.CoolantFeedMismatch, "] SteamFeedMismatch[", annunc.SteamFeedMismatch, "]"))
|
|
|
|
end
|
2023-01-03 21:50:31 +00:00
|
|
|
|
|
|
|
-- Turbine Trip
|
|
|
|
local any_trip = false
|
|
|
|
for i = 1, #annunc.TurbineTrip do any_trip = any_trip or annunc.TurbineTrip[i] end
|
|
|
|
_update_alarm_state(self, any_trip, self.alarms.TurbineTrip)
|
2023-02-07 22:51:55 +00:00
|
|
|
|
|
|
|
-- update last trips table
|
2023-08-29 13:19:50 +00:00
|
|
|
for key, val in pairs(plc_cache.rps_status) do self.last_rps_trips[key] = val end
|
2023-01-03 21:50:31 +00:00
|
|
|
end
|
|
|
|
|
2023-02-20 17:08:51 +00:00
|
|
|
-- update the internal automatic safety control performed while in auto control mode
|
|
|
|
---@param public reactor_unit reactor unit public functions
|
|
|
|
---@param self _unit_self unit instance
|
|
|
|
function logic.update_auto_safety(public, self)
|
|
|
|
local AISTATE = self.types.AISTATE
|
|
|
|
|
|
|
|
if self.auto_engaged then
|
|
|
|
local alarmed = false
|
|
|
|
|
|
|
|
for _, alarm in pairs(self.alarms) do
|
|
|
|
if alarm.tier <= PRIO.URGENT and (alarm.state == AISTATE.TRIPPED or alarm.state == AISTATE.ACKED) then
|
|
|
|
if not self.auto_was_alarmed then
|
2023-02-21 15:31:05 +00:00
|
|
|
log.info(util.c("UNIT ", self.r_id, " AUTO SCRAM due to ALARM ", alarm.id, " (", types.ALARM_NAMES[alarm.id], ") [PRIORITY ",
|
2023-02-21 17:40:34 +00:00
|
|
|
types.ALARM_PRIORITY_NAMES[alarm.tier],"]"))
|
2023-02-20 17:08:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
alarmed = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if alarmed and not self.plc_cache.rps_status.automatic then
|
2023-06-03 21:59:20 +00:00
|
|
|
public.auto_scram()
|
2023-02-20 17:08:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
self.auto_was_alarmed = alarmed
|
|
|
|
else
|
|
|
|
self.auto_was_alarmed = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-03 21:50:31 +00:00
|
|
|
-- update the two unit status text messages
|
|
|
|
---@param self _unit_self unit instance
|
|
|
|
function logic.update_status_text(self)
|
|
|
|
local AISTATE = self.types.AISTATE
|
2023-11-06 15:21:42 +00:00
|
|
|
local annunc = self.db.annunciator
|
2023-01-03 21:50:31 +00:00
|
|
|
|
|
|
|
-- check if an alarm is active (tripped or ack'd)
|
2023-02-25 04:36:16 +00:00
|
|
|
---@nodiscard
|
2023-01-03 21:50:31 +00:00
|
|
|
---@param alarm table alarm entry
|
|
|
|
---@return boolean active
|
|
|
|
local function is_active(alarm)
|
|
|
|
return alarm.state == AISTATE.TRIPPED or alarm.state == AISTATE.ACKED
|
|
|
|
end
|
|
|
|
|
|
|
|
-- update status text (what the reactor doin?)
|
|
|
|
if is_active(self.alarms.ContainmentBreach) then
|
|
|
|
-- boom? or was boom disabled
|
|
|
|
if self.plc_i ~= nil and self.plc_i.get_rps().force_dis then
|
2023-02-26 19:17:35 +00:00
|
|
|
self.status_text = { "REACTOR FORCE DISABLED", "meltdown would have occurred" }
|
2023-01-03 21:50:31 +00:00
|
|
|
else
|
|
|
|
self.status_text = { "CORE MELTDOWN", "reactor destroyed" }
|
|
|
|
end
|
|
|
|
elseif is_active(self.alarms.CriticalDamage) then
|
|
|
|
-- so much for it being a "routine turbin' trip"...
|
|
|
|
self.status_text = { "MELTDOWN IMMINENT", "evacuate facility immediately" }
|
|
|
|
elseif is_active(self.alarms.ReactorDamage) then
|
|
|
|
-- attempt to determine when a chance of a meltdown will occur
|
|
|
|
self.status_text[1] = "CONTAINMENT TAKING DAMAGE"
|
|
|
|
if self.plc_cache.damage >= 100 then
|
|
|
|
self.status_text[2] = "damage critical"
|
2023-03-05 00:49:56 +00:00
|
|
|
elseif (self.plc_cache.damage < self.damage_last) or ((self.plc_cache.damage - self.damage_initial) < 0) then
|
2023-03-04 18:38:41 +00:00
|
|
|
self.damage_decreasing = true
|
|
|
|
self.status_text = { "CONTAINMENT TOOK DAMAGE", "damage level lowering..." }
|
2023-03-05 00:49:56 +00:00
|
|
|
|
|
|
|
-- reset damage estimation data in case it goes back up again
|
|
|
|
self.damage_initial = self.plc_cache.damage
|
|
|
|
self.damage_start = util.time_s()
|
|
|
|
self.damage_est_last = 0
|
2023-03-04 18:38:41 +00:00
|
|
|
elseif (not self.damage_decreasing) or (self.plc_cache.damage > self.damage_last) then
|
|
|
|
self.damage_decreasing = false
|
|
|
|
|
|
|
|
if (self.plc_cache.damage - self.damage_initial) > 0 then
|
|
|
|
if self.plc_cache.damage > self.damage_last then
|
|
|
|
local rate = (self.plc_cache.damage - self.damage_initial) / (util.time_s() - self.damage_start)
|
|
|
|
self.damage_est_last = (100 - self.plc_cache.damage) / rate
|
|
|
|
end
|
2023-01-03 21:50:31 +00:00
|
|
|
|
2023-03-04 18:38:41 +00:00
|
|
|
self.status_text[2] = util.c("damage critical in ", util.sprintf("%.1f", self.damage_est_last), "s")
|
|
|
|
else
|
|
|
|
self.status_text[2] = "estimating time to critical..."
|
|
|
|
end
|
2023-01-03 21:50:31 +00:00
|
|
|
else
|
2023-03-04 18:38:41 +00:00
|
|
|
self.status_text = { "CONTAINMENT TOOK DAMAGE", "damage level lowering..." }
|
2023-01-03 21:50:31 +00:00
|
|
|
end
|
2023-03-05 00:49:56 +00:00
|
|
|
|
|
|
|
self.damage_last = self.plc_cache.damage
|
2023-01-03 21:50:31 +00:00
|
|
|
elseif is_active(self.alarms.ContainmentRadiation) then
|
2023-03-04 07:05:36 +00:00
|
|
|
self.status_text[1] = "RADIATION DETECTED"
|
|
|
|
|
|
|
|
if self.last_radiation >= const.EXTREME_RADIATION then
|
|
|
|
self.status_text[2] = "extremely high radiation level"
|
|
|
|
elseif self.last_radiation >= const.SEVERE_RADIATION then
|
|
|
|
self.status_text[2] = "severely high radiation level"
|
|
|
|
elseif self.last_radiation >= const.VERY_HIGH_RADIATION then
|
|
|
|
self.status_text[2] = "very high level of radiation"
|
|
|
|
elseif self.last_radiation >= const.HIGH_RADIATION then
|
|
|
|
self.status_text[2] = "high level of radiation"
|
|
|
|
elseif self.last_radiation >= const.HAZARD_RADIATION then
|
|
|
|
self.status_text[2] = "hazardous level of radiation"
|
|
|
|
else
|
|
|
|
self.status_text[2] = "elevated level of radiation"
|
|
|
|
end
|
2023-01-03 21:50:31 +00:00
|
|
|
elseif is_active(self.alarms.ReactorOverTemp) then
|
|
|
|
self.status_text = { "CORE OVER TEMP", "reactor core temperature >=1200K" }
|
|
|
|
elseif is_active(self.alarms.ReactorWasteLeak) then
|
|
|
|
self.status_text = { "WASTE LEAK", "radioactive waste leak detected" }
|
|
|
|
elseif is_active(self.alarms.ReactorHighTemp) then
|
|
|
|
self.status_text = { "CORE TEMP HIGH", "reactor core temperature >1150K" }
|
|
|
|
elseif is_active(self.alarms.ReactorHighWaste) then
|
|
|
|
self.status_text = { "WASTE LEVEL HIGH", "waste accumulating in reactor" }
|
|
|
|
elseif is_active(self.alarms.TurbineTrip) then
|
2023-02-26 19:17:35 +00:00
|
|
|
self.status_text = { "TURBINE TRIP", "turbine stall occurred" }
|
|
|
|
elseif is_active(self.alarms.RCSTransient) then
|
|
|
|
self.status_text = { "RCS TRANSIENT", "check coolant system" }
|
|
|
|
-- elseif is_active(self.alarms.RPSTransient) then
|
|
|
|
-- RPS status handled when checking reactor status
|
2023-02-20 17:08:51 +00:00
|
|
|
elseif self.emcool_opened then
|
|
|
|
self.status_text = { "EMERGENCY COOLANT OPENED", "reset RPS to close valve" }
|
2023-01-03 21:50:31 +00:00
|
|
|
-- connection dependent states
|
|
|
|
elseif self.plc_i ~= nil then
|
|
|
|
local plc_db = self.plc_i.get_db()
|
|
|
|
if plc_db.mek_status.status then
|
|
|
|
self.status_text[1] = "ACTIVE"
|
|
|
|
|
2023-11-06 15:21:42 +00:00
|
|
|
if annunc.ReactorHighDeltaT then
|
2023-01-03 21:50:31 +00:00
|
|
|
self.status_text[2] = "core temperature rising"
|
2023-11-06 15:21:42 +00:00
|
|
|
elseif annunc.ReactorTempHigh then
|
2023-01-03 21:50:31 +00:00
|
|
|
self.status_text[2] = "core temp high, system nominal"
|
2023-11-06 15:21:42 +00:00
|
|
|
elseif annunc.FuelInputRateLow then
|
2023-01-03 21:50:31 +00:00
|
|
|
self.status_text[2] = "insufficient fuel input rate"
|
2023-11-06 15:21:42 +00:00
|
|
|
elseif annunc.WasteLineOcclusion then
|
2023-01-03 21:50:31 +00:00
|
|
|
self.status_text[2] = "insufficient waste output rate"
|
2023-02-25 07:25:35 +00:00
|
|
|
elseif (util.time_ms() - self.last_rate_change_ms) <= FLOW_STABILITY_DELAY_MS then
|
2023-02-07 05:32:50 +00:00
|
|
|
self.status_text[2] = "awaiting flow stability"
|
2023-01-03 21:50:31 +00:00
|
|
|
else
|
|
|
|
self.status_text[2] = "system nominal"
|
|
|
|
end
|
|
|
|
elseif plc_db.rps_tripped then
|
|
|
|
local cause = "unknown"
|
|
|
|
|
2023-03-05 02:55:40 +00:00
|
|
|
if plc_db.rps_trip_cause == RPS_TRIP_CAUSE.OK then
|
2023-01-03 21:50:31 +00:00
|
|
|
-- hmm...
|
2023-03-05 03:32:13 +00:00
|
|
|
elseif plc_db.rps_trip_cause == RPS_TRIP_CAUSE.HIGH_DMG then
|
2023-02-26 19:17:35 +00:00
|
|
|
cause = "core damage high"
|
2023-03-05 02:55:40 +00:00
|
|
|
elseif plc_db.rps_trip_cause == RPS_TRIP_CAUSE.HIGH_TEMP then
|
2023-01-03 21:50:31 +00:00
|
|
|
cause = "core temperature high"
|
2023-03-05 03:19:53 +00:00
|
|
|
elseif plc_db.rps_trip_cause == RPS_TRIP_CAUSE.LOW_COOLANT then
|
2023-01-03 21:50:31 +00:00
|
|
|
cause = "insufficient coolant"
|
2023-03-05 02:55:40 +00:00
|
|
|
elseif plc_db.rps_trip_cause == RPS_TRIP_CAUSE.EX_WASTE then
|
2023-01-03 21:50:31 +00:00
|
|
|
cause = "excess waste"
|
2023-03-05 02:55:40 +00:00
|
|
|
elseif plc_db.rps_trip_cause == RPS_TRIP_CAUSE.EX_HCOOLANT then
|
2023-01-03 21:50:31 +00:00
|
|
|
cause = "excess heated coolant"
|
2023-03-05 02:55:40 +00:00
|
|
|
elseif plc_db.rps_trip_cause == RPS_TRIP_CAUSE.NO_FUEL then
|
2023-01-03 21:50:31 +00:00
|
|
|
cause = "insufficient fuel"
|
2023-03-05 02:55:40 +00:00
|
|
|
elseif plc_db.rps_trip_cause == RPS_TRIP_CAUSE.FAULT then
|
2023-01-03 21:50:31 +00:00
|
|
|
cause = "hardware fault"
|
2023-03-05 02:55:40 +00:00
|
|
|
elseif plc_db.rps_trip_cause == RPS_TRIP_CAUSE.TIMEOUT then
|
2023-01-03 21:50:31 +00:00
|
|
|
cause = "connection timed out"
|
2023-03-05 02:55:40 +00:00
|
|
|
elseif plc_db.rps_trip_cause == RPS_TRIP_CAUSE.MANUAL then
|
2023-01-03 21:50:31 +00:00
|
|
|
cause = "manual operator SCRAM"
|
2023-03-05 02:55:40 +00:00
|
|
|
elseif plc_db.rps_trip_cause == RPS_TRIP_CAUSE.AUTOMATIC then
|
2023-01-03 21:50:31 +00:00
|
|
|
cause = "automated system SCRAM"
|
2023-03-05 02:55:40 +00:00
|
|
|
elseif plc_db.rps_trip_cause == RPS_TRIP_CAUSE.SYS_FAIL then
|
2023-01-03 21:50:31 +00:00
|
|
|
cause = "PLC system failure"
|
2023-03-05 02:55:40 +00:00
|
|
|
elseif plc_db.rps_trip_cause == RPS_TRIP_CAUSE.FORCE_DISABLED then
|
2023-01-03 21:50:31 +00:00
|
|
|
cause = "reactor force disabled"
|
|
|
|
end
|
|
|
|
|
|
|
|
self.status_text = { "RPS SCRAM", cause }
|
2023-11-06 15:21:42 +00:00
|
|
|
elseif annunc.RadiationWarning then
|
2023-03-04 07:05:36 +00:00
|
|
|
-- elevated, non-hazardous level of radiation is low priority, so display it now if everything else was fine
|
|
|
|
self.status_text = { "RADIATION DETECTED", "elevated level of radiation" }
|
2023-01-03 21:50:31 +00:00
|
|
|
else
|
|
|
|
self.status_text[1] = "IDLE"
|
|
|
|
|
|
|
|
local temp = plc_db.mek_status.temp
|
|
|
|
if temp < 350 then
|
|
|
|
self.status_text[2] = "core cold"
|
|
|
|
elseif temp < 600 then
|
|
|
|
self.status_text[2] = "core warm"
|
|
|
|
else
|
|
|
|
self.status_text[2] = "core hot"
|
|
|
|
end
|
|
|
|
end
|
2023-11-06 15:21:42 +00:00
|
|
|
elseif annunc.RadiationWarning then
|
2023-03-04 07:05:36 +00:00
|
|
|
-- in case PLC was disconnected but radiation is present
|
|
|
|
self.status_text = { "RADIATION DETECTED", "elevated level of radiation" }
|
2023-01-03 21:50:31 +00:00
|
|
|
else
|
2023-02-25 04:36:16 +00:00
|
|
|
self.status_text = { "REACTOR OFF-LINE", "awaiting connection..." }
|
2023-01-03 21:50:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-19 05:14:27 +00:00
|
|
|
-- handle unit redstone I/O
|
|
|
|
---@param self _unit_self unit instance
|
|
|
|
function logic.handle_redstone(self)
|
2023-02-20 17:08:51 +00:00
|
|
|
local AISTATE = self.types.AISTATE
|
2023-11-06 15:21:42 +00:00
|
|
|
local annunc = self.db.annunciator
|
2024-03-29 22:31:17 +00:00
|
|
|
local cache = self.plc_cache
|
|
|
|
local rps = cache.rps_status
|
2023-02-20 17:08:51 +00:00
|
|
|
|
|
|
|
-- check if an alarm is active (tripped or ack'd)
|
2023-02-25 04:36:16 +00:00
|
|
|
---@nodiscard
|
2023-02-20 17:08:51 +00:00
|
|
|
---@param alarm table alarm entry
|
|
|
|
---@return boolean active
|
|
|
|
local function is_active(alarm)
|
|
|
|
return alarm.state == AISTATE.TRIPPED or alarm.state == AISTATE.ACKED
|
|
|
|
end
|
|
|
|
|
2023-02-19 05:14:27 +00:00
|
|
|
-- reactor controls
|
|
|
|
if self.plc_s ~= nil then
|
2024-03-29 22:31:17 +00:00
|
|
|
if (not rps.manual) and self.io_ctl.digital_read(IO.R_SCRAM) then
|
2023-02-26 19:17:35 +00:00
|
|
|
-- reactor SCRAM requested but not yet done; perform it
|
2023-02-19 05:14:27 +00:00
|
|
|
self.plc_s.in_queue.push_command(PLC_S_CMDS.SCRAM)
|
|
|
|
end
|
|
|
|
|
2024-03-29 22:31:17 +00:00
|
|
|
if cache.rps_trip and self.io_ctl.digital_read(IO.R_RESET) then
|
2023-02-26 19:17:35 +00:00
|
|
|
-- reactor RPS reset requested but not yet done; perform it
|
2023-02-19 05:14:27 +00:00
|
|
|
self.plc_s.in_queue.push_command(PLC_S_CMDS.RPS_RESET)
|
|
|
|
end
|
|
|
|
|
2024-03-29 22:31:17 +00:00
|
|
|
if (not self.auto_engaged) and (not cache.active) and
|
|
|
|
(not cache.rps_trip) and self.io_ctl.digital_read(IO.R_ENABLE) then
|
2023-02-26 19:17:35 +00:00
|
|
|
-- reactor enable requested and allowable, but not yet done; perform it
|
2023-02-19 05:14:27 +00:00
|
|
|
self.plc_s.in_queue.push_command(PLC_S_CMDS.ENABLE)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- check for request to ack all alarms
|
|
|
|
if self.io_ctl.digital_read(IO.U_ACK) then
|
|
|
|
for i = 1, #self.db.alarm_states do
|
2024-03-29 22:31:17 +00:00
|
|
|
if self.db.alarm_states[i] == ALARM_STATE.TRIPPED then self.db.alarm_states[i] = ALARM_STATE.ACKED end
|
2023-02-19 05:14:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- write reactor status outputs
|
2024-03-29 22:31:17 +00:00
|
|
|
self.io_ctl.digital_write(IO.R_ACTIVE, cache.active)
|
2023-02-20 17:08:51 +00:00
|
|
|
self.io_ctl.digital_write(IO.R_AUTO_CTRL, self.auto_engaged)
|
2024-03-29 22:31:17 +00:00
|
|
|
self.io_ctl.digital_write(IO.R_SCRAMMED, cache.rps_trip)
|
|
|
|
self.io_ctl.digital_write(IO.R_AUTO_SCRAM, rps.automatic)
|
|
|
|
self.io_ctl.digital_write(IO.R_HIGH_DMG, rps.high_dmg)
|
|
|
|
self.io_ctl.digital_write(IO.R_HIGH_TEMP, rps.high_temp)
|
|
|
|
self.io_ctl.digital_write(IO.R_LOW_COOLANT, rps.low_cool)
|
|
|
|
self.io_ctl.digital_write(IO.R_EXCESS_HC, rps.ex_hcool)
|
|
|
|
self.io_ctl.digital_write(IO.R_EXCESS_WS, rps.ex_waste)
|
|
|
|
self.io_ctl.digital_write(IO.R_INSUFF_FUEL, rps.no_fuel)
|
|
|
|
self.io_ctl.digital_write(IO.R_PLC_FAULT, rps.fault)
|
|
|
|
self.io_ctl.digital_write(IO.R_PLC_TIMEOUT, rps.timeout)
|
2023-02-19 05:14:27 +00:00
|
|
|
|
|
|
|
-- write unit outputs
|
|
|
|
|
|
|
|
local has_alarm = false
|
|
|
|
for i = 1, #self.db.alarm_states do
|
2023-03-04 06:37:15 +00:00
|
|
|
if self.db.alarm_states[i] == ALARM_STATE.TRIPPED or self.db.alarm_states[i] == ALARM_STATE.ACKED then
|
2023-02-19 05:14:27 +00:00
|
|
|
has_alarm = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
self.io_ctl.digital_write(IO.U_ALARM, has_alarm)
|
|
|
|
|
2023-02-20 17:08:51 +00:00
|
|
|
-----------------------
|
|
|
|
-- Emergency Coolant --
|
|
|
|
-----------------------
|
|
|
|
|
2024-03-29 22:31:17 +00:00
|
|
|
local boiler_water_low = false
|
|
|
|
for i = 1, #annunc.WaterLevelLow do boiler_water_low = boiler_water_low or annunc.WaterLevelLow[i] end
|
|
|
|
|
|
|
|
local enable_emer_cool = rps.low_cool or
|
|
|
|
(self.auto_engaged and
|
|
|
|
(annunc.CoolantLevelLow or (boiler_water_low and rps.ex_hcool)) and
|
|
|
|
is_active(self.alarms.ReactorOverTemp))
|
|
|
|
|
|
|
|
if enable_emer_cool and not self.emcool_opened then
|
|
|
|
log.debug(util.c(">> Emergency Coolant Enable Detail Report (Unit ", self.r_id, ") <<"))
|
|
|
|
log.debug(util.c("| CoolantLevelLow[", annunc.CoolantLevelLow, "] CoolantLevelLowLow[", rps.low_cool, "] ExcessHeatedCoolant[", rps.ex_hcool, "]"))
|
|
|
|
log.debug(util.c("| ReactorOverTemp[", AISTATE_NAMES[self.alarms.ReactorOverTemp.state], "]"))
|
|
|
|
|
|
|
|
for i = 1, #annunc.WaterLevelLow do
|
|
|
|
log.debug(util.c("| WaterLevelLow(", i, ")[", annunc.WaterLevelLow[i], "]"))
|
|
|
|
end
|
|
|
|
end
|
2023-02-20 17:08:51 +00:00
|
|
|
|
2023-08-27 17:42:25 +00:00
|
|
|
-- don't turn off emergency coolant on sufficient coolant level since it might drop again
|
|
|
|
-- turn off once system is OK again
|
|
|
|
-- if auto control is engaged, alarm check will SCRAM on reactor over temp so that's covered
|
2024-03-29 22:31:17 +00:00
|
|
|
if not cache.rps_trip then
|
2023-02-25 19:11:40 +00:00
|
|
|
-- set turbines to not dump steam
|
|
|
|
for i = 1, #self.turbines do
|
|
|
|
local session = self.turbines[i] ---@type unit_session
|
|
|
|
local turbine = session.get_db() ---@type turbinev_session_db
|
|
|
|
|
|
|
|
if turbine.state.dumping_mode ~= DUMPING_MODE.IDLE then
|
|
|
|
session.get_cmd_queue().push_data(TBV_RTU_S_DATA.SET_DUMP_MODE, DUMPING_MODE.IDLE)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-11-06 15:21:42 +00:00
|
|
|
if annunc.EmergencyCoolant > 1 and self.emcool_opened then
|
2023-02-20 17:08:51 +00:00
|
|
|
log.info(util.c("UNIT ", self.r_id, " emergency coolant valve closed"))
|
2023-02-25 19:11:40 +00:00
|
|
|
log.info(util.c("UNIT ", self.r_id, " turbines set to not dump steam"))
|
2023-02-20 17:08:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
self.emcool_opened = false
|
|
|
|
elseif enable_emer_cool or self.emcool_opened then
|
2023-02-25 19:11:40 +00:00
|
|
|
-- set turbines to dump excess steam
|
|
|
|
for i = 1, #self.turbines do
|
|
|
|
local session = self.turbines[i] ---@type unit_session
|
|
|
|
local turbine = session.get_db() ---@type turbinev_session_db
|
|
|
|
|
|
|
|
if turbine.state.dumping_mode ~= DUMPING_MODE.DUMPING_EXCESS then
|
|
|
|
session.get_cmd_queue().push_data(TBV_RTU_S_DATA.SET_DUMP_MODE, DUMPING_MODE.DUMPING_EXCESS)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-08-21 02:56:51 +00:00
|
|
|
-- make sure dynamic tanks are allowing outflow
|
|
|
|
for i = 1, #self.tanks do
|
|
|
|
local session = self.tanks[i] ---@type unit_session
|
|
|
|
local tank = session.get_db() ---@type dynamicv_session_db
|
|
|
|
|
|
|
|
if tank.state.container_mode == CONTAINER_MODE.FILL then
|
|
|
|
session.get_cmd_queue().push_data(DTV_RTU_S_DATA.SET_CONT_MODE, CONTAINER_MODE.BOTH)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-11-06 15:21:42 +00:00
|
|
|
if annunc.EmergencyCoolant > 1 and not self.emcool_opened then
|
2023-02-20 17:08:51 +00:00
|
|
|
log.info(util.c("UNIT ", self.r_id, " emergency coolant valve opened"))
|
2023-02-25 19:11:40 +00:00
|
|
|
log.info(util.c("UNIT ", self.r_id, " turbines set to dump excess steam"))
|
2023-02-20 17:08:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
self.emcool_opened = true
|
2023-02-19 05:14:27 +00:00
|
|
|
end
|
2023-08-27 17:42:25 +00:00
|
|
|
|
|
|
|
-- set valve state always
|
|
|
|
if self.emcool_opened then self.valves.emer_cool.open() else self.valves.emer_cool.close() end
|
2023-02-19 05:14:27 +00:00
|
|
|
end
|
|
|
|
|
2023-01-03 21:50:31 +00:00
|
|
|
return logic
|