GithubHelp home page GithubHelp logo

Comments (4)

chmarti1 avatar chmarti1 commented on June 16, 2024

This is a new problem created by an edit I made in the modifications for v2.2.0. I used to use _tditer() instead of _p(). _tditer() correctly resolves values under the dome, so these weird conditions don't crop up. I'll either transition back to _tditer() or I'll implement a fix to make _p() avoid the issue. _p() is preferred for numerical efficiency. _tditer() is apparently preferred for numerical stability.

from pyromat.

jranalli avatar jranalli commented on June 16, 2024

Well, if that's the case, maybe it's worth doing the try/except approach. _hybrid1 definitely handles the vast majority of cases and you can benefit from its efficiency. I only found these via a test code that pointwise crawls the space. So simplest approach for best of both worlds would be something like:

try:
  self._hybrid1(args)
except pm.utility.PMParamError as e:
    self._tditer(args)

Related by not identical issue, these types of cases crop up in the _d() calculation as well. I was able to resolve those as well by changing temperature limits. A few test cases for _d() are:

sub = pm.get('mp.CH4')
print(sub.d(p=0.11707696, T=624.375)) # T supercritical, p low
print(sub.d(p=9999.0, T=624.375)) # T&p supercritical

What I found here is that at high temperatures and various pressures, you get insane pressures at the high density boundary and it screws up the initiation of the iteration. My fix is uglier this time, but it might at least give you an idea of what kinds of changes I had to do to the iteration limits to make it work out.

Commit here. One part of the fix is to use the critical density as a limit when temperature is above the dome and pressure is below. The other part is to come up with a limit for when both p & T are above the dome. It works to compute the density at Tc & pmax, which would be an expected minimum value, but it results in an ugly recursion and I don't recommend using my exact method there.

from pyromat.

jranalli avatar jranalli commented on June 16, 2024

Since I'm documenting other numerics issues here, let me add these as well.

One involves calling things based on entropy.

sub = pm.get('mp.CH4')
ref = sub.d(T=223, s=-5.529)   # should be legit, 
# value expected is around 460 based on the forward calculation with p=2475 & T=223

The underlying codes do an iteration of _s based on density. But if you plot entropy as a function of density at that temperature you can see that it's got two possible density values that yield the entropy of interest and so your iteration code breaks. Better limits could maybe work here.

Something similar can happen with pressure and temperature for some cases. Here's the test condition

sub = pm.get('mp.N2')
sub.T(p=1.6e4, d=1355)  # errors out, should come out to be around 68

Leads to iteration of _p() based on T. Plotting pressure versus temperature shows that at very low temperatures there are two possible values of temperature that correspond to that pressure.

Just to be 100% clear, I'm not trying to nitpick here. I wrote some code to try to span the parameter space for all substances and I'm just diving into the test cases that errored out and trying to provide them so we can figure out what's going on with the numerics. No pressure as these aren't active cases I'm trying to use or anything.

from pyromat.

chmarti1 avatar chmarti1 commented on June 16, 2024

Version 2.2.1 corrects the issue. For the time being, I have reverted to _tditer() instead of _p() for the error function. The alternative requires an algorithm to calculate the saturation temperature given the density, so we can establish a minimum temperature that keeps the iteration outside of the dome when the pressure is super-critical. That's really the right way to solve the problem efficiently. Writing that algorithm isn't horribly difficult, but implementing it requires some significant testing. This can remain a goal for the future.

from pyromat.

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.