Passing PETSc options to standard solve()


283
views
1
12 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.ksp().setFromOptions()
solver.set_operator(A)
solver.solve(u_sol.vector(), b)
1
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 12 months ago by pf4d 
yeah, dolfin-adjoint generates the adjoint using the regular solve.
written 12 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 12 months ago by pf4d 
Yeah, it seems that in the new generation dolfin-adjoint, pyadjoint https://bitbucket.org/dolfin-adjoint/pyadjoint/src the task of implementing your own linear solver is easier.
written 12 months ago by Miguel 
Please login to add an answer/comment or follow this question.

Similar posts:
Search »