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)
mvs = MVarSet({ BibInfo(# Bibliographical Information name="DALEC", longName="Data Assimilation Linked Ecosystem model", version="1", entryAuthor="Verónika Ceballos-Núñez", entryAuthorOrcid="0000-0002-0046-1160", entryCreationDate="16/9/2016", doi="10.1111/j.1365-2486.2004.00891.x", further_references=BibInfo(doi="10.1016/j.agrformet.2009.05.002"), # Also from PDF in Reflex experiment sym_dict=sym_dict ), # # the following variables constitute the compartmental system: # A, # the overall compartmental matrix Input, # the overall imput t, # time for the complete system x, # state vector of the the complete system # # the following variables constitute a numerical model run : # np1, nsv1, ntimes, # Again the model run could be created explicitly (in several ways) # # the following variables constitute a quantiy model run : # qp1, qsv1, qtimes, # Again the model run could be created explicitly (in several ways) # # the following variables give a more detailed view with respect to # carbon and vegetation variables # This imformation can be used to extract the part # of a model that is concerned with carbon and vegetation # in the case of this model all of the state variables # are vegetation and carbon related but for an ecosystem model # for different elements there could be different subsystems # e.g. consisting of Nitrogen Soil state variables # # vegetation carbon VegetationCarbonInputScalar(u), # vegetation carbon partitioning. VegetationCarbonInputPartitioningTuple(b), VegetationCarbonStateVariableTuple((C_f, C_lab, C_w, C_r)) })
def test_numeric_input_tuple(self): # setup the paths to the testdata cable_out_path = Path( '/home/data/cable-data/example_runs/parallel_1901_2004_with_spinup/output/new4' ) # cable_data_set = cH.cable_ds(cable_out_path) time_slice = slice(0, None) landpoint_slice = slice(1590, 1637) # cheated # landpoint_slice = slice(None,None) # time_slice=slice(None,None,None) zarr_cache_path = cP.slice_dir_path( cable_out_path, sub_dir_trunk="zarr_mm11", time_slice=time_slice, landpoint_slice=landpoint_slice, ) if "cable_data_set" not in dir(): cable_data_set = cH.cable_ds(cable_out_path) args = { "cable_data_set": cable_data_set, "zarr_cache_path": zarr_cache_path, "landpoint_slice": landpoint_slice, "time_slice": time_slice, #'batch_size': 128, "batch_size": 12, #'rm': True } x_org_iveg = cH.cacheWrapper(cC.x_org_iveg, **args) time = cH.cacheWrapper(cC.time, **args) patches, landpoints = cC.all_pools_vary_cond_nz(**args) pcs = patches.compute() lpcs = landpoints.compute() pcs, lpcs p = Path('plots') p.mkdir(exist_ok=True) ind = 0 # first pair that has a nonconstant solution for lp = lpcs[ind] patch = lpcs[ind] # get the symbolic represantation from the database mvs = self.mvs # define some stuff to extend it with def default(t): return 1 leaf = Symbol('leaf') fine_root = Symbol('fine_root') Npp = Function("Npp") bvec_leaf = Function("bvec_leaf") bvec_fine_root = Function("bvec_fine_root") xk_leaf_cold = Function("xk_leaf_cold") xk_leaf_dry = Function("xk_leaf_dry") kleaf = Function("kleaf") kfroot = Function("kfroot") # bvec_wood = Function("bvec_wood") np1 = NumericParameterization( par_dict={}, func_dict=frozendict({ Npp: default, bvec_fine_root: default, bvec_leaf: default, xk_leaf_cold: default, kleaf: default, kfroot: default, xk_leaf_dry: default, }), ) nsv1 = NumericStartValueDict({leaf: 0.3, fine_root: 3.96}) ntimes1 = NumericSimulationTimes(np.linspace(0, 1, 11)) # extend the symbolice version with the new stuff pvs = mvs.provided_mvar_values #from IPython import embed; embed() pvs1 = pvs.union(frozenset({np1, nsv1, ntimes1})) mvs1 = MVarSet(pvs1) x = mvs1.get_StateVariableTuple() Input = mvs1.get_InputTuple() #B = mvs1.get_CompartmentalMatrix() sym_times = mvs1.get_NumericSimulationTimes() sol_smooth = mvs1.get_NumericSolutionArray() comp_slice = slice(0, 100) n = sol_smooth.shape[1] fig = plt.figure() for pool in range(n): ax = fig.add_subplot(n + 1, 1, 2 + pool) title = "\$" + latex(x[pool]) + "\$" #ax.plot( # sym_times[comp_slice], # sol_smooth[comp_slice, pool], # color='r' #) ax.plot(time[comp_slice], x_org_iveg[comp_slice, pool, patch, lp], color='b') fontsize = 10 ax.set_title(title, fontsize=fontsize) fig.savefig('solution.pdf')
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 })
for old, new in rename_dict.items() } # We want to compute the fluxes with renamed symbols. # We first check what we have to substitute. # + mvs_TECO.provided_mvar_types # - mvs_TECO.get_StateVariableTuple().subs(subs_dict) mvs_subs=MVarSet({var.subs(subs_dict) for var in {mvs_TECO.get_CompartmentalMatrix(),mvs_TECO.get_StateVariableTuple(),mvs_TECO.get_InputTuple()} }) for v in mvs_subs.computable_mvar_types(): display(mvs_subs._get_single_mvar_value(v)) # This description already that the CompartmentalMatrix and Statevector are probably not consistent. # We can make this even more obvious by computing the outflux from the `C_root` pool. mvs_subs.get_OutFluxesBySymbol()[C_roots] # and the internal flux from `C_roots` to `C_stlit`. mvs_subs.get_InternalFluxesBySymbol()[(C_roots,C_stlit)] # We can probably repair this by exchanging the positions of `C_roots` and `C_woods` as has been done in the following version of the model