Add support for objective function in SNES#5155
Conversation
|
|
||
| # Use the user-provided Jacobian. If none is provided, derive | ||
| # the Jacobian from the residual. | ||
| self.E = objective |
There was a problem hiding this comment.
One may also inspect F and decide to call derivative twice, but requires the pde_args check to be done earlier.
There was a problem hiding this comment.
It might be worthwhile to introduce an optimiser class that just takes in E and computes F and J automatically, but that could go as a separate PR
There was a problem hiding this comment.
The new line should not be added below the comment
| self.E = objective |
| if self._problem.E: | ||
| snes.setObjective(self.form_objective) | ||
| else: | ||
| snes.setObjective(None) |
There was a problem hiding this comment.
See the PETSc MR for why this is needed
Co-authored-by: Pablo Brubeck <brubeck@protonmail.com>
|
In order to get the energy at the coarse levels in MG/FAS we just need to add a tiny amount of logic in mg/ufl_utils.py. I can add it for you, if you don't mind. |
Go ahead |
| self.E = objective | ||
| self.J = J or ufl_expr.derivative(F, u) | ||
| self.F = F | ||
| self.Jp = Jp |
There was a problem hiding this comment.
| self.Jp = Jp | |
| self.Jp = Jp | |
| self.E = objective |
8465c3c to
d41cc7e
Compare
Description
Add support for objective functions in
NonlinearVariationalProblemandNonlinearVariationalSolver. Needs https://gitlab.com/petsc/petsc/-/merge_requests/9331 to be merged in PETSc