On Fri, 30 Apr 2010, Derek Gaston wrote:
> On Apr 30, 2010, at 12:09 PM, Roy Stogner wrote:
>
>> We're currently passing back a pointer to the solver, ctx, and the
>> solver contains a pointer to the System, _system.
>
> Yes, this is what we get back from the callback from Petsc... I'm
> talking about the callback to user code. As in the function pointer
> that you attach to nonlinear_solver->residual. You know... the
> function that users write. That one doesn't have any state
> information coming through to it.
Ah, I see. I guess Ben just assumed that nobody would be reusing the
same residual function for multiple systems, but then
dial-an-operator type frameworks break that assumption.
Personally I'd prefer turning residual/jacobian/matvec into functor
objects over adding a System* or void* state argument.
One other possibility that Ben pointed out the other day, though:
The DiffSolver framework originally was written to only work for
DiffSystem because it relied on being able to call assembly(bool,bool)
to request calculation of residuals, jacobians, or both at once, and
the other existing System subclasses couldn't do that. But when all
the adjoint work required assembly(bool,bool) too, I moved the
definition up to ImplicitSystem and added implementations (sometimes
suboptimally efficient for backwards compatibility...) for
LinearImplicitSystem and NonlinearImplicitSystem. So now we could
make DiffSolver work with any ImplicitSystem, you could use
PetscDiffSolver (or NewtonSolver) instead of PetscNonlinearSolver, and
since the assembly calls from there are class methods you'd have all
the state you need.
Thoughts?
---
Roy
|