[petsc-users] Setting up a SNES problem using DMDASetLocalFunction/DMDASetLocalJacobian in PETSc 3.3
Constantine Khroulev
ckhroulev at alaska.edu
Wed Sep 12 12:13:52 CDT 2012
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);
ierr = DMSetApplicationContext(da, &ctx); CHKERRQ(ierr);
#endif
ierr = SNESSetDM(snes, da); CHKERRQ(ierr);
ierr = SNESSetFromOptions(snes);CHKERRQ(ierr);
}
/* end code snippet */
--
Constantine
More information about the petsc-users
mailing list