You are on page 1of 16

The HYSYS Spreadsheet 1

The HYSYS Spreadsheet

© 1999 AEA Technology plc - All Rights Reserved 1

ADV 4_1.pdf
2 The HYSYS Spreadsheet

Workshop
The HYSYS Spreadsheet is a powerful tool that allows the user to apply
the functionality of Shreadsheet programs to flowsheet modelling. The
Spreadsheet has complete access to all process variables; this allows the
Spreadsheet to be virtually unlimited in its applicability and function.

In this module, the Spreadsheet will be used to calculate the required


orifice area of a Pressure Safety Valve. Unlike the Depressurizing utility,
where the area is an input, the flow will be inputted here and the
Spreadsheet will calculate the required area.

Learning Objectives
After completion of this module, you will be able to:

• Import and export variables to and from the Spreadsheet


• Add complex formulas to the Spreadsheet
• Use the HYSYS Spreadsheet in a wide variety of applications
• Open and run Macro Language Editor programs

Prerequisites
Before beginning this module, you should be able to:

• Add Streams and Unit Operations to the PFD


• Manoeuvre within the HYSYS interface

2
Process Overview
4 The HYSYS Spreadsheet

The HYSYS Spreadsheet


With complete access to all process variables, the Spreadsheet is a very
powerful tool in the HYSYS environment. The power of the Spreadsheet
can be fully realized by the addition of formulas, functions, logical
operators, and basic programming statements.

The Spreadsheet’s ability to import and export variables means that


seamless transfer of data between the Simulation Environment and the
Spreadsheet is a simple matter. Any changes in the Simulation
Environment are immediately reflected in the Spreadsheet, and vice-
versa.

The Spreadsheet has several common applications. For example, the


Spreadsheet can be used to:

• Transfer variables between flowsheet objects.


• Relate the pressure drop in a Heat Exchanger to the flow.
• Perform mathematical operations using variables from the
simulation.

4
The HYSYS Spreadsheet 5

Importing and Exporting Variables


The contents of any cell in the Simulation Environment can be added
to the Spreadsheet. The contents of any Spreadsheet cell can be
exported to any specifiable (blue) cell in the Simulation Environment.
Note that the contents of any Spreadsheet cell cannot be simulationsly
imported and exported.

There are three ways of importing values into the Spreadsheet.

In order for a variable to be • Drag and Drop - Position the cursor over the desired item; then
dragged out of a particular press and hold the right mouse button. Move the cursor over to
view, that view must be "un- the Spreadsheet. Once over the Spreadsheet, the cursor’s
pinned" or non-modal. Click appearance will change to a "bull’s eye" type. Release the right
on the pin to convert the view. mouse button when the "bull’s eye" cursor is over the desired
cell. The specific information about the imported variable will
appear in the Current Cell group.
• Variable Browsing - A variable may also be imported into the
Spreadsheet by placing the cursor on an empty cell in the
Spreadsheet and pressing (and releasing) the right mouse
button. Choose Import Variable from the list that appears, and
select the variable using the Variable Navigator.
• Connections Page - On the Connections page, press the
Add Import button and select the desired variable using the
Variable Navigator. After selecting the variable, choose the
desired cell from the Drop Down list.

Exporting variables from the Spreadsheet into the Simulation


environment is also a simple procedure. The methods for doing this are
very similar.

• Drag and Drop - Position the cursor over the Spreadsheet cell
that is to be exported. Press and hold the right mouse button;
the cursor should now change to the "bulls’ eye" type. Move the
"bull’s eye" cursor over to the desired cell. Release the right
mouse button, the transfer should be completed.
• Variable Browsing - A variable may be exported from the
The value in any Spreadsheet Spreadsheet into the Simulation environment by placing the
cell can be exported, except if cursor on the exportable cell in the Spreadsheet and pressing
it is an imported value. (and releasing) the right mouse button. Choose Export
Formula Result from the list that appears, and select the
desired location for the variable using the Variable Navigator.
• Connections Page - On the Connections page, press the
Add Export button and select the desired variable using the
Variable Navigator. After selecting the variable, choose the
desired cell from the Drop Down list.

5
6 The HYSYS Spreadsheet

Adding Spreadsheet Functions


The HYSYS Spreadsheet has extensive mathematical and logical
function capabilities. Users familiar with common Spreadsheet
programs will immediately recognize the form of the HYSYS functions
as similar to the form used by these other programs.
To view the available HYSYS
functions any time, press the
Function Help button. This All functions in the HYSYS Spreadsheet must be proceeded by either a
view has two pages, Functions "+" or an "@" depending on the type of function. Plus signs (+) are used
and Expressions.
for straight mathematical functions: addition, subtraction,
multiplication, and division. The ampersand (@) is used before special
functions such as logarithmic, trigonometric, and logical functions.

Some examples of the HYSYS functions and their form follow here:

• Addition - uses the "+" sign, e.g. +A1+A2


• Subtraction - uses the "-" sign, e.g. +A1-A2
• Multiplication - uses the "*" sign, e.g +A1*A2
A cell’s numerical value can be
copied to another cell using • Division - uses the "/" sign (not the "\") e.g. +A1/A2
the simple formula, +A1, for • Power - uses the "^" sign, e.g. +A2^4
example.
• Factorial - uses the "!" sign, e.g +A2!
• Square Root - uses the "@SQRT" function, e.g @SQRT(A2)
• Sine, Cosine, and Tangent - use the @sin, @cos, and @tan
functions, e.g @sin(A2). Inverse trigonometric functions are
also available, @asin, @acos, and @atan. Hyperbolic
functions can also be represented in HYSYS, they use the form
@sinh, @cosh, and @tanh.
• Logarithmic Functions - are represented in HYSYS with the
following forms: @ln, @log, and @exp.
• Pi - simply enter "+pi" to represent the number 3.1416....

Parenthesis are mandatory in


many of the advanced HYSYS
functions.
They can also be used to
designate the calculation
order.

6
The HYSYS Spreadsheet 7

Logical Operators
The HYSYS Spreadsheet supports Boolean logic, essentially a true/false
logic. A true statement has a value of 1, and a false statement has a
value of 0. For example, suppose that the cell A1 has a value of 10, and
the cell A2 has a value of 5. If the logical statement +A1<A2 were entered
into cell A3. The cell would display a value of 0 because the logic
statement is false.

The following logical operators can be used in Boolean logic


statements:

• Equal to - uses "==", e.g +A1==A2


• Not Equal to - uses "!=", e.g. +A1!=A2
• Greater than - uses ">", e.g. +A1>A2
• Less than - uses "<", e.g. +A1<A2
• Greater than or Equal to - uses ">=", e.g. +A1>=A2
• Less than or Equal to - uses "<=", e.g. +A1<=A2

IF/THEN/ELSE Statements
The HYSYS Spreadsheet also supports the basic IF/THEN/ELSE
Statement. The form of this statement is:

@if (condition) then (if true) else (if false)


The "else" is not optional here.
An If/Then statement is not
valid in HYSYS. The condition is a logical expression, such as "B1<= 10". The if true
represents what the cell will show if the condition is true; it can be a
number or a formula. The if false represents what the cell will show if
the condition is false; it can also be a number or a formula.

An example of the completed statement follows.

@if (B1<=10) then (B1*2) else (B1/10)

Suppose that the value in cell B1 is 8. What will the IF/


THEN/ELSE Statement shown above calculate? __________

7
8 The HYSYS Spreadsheet

Building the Simulation


In this module, the required orifice area for a Pressure Relief Valve will
be calculated in a manner quite different from the method used in the
Depressurization module. However, the same streams will be used.

Therefore, continue with, or open, the Depressurization case. In this


module the two streams will be combined with a mixer, a flow rate will
be specified and the Spreadsheet will be used to calculate the required
orifice area.

1. Add a Mixer to the PFD. Attach both streams as feed streams and
create a product stream named Comb. Feed.
2. Ensure that the pressure assignment on the mixer is set to "Set
The addition of a V/L
Separator allows the user to Outlet to Lowest Inlet"
calculate orifice areas for both 3. Set the Molar flowrates of both feed streams to 460 kgmole/hr
vapour and liquid streams (1000 lbmole/hr).
separately.
4. Add a V/L Separator to the system, with the feed stream as Comb.
Feed, the vapour product stream as PSV Vapour and the liquid
product stream as PSV Liquid.

The formulas that will be used to calculate the orifice area are based on
API-520. The formula for orifice area for the vapour stream is:

M× T×Z
A V = ------------------------------------------------------------------------
-
C × K d × K b × Kv × P × MW

And the equation for the orifice area required for the liquid flow is:

G × SG
AL = -------------------------------------------------------------------
-
22.8 × K d × K w × Ku × ∆P

8
The HYSYS Spreadsheet 9

The terms in the above equations are defined here:

• AV and AL = the orifice area required for vapour and liquid


flows, respectively, in square inches.
• M = the mass flow of the vapour stream in lb/hr.
• T = the stream temperature in Rankin.
Note that all of the constants
given here are defined in Field • Z = the compressibility factor of the vapour stream.
units. Using SI units without • C = the Vapour Flow constant = 315, for this example.
changing the constants will
• Kd = the Coefficient of Discharge of the orifice = 0.953, for this
give wrong results.
example.
• Kb = the Vapour Flow Correction Factor = 1.0, for this example.
• Kv = the Vapour Flow Factor for variable back pressures, used
with bellows values only = 1.0, in this example.
• MW = the average Molecular Weight of the stream.
• P = the pressure of the stream, in psia.
• G = the actual Volume Flow, in GPM.
• SG = the specific gravity of the liquid stream.
• Delta P = Pressure Drop across the valve, in PSI.
• Kw = the Liquid Flow Factor of variable back pressures, used
with bellows valves only = 1.0, in this example.
• Ku = the Liquid Viscosity Correction Factor = 1.0, in this
The units are accessed through example.
Tools/Preferences on the main
menu bar. Before entering the Spreadsheet, change the unit set to match the units
above. The easiest way to do this is to clone the Field unit set and name
the new set PSV Units. Change the required variables as shown below:

Variable Type Unit

Area in2

Temperature Rankin (R)

Actual Liquid Volume Flow USGPM

9
10 The HYSYS Spreadsheet

Adding and Defining the Spreadsheet


To install the Spreadsheet, choose Add Operation from the Flowsheet
menu and select Spreadsheet. Alternatively, select the Spreadsheet
button from the Object Pallet.
Spreadsheet Button
1. Change the size of the Spreadsheet to 4 columns and 15 rows. The
size of a Spreadsheet is set on the Parameters tab. The default
unit set for the Spreadsheet can also be changed on the
Parameters page. For this exercise, select the default unit set to
be the newly created PSV Units unit set.
2. Labels and constants can be added to the Spreadsheet, so that it
looks like this:

Of course, labels are not


necessary, but as the Spread-
sheet grows, it can become
difficult to remember what
each number represents.

10
The HYSYS Spreadsheet 11

The following variables have to be imported into the Spreadsheet:

In this Cell... Import...

B2 PSV Vapour - Mass Flow

The methods of importing B3 PSV Vapour - Temperature


variables was discussed
previously in this module. B4 PSV Vapour - Phase Z Factor

B7 PSV Vapour - Pressure

B8 PSV Vapour - Molecular Weight

D2 PSV Liquid - Act Liquid Vol. Flow

D3 PSV Liquid - Mass Density

D5 PSV Liquid - Pressure

The following formulas can now be to be added to the Spreadsheet:

In this Cell... Enter...

B12 +(b2*@sqrt(b3)*@sqrt(b4))/
The formulas must be entered (b5*b6*b7*b9*b10*@sqrt(b8))
exactly as they are given here.
A missing parenthesis or * will D4 +d3/62.4
cause an error.
D7 +d5-d6
Cell labels are not case
sensitive. D12 +(d2*@sqrt(d4))/
(22.8*d8*d9*d10*@sqrt(d7))

C14 +b12+d12

11
12 The HYSYS Spreadsheet

The final Spreadsheet should look like this:

What is the total required area of the orifice? __________

Save your case!

12
The HYSYS Spreadsheet 13

Exercise 1
Compare with the Depressurizing
Utility
In this module, and the previous one, depressurizing of a system was
examined. It may not be obvious, but the numbers used in this module
were derived from the previous module. The flow rate used here was
found by averaging the flow rate through the PSV found in the
Depressurizing module. The streams in both modules share the same
composition, the same flow and the same pressures.

Because of the similar nature of these two streams, one would expect
that inputting the orifice area that was found in this module into the
depressurizing utility would yield similar results to those found in the
Depressurization module. Well, let’s try it.

13
14 The HYSYS Spreadsheet

Create a depressurizing utility in the simulation with the following data.


If you need help in finding the locations for these variables return to the
previous module:

In this Cell... Enter... (Field) Enter... (SI)


Use only one unit set through-
out this exercise. If using Field Stream Comb. Feed Comb. Feed
units, enter everything in Field
Vessel Volume 3200 ft3 90 m3
units. If using SI, enter
everything in SI.
Liquid Volume 1800 ft3 51 m3

Wetted Area 62,000 in2 40 m2

Mode Adiabatic Adiabatic

Relief Pressure 435 psia 3000 kPa

Depress. Time 900 seconds 900 seconds

Final Pressure 14.7 psia 102 kPa

Press. Steps 100 100

Isentropic Efficiency 25 % 25 %

Vessel Spec Heat 25 BTU/lb-F 100 kJ/kg-C


C1 is equal to the Orifice
constant when working with Vessel Mass 13230 lb 6000 kg
Field units, and 2.62 * the
Orifice constant when Valve Equation General General
working in SI. This applies to
General Valves only. C1 0.953 2.5
Remember that Gc is always
32.17 when working with C2 0.5 0.5
Field units, and 1 when
Gc 32.17 1
working with SI.
Av 0.00886 ft2 0.00082 m2

Valve Rate Units lb/hr kg/hr

Upstream Pressure Units lbf/ft2 kPa

14
The HYSYS Spreadsheet 15

Calculate the utility and move to the Plots page, select the Pressure
radio button.

What final pressure and depressurizing time does the


utility calculate? __________
Is a valve of this size sufficient to meet the requirements of
complete depressurization, i.e. the final pressure is
atmospheric, in 15 minutes? __________

Exercise 2
Constant Rate Depressurization
As an additional exercise, model the value in the Depressurizing utility
as a subsonic valve with the following information:

In this Cell... Enter... (Field) Enter... (SI)

C1 72,000 32,400

C2 0 0

Valve Rate Units lb/hr kg/hr

These settings set the valve as a constant rate type valve. If C2 = 0 then
pressure has no impact on the valve’s flow rate.

What is the depressurization time in this case? __________

Save your case!

15
16 The HYSYS Spreadsheet

Challenge
The Macro Language Editor
HYSYS contains a Macro Language Editor, that lets the user write
programs that can access information from the HYSYS Simulation, and
calculate a value or a series of values.

This language editor uses the WinWrap Basic script, a language very
similar to Microsoft® Visual Basic®. The Macro Language Editor allows
users to develop, test, and execute programs. Programs can also be
saved and reopened in any number of HYSYS cases.

There are several programs already prepared for many different


applications. These programs can found on Hyprotech’s website at
www.hyprotech.com\OLE\default.htm.

In this module, a prewritten program will be used to calculate the


orifice area needed to vent the Comb. Feed stream.

1. Access the Macro Language Editor under Tools in the Main Menu
Bar.
2. With the provided disk in the A: drive, open the file A:\PSV.wwb.
3. Run the Program by selecting Run under Macro on the Menu Bar.
4. Enter a Relief Pressure of 15.5 bar (225 psig), and select Two
Phase Relief. Otherwise, accept all of the default values.

What orifice area does the program calculate? __________


How does this value compare with the value calculated
previously? __________

16

You might also like