Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that equations contain at least one variable #2865

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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: 6 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ function check_equations(eqs, iv)
isequal(single_iv, iv) ||
throw(ArgumentError("Differential w.r.t. variable ($single_iv) other than the independent variable ($iv) are not allowed."))
end

for eq in eqs
vars, pars = collect_vars(eq, iv)
isempty(vars) && !isempty(pars) &&
throw(ArgumentError("Equation $eq contains only parameters, but relationships between parameters should be specified with defaults or parameter_dependencies."))
end
end
"""
Get all the independent variables with respect to which differentials are taken.
Expand Down
6 changes: 6 additions & 0 deletions test/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,12 @@ eqs = [
]
@test_throws ArgumentError ModelingToolkit.ODESystem(eqs, t, vars, pars, name = :foo)

# equations without variables are forbidden
# https://github.com/SciML/ModelingToolkit.jl/issues/2727
@parameters p q
@test_throws ArgumentError ODESystem([p ~ q], t; name = :foo)
@test_throws ArgumentError ODESystem([p ~ 1], t; name = :foo)

@variables x(t)
@parameters M b k
eqs = [D(D(x)) ~ -b / M * D(x) - k / M * x]
Expand Down
Loading