@@ -2094,6 +2094,109 @@ struct MultiObjectiveOptimizationFunction{
20942094 initialization_data:: ID
20952095end
20962096
2097+ """
2098+ $(TYPEDEF)
2099+ """
2100+ abstract type AbstractControlFunction{iip} <: AbstractDiffEqFunction{iip} end
2101+
2102+ @doc doc"""
2103+ $(TYPEDEF)
2104+
2105+ A representation of a optimal control function `f`, defined by:
2106+
2107+ ```math
2108+ \f rac{dx}{dt} = f(x, u, p, t)
2109+ ```
2110+ where `x` are the states of the system and `u` are the inputs (or control variables).
2111+
2112+ and all of its related functions, such as the Jacobian of `f`, its gradient
2113+ with respect to time, and more. For all cases, `u0` is the initial condition,
2114+ `p` are the parameters, and `t` is the independent variable.
2115+
2116+ ```julia
2117+ ControlFunction{iip, specialize}(f;
2118+ mass_matrix = __has_mass_matrix(f) ? f.mass_matrix : I,
2119+ analytic = __has_analytic(f) ? f.analytic : nothing,
2120+ tgrad= __has_tgrad(f) ? f.tgrad : nothing,
2121+ jac = __has_jac(f) ? f.jac : nothing,
2122+ control_jac = __has_controljac(f) ? f.controljac : nothing,
2123+ jvp = __has_jvp(f) ? f.jvp : nothing,
2124+ vjp = __has_vjp(f) ? f.vjp : nothing,
2125+ jac_prototype = __has_jac_prototype(f) ? f.jac_prototype : nothing,
2126+ controljac_prototype = __has_controljac_prototype(f) ? f.controljac_prototype : nothing,
2127+ sparsity = __has_sparsity(f) ? f.sparsity : jac_prototype,
2128+ paramjac = __has_paramjac(f) ? f.paramjac : nothing,
2129+ syms = nothing,
2130+ indepsym = nothing,
2131+ paramsyms = nothing,
2132+ colorvec = __has_colorvec(f) ? f.colorvec : nothing,
2133+ sys = __has_sys(f) ? f.sys : nothing)
2134+ ```
2135+
2136+ `f` should be given as `f(x_out,x,u,p,t)` or `out = f(x,u,p,t)`.
2137+ See the section on `iip` for more details on in-place vs out-of-place handling.
2138+
2139+ - `mass_matrix`: the mass matrix `M` represented in the BVP function. Can be used
2140+ to determine that the equation is actually a BVP for differential algebraic equation (DAE)
2141+ if `M` is singular.
2142+ - `jac(J,dx,x,p,gamma,t)` or `J=jac(dx,x,p,gamma,t)`: returns ``\f rac{df}{dx}``
2143+ - `control_jac(J,du,u,p,gamma,t)` or `J=control_jac(du,u,p,gamma,t)`: returns ``\f rac{df}{du}``
2144+ - `jvp(Jv,v,du,u,p,gamma,t)` or `Jv=jvp(v,du,u,p,gamma,t)`: returns the directional
2145+ derivative ``\f rac{df}{du} v``
2146+ - `vjp(Jv,v,du,u,p,gamma,t)` or `Jv=vjp(v,du,u,p,gamma,t)`: returns the adjoint
2147+ derivative ``\f rac{df}{du}^\a st v``
2148+ - `jac_prototype`: a prototype matrix matching the type that matches the Jacobian. For example,
2149+ if the Jacobian is tridiagonal, then an appropriately sized `Tridiagonal` matrix can be used
2150+ as the prototype and integrators will specialize on this structure where possible. Non-structured
2151+ sparsity patterns should use a `SparseMatrixCSC` with a correct sparsity pattern for the Jacobian.
2152+ The default is `nothing`, which means a dense Jacobian.
2153+ - `controljac_prototype`: a prototype matrix matching the type that matches the Jacobian. For example,
2154+ if the Jacobian is tridiagonal, then an appropriately sized `Tridiagonal` matrix can be used
2155+ as the prototype and integrators will specialize on this structure where possible. Non-structured
2156+ sparsity patterns should use a `SparseMatrixCSC` with a correct sparsity pattern for the Jacobian.
2157+ The default is `nothing`, which means a dense Jacobian.
2158+ - `paramjac(pJ,u,p,t)`: returns the parameter Jacobian ``\f rac{df}{dp}``.
2159+ - `colorvec`: a color vector according to the SparseDiffTools.jl definition for the sparsity
2160+ pattern of the `jac_prototype`. This specializes the Jacobian construction when using
2161+ finite differences and automatic differentiation to be computed in an accelerated manner
2162+ based on the sparsity pattern. Defaults to `nothing`, which means a color vector will be
2163+ internally computed on demand when required. The cost of this operation is highly dependent
2164+ on the sparsity pattern.
2165+
2166+ ## iip: In-Place vs Out-Of-Place
2167+
2168+ For more details on this argument, see the ODEFunction documentation.
2169+
2170+ ## specialize: Controlling Compilation and Specialization
2171+
2172+ For more details on this argument, see the ODEFunction documentation.
2173+
2174+ ## Fields
2175+ #
2176+ The fields of the ControlFunction type directly match the names of the inputs.
2177+ """
2178+ struct ControlFunction{iip, specialize, F, TMM, Ta, Tt, TJ, CTJ, JVP, VJP,
2179+ JP, CJP, SP, TPJ, O, TCV, CTCV,
2180+ SYS, ID} <: AbstractControlFunction{iip}
2181+ f:: F
2182+ mass_matrix:: TMM
2183+ analytic:: Ta
2184+ tgrad:: Tt
2185+ jac:: TJ
2186+ controljac:: CTJ
2187+ jvp:: JVP
2188+ vjp:: VJP
2189+ jac_prototype:: JP
2190+ controljac_prototype:: CJP
2191+ sparsity:: SP
2192+ paramjac:: TPJ
2193+ observed:: O
2194+ colorvec:: TCV
2195+ controlcolorvec:: CTCV
2196+ sys:: SYS
2197+ initialization_data:: ID
2198+ end
2199+
20972200"""
20982201$(TYPEDEF)
20992202"""
0 commit comments