[petsc-dev] Fwd: [petsc-users] questions about the SNES Function Norm

Peter Brune prbrune at gmail.com
Thu May 1 14:27:47 CDT 2014


Already on it.

- Peter


On Thu, May 1, 2014 at 2:27 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:

>
> On May 1, 2014, at 2:24 PM, Peter Brune <prbrune at gmail.com> wrote:
>
> > Yes, you've got to be careful about this in the case of preconditioning.
>  I'm still pretty sure that SNESGetFunctionNorm() (which is ancient
> http://www.mcs.anl.gov/petsc/petsc-2.2.0/docs/manualpages/SNES/SNESGetFunctionNorm.html)
>
>    Yikes. This may predate proper caching of norms with vectors.
>
>    So will you make a branch and try to eliminate this beast?
>
>    Thanks
>
>     Barry
>
> > can be replaced transparently with VecNorm();  SNESSetFunctionNorm() is
> used in one place and can be eliminated, unless we're going to put wonky
> logic in there about when things are set.
> >
> >
> > On Thu, May 1, 2014 at 2:02 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
> >
> > On May 1, 2014, at 1:32 PM, Peter Brune <prbrune at gmail.com> wrote:
> >
> > > Yeah that bit of interface can most likely go away entirely.
>  SNESSet/GetFunctionNorm is barely used in the code and can be mostly
> replaced with calls to VecNorm().  It's odd that snes->norm isn't the same
> as the norm of the function at the end of an iteration, but is of course
> totally possible given the multitude of potential exit conditions.  Actual
> output would, you know, be helpful in diagnosing what exactly's going on
> instead of forcing us to stab blindly into the dark.
> >
> >    Hmm, what about the weird case with nonlinear preconditioners where
> the “function norm” may not be the function norm. Like in
> >
> >   /* check if the function is valid based upon how the inner solver is
> preconditioned */
> >     if (normschedule != SNES_NORM_NONE && normschedule !=
> SNES_NORM_INITIAL_ONLY && (npcside == PC_RIGHT || functype ==
> SNES_FUNCTION_UNPRECONDITIONED)) {
> >       ierr = SNESGetFunction(snes->pc,&FPC,NULL,NULL);CHKERRQ(ierr);
> >       if (FPC) {
> >         if (fnorm) {ierr =
> SNESGetFunctionNorm(snes->pc,fnorm);CHKERRQ(ierr);}
> >         ierr = VecCopy(FPC,F);CHKERRQ(ierr);
> >       } else {
> >         SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Preconditioner
> has no function");
> >       }
> >     } else {
> >       ierr = SNESGetSolution(snes->pc,&XPC);CHKERRQ(ierr);
> >       if (XPC) {
> >         ierr = SNESComputeFunction(snes->pc,XPC,F);CHKERRQ(ierr);
> >         if (fnorm) {ierr = VecNorm(F,NORM_2,fnorm);CHKERRQ(ierr);}
> >
> > or
> >
> >     ierr = PetscInfo4(snes,"fnorm=%18.16e, gnorm=%18.16e, ynorm=%18.16e,
> lssucceed=%d\n",(double)fnorm,(double)gnorm,(double)ynorm,(int)lssucceed);CHKERRQ(ierr);
> >
> >     if (snes->pc && snes->pcside == PC_RIGHT) {
> >       ierr =
> PetscLogEventBegin(SNES_NPCSolve,snes->pc,X,0,0);CHKERRQ(ierr);
> >       ierr = SNESSolve(snes->pc,snes->vec_rhs,X);CHKERRQ(ierr);
> >       ierr =
> PetscLogEventEnd(SNES_NPCSolve,snes->pc,X,0,0);CHKERRQ(ierr);
> >       ierr = SNESGetConvergedReason(snes->pc,&reason);CHKERRQ(ierr);
> >       if (reason < 0 && reason != SNES_DIVERGED_MAX_IT) {
> >         snes->reason = SNES_DIVERGED_INNER;
> >         PetscFunctionReturn(0);
> >       }
> >       ierr = SNESGetNPCFunction(snes,F,&fnorm);CHKERRQ(ierr);
> >     }
> >
> >     ierr = SNESSetIterationNumber(snes, i+1);CHKERRQ(ierr);
> >     ierr = SNESSetFunctionNorm(snes, fnorm);CHKERRQ(ierr);
> >
> >   and a few other cases?
> >
> >   Barry
> >
> > >
> > > - Peter
> > >
> > >
> > > On Thu, May 1, 2014 at 1:00 PM, Barry Smith <bsmith at mcs.anl.gov>
> wrote:
> > >
> > >   Peter,
> > >
> > >      This SNESSetFunctionNorm() seems pretty likely to be fragile
> where it doesn’t always get set. Is there any way we can test that it
> always gets updated properly when the function gets re-evaluated?   For
> example what if one place in the code the function is evaluated but the
> norm does not get computed and set with SNESSetFunctionNorm()?
> > >
> > >    Thanks
> > >
> > >     Barry
> > >
> > >
> > > Begin forwarded message:
> > >
> > >> From: Xiangdong <epscodes at gmail.com>
> > >> Subject: Re: [petsc-users] questions about the SNES Function Norm
> > >> Date: May 1, 2014 at 10:32:44 AM CDT
> > >> To: Matthew Knepley <knepley at gmail.com>
> > >> Cc: Barry Smith <bsmith at mcs.anl.gov>, PETSc users list <
> petsc-users at mcs.anl.gov>
> > >>
> > >> Under what condition, SNESGetFunctionNorm() will output different
> results from SENEGetFunction + VecNorm (with NORM_2)?
> > >>
> > >> For most of my test cases, it is the same. However, when I have some
> special (trivial) initial guess to the SNES problem, I see different norms.
> > >>
> > >> Another phenomenon I noticed with this is that KSP in SNES squeeze my
> matrix by eliminating rows. I have a Jacobian supposed to be 50-by-50. When
> I use KSPGetOperators/rhs/solutions, I found that the operator is 25-by-25,
> and the rhs and solution is with length 25. Do you have any clue on what
> triggered this? To my surprise, when I output the Jacobian inside the
> FormJacobianLocal, it outputs the correct matrix 50-by-50 with correct
> numerical entries. Why does the operator obtained from KSP is different and
> got rows eliminated? These rows got eliminated have only one entries per
> row, but the rhs in that row is not zero. Eliminating these rows would give
> wrong solutions.
> > >>
> > >> Thank you.
> > >>
> > >> Xiangdong
> > >>
> > >>
> > >>
> > >>
> > >>
> > >>
> > >> On Tue, Apr 29, 2014 at 3:12 PM, Matthew Knepley <knepley at gmail.com>
> wrote:
> > >> On Tue, Apr 29, 2014 at 2:09 PM, Xiangdong <epscodes at gmail.com>
> wrote:
> > >> It turns out to a be a bug  in my FormFunctionLocal(DMDALocalInfo
> *info,PetscScalar **x,PetscScalar **f,AppCtx *user). I forgot to initialize
> the array f. Zero the array f solved the problem and gave consistent result.
> > >>
> > >> Just curious, why does not petsc initialize the array f to zero by
> default inside petsc when passing the f array to FormFunctionLocal?
> > >>
> > >> If you directly set entires, you might not want us to spend the time
> writing those zeros.
> > >>
> > >> I have another quick question about the array x passed to
> FormFunctionLocal. If I want to know the which x is evaluated, how can I
> output x in a vector format? Currently, I created a global vector vecx and
> a local vector vecx_local, get the array of vecx_local_array, copy the x to
> vecx_local_array,  scatter to global vecx and output vecx. Is there a quick
> way to restore the array x to a vector and output?
> > >>
> > >> I cannot think of a better way than that.
> > >>
> > >>    Matt
> > >>
> > >> Thank you.
> > >>
> > >> Best,
> > >> Xiangdong
> > >>
> > >>
> > >>
> > >> On Mon, Apr 28, 2014 at 10:28 PM, Barry Smith <bsmith at mcs.anl.gov>
> wrote:
> > >>
> > >> On Apr 28, 2014, at 3:23 PM, Xiangdong <epscodes at gmail.com> wrote:
> > >>
> > >> > Hello everyone,
> > >> >
> > >> > When I run snes program,
> > >>
> > >>                ^^^^ what SNES program”?
> > >>
> > >> > it outputs "SNES Function norm 1.23456789e+10". It seems that this
> norm is different from residue norm (even if solving F(x)=0)
> > >>
> > >>    Please send the full output where you see this.
> > >>
> > >> > and also differ from norm of the Jacobian. What is the definition
> of this "SNES Function Norm”?
> > >>
> > >>    The SNES Function Norm as printed by PETSc is suppose to the
> 2-norm of F(x) - b (where b is usually zero) and this is also the same
> thing as the “residue norm”
> > >>
> > >>    Barry
> > >>
> > >> >
> > >> > Thank you.
> > >> >
> > >> > Best,
> > >> > Xiangdong
> > >>
> > >>
> > >>
> > >>
> > >>
> > >> --
> > >> 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
> > >>
> > >
> > >
> >
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20140501/a89e8545/attachment.html>


More information about the petsc-dev mailing list