R/ConstantInFluxRate_by_PoolIndex.R

Defines functions ConstantInFluxRate_by_PoolIndex

#' @template FluxRate
#'
#' @autocomment 
#' @s4superclasses
#' @s4subclasses
#' @s4methods
setClass(
   Class="ConstantInFluxRate_by_PoolIndex",
   slots=c(destinationIndex='PoolIndex',rate_constant='numeric')
)

ConstantInFluxRate_by_PoolIndex<-function(destinationIndex,rate_constant){
    if (rate_constant<0){
        stop(
            "Negative rate constant. 
            A rate_constant defines a flux F with F = rate_constant*pool_content. 
            Since fluxes have to be positive and pool contents are positive
            rate constants have to be positive too."
        )
    }
    new(
        'ConstantInFluxRate_by_PoolIndex'
        ,destinationIndex=PoolIndex(id=destinationIndex)
        ,rate_constant=rate_constant
    )
}

#' new object with the source pool id converted to a PoolIndex if necessary 
#' @param obj an object of class ConstantInFluxRate_by_PoolIndex
#' @param poolNames names of pools
setMethod(
    f="by_PoolName",
    signature=c(obj='ConstantInFluxRate_by_PoolIndex'),
    def=function(obj,poolNames){
        new(
            "ConstantInFluxRate_by_PoolName"
            ,destinationName=PoolName(id=obj@destinationIndex ,poolNames)
            ,rate_constant=obj@rate_constant
        )
    }
)

Try the SoilR package in your browser

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

SoilR documentation built on Oct. 13, 2023, 5:06 p.m.