Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/API/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ For systems that contain parameters with metadata like described above, have som
In the example below, we define a system with tunable parameters and extract bounds vectors

```@example metadata
@variables x(t)=0 u(t)=0 [input = true] y(t)=0 [output = true]
@variables x(t)=0 u(t)=0 [input=true] y(t)=0 [output=true]
@parameters T [tunable = true, bounds = (0, Inf)]
@parameters k [tunable = true, bounds = (0, Inf)]
eqs = [D(x) ~ (-x + k * u) / T # A first-order system with time constant T and gain k
Expand Down
3 changes: 2 additions & 1 deletion docs/src/basics/Events.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,8 @@ so far we aren't using anything that's not possible with the implicit interface.
You can also write

```julia
[temp ~ furnace_off_threshold] => ModelingToolkit.ImperativeAffect(modified = (;
[temp ~
furnace_off_threshold] => ModelingToolkit.ImperativeAffect(modified = (;
furnace_on)) do x, o, i, c
@set! x.furnace_on = false
end
Expand Down
2 changes: 1 addition & 1 deletion docs/src/basics/MTKLanguage.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ Refer the following example for different ways to define symbolic arrays.
p1[1:4]
p2[1:N]
p3[1:N,
1:M] = 10,
1:M] = 10,
[description = "A multi-dimensional array of arbitrary length with description"]
(p4[1:N, 1:M] = 10),
[description = "An alternate syntax for p3 to match the syntax of vanilla parameters macro"]
Expand Down
2 changes: 1 addition & 1 deletion docs/src/basics/Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function ModelingToolkit.get_unit(op::typeof(dummycomplex), args)
end

sts = @variables a(t)=0 [unit = u"cm"]
ps = @parameters s=-1 [unit = u"cm"] c=c [unit = u"cm"]
ps = @parameters s=-1 [unit=u"cm"] c=c [unit=u"cm"]
eqs = [D(a) ~ dummycomplex(c, s);]
sys = System(
eqs, t, [sts...;], [ps...;], name = :sys, checks = ~ModelingToolkit.CheckUnits)
Expand Down
18 changes: 9 additions & 9 deletions docs/src/examples/sparse_jacobians.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ function brusselator_2d_loop(du, u, p, t)
jm1 = limit(i + 1, N), limit(i - 1, N), limit(j + 1, N),
limit(j - 1, N)
du[i,
j,
1] = alpha * (u[im1, j, 1] + u[ip1, j, 1] + u[i, jp1, 1] + u[i, jm1, 1] -
4u[i, j, 1]) +
B + u[i, j, 1]^2 * u[i, j, 2] - (A + 1) * u[i, j, 1] +
brusselator_f(x, y, t)
j,
1] = alpha * (u[im1, j, 1] + u[ip1, j, 1] + u[i, jp1, 1] + u[i, jm1, 1] -
4u[i, j, 1]) +
B + u[i, j, 1]^2 * u[i, j, 2] - (A + 1) * u[i, j, 1] +
brusselator_f(x, y, t)
du[i,
j,
2] = alpha * (u[im1, j, 2] + u[ip1, j, 2] + u[i, jp1, 2] + u[i, jm1, 2] -
4u[i, j, 2]) +
A * u[i, j, 1] - u[i, j, 1]^2 * u[i, j, 2]
j,
2] = alpha * (u[im1, j, 2] + u[ip1, j, 2] + u[i, jp1, 2] + u[i, jm1, 2] -
4u[i, j, 2]) +
A * u[i, j, 1] - u[i, j, 1]^2 * u[i, j, 2]
end
end
p = (3.4, 1.0, 10.0, step(xyd_brusselator))
Expand Down
4 changes: 2 additions & 2 deletions docs/src/examples/tearing_parallelism.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using ModelingToolkit: t_nounits as t, D_nounits as D

# Basic electric components
@connector function Pin(; name)
@variables v(t)=1.0 i(t)=1.0 [connect = Flow]
@variables v(t)=1.0 i(t)=1.0 [connect=Flow]
System(Equation[], t, [v, i], [], name = name)
end

Expand All @@ -36,7 +36,7 @@ function ConstantVoltage(; name, V = 1.0)
end

@connector function HeatPort(; name)
@variables T(t)=293.15 Q_flow(t)=0.0 [connect = Flow]
@variables T(t)=293.15 Q_flow(t)=0.0 [connect=Flow]
System(Equation[], t, [T, Q_flow], [], name = name)
end

Expand Down
1 change: 1 addition & 0 deletions src/bipartite_graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ function Graphs.incidence_matrix(g::BipartiteGraph, val = true)
I = Int[]
J = Int[]
for i in 𝑠vertices(g), n in 𝑠neighbors(g, i)

push!(I, i)
push!(J, n)
end
Expand Down
2 changes: 2 additions & 0 deletions src/deprecations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ for T in [:ODEProblem, :DDEProblem, :SDEProblem, :SDDEProblem, :DAEProblem,
end

for pType in [SciMLBase.NullParameters, Nothing], uType in [Any, Nothing]

@eval function SciMLBase.$T(sys::System, u0::$uType, tspan, p::$pType; kw...)
ctor = string($T)
pT = string($(QuoteNode(pType)))
Expand Down Expand Up @@ -152,6 +153,7 @@ for T in [:NonlinearProblem, :NonlinearLeastSquaresProblem,
end
end
for pType in [SciMLBase.NullParameters, Nothing], uType in [Any, Nothing]

@eval function SciMLBase.$T(sys::System, u0::$uType, p::$pType; kw...)
ctor = string($T)
pT = string($(QuoteNode(pType)))
Expand Down
4 changes: 2 additions & 2 deletions src/inputoutput.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function same_or_inner_namespace(u, var)
nu == nv || # namespaces are the same
startswith(nv, nu) || # or nv starts with nu, i.e., nv is an inner namespace to nu
occursin(NAMESPACE_SEPARATOR, string(getname(var))) &&
!occursin(NAMESPACE_SEPARATOR, string(getname(u))) # or u is top level but var is internal
!occursin(NAMESPACE_SEPARATOR, string(getname(u))) # or u is top level but var is internal
end

function inner_namespace(u, var)
Expand All @@ -129,7 +129,7 @@ function inner_namespace(u, var)
nu == nv && return false
startswith(nv, nu) || # or nv starts with nu, i.e., nv is an inner namespace to nu
occursin(NAMESPACE_SEPARATOR, string(getname(var))) &&
!occursin(NAMESPACE_SEPARATOR, string(getname(u))) # or u is top level but var is internal
!occursin(NAMESPACE_SEPARATOR, string(getname(u))) # or u is top level but var is internal
end

"""
Expand Down
2 changes: 2 additions & 0 deletions src/structural_transformation/bareiss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ end

function bareiss_update!(zero!, M::StridedMatrix, k, swapto, pivot, prev_pivot)
@inbounds for i in (k + 1):size(M, 2), j in (k + 1):size(M, 1)

M[j, i] = exactdiv(M[j, i] * pivot - M[j, k] * M[k, i], prev_pivot)
end
zero!(M, (k + 1):size(M, 1), k)
Expand Down Expand Up @@ -269,6 +270,7 @@ function reduce_echelon!(A::AbstractMatrix{T}, rank, d,
end
@label out
@inbounds for i in (rank + 1):m, j in 1:n

A[i, j] = zero(T)
end
isreduced && return A
Expand Down
1 change: 1 addition & 0 deletions src/structural_transformation/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function torn_system_with_nlsolve_jacobian_sparsity(state, var_eq_matching, var_
var_rename = ones(Int64, ndsts(graph))
nlsolve_vars = Int[]
for i in nlsolve_scc_idxs, c in var_sccs[i]

append!(nlsolve_vars, c)
for v in c
var_rename[v] = 0
Expand Down
4 changes: 3 additions & 1 deletion src/structural_transformation/symbolics_tearing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ function generate_derivative_variables!(
# We need the inverse mapping of `var_sccs` to update it efficiently later.
v_to_scc = Vector{NTuple{2, Int}}(undef, ndsts(graph))
for (i, scc) in enumerate(var_sccs), (j, v) in enumerate(scc)

v_to_scc[v] = (i, j)
end
# Pairs of `(x_t, dx)` added below
Expand Down Expand Up @@ -475,7 +476,7 @@ function find_duplicate_dd(dv, solvable_graph, diff_to_var, linear_eqs, mm)
if length(nzs) == 2 &&
(abs(nzs[1]) == 1 && nzs[1] == -nzs[2]) &&
(v_t = rvs[1] == dv ? rvs[2] : rvs[1];
diff_to_var[v_t] === nothing)
diff_to_var[v_t] === nothing)
@assert dv in rvs
return eq, v_t
end
Expand Down Expand Up @@ -1128,6 +1129,7 @@ function add_additional_history!(
# We need the inverse mapping of `var_sccs` to update it efficiently later.
v_to_scc = Vector{NTuple{2, Int}}(undef, ndsts(graph))
for (i, scc) in enumerate(var_sccs), (j, v) in enumerate(scc)

v_to_scc[v] = (i, j)
end

Expand Down
1 change: 1 addition & 0 deletions src/structural_transformation/tearing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function free_equations(graph, vars_scc, var_eq_matching, varfilter::F) where {F
ne = nsrcs(graph)
seen_eqs = falses(ne)
for vars in vars_scc, var in vars

varfilter(var) || continue
ieq = var_eq_matching[var]
if ieq isa Int
Expand Down
7 changes: 4 additions & 3 deletions src/structural_transformation/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ function sorted_incidence_matrix(ts::TransformationState, val = true; only_algeq
varidx = 0
eqidx = 0
for vs in var_scc, v in vs

eq = var_eq_matching[v]
if eq !== unassigned
eqsmap[eq] = (eqidx += 1)
Expand Down Expand Up @@ -255,9 +256,9 @@ function find_eq_solvables!(state::TearingState, ieq, to_rm = Int[], coeffs = no
# if any of the variables in `a` are present in fullvars (taking into account arrays)
if any(
v -> any(isequal(v), fullvars) ||
symbolic_type(v) == ArraySymbolic() &&
Symbolics.shape(v) != Symbolics.Unknown() &&
any(x -> any(isequal(x), fullvars), collect(v)),
symbolic_type(v) == ArraySymbolic() &&
Symbolics.shape(v) != Symbolics.Unknown() &&
any(x -> any(isequal(x), fullvars), collect(v)),
vars(
a; op = Union{Differential, Shift, Pre, Sample, Hold, Initial}))
continue
Expand Down
9 changes: 5 additions & 4 deletions src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,8 @@ function full_equations(sys::AbstractSystem; simplify = false)
subs = get_substitutions(sys)
neweqs = map(equations(sys)) do eq
if iscall(eq.lhs) && operation(eq.lhs) isa Union{Shift, Differential}
return substitute_and_simplify(eq.lhs, subs, simplify) ~ substitute_and_simplify(
return substitute_and_simplify(eq.lhs, subs, simplify) ~
substitute_and_simplify(
eq.rhs, subs,
simplify)
else
Expand Down Expand Up @@ -2755,10 +2756,10 @@ function process_parameter_equations(sys::AbstractSystem)
if all(varsbuf) do sym
is_parameter(sys, sym) ||
symbolic_type(sym) == ArraySymbolic() &&
is_sized_array_symbolic(sym) &&
all(Base.Fix1(is_parameter, sys), collect(sym)) ||
is_sized_array_symbolic(sym) &&
all(Base.Fix1(is_parameter, sys), collect(sym)) ||
iscall(sym) &&
operation(sym) === getindex && is_parameter(sys, arguments(sym)[1])
operation(sym) === getindex && is_parameter(sys, arguments(sym)[1])
end
# Everything in `varsbuf` is a parameter, so this is a cheap `is_parameter`
# check.
Expand Down
2 changes: 2 additions & 0 deletions src/systems/alias_elimination.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ function find_linear_variables(graph, linear_equations, var_to_diff, irreducible
eqs = get(var_to_lineq, v, nothing)
eqs === nothing && continue
for eq in eqs, v′ in 𝑠neighbors(graph, eq)

if linear_variables[v′]
linear_variables[v′] = false
push!(stack, v′)
Expand All @@ -224,6 +225,7 @@ function find_linear_variables(graph, linear_equations, var_to_diff, irreducible
end
end
for eq in linear_equations, v in 𝑠neighbors(graph, eq)

linear_variables[v] = true
vlineqs = get!(() -> BitSet(), var_to_lineq, v)
push!(vlineqs, eq)
Expand Down
2 changes: 1 addition & 1 deletion src/systems/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ function Base.:(==)(e1::AbstractCallback, e2::AbstractCallback)
(is_discrete(e1) === is_discrete(e2)) || return false
(isequal(e1.conditions, e2.conditions) && isequal(e1.affect, e2.affect) &&
isequal(e1.initialize, e2.initialize) && isequal(e1.finalize, e2.finalize)) &&
isequal(e1.reinitializealg, e2.reinitializealg) ||
isequal(e1.reinitializealg, e2.reinitializealg) ||
return false
is_discrete(e1) ||
(isequal(e1.affect_neg, e2.affect_neg) && isequal(e1.rootfind, e2.rootfind))
Expand Down
Loading
Loading