Here is a basic outline of what is needed to make a FEAP umacr that PETSc SNES:
First, PETSc SNES requires 2 basic user-provided routines, one routine to evaluate the residual and one routine to assemble the jacobian. Say these are named FormFunction and FormJacobian. Both take the current iterate computed by SNES as an argument. Adding these routines to the SNES context is done with the functions SNESSetFunction and SNESSetJacobian. Now, when SNES needs to evaluate the residual or jacobian, it will call FormFunction and FormJacobian.
FormFunction will go something like this:
1. compute the increment between SNES current iterate x (passed as an argument by SNES) and FEAP current solution u.
2. save FEAP solution and rate arrays in temporary storage
3. update FEAP solution and rate arrays using the increment computed in 1. Note, history variable should not be updated at this point
4. call formfe with isw = 6
5. copy the feap residual array into the PETSc Vec which is to be the output. Note, the FEAP and SNES residuals have opposite signs.
6. restore feap solution and rate arrays from temporary storage
FormJacobian will essentially be the same but with isw = 3 in step 4. Also, if the PETSc ON command has been used formfe will assemble the jacobian to a PETSc Mat called Kmat. The value of this pointer can be passed out of FormJacobian. If a preconditioner is used, it will be computed in this routine as well.
The last ingredient is a way to update FEAP's solution, rate, and history variables after the SNES nonlinear method accepts a solution step. This can be done by creating a custom monitor, which should do steps 1,3,4 above, but with the flag for history variable update turned on. The monitor can also be used to write information to the feap log and output files, and/or to the screen.
The problem I mentioned in the previous post was due to my FormFunction and FormJacobian routines calling SNESGetSolutionUpdate and using that to do the update in step 3. This is not equivalent to the increment computed by the method in step 1.
I hope this is helpful!
Colin