work/call_salmodll_macrophytes.R

#' Call SALMO Shared Library
#' 
#' Call the shared library of SALMO (with additional states and parameters for
#' macrophyte coupling)
#' 
#' 
#' @param cfunc string, name of the C function to be called
#' @param nOfVar vector with number of variables
#' @param cc vector of constants for the model
#' @param pp matrix of phytoplankton parameters
#' @param uu input vector (environmental conditions)
#' @param xx state vector
#' @param pm parameters for macrophytes
#' @param mx states of macrophytes (ReacTran format)
#'
#' @return list, containing the derivatives as first element
#' 
#' @export call_salmodll_macrophytes
call_salmodll_macrophytes <-
function(
  cfunc,         # name of the C function to be called
  nOfVar,        # number of variables
  cc,            # vector of constants for the model
  pp,            # matrix for phytoplankton parameters
  uu,            # vector of boundary conditions
  xx,            # state variables
  pm,            # parameters for macrophytes
  mx             # states of macrophytes (ReacTran format)
){
  ## create empty data structure for derivatives
  dxx <- numeric(length(xx))
  ## sort order of states for use with SALMO
  xx  <- sortSalmo(xx, nOfVar["numberOfStates"], nOfVar["numberOfLayers"])
  ## call C function
  ret <- .C(
    cfunc,
    as.integer(nOfVar),
    cc = as.double(cc),
    pp = as.double(pp),
    uu = as.double(uu),
    xx = as.double(xx),
    dxx = as.double(dxx),
    pm = as.double(pm),
    mx = as.double(mx),
    aFunVegRes = as.double(numeric(nOfVar["numberOfLayers"]))
  )
  ## sort derivatives for use with ReacTran,
  ## Attention: inputs uu and states xx are still in SALMO format
  ##            for use with macrophyte module
  list(arrangeStateWise(ret$dxx, nOfVar["numberOfStates"],
    nOfVar["numberOfLayers"]), ret$uu, ret$xx, ret$aFunVegRes)
  ## SALMO format of derivatives
  #  list(ret$dxx, ret$uu, ret$xx)
}

Try the rSALMO package in your browser

Any scripts or data that you put into this service are public.

rSALMO documentation built on May 2, 2019, 6:12 p.m.