Skip to content

Make get_differential_vars type stable #2698

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

Open
wants to merge 2 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
10 changes: 0 additions & 10 deletions lib/OrdinaryDiffEqCore/src/dense/generic_dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -990,16 +990,6 @@ function interpolation_differential_vars(differential_vars, y₀, idxs)
else
return Trues(size(idxs))
end
elseif differential_vars isa DifferentialVarsUndefined #for non diagonal mass matrices, use linear interpolation.
if y₀ isa Number
return false
elseif idxs === nothing
return Falses(size(y₀))
elseif idxs isa Number
return false
else
return Falses(size(idxs))
end
elseif idxs isa Number
return return differential_vars[idxs]
elseif idxs === nothing
Expand Down
20 changes: 10 additions & 10 deletions lib/OrdinaryDiffEqCore/src/misc_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,29 @@ macro fold(arg)
end
end

struct DifferentialVarsUndefined end

"""
get_differential_vars(f, idxs, timeseries::uType)

Returns an array of booleans for which values are the differential variables
vs algebraic variables. Returns `nothing` for the cases where all variables
are differential variables. Returns `DifferentialVarsUndefined` if it cannot
be determined (i.e. the mass matrix is not diagonal).
Returns an array of booleans, for which `true` refers to a differential variable and `false`
to an algebraic variable. If the function has no mass matrix, returns `nothing` (implying
all variables are differential).
"""
function get_differential_vars(f, u)
differential_vars = nothing
if hasproperty(f, :mass_matrix)
mm = f.mass_matrix
mm = mm isa MatrixOperator ? mm.A : mm

if mm isa UniformScaling || all(!iszero, mm)
if mm isa UniformScaling
return nothing
elseif all(!iszero, mm)
return trues(size(mm, 1))
elseif !(mm isa SciMLOperators.AbstractSciMLOperator) && isdiag(mm)
differential_vars = reshape(diag(mm) .!= 0, size(u))
return reshape(diag(mm) .!= 0, size(u))
else
return DifferentialVarsUndefined()
return reshape(.~all(iszero, mm, dims=1) .!= 0, size(u))
end
else
return nothing
end
end

Expand Down
Loading