6
TUTORIAL G-13 Introduction to Scripting in GAP OBJECTIVES BASIC SCRIPTING COMMANDS www.ifm-solutions.com © IFM-Solutions 1 / 6 The user will learn in this tutorial: 1. Understand the use of the commands: DoGet, DoSet, DoCommand and LogMessage. 2. What are the AccessStrings and how to find them? 3. Use the GAP interface to execute OpenServer commands 4. Include those commands in simple GAP Scripting examples These are the basic scripting commands that will be covered in this tutorial: Syntax: DoGet(AccessString) The DoGet command returns the value of a certain variable, identified by the AccessString. The AccessString must be a string, and thus will normally be enclosed with double inverted commas. Usually, the value returned is stored in a variable. Example: W1PRes = DoGet(“GAP.MOD[{PROD}].WELL[{WELL1}].IPR[0].ResPres”) Syntax: DoSet AccessString, value The DoSet command assigns the value specified to the variable identified by the AccessString provided. Example: DoSet GAP.MOD[{PROD}].COMP[{Compressor01}].DELTAP, 200 Syntax: DoCmd(AccessString) The DoCmd command performs the command identified by the AccessString. The complete list of commands and their AccessString is provided in the User Guide for OpenServer and GAP. Example: DoCmd(“GAP.MOD[{PROD}].WELL[{WELL1}].MASK()”) Syntax: LogMsg(Message) The LogMsg command prints the message in the Script tab of the prediction Log. Example: LogMsg(“Hello World”) DoGet DoSet DoCmd LogMsg

Tutorial- G13.pdf

Embed Size (px)

Citation preview

Page 1: Tutorial- G13.pdf

TUTORIAL G-13

Introduction to Scripting in GAP

OBJECTIVES

BASIC SCRIPTING COMMANDS

www.ifm-solutions.com© IFM-Solutions

1 / 6

The user will learn in this tutorial:

1. Understand the use of the commands: DoGet, DoSet, DoCommand and LogMessage.2. What are the AccessStrings and how to find them?3. Use the GAP interface to execute OpenServer commands4. Include those commands in simple GAP Scripting examples

These are the basic scripting commands that will be covered in this tutorial:

Syntax: DoGet(AccessString)The DoGet command returns the value of a certain variable, identified by the AccessString. The AccessString must be a string, and thus will normally be enclosed with double inverted commas. Usually, the value returned is stored in a variable.Example: W1PRes = DoGet(“GAP.MOD[{PROD}].WELL[{WELL1}].IPR[0].ResPres”)

Syntax: DoSet AccessString, valueThe DoSet command assigns the value specified to the variable identified by the AccessString provided.Example: DoSet GAP.MOD[{PROD}].COMP[{Compressor01}].DELTAP, 200

Syntax: DoCmd(AccessString)The DoCmd command performs the command identified by the AccessString. The complete list of commands and their AccessString is provided in the User Guide for OpenServer and GAP.Example: DoCmd(“GAP.MOD[{PROD}].WELL[{WELL1}].MASK()”)

Syntax: LogMsg(Message)The LogMsg command prints the message in the Script tab of the prediction Log.Example: LogMsg(“Hello World”)

DoGet

DoSet

DoCmd

LogMsg

Page 2: Tutorial- G13.pdf

ACCESS STRINGS

Using the GAP model provided, find out the Access String for the following variables:

www.ifm-solutions.com© IFM-Solutions

2 / 6

Each variable or procedure in GAP has its unique identifier, called the Access String. Thus, when referring to any particular variable or procedure, the user must identify it using its Access String value.For example, the access string for a layer’s Reservoir Pressure is:

GAP.MOD[{PROD}].WELL[{WELL3}].IPR[0].ResPres

To find out the access string that identifies a variable, the usual procedure is to hold Ctrl and right click on the input box that holds the variable. In GAP, that brings up a screen showing the Access String and the value that the variable holds, as shown in the screen capture.

1

Variable

Well 3: Reservoir Pressure

Node A: Pressure (From Solver Results)

Trunk Line A: Surrounding Temperature

Access String

Please note that the GAR file provided has been created using IPM 8.0, and can only be opened with GAP IPM 8.0 and above.

Page 3: Tutorial- G13.pdf

www.ifm-solutions.com© IFM-Solutions

3 / 6

Using the DoGet mode, find the values stored in the following AccessStrings:

Using the DoSet mode, change the value of the ID of Well 3 Pipeline from 3.5 to 3 inches.

What does each Access String stand for?

3

2

Access String

GAP.MOD[{PROD}].PIPE[{Trunk Line A}].Desc[1].ID

GAP.MOD[{PROD}].WELL[{WELL2}].SolverResults[0].FWHP

GAP.MOD[{PROD}].WELL[{WELL1}].SolverResults[0].GasRate

Value Stored Units

Access String

GAP.MOD[{PROD}].PIPE[{Trunk Line A}].Desc[1].ID

GAP.MOD[{PROD}].WELL[{WELL2}].SolverResults[0].FWHP

GAP.MOD[{PROD}].WELL[{WELL1}].SolverResults[0].GasRate

Variable Represented

EXECUTE OPENSERVER STATEMENT WINDOW

SELECT THE MODE HERE

GAP has a simple interface that allows the user to execute Openserver commands (such as DoGet, DoSet and DoCmd) in a quick way.

To access the “Execute Openserver Statement” window, head to Edit | Execute Openserver Statement. That brings up the following window:

In this window you can test the outcome of certain sentences and execute simple statements.

Page 4: Tutorial- G13.pdf

4 / 6

www.ifm-solutions.com© IFM-Solutions

GAP SCRIPTING DURING A PREDICTION – ROUTINE PLACEMENT

GAP can execute scripts during a prediction. Depending on the purpose, the user can select the exact moment in which the script will run.

This is the scripting window that pops up when the user heads to Prediction | Edit prediction script. In the high-lighted comboBox, the user must select when will the prediction script be executed.

For example, certain reporting scripts will usually run after the prediction has ended. On the contrary, certain initialization routines will generally run before the start of the prediction. Other scripts must be executed in every time step, and others between the Production and the Injection networks. It is very important to define the moment in which the particular script will run.

The different “placement” options of the routines are:

The script described here is run once at the beginning or end of each solver step. This is particularly useful when there are two networks, (such as Production & Injection) and the results of one network are used to influence constraints or the behavior of the other network.

PredStepSolverProlog/Epilog

This subroutine is executed at the beginning of each prediction step. The results of the previous time step can be used to evaluate changes or trigger actions in this script.

PredStepEpilog

This subroutine is executed at the beginning of each prediction step.PredStepProlog

Subroutine that is executed once at the end of the prediction. This is executed after all calculations are done.PredEpilog

Subroutine that is executed once at the beginning of the prediction. This is executed before any calculation is done.PredProlog

Page 5: Tutorial- G13.pdf

www.ifm-solutions.com© IFM-Solutions

5 / 6

As you can see, the use of PredStepProlog is redundant with the use of the PredStepSolverProlog for the Production system, as both instructions are executed at the same time. The same happens with the use of PredStepEpilog and PredStepSolverEpilog of the Injection system, they are exactly the same moment in time. However, the use of PredStepSolverEpilog for the Production network can be used to set constraints for the Injection system.

PredProlog

PredStepProlog

1st step 2nd step nth step Last step TIME

... ...

PredEpilog

PredStepEpilog

PredStepProlog

PredStepSolverProlog PredStepSolverEpilog

From the PRODUCTION SYSTEM

From the INJECTION SYSTEM

INJECTION SYSTEMPRODUCTION SYSTEM

nth step PredStepEpilog

PredStepSolverProlog PredStepSolverEpilog

GAP SCRIPTING DURING A PREDICTION – WRITING A SIMPLE SCRIPT

In this section of the tutorial we will write a simple script that can evaluate the total pressure drop of the trunk line (both sections) and make changes in the system upon that value.

First, find the Access String that relates to the Pressure drop for the two sectionsof the trunk line.4

Variable

Pressure Drop Trunk Line Section A

Pressure Drop Trunk Line Section B

Access String

Page 6: Tutorial- G13.pdf

www.ifm-solutions.com© IFM-Solutions

6 / 6

Save this tutorial as G-13.mbi

Run the prediction until 1/1/2020 With one month timestep size.6

When the pressure drop of the total trunk line falls below 100 psi, change the manifold pressure should be lowered to 1000psi. Add a condition to the script and run a prediction with the new condition. Report the change made using a LogMsg statement.

7

Now write a script that adds the pressure drop of the two parts of the trunk line and reports it for every time step using a LogMsg statement. Write that routine in the PredStepSolverEpilog Section.

5

At which time does the pressure drop of all the trunk line falls below 100psi? ___ /___ /______

It is recommended to use the Visual Basic functions CSng or CDbl to store values as numeric variables before adding the values.

the PredStepSolverEpilog Section.

It is recommended to use the Visual Basic functions CSng or CDbl to store values as numeric variables before adding the values.

Conditions are generally added using IF … THEN statements, just as in Visual Basic.Set the manifold pressure change using a DoSet command.The Separator Pressure Access String is GAP.MOD[{PROD}].SEP[{SEPARATOR}].SolverPres[0]

Conditions are generally added using IF … THEN statements, just as in Visual Basic.Set the manifold pressure change using a DoSet command.The Separator Pressure Access String is