@@ -547,3 +547,92 @@ struct ODEAliasSpecifier <: AbstractAliasSpecifier
547547 end
548548 end
549549end
550+
551+ struct ImmutableODEProblem{uType, tType, isinplace, P, F, K, PT} < :
552+ AbstractODEProblem{uType, tType, isinplace}
553+ """ The ODE is `du = f(u,p,t)` for out-of-place and f(du,u,p,t) for in-place."""
554+ f:: F
555+ """ The initial condition is `u(tspan[1]) = u0`."""
556+ u0:: uType
557+ """ The solution `u(t)` will be computed for `tspan[1] ≤ t ≤ tspan[2]`."""
558+ tspan:: tType
559+ """ Constant parameters to be supplied as the second argument of `f`."""
560+ p:: P
561+ """ A callback to be applied to every solver which uses the problem."""
562+ kwargs:: K
563+ """ An internal argument for storing traits about the solving process."""
564+ problem_type:: PT
565+ @add_kwonly function ImmutableODEProblem {iip} (f:: AbstractODEFunction{iip} ,
566+ u0, tspan, p = NullParameters (),
567+ problem_type = StandardODEProblem ();
568+ kwargs... ) where {iip}
569+ _u0 = prepare_initial_state (u0)
570+ _tspan = promote_tspan (tspan)
571+ warn_paramtype (p)
572+ new{typeof (_u0), typeof (_tspan),
573+ isinplace (f), typeof (p), typeof (f),
574+ typeof (kwargs),
575+ typeof (problem_type)}(f,
576+ _u0,
577+ _tspan,
578+ p,
579+ kwargs,
580+ problem_type)
581+ end
582+
583+ """
584+ ImmutableODEProblem{isinplace}(f,u0,tspan,p=NullParameters(),callback=CallbackSet())
585+
586+ Define an ODE problem with the specified function.
587+ `isinplace` optionally sets whether the function is inplace or not.
588+ This is determined automatically, but not inferred.
589+ """
590+ function ImmutableODEProblem {iip} (f,
591+ u0,
592+ tspan,
593+ p = NullParameters ();
594+ kwargs... ) where {iip}
595+ _u0 = prepare_initial_state (u0)
596+ _tspan = promote_tspan (tspan)
597+ _f = ODEFunction {iip, DEFAULT_SPECIALIZATION} (f)
598+ ImmutableODEProblem (_f, _u0, _tspan, p; kwargs... )
599+ end
600+
601+ @add_kwonly function ImmutableODEProblem {iip, recompile} (f, u0, tspan,
602+ p = NullParameters ();
603+ kwargs... ) where {iip, recompile}
604+ ImmutableODEProblem {iip} (ODEFunction {iip, recompile} (f), u0, tspan, p; kwargs... )
605+ end
606+ end
607+
608+ """
609+ ImmutableODEProblem(f::ODEFunction,u0,tspan,p=NullParameters(),callback=CallbackSet())
610+
611+ Define an ODE problem from an [`ODEFunction`](@ref).
612+ """
613+ function ImmutableODEProblem (f:: AbstractODEFunction , u0, tspan, args... ; kwargs... )
614+ ImmutableODEProblem {isinplace(f)} (f, u0, tspan, args... ; kwargs... )
615+ end
616+
617+ function ImmutableODEProblem (f, u0, tspan, p = NullParameters (); kwargs... )
618+ iip = isinplace (f, 4 )
619+ _u0 = prepare_initial_state (u0)
620+ _tspan = promote_tspan (tspan)
621+ _f = ODEFunction {iip, DEFAULT_SPECIALIZATION} (f)
622+ ImmutableODEProblem (_f, _u0, _tspan, p; kwargs... )
623+ end
624+
625+ staticarray_itize (x) = x
626+ staticarray_itize (x:: Vector ) = StaticArraysCore. SVector {length(x)} (x)
627+ staticarray_itize (x:: StaticArraysCore.SizedVector ) = StaticArraysCore. SVector {length(x)} (x)
628+ staticarray_itize (x:: Matrix ) = StaticArraysCore. SMatrix {size(x)...} (x)
629+ staticarray_itize (x:: StaticArraysCore.SizedMatrix ) = StaticArraysCore. SMatrix {size(x)...} (x)
630+
631+ function Base. convert (:: Type{ImmutableODEProblem} , prob:: T ) where {T <: ODEProblem }
632+ ImmutableODEProblem (prob. f,
633+ staticarray_itize (prob. u0),
634+ prob. tspan,
635+ staticarray_itize (prob. p),
636+ prob. problem_type;
637+ prob. kwargs... )
638+ end
0 commit comments