Training and support

HYSYS Tips and Tricks: User-Variables to calculate erosional velocity in dynamic simulation models

When modelling piping networks, especially in the presence of loops and parallel piping, HYSYS Dynamics can be easily used as a pressure-flow solver simulator (this was discussed in our article “Modelling Piping Networks – HYSYS Steady State, HYSYS Hydraulics or HYSYS Dynamics?”). However, one major flaw of using this methodology is that flow assurance calculations are not available in Dynamics. An erosion calculation is quite useful when modelling piping networks. This article suggests a methodology to correct this issue by setting up user variables in HYSYS and provides a step-by-step example including a sample of the required code.

User Variables

A user variable is a feature available in HYSYS that is very useful and will definitely help users take their simulations to the next level. The creative application of user variables in the calculation of various process parameters in a HYSYS case eliminates the need of downloading information from HYSYS to perform those calculations using spreadsheets.

Erosional Velocity

Multiphase flow (gas/liquid, gas/solid or a combination of both) at high velocities causes erosion in pipes and vessels due to the impact of liquid or solid particles over their inner walls. Because of this, the erosional velocity or the erosional velocity ratio (actual velocity / erosional velocity) is a key design parameter when sizing pipes and vessels under certain conditions. Erosional velocity can be calculated as indicated in the API RP 14E [3]:


ve: Erosional velocity (ft/s) 

C: Empirical constant 

pm: Gas/liquid mixture density at flowing pressure and temperature (lb/ft3)

API RP 14E recommends a C factor based on the conditions shown in the following table:

Implementation in HYSYS Dynamics

In this example we will employ the user variable capability to calculate the erosional velocity ratio dynamically. We will assume that the user has a perfectly running piping simulation case, this means it is converged and you can start or stop the integrator (solver).

One thing to keep in mind is that a user variable needs to be linked to a specific simulation object (i.e. Flowsheet, Stream or Unit Operation). In this case because the Pipe Segment unit operation contains the relevant information to perform this calculation, we will use it to link the erosional velocity calculation. In the design TAB, go to User Variables and click the “Create New User Variable” button.

From the User Variable page, input the following information:

  • Name: ErosionalVelocityRatio
  • Tag: ErosionalVelocityRatio
  • Type: Real
  • Dimensions: Scalar
  • Units: Dimensionless
  • Macro: Check DynPressureFlowPreStep()
  • Is Variable Calculated Only: Check
  • Code:

Sub DynPressureFlowPreStep()

'This code calculates the erosional velocity using average density and velocity.

'Assumes pipe segment with constant diameter

    diameters = activeobject.SegmentInnerDiam 'm

    area = 0.25 * 3.14 * diameters(0) * diameters(0) 'm2

    inletdensity = activeobject.FeedStream.MassDensityValue

    outletdensity = activeobject.ProductStream.MassDensityValue

    averageDensity = 0.5 * (inletdensity + outletdensity)  'kg/m3

    inletvoflow = activeobject.FeedStream.ActualVolumeFlowValue

    outletvolflow = activeobject.ProductStream.ActualVolumeFlowValue

    averageFlow = 0.5 * (inletvoflow + outletvolflow)  'm3/s

    averageVelocity = averageFlow/area *3.28084 'ft/s

    averageDensity = 0.5 * (inletdensity + outletdensity) * 0.062428 'lb/ft3

    erosionalVelocity = 100 / Sqr(averageDensity)  'ft/s

    ErosionalVelocityRatio = averageVelocity/erosionalVelocity


End Sub

Notice that the presented code calculates the erosional velocity ratio using average actual volume flow and density. In addition, the area is calculated using inner diameter of the first pipe segment and it is using the Solids-free, continuous service C factor. Once completed, your interface should look like this:

Click the OK button to complete the process. Note that the calculation will be completed only after you start the integrator.  The results will be displayed in Design TAB, User Variable Page:


[1] American Petroleum Institute, API Recommended Practice 14E, Fifth Edition: Design and Installation of Offshore Production Platform Piping System, Dallas: American Petroleum Institute, 2007.

Do you have questions or comments regarding this article? Click here to contact us.



Latest articles