Skip to content
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

Fixing spurious DoF in Gibbs reactor model #1393

Merged
merged 3 commits into from
Apr 11, 2024
Merged

Conversation

andrewlee94
Copy link
Member

Fixes #1392

Summary/Motivation:

The current implementation of the Gibbs reactor model includes all elements in the Lagrange multipliers expressions, even if the elemental composition for a given component is 0. This leads to spurious degrees of freedom where the variable appears to be in active constraints but is multiplied y zero (and thus filtered out in the Pyomo solver writers).

Changes proposed in this PR:

  • Add logic to catch these cases and exclude them from the expression.

Legal Acknowledgement

By contributing to this software project, I agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the license terms described in the LICENSE.txt file at the top level of this directory.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@andrewlee94 andrewlee94 requested a review from bpaul4 as a code owner April 9, 2024 18:05
@andrewlee94 andrewlee94 self-assigned this Apr 9, 2024
@andrewlee94 andrewlee94 added bug Something isn't working enhancement New feature or request Priority:Normal Normal Priority Issue or PR unit models Issues dealing with the unit model libraries labels Apr 9, 2024
if b.control_volume.properties_out[
t
].config.parameters.element_comp[j][e]
!= 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use 0, or a very small value? Does the Pyomo solver writer specifically check for "exactly 0" values and filter those variables out?

Copy link
Member Author

@andrewlee94 andrewlee94 Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only for exact zero (and a fixed value at that). The issue is that the solver writer is filtering these out for us, but when we use the degrees_of_freedom function we still see these (and hence see spurious DoF).

This is to catch cases where the multiplier is a constant of 0 and filter them out of the expression.

Copy link
Member Author

@andrewlee94 andrewlee94 Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also just worked out a better solution to remove the unneeded multipliers entirely (so that they don't end up as unused variables).

Copy link

codecov bot commented Apr 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.62%. Comparing base (f8ccdec) to head (59dc412).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1393      +/-   ##
==========================================
- Coverage   77.63%   77.62%   -0.01%     
==========================================
  Files         391      391              
  Lines       64375    64386      +11     
  Branches    14257    14262       +5     
==========================================
+ Hits        49978    49981       +3     
- Misses      11827    11834       +7     
- Partials     2570     2571       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

for j in self.control_volume.properties_in.component_list:
if j in self.config.inert_species:
continue
elif self.control_volume.properties_out.params.element_comp[j][e] != 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AttributeError: '_IndexedGenericStateBlock' object has no attribute 'params' is thrown here. I believe a time index is missing, properties_out[0.0],params should be there instead of properties_out.params

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for me, and I have created a test specifically for your use case to be sure.

Could you check what version of IDAES you are using? I fixed this issue a while ago and StateBlocks now support .params.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using 2.2.0 dev of IDAES

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to update your version of IDAES as you are at least two full releases behind.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works fine with the latest version. Looks good.

idaes/models/unit_models/gibbs_reactor.py Outdated Show resolved Hide resolved
Copy link
Contributor

@dallan-keylogic dallan-keylogic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@ksbeattie ksbeattie merged commit 40d3dc7 into IDAES:main Apr 11, 2024
65 checks passed
@andrewlee94 andrewlee94 deleted the gibbs_dof branch April 11, 2024 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request Priority:Normal Normal Priority Issue or PR unit models Issues dealing with the unit model libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handling inert species in Gibbs Reactor
5 participants