Fix some Solvers not always using user preconditioner/Jacobian#2283
Fix some Solvers not always using user preconditioner/Jacobian#2283
Conversation
Always store the Jacobian if set, but defer to PhysicsModel Jacobian if that's set
If preconditioner or Jacobian was set using `PhysicsModel::setPrecon/setJacobian` then CVODE, ARKODE and PETSc `Solver`s would not use them
|
Just a comment: at least for CVODE the preconditioner-setting was working (I've used it in 4.4 and it seemed to do something), and it looks like you didn't need to change the preconditioner stuff here (apart from deleting the overrides in PetscSolver, which I've never used, and hiding away the use of function pointers). I'd vote for |
|
The issue is that there is a So this was broken: class MyModel : public PhysicsModel {
public:
int my_preconditioner(...) {...}
int init(bool) {
...
setPrecon((preconfunc) &MyModel::my_preconditioner); // Set in PhysicsModel but not called in CVODE etc
}
};but this worked: int my_preconditioner(...) {...}
class MyModel : public PhysicsModel {
public:
int init(bool) {
...
solver->setPrecon(my_preconditioner); // Set in CVODE
}
}; |
|
Agree fixes here are needed, and PetscSolver was broken. I think CVODE managed to work (at least precon, I haven't used Jacobian or thought about it now). CVODE would call BOUT-dev/src/solver/solver.cxx Lines 1427 to 1435 in 1d1307a and get into model->runPrecon()BOUT-dev/src/physics/physicsmodel.cxx Lines 62 to 66 in 1d1307a which does use the userprecon function set by PhysicsModel::setPrecon()BOUT-dev/include/bout/physicsmodel.hxx Line 225 in 1d1307a Sorry, I'm going on about this to check I'm not missing something - I think for people who were using preconditioning with CVODE, it was doing what they expected, and it was only possibly setting the Jacobian or preconditioning with other solvers that was previously broken. |
|
Apologies, you're entirely correct. For CVODE, it was just the jacobian that was not called correctly. The PETSc time solver was the only that didn't call the preconditioner correctly. |
CVODE, ARKODE and PETSc
Solvers only use the preconditioner or Jacobian if they were set usingSolver::setPrecon/setJacobian, and not if they were set through thePhysicsModelversions.This required adding
Solver::hasUserJacobian/runJacobianin order to access the model or solver Jacobian seamlessly.Discovered because I've started removing the old
SolverAPI and realised the PETSc solver stored its own pointers to the preconditioner/Jacobian functions! I'm not sure if anyone actually uses these functions, or this combination of solver and model functions, so possibly this doesn't affect anyone.Should the name be
Solver::hasJacobianinstead ofhasUserJacobian?