I’m trying to solve a system of ordinary differential equations with Julia’s DifferentialEquations
method. The right-hand-side of my ODEs is wrapped Fortran 90. Here is my Julia code:
using DifferentialEquations
function rhs(dNdt,N,p,t)
ccall((:__atmos_MOD_rhs, "./EvolveAtmFort.so"), Cvoid,(Ref{Float64}, Ref{Float64},Ref{Float64}),t,N,dNdt)
end
N0 = [0.0,298.9,0.0562,22.9,0.0166,35.96,0.0,0.0,0.0,0.0]*6.022e23
tspan = [0.0,1.0e6*365.0*24.0*60.0*60.0]
prob = ODEProblem(rhs,N0,tspan)
sol = solve(prob,Rodas5());
This produces the following long error, that has to do with calculating the derivative/jacobian of the right-hand-side. Below, I only include some portions of the Stacktrace
that seem important.
MethodError: no method matching Float64(::ForwardDiff.Dual{ForwardDiff.Tag{SciMLBase.TimeGradientWrapper{ODEFunction{true,typeof(rhs),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,typeof(SciMLBase.DEFAULT_OBSERVED),Nothing},Array{Float64,1},SciMLBase.NullParameters},Float64},Float64,1})
Closest candidates are:
Float64(::Real, ::RoundingMode) where T<:AbstractFloat at rounding.jl:200
Float64(::T) where T<:Number at boot.jl:716
Float64(::Float32) at float.jl:255
...
Stacktrace:
[1] convert(::Type{Float64}, ::ForwardDiff...
[2] Base.RefValue{Float64}(::ForwardDiff.Dual{...
[3] convert(::Type{Ref{Float64}}, ::ForwardDiff....
[4] cconvert(::Type{T} where T,...
[5] rhs(::Array{ForwardDiff.Dual{ForwardDiff.Tag{SciMLBase.TimeGradientWrapper...
[6] (::ODEFunction{true,typeof(rhs),LinearAlgebra...
[7] (::SciMLBase.TimeGradientWrapper{ODEFunction{true,typeof(rhs),LinearAlgebra.UniformScaling{Bool}...
[8] derivative!(::Array{Float64,1}, ::SciMLBase.TimeGradientWrapper...
[9] calc_tderivative!(::OrdinaryDiffEq.ODEIntegrator{Rodas5...
[10] calc_rosenbrock_differentiation!...
[etc...]
When I use a jacobian-free method, like Tsit5()
, the integration works just fine. Only methods that require jacobian calculations fail. What am I doing wrong? How can I adjust my Fortran wrapper so that I can use implicit methods? Thanks! I’m using Julia 1.5.3 and DifferentialEquations