11"""
22 Derivative{DF}(dyn_fun::DF) where DF<:AbstractDynamicFunction
33
4- A wrapper for an [`AbstractDynamicFunction`](@ref) for use in referencing its derivative
5- in a model.
4+ Represent the derivative of a dynamic function with respect to its phase.
65
7- It is a sub-type of [`AbstractDynamicFunction`](@ref). It represents the derivative of
8- `dyn_fun` with respect to its phase.
6+ It is a subtype of [`AbstractDynamicFunction`](@ref).
97"""
108struct Derivative{DF<: AbstractDynamicFunction } <: AbstractDynamicFunction
119 dyn_fun:: DF
1210end
1311
14- function MOI. Utilities. _to_string(
15- :: MOI.Utilities._PrintOptions ,
16- :: MOI.ModelLike ,
17- derivative:: Derivative ,
18- )
19- return string(" Derivative(" , derivative. dyn_fun, " )" )
12+ function Base. show(io:: IO , :: MIME"text/plain" , derivative:: Derivative )
13+ io_buffer = IOBuffer()
14+ show(io_buffer, derivative. dyn_fun)
15+ output = String(take!(io_buffer))
16+ return print(io, " DOI.Derivative($(output) )" )
2017end
2118
22- function phase_index(derivative:: Derivative )
23- return phase_index(derivative. dyn_fun)
24- end
19+ phase_index(derivative:: Derivative ) = phase_index(derivative. dyn_fun)
2520
2621"""
27- ExplicitDifferentialFunction{D,F }(
28- derivative::Derivative{D} ,
29- dyn_fun::F ,
30- ) where {D <:AbstractDynamicFunction,F<:AbstractDynamicFunction}
22+ ExplicitDifferentialFunction{DF }(
23+ dyn_var::DynamicVariableIndex ,
24+ dyn_fun::DF ,
25+ ) where DF <:AbstractDynamicFunction
3126
32- An object representing the function ``t_i \\ mapsto \\ dot{y}(t_i) - f_d(y(t_i), t_i, x)``.
27+ Represent the function
28+ ``t^{(i)} \\ mapsto \\ dot{\\ boldsymbol{y}}_j(t^{(i)}) - d(\\ boldsymbol{y}_j(t^{(i)}), t^{(i)}, x)``.
3329
34- It is a sub-type of [`AbstractDynamicFunction`](@ref). The derivative (stored in the `derivative`
35- field) and the dynamic function (stored in the `dyn_fun` field) must be defined in the same
36- phase, otherwise a [`NonUniquePhaseError`](@ref) error is thrown.
30+ It is a subtype of [`AbstractDynamicFunction`](@ref).
31+ Both terms must be defined in the same phase, otherwise a [`NonUniquePhaseError`](@ref) is
32+ thrown.
3733"""
38- struct ExplicitDifferentialFunction{D<: AbstractDynamicFunction ,F<: AbstractDynamicFunction } < :
39- AbstractDynamicFunction
40- derivative:: Derivative{D}
41- dyn_fun:: F
34+ struct ExplicitDifferentialFunction{DF<: AbstractDynamicFunction } <: AbstractDynamicFunction
35+ dyn_var:: DynamicVariableIndex
36+ dyn_fun:: DF
4237
4338 function ExplicitDifferentialFunction(
44- derivative :: Derivative{D} ,
45- dyn_fun:: F ,
46- ) where {D <: AbstractDynamicFunction , F <: AbstractDynamicFunction }
47- if phase_index(derivative ) != phase_index(dyn_fun)
39+ dyn_var :: DynamicVariableIndex ,
40+ dyn_fun:: DF ,
41+ ) where {DF <: AbstractDynamicFunction }
42+ if phase_index(dyn_var ) != phase_index(dyn_fun)
4843 throw(NonUniquePhaseError(" " ))
4944 end
50- return new{D,F}(derivative , dyn_fun)
45+ return new{DF}(dyn_var , dyn_fun)
5146 end
5247end
5348
54- function MOI. Utilities. _to_string(
55- options:: MOI.Utilities._PrintOptions ,
56- model:: MOI.ModelLike ,
57- edf:: ExplicitDifferentialFunction ,
58- )
59- return string(
60- MOI. Utilities. _to_string(options, model, edf. derivative),
61- " - (" ,
62- MOI. Utilities. _to_string(options, model, edf. dyn_fun),
63- " )" ,
64- )
49+ function Base. show(io:: IO , :: MIME"text/plain" , edf:: ExplicitDifferentialFunction )
50+ io_buffer = IOBuffer()
51+ show(io_buffer, Derivative(edf. dyn_var))
52+ output = String(take!(io_buffer))
53+
54+ show(io_buffer, edf. dyn_fun)
55+ output *= " - (" * String(take!(io_buffer)) * " )"
56+
57+ return print(io, output)
6558end
6659
67- phase_index(edf:: ExplicitDifferentialFunction ) = phase_index(edf. derivative )
60+ phase_index(edf:: ExplicitDifferentialFunction ) = phase_index(edf. dyn_var )
0 commit comments