knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
This is the classical and simple example of predicting production in a reservoir given an OOIP.
The MBAL server is started the same way as in Prosper and GAP.
library(rOpenserver) # Initialize OpenServer # mbal_server <- .OpenServer$new() mbal_server <- openserver() # Start Prosper cmd = "MBAL.START" mbal_server$DoCmd(cmd)
We use a simple function to get the MBAl model filename. This function can be later generalized to retrieve any model type.
get_mbal_model <- function(model) { # get the well model models_dir <- system.file("models", package = "rOpenserver") model_file <- file.path(models_dir, model) if (!file.exists(model_file)) stop("Model not found ...") else return(model_file) }
Now, we open the MBAL model using the function shown above.
Let's keep in mind that MBAL opens files a little bit different. The filename needs to be surrounded with double quotes "
, not single quotes '
as in Prosper or GAP. We make that slight change and open the model.
# MBAL opens files a little bit different. The filename needs to be surrounded with # double quote not single quotes as in Prosper or GAP. model_file <- get_mbal_model(model = "oil.mbi") print(model_file) open_cmd <- 'MBAL.OPENFILE' open_cmd <- paste0(open_cmd, '("', model_file, '")') print(open_cmd) DoCmd(mbal_server, open_cmd) # using S3 dispatch of R6 class
Enter the OOIP and write to MBAL.
ooip <- 300 DoSet(mbal_server, "MBAL.MB.TANK.OOIP", ooip)
Run the prediction.
DoSlowCmd(mbal_server, "MBAL.MB.RUNPREDICTION")
And extract the first row of the table generated by the prediction.
# we get the oil rate from the first in the results table DoGet(mbal_server, "MBAL.MB.TRES[2][0][0].OILRATE")
# shutdown MBAL Sys.sleep(3) command = "MBAL.SHUTDOWN" mbal_server$DoCmd(command) mbal_server <- NULL
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.