CalebBell / thermo

Thermodynamics and Phase Equilibrium component of Chemical Engineering Design Library (ChEDL)
MIT License
594 stars 114 forks source link

Fix RuntimeWarning #54

Closed YifeiLu closed 3 years ago

YifeiLu commented 3 years ago

"runtimewarning: invalid value encountered in double_scalars" caused by python calculation order, for example:

-27(1/3) returns -3.0 but (-27)(1/3) returns (1.5000000000000004+2.598076211353316j)

coveralls commented 3 years ago

Coverage Status

Coverage decreased (-0.005%) to 88.847% when pulling 693193f75e318745313a505b93273093da9748ab on YifeiLu:master into 9f4175a9bcebc450baeba0b4f62398686a804c27 on CalebBell:master.

CalebBell commented 3 years ago

Hi Yifei,

That's an interesting suggestion. I am not quite sure what you are suggesting - this correlation is for a sub-critical liquid; it doesn't make sense to use it when T is larger than Tc.

Changing an equation so it provides new answers in a region it was not designed for is always hard. The approach I had planned was to truncate T to Tc; avoiding the numerical issue. Do you have a plot of what the new results look like?

Sincerely, Caleb

YifeiLu commented 3 years ago

Hi Caleb,

First of all thanks a lot for this tool, it really helps me a lot! For this commit I'm not suggesting anything related to the calculation method or thermodynamics, but to fix some warning caused by python. I always get the "runtimewarning" when I run my own code. Therefore I checked the code a little bit and found this problem. This shouldn't affect the result at all as I understood, it's just a reformatting of the code to avoid such warnings. I'm actually using thermo to calculate gas properties, but I still got these warnings. FYI, I used thermo to calculate the following gas mixture with a temperature of 288.15K and pressure ranges from 50 to 70 bar.

gas_comp = OrderedDict([('methane', 0.96522), ('nitrogen', 0.00259), ('carbon dioxide', 0.00596), ('ethane', 0.01819), ('propane', 0.0046), ('isobutane', 0.00098), ('butane', 0.00101), ('2-methylbutane', 0.00047), ('pentane', 0.00032), ('hexane', 0.00066)])

On Thu, Jul 16, 2020 at 1:58 AM Caleb Bell notifications@github.com wrote:

Hi Yifei,

That's an interesting suggestion. I am not quite sure what you are suggesting - this correlation is for a sub-critical liquid; it doesn't make sense to use it when T is larger than Tc.

Changing an equation so it provides new answers in a region it was not designed for is always hard. The approach I had planned was to truncate T to Tc; avoiding the numerical issue. Do you have a plot of what the new results look like?

Sincerely, Caleb

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/CalebBell/thermo/pull/54#issuecomment-659075600, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC5CR7EY66DLTXDAERORT53R3Y7DXANCNFSM4O3ACVJQ .

CalebBell commented 3 years ago

Closing, this change made its way into the chemicals library, which thermo now uses.