You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am not familiar with dual number, by google what it is, I think it is used when automatically differentiating the objective function. Therefore, I tried another solution in the FAQ, which is to specify the autodiff to be AutoFiniteDiff() (using the RobustMultiNewton() solver). The revised code is as MRE 2, but it yields the same error message, complaining about the dual number usage in PropsSI(). I find a similar issue being reported #360 , but in my case, using TrustRegion() still does not resolve the problem (See MRE 3).
My questions are:
Should the PropsSI() function in the CoolProp package be modified to accept a dual number as an argument?
Why does the AutoFiniteDiff() still yield the error about dual number? I expect this error only happens when automatic differentiation is used.
Expected behavior
The equation can be solved successfully when specifying autodiff = AutoFiniteDiff()
Minimal Reproducible Example 1 (not specifying autodiff = AutoFiniteDiff())👇
using NonlinearSolve, CoolProp
functionmyfun_P_MWE(p, (T, init_m))
r_cont_ads =10e-3
r_ads_heat =2.5e-3
L =0.5
row_GGHS =3
row_cont =3
row_ads =10
delta_r_ads = (r_cont_ads - r_ads_heat) / row_ads
rho_fre =zeros(typeof(p), row_ads)
for i ineachindex(rho_fre)
# Obtain the density of nitrogen according to temperature and pressure
rho_fre[i] =PropsSI("D", "T", T[row_GGHS+row_cont+i], "P", p, "nitrogen")
end# Construct the nonlinear equation
f =0.0for i ineachindex(rho_fre)
f = f + rho_fre[i] * ((r_cont_ads - (i -1) * delta_r_ads)^2- (r_cont_ads - i * delta_r_ads)^2) /2* L
endreturn f - init_m
end# Solving the equation
T =collect(range(200.0, 500.0, 19))
p =1e5
init_m =2e-4# myfun_P_MWE(p,(T, init_m))
p_new =solve(
NonlinearProblem(myfun_P_MWE, p, (T, init_m))
# RobustMultiNewton(; autodiff=AutoFiniteDiff())
).u
Minimal Reproducible Example 2 (using RobustMultiNewton() with autodiff = AutoFiniteDiff())👇
using NonlinearSolve, CoolProp
functionmyfun_P_MWE(p, (T, init_m))
r_cont_ads =10e-3
r_ads_heat =2.5e-3
L =0.5
row_GGHS =3
row_cont =3
row_ads =10
delta_r_ads = (r_cont_ads - r_ads_heat) / row_ads
rho_fre =zeros(typeof(p), row_ads)
for i ineachindex(rho_fre)
# Obtain the density of nitrogen according to temperature and pressure
rho_fre[i] =PropsSI("D", "T", T[row_GGHS+row_cont+i], "P", p, "nitrogen")
end# Construct the nonlinear equation
f =0.0for i ineachindex(rho_fre)
f = f + rho_fre[i] * ((r_cont_ads - (i -1) * delta_r_ads)^2- (r_cont_ads - i * delta_r_ads)^2) /2* L
endreturn f - init_m
end# Solving the equation
T =collect(range(200.0, 500.0, 19))
p =1e5
init_m =2e-4# myfun_P_MWE(p,(T, init_m))
p_new =solve(
NonlinearProblem(myfun_P_MWE, p, (T, init_m)),
RobustMultiNewton(; autodiff=AutoFiniteDiff())
).u
Minimal Reproducible Example 3 (using TrustRegion() with autodiff = AutoFiniteDiff())👇
using NonlinearSolve, CoolProp
functionmyfun_P_MWE(p, (T, init_m))
r_cont_ads =10e-3
r_ads_heat =2.5e-3
L =0.5
row_GGHS =3
row_cont =3
row_ads =10
delta_r_ads = (r_cont_ads - r_ads_heat) / row_ads
rho_fre =zeros(typeof(p), row_ads)
for i ineachindex(rho_fre)
# Obtain the density of nitrogen according to temperature and pressure
rho_fre[i] =PropsSI("D", "T", T[row_GGHS+row_cont+i], "P", p, "nitrogen")
end# Construct the nonlinear equation
f =0.0for i ineachindex(rho_fre)
f = f + rho_fre[i] * ((r_cont_ads - (i -1) * delta_r_ads)^2- (r_cont_ads - i * delta_r_ads)^2) /2* L
endreturn f - init_m
end# Solving the equation
T =collect(range(200.0, 500.0, 19))
p =1e5
init_m =2e-4# myfun_P_MWE(p,(T, init_m))
p_new =solve(
NonlinearProblem(myfun_P_MWE, p, (T, init_m)),
# RobustMultiNewton(; autodiff=AutoFiniteDiff())TrustRegion(autodiff=AutoFiniteDiff(), radius_update_scheme=RadiusUpdateSchemes.Bastin)
).u
EDIT: This issue has been posted in the julia forum.
Describe the bug 🐞
I am trying to solve a nonlinear equation, which is constructed using the thermophysical properties of fluids via CoolProp package (See MRE 1). The error message seems to indicate that
PropsSI()
cannot accept a dual number as an argument. Following the FAQ: The solver tried to set a Dual Number in my Vector of Floats. How do I fix that? in the NonlinearSolve.jl documentation, I have initialized therho_fre
with the same element type asp
, but that doesn’t help.I am not familiar with dual number, by google what it is, I think it is used when automatically differentiating the objective function. Therefore, I tried another solution in the FAQ, which is to specify the
autodiff
to beAutoFiniteDiff()
(using theRobustMultiNewton()
solver). The revised code is as MRE 2, but it yields the same error message, complaining about the dual number usage inPropsSI()
. I find a similar issue being reported #360 , but in my case, usingTrustRegion()
still does not resolve the problem (See MRE 3).My questions are:
Should the
PropsSI()
function in the CoolProp package be modified to accept a dual number as an argument?Why does the
AutoFiniteDiff()
still yield the error about dual number? I expect this error only happens when automatic differentiation is used.Expected behavior
The equation can be solved successfully when specifying
autodiff = AutoFiniteDiff()
Minimal Reproducible Example 1 (not specifying
autodiff = AutoFiniteDiff()
)👇Error & Stacktrace 1⚠️
Minimal Reproducible Example 2 (using
RobustMultiNewton()
withautodiff = AutoFiniteDiff()
)👇Error & Stacktrace 2⚠️
Minimal Reproducible Example 3 (using
TrustRegion()
withautodiff = AutoFiniteDiff()
)👇Error & Stacktrace 3⚠️
Environment (please complete the following information):
using Pkg; Pkg.status()
using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
versioninfo()
The text was updated successfully, but these errors were encountered: