# Tutorial: Optimization of a Multi-Stage Separation Process

Level: Basic

Required Knowledge: None

Keywords: Process Simulation, EOS Calculations, Optimization

Pipe-It Utilities: Streamz Separator, Strexzel, Pipe-It Optimizer, Streamz Library, Streamz Tabulator, Streamz Copier, Linkz, Composite.

## Introduction

### Objectives

The objective of this tutorial is to optimize the process conditions of a simple 4-stage separation train using Pipe-It.

Conditions (pressure and temperature) of the three first stages are variables of the optimization problem. The objective is to maximize the final oil volume. Constraints on vessel temperature and pressure are also considered. The full optimization problem is described later. Note that the feed stream to the process is constant.

### Getting Started

The folder "Multi-Stage_Process_Optimization" contains several files and one sub-folder:

• The sub-folder "Correct Solution" contains the finalized Pipe-It;
• The files "MultiStage_Process_Optimization.ppv", "MultiStage_Process_Optimization.ppm" and "MultiStage_Process_Optimization.runlogdb" are empty Pipe-It files.
• The file "Feed_2_process.str" is a Stream file (.str) containing the molar rates in the feed stream to the process. Stream files are Pipe-It standard files. When you double-click on it in Windows explorer, the file will be open inside Strexzel, a Pipe-It utility. Note that Stream files are ASCII files, therefore they can be open in a classic text editor.
• The file "Insert_Process_Conditions.stm" is a Stream macro file (.stm) containing a set of instructions to insert automatically the process conditions inside a Stream file. This file is an ASCII file and can be open in a classic text editor.
• The file "Characterizations.chr" is a Streamz characterization file the different fluid characterization models (e.g. EOS). It is an ASCII file and can be open in a text editor. In the case of an Equation Of State (EOS) model, this file contains the critical properties of the pure components and the Binary Interaction Parameters (BIP's).
• The file "Volumetric_Conversions.cnv" is a Streamz conversion file (.cnv) containing the instructions for EOS volumetric calculations. It is an ASCII file and can be open in a text editor.

## Create the Streamz Fluid Library

The Fluid Characterization Library (also called Streamz library) contains all fluid descriptions (e.g EOS models) and conversions (EOS volume calculation) needed in the Pipe-It project. Each new fluid description needs to be added to the Streamz library following this set of instructions:

1. Open the Streamz Library window by:
• Clicking on the Streamz library icon of the toolbar;
• Clicking on Project > Streamz in the menu;
• Pressing CTRL + Shift + Z on the keyboard.

1. Add a new file by clicking on the "Add File" button of the Streamz library.

1. Choose the file "Characterizations.chr". A new window appears and should look like this:

1. Click on "OK".
1. Click again on the "Add File" button, but now choose the file "Volumetric_Conversions.cnv". A new window appears and should look like this:

1. Click on "OK" and close the Streamz library window.

Three new characterization have been added:

• EOS11
• OIL
• GAS

• EOS volume calculation for liquids
• Volume calculation using the ideal gas law for gases.

## Process Modeling

### Define a Feed Stream

#### Insert a New Resource Element on the Canvas

Insert a new resource element on the canvas either by:

• Pressing the touch R of the keyboard
• Clicking on Insert>Resource in the menu
• Clicking on the resource icon in the tool bar

#### Link the Resource File to an Existing File on the Disk

A resource element is always a reference to a file on a hard disk. We first need to link this resource element to a file on the disk. This can be done by right-clicking on the resource element. This operation can also be done by selecting the resource and pressing the touch F of the keyboard.

Select the file "Feed\_2\_process.str" and click on "Save".

This file can be open within Pipe-It by double clicking on the resource element. A new window appears:

The name of the resource element can be changed by right-clicking on it. This operation can also be done by selecting the resource file and pressing F2.

#### Set a Characterization to the Resource Element

In Pipe-It, a Stream file (.str) needs to be linked to a fluid characterization in most of the cases. This can be done by right-clicking on the resource element. This operation can also be done by selecting the resource element and pressing F3.

A new window appears. Select the "EOS11" characterization and click on "OK".

### Insert the Process Conditions

In this tutorial, we are going to use Strexzel to insert the process conditions.

#### Insert a Strexzel Process Element

First we need to insert a Strexzel process element on the canvas either by:

• Clicking on the Strexzel icon in the tool bar
• Clicking on Insert > Strexzel in the menu

#### Insert a Strexzel Macro

Insert a new resource file on the canvas by following the procedure described above. When setting the file, choose the file "Insert_Process_Conditions.stm". Note that this resource does not need to be associated with a characterization. Only Stream files need a characterization.

#### Insert an Output Ressource File

Insert a new resource element. When setting the file, type "Feed_2_process_w_cond.str" and click on "Save".

Note that this file does not exist yet, but will be created by Pipe-It. This resource element is linked to a Stream file and needs to be linked to a characterization. Set the characterization "EOS11" to this file, following the procedure described above.

At this moment, the canvas should look like this:

#### Connect the Resource Files to the Strexzel Process Element

Insert a connector by clicking on the connector icon in the tool bar or by clicking on Insert > Connector. The difference between "Elbow" and "Straight" is only graphical and will not affect the Pipe-It model.

Connect the resource element "Feed_2_process.str" to the Strexzel element. The connector should start from the resource element and be pointing the process element. When the connection is done, Pipe-It gives you several option. You need to indicate if the input resource file is:

• a macro file (.stm)
• a Stream file (.str)
• an input characterization file (.chr)

In this case, the input resource file is a Stream file.

Do the same operation for the resource element "Insert_Process_Conditions.stm". In this case, choose the option "Macro file (.stm)".

The last resource file is an output of the Strexzel process element. The connector should go from the process element and be pointing the resource file. Several options are available. Choose "Output Stream file (.str)".

At this moment, your Pipe-It project should look be similar to the following picture. You can run it by clicking on the run button in the tool bar or by pressing CTRL + R on the keyboard. #Run Pipe It?

Note that the output file "Feed_2_process_w_cond.str" has been created while Pipe-It was running. Now, it can be open by double-clicking on it. A Strexzel window appears:

### Set-up a Gas-Oil Separator

#### Insert a New Streamz Separator Element

Insert a new Streamz separator element either by:

• Clicking on the process icon of the tool bar;
• Clicking on Insert > Processes > Streamz Separator in the menu;
• Pressing the touch S of the keyboard.

Rename the Streamz separator by right-clicking on it (or pressing F2) and call it "Stage 1".

#### Inser Output Resource Elements

We now need to insert two resources elements which will be the output of the Streamz separator element:

• One file for the separator liquid;
• The other for the separator gas.

When setting the files, typewrite "Stg1_oil.str" for the first file and "Stg1_gas.str" for the second file. Both files need to be linked to the same characterization "EOS11".

At this moment, the canvas should look like this:

#### Connect the Resources Files to the Separator

Use the connector element to make connections between resource files and the separator. The procedure is described here.

When connecting the input file "Feed_2_process_w_cond.str" to the Streamz separator, several options are available. Choose "INPUT STREAMS".

When connecting the Streamz separator to the output files, several options are available. Choose "OUTPUT OIL STREAMS" for the resource "Stg1_oil.str".

Choose "OUTPUT GAS STREAMS" for "Stg1\_gas.str".

At this moment, the canvas should look like this:

#### Configure the Streamz Separator

For the moment, we have indicated:

• The feed stream to the Streamz separator (i.e. molar rates);
• The output gas and oil streams;
• The fluid characterization for the input and output streams ("EOS11").

Now, we need to configure the type of separation process we want to model. To do this, double click on the Streamz separator element. A new window appears. Select the "EOS Flash" option to perform an EOS-based flash calculation.

In the section "Variables", you have to define the pressure and temperature for the flash calculation. Use the pressure and temperature we previously defined using Strexzel and a macro file:

• Choose "P_Stga1" for the pressure:

• Choose "T_Stg1" for the temperature:

#### Run the Project

Run the project, following the instructions given here. Pipe-It will perform automatically the flash calculation of the feed stream at the given pressure and temperature, using the EOS model "EOS11". The output files "Stg1_oil.str" and Stg1_gas.str" will be created during the run. You can open them by double clicking on the resource files. They contain respectively the molar rates of all components in the separator oil and separator gas.

### Insert the Remaining Streamz Separators

Following the previous instructions, insert three additional Streamz separators with the following configuration:

Separator Name Feed file Output file (separator oil) Output file (separator gas) Pressure Temperature
Stage 2 Stg1_oil.str Stg2_oil.str Stg2_gas.str P_Stg2 T_Stg2
Stage 3 Stg2_oil.str Stg3_oil.str Stg3_gas.str P_Stg3 T_Stg3
Stage 4 Stg3_oil.str Stg4_oil.str Stg4_gas.str P_sc T_sc

Note that all files need to be set up with the same characterization "EOS11".

After having configured a new separator, it is useful to re-run the Pipe-It project, so the new output files will be created on the disk.

At this moment, the canvas should look like this:

### Gather the Gas Streams

The gas released at each stage of the separation trains need to be commingled into a single stream. This can be done using the "Tabluator" process element of Pipe-It.

#### Insert a New Tabulator Process Element

First, you need to insert a new tabulator process element on the canvas either by:

• Clicking on the process icon of the tool bar;
• Clicking on Insert > Processes > Streamz Tabulator;
• Pressing T on the keyboard.

The Tabulator process element will behave like a "mixer". It will gather the input streams and tabulated them in a single output file. Thus, a new output resource element has to be inserted.

#### Insert a New Resource Elemet

Following the instructions given here, insert a new resource element on the canvas.

Typewrite "total_gas.str" for the file name and set the characterization to "EOS11".

#### Connections

Now, we need to connect the different resources elements to the tabulator element.

First, connect the resource element "Stg1_gas.str" to the Streamz Tabulator using a connector. Several connection options are available. Choose "INPUT STREAMS".

Follow the same instructions for the other input streams:

• "Stg2_gas.str";
• "Stg3_gas.str";
• "Stg4_gas.str".

For the output file, set a connect from the tabulator element to the resource element "total_gas.str". Choose the option "OUTPUT STREAMS".

At this moment, the canvas should look like this:

#### Configure the Streamz Tabulator

The Streamz Tabulator needs to be configured.

First double-click on the tabulator element. A new window appears.

1. In the tab "Basic", tick the check box "Tabulate".

1. In the tab "Basic", click on "Add" and then on "Add all vars:"

1. In the tab "Advanced", tick the check box "Gathering options" and then select "Gather and Accumulate".

1. Click on "OK".

### Oil Volume Calculation

We want to convert the molar rates of the final oil product into a liquid volume.

#### Insert a New Copier Process Element

Insert a new Streamz Copier either by:

• Clicking on the process icon of the tool bar;
• Clicking on Insert > Processes > Streamz Copier;
• Pressing the touch Y of the keyboard.

#### Insert a New Resource Element

Insert a new resource element following the instructions given here.

Typewrite "Oil_volume.str" as file name and set the characterization to "OIL".

#### Connect the Resource Elements to the Streamz Copier

First connect the resource element "Stg4_oil.str" to the Copier element with a connector. Select "INPUT STREAMS".

Then, connect the Copier element to the output resource file "Oil_volume.str". Select "OUTPUT STREAMS".

#### Streamz EOS Calculations

The Streamz Copier element automatically picks up the correct conversion in the Streamz library. You can check this by double-clicking on the Copier element and going in the tab "Conversions".

Here, we can see that Pipe-It will perform an EOS calculation to translate moles into volume, using the EOS model. You can check the input file used for the conversion by double clicking on the green square. A new window appears showing the file where the conversion is read from. You can also double click on the file name to open the file.

In our case, we are converting molar rates (described with "EOS11" characterization) into an oil volume (characterized by "OIL"). Pipe-It will automatically use the EOS model to do this conversion.

It is important to emphasize here that the volumetric calculation is sensitive to:

• The unit used for the molar rates (here, kg-moles);
• The unit used for the volume (here m3);
• The conditions for the volumetric conversion (here, standard conditions).

### Gas Volume Calculation

Follow the same set of instructions to translate the gas molar rates from the resource file "total_gas.str" to a new resource called "Gas_volume.str". Set the characterization of this new resource file to "GAS" (instead of "OIL").

At this moment, the canvas should look like this:

### Organization of the Pipe-It Project

To make the Pipe-It project easier to understand, you can rename the following process elements:

• "Streamz Tabulator" "Gather Gas Streams";
• "Streamz Copier 001" "Oil Volumetric Conversion";
• "Streamz Copier 002" "Gas Volumetric Conversion".

In addition, you can create a composition. Select the elements as shown in Fig. \ref{fig:composite}, right click and select "Create Composite from Selection".

At this moment, the canvas should look like this:

You can rename the composite "Process Simulation".

To navigate inside the composite, you only to double click on it.Navigation t upper level can be done using the arrows of the tool bar or by double clicking on the sockets.

### Run the Pipe-It Project

The Pipe-It project can be run.

You can look at the influence of changing some of the process conditions (in the file "Insert_Process_Conditions.stm") on the final oil and gas volumes.

Each time a modification is done, the entire Pipe-It project needs to be launched.

## Process Condition Optimization

### Introduction

We have seen in the previous section that the process conditions have an impact on the final oil volume. In this section, we are going to try to maximize the oil rate by changing the process conditions. We can eventually add some topside constraints: (1) Maximum pressure for the first stage separator; (2) minimum and maximum pressure for the other stages and (3) Minimum and maximum temperature. Note that the feed stream (mixture and molar rates) will remain unchanged.

### Optimization Problem

The optimization problem we are going to consider is quite simple.

Maximize the final oil rate:

by changing the process conditions:

and subject to:

and

The first step is to link the input files and output files. This can be done using Pipe-It built-in utility called Linkz. It allows to open any ASCII file and pin-point the number you want to link. Each time you define a new link in an ASCII file, this link is added to the Linkz library. Pipe-It optimizer has access to the Linkz library. We will come to that later on.

Select the resource element "Insert_Process_Conditions.stm" and right-click on it.

A new window appears:

The last separator being the separation at standard conditions, the parameters we want to optimize are:

• P_Stg1 and T_Stg1;
• P_Stg2 and T_Stg2;
• P_Stg3 and T_Stg3.

1. Pin-point the number "20" in the Linkz interface and double-click on it;

1. A new window appears;

1. Change the name of the link. The link name is used to find the link in the Linkz library, so it is important to give understandable names. Here, call the link "P_stg1".

1. Linkz works with one (or several) keyword(s). The target (here the number "20") is located based on the keyword(s). By default, Linkz use the first word of line as keyword. In our case, the default keyword is "SET". Since the word "SET" is used several times in the file, it is not a safe keyword. Add a new keyword with the button + and then choose the word "P_stg1" located on line 2 using the arrows.

1. To make sure that the link is define in a unique way, you can click on the "Test" button and check the number of occurrences. If the link is defined in a unique way, the number of occurrence is one.

1. Click on "OK"

The link has been created and added to the Linkz library. You can check this by opening it:

• Click on the Linkz library icon in the tool bar;
• Press CTRL + Shift + L.

A new window appears:

Use the same procedure to define links for the other process conditions. Keep the same nomenclature.

We now need to link the final oil volume. Open the resource file "Oil_volume.str" in Linkz. Create a link for the oil rate (pin-point the number "615.286") using the same procedure as described above. Rename the link "Oil_rate" and choose "DATA" as single keyword for this link.

If you open the Linkz library, it should look like this:

### Pipe-It Optimizer Configuration

Pipe-It Optimizer is a user-friendly optimization tool that allows to do model-based (or black box) optimization. Several built-in solvers are available: IPOPT, reflection, simplex... For each solver iteration, variables are changed in the input files (through user-defined links), the model is launched. Objective function and constraints are then read by the optimizer (using user-defined links). The solver decides the values of the variables for the next iteration.

#### Open Pipe-It Optimizer

To open Pipe-It optimizer, you can either:

• Click on the Optimizer icon of the tool bar;
• Click on Project > optimizer;
• Press CTRL + Shift + O on the keyboard.

A new window appears:

#### Add a New Variable to the Optimizer

To add a new variable, click on the button + of the optimizer. Change the name of the variable in the column "Name" and rename it "p1". In addition, change the upper and lower limits to 1.013 for the lower bound and 50 for the higher bound.

Now, we need to link this optimizer variable to an actual number in one of the input file. We will use the linkz library for this. Double-click on the cell "Link" of the current row. A new window appears. Select "P_stg1" and click on "OK".

The optimizer variable "p1" is now mapped to the link "P_stg1". After each iteration, the value of this link in the file "Insert_Process_Conditions.stm" will be changed automatically.

Add the remaining variables following the following instructions:

Name Lower Bound Upper Bound Link
p2 1.013 50 P_Stg2
p3 1.013 50 P_Stg3
T1 50 70 T_Stg1
T2 25 45 T_Stg2
T3 18 22 T_Stg3

At this moment, the optimizer window should look like this:

You can save the optimizer settings by clicking on the "Save" button in the optimization window.

To add an objective, use the + button. Rename the variable "Qo" and change its "role" to "OBJ". Then link this variable to "Oil_volume".

The optimizer window should now look like this:

It is not directly possible to include inequality constraints between two variables in the optimizer. However, we can note the equivalency:

To add a this new constraint, use the + button. Rename the variable "Press_con". Set the lower bound to 0 and the upper bound to 1 000 000. Change its role to "CON". Then double-click on the corresponding "Equation" cell.

A new window appears. In the input box "Expression", type:

p1-p2


Then click "OK".

Add the remaining constraint following the same instruction. Name it "Press_con1". Note that the equation which needs to be entered is:

p2-p3


The optimizer window should look be similar to this:

#### Launch the Optimization

It is possible now to launch the optimization by clicking on "Optimize". Some additional settings are available:

• Solver type : IPOPT, reflection, simplex...
• Maximum number of iterations;
• Direction: Maximize or minimize the objective or find a feasible solution (i.e. a solution that honors all constraints).

It is possible to access the history of the optimization by clicking on the "History" button.

Here are some ideas for further studies:

• Try to use different solvers and compare the convergence towards the solution.
• Identify the limiting constraint(s);
• Try to change the critical constraint(s) and see the influence on the final oil product.