[petsc-users] petsc-users Digest, Vol 33, Issue 13
Barry Smith
bsmith at mcs.anl.gov
Wed Sep 7 12:54:40 CDT 2011
On Sep 7, 2011, at 11:41 AM, Kostas Kontzialis wrote:
>
> Barry,
>
> I have the following code for implementing the setting up snes and the numerical evaluation of the jacobian:
>
>
> ierr = jacobian_matrix_nz_pattern(sys);
> CHKERRQ(ierr);
>
> ierr = MatCreateMPIBAIJ(sys.comm, sys.num->nbq[sys.con->n],
> sys.ldof, sys.ldof, sys.gdof, sys.gdof, PETSC_NULL,
> sys.idxm, PETSC_NULL, sys.idxn, &sys.P);
> CHKERRQ(ierr);
>
> ierr = SNESCreate(sys.comm, &sys.snes);
> CHKERRQ(ierr);
>
> ierr = SNESSetFunction(sys.snes, sys.gres[0], base_residual_implicit, &sys);
> CHKERRQ(ierr);
>
> ierr = MatCreateSNESMF(sys.snes, &sys.J);
> CHKERRQ(ierr);
>
> ierr = MatMFFDSetFromOptions(sys.J);
> CHKERRQ(ierr);
>
>
> ierr = jacobian_diff_numerical(sys, &sys.P);
> CHKERRQ(ierr);
>
> ISColoring iscoloring;
>
> MatFDColoring fdcoloring;
>
> MatGetColoring(sys.P, MATCOLORING_SL, &iscoloring);
>
> MatFDColoringCreate(sys.P, iscoloring, &fdcoloring);
> ISColoringDestroy(iscoloring);
> MatFDColoringSetFromOptions(fdcoloring);
>
> ierr = SNESSetJacobian(sys.snes, sys.J, sys.P,
> SNESDefaultComputeJacobianColor, fdcoloring);
> CHKERRQ(ierr);
>
>
> As you can see I'm using a matrix free algorithm, However, when I run the code with with the -snes_mf_operator option I get on return the following error:
>
> Timestep 0: dt = 0.008, T = 0, Res[rho] = 0, Res[rhou] = 0, Res[rhov] = 0, Res[E] = 0, CFL = 0.177549
>
> /*********************Stage 1 of SSPIRK (3,4)******************/
>
> 0 SNES Function norm 2.755099585674e+01
> [4]PETSC ERROR: --------------------- Error Message ------------------------------------
> [4]PETSC ERROR: Object is in wrong state!
> [4]PETSC ERROR: Must call MatFDColoringSetFunction()!
>
> I haven't use the MatFDColoringSetFunction. But when I try to put it I read on the help page:
>
> Notes: This function is usually used automatically by SNES or TS (when one uses SNESSetJacobian() with the argument SNESDefaultComputeJacobianColor() or TSSetRHSJacobian() with the argument TSDefaultComputeJacobianColor()) and only needs to be used by someone computing a matrix via coloring directly by calling MatFDColoringApply()
>
Since you are creating the MatFDColoring object yourself you are obligated to provide it with the function it needs to compute columns of the Jacobian. Thus you must call MatFDColoringSetFunction()
the users manual is
MatFDColoringSetFunction - Sets the function to use for computing the Jacobian.
Logically Collective on MatFDColoring
Input Parameters:
+ coloring - the coloring context
. f - the function
- fctx - the optional user-defined function context
Calling sequence of (*f) function:
For SNES: PetscErrorCode (*f)(SNES,Vec,Vec,void*)
For TS: PetscErrorCode (*f)(TS,PetscReal,Vec,Vec,void*)
If not using SNES or TS: PetscErrorCode (*f)(void *dummy,Vec,Vec,void*) and dummy is ignored
Level: advanced
Notes: This function is usually used automatically by SNES or TS (when one uses SNESSetJacobian() with the argument
SNESDefaultComputeJacobianColor() or TSSetRHSJacobian() with the argument TSDefaultComputeJacobianColor()) and only needs to be used
by someone computing a matrix via coloring directly by calling MatFDColoringApply()
Fortran Notes:
In Fortran you must call MatFDColoringSetFunction() for a coloring object to
be used without SNES or TS or within the SNES solvers and MatFDColoringSetFunctionTS() if it is to be used
within the TS solvers.
so you pass it the same function you pass to SNESSetFunction() that is in your case base_residual_implicit,
If that does not work send a bug report to petsc-maint at mcs.anl.gov
Barry
> and furthermore I cannot figure out what the arguments are for the (*f) function.
>
> Any help?
>
> Kostas
>
More information about the petsc-users
mailing list