# [petsc-users] Get Stuck in SNES

Wed Nov 23 01:06:47 CST 2011

```Thanks for your help.

Here is my procedure:

1- Define context ( as in previous email )

2- Related the addresses ( as in previous email )

4- create the context
FieldCtx FC;

3- call residual routine:
ierr = SNESSetFunction( snes, r, _petsc_residualVector, (void*)&FC );
CHKERRQ( ierr );

4- define residual routine: ( x is solution and r is residual vector )
PetscErrorCode solver::_petsc_residualVector( SNES snes, Vec x, Vec r,
void* ctx )
{
ierr = VecGetArray( x, &xx ); CHKERRQ( ierr );

for( c=0; c<ne; c++ ) for( p=0; p<tot; p++ )
FC->e[c].Q[p] = xx[c*(noe*num)+p];

ierr = VecRestoreArray( x, &xx ); CHKERRQ( ierr );

interiorFlux( FC->flw, FC->e );
faceFlux    ( FC->flw, FC->f, FC->e );

ierr = VecGetArray( r, &rr ); CHKERRQ( ierr );

for( c=0; c<ne; c++ )
{
for( p=0; p<tot; p++ ) rr[c*tot+p] = FC->e[c].R[p];
}

ierr = VecRestoreArray( r, &rr ); CHKERRQ( ierr );
}

5- same procedure for Jacobian

6- set opitions

7- solve with SNESSolve()

Is it look right with SNES ???