You are on page 1of 6

TUTORIAL G-13

Introduction to Scripting in GAP


OBJECTIVES
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

BASIC SCRIPTING COMMANDS


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

DoGet

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)

DoSet

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

DoCmd

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())

LogMsg

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

1/6

IFM-Solutions
www.ifm-solutions.com

ACCESS STRINGS
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 layers 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.

Using the GAP model provided, find out the Access String for the following
variables:
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.
Access String

Variable
Well 3: Reservoir Pressure
Node A: Pressure (From Solver Results)
Trunk Line A: Surrounding Temperature

2/6

IFM-Solutions
www.ifm-solutions.com

EXECUTE OPENSERVER STATEMENT WINDOW


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:

SELECT THE MODE HERE

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

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

Access String

Units

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

What does each Access String stand for?


Variable Represented

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

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

IFM-Solutions
www.ifm-solutions.com

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 highlighted 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:

PredProlog

Subroutine that is executed once at the beginning of the prediction. This is


executed before any calculation is done.

PredEpilog

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

PredStepProlog

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

PredStepEpilog

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.

PredStepSolver
Prolog/Epilog

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.

4/6

IFM-Solutions
www.ifm-solutions.com

PredProlog

PredEpilog
TIME

1st step

2nd step

...

nth step

PredStepProlog

PredStepProlog

...

Last step

PredStepEpilog

PredStepEpilog

nth step
PRODUCTION SYSTEM

PredStepSolverProlog

INJECTION SYSTEM

PredStepSolverEpilog

PredStepSolverProlog

From the
PRODUCTION SYSTEM

PredStepSolverEpilog

From the
INJECTION SYSTEM

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.

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 sections
of the trunk line.
Access String

Variable

Pressure Drop Trunk Line Section A


Pressure Drop Trunk Line Section B

5/6

IFM-Solutions
www.ifm-solutions.com

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.

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

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

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

___ /___ /______

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.
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]

Save this tutorial as G-13.mbi

6/6

IFM-Solutions
www.ifm-solutions.com

You might also like