[petsc-users] question on VecPointwiseMax
Xiangdong
epscodes at gmail.com
Thu Apr 19 07:43:47 CDT 2018
Hi Barry,
I called the SNESGetSolution() through SNESMonitorSet(). I understand that
it may not be effective, but I was able to change the values of iteration
solution in old releases (two years ago). Was the solution vector set to
read status in recent version?
About the -snes_type vinewtonrsls, we discussed this a few years ago. It
does not work well for my problem, so I want to manually perform some post
processing after each iteration. For example, setting a bound for the
solution or set the maximum changes for each component of the solution in
each iteration.
https://lists.mcs.anl.gov/pipermail/petsc-users/2014-May/021520.html
Best,
Xiangdong
On Tue, Apr 17, 2018 at 5:24 PM, Smith, Barry F. <bsmith at mcs.anl.gov> wrote:
>
> Where are you call SNESGetSolution() from? Inside a SNES monitor
> routine, a SNES convergence test routine, a SNESLineSearchPostCheck()
> routine?
>
> The SNES linear solvers are solving the system, you really shouldn't
> be changing the values of the solution any time while they are doing their
> job solving the system. Of course you can change the values after the
> solver is done.
>
> If you are trying to "solve" a linear system with upper and/or lower
> bounds on the variables you should solve it as a variational inequality and
> use SNESVISetVariableBounds(), you should not try to manually restrict the
> values (that won't work). And use -snes_type vinewtonrsls
>
> Barry
>
>
>
> Barry
>
>
> > On Apr 17, 2018, at 12:04 PM, Xiangdong <epscodes at gmail.com> wrote:
> >
> > Hello everyone,
> >
> > Here are a little more information.
> >
> > Here is the function calls I have:
> >
> > SNESGetSolution(snes,&x);
> > VecPointwiseMax(x,x,xl); Fail
> > VecPointwiseMax(x,y,xl); Fail
> >
> > The error messages are"Object is in wrong state, Vec is locked read
> only, argument #1."
> >
> > It seems that the vector x returned from SNESGetSolution is locked read
> only, Is it true?
> >
> > If I want do some post processing by modifying the x after each
> nonlinear iteration, how can I get the solution and modify it?
> >
> > Thank you.
> >
> > Best,
> > Xiangdong
> >
> >
> >
> > On Tue, Apr 17, 2018 at 11:33 AM, Xiangdong <epscodes at gmail.com> wrote:
> > Hello everyone,
> >
> > When I call VecPointwiseMax(x,x,y) , I got an error message "object is
> in wrong state. Vec is locked read only, argument #1."
> >
> > However, In the online manual of output parameters of VecPointwiseMax,
> it says:
> >
> > http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/
> Vec/VecPointwiseMax.html
> > Output Parameter
> >
> > w -the result
> >
> > Notes: any subset of the x, y, and w may be the same vector. For complex
> numbers compares only the real part
> >
> > However, in the implementation of VecPointwiseMax_Seq,
> > http://www.mcs.anl.gov/petsc/petsc-current/src/vec/vec/impls
> /seq/bvec2.c.html#VecPointwiseMax_Seq,
> >
> > it seems that xin is read locked, and win and xin cannot be the same
> vectors.
> > PetscErrorCode VecPointwiseMax_Seq(Vec win,Vec xin,Vec yin)
> > 17:
> > {
> >
> > 19: PetscInt
> > n = win->map->n,i;
> >
> > 20: PetscScalar *ww,*xx,*yy; /* cannot make xx or yy const since
> might be ww */
> >
> >
> >
> > 23: VecGetArrayRead(xin,(const PetscScalar
> > **)&xx);
> >
> > 24: VecGetArrayRead(yin,(const PetscScalar
> > **)&yy);
> >
> > 25: VecGetArray
> > (win,&ww);
> >
> >
> > 27: for (i=0; i<n; i++) ww[i] = PetscMax(PetscRealPart(xx[i]),
> > PetscRealPart(yy[i]));
> >
> >
> > 29: VecRestoreArrayRead(xin,(const PetscScalar
> > **)&xx);
> >
> > 30: VecRestoreArrayRead(yin,(const PetscScalar
> > **)&yy);
> >
> > 31: VecRestoreArray
> > (win,&ww);
> >
> > 32: PetscLogFlops
> > (n);
> >
> > 33: return
> > (0);
> >
> > 34: }
> > Can w and x really be same vector in the VecPointwiseMax? Thanks.
> >
> > Best,
> > Xiangdong
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20180419/a50d03da/attachment.html>
More information about the petsc-users
mailing list