<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p><br>
    </p>
    <div class="moz-cite-prefix">Il 07/11/25 02:10, Barry Smith ha
      scritto:<br>
    </div>
    <blockquote type="cite" cite="mid:45F50A6B-E163-4750-A970-E7AE504A1B38@petsc.dev">
      
      <br id="lineBreakAtBeginningOfMessage">
      <div><br>
        <blockquote type="cite">
          <div>On Nov 6, 2025, at 4:11 AM, Stefano Zampini
            <a class="moz-txt-link-rfc2396E" href="mailto:stefano.zampini@gmail.com"><stefano.zampini@gmail.com></a> wrote:</div>
          <br class="Apple-interchange-newline">
          <div>
            <div dir="ltr">Matteo
              <div><br>
              </div>
              <div>eventually (and in some sense counterintuitively) the
                DM stores the information on the problem, not SNES. </div>
            </div>
          </div>
        </blockquote>
        <div><br>
        </div>
          "The information on the problem" here means the function you
        set with SNESSetFunction, SNESSetJacobian etc. (and possibly
        other stuff, I am not sure).</div>
    </blockquote>
    <p>Oddly, sometimes the two SNES seems to work nevertheless, but after
      your anwers I will make sure that I explicitly DMClone when I need
      more that 1 snes.</p>
    <p>Matteo</p>
    <p><br>
    </p>
    <blockquote type="cite" cite="mid:45F50A6B-E163-4750-A970-E7AE504A1B38@petsc.dev">
      <div><br>
      </div>
      <div><br>
        <blockquote type="cite">
          <div>
            <div dir="ltr">
              <div>See the snippet below to make things more clear</div>
            </div>
          </div>
        </blockquote>
        <blockquote type="cite">
          <div dir="ltr">
            <div><br>
            </div>
            <div>SNESSetDM(snes1,dm)</div>
            <div>SNESSetFunction(snes1,F)</div>
            <div>SNESSolve(snes1) // Solves F(x)=0 
              <div><br>
              </div>
              <div>SNESSetDM(snes2,dm)</div>
              <div>SNESSetFunction(snes2,G)</div>
              <div>SNESSolve(snes2) // Solves G(x)=0 
                <div><br>
                </div>
              </div>
              <div>SNESSolve(snes1) // Solves G(x), not F(x)!!</div>
              <div><br>
              </div>
              <div>If you have a plex you can call DMClone(dm,dm2) and
                set a new section on dm2 to be used on snes2 (the mesh
                won't be duplicated, only the problem dependent part)</div>
              <div>I guess you can follow the same approach with a DMDA,
                it should work. If not, you may need to call DMDuplicate
                on the DMDA.</div>
              <div><br>
              </div>
              <div><br>
              </div>
            </div>
          </div>
          <br>
          <div class="gmail_quote gmail_quote_container">
            <div dir="ltr" class="gmail_attr">Il giorno gio 6 nov 2025
              alle ore 11:19 Matteo Semplice via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" moz-do-not-send="true" class="moz-txt-link-freetext">petsc-users@mcs.anl.gov</a>>
              ha scritto:<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>
                <p>Dear Barry,</p>
                <p>    sorry for jumping into this.</p>
                <p><br>
                </p>
                <p>I am wondering if your reply is related to DMDA or to
                  DM in general. I have at least one code where I do
                  something similar to what Samuele did in his sample
                  code: create a DMPlex, create a section on this
                  DMPlex, create two SNES solving for Vecs defined on
                  that same section and attach to each of them a
                  different SNESFunction and SNESJacobian (one solves a
                  predictor and the other is a corrector). Everything
                  seems fine, but I am wondering if that code is
                  somewhat weak and should be changed by DMCloning the
                  plex as you suggested to Samuele.</p>
                <p><br>
                </p>
                <p>Thanks</p>
                <p>    Matteo</p>
                <p><br>
                </p>
                <div>On 06/11/2025 07:49, Samuele Ferri wrote:<br>
                </div>
                <blockquote type="cite">
                  <table border="0" cellspacing="0" cellpadding="0" width="100%" style="background:revert;color:revert;direction:revert;font-size:revert;height:revert;letter-spacing:revert;line-height:revert;margin:revert;opacity:revert;outline:revert;overflow:revert;padding:revert;text-align:revert;text-indent:revert;text-orientation:revert;text-overflow:revert;text-transform:revert;vertical-align:revert;white-space:revert;word-break:revert;word-spacing:revert;writing-mode:revert;zoom:revert;border:0px;display:table;width:100%;table-layout:fixed;float:none;border-spacing:0px" align="left">
                    <tbody style="background:revert;border:revert;color:revert;direction:revert;font-size:revert;height:revert;letter-spacing:revert;line-height:revert;margin:revert;opacity:revert;outline:revert;overflow:revert;padding:revert;table-layout:revert;text-align:revert;text-indent:revert;text-orientation:revert;text-overflow:revert;text-transform:revert;vertical-align:revert;white-space:revert;width:revert;word-break:revert;word-spacing:revert;writing-mode:revert;zoom:revert;display:block">
                      <tr style="background:revert;border:revert;color:revert;direction:revert;display:revert;font-size:revert;height:revert;letter-spacing:revert;line-height:revert;margin:revert;opacity:revert;outline:revert;overflow:revert;padding:revert;table-layout:revert;text-align:revert;text-indent:revert;text-orientation:revert;text-overflow:revert;text-transform:revert;vertical-align:revert;white-space:revert;width:revert;word-break:revert;word-spacing:revert;writing-mode:revert;zoom:revert">
                        <td valign="middle" width="1px" bgcolor="#A6A6A6" cellpadding="7px 2px 7px 2px" style="background-image:revert;background-position:revert;background-size:revert;background-repeat:revert;background-origin:revert;background-clip:revert;border:revert;color:revert;direction:revert;display:revert;font-size:revert;height:revert;letter-spacing:revert;line-height:revert;margin:revert;opacity:revert;outline:revert;overflow:revert;table-layout:revert;text-align:revert;text-indent:revert;text-orientation:revert;text-overflow:revert;text-transform:revert;vertical-align:revert;white-space:revert;word-break:revert;word-spacing:revert;writing-mode:revert;zoom:revert;padding:7px 2px;background-color:rgb(166,166,166);width:0px"><br>
                        </td>
                        <td valign="middle" width="100%" bgcolor="#EAEAEA" cellpadding="7px 5px 7px 15px" style="background-image:revert;background-position:revert;background-size:revert;background-repeat:revert;background-origin:revert;background-clip:revert;border:revert;direction:revert;display:revert;height:revert;letter-spacing:revert;line-height:revert;margin:revert;opacity:revert;outline:revert;overflow:revert;table-layout:revert;text-indent:revert;text-orientation:revert;text-overflow:revert;text-transform:revert;vertical-align:revert;white-space:revert;word-break:revert;word-spacing:revert;writing-mode:revert;zoom:revert;width:100%;background-color:rgb(234,234,234);padding:7px 5px 7px 15px;font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif;font-size:12px;font-weight:normal;color:rgb(33,33,33);text-align:left">
                          <div style="background:revert;border:revert;color:revert;direction:revert;display:revert;font-size:revert;height:revert;letter-spacing:revert;line-height:revert;margin:revert;opacity:revert;outline:revert;overflow:revert;padding:revert;table-layout:revert;text-align:revert;text-indent:revert;text-orientation:revert;text-overflow:revert;text-transform:revert;vertical-align:revert;white-space:revert;width:revert;word-break:revert;word-spacing:revert;writing-mode:revert;zoom:revert">
                            <a href="mailto:sale987@live.com" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">sale987@live.com</a>
                            sembra simile a un utente che in precedenza
                            ti ha inviato un messaggio di posta
                            elettronica, ma potrebbe non essere lo
                            stesso. <a href="https://urldefense.us/v3/__https://aka.ms/LearnAboutSenderIdentification__;!!G_uCfscf7eWS!d2x1h3Pt9OqhfeBcqW8pR0dbGy3bRw6bM-p0DxGAaY0CXWkqH3lpsuXiob9mOqfsy-aRVJXUig3819n2CWpYyFn4FDaTAWRxNDXZsA$" style="background:revert;color:revert;direction:revert;display:revert;font-size:revert;opacity:revert" target="_blank" moz-do-not-send="true">
                              Scopri perché potrebbe trattarsi di un
                              rischio</a> </div>
                        </td>
                        <td valign="middle" align="left" width="75px" bgcolor="#EAEAEA" cellpadding="7px 5px 7px 5px" style="background-image:revert;background-position:revert;background-size:revert;background-repeat:revert;background-origin:revert;background-clip:revert;border:revert;direction:revert;display:revert;height:revert;letter-spacing:revert;line-height:revert;margin:revert;opacity:revert;outline:revert;overflow:revert;table-layout:revert;text-indent:revert;text-orientation:revert;text-overflow:revert;text-transform:revert;vertical-align:revert;white-space:revert;word-break:revert;word-spacing:revert;writing-mode:revert;zoom:revert;width:75px;background-color:rgb(234,234,234);padding:7px 5px;font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif;font-size:12px;font-weight:normal;color:rgb(33,33,33);text-align:left"><br>
                        </td>
                      </tr>
                    </tbody>
                  </table>
                  <div>
                    <div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
                      Dear Barry,</div>
                    <div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;"> <br>
                    </div>
                    <div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
                      thank you for your reply. Now everything works
                      fine.</div>
                    <div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;"> <br>
                    </div>
                    <div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
                      Best regards</div>
                    <div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
                      Samuele</div>
                    <hr style="display:inline-block;width:98%">
                    <div id="m_-685146062800039339divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt"><b>Da:</b> Barry Smith <a href="mailto:bsmith@petsc.dev" target="_blank" moz-do-not-send="true"><bsmith@petsc.dev></a><br>
                        <b>Inviato:</b> mercoledì 5 novembre 2025 15:47<br>
                        <b>A:</b> Samuele Ferri <a href="mailto:sale987@live.com" target="_blank" moz-do-not-send="true"><sale987@live.com></a><br>
                        <b>Cc:</b> <a href="mailto:petsc-users@mcs.anl.gov" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">petsc-users@mcs.anl.gov</a>
                        <a href="mailto:petsc-users@mcs.anl.gov" target="_blank" moz-do-not-send="true"><petsc-users@mcs.anl.gov></a><br>
                        <b>Oggetto:</b> Re: [petsc-users] Two SNES on
                        the same DM not working</font>
                      <div> </div>
                    </div>
                    <div>
                      <div><br>
                      </div>
                         This is not supported. Duplicate your DM.<br id="m_-685146062800039339x_lineBreakAtBeginningOfMessage">
                      <div><br>
                        <blockquote type="cite">
                          <div>On Nov 5, 2025, at 9:17 AM, Samuele Ferri
                            <a href="mailto:sale987@live.com" target="_blank" moz-do-not-send="true"><sale987@live.com></a>
                            wrote:</div>
                          <br>
                          <div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              Dear petsc users,</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              <br>
                            </div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              in petsc version 3.24, I'm trying to
                              create two snes over the same DM, but with
                              different functions and jacobians. Despite
                              making different calls to SNESSetFunction
                              it happens the second snes uses the same
                              function of the first.</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              Can you help me finding the problem,
                              please?</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              <br>
                            </div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              Here below there is a minimal working
                              example showing the issue:</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              <br>
                            </div>
                            <div style="font-family:Helvetica;font-size:18px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">
                              <div style="line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                static char help[] = "Test SNES.\n";</div>
                            </div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              #include <petscsys.h></div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              #include <petscdmda.h></div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              #include <petscsnes.h><br>
                              <br>
                            </div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              PetscErrorCode Jac_1(SNES<span> </span><i>snes</i>,
                              Vec<span> </span><i>x</i>, Mat<span> </span><i>J</i>,
                              Mat<span> </span><i>B</i>, void *){</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscFunctionBegin;</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  printf("Jac 1\n");</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscFunctionReturn(PETSC_SUCCESS);</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              }</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              <br>
                            </div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              PetscErrorCode Function_1(SNES<span> </span><i>snes</i>,
                              Vec<span> </span><i>x</i>, Vec<span> </span><i>f</i>,
                              void *){</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscFunctionBegin;</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  printf("Function 1\n");</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscFunctionReturn(PETSC_SUCCESS);</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              }</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              <br>
                            </div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              PetscErrorCode Jac_2(SNES<span> </span><i>snes</i>,
                              Vec<span> </span><i>x</i>, Mat<span> </span><i>J</i>,
                              Mat<span> </span><i>B</i>, void *){</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscFunctionBegin;</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  printf("Jac 2\n");</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscFunctionReturn(PETSC_SUCCESS);</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              }</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              <br>
                            </div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              PetscErrorCode Function_2(SNES<span> </span><i>snes</i>,
                              Vec<span> </span><i>x</i>, Vec<span> </span><i>f</i>,
                              void *){</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscFunctionBegin;</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  printf("Function 2\n");</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscFunctionReturn(PETSC_SUCCESS);</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              }<br>
                              <br>
                            </div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              int main(int<span> </span><i>argc</i>,
                              char **<i>argv</i>) {</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              <br>
                            </div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscFunctionBeginUser;</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(PetscInitialize(&<i>argc</i>,
                              &<i>argv</i>, NULL, help));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              <br>
                            </div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  DM dm;</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                 
                              PetscCall(DMDACreate1d(PETSC_COMM_WORLD,
                              DM_BOUNDARY_NONE, 100, 1, 1, NULL,
                              &dm));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(DMSetFromOptions(dm));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(DMSetUp(dm));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              <br>
                            </div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  SNES snes1, snes2;</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  Vec r1,r2;</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  Mat J1, J2;</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              <br>
                            </div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(DMCreateGlobalVector(dm,
                              &r1));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(DMCreateGlobalVector(dm,
                              &r2))</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(DMCreateMatrix(dm,
                              &J1));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(DMCreateMatrix(dm,
                              &J2));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              <br>
                            </div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(SNESCreate(PETSC_COMM_WORLD,
                              &snes1));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(SNESCreate(PETSC_COMM_WORLD,
                              &snes2));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(SNESSetType(snes1,
                              SNESNEWTONLS));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(SNESSetType(snes2,
                              SNESNEWTONLS));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(SNESSetFromOptions(snes1));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(SNESSetFromOptions(snes2));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(SNESSetFunction(snes1, r1,
                              Function_1, NULL));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(SNESSetFunction(snes2, r2,
                              Function_2, NULL));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(SNESSetJacobian(snes1, J1,
                              J1, Jac_1, NULL));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(SNESSetJacobian(snes2, J2,
                              J2, Jac_2, NULL));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(SNESSetDM(snes1, dm));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(SNESSetDM(snes2, dm));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              <br>
                            </div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(SNESSolve(snes1, NULL,
                              NULL));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(SNESSolve(snes2, NULL,
                              NULL));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              <br>
                            </div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  printf("snes1 %p; snes2 %p\n", snes1,
                              snes2);</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              <br>
                            </div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  SNESFunctionFn *p;</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(SNESGetFunction(snes1, NULL,
                              &p, NULL));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  printf("snes1: pointer %p, true
                              function %p\n", *p, Function_1);</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(SNESGetFunction(snes2, NULL,
                              &p, NULL));</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  printf("snes2: pointer %p, true
                              function %p\n", *p, Function_2);</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                 </div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscCall(PetscFinalize());</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                                  PetscFunctionReturn(PETSC_SUCCESS);</div>
                            <div style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;line-height:22px;font-family:Calibri,Helvetica,sans-serif;font-size:12pt">
                              }</div>
                          </div>
                        </blockquote>
                      </div>
                      <br>
                    </div>
                  </div>
                </blockquote>
                <pre cols="72">-- 
Prof. Matteo Semplice
Università degli Studi dell’Insubria
Dipartimento di Scienza e Alta Tecnologia – DiSAT
Professore Associato
Via Valleggio, 11 – 22100 Como (CO) – Italia
tel.: +39 031 2386316</pre>
              </div>
            </blockquote>
          </div>
          <div><br clear="all">
          </div>
          <div><br>
          </div>
          <span class="gmail_signature_prefix">-- </span><br>
          <div dir="ltr" class="gmail_signature">Stefano</div>
        </blockquote>
      </div>
      <br>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
---
Professore Associato in Analisi Numerica
Dipartimento di Scienza e Alta Tecnologia
Università degli Studi dell'Insubria
Via Valleggio, 11 - Como</pre>
  </body>
</html>