Skip to content

Commit 76a0db4

Browse files
committed
refactor: Blocks/sources.jl (limited)
1 parent 3250589 commit 76a0db4

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/Blocks/sources.jl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,19 @@ The input variable `t` can be changed by passing a different variable as the key
9191
# Connectors:
9292
- `output`
9393
"""
94-
@component function TimeVaryingFunction(f; t = t, name)
95-
@named output = RealOutput()
96-
eqs = [
97-
output.u ~ f(t),
98-
]
99-
compose(ODESystem(eqs, Blocks.t; name = name), [output])
94+
@mtkmodel TimeVaryingFunction begin
95+
@parameters begin
96+
f
97+
_t
98+
end
99+
@components begin
100+
output = RealOutput()
101+
end
102+
@equations begin
103+
output.u ~ first(getdefault(f))(_t)
104+
end
100105
end
106+
TimeVaryingFunction.f(f; name, _t) = TimeVaryingFunction.f(; f = [f], name, _t)
101107

102108
"""
103109
Generate sine signal.

test/Blocks/sources.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ end
2828
@testset "TimeVaryingFunction" begin
2929
f(t) = t^2 + 1
3030

31-
@named src = TimeVaryingFunction(f)
31+
@named src = TimeVaryingFunction(; f, _t = t)
3232
@named int = Integrator()
3333
@named iosys = ODESystem([
3434
connect(src.output, int.input),
@@ -37,7 +37,7 @@ end
3737
systems = [int, src])
3838
sys = structural_simplify(iosys)
3939

40-
prob = ODEProblem(sys, Pair[int.x => 0.0], (0.0, 10.0))
40+
prob = ODEProblem(sys, Pair[], (0.0, 10.0))
4141

4242
sol = solve(prob, Rodas4())
4343
@test sol.retcode == Success

0 commit comments

Comments
 (0)