IDAES/idaes-pse

PETSc DAE Solver "initial_only" only option.

eslickj opened this issue · 2 comments

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.

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.

@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.