Skip to content
Merged
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
6 changes: 3 additions & 3 deletions docs/src/basics/Composition.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ function UnitMassWithFriction(k; name)
D(x) ~ v
D(v) ~ sin(t) - k*sign(v) # f = ma, sinusoidal force acting on the mass, and Coulomb friction opposing the movement
]
ODESystem(eqs, t, continuous_events=[v ~ 0], name=name) # when v = 0 there is a discontinuity
ODESystem(eqs, t; continuous_events=[v ~ 0], name) # when v = 0 there is a discontinuity
end
@named m = UnitMassWithFriction(0.7)
prob = ODEProblem(m, Pair[], (0, 10pi))
Expand All @@ -300,7 +300,7 @@ affect = [v ~ -v] # the effect is that the velocity changes sign
@named ball = ODESystem([
D(x) ~ v
D(v) ~ -9.8
], t, continuous_events = root_eqs => affect) # equation => affect
], t; continuous_events = root_eqs => affect) # equation => affect

ball = structural_simplify(ball)

Expand All @@ -327,7 +327,7 @@ continuous_events = [ # This time we have a vector of pairs
D(y) ~ vy,
D(vx) ~ -9.8-0.1vx, # gravity + some small air resistance
D(vy) ~ -0.1vy,
], t, continuous_events = continuous_events)
], t; continuous_events)


ball = structural_simplify(ball)
Expand Down
10 changes: 5 additions & 5 deletions src/systems/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,20 @@ function validate(jump::ModelingToolkit.MassActionJump, t::Symbolic; info::Strin
left_symbols = [x[1] for x in jump.reactant_stoch] #vector of pairs of symbol,int -> vector symbols
net_symbols = [x[1] for x in jump.net_stoch]
all_symbols = vcat(left_symbols,net_symbols)
allgood = _validate(all_symbols, string.(all_symbols), info = info)
allgood = _validate(all_symbols, string.(all_symbols); info)
n = sum(x->x[2],jump.reactant_stoch,init = 0)
base_unitful = all_symbols[1] #all same, get first
allgood && _validate([jump.scaled_rates, 1/(t*base_unitful^n)], ["scaled_rates", "1/(t*reactants^$n))"], info = info)
allgood && _validate([jump.scaled_rates, 1/(t*base_unitful^n)], ["scaled_rates", "1/(t*reactants^$n))"]; info)
end

function validate(jumps::ArrayPartition{<:Union{Any, Vector{<:JumpType}}}, t::Symbolic)
labels = ["in Mass Action Jumps,", "in Constant Rate Jumps,", "in Variable Rate Jumps,"]
all([validate(jumps.x[idx], t, info = labels[idx]) for idx in 1:3])
end

validate(eq::ModelingToolkit.Equation; info::String = "") = _validate([eq.lhs, eq.rhs], ["left", "right"], info = info)
validate(eq::ModelingToolkit.Equation, term::Union{Symbolic,Unitful.Quantity,Num}; info::String = "") = _validate([eq.lhs, eq.rhs, term], ["left","right","noise"], info = info)
validate(eq::ModelingToolkit.Equation, terms::Vector; info::String = "") = _validate(vcat([eq.lhs, eq.rhs], terms), vcat(["left", "right"], "noise #".*string.(1:length(terms))), info = info)
validate(eq::ModelingToolkit.Equation; info::String = "") = _validate([eq.lhs, eq.rhs], ["left", "right"]; info)
validate(eq::ModelingToolkit.Equation, term::Union{Symbolic,Unitful.Quantity,Num}; info::String = "") = _validate([eq.lhs, eq.rhs, term], ["left","right","noise"]; info)
validate(eq::ModelingToolkit.Equation, terms::Vector; info::String = "") = _validate(vcat([eq.lhs, eq.rhs], terms), vcat(["left", "right"], "noise #".*string.(1:length(terms))); info)

"Returns true iff units of equations are valid."
validate(eqs::Vector; info::String = "") = all([validate(eqs[idx], info = info*" in eq. #$idx") for idx in 1:length(eqs)])
Expand Down
2 changes: 1 addition & 1 deletion test/nonlinearsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ np = NonlinearProblem(ns, [0,0,0], [1,2,3], jac=true, sparse=true)
@parameters a
@variables x f

NonlinearSystem([0 ~ -a * x + f], [x,f], [a], name = name)
NonlinearSystem([0 ~ -a * x + f], [x,f], [a]; name)
end

function issue819()
Expand Down
2 changes: 1 addition & 1 deletion test/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ eq = D(x) ~ r*x
@variables x(t) f(t)
D = Differential(t)

ODESystem([D(x) ~ -a*x + f], name = name)
ODESystem([D(x) ~ -a*x + f]; name)
end

function issue808()
Expand Down
6 changes: 3 additions & 3 deletions test/root_equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ continuous_events = [
D(y) ~ vy
D(vx) ~ -9.8
D(vy) ~ -0.01vy # there is some small air resistance
], t, continuous_events = continuous_events)
], t; continuous_events)



Expand Down Expand Up @@ -274,7 +274,7 @@ continuous_events = [
D(y) ~ vy
D(vx) ~ -1
D(vy) ~ 0
], t, continuous_events = continuous_events)
], t; continuous_events)

ball = structural_simplify(ball)

Expand Down Expand Up @@ -304,4 +304,4 @@ sys = structural_simplify(sys)
prob = ODAEProblem(sys, zeros(2), (0.0, 5.1))
sol = solve(prob, Tsit5())
@test all(minimum((0:0.1:5) .- sol.t', dims=2) .< 0.0001) # test that the solver stepped every 0.1s as dictated by event
@test sol([0.25])[vmeasured][] == sol([0.23])[vmeasured][] # test the hold property
@test sol([0.25])[vmeasured][] == sol([0.23])[vmeasured][] # test the hold property