750750
751751 # Too basic
752752 @test_nowarn run! (mtg, m_multiscale_prev_and_timestep, df, orchestrator= orch2)
753+ end
754+
755+ # #########################
756+ # Two models, D -> W, both D and W initially have two MTG nodes, one model adds MTG nodes
757+ # #########################
758+
759+ # Ideally this would be expanded to check the reduce doesn't do anything odd as the simulation continues
760+ @testset " D -> W, both D and W have two nodes" begin
761+
762+ PlantSimEngine. @process " ToyDay" verbose = false
763+
764+ struct MyToyDayModel <: AbstractToydayModel end
765+
766+ PlantSimEngine. inputs_ (m:: MyToyDayModel ) = (a= 1 ,)
767+ PlantSimEngine. outputs_ (m:: MyToyDayModel ) = (daily_temperature= - Inf ,)
768+
769+ function PlantSimEngine. run! (m:: MyToyDayModel , models, status, meteo, constants= nothing , extra= nothing )
770+ status. daily_temperature = meteo. T + node_id (status. node)
771+ end
772+
773+ PlantSimEngine. @process " ToyWeek" verbose = false
774+
775+ struct MyToyWeekModel <: AbstractToyweekModel
776+ temperature_threshold:: Float64
777+ end
778+
779+ MyToyWeekModel () = MyToyWeekModel (30.0 )
780+ function PlantSimEngine. inputs_ (:: MyToyWeekModel )
781+ (weekly_max_temperature= [- Inf ],)
782+ end
783+ PlantSimEngine. outputs_ (m:: MyToyWeekModel ) = (refvector= false ,length= - Inf )
784+
785+ function PlantSimEngine. run! (m:: MyToyWeekModel , models, status, meteo, constants= nothing , extra= nothing )
786+ status. refvector = status. weekly_max_temperature[1 ] + 1 == status. weekly_max_temperature[2 ]
787+ add_organ! (status. node,extra," +" , " Default" , 1 , index= 1 )
788+ # Having length computed after the organ addition means the two nodes at scale Default2 will have a different length value
789+ status. length = length (status. weekly_max_temperature)
790+ end
791+
792+ PlantSimEngine. timestep_range_ (m:: MyToyWeekModel ) = TimestepRange (Week (1 ))
793+
794+ meteo_day = read_weather (joinpath (pkgdir (PlantSimEngine), " examples/meteo_day.csv" ), duration= Day)
795+
796+ m_multiscale = Dict (" Default" => (
797+ MultiScaleModel (
798+ model= MyToyDayModel (),
799+ mapped_variables= [],
800+ timestep_mapped_variables= [TimestepMappedVariable (:daily_temperature , :weekly_temperature , Week (1 ), maximum)],
801+ ),
802+ Status (a= 1 ,)
803+ ),
804+ " Default2" => (
805+ MultiScaleModel (model= MyToyWeekModel (),
806+ mapped_variables= [:weekly_max_temperature => [" Default" => :weekly_temperature ]],
807+ ),
808+ ),)
809+
810+
811+ mtg = Node (MultiScaleTreeGraph. NodeMTG (" /" , " Default2" , 1 , 1 ))
812+ mtg2 = Node (mtg, MultiScaleTreeGraph. NodeMTG (" /" , " Default2" , 1 , 1 ))
813+ mtg3 = Node (mtg2, MultiScaleTreeGraph. NodeMTG (" +" , " Default" , 1 , 1 ))
814+ mtg4 = Node (mtg2, MultiScaleTreeGraph. NodeMTG (" +" , " Default" , 1 , 2 ))
815+
816+ mtsm = PlantSimEngine. ModelTimestepMapping (MyToyWeekModel, " Default2" , Week (1 ))
817+
818+ orch2 = PlantSimEngine. Orchestrator (Day (1 ), [mtsm,])
819+
820+ # @run run!(mtg, m_multiscale, meteo_day, orchestrator=orch2)
821+ out = run! (mtg, m_multiscale, meteo_day, orchestrator= orch2)
822+
823+ @test unique! ([out[" Default2" ][i]. refvector for i in 1 : 12 ]) == [false ]
824+ @test unique! ([out[" Default2" ][i]. refvector for i in 13 : 730 ]) == [true ]
825+ # This basic test checks that two nodes are added every week to the refvector
826+ @test unique! ([out[" Default2" ][i]. length == div (i,7 )+ 1 for i in 15 : 7 : 730 ]) == [true ]
753827end
0 commit comments