-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDCA.NO.BU.R
225 lines (160 loc) · 5.33 KB
/
DCA.NO.BU.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
rm(list = ls())
library(dplyr)
#TypeWell <- read.csv("1Well.csv", header = TRUE)
#TypeWell$Oil <- as.numeric(TypeWell$Oil)
#TypeWell$Gas <- as.numeric(TypeWell$Gas)
###load for testing
econTbl <- read.csv("econTbl.csv", stringsAsFactors = FALSE)
#qi <- 100000
#b <- 1.1
#Di <- .75
#Dmin <- .10
forecast.years <- 30
Day.Month = "Months"
t.units <- ifelse(Day.Month == "Months", 12, 365)
prod.time <- forecast.years * t.units
abRate <- 150
pPhase <- quote(Oil)
ms <- 0 #multisegment forecast 1 = On 2 = Off
#time.ms <- 10 #time for multisegment forecast
#di.ms <- .1 #decline for multisgement decline
wellnames <- unique(econTbl$tcName[!is.na(econTbl$tcName)])
tc.num <- 1
tc.list <- list()
for(i in seq_len(length(wellnames)))
{
tc.list[i] <- list(wellnames[i])
}
t <- seq_len(prod.time)
t2 <- t - 1
Time1 <- 15
Yield1 <- 100
Yield2 <- 50
Yield3 <- 35
#class(b)
#qi <- 5000 *30.4
#Di <- 0.7
#class(qi)
DCA <- function(tc.num)
{
user.parms <- subset(econTbl, tcName == tc.list[tc.num])
qi <- as.numeric(user.parms[12]);
time.ms <- as.numeric(user.parms[13]);
di.ms <- as.numeric(user.parms[14]);
Di <- as.numeric(user.parms[15]);
b <- as.numeric(user.parms[16]);
Dmin <- as.numeric(user.parms[17]);
#Di <- Di/100
#Dmin <- Dmin/100
forecast.exp <-
if(ms == 1)
{ #multi.segment forecast = ms
t.ms <- seq_len(time.ms)
t.ms2 <- t.ms - 1
ai.ms <- -log(1-di.ms)/t.units
Exp.Np1.ms <- qi / ai.ms * (1 - exp(-ai.ms * t.ms))
Exp.Np2.ms <- qi / ai.ms * (1 - exp(-ai.ms * t.ms2))
exp.ms <- Exp.Np1.ms - Exp.Np2.ms
#t <- seq(time.ms, prod.time)
#t2 <- t - 1
qi <- qi * exp(-ai.ms * time.ms)
exp.ms
}
forecast.hyp <-
if(b == 0){
ai <- -log(1-Di)/t.units
Exp.Np1 <- qi / ai * (1 - exp(-ai * t))
Exp.Np2 <- qi / ai * (1 - exp(-ai * t2))
#exp <- data.frame(time = t.exp, prod.vol = Exp.Np1 - Exp.Np2)
Exp.Np1 - Exp.Np2
}else if(b == 1){
ai <- (Di / (1 - Di) / t.units)
Har.Np1 <- qi / ai * log(1 + ai * t)
Har.Np2 <- qi / ai * log(1 + ai * t2)
Har.Np1 - Har.Np2
}else{
###############Hyperbolic - b value is not 0 or 1
#determine parameters for Dmin
ai <- (1 / (t.units * b))*((1 - Di)^- b-1) #nominal deline per time units
a.yr <- (1 / b) * ((1 / (1 - Di))^b - 1) #nominal deline in years
t.trans <- ceiling(( a.yr / ( -log (1 - Dmin)) - 1)/( a.yr * b) * t.units) #time to reach Dmin
t.trans.seq <- seq(1:t.trans)
t.trans.seq2 <- t.trans.seq - 1
###########forecast to Dmin################
Hyp.Np.toDmin1 <- (qi / (( 1 - b) * ai)) * (1-(1/((1 + ai * b * t.trans.seq)^((1 - b) / b))))
Hyp.Np.toDmin2 <- (qi / (( 1 - b) * ai)) * (1-(1/((1 + ai * b * t.trans.seq2)^((1 - b) / b))))
Hyp.NpDmin <- Hyp.Np.toDmin1 - Hyp.Np.toDmin2
##########forecast expontintal to end of forecast years (Terminal decline portion of the curve)#########
aDmin <- -log(1 - Dmin)/t.units
q.trans <- qi / ((1 + b * ai * t.trans))^(1 / b) #rate at transition month
Np.trans <- (qi / (( 1 - b) * ai)) * (1-(1/((1 + ai * b * t.trans)^((1 - b) / b)))) #cum volume at tranistion month
t.exp.final <- seq(1:(prod.time - t.trans))
t.exp.final1 <- 0:(prod.time - t.trans - 1)
#########forecast from Dmin to end of forecast
Exp.Np1 <- Np.trans + q.trans / aDmin * (1 - exp(-aDmin * t.exp.final))
Exp.Np2 <- Np.trans + q.trans / aDmin * (1 - exp(-aDmin * t.exp.final1))
Exp.Np <- Exp.Np1 - Exp.Np2
append(Hyp.NpDmin, Exp.Np)
}
append(forecast.exp, forecast.hyp)
}
##############
xy <- DCA(1)
##########left off here...need to add in buildup...
plot(DCA(1))
dca.tbl <- map(seq_along(wellnames), DCA)
data.frame(wellnames, map_df(seq_along(wellnames), CF.Metrics))
AriesYield <- function(Time1, Yield1, Yield2, Yield3)
{
#calc nominal decline
a1 <- log( Yield1 / Yield2) / Time1
T1 <- seq(1 : Time1)
###1st segment
#ratio for end of the month
ratio1 <- Yield1 * exp( -a1 * T1)
ratio2 <- Yield1 * exp( -a1 * (T1 - 1))
#ratio used for the month
r1 <- if(Yield1 == Yield2)
{
ratio1
}else{
(ratio2 - ratio1) / a1
}
###2nd segment
T2 <- time - Time1
T3 <- seq(1 : T2)
##check to see if flat yield
if(Yield2 == Yield3)
{
#append the segments
append(r1, (rep(Yield2, T2)))
} else {
#calc nominal decline
a2 <- log(Yield2 / Yield3) / T2
#ratio for end of the month
ratio3 <- Yield2 * exp( -a2 * T3)
ratio4 <- Yield2 * exp( -a2 * (T3 - 1))
#append the segments
r2 <- (ratio4 - ratio3) / a2
append(r1,r2)
}
}
#TypeWell <- data.frame(Time = seq(1:time),
# qProd = DCA(qi, Di, b, Dmin),
# NpProd = cumsum(DCA(qi, Di, b, Dmin)),
# Yield = AriesYield(Time1, Yield1, Yield2, Yield3))
tw <- data.table(seq_len(time))
for(i in seq_len(nrow(econTbl)))
{
}
Econ_Metrics <- data.frame(wellnames, map_df(seq_along(wellnames), CF.Metrics))
typewell <- data.frame(Time = seq_len(time))
typewell <- typewell %>%
mutate(tcName = "tw--1",
Gas.mcf = DCA(qi, Di, b, Dmin),
Ratio = AriesYield(Time1, Yield1, Yield2, Yield3),
Oil.bbl = Gas.mcf / 1000 * Ratio)
head(typewell)
#EUR <- max(typewell$NpProd, na.rm = TRUE)/1000
#EUR
write.csv(typewell, file = "TW.csv",row.names=FALSE)