-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a way to manage computations over an MTG, considering scales, symbols... #38
Comments
Instead of defining it in e.g. m =
ModelList(
photosynthesis = FvCB() => "Leaf", # 1
carbon_offer = ("Leaf" => :A,) => CommonCPool() => "Plant", # 2
carbon_allocation = ("Plant" => :carbon_offer => first,) => CAllocationRelativeToDemand() => ["Leaf", "Internode"], # 3
) Details:
This way we can take inputs from other scales and give them to a given node, and we can define on which nodes a model is applied. Then we can make the code that will build the simulation, grouping the model calls into scales whenever possible (so we traverse the mtg as little as possible), of course taking into account the dependencies between the models for the simulation order. In the end, the code would be built automatically, and would look like something along this: init_mtg_models!(mtg, m)
function PlantSimEngine.run!(m, mtg, meteo, [...])
# Caching the traversals in the mtg root:
traversal_cache!(mtg, symbol = "Leaf")
traversal_cache!(mtg, symbol = ["Leaf", "Internode"])
for (i, meteo_) in enumerate(Tables.rows(meteo))
# Call the photosynthesis model over all leaves
MultiScaleTreeGraph.traverse!(plant, symbol="Leaf") do leaf
PlantSimEngine.run!(leaf[:models].models.photosynthesis, leaf[:models].models, leaf[:models].status[i], meteo_, constants, nothing)
end
mtg[:models].status[i].A = descendants(mtg, :A, symbol = "Leaf")
PlantSimEngine.run!(mtg[:models].models.carbon_offer, mtg[:models].models, mtg[:models].status[i], meteo_, constants, nothing)
# Here we get the values of the carbon_offer by visiting the plant, this is then used by the `carbon_allocation`:
var_carbon_offer = typeof(inputs_(m.models.carbon_offer).carbon_offer)[] # Or something like this, here we have to pre-allocate a vector for the values of the carbon offer of the plant (may have several values if several plants)
MultiScaleTreeGraph.traverse!(plant, symbol="Plant") do plant
push!(var_carbon_offer, mtg[:models].status[i].carbon_offer)
end
var_carbon_offer = first(var_carbon_offer)
MultiScaleTreeGraph.traverse!(plant, symbol=["Leaf", "Internode"]) do leaf_or_internode
leaf_or_internode[:models].status[i].A = var_carbon_offer
PlantSimEngine.run!(leaf_or_internode[:models].models.carbon_allocation, leaf_or_internode[:models].models, leaf_or_internode[:models].status[i], meteo_, constants, nothing)
end
end
end |
This is fixed in #51 |
We need to be able to manage how models are applied over an MTG, eventually by tweaking the way we traverse the MTG.
For example, we can have the photosynthesis computed for each leaf, and then a common pool of carbon at the plant scale. Obviously the photosynthesis must be run first.
We have different ways of managing this (and I'm not sure how they are done or if they are possible):
In any case, we first need to define a way of declaring that a model depends on the computation of another scale, e.g. for the carbon pool we could have:
This code would define a dependency on the photosynthesis model from nodes that are of scale 1.
We would need ways of defining dependencies for the symbol or the id of a node too, e.g.:
We could also think about including a dependency on:
Maybe the best way would be to visit the MTG from the node we are computing. If a ModelList from the current node has a dependency on a model in its descendants, then we could go an visit them, identify where is the model in their ModelList, and run the root model of this dependency. Then we would have to mark it as already simulated somehow to avoid re-running it when visiting these nodes (we can have a new field in the dependency tree that marks the id of the simulated time-step, if this id is already there, we don't simulate the model). And then continue with the node we were simulating already.
The text was updated successfully, but these errors were encountered: