Skip to content

PETSc Overhaul for DAE Index Reduction - #1824

Open
dallan-keylogic wants to merge 48 commits into
IDAES:mainfrom
dallan-keylogic:petsc_object
Open

PETSc Overhaul for DAE Index Reduction#1824
dallan-keylogic wants to merge 48 commits into
IDAES:mainfrom
dallan-keylogic:petsc_object

Conversation

@dallan-keylogic

@dallan-keylogic dallan-keylogic commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Fixes

#1399
#1347

Summary/Motivation:

After some experience with the original PETSc integrator, I've found some shortcomings:

  • If the user needs to call PETSc multiple times, they must flatten the model each time, which is slow
  • It is hard to troubleshoot model issues for either the initial condition or timestep problem
  • It is impossible to convert a time derivative variable into an algebraic variable---if the user wishes to convert a differential variable to an algebraic variable, they must fix the derivative to zero

Point 2 made handling index reduction, in which we regularly need to convert derivative variables into algebraic variables, rather difficult. This problem could be bypassed by adding dummy variables for the derivatives, then setting only a subset of them to equal actual DerivativeVars, but that would require large modifications to existing unit models to add these dummy variables to result in a situation in which the user gets confused about which variable is actually a DerivativeVar and which is just a dummy.

To address these issues, I decided to rework the PETSc interface into a class.

  • The flattened model is cached on the integrator object. If the model structure doesn't change between calls to PETSc, the user can skip re-flattening the model.
  • User-facing functions to construct the initial condition and timestamp problem have been created. These functions are called by the PETSc integrator directly when setting up subproblems as part of integration, so the problems the integrator solves are the same ones available to the user for troubleshooting.
  • The model looks for the activation status of a DerivativeVar object's discretization equation. If that equation is deactivated, it treats it as an algebraic variable. This makes the process of index reduction easier.

Changes proposed in this PR:

  • Create new PETSc object class

Notes for reviewers

  • Is checking for the activation status of the discretization equation the way we want to handle index reduction, or do we want to do something else, like use the expression replacement walker?
  • Right now, I'm expecting the user to call refresh_model if the model structure changes. Do we want to try to save the user from themselves by calling refresh_model every time the user calls dae_by_time_element unless the user specifies otherwise using a function argument or config option?

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.

@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.07143% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.62%. Comparing base (a60fbf8) to head (2f6c08b).

Files with missing lines Patch % Lines
idaes/core/solvers/petsc_object.py 91.07% 10 Missing and 15 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1824      +/-   ##
==========================================
+ Coverage   77.56%   77.62%   +0.05%     
==========================================
  Files         423      424       +1     
  Lines       67529    67809     +280     
  Branches    11420    11483      +63     
==========================================
+ Hits        52379    52635     +256     
- Misses      12531    12541      +10     
- Partials     2619     2633      +14     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dallan-keylogic
dallan-keylogic marked this pull request as ready for review July 28, 2026 16:36
Comment thread idaes/core/solvers/petsc_object.py Outdated
@ksbeattie ksbeattie added the Priority:High High Priority Issue or PR label Jul 30, 2026
@dallan-keylogic
dallan-keylogic requested a review from adam-a-a July 31, 2026 17:08
@dallan-keylogic dallan-keylogic added the CI:run-integration triggers_workflow: Integration label Jul 31, 2026
@idaes-build idaes-build removed the CI:run-integration triggers_workflow: Integration label Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority:High High Priority Issue or PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants