I am using PETScTAOSolver to solve the bounded solution problem along with OptimisationProblem class.
is OptimisationProblem class still a part of dolfinx?
in Dolfin: is was class dolfin.cpp.la.
OptimisationProblem
Thank you
Manish
dokken
August 4, 2022, 2:15pm
2
In DOLFINx, we leverage the python interface of PETSc , namely petsc4py, which has a petsctao interface: https://petsc.org/release/docs/manual/manual.pdf
It should be quite similar as to how to define a SNES solver with DOLFINx, as done in:
class NonlinearPDE_SNESProblem:
def __init__(self, F, u, bc):
V = u.function_space
du = TrialFunction(V)
self.L = form(F)
self.a = form(derivative(F, u, du))
self.bc = bc
self._F, self._J = None, None
self.u = u
def F(self, snes, x, F):
"""Assemble residual vector."""
x.ghostUpdate(addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD)
x.copy(self.u.vector)
self.u.vector.ghostUpdate(addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD)
with F.localForm() as f_local:
f_local.set(0.0)
assemble_vector(F, self.L)
apply_lifting(F, [self.a], bcs=[[self.bc]], x0=[x], scale=-1.0)
This file has been truncated. show original
# Create nonlinear problem
problem = NonlinearPDE_SNESProblem(F, u, bc)
u.x.array[:] = 0.9
b = la.create_petsc_vector(V.dofmap.index_map, V.dofmap.index_map_bs)
J = create_matrix(problem.a)
# Create Newton solver and solve
snes = PETSc.SNES().create()
snes.setFunction(problem.F, b)
snes.setJacobian(problem.J, J)
snes.setTolerances(rtol=1.0e-9, max_it=10)
snes.getKSP().setType("preonly")
snes.getKSP().setTolerances(rtol=1.0e-9)
snes.getKSP().getPC().setType("lu")
snes.solve(None, u.vector)
2 Likes
Thank you for your response. I think this approach can help me to solve the problem with PETSCTAOSolver also.