feos-org / feos

FeOs - A Framework for Equations of State and Classical Density Functional Theory
Other
115 stars 22 forks source link

Third Virial Coefficient of uv-BH implementation returns NaN #123

Closed anreimer closed 1 year ago

anreimer commented 1 year ago

Example in Python (as in lj_models.ipynb):

sigma = 3.7039
eps_k = 150.03
parameters = UVParameters.new_simple(12.0, 6.0, sigma, eps_k)
uvtheory_bh = EquationOfState.uvtheory(parameters, perturbation=Perturbation.BarkerHenderson)
uvtheory_bh.third_virial_coefficient(6 * KELVIN)

returns NaN m³/mol² Works for uv-B3 & uv-WCA implementation.

g-bauer commented 1 year ago

The u-fraction returns NaN. The reduced_density is zero and reduced_density.powf(a) (see here) returns NaN. Looks like this is a bug in num-dual. This can be reproduced with:

from num_dual import Dual64

Dual64.from_re(0.0)**1.0 # 0 + [0]ε
Dual64.from_re(0.0)**2.0 # 0 + [0]ε
Dual64.from_re(0.0)**1.5 # NaN + [NaN]ε
longemen3000 commented 1 year ago

Related: https://github.com/autodiff/autodiff/issues/242#issuecomment-1221992874

https://github.com/JuliaDiff/ForwardDiff.jl/issues/480

prehner commented 1 year ago

Since this seems to be caused by the uv-BH model actually not being differentiable sufficiently, there is nothing really to solve here, and I'm closing this issue.