About equation of state and dynamic links library #428
Replies: 3 comments 2 replies
-
Hi @Jackxi1024, The short answer is that yes you can write a wrapper that will allow Pyomo to call external function, but there are some conditions that need to be met. The first thing to note is that the Next, you function needs to return more than just the value of the property at the given state - at a minimum it needs to return the first partial derivatives of each property with respect to each state, and ideally the second partial derivatives as well. Most existing property tools do not support this behaviour, hence why IDAES has created our own tools for this. There are multiple ways to address this, notably analytical differentiation my hand, automatic differentiation tools or numerical methods, but these often involve a bit of work and have different advantages and disadvantages. Extending from the above however, the solvers we use assume that the functions of the model are twice-continuously differentiable - i.e. they are smooth in both the first and second derivatives. Phase equilibrium phenomena are notably not smooth - phases appear and disappear depending upon the state. When we wrote our external function methods, we put a lot of thought into how to handle this behaviour and smooth these transitions wherever possible. Depending on how the tool you wish to use is structured, this might be a lot of work. I will note that you can sometimes get away with non-smooth functions, but you risk having trouble converging the problem near the phase transition points. Going back to the example of the Cubic EoS in IDAES - the A better example for what you want can be found in the Helmholtz equation of state code: https://github.com/IDAES/idaes-pse/tree/main/idaes/generic_models/properties/helmholtz. In this case all the calculations for the equation of state are done in the external function, and there is only a thin Python wrapper in place to link this all to Pyomo. So, to conclude; yes it is possible, but there is a lot of work involved. |
Beta Was this translation helpful? Give feedback.
-
I want to build the PC-SATF equation, which is applicable to polymer system.
The equation is complicated. The reference paper is "Perturbed-Chain SAFT: An Equation of State Based on a
Perturbation Theory for Chain Molecules".
The equation of state has been written by someone, and the compressibility factor, residual enthalpy and fugacity can be calculated by calling the corresponding Python method. The project website is: https://github.com/zmeri/PC-SAFT
However, when I define the equation of state in idaes according to the file ceos.py,I find it difficult to call external functions
…------------------ 原始邮件 ------------------
发件人: "IDAES/idaes-pse" ***@***.***>;
发送时间: 2021年7月19日(星期一) 晚上10:27
***@***.***>;
***@***.******@***.***>;
主题: Re: [IDAES/idaes-pse] About equation of state and dynamic links library (#428)
@Jackxi1024 What is the EoS you are trying to use with IDAES? Can you post a link to a representative paper?
Building off @andrewlee94's response, I recommend considering if your EoS is either cubic or a Helmholtz-like model. If so, I would look at the current approach in IDAES for these models.
Thermodynamic modeling is often one of the most challenging aspects of equation-oriented simulation and optimization.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Beta Was this translation helpful? Give feedback.
-
Thank you very much. I'll search for related projects
…------------------ 原始邮件 ------------------
发件人: "IDAES/idaes-pse" ***@***.***>;
发送时间: 2021年7月19日(星期一) 晚上11:03
***@***.***>;
***@***.******@***.***>;
主题: Re: [IDAES/idaes-pse] About equation of state and dynamic links library (#428)
Whilst I am not very familiar with the equations of the PC_SAFT equation of state, I believe you are looking at a lot of work to get that working with IDAES. However, a group from Switzerland is already working on developing an IDAES implementation of the PC-SAFT EoS, although I am not sure how far they have gotten yet.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Beta Was this translation helpful? Give feedback.
-
Hello, I recently tried to add a new equation of state to idaes. I found a python package to calculate the compress factor, residual enthalpy and fugacity of the equation of state, but I found it difficult for pyomo to call external python functions. Moreover, due to the complexity of the equation of state, I can't write explicit expressions for compressibility factor, residual enthalpy and fugacity (they can be expressed by Constraints of pyomo)
Later, I saw the dynamic link library file "cubic_roots.so" in the cubic equation of state file "ceos. py". You use this external file to calculate the compressibility factor of the gas or liquid phase. This makes me very inspired. It seems that pyomo will dynamically call this dynamic link library when solving the model
Therefore, I'm wondering whether I can make the external function as a dynamic link library and return it to equation of state
of idaes. More in detail, when solving the flash model, I need the fugacity of the gas-liquid components, and I can dynamically get a value by calling the dynamic link library
I hope you can provide some suggestions about this DLL. Thank you very much
Beta Was this translation helpful? Give feedback.
All reactions