Model {SoilR} | R Documentation |
This function creates an object of class Model, The arguments can be given in different form as long as they can be converted to the necessary internal building blocks. (See the links)
Model( t, A, ivList, inputFluxes, solverfunc = deSolve.lsoda.wrapper, pass = FALSE )
t |
A vector containing the points in time where the solution is sought. |
A |
something that can be converted by GeneralDecompOp to any of
the available subclasses of |
ivList |
A numeric vector containing the initial amount of carbon for the n pools. The length of this vector is equal to the number of pools. This is checked by an internal function. |
inputFluxes |
something that can be converted by InFluxes to any of the available subclasses of InFluxes. |
solverfunc |
The function used to actually solve the ODE system. The
default is |
pass |
Forces the constructor to create the model even if it does not pass internal sanity checks |
This function Model
wraps the internal constructor of class
Model. The internal constructor requires the argument A
to be of class DecompOp and argument inputFluxes
to be
of class InFluxes. Before calling the internal constructor
Model
calls GeneralDecompOp on its argument A
and
InFluxes on its argument inputFluxes
to convert them into
the required classes. Both are generic functions. Follow the links to see
for which kind of inputs conversion methods are available. The attempted
conversion allows great flexibility with respect to arguments and
independence from the actual implementation. However if your code uses the
wrong argument the error will most likely occur in the delegate functions.
If this happens inspect the error message (or use traceback()
) to see
which function was called and try to call the constructor of the desired
subclass explicitly with your arguments. The subclasses are linked in the
class documentation DecompOp or InFluxes
respectively.
Note also that this function checks its arguments quite elaborately and tries to detect accidental unreasonable combinations, especially concerning two kinds of errors.
unintended extrapolation of time series data
violations of mass balance by the DecompOp argument.
SoilR has a lot of unit tests which are installed with the package and are sometimes instructive as examples. To see example scenarios for parameter check look at:
An object of class Model that can be queried by many methods to be found there.
This function is called by many of the predefinedModels.
Package functions called in the examples:
example.2DInFluxes.Args
,
example.2DGeneralDecompOpArgs
,
# vim:set ff=unix expandtab ts=2 sw=2: test.all.possible.Model.arguments <- function(){ # This example shows different kinds of arguments to the function Model. # The model objects we will build will share some common features. # - two pools # - initial values iv<- c(5,6) times <- seq(1,10,by=0.1) # The other parameters A and inputFluxes will be different # The function Model will transform these arguments # into objects of the classes required by the internal constructor. # This leads to a number of possible argument types. # We demonstrate some of the possibilities here. # Let us first look at the choeices for argument 'A'. #) possibleAs <- example.2DGeneralDecompOpArgs() # Since "Model" will call "InFluxes" on its "inputFluxes" # argument there are again different choices # we have included a function in SoilR that produces 2D examples possibleInfluxes <- example.2DInFluxes.Args() print(possibleInfluxes$I.vec) # We can build a lot of models from the possible combinations # for instance #m1 <- Model( # t=times, # A=matrix(nrow=2,byrow=TRUE,c(-0.1,0,0,-0.2)), # ivList=iv, # inputFluxes=possibleInfluxes$I.vec) ## We now produce all combinations of As and InputFluxes combinations <- listProduct(possibleAs,possibleInfluxes) print(length(combinations)) # and a Model for each models <- lapply( combinations, function(combi){ #Model(t=times,A=combi$A,ivList=iv,inputFluxes=combi$I) Model(t=times,A=combi[[1]],ivList=iv,inputFluxes=combi[[2]]) } ) ## lets check that we can compute something# lapply(models,getC) }