@@ -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,11 +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, 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
2326
+ cost:: C
2327
+ equality:: EC
2328
+ inequality:: IC
2318
2329
mass_matrix:: TMM
2319
2330
analytic:: Ta
2320
2331
tgrad:: Tt
@@ -4326,6 +4337,9 @@ function MultiObjectiveOptimizationFunction{iip}(f, adtype::AbstractADType = NoA
4326
4337
end
4327
4338
4328
4339
function BVPFunction {iip, specialize, twopoint} (f, bc;
4340
+ cost = __has_cost (f) ? f. cost : nothing ,
4341
+ equality = __has_equality (f) ? f. equality : nothing ,
4342
+ inequality = __has_inequality (f) ? f. inequality : nothing ,
4329
4343
mass_matrix = __has_mass_matrix (f) ? f. mass_matrix : I,
4330
4344
analytic = __has_analytic (f) ? f. analytic : nothing ,
4331
4345
tgrad = __has_tgrad (f) ? f. tgrad : nothing ,
@@ -4426,14 +4440,17 @@ function BVPFunction{iip, specialize, twopoint}(f, bc;
4426
4440
Wfactiip = Wfact != = nothing ? isinplace (Wfact, 5 , " Wfact" , iip) : iip
4427
4441
Wfact_tiip = Wfact_t != = nothing ? isinplace (Wfact_t, 5 , " Wfact_t" , iip) : iip
4428
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
4429
4446
4430
4447
nonconforming = (bciip, jaciip, tgradiip, jvpiip, vjpiip, Wfactiip, Wfact_tiip,
4431
- paramjaciip) .!= iip
4448
+ paramjaciip, costiip, equalityiip, inequalityiip ) .!= iip
4432
4449
bc_nonconforming = bcjaciip .!= bciip
4433
4450
if any (nonconforming)
4434
4451
nonconforming = findall (nonconforming)
4435
- functions = [" bc" , " jac" , " bcjac " , " tgrad" , " jvp" , " vjp" , " Wfact" , " Wfact_t" ,
4436
- " paramjac" ][nonconforming]
4452
+ functions = [" bc" , " jac" , " tgrad" , " jvp" , " vjp" , " Wfact" , " Wfact_t" ,
4453
+ " paramjac" , " cost " , " equality " , " inequality " ][nonconforming]
4437
4454
throw (NonconformingFunctionsError (functions))
4438
4455
end
4439
4456
@@ -4464,24 +4481,25 @@ function BVPFunction{iip, specialize, twopoint}(f, bc;
4464
4481
sys = something (sys, SymbolCache (syms, paramsyms, indepsym))
4465
4482
4466
4483
if specialize === NoSpecialize
4467
- BVPFunction{iip, specialize, twopoint, Any, Any, Any, Any, Any,
4484
+ BVPFunction{iip, specialize, twopoint, Any, Any, Any, Any, Any, Any, Any, Any,
4468
4485
Any, Any, Any, Any, Any, Any, Any, Any, Any, Any,
4469
4486
Any,
4470
4487
Any, typeof (_colorvec), typeof (_bccolorvec), Any, Any}(
4471
- _f, bc, mass_matrix,
4488
+ _f, bc, cost, equality, inequality, mass_matrix,
4472
4489
analytic, tgrad, jac, bcjac, jvp, vjp, jac_prototype,
4473
4490
bcjac_prototype, bcresid_prototype,
4474
4491
sparsity, Wfact, Wfact_t, paramjac, observed,
4475
4492
_colorvec, _bccolorvec, sys, initialization_data)
4476
4493
else
4477
- BVPFunction{iip, specialize, twopoint, typeof (_f), typeof (bc),
4494
+ BVPFunction{iip, specialize, twopoint, typeof (_f), typeof (bc), typeof (cost),
4495
+ typeof (equality), typeof (inequality),
4478
4496
typeof (mass_matrix), typeof (analytic), typeof (tgrad), typeof (jac),
4479
4497
typeof (bcjac), typeof (jvp), typeof (vjp), typeof (jac_prototype),
4480
4498
typeof (bcjac_prototype), typeof (bcresid_prototype), typeof (sparsity),
4481
4499
typeof (Wfact), typeof (Wfact_t), typeof (paramjac), typeof (observed),
4482
4500
typeof (_colorvec), typeof (_bccolorvec), typeof (sys),
4483
4501
typeof (initialization_data)}(
4484
- _f, bc, mass_matrix, analytic,
4502
+ _f, bc, cost, equality, inequality, mass_matrix, analytic,
4485
4503
tgrad, jac, bcjac, jvp, vjp,
4486
4504
jac_prototype, bcjac_prototype, bcresid_prototype, sparsity,
4487
4505
Wfact, Wfact_t, paramjac,
@@ -4937,6 +4955,9 @@ __has_initialization_data(f) = isdefined(f, :initialization_data)
4937
4955
__has_polynomialize (f) = isdefined (f, :polynomialize )
4938
4956
__has_unpolynomialize (f) = isdefined (f, :unpolynomialize )
4939
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 )
4940
4961
4941
4962
# compatibility
4942
4963
has_invW (f:: AbstractSciMLFunction ) = false
0 commit comments