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 ??? Thanks again for your attention. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20111123/5d65352e/attachment-0001.htm>