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

Adaptive solution fails

+1 vote

Hello
I have a simple elliptic problem in 2d which I want to solve using the automatic adaptive solver. The domain is obtained by subtracting two ellipses.

After the first step, the solution process reports nan. The code is below. Can you see whats wrong with my approach.

from dolfin import *

n1, n2 = 20, 20

# center of the ellipses
x1, y1 = 0.0, 0.0
x2, y2 = 0.0, 0.0
# major and minor axes
a1, b1 = 2.0, 1.0
a2, b2 = 1.0, 0.5

e1 = Ellipse(x1, y1, a1, b1, n1)
e2 = Ellipse(x2, y2, a2, b2, n2)
g2d = e1 - e2

mesh = Mesh(g2d, 20)
plot(mesh)

V = FunctionSpace(mesh, 'CG', 1)
u = TrialFunction(V)
v = TestFunction(V)

a = inner(grad(u), grad(v))*dx
L = v*dx

bc = DirichletBC(V, 0, "on_boundary")

u = Function(V)

# Functional
M = u*dx
tol = 1.0e-5

# 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")
interactive()

Solution on first mesh is fine. But after first adaptation, solution becomes nan.

asked May 20, 2014 by praveen FEniCS User (2,760 points)
edited May 20, 2014 by praveen

1 Answer

+2 votes
 
Best answer

Hi, if you are using DOLFIN version 1.3.0 then the issue might be due to poor quality of the mesh. Try inspecting with

print MeshQuality.radius_ratio_min_max(mesh)

With 1.3.0. I got (6.281173058588524e-36, 0.9999985309411911); the first value suggests
that the mesh has some degenerate element(s).

answered May 20, 2014 by MiroK FEniCS Expert (80,920 points)
selected May 21, 2014 by praveen

Yes I get min ratio to be almost zero. But I dont see why it happens. It is a simple domain and I use built in mesh generator.

The built in mesh generator in version 1.3.0 seems to have hard time meshing circular/elliptical domains. See also here.

Thanks. I will have to wait for the new release. I have never compiled fenics myself.

...