Skip to content

Commit 8292ff1

Browse files
Brad Carmanoxinabox
authored andcommitted
format
1 parent f9ebf03 commit 8292ff1

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/Blocks/sources.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,14 +592,14 @@ function set_sampled_data!(memory::Parameter{T}, t, x, Δt::Parameter{T}) where
592592
i = round(Int, t / Δt) + 1 #expensive
593593
if i == n + 1
594594
push!(memory.data, x)
595-
elseif i<=n
595+
elseif i <= n
596596
@inbounds memory.data[i] = x
597597
else
598598
error("Memory buffer skipped a step: n=$n, i=$i")
599599
end
600600

601601
# memory.ref = Δt
602-
602+
603603
return x
604604
end
605605
Symbolics.@register_symbolic set_sampled_data!(memory, t, x, Δt)
@@ -614,10 +614,8 @@ end
614614
Symbolics.derivative(::typeof(set_sampled_data!), args::NTuple{4, Any}, ::Val{3}) = 1
615615

616616
function first_order_backwards_difference(t, x, Δt, memory)
617-
618617
x1 = set_sampled_data!(memory, t, x, Δt)
619618
x0 = get_sampled_data_const(t - Δt, memory)
620619

621620
return (x1 - x0) / Δt
622621
end
623-

test/Blocks/sources.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ using ModelingToolkitStandardLibrary.Blocks: smooth_sin, smooth_cos, smooth_damp
66
using OrdinaryDiffEq: ReturnCode.Success
77

88
@parameters t
9+
D = Differential(t)
910

1011
@testset "Constant" begin
1112
@named src = Constant(k = 2)
@@ -413,11 +414,13 @@ end
413414
time = 0:dt:t_end
414415
x = @. time^2 + 1.0
415416

417+
vars = @variables y(t)=1 dy(t)=0
418+
416419
@named src = SampledData(Float64)
417420
@named int = Integrator()
418-
@named iosys = ODESystem([
419-
connect(src.output, int.input),
420-
],
421+
@named iosys = ODESystem([y ~ src.output.u
422+
D(y) ~ dy
423+
connect(src.output, int.input)],
421424
t,
422425
systems = [int, src])
423426
sys = structural_simplify(iosys)
@@ -432,4 +435,5 @@ end
432435

433436
@test sol(time)[src.output.u]x atol=1e-3
434437
@test sol[int.output.u][end]1 / 3 * 10^3 + 10.0 atol=1e-3 # closed-form solution to integral
438+
@test sol[dy][end]2 * time[end] atol=1e-3
435439
end

0 commit comments

Comments
 (0)