You are on page 1of 10

'------------------------------------------------------------------------------' Project

:
MERLIN
' Procedure :
Form_Load
' Description:
[type_description_here]
' Created by :
Project Administrator
' Machine
:
JIM4550
' Date-Time :
8/15/2016-9:40:53 AM
'
' Parameters :
'------------------------------------------------------------------------------Private Sub Form_Load()
On Error GoTo Form_Load_Err
Dim I As Integer
PvtCorChg = False
FromLoad = True
LangSetupLocal = False
nReg = 1
PVTFluidSysTypeBut(PVTFluidSystem(nReg)).Value = True
nRegOld = nReg
RegBox = nReg
Call PossitionPanel(PVTCor, 3)
PlotLarge(1) = 0
PlotLarge(2) = 0
PlotLarge(3) = 0
sPMAX = pMax(nReg)
sRTEMP = RTemp(nReg)
sRhoSco = RhoSco(nReg)
sRhoScg = RhoScg(nReg)
sYN2 = YN2(nReg)
sYCO2 = YCO2(nReg)
sH2S = YH2S(nReg)
sRSI = RSI(nReg)
sSALIN = Salin(nReg)
sPbMsd = PbMsd(nReg)
sBobMsd = BobMsd(nReg)
sVobMsd = VobMsd(nReg)
sBobMsdInit = BobMsdInit(nReg)
'... JLB6-3-2015
sVobMsdInit = VobMsdInit(nReg)
'... JLB6-3-2015
sRVOInitMsd = RvoInitMsd(nReg)
'... JLB7-16-2015
sWetGasGravDew = WetGasGravDew(nReg) '... JLB7-16-2015
sPsep = Psep(nReg)
sTsep = Tsep(nReg)
sTamb = Tamb(nReg)
sTgrad = Tgrad(nReg)
sRockC = Str(GasPVT(1, 4, nReg))
PVTFluidSysTypeBut(PVTFluidSystem(nReg)).Value = True
EMW(1) = 600
UnderSatTempFlag = UnderSatOpt '... Load undersaturated flag and set check
box below JLB5-18-2015
ReDim ResetFlagUSatPress(nRegions(11))
'
'.. set regions flag for all regions 1[=] normal PVT and 2[=] PVT
'
If UnderSatOpt = 1 Then

UnderSat.Value = 1
For I = 1 To nRegions(11)
ResetFlagUSatPress(I) = 2
Next
Else
UnderSat.Value = 0
For I = 1 To nRegions(11)
ResetFlagUSatPress(I) = 1
Next
End If
PvtTabChg = False
For I = 2 To 10
EMW(I) = 600 - I * 50
Next
APIEMW(1) = 5
APIEMW(2) = 13
APIEMW(3) = 19
APIEMW(4) = 24
APIEMW(5) = 28
APIEMW(6) = 33
APIEMW(7) = 38
APIEMW(8) = 44
APIEMW(9) = 52
APIEMW(10) = 70
BPPF(1) = 0.17
BPPF(2) = 0.3
BPPF(3) = 0.43
BPPF(4) = 0.58
BPPF(5) = 0.75
BPPF(6) = 0.94
BPPF(7) = 1.19
BPPF(8) = 1.47
BPPF(9) = 1.74
BPPF(10) = 2.1
BPPF(11) = 2.7
BPPF(12) = 3.29
BPPF(13) = 3.8
BPPF(14) = 4.3
BPPF(15) = 4.9
BPPF(16) = 5.7
BPPF(17) = 6.7
For I = 1 To 17
GMF(I) = I * 0.05
Next
PvtT(1,
PvtT(1,
PvtT(1,
PvtT(1,
PvtT(2,
PvtT(2,
PvtT(2,

1)
2)
3)
4)
1)
2)
3)

=
=
=
=
=
=
=

"Oil Viscosity vs Pressure"


"Oil FVF vs Pressure"
"Gas:Oil Ratio vs Pressure"
"Condensate Yield vs Press" '... JLB6-26-2015
"Gas Viscosity. vs Pressure"
"Gas FVF vs Pressure"
"Rock Compressibility Msips"
'... JLB8-15-2015

PvtT(3, 1) = "Water Viscosity. vs Pressure"


PvtT(3, 2) = "Water FVF vs Pressure"
PaintForm
'PvtCorChg = False
If ReportModel Then
SaveBut.Enabled = False
TextArea.Enabled = False
End If
'
'... Define Rv constants JLB5-22-2015
'
'
'... First set of constants are to calculate DEw Point pressure (table 1 in
McCain paper)
'
C0Rv(1, 1) = 9.8895
C0Rv(2, 1) = 11.7
C0Rv(3, 1) = 3.5202
C0Rv(4, 1) = 0
'
C1Rv(1, 1) = -0.87528
C1Rv(2, 1) = -0.29709
C1Rv(3, 1) = -2.9145
C1Rv(4, 1) = 0
'
C2Rv(1, 1) = -0.01691
C2Rv(2, 1) = 0.00151
C2Rv(3, 1) = -0.81744
C2Rv(4, 1) = 0
'
C3Rv(1, 1) = 0
C3Rv(2, 1) = 0
C3Rv(3, 1) = 0
C3Rv(4, 1) = 0
'
C4Rv(1, 1) = 0
C4Rv(2, 1) = 0
C4Rv(3, 1) = 0
C4Rv(4, 1) = 0
'
'... Second Set of constants calculate yield curve (table 2 in McCain paper)
'
C0Rv(1, 2) = 20.809
C0Rv(2, 2) = 11.175
C0Rv(3, 2) = -13.365
C0Rv(4, 2) = -1.5309
'
C1Rv(1, 2) = -6.7095
C1Rv(2, 2) = -1.2965
C1Rv(3, 2) = 27.652
C1Rv(4, 2) = 0.0058453
'
C2Rv(1, 2) = 0.5136
C2Rv(2, 2) = 0.042311
C2Rv(3, 2) = -18.598
C2Rv(4, 2) = -0.0000014
'
C3Rv(1, 2) = 0

C3Rv(2, 2) = -0.00054
C3Rv(3, 2) = 4.3658
C3Rv(4, 2) = 0
'
C4Rv(1, 2) = 0
C4Rv(2, 2) = 0.00000249
C4Rv(3, 2) = 0
C4Rv(4, 2) = 0
'
'... Third set of constants calculate wet gas gravity (for gas proeprties be
low the dew point pressure)
'
C0Rv(1, 3) = -0.92913
C0Rv(2, 3) = -19.79538
C0Rv(3, 3) = 0
C0Rv(4, 3) = 0
'
C1Rv(1, 3) = 2.1688
C1Rv(2, 3) = 84.86958
C1Rv(3, 3) = 0
C1Rv(4, 3) = 0
'
C2Rv(1, 3) = -2.73343
C2Rv(2, 3) = -120.65049
C2Rv(3, 3) = 0
C2Rv(4, 3) = 0
'
C3Rv(1, 3) = 2.74921
C3Rv(2, 3) = 70.96942
C3Rv(3, 3) = 0
C3Rv(4, 3) = 0
'
C4Rv(1, 3) = 0
C4Rv(2, 3) = -15.24672
C4Rv(3, 3) = 0
C4Rv(4, 3) = 0
'
YieldAtBp.Text = Format(RvoInitMsd(nReg), "###.#")
'... J
LB7-16-2015
WetGasGrav.Text = Format(WetGasGravDew(nReg), "#.###")
'... J
LB7-16-2015
'
'.. define constants for rock Cr JLB8-11-2015
'
A_Var(1) = -0.00002399
A_Var(2) = 0.0001054
A_Var(3) = -0.0000285
'
B_Var(1) = 300
B_Var(2) = 500
B_Var(3) = 300
'
C_Var(1) = 0.0623
C_Var(2) = -0.225
C_Var(3) = 0.1395
'
D_Var(1) = 0.00004308
D_Var(2) = -0.00001103
D_Var(3) = 0.0001183
'

K1_Var(1)
K1_Var(2)
K1_Var(3)
'
K2_Var(1)
K2_Var(2)
K2_Var(3)
'
K3_Var(1)
K3_Var(2)
K3_Var(3)

= 0.85
= 0.9
= 0.85
= 0.8
= 0.9
= 0.85
= 0.45
= 0.6
= 0.55

Exit Sub
Form_Load_Err:
MsgBox Err.Description & vbCrLf & "in MERLIN.PVTCor.Form_Load ", vbExclamati
on + vbOKOnly, "Application Error"
Resume Next
End Sub
'------------------------------------------------------------------------------' Project
:
MERLIN
' Procedure :
CalcDewPress
' Description:
[type_description_here]
' Created by :
Project Administrator
' Machine
:
JIM4550
' Date-Time :
8/15/2016-9:40:53 AM
'
' Parameters :
API (Single)
'
WetGrav (Single)
'
YieldGas (Single)
'
Temp (Single)
'------------------------------------------------------------------------------Function CalcDewPress(API As Single, _
WetGrav As Single, _
YieldGas As Single, _
Temp As Single) As Single
On Error GoTo CalcDewPress_Err
'===========================================================================
===================================================================
'... From SPE paper "Tools to Manage Gas/Condensate Reservoirs:Novel Fluid-P
roperty Correlations on the Basis of Commonly Available Field Data"
'
Ovalle/Lenn/McCain
'... Calculate dew point pressure JLB6/17/2015
'... Interate using coefficients from yield correlation
'===========================================================================
===================================================================
Dim PBGuess
As Single
Dim IBoundLow

As Integer

Dim PBoundLow

As Single

Dim YieldBoundLow As Single

Dim IBoundHigh

As Integer

Dim PBoundHigh

As Single

Dim YieldBoundHigh As Single


Dim YieldChange

As Single

Dim iC

As Integer

Dim YieldTry

As Single

Dim IBoundSum

As Integer

Dim SlopeYield

As Single

Dim InterceptYield As Single


'
IBoundLow = -1
IBoundHigh = -1
YieldChange = 100
iC = 0
PBGuess = 5000
'
Do While YieldChange > 0.01 And iC < 1000 And PBGuess > 100
YieldTry = CalcGasYieldAtPress(Temp, API, WetGrav, PBGuess)
'
'... Reset bounds
'
IBoundSum = IBoundHigh + IBoundLow
If YieldTry > YieldGas Then
'
'... Reduce PBGuess by 100 psi, upper bound found
'
IBoundHigh = 0
PBoundHigh = PBGuess
YieldBoundHigh = YieldTry
'
If IBoundSum <> 0 Then
If PBGuess < 600 Then
PBGuess = PBGuess / 2#
Else
PBGuess = PBGuess - 300
End If
End If
ElseIf YieldTry < YieldGas Then
'
'... Reduce PBGuess by 100 psi, upper bound found
'
IBoundLow = 0
PBoundLow = PBGuess
YieldBoundLow = YieldTry
If IBoundSum <> 0 Then

PBGuess = PBGuess + 150


End If
End If
'
'... Find next pressure guess
'
If (IBoundSum) = 0 Then
'
'... Solution bounded - use interval halving to find solution
'
'SlopeYield = (YieldBoundHigh - YieldBoundLow) / (PBoundHigh - PBoun
dLow)
'InterceptYield = YieldBoundHigh - SlopeYield * PBoundHigh
PBGuess = (PBoundHigh + PBoundLow) / 2#
End If
'
'... Convergence criteria for the loop
'
YieldChange = Abs(YieldGas - YieldTry)
iC = iC + 1
Loop
CalcDewPress = PBGuess
Exit Function
CalcDewPress_Err:
MsgBox Err.Description & vbCrLf & "in MERLIN.PVTCor.CalcDewPress ", vbExclam
ation + vbOKOnly, "Application Error"
Resume Next
End Function
'------------------------------------------------------------------------------' Project
:
MERLIN
' Procedure :
CalcGasYieldAtPress
' Description:
[type_description_here]
' Created by :
Project Administrator
' Machine
:
JIM4550
' Date-Time :
8/15/2016-9:40:53 AM
'
' Parameters :
Temp (Single)
'
API (Single)
'
DewWetGasGrav (Single)
'
Press (Single)
'------------------------------------------------------------------------------Function CalcGasYieldAtPress(Temp As Single, _
API As Single, _
DewWetGasGrav As Single, _
Press As Single) As Single
On Error GoTo CalcGasYieldAtPress_Err
'=====================================================================
'... Calculate GasYield at or below dew point pressure JLB6/17/2015

'=====================================================================
Dim ZTot
As Double
Dim ZVar(4) As Double

+
+
+
+

'
VarCond(1) = Log(Press)
VarCond(2) = API
VarCond(3) = DewWetGasGrav
VarCond(4) = Temp
'
ZVar(1) = C0Rv(1, 2) + C1Rv(1, 2) * VarCond(1) + C2Rv(1,
C3Rv(1, 2) * VarCond(1) ^ 3 + C4Rv(1, 2) * VarCond(1) ^ 4
ZVar(2) = C0Rv(2, 2) + C1Rv(2, 2) * VarCond(2) + C2Rv(2,
C3Rv(2, 2) * VarCond(2) ^ 3 + C4Rv(2, 2) * VarCond(2) ^ 4
ZVar(3) = C0Rv(3, 2) + C1Rv(3, 2) * VarCond(3) + C2Rv(3,
C3Rv(3, 2) * VarCond(3) ^ 3 + C4Rv(3, 2) * VarCond(3) ^ 4
ZVar(4) = C0Rv(4, 2) + C1Rv(4, 2) * VarCond(4) + C2Rv(4,
C3Rv(4, 2) * VarCond(4) ^ 3 + C4Rv(4, 2) * VarCond(4) ^ 4
ZTot = ZVar(1) + ZVar(2) + ZVar(3) + ZVar(4)

2) * VarCond(1) ^ 2
2) * VarCond(2) ^ 2
2) * VarCond(3) ^ 2
2) * VarCond(4) ^ 2

'
If ZTot < 7 Then
CalcGasYieldAtPress = Exp(3.684 + 0.61967 * ZTot + 0.015359 * ZTot ^ 2)
Else
CalcGasYieldAtPress = 0
End If
'
Exit Function
CalcGasYieldAtPress_Err:
MsgBox Err.Description & vbCrLf & "in MERLIN.PVTCor.CalcGasYieldAtPress ", v
bExclamation + vbOKOnly, "Application Error"
Resume Next
End Function
'------------------------------------------------------------------------------' Project
:
MERLIN
' Procedure :
CalcGasGravAtPress
' Description:
[type_description_here]
' Created by :
Project Administrator
' Machine
:
JIM4550
' Date-Time :
8/15/2016-9:40:53 AM
'
' Parameters :
YieldGas (Single)
'
API (Single)
'
Press (Single)
'
Temp (Single)
'------------------------------------------------------------------------------Function CalcGasGravAtPress(YieldGas As Single, _
API As Single, _
Press As Single, _
Temp As Single) As Single

On Error GoTo CalcGasGravAtPress_Err


'=====================================================================
'... Calculate WetGasGrav at or below dew point pressure JLB6/17/2015
'=====================================================================
'===========================================================================
===================================================================
'... From SPE paper "Tools to Manage Gas/Condensate Reservoirs:Novel Fluid-P
roperty Correlations on the Basis of Commonly Available Field Data"
'
Ovalle/Lenn/McCain
'... Calculate dew point pressure JLB6/17/2015
'... Interate using coefficients from yield correlation
'===========================================================================
===================================================================
Dim GravGuess
As Single
Dim IBoundLow

As Integer

Dim GravBoundLow

As Single

Dim YieldBoundLow As Single


Dim IBoundHigh

As Integer

Dim GravBoundHigh As Single


Dim YieldBoundHigh As Single
Dim YieldChange

As Single

Dim iC

As Integer

Dim YieldTry

As Single

Dim IBoundSum

As Integer

Dim SlopeYield

As Single

Dim InterceptYield As Single


'
IBoundLow = -1
IBoundHigh = -1
YieldChange = 0.25
iC = 0
GravGuess = 1
'
Do While YieldChange > 0.001 And iC < 1000 And GravGuess > 0.4
YieldTry = CalcGasYieldAtPress(Temp, API, GravGuess, Press)
'
'... Reset bounds
'
IBoundSum = IBoundHigh + IBoundLow
If YieldTry > YieldGas Then
'
'... Reduce GravGuess by 100 psi, upper bound found
'
IBoundHigh = 0

GravBoundHigh = GravGuess
YieldBoundHigh = YieldTry
'
If IBoundSum <> 0 Then
If GravGuess < 0.5 Then
GravGuess = GravGuess / 2#
Else
GravGuess = GravGuess - 0.15
End If
End If
ElseIf YieldTry < YieldGas Then
'
'... Reduce GravGuess by 100 psi, upper bound found
'
IBoundLow = 0
GravBoundLow = GravGuess
YieldBoundLow = YieldTry
If IBoundSum <> 0 Then
GravGuess = GravGuess + 0.25
End If
End If
'
'... Find next pressure guess
'
If (IBoundSum) = 0 Then
'
'... Solution bounded - use interval halving to find solution
'
GravGuess = (GravBoundHigh + GravBoundLow) / 2#
End If
'
'... Convergence criteria for the loop
'
YieldChange = Abs(YieldGas - YieldTry)
iC = iC + 1
Loop
'
CalcGasGravAtPress = GravGuess
Exit Function
CalcGasGravAtPress_Err:
MsgBox Err.Description & vbCrLf & "in MERLIN.PVTCor.CalcGasGravAtPress ", vb
Exclamation + vbOKOnly, "Application Error"
Resume Next
End Function

You might also like