[petsc-users] Problems about Matrix-Free and DM object

Matthew Knepley knepley at gmail.com
Thu Oct 11 10:54:33 CDT 2018


On Thu, Oct 11, 2018 at 11:38 AM Yingjie Wu <yjwu16 at gmail.com> wrote:

> Dear Petsc developer:
> Hi,
> Thank you very much for your previous reply. I feel that I have learned a
> lot about the matrix-free method.
> I was studying the example /src/snes/example/tutorials/ex28.c recently.
> One of its tests is as follows:
>
> -u_da_grid_x 20 -snes_converged_reason -snes_monitor_short
> -ksp_monitor_short -problem_type 2 -snes_mf_operator -pack_dm_mat_type
> {{aij nest}} -pc_type fieldsplit -pc_fieldsplit_dm_splits
> -pc_fieldsplit_type additive -fieldsplit_u_ksp_type gmres
> -fieldsplit_k_pc_type jacobi
>
> The example is calculated by the Matrix-free method, and the precondition
> matrix is divided by FieldSplit. There are several questions in the
> procedure that make me feel uncertain.
> 1. The program uses the Matrixfree method by the command
> "-snes_mf_operator", but the form of Jacobian matrix is not defined as
> MATMFFD in the program. Does the program automatically set the Jacobian
> matrix to the form of MATMFFD after opening the command?
>

If you give that option, PETSc will automatically create a MFFD Mat object
and stick your nonlinear residual evaluation in it.


> Both Jacobian matrix and precondition matrix are defined as B in the
> program, and matrix elements are provided by Jacobian evaluation program.
> But the Jacobian matrix in the Matrixfree method is in the form of MATMFFD.
> You mentioned earlier that adding elements to the matrix with type MATMFFD
> can cause program errors, but why does the program work in this example?
> The procedures are as follows:
>
> ierr = SNESSetFunction(snes,F,FormFunction_All,user);CHKERRQ(ierr);
> ierr = SNESSetJacobian(snes,B,B,FormJacobian_All,user);CHKERRQ(ierr);
>
>
Because the FoirmJacobian() function in ex28 only ever puts values into the
preconditioning matrix. This is generally the right way to proceed.


> 2.Can we use DMCompositeScatter to scatter ghost value into local vectors?
> I didn't seem to mention the documentation. The program only uses the
> following functions, but can use ghost value.
>     ierr = DMCompositeScatter(user->pack,X,Uloc,Kloc);CHKERRQ(ierr);
>     ierr = DMDAVecGetArray(dau,Uloc,&u);CHKERRQ(ierr);
>     ierr = DMDAVecGetArray(dak,Kloc,&k);CHKERRQ(ierr);
>

DMCompositeScatter splits a vector up into the smaller vectors for each
system. DMComposite is very specialized, and we do not
recommend using it except in special cases.

DMGlobalToLocal() and DMLocalToGlobal() communicate ghost values.

  Thanks,

     Matt


> Greatly appreciated your reply and attention.
> Thanks,
> Yingjie
>
>

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

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20181011/b76ab3d1/attachment.html>


More information about the petsc-users mailing list