def test_creation(self): a, b, c = symbols('a b c') In = InputTuple((a, b)) self.assertEqual(type(In), InputTuple) J = In.subs({b: c}) self.assertEqual(type(J), InputTuple) In = InputTuple((1, 1)) self.assertEqual(type(In), InputTuple) M = Matrix((1, 1)) In = InputTuple(M) self.assertEqual(type(In), InputTuple) I1 = ImmutableMatrix(2, 1, [1, 3]) I2 = ImmutableMatrix(2, 1, [1, 3]) In = InputTuple(I1+I2) self.assertEqual(type(In), InputTuple) self.assertEqual(In[0, 0], 2) self.assertEqual(In[1, 0], 6)
,'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 name="",
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 B = CompartmentalMatrix(A * K) t = TimeSymbol("t") # unit: "day" u = NPP(t) b = ImmutableMatrix([beta_leaf, beta_root, beta_wood, 0, 0, 0, 0, 0, 0]) Input = InputTuple(u * b) mvs = CMTVS( { BibInfo( # Bibliographical Information name="CABLE_yuanyuan", longName="Terrestrial Ecosystem Model", version="", entryAuthor="Markus Müller", entryAuthorOrcid="0000-0003-0009-4169", entryCreationDate="08/24/2021", doi="", sym_dict=sym_dict), B, # the overall compartmental matrix Input, # the overall input t, # time for the complete system
# b = VegetationCarbonInputScalar(sympify(1)) # b looks very funny to me. Should it not be something more along the lines # of sum(Iv) where Iv is the input to the vegetation pools (VegetationCarbonInputTuple) # my take would actually be: #u = VegetationCarbonInputScalar( # Piecewise((GPP,NPP<0),(NPP,NPP>=0)) #) #b = VegetationCarbonInputPartitioningTuple( # ( # Piecewise((Allo_fact_leaf-R_leaf/GPP,NPP<0),(Allo_fact_leaf,NPP>=0)), # Piecewise((Allo_fact_stem-R_stem/GPP,NPP<0),(Allo_fact_stem,NPP>=0)), # Piecewise((Allo_fact_roots-R_roots/GPP,NPP<0),(Allo_fact_roots,NPP>=0)) # ) #) #Input = InputTuple(b*u) Input = InputTuple((a_L, a_S, a_R)) vcsvt = VegetationCarbonStateVariableTuple((C_leaf, C_stem, C_roots)) A = CompartmentalMatrix([[-(r_n + r_w + r_t), 0, 0], [0, -(1 / (Y_stem * 365)), 0], [0, 0, -(1 / (Y_roots * 365))]]) t = TimeSymbol("t") mvs = CMTVS( { BibInfo( # Bibliographical Information name="ISAM", longName="Integrated Science Assessment Model", version="", entryAuthor="Verónika Ceballos-Núñez", entryAuthorOrcid="0000-0002-0046-1160",
,'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( # par_dict={#"Evergreen needle leaf forest": # Delta_t: 1,
#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 # doi: 10.1111/j.1365-2486.2004.00890.x mvs = MVarSet({ BibInfo( # Bibliographical Information
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" np1 = NumericParameterization(par_dict={ sigma_r: 0.01,
'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({}) ) nsv1 = NumericStartValueDict({
, 'r': '"fraction of decomposer biomass released as CO$_2$"' # "\\text{time}^{-1}" , 's': '"decomposers production rate of soil organic matter"' # "\\text{time}^{-1}" , 'Phi_l': 'fresh organic matter carbon flux' # "(\\text{quantity of carbon})(\\text{time}))^{-1}" } for name in sym_dict.keys(): var(name) t = TimeSymbol("t") # unit: "" x = StateVariableTuple((C_s, C_ds)) u = InputTuple((0, Phi_l)) B = CompartmentalMatrix([[0, s - A], [0, A - r - s]]) mvs = CMTVS( { BibInfo( # Bibliographical Information name="FB2005 - The model of SOM dynamics (model 2)", longName="The C-N model of SOM dynamics, two decomposer types", version="1", entryAuthor="Holger Metzler", entryAuthorOrcid="0000-0002-8239-1601", entryCreationDate="22/03/2016", doi="10.1111/j.1461-0248.2005.00813.x", sym_dict=sym_dict), B, # the overall compartmental matrix u, # the overall input
'mu_S': 'relative growth rate of bacteria (dependent on substrate concentration)', 'Exu': 'exudation rate (dependent on time)', } for name in sym_dict.keys(): var(name) # t is not an instance of symbol but of TimeSymbol, Therefore it can not # created along with the other symbols but hast to be created before it appears # in any expressions. t = TimeSymbol('t') # in the original pub unit: "hour" mu_S = mu_max * S / (K_s * theta + S) # "hr^{-1}" Exu = ExuM * exp(-ExuT * t) # "hr^{-1}" x = StateVariableTuple((X, S)) u = InputTuple((0, BGF + Exu)) T = ImmutableMatrix([[-1, Y], [K_r, -1]]) N = ImmutableMatrix([[D_max * K_d / (K_d + S / theta), 0], [0, X / Y * mu_max / (K_s * theta + S)]]) B = CompartmentalMatrix(T * N) # Original values from linked model (no nitrogen cycle considered in this model here): np1 = NumericParameterization(par_dict={ D_max: 0.26, Y: 0.44, K_s: 3.0, theta: 0.23, ExuT: 0.8, BGF: 0.15, K_d: 14.5, K_r: 0.4, ExuM: 8.0,
,'J': 'mean annual carbon input' # "t C ha^{-1}yr^{-1}" ,'a': 'flux coefficient to BIO' ,'b': 'flux coefficient to HUM' ,'f_T': 'function of temperature' ,'f_W': 'function of soil moisture' } for name in sym_dict.keys(): var(name) x = 1.67 * (1.85 + 1.60 * exp(-0.0786 * pClay)) gamma = DR/(1+DR) a = 0.46/(1+x) b = 0.54/(1+x) t = TimeSymbol("t") # unit: "year" # ??? parameters are yearly, but it is run on monthly basis x = StateVariableTuple((C_1, C_2, C_3, C_4, C_5)) u = InputTuple((J * ImmutableMatrix(5, 1, [gamma, 1-gamma, 0, 0, 0]))) xi = f_T * f_W # environmental effects multiplier A = ImmutableMatrix([[ -k_1, 0 , 0, 0, 0], [ 0, -k_2, 0, 0, 0], [ a*k_1, a*k_2, -k_3+a*k_3, a*k_4, 0], [ b*k_1, b*k_2, b*k_3,-k_4+b*k_4, 0], [ 0, 0, 0, 0, 0]]) B = CompartmentalMatrix(xi * A) # Original values without effects of temperature and soil moisture # doi = {10.1007/978-3-642-61094-3_17}, np1 = NumericParameterization( par_dict={ k_1: 10 ,k_2: 0.3 ,k_3: 0.66 ,k_4: 0.02
'F_5': 'Cycling rate of pool 5' # "yr^{-1}" , 'F_21': 'Transfer coefficient from non-woody to woody vegetation', 'F_41': 'Transfer coefficient from non-woody to detritus', 'F_42': 'Transfer coefficient from ground vegetaion to detritus', 'F_52': 'Transfer coefficient from woody parts to soil', 'F_43': 'Transfer coefficient from ground vegetation to deteritus', 'F_53': 'Transfer coefficient from ground vegetation to soil', 'F_54': 'Transfer coefficient from detritus to soil' } for name in sym_dict.keys(): var(name) t = TimeSymbol("t") # unit: "day" x = StateVariableTuple((x_1, x_2, x_3, x_4, x_5)) u = InputTuple((I_1, 0, I_3, 0, 0)) B = CompartmentalMatrix([[-F_1, 0, 0, 0, 0], [F_21, -F_2, 0, 0, 0], [0, 0, -F_3, 0, 0], [F_41, F_42, F_43, -F_4, 0], [0, F_52, F_53, F_54, -F_5]]) np1 = NumericParameterization(par_dict={ I_1: 77, I_3: 36, F_1: 2.081, F_2: 0.0686, F_3: 0.5217, F_4: 0.5926, F_5: 9.813e-3, F_21: 0.8378, F_41: 0.5676, F_42: 0.0322, F_52: 4.425e-3,
,'K_l': 'half-saturation constant for litter carbon assimilation by microbial biomass' # "g C*m^{-2}" ,'V_s': 'maximum rate of soil carbon assimilation per unit microbial biomass per year' # "year^{-1}" ,'K_s': 'half-saturation constant for soil carbon assimilation by microbial biomass' # "g C*m^{-2}" ,'lamda_l': 'litter carbon decomposition rate' ,'lamda_s': 'soil organic matter decomposition rate' ,'mu_b': 'turnover rate of microbial biomass per year' # "year^{-1}" ,'F_NPP': 'carbon influx into soil' # "g C*m^{-2}*year^{-1}" } for name in sym_dict.keys(): var(name) lamda_l = (C_b*V_l)/(C_l+K_l) lamda_s = (C_b*V_s)/(C_s+K_s) t = TimeSymbol("t") # unit: "year" x = StateVariableTuple((C_l, C_s, C_b)) u = InputTuple(((1-alpha)*F_NPP, alpha*F_NPP, 0)) B = CompartmentalMatrix( [[ -lamda_l, 0, 0], [ 0, -lamda_s, mu_b], [epsilon*lamda_l, epsilon*lamda_s, -mu_b]]) mvs = CMTVS( { BibInfo(# Bibliographical Information name="Three-pool microbial", longName="", version="1", entryAuthor="Holger Metzler", entryAuthorOrcid="0000-0002-8239-1601", entryCreationDate="22/01/2018", doi="10.5194/bg-11-1817-2014",
)) 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( ImmutableMatrix([ Npp(t) * bvec_leaf(t), Npp(t) * bvec_fine_root(t), # Npp(t)*bvec_wood(t), # 0, # 0, # 0, # 0, # 0, # 0 ])) # fraction from plant to different litter pools: casa_cnp.F90 Line 969, 970 fac_l = Max(0.001, 0.85 - 0.018 * r_lign_leaf) fac_r = Max(0.001, 0.85 - 0.018 * r_lign_fine_root) # formulate as piecewise xk_leaf_cold_max = Symbol("xk_leaf_cold_max") T_shed = Symbol("T_shed") xk_temp = q_10**( (T_soil(t) - 35 - 273.15) / 10
'C_s': 'soil organic matter' # "g C m^{-2}" ,'C_b': 'microbial biomass' # "g C m^{-2}" ,'epsilon': 'microbial growth efficiency' ,'V_s': 'maximum rate of soil carbon assimilation per unit microbial biomass per year' # "year^{-1}" ,'K_s': 'half-saturation constant for soil carbon assimilation by microbial biomass' # "g C m^{-2}" ,'lamda': 'soil organic matter decomposition rate' ,'mu_b': 'turnover rate of microbial biomass per year' # "year^{-1}" ,'F_NPP': 'carbon influx into soil' # "g C m^{-2} year^{-1}" } for name in sym_dict.keys(): var(name) lamda = (C_b*V_s)/(C_s+K_s) t = TimeSymbol("t") # unit: "year" x = StateVariableTuple((C_s, C_b)) u = InputTuple((F_NPP, 0)) B = CompartmentalMatrix([[ -lamda, mu_b], [epsilon*lamda, -mu_b]]) mvs = CMTVS( { BibInfo(# Bibliographical Information name="Two-pool microbial", longName="", version="1", entryAuthor="Holger Metzler", entryAuthorOrcid="0000-0002-8239-1601", entryCreationDate="18/01/2018", doi="10.5194/bg-11-1817-2014", sym_dict=sym_dict ),
for name in sym_dict.keys(): var(name) k_1 = K_1 * exp(-3 * Ls) k_3 = K_3 * exp(-3 * Ls) k_5 = K_5 * (1 - 0.75 * Tx) E_s = 0.85 - 0.68 * Tx F_m = 0.85 - 0.018 * LN F_s = 1 - F_m alpha_51 = 0.55 * (1 - A_l) alpha_53 = 0.45 * (1 - A_l) alpha_61 = 0.7 * A_l alpha_63 = alpha_61 alpha_65 = 1 - E_s - 0.004 t = TimeSymbol("t") # unit: "year" #??? monthly x = StateVariableTuple((C_1, C_2, C_3, C_4, C_5, C_6, C_7)) u = InputTuple((J_1 * F_s, J_1 * F_m, J_2 * F_s, J_2 * F_m, 0, 0, 0)) xi = f_T * f_W #environmental effects multiplier (DEFAG) A = ([-k_1, 0, 0, 0, 0, 0, 0], [0, -K_2, 0, 0, 0, 0, 0], [0, 0, -k_3, 0, 0, 0, 0], [0, 0, 0, -K_4, 0, 0, 0], [ alpha_51 * k_1, 0.45 * K_2, alpha_53 * k_3, 0.45 * K_4, -k_5, 0.42 * K_6, 0.45 * K_7 ], [alpha_61 * k_1, 0, alpha_63 * k_3, 0, alpha_65 * k_5, -K_6, 0], [0, 0, 0, 0, 0.004 * k_5, 0.03 * K_6, -K_7]) B = CompartmentalMatrix(xi * ImmutableMatrix(A)) #Original values without effects of temperature and soil moisture: np1 = NumericParameterization(par_dict={ K_1: 0.076, K_2: 0.28, K_3: 0.094, K_4: 0.35,
def test_immutability(self): T = InputTuple([1, 0, 1, 0]) with self.assertRaises(TypeError): T[1] = 1
'B': 'stable pool' # "MgC*ha^{-1}" , 'alpha': 'annual decomposition rate of labile pool' # "yr^{-1}" , 'beta': 'annual decomposition rate of stable pool' # "yr^{-1}" , 'm': 'annual organic matter input' # "MgC yr^{-1}" , 'K': 'isohumic coefficient' } for name in sym_dict.keys(): var(name) t = TimeSymbol("t") # unit: "year" C = StateVariableTuple((A, B)) I = InputTuple((m, 0)) A_GeM = CompartmentalMatrix([[-alpha, 0], [alpha * K, -beta]]) mvs = CMTVS( { BibInfo( # Bibliographical Information name="", longName="Henin and Dupois", version="1", entryAuthor="Holger Metzler", entryAuthorOrcid="0000-0002-8239-1601", entryCreationDate="09/03/2016", doi="", # bibtex="@inproceedings{Henin1945Annalesagronomiques, # author = {H\\'{e}nin, S and Dupuis, M}, # booktitle = {Annales agronomiques},
)) 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(( Npp(t) * bvec_leaf(t), Npp(t) * bvec_fine_root(t), Npp(t) * bvec_wood(t), 0, 0, 0, 0, 0, 0, )) # fraction from plant to different litter pools: casa_cnp.F90 Line 969, 970 fac_l = Max(0.001, 0.85 - 0.018 * r_lign_leaf) fac_r = Max(0.001, 0.85 - 0.018 * r_lign_fine_root) # formulate as piecewise xk_leaf_cold_max = Symbol("xk_leaf_cold_max") T_shed = Symbol("T_shed") xk_leaf_cold_exp = Symbol("xk_leaf_cold_exp") # xk_leaf_cold is temperature scalar for leaf: casa_cnp.F90 Line 785-787 xk_leaf_cold = Piecewise(
'B': 'Vector of partitioning coefficients of the photosynthetically fixed carbon (b_1, b_2, b_3)', 'C': 'Diagonal matrix with exit rates of carbon from the eight carbon pools (c_)', 'xi': 'Environmental scalar representing effects of temperature and moisture on the carbon transfer among pools' # xi_(t) } for name in sym_dict.keys(): var(name) f_W = Min((0.5 * W), 1) f_T = Q_10**((T - 10) / 10) xi = f_W * f_T x = StateVariableTuple((x_1, x_2, x_3, x_4, x_5, x_6, x_7, x_8)) B = (b_1, b_2, b_3, 0, 0, 0, 0, 0) Input = InputTuple(U * ImmutableMatrix(B)) A = ImmutableMatrix([[-1, 0, 0, 0, 0, 0, 0, 0], [0, -1, 0, 0, 0, 0, 0, 0], [0, 0, -1, 0, 0, 0, 0, 0], [f_41, 0, f_43, -1, 0, 0, 0, 0], [f_51, f_52, f_53, 0, -1, 0, 0, 0], [0, 0, 0, f_64, f_65, -1, f_67, f_68], [0, 0, 0, 0, f_75, f_76, -1, 0], [0, 0, 0, 0, 0, f_86, f_87, -1]]) C = ImmutableMatrix(diag(c_1, c_2, c_3, c_4, c_5, c_6, c_7, c_8)) CM = CompartmentalMatrix(xi * A * C) 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={
def test_shape(self): I = InputTuple((1, 1)) print(I, type(I))
'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)
'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={ k_1: 0.8,
, '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({ #})
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") # parameter_sets: # - "Original dataset of the publication":
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 = InputTuple((sigma_c * A, sigma_r * W_r, 0, 0, 0)) 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" np1 = NumericParameterization(par_dict={ sigma_r: 0.01,