[petsc-users] Using operators in KSP

Jed Brown jed at jedbrown.org
Sat Jun 14 17:40:18 CDT 2014


"Sun, Hui" <hus003 at ucsd.edu> writes:

> 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?

DMKSPSetComputeOperators() is sort of similar, but you still build
matrices.  You can use MatShell to wrap a "matrix-free" (unassembled)
linear operator.  If you like the interface DMDASNESSetFunctionLocal, I
recommend just using that interface and -snes_type ksponly (just do one
linear solve and don't bother checking for convergence; recommended for
linear problems formulated using SNES).  This is also the easiest route
if you might later generalize to a nonlinear problem (e.g.,
non-Newtonian rheology or Navier-Stokes).

Note that most preconditioners will require a matrix to be assembled.
You can set a sparsity pattern for the Stokes operator (or use the
pattern from DMDA if it's good enough) and use coloring (default) to
assemble a matrix.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20140614/5ba50e03/attachment.pgp>


More information about the petsc-users mailing list