From 6f176f6634658811c92ff73548a20c2adb5de27e Mon Sep 17 00:00:00 2001 From: Yingbo Ma Date: Sat, 16 Sep 2023 15:54:44 -0400 Subject: [PATCH 1/2] Handle analysis point correctly --- src/systems/connectors.jl | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/systems/connectors.jl b/src/systems/connectors.jl index fad7648d86..4522a8ff7c 100644 --- a/src/systems/connectors.jl +++ b/src/systems/connectors.jl @@ -299,14 +299,10 @@ function generate_connection_set!(connectionsets, domain_csets, else if lhs isa Number || lhs isa Symbolic push!(eqs, eq) # split connections and equations - elseif lhs isa Connection - if get_systems(lhs) === :domain - connection2set!(domain_csets, namespace, get_systems(rhs), isouter) - else - push!(cts, get_systems(rhs)) - end + elseif lhs isa Connection && get_systems(lhs) === :domain + connection2set!(domain_csets, namespace, get_systems(rhs), isouter) else - error("$eq is not a legal equation!") + push!(cts, get_systems(rhs)) end end end From 97e558f1cf555189cec88724c543b87e192b86bf Mon Sep 17 00:00:00 2001 From: Yingbo Ma Date: Sat, 16 Sep 2023 16:25:16 -0400 Subject: [PATCH 2/2] Handle jacobian and tgrad correctly when parameters are split --- src/systems/diffeqs/abstractodesystem.jl | 49 +++++++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/src/systems/diffeqs/abstractodesystem.jl b/src/systems/diffeqs/abstractodesystem.jl index ebc612a774..596cbbef4e 100644 --- a/src/systems/diffeqs/abstractodesystem.jl +++ b/src/systems/diffeqs/abstractodesystem.jl @@ -84,14 +84,37 @@ function generate_tgrad(sys::AbstractODESystem, dvs = states(sys), ps = paramete simplify = false, kwargs...) tgrad = calculate_tgrad(sys, simplify = simplify) pre = get_preprocess_constants(tgrad) - return build_function(tgrad, dvs, ps, get_iv(sys); postprocess_fbody = pre, kwargs...) + if ps isa Tuple + return build_function(tgrad, + dvs, + ps..., + get_iv(sys); + postprocess_fbody = pre, + kwargs...) + else + return build_function(tgrad, + dvs, + ps, + get_iv(sys); + postprocess_fbody = pre, + kwargs...) + end end function generate_jacobian(sys::AbstractODESystem, dvs = states(sys), ps = parameters(sys); simplify = false, sparse = false, kwargs...) jac = calculate_jacobian(sys; simplify = simplify, sparse = sparse) pre = get_preprocess_constants(jac) - return build_function(jac, dvs, ps, get_iv(sys); postprocess_fbody = pre, kwargs...) + if ps isa Tuple + return build_function(jac, + dvs, + ps..., + get_iv(sys); + postprocess_fbody = pre, + kwargs...) + else + return build_function(jac, dvs, ps, get_iv(sys); postprocess_fbody = pre, kwargs...) + end end function generate_control_jacobian(sys::AbstractODESystem, dvs = states(sys), @@ -364,8 +387,15 @@ function DiffEqBase.ODEFunction{iip, specialize}(sys::AbstractODESystem, dvs = s tgrad_oop, tgrad_iip = eval_expression ? (drop_expr(@RuntimeGeneratedFunction(eval_module, ex)) for ex in tgrad_gen) : tgrad_gen - _tgrad(u, p, t) = tgrad_oop(u, p, t) - _tgrad(J, u, p, t) = tgrad_iip(J, u, p, t) + if p isa Tuple + __tgrad(u, p, t) = tgrad_oop(u, p..., t) + __tgrad(J, u, p, t) = tgrad_iip(J, u, p..., t) + _tgrad = __tgrad + else + ___tgrad(u, p, t) = tgrad_oop(u, p, t) + ___tgrad(J, u, p, t) = tgrad_iip(J, u, p, t) + _tgrad = ___tgrad + end else _tgrad = nothing end @@ -379,8 +409,15 @@ function DiffEqBase.ODEFunction{iip, specialize}(sys::AbstractODESystem, dvs = s jac_oop, jac_iip = eval_expression ? (drop_expr(@RuntimeGeneratedFunction(eval_module, ex)) for ex in jac_gen) : jac_gen - _jac(u, p, t) = jac_oop(u, p, t) - _jac(J, u, p, t) = jac_iip(J, u, p, t) + if p isa Tuple + __jac(u, p, t) = jac_oop(u, p..., t) + __jac(J, u, p, t) = jac_iip(J, u, p..., t) + _jac = __jac + else + ___jac(u, p, t) = jac_oop(u, p, t) + ___jac(J, u, p, t) = jac_iip(J, u, p, t) + _jac = ___jac + end else _jac = nothing end