697
697
```julia
698
698
DiffEqBase.ODEProblem{iip}(sys::AbstractODESystem, u0map, tspan,
699
699
parammap = DiffEqBase.NullParameters();
700
+ allow_cost = false,
700
701
version = nothing, tgrad = false,
701
702
jac = false,
702
703
checkbounds = false, sparse = false,
730
731
function DiffEqBase. ODEProblem {iip, specialize} (sys:: AbstractODESystem , u0map = [],
731
732
tspan = get_tspan (sys),
732
733
parammap = DiffEqBase. NullParameters ();
734
+ allow_cost = false ,
733
735
callback = nothing ,
734
736
check_length = true ,
735
737
warn_initialize_determined = true ,
@@ -745,9 +747,10 @@ function DiffEqBase.ODEProblem{iip, specialize}(sys::AbstractODESystem, u0map =
745
747
Consider a BVProblem instead." )
746
748
end
747
749
748
- if ! isempty (get_costs (sys))
749
- error (" An ODESystem with costs cannot be solved using a regular ODEProblem.
750
- Solvers for optimal control problems are forthcoming." )
750
+ if ! isempty (get_costs (sys)) && ! allow_cost
751
+ error (" ODEProblem will not optimize solutions of ODESystems that have associated cost functions.
752
+ Solvers for optimal control problems are forthcoming. In order to bypass this error (e.g.
753
+ to check the cost of a regular solution), pass `allow_cost` = true into the constructor." )
751
754
end
752
755
753
756
f, u0, p = process_SciMLProblem (ODEFunction{iip, specialize}, sys, u0map, parammap;
@@ -801,21 +804,19 @@ If an ODESystem without `constraints` is specified, it will be treated as an ini
801
804
802
805
```julia
803
806
@parameters g t_c = 0.5
804
- @variables x(..) y(t) [state_priority = 10] λ(t)
807
+ @variables x(..) y(t) λ(t)
805
808
eqs = [D(D(x(t))) ~ λ * x(t)
806
809
D(D(y)) ~ λ * y - g
807
810
x(t)^2 + y^2 ~ 1]
808
811
cstr = [x(0.5) ~ 1]
809
- @named cstrs = ConstraintsSystem(cstr, t)
810
- @mtkbuild pend = ODESystem(eqs, t)
812
+ @mtkbuild pend = ODESystem(eqs, t; constraints = cstrs)
811
813
812
814
tspan = (0.0, 1.5)
813
815
u0map = [x(t) => 0.6, y => 0.8]
814
816
parammap = [g => 1]
815
817
guesses = [λ => 1]
816
- constraints = [x(0.5) ~ 1]
817
818
818
- bvp = SciMLBase.BVProblem{true, SciMLBase.AutoSpecialize}(pend, u0map, tspan, parammap; constraints, guesses, check_length = false)
819
+ bvp = SciMLBase.BVProblem{true, SciMLBase.AutoSpecialize}(pend, u0map, tspan, parammap; guesses, check_length = false)
819
820
```
820
821
821
822
If the `ODESystem` has algebraic equations, like `x(t)^2 + y(t)^2`, the resulting
@@ -844,6 +845,7 @@ function SciMLBase.BVProblem{iip, specialize}(sys::AbstractODESystem, u0map = []
844
845
tspan = get_tspan (sys),
845
846
parammap = DiffEqBase. NullParameters ();
846
847
guesses = Dict (),
848
+ allow_cost = false ,
847
849
version = nothing , tgrad = false ,
848
850
callback = nothing ,
849
851
check_length = true ,
@@ -857,9 +859,10 @@ function SciMLBase.BVProblem{iip, specialize}(sys::AbstractODESystem, u0map = []
857
859
end
858
860
! isnothing (callback) && error (" BVP solvers do not support callbacks." )
859
861
860
- if ! isempty (get_costs (sys))
861
- error (" An ODESystem with costs cannot be solved using a regular DAEProblem.
862
- Solvers for optimal control problems are forthcoming." )
862
+ if ! isempty (get_costs (sys)) && ! allow_cost
863
+ error (" BVProblem will not optimize solutions of ODESystems that have associated cost functions.
864
+ Solvers for optimal control problems are forthcoming. In order to bypass this error (e.g.
865
+ to check the cost of a regular solution), pass `allow_cost` = true into the constructor." )
863
866
end
864
867
865
868
has_alg_eqs (sys) &&
@@ -958,16 +961,19 @@ end
958
961
959
962
function DiffEqBase. DAEProblem {iip} (sys:: AbstractODESystem , du0map, u0map, tspan,
960
963
parammap = DiffEqBase. NullParameters ();
964
+ allow_cost = false ,
961
965
warn_initialize_determined = true ,
962
966
check_length = true , eval_expression = false , eval_module = @__MODULE__ , kwargs... ) where {iip}
963
967
if ! iscomplete (sys)
964
968
error (" A completed system is required. Call `complete` or `structural_simplify` on the system before creating a `DAEProblem`" )
965
969
end
966
970
967
- if ! isempty (get_costs (sys))
968
- error (" An ODESystem with costs cannot be solved using a regular DAEProblem.
969
- Solvers for optimal control problems are forthcoming." )
971
+ if ! isempty (get_costs (sys)) && ! allow_cost
972
+ error (" DAEProblem will not optimize solutions of ODESystems that have associated cost functions.
973
+ Solvers for optimal control problems are forthcoming. In order to bypass this error (e.g.
974
+ to check the cost of a regular solution), pass `allow_cost` = true into the constructor." )
970
975
end
976
+
971
977
f, du0, u0, p = process_SciMLProblem (DAEFunction{iip}, sys, u0map, parammap;
972
978
implicit_dae = true , du0map = du0map, check_length,
973
979
t = tspan != = nothing ? tspan[1 ] : tspan,
0 commit comments