gpt4 book ai didi

使用 fortran 包装的右侧时,Julia 的 DifferentialEquations 包失败

转载 作者:行者123 更新时间:2023-12-04 01:05:33 25 4
gpt4 key购买 nike

我正在尝试使用 Julia 的 DifferentialEquations 方法求解常微分方程组。我的 ODE 的右侧被包裹 Fortran 90 .这是我的 Julia 代码:

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());

这会产生以下长错误,这与计算右侧的导数/雅可比矩阵有关。下面,我只包含一些看起来很重要的 Stacktrace 部分。

MethodError: no method matching Float64(::ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.TimeGradientWrapper{ODEFunction{true,typeof(rhs),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Float64,1},DiffEqBase.NullParameters},Float64},Float64,1})
Closest candidates are:
Float64(::Real, !Matched::RoundingMode) where T<:AbstractFloat at rounding.jl:200
Float64(::T) where T<:Number at boot.jl:715
Float64(!Matched::Int8) at float.jl:60
...

Stacktrace:
[1] convert(::Type{Float64},...
[2] Base.RefValue{Float64}...
[3] convert(::Type{Ref{Float64}}, ...
[4] cconvert(::Type{T} where T,
[5] rhs(::Array{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.TimeGradientWrapper{...
[6] (::ODEFunction{true,typeof(rhs),LinearAlgebra...
[7] (::DiffEqBase.TimeGradientWrapper{ODEFunction{true,typeof(rhs),LinearAlgebra...
[8] derivative!(::Array{Float64,1},...
[9] calc_tderivative!(::OrdinaryDiffEq...
[10] calc_rosenbrock_differentiation! at...
[etc...]

当我使用无 jacobian 方法时,如 Tsit5(),集成工作正常。只有需要雅可比计算的方法才会失败。我究竟做错了什么?如何调整我的 Fortran 包装程序以便我可以使用隐式方法?谢谢!

最佳答案

这是由于某些隐式求解器中的隐式自动微分。您需要将其关闭,即 Rodas5(autodiff=false)

关于使用 fortran 包装的右侧时,Julia 的 DifferentialEquations 包失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66594137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com