Passing PETSc options to standard solve()

10 months ago by

How to pass PETSc options to the standard solve() in FEniCS? First solve (standard) doesn't see the options, whereas the PETScKrylovSolver does.

from dolfin import *

PETScOptions().set("ksp_monitor_true_residual", "")
PETScOptions().set("ksp_monitor_singular_value", "")

mesh = UnitSquareMesh(10,10)
V = FunctionSpace(mesh, 'CG', 1)

u = TrialFunction(V)
v = TestFunction(V)

a = inner(grad(u), grad(v))*dx + u*v*dx
f = Constant(5.0)
L = f*v*dx

u_sol = Function(V)

solve(a==L, u_sol, solver_parameters={"linear_solver":"cg"})

A = assemble(a)
b = assemble(L)

solver = PETScKrylovSolver()
solver.solve(u_sol.vector(), b)
Community: FEniCS Project
I feel like the generic solve method is just there to let people who don't want to care about the details to just "solve".  Is there a problem with using the more explicit wrapper functions to make you want to use "solve" instead?
written 10 months ago by pf4d  
yeah, dolfin-adjoint generates the adjoint using the regular solve.
written 10 months ago by Miguel  
That is a valid reason. I have used dolfin-adjoint for quite a few things, and it's great software, but it can't do everything. I feel like unless you are using the checkpointing, it is better to solve the adjoint manually.
written 10 months ago by pf4d  
Yeah, it seems that in the new generation dolfin-adjoint, pyadjoint the task of implementing your own linear solver is easier.
written 10 months ago by Miguel  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »