def make_daily_iterator_sym( V_init, mpa, func_dict ): # b (b vector for partial allocation) beta_wood = 1- mpa.beta_leaf- mpa.beta_root b = np.array( [ mpa.beta_leaf, mpa.beta_root, beta_wood, 0, 0, 0, 0, 0, 0 ], ).reshape(9,1) # Now construct B matrix B=A*K B_func = construct_matrix_func_sym( pa=mpa, ) # Build the iterator which is the representation of a dynamical system # for looping forward over the results of a difference equation # X_{i+1}=f(X_{i},i) # This is the discrete counterpart to the initial value problem # of the continuous ODE # dX/dt = f(X,t) and initial values X(t=0)=X_0 def f(it,V): X = V[0:9] co2 = V[9] npp = func_dict[Symbol('npp')](it,X) B = B_func(it,X) X_new = X + npp * b + B@X # we also compute the respired co2 in every (daily) timestep # and use this part of the solution later to sum up the monthly amount co2_new = -np.sum(B @ X) # fixme add computer for respirattion V_new = np.concatenate((X_new,np.array([co2_new]).reshape(1,1)), axis=0) return V_new #X_0 = np.array(x_init).reshape(9,1) #transform the tuple to a matrix #co2_0 = np.array([0]).reshape(1,1) #V_0 = np.concatenate((X_0, co2_0), axis=0) return TimeStepIterator2( initial_values=V_init, f=f#, #max_it=max(day_indices)+1 )
def make_daily_iterator(x_init, npp, clay, silt, lig_wood, lig_leaf, beta_leaf, beta_root, f_leaf2metlit, f_root2metlit, f_wood2CWD, f_metlit2mic, k_leaf, k_root, k_wood, k_metlit, k_mic, k_slowsom, k_passsom): # Construct npp(day) # in general this function can depend on the day i and the state_vector X # e.g. typically the size fo X.leaf... # In this case it only depends on the day i def npp_func(day, X): return npp[day_2_month_index(day)] * b # b (b vector for partial allocation) beta_wood = 1 - beta_leaf - beta_root b = np.array( [beta_leaf, beta_root, beta_wood, 0, 0, 0, 0, 0, 0], ).reshape(9, 1) # Now construct B matrix B=A*K B_func = make_compartmental_matrix_func(clay, silt, lig_wood, lig_leaf, f_leaf2metlit, f_root2metlit, f_wood2CWD, f_metlit2mic, k_leaf, k_root, k_wood, k_metlit, k_mic, k_slowsom, k_passsom) # Build the iterator which is the representation of a dynamical system # for looping forward over the results of a difference equation # X_{i+1}=f(X_{i},i) # This is the discrete counterpart to the initial value problem # of the continuous ODE # dX/dt = f(X,t) and initial values X(t=0)=X_0 def f(it, V): X = V[0:9] co2 = V[9] npp = npp_func(it, X) B = B_func(it, X) X_new = X + npp * b + B @ X # we also compute the respired co2 in every (daily) timestep # and use this part of the solution later to sum up the monthly amount co2_new = respiration_from_compartmental_matrix(B, X) V_new = np.concatenate((X_new, np.array([co2_new]).reshape(1, 1)), axis=0) return V_new X_0 = np.array(x_init).reshape(9, 1) #transform the tuple to a matrix co2_0 = np.array([0]).reshape(1, 1) V_0 = np.concatenate((X_0, co2_0), axis=0) return TimeStepIterator2( initial_values=V_0, f=f, #max_it=max(day_indices)+1 )