-
-
Notifications
You must be signed in to change notification settings - Fork 107
SecondOrderDDEProblem (and underlying DynamicalDDEProblem) #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,27 @@ struct DDEFunction{iip,F,TMM,Ta,Tt,TJ,JVP,VJP,JP,SP,TW,TWt,TPJ,S,TCV} <: Abstrac | |
colorvec::TCV | ||
end | ||
|
||
""" | ||
$(TYPEDEF) | ||
""" | ||
struct DynamicalDDEFunction{iip,F1,F2,TMM,Ta,Tt,TJ,JVP,VJP,JP,SP,TW,TWt,TPJ,S,TCV} <: AbstractDDEFunction{iip} | ||
f1::F1 | ||
f2::F2 | ||
mass_matrix::TMM | ||
analytic::Ta | ||
tgrad::Tt | ||
jac::TJ | ||
jvp::JVP | ||
vjp::VJP | ||
jac_prototype::JP | ||
sparsity::SP | ||
Wfact::TW | ||
Wfact_t::TWt | ||
paramjac::TPJ | ||
syms::S | ||
colorvec::TCV | ||
end | ||
|
||
""" | ||
$(TYPEDEF) | ||
""" | ||
|
@@ -322,6 +343,21 @@ end | |
(f::DDEFunction)(args...) = f.f(args...) | ||
(f::DDEFunction)(::Type{Val{:analytic}},args...) = f.analytic(args...) | ||
|
||
function (f::DynamicalDDEFunction)(u,h,p,t) | ||
ArrayPartition(f.f1(u.x[1],u.x[2],h,p,t),f.f2(u.x[1],u.x[2],h,p,t)) | ||
end | ||
function (f::DynamicalDDEFunction)(du,u,h,p,t) | ||
f.f1(du.x[1],u.x[1],u.x[2],h,p,t) | ||
f.f2(du.x[2],u.x[1],u.x[2],h,p,t) | ||
end | ||
function Base.getproperty(f::DynamicalDDEFunction, name::Symbol) | ||
if name === :f | ||
# Use the f property as an alias for calling the function itself, so DynamicalDDEFunction fits the same interface as DDEFunction as expected by the ODEFunctionWrapper in DelayDiffEq.jl. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See SciML/DelayDiffEq.jl#203: this is so that |
||
return f | ||
end | ||
return getfield(f, name) | ||
end | ||
|
||
(f::SDEFunction)(args...) = f.f(args...) | ||
(f::SDEFunction)(::Type{Val{:analytic}},args...) = f.analytic(args...) | ||
(f::SDEFunction)(::Type{Val{:tgrad}},args...) = f.tgrad(args...) | ||
|
@@ -933,6 +969,63 @@ DDEFunction{iip}(f::DDEFunction; kwargs...) where iip = f | |
DDEFunction(f; kwargs...) = DDEFunction{isinplace(f, 5),RECOMPILE_BY_DEFAULT}(f; kwargs...) | ||
DDEFunction(f::DDEFunction; kwargs...) = f | ||
|
||
@add_kwonly function DynamicalDDEFunction{iip}(f1,f2,mass_matrix,analytic,tgrad,jac,jvp,vjp, | ||
jac_prototype,sparsity,Wfact,Wfact_t,paramjac, | ||
syms,colorvec) where iip | ||
f1 = typeof(f1) <: AbstractDiffEqOperator ? f1 : DDEFunction(f1) | ||
f2 = DDEFunction(f2) | ||
DynamicalDDEFunction{isinplace(f2),typeof(f1),typeof(f2),typeof(mass_matrix), | ||
typeof(analytic),typeof(tgrad),typeof(jac),typeof(jvp),typeof(vjp), | ||
typeof(jac_prototype), | ||
typeof(Wfact),typeof(Wfact_t),typeof(paramjac),typeof(syms), | ||
typeof(colorvec)}(f1,f2,mass_matrix,analytic,tgrad,jac,jvp,vjp, | ||
jac_prototype,sparsity,Wfact,Wfact_t,paramjac,syms,colorvec) | ||
end | ||
function DynamicalDDEFunction{iip,true}(f1,f2;mass_matrix=I, | ||
analytic=nothing, | ||
tgrad=nothing, | ||
jac=nothing, | ||
jvp=nothing, | ||
vjp=nothing, | ||
jac_prototype=nothing, | ||
sparsity=jac_prototype, | ||
Wfact=nothing, | ||
Wfact_t=nothing, | ||
paramjac = nothing, | ||
syms = nothing, | ||
colorvec = nothing) where iip | ||
DynamicalDDEFunction{iip,typeof(f1),typeof(f2),typeof(mass_matrix), | ||
typeof(analytic), | ||
typeof(tgrad),typeof(jac),typeof(jvp),typeof(vjp),typeof(jac_prototype),typeof(sparsity), | ||
typeof(Wfact),typeof(Wfact_t),typeof(paramjac),typeof(syms), | ||
typeof(colorvec)}( | ||
f1,f2,mass_matrix,analytic,tgrad,jac,jvp,vjp,jac_prototype,sparsity, | ||
Wfact,Wfact_t,paramjac,syms,colorvec) | ||
end | ||
function DynamicalDDEFunction{iip,false}(f1,f2;mass_matrix=I, | ||
analytic=nothing, | ||
tgrad=nothing, | ||
jac=nothing, | ||
jvp=nothing, | ||
vjp=nothing, | ||
jac_prototype=nothing, | ||
sparsity=jac_prototype, | ||
Wfact=nothing, | ||
Wfact_t=nothing, | ||
paramjac = nothing, | ||
syms = nothing, | ||
colorvec = nothing) where iip | ||
DynamicalDDEFunction{iip,Any,Any,Any,Any,Any,Any,Any, | ||
Any,Any,Any,Any,Any}( | ||
f1,f2,mass_matrix,analytic,tgrad, | ||
jac,jvp,vjp,jac_prototype,sparsity, | ||
Wfact,Wfact_t,paramjac,syms,colorvec) | ||
end | ||
DynamicalDDEFunction(f1,f2=nothing; kwargs...) = DynamicalDDEFunction{isinplace(f1, 6)}(f1, f2; kwargs...) | ||
DynamicalDDEFunction{iip}(f1,f2; kwargs...) where iip = | ||
DynamicalDDEFunction{iip,RECOMPILE_BY_DEFAULT}(DDEFunction{iip}(f1), DDEFunction{iip}(f2); kwargs...) | ||
DynamicalDDEFunction(f::DynamicalDDEFunction; kwargs...) = f | ||
|
||
function SDDEFunction{iip,true}(f,g; | ||
mass_matrix=I, | ||
analytic=nothing, | ||
|
@@ -1135,14 +1228,14 @@ has_Wfact_t(f::Union{SplitFunction,SplitSDEFunction}) = has_Wfact_t(f.f1) | |
has_paramjac(f::Union{SplitFunction,SplitSDEFunction}) = has_paramjac(f.f1) | ||
has_colorvec(f::Union{SplitFunction,SplitSDEFunction}) = has_colorvec(f.f1) | ||
|
||
has_jac(f::DynamicalODEFunction) = has_jac(f.f1) | ||
has_jvp(f::DynamicalODEFunction) = has_jvp(f.f1) | ||
has_vjp(f::DynamicalODEFunction) = has_vjp(f.f1) | ||
has_tgrad(f::DynamicalODEFunction) = has_tgrad(f.f1) | ||
has_Wfact(f::DynamicalODEFunction) = has_Wfact(f.f1) | ||
has_Wfact_t(f::DynamicalODEFunction) = has_Wfact_t(f.f1) | ||
has_paramjac(f::DynamicalODEFunction) = has_paramjac(f.f1) | ||
has_colorvec(f::DynamicalODEFunction) = has_colorvec(f.f1) | ||
has_jac(f::Union{DynamicalODEFunction,DynamicalDDEFunction}) = has_jac(f.f1) | ||
has_jvp(f::Union{DynamicalODEFunction,DynamicalDDEFunction}) = has_jvp(f.f1) | ||
has_vjp(f::Union{DynamicalODEFunction,DynamicalDDEFunction}) = has_vjp(f.f1) | ||
has_tgrad(f::Union{DynamicalODEFunction,DynamicalDDEFunction}) = has_tgrad(f.f1) | ||
has_Wfact(f::Union{DynamicalODEFunction,DynamicalDDEFunction}) = has_Wfact(f.f1) | ||
has_Wfact_t(f::Union{DynamicalODEFunction,DynamicalDDEFunction}) = has_Wfact_t(f.f1) | ||
has_paramjac(f::Union{DynamicalODEFunction,DynamicalDDEFunction}) = has_paramjac(f.f1) | ||
has_colorvec(f::Union{DynamicalODEFunction,DynamicalDDEFunction}) = has_colorvec(f.f1) | ||
|
||
has_jac(f::Union{UDerivativeWrapper,UJacobianWrapper}) = has_jac(f.f) | ||
has_jvp(f::Union{UDerivativeWrapper,UJacobianWrapper}) = has_jvp(f.f) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Varargs are used here so the optional
v0
,u0
initial conditions can be handled by dispatch by the two constructors above, and the code doesn't have to be repeated for any of the following constructors.f1
andf2
's types are specified to beFunction
so that the constructor doesn't just pull out the first 2 arguments of and try to pass on the rest, which would result in more confusing dispatch errors down the line if an incorrect call is made.