@@ -2230,6 +2230,9 @@ with respect to time, and more. For all cases, `u0` is the initial condition,
2230
2230
2231
2231
```julia
2232
2232
BVPFunction{iip, specialize}(f, bc;
2233
+ cost = __has_cost(f) ? f.cost : nothing,
2234
+ equality = __has_equality(f) ? f.equality : nothing,
2235
+ inequality = __has_inequality(f) ? f.inequality : nothing,
2233
2236
mass_matrix = __has_mass_matrix(f) ? f.mass_matrix : I,
2234
2237
analytic = __has_analytic(f) ? f.analytic : nothing,
2235
2238
tgrad= __has_tgrad(f) ? f.tgrad : nothing,
@@ -2257,6 +2260,11 @@ See the section on `iip` for more details on in-place vs out-of-place handling.
2257
2260
All of the remaining functions are optional for improving or accelerating
2258
2261
the usage of `f` and `bc`. These include:
2259
2262
2263
+ - `cost(u, p)`: the target to be minimized, similar with the `cost` function
2264
+ in [`OptimizationFunction`](@ref). This is used to define the objective function
2265
+ of the BVP, which can be minimized by optimization solvers.
2266
+ - `equality(res, u, t)`: equality constraints functions for the BVP.
2267
+ - `inequality(res, u, t)`: inequality contraints functions for the BVP.
2260
2268
- `mass_matrix`: the mass matrix `M` represented in the BVP function. Can be used
2261
2269
to determine that the equation is actually a BVP for differential algebraic equation (DAE)
2262
2270
if `M` is singular.
@@ -2310,12 +2318,14 @@ For more details on this argument, see the ODEFunction documentation.
2310
2318
2311
2319
The fields of the BVPFunction type directly match the names of the inputs.
2312
2320
"""
2313
- struct BVPFunction{iip, specialize, twopoint, F, BF, C, TMM, Ta, Tt, TJ, BCTJ, JVP, VJP,
2321
+ struct BVPFunction{iip, specialize, twopoint, F, BF, C, EC, IC, TMM, Ta, Tt, TJ, BCTJ, JVP, VJP,
2314
2322
JP, BCJP, BCRP, SP, TW, TWt, TPJ, O, TCV, BCTCV,
2315
2323
SYS, ID} <: AbstractBVPFunction{iip, twopoint}
2316
2324
f:: F
2317
2325
bc:: BF
2318
2326
cost:: C
2327
+ equality:: EC
2328
+ inequality:: IC
2319
2329
mass_matrix:: TMM
2320
2330
analytic:: Ta
2321
2331
tgrad:: Tt
@@ -4327,7 +4337,9 @@ function MultiObjectiveOptimizationFunction{iip}(f, adtype::AbstractADType = NoA
4327
4337
end
4328
4338
4329
4339
function BVPFunction {iip, specialize, twopoint} (f, bc;
4330
- cost = (x, p) -> zero (x),
4340
+ cost = __has_cost (f) ? f. cost : nothing ,
4341
+ equality = __has_equality (f) ? f. equality : nothing ,
4342
+ inequality = __has_inequality (f) ? f. inequality : nothing ,
4331
4343
mass_matrix = __has_mass_matrix (f) ? f. mass_matrix : I,
4332
4344
analytic = __has_analytic (f) ? f. analytic : nothing ,
4333
4345
tgrad = __has_tgrad (f) ? f. tgrad : nothing ,
@@ -4428,14 +4440,17 @@ function BVPFunction{iip, specialize, twopoint}(f, bc;
4428
4440
Wfactiip = Wfact != = nothing ? isinplace (Wfact, 5 , " Wfact" , iip) : iip
4429
4441
Wfact_tiip = Wfact_t != = nothing ? isinplace (Wfact_t, 5 , " Wfact_t" , iip) : iip
4430
4442
paramjaciip = paramjac != = nothing ? isinplace (paramjac, 4 , " paramjac" , iip) : iip
4443
+ costiip = cost != = nothing ? isinplace (cost, 2 , " cost" , iip) : iip
4444
+ equalityiip = equality != = nothing ? isinplace (equality, 3 , " equality" , iip) : iip
4445
+ inequalityiip = inequality != = nothing ? isinplace (inequality, 3 , " inequality" , iip) : iip
4431
4446
4432
4447
nonconforming = (bciip, jaciip, tgradiip, jvpiip, vjpiip, Wfactiip, Wfact_tiip,
4433
- paramjaciip) .!= iip
4448
+ paramjaciip, costiip, equalityiip, inequalityiip ) .!= iip
4434
4449
bc_nonconforming = bcjaciip .!= bciip
4435
4450
if any (nonconforming)
4436
4451
nonconforming = findall (nonconforming)
4437
- functions = [" bc" , " jac" , " bcjac " , " tgrad" , " jvp" , " vjp" , " Wfact" , " Wfact_t" ,
4438
- " paramjac" ][nonconforming]
4452
+ functions = [" bc" , " jac" , " tgrad" , " jvp" , " vjp" , " Wfact" , " Wfact_t" ,
4453
+ " paramjac" , " cost " , " equality " , " inequality " ][nonconforming]
4439
4454
throw (NonconformingFunctionsError (functions))
4440
4455
end
4441
4456
@@ -4466,24 +4481,25 @@ function BVPFunction{iip, specialize, twopoint}(f, bc;
4466
4481
sys = something (sys, SymbolCache (syms, paramsyms, indepsym))
4467
4482
4468
4483
if specialize === NoSpecialize
4469
- BVPFunction{iip, specialize, twopoint, Any, Any, Any, Any, Any, Any,
4484
+ BVPFunction{iip, specialize, twopoint, Any, Any, Any, Any, Any, Any, Any, Any,
4470
4485
Any, Any, Any, Any, Any, Any, Any, Any, Any, Any,
4471
4486
Any,
4472
4487
Any, typeof (_colorvec), typeof (_bccolorvec), Any, Any}(
4473
- _f, bc, mass_matrix,
4488
+ _f, bc, cost, equality, inequality, mass_matrix,
4474
4489
analytic, tgrad, jac, bcjac, jvp, vjp, jac_prototype,
4475
4490
bcjac_prototype, bcresid_prototype,
4476
4491
sparsity, Wfact, Wfact_t, paramjac, observed,
4477
4492
_colorvec, _bccolorvec, sys, initialization_data)
4478
4493
else
4479
4494
BVPFunction{iip, specialize, twopoint, typeof (_f), typeof (bc), typeof (cost),
4495
+ typeof (equality), typeof (inequality),
4480
4496
typeof (mass_matrix), typeof (analytic), typeof (tgrad), typeof (jac),
4481
4497
typeof (bcjac), typeof (jvp), typeof (vjp), typeof (jac_prototype),
4482
4498
typeof (bcjac_prototype), typeof (bcresid_prototype), typeof (sparsity),
4483
4499
typeof (Wfact), typeof (Wfact_t), typeof (paramjac), typeof (observed),
4484
4500
typeof (_colorvec), typeof (_bccolorvec), typeof (sys),
4485
4501
typeof (initialization_data)}(
4486
- _f, bc, cost, mass_matrix, analytic,
4502
+ _f, bc, cost, equality, inequality, mass_matrix, analytic,
4487
4503
tgrad, jac, bcjac, jvp, vjp,
4488
4504
jac_prototype, bcjac_prototype, bcresid_prototype, sparsity,
4489
4505
Wfact, Wfact_t, paramjac,
@@ -4939,6 +4955,9 @@ __has_initialization_data(f) = isdefined(f, :initialization_data)
4939
4955
__has_polynomialize (f) = isdefined (f, :polynomialize )
4940
4956
__has_unpolynomialize (f) = isdefined (f, :unpolynomialize )
4941
4957
__has_denominator (f) = isdefined (f, :denominator )
4958
+ __has_cost (f) = isdefined (f, :cost )
4959
+ __has_equality (f) = isdefined (f, :equality )
4960
+ __has_inequality (f) = isdefined (f, :inequality )
4942
4961
4943
4962
# compatibility
4944
4963
has_invW (f:: AbstractSciMLFunction ) = false
0 commit comments