Professional Documents
Culture Documents
VM Gsim Com Automation
VM Gsim Com Automation
VM Gsim Com Automation
5 Manual 1
To view the Table of Contents in Adobe Reader, right click on the left hand column of
the document and select Bookmarks.
The COM interface to VMGSim is used to interact directly with the simulator from a programming language
instead of using the graphical user interface from VMGSim. This allows users to do diverse things such as per-
form custom calculations, code optimization routines, create operator trainers or embed the engine in another
application.
The file VMGMasterInterface.dll must be registered before using the COM Automation engine from VMGSim.
This file is automatically installed and registered during the standard installation of VMGSim. Registration can
be performed manually by running the file RegisterVMGSim.bat located in the installation directory of the pro-
gram.
Declaration Statements
Option Explicit ' optional
Option Base 0
The names of the simulation objects (e.g. unit operation names) are case sensitive and the following characters
are not accepted as names, space ( ), commas (,), bars (|) and periods (.).
Simulation Objects
Object Hierarchy
The simulation engine has an object oriented design with a pre-defined hierarchy. This section of the manual
describes how the main objects interact with each other and how they can be accessed through COM inter-
faces.
The top object in the hierarchy is known as the main simulation engine. This object is in charge of creating,
storing and recalling simulation cases. The engine interacts directly with a number of different objects such as
the thermodynamics manager, the root flowsheet, the units system, the case study manager, the historian,
etcetera.
A flowsheet contains unit operations that are connected through material ports. The unit operations contain vari-
ables of different types, for example signal ports, energy ports and profiles. The thermodynamics manager con-
tains a list of thermodynamic cases which can be associated with a flowsheet or unit operations. This
association defines the equilibrium calculations carried out by the different unit operations.
Every object has a name and can be uniquely identified by the concept of path or full name. The path of an
object is built by joining the name of the object and the path of the parent object with a period (.). For example,
the path /.C1.DeltaP refers to an object called DeltaP inside of an object called C1 that in turn is contained
inside of an object called /.
The root flowsheet is always called / and the thermodynamics manager is always called $. It is common to
not write the first . after either / or $. For example, /C1.DeltaP.instead of the equivalent /.C1.DeltaP
The image below shows a simplified object structure of the simulation engine.
The simulator keeps a separate copy of every unit operation for each solver and the main engine keeps them
synchronised. The user can set the active engine in a per flowsheet basis. This active engine is the source for
values when a variable is inspected. For example, the temperature from a stream can have a steady state and a
dynamics value. The value returned by the variable depends on the active engine.
Object interfaces
The user interacts with the different objects through COM interfaces. An interface is a type of contract that
ensures that an object implements a specific set of functions. The objects from the simulator may implement
more than one interface allowing the user to cast the object to the most convenient interface depending on the
situation.
The most important interface is the VMGObject which is implemented by most objects and it is also inherited by
most interfaces. A VMGObject implements methods such as GetName, GetParent and GetVMGObject. This
interface offers generic access to most objects which is convenient for traversing hierarchies of objects.
The main engine is of type VMGMainEngine which also implements the VMGObject. The main engine contains
functions and properties to create simulation cases and access the main objects of the simulation. This is the
only interface that users can instantiate directly, for example,
Dim gVMGEngine as VMGMainEngine
Set gVMGEngine = New VMGMainEngine
Cast as an object
Dim asObj as VMGObject
Set asObj = gVMGEngine
When working with VBA, an easy way to inspect the available functions from an interface is by typing . and
looking and the dropdown control (IntelliSense).
The unit operations implement three interfaces, VMGObject, VMGUnitOperation and a specific interface
depending on the type of unit operation, for example a cooler implements the VMGOpCooler interface.
Dim cool as VMGOpCooler
Set cool = gVMGEngine.RootFlowsheet.AddUnitOp(eCooler, C1)
Another important interface is the VMGVariable that exposes functions to interact with variables of any type
(scalars, vectors, strings, and numbers). This interface also implements VMGObject.
Dim Var as VMGVariable
The ability to cast to different interfaces is contained within the objects. For example, a unit operation that is
defined as a VMGObject can be casted as a VMGUnitOperation at any time,
Dim names
Dim asObj as VMGObject
Set asObj = gVMGEngine.RootFlowsheet.AddUnitOp(eHeater, H1)
For convenience, the interfaces inherit the methods from their base interfaces, for example, a VMGVariable
exposes the method GetName which is originally defined in VMGObject.
Dim Var as VMGVariable
Set Var = cool.DeltaP
Debug.Print Var.GetPath() Inherited method
Setting up a Simulation
There are two steps required in order to set up a simulation session. The first step is to instantiate the main
engine and the second step is to set up a callback object. The callback is the mechanism used by the VMGSim
engine to provide feedback on the status of the simulator. It notifies about actions taken, errors and warnings.
The installation of VMGSim includes base projects that can be used as a starting point when using the COM
interface. These projects are described later in the manual.
Do something with it
MsgBox renderedMsg
End Function
If withDynamics Then
Call gVMGEngine.AddDynamicsSupport2
End If
Exit Sub
'... Connect
Call Cooler.InPort.ConnectTo(Feed)
Call Cooler.Outport.ConnectTo(Product)
Exit Sub
Getting Started
Excel and the VMGSim COM Interface
This section was written based on Office 2007
This section will talk about how to get started with the VMG COM Interface using Microsoft Excel. There will be
instructions on how to add the Engine DLL as a reference, as well as how to build your own case and use the
Base Project example case.
Getting Started
In order to start developing with the DLL, we must first prep Excel 2007 into a more development friendly set-
ting. We will need to start by enabling the Developer ribbon. (This option is off by default) If you have done this
previously, please skip this section.
1. Click the Office balloon and click the Excel Options button
2. The Excel Options window should now appear. Please make sure that the Show Developer tab in
the Ribbon option is checked. Next press OK to save the changes.
Now that the Developer tab has been enabled, we need to add a reference to the VMGEngine DLL.
1. In the newly acquired Developer tab, please click the Visual Basic button. This will open up Excels
VB editor where we can add/edit code etc.
3. Look for VMGSim COM Interface in the list of Available References, select the VMGSim DLL and
press OK
At this point you are ready to start coding with the VMGSim Interface. The main engine can be created as
shown below,
The CreateEngine routine still needs to set up a callback object and maybe enable the dynamics engine. See
the Setting up a simulation sub section of this manual inside of Introduction to VMGSim Automation.
The installation of VMGSim comes with an Excel file called BaseProject.xls that serves as a proper starting
point to develop your own projects. It is recommended that you start working from this file because it is already
set up with a callback and it contains a simple simulation that can be used as reference. This Excel example is
explained further in the next section of the manual.
Excel Examples\BaseProject\BaseProject.xls
Purpose
The purpose of this example is to show how easy it is to get up and running with the VMGSim Engine. This file is
also provided as a starting point for your own projects.
Description
In this example, a simple case is built from scratch. The case has 2 Streams and 1 Cooler. The T, P, MoleFlow,
and Fraction values will be filled in for the first stream, and a DeltaP will be specified for the Cooler. The case
will then solve for the rest of the values.
To clean up the worksheet and start again, simply press the Clear button.
Dim i As Long
Dim cbNames
Dim doNew As Boolean
doNew = False
If doNew Then
'... Create a new instance of the engine
Set gVMGEngine = New VMGMainEngine
End If
Exit Sub
localErr:
Call MsgBox("Error while trying to create simulation engine." & _
vbCrLf & Err.Description, vbCritical, "VMG Engine Error")
End Sub
'... Connect
Call Cooler.InPort.ConnectTo(Feed)
Call Cooler.Outport.ConnectTo(Product)
End Sub
And thats all! VMGSim will automatically solve as you set values into the simulation.
You can use this example in your own projects by just removing the SimTest worksheet and writing your own
code to call CreateEngine and interact with the simulator.
Getting Started
1. Once the Visual Basic is opened the first step is to add a reference to the VMGEngine DLL. In the
Project menu select References .... Look for VMGSim COM Interface in the list of Available
References, select the VMGSim DLL and press OK
At this point you are ready to start coding with the VMGSim Interface. The main engine can be created as
shown below,
The CreateEngine routine still needs to set up a callback object and maybe enable the dynamics engine. See
the Setting up a simulation sub section of this manual inside of Introduction to VMGSim Automation.
The installation of VMGSim comes with a Visual Basic 6 project called BaseProject.vbp that serves as a proper
starting point to develop your own projects. It is recommended that you start working from this file because it is
already set up with a callback and it contains a simple simulation that can be used as reference. This VB project
is explained further in the next section of the manual.
VB6 Examples\BaseProject\BaseProject.vbp
Purpose
The purpose of this example is to show how easy it is to get up and running with the VMGSim Engine. This file is
also provided as a starting point for your own projects.
Description
In this example, a simple case is built from scratch. The case has 2 Streams and 1 Cooler. The T, P, MoleFlow,
and Fraction values will be filled in for the first stream, and a DeltaP will be specified for the Cooler. The case
will then solve for the rest of the values.
To clean up the status messages and start again, simply press the Clear button.
Dim i As Long
Dim cbNames
Dim doNew As Boolean
doNew = False
If doNew Then
'... Create a new instance of the engine
Set gVMGEngine = New VMGMainEngine
End If
Exit Sub
localErr:
Call MsgBox("Error while trying to create simulation engine." & _
vbCrLf & Err.Description, vbCritical, "VMG Engine Error")
End Sub
'... Connect
Call Cooler.InPort.ConnectTo(Feed)
Call Cooler.Outport.ConnectTo(Product)
End Sub
And thats all! VMGSim will automatically solve as you set values into the simulation.
You can use this example in your own projects by just removing the from frmMain and writing your own code
to call CreateEngine and interact with the simulator.
For the purposes of this guide the main difference between the Express Edition and the Standard, Professional
and upper editions is the availability of Project and Item templates. These templates allow the user to quickly set
up a new project type with all the minimum necessary components and settings.
This guide will present the way to properly setup a project within Visual Basic 2008 Express Edition so that it
can use the VMGSim COM Interface.
Getting Started
1. Open Visual Basic 2008 Express Edition and Add a New Project. From the available Project Tem-
plates choose the Windows Forms Application. Rename your project and press OK.
2. Once the New Project has been created you will be presented with the default form. The first task is
to Add a Reference to the VMGEngine DLL. In the Project menu select Add Reference.... Go to
the COM tab and select the VMGSim COM Interface component from the list then press OK.
3. Now it is necessary to instruct VB 2008 to make the classes defined in our project (i.e. the callback
class) compatible with the VMGSim COM Interface. To do this, double click on the My Project item
in the Solution Explorer pane to bring the Application Properties window. In the Application tab click
on the Assembly Information... button. This will bring the Assembly Information window. Enable
the Make assembly COM-Visible and then press OK.
If you have Visual Studio 2008 Standard Edition or upper you can skip this step by using the VB COM Class
template when adding the class to define the callback.
At this point you are ready to start coding with the VMGSim Interface. The main engine can be created as
shown below,
In the .NET Framework it is necessary to enable the code to see the methods and functions of the reference
to be used. In Visual Basic 2008 this can be accomplished by explicitly typing the reference name followed by a
dot (e.g. gVMGEngine = New VMGMasterInterface.VMGMainEngine) every time it needs to use a method or
function or by importing the reference to the current file (e.g. Imports VMGMasterInterface) and then just call
the method or function that is needed.
The CreateEngine routine still needs to set up a callback object and maybe enable the dynamics engine. See
the Setting up a simulation sub section of this manual inside of Introduction to VMGSim Automation.
The installation of VMGSim comes with a Visual Basic 2008 project called BaseProject.vbproj that serves as a
proper starting point to develop your own projects. It is recommended that you start working from this file
because it is already set up with a callback and it contains a simple simulation that can be used as reference.
This VB 2008 project is explained further in the section below.
Purpose
The purpose of this example is to show how easy it is to get up and running with the VMGSim Engine. This file is
also provided as a starting point for your own projects.
Description
In this example, a simple case is built from scratch. The case has 2 Streams and 1 Cooler. The T, P, MoleFlow,
and Fraction values will be filled in for the first stream, and a DeltaP will be specified for the Cooler. The case
will then solve for the rest of the values.
To clean up the status messages and start again, simply press the Clear button.
The VMGEngine and the callback will be globals, such that once initialized we can use them throughout the pro-
gram.
Public gVMGEngine As VMGMainEngine '... The VMGSim engine
Public gCallBack As VMGCallBack '... Callback the engine calls to notify events
CreateEngine is the main routine in the VMGGlobals module. This routine accepts a few default parameters
that customize the creation of the simulation engine depending on the situation. It also has the appropriate
checks to avoid re-creating the simulation engine if it is not necessary.
Public Sub CreateEngine(Optional ByVal withDynamics As Boolean = False, _
Optional ByVal optimizeCode As Boolean = False, _
Optional ByVal logCommands As Boolean = True)
'-----------------------------------------------------------------------------------
----
' Purpose : Starts a new instance of the VMGEngine and hooks the CallBack
'
' Arguments:
' withDynamics - Indicates if it should attempt to activate the dynamics engine
' optimizeCode - Sets up a flag in st state engine that speeds up calculations but
increases memory footprint
' logCommmands - Logs the commands to a tst file that is included inside of the vmp
file.
'----------------------------------------------------------------------------------
-----
'
Dim i As Long
Dim cbNames
Dim doNew As Boolean
doNew = False
If doNew Then
'... Create a new instance of the engine
gVMGEngine = New VMGMainEngine
End If
If withDynamics Then
If Not gVMGEngine.HasDynamicsSupport() Then
Call gVMGEngine.AddDynamicsSupport2()
End If
End If
Exit Sub
localErr:
Call MsgBox("Error while trying to create simulation engine." & vbCrLf & Err.De-
scription, vbCritical, "VMG Engine Error")
End Sub
'... Connect
Call Cooler.InPort.ConnectTo(Feed)
Call Cooler.Outport.ConnectTo(Product)
Exit Sub
localErr:
Call MsgBox("Error while running simulation test", vbCritical, "VMGSim COM Error")
End Sub
And thats all! VMGSim will automatically solve as you set values into the simulation.
You can use this example in your own projects by just removing or modifying the form frmMain and writing
your own code to call CreateEngine and interact with the simulator.
Programming Interface
VMGMainEngine
VMGMainEngine
VMGSim main class, this class handles the entire simulation.
Implements VMGObject.
Public Members
< VMGIntegrator > Get ActiveIntegrator()
Returns the integrator that is currently active.
<Long> AddDynamicsSupport2()
Adds dynamics support to the simulation case.
<Variant>CallBackNames()
Returns an array with the names of the actual call backs.
<Boolean> CanRunAssistants()
Returns a Boolean with the value of True if the Case has dynamics support and a valid license to run the
Dynamics Assistants.
<Boolean> CanRunFullDynamics()
Returns a Boolean with the value of True if the Case has dynamics support and a valid license to run Full
Dynamics.
CleanUp()
Cleans up the main engine.
<Long>ClearCase()
Clears the current case. It is equivalent to creating a new case.
CreateDataSet(<VMGObject> vObj)
Adds a data set to the historian with the default variables of the vObjs unit operation type, vObj can be any
VMGUnitOperation.
<String> CreateUniqueID()
Generates a unique ID, The ID is generic and can be used for any purpose; nothing gets stored or modified
inside the engine.
<VMGHistorian> GetHistorian()
Returns the historian object.
Go()
Starts the solver.
<Boolean> HasDynamicsSupport()
Returns a Boolean with the value of True if the simulation case has dynamics support.
hold()
Stops the solver.
ReadScript(<String> path)
Reads and executes a script file.
RecoverDynSnapshot(<String> path)
Recovers the previously stored dynamics state.
<Long> RemoveDynamicsSupport()
Removes dynamics support from the simulation case.
SaveDynSnapshot(<String> path)
Stores the dynamics state of the flowsheet specified by the path.
<Variant> Solve()
Initializes the solver sequence.
AddDynamicsSupport
Deprecated. Use AddDynamicsSupport2 instead.
AddDynamicsSupport2
Adds dynamics support to the simulation case.
Method:
Public Function AddDynamicsSupport2() As Long
Parameters:
There are no parameters in this function.
Return values:
AddDynamicsSupport2 - Returns 0 as Long if there were no errors.
Example:
Public Sub test()
Dim retVal As Long
retVal = gVMGEngine.AddDynamicsSupport2()
End Sub
CanSetValueInDynamics2
Returns a Boolean with the value of True if the variable value is allowed to change.
Method:
CanSetValueInDynamics2(ByVal path As String, ByVal Value, ByVal calcStatus As Long, Optional ByVal
ignIntegRunning As Boolean = False) As Boolean
Parameters:
path variable path as string.
Value value intended to be set as variant.
calcStatus status being set for the variable as long, (2 spec, 4, calculated,128 dynamics estimate).
ignIntegRunning if this value is true it assumes that the integrator is running.
Return values:
CanSetValueInDynamics2 - This function returns True as Boolean if the change is allowed.
Example:
Public Sub test()
Dim CanSetVal As Boolean
CanSetVal = gVMGEngine.CanSetValueInDynamics2("/C1.Out.T",2,True)
End Sub
CleanUp
Cleans the main engine, makes it nothing.
Method:
Public Sub CleanUp()
Parameters:
There are no parameters in this function.
Return values:
CleanUp - This function does not return anything.
Example:
Public Sub test()
call gVMGEngine.CleanUp()
End Sub
ClearCase
Clears the current case. It is equivalent to creating a new case.
Method:
Public Function ClearCase() As Long
Parameters:
There are no parameters in this function.
Return values:
ClearCase - Returns 0 as Long if there were no errors.
Example:
Public Sub test()
call gVMGEngine.ClearCase()
End Sub
CreateDataSet
Adds a data set to the historian with the default variables of the vObjs unit operation type, vObj can be any
VMGUnitOperation.
Method:
Public Sub CreateDataSet(vObj As VMGObject)
Parameters:
vObj any VMGUnitOperation as VMGObject.
Return values:
CreateDataSet - This function does not return anything.
Example:
Public Sub test()
Dim vCooler As VMGOpCooler
Set vCooler = gVMGEngine.GetVMGObject("/C1")
Call gVMGEngine.CreateDataSet(vCooler)
End Sub
CreateUniqueID
Generates a unique ID, The ID is generic and can be used for any purpose; nothing gets stored or modified
inside the engine.
Method:
Public Function CreateUniqueID() As String
Parameters:
There are no parameters in this function.
Return values:
CreateUniqueID - This function returns the unique ID as String.
Example:
Public Sub test()
Dim uniqueID As String
uniqueID = gVMGEngine.CreateUniqueID
End Sub
Eval
Evaluates Command Line Interface statements; it can be used to set values or to retrieve information. This is an
auxiliary method.
Method:
Public Function Eval(rawCmd As String) as Variant
Parameters:
rawCmd command line interface statement as string.
Return values:
Eval - It is context dependant, the most common way to use it is to return a rendered representation of the
objects. When used to set a value it returns an empty string.
Example:
Example1 Set Value:
Public Sub test()
Dim cmd As String
cmd = "/H1.DeltaP = 30 psi"
Call gVMGEngine.Eval(cmd)
End Sub
Get ActiveIntegrator
Returns the integrator that is currently active.
Method:
Public Property Get ActiveIntegrator() As VMGIntegrator
Parameters:
There are no parameters in this function.
Return values:
ActiveIntegrator - The function returns the active integrator as VMGIntegrator.
Example:
Public Sub test()
Dim vInt As VMGIntegrator
Set vInt = gVMGEngine.ActiveIntegrator()
End Sub
Get AppTitle
Returns the applications title.
Method:
Public Property Get AppTitle() As String
Parameters:
There are no parameters in this function.
Return values:
AppTitle - This function returns the applications title as String.
Example:
Public Sub test()
Dim appTitle As String
appTitle = gVMGEngine.appTitle
End Sub
Get AutoLogCommands
Returns a Boolean with the value of True if the Commands are being Auto Logged in the TST file; the default
value of the property is True
Method:
Public Property Get AutoLogCommands() As Boolean
Parameters:
There are no parameters in this function.
Return values:
Get AutoLogCommands - This function returns True as Boolean when the property is active.
Example:
Public Sub test()
Dim isActive As Boolean
isActive = gVMGEngine.AutoLogCommands
End Sub
Get CallBackNames
Returns an array with the names of the actual call backs.
Method:
Public Property Get CallBackNames()
Parameters:
There are no parameters in this function.
Return values:
Get CallBackNames - This function returns a list with the names of the actual call backs in an array as Variant.
Example:
Public Sub test()
Dim names As Variant
names = gVMGEngine.callbackNames
End Sub
Get CanRunAssistants
Returns a Boolean with the value of True if the Case has dynamics support and a valid license to run Full
Dynamics.
Method:
Property Get CanRunAssistants() As Boolean
Parameters:
There are no parameters in this function.
Return values:
Get CanRunAssistants - This function returns True as Boolean if Dynamics Assistants can be run in the case.
Example:
Public Sub test()
Dim CanRun As Boolean
CanRun = gVMGEngine.CanRunAssistants
End Sub
Get CanRunFullDynamics
Returns a Boolean with the value of True if the Case has dynamics support and a valid license to run Full
Dynamics.
Method:
Property Get CanRunFullDynamics() As Boolean
Parameters:
There are no parameters in this function.
Return values:
Get CanRunFullDynamics - This function returns True as Boolean if Full Dynamics can be run in the case.
Example:
Public Sub test()
Dim CanRun As Boolean
CanRun = gVMGEngine.CanRunFullDynamics
End Sub
Get ConfigOpDefbyObjectType
Returns the configuration definition object of the specified unit operation type.
Method:
Property Get ConfigOpDefbyObjectType(objType As String) As ConfigOpDef
Parameters:
objType is the object type Id of the unit operation type desired to get the configuration object form (i.e
Stream.Stream_Material).
Return values:
Get ConfigOpDefbyObjectType - Returns the configuration object as ConfigOpDef.
Example:
Public Sub test()
Dim coolerConfig as ConfigOpDef
Set coolerConfig = gVMGEngine.ConfigOpDefbyObjectType("Heater.Cooler")
End Sub
Get EnableVisibleObjects
Returns a Boolean with the value of True when dialog boxes are allowed to be displayed.
Method:
Public Property Get EnableVisibleObjects() As Boolean
Parameters:
There are no parameters in this function.
Return values:
Get EnableVisibleObjects - Returns the value of the property as Boolean.
Example:
Public Sub test()
Dim areVisObjsEnabled As Boolean
areVisObjsEnabled = gVMGEngine.EnableVisibleObjects
End Sub
Get FlowsheetsList
Returns an array with the flowsheets in the active case.
Method:
Public Property Get FlowsheetsList() As Variant
Parameters:
There are no parameters in this function.
Return values:
Get FlowsheetsList - Returns the list of flowsheets in an array as a Variant.
Example:
Public Sub test()
Dim listArr as Variant
listArr = gVMGEngine.FlowsheetsList
End Sub
Get HasDynamicsSupport
Returns a Boolean with the value of True if the simulation case has dynamics support.
Method:
Public Property Get HasDynamicsSupport() As Boolean
Parameters:
There are no parameters in this function.
Return values:
Get HasDynamicsSupport - This function returns True as Boolean if the case has dynamics support.
Example:
Public Sub test()
Dim HasDynSup as Boolean
HasDynSup = gVMGEngine.HasDynamicsSupport
End Sub
Get IsIntegratorRunning
Returns a Boolean with the value of True if there is an integrator running.
Method:
Public Property Get IsIntegratorRunning() As Boolean
Parameters:
There are no parameters in this function.
Return values:
Get IsIntegratorRunning - Returns the value as Boolean.
Example:
Public Sub test()
Dim intRunning as Boolean
intRunningn = gVMGEngine.IsIntegratorRunning
End Sub
Get IsOnHold
Returns a Boolean with the value of True if the solver is on hold.
Method:
Public Property Get IsOnHold() As Boolean
Parameters:
There are no parameters in this function.
Return values:
Get IsOnHold - Returns the value as Boolean.
Example:
Public Sub test()
Dim isOnHold as Boolean
isOnHold = gVMGEngine.IsOnHold
End Sub
Get PropertyOrderList
Returns an array with the properties list.
Method:
Public Property Get PropertyOrderList()
Parameters:
There are no parameters in this function.
Return values:
PropertyOrderList - Returns the list of properties in an array as a Variant.
Example:
Public Sub test()
Dim props as Variant
props = gVMGEngine.PropertyOrderList
End Sub
Get SolverState
Returns the solver state; 1 running, 0 on hold.
Method:
Public Property Get SolverState() As Long
Parameters:
There are no parameters in this function.
Return values:
Get SolverState - Returns 1 when running, 0 when on hold as Long.
Example:
Public Sub test()
Dim solverState as Long
solverState = gVMGEngine.SolverState
End Sub
Get ThermoAdmin
Returns the Thermo Administrator object as VMGThermoAdmin.
Method:
Public Property Get ThermoAdmin() As VMGThermoAdmin
Parameters:
There are no parameters in this function.
Return values:
ThermoAdmin - Returns the Thermo Administrator as VMGThermoAdmin.
Example:
Public Sub test()
Dim ThermoAdmin As VMGThermoAdmin
Set ThermoAdmin = gVMGEngine.ThermoAdmin
End Sub
Get UnitSystem
Returns the Unit System object as VMGUnitSystem.
Method:
Property Get UnitSystem() As VMGUnitSystem
Parameters:
There are no parameters in this function.
Return values:
UnitSystem - Returns the Unit System as VMGUnitSystem.
Example:
Public Sub test()
Dim UnitsSys As VMGUnitSystem
Set UnitsSys = gVMGEngine.UnitSystem
End Sub
Get UserDataPath
Returns the path of the folder where the user information is stored.
Method:
Public Property Get UserDataPath() As String
Parameters:
There are no parameters in this function.
Return values:
UserDataPath - Returns the user path as String.
Example:
Public Sub test()
Dim userDataPath as String
userDataPath = gVMGEngine.UserDataPath
End Sub
Get UtilLibrary
Returns the utility library object as VMGUtilLibrary.
Method:
Public Property Get UtilLibrary()
Parameters:
There are no parameters in this function.
Return values:
Get UtilLibrary - Returns the Utility Library Object as VMGUtilLibrary.
Example:
Public Sub test()
Dim utilLib as VMGUtilLibrary
Set utilLib = gVMGEngine.UtilLibrary
End Sub
GetCompoundNames
Returns an array with the compound names associated to the Object.
Method:
Public Function GetCompoundNames(obj As VMGObject)
Parameters:
Obj VMGObject associated to the compounds.
Return values:
GetCompoundNames - Returns the compound names in an array as a Variant.
Example:
Public Sub test()
Dim listArr as Variant
listArr = gVMGEngine.FlowsheetsList
End Sub
GetFreeName
Returns a name based on the given name but that is not currently used.
Method:
Public Function GetFreeName(parentPath As String, baseName As String, knownList, Optional forceEnum As
Boolean = True) As String
Parameters:
parentPath String with the parent path, a flowsheet is most commonly passed. The method checks if the chil-
dren unit operations contained have the same name that we want to use. It can be an empty string, if the name
to check is going to be in the knownList.
baseName Name that we want to check.
knownList array as Variant, with the names that we want to compare against.
forceEnum If a number its going to be forced to be appended.
Return values:
GetFreeName - Returns the free name as String.
Example:
Public Sub test()
Dim knownNames As Variant
Dim freeName As String
knownNames = Null '...Empty array
freeName = gVMGEngine.GetFreeName("/", "C1", knownNames, False)
'...Returns "C1" if the name is not there
'...Returns "C11" if the name is there
End Sub
GetHistorian
Returns the historian object.
Method:
Public Function GetHistorian() As VMGHistorian
Parameters:
There are no parameters in this function.
Return values:
GetHistorian - Returns the historian object as VMGHistorian.
Example:
Public Sub test()
Dim Hist as VMGHistorian
Set Hist = gVMGEngine.GetHistorian
End Sub
GetIntegrator
Returns the integrator attached to the flowsheet of the specified path.
Method:
Public Function GetIntegrator(Optional flPath As String = "") As VMGIntegrator
Parameters:
flPath Flowsheet path as string.
Return values:
GetIntegrator - Returns the specified integrator object as VMGIntegrator.
Example:
Public Sub test()
Dim integ as VMGIntegrator
Set integ = gVMGEngine.GetIntegrator("/")
End Sub
GetScheduler
Returns the scheduler of the specified path.
Method:
Public Function GetScheduler(schedPath As String) As VMGScheduler
Parameters:
schedPath Scheduler Path as String.
Return values:
GetScheduler - Returns the specified Scheduler object as VMGScheduler.
Example:
Public Sub test()
Dim scheduler as VMGScheduler
Set scheduler = gVMGEngine.GetScheduler("Sched1")
End Sub
GetVMGVariable
Returns a VMGVariable of the specified path.
Method:
Public Function GetVMGVariable(path As String) As VMGVariable
Parameters:
path VMGVariable path as string.
Return values:
GetVMGVariable - Returns the specified variable object as VMGVariable.
Example:
Public Sub test()
Dim Temp as VMGVariable
Set Temp = gVMGEngine.GetVMGVariable("/C1.Out.T")
End Sub
Go
Starts the solver.
Method:
Public Function Go()
Parameters:
There are no parameters in this function.
Return values:
Go - This function does not return anything.
Example:
Public Sub test()
Call gVMGEngine.Go()
End Sub
hold
Stops the solver.
Method:
Public Function hold()
Parameters:
There are no parameters in this function.
Return values:
hold - This function does not return anything.
Example:
Public Sub test()
Call gVMGEngine.hold()
End Sub
Let AutoLogCommands
Sets the mode for logging the Commands. True when the Commands will be Auto Logged.
Method:
Public Property Let AutoLogCommands(val As Boolean)
Parameters:
val Boolean that specifies if the property value.
Return values:
Let AutoLogCommands - This function does not return anything.
Example:
Public Sub test(value as Boolean)
gVMGEngine.AutoLogCommands = value
End Sub
Let EnableVisibleObjects
Sets the mode for dialog boxes visibility. This is useful when running the engine as a silent entity where the user
is not intended to interact with any windows from the simulator.
Method:
Public Property Let EnableVisibleObjects(vis As Boolean)
Parameters:
Vis Boolean, sets the property value.
Return values:
Let EnableVisibleObjects - This function does not return anything.
Example:
Public Sub test()
gVMGEngine.EnableVisibleObjects = True
End Sub
Let SolverState
Sets the solver state; 1 starts solver, 0 stops solver.
Method:
Public Property Let SolverState(theState As Long)
Parameters:
theState - Property Value as Long.
Return values:
Let SolverState - This function does not return anything.
Example:
Public Sub test()
gVMGEngine.SolverState = 1 '... Starts Solver
End Sub
Let UserDataPath
Sets the path of the folder where the user information is stored.
Method:
Public Property Let UserDataPath(path As String)
Parameters:
Path Applications user folder as String.
Return values:
Let UserDataPath - This function does not return anything.
Example:
Public Sub test()
Dim userDataPath as String
userDataPath = "C:\Users\User_1\AppData\Roaming\VMG"
gVMGEngine.UserDataPath = userDataPath
End Sub
LogCommands
Stores the command line statements in the specified path.
Method:
Public Sub LogCommands(ByVal path As String, Optional append As Boolean = True)
Parameters:
path File path as String.
append Boolean, If True Appends to the existing file, if False overwrites the file.
Return values:
LogCommands - This function does not return anything.
Example:
Public Sub test()
Call gVMGEngine.LogCommands("C:\temp\temp.txt", True)
End Sub
LogOutput
Specifies a file where all the callback messages are going to be saved.
Method:
Public Sub LogOutput(activate As Boolean, filePath As String)
Parameters:
activate activate or deactivate the Logging as Boolean.
filePath File path as String.
Return values:
LogOutput - This function does not return anything.
Example:
Public Sub test()
Call gVMGEngine.Output(True, "C:\temp\CallBackMessages.txt")
End Sub
LogStringToFile
Logs a string in a specified file.
Method:
Public Sub LogStringToFile(ByVal txt As String, Optional fileName As String = "C:\temp\temp.txt", Optional
mode As String = "a", Optional addCarriageReturn As Boolean = True, Optional onlyInDebugMode As
Boolean = True)
Parameters:
txt text to be written as String.
fileName File path as String.
mode a for append in file, w for writing to a new file.
addCarriageReturn If after line, auto add a Carriage Return, value as Boolean.
onlyInDebugMode Write line only when debug mode is active, value as Boolean.
Return values:
LogStringToFile - This function does not return anything.
Example:
Public Sub test()
Call gVMGEngine. LogStringToFile ("Start Test", "C:\temp\LogFile.txt")
End Sub
ReadScript
Reads and executes a script file; useful for initialization values at different conditions, run one script for one scen-
ario then change to another.
Method:
Public Sub ReadScript(path As String)
Parameters:
Path File path as String.
Return values:
ReadScript - This function does not return anything.
Example:
Public Sub test()
Call gVMGEngine.ReadScript("C:\temp\InitWinterConditions.txt")
End Sub
RecallFile
Recalls the specified simulation case.
Method:
Public Function RecallFile(ByVal fileName As String) As Long
Parameters:
fileName File path as String.
Return values:
RecallFile - Returns 0 as Long if there were no errors during recalling.
Example:
Public Sub test()
Dim RetVal as Long
RetVal = gVMGEngine.RecallFile("C:\temp\Case1.vmp")
End Sub
RemoveDynamicsSupport
Removes dynamics support from the simulation case.
Method:
Public Function RemoveDynamicsSupport() As Long
Parameters:
There are no parameters in this function.
Return values:
RemoveDynamicsSupport - Returns 0 as Long if there were no errors.
Example:
Public Sub test()
Call gVMGEngine.RemoveDynamicsSupport()
End Sub
RenderMessage
Send a message to the simulation.
Method:
Public Function RenderMessage(msg As Variant, args As Variant) As Variant
Parameters:
msg - message as Variant.
args arguments as Variant.
Return values:
RenderMessage - Returns 0 as Variant if there were no errors.
Example:
Public Sub test()
Dim msg as String
Dim args as Variant
Dim renderMsg as Variant
msg = "CMDFinishedRecall2"
args = Array("C:\VMGSimCases\Plant2.vmp", "C:\VMGsimTempDir")
renderedMsg = gVMGEngine.RenderMessage(CStr(msg), args)
End Sub
ReturnValidName
Returns a valid name based on the given name; removes not supported characters.
Method:
Public Function ReturnValidName(name As String) As String
Parameters:
name proposed name as String.
Return values:
ReturnValidName - Returns a valid name as String.
Example:
Public Sub test()
Dim validName as String
validName = gVMGEngine.ReturnValidName("Super Cooler")
'...Returns "Super_Cooler"
End Sub
RootFlowsheet
Returns the Main Flowsheet.
Method:
Public Property Get RootFlowsheet() As VMGOpFlowsheet
Parameters:
There are no parameters in this function.
Return values:
RootFlowsheet - Returns the Main Flowsheet as VMGOpFlowsheet.
Example:
Public Sub test()
Dim rootFlowsheet as VMGOpFlowsheet
Set rootFlowsheet = gVMGEngine.RootFlowsheet
End Sub
SaveDynSnapshot
Stores the dynamics state of the flowsheet specified by the path.
Method:
Public Function SaveDynSnapshot(path As String)
Parameters:
Path Flowsheet path as String.
Return values:
SaveDynSnapshot - This function does not return anything.
Example:
Public Sub test()
Call gVMGEngine.SaveDynSnapshot("/")
End Sub
SaveFile
Saves the simulation case with the given name.
Method:
Public Function SaveFile(fileName) As Long
Parameters:
fileName File path as String.
Return values:
SaveFile - Returns 0 as Long if there were no errors.
Example:
Public Sub test()
Call gVMGEngine.SaveFile("C:\temp\Case1.vmp")
End Sub
SetCallBackCOMObject
Sets a call back object and prepares it to receive messages.
Method:
Public Sub SetCallBackCOMObject(obj As Object, name As String, Optional idx As Long = -1)
Parameters:
obj user Call back Object ready to receive messages as Object.
name CallBack name as String.
idx- Callback index in callbacks collection.
Return values:
SetCallBackCOMObject - This function does not return anything.
Example:
Public Sub test()
'... Note VMGCallBack its a Class made by the user
Dim gCallBack as VMGCallBack
'... Create and set the callback
Set gCallBack = New VMGCallBack
Call gVMGEngine.SetCallBackComObject(gCallBack, "CB")
End Sub
'----------------------------------------------------------------------------------
-----
' Purpose : This function is called by the VMG engine to notify of any changes that
happen to the simulation.
' The developer can implement an action based on the msg sent in this method.
' This implementation contains basic handling of messages
'
' Arguments:
' msg - Key that maps to a specific action carried out by the simulator
' args - Extra information used to describe msg. args can be Null, a string or an
array of values
' sMsgType - Defines the type of message. It can have a value of "Info", "Warning"
or "Error"
'----------------------------------------------------------------------------------
-----
Dim renderedMsg As String
Dim ignStr As String
'...for example...
' If sMsgType = ERR_MSG Then
' Call MsgBox(renderedMsg, vbCritical, "Error in VMGEngine")
' End If
'
' If msg = SOLVED_SIM Then
' Call MethodToRefreshValues
' End If
'
Exit Function
localErr:
'... No error handling for now
End Function
End Sub
Solve
Initializes the solver sequence.
Method:
Public Function Solve()
Parameters:
There are no parameters in this function.
Return values:
Solve - This function does not return anything.
Example:
Public Sub test()
Call gVMGEngine.Solve()
End Sub
VMGObject
VMGObject
VMGSim base object. Almost every object in the simulation implements this interface.
Public Members
<eVMGActiveEngine> ActiveEngine()
Returns the ActiveEngine value. 0 for steady state and 2 for dynamics.
DeleteVMGObjectByName(<String> name)
Removes the specified VMGObject. The VMGObject being deleted must be a child of the current VMGObject.
<String> DisplayName()
Returns the Display Name as seen by the user.
<Variant> GetContainedObjects()
Returns the contained items within the VMGObject. Examples of returned items can be properties, unit oper-
ations, parameters, or ports.
<String> GetName()
Returns a String containing the name of the VMGObject.
<Variant> GetObjectTypeID()
Returns a unique identifier for the type of object.
<VMGObject> GetParent()
Returns the immediate Parent of the VMGObject
<String> GetPath()
Returns the path of the VMGobject as a String.
<Variant> GetVMGObjectNames()
Returns the names of the objects contained inside of the VMGObject.
<Boolean> HasDynSupport()
Returns a Boolean with a value of True if the VMGObject has Dynamics support.
<Boolean> HasSSSupport()
Returns a Boolean with a value of True if the VMGObject has Steady State support.
<Boolean> IsValidIface()
Checks if the object behind the interface is still alive.
<VMGThermoCase> ThermoCase()
Returns the Thermo Case associated the VMGObject.
DeleteVMGObjectByName
Removes the specified VMGObject. The VMGObject being deleted must be a child of the current VMGObject.
Method:
Public Sub DeleteVMGObjectByName(name As String).
Parameters:
Name This is a String that specifies which object will be deleted. The name cannot be a path.
Return values:
This function does not return anything.
Example:
Public Sub test(vOb As VMGObject)
Dim name as String
name = S1
Call vOb.DeleteVMGObjectByName(name)
End Sub
Get ActiveEngine
Returns the type of active engine behind the VMGObject.
Method:
Public Property Get ActiveEngine() As eVMGActiveEngine.
Parameters:
There are no parameters in this function.
Return values:
This function returns the Active Engine value of the object. The value will be eSS_ENGINE (0) if the VMGOb-
ject is a Steady State Object and the value will be eDYN_ENGINE (2) if the VMGObject is a Dynamics Object.
Example:
Public Sub test(vOb As VMGObject)
Dim vActEng As eVMGActiveEngine
vActEng = vOb.ActiveEngine()
End Sub
Get DisplayName
Returns the Display Name of the object.
Method:
Public Property Get DisplayName() As String.
Parameters:
There are no parameters in this function.
Return values:
DisplayName This function returns the display name of the VMGObject.
Example:
Public Sub test(vOb As VMGObject)
Dim name As String
name = vOb.DisplayName()
End Sub
Get IsValidIface
Checks if the object behind the interface is still alive.
Method:
Public Property Get IsValidIface() As Boolean.
Parameters:
There are no parameters in this function.
Return values:
IsValidIface This function returns a Boolean value for if the object still exists. This enables us to check if the
object behind the interface has not been removed.
Example:
Public Sub test(vOb As VMGObject)
Dim valid As Boolean
valid = vOb.IsValidIface
If valid Then
Delete the object
Dim parent as VMGObject
Set parent = vObj.GetParent()
Call parent.DeleteVMGObjectByName(vOb.GetName())
vOb should not be valid anymore (assuming it got deleted)
valid = vOb.IsValidIface
End If
End Sub
Get ParentFlowsheet
Returns the immediate Flowsheet that the object belongs to.
Method:
Public Property Get ParentFlowsheet(Optional inclSubFlsht As Boolean = True) As VMGUnitOperation.
Parameters:
inclSubFlsht If the Boolean is true, then it will include the sub flowsheet in the search, if it is false, then it will
not include the sub flowsheet in the search. By default, the Boolean value for this is True.
Return values:
ParentFlowsheet This function returns the parent flowsheet of the current VMGObject specified by the
inclSubFlsht boolean.
Example:
Public Sub test(vOb As VMGObject)
Dim inclSubFlsht As Boolean
Dim vUnit As VMGUnitOperation
inclSubFlsht = True
Get ThermoCase
Returns the Thermo Case associated with the VMGObject. A thermodynamic case is usually directly asso-
ciated to a flowsheet and it is used by all the children objects. This property traverses up the hierarchy of objects
until it finds an object that is directly bound to a Thermo Case.
Method:
Public Property Get ThermoCase() As VMGThermoCase.
Parameters:
There are no parameters in this function
Return values:
ThermoCase This function will return the ThermoCase of the VMGObject as defined by the user.
Example:
Public Sub test(vOb As VMGObject)
Dim vOb As VMGObject
Dim thermal As VMGThermoCase
GetContainedObjects
Returns the items contained within the VMGObject. Examples of returned items can be properties, unit oper-
ations, parameters, or ports.
Method:
Public Function GetContainedObjects().
Parameters:
There are no parameters in this function.
Return values:
GetContainedObjects This function returns the items that are contained within the VMGObject.
Example:
Public Sub test(vOb As VMGObject)
Dim vContained
vContained = vOb.GetContainedObjects
End Sub
GetInfoValue
An auxiliary method to retrieve a tag value previously set by SetInfoValue.
Method:
Public Function GetInfoValue(ByVal key As String).
Parameters:
Key Is the tag that was set with SetInfoValue at an earlier time
Return values:
GetInfoValue This function returns the value of the tag as specified by the key parameter
Example:
Public Sub test(vOb as VMGObject)
Dim key As String
Dim value
key = ExampleTag
value = vOb.GetInfoValue(key)
End Sub
GetName
Returns a String containing the name of the VMGObject.
Method:
Public Function GetName() As String.
Parameters:
There are no parameters in this function.
Return values:
GetName The VMGObject name is returned when the function is called.
Example:
Public Sub test(vOb As VMGObject)
Dim name As String
name = vOb.GetName()
End Sub
GetObjectTypeID
Returns a unique identifier for the type of object contained in the VMGObject. For example, the ID of a heater
unit operation is Heater.Heater.
Method:
Public Function GetObjectTypeID().
Parameters:
There are no parameters in this function.
Return values:
GetObjectTypeID The VMGObject Type ID is returned when the function is called.
Example:
Public Sub test(vOb As VMGObject)
Dim obID
obID = vOb.GetObjectTypeID()
End Sub
GetParent
Returns the immediate Parent of the VMGObject. For example, the parent of a unit operation is a flowsheet.
Method:
Public Function GetParent() As VMGObject.
Parameters:
There are no parameters in this function
Return values:
GetParent The function returns a VMGObject that is the parent of the current VMGObject.
Example:
Public Sub test(vOb As VMGObject)
Dim par As VMGObject
GetPath
Returns a String that contains the path of the VMGObject.
Method:
Public Function GetPath() As String.
Parameters:
There are no parameters in this function
Return values:
GetPath The VMGObject Path is returned when the function is called. For example, the path of the DeltaP
variable of a heater called H1 may be /H1.DeltaP.
Example:
Public Sub test(vOb As VMGObject)
Dim path As String
path = vOb.GetPath()
End Sub
GetVMGObject
Return as VMGObject based in the name.
Method:
Public Function GetVMGObject(name As String) As VMGObject.
Parameters:
Name The name is a String value passed in to search for the VMGObject. The name can be used in three dif-
ferent ways:
l Child Name: This means that the name represents an immediate child of the VMGObject. Example: Actual
VMGObject Path: /, name is S1, the function will return an object called S1.
l Relative Path: This means that the name can be the path of any VMGObject that is contained within the
current VMGObject. Example: Actual VMGObject Path: /, name is FS1.S2, the return object will be
an object called S2 contained inside of an object called FS1 which in turn is contained inside of the
root object /.
l Absolute Path: This means that the name is a full path of where the VMGObject being specified is.
Using this method, it is possible to access any VMGObject outside of the current VMGObject. Example:
Actual VMGObject Path: /S1, name is /S2, the function will return a object called S2 contained
inside of the root object called /.
Return values:
GetVMGObject This function returns the VMGObject at the specified path or name.
Example:
Example # 1 name = child name
Public Sub test()
Dim vStream As VMGObject
Dim vFlowSheet As VMGObject
Dim name as string
name =S1
Set vFlowSheet = gVMGSimIface.GetVMGObject("/")
Set vStream = vFlowSheet.GetVMGObject(name)
End Sub
name =In.T
Set vStream = gVMGSimIface.GetVMGObject("/S1")
Set vTemperature = vStream.GetVMGObject(name)
End Sub
name =/S2.In.T
Set vStream = gVMGSimIface.GetVMGObject("/S1")
Set vTemperature = vStream.GetVMGObject(name)
End Sub
GetVMGObjectNames
Returns the names of the objects contained in the VMGObject.GetVMGObjectNames
Method:
Public Function GetVMGObjectNames().
Parameters:
There are no parameters in this function.
Return values:
GetVMGObjectNames This function returns the names of the objects contained in the VMGObject.
Example:
Public Sub test(vOb As VMGObject)
Dim Names
Names = vOb.GetVMGObjectNames()
End Sub
HasDynSupport
Indicates whether the VMGObject has Dynamics support or not.
Method:
Public Function HasDynSupport() As Boolean.
Parameters:
There are no parameters in this function.
Return values:
HasDynSupport This function returns a Boolean. The value is True if the VMGObject has Dynamics sup-
port.
Example:
Public Sub test(vOb As VMGObject)
Dim support As Boolean
support = vOb.HasDynSupport()
End Sub
HasSSSupport
Indicates whether the VMGObject has Steady State support or not.
Method:
Public Function HasSSSupport() As Boolean.
Parameters:
There are no parameters in this function.
Return values:
HasSSSupport This function returns a Boolean. The value is True if the VMGObject has Steady State sup-
port.
Example:
Public Sub test(vOb As VMGObject)
Dim support As Boolean
support = vOb.HasSSSupport()
End Sub
SetInfoValue
An auxiliary method to set tags to the actual VMGObject.
Method:
Public Sub SetInfoValue(ByVal key As String, ByVal value, Optional silent As Boolean = True).
Parameters:
Key Is a string that will be the name of the tag that the user will set. This tag should not contain spaces.
Value This is the value that will be set to the VMGObject that the function will match with Key.
Silent This is an optional Boolean parameter to indicate if this action should be sent to the log file. By default
the Boolean value is True (does not get logged).
Return values:
This function does not return anything.
Example:
Public Sub test(vOb As VMGObject)
Dim key As String
Dim value As String
Dim silent As Boolean
key = ExampleTag
value = 4
silent = True
Call vOb.SetInfoValue(key,value,silent)
End Sub
VMG Objects
VMGObjects
This object contains a list of objects that implement the VMGObject interface. For example, a list of variables or
a list of unit operations.
Public Members
<Long> Get Count()
Returns the number of objects.
Get ContentsAsArray
Returns the objects as an array.
Method:
Public Property Get ContentsAsArray()
Parameters:
There are no parameters in this function.
Return values:
ContentsAsArray Array of objects that implement the VMGObject interface.
Example:
Public Sub test(vOb As VMGObjects)
Dim objs
objs = vOb.ContentsArArray()
End Sub
Get Count
Returns the number of objects.
Method:
Public Property Get Count() As Long
Parameters:
There are no parameters in this function.
Return values:
Count Number of objects inside of the list.
Example:
Public Sub test(vOb As VMGObjects)
Dim result As Long
result = vOb.Count
End Sub
Get Names
Returns an array with the names of the objects.
Method:
Public Property Get Names()
Parameters:
There are no parameters in this function.
Return values:
Names Returns an array of strings with the names of the objects.
Example:
Public Sub test(vOb As VMGObjects)
Dim names
names = vOb.Names()
End Sub
Item
Returns the object at the specified index (base 0) or with the name provided.
Method:
Public Property Get Item(idxOrName) As VMGObject
Parameters:
idxOrName Index (base 0) or name of the object. For example, if the list contains two objects called S1 and
S2 respectively, the user can request the object S2 by setting idxOrName to either 1 or S2.
Return values:
Item Returns the VMGObject found in the list.
Example:
Public Sub test(vOb As VMGObjects)
Dim theObj as VMGObject
VMGOpFlowsheets
VMGOpFlowsheet
This interface is implemented by Flowsheets or SubFowsheets. It is primarily used to access, create and
remove unit operations. The main flowsheet is also known as the root flowsheet and it is available at all times.
The root flowsheet can be accessed like this,
Set vFlowsheet = gVMGEngine.RootFlowsheet
Or
Set vFlowsheet = gVMGEngine.GetVMGObject(/)
<VMGCompTrainManager> GetCompressorTrainManager()
Returns the compressor train manager for the flowsheet (dynamics only).
<VMGObjects> GetSigStreams()
Returns a list of signal streams that belongs to a flowsheet. This list does not include streams that belong to nes-
ted flowsheets.
InitFromSteadyState()
Initializes the dynamics engine from values in the steady state engine (dynamics only).
TakeSnapshot()
Takes a snapshot of the current values in the dynamics engine.
DeleteUnitOperation(<String> name)
Deletes a unit operation.
AddEnergyStream
Adds a energy stream to the flowsheet.
Method:
Public Function AddEnergyStream(name As String) As VMGOpStreamEnergy
Parameters:
name Name of the stream. The name cannot contain spaces ( ), commas(,) or periods (.). Duplicate
names are not allowed.
Return values:
AddEnergyStream The new stream created.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Dim vSt as VMGOpStreamEnergy
Set vSt = vFlowsheet.AddEnergyStream(S1)
End Sub
AddMaterialStream
Adds a material stream to the flowsheet.
Method:
Public Function AddMaterialStream(name As String) As VMGOPStream
Parameters:
name Name of the stream. The name cannot contain spaces ( ), commas(,) or periods (.). Duplicate
names are not allowed.
Return values:
AddMaterialStream The new stream created.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Dim vSt as VMGOpStream
Set vSt = vFlowsheet.AddMaterialStream(S1)
End Sub
AddSignalStream
Adds a signal stream to the flowsheet.
Method:
Public Function AddSignalStream(name As String) As VMGOpStreamSignal
Parameters:
name Name of the stream. The name cannot contain spaces ( ), commas(,) or periods (.). Duplicate
names are not allowed.
Return values:
AddSignalStream The new stream created.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Dim vSt as VMGOpStreamSignal
Set vSt = vFlowsheet.AddSignalStream(S1)
End Sub
AddUnitOp
Adds a unit operation to the flowsheet.
Method:
Public Function AddUnitOp(OpType As eVMGUnitOpTypes, ByVal name As String, Optional initScript As
String = "") As VMGUnitOperation
Parameters:
OpType Enumeration that defined the unit operation type.
name Name of the unit operation. The name cannot contain spaces ( ), commas(,) or periods (.). Duplic-
ate names are not allowed.
initScript Initialization script to be run with the unit operation. This script can be used to define default values.
Return values:
AddUnitOp The new unit operation created.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Dim vOp1 as VMGUnitOperation
Dim vOp2 as VMGUnitOperation
AddUnitOpByTypeID
Adds a unit operation to the flowsheet by defining the unit operation type as a string.
Method:
Public Function AddUnitOpByTypeID(TypeId As String, name As String, Optional initScript As String = "") As
VMGUnitOperation
Parameters:
TypeId Internal type name of the unit operation. For example, Heater.Heater corresponds to a heater.
name Name of the unit operation. The name cannot contain spaces ( ), commas(,) or periods (.). Duplic-
ate names are not allowed.
initScript - Initialization script to be run with the unit operation. This script can be used to define default values.
Return values:
AddUnitOpByTypeID The new unit operation created.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Dim vOp1 as VMGUnitOperation
Dim vOp2 as VMGUnitOperation
ClearShapshot
Clears a snapshot from memory.
Method:
Public Sub ClearShapshot(Optional atTime As Double = 0#)
Parameters:
atTime - Integrator time associated with the snapshot.
Return values:
This function does not return anything.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Call vFlowsheet.ClearSnapshot()
End Sub
CreateFlowsheetInside
Creates a flowsheet inside of this flowsheet.
Method:
Public Function CreateFlowsheetInside(flowSheetName As String) As VMGOpFlowsheet
Parameters:
flowSheetName - Name of the stream. The name cannot contain spaces ( ), commas(,) or periods (.).
Duplicate names are not allowed.
Return values:
CreateFlowsheetInside The flowsheet getting created.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Dim vFl as VMGOpFlowsheet
Set vFl = vFlowsheet.CreateFlowsheetInside(SF1)
End Sub
DeleteUnitOperation
Deletes a unit operation. It can also be a stream.
Method:
Public Sub DeleteUnitOperation(name As String)
Parameters:
name Name of the unit operation to delete.
Return values:
This function does not return anything.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Call vFlowsheet.DeleteUnitOperation(S1)
End Sub
Get AssistantType
Returns the type of dynamics assistant being run if available (Depressuring or Compressor Train).
Method:
Public Property Get AssistantType() As String
Parameters:
There are no parameters in this function.
Return values:
AssistantType It can return either "Compressor Train" or "Depressuring System".
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Dim aType as String
aType = vFlowsheet.AssistantType
End Sub
Get Integrator
Returns the integrator associated to the flowsheet (dynamics only).
Method:
Public Property Get Integrator() As VMGIntegrator
Parameters:
There are no parameters in this function.
Return values:
Integrator Integrator that belongs to the flowsheet.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Dim vObj as VMGIntegrator
Set vObj = vFlowsheet.Integrator
End Sub
Get UnitOpTypesInUse
Returns an array of strings with the unit operation types being used.
Method:
Public Property Get UnitOpTypesInUse(Optional inclFlshts As Boolean = False, Optional sortList As Boolean =
False, Optional filterOut As String = "")
Parameters:
inclFlshts It traverses the nested flowsheets if this parameter is True.
sortList It sorts the return value alphabetically if this parameter is True.
filterOut The unit operations of this type are not included in the return value.
Return values:
UnitOpTypesInUse - An array with the unit operation types being used. For example, it will return
Stream.Stream_Material, Heater.Heater and Heater.HeatExchangerUA if the flowsheet only contained
material streams, heaters and heat exchangers.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Dim opTypes
opTypes = vFlowsheet.UnitOpTypesInUse
End Sub
GetCompressorTrainManager
Returns the compressor train manager for the flowsheet (dynamics only).
Method:
Public Function GetCompressorTrainManager() As VMGCompTrainManager
Parameters:
There are no parameters in this function.
Return values:
GetCompressorTrainManager The compressor train manager. The dynamics engine must be enabled.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Dim vObj as VMGCompTrainManager
Set vObj = vFlowsheet.GetCompressorTrainManager()
End Sub
GetContainedUnitOps
Returns a list of unit operations that belong to a flowsheet. The user can provide an optional parameter to
define a specific type of unit operation.
Method:
Public Function GetContainedUnitOps(Optional filter As String = "") As VMGObjects
Parameters:
filter - This function returns all the unit operations if filter is an empty string otherwise it returns the unit oper-
ations of a specific type.
Return values:
GetContainedUnitOps An instance of VMGObjects with the list of objects.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Dim vObjs as VMGObjects
All unit operations
Set vObjs = vFlowsheet.GetContainedUnitOps()
Heaters
Set vObjs = vFlowsheet.GetContainedUnitOps(Heater.Heater)
End Sub
GetDepressuringSystemManager
Returns the depressuring system managerGetDepressuringSystemManager for the flowsheet (dynamics
only).
Returns the depressuring system manager for the flowsheet (dynamics only).
Method:
Public Function GetDepressuringSystemManager() As VMGDepSysManager
Parameters:
There are no parameters in this function.
Return values:
GetDepressuringSystemManager The depressuring system manager. The dynamics engine must be
enabled.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Dim vObj as VMGDepSysManager
Set vObj = vFlowsheet.GetDepressuringSystemManager()
End Sub
GetEneStreams
Returns a list of energy streams that belongs to a flowsheet. This list does not include streams that belong to
nested flowsheets.
Method:
Public Function GetEneStreams() As VMGObjects
Parameters:
There are no parameters in this function.
Return values:
GetEneStreams An instance of VMGObjects with the list of objects.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Dim vObjs as VMGObjects
Set vObjs = vFlowsheet.GetEneStreams()
End Sub
GetFlowsheets
Returns a list of flowsheets that belongs to a flowsheet. This list does not include flowsheets that belong to nes-
ted flowsheets.
Method:
Public Function GetFlowsheets() As VMGObjects
Parameters:
There are no parameters in this function.
Return values:
GetFlowsheets An instance of VMGObjects with the list of objects.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Dim vObjs as VMGObjects
Set vObjs = vFlowsheet.GetFlowsheets()
End Sub
GetMatStreams
Returns a list of material streams that belongs to a flowsheet. This list does not include streams that belong to
nested flowsheets.
Method:
Public Function GetMatStreams() As VMGObjects
Parameters:
There are no parameters in this function.
Return values:
GetMatStreams An instance of VMGObjects with the list of objects.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Dim vObjs as VMGObjects
Set vObjs = vFlowsheet.GetMatStreams()
End Sub
GetSigStreams
Returns a list of signal streams that belongs to a flowsheet. This list does not include streams that belong to nes-
ted flowsheets.
Method:
Public Function GetSigStreams() As VMGObjects
Parameters:
There are no parameters in this function.
Return values:
GetSigStreams An instance of VMGObjects with the list of objects.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Dim vObjs as VMGObjects
Set vObjs = vFlowsheet.GetSigStreams()
End Sub
GetStream
Returns a stream with a specified name.
Method:
Public Function GetStream(name As String) As VMGUnitOperation
Parameters:
name Name of the stream.
Return values:
GetStream The stream being returned.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Dim vSt as VMGUnitOperation
Set vSt = vFlowsheet.GetStream(S1)
End Sub
GetUnitOp
Returns a unit operation with a specified name. It can also be a stream.
Method:
Public Function GetUnitOp(name As String) As VMGUnitOperation
Parameters:
name Name of the unit operation.
Return values:
GetUnitOp The unit operation being returned.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Dim vOp as VMGUnitOperation
Set vOp = vFlowsheet.GetUnitOp(C1)
End Sub
GetUnitOps
Returns a list of unit operations that belongs to a flowsheet. The user can provide an optional parameter to
define a specific type of unit operation.
Method:
Public Function GetUnitOps(Optional OpType As eVMGUnitOpTypes = -1) As VMGObjects
Parameters:
OpType - This function returns all the unit operations if OpType is -1, otherwise it returns the unit operations of
a specific type.
Return values:
GetUnitOps An instance of VMGObjects with the list of objects.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Dim vObjs as VMGObjects
All unit operations
Set vObjs = vFlowsheet.GetUnitOps()
Heaters
Set vObjs = vFlowsheet.GetUnitOps(eHeater)
End Sub
HasSnaphot
Returns a Boolean with a value of True if there is a snapshot of the dynamics engine available. Snapshots may
be deleted automatically if the topology of the simulation changes (e.g. adding a unit operation).
Method:
Public Function HasSnaphot(Optional atTime As Double = 0#) As Boolean
Parameters:
atTime Integrator time associated with the snapshot.
Return values:
HasSnaphot - Returns true if the snapshot is available.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Dim hasIt as Boolean
hasIt = vFlowsheet.HasSnapshot()
End Sub
InitFromSteadyState
Initializes the dynamics engine from values in the steady state engine (dynamics only).
Method:
Public Sub InitFromSteadyState()
Parameters:
There are no parameters in this function.
Return values:
This function does not return anything.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Call VFlowsheet.InitFromSteadyState
End Sub
LoadShapshot
Resets the state of the dynamics engine based on a snapshot taken previously. Snapshots are cleared from
memory if the topology of the simulation changes (e.g. removing unit operations).
Method:
Public Sub LoadShapshot(Optional atTime As Double = 0#)
Parameters:
atTime Integrator times that should be recovered.
Return values:
This function does not return anything.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Call vFlowsheet.LoadSnapshot()
End Sub
TakeSnapshot
Takes a snapshot of the current values in the dynamics engine. The snapshot is associated with the current
time of the integrator. This is commonly used before the integrator is run in order to be able to reset the dynam-
ics engine to its initial values.
Method:
Public Sub TakeSnapshot()
Parameters:
There are no parameters in this function.
Return values:
This function does not return anything.
Example:
Public Sub test(vFlowsheet as VMGOpFlowsheet)
Call vFlowsheet.TakeSnapshot()
End Sub
VMGPortMaterial
VMGPortMaterial
Implements the VMGObject and VMGPort interfaces. This object is implemented by the material ports from the
unit operations.
Public Members
<Variant> GetCompositionValues(<Boolean> Optional internalUnits Default value
= False)
This function returns an array with the values of the molar composition. By default it returns the values in the act-
ive unit set or it may return them in internal units (i.e. fractions that add up to 1.0).
<Variant> GetMoleWtPerCmp()
This function returns the molecular weight per component.
<Variant> GetCompoundNames()
This function returns the compound names.
<Variant> GetStdMolVolPerCmp()
This function returns the standard molar volume per component.
<Variant> GetCompositionStatus()
This function returns the composition status (e.g. specification = 2, calculated = 4).
<VMGVariable>Get Cp()
This function returns property Cp.
<VMGVariable>Get MW()
This function returns property MW.
<VMGVariable> StdLiqDen()
This function returns property Std Liquid Density.
<VMGObject> GetConnectedOil()
This function returns the connected assay or blend object.
<String> GetConnectedOilPath()
This function returns the path of the connected assay or blend object.
Get Cp
This function returns property Cp.
Method:
Public Property Get Cp() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get Cp This function returns property Cp.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get Cv
This function returns property Cv.
Method:
Public Property Get Cv() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get Cv This function returns property Cv.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get Fraction
This function returns property Mole Fraction.
Method:
Public Property Get Fraction() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get Fraction This function returns property Fraction.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get H
This function returns property Enthalpy.
Method:
Public Property Get H() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get H This function returns property H.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get IsConnToOil
Returns True if the stream is connected to an oil (assay or blend).
Method:
Public Property Get IsConnToOil() As Boolean
Parameters:
This function does not require parameters.
Return values:
Get IsConnToOil A return value of True means that the stream obtains its composition from an Assay or a
Blend.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As Boolean
Get MassDensity
This function returns property Mass Density.
Method:
Public Property Get MassDensity() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get MassDensity This function returns property MassDensity.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get MassFlow
This function returns property Mass Flow.
Method:
Public Property Get MassFlow() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get MassFlow This function returns property MassFlow.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get MassFlows
This function returns property Mass Flows.
Method:
Public Property Get MassFlows() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get MassFlows This function returns property MassFlows.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get MassFrac
This function returns property Mass Fraction.
Method:
Public Property Get MassFrac() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get MassFrac This function returns property MassFrac.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get MolarVolume
This function returns property Molar Volume.
Method:
Public Property Get MolarVolume() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get MolarVolume This function returns property MolarVolume.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get MoleFlow
This function returns property Molar Flow.
Method:
Public Property Get MoleFlow() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get MoleFlow This function returns property MoleFlow.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get MoleFlows
This function returns property Mole Flows.
Method:
Public Property Get MoleFlows() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get MoleFlows This function returns property MoleFlows.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get MW
This function returns property MW.
Method:
Public Property Get MW() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get MW This function returns property MW.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get P
This function returns property Pressure.
Method:
Public Property Get P() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get P This function returns property P.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get Q
This function returns property Energy Flow.
Method:
Public Property Get Q() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get Q This function returns property Q.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get RenderFlashResults2
This function returns an array with rendered information of the equilibrium values for all the phases.
Method:
Public Function RenderFlashResults2(propNames, fracNames)
Parameters:
propNames Array of strings with the property names being requested (e.g. Array(T, P, MoleFlow) ). A
default property list is returned if propNames is Null.
fracNames Array of strings with the names of the compositional properties being requested. The available
properties are Fraction, MassFraction, StdVolFraction, MoleFlows, MassFlows,
StdLiqVolumeFlows. Only mole fraction is returned if fracNames is Null.
Return values:
Get RenderFlashResults2 The array of information in the return value contains physical property information
for the phases in equilibrium including unit names and variable names.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Dim propNames
Dim fracNames
Default contents
Set result = vPort.RenderFlashResults2(Null, Null)
Specify the return values
propNames = Array(T, P)
fracNames = Array(MassFraction, MoleFlows)
Set result = vPort.RenderFlashResults2(propNames, fracNames)
End Sub
Get S
This function returns property Entropy.
Method:
Public Property Get S() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get S This function returns property S.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get StdGasVolFlow
This function returns property Std Gas Volume Flow.
Method:
Public Property Get StdGasVolFlow() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get StdGasVolFlow This function returns property StdGasVolFlow.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get StdLiqDen
This function returns property Std Liquid Density.
Method:
Public Property Get StdLiqDen() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get StdLiqDen This function returns property StdLiqDen.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get StdLiqVolFlow
This function returns property Std Liq Volume Flow.
Method:
Public Property Get StdLiqVolFlow() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get StdLiqVolFlow This function returns property StdLiqVolFlow.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get StdLiqVolFlows
This function returns property Std Liq Volume Flows.
Method:
Public Property Get StdLiqVolFlows() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get StdLiqVolFlows This function returns property StdLiqVolFlows.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get StdVolFrac
This function returns property Std Volume Fraction.
Method:
Public Property Get StdVolFrac() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get StdVolFrac This function returns property StdVolFrac.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get SurfaceTension
This function returns property Surface Tension.
Method:
Public Property Get SurfaceTension() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get SurfaceTension This function returns property SurfaceTension.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get T
This function returns property Temperature.
Method:
Public Property Get T() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get T This function returns property T.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get ThermoConductivity
This function returns property Thermal Conductivity.
Method:
Public Property Get ThermoConductivity() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get ThermoConductivity This function returns property ThermoConductivity.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get VapFrac
This function returns property Vapor Fraction (mole basis).
Method:
Public Property Get VapFrac() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get VapFrac This function returns property VapFrac.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get Viscosity
This function returns property Viscosity.
Method:
Public Property Get Viscosity() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get Viscosity This function returns property Viscosity.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get VolFlow
This function returns property Actual Volume Flow.
Method:
Public Property Get VolFlow() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get VolFlow This function returns property VolFlow.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
Get ZFactor
This function returns property ZFactor.
Method:
Public Property Get ZFactor() As VMGVariable
Parameters:
This function does not require parameters.
Return values:
Get ZFactor This function returns property ZFactor.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGVariable
GetCompositionStatus
This function returns the composition status (e.g. specification = 2, calculated = 4).
Method:
Public Function GetCompositionStatus()
Parameters:
This function does not require parameters.
Return values:
GetCompositionStatus This function returns the composition status.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As Variant
result = vPort.GetCompositionStatus
End Sub
GetCompositionValues
This function returns an array with the values of the molar composition. By default it returns the values in the act-
ive unit set or it may return them in internal units (i.e. fractions that add up to 1.0).
Method:
Public Function GetCompositionValues(Optional internalUnits As Boolean = False)
Parameters:
interalUnits A Boolean to use internal units
Return values:
GetCompositionValues This function returns the composition values.
Example:
Public Sub test(vPort as VMGPortMaterial)
End Sub
GetCompoundNames
This function returns the compound names.
Method:
Public Function GetCompoundNames()
Parameters:
This function does not require parameters.
Return values:
GetCompoundNames This function returns the compound names.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As Variant
result = vPort.GetCompoundNames
End Sub
GetConnectedOil
This function returns the connected assay or blend object.
Method:
Public Function GetConnectedOil() As VMGObject
Parameters:
This function does not require parameters.
Return values:
GetConnectedOil An instance of a VMGAssay or VMGBlend if the port is connected to an oil
Example:GetConnectedOil
Public Sub test(vPort as VMGPortMaterial)
Dim result As VMGObject
GetConnectedOilPath
This function returns the path of the connected assay or blend object.
Method:
Public Function GetConnectedOilPath() As String
Parameters:
This function does not require parameters.
Return values:
GetConnectedOilPath This function returns the path of the assay or blend if the port is connected to an oil.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As String
result = vPort.GetConnectedOilPath()
End Sub
GetMassFractionValues
This function returns an array with the values of the mass composition. By default it returns the values in the act-
ive unit set or it may return them in internal units (i.e. fractions that add up to 1.0).
Method:
Public Function GetMassFractionValues(Optional internalUnits As Boolean = False)
Parameters:
interalUnits A Boolean for using internal units
Return values:
GetMassFractionValues This function returns the mass fraction values.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As Variant
result = vPort.GetMassFractionValues
End Sub
GetMoleWtPerCmp
This function returns the molecular weight per component.
Method:
Public Function GetMoleWtPerCmp()
Parameters:
This function does not require parameters.
Return values:
GetMoleWtPerCmp This function returns the mole weight per component.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As Variant
result = vPort.GetMoleWtPerCmp
End Sub
GetStdMolVolPerCmp
This function returns the standard molar volume per component.
Method:
Public Function GetStdMolVolPerCmp()
Parameters:
This function does not require parameters.
Return values:
GetStdMolVolPerCmp This function returns the mole per component at STD.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As Variant
result = vPort.GetStdMolVolPerCmp
End Sub
GetStdVolFractionValues
This function returns an array with the values of the standard liquid volume composition. By default it returns the
values in the active unit set or it may return them in internal units (i.e. fractions that add up to 1.0).
Method:
Public Function GetStdVolFractionValues(Optional internalUnits As Boolean = False)
Parameters:
interalUnits A Boolean to use internal units.
Return values:
GetStdVolFractionValues This function returns the volume fraction values at STD.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim result As Variant
result = vPort.GetStdVolFractionValues
End Sub
InitFromObject
Initializes the values in the dynamics object based on another object.
Method:
Public Sub InitFromObject(fromObj As VMGObject, takeFromEngine As eVMGActiveEngine)
Parameters:
fromObj Object with the initialization information. It can be a material stream, a material port or a holdup.
takeFromEngine - Indicates the engine where the information is being taken from. For example, the port may
be getting initialized with the steady state values of another material port.
Return values:
This function does not require parameters.
Example:
Public Sub test(vPort as VMGPortMaterial)
Dim otherPort as VMGPortMaterial
Set otherPort = gVMGEngine.GetVMGObject(S1.In)
Call vPort.InitFromObject(otherPort, eSS_ENGINE)
End Sub
VMGThermoAdmin
VMGThermoAdmin
This object is used to manage the thermodynamic objects used in the simulator. It may be accessed through the
VMGMainEngine as follows,
Set vThAdmin = gVMGEngine.ThermoAdmin
Or
Set vThAdmin = gVMGEngine.GetVMGObject($)
Public Members
<VMGObjects> Get ThermoCases()
This function returns a VMGObjects containing the thermodynamic cases.
<Variant> GetAllSelectedCompoundNames()
AddThermoCase
This function adds a Thermo Case. This thermodynamic case is automatically assigned to the root flowsheet if
necessary.
Method:
Public Function AddThermoCase(ByVal name As String, pkg As eVMGPropPkgs, Optional liqPkg As
eVMGPropPkgs = -1, Optional withSolids As Boolean = False) As VMGThermoCase
Parameters:
name Name to be assigned to the new thermodynamic case. It cannot contain spaces ( ), commas (,) or
periods (.).
pkg The property package enumeration value for the vapor and liquid phase. This value is overridden for the
liquid phase if a specific value is provided in the liqPkg parameter.
liqPkg Property package for the liquid phase. pkgName is used if this value is -1.
withSolids - Adds an inert solid phase if this value is True.
Return values:
AddThermoCase The new VMGThermoCase created. This thermodynamic case is automatically assigned
to the root flowsheet if necessary.
Example:
Public Sub test(vThermo as VMGThermoAdmin)
Dim thCase as VMGThermoCase
Set thCase = vThermo.AddThermoCase(eAdvancedPengRobinson)
End Sub
AddThermoCaseByPkgName
This function adds the thermo case using package names. This thermodynamic case is automatically assigned
to the root flowsheet if necessary.
Method:
Public Function AddThermoCaseByPkgName(ByVal name As String, ByVal pkgName As String, Optional
ByVal liqPkg As String = "", Optional ByVal solPkg As String = "") As VMGThermoCase
Parameters:
name Name to be assigned to the new thermodynamic case. It cannot contain spaces ( ), commas (,) or
periods (.).
pkgName The property package name for the vapor and liquid phase. This value is overridden for the liquid
phase if a specific value is provided in the liqPkg parameter.
liqPkg Property package for the liquid phase. pkgName is used if this value is empty.
solPkg An inert solid phase is included in the calculations if a value is provided. The only solid property pack-
age available at this point is SimpleSolid.
Return values:
AddThermoCaseByPkgName The new VMGThermoCase created. This thermodynamic case is auto-
matically assigned to the root flowsheet if necessary.
Example:
Public Sub test(vThermo as VMGThermoAdmin)
Dim thCase as VMGThermoCase
Dim pkg as String
pkg = Advanced_Peng-Robinson
Set thCase = vThermo.AddThermoCaseByPkgName(pkg)
End Sub
AvPropPkgNames
This function returns the names of all the property package available.
Method:
Public Property Get AvPropPkgNames()
Parameters:
There are no parameters in this function.
Return values:
AvPropPkgNames An array of strings with the property package names.
Example:
Public Sub test(vThermo as VMGThermoAdmin)
Dim result As Variant
Returns Advanced_Peng-Robinson, Amines, etc ...
Result = vThermo.AvPropPkgNames
End Sub
Get ThermoCases
This function returns a VMGObjects containing the thermodynamic cases.
Method:
Public Property Get ThermoCases() As VMGObjects
Parameters:
There are no parameters in this function.
Return values:
ThermoCases An instance of VMGObjects that contains a list of VMGThermoCase objects.
Example:
Public Sub test(vThermo as VMGThermoAdmin)
Dim result As VMGObjects
GetAllSelectedCompoundNames
This function returns a variant with all the selected compound names across all the thermodynamic cases.
Method:
Public Function GetAllSelectedCompoundNames() As Variant
Parameters:
There are no parameters in this function.
Return values:
GetAllSelectedCompoundNames Array of strings with the compound names.
Example:
Public Sub test(vThermo as VMGThermoAdmin)
Dim names
Name s= vThermo.GetAllSelectedCompoundNames()
End Sub
VMGUnitOperation
VMGUnitOperation
Implements the VMGObject interface. The VMGUnitOperation is implemented by every unit operation including
streams and flowsheets.
<Variant>GetCompoundNames()
This function returns the names of the compounds associated with the unit operation.
<String> RenderLastLocalMessage()
Returns a rendered status message for the unit operation. This is the same text shown in the unit operation
forms in VMGSim.
<Variant>GetRenderedMessagesAndTypes()
This function returns an array or arrays with all the rendered messages and their type (Info, Warning or
Error).
<Variant>GetLastLocalMessage()
This function returns an array with a message key, arguments and a message type.
<Variant>GetLocalMessages()
This function returns an array of arrays with a message key, arguments and a message type.
<Variant>GetParameterNames()
This function returns the Names of all the parameters.
<Variant>GetParameterValue(paramName)
This function returns the value contained within the specified parameter.
<Boolean> HasErrorOrWarning()
Checks if the Unit of Operation has any Errors or Warnings.
<Boolean> IsSolved()
This function checks to see if the VMGUnitOperation is solved.
SetParameterValue(<Variant>paramName, <Variant>value)
Sets the value of the specified parameter.
Resolve()
Forces the VMGUnitOperation to resolve (steady state).
GetCompoundCount
This function returns the total number of compounds.
Method:
Public Function GetCompoundCount() As Long
Parameters:
This function does not require parameters.
Return values:
GetCompoundCount This function returns a Long which contains the total number of compounds.
Example:
Public Sub test(vUni As VMGUnitOperation)
Dim numCompound As Long
numCompound = vUni.GetCompoundCount
End Sub
GetCompoundIndex
This function returns the index with the location of the specified compound (base 0).
Method:
Public Function GetCompoundIndex(cmpName As String) As Long
Parameters:
cmpName This is a string that contains the name of the specified compound
Return values:
GetCompoundIndex This function returns the corresponding index number of the specified compound.
Example:
Public Sub test(vUni As VMGUnitOperation)
Dim index As Long
Dim cmpName As String
cmpName = WATER
index = vUni.GetCompoundIndex(cmpName)
End Sub
GetCompoundNames
This function returns the names of the compounds associated with the unit operation.
Method:
Public Function GetCompoundNames()
Parameters:
This function does not require parameters.
Return values:
GetCompoundNames This function returns variants containing the names of all the compounds associated
with the VMGUnitOperation.
Example:
Public Sub test(vUni As VMGUnitOperation)
Dim names
names = vUni.GetCompoundNames()
End Sub
GetLastLocalMessage
This function returns an array with a message key, arguments and a message type.
Method:
Public Function GetLastLocalMessage()
Parameters:
This function does not require parameters.
Return values:
GetLastLocalMessage This function returns an array with the information related to the status of the unit oper-
ation.
Example:
Public Sub test(vUni As VMGUnitOperation)
Dim localmsg
localmsg = vUni.GetLastLocalMessage()
End Sub
GetLocalMessages
This function returns an array of arrays with a message key, arguments and a message type.
Method:
Public FuncGetLocalMessagestion GetLocalMessages()
Parameters:
This function does not require parameters.
Return values:
GetLocalMessages This function returns an array of arrays with the information related to the status of the
unit operation.
Example:
Public Sub test(vUni As VMGUnitOperation)
Dim localmsg
localmsg = vUni.GetLocalMessages()
End Sub
GetObjsByGroup
This function returns the objects in a predefined group.
Method:
Public Function GetObjsByGroup(groupName As String)
Parameters:
groupName This is a String that contains the name of a predefined group. An example of this would be
StripCharDef
Return value:
GetObjsByGroup This function returns the objects that are contained within the predefined group.
Example:
Public Sub test(vUni As VMGUnitOperation)
Dim vars
Dim groupName As String
groupName = StripCharDef
vars = vUni.GetObjsByGroup(groupName)
End Sub
GetObjsNamesByGroup
This function returns the name of the objects in the specified group.
Method:
Public Function GetObjsNamesByGroup(groupName As String)
Parameters:
groupName String variable that contains the name of a predefined group. An example of this would be
StripCharDef
Return values:
GetObjsNamesByGroup This function returns the names of all the objects that are contained within the pre-
defined group.
Example:
Public Sub test(vUni As VMGUnitOperation)
Dim groupName As String
Dim varNames
groupName = StripCharDef
varNames = vUni.GetObjsNamesByGroup(groupName)
End Sub
GetParameterValue
This function returns the value contained within the specified parameter.
Method:
Public Function GetParameterValue(ByVal paramName)
Parameter:
paramName This is the name of the parameter in which information will be extracted from.
Return value:
GetParameterValue This function returns the value of the specified parameter.
Example:
Public Sub test(vUni As VMGUnitOperation)
Dim paramName
Dim value
paramName = MaxIterations
value = vUni.GetParameterValue(paramName)
End Sub
GetPort
This function returns the VMGPort as specified by the name.
Method:
Public Function GetPort(name As String) As VMGPort
Parameter:
Name This is a string that contains the name of the port being retrieved
Return value:
GetPort This returns the VMGPort as specified by the name.
Example:
Public Sub test(vUni As VMGUnitOperation)
Dim name As String
Dim vPort As VMGPort
name = In0
Set vPort = vUni.GetPort(name)
End Sub
GetPortNames
This function returns the names of the ports within the VMGUnitOperation.
Method:
Public Function GetPortNames(Optional portType As eVMGPortTypes = 31, Optional useDispName As
Boolean = False)
Parameters:
portType This parameter determines which names the function will return. The default value is 31 (eALL_
PORT), which makes the function return all the ports. Options for portType are taken from the enumeration
eVMGPortTypes.
useDispName This parameter determines either or not the function is going to use the Display Name for
when it retrieves the port names. By default the value of useDispName is False
Return values:
GetPortNames This function returns the names of the ports in the VMGUnitOperation. (Example: In, Out,
DeltaP, etc)
Example:
Public Sub test(vUni As VMGUnitOperation)
Dim portType As eVMGPortTypes
Dim useDispName As Boolean
Dim names
portType = eALL_PORT
useDispName = False
names = vUni.GetPortNames(portType,useDisName)
End Sub
GetRenderedMessagesAndTypes
This function returns an array or arrays with all the rendered messages and their type (Info, Warning or
Error).
Method:
Public Function GetRenderedMessagesAndTypes()
Parameter:
This function does not require any parameters
Return value:
GetRenderedMessagesAndTypes This function returns the messages as well as the types associated with
the VMGUnitOperation. An example of the messages would be solved and an example of the types would be
Info.
Example:
Public Sub test(vUni As VMGUnitOperation)
Dim renMsg
enMsg = vUni.GetRenderedMessagesAndTypes()
End Sub
HasErrorOrWarning
Checks to see if the Unit of Operation has any Errors or Warnings.
Method:
Public Function HasErrorOrWarning() As Boolean
Parameter:
This function does not require any parameters.
Return values:
HasErrorOrWarning This function returns a Boolean for if the VMGUnitOperation has any errors.
Example:
Public Sub test(vUni As VMGUnitOperation)
Dim hasErr As Boolean
hasErr = vUni.HasErrorOrWarning()
End Sub
IsSolved
This function checks to see if the VMGUnitOperation is solved.
Method:
Public Property Get IsSolved() As Boolean
Parameters:
This function does not require parameters.
Return values:
IsSolved This function returns a Boolean for if the VMGUnitOperation is solved or not
Example:
Public Sub test(vUni As VMGUnitOperation)
Dim solved As Boolean
solved = vUni.IsSolved()
End Sub
GetParameterNames
This function returns the Names of all the parameters.
Method:
Public Function GetParameterNames()
Parameters:
This function does not require parameters.
Return values:
GetParameterNames This function returns the names of all the parameters.
Example:
Public Sub test(vUni As VMGUnitOperation)
Dim param
param = vUni.GetParameterNames()
End Sub
RenderLastLocalMessage
Returns a rendered status message for the unit operation. This is the same text shown in the unit operation
forms in VMGSim.
Method:
Public Function RenderLastLocalMessage() As String
Parameter:
There are no parameters in this function
Return values:
RenderLastLocalMessage String with the rendered status for the unit operation. The unit operation may con-
tain more than one status message. This function returns the last message.
Example:
Public Sub test(vUni As VMGUnitOperation)
Dim msg
msg = vUni.RenderLastLocalMessage()
End Sub
Resolve
This function forces the VMGUnitOperation to resolve (steady state).
Method:
Public Sub Resolve()
Parameter:
There are no parameters in this function
Return values:
Resolve This function forces the VMGUnitOperation to resolve
Example:
Public Sub test(vUni As VMGUnitOperation)
Call vUni.Resolve()
End Sub
SetParameterValue
This function sets the value of the specified parameter.
Method:
Public Function SetParameterValue(ByVal paramName, value)
Parameter:
paramName This is the parameter name that will be set by the function
value This is the value that will be set into the parameter specified by paramName
Return values:
This function does not return anything
Example:
Public Sub test(vHeater As VMGUnitOperation)
Call vHeater.SetParameterValue(NumberSegments, 4)
End Sub
VMGUnitSystem
VMGUnitSystem
This interface is used to manage unit conversions in VMGSim. The unit system is always available and can be
accessed from the VMGMainEngine as follows,
gVMGEngine.UnitSystem
The public methods implemented by the VMGUnitSystem interface are based on some basic concepts used by
VMGSim. The Unit Set is the most important concept to understand when working with unit conversions. A
unit set is a group of default units that can be used by every variable in the simulator. There is always an active
unit set and variables report their values based on this set unless otherwise specified. For example, if the active
unit set is Field, the variables of type Temperature will be reported and set in Fahrenheit by default. If the act-
ive unit set is changed to SI, then the default units for Temperature will be Celsius. It is important to note that
the VMG unit set is a special set because it is also the unit set used by the simulation engine for internal cal-
culations. You can open the VMGSims Unit Sets menu in order to inspect the units used by every unit set.
The unit sets contain a unit for each unit type. Every unit can be identified by a unit name (e.g. psia, K) or by
a unit ID (e.g. 46 for psia, 49 for K). These units belong to a unit type that can be identified either by unit type
name or by unit type ID (e.g. 1 for Pressure, 2 for Temperature). For example, the units K, F, R and C
belong to the Temperature unit type.
Public Members
<String> Get ActiveUnitSet()
Returns the active unit set for the simulation engine (e.g. Field, SI, VMG, Refinery, etc).
<Variant> GetUnitSetNames()
Returns the Unit Set Names available.
FromActiveToInternal
Converts a value from the active unit set to the internal unit set for a given unit type ID.
Method:
Public Function FromActiveToInternal(ByVal UnitTypeID As Long, val)
Parameters:
UnitTypeID The unit type id for a variable. This value can be requested directed from any VMGVariable.
Return values:
FromActiveToInternal Converted value.
Example:
Public Sub test(vEng As VMGMainEngine)
Dim Val as Double
Dim utIDTemp as Long
FromActiveToUnitName
Converts a value from the active unit set to a specific unit name.
Method:
Public Function FromActiveToUnitName(ByVal UnitTypeID As Long, ByVal UnitName As String, val)
Parameters:
UnitTypeID - The unit type id for a variable. This value can be requested directed from any VMGVariable.
UnitName - The target unit name.
Return values:
FromActiveToUnitName - Converted value.
Example:
Public Sub test(vEng As VMGMainEngine)
Dim Val as Double
Dim utIDTemp as Long
FromInternalToUnitName
Converts a value from the internal unit set to a specific unit name.
Method:
Public Function FromInternalToUnitName(ByVal UnitTypeID As Long, ByVal UnitName As String, val)
Parameters:
UnitTypeID - The unit type id for a variable. This value can be requested directed from any VMGVariable.
UnitName The target unit name.
Return values:
FromInternalToUnitName - Converted value.
Example:
Public Sub test(vEng As VMGMainEngine)
Dim Val as Double
Dim utIDTemp as Long
FromUnitNameToActive
Converts a value from a specific unit name ot the active unit set.
Method:
Public Function FromUnitNameToActive(ByVal UnitTypeID As Long, ByVal UnitName As String, val)
Parameters:
UnitTypeID - The unit type id for a variable. This value can be requested directed from any VMGVariable.
UnitName - The source unit name.
Return values:
FromUnitNameToActive - Converted value.
Example:
Public Sub test(vEng As VMGMainEngine)
Dim Val as Double
Dim utIDTemp as Long
FromUnitNameToInternal
Converts a value from a specific unit name to the internal unit set.
Method:
Public Function FromUnitNameToInternal(ByVal UnitTypeID As Long, ByVal UnitName As String, val)
Parameters:
UnitTypeID - The unit type id for a variable. This value can be requested directed from any VMGVariable.
UnitName - The source unit name.
Return values:
FromUnitNameToInternal - Converted value.
Example:
Public Sub test(vEng As VMGMainEngine)
Dim Val as Double
Dim utIDTemp as Long
Get ActiveUnitSet
Returns the active unit set for the simulation engine (e.g. Field, SI, VMG, Refinery, etc).
Method:
Public Property Get ActiveUnitSet() As String
Parameters:
There are no parameters in this function.
Return values:
ActiveUnitSet The active unit set as a string. It can also be a custom unit set created by the user in VMGSim.
This value is stored with the simulation cases and the active set may change when recalling a case.
Example:
Public Sub test(vEng As VMGMainEngine)
Dim unitSet As String
unitSet = vEng.UnitSystem.ActiveUnitSet
End Sub
GetActiveUnitName
Returns the Active Unit Name for a unit type ID.
Method:
Public Function GetActiveUnitName(ByVal UnitTypeID) As String
Parameters:
UnitTypeID - The unit type id for a variable. This value can be requested directed from any VMGVariable.
Return values:
GetActiveUnitName Unit name for the active unit set, for example F for unit type id of 2 (Temperature).
Example:
Public Sub test(vEng As VMGMainEngine)
Dim utIDTemp as Long
Dim uName as String
GetUnitNameByUnitID
Returns the Unit Name for a specific unit ID.
Method:
Public Function GetUnitNameByUnitID(ByVal unitID As Long) As String
Parameters:
unitID Unit ID.
Return values:
GetUnitNameByUnitID Unit name for a specified unit ID.
Example:
Public Sub test(vEng As VMGMainEngine)
Dim uID as Long
Dim uName as String
GetUnitNameByUnitSet
Returns the Unit Name for a specific Unit Set.
Method:
Public Function GetUnitNameByUnitSet(ByVal unitSetName As String, ByVal UnitTypeID) As String
Parameters:
unitSetName - There are no parameters in this function.
UnitTypeID - The unit type id for a variable. This value can be requested directed from any VMGVariable.
Return values:
GetUnitNameByUnitSet Unit name for the specified unit set.
Example:
Public Sub test(vEng As VMGMainEngine)
Dim utIDTemp as Long
Dim uName as String
GetUnitSetNames
Returns the Unit Set Names available.
Method:
Public Function GetUnitSetNames()
Parameters:
There are no parameters in this function.
Return values:
GetUnitSetNames - Returns the Unit Set Names available including the ones created by the user when using
VMGSim.
Example:
Public Sub test(vEng As VMGMainEngine)
Dim setNames
Returns Field, SI, VMG, etc
setNames = vEng.UnitSystem.GetUnitSetNames()
End Sub
GetUnitTypeName
Returns the Unit Type Name for a given Unit Type ID based on the active unit set.
Method:
Public Function GetUnitTypeName(ByVal UnitTypeID As Long)
Parameters:
UnitTypeID - The unit type id for a variable. This value can be requested directed from any VMGVariable.
Return values:
GetUnitTypeName A unit type name, for example F or psia.
Example:
Public Sub test(vEng As VMGMainEngine)
Dim utName as String
Dim utIDTemp as Long Temperature unit type id
utIDTemp = 2 Temperature unit type id
vEng.UnitSystem.ActiveUnitSet = Field
Returns F
utName = vEng.UnitSystem.GetUnitTypeName(utIDTemp)
End Sub
Let ActiveUnitSet
Sets the active unit set to the specified set (e.g. Field, SI, VMG, Refinery, etc).
Method:
Public Property Let ActiveUnitSet(ByVal theSet As String)
Parameters:
theSet - There are no parameters in this function.
Return values:
This function does not return anything.
Example:
Public Sub test(vEng As VMGMainEngine)
vEng.UnitSystem.ActiveUnitSet = Field
End Sub
SupportsSet
Checks if the specified unit set is supported.
Method:
Public Function SupportsSet(ByVal setName As String) As Boolean
Parameters:
setName Unit set name (e.g. Field).
Return values:
SupportsSet True if the unit set is available.
Example:
Public Sub test(vEng As VMGMainEngine)
Dim bSupported as Boolean
bSupported = vEng.UnitSystem.SupportsSet(Field)
End Sub
UnitNamesByType
Returns the Unit Names available for a unit type id. For example, K, F, R, C for unit type id of 1 (Tem-
perature).
Method:
Public Function UnitNamesByType(ByVal UnitTypeID As Long)
Parameters:
UnitTypeID - The unit type id for a variable. This value can be requested directed from any VMGVariable.
Return values:
UnitNamesByType An array of strings.
Example:
Public Sub test(vEng As VMGMainEngine)
Dim utNames
Dim utIDTemp as Long
utIDTemp = 2 Temperature unit type id
Returns F, C, K, R
utNames = vEng.UnitSystem.UnitNamesByType(utIDTemp)
End Sub
VMGVariable
VMGVariable
This interface is implemented by every object that can return a value. It also implements methods to handle vec-
tors and matrices.
<Variant> GetValues()
This function returns a vector containing the values of the VMGVariable
<Variant> GetSSValues()
This function returns a vector containing the steady state values of the VMGVariable
<Variant> GetDynValues()
This function returns a vector containing the dynamic values of the VMGVariable
<Long> GetDataType()
Same as property DataType
<Variant> GetOptions()
This function returns an array of values allowed by the variable.
<Long> GetUnitTypeId()
Same as property UnitTypeId
<String> GetUnitName()
Same as property UnitName
<Long> GetStatus()
Same as property Status.
ForceResults(<Boolean> theForceResults )
Public Property Let ForceResults(theForceResults As Boolean)
SetAsSpec(<Boolean> asSpec )
Sets a variable as a specification (for the dynamics engine only)
<Boolean> IsSpec()
Returns a Boolean value of True if the variable is a specification.
<String> GetVarType()
Returns the variable type. For example, this function returns P for a variable that contains values of type Pres-
sure.
<Variant> Values()
This property returns the array that contains the values of the VMGVariable
Values(<Variant> vals)
Specifies an array of values for a vector variable. It assumes that the values are in units that correspond to the
active unit set.
<Long> UnitTypeID()
Returns the unique id of the type of units used by the variable
<String> UnitName()
Returns the unit name used by the variable in the active unit set
<Long> Status()
Returns the calculation status of the variable.
<Boolean> IsReadOnly()
Returns a Boolean with a value of True if the variable is read only
<Boolean> IsAlwaysPresent()
Returns a Boolean with a value of True if the variable is always present in the object where it is contained
<Variant> GetValidUnitNames()
Returns an array with the valid unit names supported by the variable. For example, if the variable is of type
Temperature it will return an array with C, K, F and R.
<Variant> GetValuesAtUnits(<String>UnitName)
Returns the array of values of a variable at specific units
<String> Description()
Returns a short description for the variable (when available)
<String> UnitTypeName()
Returns the unit type name of the variable. For example, if the variable is a pressure, it will return Pressure.
Get DataType
Returns an integer value that represents the type of data contained. The possible values are the binary com-
bination of the following values:
0: Unknown type
1: Floating point value
2: Integer
4: String
8: Boolean
16: Vector
32: Scalar
64: Matrix
128: Object
For example, a data type of 33 represents a scalar variable with a floating point value (33 = 32 + 1 = Scalar +
Floating point). A data type of 18 represents a vector of integers (18 = 16 + 2 = Vector + Integer).
Method:
Public Property Get DataType() As Long
Parameters:
There are no parameters in this function.
Return values:
DataType This property returns and integer value that represents the type of data contained.
Example:
Public Sub test(vVar as VMGVariable)
Dim result As Long
result = vVar.DataType
End sub
Get Description
Returns a short description for the variable (when available).
Method:
Public Property Get Description() As String
Parameters:
There are no parameters in this function.
Return values:
Description - Returns a short description for the variable (when available).
Example:
Public Sub test(vVar as VMGVariable)
Dim result As String
result = vVar.Description
End sub
Get ForceResults
Returns a Boolean value of True if the GetValue method will attempt to return the value from the non active
engine when the variable is not found in the active engine. For example, if the active engine is Dynamics, the
GetValue may return the value found in the Steady State engine if the variable is not supported in the Dynamics
engine.
Method:
Public Property Get ForceResults() As Boolean
Parameters:
There are no parameters in this function.
Return values:
ForceResults - This function returns a Boolean value of True if the GetValue method will attempt to return the
value from the non active engine when the variable is not found in the active engine. For example, if the active
engine is Dynamics, the GetValue may return the value found in the Steady State engine if the variable is not
supported in the Dynamics engine.
Example:
Public Sub test(vVar as VMGVariable)
Dim result as Boolean
result = vVar.ForceResult()
End sub
Get IsReadOnly
Returns a Boolean with a value of True if the variable is read only (i.e. cannot be modified by the user).
Method:
Public Property Get IsReadOnly() As Boolean
Parameters:
There are no parameters in this function.
Return values:
IsReadOnly - Returns a Boolean with a value of True if the variable is read only
Example:
Public Sub test(vVar as VMGVariable)
Dim result as Boolean
result = vVar.IsReadOnly
End sub
Get Size
Returns the size of the vector. This property will return 1 if the variable is a scalar.
Method:
Public Property Get Size() As Long
Parameters:
There are no parameters in this function.
Return values:
Size This property returns the size of the vector
Example:
Public Sub test(vVar as VMGVariable)
Dim result As Long
result = vVar.GetSize
End sub
Get Status
Same as function GetStatus. Returns the calculation status of the variable. The allowed return values are,
1: Unknown value.
2: Specification.
4: Calculated by the simulation engine.
8: Passed value across a connection.
32: Estimated value in a recycle point.
Method:
Public Property Get Status() As Long
Parameters:
There are no parameters in this function.
Return values:
Status - Returns the calculation status of the variable.
Example:
Public Sub test(vVar as VMGVariable)
Dim result As Long
result = vVar.Status
End sub
Get UnitName
Same as function GetUnitName. Returns the unit name used by the variable in the active unit set. For example,
a Temperature will return a F when the active unit set is Field.
Method:
Public Property Get UnitName() As String
Parameters:
There are no parameters in this function.
Return values:
UnitName - Returns the unit name used by the variable in the active unit set.
Example:
Public Sub test(vVar as VMGVariable)
Dim result As String
result = vVar.UnitName
End sub
Get UnitTypeID
Same as function GetUnitTypeID. Returns the unique id of the type of units used by the variable. For example,
if the variable is of type Pressure then it returns a 1. See reference for VMGUnitSystem for more information
on units handling.
Method:
Public Property Get UnitTypeID() As Long
Parameters:
There are no parameters in this function.
Return values:
UnitTypeID - Returns the unique id of the type of units used by the variable.
Example:
Public Sub test(vVar as VMGVariable)
Dim result As Long
result = vVar.UnitTypeID
End sub
Get UnitTypeName
Returns the unit type name of the variable. For example, if the variable is a pressure, it will return Pressure.
Method:
Public Property Get UnitTypeName() As String
Parameters:
There are no parameters in this function.
Return values:
UnitTypeName - Returns the unit type name of the variable. For example, if the variable is a pressure, it will
return Pressure.
Example:
Public Sub test(vVar as VMGVariable)
Dim result As String
result = vVar.UnitTypeName
End sub
Get Value
Returns the current value of the variable. It returns the first item in the case where the variable is a vector. The
value is returned in the units that correspond to the active unit set.
Method:
Public Property Get Value()
Parameters:
There are no parameters in this function.
Return values:
Value This property returns the value of the variable
Example:
Public Sub test(vVar as VMGVariable)
Dim result As Variant
result = vVar.Value
End sub
Get Values
Returns the current array of values of a vector variable. It returns an array with one item if the variable is a
scalar. The values are returned in the units that correspond to the active unit set.
Method:
Public Property Get Values()
Parameters:
There are no parameters in this function.
Return values:
Values This property returns the array that contains the values of the VMGVariable
Example:
Public Sub test(vVar as VMGVariable)
Dim result() As Variant
GetDataType
Same as property DataType.
GetDynValue
Returns the current value of the variable in the dynamics engine. It returns the value at the specified Index if the
variable is a vector or a matrix. The value is returned in the units that correspond to the active unit set.
Method:
Public Function GetDynValue(Optional index As Long = 0)
Parameters:
Index This indicates which index from the vector to be returned (for vectors only)
Return values:
GetDynValue - This function returns the dynamic value at the appointed index, if no index is specified, the
default is index 0
Example:
Public Sub test(vVar as VMGVariable)
Dim result As Variant
Dim index As Long
index = 0
Result = vVar.GetDynValue(index)
End sub
GetDynValues
Returns an array of values from the variable from the dynamics engine. If the variable is a scalar, then it wraps
the return value as an array with one element. The values are returned in the units that correspond to the active
unit set.
Method:
Public Function GetDynValues()
Parameters:
There are no parameters in this function.
Return values:
GetDynValues - This function returns a vector containing the dynamic values of the VMGVariable
Example:
Public Sub test(vVar as VMGVariable)
Dim result() As Variant
Set result = vVar.GetDynValues
End sub
GetOptions
Returns an array of values allowed by the variable. For example, the variable Characteristic from a Valve can
accept the following options, Linear, EqualPercentage, QuickOpening.
Method:
Public Function GetOptions()
Parameters:
There are no parameters in this function.
Return values:
GetOptions - This function returns an array of values allowed by the variable. For example, the variable Char-
acteristic from a Valve can accept the following options, Linear, EqualPercentage, QuickOpening.
Example:
Public Sub test(vVar as VMGVariable)
Dim result() As Variant
Set result = vVar.GetOPtions
End sub
GetSSValue
Returns the current value of the variable in the steady state engine. It returns the value at the specified Index if
the variable is a vector or a matrix. The value is returned in the units that correspond to the active unit set.
Method:
Public Function GetSSValue(Optional index As Long = 0)
Parameters:
Index This indicates which index from the vector to be returned (for vectors only)
Return values:
GetSSValue - This function returns the steady state value at the appointed index, if no index is specified, the
default is index 0.
Example:
Public Sub test(vVar as VMGVariable)
Dim result As Variant
Dim index As Long
index = 0
result = vVar.GetSSValue(index)
End sub
GetSSValues
Returns an array of values from the variable from the steady state engine. If the variable is a scalar, then it
wraps the return value as an array with one element. The values are returned in the units that correspond to the
active unit set.
Method:
Public Function GetSSValues()
Parameters:
There are no parameters in this function.
Return values:
GetSSValues - This function returns a vector containing the steady state values of the VMGVariable
Example:
Public Sub test(vVar as VMGVariable)
Dim result() As Variant
Set result = vVar.GetSSValues
End sub
GetStatus
Same as property Status.
GetUnitName
Same as property UnitName.
GetUnitTypeId
Same as property UnitTypeId.
GetValidUnitNames
Returns an array with the valid unit names supported by the variable. For example, if the variable is of type
Temperature it will return an array with C, K, F and R.
Method:
Public Function GetValidUnitNames()
Parameters:
There are no parameters in this function.
Return values:
GetValidUnitNames - Returns an array with the valid unit names supported by the variable.
Example:
Public Sub test(vVar as VMGVariable)
Dim result() As Variant
Set result = vVar.GetValidUnitNames
End sub
GetValue
Returns the current value of the variable. It returns the value at the specified Index if the variable is a vector or a
matrix. The value is returned in the units that correspond to the active unit set.
Method:
Public Function GetValue(Optional index As Long = 0)
Parameters:
Index This indicates which index from the vector to be returned (for vectors only)
Return values:
GetValue - This function returns the value at the appointed index, if no index is specified, the default is index 0
Example:
Public Sub test(vVar as VMGVariable)
Dim result As Variant
Dim index As Long
index = 0
result = vVar.GetValue(index)
End sub
GetValueAtUnits
Returns the value of the variable at specific units.
Method:
Public Function GetValueAtUnits(UnitName As String, Optional idx As Long = 0)
Parameters:
UnitName This is a String containing the Unit Name
Idx This is a Long containing the index
Return values:
GetValueAtUnits - Returns the value of the variable at specific units.
Example:
Public Sub test(vVar as VMGVariable)
Dim unitName as String
Dim value as Double
GetValueInternalUnits
Returns the current value of the variable. It returns the value at the specified Index if the variable is a vector or a
matrix. The value is returned in the units of the internal unit set (VMG unit set).
Method:
Public Function GetValueInternalUnits(Optional index As Long = 0)
Parameters:
Index This indicates which index from the vector to be returned (for vectors only)
Return values:
GetValueInternalUnits - This function returns the internal units at the appointed index, if no index is specified,
the default is index 0
Example:
Public Sub test(vVar as VMGVariable)
Dim result As Variant
Dim index As Long
index = 0
result = vVar.GetValueInternalUnits(index)
End sub
GetValues
Returns an array of values from the variable. If the variable is a scalar, then it wraps the return value as an array
with one element. The values are returned in the units that correspond to the active unit set.
Method:
Public Function GetValues()
Parameters:
There are no parameters in this function.
Return values:
GetValues - This function returns a vector containing the values of the VMGVariable
Example:
Public Sub test(vVar as VMGVariable)
Dim result() As Variant
GetValuesAtUnits
Returns the array of values of a variable at specific units.
Method:
Public Function GetValuesAtUnits(UnitName As String)
Parameters:
UnitName This is a String containing the Unit Name
Return values:
GetValuesAtUnits - Returns the array of values of a variable at specific units
Example:
Public Sub test(vVar as VMGVariable)
Dim unitName as String
Dim values as Double
GetVarType
Returns the variable type. For example, this function returns P for a variable that contains values of type Pres-
sure.
Method:
Public Function GetVarType() As String
Parameters:
There are no parameters in this function.
Return values:
GetVarType This function returns the variable type.
Example:
Public Sub test(vVar as VMGVariable)
Dim result As String
result = vVar.GetVarType()
End sub
IsAlwaysPresent
Returns a Boolean with a value of True if the variable is always present in the object where it is contined.
Method:
Public Property Get IsAlwaysPresent() As Boolean
Parameters:
There are no parameters in this function.
Return values:
IsAlwaysPresent - Returns a Boolean with a value of True if the variable is always present in the object where it
is contined
Example:
Public Sub test(vVar as VMGVariable)
Dim result As Boolean
result = vVar.IsAlwaysPresent
End sub
IsSpec
Returns a Boolean value of True if the variable is a specification.
Method:
Public Function IsSpec() As Boolean
Parameters:
There are no parameters in this function.
Return values:
IsSpec This function returns a Boolean value of True if the variable is a specification
Example:
Public Sub test(vVar as VMGVariable)
Dim result As Boolean
result = vVar.IsSpec
End sub
Let ForceResults
If this variable is set to true, then the GetValue method will attempt to return the value from the non active
engine when the variable is not found in the active engine. For example, if the active engine is Dynamics, the
GetValue may return the value found in the Steady State engine if the variable is not supported in the Dynamics
engine.
Method:
Public Property Let ForceResults(theForceResults As Boolean)
Parameters:
theForceResults This is the Boolean that toggles the setting for ForceResults
Return values:
This function does not return anything.
Example:
Public Sub test(vVar as VMGVariable)
Dim theForceResults As Boolean
theForceResults = True
Call vVar.ForceResults(theForceResults)
End sub
Let Value
Specifies the value of the variable. The value is assumed to be in the units that correspond to the active unit set.
This is the default property for the interface, therefore a a VB user can do things like, vVar.Value = 10 or vVar =
10.
Method:
Public Property Let Value(val As Variant)
Parameters:
Val This is the value that will be set in the VMGVariable
Return values:
This function does not return anything.
Example:
Public Sub test(vVar as VMGVariable)
Dim theVal as double
theVal = 10
Let Values
Specifies an array of values for a vector variable. It assumes that the values are in units that correspond to the
active unit set.
Method:
Public Property Let Values(vals As Variant)
Parameters:
vals This is the array of values being set into the VMGVariable
Return values:
This function does not return anything.
Example:
Public Sub test(vVar as VMGVariable)
Dim values(0 to 1) As Long
values(0) = 1.23
values(1) = 4.56
Call vVar.Values(values)
End sub
SetAsSpec
Sets a variable as a specification (for the dynamics engine only)
Method:
Public Sub SetAsSpec(asSpec As Boolean)
Parameters:
asSpec A Boolean for toggling As Spec
Return values:
This function does not return anything.
Example:
Public Sub test(vVar as VMGVariable)
Dim asSpec As Boolean
asSpec = True
Call vVar.SetAsSpec(asSpec)
End sub
SetValues
Puts an array of values into the variable (for vectors only).
Method:
Public Sub SetValues(Values, Optional UnitName As String = "", Optional calcStatus As Long = gPyFIXED_V)
Parameters:
values This the value to be put into the VMGVariable.
UnitName This is a string containing the units of the values. The values are assumes to be in the active units
set if UnitName is not specified.
calcStatus This is the status of the value being set.
Return values:
This function does not return anything.
Example:
Public Sub test(vVar as VMGVariable)
Dim values (0 to 1) As Long
values(0) = 23.5
values(1) = 45.2
Call vVar.SetValues(values)
End sub
Examples
Dynamic Simulation
This example was written using Microsoft Excel 2013.
Purpose
This example provides an excel spreadsheet that recalls a dynamic simulation case and runs the model. The
integrator is controlled from the excel spreadsheet, the user can specify variables while the integrator is run-
ning. Selected variables will be updated in the spreadsheet as the integrator runs, the frequency at which the
variables update can be controlled by the user.
The files used in this example are located in the (Installation folder)\Documentation\VMG Automation
folder under the following subfolders:
\Excel Examples\Dynamics\Dynamics-FlowControl.xlsm
\Cases\ Dyn-FlowControl.vmp
This example is ready to run based on the dynamic Dyn-FlowControl.vmp simulation but it can be easily mod-
ified to run based on a different case. Note, the Visio image at the top of the Main Excel worksheet is not linked
live to the case and it is only provided as reference.
This example is also based on named ranges. The range Case Path defines the path of the simulation case
similarly to the Excel Case Study example. The button Change Case allows the user to browse for a sim-
ulation and writes the file path to the range case Path.
The input values are defined in a table starting with the named range InputInit (Cell A21). The first column
shows the paths of the variables, the second column displays the units (which will default to the base case if left
blank), the values are entered in the third column. The values may be adjusted as the integrator is running.
Columns can be amended, added or removed as required.
The output values are displayed in a table starting with the named range OutputInit (Cell E21). The first column
shows the paths of the variables, the second column displays the units (which will default to the base case if left
blank), the values are shown in the third column. The values will update as the simulation runs. Columns can be
amended, added or removed as required.
The integrator time and integrator stop time are displayed in the ranges IntegStep (Cell K21) and stop (Cell
K22) respectively. The integrator time is updated from the simulation, the stop time is a variable which may be
adjusted by the user. The value can be altered while the integrator is running.
The Start/Stop Integrator button is in charge of running the simulation based on the case specified in the range
named CasePath. Start/Stop Integrator will start the integrator if the integrator is stopped or stop the integ-
rator if the integrator is running.
'... Grab the Case file path defined in a range called CasePath
path = Range(RNG_CASE).Value()
If gVMGEngine.RootFlowsheet.Integrator.IsRunning Then
'... Pause the simulation
Call gVMGEngine.RootFlowsheet.Integrator.StopIntegrator
Call LogMessageToWksht("Integrator Stopped")
ElseIf IsInit Then
'... Run the simulation
Call RunSimulation(path)
End If
End Sub
The function InitiateSimulation is responsible for recalling the case. The function returns the Boolean value
true if the case has been successfully recalled, and false if unsuccessful.
Call ClearOutput
InitiateSimulation = True
Exit Function
LocalErr:
MsgBox "Error found while initializing simulation", vbCritical, "VMGSim Error"
End Function
While the simulation is running the callback message DynStep is used as an instruction to update the spread-
sheet. Output values and the integrator time are updated in the spreadsheet when the integrator has run until
the steps are equal to the global constant UPDATE. The default value of UPDATE is 100 which is equal to
100 integrator steps. The value can be adjusted in Module/VMGGlobals.
'... Ensure that the integrator time is initialised and updates in excel at the end of
a run
If msg = "DYNMsg" Then
stepCount = 0
Call UpdateResults
End Sub
The simulation can be updated while the integrator is running due to the sub routine Worksheet_Selec-
tionChange located in /Sheet1(Main). Changes to the input values or the integrator stop time will be detected
and will be updated in the simulator.
'-------------------------------------------------------------------------------------
--
'...Detect any changes to input variables and update the simulator
'-------------------------------------------------------------------------------------
--
LocalErr:
'... No handling for now, just exiting
End Sub
The subroutines UpdateSimInputs and UpdateResults are called frequently in the code and are shortcuts to
updating the simulator or the spreadsheet. UpdateSimInputs reads the input values from the spreadsheet and
updates the simulator, providing the variable path is defined in the table starting with the named range InputInit
(Cell A21) along with the corresponding value. UpdateResults reads the output values in the simulator and
updates the spreadsheet, providing the variable path is defined in the table starting with the named range Out-
putInit (Cell E21).
The files used in this example are located in the (Installation folder)\Documentation\VMG Automation
folder under the following subfolders:
Excel Examples\Case Study\Case Study.xls
Cases\HCRefrigerationLoop.vmp
This example is ready to run based on the HCRefrigerationLoop.vmp simulation but it can be easily modified to
run based on a different case. Note, the Visio image at the top of the Main Excel worksheet is not linked live to
the case and it is only provided as reference.
The range named CasePath (cell B15) defines the path of the simulation case. It can be a relative file path
based on the location of the Excel file. The Change Case button can be selected to browse for the case to input
the full path in the Case Path. Range UnitSet (cell B17) defines a default unit set for the case study.
This example is based on named ranges, therefore, instead of referring to a cell as the predefined B15, it is
possible to refer to the same cell as range CasePath. This provides the flexibility of moving the cell to a dif-
ferent location in the spreadsheet (e.g. to cell B16) and still preserve the name CasePath. Range names are
displayed and modified in the top left corner of the Excel worksheet.
The input values are defined in a table that has at least three columns and one row. This table starts in a range
called InputInit (cell A21). It uses the first column for the paths of the variables to modify, the second column to
define the units of the input values and the rest of the columns are used to define the actual values of every data
set. If the units are not provided, then it assumes the input values are in the selected unit set (default to Field).
Rows or columns can be added or removed as required.
If Compositional information is an input variable, then those details should be entered in between the <Vector>
and </Vector> rows. This signifies that an entire vector containing composition information will be inbetween
these two markers. The following types of composition information are supported: Fraction, Mass Fraction, and
Std Vol Fraction, as well as Mole, Mass and Std Volume Flows. Every component in the case needs to be listed
to avoid having VMGSim normalize the inputted values in the case.
The output variables are defined in a table that has at least two columns and one row. This table starts in a
range called OutputInit (cell A29). It uses the first column for the paths of the variables to inspect and the
second column for the units of the output values. If the units are not provided, then it assumes the input values
are in the selected unit set (default to Field). Rows can be added or removed as required. The case study is in
charge of providing the output values based on the input.
The Run button is in charge of running the case study based on the simulation case specified in the range
named CasePath. A Case Study Run takes the following sequence of steps (source code is located in the
module mainModule in the method RunSimulation) ,
1. Create the simulation engine. This step may be slow the first time it is run because it has to validate
the license and load internal resource.
2. Recall the simulation case.
3. Assigns the default unit set to the case (if available)
4. Inputs the first set of input variables to the model and solves the simulation.
5. Outputs the first set of results to the Excel worksheet.
6. Steps 4 and 5 are run for all the input columns with data.
The files used in this example are located in the (Installation folder)\Documentation\VMG Automation
folder under the following subfolders:
Excel Examples\ Multi Case Stream Summary\ Multi Case Stream Summary.xls
Description
The application allows the user select streams from multiple simulation cases; select the properties to be
reporter. The product from the excel application is a tabular report containing the streams as columns and the
properties as rows
Select a Case
Use the Add Case.. button to browse trough your cases, and add a case to the cases list.
Select a Flowsheets
One a case is selected the Flowsheets list will show all the available flowsheets.
Select a flowsheet to populate the streams list
Select a Stream
From the streams list select the streams desired to have in the report, by double clicking on it or by using the
selection buttons.
The selected streams will be added to the selection section
Important
This application wont report compounds fractions, or compounds flows when streams where different
compound list are mixed in the report.
Select a Phase
Select a phase from the phase list
Select a Property
Select one or more properties from the properties list
When the properties are selected they appear in the Selected section
Extra Configuration
Once the properties are selected, they can still be modified, to change the phase, the property or the display unit
Execute Report
Once the streams and properties are selected, use the report buttons, to create the report.
Once the report is created, it can still be modified by changing the properties and click on the recreate button.
Global Settings
The global settings are allocated in the settings worksheet
Reactor Optimization
Purpose
In this example we have the task of optimizing the length of a plug-flow reactor (PFR) to maximize the expected
profit given a particular objective function. This is accomplished by using the VMGSim COM Interface along
with the Excel Solver Add-In.
The files used in this example are located in the (Installation folder)\Documentation\VMG Automation
folder under the following subfolders:
Description
A VMGSim simulation case of an auto-thermal ammonia synthesis reactor has been setup as an approximate
model. A feed to the reactor is pre-heated before entering the PFR by exchanging energy released by the reac-
tion in the PFR.
The feed to the reactor as well as the construction material and the temperature at the reactor inlet are con-
sidered fixed. Therefore, the length of the reactor is the only variable left to optimize. This simplifies the problem
as the length will be the only variable that will affect the outlet conditions and composition.
Important
You should ensure that Excel has the Solver Add-In installed and activated and that the Reactor
Optimization.xls file has the appropriate references (VMGSim COM Interface and SOLVER) activated.
Note: If there is a CallBackMessages worksheet already in the Excel workbook its contents will be deleted
and replaced by the new VMGCallBack messages.
The optimization will run. You can see the progress in the Excel Status bar at the bottom of your window. At the
end of the optimization run the cell containing the optimum length will be selected.
Note: If there is a Profiles worksheet already in the Excel workbook its contents will be deleted and replaced
by the new profiles and plots.
Remember
By using the standard modules you can start developing your program right away. However, you can
always modify the standard modules (VMGCallBack and VMGGlobals) to add extra functionality for
your program.
Global variables
In addition to the global constants and variables declared in the standard modules it is necessary to declare a
few more global constants and modules so they are available to all the subroutines and functions in the pro-
gram.
These declarations can be found in the modOptimize module of the Reactor Optimization.xls VBA project.
We start by defining VBA settings:
Option Private Module '... Public variables available only to this project
Option Explicit '... All variables must be declared
Option Base 0 '... All arrays are zero-based
The following variables are declared in the modOptimize module and later initialized and linked to their respect-
ive Unit Operations in the InitializePublicObjects subroutine.
'... We need to keep these as global variables because they need to be "live" for the
Excel Solver
Public gFeed As VMGOPStream '... Represents the Reactor Feed Stream before
the Heater
Public gReactor As VMGUnitOperation '... Represents the PRF Ammonia Reactor
Public gReactorTop As VMGOPStream '... Represents the Feed Stream out of the
Heater into the Reactor
The following variables are used to manipulate the logging capabilities of the program:
'... Logging variables
Public gCBCounter As Long
Public gLogCallBack As Boolean
Public gRecallError As Boolean
Finally, global constants are used to easily interact with the worksheet:
'... Worksheet and Ranges Names
Public Const WS_MAIN As String = "Main"
Public Const WS_PROFILES As String = "Profiles"
Public Const WS_CALLBACK As String = "CallBackMessages"
Public Const RNG_CASEPATH As String = "CasePath"
Public Const RNG_GUESS As String = "InitGuess"
Public Const RNG_OPTIMUM As String = "OptimumLength"
Custom functions
There are three custom functions used in the Main worksheet: xlVMGObjFunc, xlVMGGetValue and
xlVMGGetValues. These functions are located in the modOptimize module of the Reactor Optimization.xls VBA
project. The first of these functions is designed to be the Objective Function for the optimization problem. The
last two functions are designed to pass the reactor length to the simulation case, resolve it and obtain an
updated value for the variable requested.
The xlVMGObjFunc is fairly straightforward. It takes in four arguments and returns the value of the profit func-
tion to maximize:
Public Function xlVMGObjFunc(ByVal Length As Double, ByVal N2Flow As Double, ByVal
FeedT As Double, _
ByVal ReactorTopT As Double) As Double
'----------------------------------------------------------------------------------
-----
' Purpose : Implements the Objective Function to Optimize with the Excel Solver
'
' Arguments:
' Length - Reactor length in [m]
' N2Flow - N2 flow at the reactor outlet in [kmol/h]
' FeedT - Feed gas temperature in [C]
' ReactorTopT - Reacting gas temperature at the reactor outlet [C]
'----------------------------------------------------------------------------------
-----
'
End Function
The xlVMGGetValue function interacts with the simulation case by taking the path of the desired variable and
the value to be set for the reactor length. An optional Boolean can be added as a third argument to indicate if the
function should be calculated every time the worksheet changes or only when any of the arguments change
(default):
Public Function xlVMGGetValue(ByVal objPath As String, ByVal inputVar As Double, _
Optional ByVal GO As Boolean = False) As Double
'----------------------------------------------------------------------------------
-----
' Purpose : Returns the value of the objPath after sending the inputVar to the
Reactor
'
' Arguments:
' objPath - Absolute variable simulation path of the desired variable
' inputVar - Reactor length in [m]
' GO - Boolean to allow automatic calculation of this function
'----------------------------------------------------------------------------------
-----
'
The function starts by setting an error handling procedure and determining if is in calculating mode.
On Error GoTo local_Err
temp = gLogCallBack
gLogCallBack = False '... Can't write to other cells from a custom function
Remember
It is not possible to write anything to any cell from a custom function called within a worksheet cell. If out-
put to a cell is attempted Excel will raise an error. Only the return value of the function can be written to
the cell that called the function.
The function checks that the VMGEngine is running and then gets the Length port of the PFR reactor:
Call PrepareEngine
Since the only variable that can change the results of the simulation is the reactor length its value is compared
against the current value sent to the function (inputVar). If the value is has changed, the new value is sent to the
simulation and the case is resolved:
'... No need for calculation if the Reactor length hasn't changed
If Length.GetValue <> inputVar Then
gVMGEngine.hold
Call Length.SetValue(inputVar)
gVMGEngine.GO
gVMGEngine.Solve
End If
The function is now ready to return the value of the desired variable and set the logging configuration back to its
value before executing the function:
Set var = gVMGEngine.GetVMGObject(objPath)
xlVMGGetValue = var.GetValue
local_Err:
Call gErrorMessage("modOptimize.xlVMGGetValue", Err.Number, Err.Description)
gLogCallBack = temp
End Function
The xlVMGGetValues function is similar to the xlVMGGetValue one. The only difference is that it will take and
index (zero-based) and return the appropriate value for a vector property:
Public Function xlVMGGetValues(ByVal objPath As String, ByVal idx As Long, ByVal
inputVar As Double, Optional ByVal GO As Boolean = False) As Double
'----------------------------------------------------------------------------------
-----
' Purpose : Returns the value of the objPath at the position idx (objPath is a
vector)
' after sending the inputVar to the Reactor
'
' Arguments:
' objPath - Absolute variable simulation path of the desired variable
' idx - Index of the element to be returned (zero-based)
' inputVar - Reactor length in [m]
' GO - Boolean to allow automatic calculation of this function
'----------------------------------------------------------------------------------
-----
'
temp = gLogCallBack
gLogCallBack = False '... Can't write to other cells from a custom function
Call PrepareEngine
local_Err:
Call gErrorMessage("modOptimize.xlVMGGetValues", Err.Number, Err.Description)
gLogCallBack = temp
End Function
VB Test
Purpose
This example contains a test for varied methods and objects in the VMGSim COM Interface. It can be used as
reference for common tasks such as recalling cases, manipulating variables, deleting unit operations.
The files used in this example are located in the (Installation folder)\Documentation\VMG Automation
folder under the following subfolders:
VB6 Examples\MainTest\MainTest.vbp
VB6 Examples\MainTest\MainTest.exe
Description
The source code for example can be opened in Visual Basic 6. It provides a very simple user interface with a but-
ton to run the test and a button to clear the output,
The main method is called BuildSimulation and it is located in the file frmMain.frm. The code begins by creating
a simulation engine and calling a couple of method to show how to clear a case and how to set the active unit
set.
Call LogMessage("")
Call LogMessage(VMGGlobals.RenderVMGObject(Thermo))
Unit operations are created and then a few methods are added in order to inspect the contents of the flowsheet.
This code requires interaction with the VMGOpFlowsheet interface and the VMGObjects interface (list of
objects). See other sections of the manual for a detailed reference of the methods from these interfaces.
For clarity, the rest of the code is not presented here but it may be a useful reference for learning tips and
tricks when working with the VMGSim COM Interface. The finished test is shown in the image below,
Copyright Notice
The copyright in this manual and its associated computer program are the property of Virtual Materials Group,
Inc. All rights reserved.
Both this manual and the associated computer program have been provided pursuant to a License Agreement
containing restrictions on use.
Virtual Materials Group reserves the right to make changes to this manual or its accompanying software without
obligation to notify any person or organization.
No part of this manual may be reproduced, transmitted, transcribed, stored in a retrieval system, or translated
into any other language, in any form or by any means without the prior written consent of Virtual Materials
Group, Inc. 300 - 3553 31 Street NW, Calgary, AB, Canada, T2L 2K7.
Windows95, Windows 98, Windows 2000, Windows XP, Windows NT, Visio and Excel are registered trade-
marks of Microsoft
Sim42 is a registered trademark of the SIM42 Foundation.
Use is made of the following components from SuiteSparse: AMD, BTF, COLAMD, KLU, UMFPACK. SuiteS-
parse is available from http://www.cise.ufl.edu/research/sparse/SuiteSparse/ and the excellent work of Tim
Davis and other authors of the packages is gratefully acknowledged.
The current version used is SuiteSparse v3.2.0, except that UMFPACK v5.0.2 has been substituted, since it is
available under LGPL as opposed to GPL.
The code is compiled and used as a dynamic link library to comply with the terms of the LGPL associated with
some of the packages. A zip file with the source code and build files accompanies this document.
While the license permits free use and modification of the package by anyone, Virtual Materials Group can
provide technical support for the VMGSim simulator only when it is used with the compiled library as supplied,
since any changes to the library behavior may impact the simulator performance in unpredictable ways.
Use is made of the LightOPC server library which is made available thanks to the efforts of enthusiasts from
Lab43. LightOPC is released under the LGLP v.2. license available from: http://www.gnu.org/copyleft/lgpl.html.
Source code from this application can be found in http://www.ipi.ac.ru/lab43/lopc-en.html.
Use is made of the IPOPT numerical library for optimization released as open source under the Common
Public License (CPL, http://www.eclipse.org/legal/cpl-v10.html) thanks to the efforts of people from the
COIN|OR foundation. The source code is available from https://projects.coin-or.org/Ipopt.
VMGSim Contacts
Contacting Virtual Materials Group
Website: www.virtualmaterials.com
Support:
support.ca@virtualmaterials.com
China Europe
International Innotech Inc. Virtual Materials Group Europe, S.L.
Beijing Office Gran Va Carles III, 98, P.10,
Ocean Express, A-1502 08028
66 Xiaguang Li, Chaoyang District Barcelona,Spain
Beijing 100027 China
Tel: +34-93-409-7286
Tel: +86-10-8446-7078
Michele Manzulli
Ricky Hsu michele.manzulli@virtualmaterials.com
ricky@virtualmaterials.com
Support:
support.europe@virtualmaterials.com
Japan Mexico
VMG Japan Corporation AAOP
Akasaka Lions Building 8F Av. Mariano Escobedo #752-1603
1-1-2, Motoakasaka Colonia Nueva Anzures, Mxico D.F. 11590
Hideo Iketani
Tel: +81-3-6721-1857
hideoiktn@virtualmaterials.com
Middle East North Africa
Enterprise Business Solutions W.L.L Process Village
P.O Box: 18384 14c, Road #198, Digla
Farwaniya, Kuwait Maadi, Cairo Egypt
81004
Tel: +20-2519-1282
Mr. Mohammed Farhat
Tel: +965-25770401 Hossam Attia
http://www.ebs-group.net/ hossam.attia@virtualmaterials.com
South Korea United States
CMSI Inc. Virtual Materials Group, Inc. USA
(Suite7, Taeyang21 Bldg., Yeoksam-dong) 17171 Park Row Drive, Suite 273
Houston, TX , USA
Yeoksam-ro, Gangnam-gu, Seoul 135-080, South
Korea 77084
Tel: +1 (281) 944-9902
Fax: +1 (832) 369-7751
Tel: +82-2-2051-2312
Fax: +82-2-2051-2306 Gerald Jacobs
gerald@virtualmaterials.com
Kelly Lee
Andrew Nathan
Kelly.lee@cmsikorea.com andrew@virtualmaterials.com