Access Thermodynamic Properties and Models from CHEMCAD using MATLAB

A separation unit operation in MATLAB requires thermodynamic properties and models. This unit operation and many other unit operations in the chemical industry require VLE calculations.

CHEMCAD provides VLE data. CHEMCAD has several built-in thermodynamic models, e.g. NRTL, Wilson, UNIFAC, UNIQUAC, Peng-Robinson (PR), Soave-Redlich-Kwong (SRK).

This code snippet shows how to obtain thermodynamic and VLE data from CHEMCAD using MATLAB:


%Feed stream is already defined in the flowsheet.
%Use CHEMCAD flash calculations and retrieve calculated liquid
%and vapor stream. 

try
%Path to load the CCAPI DLL. Replace the path according to your user
%account

asmInfo = NET.addAssembly('C:\Users\...\Documents\My Simulations\CC-API\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 = '..\...\OneFeed.cc7';

%Loading the CHEMCAD flowsheet to MATLAB

chemcad.LoadFlowsheet(path);
flowsheet = chemcad.CurrentFlowsheet;
%Select the feed stream to flash.
%In the selected flowsheet, the stream ID is 1. 

feedStream = flowsheet.GetStreamByIdInCurUnits(1);


%Use Vapor Pressure (VP) flash method
%to calculate results.

%Enter vapor fraction of the stream

vaporFraction = 0.4;

%Enter pressure in current flowsheet engineering
%unit of the stream. It is bar in the selected flowsheet.

flashPressure = 2; %bar

%Use VPFlash Method on feed stream

flashResults = flowsheet.CalculateVPFlash(vaporFraction,flashPressure,feedStream);

%Printing the flash results

streamLiquid = flashResults.LiquidStream;
streamVapor = flashResults.VaporStream;

%The units of these values depend on the 
%selected engineering set in CHECMAD flowsheet

%Temperature of the vapor stream

vaporTemperature = streamVapor.Temperature % Degree C
%Enthalpy of vapor stream

vaporEnthalpy = streamVapor.Enthalpy %MJ/h
%Temperature of liquid stream

liquidTemperature = streamLiquid.Temperature %Degree C
%Enthalpy of liquid stream

streamLiquid = streamLiquid.Enthalpy %MJ/h
chemcad.Release;
chemcad=0;
asmInfo=0;
flowsheet=0;
%It is recommended to use the following code
%to handle exceptions

catch e 
e.message
if(isa(e,'NET.NetException'))
e.ExceptionObject
chemcad.Release;
chemcad=0;
asmInfo=0;
flowsheet=0;
 end
end

Files:
Download OneFeed.cc7