-
-
Notifications
You must be signed in to change notification settings - Fork 349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SolutionArray/ flamebase importers allow unnormalized and/or negative mass/mole fractions #1037
Conversation
774b7a5
to
01541b7
Compare
01541b7
to
edab027
Compare
Thanks, @DavidAkinpelu. As I am involved with this, I’ll leave it to @speth and/or @bryanwweber to review. |
3cba59a
to
384546d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @DavidAkinpelu! Thank you for contributing this change, and welcome to contributing to Cantera! I've made a few comments below. I think overall the change is a great addition and it'll certainly make the SolutionArray
more useful. The comments are mainly aimed at simplifying the code and hopefully making it a little easier for the next person to understand!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @DavidAkinpelu! These changes are looking great. I have a few more comments, mostly to clarify wording and text formatting in a few places.
cc4c3dc
to
0ce56cf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @DavidAkinpelu! This is very close, great work so far.
Sorry, two more comments:
Since I really can't decide, I'm going to ping @speth for a third opinion. |
I’d be ok with that compromise. For reading from file, not getting back what was saved was the starting point for this PR, and it certainly should not be normalized in that case by default. Normalize is only enforced by default when composition is explicitly set; otherwise Cantera allows for deviations. |
93382ea
to
59b827f
Compare
408bf6c
to
005c96e
Compare
@DavidAkinpelu I'm going to reply in a top level comment here so that I can have some more space. I guess what you mean is this: import cantera as ct
gas
In [2]: gas = ct.Solution("h2o2.yaml")
In [3]: import numpy as np
In [5]: x = np.ones(gas.n_species) * 0.3
In [6]: gas.set_unnormalized_mole_fractions(x)
In [9]: gas.X
Out[9]: array([0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3])
In [10]: gas.Y
Out[10]:
array([0.00912106, 0.00456053, 0.07238482, 0.14476964, 0.07694535,
0.08150588, 0.14933017, 0.1538907 , 0.18074715, 0.1267447 ])
In [11]: gas.mean_molecular_weight
Out[11]: 66.3081
In [13]: np.dot(gas.X, gas.molecular_weights)
Out[13]: 66.3081
In [16]: 1/np.dot(gas.Y, 1/gas.molecular_weights)
Out[16]: 22.102699999999995 If the system were in a consistent state, those would be the same values, but they're not. As far as I can see, this kind of transformation is inevitable since the conversion from mole to mass fraction relies on the sum of them being equal to 1.0. In the end, I don't think the right procedure is to simply disable the non-normalized mole fraction setter when In addition, I think it would be a better user experience if the |
Thanks for the clarification, you couldn't have explained it better. You are right. in the previous case, appending using |
Linking #390 as this is related. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allowing users the option to preserve mass fraction arrays that do not sum to 1 and contain negative values makes sense to me, but I think we should be careful about when that makes sense as a default behavior. I view working with such arrays as something that only a fairly experienced user should be trying to do, given the numerous pitfalls, and it's not unreasonable to expect such users to be able to set this option when they need it.
The case where I can see doing this by default is when the source of the mass fractions is a ThermoPhase
object, where the only way that such a mass fraction vector could have been set in the first place is with one of the noNorm
setters.
The case of restoring data from a file is a bit fuzzier. If you assume that the data came from Cantera, it could make sense, but I don't think that's an assumption that's universally true, and I think from the viewpoint of seeing this as an advanced option, I would recommend defaulting to the current behavior of normalizing the mass fractions.
When setting the state from a list or Numpy array, deciding not to normalize by default would be a significant departure from the behavior for the Solution
object and the underlying Phase
class, and I don't think the SolutionArray
class should be a special case here.
b25c39c
to
3ec15dc
Compare
@bryanwweber, @speth... The PR is updated and is ready for further review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @DavidAkinpelu. This largely looks good to me. With the exception of the one case where mass and mole fractions are mixed up, most of my comments are just a few points where the code might be simplified a bit and some suggestions for the documentation.
Update AUTHORS insert name alphabetically
fix typos
7a949b0
to
f9da9c2
Compare
@speth... The PR is updated and is ready for further review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates, @DavidAkinpelu. I just saw one last typo that can be fixed. Otherwise, I think this is good to go.
f9da9c2
to
9b73c48
Compare
@speth.. The PR has been updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thank you!
Changes proposed in this pull request
SolutionArray
/Flambase
importers allow negative values for mass and mole fractionsSolutionArray
appendsSolution
object with unnormalized mass/mole fractionsIf applicable, fill in the issue number this pull request is fixing
Closes #1016
If applicable, provide an example illustrating new features this pull request is introducing
Operating system: Windows 10
Python Version: 3.9.2
Cantera version: 2.6.0a1
Checklist
scons build
&scons test
) and unit tests address code coverage