<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:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@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:Aptos;
        panose-1:2 11 6 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:10.0pt;
        font-family:"Aptos",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        font-size:10.0pt;
        font-family:"Aptos",sans-serif;}
p.m5206826287588213837msolistparagraph, li.m5206826287588213837msolistparagraph, div.m5206826287588213837msolistparagraph
        {mso-style-name:m5206826287588213837msolistparagraph;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Aptos",sans-serif;}
span.EmailStyle21
        {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;}
/* List Definitions */
@list l0
        {mso-list-id:695040495;
        mso-list-template-ids:1277988554;}
@list l0:level1
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:.5in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level2
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:1.0in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level3
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:1.5in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level4
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:2.0in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level5
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:2.5in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level6
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:3.0in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level7
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:3.5in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level8
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:4.0in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level9
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:4.5in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l1
        {mso-list-id:1045259198;
        mso-list-template-ids:1588986956;}
@list l1:level1
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:.5in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l1:level2
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:1.0in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l1:level3
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:1.5in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l1:level4
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:2.0in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l1:level5
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:2.5in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l1:level6
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:3.0in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l1:level7
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:3.5in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l1:level8
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:4.0in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l1:level9
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:4.5in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l2
        {mso-list-id:1379819502;
        mso-list-type:hybrid;
        mso-list-template-ids:1661517788 1653888544 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l2:level1
        {mso-level-start-at:0;
        mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Symbol;
        mso-fareast-font-family:Aptos;
        mso-bidi-font-family:"Times New Roman";}
@list l2:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l2:level3
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Wingdings;}
@list l2:level4
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Symbol;}
@list l2:level5
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l2:level6
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Wingdings;}
@list l2:level7
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Symbol;}
@list l2:level8
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l2:level9
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Wingdings;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
--></style>
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt">The other symptom is the same:<o:p></o:p></span></p>
<ul style="margin-top:0in" type="disc">
<li class="MsoListParagraph" style="margin-left:0in;mso-list:l2 level1 lfo3"><span style="font-size:11.0pt">Using coloring, finite differencing respects the specified non-zero pattern, but gives wrong (very large) Jacobian entries (J_ij)<o:p></o:p></span></li><li class="MsoListParagraph" style="margin-left:0in;mso-list:l2 level1 lfo3"><span style="font-size:11.0pt">Using dense matrix assumption, finite differencing does not respect the non-zero pattern determined by your numeric, which is a clear sign of residual
 function code bug (your residual function does not respect your numeric).<o:p></o:p></span></li></ul>
<p class="MsoNormal"><span style="font-size:11.0pt">-Ling<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<div id="mail-editor-reference-message-container">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">petsc-users <petsc-users-bounces@mcs.anl.gov> on behalf of Zou, Ling via petsc-users <petsc-users@mcs.anl.gov><br>
<b>Date: </b>Sunday, April 21, 2024 at 2:28 PM<br>
<b>To: </b>Mark Lohry <mlohry@gmail.com><br>
<b>Cc: </b>PETSc <petsc-users@mcs.anl.gov><br>
<b>Subject: </b>Re: [petsc-users] finite difference jacobian errors when given non-constant initial condition<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">Very interesting.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">I happened to encounter something very similar a couple of days ago, which, of course, was due to a code bug I introduced. The code bug was in the residual function. I used a local vector to track ‘heat flux’,
 which should be zero-ed out at the beginning of each residual function evaluation. I did not zero it, and I observed very similar results, the Jacobian is completely wrong, with large values (J_ij keeps increasing after each iteration), and non-zero values
 are observed in locations which should be perfect zero. The symptom is very much like what you are seeing here. I suspect a similar bug. (Maybe you forgot zero the coefficients of P1 re-construction? Using constant value 1, reconstructed dphi/dx = 0, so however
 many iterations, still zero).</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">-Ling</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<div id="mail-editor-reference-message-container">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">Mark Lohry <mlohry@gmail.com><br>
<b>Date: </b>Sunday, April 21, 2024 at 12:35 PM<br>
<b>To: </b>Zou, Ling <lzou@anl.gov><br>
<b>Cc: </b>PETSc <petsc-users@mcs.anl.gov><br>
<b>Subject: </b>Re: [petsc-users] finite difference jacobian errors when given non-constant initial condition</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:1.0pt;color:white">The coloring I'm fairly confident is correct -- I use the same process for 3D unstructured grids and everything seems to work. The residual function is also validated. As a test I did as you suggested
 -- assume the matrix is dense -- and </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:1.0pt;color:white">ZjQcmQRYFpfptBannerStart</span><o:p></o:p></p>
</div>
<div style="border:none;border-top:solid #90A4AE 3.0pt;padding:0in 0in 0in 0in;display:block!important;text-align:left!important;margin:0px!important;padding:16px!important;border-radius:4px!important;min-width:200px!important;background-color:#D0D8DC!important;border-top:#90a4ae!important" id="pfptBannerl1qrzjb">
<div id="pfptBannerl1qrzjb">
<div id="pfptBannerl1qrzjb">
<p class="MsoNormal" style="line-height:13.5pt;background:#D0D8DC"><b><span style="font-size:12.0pt;font-family:"Arial",sans-serif;color:black">This Message Is From an External Sender
</span></b><o:p></o:p></p>
</div>
<div id="pfptBannerl1qrzjb">
<p class="MsoNormal" style="line-height:13.5pt;background:#D0D8DC"><span style="font-size:12.0pt;font-family:"Arial",sans-serif;color:black">This message came from outside your organization.
</span><o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal" style="background:#D0D8DC"><span style="font-size:12.0pt;color:black"> </span><o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><span style="font-size:1.0pt;color:white">ZjQcmQRYFpfptBannerEnd</span><o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">The coloring I'm fairly confident is correct -- I use the same process for 3D unstructured grids and everything seems to work. The residual function is also validated.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">As a test I did as you suggested -- assume the matrix is dense -- and I get the same bad results, just now the zero blocks are filled.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">Assuming dense, giving it a constant vector, all is good:</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"> 4.23516e-16     -1.10266      0.31831   -0.0852909            0            0     -0.31831      1.18795<br>
     1.10266 -4.23516e-16     -1.18795      0.31831            0            0    0.0852909     -0.31831<br>
    -0.31831      1.18795  2.11758e-16     -1.10266      0.31831   -0.0852909            0            0<br>
   0.0852909     -0.31831      1.10266 -4.23516e-16     -1.18795      0.31831            0            0<br>
           0            0     -0.31831      1.18795  2.11758e-16     -1.10266      0.31831   -0.0852909<br>
           0            0    0.0852909     -0.31831      1.10266 -4.23516e-16     -1.18795      0.31831<br>
     0.31831   -0.0852909            0            0     -0.31831      1.18795  4.23516e-16     -1.10266</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">Assuming dense, giving it sin(x), all is bad:</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">-1.76177e+08 -6.07287e+07 -6.07287e+07 -1.76177e+08  1.76177e+08  6.07287e+07  6.07287e+07  1.76177e+08<br>
-1.31161e+08 -4.52116e+07 -4.52116e+07 -1.31161e+08  1.31161e+08  4.52116e+07  4.52116e+07  1.31161e+08<br>
 1.31161e+08  4.52116e+07  4.52116e+07  1.31161e+08 -1.31161e+08 -4.52116e+07 -4.52116e+07 -1.31161e+08<br>
 1.76177e+08  6.07287e+07  6.07287e+07  1.76177e+08 -1.76177e+08 -6.07287e+07 -6.07287e+07 -1.76177e+08<br>
 1.76177e+08  6.07287e+07  6.07287e+07  1.76177e+08 -1.76177e+08 -6.07287e+07 -6.07287e+07 -1.76177e+08<br>
 1.31161e+08  4.52116e+07  4.52116e+07  1.31161e+08 -1.31161e+08 -4.52116e+07 -4.52116e+07 -1.31161e+08<br>
-1.31161e+08 -4.52116e+07 -4.52116e+07 -1.31161e+08  1.31161e+08  4.52116e+07  4.52116e+07  1.31161e+08<br>
-1.76177e+08 -6.07287e+07 -6.07287e+07 -1.76177e+08  1.76177e+08  6.07287e+07  6.07287e+07  1.76177e+08</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">Scratching my head over here... I've been using these routines successfully for years in much more complex code.</span><o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><span style="font-size:12.0pt"> </span><o:p></o:p></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">On Sun, Apr 21, 2024 at 12:36</span><span style="font-size:12.0pt;font-family:"Arial",sans-serif"> </span><span style="font-size:12.0pt">PM Zou, Ling <<a href="mailto:lzou@anl.gov">lzou@anl.gov</a>> wrote:</span><o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">Edit:</span><o:p></o:p></p>
<ul type="disc">
<li class="m5206826287588213837msolistparagraph" style="mso-list:l1 level1 lfo1">
<span style="font-size:11.0pt">how do you do the coloring when using PETSc finite differencing? An incorrect coloring may give you wrong Jacobian.
<span style="color:black;background:yellow">For debugging purpose,</span> the simplest way to avoid an incorrect coloring is to assume the matrix is dense (slow but error proofing).
<span style="color:black;background:yellow">If the numeric converges as expected, then fine tune your coloring to make it right and fast.</span></span><o:p></o:p></li></ul>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<div id="m_5206826287588213837mail-editor-reference-message-container">
<div>
<div style="border:none;border-top:solid windowtext 1.0pt;padding:3.0pt 0in 0in 0in;border-color:currentcolor currentcolor">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;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 Zou, Ling via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>><br>
<b>Date: </b>Sunday, April 21, 2024 at 11:29 AM<br>
<b>To: </b>Mark Lohry <<a href="mailto:mlohry@gmail.com" target="_blank">mlohry@gmail.com</a>>, PETSc <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>><br>
<b>Subject: </b>Re: [petsc-users] finite difference jacobian errors when given non-constant initial condition</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">Hi Mark, I am working on a project having similar numeric you have, one-dimensional finite volume method with second-order slope limiter TVD, and PETSc finite differencing gives perfect Jacobian even for complex
 problems.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">So, I tend to believe that your implementation may have some problem. Some lessons I learned during my code development:</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<ul type="disc">
<li class="m5206826287588213837msolistparagraph" style="mso-list:l0 level1 lfo2">
<span style="font-size:11.0pt">how do you do the coloring when using PETSc finite differencing? An incorrect coloring may give you wrong Jacobian. The simplest way to avoid an incorrect coloring is to assume the matrix is dense (slow but error proofing).</span><o:p></o:p></li><li class="m5206826287588213837msolistparagraph" style="mso-list:l0 level1 lfo2">
<span style="font-size:11.0pt">Residual function evaluation not correctly implemented can also lead to incorrect Jacobian. In your case, you may want to take a careful look at the order of execution, when to update your unknown vector, when to perform P1 reconstruction,
 and when to evaluate the residual.</span><o:p></o:p></li></ul>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">-Ling</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<div id="m_5206826287588213837mail-editor-reference-message-container">
<div>
<div style="border:none;border-top:solid windowtext 1.0pt;padding:3.0pt 0in 0in 0in;border-color:currentcolor currentcolor">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;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 Mark Lohry <<a href="mailto:mlohry@gmail.com" target="_blank">mlohry@gmail.com</a>><br>
<b>Date: </b>Saturday, April 20, 2024 at 1:35 PM<br>
<b>To: </b>PETSc <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>><br>
<b>Subject: </b>[petsc-users] finite difference jacobian errors when given non-constant initial condition</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:1.0pt;color:white">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, </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:1.0pt;color:white">ZjQcmQRYFpfptBannerStart</span><o:p></o:p></p>
</div>
<div id="m_5206826287588213837pfptBannerovsgilx">
<div id="m_5206826287588213837pfptBannerovsgilx">
<p class="MsoNormal" style="line-height:13.5pt;background:#D0D8DC"><b><span style="font-size:12.0pt;font-family:"Arial",sans-serif;color:black">This Message Is From an External Sender
</span></b><o:p></o:p></p>
</div>
<div id="m_5206826287588213837pfptBannerovsgilx">
<p class="MsoNormal" style="line-height:13.5pt;background:#D0D8DC"><span style="font-size:12.0pt;font-family:"Arial",sans-serif;color:black">This message came from outside your organization.
</span><o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal" style="background:#D0D8DC"><span style="font-size:12.0pt;color:black"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:1.0pt;color:white">ZjQcmQRYFpfptBannerEnd</span><o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">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.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">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?</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">Analytically computed Jacobian:</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"> 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</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">petsc finite difference jacobian when given f(x)=1:</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"> 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</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">petsc finite difference jacobian when given f(x) = sin(x):</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">-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</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt"> </span><o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>