Você está na página 1de 292

VMGSimCOMAutomation v. 9.

5 Manual 1

Welcome to VMGSim COMAutomation


Version 9.5

To view the Table of Contents in Adobe Reader, right click on the left hand column of
the document and select Bookmarks.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 2

Introduction to VMGSim Automation


Introduction to VMGSim Automation
Introduction
The VMGSim COM Automation engine provides a programming interface to interact directly with the process
simulator without VMGSims graphical user interface. It can be used from any COM compliant application such
as Excel (Visual Basic for Applications), Visual Basic and Visual C++.

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.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 3

Coding in Visual Basic or Visual Basic for Applications


The documentation from this manual is based on Visual Basic for Applications such that it can be used in an
Excel spreadsheet. Most examples assume that there is a simulation engine of type VMGMainEngine already
created and ready to run. The variable gVMGEngine is used throughout the examples to refer to an instance of
this engine object and can be created like this,
Dim gVMGEngine as VMGMainEngine
Set gVMGEngine = New VMGMainEngine
All arrays in the property package are zero-based so it is important in all Visual Basic (VB) or Visual Basic for
Applications (VBA) client code to remember to include the following declaration statements at the top of every
form or module.

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 (.).

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 4

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.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 5

Steady State and Dynamics Solvers


VMGSim can run in steady state or dynamics. The steady state is always active by default and the dynamics
engine has to be explicitly activated (special license required).

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.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 6

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

Direct access to main objects


Dim vUn as VMGUnitSystem
Dim vFl as VMGOpFlowsheet
Dim vTh as VMGThermoAdmin

Set vUn = gVMGEngine.UnitSystem


Set vFl = gVMGEngine.RootFlowsheet
Set vTh = gVMGEngine.ThermoAdmin

Interact with cases


Call gVMGEngine.RecallFile(C:\Cases\Case1.vmp)
Call gVMGEngine.ClearCase()
Call gVMGEngine.SaveFile(C:\Cases\Case2.vmp)

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)

Cast it to other interfaces


Dim asObj as VMGObject
Dim asOp as VMGUnitOperation

Set asObj = cool


Set asOp = cool

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 7

Set Var = cool.DeltaP

Set and get values


Var.Value = 10.0
Debug.Print var.Value

Cast it to other interfaces


Dim asObj as VMGObject
Set asObj = Var

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)

When it is casted as a VMGObject, I cannot access


names = asObj.GetCompoundNames()

Dim asOp as VMGUnitOperation


Set asOp = asObj

Now I can access this method.


names = asOp.GetCompoundNames()

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 8

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.

A callback is set up by instantiating a COM interfaces that implements the method,


Public Function PyInfoMessage(msg As Variant, args As Variant, ByVal sMsgType As
String) As Variant
this object is passed to the main engine such that it can be called to notify of events. A return value different than
Null will instruct a steady state simulation to stop solving (assuming it is in the middle of a solve pass).

The code of a callback class may look like this,


Assume this is the content of a class in a file called
VMGCallBack.cls

Public Function PyInfoMessage(msg As Variant, args As Variant, ByVal sMsgType As


String) As Variant

Render the message


Dim renderedMsg as String
renderedMsg = gVMGEngine.RenderMessage(msg, args)

Do something with it
MsgBox renderedMsg

End Function

The callback would be set up by doing,


Dim gVMGEngine as VMGMainEngine
Dim gCallBack as VMGCallBack

Public Sub CreateEngine(withDynamics as Boolean)

Set gVMGEngine = New VMGMainEngine


Set gCallBack = New VMGCallBack

Call gVMGEngine.SetCallBackCOMObject(gCallBack, "CB")

If withDynamics Then
Call gVMGEngine.AddDynamicsSupport2
End If

Exit Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 9

A sample program of a full simulation could look like this,


Dim gVMGEngine as VMGMainEngine
Dim gCallBack as VMGCallBack

Public Sub TestSimulation()


Instantiate the engine
Set gVMGEngine = New VMGMainEngine
Set up the callback
Set gCallBack = New VMGCallBack
Call gVMGEngine.SetCallBackCOMObject(gCallBack, "CB")

'... Define the SI unit set


gVMGEngine.UnitSystem.ActiveUnitSet = "SI"

'... Set up the thermo


Dim Thermo As VMGThermoCase
Dim arrCompounds()

Set Thermo = gVMGEngine.ThermoAdmin.AddThermoCase("Th1", _


eAdvancedPengRobinson)
arrCompounds = Array("METHANE", "ETHANE", "PROPANE")
Call Thermo.AddCompounds(arrCompounds)

'... Add some Unit Operations


Dim Feed As VMGOPStream
Dim Product As VMGOPStream
Dim Cooler As VMGOpCooler
Dim Flsht As VMGOpFlowsheet

Set Flsht = gVMGEngine.RootFlowsheet


Set Feed = Flsht.AddMaterialStream("S1")
Set Cooler = Flsht.AddUnitOp(eCooler, "C1")
Set Product = Flsht.AddMaterialStream("S2")

'... Connect
Call Cooler.InPort.ConnectTo(Feed)
Call Cooler.Outport.ConnectTo(Product)

'... Add specifications


Feed.T = 20 'C
Feed.P = 101.325 'kPa
Feed.MoleFlow = 100 'kgmole/h
Feed.Fraction.Values = Array(0.1, 0.2, 0.3, 0.2, 0.2)
Cooler.DeltaP = 10 'kPa
Call Cooler.OutQ.SetValue(100000#, "Btu/h")

Exit Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 10

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.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 11

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.

2. In the VB editor, click Tools -> References...

3. Look for VMGSim COM Interface in the list of Available References, select the VMGSim DLL and
press OK

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 12

At this point you are ready to start coding with the VMGSim Interface. The main engine can be created as
shown below,

Global gVMGEngine As VMGMainEngine 'The engine

Public Sub CreateEngine()


Set gVMGEngine = New VMGMainEngine
End Sub

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 Base Project


The file for this example is located in the (Installation folder)\Documentation\VMG Automation folder
under the following subfolders:

Excel Examples\BaseProject\BaseProject.xls

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 13

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.

How to use this example


This example is ready to be used out of the box. There are two buttons in the worksheet called SimTest.
These are used to control the program.

Running the Program


Click on the Run Test button located in the SimTest worksheet. The program will then run its course and dis-
play information for you as it completes tasks. The Status area will display the output of the simulation, and the
Last Message area is a display of the last message that is in the Status area.

To clean up the worksheet and start again, simply press the Clear button.

Understanding the code


Global variables
We will start by declaring some global variables that will be used throughout the program. These declarations
can be found in the VMGGlobals module of the BaseProject.xls VBA project.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 14

We start by defining VBA settings:


Option Explicit 'All variables must be declared
Option Base 0 'All arrays are zero-based
The VMGEngine will be a global, such that once initialized we can use it throughout the program.
Global gVMGEngine As VMGMainEngine 'The engine
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 withDynamics As Boolean = False, _
Optional optimizeCode As Boolean = True, _
Optional 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

On Error GoTo localErr

doNew = False

'... Decide if I should create it, or it is already running


If gVMGEngine Is Nothing Then
doNew = True
Else
If gVMGEngine.IsValidIface() Then
'... If it is already there, then just clear the case
Call gVMGEngine.ClearCase
Else
doNew = True
End If
End If

If doNew Then
'... Create a new instance of the engine
Set gVMGEngine = New VMGMainEngine

'... Activate code optimization in steady state to converge


recycls faster.
If optimizeCode Then Call gVMGEngine.Eval("optimizecode 1")

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 15

'... Log commands to *.tst file


If logCommands Then
gVMGEngine.AutoLogCommands = True
Else
gVMGEngine.AutoLogCommands = False
End If

End If

'... Create and set the callback


Set gCallBack = New VMGCallBack
Call gVMGEngine.SetCallBackCOMObject(gCallBack, "CB")

'... Activate dynamics engine


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.Description, vbCritical, "VMG Engine Error")

End Sub

Setting up and running the case


The following can be done anywhere, but for this example the code was written in the SimTest worksheet.
The following sub routine initializes the engine, sets up a few unit operations, connects them and solves them.
Private Sub BuildSimulation()

Dim Thermo As VMGThermoCase


Dim arrCompounds()
Dim Feed As VMGOPStream
Dim Product As VMGOPStream
Dim Cooler As VMGOpCooler
Dim Flsht As VMGOpFlowsheet

'... Start a new VMGSim engine


'... This calls the sub routine that we created in VMGGlobals
Call CreateEngine

'... Define the SI unit set


gVMGEngine.UnitSystem.ActiveUnitSet = "SI"

'... Set up the thermo


Set Thermo = gVMGEngine.ThermoAdmin.AddThermoCase("RootThermo2",_
eAdvancedPengRobinson)

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 16

arrCompounds = Array("METHANE", "ETHANE", "PROPANE", "n-BUTANE",_


"ISOBUTANE")
Call Thermo.AddCompounds(arrCompounds)

'... Add some Unit Operations


Set Flsht = gVMGEngine.RootFlowsheet
Set Feed = Flsht.AddMaterialStream("S1")
Set Cooler = Flsht.AddUnitOp(eCooler, "C1")
Set Product = Flsht.AddMaterialStream("S2")

'... Connect
Call Cooler.InPort.ConnectTo(Feed)
Call Cooler.Outport.ConnectTo(Product)

'... Add specifications


Feed.T = 20 'C
Feed.P = 101.325 'kPa
Feed.MoleFlow = 100 'kgmole/h
Feed.Fraction.Values = Array(0.1, 0.2, 0.3, 0.2, 0.2)
Cooler.DeltaP = 10 'kPa
Call Cooler.OutQ.SetValue(100000#, "Btu/h")

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.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 17

Visual Basic 6 and the VMGSim COM Interface


This section will talk about how to get started with the VMG COM Interface using Microsoft Visual Basic 6.
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
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,

Global gVMGEngine As VMGMainEngine 'The engine

Public Sub CreateEngine()


Set gVMGEngine = New VMGMainEngine
End Sub

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.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 18

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 Base Project


The file for this example is located in the (Installation folder)\Documentation\VMG Automation folder
under the following subfolders:

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.

How to use this example


This example is ready to be used out of the box. There are two buttons in the main form. These are used to con-
trol the program.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 19

Running the Program


Click on the Run Test button from the main form. The program will then run its course and display information
for you as it completes tasks. The status of the simulation is output to a Text Box in the main form.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 20

To clean up the status messages and start again, simply press the Clear button.

Understanding the code


Global variables
We will start by declaring some global variables that will be used throughout the program. These declarations
can be found in the module VMGGlobals.bas module of the BaseProject.vbp project.
We start by defining VB settings:
Option Explicit 'All variables must be declared
Option Base 0 'All arrays are zero-based
The VMGEngine will be a global, such that once initialized we can use it throughout the program.
Global gVMGEngine As VMGMainEngine 'The engine
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 withDynamics As Boolean = False, _
Optional optimizeCode As Boolean = True, _
Optional logCommands As Boolean = True)
'------------------------------------------------------------------
' Purpose : Starts a new instance of the VMGEngine and
hooks the CallBack
'
' Arguments:

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 21

' 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

On Error GoTo localErr

doNew = False

'... Decide if I should create it, or it is already running


If gVMGEngine Is Nothing Then
doNew = True
Else
If gVMGEngine.IsValidIface() Then
'... If it is already there, then just clear the case
Call gVMGEngine.ClearCase
Else
doNew = True
End If
End If

If doNew Then
'... Create a new instance of the engine
Set gVMGEngine = New VMGMainEngine

'... Activate code optimization in steady state to converge


recycls faster.
If optimizeCode Then Call gVMGEngine.Eval("optimizecode 1")

'... Log commands to *.tst file


If logCommands Then
gVMGEngine.AutoLogCommands = True
Else
gVMGEngine.AutoLogCommands = False
End If

End If

'... Create and set the callback


Set gCallBack = New VMGCallBack
Call gVMGEngine.SetCallBackCOMObject(gCallBack, "CB")

'... Activate dynamics engine


If withDynamics Then
If Not gVMGEngine.HasDynamicsSupport() Then
Call gVMGEngine.AddDynamicsSupport2
End If
End If

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 22

Exit Sub

localErr:
Call MsgBox("Error while trying to create simulation engine." & _
vbCrLf & Err.Description, vbCritical, "VMG Engine Error")

End Sub

Setting up and running the case


The following code can be written anywhere, but for this example the code was written in the frmMain form. The
following sub routine initializes the engine, sets up a few unit operations, connects them and solves them. For
clarity, the code shown here does not include the lines to log messages into the Text Box.
Private Sub BuildSimulation()

Dim Thermo As VMGThermoCase


Dim arrCompounds()
Dim Feed As VMGOPStream
Dim Product As VMGOPStream
Dim Cooler As VMGOpCooler
Dim Flsht As VMGOpFlowsheet

'... Start a new VMGSim engine


'... This calls the sub routine that we created in VMGGlobals
Call CreateEngine

'... Define the SI unit set


gVMGEngine.UnitSystem.ActiveUnitSet = "SI"

'... Set up the thermo


Set Thermo = gVMGEngine.ThermoAdmin.AddThermoCase("RootThermo2",_
eAdvancedPengRobinson)
arrCompounds = Array("METHANE", "ETHANE", "PROPANE", "n-BUTANE",_
"ISOBUTANE")
Call Thermo.AddCompounds(arrCompounds)

'... Add some Unit Operations


Set Flsht = gVMGEngine.RootFlowsheet
Set Feed = Flsht.AddMaterialStream("S1")
Set Cooler = Flsht.AddUnitOp(eCooler, "C1")
Set Product = Flsht.AddMaterialStream("S2")

'... Connect
Call Cooler.InPort.ConnectTo(Feed)
Call Cooler.Outport.ConnectTo(Product)

'... Add specifications


Feed.T = 20 'C
Feed.P = 101.325 'kPa

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 23

Feed.MoleFlow = 100 'kgmole/h


Feed.Fraction.Values = Array(0.1, 0.2, 0.3, 0.2, 0.2)
Cooler.DeltaP = 10 'kPa
Call Cooler.OutQ.SetValue(100000#, "Btu/h")

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.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 24

Visual Basic 2008 and the VMGSim COM Interface


This section will describe how to get started with the VMGSim COM Interface using Microsoft Visual Basic
2008. It begins by first covering basic topics such as setting up the project in the development environment and
how to add a reference to the VMGSim engine. The latter part includes instructions on how the Base Project
example was developed and how to use it as a starting point for new projects.

Microsoft .NET Framework


The .NET Framework is a component that allows building and running applications that are safer, consistent,
robust and more efficient. It is comprised of two main components: the Common Language Runtime (CLR) and
the .NET Framework Class Library. For more information about the .NET Framework please refer to the
Microsoft web site (http://www.microsoft.com/NET/).

Visual Studio 2008 Editions


The Visual Studio 2008 development system is available in several editions. Each of these editions builds on
the previous one to offer more tools for the development of software. In this guide the focus will be on the
Express Edition. Visual Basic 2008 Express Edition is free and is available for download at the Microsoft web
site (http://www.microsoft.com/express/vb/Default.aspx).

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.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 25

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.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 26

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,

Imports VMGMasterInterface '... Make the VMGSim COM Interface available

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 27

Public gVMGEngine As VMGMainEngine '... The VMGSim engine

Public Sub CreateEngine()


gVMGEngine = New VMGMainEngine
End Sub

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.

VB2008 Base Project


The file for this example is located in the (Installation folder)\Documentation\VMG Automation folder
under the following subfolders:
VS2008 Examples\VB\BaseProject\BaseProject\BaseProject.vbproj

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.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 28

How to use this example


This example is ready to be used out of the box. There are two buttons in the main form. These are used to con-
trol the program.

Running the Program


Click on the Run Test button from the main form. The program will then run its course and display information
for you as it completes tasks. The status of the simulation is output to a Text Box in the main form.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 29

To clean up the status messages and start again, simply press the Clear button.

Understanding the code


Global variables
We will start by declaring some global variables that will be used throughout the program. These declarations
can be found in the VMGGlobals.vb module of the BaseProject.vbp project.
We start by defining VB settings:
Option Explicit On '... Force variable declaration
Imports VMGMasterInterface '... Make the VMGSim COM Interface available

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)
'-----------------------------------------------------------------------------------
----

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 30

' 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

On Error GoTo localErr

doNew = False

'... Decide if I should create it, or it is already running


If gVMGEngine Is Nothing Then
doNew = True
Else
If gVMGEngine.IsValidIface() Then
'... If it is already there, then just clear the case
Call gVMGEngine.ClearCase()
Else
doNew = True
End If
End If

If doNew Then
'... Create a new instance of the engine
gVMGEngine = New VMGMainEngine

'... Activate code optimization in steady state to converge recycles faster.


'... It MUST run as "optimizecode 0" for now (optimizecode breaks .NET com-
patibility)
'If optimizeCode Then Call gVMGEngine.Eval("optimizecode 1")

'... Log commands to *.tst file


If logCommands Then
gVMGEngine.AutoLogCommands = True
Else
gVMGEngine.AutoLogCommands = False
End If

End If

''... Create and set the callback


gCallBack = New VMGCallBack
gVMGEngine.SetCallBackCOMObject(gCallBack, "CB")

'... Activate dynamics engine

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 31

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

Setting up and running the case


The following code can be written anywhere, but for this example the code was written in the frmMain form. The
following sub routine initializes the engine, sets up a few unit operations, connects them and solves them. For
clarity, the code shown here does not include the lines to log messages into the Text Box.
Note that the AddCompounds() method of the ThermoCase cannot accept the .NET String type. Instead we
have to cast the array of Strings as an Object.

Private Sub BuildSimulation()


'----------------------------------------------------------------------------------
-----
' Sample simulation run. Add thermo, adds unit ops and solves them.
'----------------------------------------------------------------------------------
-----
'

Dim Thermo As VMGMasterInterface.VMGThermoCase


Dim arrCompounds() As String
Dim arrComposition() As Double = {0.1, 0.2, 0.3, 0.2, 0.2}
Dim Feed As VMGMasterInterface.VMGOPStream
Dim Product As VMGMasterInterface.VMGOPStream
Dim Cooler As VMGMasterInterface.VMGOpCooler
Dim Flsht As VMGMasterInterface.VMGOpFlowsheet

On Error GoTo localErr

'... Start a new VMGSim engine


Call CreateEngine(withDynamics:=False, optimizeCode:=False, logCommands:=True)

'... Define the SI unit set


gVMGEngine.UnitSystem.ActiveUnitSet = "SI"

'... Set up the thermo


Thermo = gVMGEngine.ThermoAdmin.AddThermoCase("RootThermo2", _
eVMGPropPkgs.eAdvancedPengRobinson)

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 32

arrCompounds = New String() {"METHANE", "ETHANE", "PROPANE", "n-BUTANE",


"ISOBUTANE"}
Call Thermo.AddCompounds(CType(arrCompounds, Object)) '... Must send an Object
to the COM

'... Add some Unit Operations


Flsht = gVMGEngine.RootFlowsheet
Feed = Flsht.AddMaterialStream("S1")
Cooler = Flsht.AddUnitOp(eVMGUnitOpTypes.eCooler, "C1")
Product = Flsht.AddMaterialStream("S2")

'... Connect
Call Cooler.InPort.ConnectTo(Feed)
Call Cooler.Outport.ConnectTo(Product)

'... Add specifications


Call Feed.T.SetValue(20) 'C
Call Feed.P.SetValue(101.325) 'kPa
Call Feed.MoleFlow.SetValue(100) 'kgmole/h
Call Feed.Fraction.SetValues(arrComposition)
Call Cooler.DeltaP.SetValue(10) 'kPa
Call Cooler.OutQ.SetValue(100000.0#, "Btu/h")

'... Look at some results


Call LogMessage(VMGGlobals.RenderVMGObject(Feed.InPort))
Call LogMessage(VMGGlobals.RenderVMGObject(Product.InPort))

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.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 33

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> AddDynamicsSupport(Optional <Boolean> StdAlone Default Value =


False, Optional <long> isvisible Default Value = 0)
Deprecated. Use AddDynamicsSupport2 instead.

<Long> AddDynamicsSupport2()
Adds dynamics support to the simulation case.

<String> Get AppTitle()


Returns the applications title.

<Boolean> 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.

Let AutoLogCommands(<Boolean> val)


Sets the mode for logging the Commands. True when the Commands will be Auto Logged.

<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.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 34

<Boolean> CanSetValueInDynamics2(<String>path, <Variant>value, <Long>-


calcStatus, Optional <Boolean> ignIntegRunning Default Value = False)
Returns a Boolean with the value of True if the variable value is allowed to change.

CleanUp()
Cleans up the main engine.

<Long>ClearCase()
Clears the current case. It is equivalent to creating a new case.

<ConfigOpDef> Get ConfigOpDefbyObjectType(<String> objType)


Returns the configuration definition object of the specified unit operation type.

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.

<Boolean> Get EnableVisibleObjects()


Returns a Boolean with the value of True when dialog boxes are allowed to be displayed.

Let EnableVisibleObjects(<Boolean> vis)


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.

<Variant> Eval(<String> rawCmd)


Evaluates Command Line Interface statements.

<Variant> Get FlowsheetsList()


Returns an array with the flowsheets in the active case.

<Variant> GetCompoundNames(<VMGObject> obj)


Returns an array with the compound names associated to the Object.

<String> GetFreeName(<String> parentPath, <String> baseName, <Variant>


knownList, Optional <Boolean> forceEnum Default Value= True)
Returns a name based on the given name but that is not currently used.

<VMGHistorian> GetHistorian()
Returns the historian object.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 35

<VMGIntegrator> GetIntegrator(Optional <String> flPath Default Value = )


Returns the integrator attached to the flowsheet of the specified path.

<VMGScheduler> GetScheduler(<String> schedPath)


Returns the scheduler of the specified path.

<VMGVariable> GetVMGVariable(<String> path)


Returns a VMGVaribale of the specified path.

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.

<Long> Get IntegRunningCount()


Returns the number of integrators currently running.

<Boolean> Get IsIntegratorRunning()


Returns a Boolean with the value of True if there is an integrator running.

<Boolean> Get IsOnHold()


Returns a Boolean with the value of True if the solver is on hold.

LogCommands(<String> path, Optional <Boolean> append Default Value = True)


Stores the command line statements in the specified path.

LogOutput(<Boolean> activate, <String> filePath)


Specifies a file where all the callback messages are going to be saved.

LogStringToFile(<String> txt, Optional <String> fileName Default Value= "C:\tem-


p\temp.txt", Optional <String> mode Defaut Value = "a", <Boolean> Optional
addCarriageReturn Default Value = True, Optional <Boolean> onlyInDebugMode
Default Value = True)
Logs a string in a specified file.

<Variant> Get PropertyOrderList()


Returns an array with the properties list.

ReadScript(<String> path)
Reads and executes a script file.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 36

<Long> RecallFile(<string> fileName)


Recalls the specified simulation case.

RecoverDynSnapshot(<String> path)
Recovers the previously stored dynamics state.

<Long> RemoveDynamicsSupport()
Removes dynamics support from the simulation case.

<Variant> RenderMessage(<Variant> msg, <Variant> args)


Sends a message to the simulation.

<String> ReturnValidName(<String> name)


Returns a valid name based on the given name; removes not supported characters.

<VMGOpFlowsheet> Get RootFlowsheet()


Returns the Main Flowsheet.

SaveDynSnapshot(<String> path)
Stores the dynamics state of the flowsheet specified by the path.

<Long> SaveFile(<String> fileName)


Saves the simulation case with the given name.

SetCallBackCOMObject(<Object> obj, <String> name, Optional <Long> idx Default


Value = -1)
Sets a call back object and prepares it to receive messages.

<Variant> Solve()
Initializes the solver sequence.

<Long> Get SolverState()


Returns the solver state; 1 running, 0 on hold.

Let SolverState(<Long> theState)


Sets the solver state; 1 starts solver, 0 stops solver.

<VMGThermoAdmin> Get ThermoAdmin()


Returns the Thermo Administrator object.

<VMGUnitSystem> Get UnitSystem()


Returns the unit system object.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 37

<String> Get UserDataPath()


Returns the path of the folder where the user information is stored.

Let UserDataPath(<String> path)


Sets the path of the folder where the user information is stored.

<VMGUtilLibrary> Get UtilLibrary()


Returns the utility library object as VMGUtilLibrary.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 38

AddDynamicsSupport
Deprecated. Use AddDynamicsSupport2 instead.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 39

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 40

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 41

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 42

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 43

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 44

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 45

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

Example2 Render Object:


Public Sub test()
Dim cmd As String
Dim retVal As Variant
cmd = "/H1.DeltaP"
retVal = gVMGEngine.Eval(cmd)
End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 46

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 47

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 48

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 49

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 50

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 51

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 52

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 53

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 54

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 55

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 56

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 57

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 58

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 59

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 60

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 61

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 62

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 63

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 64

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 65

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 66

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 67

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 68

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 69

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 70

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 71

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 72

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 73

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 74

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 75

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 76

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 77

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 78

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 79

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 80

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 81

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 82

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 83

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 84

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 85

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 86

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 87

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

Typical CallBack Class VBA Code:


Option Explicit

Private myIgnoreColl As New Collection

'Common msg keys...


Private Const SOLVED_SIM As String = "SimComNotifySolved" 'Steady state simulation
finished a solve pass
Private Const DYNSTART As String = "DYNStart" 'Dynamics integrator star-
ted running
Private Const DYNSTEP As String = "DYNStep" 'Dynamics integrator step
notify
Private Const DYNSTOP As String = "DYNStop" 'Dynamics integrator
stopped

'Message type constants


Private Const INFO_MSG As String = "Info"
Private Const WARN_MSG As String = "Warning"
Private Const ERR_MSG As String = "Error"

Public Function PyInfoMessage(msg As Variant, args As Variant, ByVal sMsgType As


String) As Variant

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 88

'----------------------------------------------------------------------------------
-----
' 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

On Error GoTo localErr

'... Check if it is an ignored message


On Error Resume Next
ignStr = ""
ignStr = myIgnoreColl.Item(CStr(msg))
If Not ignStr = "" Then Exit Function

'... Reactivate the error handling


On Error GoTo localErr

'... Render the message and log it


renderedMsg = gVMGEngine.RenderMessage(CStr(msg), args)
'Call VMGGlobals.LogMessage(renderedMsg)
If gDebugMsgs Then Debug.Print renderedMsg

'... Let it process other events


DoEvents

'... Extra processing based on the msg can be added here


If msg = "CMDRecallError" Then
'... Activate this flag
gRecallError = True

ElseIf msg = "CMDFinishedRecall2" Then


'... Clear this flag
gRecallError = False
End If

'...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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 89

localErr:
'... No error handling for now

End Function

Private Sub Class_Initialize()


'----------------------------------------------------------------------------------
-----
' Purpose : Called when the class is instantiated
' Sets up a collection of msg keys to be ignored
'----------------------------------------------------------------------------------
-----
'

'... This is a collection of items to ignore for display


Call myIgnoreColl.Add("1", "DoneForgetting")
Call myIgnoreColl.Add("2", "DYNMsg")
Call myIgnoreColl.Add("3", "ForgettingOp")
Call myIgnoreColl.Add("4", "InnerLoopSummary")
Call myIgnoreColl.Add("5", "ForgotOp")
Call myIgnoreColl.Add("6", "BeforePortDisconnect")
Call myIgnoreColl.Add("7", "UpdatedVector")
Call myIgnoreColl.Add("8", "LoadedHistory")
Call myIgnoreColl.Add("9", "AfterSetValNoReSolve")
Call myIgnoreColl.Add("10", "CMDNotifyBeforeAdd")
Call myIgnoreColl.Add("11", "CMDNotifyBeforeMinus")
Call myIgnoreColl.Add("12", "CMDNotifyBeforeDeleteObj")
Call myIgnoreColl.Add("13", "CMDNotifyBeforeDisconnect")
Call myIgnoreColl.Add("14", "CMDNotifyBeforeReadFile")
Call myIgnoreColl.Add("15", "VMGRecallFixup")
Call myIgnoreColl.Add("16", "VMGBeforeChangeEngine")
Call myIgnoreColl.Add("17", "VMGSimMonitorAddedObject")
Call myIgnoreColl.Add("18", "VMGTakingSnapshot")
Call myIgnoreColl.Add("19", "VMGLoadingSnapshot")
Call myIgnoreColl.Add("20", "VMGClearingSnapshot")
Call myIgnoreColl.Add("21", "VMGForcClSnpsht")
Call myIgnoreColl.Add("22", "DoneSolving")
Call myIgnoreColl.Add("23", "SolvingOpChild")

End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 90

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 91

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.

<Variant> GetInfoValue (<String> key)


An auxiliary method to retrieve a tag value previously set by SetInfoValue.

<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.

<VMGObject> GetVMGObject(<String> name)


Returns the specified VMGObject.

<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.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 92

<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.

<VMGUnitOperation> ParentFlowsheet(Optional <Boolean> inclSubFlsht Default


value= True)
Returns the immediate Flowsheet that the VMGObject belongs to.

SetInfoValue (<String> key, <Object> value, Optional <Boolean> silent = True)


An auxiliary method to set tags to the VMGObject

<VMGThermoCase> ThermoCase()
Returns the Thermo Case associated the VMGObject.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 93

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 94

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 95

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 96

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 97

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

Set vUnit = vOb.ParentFlowsheet(inclSubFlsht)


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 98

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

Set thermal = vOb.ThermoCase()


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 99

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 100

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 101

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 102

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 103

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

Set par = vOb.GetParent()


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 104

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 105

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

Example # 2 name = relative path


Public Sub test()
Dim vTemperature As VMGObject
Dim vStream As VMGObject
Dim name as string

name =In.T
Set vStream = gVMGSimIface.GetVMGObject("/S1")
Set vTemperature = vStream.GetVMGObject(name)
End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 106

Example # 3 name = Absolute Path


Public Sub test()
Dim vTemperature As VMGObject
Dim vStream As VMGObject
Dim name as string

name =/S2.In.T
Set vStream = gVMGSimIface.GetVMGObject("/S1")
Set vTemperature = vStream.GetVMGObject(name)
End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 107

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 108

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 109

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 110

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 111

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.

<VMGObject> Get Item(<Variant> idxOrName)


Returns the object at the specified index (base 0) or with the name provided.

<Variant> Get Names()


Returns an array with the names of the objects.

<Variant> Get ContentsAsArray()


Returns the objects as an array.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 112

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 113

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 114

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 115

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

Return the third item (first item has index 0)


Set theObj = vOb.Item(2)

Return the item called S1


Set theObj = vOb.Item(S1)
End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 116

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(/)

Public Member Functions


<VMGUnitOperation> GetStream(<String> name)
Returns a stream with a specified name.

<VMGUnitOperation> GetUnitOp(<String> name)


Returns a unit operation with a specified name. It can also be a stream.

< VMGUnitOperation> AddUnitOp(<eVMGUnitOpTypes >OpType, <String> name,


Optional <String> initScript Default Value = "")
Adds a unit operation to the flowsheet.

< VMGUnitOperation> AddUnitOpByTypeID(<String> TypeId, <String> name,


Optional <String> initScript Default Value = "")
Adds a unit operation to the flowsheet by defining the unit operation type as a string.

<VMGOpStream> AddMaterialStream(<String> name)


Adds a material stream to the flowsheet.

<VMGOpStreamSignal> AddSignalStream(<String> name)


Adds a signal stream to the flowsheet.

<VMGOpStreamEnergy> AddEnergyStream(<String> name)


Adds an energy stream to the flowsheet.

<VMGCompTrainManager> GetCompressorTrainManager()
Returns the compressor train manager for the flowsheet (dynamics only).

< VMGDepSysManager> GetDepressuringSystemManager()


Returns the depressuring system manager for the flowsheet (dynamics only).

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 117

<String> Get AssistantType()


Returns the type of dynamics assistant being run (Depressuring or Compressor Train).

< VMGOpFlowsheet> CreateFlowsheetInside(<String> flowSheetName)


Creates a flowsheet inside of this flowsheet.

< VMGObjects> GetMatStreams()


Returns a list of material streams that belongs to a flowsheet. This list does not include streams that belong to
nested flowsheets.

< VMGObjects> GetEneStreams()


Returns a list of energy streams that belongs to a flowsheet. This list does not include streams that belong to
nested flowsheets.

<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.

< VMGObjects> GetFlowsheets()


Returns a list of flowsheets that belongs to a flowsheet. This list does not include flowsheets that belong to nes-
ted flowsheets.

< VMGObjects> GetUnitOps(Optional <eVMGUnitOpTypes> OpType = -1)


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.

< VMGObjects> GetContainedUnitOps(Optional <String> filter Default Value = "")


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.

<VMGIntegrator> Get Integrator()


Returns the integrator associated to the flowsheet (dynamics only).

InitFromSteadyState()
Initializes the dynamics engine from values in the steady state engine (dynamics only).

<Variant> Get UnitOpTypesInUse(Optional <Boolean> inclFlshts Default Value =


False, Optional < Boolean> sortList Default Value = False, Optional <String> fil-
terOut Default Value = "")
Returns an array of strings with the unit operation types being used.

TakeSnapshot()
Takes a snapshot of the current values in the dynamics engine.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 118

LoadShapshot(Optional <Double> atTime Default Value = 0#)


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).

ClearShapshot(Optional <Double> atTime Default Value = 0#)


Clears a snapshot from memory.

<Boolean> HasSnaphot(Optional <Double> atTime Default Value = 0#)


Returns a Boolean with a value of True if there is a snapshot of the dynamics engine available.

DeleteUnitOperation(<String> name)
Deletes a unit operation.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 119

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 120

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 121

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 122

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

Add a cooler named C1


Set vOp1 = vFlowsheet.AddUnitOp(eCooler, C1)
Add a cooler with a default DeltaP
Set vOp1 = vFlowsheet.AddUnitOp(eCooler, C1, DeltaP = 10 kPa)
End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 123

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

Add a cooler named C1


Set vOp1 = vFlowsheet.AddUnitOp(Heater.Cooler, C1)
Add a cooler with a default DeltaP
Set vOp1 = vFlowsheet.AddUnitOp(Heater.Cooler, C1, _
DeltaP = 10 kPa)
End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 124

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 125

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 126

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 127

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 128

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 129

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 130

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 131

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 132

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 133

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 134

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 135

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 136

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 137

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 138

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 139

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 140

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 141

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 142

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 143

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 144

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).

<Variant> GetMassFractionValues(<Boolean>Optional internalUnits Default Value


= False)
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).

<Variant> GetStdVolFractionValues(<Boolean>Optional internalUnits Default


Value = False)
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).

<VMGVariable> Get P()


This function returns property Pressure.

<VMGVariable> Get T()


This function returns property Temperature.

<VMGVariable> Get H()


This function returns property Enthalpy.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 145

<VMGVariable> Get S()


This function returns property Entropy.

<VMGVariable>Get Cp()
This function returns property Cp.

<VMGVariable>Get MW()
This function returns property MW.

<VMGVariable> Get VapFrac()


This function returns property Vapor Fraction (mole basis).

<VMGVariable> StdLiqDen()
This function returns property Std Liquid Density.

<VMGVariable> Get Viscosity()


This function returns property Viscosity.

<VMGVariable> Get SurfaceTension()


This function returns property Surface Tension.

<VMGVariable> Get ThermoConductivity()


This function returns property Thermal Conductivity.

<VMGVariable> Get MoleFlow()


This function returns property Molar Flow.

<VMGVariable> Get Q()


This function returns property Energy Flow.

<VMGVariable> Get MassFlow()


This function returns property Mass Flow.

<VMGVariable> Get VolFlow()


This function returns property Actual Volumetric Flow.

<VMGVariable> Get StdLiqVolFlow()


This function returns property Std Liq Volume Flow.

<VMGVariable> Get StdGasVolFlow()


This function returns property Std Gas Volume Flow.

<VMGVariable> Get Fraction()


This function returns property Mole Fraction.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 146

<VMGVariable> Get MassFrac()


This function returns property Mass Fraction.

<VMGVariable> Get StdVolFrac()


This function returns property Std Volume Fraction.

<VMGVariable> Get MoleFlows()


This function returns property Mole Flows.

<VMGVariable> Get MassFlows()


This function returns property Mass Flows.

<VMGVariable> Get StdLiqVolFlows()


This function returns property Std Liq Volume Flows.

<VMGVariable> Get MolarVolume()


This function returns property Molar Volume.

<VMGVariable> Get ZFactor()


This function returns property ZFactor.

<VMGVariable> Get Cv()


This function returns property Cv.

<VMGVariable> Get MassDensity()


This function returns property Mass Density.

<Vaiant> RenderFlashResults2(<Variant>propNames, <Variant>fracNames)


This function returns an array with rendered information of the equilibrium values for all the phases.

<Boolean> Get IsConnToOil()


Returns True if the stream is connected to an oil (assay or blend).

<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.

InitFromObject(<VMGObject> fromObj, <eVMGActiveEngine> takeFromEngine)


Initializes the values in the dynamics object based on another object.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 147

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

Set result = vPort.Cp


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 148

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

Set result = vPort.Cv


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 149

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

Set result = vPort.Fraction


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 150

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

Set result = vPort.H


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 151

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

Set result = vPort.IsConnToOil


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 152

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

Set result = vPort.MassDensity


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 153

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

Set result = vPort.MassFlow


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 154

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

Set result = vPort.MassFlows


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 155

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

Set result = vPort.MassFrac


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 156

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

Set result = vPort.MolarVolume


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 157

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

Set result = vPort.MoleFlow


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 158

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

Set result = vPort.MoleFlows


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 159

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

Set result = vPort.MW


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 160

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

Set result = vPort.P


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 161

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

Set result = vPort.Q


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 162

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 163

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

Set result = vPort.S


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 164

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

Set result = vPort.StdGasVolFlow


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 165

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

Set result = vPort.StdLiqDen


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 166

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

Set result = vPort.StdLiqVolFlow


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 167

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

Set result = vPort.StdLiqVolFlows


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 168

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

Set result = vPort.StdVolFrac


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 169

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

Set result = vPort.SurfaceTension


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 170

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

Set result = vPort.T


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 171

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

Set result = vPort.ThermoConductivity


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 172

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

Set result = vPort.VapFrac


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 173

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

Set result = vPort.Viscosity


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 174

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

Set result = vPort.VolFlow


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 175

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

Set result = vPort.ZFactor


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 176

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 177

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 178

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 179

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

Set result = vPort.GetConnectedOil


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 180

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 181

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 182

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 183

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 184

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 185

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 186

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> Get AvPropPkgNames()


This function returns the names of all the property package available.

<VMGThermoCase> AddThermoCaseByPkgName(<String> name, String


pkgName, Optional <String> liqPkg Default Value = "", Optional <String> solPkg
Default Value = "")
This function adds the thermo case using a property package name.

<VMGThermoCase> AddThermoCase(<String> name, <eVMGPropPkgs> pkg,


Optional <eVMGPropPkgs> liqPkg Defaul Value = -1, Optional <Boolean>
withSolids Default Value = False)
This function adds a thermodynamic case through an enumeration.

<Variant> GetAllSelectedCompoundNames()

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 187

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 188

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 189

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 190

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

Set result = vThermo.ThermoCases


End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 191

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 192

VMGUnitOperation
VMGUnitOperation
Implements the VMGObject interface. The VMGUnitOperation is implemented by every unit operation including
streams and flowsheets.

Public Member Function


<Long> GetCompoundCount()
This function returns the total number of compounds.

<Long> GetCompoundIndex(<String> cmpName)


This function returns the index with the location of the specified compound (base 0).

<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> GetObjsByGroup (<String> groupName)


Returns the objects in the specified group.

<Variant> GetObjsNamesByGroup (<String> groupName)


Returns the names of the objects in the specified group.

<Variant>GetPortNames(Optional <eVMGPortTypes> portType Default value = 31,


Optional <Boolean> useDispName Default value = False )
This returns the names of the Ports.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 193

<Variant>GetParameterNames()
This function returns the Names of all the parameters.

<Variant>GetParameterValue(paramName)
This function returns the value contained within the specified parameter.

<VMGPort> GetPort(<String> name)


This function returns the VMGPort as specified by the name.

<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).

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 194

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 195

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 196

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 197

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 198

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 199

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 200

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 201

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 202

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 203

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 204

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 205

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 206

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 207

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 208

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 209

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 210

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 211

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).

Public Property Let ActiveUnitSet(<String> theSet)


Sets the active unit set to the specified set (e.g. Field, SI, VMG, Refinery, etc).

<Variant> GetUnitSetNames()
Returns the Unit Set Names available.

<Boolean> SupportsSet(<String> setName)


Checks if the specified unit set is supported.

<Variant> GetUnitTypeName(<Long> UnitTypeID)


Returns the Unit Type Name for a given Unit Type ID based on the active unit set.

<Variant> UnitNamesByType(<Long> UnitTypeID)


Returns the Unit Names available for a unit type id. For example, K, F, R, C for unit type id of 1 (Tem-
perature).

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 212

<Variant> FromActiveToInternal(<Long> UnitTypeID, <Variant> val)


Converts a value from the active unit set to the internal unit set for a given unit type ID.

<Variant> FromInternalToUnitName(<Long> UnitTypeID, <String> UnitName,<Vari-


ant> val)
Converts a value from the internal unit set to a specific unit name.

<Variant> FromUnitNameToInternal(<Long> UnitTypeID, <String> UnitName, <Vari-


ant> val)
Converts a value from a specific unit name to the internal unit set.

<Variant> FromActiveToUnitName(<Long> UnitTypeID, <String> UnitName, <Vari-


ant> val)
Converts a value from the active unit set to a specific unit name.

<Variant> FromUnitNameToActive(<Long> UnitTypeID, <String>UnitName, <Vari-


ant> val)
Converts a value from a specific unit name ot the active unit set.

<String> GetActiveUnitName(<Variant> UnitTypeID)


Returns the Active Unit Name for a unit type ID.

<String> GetUnitNameByUnitSet(<String> unitSetName, <Variant> UnitTypeID)


Returns the Unit Name for a specific Unit Set.

<String> GetUnitNameByUnitID(<Long> unitID)


Returns the Unit Name for a specific unit ID.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 213

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

utIDTemp = 2 Temperature unit type id


Val = 10.0
Val = vEng.UnitSystem.FromActiveToInternal(utIDTemp, Val)
End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 214

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

utIDTemp = 2 Temperature unit type id


Val = 10.0
Val = vEng.UnitSystem.FromActiveToUnitName(utIDTemp, C, Val)
End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 215

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

utIDTemp = 2 Temperature unit type id


Val = 10.0
Val = vEng.UnitSystem.FromInternalToUnitName(utIDTemp, C, Val)
End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 216

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

utIDTemp = 2 Temperature unit type id


Val = 10.0
Val = vEng.UnitSystem.FromUnitNameToActive(utIDTemp, C, Val)
End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 217

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

utIDTemp = 2 Temperature unit type id


Val = 10.0
Val = vEng.UnitSystem.FromUnitNameToInternal(utIDTemp, C, Val)
End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 218

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 219

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

utIDTemp = 2 Temperature unit type id


uName = vEng.UnitSystem.GetActiveUnitName(utIDTemp)
End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 220

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

uID = 48 kPa unit id


uName = vEng.UnitSystem.GetUnitNameByUnitID(uID)
End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 221

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

utIDTemp = 2 Temperature unit type id


uName = vEng.UnitSystem.GetUnitNameByUnitSet(Field, utIDTemp)
End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 222

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 223

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 224

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 225

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 226

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 227

VMGVariable
VMGVariable
This interface is implemented by every object that can return a value. It also implements methods to handle vec-
tors and matrices.

Public Member Functions


<Variant> GetValue(Optional <Long> index Default value = 0)
This function returns the value at the appointed index, if no index is specified, the default is index 0

<Variant> GetSSValue(Optional <Long> index Default value = 0)


This function returns the steady state value at the appointed index, if no index is specified, the default is index 0.

<Variant> GetDynValue(Optional <Long> index Default value = 0)


This function returns the dynamic value at the appointed index, if no index is specified, the default is index 0

<Variant> GetValueInternalUnits(Optional <Long> index Default value = 0)


This function returns the internal units at the appointed index, if no index is specified, the default is index 0

SetValues(Values, Optional UnitName As String = "", Optional calcStatus As Long


= gPyFIXED_V)
Puts an array of values into the variable (for vectors only).

<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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 228

<String> GetUnitName()
Same as property UnitName

<Long> GetStatus()
Same as property Status.

ForceResults(<Boolean> theForceResults )
Public Property Let ForceResults(theForceResults As Boolean)

<Boolean> Get 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

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.

<Long> Size() As Long


Returns the size of the vector. This property will return 1 if the variable is a scalar.

<Long> DataType() As Long


This property returns an integer value that represents the type of data contained

<Variant> Get Value()


This property returns the value of the variable

<Variant> Let Value(<Variant> val)


Specifies the value of the variable.

<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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 229

<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> GetValueAtUnits(<String>UnitName, Optional <Long> idx Default value


= 0)
Returns the value of the variable at specific units

<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.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 230

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 231

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 232

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 233

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 234

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 235

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 236

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 237

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 238

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 239

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 240

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

Set result = vVar.Values


End sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 241

GetDataType
Same as property DataType.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 242

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 243

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 244

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 245

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 246

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 247

GetStatus
Same as property Status.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 248

GetUnitName
Same as property UnitName.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 249

GetUnitTypeId
Same as property UnitTypeId.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 250

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 251

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 252

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

Return value in Fahrenheit


unitName = F
value = vVar.GetValueAtUnits(unitName)
End sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 253

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 254

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

Set result = vVar.GetValues


End sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 255

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

Return value in Fahrenheit


unitName = F
values = vVar.GetValuesAtUnits(unitName)
End sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 256

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 257

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 258

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 259

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 260

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

Assign through the Value property


vVar.Value = theVal

Assign directly (default property)


vVar = theVal
End sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 261

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 262

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 263

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 264

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

How to use this example


The following image shows the main worksheet of the Excel file provided.

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 265

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.

Understanding the code


On clicking Start/Stop Integrator for the first time the following sequence of events will occur:
1. The dynamic simulation engine will be created
2. The simulation case will be recalled
3. Unit sets will be assigned
4. The integrator will be initialised in the simulation
5. The input variables will be written to the simulation

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 266

6. The initial output variables will be written to the spreadsheet.


7. The global variable IsInit is set to true to indicate that the simulation has been successfully recalled.
8. Steps 5 and 6 will be repeated
9. The integrator will be started and run for a pre-determined number of steps
10. The spreadsheet will be updated
11. Steps 9 and 10 will be repeated until the button Start/Stop Integrator is pressed or until the integ-
rator stop time is reached
On clicking Start/Stop Integrator to stop the integrator the following sequence of events will occur:
12. The integrator will be stopped
13. The spreadsheet will be updated
The simulation can be run from its stopped position by clicking Start/Stop Integrator to re-start the integrator.
The above sequence will be initialised at step 8
The button Start/Stop Integrator uses the global variable IsInit to determine if the case has been successfully
recalled. If IsInit is false, the function InitiateSimulation is called. If IsInit is true and the integrator is not run-
ning, the sub routine RunSimulation is called. If IsInit is true and the integrator is running the integrator is
stopped.
Private Sub BtnStartIntegrator_Click()
'-------------------------------------------------------------------------------------
--
'...Toggle the Integrator
'-------------------------------------------------------------------------------------
--

Dim path As String

'... Enable messages to be dumped to the "Immediate Window"


gDebugMsgs = True

'... Grab the Case file path defined in a range called CasePath
path = Range(RNG_CASE).Value()

'... Recall the case when needed


If Not IsInit Then
IsInit = InitiateSimulation(path)
End If

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 267

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.

Public Function InitiateSimulation(ByVal CasePath As String) As Boolean


'-------------------------------------------------------------------------------------
--
'Display initial simulation values before running integrator
'
'Arguments:
'CasePath: with the case being processed
'
'Returns True if the simulation case was successfully recalled
'-------------------------------------------------------------------------------------
--

Dim unitSet As String


Dim wksht As Worksheet
Dim intData As Variant
Dim vVar As VMGVariable
Dim units As String

On Error GoTo LocalErr

Call ClearOutput

Call LogMessageToWksht("Creating simulation engine")


Call CreateEngine(withDynamics:=True, optimizeCode:=True, logCommands:=True)

'... Recall case


gRecallError = False '... Clear this flag
Call ChDir(ActiveWorkbook.path) '... Enable relative paths
Call gVMGEngine.RecallFile(CasePath)
If gRecallError Then
'... Error occured while recalling. Quit
MsgBox "Failed recalling case:" & vbCrLf & CasePath
InitiateSimulation = False
Exit Function
End If

Set wksht = GetCSInputWorksheet()

'... Set unit set


unitSet = wksht.Range(RNG_UNITS).Value
If unitSet <> "" Then
gVMGEngine.UnitSystem.ActiveUnitSet = unitSet
End If

'... Set integrator


intData = Range(RNG_INTSTEP).Value
units = Range(RNG_INTSTEP).Offset(0, -1).Value
Set vVar = gVMGEngine.RootFlowsheet.GetVMGObject("/Integrator.IntegratorTime")
Call vVar.SetValue(intData, units)
intData = Range(RNG_STOP).Value
units = Range(RNG_STOP).Offset(0, -1).Value
Set vVar = gVMGEngine.RootFlowsheet.GetVMGObject("/Integrator.StopTime")

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 268

Call vVar.SetValue(intData, units)

'...Write Excel input specifications to the Simulation case


Call UpdateSimInputs

'...Write simulation results to Excel


Call UpdateResults

Call LogMessageToWksht("Loaded Initial Dynamic Output Values")

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.

Public Sub RefreshFromMessage(msg As Variant, args As Variant, ByVal sMsgType As


String)
'-------------------------------------------------------------------------------------
--
' Purpose: Evaluates 'msg' to determine simulation events
'-------------------------------------------------------------------------------------
--

Dim renderedMsg As String


Dim integCount As Range

Set integCount = Range(RNG_INTSTEP)

renderedMsg = gVMGEngine.RenderMessage(CStr(msg), args)

If msg = "DYNStep" Then


'...Upate output variables in Excel (UPDATE controls integrator steps per update)
stepCount = stepCount + 1
If stepCount / UPDATE = Int(stepCount / UPDATE) Then
Call UpdateResults
'... Update integrator time in Excel
integCount = gVMGEngine.ActiveIntegrator.integtime
End If
End If

'... 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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 269

'... Update integrator time in Excel


integCount = gVMGEngine.ActiveIntegrator.integtime
End If

'... write info to main worksheet


Call LogMessageToWksht(renderedMsg)

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.

Private Sub WorkSheet_SelectionChange(ByVal Target As Range)

'-------------------------------------------------------------------------------------
--
'...Detect any changes to input variables and update the simulator
'-------------------------------------------------------------------------------------
--

Dim intData As Variant


Dim vVar As VMGVariable
Dim units As String

On Error GoTo LocalErr

'...Restrict event trap to input variables while the integrator is running


If Target.Column = 3 Then
If gVMGEngine.RootFlowsheet.Integrator.IsRunning Then
'...Write new specification to simulation
Call UpdateSimInputs
End If
End If

'...Restrict event trap to integrator stop time.


'...The Event Capture triggers the condition when the cell is selected.
'...Therefore, the target cell has been offset to capture the event when return is
pressed.
If Target.Address = Range(RNG_STOP).Offset(1, 0).Address Then
intData = Range(RNG_STOP).Value
units = Range(RNG_STOP).Offset(0, -1).Value
Set vVar = gVMGEngine.RootFlowsheet.GetVMGObject("/Integrator.StopTime")
Call vVar.SetValue(intData, units)
Call LogMessageToWksht("Integrator Stopped")
End If

LocalErr:
'... No handling for now, just exiting
End Sub

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 270

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).

Excel Case Study


Purpose
This example provides a ready to use Excel spreadsheet that recalls a simulation case and runs the model at
different conditions. The user can change the input variables, the output variables and the number of data
points that are run.

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

How to use this example


The following image shows the main worksheet of the Excel file provided.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 271

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 272

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.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 273

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.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 274

Multi Case Stream Summary


Purpose
This Excel application uses VMGSim COM Engine to extract information from material streams from one or
more simulation cases at the same time.

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

Adding a material stream to the report


Adding a material summary to the report requires 3 easy steps

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 275

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.

Adding a property to the report


Adding a material summary to the report requires 2 easy steps

Select a Phase
Select a phase from the phase list

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 276

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.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 277

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

The global settings are read when loading the file,


The Water Frac Phase criteria is used to tag a liquid as heavy or light liquid when only one liquid is present in the
stream

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 278

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:

Excel Examples\Optimization\Reactor Optimization.xls

Cases\Ammonia Synthesis PFR.vmp

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.

How to use this example


This example is ready to be used to run a single-variable optimization search for the Ammonia Synthesis
PFR.vmp case in the VMG Automation folder of your installation directory. The three buttons in the Main
worksheet are used to execute the program.

Important

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 279

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.

Initializing the program


Click on the Initialize Variables button located in the Main worksheet. The program will create an instance of
the VMGSim Engine and then recall the case and prepare all variables to run the optimization.
This will also create a CallBackMessages worksheet where the messages from the VMGCallBack will be
logged.

Note: If there is a CallBackMessages worksheet already in the Excel workbook its contents will be deleted
and replaced by the new VMGCallBack messages.

Running the optimization


After initializing the program click on the Run Optimization button located in the Main worksheet. The pro-
gram will ask you to decide whether to use predefined default Excel Solver settings or to use your own settings
by showing you the Excel Solver dialog box.

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.

Generating profiles and plots


Click on the Generate Profiles button located in the Main worksheet. This will create a worksheet called Pro-
files where the reactor Temperature and Mole Flows will be written. Plots of these profiles will also be created
and configured automatically. When the program finishes these tasks it will present the Profiles worksheet.

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.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 280

Understanding the code


Interacting with the Excel Solver Add-In
Just like any other functionality of Excel the Solver Add-In can be automated through VBA code. However, it
has a specific structure and way to interact with. The major drawback is that it is only possible to set it up, con-
figure it, let it run and wait for the results. In other words, it is not possible to step into the actual optimization
routines to manipulate more advanced features.
The most important thing to keep in mind when designing custom functions that will interact with the Excel
Solver, is that they have to accommodate the Solvers particular calculation sequence. Particularly, when these
custom functions are also interacting with an external COM interface, such as the VMGSim COM Interface.
This means that we should implement a calculation sequence where the objective function (target cell) depends
on values that are defined by custom functions that use the Solvers manipulated value(s).
For this example, the calculation sequence is implemented in the following steps:
1. The Excel Solver will try a value for the reactor length (cell E23) and expect the value of the
Objective function to change (cell E47).
2. The Objective function needs the values of cells E23, E24, E25 and E26 (properties from the
simulation case) to calculate and return a value.
3. Cells E24 through E26 depend on the reactor length (cell E23) as defined by the
xlVMGGetValue and the xlVMGGetValues functions.
4. The Excel Solver can now process the new value for the Objective function and, if necessary, try
a new value for the reactor length, thus starting the sequence again.

Initializing the program


The program uses the standard VMGCallBack class and VMGGlobals module distributed with the Base Project
for Excel and discussed in the Getting Started section of the VMG Automation Manual.
These standard modules allow you to forget about setting up the basic functionality of the VMGSim COM Inter-
face and focus on the development of your program.

Remember

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 281

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.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 282

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]
'----------------------------------------------------------------------------------
-----
'

Dim term2 As Double, term3 As Double


Dim term4 As Double, term5 As Double

term2 = -17000# * N2Flow * 0.7854


term3 = 704.04 * (ReactorTopT + 273.15)
term4 = -699.3 * (FeedT + 273.15)
term5 = -Sqr(34566000# + 2101000000# * Length)

xlVMGObjFunc = 11987700# + term2 + term3 + term4 + term5

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 283

Application.Volatile GO '... Determine if should calculate automatically

Variable declarations and logging configuration follow:


Dim Length As VMGVariable
Dim var As VMGVariable
Dim temp As Boolean
Dim CasePath As String

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

Set Length = gReactor.GetVMGObject("Length")

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

gLogCallBack = temp '... Logging setting back to original


Exit Function

local_Err:
Call gErrorMessage("modOptimize.xlVMGGetValue", Err.Number, Err.Description)
gLogCallBack = temp

End Function

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 284

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
'----------------------------------------------------------------------------------
-----
'

On Error GoTo local_Err

Application.Volatile GO '... Determine if should calculate automatically

Dim Length As VMGPortSignal


Dim var As VMGVariable
Dim temp As Boolean
Dim CasePath As String

temp = gLogCallBack
gLogCallBack = False '... Can't write to other cells from a custom function

Call PrepareEngine

Set Length = gReactor.GetPort("Length")

'... 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

Set var = gVMGEngine.GetVMGObject(objPath)


xlVMGGetValues = var.GetValue(idx)

gLogCallBack = temp '... Logging setting back to original


Exit Function

local_Err:
Call gErrorMessage("modOptimize.xlVMGGetValues", Err.Number, Err.Description)
gLogCallBack = temp

End Function

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 285

Other subroutines and functions


Several other subroutines and functions are used throughout the example program. Some of the most relevant
ones are described below.
The InitializePublicObjects subroutine takes care of creating the VMGEngine, recalling the case and linking the
Unit Operations to the global objects defined in the declarations section of the modOptimize module.
The PrepareEngine subroutine is used in the custom functions to check that the VMGEngine is properly set. If
necessary, it calls the InitializePublicObjects.
The GetVMGOp function takes in a Unit Operation path and returns an object of type VMGUnitOperation which
can then be assigned to a variable declared as any type of Unit Operation.
The RunExcelSolver subroutine loads the default settings for our optimization problem into the Excel Solver
and instructs it to run.
The GenerateProfiles subroutine takes the current optimum length and retrieves reactor profiles to plot them.
The GetPFRProfile function is a custom way of retrieving PFR profiles in an array.
The RenderTemperaturePlot subroutine creates and configures the reactor temperature profile with the values
generated by the GenerateProfiles subroutine.
The RenderFlowsPlot subroutine creates and configures the reactor mole flow profiles with the values gen-
erated by the GenerateProfiles subroutine.

Extending the code


This example case can be used as a starting point to perform any other automation task involving the use of the
Excel Solver Add-In and a VMGSim simulation case.
For instance, the xlVMGGetValue and the xlVMGGetValues could be changed to accept a path and a value to
set instead of just accepting a value and setting it to the predefined path (reactor length).
The most important aspect to remember is that the value(s) the Excel Solver manipulates should trigger the
VMGSim case calculation before the objective function is calculated.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 286

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,

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 287

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.

Dim Thermo As VMGThermoCase


Dim arrCompounds()
Dim Feed As VMGOPStream
Dim Product As VMGOPStream
Dim Cooler As VMGOpCooler
Dim Flsht As VMGOpFlowsheet
Dim vObj As VMGObject
Dim vOp As VMGUnitOperation
Dim tempVar
Dim vVar As VMGVariable
Dim vObjs As VMGObjects

'... Start a new VMGSim engine


Call LogMessage("---- Creating engine... ----")
Call LogMessage("")
Call CreateEngine(withDynamics:=False, optimizeCode:=True, logCommands:=True)

'... Enable errors in visible dialog boxes


'gVMGEngine.EnableVisibleObjects = True

'... Clear case


Call gVMGEngine.ClearCase

'... Define the SI unit set


gVMGEngine.UnitSystem.ActiveUnitSet = "SI"

The code then proceeds to create a new thermodynamic case,


'... Set up the thermo
Call LogMessage("")
Call LogMessage("---- Adding thermodynamics case ----")
Call LogMessage("")

Set Thermo = gVMGEngine.ThermoAdmin.AddThermoCase("RootThermo2", eAd-


vancedPengRobinson)
arrCompounds = Array("METHANE", "ETHANE", "PROPANE", "n-BUTANE", "ISOBUTANE")
Call Thermo.AddCompounds(arrCompounds)

Call LogMessage("")
Call LogMessage(VMGGlobals.RenderVMGObject(Thermo))

'... Test no duplicates allowed


Set vObj = Nothing

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 288

Set vObj = gVMGEngine.ThermoAdmin.AddThermoCase("RootThermo2", eAd-


vancedPengRobinson)
If Not vObj Is Nothing Then
MsgBox "Error when attempting to create a duplicate object", vbCritical
End If

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.

Set Flsht = gVMGEngine.RootFlowsheet

Set Feed = Flsht.AddMaterialStream("S1")


Set Cooler = Flsht.AddUnitOp(eCooler, "C1")
Set Product = Flsht.AddMaterialStream("S2")

'... Test no duplicates allowed


Set vObj = Nothing
Set vObj = Flsht.AddMaterialStream("C1")
If Not vObj Is Nothing Then
MsgBox "Error when attempting to create a duplicate object", vbCritical
End If

'... Test lists of objects


Set vObjs = Flsht.GetUnitOps()
tempVar = vObjs.Names()
Call LogMessage("All unit op names: " & Join(tempVar, ", "))

'... Filter by type


Set vObjs = Flsht.GetUnitOps(eCooler)
tempVar = vObjs.Names()
Call LogMessage("All cooler names: " & Join(tempVar, ", "))

Set vObjs = Flsht.GetUnitOps(eStream_Material)


tempVar = vObjs.Names()
Call LogMessage("All cooler names: " & Join(tempVar, ", "))

'... Different way of grabbing all streams


Set vObjs = Flsht.GetMatStreams()
tempVar = vObjs.Names()
Call LogMessage("All cooler names: " & Join(tempVar, ", "))

'... Non existent type


Set vObjs = Flsht.GetUnitOps(eHeatExchanger)
tempVar = vObjs.Names()
Call LogMessage("All hx names: " & Join(tempVar, ", "))

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 (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 289

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 290

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.

2002-2015 Virtual Materials Group, Inc.

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.

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 291

VMGSim Contacts
Contacting Virtual Materials Group
Website: www.virtualmaterials.com

Australia/New Zealand Canada


Saybry Limited Virtual Materials Group, Inc.
47 Stranolar Drive Alastair Ross Technology Centre
Mt. Roskill Sth. #300, 3553 - 31 Street NW
Auckland 1041 Calgary, AB, Canada T2L 2K7
New Zealand
Tel: 1-403-457-4595
Phone: +64 9 627 3018 Fax: 1-403-457-4637
Support: 1-403-288-3587
Brent Young Toll Free: 1-855-6-VMGSim
saybry@virtualmaterials.com
James van der Lee
james@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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com


VMGSimCOMAutomation v. 9.5 Manual 292

Minato-ku, Tokyo 107-0051 Japan


Javier Sanchez
Norio Takayama Tel: +52 55 5531 9918
Tel: +81-3-6721-1857 arturojavier.sanchez@aaop.com.mx
norio@virtualmaterials.com

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

Copyright (c) 2002-2015Virtual Materials Group, Inc. All Rights Reservedsupport@virtualmaterials.com