# How to implement Flat Days or Ramp up period onto Auto Decline Curve Analysis (DCA) data function?

I've used the original Spotfire DCA workflow and added a few more bounds to the TC variables (b, IP, and De). Code looks to be flowing through correctly. My only qualm is being able to add a few if statements based on a ramp-up period when the well is originally flowing back. Some wells don't start IP until the second month, while others start at 0. The wells that IP immediately fit perfectly while the wells that IP either on Month 1 or Month 2 have a rather weird fit to the data. I'm trying to add a ramp-up or days flat period. Any help on this would be greatly appreciated.

Code below

``````Hyp.q.forward.fun = function( time, Hyp.qi, Hyp.b, Hyp.Di ){
Hyp.q.theo = Hyp.qi*(1 + Hyp.b*Hyp.Di*time)^(-1/Hyp.b)
return(Hyp.q.theo)
}

residfun = function(x,x.days,y.prod){
Hyp.qi = x
Hyp.b  = x
Hyp.Di = x
q.theo = (365.25/12)*Hyp.q.forward.fun(
time=x.days,
Hyp.qi=Hyp.qi,
Hyp.b=Hyp.b,
Hyp.Di=Hyp.Di)

residual = sqrt(sum((q.theo-y.prod)^2))
return(residual)
}

min.data = 3

result = data.frame(
time.days =  numeric(0),
time.months = numeric(0),
production = numeric(0),
theo = numeric(0)
)
Hyp.qi       =as.numeric(NA)
Hyp.b        =as.numeric(NA)
Hyp.Di.daily =as.numeric(NA)
Hyp.Di.annual=as.numeric(NA)

ok = length(col.Production)>0
if(ok) ok = length(col.Date) == length(col.Production)

if(ok){
u.order = order(col.Date)

col.Date       = col.Date[u.order]
col.Production = col.Production[u.order]

t.days = as.numeric(difftime(col.Date,min(col.Date),units="days"))
t.months = round(t.days*12/365.25)

u0 = which.max(col.Production)
u = u0:length(col.Production)

x.months = t.months[u]
x.days = t.days[u]
y.prod = col.Production[u]

x0 = c(y.prod*12/365.25,1.00,0.005)

optim.result = optim(
par = x0,
fn=residfun,
x.days=x.days, y.prod=y.prod,
lower=c(0,0,0),
upper=c(Inf, 1.6,Inf),
method="L-BFGS-B"

)

Hyp.qi = optim.result\$par*(365.25/12) # Monthly
Hyp.b  = optim.result\$par
Hyp.Di.daily  = optim.result\$par
Hyp.Di.annual = optim.result\$par*365.25 # Annualized

result = data.frame(
time.days   = x.days,
time.months = x.months,
production = y.prod
)
}
``````

DCA

Decline Curve Analysis

Oil and Gas Sector

Oil and Gas

Analytics

TERR

R