[petsc-users] Example for solving system of pde with snes

Jed Brown jed at jedbrown.org
Sun Sep 10 08:07:39 CDT 2017


Praveen C <cpraveen at gmail.com> writes:

> Hello Matt
>
>
>> No. You want 2 DAs, 1 for evaluating residuals with s = 3, and one for
>> making a Jacobian with s = 1. You give these
>> two DAs to
>>
>> http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/SNES/
>> DMDASNESSetFunctionLocal.html
>> http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/SNES/
>> DMDASNESSetJacobianLocal.html
>>
>> and I think it should work as you want. Its too bad we cannot handle this
>> case with SNESSetDM() since it only takes
>> a single DM and there is no way to specialize the Jacobian.
>>
>>
> ok, I was on wrong track trying to use SNESSetFunction and SNESSetJacobian
> which wouldnt have worked.

You can use SNESSetJacobian, but DMSNESSetJacobianLocal is more
convenient in my opinion.

> I still have some doubt. If
>
> da0 --> for residual
> da1 --> for jacobian
>
> I still need to call SNESetDM. So here I pass da0 ? But then how will snes
> know about da1 ?

This should work.

DMCreateMatrix(da1, &Jpre);
SNESSetDM(snes, da0);
SNESSetJacobian(snes, NULL, Jpre, NULL, NULL);
DMDASNESSetJacobianLocal(da0, func, ctx);

Your func will assemble into the Pmat argument.  You might run with
-snes_mf_operator to apply the action of the true Jacobian while
preconditioning with the preconditioning matrix.  See also
src/snes/examples/tutorials/ex15.c and its handling of "-alloc_star".
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20170910/f48abe37/attachment.sig>


More information about the petsc-users mailing list