<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Aug 17, 2015 at 11:46 AM, Reza Yaghmaie <span dir="ltr"><<a href="mailto:reza.yaghmaie2@gmail.com" target="_blank">reza.yaghmaie2@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div>Hi,</div><div><br></div><div>I have problems with passing variables through  <b>SNESSetFunction</b> in my code. basically I have the following subroutines in the main body of the Fortran code. Could you provide some insight on how to transfer variables into the residual calculation routine (<b>FormFunction1</b>)?</div></div></blockquote><div><br></div><div>Extra arguments to your FormFunction are meant to be passed in a context, through the context variable.</div><div><br></div><div>This is difficult in Fortran, but you can use a PetscObject as a container. You can attach other</div><div>PetscObjects using PetscObjectCompose() in Fortran.</div><div><br></div><div>   Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Thanks,</div><div>Reza</div><div>------------------------------------------------------------------------------------------------------------------</div><div><b><font size="4">main code</font></b></div><div><br></div><div><div><span style="white-space:pre-wrap">     </span><b>SNES</b>      snes</div><div><span style="white-space:pre-wrap">     </span><b>Vec</b>          xvec,rvec</div></div><div><div><span style="white-space:pre-wrap">    </span><b>external</b>   FormFunction1</div></div><div><div><span style="white-space:pre-wrap">     </span><b>real*8</b>       variable1(10),variable2(20,20),variable3(30),variable4(40,40)</div></div><div><br></div><div><br></div><div><div>      call <b>SNESSetFunction</b>(snes,rvec,FormFunction1,</div><div>     &<span style="white-space:pre-wrap">          </span>PETSC_NULL_OBJECT,</div><div>     &<span style="white-space:pre-wrap">          </span>variable1,variable2,variable3,variable4,<br></div><div>     &<span style="white-space:pre-wrap">          </span>ierr)<br></div></div><div><br></div><div><div>      end</div></div><div><br></div><div><div>      subroutine <b>FormFunction1</b>(snes,XVEC,FVEC,</div><div>     &<span style="white-space:pre-wrap">               </span>dummy,</div><div>     &<span style="white-space:pre-wrap">              </span>varable1,varable2,varable3,varable4,<br></div><div>     &<span style="white-space:pre-wrap">              </span>ierr)<br></div></div><div><br></div><div><div><span style="white-space:pre-wrap">  </span><b>SNES</b>                      snes</div><div><span style="white-space:pre-wrap">     </span><b>Vec</b>                         XVEC,FVEC</div><div><span style="white-space:pre-wrap">    </span><b>PetscFortranAddr</b>    dummy</div></div><div><div><span style="white-space:pre-wrap">    </span><b>real*8</b>                       variable1(10),variable2(20,20),variable3(30),variable4(40,40)</div></div><div><br></div><div><br></div><div><div>      return</div><div>      end</div></div><div>--------------------------------------------------------------------------------------------------------------</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">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></div>