<div dir="ltr"><div dir="ltr">On Mon, Apr 15, 2019 at 5:03 AM Pierre Jolivet via petsc-dev <<a href="mailto:petsc-dev@mcs.anl.gov">petsc-dev@mcs.anl.gov</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word">OK, my solver is now working properly with a call to<div>PetscObjectCompose((PetscObject)isS, "pmat", (PetscObject) myS);</div><div><br></div><div>I have two follow-up questions:</div><div>1) am I supposed to call this, or is it the sign of something done wrong in my sequence of SNESSolve/KSPSetUp/KSPSetFromOptions/KSPSetOperators…?</div></div></blockquote><div><br></div><div>Yes, unfortunately. We want to let the user pass in preconditioning matrices for arbitrarily nested splits without pulling out</div><div>the objects explicitly, so we need a way to locate a particular split. I guess you could imagine using the prefix, which would</div><div>be an XML way of doing things. We are doing it by attaching things to the IS, since the Solver/Mat objects are created on the</div><div>fly. In fact, the IS is created on the fly by a DM sometimes, so you can attach to the DM (I do this for Plex).</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div>2) I have currently hardwired the split name I’m using when calling PCFieldSplitGetIS to get “isS” (from above) for debugging purposes. Could I create a PR with a new function like PCFieldSplitGetISByIndex(PC pc,const PetscInt n,IS *is) that will return the nth IS? Right now, I would need to get the KSP prefix followed up by some string comparison to get the actual IS prefix, whereas I know the position of the KSP in the PC_FieldSplitLink.</div></div></blockquote><div><br></div><div>That sounds fine to me.</div><div><br></div><div>   Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div>Thanks,</div><div>Pierre<br><div><br><blockquote type="cite"><div>On 14 Apr 2019, at 10:54 PM, Pierre Jolivet via petsc-dev <<a href="mailto:petsc-dev@mcs.anl.gov" target="_blank">petsc-dev@mcs.anl.gov</a>> wrote:</div><br class="gmail-m_1250767179641375552Apple-interchange-newline"><div><div style="word-wrap:break-word">I think I figured out what my problem is _exactly_.<div>The Mat inside the MATNEST on which I’m using a PCFIELDSPLIT is unassembled before the first KSPSolve, except for the last field.</div><div>Matt, you nailed it, when I call KSPSetFromOptions on the global PCFIELDSPLIT, then KSPSetUp explicitly on the inner PCFIELDSPLIT, the matrices associated to all fields are created here: <a href="https://www.mcs.anl.gov/petsc/petsc-current/src/ksp/pc/impls/fieldsplit/fieldsplit.c.html#line656" target="_blank">https://www.mcs.anl.gov/petsc/petsc-current/src/ksp/pc/impls/fieldsplit/fieldsplit.c.html#line656</a></div><div>Then, whatever I do with the matrix from the last field, currently trying MatCopy(myAssembledS, generatedS), before the first KSPSolve is reset by <a href="https://www.mcs.anl.gov/petsc/petsc-current/src/ksp/pc/impls/fieldsplit/fieldsplit.c.html#line688" target="_blank">https://www.mcs.anl.gov/petsc/petsc-current/src/ksp/pc/impls/fieldsplit/fieldsplit.c.html#line688</a> and my solver fails…</div><div><br></div><div>So pretty simple question, how do I set a “pmat” for my last assembled field so that <a href="https://www.mcs.anl.gov/petsc/petsc-current/src/ksp/pc/impls/fieldsplit/fieldsplit.c.html#line646" target="_blank">https://www.mcs.anl.gov/petsc/petsc-current/src/ksp/pc/impls/fieldsplit/fieldsplit.c.html#line646</a> and <a href="https://www.mcs.anl.gov/petsc/petsc-current/src/ksp/pc/impls/fieldsplit/fieldsplit.c.html#line686" target="_blank">https://www.mcs.anl.gov/petsc/petsc-current/src/ksp/pc/impls/fieldsplit/fieldsplit.c.html#line686</a> will return a non null pmat.</div><div><br></div><div>This may sound really trivial but I’m lost in limbo right now. When everything is not wrapped inside an outer PCFIELDSPLIT, everything just work.</div><div><br></div><div>Thanks,</div><div>Pierre</div><div><div><br><blockquote type="cite"><div>On 25 Mar 2019, at 6:57 PM, Pierre Jolivet via petsc-dev <<a href="mailto:petsc-dev@mcs.anl.gov" target="_blank">petsc-dev@mcs.anl.gov</a>> wrote:</div><br class="gmail-m_1250767179641375552Apple-interchange-newline"><div><div style="word-wrap:break-word">Thanks, this makes (slightly) more sense to me know.<div>For some reason my application is still not acting properly but I must be screwing somewhere else the nested FieldSplit…</div><div><br></div><div>Thank you,</div><div>Pierre<br><div><div><br><blockquote type="cite"><div>On 24 Mar 2019, at 11:42 PM, Dave May via petsc-dev <<a href="mailto:petsc-dev@mcs.anl.gov" target="_blank">petsc-dev@mcs.anl.gov</a>> wrote:</div><br class="gmail-m_1250767179641375552Apple-interchange-newline"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Matt is right.<div><br></div><div>When you defined the operator S, you basically invalidate the operator N (in the sense that they are no longer consistent). Hence when you use KSP nest to solve your problem your A matrix looks like </div><div><div>  A = diag[1, 2, 4, 0, 8]</div></div><div>but the B matrix you have defined looks like</div><div><div>  B = diag[1, 2, 4, 0.00001]</div></div><div><br></div><div>The only way to obtain the correct answer with your code is thus to use the option</div><div>-ksp_type preonly<br></div><div><br></div><div>Thanks</div><div>Dave</div><div><br><div><br></div></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, 24 Mar 2019 at 22:09, Mark Adams via petsc-dev <<a href="mailto:petsc-dev@mcs.anl.gov" target="_blank">petsc-dev@mcs.anl.gov</a>> wrote:<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 dir="ltr">I think he is saying that this line seems to have no effect (and the comment is hence wrong):<div><br></div><div><pre class="gmail-m_1250767179641375552gmail-m_8767326949575149941gmail-m_928777800623408844gmail-aLF-aPX-K0-aPE" style="font-family:"Courier New",Courier,monospace,arial,sans-serif;margin-top:0px;margin-bottom:0px;white-space:pre-wrap;font-size:14px">KSPSetOperators(subksp[nsplits - 1], S, S);</pre></div><div><pre class="gmail-m_1250767179641375552gmail-m_8767326949575149941gmail-m_928777800623408844gmail-aLF-aPX-K0-aPE" style="margin-top:0px;margin-bottom:0px"><pre class="gmail-m_1250767179641375552gmail-m_8767326949575149941gmail-m_928777800623408844gmail-aLF-aPX-K0-aPE" style="font-family:"Courier New",Courier,monospace,arial,sans-serif;font-size:14px;white-space:pre-wrap;margin-top:0px;margin-bottom:0px">// J2 = [[4, 0] ; [0, 0.00001]]</pre><pre class="gmail-m_1250767179641375552gmail-m_8767326949575149941gmail-m_928777800623408844gmail-aLF-aPX-K0-aPE" style="font-family:"Courier New",Courier,monospace,arial,sans-serif;font-size:14px;white-space:pre-wrap;margin-top:0px;margin-bottom:0px"><br></pre><font face="arial, helvetica, sans-serif">J2 is a 2x2 but this block has been changed into two single equation fields. Does this KSPSetOperators supposed to copy this 1x1 S matrix into the (1,1) block of the "J2", or do some sort of correct mixing internally, to get what he wants?</font><br></pre><pre class="gmail-m_1250767179641375552gmail-m_8767326949575149941gmail-m_928777800623408844gmail-aLF-aPX-K0-aPE" style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><br></font></pre><pre class="gmail-m_1250767179641375552gmail-m_8767326949575149941gmail-m_928777800623408844gmail-aLF-aPX-K0-aPE" style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif">BTW, this line does not seem necessary to me so maybe I'm missing something.</font></pre><pre class="gmail-m_1250767179641375552gmail-m_8767326949575149941gmail-m_928777800623408844gmail-aLF-aPX-K0-aPE" style="margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><br></font></pre><pre class="gmail-m_1250767179641375552gmail-m_8767326949575149941gmail-m_928777800623408844gmail-aLF-aPX-K0-aPE" style="margin-top:0px;margin-bottom:0px"><pre class="gmail-m_1250767179641375552gmail-m_8767326949575149941gmail-m_928777800623408844gmail-aLF-aPX-K0-aPE" style="font-family:"Courier New",Courier,monospace,arial,sans-serif;margin-top:0px;margin-bottom:0px;white-space:pre-wrap;font-size:14px">KSPSetOperators(sub, J2, J2);</pre><pre class="gmail-m_1250767179641375552gmail-m_8767326949575149941gmail-m_928777800623408844gmail-aLF-aPX-K0-aPE" style="font-family:"Courier New",Courier,monospace,arial,sans-serif;margin-top:0px;margin-bottom:0px;white-space:pre-wrap;font-size:14px"><br></pre></pre></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Mar 24, 2019 at 4:33 PM Matthew Knepley via petsc-dev <<a href="mailto:petsc-dev@mcs.anl.gov" target="_blank">petsc-dev@mcs.anl.gov</a>> wrote:<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 dir="ltr"><div dir="ltr">On Sun, Mar 24, 2019 at 10:21 AM Pierre Jolivet <<a href="mailto:pierre.jolivet@enseeiht.fr" target="_blank">pierre.jolivet@enseeiht.fr</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>It’s a 4x4 matrix.<div>The first 2x2 diagonal matrix is a field.<div>The second 2x2 diagonal matrix is another field.</div><div>In the second field, the first diagonal coefficient is a subfield.</div><div>In the second field, the second diagonal coefficient is another subfield.</div><div>I’m changing the operators from the second subfield (last diagonal coefficient of the matrix).</div><div>When I solve a system with the complete matrix (2 fields), I get a different “partial solution" than when I solve the “partial system” on just the second field (with the two subfields in which I modified the operators from the second one).</div></div></div></blockquote><div><br></div><div>I may understand waht you are doing.</div><div>Fieldsplit calls MatGetSubMatrix() which can copy values, depending on the implementation,</div><div>so changing values in the original matrix may or may not change it in the PC.</div><div> </div><div>   Matt</div><div><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><div><div>I don’t know if this makes more or less sense… sorry :\</div><div>Thanks,</div><div>Pierre<br><div><br><blockquote type="cite"><div>On 24 Mar 2019, at 8:42 PM, Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>> wrote:</div><br class="gmail-m_1250767179641375552gmail-m_8767326949575149941gmail-m_928777800623408844gmail-m_4707396507371526411gmail-m_-4800910044753334158Apple-interchange-newline"><div><div dir="ltr"><div dir="ltr">On Sat, Mar 23, 2019 at 9:12 PM Pierre Jolivet via petsc-dev <<a href="mailto:petsc-dev@mcs.anl.gov" target="_blank">petsc-dev@mcs.anl.gov</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I’m trying to figure out why both solutions are not consistent in the following example.<br>
Is what I’m doing complete nonsense?<br></blockquote><div><br></div><div>The code does not make clear what you are asking. I can see its a nested fieldsplit.</div><div><br></div><div>  Thanks,</div><div><br></div><div>     Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Thanks in advance for your help,<br>
Pierre<br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail-m_1250767179641375552gmail-m_8767326949575149941gmail-m_928777800623408844gmail-m_4707396507371526411gmail-m_-4800910044753334158gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>
</div></blockquote></div><br></div></div></div></blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail-m_1250767179641375552gmail-m_8767326949575149941gmail-m_928777800623408844gmail-m_4707396507371526411gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>
</blockquote></div>
</blockquote></div>
</div></blockquote></div><br></div></div></div></div></blockquote></div><br></div></div></div></blockquote></div><br></div></div></blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>