Make the concept of saving state vectors more general#720
Conversation
dbd2d80 to
66ad398
Compare
4eafd05 to
84daca7
Compare
|
@bryanwweber ... at this point, Note: other phases not covered by this PR can be very easily added by overloading |
84daca7 to
00cb5e1
Compare
a506fef to
b78b14a
Compare
b78b14a to
ef3359a
Compare
2f1fa34 to
c86c704
Compare
speth
left a comment
There was a problem hiding this comment.
Conditioning saveState and restoreState on isIncompressible makes sense to me, and is a fine resolution for #595. Strictly speaking, we would probably like to have saveState use the variables in defaultState and get the kind of behavior that this PR gets in SolutionArray.colect_data, but that has the potential to get messy, and I don't think we have any phase types right now where that would really be worthwhile.
Disabling the composition setters for stoichiometric phases seems unnecessary. The mass/mole fractions get normalized anyway, so any value specified there will have no effect in any case.
I'm not sure that it's worth the extra complexity of keeping track of which phases have fixed stoichiometry in order to reduce the size of the state used by Phase::saveState and Phase::restoreState by one variable. As it is, the the Python state property doesn't even handle this -- we would need to add yet another method which returned the size of the state depending on the value of isStoichPhase.
I think the best way to disable setting density to fix #644 and other equivalent scenarios is to override the setDensity method of the appropriate class at the C++ level. This achieves the desired behavior in all language interfaces, not just Python, and avoids the overhead of the _check_setter method.
After that, the only case in which the distinction between the "partial states" and "full states" is made is within SolutionArray, where it's still part of a special case, so I'm hoping there's an opportunity to simplify this somewhat.
|
@speth ... thanks for the comments!
That is exactly what this PR is trying to accomplish 😁 (it's actually less messy than I thought at first)
That's a minor side-effect of the implementation. I mainly needed to peel off the compositions for stoichiometric phases as this makes things consistent with the Your comment still pointed out one case I hadn't thought off (someone could add |
c86c704 to
16c5073
Compare
|
@speth ... I confirmed that this PR indeed allows I added more detailed unit tests to that effect, i.e. |
16c5073 to
1ec740d
Compare
1ec740d to
2050c61
Compare
|
Edit: the behavior described below is easy to fix (see f8abd72 pushed below) There's one behavior I observed and am not sure about. For The current behavior for This potentially confusing (and pre-exisiting) behavior could be avoided by adding all of the setters that are defined for |
8058130 to
f8abd72
Compare
I can look into that but with #652 in mind it's hard to keep track. As most of the setters are presumably still inherited from |
speth
left a comment
There was a problem hiding this comment.
OK, I think we're making progress here!
I like the name assignDensity -- it clearly sets this apart from setDensity.
I did notice a few added blank lines containing whitespace. If you could clean those up it would be appreciated. They are unfortunately not visible in the GitHub UI, but you can see them pretty clearly in the output of git diff if you have color formatting enabled.
- switch 'isIncompressible' to 'isCompressible' - switch 'isStoichPhase' to 'isPure' - improve deprecation warning messages and docstrings - rename 'setConstDensity' to 'assignDensity' - remove warnings for assigning mole fractions for pure substances - rename 'defaultState' to 'nativeState'; use map instead of vector
62aee52 to
b762b60
Compare
|
FYI, I just noticed in the documentation for |
Thanks for pointing this out. Will address in a final revision. @speth ... I believe this is now converging. This time around I decided to shorten PS: the signature of |
@bryanwweber ... I figure the differentiation between What would you suggest as a replacement for this description? Or would you suggest to move pressure back, let |
|
I think it probably makes most sense to change the description, since as you note, not every phase has density as the independent variable. |
|
I wouldn't sweat over the distinction between |
|
@bryanwweber and @speth ... there were several instances where updates from this PR affect descriptions of Phase definitions. To facilitate review, I kept updates in a single commit (a582743). |
speth
left a comment
There was a problem hiding this comment.
Regarding the SolutionArray state properties, I pushed an update to my branch (08cabf5) which achieves what I was after with at least the properties that are defined on ThermoPhase maintaining the existing behavior, and then any other properties being added dynamically. You should be able to add that to your branch without affecting the authorship information using git cherry-pick.
Thanks for making the updates to the documentation. My remaining comments just pertain to those updates.
I tried that before, unsuccessfully. Are you writing to my repo or upstream? ( |
Neither, I'm pushing to my fork. |
71d9903 to
d1cc10d
Compare
Pretty obvious (in hindsight! you even mentioned as much). Thus far, I haven't had your fork set up as a remote. Thanks for resolving! |
d1cc10d to
86d953c
Compare
bryanwweber
left a comment
There was a problem hiding this comment.
I'm deferring final review approval to @speth at this point. I think we've converged to a good place.
Thanks, Bryan! |
|
Thank you @ischoegl! |
|
Thanks for the thorough review and discussion @speth! |
Please fill in the issue number this pull request is fixing:
Fixes #595, fixes #644,
Changes proposed in this pull request:
thermo-models.yamlcan be saved and restored correctlySolutionArray(almost) phase agnosticE.g. using the examples from #595 and #644, the behavior is now correct, and invalid setters are disabled (or deprecated).