[petsc-dev] Why does TSDefaultComputeJacobianColor exist?

Jed Brown jed at 59A2.org
Sun Apr 18 12:15:18 CDT 2010


On Thu, 15 Apr 2010 12:57:26 -0500, Barry Smith <bsmith at mcs.anl.gov> wrote:
> 
>     Sadly, I do not remember why I needed to have a separate version  
> for TS, but I do remember not being happy with needing one but not  
> finding a good alternative.
> 
>     The function in the TS case has an extra t argument, that is  
> definitely part of the reason there is separate code but I do not  
> remember if there are other reasons.

The thing is that t is closed over by whatever the TS gives to
SNESSetFunction (i.e. it is stored in the TS context).  I'll think about
this a bit more, but I think all we need is to get the coloring through
the TS to the SNES (usually TS is responsible for controlling
SNESSetJacobian so, strictly speaking, the user shouldn't be messing
around with the SNES directly at this level).

I have a working solution in a nonequilibrium radiation-diffusion
example I'm putting together.

    ierr = TSGetSNES(ts,&snes);CHKERRQ(ierr);
    ierr = DAGetColoring(rd->da,IS_COLORING_GHOSTED,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);

The only thing that needs to be exposed is a common SNESTSFormFunction
(currently each implementation gives their implementation of this thing
to the SNES, I'm proposing having one of these and a slot in TS for the
implementation-defined value.  This would also clean up some other
messiness that currently has each implementation setting up the SNES in
a delicate manner so as not to disturb matrix-free things.

Jed



More information about the petsc-dev mailing list