Professional Documents
Culture Documents
User Unit Operations 1
User Unit Operations 1
User Unit Operations 1
Extn 2.pdf
2 User Unit Operations
Introduction
User unit operations, just like unit operation extensions, allow the
HYSYS user to build a custom unit operation for their simulations. User
unit operations and unit operation extensions differ from each other in
several ways; the most important difference is the location of the
defining code.With a unit operation extension, the defining code exists
outside of the HYSYS simulation in a separate DLL; while the defining
code for a user unit operation is written and exists within the HYSYS
simulation.
User unit operations operate much like any other operation in HYSYS
with one important exception; with these operations, the user must
supply the code that will define their function.
Having the user enter the defining code means that user unit
operations can be used to model operations that are not available with
the normal HYSYS package. It also means that HYSYS users are virtually
unlimited in regards to the amount of customization that they can
introduce into a simulation.
Learning Objectives
By completing this module, you will learn:
Prerequisites
Before beginning this module, you should have some experience with
writing VB compatible code in HYSYS, either with the MLE, user
variables, or user unit operations.
2
User Unit Operations 3
Background
User unit operations and unit operation extensions both offer the
HYSYS user an opportunity to increase the functionality of the HYSYS
program through the addition of custom built unit operations.
User unit operations are often easier to construct and install than unit
operation extensions. For example, user unit operations do not have a
separate EDF file defining the views of the operation. Instead, a generic
interface is used for all user unit operations. The code of the operation
exists within the HYSYS simulation and is saved whenever the
simulation is saved. Although, user unit operations can be exported to a
separate file and imported into another simulation.
One disadvantage of the user unit operation is that the code is not in a
compiled form like it is for extensions. This means that the user unit
operation code can not be distributed without possibly distributing
confidential and proprietary information. Another limitation is that the
Because the defining code for
extensions is complied, it can
views for the user unit operation can not be modified and customized
be freely distributed without like the views for extensions.
any risk of sharing proprietary
or confidential information. On the other hand, a major advantage of the user unit operation, is that
the use of a separate programming environment is not required. The
code is written within the HYSYS program so a separate compiler is not
needed. To write an unit operation extension you will need to use a
separate programming environment like VB or C++.
3
4 User Unit Operations
The Calculate method should be used in this subroutine (and only this
subroutine) to write calculated values back into the simulation. Any
values returned to the simulation via the Calculate method will appear
in black to the HYSYS user.
4
User Unit Operations 5
Workshop
In this workshop, we will create and install a user unit operation that
will model a steam ejector vacuum pump.
The user can either specify information about the motive steam, or
about the suction stream, and the operation will calculate the
remaining parameters.
5
6 User Unit Operations
ActiveObject.Feeds1Name = "Inlet"
ActiveObject.Products1Name = "Outlet"
4. By default, only the first feed nozzle and the first product nozzle
are active. Before we can change the label of the second feed
stream, we need to activate it. Add the following two lines of code
immediately after the two lines entered for step 3.
ActiveObject.Feeds2Active = True
ActiveObject.Feeds2Name = "Motive Steam"
6
User Unit Operations 7
5. The first line of code that must be added will prevent the
subroutine from running if the HYSYS solver is in the middle of a
"forget" pass. Add the following line of code to the Execute
subroutine.
6. The next step in this subroutine will set the stream variables to
reference the correct objects. Complete the partially written code
so that it looks like the following.
7
8 User Unit Operations
8
User Unit Operations 9
10. The first line of code that should be added will check to see if the
operation is set to be "ignored" and exit the subroutine if this is
the case. Add the following line of code to the subroutine.
11. The code that will be entered here will add the following message
to the status bar: "Requires a Feed Stream." This message will be
displayed if there is no feed stream attached to the operation. Add
the following line of code to the subroutine.
Call ActiveObject.AddStatusCondition(slMissingRequiredInformation, 1, _
"Requires a Feed Stream")
12. This step will also print an error message into the status bar. This
time the message should read, "Requires a Motive Steam
Stream." Add the required code to the subroutine. Hint: it looks a
lot like the code for step #11, but the unique identifier in the line
above (the number 1) will have to be different for this error
message (use the number 2).
13. The code that will go here will add another warning message to
the status bar if the motive steam stream does not have enough
water in it. Add the following line of code to the subroutine.
Return to the PFD view and force the operation to resolve by changing
one of the parameters in one of the feed streams. For example, change
the pressure in the steam stream to a different, but similar, value.
9
10 User Unit Operations
Exercise
In this exercise, you are asked to build a working user unit operation
without step-by-step guidance from the instructor.
Completing one of the above options will bring up the Add User Unit
Operation window.
10
User Unit Operations 11
If there have not been any user unit operations added (or imported) to
the simulation before this point, there will be only three options
available to the user: Cancel, Create Type, or Import Type. If a
previously exported user unit operation exists, it could now be
imported; however, we are going to create a new user unit operation
type so select the Create Type button. The following view will appear.
Type the name for the user unit operation here. It is always a good idea
to use a name that will somehow describe the function of the user unit
operation. In this case, enter P-Doubler for the type’s name, and press
the OK button. This will return you to the previous view and HYSYS will
display the newly created type’s name in the Available User Unit
Operations list.
In order to create a new user unit operation, highlight the name of the
newly created type and press the Add button. This will bring up the
User Unit Op view.
From this page you can access the code editor by selecting the Edit
button on the Code page.
11
12 User Unit Operations
The next bit of code should be three local variable declarations for the
stream objects.
Use the IsKnown property to determine if all of these items are defined.
If any one of the five is not defined, then exit the subroutine.
Next, use the Calculate method to set the outlet stream’s pressure at
twice the pressure value of the inlet stream.
12
User Unit Operations 13
Declare three local variables to represent the streams. Hint: see the
second paragraph of the Execute subroutine on the previous page, you
may cut-and-paste the code from there to here.
Next, set the declared variables to reference the proper streams. You
may wish to check to make sure that the streams are valid before you
set the reference.
Use three separate If ... Then statements to display status bar messages
to alert the user to missing streams. Hint: see step #11 in the Workshop
section of this module. Remember that the unique identifier must be
different for each message.
13
14 User Unit Operations
Advanced Users
How will this affect the balance performed at the end of the
Execute subroutine? __________
14