Skip to content

Commit aaa8b9e

Browse files
baggepinnenAayushSabharwal
authored andcommitted
rm old discrete system
rm more stuff
1 parent 74cada4 commit aaa8b9e

13 files changed

+45
-902
lines changed

src/ModelingToolkit.jl

+2-6
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ include("systems/optimization/modelingtoolkitize.jl")
150150
include("systems/pde/pdesystem.jl")
151151

152152
include("systems/sparsematrixclil.jl")
153-
include("systems/discrete_system/discrete_system.jl")
153+
154154
include("systems/unit_check.jl")
155155
include("systems/validation.jl")
156156
include("systems/dependency_graphs.jl")
@@ -196,7 +196,7 @@ export NonlinearFunction, NonlinearFunctionExpr
196196
export NonlinearProblem, BlockNonlinearProblem, NonlinearProblemExpr
197197
export OptimizationProblem, OptimizationProblemExpr, constraints
198198
export SteadyStateProblem, SteadyStateProblemExpr
199-
export JumpProblem, DiscreteProblem
199+
export JumpProblem
200200
export NonlinearSystem, OptimizationSystem, ConstraintsSystem
201201
export alias_elimination, flatten
202202
export connect, domain_connect, @connector, Connection, Flow, Stream, instream
@@ -214,9 +214,6 @@ export SymScope, LocalScope, ParentScope, DelayParentScope, GlobalScope
214214
export independent_variable, equations, controls,
215215
observed, structure, full_equations
216216
export structural_simplify, expand_connections, linearize, linearization_function
217-
export DiscreteSystem,
218-
DiscreteProblem, DiscreteProblemExpr, DiscreteFunction,
219-
DiscreteFunctionExpr
220217

221218
export calculate_jacobian, generate_jacobian, generate_function
222219
export calculate_control_jacobian, generate_control_jacobian
@@ -227,7 +224,6 @@ export calculate_hessian, generate_hessian
227224
export calculate_massmatrix, generate_diffusion_function
228225
export stochastic_integral_transform
229226
export TearingState, StateSelectionState
230-
export generate_difference_cb
231227

232228
export BipartiteGraph, equation_dependencies, variable_dependencies
233229
export eqeq_dependencies, varvar_dependencies

src/clock.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ end
4242
has_time_domain(x::Num) = has_time_domain(value(x))
4343
has_time_domain(x) = false
4444

45-
for op in [Differential, Difference]
45+
for op in [Differential]
4646
@eval input_timedomain(::$op, arg = nothing) = Continuous()
4747
@eval output_timedomain(::$op, arg = nothing) = Continuous()
4848
end

src/structural_transformation/codegen.jl

+1-2
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,7 @@ function ODAEProblem{iip}(sys,
543543
u0 = ModelingToolkit.varmap_to_vars(u0map, dvs; defaults = defs, tofloat = true)
544544
p = ModelingToolkit.varmap_to_vars(parammap, ps; defaults = defs, tofloat, use_union)
545545

546-
has_difference = any(isdifferenceeq, eqs)
547-
cbs = process_events(sys; callback, has_difference, kwargs...)
546+
cbs = process_events(sys; callback, kwargs...)
548547

549548
kwargs = filter_kwargs(kwargs)
550549
if cbs === nothing

src/systems/callbacks.jl

+2-5
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ merge_cb(::Nothing, x) = merge_cb(x, nothing)
498498
merge_cb(x, ::Nothing) = x
499499
merge_cb(x, y) = CallbackSet(x, y)
500500

501-
function process_events(sys; callback = nothing, has_difference = false, kwargs...)
501+
function process_events(sys; callback = nothing, kwargs...)
502502
if has_continuous_events(sys)
503503
contin_cb = generate_rootfinding_callback(sys; kwargs...)
504504
else
@@ -509,9 +509,6 @@ function process_events(sys; callback = nothing, has_difference = false, kwargs.
509509
else
510510
discrete_cb = nothing
511511
end
512-
difference_cb = has_difference ? generate_difference_cb(sys; kwargs...) : nothing
513512

514-
cb = merge_cb(contin_cb, difference_cb)
515-
cb = merge_cb(cb, callback)
516-
(discrete_cb === nothing) ? cb : CallbackSet(cb, discrete_cb...)
513+
(discrete_cb === nothing) ? contin_cb : CallbackSet(contin_cb, discrete_cb...)
517514
end

src/systems/diffeqs/abstractodesystem.jl

+10-64
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ function generate_function(sys::AbstractODESystem, dvs = unknowns(sys), ps = par
144144
ddvs = implicit_dae ? map(Differential(get_iv(sys)), dvs) :
145145
nothing,
146146
isdde = false,
147-
has_difference = false,
148147
kwargs...)
149148
if isdde
150149
eqs = delay_to_function(sys)
@@ -167,8 +166,7 @@ function generate_function(sys::AbstractODESystem, dvs = unknowns(sys), ps = par
167166
if isdde
168167
build_function(rhss, u, DDE_HISTORY_FUN, p, t; kwargs...)
169168
else
170-
pre, sol_states = get_substitutions_and_solved_unknowns(sys,
171-
no_postprocess = has_difference)
169+
pre, sol_states = get_substitutions_and_solved_unknowns(sys)
172170

173171
if implicit_dae
174172
build_function(rhss, ddvs, u, p, t; postprocess_fbody = pre,
@@ -226,52 +224,6 @@ function delay_to_function(expr, iv, sts, ps, h)
226224
end
227225
end
228226

229-
function generate_difference_cb(sys::ODESystem, dvs = unknowns(sys), ps = parameters(sys);
230-
kwargs...)
231-
eqs = equations(sys)
232-
check_operator_variables(eqs, Difference)
233-
234-
var2eq = Dict(arguments(eq.lhs)[1] => eq for eq in eqs if isdifference(eq.lhs))
235-
236-
u = map(x -> time_varying_as_func(value(x), sys), dvs)
237-
p = map(x -> time_varying_as_func(value(x), sys), ps)
238-
t = get_iv(sys)
239-
240-
body = map(dvs) do v
241-
eq = get(var2eq, v, nothing)
242-
eq === nothing && return v
243-
d = operation(eq.lhs)
244-
d.update ? eq.rhs : eq.rhs + v
245-
end
246-
247-
pre = get_postprocess_fbody(sys)
248-
cpre = get_preprocess_constants(body)
249-
pre2 = x -> pre(cpre(x))
250-
f_oop, f_iip = build_function(body, u, p, t; expression = Val{false},
251-
postprocess_fbody = pre2, kwargs...)
252-
253-
cb_affect! = let f_oop = f_oop, f_iip = f_iip
254-
function cb_affect!(integ)
255-
if DiffEqBase.isinplace(integ.sol.prob)
256-
tmp, = DiffEqBase.get_tmp_cache(integ)
257-
f_iip(tmp, integ.u, integ.p, integ.t) # aliasing `integ.u` would be bad.
258-
copyto!(integ.u, tmp)
259-
else
260-
integ.u = f_oop(integ.u, integ.p, integ.t)
261-
end
262-
return nothing
263-
end
264-
end
265-
266-
getdt(eq) = operation(eq.lhs).dt
267-
deqs = values(var2eq)
268-
dt = getdt(first(deqs))
269-
all(dt == getdt(eq) for eq in deqs) ||
270-
error("All difference variables should have same time steps.")
271-
272-
PeriodicCallback(cb_affect!, first(dt))
273-
end
274-
275227
function calculate_massmatrix(sys::AbstractODESystem; simplify = false)
276228
eqs = [eq for eq in equations(sys) if !isdifferenceeq(eq)]
277229
dvs = unknowns(sys)
@@ -940,11 +892,11 @@ function DiffEqBase.ODEProblem{iip, specialize}(sys::AbstractODESystem, u0map =
940892
check_length = true,
941893
kwargs...) where {iip, specialize}
942894
has_difference = any(isdifferenceeq, equations(sys))
895+
has_difference && error("The operators Difference and DiscreteUpdate are deprecated. Use ShiftIndex instead.")
943896
f, u0, p = process_DEProblem(ODEFunction{iip, specialize}, sys, u0map, parammap;
944897
t = tspan !== nothing ? tspan[1] : tspan,
945-
has_difference = has_difference,
946898
check_length, kwargs...)
947-
cbs = process_events(sys; callback, has_difference, kwargs...)
899+
cbs = process_events(sys; callback, kwargs...)
948900
inits = []
949901
if has_discrete_subsystems(sys) && (dss = get_discrete_subsystems(sys)) !== nothing
950902
affects, inits, clocks, svs = ModelingToolkit.generate_discrete_affect(dss...)
@@ -1010,23 +962,17 @@ function DiffEqBase.DAEProblem{iip}(sys::AbstractODESystem, du0map, u0map, tspan
1010962
parammap = DiffEqBase.NullParameters();
1011963
check_length = true, kwargs...) where {iip}
1012964
has_difference = any(isdifferenceeq, equations(sys))
965+
has_difference && error("The operators Difference and DiscreteUpdate are deprecated. Use ShiftIndex instead.")
1013966
f, du0, u0, p = process_DEProblem(DAEFunction{iip}, sys, u0map, parammap;
1014-
implicit_dae = true, du0map = du0map,
1015-
has_difference = has_difference, check_length,
967+
implicit_dae = true, du0map = du0map, check_length,
1016968
kwargs...)
1017969
diffvars = collect_differential_variables(sys)
1018970
sts = unknowns(sys)
1019971
differential_vars = map(Base.Fix2(in, diffvars), sts)
1020972
kwargs = filter_kwargs(kwargs)
1021973

1022-
if has_difference
1023-
DAEProblem{iip}(f, du0, u0, tspan, p;
1024-
difference_cb = generate_difference_cb(sys; kwargs...),
1025-
differential_vars = differential_vars, kwargs...)
1026-
else
1027-
DAEProblem{iip}(f, du0, u0, tspan, p; differential_vars = differential_vars,
974+
DAEProblem{iip}(f, du0, u0, tspan, p; differential_vars = differential_vars,
1028975
kwargs...)
1029-
end
1030976
end
1031977

1032978
function generate_history(sys::AbstractODESystem, u0; kwargs...)
@@ -1043,15 +989,15 @@ function DiffEqBase.DDEProblem{iip}(sys::AbstractODESystem, u0map = [],
1043989
check_length = true,
1044990
kwargs...) where {iip}
1045991
has_difference = any(isdifferenceeq, equations(sys))
992+
has_difference && error("The operators Difference and DiscreteUpdate are deprecated. Use ShiftIndex instead.")
1046993
f, u0, p = process_DEProblem(DDEFunction{iip}, sys, u0map, parammap;
1047994
t = tspan !== nothing ? tspan[1] : tspan,
1048-
has_difference = has_difference,
1049995
symbolic_u0 = true,
1050996
check_length, kwargs...)
1051997
h_oop, h_iip = generate_history(sys, u0)
1052998
h = h_oop
1053999
u0 = h(p, tspan[1])
1054-
cbs = process_events(sys; callback, has_difference, kwargs...)
1000+
cbs = process_events(sys; callback, kwargs...)
10551001
inits = []
10561002
if has_discrete_subsystems(sys) && (dss = get_discrete_subsystems(sys)) !== nothing
10571003
affects, inits, clocks, svs = ModelingToolkit.generate_discrete_affect(dss...)
@@ -1103,16 +1049,16 @@ function DiffEqBase.SDDEProblem{iip}(sys::AbstractODESystem, u0map = [],
11031049
sparsenoise = nothing,
11041050
kwargs...) where {iip}
11051051
has_difference = any(isdifferenceeq, equations(sys))
1052+
has_difference && error("The operators Difference and DiscreteUpdate are deprecated. Use ShiftIndex instead.")
11061053
f, u0, p = process_DEProblem(SDDEFunction{iip}, sys, u0map, parammap;
11071054
t = tspan !== nothing ? tspan[1] : tspan,
1108-
has_difference = has_difference,
11091055
symbolic_u0 = true,
11101056
check_length, kwargs...)
11111057
h_oop, h_iip = generate_history(sys, u0)
11121058
h(out, p, t) = h_iip(out, p, t)
11131059
h(p, t) = h_oop(p, t)
11141060
u0 = h(p, tspan[1])
1115-
cbs = process_events(sys; callback, has_difference, kwargs...)
1061+
cbs = process_events(sys; callback, kwargs...)
11161062
inits = []
11171063
if has_discrete_subsystems(sys) && (dss = get_discrete_subsystems(sys)) !== nothing
11181064
affects, inits, clocks, svs = ModelingToolkit.generate_discrete_affect(dss...)

0 commit comments

Comments
 (0)