Comments (3)
Hi @yoelcortes,
Thank you as always for the quick answer and in-depth explanation. I understand that throwing errors or warnings in _chemical.Tsat
is undesirable because it would break existing functionality or at least affect performance. However, I think that in-experienced users like me should be warned when they use _chemical.Tsat
for their own purpose and the returned result is wrong. I would like to propose a solution, which should satisfy both demands:
Throwing an error is switched on per default (such that users will encounter an error when using _chemical.Tsat
directly), but the error is suppressed when_chemical.Tsat
is used internally in thermosteam (such that performance and overhead of internal functions like VLE are not affected):
def Tsat(self, P, Tguess=None, Tmin=None, Tmax=None, check=True): # checking the result is turned on by default
...
if y0 < 0. < y1:
T = IQ_interpolation(lambda T: Psat(T) - P,
Tmin, Tmax, y0, y1,
Tguess, 1e-6, 1e-2, checkroot=False)
else:
T = aitken_secant(lambda T: Psat(T) - P,
Tmin, Tmax, 1e-6, 1e-2, checkroot=False)
# check result before returning
if check is True:
if T > Tmax or T < Tmin:
raise ValueError("...")
return T
Internal use suppresses the check actively, e.g. in equilibrium.vle.VLE
:
...
def _set_PV_chemical(self, P, V):
# Set vapor fraction
self._T = self._thermal_condition.T = self._chemical.Tsat(P, check=False) # check switched off
...
What do you think?
from thermosteam.
Hi Ben,
I'm happy to see you post issues and glad to see you actively using the software. The reason why Tsat
does not throw an error is because Psat
allows for extrapolation. All TDependentProperty objects (including Psat) are from the Caleb's thermo. You can avoid extrapolation of Psat by setting <Chemical>.Psat.extrapolation = None
. For enhancements to the thermo library (warning messages or better error messages), please submit an issue to https://github.com/CalebBell/thermo. I am also a contributor there and I help out in resolving issues too. I would personally avoid warnings in this case (just let it extrapolate) because it is a "hot" path and can lead to lot's of warnings and some overhead.
Yeah, removing extrapolation would break the code in some places and slow down iteration is others. One example is in VLE when working with chemicals with vastly different critical points. I believe other models for VLE such as PSRK would be able to avoid extrapolations. This is within my goals, but I probably cannot get to it this year.
Thanks!
from thermosteam.
Yeah, there are only a few places where Tsat is used, so this kind of API works and is easy to implement. For other properties, you'll need to set <TDependentProperties>.extrapolate=False
(for now at least). I went ahead and added a check for the value of P (should be under Pc):
thermosteam/thermosteam/_chemical.py
Line 1299 in d15539e
Thanks!
from thermosteam.
Related Issues (20)
- Aliases in `Chemical.copy` HOT 2
- Issue with ternary HOT 1
- [Feature request] auto-determine phases when creating `Stream` objects HOT 5
- Error when creating Stream with three chemicals and `vlle=True` HOT 5
- Consider phases in reaction enthalpy calculation HOT 7
- Account for phase changes in adiabatic reactions HOT 1
- `Mixture.solve_T_at_SP` returns incorrect results HOT 1
- Entropy setter sometimes does not work on `MultiStream` objects HOT 3
- Pressure-dependency of enthalpy is not accounted for HOT 3
- Cache is (still) broken HOT 3
- Proper way to set Cn methods? HOT 1
- Redirect previous thermosteam docs domain to biosteam docs domain HOT 2
- Bug in copying `ChemicalIndexer` HOT 2
- Thermosteam is no long Python 3.8-compatible HOT 2
- units_of_measure importing error due to pint verion HOT 3
- Python 3.8 no longer supported (only Python>=3.9 is supported)
- TypeError: 'NoneType' Object is not callable HOT 2
- Use pint.get_application_registry() rather than creating one with UnitRegistry() HOT 1
- Save report bug HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from thermosteam.