Case A Excel Gas Cooler

You might also like

Download as xls, pdf, or txt
Download as xls, pdf, or txt
You are on page 1of 10

Introduction:

There may be several methods to deal with below issue. I am only suggesting one of them.
The purpose of this exercise is to simulate a gas cooler in hysys using VBA codes. Gas cooler shell
side fluid is a mix. of Methane and Ethane of known mass fraction, temperature, pressure and mass
flow rate. Outlet temperature and pressure are also known. Cooling water is provided as tube side
fluid with known temperature and pressure. Also outlet water pressure is known.

Refer Annexure 1_PFD. This sheet is a graphical representation of the given system.
All the input parameters are to be typed in this sheet (in YELLOW boxes). GREEN boxes are for hysys
calculated values (cooling water flow rate).

Refer Annexure 2_Input table. VBA program takes all the input parameters from this sheet.
There is no need to type anything in this sheet, as all the values are linked from Annexure_1_PFD.

Refer Annexure 3_output_table. This sheet receives the hysys calculated values. In this case, mass
flow rate of cooling water, process outlet stream mass fraction, density, viscosity calculated by
hysys are reported to this sheet by VBA codes. These values are linked to Annexure_1_PFD.

Refer Annexure 4_VBA_Code. Hysys model for this system is prepared. VBA code has been written
so that hysys takes the data from Annexure 2_Input table and provides calculated values in the
Annexure_3_output_table.

Prepared by:
Ajay S. Satpute
Sr. Process Engineer
Ramboll Oil & Gas, Qatar
Instructions:

1. This program shall work only if you have HYSYS installed in your PC AND
you have opened relevant hysys file.
2. Do not add or delete rows/columns in Annexure_2_Input_table or Annexure_3_output_table.
3. Prepare a simple PFD for this system. Type the input data (highlighted in YELLOW) as given in "Annexure_1_PFD".

4. Prepare a hysys file (preferably save it in the same folder and same file name as that of excel file).
5. In this file, go to VIEW, click on "Macros", Click on "Create". Name the Macro as StartHYSYS (you may choose any
name you want). Copy VBA codes from Annexure_4_VBA_Code worksheet to the Macro file.
6. Insert a rectangle from shapes. Type in it LinkToHysys (you may write any other text). Right click on the rectangle
and Click of "Assign Macro", which is StartHYSYS in this case.
7. Click on "LinkToHYSYS" tab in "Annexure_2_Input_table" worksheet.
8. Program shall open the hysys file (if license is available), receive values from "Annexure_2_Input_table" worksheet,
run the hysys file and export hysys calculated values from hysys to excel sheet. The graphical representation of the
results is shown in "Annexure_1_PFD" worsksheet.

8. Make sure "Hysys 7.3 type Library" is cheked in VIEW/Macros/Tools/References.


GAS COOLER

LinkToHYSYS

PF_IN (process fluid in)


70 oC
5 kg/cm2g
5000 kg/h
0.4
0.6 Mass fraction (Ethane)

CW_IN (cooling water in) GAS CW_OUT (cooling water out)


30 oC COOLER 40 oC
3.5 kg/cm2g 3.4 kg/cm2g
4864 kg/h

PF_OUT (process fluid out)


50 oC
4.9 kg/cm2g
Annexure 2: Input Table

Hysys file path: C:\Documents and Settings\Desktop\Case_A_EXCEL.hsc

Input Table:

Hysys stream number Description Temp. Pressure Flow rate Methane Ethane
mass mass
o
C 2
kg/cm g kg/h fraction fraction

PF_IN Process fluid in 70 5 5000 0.4 0.6

PF_OUT Process fluid out 50 4.9

CW_IN Cooling water in 30 3.5

CW_OUT Cooling water out 40 3.4


Annexure_3_output_table

Output Table:

Hysys stream number Description Temp. Pressure Flow rate Methane Ethane Mass
Viscosity,
mass mass density,
cP
o
C kg/cm2g kg/h fraction fraction kg/m3

CW_IN Cooling water in 30.0 3.5 4863.5

PF_OUT Process fluid out 0.4 0.6 4.9 0.012


' "Below three lines shall be same in all cases".
Option Explicit
Public hyApp As HYSYS.Application
Public simCase As SimulationCase

' "Taking reference from worksheet Annexure 1_PFD, prepare a hysys file Snapshot is saved in Annexure_5_hysys_snapshot in

' "First define the streams (preferably all the strems in your hysys file"
Public PF_IN As ProcessStream
Public PF_OUT As ProcessStream
Public CW_IN As ProcessStream
Public CW_OUT As ProcessStream
Public pStream As ProcessStream

Public Sub StartHYSYS() ' "StartHYSYS is your MACRO name".


Dim fileName As String

' "Set all the streams dimensions".


Dim PRESPF_IN As Double, FLOWPF_IN As Double, TEMPPF_IN As Double
Dim PRESPF_OUT As Double, FLOWPF_OUT As Double, TEMPPF_OUT As Double
Dim PRESCW_IN As Double, FLOWCW_IN As Double, TEMPCW_IN As Double
Dim PRESCW_OUT As Double, FLOWCW_OUT As Double, TEMPCW_OUT As Double
Dim Compositions As Variant

' "LOADING HYSYS SIMULATION FILE (This will open your hysys file as per path provided, if the hysys file is not open already)".
Set hyApp = CreateObject("HYSYS.Application")
hyApp.Visible = True
Set simCase = hyApp.ActiveDocument
If simCase Is Nothing Then
fileName = Worksheets("Annexure_2_Input_table").Range("B2") ' "Make sure your hysys file path is correct".

If fileName <> "False" And simCase Is Nothing Then


Set simCase = GetObject(fileName, "HYSYS.SimulationCase")
simCase.Visible = True
End If
End If

' "Set all the streams".


Set PF_IN = simCase.Flowsheet.MaterialStreams.item("PF_IN")
Set PF_OUT = simCase.Flowsheet.MaterialStreams.item("PF_OUT")
Set CW_IN = simCase.Flowsheet.MaterialStreams.item("CW_IN")
Set CW_OUT = simCase.Flowsheet.MaterialStreams.item("CW_OUT")

' "Export data from excel (Annexure_1_PFD) to hysys file"

' "Set compositions from excel (Annexure_1_PFD) to hysys file"


' Mass fraction values of stream PF_IN is exported from excel to hysys.

Compositions = PF_IN.ComponentMassFractionValue
Compositions(0) = Worksheets("Annexure_2_Input_table").Range("G6").Value ' "Make sure first component (Methane) mass
Compositions(1) = Worksheets("Annexure_2_Input_table").Range("H6").Value ' "Make sure second component (Ethane) ma
PF_IN.ComponentMassFraction.Values = Compositions

' "Set temp. from excel (Annexure_1_PFD) to hysys file"


TEMPPF_IN = Worksheets("Annexure_2_Input_table").Range("D6").Value ' "Make sure PF_IN input temperature is taken fro
PF_IN.Temperature.SetValue TEMPPF_IN, "C" ' "Temperature unit set is oC".

TEMPPF_OUT = Worksheets("Annexure_2_Input_table").Range("D7").Value ' "Make sure PF_OUT input temperature is taken


PF_OUT.Temperature.SetValue TEMPPF_OUT, "C" ' "Temperature unit set is oC".

TEMPCW_IN = Worksheets("Annexure_2_Input_table").Range("D9").Value ' "Make sure CW_IN input temperature is taken fr


CW_IN.Temperature.SetValue TEMPCW_IN, "C" ' "Temperature unit set is oC".

TEMPCW_OUT = Worksheets("Annexure_2_Input_table").Range("D10").Value ' "Make sure CW_OUT input temperature is ta


CW_OUT.Temperature.SetValue TEMPCW_OUT, "C" ' "Temperature unit set is oC".

' Set pressure from excel (Annexure_1_PFD) to hysys file

PRESPF_IN = Worksheets("Annexure_2_Input_table").Range("E6").Value ' "Make sure PF_IN input pressure is taken from co
PF_IN.Pressure.SetValue PRESPF_IN, "kg/cm2_g" ' "Pressure unit set is kg/cm2_g".

PRESPF_OUT = Worksheets("Annexure_2_Input_table").Range("E7").Value ' "Make sure PF_OUT input pressure is taken from
PF_OUT.Pressure.SetValue PRESPF_OUT, "kg/cm2_g" ' "Pressure unit set is kg/cm2_g".

PRESCW_IN = Worksheets("Annexure_2_Input_table").Range("E9").Value ' "Make sure CW_IN input pressure is taken from
CW_IN.Pressure.SetValue PRESCW_IN, "kg/cm2_g" ' "Pressure unit set is kg/cm2_g".

PRESCW_OUT = Worksheets("Annexure_2_Input_table").Range("E10").Value ' "Make sure CW_OUT input pressure is taken


CW_OUT.Pressure.SetValue PRESCW_OUT, "kg/cm2_g" ' "Pressure unit set is kg/cm2_g".
' Set mass flow rate from excel (Annexure_1_PFD) to hysys file
FLOWPF_IN = Worksheets("Annexure_2_Input_table").Range("F6").Value ' "Make sure PF_IN input flow is taken from correc
PF_IN.MassFlow.SetValue FLOWPF_IN, "kg/h" ' "Mass flow unit set is kg/h".

' Export data from hysys to excel


' Temperature
Worksheets("Annexure_3_output_table").Range("D6").Value = CW_IN.Temperature.GetValue("C") ' "Although it is an input p

' Flow
Worksheets("Annexure_3_output_table").Range("F6").Value = CW_IN.MassFlow.GetValue("kg/h") ' "Hysys will calculate the m

' Pressure
Worksheets("Annexure_3_output_table").Range("E6").Value = CW_IN.Pressure.GetValue("kg/cm2_g") ' "Although it is an inp

' Mass fraction


Set pStream = simCase.Flowsheet.MaterialStreams.item("PF_OUT")
Worksheets("Annexure_3_output_table").Range("J" & 7).Value = pStream.ComponentMassFraction(0)
Worksheets("Annexure_3_output_table").Range("K" & 7).Value = pStream.ComponentMassFraction(1)

' Mass density


Worksheets("Annexure_3_output_table").Range("L7").Value = PF_OUT.MassDensity.GetValue("kg/m3") ' "Hysys will calculate

' Viscosity
Worksheets("Annexure_3_output_table").Range("M7").Value = PF_OUT.Viscosity.GetValue("cP") ' "Hysys will calculate the m

End Sub

You might also like