Skip to content

Commit f9cd33f

Browse files
committed
Add default cost
1 parent fac21aa commit f9cd33f

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

lib/BoundaryValueDiffEqCore/src/utils.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,10 @@ end
617617
@inline __concrete_kwargs(::Nothing, ::Nothing, nlsolve_kwargs,
618618
optimize_kwargs) = (nlsolve_kwargs..., alias_u0 = true)
619619

620+
@inline __default_cost(::Nothing) = (x, p) -> 0.0
621+
@inline __default_cost(f) = f
622+
@inline __default_cost(fun::BVPFunction) = __default_cost(fun.cost)
623+
620624
function __construct_internal_problem(
621625
prob::BVProblem, alg, loss, jac, jac_prototype, resid_prototype, y, p, M, N)
622626
T = eltype(y)
@@ -626,12 +630,11 @@ function __construct_internal_problem(
626630
jac_prototype = jac_prototype)
627631
return __internal_nlsolve_problem(prob, resid_prototype, y, nlf, y, p)
628632
else
629-
optf = OptimizationFunction{iip}((x, p) -> 0.0, AutoFiniteDiff(), # Need to investigate the ForwardDiff dual problem
633+
optf = OptimizationFunction{iip}(__default_cost(prob.f), AutoFiniteDiff(), # Need to investigate the ForwardDiff dual problem
630634
cons = loss,
631635
cons_j = jac, cons_jac_prototype = jac_prototype)
632636
lcons = zeros(T, N*M)
633637
ucons = zeros(T, N*M)
634-
println("p: ", p)
635638
return __internal_optimization_problem(
636639
prob, optf, y, p; lcons = lcons, ucons = ucons)
637640
end
@@ -646,7 +649,8 @@ function __construct_internal_problem(
646649
jac_prototype = jac_prototype)
647650
return __internal_nlsolve_problem(prob, resid_prototype, y, nlf, y, p)
648651
else
649-
optf = OptimizationFunction{iip}((x, p) -> 0.0, get_dense_ad(diffmode), cons = loss,
652+
optf = OptimizationFunction{iip}(
653+
__default_cost(prob.f), get_dense_ad(diffmode), cons = loss,
650654
cons_j = jac, cons_jac_prototype = Matrix(jac_prototype))
651655
lcons = zeros(T, N*M)
652656
ucons = zeros(T, N*M)

0 commit comments

Comments
 (0)