by_PoolIndex,function,character,character-method {SoilR}R Documentation

convert a function f of to f_vec

Description

convert a function f of to f_vec

Usage

## S4 method for signature ''function',character,character'
by_PoolIndex(obj, poolNames, timeSymbol)

Arguments

obj

For this method a function, whose formal arguments must have names that are elements of the union of poolNames and timeSymbol

poolNames

The ordered poolnames

timeSymbol

The name of the argument of obj that represents time.

Value

f_vec(vec,t) A new function that extracts the arguments of obj from a complete vector of state variables and the time argument t and applies the original function to these arguments The ode solvers used by SoilR expect a vector valued function of the state vector and time that represents the derivative. The components of this vector are scalar functions of a vector argument and time. It is possible for the user to define such functions directly, but the definition always depends on the order of state variables. Furthermore these functions usually do not use the complete state vector but only some parts of it. It is much clearer more intuitive and less error prone to be able to define functions that have only formal arguments that are used. This is what this method is used for.

Examples

leaf_resp=function(leaf_pool_content){leaf_pool_content*4}
leaf_resp(1)
poolNames=c(
   "some_thing"
  ,"some_thing_else"
  ,"some_thing_altogther"
  ,"leaf_pool_content"
)
leaf_resp_vec=by_PoolIndex(leaf_resp,poolNames,timeSymbol='t')
# The result is the same since the only the forth position in the vector
leaf_resp_vec(c(1,27,3,1),5) 

[Package SoilR version 1.2.107 Index]