477477alg_order (:: MPRK22 ) = 2
478478isfsal (:: MPRK22 ) = false
479479
480+ function get_constant_parameters (alg:: MPRK22 )
481+ if ! (alg. alpha ≥ 1 / 2 )
482+ throw (ArgumentError (" MPRK22 requires α ≥ 1/2." ))
483+ end
484+
485+ a21 = alg. alpha
486+ b2 = 1 / (2 * a21)
487+ b1 = 1 - b2
488+ c2 = a21
489+
490+ # This should never happen
491+ if ! all ((a21, b1, b2, c2) .≥ 0 )
492+ throw (ArgumentError (" MPRK22 requires nonnegative RK coefficients." ))
493+ end
494+ return a21, b1, b2, c2
495+ end
496+
480497struct MPRK22Cache{uType, rateType, PType, tabType, Thread, F, uNoUnitsType} < :
481498 OrdinaryDiffEqMutableCache
482499 u:: uType
@@ -501,8 +518,11 @@ function alg_cache(alg::MPRK22, u, rate_prototype, ::Type{uEltypeNoUnits},
501518 :: Type{uBottomEltypeNoUnits} , :: Type{tTypeNoUnits} ,
502519 uprev, uprev2, f, t, dt, reltol, p, calck,
503520 :: Val{true} ) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
504- tab = MPRK22ConstantCache (alg. alpha, 1 - 1 / (2 * alg. alpha), 1 / (2 * alg. alpha),
505- alg. alpha, floatmin (uEltypeNoUnits))
521+ if ! (f isa PDSFunction || f isa ConservativePDSFunction)
522+ throw (ArgumentError (" MPRK22 can only be applied to production-destruction systems" ))
523+ end
524+ a21, b1, b2, c2 = get_constant_parameters (alg)
525+ tab = MPRK22ConstantCache (a21, b1, b2, c2, floatmin (uEltypeNoUnits))
506526
507527 tmp = zero (u)
508528
@@ -542,11 +562,12 @@ function alg_cache(alg::MPRK22, u, rate_prototype, ::Type{uEltypeNoUnits},
542562 :: Type{uBottomEltypeNoUnits} , :: Type{tTypeNoUnits} ,
543563 uprev, uprev2, f, t, dt, reltol, p, calck,
544564 :: Val{false} ) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
565+ if ! (f isa PDSFunction || f isa ConservativePDSFunction)
566+ throw (ArgumentError (" MPRK22 can only be applied to production-destruction systems" ))
567+ end
545568
546- # TODO : Should assert alg.alpha >= 0.5
547-
548- MPRK22ConstantCache (alg. alpha, 1 - 1 / (2 * alg. alpha), 1 / (2 * alg. alpha), alg. alpha,
549- floatmin (uEltypeNoUnits))
569+ a21, b1, b2, c2 = get_constant_parameters (alg)
570+ MPRK22ConstantCache (a21, b1, b2, c2, floatmin (uEltypeNoUnits))
550571end
551572
552573function initialize! (integrator, cache:: MPRK22ConstantCache )
@@ -811,14 +832,22 @@ struct MPRK43Cache{uType, rateType, PType, tabType, Thread, F, uNoUnitsType} <:
811832end
812833
813834function get_constant_parameters (alg:: MPRK43I )
814- @assert alg. alpha ≥ 1 / 3 && alg. alpha ≠ 2 / 3 " MPRK43I requires α ≥ 1/3 and α ≠ 2/3."
835+ if ! (alg. alpha ≥ 1 / 3 && alg. alpha ≠ 2 / 3 )
836+ throw (ArgumentError (" MPRK43I requires α ≥ 1/3 and α ≠ 2/3." ))
837+ end
815838 α0 = 1 / 6 * (3 + (3 - 2 * sqrt (2 ))^ (1 / 3 ) + (3 + 2 * sqrt (2 ))^ (1 / 3 ))
816839 if 1 / 3 ≤ alg. alpha < 2 / 3
817- @assert 2 / 3 ≤ alg. beta≤ 3 * alg. alpha* (1 - alg. alpha) " For this choice of α MPRK43I requires 2/3 ≤ β ≤ 3α(1-α)."
840+ if ! (2 / 3 ≤ alg. beta ≤ 3 * alg. alpha * (1 - alg. alpha))
841+ throw (ArgumentError (" For this choice of α MPRK43I requires 2/3 ≤ β ≤ 3α(1-α)." ))
842+ end
818843 elseif 2 / 3 < alg. alpha ≤ α0
819- @assert 3 * alg. alpha* (1 - alg. alpha)≤ alg. beta≤ 2 / 3 " For this choice of α MPRK43I requires 3α(1-α) ≤ β ≤ 2/3."
844+ if ! (3 * alg. alpha * (1 - alg. alpha) ≤ alg. beta ≤ 2 / 3 )
845+ throw (ArgumentError (" For this choice of α MPRK43I requires 3α(1-α) ≤ β ≤ 2/3." ))
846+ end
820847 else
821- @assert (3 * alg. alpha - 2 )/ (6 * alg. alpha - 3 )≤ alg. beta≤ 2 / 3 " For this choice of α MPRK43I requires (3α-2)/(6α-3) ≤ β ≤ 2/3."
848+ if ! ((3 * alg. alpha - 2 ) / (6 * alg. alpha - 3 ) ≤ alg. beta ≤ 2 / 3 )
849+ throw (ArgumentError (" For this choice of α MPRK43I requires (3α-2)/(6α-3) ≤ β ≤ 2/3." ))
850+ end
822851 end
823852
824853 a21 = alg. alpha
@@ -837,12 +866,17 @@ function get_constant_parameters(alg::MPRK43I)
837866 q1 = 1 / (3 * a21 * (a31 + a32) * b3)
838867 q2 = 1 / a21
839868
840- @assert all ((a21, a31, a32, b1, b2, b3, c2, c3, beta1, beta2) .≥ 0 ) " MPRK43I requires nonnegative RK coefficients."
869+ # This should never happen
870+ if ! all ((a21, a31, a32, b1, b2, b3, c2, c3, beta1, beta2) .≥ 0 )
871+ throw (ArgumentError (" MPRK43I requires nonnegative RK coefficients." ))
872+ end
841873 return a21, a31, a32, b1, b2, b3, c2, c3, beta1, beta2, q1, q2
842874end
843875
844876function get_constant_parameters (alg:: MPRK43II )
845- @assert 3 / 8 ≤ alg. gamma≤ 3 / 4 " MPRK43II requires 3/8 ≤ γ ≤ 3/4."
877+ if ! (3 / 8 ≤ alg. gamma ≤ 3 / 4 )
878+ throw (ArgumentError (" MPRK43II requires 3/8 ≤ γ ≤ 3/4." ))
879+ end
846880
847881 a21 = 2 * one (alg. gamma) / 3
848882 a31 = a21 - 1 / (4 * alg. gamma)
@@ -859,7 +893,10 @@ function get_constant_parameters(alg::MPRK43II)
859893 q1 = 1 / (3 * a21 * (a31 + a32) * b3)
860894 q2 = 1 / a21
861895
862- @assert all ((a21, a31, a32, b1, b2, b3, c2, c3, beta1, beta2) .≥ 0 ) " MPRK43II requires nonnegative RK coefficients."
896+ # This should never happen
897+ if ! all ((a21, a31, a32, b1, b2, b3, c2, c3, beta1, beta2) .≥ 0 )
898+ throw (ArgumentError (" MPRK43II requires nonnegative RK coefficients." ))
899+ end
863900 return a21, a31, a32, b1, b2, b3, c2, c3, beta1, beta2, q1, q2
864901end
865902
@@ -883,6 +920,9 @@ function alg_cache(alg::Union{MPRK43I, MPRK43II}, u, rate_prototype, ::Type{uElt
883920 :: Type{uBottomEltypeNoUnits} , :: Type{tTypeNoUnits} ,
884921 uprev, uprev2, f, t, dt, reltol, p, calck,
885922 :: Val{false} ) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
923+ if ! (f isa PDSFunction || f isa ConservativePDSFunction)
924+ throw (ArgumentError (" MPRK43 can only be applied to production-destruction systems" ))
925+ end
886926 a21, a31, a32, b1, b2, b3, c2, c3, beta1, beta2, q1, q2 = get_constant_parameters (alg)
887927 tab = MPRK43ConstantCache (a21, a31, a32, b1, b2, b3, c2, c3,
888928 beta1, beta2, q1, q2, floatmin (uEltypeNoUnits))
@@ -1010,6 +1050,9 @@ function alg_cache(alg::Union{MPRK43I, MPRK43II}, u, rate_prototype, ::Type{uElt
10101050 :: Type{uBottomEltypeNoUnits} , :: Type{tTypeNoUnits} ,
10111051 uprev, uprev2, f, t, dt, reltol, p, calck,
10121052 :: Val{true} ) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
1053+ if ! (f isa PDSFunction || f isa ConservativePDSFunction)
1054+ throw (ArgumentError (" MPRK43 can only be applied to production-destruction systems" ))
1055+ end
10131056 a21, a31, a32, b1, b2, b3, c2, c3, beta1, beta2, q1, q2 = get_constant_parameters (alg)
10141057 tab = MPRK43ConstantCache (a21, a31, a32, b1, b2, b3, c2, c3,
10151058 beta1, beta2, q1, q2, floatmin (uEltypeNoUnits))
0 commit comments