Giter Club home page Giter Club logo

Comments (12)

pw0908 avatar pw0908 commented on June 29, 2024

Hi Andrés,
This is quite interesting; we can definitely try and implement it into our code. How quickly does this tend to converge? Have you considering using other cubics such as RK and keeping the b parameter, but relating to the existing parameters in the eos (such as sigma in SAFT)? If you can implement this with slightly more accurate cubics, it might be interesting to see if this strategy could work in the liquid phase as well (which would be amazing!).

from clapeyron.jl.

BradenDKelly avatar BradenDKelly commented on June 29, 2024

@pw0908 @longemen3000 How much have you folks played with solvers on the liquid side? For complex organic mixtures I find myself having a tough time solving for the liquid root. This could be due to simple thermodynamics - the EOS simply doesn't find a liquid root, which is fine, but on a scale of 1 to 10, how confident are you in the solvers ability to find the liquid root? I doubt I will believe anything over a 7 haha :)

from clapeyron.jl.

longemen3000 avatar longemen3000 commented on June 29, 2024

We use that volume solver everywhere, and where it failed, it was always an EoS problem (an initial point that is not in the correct vdW loop). The solver normally thows NaN when it founds a mechanical instability (dpdv > 0).it could be that our initial point for SAFT gamma Mie in your particular case is to high.

The internal iteration algorithm can be called with volume_compress(model, P, T, z;V0=x0_volume_liquid(model, T, z). You can try different values of V0 to see if the initial point is bad or the algorithm is.

Looking at our initial point for SAFT gamma Mie, it could take some improvements, maybe the assoc solver fails at the starting liquid conditions (it happened before with VRMie, and gamma Mie inherits from VRMie)

from clapeyron.jl.

pw0908 avatar pw0908 commented on June 29, 2024

Adding to what Andrés said, we also know there is a problem when additional roots appear in the eos (such as GERG-2008 or SAFT at very low temperatures). We haven't found a way to deal with these yet but we know there are strategies for it in the literature.

For your case however, I'd be curious to see what examples you have where our solvers fail? Complex organic mixtures really could mean anything; it seems that the failure of our method relies more on the conditions than the system as well.

from clapeyron.jl.

BradenDKelly avatar BradenDKelly commented on June 29, 2024

Here is a completely gutted, minimum example of the script I am running. I go through alot more molecules, as well as mixtures, but we can look at the single case of azelaic acid, which has a melting point of 109 celcius. I am calculating thermodynamic properties I find interesting. I would prefer the subcooled zone, but in this example we should be in a stable liquid zone (I don't know how accurate the GammaMie is with liquids flirting with the solid equilibria line).

using Clapeyron

A_list = [("azelaic acid", ["COOH"=>2, "CH2"=>7])]

model = SAFTgammaMie(A_list)

pad = 25
T = 109 + 273.15 + pad
P = 1e5

Z = compressibility_factor(model, P, T, [1.0]; phase=:liquid)

println(Z)

A typical error looks like this:

ERROR: LoadError: DomainError with -0.5481253908259618:
log will only return a complex result if called with a complex argument. Try log(Complex(x)).
Stacktrace:
  [1] throw_complex_domainerror(f::Symbol, x::Float64)
    @ Base.Math .\math.jl:33
  [2] log(x::Float64)
    @ Base.Math .\special\log.jl:285
  [3] log (repeats 2 times)
    @ C:\Users\bkelly\.julia\packages\ForwardDiff\PBzup\src\dual.jl:208 [inlined]
  [4] ÂHS(model::SAFTgammaMie{BasicIdeal}, V::ForwardDiff.Dual{ForwardDiff.Tag{Clapeyron.var"#647#648"{SAFTgammaMie{BasicIdeal}, Float64, Vector{Float64}}, ForwardDiff.Dual{ForwardDiff.Tag{Clapeyron.var"#f#650"{SAFTgammaMie{BasicIdeal}, Float64, Vector{Float64}}, Float64}, Float64, 1}}, ForwardDiff.Dual{ForwardDiff.Tag{Clapeyron.var"#f#650"{SAFTgammaMie{BasicIdeal}, Float64, Vector{Float64}}, Float64}, Float64, 1}, 1}, T::Float64, z::Vector{Float64})
    @ Clapeyron C:\Users\bkelly\.julia\packages\Clapeyron\li4cA\src\models\eos\SAFT\SAFTgammaMie\SAFTgammaMie.jl:72
  [5] a_mono(model::SAFTgammaMie{BasicIdeal}, V::ForwardDiff.Dual{ForwardDiff.Tag{Clapeyron.var"#647#648"{SAFTgammaMie{BasicIdeal}, Float64, Vector{Float64}}, ForwardDiff.Dual{ForwardDiff.Tag{Clapeyron.var"#f#650"{SAFTgammaMie{BasicIdeal}, Float64, Vector{Float64}}, Float64}, Float64, 1}}, ForwardDiff.Dual{ForwardDiff.Tag{Clapeyron.var"#f#650"{SAFTgammaMie{BasicIdeal}, Float64, Vector{Float64}}, Float64}, Float64, 1}, 1}, T::Float64, z::Vector{Float64})
    @ Clapeyron C:\Users\bkelly\.julia\packages\Clapeyron\li4cA\src\models\eos\SAFT\SAFTgammaMie\SAFTgammaMie.jl:47
  [6] a_res(model::SAFTgammaMie{BasicIdeal}, V::ForwardDiff.Dual{ForwardDiff.Tag{Clapeyron.var"#647#648"{SAFTgammaMie{BasicIdeal}, Float64, Vector{Float64}}, ForwardDiff.Dual{ForwardDiff.Tag{Clapeyron.var"#f#650"{SAFTgammaMie{BasicIdeal}, Float64, Vector{Float64}}, Float64}, Float64, 1}}, ForwardDiff.Dual{ForwardDiff.Tag{Clapeyron.var"#f#650"{SAFTgammaMie{BasicIdeal}, Float64, Vector{Float64}}, Float64}, Float64, 1}, 1}, T::Float64, z::Vector{Float64})
    @ Clapeyron C:\Users\bkelly\.julia\packages\Clapeyron\li4cA\src\models\eos\SAFT\SAFTgammaMie\SAFTgammaMie.jl:43
  [7] eos(model::SAFTgammaMie{BasicIdeal}, V::ForwardDiff.Dual{ForwardDiff.Tag{Clapeyron.var"#647#648"{SAFTgammaMie{BasicIdeal}, Float64, Vector{Float64}}, ForwardDiff.Dual{ForwardDiff.Tag{Clapeyron.var"#f#650"{SAFTgammaMie{BasicIdeal}, Float64, Vector{Float64}}, Float64}, Float64, 1}}, ForwardDiff.Dual{ForwardDiff.Tag{Clapeyron.var"#f#650"{SAFTgammaMie{BasicIdeal}, Float64, Vector{Float64}}, Float64}, Float64, 1}, 1}, T::Float64, z::Vector{Float64})
    @ Clapeyron C:\Users\bkelly\.julia\packages\Clapeyron\li4cA\src\models\eos.jl:25
  [8] #647
    @ C:\Users\bkelly\.julia\packages\Clapeyron\li4cA\src\methods\differentials.jl:25 [inlined]
  [9] derivative
    @ C:\Users\bkelly\.julia\packages\ForwardDiff\PBzup\src\derivative.jl:14 [inlined]
 [10] ∂f∂V(model::SAFTgammaMie{BasicIdeal}, V::ForwardDiff.Dual{ForwardDiff.Tag{Clapeyron.var"#f#650"{SAFTgammaMie{BasicIdeal}, Float64, Vector{Float64}}, Float64}, Float64, 1}, T::Float64, z::Vector{Float64})
    @ Clapeyron C:\Users\bkelly\.julia\packages\Clapeyron\li4cA\src\methods\differentials.jl:25
 [11] pressure(model::SAFTgammaMie{BasicIdeal}, V::ForwardDiff.Dual{ForwardDiff.Tag{Clapeyron.var"#f#650"{SAFTgammaMie{BasicIdeal}, Float64, Vector{Float64}}, Float64}, Float64, 1}, T::Float64, z::Vector{Float64})
    @ Clapeyron C:\Users\bkelly\.julia\packages\Clapeyron\li4cA\src\methods\VT.jl:2
 [12] f
    @ C:\Users\bkelly\.julia\packages\Clapeyron\li4cA\src\methods\differentials.jl:73 [inlined]
 [13] static_dual_eval
    @ C:\Users\bkelly\.julia\packages\ForwardDiff\PBzup\src\apiutils.jl:32 [inlined]
 [14] vector_mode_gradient!
    @ C:\Users\bkelly\.julia\packages\ForwardDiff\PBzup\src\gradient.jl:125 [inlined]
 [15] gradient!
    @ C:\Users\bkelly\.julia\packages\ForwardDiff\PBzup\src\gradient.jl:48 [inlined]
 [16] p∂p∂V(model::SAFTgammaMie{BasicIdeal}, V::Float64, T::Float64, z::Vector{Float64})
    @ Clapeyron C:\Users\bkelly\.julia\packages\Clapeyron\li4cA\src\methods\differentials.jl:75
 [17] (::Clapeyron.var"#f_fixpoint#664"{SAFTgammaMie{BasicIdeal}, Float64, Float64, Vector{Float64}})(_V::Float64)
    @ Clapeyron C:\Users\bkelly\.julia\packages\Clapeyron\li4cA\src\methods\property_solvers\volume.jl:21
 [18] _fixpoint(f::Clapeyron.var"#f_fixpoint#664"{SAFTgammaMie{BasicIdeal}, Float64, Float64, Vector{Float64}}, x0::Float64, method::Clapeyron.Solvers.SimpleFixPoint{Float64}, atol::Float64, rtol::Float64, max_iters::Int64, norm::Function, antinan::Bool)
    @ Clapeyron.Solvers C:\Users\bkelly\.julia\packages\Clapeyron\li4cA\src\solvers\fixpoint\fixpoint.jl:48
 [19] #fixpoint#22
    @ C:\Users\bkelly\.julia\packages\Clapeyron\li4cA\src\solvers\fixpoint\fixpoint.jl:33 [inlined]
 [20] volume_compress(model::SAFTgammaMie{BasicIdeal}, p::Float64, T::Float64, z::Vector{Float64}; V0::Float64, max_iters::Int64)
    @ Clapeyron C:\Users\bkelly\.julia\packages\Clapeyron\li4cA\src\methods\property_solvers\volume.jl:29
 [21] volume(model::SAFTgammaMie{BasicIdeal}, p::Float64, T::Float64, z::Vector{Float64}; phase::Symbol, threaded::Bool)
    @ Clapeyron C:\Users\bkelly\.julia\packages\Clapeyron\li4cA\src\methods\property_solvers\volume.jl:95
 [22] #chemical_potential#694
    @ C:\Users\bkelly\.julia\packages\Clapeyron\li4cA\src\methods\pT.jl:7 [inlined]
 [23] get_dG(coformer_list::Vector{Tuple{String, Vector{Pair{String, Int64}}}}, T::Float64, P::Float64)
    @ Main C:\Users\bkelly\Julia\test.jl:66
 [24] top-level scope
    @ C:\Users\bkelly\Julia\test.jl:76
in expression starting at C:\Users\bkelly\Julia\test.jl:76

It could be that I am simply asking the EOS to calculate a liquid property where it feels quite certain, there is no liquid. I don't want to infer this is the algorithms fault, I am just ...curious. If I don't force it to calculate liquid properties, it does not find the any root for me. But if I bump up pad=125, then is finds a root a Z~0.8. But, specifying either vapor or liquid, leads to the above error.

from clapeyron.jl.

pw0908 avatar pw0908 commented on June 29, 2024

What version of Clapeyron are you using? Both Andrés and I were able to run this code and get about Z=0.0055?

from clapeyron.jl.

longemen3000 avatar longemen3000 commented on June 29, 2024

cannot reproduce the error:

julia> versioninfo()
Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-4720HQ CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, haswell)

julia> using Pkg; Pkg.status("Clapeyron")
      Status `C:\Users\andres\.julia\environments\v1.7\Project.toml`
  [7c7805af] Clapeyron v0.3.4 `C:\Users\andres\.julia\dev\Clapeyron`
  
julia> Z = compressibility_factor(model, P, T, [1.0]; phase=:liquid)
0.0055271245008312875

from clapeyron.jl.

BradenDKelly avatar BradenDKelly commented on June 29, 2024

I am running Julia Version 1.6.1 (2021-04-23)

using Clapeyron version 0.2.1.

Shiza. Okay, I have 1.7.2 on a desktop and am adding Clapeyron to it. It will take awhile, VPN's are silly things, but so are hackers :S

At least I have some light to look forward too

from clapeyron.jl.

pw0908 avatar pw0908 commented on June 29, 2024

Oh boy, you have a lot to look forward to... we've made some significant speed ups to SAFT-gamma Mie specifically

from clapeyron.jl.

longemen3000 avatar longemen3000 commented on June 29, 2024

significant is an understatement on how fast SAFTgammaMie got:

julia> @btime Z = compressibility_factor(model, P, T; phase=:liquid)
  78.300 μs (69 allocations: 13.45 KiB)

the only breaking change between 0.2.x and 0.3.x is that sat_pure was renamed saturation_pressure

from clapeyron.jl.

BradenDKelly avatar BradenDKelly commented on June 29, 2024

I have puttered with Gamma Mie on my own laptop at home a bit, awhile ago, and definitely remembered it being a lot faster than what I was experiencing here haha.

I will have to respond to this tomorrow. The VPN is asking me to calm down and not bother it with importing from the outside world. I am proceeding with negotiations. VPN's are incredibly hard to bribe.

@longemen3000 when I was running it (successfully) it was taking several minutes. significant is indeed an understatement. I imagine there must have been a lot of evil allocations. MB worth, maybe even GB.

Also, the first example I gave in the script, did run for me once at pad=25 when I didn't specify phase. I am sure of it now.

from clapeyron.jl.

BradenDKelly avatar BradenDKelly commented on June 29, 2024

It purrs along really nicely now that it is running Clapeyron v0.3.4. There is still a steep precompile time, but its quick after that. Everything is different now. The properties I was calculating before, have all changed in values. They make alot more sense now.

from clapeyron.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.