<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On Jan 20, 2022, at 4:13 PM, Xiong, Jing via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" class="">petsc-users@mcs.anl.gov</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class="">
<div style="margin-top: 0pt; margin-bottom: 0pt; color: rgb(14, 16, 26); background-color: transparent;" class="">
<span data-preserver-spaces="true" style="background-color: transparent;" class="">Hi,</span></div>
<div style="margin-top: 0pt; margin-bottom: 0pt; color: rgb(14, 16, 26); background-color: transparent;" class="">
<br class="">
</div>
<div style="margin-top: 0pt; margin-bottom: 0pt; color: rgb(14, 16, 26); background-color: transparent;" class="">
<span data-preserver-spaces="true" style="background-color: transparent;" class="">I hope you are well.</span></div>
<div style="margin-top: 0pt; margin-bottom: 0pt; color: rgb(14, 16, 26); background-color: transparent;" class="">
<span data-preserver-spaces="true" style="background-color: transparent;" class="">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. </span></div>
<div style="margin-top: 0pt; margin-bottom: 0pt; color: rgb(14, 16, 26); background-color: transparent;" class="">
<br class="">
</div>
<div style="margin-top: 0pt; margin-bottom: 0pt; color: rgb(14, 16, 26); background-color: transparent;" class="">
<span data-preserver-spaces="true" style="background-color: transparent;" class="">The only example I got right now is for solving ODEs in the paper: PETSc/TS: A Modern Scalable ODE/DAE Solver Library. </span></div>
<div style="margin-top: 0pt; margin-bottom: 0pt; color: rgb(14, 16, 26); background-color: transparent;" class="">
<span data-preserver-spaces="true" style="background-color: transparent;" class="">And I got the following questions:</span></div>
<ol style="color: rgb(14, 16, 26); background-color: transparent; margin-top: 0pt; margin-bottom: 0pt;" class="">
<li style="background-color: transparent; margin-top: 0pt; margin-bottom: 0pt; list-style-type: decimal;" class="">
<span data-preserver-spaces="true" style="background-color: transparent; margin-top: 0pt; margin-bottom: 0pt;" class=""><b class="">Is petsc4py the right package to use?</b></span></li></ol>
</div>
</div>
</blockquote>
<div><br class="">
</div>
<div>Yes, you need petsc4py for python. </div>
<br class="">
<blockquote type="cite" class="">
<div class="">
<div style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class="">
<ol style="color: rgb(14, 16, 26); background-color: transparent; margin-top: 0pt; margin-bottom: 0pt;" class="" start="2">
<li style="background-color: transparent; margin-top: 0pt; margin-bottom: 0pt; list-style-type: decimal;" class="">
<span data-preserver-spaces="true" style="background-color: transparent; margin-top: 0pt; margin-bottom: 0pt;" class=""><b class="">Could you give an example for solving DAEs in python?</b></span></li></ol>
</div>
</div>
</blockquote>
<div><br class="">
</div>
<div>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/.</div>
<div>
<ol class="MailOutline">
<li class="">How to solve an ODE with explicit methods.</li><li class="">How to solve an ODE/DAE with implicit methods.</li><li class="">How to use TSAdjoint to calculate adjoint sensitivities.</li><li class="">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). </li></ol>
</div>
<br class="">
<blockquote type="cite" class="">
<div class="">
<div style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class="">
<ol style="color: rgb(14, 16, 26); background-color: transparent; margin-top: 0pt; margin-bottom: 0pt;" class="" start="3">
<li style="background-color: transparent; margin-top: 0pt; margin-bottom: 0pt; list-style-type: decimal;" class="">
<span data-preserver-spaces="true" style="background-color: transparent; margin-top: 0pt; margin-bottom: 0pt;" class=""><b class="">Is Jacobian must be specified? If not, could your show an example for solving DAEs without specified Jacobian in python?</b></span></li></ol>
</div>
</div>
</blockquote>
<div><br class="">
</div>
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.</div>
<div><br class="">
</div>
<div>Hong</div>
<div><br class="">
<blockquote type="cite" class="">
<div class="">
<div style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class="">
<div class=""><span data-preserver-spaces="true" style="background-color: transparent; margin-top: 0pt; margin-bottom: 0pt;" class=""><br class="">
</span></div>
<div class=""><span data-preserver-spaces="true" style="background-color: transparent; margin-top: 0pt; margin-bottom: 0pt;" class="">Thank you for your help.</span></div>
<div class=""><span data-preserver-spaces="true" style="background-color: transparent; margin-top: 0pt; margin-bottom: 0pt;" class=""><b class=""><br class="">
</b></span></div>
<div class=""><span data-preserver-spaces="true" style="background-color: transparent; margin-top: 0pt; margin-bottom: 0pt;" class="">Best,</span></div>
<div class=""><span data-preserver-spaces="true" style="background-color: transparent; margin-top: 0pt; margin-bottom: 0pt;" class="">Jing</span></div>
</div>
</div>
</blockquote>
</div>
<br class="">
</body>
</html>