Git Product home page Git Product logo

Comments (3)

BenPortner avatar BenPortner commented on June 12, 2024 1

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.

yoelcortes avatar yoelcortes commented on June 12, 2024

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.

yoelcortes avatar yoelcortes commented on June 12, 2024

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):

def Tsat(self, P, Tguess=None, Tmin=None, Tmax=None, *, check_validity=True):

Thanks!

from thermosteam.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.