How can I wrap a media package that isn’t compatible with automatic differentiation?
I need the Jacobians of density and temperature with respect to enthalpy and pressure for developing a transient heat pump simulation. Since CoolProp doesn’t accept Dual numbers, automatic differentiation can’t be used during the DE.jl solve process, and the simulation runs much slower than expected.
What’s the simplest way to handle this problem? I need easy access to R410a and humid air properties, like in CoolProp.
Thank you for sharing helpful examples. It seems that CarnotCycles.jl mainly focuses on design optimization and steady-state analysis, so it might not be ideal for cases that require frequent DE solve, Jacobian evaluations, or property calculations. I’ll take a closer look at how Clapeyron.jl serves as a replacement for CoolProp.
I’ve been very interested in Clapeyron.jl, but I haven’t been using it because I didn’t fully understand how it differs from REFPROP and CoolProp. Would it be fair to say that the relationship between CoolProp and Clapeyron.jl is similar to that between REFPROP and teqp developed by NIST?
No, there is no such relationship. Clapeyron.jl is an independent package for thermodynamic models. Amongst these models are the multiparameter EoS models from CoolProp. Clapeyron.jl is a pure Julia implementation, whereas CoolProp.jl is a wrapper to the C++ (?) CoolProp API. That is why you cannot differentiate through the CoolProp.jl models, but through the Clapeyron.jl models.
Even if you cannot AD through the library, you can define AD rules if you know how to calculate the derivative so that AD works on the library. This of course can take a good chunk of work, and for two-phase flows you have to be very careful in order to get numerical stability.
For these models, you may want to look at HVAC.jl? @avinash1 builds these kinds of models and can give more info.
It seems I should follow the derivative-writing rules for Symbolics.jl, which would involve checking the phase of the substance through conditional branching, then writing the derivatives for each phase. If you have any relevant examples or links, that would be really helpful.
If Clapeyron.jl already includes this kind of functionality and supports AD-compatible property calculations, and if CoolProp has enough EOS data for refrigerants like R410a, I could compute the derivatives for density and other properties without much effort.
Regarding HVAC.jl, I understand that it has developed an independent package tailored for Dyad, separate from Clapeyron.jl and CoolProp.jl. Is it available for academic use, and how can I access it?
Btw, you should first try to rewrite your derivatives consistently and take into account which thermodynamic variables are held constant (isothermal, isentropic, etc.). E.g. drho/dp might directly be related to the isothermal compressibility etc. Not sure if this is possible in your case.