def test_creation(self): a, b, c = symbols('a b c') X = StateVariableTuple((a, b)) self.assertEqual(type(X), StateVariableTuple) print(X, type(X)) Y = X.subs({b: c}) print(Y, type(Y)) self.assertEqual(type(Y), StateVariableTuple)
def setUp(self): I_vl, I_vw = symbols("I_vl I_vw") vl, vw = symbols("vl vw") k_vl, k_vw = symbols("k_vl k_vw") self.provided_values=frozenset( [ InFluxesBySymbol({vl: I_vl, vw: I_vw}), OutFluxesBySymbol({vl: k_vl * vl, vw: k_vw * vw}), InternalFluxesBySymbol({(vl, vw): k_vl * vl, (vw, vl): k_vw * vw}), TimeSymbol("t"), StateVariableTuple((vl, vw)) ] ) self.mvs=MVarSet(self.provided_values)
'adsorption rate of dissolved organic matter', 'I_P': 'soil organic carbon input rate' # "mgC g^{-1}\\text{ soil } h^{-1}" , 'I_D': 'dissolved organic carbon input rate' # "mgC g^{-1}\\text{ soil } h^{-1}" } for name in sym_dict.keys(): var(name) F_E = m_R # "h^{-1}" F_R = (1 / E_C - 1) * (V_D + m_R) * D / (K_D + D) # "h^{-1}" F_U = 1 / E_C * (V_D + m_R) * B / (K_D + D) # "h^{-1}" F_A = K_ads * (1 - Q / Q_max) # "h^{-1}" t = TimeSymbol("t") # unit: "hour" x = StateVariableTuple((P, M, Q, B, D, EP, EM)) u = InputTuple((I_P, 0, 0, 0, I_D, 0, 0)) T = ImmutableMatrix( [[-1, 0, 0, (1 - g_D) * (1 - p_EP - p_EM) * F_E / (F_E + F_R), 0, 0, 0], [1 - f_D, -1, 0, 0, 0, 0, 0], [0, 0, -1, 0, F_A / (F_U + F_A), 0, 0], [0, 0, 0, -1, F_U / (F_U + F_A), 0, 0], [f_D, 1, 1, g_D * (1 - p_EP - p_EM) * F_E / (F_E + F_R), -1, 1, 1], [0, 0, 0, p_EP * F_E / (F_E + F_R), 0, -1, 0], [0, 0, 0, p_EM * F_E / (F_E + F_R), 0, 0, -1]]) N = ImmutableMatrix([[V_P * EP / (K_P + P), 0, 0, 0, 0, 0, 0], [0, V_M * EM / (K_M + M), 0, 0, 0, 0, 0], [0, 0, K_des / Q_max, 0, 0, 0, 0], [0, 0, 0, F_E + F_R, 0, 0, 0], [0, 0, 0, 0, F_U + F_A, 0, 0], [0, 0, 0, 0, 0, r_EP, 0], [0, 0, 0, 0, 0, 0, r_EM]]) B = CompartmentalMatrix(T * N)
(0, DOY <= DOY_senesc)) t_CWDN = N_cwd * tau_cwd * g_T t_litterN = N_litter * tau_litter * g_T # "gN*m^{-2}*day^{-1}" t_rootN = N_root * tau_root # "gN*m^{-2}*day^{-1}" t_woodN = N_wood * tau_wood # "gN*m^{-2}*day^{-1}" t_soilN = N_soil * tau_soil * g_T * (1 - DON_leach_prop) nitr = N_NH4 * nitr_rate * g_T #In equation <nitr_ratio>, in table 6 <nitr_rate> L_NO3 = N_NO3 * leach_rate L_DON = N_soil * tau_soil * g_T * DON_leach_prop xc = CarbonStateVariableTuple((C_labile, C_bud, C_leaf, C_wood, C_root, C_labileRa, C_litter, C_soil, C_cwd)) xn = NitrogenStateVariableTuple((N_leaf, N_wood, N_root, N_labile, N_bud, N_litter, N_soil, N_cwd, N_NH4, N_NO3)) # here we just stick the two parts together x = StateVariableTuple(list(xc) + list(xn)) # but we could also use any other ordering and also more variables for the global state vector # e.g. (same but manually put together) # x = StateVariableTuple((C_labile, C_bud, C_leaf, C_wood, C_root, C_labileRa, C_litter, C_soil, C_cwd, N_leaf, N_wood, N_root, N_labile, N_bud, N_litter, N_soil, N_cwd, N_NH4, N_NO3)) u = GPP b = ImmutableMatrix((1, 0, 0, 0, 0, 0)) c_in_t = CarbonInputTuple(tuple(u * b) + (0, 0, 0)) #Input = InputTuple(tuple(u*b)+(0,0,0,0,0,0,0,0,0,0,0,0,0)) A_c = CarbonCompartmentalMatrix( [[ -(a_budC + a_rootC + a_woodC + a_labileRamain + Ra_growth + Ra_excess) / C_labile, 0, 0, 0, 0, 0, 0, 0, 0 ], [ a_budC / C_labile, -(a_budC2leaf + a_budC2Ramain) / C_bud, 0, 0, 0, 0, 0, 0, 0
,'mu_leaf': 'Turnover rate of plant pool Leaf' #unit: "year^{-1}" # In table with parameter values. In Appendix B the unit is "d^{-1}" ,'mu_root': 'Turnover rate of plant pool Root' #unit: "year^{-1}" # In table with parameter values. In Appendix B the unit is "d^{-1}" ,'mu_wood': 'Turnover rate of plant pool Wood' #unit: "year^{-1}" # In table with parameter values. In Appendix B the unit is "d^{-1}" } for name in sym_dict.keys(): var(name) x_nup = Min(1,(N_min/(F_nupmin*Delta_t))) x_pup = Min(1,(P_lab/(F_pupmin*Delta_t))) x_npup = Min(x_nup,x_pup) x_nleaf = (n_leaf/(n_leaf+k_n)) x_pleaf = (p_leaf/(p_leaf+k_p)) x_npleaf = Min(x_nleaf,x_pleaf) F_c = x_npleaf*x_npup*F_cmax #unit: "gC*m^{-2}*d^{-1}" u = F_c x = StateVariableTuple((C_leaf, C_root, C_wood)) b = (a_leaf, a_root, a_wood) Input = InputTuple(u * ImmutableMatrix(b)) A = CompartmentalMatrix( diag(-mu_leaf, -mu_root, -mu_wood) ) t = TimeSymbol("t") #'day' # timeResolution = daily # or yearly? incongruent turnover units # Commented out the following lines because original publication only has 3 parameter values # In original publication: ## See table 1 for parameter values; a_(leaf,wood,root) and 1/mu_(leaf,wood,root) are based on CASA ## 1/mu_(leaf,wood,root) = Mean residence time of plant tissue ## 1/n_max,leaf and 1/p_max,leaf : maximal leaf N:C and P:C ratios = 1.2*mean (min is obtained by 0.8*mean) # # mean estimates were obtained from Glopnet datasets for each biome (Wright et al., 2004) #np1 = NumericParameterization(
]) roots_in_fluxes = {E: GPP} roots_out_fluxes = { E: MR + GR, B_R: S_R * B_R, } roots_internal_fluxes = { (E, B_R): f_R * C_gR / (C_gR + delta_R) * eta_R * E, (E, C_R): f_R * delta_R / (C_gR + delta_R) * E, (C_R, E): S_R * C_R, } roots = (roots_sv_set, roots_in_fluxes, roots_out_fluxes, roots_internal_fluxes) srm = SmoothReservoirModel.from_state_variable_indexed_fluxes( Matrix([E, B_R, C_R]), t, roots_in_fluxes, roots_out_fluxes, roots_internal_fluxes) mvs = CMTVS( { InFluxesBySymbol(roots[1]), OutFluxesBySymbol(roots[2]), InternalFluxesBySymbol(roots[3]), TimeSymbol("t"), StateVariableTuple((E, B_R, C_R)) }, bgc_md2_computers())
W_i = (Max(0, (Min(1, ((theta_i - theta_wilt) / (theta_field - theta_wilt)))))) epsilon_R = 1 - epsilon_L - epsilon_S a_S = ((epsilon_S + (omega * (1 - L))) / (1 + (omega * (2 - L - W)))) a_R = ((epsilon_R + (omega * (1 - W))) / (1 + (omega * (2 - L - W)))) #a_R=((epsilon_R+(omega*(1-W)))/(1+(omega*(1-L-W)))) # For grasses a_L = 1 - a_S - a_R #a_L=((epsilon_L+(omega*L))/(1+(omega*(1-L-W)))) # For grasses A_S = (Piecewise((a_S * G, N < 0), (a_S * N + R_gS + R_mS, N > 0))) A_R = (Piecewise((a_R * G, N < 0), (a_R * N + R_gR + R_mR, N >= 0))) #beta_T=(Piecewise((1,T_air>= T_cold),(Piecewise((((T_air-T_cold-5)/5),T_air>(T_cold-5)),(0,T_air<=(T_cold-5))),T_cold>T_air))) # Had to comment it out because of problems of piecewise in matrix gamma_T = gamma_Tmax * (1 - beta_T)**b_T D_L = (gamma_N + gamma_W + gamma_T) * C_L D_S = gamma_S * C_S D_R = gamma_R * C_R x = StateVariableTuple((C_L, C_S, C_R)) b = 1 u = (C_L, C_S, C_R) Input = InputTuple( ImmutableMatrix(u) * 1 ) #Fixme: does input always have to be a Tuple? what happens when, in this case, "f_v = u + A*x"? A = CompartmentalMatrix([[-(gamma_N + gamma_W + gamma_T), 0, 0], [0, -gamma_S - R_gS - R_mS, 0], [0, 0, -gamma_R - R_gR - R_mR]]) # t = TimeSymbol("t") # parameter_sets: # - "Original dataset of the publication": # values: {k_n: 0.5, omega: 0.8, epsilon_L: 0.35, epsilon_S: 0.1, epsilon_R: 0.55} # desc: Eastern US and Germany, cold broadleaf deciduous
R = 8.314 Arrhenius = exp((E_p * (T_k - 298)) / (R * T_k * 298)) I = I_0 * exp(-k * L) J_e = 1 #((alpha_q * I * J_m)/(sqrt((J_m)^2 * (alpha_q)^2 * I^2))) * ((C_i - Gamma)/(4*(C_i + 2 * Gamma))) #Fixme: had to set J_e to 1 because problem with sqrt AttributeError: 'Not' object has no attribute '_eval_power' J_c = (V_m * (C_i - Gamma)) / (C_i + K_c * (1 + (O_x / K_o))) A = Min(J_c, J_e) - R_d g_l * A / ((C_i - Gamma) * (1 + (D / D_0))) A_n = G_s * (C_a - C_i) A_c = A_n * (1 - exp(-k * L)) / k GPP = A_c * 3600 * 12 / 1000000 # Scaling expression from TECO fortran code, line 667.' # gC*day^{-1} f_W = Min((0.5 * W), 1) f_T = Q_10 * ((T - 10) / 10) xi = f_W * f_T t = TimeSymbol("t") # unit: "day" #x = StateVariableTuple((C_foliage, C_roots, C_wood, C_metlit, C_stlit, C_fastsom, C_slowsom, C_passsom)) x = StateVariableTuple((C_foliage, C_wood, C_roots, C_metlit, C_stlit, C_fastsom, C_slowsom, C_passsom)) u = GPP b = (b_foliage, b_roots, b_wood, 0, 0, 0, 0, 0) Input = InputTuple(u * ImmutableMatrix(b)) B = CompartmentalMatrix( [[-cr_foliage, 0, 0, 0, 0, 0, 0, 0], [0, -cr_wood, 0, 0, 0, 0, 0, 0], [0, 0, -cr_root, 0, 0, 0, 0, 0], [f_foliage2metlit, 0, f_roots2metlit, -cr_metlit, 0, 0, 0, 0], [f_foliage2stlit, f_wood2stlit, f_roots2stlit, 0, -cr_stlit, 0, 0, 0], [ 0, 0, 0, f_metlit2fastsom, f_stlit2fastsom, -cr_fastsom, f_slowsom2fastsom, f_passsom2fastsom ], [0, 0, 0, 0, f_stlit2slowsom, f_fastsom2slowsom, -cr_slowsom, 0], [0, 0, 0, 0, 0, f_fastsom2passsom, f_slowsom2passsom, -cr_passsom]]) np1 = NumericParameterization(par_dict={ GPP: 3.370,
code = k + " = Function('{0}')".format(k) exec(code) t = TimeSymbol("t") beta_root = 1.0 - (beta_leaf + beta_wood) mvs = CMTVS( { t, StateVariableTuple(( #vl, #vw, C_leaf, C_wood, C_root, C_aom1, C_aom2, C_smb1, C_smb2, C_smr, C_nom, C_dom, C_psom, )), InFluxesBySymbol({ #vl: I_vl, vw: I_vw C_leaf: NPP(t) * beta_leaf, C_root: NPP(t) * beta_root, C_wood: NPP(t) * beta_wood }), OutFluxesBySymbol({ #vl: k_vl_o * vl, vw: k_vw_o * vw
,'s': '"decomposers production rate of soil organic matter"' # "\\text{time}^{-1}" ,'k': '"rate of fresh organic matter decomposition under substrate limitation ($N$ excess)"' # "\\text{time}^{-1}" ,'y': 'soil organic matter decomposer consumption rate of fresh organic matter under substrate limitations' # "\\text{time}^{-1}" ,'alpha': '"$N:C$ ratio in soil organic matter and in decomposers"' ,'beta': '"$N:C$ ratio in fresh organic matter"' ,'i': '"rate of mineral $N$ diffusion in soil"' # "\\text{time}^{-1}" ,'Phi_l': 'fresh organic matter carbon flux' # "(\\text{quantity of carbon})(\\text{time}))^{-1}" ,'Phi_i': 'nitrogen that flows into the ecosystem' # "(\\text{quantity of nitrogen})(\\text{time}))^{-1}" ,'Phi_o': 'nitrogen that flows out of the ecosystem' # "(\\text{quantity of nitrogen})(\\text{time}))^{-1}" ,'Phi_up': 'nitrogen flux associated with the nitrogen uptake by the plant cover' # "(\\text{quantity of nitrogen})(\\text{time}))^{-1}" } for name in sym_dict.keys(): var(name) t = TimeSymbol("t") # unit: "" x = StateVariableTuple((C_s, C_f, C_ds, C_df, N)) u = InputTuple((0, Phi_l, 0, 0, Phi_i-Phi_o-Phi_up)) B = CompartmentalMatrix([[-A/C_s*C_ds, 0, s, s, 0], [ 0, -y, 0, -alpha*r/(alpha-beta), -i/(alpha-beta)], [ A/C_s*C_ds, y, -(s+r), 0, 0], [ 0, 0, 0, -(s+r)+alpha*r/(alpha-beta), i/(alpha-beta)], [ 0, (beta-alpha)*y, alpha*r, 0, -i]]) #suggested_steady_states: # - C_f: (s+r-3)/y*C_ds # C_df: (s+r-A)*(Phi_i-Phi_o-Phi_up+beta*Phi_l-alpha*(A-s)*Phi_l/(s+r-A)) # C_ds: (s+r)*(-(Phi_i-Phi_o-Phi_up+beta*Phi_l) + alpha*s*Phi_l/(s+r))/(A*r*alpha) # N: alpha*s-beta*(s+r)/i*C_df mvs = CMTVS( { BibInfo(# Bibliographical Information
exec(code) # some we will also use some symbols for functions (which appear with an argument) func_dict={ "I_vl": "Influx into vegetation leaf pool", "r_vl_o": "out flux rate of leaf pool", } for k in func_dict.keys(): code=k+" = Function('{0}')".format(k) exec(code) t=TimeSymbol("t") mvs = CMTVS( { StateVariableTuple((vl, vw)), t, InFluxesBySymbol({vl: I_vl(t), vw: I_vw}), OutFluxesBySymbol({vl: r_vl_o(t) * vl, vw: r_vw_o * vw}), InternalFluxesBySymbol({(vl, vw): r_vl_2_vw * vl, (vw, vl): r_vw_2_vl * vw}), }, computers=module_computers(bgc_c) ) # - # The last statement in the code defines a variable `mvs` which is # an instance of CMTVS which stands for `C`onnected`M`ulti`T`ype`V`ariable`S`et". # It contains information in two forms. # 1. Variables of certain type (like InFluxesBySymbol) # 2. a set of functions that "connect" these Variables and to other results we did not specify but which can be computed.
} for k in func_dict.keys(): code = k + " = Function('{0}')".format(k) exec(code) t = TimeSymbol("t") beta_root = 1.0 - (beta_leaf + beta_wood) mvs = CMTVS( { t, StateVariableTuple(( C_leaf, C_wood, C_root, C_leaf_litter, C_wood_litter, C_root_litter, C_soil_fast, C_soil_slow, C_soil_passive, )), InFluxesBySymbol({ C_leaf: NPP(t) * beta_leaf, C_root: NPP(t) * beta_root, C_wood: NPP(t) * beta_wood }), OutFluxesBySymbol( { C_leaf_litter: r_C_leaf_litter_rh * C_leaf_litter * xi(t), C_wood_litter: r_C_wood_litter_rh * C_wood_litter * xi(t), C_root_litter: r_C_root_litter_rh * C_root_litter * xi(t),
'f_mic2passsom': 'Transfer coefficient from Fast to Passive SOM', 'f_CWD2slowsom': 'Transfer coefficient from CWD to Slow SOM', 'f_CWD2passsom': 'Transfer coefficient from CWD to passive SOM', 'f_slowsom2passsom': 'Transfer coefficient from Slow to Passive SOM', 'lig_leaf': '?', 'lig_wood': '?', 'clay': '?', 'silt': '?', } for name in sym_dict.keys(): var(name) NPP = Function('NPP') x = StateVariableTuple((C_leaf, C_root, C_wood, C_metlit, C_stlit, CWD, C_mic, C_slowsom, C_passsom)) K = ImmutableMatrix.diag([ k_leaf, k_root, k_wood, k_metlit, k_stlit, k_CWD, k_mic, k_slowsom, k_passsom ]) A = ImmutableMatrix( [[-1, 0, 0, 0, 0, 0, 0, 0, 0], [0, -1, 0, 0, 0, 0, 0, 0, 0], [0, 0, -1, 0, 0, 0, 0, 0, 0], [f_leaf2metlit, f_root2metlit, 0, -1, 0, 0, 0, 0, 0], [f_leaf2stlit, f_root2stlit, 0, 0, -1, 0, 0, 0, 0], [0, 0, f_wood2CWD, 0, 0, -1, 0, 0, 0], [0, 0, 0, f_metlit2mic, f_stlit2mic, 0, -1, 0, 0], [0, 0, 0, 0, f_stlit2slowsom, f_CWD2slowsom, f_mic2slowsom, -1, 0], [0, 0, 0, 0, 0, f_CWD2passsom, f_mic2passsom, f_slowsom2passsom, -1]]) # tranfer
'soil organic carbon input rate' # "mg C cm^{-3} h^{-1}" , 'I_D': 'dissolved organic carbon input rate' # "mg C cm^{-3} h^{-1}" } for name in sym_dict.keys(): var(name) R = 0.008314 # "kJ mol^{-1} K^{-1}" V_U = V_Umax * exp(-E_aU / (R * (T + 273))) # V = V_max * exp(-E_a / (R * (T + 273))) # E_C = epsilon_0 + epsilon_s * T # K_U = K_U0 + K_Us * T # "mg C cm^{-3}" K = K_0 + K_s * T # "mg C cm^{-3}" t = TimeSymbol("t") # unit: "hour" x = StateVariableTuple((S, D, B, E)) u = InputTuple((I_S, I_D, 0, 0)) T_M = ImmutableMatrix([[-1, 0, a_BS * r_B / (r_B + r_E), 0], [1, -1, (1 - a_BS) * r_B / (r_B + r_E), 1], [1, E_C, -1, 0], [0, 0, r_E / (r_B + r_E), -1]]) N = ImmutableMatrix([[V * E / (K + S), 0, 0, 0], [0, V_U * B / (K_U + D), 0, 0], [0, 0, r_B + r_E, 0], [0, 0, 0, r_L]]) B = CompartmentalMatrix((T_M * N)) #np1 = NumericParameterization( # par_dict={ #}, # func_dict=frozendict({}) #) # #nsv1 = NumericStartValueDict({
Km = exp(K_slope * T + K_int) * ak Km_r1 = Km * Kmod_1 Km_r2 = Km * Kmod_2 Km_r3 = Km * Kmod_3 Km_r4 = Km * Kmod_4 F1 = MIC_r * Vmax_r1 * LIT_m / (Km_r1 + LIT_m) F2 = MIC_r * Vmax_r2 * LIT_s / (Km_r2 + LIT_s) F3 = MIC_r * Vmax_r3 * SOM_p / (Km_r3 + SOM_p) F4 = MIC_r * Vmax_r4 * SOM_c / (Km_r4 + SOM_c) F5 = MIC_r * tau_r F6 = MIC_k * Vmax_k1 * LIT_m / (Km_k1 + LIT_m) F7 = MIC_k * Vmax_k2 * LIT_s / (Km_k2 + LIT_s) F8 = MIC_k * Vmax_k3 * SOM_p / (Km_k3 + SOM_p) F9 = MIC_k * Vmax_k4 * SOM_c / (Km_k4 + SOM_c) F10 = MIC_k * tau_k x = StateVariableTuple((LIT_m, LIT_s, MIC_r, MIC_k, SOM_p, SOM_c)) mvs = CMTVS( { BibInfo( # Bibliographical Information name="MIMICS", longName="Microbial-Mineral Carbon Stabilization", version="1", entryAuthor="Carlos Sierra", entryAuthorOrcid="0000-0003-0009-4169", entryCreationDate="14/08/2018", doi="10.5194/bg-11-3899-2014", sym_dict=sym_dict), TimeSymbol("t"), # unit: "hour" x, # state vector of the complete system # InFluxesBySymbol({})
vl, vw = symbols("vl vw") k_vl, k_vw = symbols("k_vl k_vw") # the keys of the internal flux dictionary are tuples (source_pool,target_pool) # srm:SmoothReservoirModel # srm=SmoothReservoirModel.from_state_variable_indexed_fluxes( # in_fluxes # ,out_fluxes # ,internal_fluxes # ) #specialVars = { mvs = MVarSet({ InFluxesBySymbol({ vl: I_vl, vw: I_vw }), OutFluxesBySymbol({ vl: k_vl * vl, vw: k_vw * vw }), InternalFluxesBySymbol({ (vl, vw): k_vl * vl, (vw, vl): k_vw * vw }), TimeSymbol("t"), StateVariableTuple((vl, vw)) # ,'SmoothReservoirModel':srm })
"NPP": "Net Primary Production per area", } # For the code we only use the first column for name in sym_dict.keys(): var(name) # The following parameters would be needed to compute NPP from GPP since they are not given # ("p_2" , "1" ,"Fraction of GPP respired "), # no parameter values in publication # ("GPP" , "mass*length**(-2)*time**(-1)" ,"Gross Primary Production per area"), # ("G" , "mass*length**(-2)*time**(-1)" ,), # Temperature sensitive rate parameterd T_rate = 0.5 * exp(p_10 * ((maxt + mint) / 2)) # state vector x = StateVariableTuple((C_f, C_lab, C_w, C_r)) # NetPrimaryProduction can not be computted in the absence of G and p_2 with # the following formula NPP = (1-p_2)*G # CAUTION: there are 2 NPPs, need to # correct according to ACM model so NPP has been made a parameter instead of an # expression # scalar function of photosynthetic inputs u = NPP # tuple of partitioning coefficients of photosynthetically fixed carbon b = ((p_3 * multtl), 0, (1 - p_4), p_4) # f_v = u*b+A*x # matrix of cycling rates
def test_immutability(self): a, b, c = symbols('a b c') T = StateVariableTuple((a, b, c)) with self.assertRaises(TypeError): T[1] = 1
J = (J_max * I_dens) / (I_dens + (2.1 * J_max)) R_d = (0.775 * N_a) - 0.238 A_1 = (V_cmax * ((C_i - 31) / (C_i + 827))) - R_d A_2 = (J * ((C_i - 31) / ((4.5 * C_i) + (10.5 * 31)))) - R_d sigma_c = Min(A_1, A_2) W_g = W_p + W_s + W_r f_N = (sigma_r * W_r * f_C) / (sigma_c * A) C = W_C / W_g N = W_N / W_g P = f_C * sigma_r * W_r / (f_N * sigma_c * A) Q = f_N / (Beta * f_C) lambda_p = P / (1 + P + Q) lambda_s = Q / (1 + P + Q) lambda_r = 1 / (1 + P + Q) x = StateVariableTuple((W_N, W_C, W_p, W_s, W_r)) u = (sigma_c * A, sigma_r * W_r, 0, 0, 0) b = 1 Input = InputTuple(b * ImmutableMatrix(u)) A = CompartmentalMatrix( [[ -((f_cp * lambda_p * W_p) + (f_cs * lambda_s * W_s) + (f_cr * lambda_r * W_r)) * ((kappa * W_N) / W_g**2), 0, 0, 0, 0 ], [ 0, -((f_np * lambda_p * W_p) + (f_ns * lambda_s * W_s) + (f_nr * lambda_r * W_r)) * ((kappa * W_C) / W_g**2), 0, 0, 0 ], [0, (kappa * N * lambda_p * W_p) / W_g, 0, 0, 0], [0, (kappa * N * lambda_s * W_s) / W_g, 0, 0, 0], [0, (kappa * N * lambda_r * W_r) / W_g, 0, 0, 0]]) t = TimeSymbol("t") # unit: "day"
J_c4 = k * C_i # the compensation point is taken to be 0 for C4 plants T = V_m / 8.2 J_s = ((3 * T * (1 - (Gamma / C_i))) + (J_p * Gamma / C_i)) J_i = alpha_4 * Q_p A_g = Min(J_e, J_c, J_s) # A_g = Min(J_i,J_e,J_c) #C4 fT_stem = exp(E_0 * ((1 / (15 - T_0)) - (1 / (T_stem - T_0)))) R_leaf = gamma * V_m fT_soil = exp(E_0 * ((1 / (15 - T_0)) - (1 / (T_soil - T_0)))) R_stem = Beta_stem * lambda_sapwood * C_is * fT_stem R_root = Beta_root * C_ir * fT_soil A_n = A_g - R_leaf GPP_i = integrate(A_g, t) NPP_i = ((1 - eta) * (integrate(A_g - R_leaf - R_stem - R_root, t))) x = StateVariableTuple((C_il, C_is, C_ir)) u = NPP_i b = (a_il, a_is, a_ir) Input = InputTuple(u * ImmutableMatrix(b)) A = CompartmentalMatrix(diag(-1 / tau_il, -1 / tau_is, -1 / tau_ir)) t = TimeSymbol("t") #model_run_data: # parameter_sets: # - "Tropical evergreen trees": # values: {a_il: 0.25,a_is: 0.5,a_ir: 0.25} mvs = CMTVS( { BibInfo( # Bibliographical Information name="IBIS",
'gamma_L': 'Stem turnover rate' } for name in sym_dict.keys(): var(name) epsilon_L = 1 - epsilon_R - epsilon_S a_S = (epsilon_S + (Omega * (1.5 - L - (0.5 * N_ava)))) / (1 + (Omega * (3 - L - W - N_ava))) a_R = (epsilon_R + (Omega * (1.5 - W - (0.5 * N_ava)))) / (1 + (Omega * (3 - L - W - N_ava))) a_L = epsilon_L / (1 + (Omega * (3 - L - W - N_ava))) #, "a_L = 1-a_S-a_R" x = StateVariableTuple((C_S, C_R, C_L)) u = NPP b = (a_S, a_R, a_L) Input = InputTuple(u * ImmutableMatrix(b)) A = CompartmentalMatrix([[-gamma_S, 0, 0], [0, -gamma_R, 0], [0, 0, -gamma_L]]) t = TimeSymbol("t") mvs = MVarSet({ BibInfo( # Bibliographical Information name="CEVSA2 ", longName="", version="2", entryAuthor="Verónika Ceballos-Núñez", entryAuthorOrcid="0000-0002-0046-1160", entryCreationDate="", doi="10.1016/j.ecocom.2010.04.002",
R = 8.314 Arrhenius = exp((E_p * (T_k - 298)) / (R * T_k * 298)) I = I_0 * exp(-k * L) J_e = 1 #((alpha_q * I * J_m)/(sqrt((J_m)^2 * (alpha_q)^2 * I^2))) * ((C_i - Gamma)/(4*(C_i + 2 * Gamma))) #Fixme: had to set J_e to 1 because problem with sqrt AttributeError: 'Not' object has no attribute '_eval_power' J_c = (V_m * (C_i - Gamma)) / (C_i + K_c * (1 + (O_x / K_o))) A = Min(J_c, J_e) - R_d g_l * A / ((C_i - Gamma) * (1 + (D / D_0))) A_n = G_s * (C_a - C_i) A_c = A_n * (1 - exp(-k * L)) / k GPP = A_c * 3600 * 12 / 1000000 # Scaling expression from TECO fortran code, line 667.' # gC*day^{-1} f_W = Min((0.5 * W), 1) f_T = Q_10 * ((T - 10) / 10) xi = f_W * f_T t = TimeSymbol("t") # unit: "day" x = StateVariableTuple((x_1, x_2, x_3, x_4, x_5, x_6, x_7, x_8)) u = GPP b = ImmutableMatrix((b_1, b_2, b_3)) Input = InputTuple(tuple(u * b) + (0, 0, 0, 0, 0)) B = CompartmentalMatrix([[-c_1, 0, 0, 0, 0, 0, 0, 0], [0, -c_2, 0, 0, 0, 0, 0, 0], [0, 0, -c_3, 0, 0, 0, 0, 0], [f_41, 0, f_43, -c_4, 0, 0, 0, 0], [f_51, f_52, f_53, 0, -c_5, 0, 0, 0], [0, 0, 0, f_64, f_65, -c_6, f_67, f_68], [0, 0, 0, 0, f_75, f_76, -c_7, 0], [0, 0, 0, 0, 0, f_86, f_87, -c_8]]) np1 = NumericParameterization(par_dict={ GPP: 3.370, b_1: 0.14, b_2: 0.26,
, 'k_2': 'decomposition rate of old pool' # "yr^{-1}" , 'i': 'mean annual carbon input' # "kgC m^{-2}yr^{-1}" , 'h': 'humification coefficient', 'r': 'climatic and edaphic factors' } for name in sym_dict.keys(): var(name) xi = r #environmental effects multiplier T = ImmutableMatrix([[-1, 0], [h, -1]]) #transition operator N = diag(k_1, k_2) #decomposition operator t = TimeSymbol("t") # unit: "year" x = StateVariableTuple((Y, O)) u = InputTuple((i, 0)) B = CompartmentalMatrix(xi * T * N) # - "Bare fallow": np1 = NumericParameterization(par_dict={ k_1: 0.8, k_2: 0.00605, i: 0, h: 0.13, r: 1.32 }, func_dict=frozendict({})) nsv1 = NumericStartValueDict({Y: 0.3, O: 3.96}) # - "+N +straw": np2 = NumericParameterization(par_dict={
R_m = R_mf + R_mr + R_msw APAR = I_0 * (1 - exp(-k * sigma * C_f)) E_nf = Piecewise( (((((1.84 * n_f) - 0.01) / (0.017 + n_f)) / (((1.84 * n_crit) - 0.01) / (0.017 + n_crit))), n_f < n_crit), (1, n_f > n_crit)) epsilon_0 = Piecewise((epsilon_young, age <= t_1), (Piecewise( ((epsilon_young - ((epsilon_young - epsilon_old) * ((age - t_1) / (t_2 - t_1)))), t_1 < age), (Piecewise(((epsilon_young - ((epsilon_young - epsilon_old) * ((age - t_1) / (t_2 - t_1)))), age < t_2), (epsilon_old, age >= t_2)), True)), True)) GPP = epsilon_0 * E_nf * APAR NPP = GPP - (R_c + R_m) a_w = 1 - a_f - a_r x = StateVariableTuple( (C_f, C_r, C_w, C_wl, C_u, C_m, C_v, C_n, C_a, C_s, C_p)) u = NPP b = ImmutableMatrix((a_f, a_r, a_w)) Input = InputTuple(tuple(u * b) + (0, 0, 0, 0, 0, 0, 0, 0)) A = CompartmentalMatrix([[-s_f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, -s_r, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, -s_w, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, s_w, -d_wl, 0, 0, 0, 0, 0, 0, 0], [buf * s_f, 0, 0, 0, -d_u, 0, 0, 0, 0, 0, 0], [bmf * s_f, bmr * s_r, 0, 0, 0, -d_m, 0, 0, 0, 0, 0], [0, bvr * s_r, 0, 0, 0, 0, -d_v, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, -d_n, 0, 0, 0], [ 0, 0, 0, baw * d_wl, bau * d_u, bam * d_m, bav * d_v, ban * d_n, -d_a, bas * d_s, bap * d_p ],
'Fixed partitioning ratio (fraction) of available carbon allocated to foliage', 'eta_r': 'Fixed partitioning ratio (fraction) of available carbon allocated to roots', 'eta_w': 'Fixed partitioning ratio (fraction) of available carbon allocated to wood', 'gamma_f': 'Foliage turnover rate', 'gamma_r': 'Roots turnover rate', 'gamma_w': 'Wood turnover rate' } for name in sym_dict.keys(): var(name) f_W = Min((0.5 * W), 1) f_T = Q_10**((T - 10) / 10) epsilon_t = f_W * f_T x = StateVariableTuple((C_f, C_r, C_w)) u = GPP * epsilon_t b = (eta_f, eta_w, eta_r) Input = InputTuple(u * ImmutableMatrix(b)) A = CompartmentalMatrix(diag(-gamma_f, -gamma_w, -gamma_r)) t = TimeSymbol("t") # "Original parameters of the publication. Parameter value of GPP corresponds to an annual average" # T, Q_10, and W are variables that should be looked at in a data set. What I have here are invented values np1 = NumericParameterization( par_dict={ Q_10: 1, W: 4.2, T: 25, GPP: 3370, #"gC*day^{-1}"
'W': 'Carbon in woody tissue', 'G': 'Net rate of plant carbon production', 'eta_f': 'Allocation fraction to foliar biomass', 'eta_r': 'Allocation fraction to roots biomass', 'eta_w': 'Allocation fraction to wood (in stem, branches and large structurl roots) biomass', 'gamma_f': 'Foliage senescence rate' #unit: "yr^{-1}" , 'gamma_r': 'Roots senescence rate' #unit: "yr^{-1}" , 'gamma_w': 'Wood senescence rate' #unit: "yr^{-1}" } for name in sym_dict.keys(): var(name) x = StateVariableTuple((F, R, W)) u = G b = (eta_f, eta_w, eta_r) Input = InputTuple(u * ImmutableMatrix(b)) A = CompartmentalMatrix(diag(-gamma_f, -gamma_w, -gamma_r)) t = TimeSymbol("t") #'yr' # Commented out the following lines because original publication only has 3 parameter values #np1 = NumericParameterization( # par_dict={ # G: , #"Mg*ha^{-1}*yr^{-1}" # eta_f: 'Rational(1,3)', # eta_r: 'Rational(1,3)', # eta_w: 'Rational(1,3)', #},
'gamma_f': 'Foliage turnover rate', 'gamma_r': 'Roots turnover rate', 'gamma_w': 'Wood turnover rate', 'l_s': 'Fraction of litter partitioned to the soil', 'l_p': 'Fraction of litter available for plant', 's_p': 'Fraction of soil carbon available for plant', 'l_dr': 'Litter decomposition/respiration', 's_dr': 'Soil decomposition/respiration', 'u': 'scalar function of photosynthetic inputs' } for name in sym_dict.keys(): var(name) #Model based on Fig. 1 in page 127 (3 in the PDF) of doi= "10.1016/0304-3800(88)90112-3", no ODEs in publication t = TimeSymbol("t") #"the model has a daily and a yearly component. Allocation occurs yearly" x = StateVariableTuple((C_f, C_r, C_w,C_frl,C_s)) b = ImmutableMatrix((eta_f, eta_w, eta_r)) Input = InputTuple(tuple(u * b)+(0,0)) A = CompartmentalMatrix( [[-gamma_f, 0 , 0 , (l_p*eta_f) ,(s_p*eta_f)], [ 0 ,-gamma_r, 0 , (l_p*eta_r) ,(s_p*eta_r)], [ 0 , 0 ,-gamma_w, (l_p*eta_w) ,(s_p*eta_w)], [ gamma_f, gamma_r, gamma_w, -(l_p+l_s+l_dr), 0 ], [ 0 , 0 , 0 , l_s ,-(s_p+s_dr)] ]) ## The following are default values suggested by this entry's creator only to be able to run the model: np1 = NumericParameterization( par_dict={u: 1400, eta_f: 0.48, eta_r: 0.44, eta_w: 0.49, gamma_r: 3.03, gamma_f: 23.32, gamma_w: 0.04}, func_dict=frozendict({}) )
ms = Function("ms") xk_n_limit = Function("xk_n_limit") Npp = Function("Npp") phase = Function("phase") r_leaf = Function("r_leaf") r_fine_root = Function("r_fine_root") r_wood = Function("r_wood") x = StateVariableTuple(( leaf, fine_root, wood, metabolic_lit, structural_lit, cwd, fast_soil, slow_soil, passive_soil, )) t = TimeSymbol("t") # Input = InputTuple(u*ImmutableMatrix(b)) # InputFluxes={ # leaf : (ds.NPP * ds.fracCalloc.sel(plant_casa_pools=leaf_ind)), # wood : (ds.NPP * ds.fracCalloc.sel(plant_casa_pools=wood_ind)), # fine_root : (ds.NPP * ds.fracCalloc.sel(plant_casa_pools=root_ind)) # } Input = InputTuple((
W_i = (Max(0, (Min(1, ((theta_i - theta_wilt) / (theta_field - theta_wilt)))))) epsilon_R = 1 - epsilon_L - epsilon_S a_S = ((epsilon_S + (omega * (1 - L))) / (1 + (omega * (2 - L - W)))) a_R = ((epsilon_R + (omega * (1 - W))) / (1 + (omega * (2 - L - W)))) #a_R=((epsilon_R+(omega*(1-W)))/(1+(omega*(1-L-W)))) # For grasses a_L = 1 - a_S - a_R #a_L=((epsilon_L+(omega*L))/(1+(omega*(1-L-W)))) # For grasses A_S = (Piecewise((a_S * G, N < 0), (a_S * N + R_gS + R_mS, N > 0))) A_R = (Piecewise((a_R * G, N < 0), (a_R * N + R_gR + R_mR, N >= 0))) #beta_T=(Piecewise((1,T_air>= T_cold),(Piecewise((((T_air-T_cold-5)/5),T_air>(T_cold-5)),(0,T_air<=(T_cold-5))),T_cold>T_air))) # Had to comment it out because of problems of piecewise in matrix gamma_T = gamma_Tmax * (1 - beta_T)**b_T D_L = (gamma_N + gamma_W + gamma_T) * C_L D_S = gamma_S * C_S D_R = gamma_R * C_R x = StateVariableTuple((C_L, C_S, C_R, C_D, C_H)) u = (G, 0, 0, 0, 0) Input = InputTuple(u) #f_v = u + A*x A = CompartmentalMatrix([[ -(gamma_N + gamma_W + gamma_T + (A_R + A_S + ((R_gL + R_mL) / C_L))), 0, 0, 0, 0 ], [A_S, -gamma_S - ((R_gS - R_mS) / C_S), 0, 0, 0], [A_R, 0, -gamma_R - ((R_gR - R_mR) / C_R), 0, 0], [ gamma_N + gamma_W + gamma_T, gamma_S, gamma_R, -gamma_DH - (R_hD / C_D), 0 ], [0, 0, 0, gamma_DH, -(R_hH / C_H)]]) ### Had to divide Respiration fluxes by state variables because the flux was not presented as a rate*state variable tuple. t = TimeSymbol("t")
,'d32': 'Fraction of passive soil coming from slow soil' } for name in sym_dict.keys(): var(name) #a_leaf + a_root + a_wood = 1 #b1l + b2l = 1 #b1r + b2r = 1 x_nup = Min(1,(N_min/(F_nupmin*Delta_t))) x_pup = Min(1,(P_lab/(F_pupmin*Delta_t))) x_npup = Min(x_nup,x_pup) x_nleaf = (n_leaf/(n_leaf+k_n)) x_pleaf = (p_leaf/(p_leaf+k_p)) x_npleaf = Min(x_nleaf,x_pleaf) F_c = x_npleaf*x_npup*F_cmax #unit: "gC*m^{-2}*d^{-1}" u = F_c x = StateVariableTuple((C_leaf, C_root, C_wood, C_j1, C_j2, C_j3, C_k1, C_k2, C_k3)) b = ImmutableMatrix((a_leaf, a_root, a_wood)) Input = InputTuple(tuple(u*b)+(0,0,0,0,0,0)) A = CompartmentalMatrix([ [-mu_leaf*(b1l+b2l), 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,[ 0 ,-mu_root*(b1r+b2r), 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,[ 0 , 0 ,-mu_wood*b3w, 0 , 0 , 0 , 0 , 0 , 0 ] ,[ mu_leaf*b1l , mu_root*b1r , 0 ,-mu_j1*m_n*(c11+c21), 0 , 0 , 0 , 0 , 0 ] ,[ mu_leaf*b2l , mu_root*b2r , 0 , 0 ,-mu_j2*m_n*(c12+c22), 0 , 0 , 0 , 0 ] ,[ 0 , 0 , mu_wood*b3w, 0 , 0 ,-mu_j3*m_n*(c23+c33), 0 , 0 , 0 ] ,[ 0 , 0 , 0 , mu_j1*m_n*c11 , mu_j2*m_n*c12 , 0 ,-mu_k1*(d21+d31), mu_k2*d12 , mu_k3*d13 ] ,[ 0 , 0 , 0 , mu_j1*m_n*c21 , mu_j2*m_n*c22 , mu_j3*m_n*c23 , mu_k1*d21 ,-mu_k2*(d12+d32), mu_k3*d23 ] ,[ 0 , 0 , 0 , 0 , 0 , mu_j3*m_n*c33 , mu_k1*d31 , mu_k2*d32 ,-mu_k3*(d13+d23)] ]) ### When not explicit in equations B1, B2, B3 (Appendix B), followed the fluxes from Fig 1. However, the soil fluxes are not clear. t = TimeSymbol("t") #'day' # or 'year'? incongruent turnover units