[petsc-users] Setting/creating Mats for SNES use

Dave May dave.mayhem23 at gmail.com
Mon Nov 2 15:19:48 CST 2015


On 2 November 2015 at 21:49, Justin Chang <jychang48 at gmail.com> wrote:

> So when would I use one over the other?
>
> - If I wanted to solve a problem using a direct solver or an iterative
> solver without a preconditioner, I would use A = J?
>

Yes.


>
> - The documentation for SNESSetJacobian() says that AMat and PMat are
> usually the same, but if I used something like GAMG would I need to create
> two different objects/Mats?
>

I would say "maybe".

If the Jacobian (here A) was defined via a matrix-free finite difference
approximation, but you wish to use a non-trivial preconditioner, you might
wish to assemble J. J might be the Picard linearized operator (for example).

Another use case where A != J might arise is if you define A with a high
order spatial discretization (probably matrix free) and you use a low order
discretization to define the preconditioner which will ultimately be passed
to GAMG.



>
> Thanks,
> Justin
>
> On Mon, Nov 2, 2015 at 1:39 PM, Jed Brown <jed at jedbrown.org> wrote:
>
>> Justin Chang <jychang48 at gmail.com> writes:
>>
>> > Hi all,
>> >
>> > In my DMPlex program, I have these lines:
>> >
>> > Mat A,J;
>> >
>> > ...
>> >
>> > ierr = DMSetMatType(dm, MATAIJ); CHKERRQ(ierr);
>> > ierr = DMCreateMatrix(dm, &J); CHKERRQ(ierr);
>> > A = J;
>> >
>> > ierr = DMSNESSetFunctionLocal(dm, ...); CHKERRQ(ierr);
>> > ierr = DMSNESSetJacobianLocal(dm, ...); CHKERRQ(ierr);
>> > ierr = SNESSetJacobian(snes, A, J, NULL, NULL); CHKERRQ(ierr);
>> > ierr = SNESSetFromOptions(snes); CHKERRQ(ierr);
>> >
>> > ...
>> >
>> > ierr = SNESSolve(snes, NULL, x); CHKERRQ(ierr);
>> >
>> > ...
>> > ierr = MatDestroy(&J); CHKERRQ(ierr);
>> >
>> >
>> > For the line "A = J;",
>>
>> This means you have two handles referring to the same object.
>>
>> > what exactly is the difference, if any, between that and "ierr =
>> > MatDuplicate(...)"
>>
>> This creates a new object.
>>
>> > or "ierr = MatCopy(...)"?
>>
>> The second argument needs to be a valid Mat to call this function.
>>
>> > Do these different options somehow affect memory usage/performance?
>>
>> Yes.
>>
>> > Say I am solving a standard poisson equation using either GAMG and/or
>> > HYPRE.
>> >
>> > Thanks,
>> > Justin
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20151102/35a8a644/attachment-0001.html>


More information about the petsc-users mailing list