Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hexaeder committed Nov 29, 2024
1 parent edaeb65 commit 93e6b1d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ext/MTKExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ function EdgeModel(sys::ODESystem, srcin, dstin, srcout, dstout; verbose=false,

mass_matrix = gen.mass_matrix
c = EdgeModel(;f, g, sym, insym, outsym, psym, obssym,
obsf, mass_matrix, ff=gen.fftype, name, allow_output_sym_clash=true, kwargs...)
obsf, mass_matrix, ff=gen.fftype, name, extin=extin_nwidx,
allow_output_sym_clash=true, kwargs...)
set_metadata!(c, :observed, gen.observed)
set_metadata!(c, :equations, gen.equations)
set_metadata!(c, :outputeqs, gen.outputeqs)
Expand Down
35 changes: 33 additions & 2 deletions test/external_inputs_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ using NetworkDynamics, Graphs
using Chairmarks: @b

using NetworkDynamics: StateBufIdx, OutBufIdx, ExtMap, collect_externals!
using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as Dt
using Random
using CUDA, Adapt

Expand Down Expand Up @@ -31,8 +33,37 @@ using CUDA, Adapt
end

@testset "test construction of elements with external inputs" begin
function fext(dv, v, ein, p, t, ext)
function fvext(dv, v, ein, ext, p, t)
dv[1] = ext[1]
end
c = VertexModel(f=fext, g=1, dim=1, extin=[VIndex(18,:a)])
function gvext(out, v, ein, ext, p, t)
out .= ext
end
v_noff = VertexModel(f=fvext, g=1, dim=1, extin=[VIndex(2,:a)])
v_ff = VertexModel(f=fvext, g=gvext, outdim=1, dim=1, extin=[VIndex(2,:a)])

function feext(de, e, vsrc, vdst, ext, p ,t)
de[1] = ext[1]
end
function geext(outsrc, outdst, e, vsrc, vdst, ext, p, t)
outsrc .= ext
outdst .= ext
end
e_noff = EdgeModel(f=feext, g=AntiSymmetric(1), dim=1, extin=[EIndex(2,:a)])
e_ff = EdgeModel(f=feext, g=geext, outdim=1, dim=1, extin=[EIndex(2,:a)])

@mtkmodel EdgeExt begin
@variables begin
srcin(t)
dstin(t)
extin1(t)
extin2(t)
out(t)
end
@equations begin
out ~ extin1 + extin2
end
end
@named edge = EdgeExt()
edgem = EdgeModel(edge, :srcin, :dstin, Directed(:out); extin=[:extin1 => VIndex(2,:a), :extin2 => VIndex(2,:a)])
end

0 comments on commit 93e6b1d

Please sign in to comment.