[petsc-users] Context behind SNESComputeFunction call

Smith, Barry F. bsmith at mcs.anl.gov
Fri Jan 26 16:10:54 CST 2018



> On Jan 26, 2018, at 2:15 PM, Kong, Fande <fande.kong at inl.gov> wrote:
> 
> 
> 
> On Mon, Jan 8, 2018 at 2:15 PM, Smith, Barry F. <bsmith at mcs.anl.gov> wrote:
> 
> 
> > On Jan 8, 2018, at 2:59 PM, Alexander Lindsay <alexlindsay239 at gmail.com> wrote:
> >
> > Is there any elegant way to tell whether SNESComputeFunction is being called under different conceptual contexts?
> >
> > E.g. non-linear residual evaluation vs. Jacobian formation from finite differencing vs. Jacobian-vector products from finite differencing?
> 
>   Under normal usage with the options database no.
> 
> Hi Barry,
> 
> How difficult to provide an API? Is it possible?
> 
>  
> 
>   If you have some reason to know you could write three functions and provide them to SNESSetFunction(), MatMFFDSetFunction(), and MatFDColoringSetFunction(). Note that these functions have slightly different calling sequences but you can have all of them call the same  underlying common function if you are only interested in, for example, how many times the function is used for each purpose.
> 
> If we use this way for the Jacobian-free Newton, the function evaluation will be called twice at the first linear iteration because the computed residual vector at the nonlinear step  is not reused. Any way to reuse the function residual of the Newton step instead of recomputing a new residual at the first linear iteration?

   It does reuse the function evaluation. Why do you think it does not? If you look at MatMult_MFFD() you will see the lines of code

  /* compute func(U) as base for differencing; only needed first time in and not when provided by user */
  if (ctx->ncurrenth == 1 && ctx->current_f_allocated) {
    ierr = (*ctx->func)(ctx->funcctx,U,F);CHKERRQ(ierr);
  }

since the if is satisfied it does not compute the function at the base location.  To double check I ran src/snes/examples/tutorials/ex19 with -snes_mf in the debugger and verified that the "extra" function evaluations are not done.

  Barry


> 
> Fande,
> 
>  
> 
>    Barry
> 
> 
> 
> >
> > Alex
> 
> 



More information about the petsc-users mailing list