Example #1
0
def make_daily_iterator_sym(mvs, V_init: StartVector, par_dict, func_dict):
    B_func, u_func = make_B_u_funcs_2(mvs, par_dict, func_dict)
    sv = mvs.get_StateVariableTuple()
    n = len(sv)
    # build an array in the correct order of the StateVariables which in our case is already correct
    # since V_init was built automatically but in case somebody handcrafted it and changed
    # the order later in the symbolic formulation....
    V_arr = np.array([V_init.__getattribute__(str(v))
                      for v in sv] + [V_init.rh]).reshape(
                          n + 1, 1)  #reshaping is neccessary for matmux

    def f(it, V):
        X = V[0:n]
        b = u_func(it, X)
        B = B_func(it, X)
        outfluxes = B @ X
        X_new = X + b + outfluxes
        # we also compute the autotrophic and heterotrophic respiration in every (daily) timestep
        #ra= -np.sum(outfluxes[0:3]) # check with  mvs.get_StateVariableTuple()[0:3]
        rh = -(outfluxes[3:n]).reshape(
            (n - 3, )).sum()  # check with  mvs.get_StateVariableTuple()[3:9]
        V_new = np.concatenate((X_new.reshape(n, 1), rh.reshape(1, 1)), axis=0)
        return V_new

    return TimeStepIterator2(
        initial_values=V_arr,
        f=f,
    )
Example #2
0
def make_daily_iterator_sym(
        mvs,
        V_init: StartVector,
        par_dict,
        func_dict
    ):
    B_func, u_func = make_B_u_funcs_2(mvs,par_dict,func_dict)  
    sv=mvs.get_StateVariableTuple()
    n=len(sv)
    # build an array in the correct order of the StateVariables which in our case is already correct 
    # since V_init was built automatically but in case somebody handcrafted it and changed
    # the order later in the symbolic formulation....
    V_arr=np.array(
        [V_init.__getattribute__(str(v)) for v in sv]+
        [V_init.ra,V_init.rh]
    ).reshape(n+2,1) #reshaping is neccessary for matmul
    
    def f(it,V):
        X = V[0:n]
        b = u_func(it,X)
        B = B_func(it,X)
        X_new = X + b + B @ X
        # we also compute the autotrophic and heterotrophic respiration in every (daily) timestep
        
        ra = np.sum(
            [
              numOutFluxesBySymbol[k](0,*X_0) 
                for k in [C_leaf,C_wood,C_root] 
                if k in numOutFluxesBySymbol.keys()
            ]
        )
        rh = np.sum(
            [
                numOutFluxesBySymbol[k](0,*X_0) 
                for k in [C_leaf_litter,C_wood_litter,C_root_litter,C_soil_fast,C_soil_slow,C_soil_passive] 
                if k in numOutFluxesBySymbol.keys()
            ]
        )
        V_new = np.concatenate((X_new.reshape(n,1),np.array([ra,rh]).reshape(2,1)), axis=0)
        return V_new
    
    return TimeStepIterator2(
        initial_values=V_arr,
        f=f,
    )
Example #3
0

def npp_func(day):
    month = day_2_month_index(day)
    return dvs.npp[month] * 86400  # kg/m2/s kg/m2/day


def xi_func(day):
    return 1.0  # preliminary fake for lack of better data...


func_dict = {'NPP': npp_func, 'xi': xi_func}
# for the next line to work the
# two dictionaries par_dict and func_dict have to be complete.
# In sympy terms this means that the expressions for
B_func, u_func = make_B_u_funcs_2(mvs, par_dict, func_dict)
# we create a numeric startvector for the compartmental system
#
svs_0 = Observables(*map(lambda v: v[0], svs))

X_0 = np.array((
    svs_0.cVeg / 3,
    svs_0.cVeg / 3,
    svs_0.cVeg / 3,
    svs_0.cLitter / 2,
    svs_0.cLitter / 2,
    svs_0.cSoil / 6,
    svs_0.cSoil / 6,
    svs_0.cSoil / 6,
    svs_0.cSoil / 6,
    svs_0.cSoil / 6,