On Mon, Aug 17, 2015 at 11:46 AM, Reza Yaghmaie <[email protected]> wrote:
> > Hi, > > I have problems with passing variables through *SNESSetFunction* 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 (*FormFunction1*)? > Extra arguments to your FormFunction are meant to be passed in a context, through the context variable. This is difficult in Fortran, but you can use a PetscObject as a container. You can attach other PetscObjects using PetscObjectCompose() in Fortran. Matt > Thanks, > Reza > > ------------------------------------------------------------------------------------------------------------------ > *main code* > > *SNES* snes > *Vec* xvec,rvec > *external* FormFunction1 > *real*8* > variable1(10),variable2(20,20),variable3(30),variable4(40,40) > > > call *SNESSetFunction*(snes,rvec,FormFunction1, > & PETSC_NULL_OBJECT, > & variable1,variable2,variable3,variable4, > & ierr) > > end > > subroutine *FormFunction1*(snes,XVEC,FVEC, > & dummy, > & varable1,varable2,varable3,varable4, > & ierr) > > *SNES* snes > *Vec* XVEC,FVEC > *PetscFortranAddr* dummy > *real*8* > variable1(10),variable2(20,20),variable3(30),variable4(40,40) > > > return > end > > -------------------------------------------------------------------------------------------------------------- > > > > > > -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener
