Closed VEZY closed 1 month ago
Hmmm, it is working for the biomass with the simulation below. We have:
LeafBiomass
that computes the current biomassRankLeafPruning
that takes the current biomass as inputRmQ10FixedN
and LeafAreaModel
that use the values from the day beforeSo, based on the assumption from before, it shouldn't work. The problem probably happens for a different reason than I thought.
Simulation code:
using PlantMeteo, PlantSimEngine, DataFrames, CSV
using XPalm
meteo = CSV.read(joinpath(dirname(dirname(pathof(XPalm))), "0-data/meteo.csv"), DataFrame)
meteo.T = meteo.Taverage
meteo.Rh .= (meteo.Rh_max .- meteo.Rh_min) ./ 2 ./ 100
m = Weather(meteo)
p = Palm(nsteps=nrow(m))
mapping = Dict(
"Leaf" => (
XPalm.RankLeafPruning(p.parameters[:rank_leaf_pruning]),
MultiScaleModel(
model=XPalm.LeafAreaModel(
p.parameters[:lma_min],
p.parameters[:leaflets_biomass_contribution],
p.parameters[:potential_area][:leaf_area_first_leaf],
),
mapping=[PreviousTimeStep(:biomass),],
),
MultiScaleModel(
model=XPalm.RmQ10FixedN(
p.parameters[:respiration][:Leaf][:Q10],
p.parameters[:respiration][:Leaf][:Rm_base],
p.parameters[:respiration][:Leaf][:T_ref],
p.parameters[:respiration][:Leaf][:P_alive],
p.parameters[:nitrogen_content][:Leaf]
),
mapping=[PreviousTimeStep(:biomass),],
),
XPalm.LeafBiomass(
initial_biomass=p.parameters[:potential_area][:leaf_area_first_leaf] * p.parameters[:lma_min] /
p.parameters[:leaflets_biomass_contribution],
respiration_cost=p.parameters[:carbon_demand][:leaf][:respiration_cost],
),
Status(carbon_allocation=1.0, state="undetermined", rank=1)
)
)
dep(mapping)
to_initialize(mapping, p.mtg)
outs = Dict{String,Any}(
"Leaf" => (:biomass, :Rm, :leaf_area),
)
p = Palm(nsteps=nrow(m))
sim = run!(p.mtg, mapping, m, outputs=outs, executor=SequentialEx());
outputs(sim, DataFrame)
There is an issue when a variable at a given scale is needed at the current time-step for one model and at the previous time-step for another one.
You can look in XPalm to reproduce the error. The model
XPalm.OrganReserveFilling
needs the current values forreserve_organs
, but the modelXPalm.OrgansCarbonAllocationModel
needs the values from the previous day to avoid a cyclic dependency.If we get the full model mapping and then compute it, we get:
Note that
:reserve_organs
appears twice, once as is, and once wrapped inPreviousTimeStep(:reserve_organs, :carbon_allocation)
.We have to think about how we can manage such issue. For now, I changed the name of the variable for
OrgansCarbonAllocationModel
into:reserve_organs_all
.