This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to get convergence rate in adaptive poisson problem ?

0 votes

Thank you for your any help !!! I appreciate it.

I know how to solve poisson problem using AdaptiveLinearVariationalSolver().
But how do I get the error and convervence rate at every refinement step ?

My code is below:

from dolfin import *

# Create mesh and define function space
mesh = UnitSquareMesh(8, 8)
V = FunctionSpace(mesh, "Lagrange", 1)

# Define boundary condition
u0 = Function(V)
bc = DirichletBC(V, u0, "x[0] < DOLFIN_EPS || x[0] > 1.0 - DOLFIN_EPS")

# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Expression("10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)",
               degree=1)
g = Expression("sin(5*x[0])", degree=1)
a = inner(grad(u), grad(v))*dx()
L = f*v*dx() + g*v*ds()

# Define function for the solution
u = Function(V)

# Define goal functional (quantity of interest)
M = u*dx()

# Define error tolerance
tol = 1.e-4

# Solve equation a = L with respect to u and the given boundary
# conditions, such that the estimated error (measured in M) is less
# than tol

problem = LinearVariationalProblem(a, L, u, bc)
solver = AdaptiveLinearVariationalSolver(problem, M)
solver.parameters["error_control"]["dual_variational_solver"]["linear_solver"] = "cg"
solver.solve(tol)

solver.summary()

# Plot solution(s)
plot(u.root_node(), title="Solution on initial mesh")
plot(u.leaf_node(), title="Solution on final mesh")
plot(mesh.root_node())
plot(mesh.leaf_node())
interactive()
asked Jun 4, 2017 by fanronghong FEniCS User (1,680 points)

Is it possible to set the number of steps? If so, set them to 1 and compare step by step. If not, it is possible to refine manually:

https://fenicsproject.org/olddocs/dolfin/1.5.0/python/programmers-reference/mesh/refinement/refine.html

Let me know if it is useful. Best regards!

Thank you for your answer.

Your idea is great.
But I can't find such parameters to set until now.

I find a parameter, "adapt_iter".
But I don't how to set the parameter in solver.

...