%Basic model for reactive distillation column for biodiesel production
%By Emilie Øritsland Houge
clc, clear all, close all
format long

%% Feed flows
%     metOH/TG/DG/MG/GL/BD
F = [300 50 0 0 0 0];      % Feed flowrates [kmol/h]
F_new = [300 51 0 0 0 0];  % Disturbance in feed [kmol/h]
F0 = sum(F);               % Total feed flowrate [kmol/h]
F0_new = sum(F_new);       % Total feed flowrate [kmol/h]
x_in = F/F0;               % Molar fractions
x_new = F_new/F0_new;      % Disturbance molar fractions [kmol/h]
Mw = [32.042 878 616 354 92.095 294]; %Molecular weights [kg/kmol]

%% Distillation data, set equal to HYSYS file 
Ntrays = 20;        % Number of trays
NC = 6;             % Number of compounds    
D = 56.9;           % Distillate [kmol/h]
Vb = 237.4;         % Vapour boil up [kmol/h]
B = 293.1;          % Bottoms, [kmol/h]
Ref = 3;            % Reflux ratio
Con_set = 5;        % Holdup condenser [kmol]
Reb_set = 5;        % Holdup reboiler [kmol]


%% Simulation
t0 = 0;     %[h]
tfin = 20;  %[h]

tic
sim('reactivedistillation_sfcn2')
toc

