---
title: "Raquifer"
output: rmarkdown::html_vignette
bibliography: REFERENCES.bib
csl: apa-6th-edition.csl
vignette: >
  %\VignetteIndexEntry{Raquifer}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```


## `Raquifer`

`Raquifer` estimates the cumulative water influx into hydrocarbon reservoirs using un-steady and pseudo-steady state modeling approaches. It generates a data frame of cumulative water influx over time for edge-drive and bottom-drive aquifers. Van Everdingen and Hurst un-steady state model for the constant terminal pressure solution predicts the cumulative influx for edge-water drive aquifers with radial flow [@VanEverdingen1949]. For the bottom-water drive aquifers with linear/radial flow, the Yildiz-Khosravi un-steady state model for the constant terminal pressure solution is used [@Yildiz2007]. Nabor and Barham linear flow model for the constant terminal pressure solution is used for the edge-water and bottom-water drive aquifers modeling[@Nabor1964]. For the linear and radial pseudo-steady state flow modeling in aquifers, the Fetkovich method is used [@Fetkovich1971]. 

Cumulative water influx predictions are generated by three different functions: `aquifer_param()`, `aquifer_time()`, and `aquifer_predict()`.


## `aquifer_param() arguments`

+ `input_unit`: A unit system for parameters, a character string either 'SI' or 'Field'
+ `output_unit`: A unit system for properties, a character string either 'SI' or 'Field'
+ `param model`: State of flow in the aquifer, a character string either 'uss' for the un-steady state flow or 'pss' for the pseudo-steady state flow
+ `flow_type`: A character string either 'radial' or 'linear'
+ `water_drive`: A character string either 'edge' or 'bottom'
+ `phi`: Aquifer porosity, a numeric fraction
+ `perm_h`: Aquifer horizontal permeability in 'md' in both 'SI' and 'Field' input unit systems. A NULL value must be used for the combination of 'uss', 'linear', and 'bottom' flow
+ `perm_v`: Aquifer vertical permeability in 'md' in both 'SI' and 'Field' input unit systems. A NULL value must be used for the combination of 'uss', 'linear', 'edge' flow. A NULL value must be used for the combination of 'uss', 'radial', 'edge' flow. A NULL value must be used for the combination of 'pss', 'radial', 'edge' flow.
+ `h_a`: Aquifer` height in 'm' or 'ft' in 'SI' and 'Field' input unit systems, respectively.
+ `r_a`: Aquifer radius in 'm' or 'ft' in 'SI' and 'Field' input unit systems, respectively. A NULL value must be used for the combination of 'uss', 'linear', 'edge' flow. A NULL value must be used for the combination of 'uss', 'linear', 'bottom' flow.
+ `r_R`: Reservoir radius in 'm' or 'ft' in 'SI' and 'Field' input unit systems, respectively. A NULL value must be used for the combination of 'uss', 'linear', 'edge' flow. A NULL value must be used for the combination of 'uss', 'linear', 'bottom' flow.
+ `w_a`: Aquifer width in 'm' or 'ft' in 'SI' and 'Field' input unit systems, respectively. A NULL value must be used for the combination of 'uss', 'radial', 'edge' flow. A NULL value must be used for the combination of 'uss', 'radial', 'bottom' flow. A NULL value must be used for the combination of 'pss', 'radial', 'edge' flow.
+ `l_a`: Aquifer length in 'm' or 'ft' in 'SI' and 'Field' input unit systems, respectively. A NULL value must be used for the combination of 'uss', 'radial', 'edge' flow. A NULL value must be used for the combination of 'uss', 'radial', 'bottom' flow. A NULL value must be used for the combination of 'pss', 'radial', 'edge' flow.
+ `tetha`: Fraction of reservoir encircled by the aquifer, reported in "degrees" in both 'SI' and 'Field' input unit systems. A NULL value must be used for the combination of 'uss', 'radial', 'bottom' flow. A NULL value must be used for the combination of 'uss', 'linear', 'edge' flow. A NULL value must be used for the combination of 'uss', 'linear', 'bottom' flow.
+ `mu_water`: Water viscosity in 'mPa.s' or 'cp' in 'SI' and 'Field' input unit systems, respectively
+ `c_water`: Water compressibility in '1/kPa' or '1/psi' in 'SI' and 'Field' input unit systems, respectively
+ `c_rock`: Rock compressibility in '1/kPa' or '1/psi' in 'SI' and 'Field' input unit systems, respectively
+ `pressure`: A numeric vector of pressure data at the boundary of reservoir/aquifer. Must have the same length as the 'aquifer_time()' object


## `aquifer_time() arguments`

+ `x`: A vector or sequence of times/dates.
+ `unit`: A unit system for input vector x.

## `aquifer_predict() arguments`

+ `aquifer_lst`: A list object of class 'decline'.
+ `time_lst`: A list object of class 'time'




## `Installation`

The `Raquifer` can be installed from [CRAN](https://CRAN.R-project.org) with:


```{r, eval = FALSE, warning = FALSE}
install.packages("Raquifer")
```



## `Examples` 

#### `Example 1: Un-steady state radial flow, edge-water drive`

```{r, fig.width = 6, fig.height= 4, fig.align = "center", warning = TRUE}
library(Raquifer)
library(ggplot2)
library(magrittr)

aqu_time <- aquifer_time(x = c(0,0.368,2.439,4.957,7.732,11.926,18.126,30.044) * 365, unit = "day")

parameters <- aquifer_param(input_unit = "Field", output_unit = "Field", model = "uss", 
                            flow_type = "radial", water_drive = "edge", phi = 0.27, perm_h = 64.2, 
                            h_a = 20, r_a = 5 * 14892, r_R = 14892, tetha = 180,
                            mu_water = 0.485, c_water = 3.88e-6, c_rock = 2e-6, 
                            pressure = c(1640,1600,1400,1200,1000,800,600,400))

aqu_time

parameters

pred_veh <- aquifer_predict(aquifer_lst = parameters, time_lst = aqu_time)

head(pred_veh)

pred_veh %>% ggplot(aes(x = `Time (days)`, y = `We (MMbbl)`)) +
  geom_point(size = 3, color = "blue") +
  theme_bw()

```


#### `Example 2: Un-steady state radial flow, bottom-water drive`

```{r, fig.width = 6, fig.height= 4, fig.align = "center", warning = TRUE}
library(Raquifer)
library(ggplot2)
library(magrittr)

aqu_time <- aquifer_time(x = c(0,0.368,2.439,4.957,7.732,11.926,18.126,30.044) * 365, unit = "day")

parameters <- aquifer_param(input_unit = "Field", output_unit = "Field", model = "uss", 
                            flow_type = "radial", water_drive = "bottom", phi = 0.27, perm_h = 64.2, 
                            perm_v = 64.2, h_a = 20, r_a = 5 * 14892, r_R = 14892, 
                            mu_water = 0.485, c_water = 3.88e-6, c_rock = 2e-6, 
                            pressure = c(1640,1600,1400,1200,1000,800,600,400))

pred_ykh <- aquifer_predict(aquifer_lst = parameters, time_lst = aqu_time)

head(pred_ykh)

pred_ykh %>% ggplot(aes(x = `Time (days)`, y = `We (MMbbl)`)) +
  geom_point(size = 3, color = "blue") +
  theme_bw()

```


#### `Example 3: Pseudo-steady state radial flow, edge-water drive`

```{r, fig.width = 6, fig.height= 4, fig.align = "center", warning = TRUE}
library(Raquifer)
library(ggplot2)
library(magrittr)

aqu_time <- aquifer_time(x = c(0,0.368,2.439,4.957,7.732,11.926,18.126,30.044) * 365, unit = "day")

parameters <- aquifer_param(input_unit = "Field", output_unit = "Field", model = "pss", 
                            flow_type = "radial", water_drive = "edge", phi = 0.27, perm_h = 64.2, 
                            h_a = 20, r_a = 5 * 14892, r_R = 14892, tetha = 180,
                            mu_water = 0.485, c_water = 3.88e-6, c_rock = 2e-6, 
                            pressure = c(1640,1600,1400,1200,1000,800,600,400))

pred_fetk <- aquifer_predict(aquifer_lst = parameters, time_lst = aqu_time)

head(pred_fetk)

pred_fetk %>% ggplot(aes(x = `Time (days)`, y = `We (MMbbl)`)) +
  geom_point(size = 3, color = "blue") +
  theme_bw()

```



#### `Example 4: Un-steady state linear flow, edge-water drive`

```{r, fig.width = 6, fig.height= 4, fig.align = "center", warning = TRUE}
library(Raquifer)
library(ggplot2)
library(magrittr)

aqu_time <- aquifer_time(x = c(0,0.368,2.439,4.957,7.732,11.926,18.126,30.044) * 365, unit = "day")

parameters <- aquifer_param(input_unit = "Field", output_unit = "Field", model = "uss", 
                            flow_type = "linear", water_drive = "edge", phi = 0.27, perm_h = 64.2, 
                            h_a = 20, w_a = 29784, l_a = 161145, mu_water = 0.485, c_water = 3.88e-6, 
                            c_rock = 2e-6, pressure = c(1640,1600,1400,1200,1000,800,600,400))

pred_nb_01 <- aquifer_predict(aquifer_lst = parameters, time_lst = aqu_time)

head(pred_nb_01)

pred_nb_01 %>% ggplot(aes(x = `Time (days)`, y = `We (MMbbl)`)) +
  geom_point(size = 3, color = "blue") +
  theme_bw()

```



#### `Example 5: Un-steady state linear flow, bottom-water drive`

```{r, fig.width = 6, fig.height= 4, fig.align = "center", warning = TRUE}
library(Raquifer)
library(ggplot2)
library(magrittr)

aqu_time <- aquifer_time(x = c(0,0.368,2.439,4.957,7.732,11.926,18.126,30.044) * 365, unit = "day")

parameters <- aquifer_param(input_unit = "Field", output_unit = "Field", model = "uss", 
                            flow_type = "linear", water_drive = "bottom", phi = 0.27, perm_v = 64.2, 
                            h_a = 20, w_a = 29784, l_a = 161145, mu_water = 0.485, c_water = 3.88e-6, 
                            c_rock = 2e-6, pressure = c(1640,1600,1400,1200,1000,800,600,400))

pred_nb_02 <- aquifer_predict(aquifer_lst = parameters, time_lst = aqu_time)

head(pred_nb_02)

pred_nb_02 %>% ggplot(aes(x = `Time (days)`, y = `We (MMbbl)`)) +
  geom_point(size = 3, color = "blue") +
  theme_bw()

```



#### `Example 6: Pseudo-steady state linear flow, edge-water drive`

```{r, fig.width = 6, fig.height= 4, fig.align = "center", warning = TRUE}
library(Raquifer)
library(ggplot2)
library(magrittr)

aqu_time <- aquifer_time(x = c(0,0.368,2.439,4.957,7.732,11.926,18.126,30.044) * 365, unit = "day")

parameters <- aquifer_param(input_unit = "Field", output_unit = "Field", model = "pss", 
                            flow_type = "linear", water_drive = "edge", phi = 0.27, perm_h = 64.2, 
                            h_a = 20, w_a = 29784, l_a = 161145, mu_water = 0.485, c_water = 3.88e-6, 
                            c_rock = 2e-6, pressure = c(1640,1600,1400,1200,1000,800,600,400))

parameters

pred_fetk_02 <- aquifer_predict(aquifer_lst = parameters, time_lst = aqu_time)

head(pred_fetk_02)

pred_fetk_02 %>% ggplot(aes(x = `Time (days)`, y = `We (MMbbl)`)) +
  geom_point(size = 3, color = "blue") +
  theme_bw()

```




#### `Example 7: Pseudo-steady state linear flow, bottom-water drive`

```{r, fig.width = 6, fig.height= 4, fig.align = "center", warning = TRUE}
library(Raquifer)
library(ggplot2)
library(magrittr)

aqu_time <- aquifer_time(x = c(0,0.368,2.439,4.957,7.732,11.926,18.126,30.044) * 365, unit = "day")

parameters <- aquifer_param(input_unit = "Field", output_unit = "Field", model = "pss", 
                            flow_type = "linear", water_drive = "bottom", phi = 0.27, perm_v = 64.2, 
                            h_a = 20, w_a = 29784, l_a = 161145, mu_water = 0.485, c_water = 3.88e-6, 
                            c_rock = 2e-6, pressure = c(1640,1600,1400,1200,1000,800,600,400))

pred_fetk_03 <- aquifer_predict(aquifer_lst = parameters, time_lst = aqu_time)

head(pred_fetk_03)

pred_fetk_03 %>% ggplot(aes(x = `Time (days)`, y = `We (MMbbl)`)) +
  geom_point(size = 3, color = "blue") +
  theme_bw()

```



#### `Example 8: Un-steady state radial flow, edge-water drive`

```{r, fig.width = 6, fig.height= 4, fig.align = "center", warning = TRUE}
library(Raquifer)
library(ggplot2)
library(magrittr)

aqu_time <- aquifer_time(x = seq(as.Date("2020/1/1"), by = "year", length.out = 8), unit = "date")

parameters <- aquifer_param(input_unit = "Field", output_unit = "SI", model = "uss", 
                            flow_type = "radial", water_drive = "edge", phi = 0.27, perm_h = 64.2, 
                            h_a = 20, r_a = 5 * 14892, r_R = 14892, tetha = 180,
                            mu_water = 0.485, c_water = 3.88e-6, c_rock = 2e-6, 
                            pressure = c(1640,1600,1400,1200,1000,800,600,400))

aqu_time

parameters

pred_veh <- aquifer_predict(aquifer_lst = parameters, time_lst = aqu_time)

head(pred_veh)

pred_veh %>% ggplot(aes(x = `Time (days)`, y = `We (m3)`)) +
  geom_point(size = 3, color = "blue") +
  theme_bw()

```



#### `Example 8: Un-steady state radial flow, edge-water drive`

```{r, fig.width = 6, fig.height= 4, fig.align = "center", warning = TRUE}
library(Raquifer)
library(ggplot2)
library(magrittr)

aqu_time <- aquifer_time(x = 1:8, unit = "month")

parameters <- aquifer_param(input_unit = "Field", output_unit = "SI", model = "uss", 
                            flow_type = "radial", water_drive = "edge", phi = 0.27, perm_h = 64.2, 
                            h_a = 20, r_a = 5 * 14892, r_R = 14892, tetha = 180,
                            mu_water = 0.485, c_water = 3.88e-6, c_rock = 2e-6, 
                            pressure = c(1640,1600,1400,1200,1000,800,600,400))

aqu_time

parameters

pred_veh <- aquifer_predict(aquifer_lst = parameters, time_lst = aqu_time)

head(pred_veh)

pred_veh %>% ggplot(aes(x = `Time (months)`, y = `We (m3)`)) +
  geom_point(size = 3, color = "blue") +
  theme_bw()

```

## `References`