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

Add notebook for scaling workshop #135

Merged
merged 14 commits into from
Nov 5, 2024
Merged

Conversation

andrewlee94
Copy link
Member

@andrewlee94 andrewlee94 commented Oct 24, 2024

Scaling Workshop Notebook

Requires IDAES/idaes-pse#1507 IDAES/idaes-pse#1454

This PR adds a new example notebook that covers how to create Scalers for IDAES models (we also have a recording of me presenting this to a small group at NETL (needs to be cleaned up yet)).


Legal Acknowledgement

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

I agree my contributions are submitted under the license terms described in the LICENSE.txt file at the top level of this directory.
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.

📚 Documentation preview 📚: https://idaes-examples--135.org.readthedocs.build/en/135/

@andrewlee94 andrewlee94 added Priority:Normal Normal Priority Issue or PR documentation Improvements or additions to documentation enhancement New feature or request labels Oct 24, 2024
@andrewlee94
Copy link
Member Author

@lbianchi-lbl @dangunter Could one of you double check to make sure I did all the things I need to to add a new example?

@ksbeattie ksbeattie requested review from elbashandy, lbianchi-lbl and dangunter and removed request for elbashandy October 24, 2024 18:28
Copy link
Contributor

@agarciadiego agarciadiego left a comment

Choose a reason for hiding this comment

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

A couple of typos

"source": [
"These diagnostics can help give us an idea of what may be causing problems in our model. From the output above, we can see that the variables with large Jacobian norms (i.e., high sensitivities) are the outlet flow rate and temperature, as well as the rate-based extent of reaction. We can also see that the constraints with large Jacobian norms are the enthalpy balance and H20 material balance for the reactor. Understanding what this means however is often complicated and requires some thought.\n",
"\n",
"For example, one might wonder why the volumetric flow rate at the outlet of the reactor is so important as it is effectively determined by the inlet flow rate (due to the water balance effectively conserving volume). However, it is important to realize that from the point of view of the solver, the outlet flowrate is a free variable that can be manipulated, and that changing the volumetric flowrate at the outlet has a significant effect on the outlet concentrations (all other things kept constant). Thus as far as the solver is concerned, the outlet volumetric flowrate has a significant impact on the solution. This also explains why the H2O material balance is so important, as this is what governs the outlet flowrate. However, the material balances and concentrations of the other species in the system are what really matter, but this is not reflected in the model Jacobian. Once of the goals of scaling the model should be to balance these to ensure that the water balance does not come to dominate the other species.\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

If you want to understand where those values are coming from, you need to use the method in the SVDToolbox to print out Jacobian rows and columns. You'll quickly find that, for the volumetric flowrate, it has an enormous Jacobian value because it's being multiplied by the molar enthalpy (1e3 to 1e4 in J/mol) and the molar density (5.5e4 mol/m^3 for water) in the enthalpy balance constraint.

The volumetric flow rate being determined by the inlet flow rate is immaterial. Even if it is, changes in the volumetric flowrate to satisfy that constraint must be counteracted by other variables to make the residual small. And the volumetric flowrate does have a significant impact on the solution. The impact is just seen in variables like enthalpy, not the ones users typically look at.

I think it's worth mentioning that having a big value in the Jacobian does not mean a variable is "important". It's how sensitive the constraint residual is to that change in variable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

Comment on lines +1083 to +1086
" h_in += sum(\n",
" self.get_expression_nominal_values(\n",
" model.control_volume.properties_in[t].get_enthalpy_flow_terms(p)\n",
" )\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

Summing the absolute values here makes more sense than just summing everything in the Expression

Copy link
Contributor

Choose a reason for hiding this comment

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

At any rate, this is probably something I change as soon as I get scaling hints working. I would much rather have a scaling factor for enthalpy flow terms determined by the property package than by some dodgy sum of whatever happens to be the present values.

Copy link
Member Author

Choose a reason for hiding this comment

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

That one will depend on whether the property package uses an Expression or not (most do but not all). Also, at this level that should work either way as we can only rely on having phase-bases terms.

@andrewlee94 andrewlee94 enabled auto-merge (squash) November 5, 2024 21:02
@andrewlee94 andrewlee94 merged commit 919300c into IDAES:main Nov 5, 2024
11 checks passed
@andrewlee94 andrewlee94 deleted the scaling branch November 5, 2024 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request Priority:Normal Normal Priority Issue or PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants