Check out src/numerics/petsc_nonlinear_solver.C... around line 112 there is a __petsc_snes_jacobian function. This is the _actual_ function that libMesh passes into Petsc SNES for you.

The genius is that you can pass one pointer (which comes through as "ctx" in __petsc_snes_jacobian() ) to Petsc that Petsc will just pass back to you all the time. libMesh (Ben?) takes advantage of this by passing a pointer to the solver. That means that "ctx" is always a pointer to the solver... but to use it we use a static_cast to get it back to a solver pointer. From there, you can get to the system (as it does there in __petsc_snes_jacobian.

Now... that still might not answer your question because the jacobian assembly function that you attach to the nonlinear-implicit-system has a signature of: (const NumericVector<Number>&, SparseMatrix<Number>&) which obviously doesn't pass the system. So what to do? In Ben's example code that uses NonlinearImplicitSystem (I've attached it just in case you missed it a few months ago) he just does this at the top of his main .C file: EquationSystems *_equation_system = NULL; essentially just creating a global variable that holds a pointer to the equation system. He sets that in his main... and then his compute_jacobian() function just uses the global variable....

Personally, I don't use that approach... but mine is even more complicated (I have objects that provide residuals / jacobians and they store references to their own EquationSystems object...).

I don't see why we couldn't modify the signature of the function pointer that you attach to NonlinearImplicitSystem to also pass an EquationSystems object. It's kind of hard to assemble anything without it.... and we're already getting pointers to it in __petsc_snes_jacobian Anyone have any objections?

Sorry for the long winded reply... the short of it is: just use a global variable ;-)

Derek

PS - Ben... we really need to make this an official example. Do you want me to do it?



On Jul 22, 2008, at 5:30 PM, Andrea Hawkins wrote:

Hi-

I am trying to solve a nonlinear system using as my system class
TransientNonlinearImplicitSystem with the PetscNonlinearSolver. I
realize the PetscNonlinearSolver class has a function pointer for
jacobian, but I am wondering how when the function jacobian is
actually defined to interface with the
TransientNonlinearImplicitSystem. i.e. how do I access the equation
system.

Do you have a simple example of something similar being done I could look at?

Thanks,
Andrea

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Libmesh-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libmesh-users

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Libmesh-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libmesh-users

Reply via email to