Skip to content

Commit ddcf59e

Browse files
Merge pull request #2822 from SciML/nameof_operator
Add nameof dispatches on operators
2 parents 59cd46b + 898307a commit ddcf59e

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ SpecialFunctions = "0.7, 0.8, 0.9, 0.10, 1.0, 2"
109109
StaticArrays = "0.10, 0.11, 0.12, 1.0"
110110
SymbolicIndexingInterface = "0.3.12"
111111
SymbolicUtils = "2.1"
112-
Symbolics = "5.30.1"
112+
Symbolics = "5.32"
113113
URIs = "1"
114114
UnPack = "0.1, 1.0"
115115
Unitful = "1.1"

src/discretedomain.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ struct SampleTime <: Operator
44
SampleTime() = SymbolicUtils.term(SampleTime, type = Real)
55
end
66
SymbolicUtils.promote_symtype(::Type{<:SampleTime}, t...) = Real
7+
Base.nameof(::SampleTime) = :SampleTime
8+
SymbolicUtils.isbinop(::SampleTime) = false
79

810
# Shift
911

@@ -32,6 +34,9 @@ struct Shift <: Operator
3234
end
3335
Shift(steps::Int) = new(nothing, steps)
3436
normalize_to_differential(s::Shift) = Differential(s.t)^s.steps
37+
Base.nameof(::Shift) = :Shift
38+
SymbolicUtils.isbinop(::Shift) = false
39+
3540
function (D::Shift)(x, allow_zero = false)
3641
!allow_zero && D.steps == 0 && return x
3742
Term{symtype(x)}(D, Any[x])
@@ -108,6 +113,8 @@ Sample(x) = Sample()(x)
108113
(D::Sample)(x) = Term{symtype(x)}(D, Any[x])
109114
(D::Sample)(x::Num) = Num(D(value(x)))
110115
SymbolicUtils.promote_symtype(::Sample, x) = x
116+
Base.nameof(::Sample) = :Sample
117+
SymbolicUtils.isbinop(::Sample) = false
111118

112119
Base.show(io::IO, D::Sample) = print(io, "Sample(", D.clock, ")")
113120

@@ -137,6 +144,8 @@ end
137144
(D::Hold)(x) = Term{symtype(x)}(D, Any[x])
138145
(D::Hold)(x::Num) = Num(D(value(x)))
139146
SymbolicUtils.promote_symtype(::Hold, x) = x
147+
Base.nameof(::Hold) = :Hold
148+
SymbolicUtils.isbinop(::Hold) = false
140149

141150
Hold(x) = Hold()(x)
142151

test/initializationsystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ initprob = ModelingToolkit.InitializationProblem(pend, 0.0, [x => 1, y => 0], [g
2222
@test initprob isa NonlinearProblem
2323
sol = solve(initprob)
2424
@test SciMLBase.successful_retcode(sol)
25-
@test sol.u == [0.0, 0.0, 0.0]
25+
@test sol.u == [0.0, 0.0, 0.0, 0.0]
2626
@test maximum(abs.(sol[conditions])) < 1e-14
2727

2828
initprob = ModelingToolkit.InitializationProblem(

0 commit comments

Comments
 (0)