[petsc-users] about FD Jacobian for the new DAE solver
Jed Brown
jed at 59A2.org
Thu Apr 29 16:37:48 CDT 2010
On Thu, 29 Apr 2010 21:08:38 +0000, "Li, Zhisong (lizs)" <lizs at mail.uc.edu> wrote:
> Hi,
>
> Last time I was suggested by Jed using the DAE solver to build my
> nonlinear CFD code based on TS. For incompressible N-S equations, I
> think it's difficult to derive the analytical Jacobian formulation,
> and we need a finite difference approximation or matrix-free method.
It's pretty easy to code an analytic Jacobian for incompressible
Navier-Stokes since it's only a quadratic nonlinearity. But
> What I previously done was integrating the incompressible N-S equations into tutorial code ts/ex7.c . It simply uses an argument "TSDefaultComputeJacobianColor" to finish the Jacobian issue. When I switch to TSSetIFunction() and TSSetIJacobian(), this argument doesn't work anymore. And if I remove all Jacobian-related lines and use -snes_mf command option, it prompts out error message "Must Set Jacobian!". Do you know how to resolve this for both methods?
If you use -snes_mf or -snes_fd, then you can call TSSetIJacobian() and
not provide a function. If you are using petsc-dev, then
ts/examples/tutorials/ex10.c has the following method (which is also
more efficient than TSDefaultComputeJacobianColor).
SNES snes;
ISColoring iscoloring;
ierr = TSGetSNES(ts,&snes);
ierr = DAGetColoring(rd->da,IS_COLORING_GLOBAL,MATAIJ,&iscoloring);CHKERRQ(ierr);
ierr = MatFDColoringCreate(B,iscoloring,&matfdcoloring);CHKERRQ(ierr);
ierr = ISColoringDestroy(iscoloring);CHKERRQ(ierr);
ierr = MatFDColoringSetFunction(matfdcoloring,(PetscErrorCode(*)(void))SNESTSFormFunction,ts);CHKERRQ(ierr);
ierr = MatFDColoringSetFromOptions(matfdcoloring);CHKERRQ(ierr);
ierr = SNESSetJacobian(snes,A,B,SNESDefaultComputeJacobianColor,matfdcoloring);CHKERRQ(ierr);
But it looks like TSPSEUDO will currently overwrite this (the other
integrators deal with this correctly). I'll push a fix shortly.
Jed
More information about the petsc-users
mailing list