Fill out the DRC mode set with ctrl_shutdown (u = -5*beta), ctrl_scram (u = -8*beta), and ctrl_heatup (feedback-linearizing P on ramped T_avg reference, saturated u, no integrator). Add ctrl_operation_lqr as a full-state-feedback counterpart to ctrl_operation — K cached, closed-loop essentially perfect under the 100%->80% Q_sg step where plain P has ~5F overshoot. Add pke_linearize for numerical (A, B, B_w) Jacobians at any operating point; test_linearize confirms ~4e-4 rel err vs nonlinear sim for a 5% Q_sg step. Extend pke_solver with an optional x0 argument so each mode can start from a plausible IC. main_mode_sweep.m exercises all five modes back-to-back and saves the 4-panel plots. CLAUDE.md updated with model-validity-range note (trust region is ~+/-50C around operating point; true cold shutdown is out of scope for the linear feedback coefficients). Hacker-Split: build out control layer end-to-end for reachability. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
65 lines
2.7 KiB
Matlab
65 lines
2.7 KiB
Matlab
function [t, X, U] = pke_solver(plant, Q_sg, ctrl_fn, ref, tspan, x0)
|
|
% PKE_SOLVER Solve the coupled PKE + T/H system in closed loop with a mode controller.
|
|
%
|
|
% Inputs:
|
|
% plant - parameter struct from pke_params()
|
|
% Q_sg - function handle Q_sg(t) returning SG heat removal [W]
|
|
% ctrl_fn - function handle u = ctrl_fn(t, x, plant, ref)
|
|
% ref - struct of per-mode setpoints (e.g. ref.T_avg); [] if unused
|
|
% tspan - [t_start, t_end] in seconds
|
|
% x0 - (optional) initial state vector (10 x 1). Defaults to the
|
|
% operating steady state from pke_initial_conditions(plant).
|
|
%
|
|
% Outputs:
|
|
% t - time vector (M x 1) from the ODE solver
|
|
% X - state matrix (M x 10): columns are [n, C1..C6, T_f, T_c, T_cold]
|
|
% U - control input trajectory (M x 1): u evaluated at each (t(k), X(k,:))
|
|
|
|
CtoF = @(T) T * 9/5 + 32;
|
|
|
|
%% ===== Print Steady-State =====
|
|
fprintf('=== Steady-State Conditions ===\n');
|
|
fprintf(' beta = %.5f (%.1f pcm)\n', plant.beta, plant.beta*1e5);
|
|
fprintf(' Lambda = %.1e s\n', plant.Lambda);
|
|
fprintf(' P0 = %.0f MWth\n', plant.P0/1e6);
|
|
fprintf(' T_cold = %.1f F\n', CtoF(plant.T_cold0));
|
|
fprintf(' T_avg = %.1f F\n', CtoF(plant.T_c0));
|
|
fprintf(' T_hot = %.1f F\n', CtoF(plant.T_hot0));
|
|
fprintf(' T_fuel = %.1f F\n', CtoF(plant.T_f0));
|
|
fprintf(' Core dT = %.1f F\n', plant.dT_core * 9/5);
|
|
fprintf('================================\n\n');
|
|
|
|
%% ===== Solve closed-loop =====
|
|
if nargin < 6 || isempty(x0)
|
|
x0 = pke_initial_conditions(plant);
|
|
end
|
|
options = odeset('RelTol', 1e-8, 'AbsTol', 1e-10);
|
|
|
|
rhs = @(t, x) pke_th_rhs(t, x, plant, Q_sg, ctrl_fn(t, x, plant, ref));
|
|
[t, X] = ode15s(rhs, tspan, x0, options);
|
|
|
|
%% ===== Reconstruct control trajectory =====
|
|
M = length(t);
|
|
U = zeros(M, 1);
|
|
for k = 1:M
|
|
U(k) = ctrl_fn(t(k), X(k,:).', plant, ref);
|
|
end
|
|
|
|
%% ===== Print Final State =====
|
|
n = X(end, 1); T_f = X(end, 8); T_c = X(end, 9); T_cold = X(end, 10);
|
|
T_hot = 2*T_c - T_cold;
|
|
rho_tot = U(end) ...
|
|
+ plant.alpha_f*(T_f - plant.T_f0) ...
|
|
+ plant.alpha_c*(T_c - plant.T_c0);
|
|
|
|
fprintf('=== Final State (t = %.0f s) ===\n', t(end));
|
|
fprintf(' Power = %.1f MWth (%.3f x nominal)\n', n*plant.P0/1e6, n);
|
|
fprintf(' T_fuel = %.1f F\n', CtoF(T_f));
|
|
fprintf(' T_hot = %.1f F\n', CtoF(T_hot));
|
|
fprintf(' T_avg = %.1f F\n', CtoF(T_c));
|
|
fprintf(' T_cold = %.1f F\n', CtoF(T_cold));
|
|
fprintf(' u = %.4f $ (external reactivity from controller)\n', U(end)/plant.beta);
|
|
fprintf(' rho = %.4f $ (total, incl. T-feedback)\n', rho_tot/plant.beta);
|
|
|
|
end
|