function dxdt = pke_th_rhs(t, x, plant, Q_sg, u) % PKE_TH_RHS ODE right-hand side for coupled PKE + thermal-hydraulics. % % State x = [n; C1..C6; T_f; T_c; T_cold] (10 x 1) % % Inputs: % t - time [s] % x - continuous state vector (10 x 1) % plant - parameter struct from pke_params() % Q_sg - function handle Q_sg(t) returning SG heat removal [W] % u - external reactivity (rod worth) [dk/k], scalar % % The controller is responsible for computing u; this function treats u % as a given input. Q_sg is the bounded disturbance. n = x(1); C = x(2:7); T_f = x(8); T_c = x(9); T_cold = x(10); T_hot = 2 * T_c - T_cold; Q_sg_val = Q_sg(t); % --- Reactivity with feedback --- % rho = u + alpha_f*(T_f - T_f0) + alpha_c*(T_c - T_c0) rho = u ... + plant.alpha_f * (T_f - plant.T_f0) ... + plant.alpha_c * (T_c - plant.T_c0); % --- Neutronics --- dndt = (rho - plant.beta) / plant.Lambda * n + plant.lambda_i' * C; dCdt = (plant.beta_i / plant.Lambda) * n - plant.lambda_i .* C; % --- Thermal-hydraulics --- % Fuel node: fission power in, heat transfer to coolant out dTf_dt = (plant.P0 * n - plant.hA * (T_f - T_c)) / (plant.M_f * plant.c_f); % Core coolant: heat from fuel in, bulk enthalpy flow out dTc_dt = (plant.hA * (T_f - T_c) - 2*plant.W*plant.c_c*(T_c - T_cold)) ... / (plant.M_c * plant.c_c); % SG/loop node: hot leg enthalpy in, SG heat removal out dTcold_dt = (plant.W * plant.c_c * (T_hot - T_cold) - Q_sg_val) ... / (plant.M_sg * plant.c_c); dxdt = [dndt; dCdt; dTf_dt; dTc_dt; dTcold_dt]; end