R/odin.R

Defines functions vaccine

## Automatically generated by odin 1.3.3 - do not edit
vaccine_ <- R6::R6Class(
  "odin_model",
  cloneable = FALSE,

  private = list(
    ptr = NULL,
    use_dde = NULL,

    odin = NULL,
    variable_order = NULL,
    output_order = NULL,
    n_out = NULL,
    ynames = NULL,
    interpolate_t = NULL,
    cfuns = list(
      rhs_dde = "vaccine_rhs_dde",
      rhs_desolve = "vaccine_rhs_desolve",
      initmod_desolve = "vaccine_initmod_desolve",
      output_dde = "vaccine_output_dde"),
    dll = "nimue",
    user = c("beta_set", "D_0", "E1_0", "E2_0", "gamma_E",
             "gamma_get_mv_die", "gamma_get_mv_survive", "gamma_get_ox_die",
             "gamma_get_ox_survive", "gamma_ICase", "gamma_IMild",
             "gamma_not_get_mv_die", "gamma_not_get_mv_survive",
             "gamma_not_get_ox_die", "gamma_not_get_ox_survive", "gamma_R",
             "gamma_rec", "gamma_vaccine", "hosp_beds", "ICase1_0",
             "ICase2_0", "ICU_beds", "IMild_0", "IMVGetDie1_0",
             "IMVGetDie2_0", "IMVGetLive1_0", "IMVGetLive2_0",
             "IMVNotGetDie1_0", "IMVNotGetDie2_0", "IMVNotGetLive1_0",
             "IMVNotGetLive2_0", "IOxGetDie1_0", "IOxGetDie2_0",
             "IOxGetLive1_0", "IOxGetLive2_0", "IOxNotGetDie1_0",
             "IOxNotGetDie2_0", "IOxNotGetLive1_0", "IOxNotGetLive2_0",
             "IRec1_0", "IRec2_0", "max_vaccine", "mix_mat_set", "N_age",
             "N_prioritisation_steps", "N_vaccine", "prob_hosp",
             "prob_hosp_multiplier", "prob_non_severe_death_no_treatment",
             "prob_non_severe_death_treatment", "prob_severe",
             "prob_severe_death_no_treatment", "prob_severe_death_treatment",
             "prob_severe_multiplier", "R1_0", "R2_0", "rel_infectiousness",
             "rel_infectiousness_vaccinated", "S_0", "tt_beta",
             "tt_dur_get_mv_die", "tt_dur_get_mv_survive",
             "tt_dur_get_ox_die", "tt_dur_get_ox_survive", "tt_dur_R",
             "tt_hosp_beds", "tt_ICU_beds", "tt_matrix",
             "tt_prob_hosp_multiplier", "tt_prob_severe_multiplier",
             "tt_vaccine", "tt_vaccine_efficacy_disease",
             "tt_vaccine_efficacy_infection", "vaccine_coverage_mat",
             "vaccine_efficacy_infection"),

    ## This is never called, but is used to ensure that R finds our
    ## symbols that we will use from the package; without this they
    ## cannot be found by dynamic lookup now that we use the package
    ## FFI registration system.
    registration = function() {
      if (FALSE) {
        .C("vaccine_rhs_dde", package = "nimue")
        .C("vaccine_rhs_desolve", package = "nimue")
        .C("vaccine_initmod_desolve", package = "nimue")
        .C("vaccine_output_dde", package = "nimue")
      }
    },

    ## This only does something in delay models
    set_initial = function(t, y, use_dde) {
      .Call("vaccine_set_initial", private$ptr, t, y, use_dde,
            PACKAGE= "nimue")
    },

    update_metadata = function() {
      meta <- .Call("vaccine_metadata", private$ptr,
                    PACKAGE = "nimue")
      private$variable_order <- meta$variable_order
      private$output_order <- meta$output_order
      private$n_out <- meta$n_out
      private$ynames <- private$odin$make_names(
        private$variable_order, private$output_order, FALSE)
      private$interpolate_t <- meta$interpolate_t
    }
  ),

  public = list(
    initialize = function(..., user = list(...), use_dde = FALSE,
                          unused_user_action = NULL) {
      private$odin <- asNamespace("odin")
      private$ptr <- .Call("vaccine_create", user, PACKAGE = "nimue")
      self$set_user(user = user, unused_user_action = unused_user_action)
      private$use_dde <- use_dde
      private$update_metadata()
    },

    ir = function() {
      path_ir <- system.file("odin/vaccine.json", mustWork = TRUE,
                             package = "nimue")
      json <- readLines(path_ir)
      class(json) <- "json"
      json
    },

    ## Do we need to have the user-settable args here? It would be
    ## nice, but that's not super straightforward to do.
    set_user = function(..., user = list(...), unused_user_action = NULL) {
      private$odin$support_check_user(user, private$user, unused_user_action)
      .Call("vaccine_set_user", private$ptr, user, PACKAGE = "nimue")
      private$update_metadata()
    },

    ## This might be time sensitive and, so we can avoid computing
    ## it. I wonder if that's an optimisation we should drop for now
    ## as it does not seem generally useful. This would bring us
    ## closer to the js version which requires that we always pass the
    ## time in.
    initial = function(t) {
      .Call("vaccine_initial_conditions", private$ptr, t, PACKAGE = "nimue")
    },

    rhs = function(t, y) {
      .Call("vaccine_rhs_r", private$ptr, t, y, PACKAGE = "nimue")
    },

    deriv = function(t, y) {
      self$rhs(t, y)
    },

    contents = function() {
      .Call("vaccine_contents", private$ptr, PACKAGE = "nimue")
    },

    transform_variables = function(y) {
      private$odin$support_transform_variables(y, private)
    },

    engine = function() {
      "c"
    },

    run = function(t, y = NULL, ..., use_names = TRUE) {
      private$odin$wrapper_run_ode(
        self, private, t, y, ..., use_names = use_names)
    }
  ))


vaccine <- function(..., user = list(...), use_dde = FALSE,
                     unused_user_action = NULL) {
  asNamespace("odin")$deprecated_constructor_call("vaccine")
  vaccine_$new(user = user, use_dde = use_dde,
                unused_user_action = unused_user_action)
}
class(vaccine) <- "odin_generator"
attr(vaccine, "generator") <- vaccine_
mrc-ide/nimue documentation built on March 25, 2022, 4:45 a.m.