[petsc-users] petsc-users Digest, Vol 26, Issue 31
Barry Smith
bsmith at mcs.anl.gov
Sun Feb 13 21:45:47 CST 2011
On Feb 13, 2011, at 9:09 PM, Kontsantinos Kontzialis wrote:
Don't get the snes and ksp and do kspsetoperators() instead use TSSetRHSJacobian()
Do not use MatCreateSNESMF() that is for working with the nonlinear solver use
MatCreateMFFD() you then need to call MatMFFDSetFunction() to give it the function it will provide the derivative of.
You need to pass a function to TSSetRHSJacobian() that sets the MatMFFDSetBase() and then calls MatAssemblyBegin/End()
Barry
>
> here is a fragment from my code where I try to work on the implicit scheme
>
> // Apply initial conditions
> ierr = initial_conditions(sys);
> CHKERRQ(ierr);
>
> ierr = TSCreate(sys.comm, &sys.ts);
> CHKERRQ(ierr);
>
> ierr = TSSetSolution(sys.ts, sys.gsv);
> CHKERRQ(ierr);
>
> ierr = TSSetFromOptions(sys.ts);
> CHKERRQ(ierr);
>
> ierr = TSSetProblemType(sys.ts, TS_NONLINEAR);
> CHKERRQ(ierr);
>
> ierr = TSSetType(sys.ts, TSBEULER);
> CHKERRQ(ierr);
>
> ierr = TSSetRHSFunction(sys.ts, base_residual, &sys);
> CHKERRQ(ierr);
>
> ierr = TSGetSNES(sys.ts, &sys.snes);
> CHKERRQ(ierr);
>
> ierr = SNESSetFromOptions(sys.snes);
> CHKERRQ(ierr);
>
> ierr = MatCreateSNESMF(sys.snes, &sys.J);
> CHKERRQ(ierr);
>
> ierr = TSSetRHSJacobian(sys.ts, sys.J, sys.J, jacobian_matrix, &sys);
> CHKERRQ(ierr);
>
> ierr = SNESGetKSP(sys.snes, &sys.ksp);
> CHKERRQ(ierr)
>
> ierr = MatScale(sys.M, 1.0 / sys.con->dt);
> CHKERRQ(ierr);
>
> ierr = MatAYPX(sys.J, -1.0, sys.M, DIFFERENT_NONZERO_PATTERN);
> CHKERRQ(ierr);
>
> ierr = KSPSetOperators(sys.ksp, sys.J, sys.J, SAME_NONZERO_PATTERN);
> CHKERRQ(ierr);
>
> sys.con->j = 0;
> sys.con->tm = 0;
>
> ierr = TSSetDuration(sys.ts, 10000, sys.con->etime);
> CHKERRQ(ierr);
>
> ierr = TSMonitorSet(sys.ts, monitor, &sys, PETSC_NULL);
> CHKERRQ(ierr);
>
> ierr = PetscMalloc (sys.ldof*sizeof (PetscScalar ),&sys.Lim);
> CHKERRQ(ierr);
>
> ierr = TSSetSolution(sys.ts, PETSC_NULL);
> CHKERRQ(ierr);
>
> sys is my application context. Petsc tells me that I should call first the snessetfunction due to
> MatCreateSNESMF, 'cause I want to use an MF approach. what can I do? on an explicit run I do
> not use the jacobian, but how can I use it there now with a MF? Im confused.
>
> Thank you,
>
> kostas
More information about the petsc-users
mailing list