%% main.m — closed-loop entry point % % Scenario: a 100% → 80% SG demand step. Compare the plant's intrinsic % feedback response (ctrl_null) against the stabilizing operation-mode % controller (ctrl_operation) holding T_avg at the nominal setpoint. % % Controller signature (thesis naming): % u = ctrl_(t, x, plant, ref) % where x is the continuous state vector and u is the external rod reactivity. clear; clc; close all; addpath('controllers'); %% ===== Plant ===== plant = pke_params(); %% ===== Scenario ===== % SG heat removal: step down to 80% at t = 30s, hold. Q_sg = @(t) plant.P0 * (1.0 - 0.2 * (t >= 30)); % Reference for the operation-mode controller. ref = struct(); ref.T_avg = plant.T_c0; % hold T_avg at steady-state value % Simulation window. tspan = [0, 600]; %% ===== Baseline: unforced feedback response ===== fprintf('\n----- Run 1: ctrl_null (plant feedback only) -----\n'); [t1, X1, U1] = pke_solver(plant, Q_sg, @ctrl_null, [], tspan); %% ===== Closed loop: operation mode ===== fprintf('\n----- Run 2: ctrl_operation (P on T_avg) -----\n'); [t2, X2, U2] = pke_solver(plant, Q_sg, @ctrl_operation, ref, tspan); %% ===== Plots ===== plot_pke_results(t1, X1, U1, plant, Q_sg, 'ctrl_null (baseline)'); plot_pke_results(t2, X2, U2, plant, Q_sg, 'ctrl_operation (P on T_avg)'); %% ===== Quick comparison figure ===== CtoF = @(T) T*9/5 + 32; figure('Position', [100 50 1000 450], 'Name', 'T_avg comparison'); plot(t1, CtoF(X1(:,9)), 'b-', 'LineWidth', 1.5); hold on; plot(t2, CtoF(X2(:,9)), 'r-', 'LineWidth', 1.5); yline(CtoF(plant.T_c0), 'k--', 'LineWidth', 1.0); xlabel('Time [s]'); ylabel('T_{avg} [F]'); legend('ctrl\_null', 'ctrl\_operation', 'setpoint', 'Location', 'best'); title('T_{avg} tracking: baseline vs stabilizing controller'); grid on;