Read Unit Operations and Streams from a CHEMCAD Flowsheet using MATLAB

The main content of a CHEMCAD flowsheet are unit operations and streams.

MATLAB can be used to optimize a process in a flowsheet. For this, MATLAB has to access any parameter in the flowsheet.

This code snippet demonstrates how to access 12 parameters of one unit operation and all parameters of one stream in a CHEMCAD flowsheet:

%Retrieve all the data of a stream and some of the parameters
%of a unit operation. Gibbs reactor is taken as an example for
%this code snippet.
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 = '..\...\UnitOpsData.cc7';

%Loading the CHEMCAD flowsheet to MATLAB
chemcad.LoadFlowsheet(path);
flowsheet = chemcad.CurrentFlowsheet;
%Read streams data

%Select the desired stream in flowsheet by ID

selectedStream= flowsheet.GetStreamByIdInCurUnits(1);
disp('Selected stream data')
Enthalpy   = selectedStream.Enthalpy

LiquidCp   = selectedStream.LiquidCp

LiquidSurfaceTension   = selectedStream.LiquidSurfaceTension

LiquidViscosity  = selectedStream.LiquidViscosity

LiquidThermalConductivity = selectedStream.LiquidThermalConductivity

GrossHValue   = selectedStream.GrossHValue

LiquidLatentHeat   = selectedStream.LiquidLatentHeat

MassVaporFraction =  selectedStream.MassVaporFraction

MoleVaporFraction  =  selectedStream.MoleVaporFraction

NetHValue = selectedStream.NetHValue

TotalActualDensity = selectedStream.TotalActualDensity

TotalEntropy  =    selectedStream.TotalEntropy 

VaporEnthalpy  = selectedStream.VaporEnthalpy

VaporThermalConductivity  =     selectedStream.VaporThermalConductivity

VaporViscosity  =    selectedStream.VaporViscosity

%Retrieve parameters of the distillation column
%present in CHEMCAD flowsheet
Reactor=flowsheet.GetUnitOperationById(4);
disp('Gibbs reactor parameters')

Id = Reactor.Id

Name =  Reactor.Name

HeatDuty = Reactor.HeatDuty

LamdaFactor = Reactor.LamdaFactor

Pressure = Reactor.Pressure

Temperature = Reactor.Temperature

ReactionPhase = Reactor.ReactionPhase

MaxAllowableTemp = Reactor.MaxAllowableTemp

MinAllowableTemp = Reactor.MinAllowableTemp

ApproachDeltaTemp = Reactor.ApproachDT

HeatofReaction= Reactor.OverallHeatOfRxn

PressureDrop = Reactor.PressureDrop


chemcad.Release;
clear;

%It is recommended to use the following code
%to handle exceptions

catch e 
e.message
if(isa(e,'NET.NetException'))
e.ExceptionObject
chemcad.Release;
clear;
end
end

Files:
Download UnitOpsData.cc7