<head><!-- BaNnErBlUrFlE-HeAdEr-start -->
<style>
  #pfptBannerovsgilx { all: revert !important; display: block !important; 
    visibility: visible !important; opacity: 1 !important; 
    background-color: #D0D8DC !important; 
    max-width: none !important; max-height: none !important }
  .pfptPrimaryButtonovsgilx:hover, .pfptPrimaryButtonovsgilx:focus {
    background-color: #b4c1c7 !important; }
  .pfptPrimaryButtonovsgilx:active {
    background-color: #90a4ae !important; }
</style>

<!-- BaNnErBlUrFlE-HeAdEr-end -->
</head><!-- BaNnErBlUrFlE-BoDy-start -->
<!-- Preheader Text : BEGIN -->
<div style="display:none !important;display:none;visibility:hidden;mso-hide:all;font-size:1px;color:#ffffff;line-height:1px;height:0px;max-height:0px;opacity:0;overflow:hidden;">
 I have a 1-dimensional P1 discontinuous Galerkin discretization of the linear advection equation with 4 cells and periodic boundaries on [-pi,+pi]. I'm comparing the results from SNESComputeJacobian with a hand-written Jacobian. Being linear,
</div>
<!-- Preheader Text : END -->

<!-- Email Banner : BEGIN -->
<div style="display:none !important;display:none;visibility:hidden;mso-hide:all;font-size:1px;color:#ffffff;line-height:1px;height:0px;max-height:0px;opacity:0;overflow:hidden;">ZjQcmQRYFpfptBannerStart</div>

<!--[if ((ie)|(mso))]>
  <table border="0" cellspacing="0" cellpadding="0" width="100%" style="padding: 16px 0px 16px 0px; direction: ltr" ><tr><td>
    <table border="0" cellspacing="0" cellpadding="0" style="padding: 0px 10px 5px 6px; width: 100%; border-radius:4px; border-top:4px solid #90a4ae;background-color:#D0D8DC;"><tr><td valign="top">
      <table align="left" border="0" cellspacing="0" cellpadding="0" style="padding: 4px 8px 4px 8px">
        <tr><td style="color:#000000; font-family: 'Arial', sans-serif; font-weight:bold; font-size:14px; direction: ltr">
          This Message Is From an External Sender
        </td></tr>
        <tr><td style="color:#000000; font-weight:normal; font-family: 'Arial', sans-serif; font-size:12px; direction: ltr">
          This message came from outside your organization.
        </td></tr>

      </table>

    </td></tr></table>
  </td></tr></table>
<![endif]-->

<![if !((ie)|(mso))]>
  <div dir="ltr"  id="pfptBannerovsgilx" style="all: revert !important; display:block !important; text-align: left !important; margin:16px 0px 16px 0px !important; padding:8px 16px 8px 16px !important; border-radius: 4px !important; min-width: 200px !important; background-color: #D0D8DC !important; background-color: #D0D8DC; border-top: 4px solid #90a4ae !important; border-top: 4px solid #90a4ae;">
    <div id="pfptBannerovsgilx" style="all: unset !important; float:left !important; display:block !important; margin: 0px 0px 1px 0px !important; max-width: 600px !important;">
      <div id="pfptBannerovsgilx" style="all: unset !important; display:block !important; visibility: visible !important; background-color: #D0D8DC !important; color:#000000 !important; color:#000000; font-family: 'Arial', sans-serif !important; font-family: 'Arial', sans-serif; font-weight:bold !important; font-weight:bold; font-size:14px !important; line-height:18px !important; line-height:18px">
        This Message Is From an External Sender
      </div>
      <div id="pfptBannerovsgilx" style="all: unset !important; display:block !important; visibility: visible !important; background-color: #D0D8DC !important; color:#000000 !important; color:#000000; font-weight:normal; font-family: 'Arial', sans-serif !important; font-family: 'Arial', sans-serif; font-size:12px !important; line-height:18px !important; line-height:18px; margin-top:2px !important;">
This message came from outside your organization.
      </div>

    </div>

    <div style="clear: both !important; display: block !important; visibility: hidden !important; line-height: 0 !important; font-size: 0.01px !important; height: 0px"> </div>
  </div>
<![endif]>

<div style="display:none !important;display:none;visibility:hidden;mso-hide:all;font-size:1px;color:#ffffff;line-height:1px;height:0px;max-height:0px;opacity:0;overflow:hidden;">ZjQcmQRYFpfptBannerEnd</div>
<!-- Email Banner : END -->

<!-- BaNnErBlUrFlE-BoDy-end -->
<div dir="ltr"><div>I have a 1-dimensional P1 discontinuous Galerkin discretization of the linear advection equation with 4 cells and periodic boundaries on [-pi,+pi]. I'm comparing the results from SNESComputeJacobian with a hand-written Jacobian. Being linear, the Jacobian should be constant/independent of the solution.</div><div><br></div><div>When I set the initial condition passed to SNESComputeJacobian as some constant, say f(x)=1 or 0, the petsc finite difference jacobian agrees with my hand coded-version. But when I pass it some non-constant value, e.g. f(x)=sin(x), something goes horribly wrong in the petsc jacobian. Implementing my own rudimentary finite difference approximation (similar to how I thought petsc computes it) it returns the correct jacobian to expected error. Any idea what could be going on?</div><div><br></div><div>Analytically computed Jacobian:</div><div> 4.44089e-16     -1.10266      0.31831   -0.0852909            0            0     -0.31831      1.18795<br>     1.10266 -4.44089e-16     -1.18795      0.31831            0            0    0.0852909     -0.31831<br>    -0.31831      1.18795  4.44089e-16     -1.10266      0.31831   -0.0852909            0            0<br>   0.0852909     -0.31831      1.10266 -4.44089e-16     -1.18795      0.31831            0            0<br>           0            0     -0.31831      1.18795  4.44089e-16     -1.10266      0.31831   -0.0852909<br>           0            0    0.0852909     -0.31831      1.10266 -4.44089e-16     -1.18795      0.31831<br>     0.31831   -0.0852909            0            0     -0.31831      1.18795  4.44089e-16     -1.10266<br>    -1.18795      0.31831            0            0    0.0852909     -0.31831      1.10266 -4.44089e-16<br></div><div><br></div><div><br></div><div>petsc finite difference jacobian when given f(x)=1:</div><div> 4.44089e-16     -1.10266      0.31831   -0.0852909            0            0     -0.31831      1.18795<br>     1.10266 -4.44089e-16     -1.18795      0.31831            0            0    0.0852909     -0.31831<br>    -0.31831      1.18795  4.44089e-16     -1.10266      0.31831   -0.0852909            0            0<br>   0.0852909     -0.31831      1.10266 -4.44089e-16     -1.18795      0.31831            0            0<br>           0            0     -0.31831      1.18795  4.44089e-16     -1.10266      0.31831   -0.0852909<br>           0            0    0.0852909     -0.31831      1.10266 -4.44089e-16     -1.18795      0.31831<br>     0.31831   -0.0852909            0            0     -0.31831      1.18795  4.44089e-16     -1.10266<br>    -1.18795      0.31831            0            0    0.0852909     -0.31831      1.10266 -4.44089e-16</div><div><br></div><div>petsc finite difference jacobian when given f(x) = sin(x):</div><div>-1.65547e+08 -3.31856e+08 -1.25427e+09   4.4844e+08            0            0  1.03206e+08  7.86375e+07<br> 9.13788e+07  1.83178e+08  6.92336e+08  -2.4753e+08            0            0 -5.69678e+07 -4.34064e+07<br>  3.7084e+07  7.43387e+07  2.80969e+08 -1.00455e+08  -5.0384e+07 -2.99747e+07            0            0<br>  3.7084e+07  7.43387e+07  2.80969e+08 -1.00455e+08  -5.0384e+07 -2.99747e+07            0            0<br>           0            0  2.80969e+08 -1.00455e+08  -5.0384e+07 -2.99747e+07 -2.31191e+07 -1.76155e+07<br>           0            0  2.80969e+08 -1.00455e+08  -5.0384e+07 -2.99747e+07 -2.31191e+07 -1.76155e+07<br> 9.13788e+07  1.83178e+08            0            0 -1.24151e+08 -7.38608e+07 -5.69678e+07 -4.34064e+07<br>-1.65547e+08 -3.31856e+08            0            0  2.24919e+08   1.3381e+08  1.03206e+08  7.86375e+07<br></div><div><br></div></div>