Skip to content

Commit

Permalink
variable ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Dec 12, 2019
1 parent 1bebe9c commit 6288680
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/systems/nonlinear/nonlinear_system.jl
Expand Up @@ -41,8 +41,15 @@ struct NonlinearSystem <: AbstractSystem
ps = reduce(, map(_find_params(vs), rhss); init = vnil())
new(eqs, vs, collect(ps))
end

function NonlinearSystem(eqs, vs, ps)
rhss = [eq.rhs for eq eqs]
new(eqs, vs, [p.op for p in ps])
end
end



vnil() = Set{Variable}()
_find_params(vs) = Base.Fix2(_find_params, vs)
function _find_params(O, vs)
Expand All @@ -65,9 +72,9 @@ function calculate_jacobian(sys::NonlinearSystem)
return jac
end

function generate_jacobian(sys::NonlinearSystem)
function generate_jacobian(sys::NonlinearSystem, vs = sys.vs, ps = sys.ps, expression = Val{true}; kwargs...)
jac = calculate_jacobian(sys)
return build_function(jac, clean.(sys.vs), sys.ps, (), NLSysToExpr(sys))
return build_function(jac, clean.(vs), clean.(ps), (), NLSysToExpr(sys))
end

struct NLSysToExpr
Expand All @@ -84,7 +91,7 @@ end
(f::NLSysToExpr)(x) = convert(Expr, x)


function generate_function(sys::NonlinearSystem, vs, ps, expression = Val{true}; kwargs...)
function generate_function(sys::NonlinearSystem, vs = sys.vs, ps = sys.ps, expression = Val{true}; kwargs...)
rhss = [eq.rhs for eq sys.eqs]
vs′ = [clean(v) for v vs]
ps′ = [clean(p) for p ps]
Expand Down

0 comments on commit 6288680

Please sign in to comment.