IDAES / idaes-pse

The IDAES Process Systems Engineering Framework
https://idaes-pse.readthedocs.io/
Other
213 stars 228 forks source link

PETSc DAE Solver "initial_only" only option. #1347

Open eslickj opened 6 months ago

eslickj commented 6 months ago

When using the petsc.petsc_dae_by_time_element() function to solve a DAE model, I think it would be useful to have an "initial_only" option. I may not have thought this through well enough, but the idea is that when you initialize a DAE model and you are solving with an integrator, only the initial condition matters. Next time you solve it the trajectory is just replaced. If I break the model up and initialize unit by unit, getting the trajectory is just a waste of time. This isn't really a PETSc solver issue specifically, but petsc.petsc_dae_by_time_element() does conveniently split off the initial condition equations for you. I'm know there are other ways to approach this, but adding the option seems convenient.

I think this would be easy to implement. Just terminate the function after solving the initial conditions. The results should be in the model. Return the solver status and None for the trajectory.

dallan-keylogic commented 6 months ago

Possibly what should be done is to provide a way to return the initial condition problem. I've had to do things like add break statements in the middle of the PETSc code in order to do model diagnostics because my initial condition problem was badly specified. The only trick is figuring out how to handle the context manager.

eslickj commented 6 months ago

@dallan-keylogic, what about a new context manager that you could use like

with InitialConditionProblemManager(...) as ic_model:
    #diagnostics, solve, or whatever.

We could maybe just copy the first part of the petsc time stepping solver wrapper and build on TemporarySubsystemManager. It shouldn't be too hard to put together since it's basically all there. The only trick is you may want an option to revert any changes you make to variable values. Like if I want to solve the initial condition problem, I want to keep the variable values. If you are doing diagnostics, maybe you don't want to keep any changes.