equinor / neqsim-python

NeqSim is a library for calculation of fluid behavior, phase equilibrium and process simulation. This project is a Python interface to NeqSim.
https://equinor.github.io/neqsimhome/
Apache License 2.0
58 stars 15 forks source link

ERROR neqsim.thermo.phase.PhaseEos - Fails with pseudo components #267

Closed sface-admin closed 2 months ago

sface-admin commented 5 months ago

This is an extension of previously raised issue #241 I get similar error for another gas composition, where all components are non zero. Notice that error starts with addition of C7 pseudo onwards. See the script below,

fluid1 = fluid("srk") fluid1.setTemperature(40, "C") fluid1.setPressure(50, "bara") fluid1.addComponent("nitrogen", 0.88) fluid1.addComponent("CO2", 5.7) fluid1.addComponent("methane", 86.89) fluid1.addComponent("ethane", 3.59) fluid1.addComponent("propane", 1.25) fluid1.addComponent("i-butane", 0.19) fluid1.addComponent("n-butane", 0.35) fluid1.addComponent("i-pentane", 0.12) fluid1.addComponent("n-pentane", 0.12) fluid1.addTBPfraction("C6", 0.15, 86/1000.0, 0.672) fluid1.addTBPfraction("C7", 0.2, 96/1000.0, 0.737) fluid1.addTBPfraction("C8", 0.22, 106/1000.0, 0.767) fluid1.addTBPfraction("C9", 0.13, 121/1000.0, 0.783) fluid1.addPlusFraction("C10+", 0.21, 172/1000.0, 0.818) fluid1.setMixingRule("classic") fluid1.setMultiPhaseCheck(True) fluid1.useVolumeCorrection(True) initPhysicalProperties() thermoOps = jNeqSim.thermodynamicOperations.ThermodynamicOperations(fluid1) thermoOps.calcPTphaseEnvelope() plt.plot(list(thermoOps.getOperation().get("dewT")), list(thermoOps.getOperation().get("dewP")), label="DewPoint") plt.plot(list(thermoOps.getOperation().get("bubT")), list(thermoOps.getOperation().get("bubP")), label="BubblePoint") plt.show()

EvenSol commented 5 months ago

Thanks again for reporting this. However I have problems to reproduce the error. The follwing script work fine on my computer:


from neqsim.thermo import fluid
from neqsim import jNeqSim
import matplotlib.pyplot as plt 
fluid1 = fluid("srk")
fluid1.setTemperature(40, "C")
fluid1.setPressure(50, "bara")
fluid1.addComponent("nitrogen", 0.88)
fluid1.addComponent("CO2", 5.7)
fluid1.addComponent("methane", 86.89)
fluid1.addComponent("ethane", 3.59)
fluid1.addComponent("propane", 1.25)
fluid1.addComponent("i-butane", 0.19)
fluid1.addComponent("n-butane", 0.35)
fluid1.addComponent("i-pentane", 0.12)
fluid1.addComponent("n-pentane", 0.12)
fluid1.addTBPfraction("C6", 0.15, 86/1000.0, 0.672)
fluid1.addTBPfraction("C7", 0.2, 96/1000.0, 0.737)
fluid1.addTBPfraction("C8", 0.22, 106/1000.0, 0.767)
fluid1.addTBPfraction("C9", 0.13, 121/1000.0, 0.783)
fluid1.addPlusFraction("C10+", 0.21, 172/1000.0, 0.818)
fluid1.setMixingRule("classic")
fluid1.setMultiPhaseCheck(True)
fluid1.useVolumeCorrection(True)

thermoOps = jNeqSim.thermodynamicOperations.ThermodynamicOperations(fluid1)
thermoOps.calcPTphaseEnvelope()
plt.plot(list(thermoOps.getOperation().get("dewT2")), list(thermoOps.getOperation().get("dewP2")), label="DewPoint")
plt.plot(list(thermoOps.getOperation().get("bubT2")), list(thermoOps.getOperation().get("bubP2")), label="BubblePoint")
plt.show()
sface-admin commented 2 months ago

Hi Even. Thanks for checking it. However I keep getting this error. Looks like it is dependent on the machine configuration then. I am running python 3.10.11 on windows10, Eclipse Temurin JDK 21.0.3+9 and Neqsim 2.5.31. Please let me know the type of machine on which you have tested this code. Thanks.

EvenSol commented 2 months ago

Hi - can you try to upgrade to the new version of neqsim (2.5.32) and see if that helps? We have modified the phase envelope algorithm a bit, and hope it can solve some of the problems.

The new algorithm is called using: thermoOps = jNeqSim.thermodynamicOperations.ThermodynamicOperations(fluid0_HC) thermoOps.calcPTphaseEnvelope2()

Some examples can be seen here: https://colab.research.google.com/drive/1tuSXN5Myk97SSxxJJ21vo4G8lwILT9K2?usp=sharing

EvenSol commented 2 months ago

I run the following script with no problems on my local computer (Win10, Python 3.11.6, OpenJDK Runtime Environment Temurin-21.0.2+13 (build 21.0.2+13-LTS) OpenJDK 64-Bit Server VM Temurin-21.0.2+13 (build 21.0.2+13-LTS, mixed mode, sharing). The script runs fine giving the following output.

from neqsim.thermo import fluid
from neqsim import jNeqSim
import matplotlib.pyplot as plt 
fluid1 = fluid("srk")
fluid1.setTemperature(40, "C")
fluid1.setPressure(50, "bara")
fluid1.addComponent("nitrogen", 0.88)
fluid1.addComponent("CO2", 5.7)
fluid1.addComponent("methane", 86.89)
fluid1.addComponent("ethane", 3.59)
fluid1.addComponent("propane", 1.25)
fluid1.addComponent("i-butane", 0.19)
fluid1.addComponent("n-butane", 0.35)
fluid1.addComponent("i-pentane", 0.12)
fluid1.addComponent("n-pentane", 0.12)
fluid1.addTBPfraction("C6", 0.15, 86/1000.0, 0.672)
fluid1.addTBPfraction("C7", 0.2, 96/1000.0, 0.737)
fluid1.addTBPfraction("C8", 0.22, 106/1000.0, 0.767)
fluid1.addTBPfraction("C9", 0.13, 121/1000.0, 0.783)
fluid1.addPlusFraction("C10+", 0.21, 172/1000.0, 0.818)
fluid1.setMixingRule("classic")
fluid1.setMultiPhaseCheck(True)
fluid1.useVolumeCorrection(True)

thermoOps = jNeqSim.thermodynamicOperations.ThermodynamicOperations(fluid1)
thermoOps.calcPTphaseEnvelope2()
plt.plot(list(thermoOps.getOperation().get("dewT")), list(thermoOps.getOperation().get("dewP")), label="DewPoint")
plt.plot(list(thermoOps.getOperation().get("bubT")), list(thermoOps.getOperation().get("bubP")), label="BubblePoint")
plt.show()

image

sface-admin commented 2 months ago

Hi Even. I have now upgraded to newer version and the new algorithm is able to generate the bubble pressures. I am now getting exactly the same curve as you have got it. However, the error still appears, which is - "[main] ERROR neqsim.thermo.phase.PhaseEos - PhaseSrkEos:molarVolume - Variable Molar volume is NaN". May be it is because, the bubble pressure algorithm is not able to converge in the intermediate points. Thanks again for your help.

EvenSol commented 2 months ago

Hi Even. I have now upgraded to newer version and the new algorithm is able to generate the bubble pressures. I am now getting exactly the same curve as you have got it. However, the error still appears, which is - "[main] ERROR neqsim.thermo.phase.PhaseEos - PhaseSrkEos:molarVolume - Variable Molar volume is NaN". May be it is because, the bubble pressure algorithm is not able to converge in the intermediate points. Thanks again for your help.

Great that it works. Yes, this error comes if the algorithm is failing in solving the volume root of the EoS. This is intedend and ok. However, I though this output was supressed when using neqsim in Python (log4j is configured not to log messages from Java when using neqsim from Python). Maybe you have some other log4j config file that is turning on logging.