[petsc-users] Question about TSSetIJacobian examples
Barry Smith
bsmith at mcs.anl.gov
Mon Jan 25 11:34:01 CST 2016
The reason for the MatAssembly... on A when A is not B is when using a matrix-free A. For example -snes_mf_operator
Recall that matrix free matrix vector products with finite differences are computed with
F(U + alpha*dx) - F(U)
J(U)*dx = -----------------------------------
alpha*dx
dx, of course, is different for each call to the multiply. Each new Newton step uses a new U. The MatAssemblyBegin/End() is when the matrix free matrix A
is informed of the new U value (otherwise even with new Newton steps the original U from the first Newton step would be used forever); this is handled internally by the MatCreateSNESMF() object.
Barry
> On Jan 25, 2016, at 4:58 AM, Torquil Macdonald Sørensen <torquil at gmail.com> wrote:
>
> Hi!
>
> I have been looking at some of the PETSc examples where TSSetIJacobian,
> and there is one thing which is unclear to me. Consider e.g. the example:
>
> http://www.mcs.anl.gov/petsc/petsc-current/src/ts/examples/tutorials/ex8.c.html
>
> In the function RoberJacobian(), CEJacobian(), OregoJacobian(), there
> are two matrix function arguments A and B. The matrix A is the one that
> is actually set in the code. My question is: what is the purpose of
>
> MatAssemblyBegin(B,MAT_FINAL_ASSEMBLY);
> MatAssemblyEnd(B,MAT_FINAL_ASSEMBLY);
>
> when A != B at the end of the function? How does that piece of code
> affect B? In the documentation of these functions it says that they are
> to be called after e.g. MatSetValues. But MatSetValues have not been
> called on B in those functions, so that's why I'm wondering what those
> lines are for.
>
> Best regards,
> Torquil Sørensen
>
More information about the petsc-users
mailing list