[petsc-users] Setting up a SNES problem using DMDASetLocalFunction/DMDASetLocalJacobian in PETSc 3.3
Matthew Knepley
knepley at gmail.com
Wed Sep 12 12:17:49 CDT 2012
On Wed, Sep 12, 2012 at 12:13 PM, Constantine Khroulev <ckhroulev at alaska.edu
> wrote:
> Hi,
>
> While updating our code to work with PETSc 3.3 I noticed that (as far
> as I can tell) there is no SNESDAFormFunction/SNESDAComputeJacobian
> equivalent in 3.3.
>
> I came up with a workaround (see below), but I am not sure if this is
> legal. (See the "SNESSetFunction(snes, F, PETSC_NULL, PETSC_NULL)",
> for example.)
>
> What would you recommend?
>
> /* begin code snippet */
> {
> ierr = DMDACreate2d(..., &da); CHKERRQ(ierr);
>
> ierr = DMCreateGlobalVector(da, &F); CHKERRQ(ierr);
> ierr = DMCreateMatrix(da, "baij", &J); CHKERRQ(ierr);
>
> ierr = SNESCreate(com, &snes);CHKERRQ(ierr);
>
> ierr =
> DMDASetLocalFunction(da,(DMDALocalFunction1)LocalFunction);CHKERRQ(ierr);
> ierr =
> DMDASetLocalJacobian(da,(DMDALocalFunction1)LocalJacobian);CHKERRQ(ierr);
>
> #if I_HAVE_PETSC32==1
> ierr = SNESSetFunction(snes, F, SNESDAFormFunction, &ctx); CHKERRQ(ierr);
> ierr = SNESSetJacobian(snes, J, J, SNESDAComputeJacobian, &ctx);
> CHKERRQ(ierr);
> #else /* PETSc 3.3 */
> ierr = SNESSetFunction(snes, F, PETSC_NULL, PETSC_NULL); CHKERRQ(ierr);
> ierr = SNESSetJacobian(snes, J, J, PETSC_NULL, PETSC_NULL);
> CHKERRQ(ierr);
>
You do not need these two. If the DM is set, SNES will take the assembly
function from the
DM. Refer to SNES ex5.
Thanks,
Matt
> ierr = DMSetApplicationContext(da, &ctx); CHKERRQ(ierr);
> #endif
>
> ierr = SNESSetDM(snes, da); CHKERRQ(ierr);
>
> ierr = SNESSetFromOptions(snes);CHKERRQ(ierr);
> }
> /* end code snippet */
>
> --
> Constantine
>
--
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120912/1f8caf99/attachment.html>
More information about the petsc-users
mailing list