Skip to content

Commit 2d343f6

Browse files
committed
Addendum : prototype tests moved to a new file, remove them from the old file.
1 parent cb77476 commit 2d343f6

1 file changed

Lines changed: 1 addition & 150 deletions

File tree

test/test-simulation.jl

Lines changed: 1 addition & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -292,153 +292,4 @@ end;
292292
end
293293
end
294294
end
295-
end
296-
297-
298-
299-
300-
using PlantSimEngine
301-
# Include the example dummy processes:
302-
using PlantSimEngine.Examples
303-
using Test, Aqua
304-
using Tables, DataFrames, CSV
305-
using MultiScaleTreeGraph
306-
using PlantMeteo, Statistics
307-
using Documenter # for doctests
308-
309-
using PlantMeteo.Dates
310-
include("helper-functions.jl")
311-
312-
313-
314-
# These models might be worth exposing in the future ?
315-
PlantSimEngine.@process "basic_current_timestep" verbose = false
316-
317-
struct HelperCurrentTimestepModel <: AbstractBasic_Current_TimestepModel
318-
end
319-
320-
PlantSimEngine.inputs_(::HelperCurrentTimestepModel) = (next_timestep=1,)
321-
PlantSimEngine.outputs_(m::HelperCurrentTimestepModel) = (current_timestep=1,)
322-
323-
function PlantSimEngine.run!(m::HelperCurrentTimestepModel, models, status, meteo, constants=nothing, extra=nothing)
324-
status.current_timestep = status.next_timestep
325-
end
326-
327-
PlantSimEngine.ObjectDependencyTrait(::Type{<:HelperCurrentTimestepModel}) = PlantSimEngine.IsObjectDependent()
328-
PlantSimEngine.TimeStepDependencyTrait(::Type{<:HelperCurrentTimestepModel}) = PlantSimEngine.IsTimeStepDependent()
329-
330-
PlantSimEngine.timestep_range_(m::HelperCurrentTimestepModel) = Day(1)
331-
332-
333-
PlantSimEngine.@process "basic_next_timestep" verbose = false
334-
struct HelperNextTimestepModel <: AbstractBasic_Next_TimestepModel
335-
end
336-
337-
PlantSimEngine.inputs_(::HelperNextTimestepModel) = (current_timestep=1,)
338-
PlantSimEngine.outputs_(m::HelperNextTimestepModel) = (next_timestep=1,)
339-
340-
function PlantSimEngine.run!(m::HelperNextTimestepModel, models, status, meteo, constants=nothing, extra=nothing)
341-
status.next_timestep = status.current_timestep + 1
342-
end
343-
344-
PlantSimEngine.timestep_range_(m::HelperNextTimestepModel) = Day(1)
345-
346-
347-
348-
349-
350-
PlantSimEngine.@process "ToyDay" verbose = false
351-
352-
struct MyToyDayModel <: AbstractToydayModel end
353-
354-
PlantSimEngine.inputs_(m::MyToyDayModel) = (a=1,)
355-
PlantSimEngine.outputs_(m::MyToyDayModel) = (daily_temperature=-Inf,)
356-
357-
function PlantSimEngine.run!(m::MyToyDayModel, models, status, meteo, constants=nothing, extra=nothing)
358-
status.daily_temperature = meteo.T
359-
end
360-
361-
PlantSimEngine.@process "ToyWeek" verbose = false
362-
363-
struct MyToyWeekModel <: AbstractToyweekModel
364-
temperature_threshold::Float64
365-
end
366-
367-
MyToyWeekModel() = MyToyWeekModel(30.0)
368-
function PlantSimEngine.inputs_(::MyToyWeekModel)
369-
(weekly_max_temperature=-Inf,)
370-
end
371-
PlantSimEngine.outputs_(m::MyToyWeekModel) = (hot = false,)
372-
373-
function PlantSimEngine.run!(m::MyToyWeekModel, models, status, meteo, constants=nothing, extra=nothing)
374-
status.hot = status.weekly_max_temperature > m.temperature_threshold
375-
end
376-
377-
PlantSimEngine.timestep_range_(m::MyToyWeekModel) = Week(1)
378-
379-
380-
381-
PlantSimEngine.@process "DWConnector" verbose = false
382-
383-
struct MyDwconnectorModel <: AbstractDwconnectorModel
384-
T_daily::Array{Float64}
385-
end
386-
387-
MyDwconnectorModel() = MyDwconnectorModel(Array{Float64}(undef, 7))
388-
389-
function PlantSimEngine.inputs_(::MyDwconnectorModel)
390-
(daily_temperature=-Inf, current_timestep=1,)
391-
end
392-
PlantSimEngine.outputs_(m::MyDwconnectorModel) = (weekly_max_temperature = 0.0,)
393-
394-
function PlantSimEngine.run!(m::MyDwconnectorModel, models, status, meteo, constants=nothing, extra=nothing)
395-
m.T_daily[1 + (status.current_timestep % 7)] = status.daily_temperature
396-
397-
if(status.current_timestep % 7 == 1)
398-
status.weekly_max_temperature = sum(m.T_daily)/7.0
399-
else
400-
status.weekly_max_temperature = 0
401-
end
402-
end
403-
404-
PlantSimEngine.timestep_range_(m::MyDwconnectorModel) = Day(1)
405-
406-
407-
408-
409-
410-
meteo_day = read_weather(joinpath(pkgdir(PlantSimEngine), "examples/meteo_day.csv"), duration=Day)
411-
412-
m = Dict("Default" => (
413-
MyToyDayModel(),
414-
MyToyWeekModel(),
415-
MyDwconnectorModel(),
416-
HelperNextTimestepModel(),
417-
MultiScaleModel(
418-
model=HelperCurrentTimestepModel(),
419-
mapped_variables=[PreviousTimeStep(:next_timestep),],
420-
),
421-
Status(a=1,)))
422-
423-
to_initialize(m)
424-
425-
models_timestep = Dict(MyToyDayModel=>1, MyDwconnectorModel => 1, MyToyWeekModel =>7, HelperNextTimestepModel => 1, HelperCurrentTimestepModel => 1)
426-
427-
mtg = Node(MultiScaleTreeGraph.NodeMTG("/", "Default", 1, 1))
428-
429-
out = run!(mtg, m, meteo_day, default_timestep=1, model_timesteps=models_timestep)
430-
431-
@testset "Test varying timestep" begin
432-
433-
434-
@test
435-
@test
436-
437-
end
438-
439-
440-
# NOTE : replace_mapping_status_vectors_with_generated_models is assumed to have already run if used
441-
# otherwise there might be vector length conflicts with timesteps
442-
sim = @enter PlantSimEngine.GraphSimulation(mtg, m, nsteps=nothing, check=true, outputs=nothing, default_timestep=1, model_timesteps=models_timestep)
443-
444-
using PlantSimEngine
295+
end

0 commit comments

Comments
 (0)