Adaptive Solver: get coordinates of refined mesh

Hi,

i try to get the solution of a AdaptiveNonlinearVariationalSolver as arrays of the refined mesh coordinates and the solution.

This is my code:

from dolfin import *

mesh = IntervalMesh(100, 0, 10)
V = FunctionSpace(mesh, “CG”, 1)

def boundary(x, on_boundary):
return on_boundary and near(x[0], 0)

uL = Constant(1)
bcL = DirichletBC(V, uL, boundary)

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

a = -inner(grad(u), grad(v)) * dx
L = 1./20. * (exp(10 * u)-exp(-20 * u)) * v * dx

u_ = Function(V)
M = u_*dx()
tol = 1.e-5
F = a-L
F = action(F, u_)
J = derivative(F, u_, u)

problem = NonlinearVariationalProblem(F, u_, bcL, J)
solver = AdaptiveNonlinearVariationalSolver(problem, M)
solver.solve(tol)
solution_array = u_.leaf_node().compute_vertex_values()

Analogously to the last line, I tried to get the refined mesh coordinates using

mesh.leaf_node()

And I got the error message

AttributeError: ‘dolfin.cpp.generation.IntervalMesh’ object has no attribute ‘leaf_node’

How do I get the refined mesh then? Online I only found the way using leaf_node, which doesn’t seem to work for my problem…

Thanks for helping me out!

1 Like

To get the refined mesh, you can project the mesh function space to a function; then, you can easily extract the refined mesh.
Use the following code for the same :

R = u_.leaf_node().function_space()
plot(R.mesh())
2 Likes

Thanks a lot, that does the trick!

1 Like