1+ # ############################################
2+ # ## Simulation with many organs in the MTG (but only a few different types of organs)
3+
4+
5+ PlantSimEngine. @process " organ_crazy_emergence" verbose = false
6+
7+ """
8+ ToyInternodeCrazyEmergence(;init_TT=0.0, TT_emergence = 300)
9+
10+ Computes the organ emergence based on cumulated thermal time since last event.
11+ """
12+ struct ToyInternodeCrazyEmergence <: AbstractOrgan_Crazy_EmergenceModel
13+ TT_emergence:: Float64
14+ end
15+
16+ ToyInternodeCrazyEmergence (; TT_emergence= 300.0 ) = ToyInternodeCrazyEmergence (TT_emergence)
17+
18+ PlantSimEngine. inputs_ (m:: ToyInternodeCrazyEmergence ) = (TT_cu= - Inf ,)
19+ PlantSimEngine. outputs_ (m:: ToyInternodeCrazyEmergence ) = (TT_cu_emergence= 0.0 ,)
20+
21+ function PlantSimEngine. run! (m:: ToyInternodeCrazyEmergence , models, status, meteo, constants= nothing , sim_object= nothing )
22+
23+ # root = get_root(status.node)
24+
25+ # if nleaves(root) > 10000
26+ # return nothing
27+ # end
28+
29+ if length (MultiScaleTreeGraph. children (status. node)) == 1 && status. TT_cu - status. TT_cu_emergence >= m. TT_emergence
30+
31+ status_new_internode = add_organ! (status. node, sim_object, " <" , " Internode" , 2 , index= 1 )
32+ add_organ! (status_new_internode. node, sim_object, " +" , " Leaf" , 2 , index= 1 )
33+ status_new_internode. TT_cu_emergence = status. TT_cu
34+ elseif (length (MultiScaleTreeGraph. children (status. node)) >= 2 && length (MultiScaleTreeGraph. children (status. node)) < 7 ) && status. TT_cu - status. TT_cu_emergence >= m. TT_emergence
35+ status_new_internode = add_organ! (status. node, sim_object, " <" , " Internode" , 2 , index= 1 )
36+ add_organ! (status. node, sim_object, " +" , " Leaf" , 2 , index= 4 )
37+ add_organ! (status. node, sim_object, " +" , " Leaf" , 2 , index= 5 )
38+ status_new_internode. TT_cu_emergence = status. TT_cu
39+ elseif (length (MultiScaleTreeGraph. children (status. node)) >= 7 && length (MultiScaleTreeGraph. children (status. node)) < 30 ) && status. TT_cu - status. TT_cu_emergence >= m. TT_emergence
40+ add_organ! (status. node, sim_object, " +" , " Leaf" , 2 , index= 6 )
41+ add_organ! (status. node, sim_object, " +" , " Leaf" , 2 , index= 7 )
42+ add_organ! (status. node, sim_object, " +" , " Leaf" , 2 , index= 8 )
43+ add_organ! (status. node, sim_object, " +" , " Leaf" , 2 , index= 9 )
44+ add_organ! (status. node, sim_object, " +" , " Leaf" , 2 , index= 10 )
45+ add_organ! (status. node, sim_object, " +" , " Leaf" , 2 , index= 11 )
46+
47+ end
48+
49+ return nothing
50+ end
51+
52+
53+ # Wrapped this into a function so that it doesn't plague the benchmark with variables on a global scope
54+ # @check_allocs
55+ function do_benchmark_on_heavier_mtg ()
56+ mtg = import_mtg_example ();
57+
58+ # Example meteo, 365 timesteps :
59+ meteo_day = read_weather (joinpath (pkgdir (PlantSimEngine), " examples/meteo_day.csv" ), duration= Day)
60+
61+ # similar to the mtg growth test but with a much lower emergence threshold
62+ mapping = Dict (
63+ " Scene" => ToyDegreeDaysCumulModel (),
64+ " Plant" => (
65+ MultiScaleModel (
66+ model= ToyLAIModel (),
67+ mapping= [
68+ :TT_cu => " Scene" ,
69+ ],
70+ ),
71+ PlantSimEngine. Examples. Beer (0.6 ),
72+ MultiScaleModel (
73+ model= ToyCAllocationModel (),
74+ mapping= [
75+ :carbon_assimilation => [" Leaf" ],
76+ :carbon_demand => [" Leaf" , " Internode" ],
77+ :carbon_allocation => [" Leaf" , " Internode" ]
78+ ],
79+ ),
80+ MultiScaleModel (
81+ model= ToyPlantRmModel (),
82+ mapping= [:Rm_organs => [" Leaf" => :Rm , " Internode" => :Rm ],],
83+ ),
84+ ),
85+ " Internode" => (
86+ MultiScaleModel (
87+ model= ToyCDemandModel (optimal_biomass= 10.0 , development_duration= 200.0 ),
88+ mapping= [:TT => " Scene" ,],
89+ ),
90+ MultiScaleModel (
91+ model= ToyInternodeCrazyEmergence (TT_emergence= 1.0 ),
92+ mapping= [:TT_cu => " Scene" ],
93+ ),
94+ ToyMaintenanceRespirationModel (1.5 , 0.06 , 25.0 , 0.6 , 0.004 ),
95+ Status (carbon_biomass= 1.0 )
96+ ),
97+ " Leaf" => (
98+ MultiScaleModel (
99+ model= ToyAssimModel (),
100+ mapping= [:soil_water_content => " Soil" , :aPPFD => " Plant" ],
101+ ),
102+ MultiScaleModel (
103+ model= ToyCDemandModel (optimal_biomass= 10.0 , development_duration= 200.0 ),
104+ mapping= [:TT => " Scene" ,],
105+ ),
106+ ToyMaintenanceRespirationModel (2.1 , 0.06 , 25.0 , 1.0 , 0.025 ),
107+ Status (carbon_biomass= 1.0 )
108+ ),
109+ " Soil" => (
110+ ToySoilWaterModel (),
111+ ),
112+ )
113+
114+ out_vars = Dict (
115+ " Leaf" => (:carbon_assimilation , :carbon_demand , :soil_water_content , :carbon_allocation ),
116+ " Internode" => (:carbon_allocation , :TT_cu_emergence ),
117+ " Plant" => (:carbon_allocation ,),
118+ " Soil" => (:soil_water_content ,),
119+ )
120+
121+ out = run! (mtg, mapping, meteo_day, outputs= out_vars, executor= SequentialEx ());
122+ end
0 commit comments