setup_statevars {care4cmodel}R Documentation

State Variable Setup and Initialization Given a c4c_concept concept definition, and a matching vector of initial areas the state variables required for simulating the concept are set up and initialized.

Description

The state variables to be created are the areas attributed to the single stand development phases defined in the concept definition of interest. More precisely, each subphase has an area which is a state variable. When initializing, the intial areas can be given for each phase in init_areas, or for each subphase. In the former case the initial phase areas are equally divided among the respective subphases.
In order to allow post-hoc reconstruction of the area flows, the function also creates the cumulative inflows and outflows to each subphase area as state variables and initializes them with 0.

Usage

setup_statevars(concept_def, init_areas, detailed = FALSE)

Arguments

concept_def

The concept definition of interest as a c4c_object

init_areas

A vector providing the initial areas for the stand development (sub) phases defined in concept_def in the same order. In case init_areas relates to the phases, detailed must be FALSE. If it relates directly to the subphases, detailed must be TRUE. In the former case, the areas given for a phase are equally divided among its subphases. The areas must be given in the same area unit as named in concept_def, usually ha.

detailed

Logical, FALSE (default) indicates that init_areas is given for each stand development phase (and will be equally distributed among the subphases). TRUE indicates that init_areas is directly given for each subphase.

Value

A vector which is actually a sequence of three different blocks. This format is required for simulations with deSolve. Each block has as many elements as the total number of subpbases defined in concept_def. Each element refers to each subphase in the order of the phase sequence. The first block, contains the initial areas attributed to all subphases in the order of the phase sequence. The second and the third block will track the cumulative in- and outflows of each area during the simulation. They are initialized with 0.

Examples

  # Initialize with phase wise initial areas
  init_areas <- c(1000, 400, 250, 125, 125, 100)
  state_vars <- pine_thinning_from_above_1 |> setup_statevars(init_areas)
  state_vars

  # Initialize with subphase wise initial areas
  # Assume, we are afforesting 1000 ha, so all area has to be initially in
  # the first subphase of the first stand development phase
  n_sub <- sum(pine_thinning_from_above_1$growth_and_yield$n_subphases)
  init_areas    <- rep(0, n_sub)
  init_areas[1] <- 1000
  state_vars    <- setup_statevars(pine_thinning_from_above_1,
                                   init_areas,
                                   detailed = TRUE)
  state_vars


[Package care4cmodel version 1.0.1 Index]