ChemCAD 5 services to visual basic applications: User Manual, страница 4

Method             GetFlash                     

Returns                        a handle to IFlash

Method             GetStreamUnitConversion

Returns                        a handle to IStreamUnitConversion

Method             GetCurUnitOp

Returns                        a handle to ICurUnitOp

Method             GetEnthalpy

Returns                        a handle to IEnthalpy

Method             GetKValues

Returns                        a handle to IKValues

Method             GetFlowsheet

Returns                        a handle to IFlowsheet

Method             GetStreamInfo

Returns                        a handle to IStreamInfo

Method             GetStreamProperty

Returns                        a handle to IStreamProperty

Method             GetUnitOpInfo

Returns                        a handle to IUnitOpInfo

Method             GetUnitOpSpecUnitConversion

Returns                        a handle to IUnitOpSpecUnitConversion

Method             GetEngUnitConversion

Returns                        a handle to IEngUnitConversion

Method             GetCompPPData

Returns                        a handle to ICompPPData

The following two methods give Excel UnitOp user the control to decide when to save the current workbook. By default CHEMCAD saves the workbook after every run of the current Excel UnitOp. Alternatively, user can set the flag to FALSE during a run using SetSaveWorkBookFlag to skip saving workbook after the run.

Method             GetSaveWorkBookFlag

Returns                        a boolean flag

Method             SetSaveWorkBookFlag

Returns                        a boolean flag

Argument

Type

Description

bSaveAfterRun

boolean

CHEMCAD saves workbook if set TRUE

User Rate Expressions

If user is modeling a reaction system that deviate from the standard rate expressions in CHEMCAD 5, the user may open the equipment dialog, select “user-specified” for kinetic rate. After entering stoichiometric coefficients, user rate expression dialog will appear. User specifies a VB file to hold the generated codes, and an Excel workbook for CHEMCAD 5 to activate at the time of simulation. Then user will enter their rate expressions for each of the chemical reactions. When click “OK”, the VB codes will be generated and stored in the specified VB file. Next CHEMCAD 5 can import the codes in the VB file into the Excel workbook directly. User is recommended to enter Visual Basic Editor, check for any errors using Debug, and make necessary changes.

Now run simulation in CHEMCAD 5 and the user rate expressions will be activated in either kinetic reactor or batch reactor. If the same set of rate expressions is used in several reactors, enter all the expressions in the equipment dialog for one reactor, and specify the identical Excel workbook path for all of the rest of reactors. If different sets of rate expressions are used in same different reactors, specify Excel workbook paths and rate expressions using different VB files and Excel workbooks respectively.  

The Excel macro activated during simulation has the following signature:

            Sub UserRxnRates(ByRef Rate() As Double, ByVal Temp As Double,

           ByVal Pres As Double, ByVal Rpm As Double, ByRef Conc() As Double,

    ByRef KPar() As Single, ByVal ChemCADEntry As Object)

    Rate(1) = RxnRate001(Temp, Pres, Rpm, Conc, KPar, ChemCADEntry) 

    Rate(2) = RxnRate002(Temp, Pres, Rpm, Conc, KPar, ChemCADEntry) 

    …

End Sub

Here array Rate returns the rates of chemical reactions, Temp is current temperature in user unit, Pres is current pressure in user unit, Rpm is the propeller speed, array Conc contains concentrations in user units, array KPar carries kinetic parameters, and ChemCADEntry is an object handle through which many CHEMCAD 5 information can be accessed. Currently 10 kinetic parameters are assigned for each reaction. Among the 10 parameters, the first is frequency factor and the second is the exponential term including activation energy and temperature. The rest in the 10 are reserved at this time. Within this macro, the functions for each of the rate expressions are called. The rate function for reaction no. 1 looks like the following