<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Qi<div class=""><br class=""></div><div class="">Backward Euler is a special case of Theta methods in PETSc (Theta=1). In src/ts/impls/implicit/theta/theta.c on top of SNESTSFormFunction_Theta you have some explanation of what is solved for at each time step (see below). SNES then solves for the Newton update dy_n and the next Newton iterate is computed as x_{n+1} = x_{n} - lambda * dy_n. Hope this helps.</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 21px; line-height: normal; font-family: Menlo; color: rgb(64, 11, 217);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">/*</span></div><div style="margin: 0px; font-stretch: normal; font-size: 21px; line-height: normal; font-family: Menlo; color: rgb(64, 11, 217);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> This defines the nonlinear equation that is to be solved with SNES</span></div><div style="margin: 0px; font-stretch: normal; font-size: 21px; line-height: normal; font-family: Menlo; color: rgb(64, 11, 217);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> G(U) = F[t0+Theta*dt, U, (U-U0)*shift] = 0</span></div><div style="margin: 0px; font-stretch: normal; font-size: 21px; line-height: normal; font-family: Menlo; min-height: 24px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 21px; line-height: normal; font-family: Menlo; color: rgb(64, 11, 217);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> Note that U here is the stage argument. This means that U = U_{n+1} only if endpoint = true,</span></div><div style="margin: 0px; font-stretch: normal; font-size: 21px; line-height: normal; font-family: Menlo; color: rgb(64, 11, 217);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> otherwise U = theta U_{n+1} + (1 - theta) U0, which for the case of implicit midpoint is</span></div><div style="margin: 0px; font-stretch: normal; font-size: 21px; line-height: normal; font-family: Menlo; color: rgb(64, 11, 217);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> U = (U_{n+1} + U0)/2</span></div><div style="margin: 0px; font-stretch: normal; font-size: 21px; line-height: normal; font-family: Menlo; color: rgb(64, 11, 217);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">*/</span></div><div style="margin: 0px; font-stretch: normal; font-size: 21px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #2fb41d" class="">static</span><span style="font-variant-ligatures: no-common-ligatures" class=""> PetscErrorCode SNESTSFormFunction_Theta(SNES snes,Vec x,Vec y,TS ts)</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div><br class=""><blockquote type="cite" class=""><div class="">On Jul 14, 2021, at 6:12 AM, Tang, Qi <<a href="mailto:tangqi@msu.edu" class="">tangqi@msu.edu</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<div class="">Hi,</div>
<div class=""><br class="">
</div>
<div class="">During the process to experiment the suggestion Matt made, we ran into some questions regarding to TSSolve vs KSPSolve. We got different initial unpreconditioned residual using two solvers. Let’s say we solve the problem with backward Euler and
there is no rhs. We guess TSSolve solves</div>
<div class="">(U^{n+1}-U^n)/dt = A U^{n+1}.</div>
<div class="">(We only provides IJacobian in this case and turn on TS_LINEAR.)</div>
<div class="">So we guess the initial unpreconditioned residual would be ||U^n/dt||_2, which seems different from the residual we got from a backward Euler stepping we implemented by ourself through KSPSolve.</div>
<div class=""><br class="">
</div>
<div class="">Do we have some misunderstanding on TSSolve? </div>
<div class=""><br class="">
</div>
<div class="">Thanks,</div>
<div class="">
<div class="">Qi</div>
<div class="">T5@LANL</div>
<div class=""><br class="">
</div>
<br class="Apple-interchange-newline">
</div>
<div class=""><br class="">
<blockquote type="cite" class="">
<div class="">On Jul 7, 2021, at 3:54 PM, Matthew Knepley <<a href="mailto:knepley@gmail.com" class="">knepley@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 16px; 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;" class="">
<div dir="ltr" class="">On Wed, Jul 7, 2021 at 2:33 PM Jorti, Zakariae <<a href="mailto:zjorti@lanl.gov" class="">zjorti@lanl.gov</a>> wrote:<br class="">
</div>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;">
<div class="">
<div id="gmail-m_4217968377908507552divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;" class=""><p class="">Hi Matt,</p><p class=""><br class="">
</p><p class="">Thanks for your quick reply. </p><p class="">I have not completely understood your suggestion, could you please elaborate a bit more? </p><p class="">For your convenience, here is how I am proceeding for the moment in my code: </p><p class=""><br class="">
</p><p class="">TSGetKSP(ts,&ksp);<br class="">
</p><p class="">KSPGetPC(ksp,&pc); <br class="">
</p><p class="">PCSetType(pc,PCFIELDSPLIT);</p><p class="">PCFieldSplitSetDetectSaddlePoint(pc,PETSC_TRUE);</p><p class="">PCSetUp(pc);</p><p class="">PCFieldSplitGetSubKSP(pc, &n, &subksp);</p><p class="">KSPGetPC(subksp[1], &(subpc[1]));</p>
</div>
</div>
</blockquote>
<div class="">I do not like the two lines above. We should not have to do this. <br class="">
</div>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;">
<div class="">
<div id="gmail-m_4217968377908507552divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;" class=""><p class=""><span style="font-size: 12pt;" class="">KSPSetOperators(subksp[1],T,T);</span></p>
</div>
</div>
</blockquote>
<div class=""> In the above line, I want you to use a separate preconditioning matrix M, instead of T. That way, it will provide<br class="">
</div>
<div class="">the preconditioning matrix for your Schur complement problem.</div>
<div class=""><br class="">
</div>
<div class=""> Thanks,</div>
<div class=""><br class="">
</div>
<div class=""> Matt</div>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;">
<div class="">
<div id="gmail-m_4217968377908507552divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;" class=""><p class=""><span style="font-size: 12pt;" class="">KSPSetUp(subksp[1]);</span><br class="">
</p><p class="">PetscFree(subksp);</p><p class="">TSSolve(ts,X);<br class="">
</p><p class=""><br class="">
</p><p class="">Thank you.</p><p class="">Best,</p><p class=""><br class="">
</p><p class="">Zakariae</p>
</div>
<hr style="display: inline-block; width: 1015.21875px;" class="">
<div id="gmail-m_4217968377908507552divRplyFwdMsg" dir="ltr" class=""><font face="Calibri, sans-serif" style="font-size: 11pt;" class=""><b class="">From:</b><span class="Apple-converted-space"> </span>Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank" class="">knepley@gmail.com</a>><br class="">
<b class="">Sent:</b><span class="Apple-converted-space"> </span>Wednesday, July 7, 2021 12:11:10 PM<br class="">
<b class="">To:</b><span class="Apple-converted-space"> </span>Jorti, Zakariae<br class="">
<b class="">Cc:</b><span class="Apple-converted-space"> </span><a href="mailto:petsc-users@mcs.anl.gov" target="_blank" class="">petsc-users@mcs.anl.gov</a>; Tang, Qi; Tang, Xianzhu<br class="">
<b class="">Subject:</b><span class="Apple-converted-space"> </span>[EXTERNAL] Re: [petsc-users] Problem with PCFIELDSPLIT</font>
<div class=""> </div>
</div>
<div class="">
<div dir="ltr" class="">
<div dir="ltr" class="">On Wed, Jul 7, 2021 at 1:51 PM Jorti, Zakariae via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank" class="">petsc-users@mcs.anl.gov</a>> wrote:<br class="">
</div>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;">
<div dir="ltr" class="">
<div id="gmail-m_4217968377908507552gmail-m_4230588803823514004divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; font-family: Calibri, Helvetica, sans-serif, Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" class=""><p class="">Hi,</p><p class=""><br class="">
</p><p class="">I am trying to build a PCFIELDSPLIT preconditioner for a matrix </p><p class="">J = [A00 A01]</p><p class=""> [A10 A11] </p><p class="">that has the following shape: </p><p class=""><br class="">
</p><p class="">M_{user}^{-1} = [I -ksp(A00) A01] [ksp(A00) 0] [I 0]</p><p class=""> [0 I] [0 ksp(T)] [-A10 ksp(A00) I ]<br class="">
</p><p class=""><br class="">
</p><p class="">where T is a user-defined Schur complement approximation that replaces the true Schur complement S:= A11 - A10 ksp(A00) A01.</p><p class=""><br class="">
</p><p class="">I am trying to do something similar to this example (lines 41--45 and 116--121): <a href="https://urldefense.com/v3/__https://www.mcs.anl.gov/petsc/petsc-current/src/snes/tutorials/ex70.c.html__;!!HXCxUKc!hoEfgnaraTfQoSgAiplsc6GJ_HuPXN88m5AJVy1gb7WVMNkGENDnJ3zToOGlhw$" id="gmail-m_4217968377908507552gmail-m_4230588803823514004LPlnk826214" target="_blank" class="">https://www.mcs.anl.gov/petsc/petsc-current/src/snes/tutorials/ex70.c.html</a></p><p class=""><br class="">
</p><p class="">The problem I have is that I manage to replace S with T on a separate single linear system but not for the linear systems generated by my time-dependent PDE. Even if I set the preconditioner <span style="font-size: 12pt;" class="">M_{user}^{-1}
correctly, the T matrix gets replaced by S in the preconditioner once I call TSSolve. </span></p><p class=""><span style="font-size: 12pt;" class="">Do you have any suggestions how to fix this knowing that the matrix J does not change over time?</span></p>
<div class=""><span style="font-size: 12pt;" class=""></span><br class="webkit-block-placeholder">
</div>
</div>
</div>
</blockquote>
<div class="">I don't like how it is done in that example for this very reason.</div>
<div class=""><br class="">
</div>
<div class="">When I want to use a custom preconditioning matrix for the Schur complement, I always give a preconditioning matrix M to the outer solve.</div>
<div class="">Then PCFIELDSPLIT automatically pulls the correct block from M, (1,1) for the Schur complement, for that preconditioning matrix without</div>
<div class="">extra code. Can you do this?</div>
<div class=""><br class="">
</div>
<div class=""> Thanks,</div>
<div class=""><br class="">
</div>
<div class=""> Matt</div>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;">
<div dir="ltr" class="">
<div id="gmail-m_4217968377908507552gmail-m_4230588803823514004divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; font-family: Calibri, Helvetica, sans-serif, Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" class=""><p class=""><span style="font-size: 12pt;" class="">Many thanks.</span></p><p class=""><span style="font-size: 12pt;" class=""><br class="">
</span></p><p class=""><span style="font-size: 12pt;" class="">Best regards,</span></p><p class=""><span style="font-size: 12pt;" class=""><br class="">
</span></p><p class=""><span style="font-size: 12pt;" class="">Zakariae </span></p>
<div class=""><span style="font-size: 12pt;" class=""></span><br class="webkit-block-placeholder">
</div>
</div>
</div>
</blockquote>
</div>
<br clear="all" class="">
<div class=""><br class="">
</div>
--<span class="Apple-converted-space"> </span><br class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div class="">
<div dir="ltr" class="">
<div class="">
<div dir="ltr" class="">
<div class="">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br class="">
-- Norbert Wiener</div>
<div class=""><br class="">
</div>
<div class=""><a href="https://urldefense.com/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!HXCxUKc!hoEfgnaraTfQoSgAiplsc6GJ_HuPXN88m5AJVy1gb7WVMNkGENDnJ3wB3dcMFw$" target="_blank" class="">https://www.cse.buffalo.edu/~knepley/</a><br class="">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br clear="all" class="">
<div class=""><br class="">
</div>
--<span class="Apple-converted-space"> </span><br class="">
<div dir="ltr" class="gmail_signature">
<div dir="ltr" class="">
<div class="">
<div dir="ltr" class="">
<div class="">
<div dir="ltr" class="">
<div class="">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br class="">
-- Norbert Wiener</div>
<div class=""><br class="">
</div>
<div class=""><a href="https://urldefense.com/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!HXCxUKc!hoEfgnaraTfQoSgAiplsc6GJ_HuPXN88m5AJVy1gb7WVMNkGENDnJ3wB3dcMFw$" target="_blank" class="">https://www.cse.buffalo.edu/~knepley/</a></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</div></blockquote></div><br class=""></div></body></html>