MATLAB optimizes a Distillation Column in a CHEMCAD flowsheet

Read distillation column hydraulics using MATLAB

Distillation is one of the most studied unit operations in terms of optimization and control. One way to optimize a distillation column is to find the optimal feed stage. Another way is to tune the control loops.

CHEMCAD is the better tool to simulate a distillation column due to its thermodynamic engine. The CHEMCAD flash algorithms are superior in convergence than any self-programmed algorithm will be. CHEMCAD has 3 specific optimization algorithms: Generalized Reduced Gradient, Successive Quadratic Programming (SQP), and Simultaneous Modular SQP.

MATLAB has an optimization toolbox with 19 built-in algorithms. The community offers many more open source optimization algorithms.

This code snippet combines the best of both worlds. It shows how to read the distillation column hydraulics. It does not show how the optimization is done in MATLAB.

%%Code snippet to read the colum hydraulics data
%%from the CHEMCAD flowsheet using MATLAB with
%%the help of CC-API.

try
%Path to load the CC-API DLL to load library. 
asmInfo = NET.addAssembly('F:\CGC.CC-API.dll');

%Put your .NET Interface key here

license_key='.......'

%Starting CHEMCAD Server

chemcad = CCAPI.Server(license_key);;

%Path to the CHEMCAD flowsheet
path='..\..\Deisobutanizer.cc7';

%Load the CHEMCAD flowsheet
chemcad.LoadFlowsheet(path);
flowsheet=chemcad.CurrentFlowsheet;

%Get an array containing pressure of each tray
%from the first column in the flowsheet

column=flowsheet.GetUnitOperationById(1);

%Get the number of the stages from the CHEMCAD flowsheet
noStages=column.NoOfStages;

%Reading the column hydraulics from the flowsheet

columnResult=column.GetColumnHydraulicsFromSizing(CCAPI.ColumnType.Tray);

%Display result in MATLAB command window
Pressure=columnResult.Pressure;
for i=1:50
fprintf('The Presure at stage %d is %2.1f \n',i,Pressure.Get(i))
end
    
    
%Get an array containing flood percentage of each tray
%from the first column in the flowsheet.

FloodPercent=columnResult.FloodPercent;

%Display result in MATLAB command window
for i=1:50
fprintf('The Flood Percentage at stage %d is %2.1f \n',i,FloodPercent.Get(i))
end

%Release the CHEMCAD objects
chemcad.Release;
chemcad=0;
asmInfo=0;
flowsheet=0;
%Exception handling and release CHEMCAD objects from MATLAB
%If some error occurs or if the reply results in end of program
catch e 
   e.message
  if(isa(e,'NET.NetException'))
    e.ExceptionObject
    chemcad.Release;
    chemcad=0;
    asmInfo=0;
    flowsheet=0;
  end
end

Files:
Download Deisobutanizer.cc7