<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:DengXian;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Aptos;
        panose-1:2 11 0 4 2 2 2 2 2 4;}
@font-face
        {font-family:"\@DengXian";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:12.0pt;
        font-family:"Aptos",sans-serif;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Aptos",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        mso-ligatures:none;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="#467886" vlink="#96607D" style="word-wrap:break-word">
<div class="WordSection1">
<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<o:p></o:p></p>
<p class="MsoNormal"><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<br>
<br>
<o:p></o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 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 <petsc-users-bounces@mcs.anl.gov> on behalf of Art <mac3bar@gmail.com><br>
<b>Date: </b>Monday, July 7, 2025 at 9:33 AM<br>
<b>To: </b>"petsc-users@mcs.anl.gov" <petsc-users@mcs.anl.gov><br>
<b>Subject: </b>[petsc-users] Matrix-Free J*v in PETSc<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></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<o:p></o:p></p>
</div>
</div>
</body>
</html>