You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/utils.jl
+51Lines changed: 51 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1185,3 +1185,54 @@ function guesses_from_metadata!(guesses, vars)
1185
1185
guesses[vars[i]] = varguesses[i]
1186
1186
end
1187
1187
end
1188
+
1189
+
"""
1190
+
$(TYPEDSIGNATURES)
1191
+
1192
+
Find all the unknowns and parameters from the equations of a SDESystem or ODESystem. Return re-ordered equations, differential variables, all variables, and parameters.
1193
+
"""
1194
+
functionprocess_equations(eqs, iv)
1195
+
eqs =collect(eqs)
1196
+
1197
+
diffvars =OrderedSet()
1198
+
allunknowns =OrderedSet()
1199
+
ps =OrderedSet()
1200
+
1201
+
# NOTE: this assumes that the order of algebraic equations doesn't matter
1202
+
# reorder equations such that it is in the form of `diffeq, algeeq`
1203
+
diffeq = Equation[]
1204
+
algeeq = Equation[]
1205
+
# initial loop for finding `iv`
1206
+
if iv ===nothing
1207
+
for eq in eqs
1208
+
if!(eq.lhs isa Number) # assume eq.lhs is either Differential or Number
1209
+
iv =iv_from_nested_derivative(eq.lhs)
1210
+
break
1211
+
end
1212
+
end
1213
+
end
1214
+
iv =value(iv)
1215
+
iv ===nothing&&throw(ArgumentError("Please pass in independent variables."))
1216
+
1217
+
compressed_eqs = Equation[] # equations that need to be expanded later, like `connect(a, b)`
1218
+
for eq in eqs
1219
+
eq.lhs isa Union{Symbolic, Number} || (push!(compressed_eqs, eq); continue)
throw(ArgumentError("An ODESystem can only have one independent variable."))
1226
+
diffvar in diffvars &&
1227
+
throw(ArgumentError("The differential variable $diffvar is not unique in the system of equations."))
1228
+
!(symtype(diffvar) === Real ||eltype(symtype(diffvar)) === Real) &&throw(ArgumentError("Differential variable $diffvar has type $(symtype(diffvar)). Differential variables should not be concretely typed."))
@test_throwsErrorException("SDESystem constructed by defining Brownian variables with @brownian must be simplified by calling `structural_simplify` before a SDEProblem can be constructed.") SDEProblem(de, u0map, (0.0, 100.0), parammap)
954
965
de =structural_simplify(de)
955
966
@testSDEProblem(de, u0map, (0.0, 100.0), parammap) isa SDEProblem
0 commit comments