Skip to content

Commit 2e3e7f2

Browse files
authored
Allow indicating variables as input/output (#1132)
1 parent 0a1ccc0 commit 2e3e7f2

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/variables.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
struct VariableUnit end
22
struct VariableConnectType end
3-
struct VariabelNoiseType end
4-
struct VariabelDescriptionType end
3+
struct VariableNoiseType end
4+
struct VariableDescriptionType end
5+
struct VariableInput end
6+
struct VariableOutput end
57
Symbolics.option_to_metadata_type(::Val{:unit}) = VariableUnit
68
Symbolics.option_to_metadata_type(::Val{:connect}) = VariableConnectType
7-
Symbolics.option_to_metadata_type(::Val{:noise}) = VariabelNoiseType
8-
Symbolics.option_to_metadata_type(::Val{:description}) = VariabelDescriptionType
9+
Symbolics.option_to_metadata_type(::Val{:noise}) = VariableNoiseType
10+
Symbolics.option_to_metadata_type(::Val{:description}) = VariableDescriptionType
11+
Symbolics.option_to_metadata_type(::Val{:input}) = VariableInput
12+
Symbolics.option_to_metadata_type(::Val{:output}) = VariableOutput
913

1014
"""
1115
$(SIGNATURES)

test/inputoutput.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ModelingToolkit, OrdinaryDiffEq, Test
1+
using ModelingToolkit, OrdinaryDiffEq, Symbolics, Test
22

33
@parameters t σ ρ β
44
@variables x(t) y(t) z(t) F(t) u(t)
@@ -37,3 +37,16 @@ collapsed_eqs = [D(lorenz1.x) ~ (lorenz1.σ * (lorenz1.y - lorenz1.x) +
3737
simplifyeqs(eqs) = Equation.((x->x.lhs).(eqs), simplify.((x->x.rhs).(eqs)))
3838

3939
@test isequal(simplifyeqs(equations(connected)), simplifyeqs(collapsed_eqs))
40+
41+
# Variables indicated to be input/output
42+
@variables x [input=true]
43+
@test hasmetadata(x, Symbolics.option_to_metadata_type(Val(:input)))
44+
@test getmetadata(x, Symbolics.option_to_metadata_type(Val(:input))) == true
45+
@test !hasmetadata(x, Symbolics.option_to_metadata_type(Val(:output)))
46+
@test_throws KeyError getmetadata(x, Symbolics.option_to_metadata_type(Val(:output)))
47+
48+
@variables y [output=true]
49+
@test hasmetadata(y, Symbolics.option_to_metadata_type(Val(:output)))
50+
@test getmetadata(y, Symbolics.option_to_metadata_type(Val(:output))) == true
51+
@test !hasmetadata(y, Symbolics.option_to_metadata_type(Val(:input)))
52+
@test_throws KeyError getmetadata(y, Symbolics.option_to_metadata_type(Val(:input)))

0 commit comments

Comments
 (0)