[petsc-users] Using operators in KSP

Matthew Knepley knepley at gmail.com
Mon Jun 16 05:09:08 CDT 2014


On Mon, Jun 16, 2014 at 12:40 AM, Sun, Hui <hus003 at ucsd.edu> wrote:

> Thank you Barry and Jed for answering my question. Here is another
> question: If I have a nonlinear PDE, for example, Poisson Boltzmann with an
> inhomogeneous dielectric constant epsilon. I want to solve for psi, but not
> epsilon. But to form the SetFunctionLocal, one needs to provide psi as well
> as epsilon.
>
> The user defined function which is passed to DMDASNESSetFunctionLocal
> should be of the format
> PetscErrorCode (*func)(DMDALocalInfo*,void*,void*,void*),
> where the first void* corresponds to x, the dimensional pointer to state
> at which to evaluate residual; and the second void* corresponds to f, the
> dimensional pointer to residual, write the residual here; and the third
> void* is the optional context passed above.
>
> The scalar field epsilon is not part of x, neither is it part of f, it
> seems that the only choice is to pass it in the third void*. However, if I
> have some other parameters, should I set up a struct, which includes those
> other parameters, and a distributed Vec for epsilon, and pass it in the
> third void*?
>

Yes, that is the idea. For example,


http://www.mcs.anl.gov/petsc/petsc-current/src/snes/examples/tutorials/ex5.c.html

defines a struct with problem parameters (so does ex19)

  Thanks,

     Matt


> Best,
> Hui
>
> ________________________________________
> From: Barry Smith [bsmith at mcs.anl.gov]
> Sent: Saturday, June 14, 2014 3:43 PM
> To: Sun, Hui
> Cc: petsc-users at mcs.anl.gov
> Subject: Re: [petsc-users] Using operators in KSP
>
>    MatCreateShell() is what I think you need.  You provide a “matrix-free”
> linear operator with MatShellSetOperation(mat,MATOP_MULT,yourfunction) and
> yourfunction applies the linear operator any way it likes.
>
>    You then provide this matrix as the first Mat argument to
> KSPSetOperators().
>
>
>    Barry
>
>
>
> On Jun 14, 2014, at 5:18 PM, Sun, Hui <hus003 at ucsd.edu> wrote:
>
> > I try to program 2D Stokes equation solver, so it is a linear PDE, and
> there are u, v, p on every grid point. One way on my mind is to form a
> matrix-free block matrix. In that way, if the discretization is n by n,
> then the matrix is 3n by 3n. However, I'm also thinking if it is possible
> to define the PDE operator as what DMDASNESSetFunctionLocal does in SNES
> example ex19? In that example, the unknowns (u, v, omega, T) are defined as
> a struct of four PestsScalar on every grid point, and then the interface
> converts PestcScalar** to Vec, and an operator instead of a matrix is
> formed.
> >
> > Is there a function in KSP similar to DMDASNESSetFunctionLocal in SNES?
>
>


-- 
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-users/attachments/20140616/31bd3266/attachment.html>


More information about the petsc-users mailing list