% Script that plots the active constrains region
clear
close all
load('outputAC.mat')



%% Plot with text and annotations


figure
plot(z_h_save*3,Tin_c-273.15,'b','Linewidth',1)                                    % hot stream mass flow
ylabel('Temperature, T$_{c,in}$ ($^\circ$C)','Interpreter','latex')              % temperature
hold on
plot([3 3],[293 min(Tin_c)]-273.15,'r','linewidth',1)                            % hot valve bottelneck
plot([3 3.5],[min(Tin_c),293.6]-273.15,'b--','Linewidth',1)                      % extend hot stream plot
%plot([1 1],[min(Tin_c) 303],'r--','linewidth',1)                                % hot valve bottelneck
xlabel('Hot stream mass flow, (kg/s)','Interpreter','latex')
ylim([293 303]-273.15)
xlim([0 3.5])
ax2 = gca;
ax2.FontSize = 14;
ax2.TickLabelInterpreter = 'latex';

%% Add feasible/infeasible regions
xstr = [2.1 0.2 ];
ystr = [28.3 23];
str = {'Infeasible Operation', 'May set $F_H$ freely'};
text(xstr,ystr,str,'FontSize',14,'Interpreter','latex')

%% Add numbers for each feasible region
xcirc1 = 0.2;
ycirc1 = 298-273.13;
circ1 = {'Region \raisebox{.5pt}{\textcircled{\raisebox{-.9pt} {1}}}'};
circ23 = {'\raisebox{.5pt}{\textcircled{\raisebox{-.9pt} {2}}}','\raisebox{.5pt}{\textcircled{\raisebox{-.9pt} {3}}}'};
text(xcirc1,ycirc1,circ1,'FontSize',14,'Interpreter','latex');

%% Add arrow indicating the constraints
xB1 = [0.4900 0.4911]; % point of starting annotation
yB1 = [0.6923 0.6216]; % ending annotation

xB2 = [0.6913 0.7913];
yB2 = [0.26 0.26];

strcirc2 = {'Region \raisebox{.5pt}{\textcircled{\raisebox{-.9pt} {2}}}'};
strcirc3 = {'Region \raisebox{.5pt}{\textcircled{\raisebox{-.9pt} {3}}}'};

%strcirc2 = {'\raisebox{.5pt}{\textcircled{\raisebox{-.9pt} {2}}}'};
%strcirc3 = {'\raisebox{.5pt}{\textcircled{\raisebox{-.9pt} {3}}}'};

ann1 = annotation('textarrow',xB1,yB1,'String',strcirc3,'Interpreter','latex','FontSize',14,'Color','b'); % Region 3
ann2 = annotation('textarrow', xB2,yB2,'String',strcirc2,'Interpreter','latex','FontSize',14,'Color','r'); % Region 2

