On Wed, Oct 8, 2008 at 12:55 PM, Jed Brown <[EMAIL PROTECTED]> wrote:
> On Wed 2008-10-08 12:42, John Peterson wrote:
>> Thanks Jed...
>>
>> On Wed, Oct 8, 2008 at 12:24 PM, Jed Brown <[EMAIL PROTECTED]> wrote:
>> >
>> > class MyShell {
>> > public:
>> >      int mult(...);
>> > };
>> >
>> > PetscErrorCode MyMult(Mat A,Vec x,Vec y)
>> > {
>> >  MyShell *shell;
>> >  MatShellGetContext(A,(void**)&shell);
>> >  shell->mult(x,y);
>> > }
>> >
>> >
>> > // elsewhere, perhaps in the MyShell constructor
>> > MatShellCreate(comm,m,n,M,N,&B);
>> > MatShellSetOperation(B,MATOP_MULT,(void(*)(void))MyMult);
>>
>>
>> MatShellCreate (or CreateShell?) takes a void* ctx, so if it were in
>> MyShell constructor we'd also pass static_cast<void*>(this) ?
>
> Yeah, that's what I meant.
>
> The same procedure is recommended for other callbacks (convergence
> tests, custom preconditioners, function/Jacobian evaluation, etc) in
> PETSc.  Presumably you do something like this with the SNES interface?

Actually, it looks like (src/numerics/petsc_nonlinear_solver.C) we use
some specially-named global functions for e.g. SNESSetJacobian, but we
do pass "this" as the context pointer, where "this" is LibMesh's
PetscNonlinearSolver class.    I'd much rather encapsulate the global
functions in a class as you have done.

-- 
John

-------------------------------------------------------------------------
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