88
99function get_root_end_node (node:: MultiScaleTreeGraph.Node )
1010 root = MultiScaleTreeGraph. get_root (node)
11- return MultiScaleTreeGraph. traverse (root, x-> x, symbol= " Root" , filter_fun = MultiScaleTreeGraph. isleaf)
11+ return MultiScaleTreeGraph. traverse (root, x -> x, symbol= " Root" , filter_fun= MultiScaleTreeGraph. isleaf)
1212end
1313
1414function get_roots_count (node:: MultiScaleTreeGraph.Node )
1515 root = MultiScaleTreeGraph. get_root (node)
16- return length (MultiScaleTreeGraph. traverse (root, x-> x, symbol= " Root" ))
16+ return length (MultiScaleTreeGraph. traverse (root, x -> x, symbol= " Root" ))
1717end
1818
1919function get_n_leaves (node:: MultiScaleTreeGraph.Node )
2020 root = MultiScaleTreeGraph. get_root (node)
21- nleaves = length (MultiScaleTreeGraph. traverse (root, x-> 1 , symbol= " Leaf" ))
21+ nleaves = length (MultiScaleTreeGraph. traverse (root, x -> 1 , symbol= " Leaf" ))
2222 return nleaves
2323end
2424
@@ -32,10 +32,10 @@ struct ToyCustomInternodeEmergence{T} <: AbstractOrgan_EmergenceModel
3232 water_leaf_threshold:: T
3333end
3434
35- ToyCustomInternodeEmergence (;TT_emergence= 300.0 , carbon_internode_creation_cost= 200.0 , leaf_surface_area= 3.0 ,leaves_max_surface_area= 100.0 ,
36- water_leaf_threshold= 30.0 ) = ToyCustomInternodeEmergence (TT_emergence, carbon_internode_creation_cost, leaf_surface_area, leaves_max_surface_area, water_leaf_threshold)
35+ ToyCustomInternodeEmergence (; TT_emergence= 300.0 , carbon_internode_creation_cost= 200.0 , leaf_surface_area= 3.0 , leaves_max_surface_area= 100.0 ,
36+ water_leaf_threshold= 30.0 ) = ToyCustomInternodeEmergence (TT_emergence, carbon_internode_creation_cost, leaf_surface_area, leaves_max_surface_area, water_leaf_threshold)
3737
38- PlantSimEngine. inputs_ (m:: ToyCustomInternodeEmergence ) = (TT_cu= 0.0 ,water_stock= 0.0 , carbon_stock= 0.0 )
38+ PlantSimEngine. inputs_ (m:: ToyCustomInternodeEmergence ) = (TT_cu= 0.0 , water_stock= 0.0 , carbon_stock= 0.0 )
3939PlantSimEngine. outputs_ (m:: ToyCustomInternodeEmergence ) = (TT_cu_emergence= 0.0 , carbon_organ_creation_consumed= 0.0 )
4040
4141function PlantSimEngine. run! (m:: ToyCustomInternodeEmergence , models, status, meteo, constants= nothing , sim_object= nothing )
@@ -46,7 +46,7 @@ function PlantSimEngine.run!(m::ToyCustomInternodeEmergence, models, status, met
4646 if leaves_surface_area > m. leaves_max_surface_area
4747 return nothing
4848 end
49-
49+
5050 # if water levels are low, prioritise roots
5151 if status. water_stock < m. water_leaf_threshold
5252 return nothing
@@ -56,9 +56,9 @@ function PlantSimEngine.run!(m::ToyCustomInternodeEmergence, models, status, met
5656 if status. carbon_stock < m. carbon_internode_creation_cost
5757 return nothing
5858 end
59-
60- if length (MultiScaleTreeGraph. children (status. node)) == 2 &&
61- status. TT_cu - status. TT_cu_emergence >= m. TT_emergence
59+
60+ if length (MultiScaleTreeGraph. children (status. node)) == 2 &&
61+ status. TT_cu - status. TT_cu_emergence >= m. TT_emergence
6262 status_new_internode = add_organ! (status. node, sim_object, " <" , " Internode" , 2 , index= 1 )
6363 add_organ! (status_new_internode. node, sim_object, " +" , " Leaf" , 2 , index= 1 )
6464 add_organ! (status_new_internode. node, sim_object, " +" , " Leaf" , 2 , index= 1 )
@@ -104,15 +104,15 @@ struct ToyRootGrowthModel{T} <: AbstractRoot_GrowthModel
104104 root_max_len:: Int
105105end
106106
107- PlantSimEngine. inputs_ (:: ToyRootGrowthModel ) = (water_stock= 0.0 ,carbon_stock= 0.0 ,)
107+ PlantSimEngine. inputs_ (:: ToyRootGrowthModel ) = (water_stock= 0.0 , carbon_stock= 0.0 ,)
108108PlantSimEngine. outputs_ (:: ToyRootGrowthModel ) = (carbon_root_creation_consumed= 0.0 ,)
109109
110110function PlantSimEngine. run! (m:: ToyRootGrowthModel , models, status, meteo, constants= nothing , extra= nothing )
111111 if status. water_stock < m. water_threshold && status. carbon_stock > m. carbon_root_creation_cost
112-
112+
113113 root_end = get_root_end_node (status. node)
114-
115- if length (root_end) != 1
114+
115+ if length (root_end) != 1
116116 throw (AssertionError (" Couldn't find MTG leaf node with symbol \" Root\" " ))
117117 end
118118 root_len = get_roots_count (root_end[1 ])
@@ -135,10 +135,10 @@ struct ToyStockComputationModel <: AbstractResource_Stock_ComputationModel
135135end
136136# status.water_stock += meteo.precipitations * root_water_assimilation_ratio
137137
138- PlantSimEngine. inputs_ (:: ToyStockComputationModel ) =
139- (water_absorbed= 0.0 ,carbon_captured= 0.0 ,carbon_organ_creation_consumed= 0.0 ,carbon_root_creation_consumed= 0.0 )
138+ PlantSimEngine. inputs_ (:: ToyStockComputationModel ) =
139+ (water_absorbed= 0.0 , carbon_captured= 0.0 , carbon_organ_creation_consumed= 0.0 , carbon_root_creation_consumed= 0.0 )
140140
141- PlantSimEngine. outputs_ (:: ToyStockComputationModel ) = (water_stock= - Inf ,carbon_stock= - Inf )
141+ PlantSimEngine. outputs_ (:: ToyStockComputationModel ) = (water_stock= - Inf , carbon_stock= - Inf )
142142
143143function PlantSimEngine. run! (m:: ToyStockComputationModel , models, status, meteo, constants= nothing , extra= nothing )
144144 status. water_stock += sum (status. water_absorbed) # - status.water_transpiration
@@ -158,7 +158,7 @@ PlantSimEngine.ObjectDependencyTrait(::Type{<:ToyStockComputationModel}) = Plant
158158
159159PlantSimEngine. @process " leaf_carbon_capture" verbose = false
160160
161- struct ToyLeafCarbonCaptureModel<: AbstractLeaf_Carbon_CaptureModel end
161+ struct ToyLeafCarbonCaptureModel <: AbstractLeaf_Carbon_CaptureModel end
162162
163163function PlantSimEngine. inputs_ (:: ToyLeafCarbonCaptureModel )
164164 NamedTuple ()# (TT_cu=-Inf)
@@ -168,70 +168,68 @@ function PlantSimEngine.outputs_(::ToyLeafCarbonCaptureModel)
168168 (carbon_captured= 0.0 ,)
169169end
170170
171- function PlantSimEngine. run! (:: ToyLeafCarbonCaptureModel , models, status, meteo, constants, extra)
172- # very crude approximation with LAI of 1 and constant PPFD
173- status. carbon_captured = 200.0 * (1.0 - exp (- 0.2 ))
171+ function PlantSimEngine. run! (:: ToyLeafCarbonCaptureModel , models, status, meteo, constants, extra)
172+ # very crude approximation with LAI of 1 and constant aPPFD
173+ status. carbon_captured = 200.0 * (1.0 - exp (- 0.2 ))
174174end
175175
176176PlantSimEngine. ObjectDependencyTrait (:: Type{<:ToyLeafCarbonCaptureModel} ) = PlantSimEngine. IsObjectIndependent ()
177177PlantSimEngine. TimeStepDependencyTrait (:: Type{<:ToyLeafCarbonCaptureModel} ) = PlantSimEngine. IsTimeStepIndependent ()
178178
179179mapping = Dict (
180- " Scene" => ToyDegreeDaysCumulModel (),
181- " Plant" => (
182- MultiScaleModel (
183- model= ToyStockComputationModel (),
184- mapped_variables= [
185- :carbon_captured => [" Leaf" ],
186- :water_absorbed => [" Root" ],
187- :carbon_root_creation_consumed => [" Root" ],
188- :carbon_organ_creation_consumed => [" Internode" ]
189-
190- ],
180+ " Scene" => ToyDegreeDaysCumulModel (),
181+ " Plant" => (
182+ MultiScaleModel (
183+ model= ToyStockComputationModel (),
184+ mapped_variables= [
185+ :carbon_captured => [" Leaf" ],
186+ :water_absorbed => [" Root" ],
187+ :carbon_root_creation_consumed => [" Root" ],
188+ :carbon_organ_creation_consumed => [" Internode" ]],
191189 ),
192- Status (water_stock = 0.0 , carbon_stock = 0.0 )
190+ Status (water_stock= 0.0 , carbon_stock= 0.0 )
193191 ),
194- " Internode" => (
192+ " Internode" => (
195193 MultiScaleModel (
196194 model= ToyCustomInternodeEmergence (),# TT_emergence=20.0),
197195 mapped_variables= [:TT_cu => " Scene" ,
198- PreviousTimeStep (:water_stock )=> " Plant" ,
199- PreviousTimeStep (:carbon_stock )=> " Plant" ],
200- ),
196+ PreviousTimeStep (:water_stock ) => " Plant" ,
197+ PreviousTimeStep (:carbon_stock ) => " Plant" ],
198+ ),
201199 Status (carbon_organ_creation_consumed= 0.0 ),
202200 ),
203- " Root" => ( MultiScaleModel (
201+ " Root" => (MultiScaleModel (
204202 model= ToyRootGrowthModel (10.0 , 50.0 , 10 ),
205- mapped_variables= [PreviousTimeStep (:carbon_stock )=> " Plant" ,
206- PreviousTimeStep (:water_stock )=> " Plant" ],
207- ),
208- ToyWaterAbsorptionModel (),
209- Status (carbon_root_creation_consumed= 0.0 , root_water_assimilation= 1.0 ),
210- ),
211- " Leaf" => ( ToyLeafCarbonCaptureModel (),),
203+ mapped_variables= [PreviousTimeStep (:carbon_stock ) => " Plant" ,
204+ PreviousTimeStep (:water_stock ) => " Plant" ],
205+ ),
206+ ToyWaterAbsorptionModel (),
207+ Status (carbon_root_creation_consumed= 0.0 , root_water_assimilation= 1.0 ),
208+ ),
209+ " Leaf" => (ToyLeafCarbonCaptureModel (),),
212210)
213211
214- mtg = MultiScaleTreeGraph. Node (MultiScaleTreeGraph. NodeMTG (" /" , " Scene" , 1 , 0 ))
212+ mtg = MultiScaleTreeGraph. Node (MultiScaleTreeGraph. NodeMTG (" /" , " Scene" , 1 , 0 ))
213+
214+ plant = MultiScaleTreeGraph. Node (mtg, MultiScaleTreeGraph. NodeMTG (" +" , " Plant" , 1 , 1 ))
215215
216- plant = MultiScaleTreeGraph. Node (mtg, MultiScaleTreeGraph. NodeMTG (" +" , " Plant" , 1 , 1 ))
217-
218- internode1 = MultiScaleTreeGraph. Node (plant, MultiScaleTreeGraph. NodeMTG (" /" , " Internode" , 1 , 2 ))
219- MultiScaleTreeGraph. Node (internode1, MultiScaleTreeGraph. NodeMTG (" +" , " Leaf" , 1 , 2 ))
220- MultiScaleTreeGraph. Node (internode1, MultiScaleTreeGraph. NodeMTG (" +" , " Leaf" , 1 , 2 ))
216+ internode1 = MultiScaleTreeGraph. Node (plant, MultiScaleTreeGraph. NodeMTG (" /" , " Internode" , 1 , 2 ))
217+ MultiScaleTreeGraph. Node (internode1, MultiScaleTreeGraph. NodeMTG (" +" , " Leaf" , 1 , 2 ))
218+ MultiScaleTreeGraph. Node (internode1, MultiScaleTreeGraph. NodeMTG (" +" , " Leaf" , 1 , 2 ))
221219
222- internode2 = MultiScaleTreeGraph. Node (internode1, MultiScaleTreeGraph. NodeMTG (" <" , " Internode" , 1 , 2 ))
223- MultiScaleTreeGraph. Node (internode2, MultiScaleTreeGraph. NodeMTG (" +" , " Leaf" , 1 , 2 ))
224- MultiScaleTreeGraph. Node (internode2, MultiScaleTreeGraph. NodeMTG (" +" , " Leaf" , 1 , 2 ))
220+ internode2 = MultiScaleTreeGraph. Node (internode1, MultiScaleTreeGraph. NodeMTG (" <" , " Internode" , 1 , 2 ))
221+ MultiScaleTreeGraph. Node (internode2, MultiScaleTreeGraph. NodeMTG (" +" , " Leaf" , 1 , 2 ))
222+ MultiScaleTreeGraph. Node (internode2, MultiScaleTreeGraph. NodeMTG (" +" , " Leaf" , 1 , 2 ))
223+
224+ plant_root_start = MultiScaleTreeGraph. Node (
225+ plant,
226+ MultiScaleTreeGraph. NodeMTG (" +" , " Root" , 1 , 3 ),
227+ )
225228
226- plant_root_start = MultiScaleTreeGraph. Node (
227- plant,
228- MultiScaleTreeGraph. NodeMTG (" +" , " Root" , 1 , 3 ),
229- )
229+ meteo_day = CSV. read (joinpath (pkgdir (PlantSimEngine), " examples/meteo_day.csv" ), DataFrame, header= 18 )
230230
231- meteo_day = CSV. read (joinpath (pkgdir (PlantSimEngine), " examples/meteo_day.csv" ), DataFrame, header= 18 )
232-
233- outs = run! (mtg, mapping, meteo_day)
234- mtg
231+ outs = run! (mtg, mapping, meteo_day)
232+ mtg
235233
236234
237- length (MultiScaleTreeGraph. traverse (mtg,x -> x, symbol= " Leaf" ))
235+ length (MultiScaleTreeGraph. traverse (mtg, x -> x, symbol= " Leaf" ))
0 commit comments