<div dir="ltr">Thank you very much for your help and the examples provided. I was able to implement the Jacobian-times-vector (Jv) approach as recommended, and it works great!.<div><br></div><div>Art</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">El mar, 8 jul 2025 a las 13:36, Zhang, Hong (<<a href="mailto:hongzhang@anl.gov">hongzhang@anl.gov</a>>) escribió:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg-5573078846753748831">
<div lang="EN-US" style="overflow-wrap: break-word;">
<div class="m_-5573078846753748831WordSection1">
<p class="MsoNormal">For a python example, please take a look at src/binding/petsc4py/demo/legacy/ode/vanderpol.py and you will see how jvp is done in the class IJacShell.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Hong<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(181,196,223);padding:3pt 0in 0in">
<p class="MsoNormal"><b><span style="font-family:Calibri,sans-serif;color:black">From:
</span></b><span style="font-family:Calibri,sans-serif;color:black">petsc-users <<a href="mailto:petsc-users-bounces@mcs.anl.gov" target="_blank">petsc-users-bounces@mcs.anl.gov</a>> on behalf of "Zhang, Hong via petsc-users" <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>><br>
<b>Reply-To: </b>"Zhang, Hong" <<a href="mailto:hongzhang@anl.gov" target="_blank">hongzhang@anl.gov</a>><br>
<b>Date: </b>Tuesday, July 8, 2025 at 12:21 PM<br>
<b>To: </b>Art <<a href="mailto:mac3bar@gmail.com" target="_blank">mac3bar@gmail.com</a>>, "<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>" <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>><br>
<b>Subject: </b>Re: [petsc-users] Matrix-Free J*v in PETSc<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal">Hi Art,<br>
<br>
Here is a TS example that uses MatShell for implicit time integration and adjoint sensitivity calculation:
<br>
src/ts/tutorials/advection-diffusion-reaction/ex5adj_mf.c<u></u><u></u></p>
<p class="MsoNormal" style="margin-bottom:12pt"><br>
You will need to provide a (jvp) routine like MyIMatMult() in this example. Adjoints require vjp (vector-Jacobian product) routines that are also included in this example.<br>
<br>
Hong<u></u><u></u></p>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(181,196,223);padding:3pt 0in 0in">
<p class="MsoNormal"><b><span style="font-family:Calibri,sans-serif;color:black">From:
</span></b><span style="font-family:Calibri,sans-serif;color:black">petsc-users <<a href="mailto:petsc-users-bounces@mcs.anl.gov" target="_blank">petsc-users-bounces@mcs.anl.gov</a>> on behalf of Art <<a href="mailto:mac3bar@gmail.com" target="_blank">mac3bar@gmail.com</a>><br>
<b>Date: </b>Monday, July 7, 2025 at 9:33 AM<br>
<b>To: </b>"<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>" <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>><br>
<b>Subject: </b>[petsc-users] Matrix-Free J*v in PETSc<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Hi all,<br>
<br>
I am integrating a stiff system of ODEs/PDEs using PETSc TS (typically with BDF or other implicit time-stepping schemes), and I would like to exploit the fact that I can efficiently compute the action of the Jacobian on a vector (Jv) without assembling the
full Jacobian matrix. Since for a large system it becomes expensive to assemble the Jacobian in each iteration. In scikits.odes (SUNDIALS/CVODE), there is a native API for passing only a J*v routine to the time integrator. In my experience, when I use only
a Jacobian-vector product routine (without assembling the full matrix), the performance improves significantly for large systems. However, in PETSc TS, the workflow seems more matrix-centric, and I have only found the possibility to use MatShell for the Jacobian<br>
<br>
Is there a way to do something similar in PETSc TS (for BDF or other implicit schemes)?<br>
<br>
Currently, I use the matrix-free Newton-Krylov method to approximate the Jacobian and have adjusted the tolerances to achieve convergence, as recommended by Barry. In that case, I obtain similar integration times with scikits.odes CVODE without using the Jacobian
times vector.<br>
<br>
Best regards,<br>
<br>
Art<u></u><u></u></p>
</div>
</div>
</div>
</div></blockquote></div>