[petsc-users] Asking examples about solving DAE in python

Zhang, Hong hongzhang at anl.gov
Thu Jan 20 17:05:36 CST 2022

On Jan 20, 2022, at 4:13 PM, Xiong, Jing via petsc-users <petsc-users at mcs.anl.gov<mailto:petsc-users at mcs.anl.gov>> wrote:


I hope you are well.
I'm very interested in PETSc and want to explore the possibility of whether it could solve Differential-algebraic equations (DAE) in python. I know there are great examples in C, but I'm struggling to connect the examples in python.

The only example I got right now is for solving ODEs in the paper: PETSc/TS: A Modern Scalable ODE/DAE Solver Library.
And I got the following questions:

  1.  Is petsc4py the right package to use?

Yes, you need petsc4py for python.

  1.  Could you give an example for solving DAEs in python?

src/binding/petsc4py/demo/ode/vanderpol.py gives a simple example to demonstrate a variety of PETSc capabilities. The corresponding C version of this example is ex20adj.c in src/ts/tutorials/.

  1.  How to solve an ODE with explicit methods.
  2.  How to solve an ODE/DAE with implicit methods.
  3.  How to use TSAdjoint to calculate adjoint sensitivities.
  4.  How to do a manual matrix-free implementation (e.g. you may already have a way to differentiate your RHS function to generate the Jacobian-vector product).

  1.  Is Jacobian must be specified? If not, could your show an example for solving DAEs without specified Jacobian in python?

PETSc can do finite-difference approximations to generate the Jacobian matrix automatically. This may work nicely for small-sized problems. You can also try to use an AD tool to produce the Jacobian-vector product and use it in a matrix-free implementation.


Thank you for your help.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20220120/db8b7952/attachment.html>

More information about the petsc-users mailing list