Skip to content

Commit baea381

Browse files
committed
add check
1 parent 2ca9ecf commit baea381

File tree

8 files changed

+22
-0
lines changed

8 files changed

+22
-0
lines changed

src/systems/diffeqs/odesystem.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ struct ODESystem <: AbstractODESystem
202202
check_parameters(ps, iv)
203203
check_equations(deqs, iv)
204204
check_equations(equations(cevents), iv)
205+
check_var_types(ODESystem, dvs)
205206
end
206207
if checks == true || (checks & CheckUnits) > 0
207208
u = __get_unit_type(dvs, ps, iv)

src/systems/diffeqs/sdesystem.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ struct SDESystem <: AbstractODESystem
170170
check_parameters(ps, iv)
171171
check_equations(deqs, iv)
172172
check_equations(neqs, dvs)
173+
check_var_types(SDESystem, dvs)
173174
if size(neqs, 1) != length(deqs)
174175
throw(ArgumentError("Noise equations ill-formed. Number of rows must match number of drift equations. size(neqs,1) = $(size(neqs,1)) != length(deqs) = $(length(deqs))"))
175176
end

src/systems/discrete_system/discrete_system.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ struct DiscreteSystem <: AbstractTimeDependentSystem
122122
check_independent_variables([iv])
123123
check_variables(dvs, iv)
124124
check_parameters(ps, iv)
125+
check_var_types(DiscreteSystem, dvs)
125126
end
126127
if checks == true || (checks & CheckUnits) > 0
127128
u = __get_unit_type(dvs, ps, iv)

src/systems/jumps/jumpsystem.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ struct JumpSystem{U <: ArrayPartition} <: AbstractTimeDependentSystem
147147
check_independent_variables([iv])
148148
check_variables(unknowns, iv)
149149
check_parameters(ps, iv)
150+
check_var_types(JumpSystem, unknowns)
150151
end
151152
if checks == true || (checks & CheckUnits) > 0
152153
u = __get_unit_type(unknowns, ps, iv)

src/systems/nonlinear/nonlinearsystem.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ struct NonlinearSystem <: AbstractTimeIndependentSystem
115115
tearing_state = nothing, substitutions = nothing,
116116
complete = false, index_cache = nothing, parent = nothing,
117117
isscheduled = false; checks::Union{Bool, Int} = true)
118+
if checks == true || (checks & CheckComponents) > 0
119+
check_var_types(NonlinearSystem, unknowns)
120+
end
118121
if checks == true || (checks & CheckUnits) > 0
119122
u = __get_unit_type(unknowns, ps)
120123
check_units(u, eqs)

src/systems/optimization/optimizationsystem.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ struct OptimizationSystem <: AbstractOptimizationSystem
7373
gui_metadata = nothing, complete = false, index_cache = nothing, parent = nothing,
7474
isscheduled = false;
7575
checks::Union{Bool, Int} = true)
76+
if checks == true || (checks & CheckComponents) > 0
77+
check_var_types(OptimizationSystem, unknowns)
78+
end
7679
if checks == true || (checks & CheckUnits) > 0
7780
u = __get_unit_type(unknowns, ps)
7881
unwrap(op) isa Symbolic && check_units(u, op)

src/systems/pde/pdesystem.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ struct PDESystem <: ModelingToolkit.AbstractMultivariateSystem
102102
checks::Union{Bool, Int} = true,
103103
description = "",
104104
name)
105+
if checks == true || (checks & CheckComponents) > 0
106+
check_var_types(PDESystem, dvs)
107+
end
105108
if checks == true || (checks & CheckUnits) > 0
106109
u = __get_unit_type(dvs, ivs, ps)
107110
check_units(u, eqs)

src/utils.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@ function check_variables(dvs, iv)
155155
end
156156
end
157157

158+
function check_var_types(sys_type::Type{T}, dvs) where T <: AbstractSystem
159+
any(u -> !(symtype(u) <: Number), dvs) && error("The type of unknown variables must be a numeric type.")
160+
if sys_type == ODESystem || sys_type == SDESystem || sys_type == PDESystem
161+
any(u -> !(symtype(u) <: Float), dvs) && error("The type of unknown variables for an SDESystem, PDESystem, or ODESystem must be a float.")
162+
end
163+
nothing
164+
end
165+
158166
function check_lhs(eq::Equation, op, dvs::Set)
159167
v = unwrap(eq.lhs)
160168
_iszero(v) && return
@@ -1182,3 +1190,4 @@ function guesses_from_metadata!(guesses, vars)
11821190
guesses[vars[i]] = varguesses[i]
11831191
end
11841192
end
1193+

0 commit comments

Comments
 (0)