3 Using OpenServer
3.5 Multiple Values for Arrays
This section describes how the DoSet / DoGet functions are used to retrieve and set more than one item in an array.
3.5.1 Multiple DoGet Values
Consider a situation where one wishes to extract tank pressures from a 5-tank MBAL model.
The following fragment of VBA code could be used:
Range("C1") = DoGet("MBAL.MB.TANK[0].PRESS") Range("C2") = DoGet("MBAL.MB.TANK[1].PRESS") Range("C3") = DoGet("MBAL.MB.TANK[2].PRESS") Range("C4") = DoGet("MBAL.MB.TANK[3].PRESS") Range("C5") = DoGet("MBAL.MB.TANK[4].PRESS")
A quicker method is to get all the pressures in one DoGet call, and there are two options to achieve the objective:
- Get the pressures for all the available tanks: Range("C1") = DoGet("
MBAL.MB.TANK[$].PRESS")
- Get the pressures for tank index zero through to tank index four: Range ("C1") = DoGet("MBAL.MB.TANK[0,1,2,3,4].PRESS")
The above example using multiple DoGet calls will return all the tank pressures in the model.
The values will be returned in a single text variable separated by the ‘|’ character e.g.
5132.0|4893.0|4598.3|4882.0|4976.6
There are several other variations which can be used to extract data from multiple tanks using the following syntax:
- Return the pressure for tank 0,1,2 and 4: Range("C1") = DoGet("MBAL .MB.TANK[0:2,4].PRESS")
- Return the pressure for tank 1 and 3: Range("C1") = DoGet("MBAL.
MB.TANK[1,3].PRESS")
3.5.2 Multiple DoSet Values
The DoSet function can use multiple tag names in a similar manner to the DoGet function as previously described. All the different forms of the variable tag names used by the DoGet can be used for the DoSet function.
For the DoSet function, a text variable is passed to the function which contains a list of the values to set, separated by the ‘|’ character. For example, the following string can be used to set multiple OOIP's in a multi-tank system to tank 1, 4 and 5:
DoSet " MBAL. MB. TANK[ 1, 4, 5] . OOI P" , " 250. 0| 129. 0|
349. 0"
The above command will set the OOIP of tank index 1 to 250.0, tank index 4 to 129.0 and tank index 5 to 349.0.
There is an extra feature available with the DoSet function, where all tanks specified in the indices array [1,4,5] can have the same OOIP assigned using the following DoSet command:
DoSet " MBAL. MB. TANK[ 1, 4, 5] . OOI P" , " 250. 0"
The above technique can be used to set many items in a list to the same value.
3.5.3 Using More than One Multiple Array
The examples shown so far allow more than one index of a particular array to be accessed. However, we can also access multiple indices of more than one array at a time.
Consider the tag name for accessing the production data for an MBAL tank:
MBAL.MB.TANK[2].PRODHIST[4].CUMOIL
This tag identifies the Np for the 4th index of the production history table for the 2nd index
tank.
We have already seen how we could access more than one production history record or more than one tank e.g. :
MBAL.MB.TANK[2].PRODHIST[3 :7].CUMOIL MBAL.MB.TANK[$].PRODHIST[4].CUMOIL
However we can also have multiple indices for both the production history records and the tank in the same tag name.
For example :
DoSet "MBAL.MB.TANK[1,2].PRODHIST[4:6]", "11.2|14.5|16.3|
5.2|6.1|7.5"
The above command sets indices 4, 5 and 6 of the production history for both tanks 1 and 2. The data in the values to set is ordered such that the index to the right varies first.
In other words the order is:
MBAL.MB.TANK[1].PRODHIST[4].CUMOIL MBAL.MB.TANK[1].PRODHIST[5].CUMOIL MBAL.MB.TANK[1].PRODHIST[6].CUMOIL MBAL.MB.TANK[2].PRODHIST[4].CUMOIL MBAL.MB.TANK[2].PRODHIST[5].CUMOIL MBAL.MB.TANK[2].PRODHIST[6].CUMOIL
As before, this method will work equally well for the DoGet function.
The example shown above has two arrays. However, it is possible to use multiple indices for any number of arrays in a tag string e.g. :
MBAL.MB.WELL[1:3].IPR[4,7].CONEMATCH[$][3,5:8].PRESS
3.6 Units
Units are handled the same way in all the IPM programs.
Use of Units in OpenServer:
By default, when a variable is accessed from the OpenServer using the DoGet function, the value returned is in the same units as defined for the current model.
For example, if a GAP model has degrees Celcius selected for the surface temperature variable of pipes, and the value entered for pipe ‘pipe3’ is 10 degrees C, then performing a DoGet on the tag “GAP.MOD[0].PIPE[{pipe3}].TMPSUR” will return 10.
Similarly, when a DoSet function is used, the value passed to the function is interpreted as being in the current unit displayed in the interface.
The units a variable is using can be queried using the UNITNAME(tag) function. This function will return the units label currently in use for that variable.
For example, performing a DoGet function on the string “GAP.UNITNAME(MOD[0].
PIPE[{pipe3}].TMPSUR)” would return the string “degrees C”.
The same information can be obtained by appending UNITNAME to a tag e.g. “GAP.
MOD[0].PIPE[{pipe3}].TMPSUR.UNITNAME”
There are a number of ways of modifying the above behaviour.
Variables are normally stored internally in the programs in field units. To access a variable in field units, not the currently selected unit, use the RAWVAL(tag) function.
For example, performing a DoGet on the string “GAP.RAWVAL(GAP.MOD[0].PIPE [{pipe3}].TMPSUR)” would return 50, since field units for temperature are degrees F.
Similarly, if the RAWVAL modifier is used for a tag name with a DoSet function, the OpenServer will interpret the passed value as being in Oil Field units.
The automatic conversion of variable values from field units to user selected units can be switched off completely if desired. This is accomplished by setting the global variable DOUNITCONV, which is 1 by default, to zero. E.g.:
DoSet “PROSPER.DOUNITCONV”, “0”
Setting the above flag means all subsequent DoGet and DoSet calls will use Oilfield units. Note that unit conversion can be switched on again by setting the DOUNITCONV variable back to 1.
The currently selected units system can be set using the SETUNITSYS() function.
Performing a DoCmd on the string “MBAL.SETUNITSYS(""Norwegian S.I."")” will set the input and output units to the Norwegian S.I. system for the current MBAL model.
Use of Units Validation Ranges in OpenServer:
There are also methods to get and set the minimum and maximum validation ranges as defined in the units system dialog.
To get the minimum value of variable, add UNITMIN to the end of the tag name e.g.
Range("C1") = DoGet("MBAL.MB.TANK[0].PRESS.UNITMIN") Similarly, the maximum validation range of a unit value can be obtained by appending
the tag with UNITMAX.
Minimum and maximum values of a variable with the same tag can be changed by using the DoSet function as per the following example:
DoSet “MBAL.MB.TANK[0].PRESS.UNITMAX”, “15000.0”