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

Is this right Expression('pow(x[0], -0.2)', degree=2) ???

0 votes

Thank you for your any help !!!

When I set u_D = Expression('pow(x[0], 0.2) * x[1]', degree=5), I got a result.
But when I set u_D = Expression('pow(x[0], -0.2) * x[1]', degree=5), the L2-error become NaN.

Why ??? Is that right using pow(x[0], -0.2) in an Expression() ???

Below is my code:

from fenics import *

# Create mesh and define function space
mesh = UnitSquareMesh(10, 10)
V = FunctionSpace(mesh, 'P', 1)

# Define boundary condition
u_D = Expression('pow(x[0],-0.2) * x[1]', degree=5)

def boundary(x, on_boundary):
    return on_boundary
bc = DirichletBC(V, u_D, boundary)

# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(0)
a = dot(grad(u), grad(v))*dx
L = f*v*dx

# Compute solution
u = Function(V)
solve(a == L, u, bc)

# Plot solution and mesh
plot(u)

# Compute error in L2 norm
error_L2 = errornorm(u_D, u, 'L2')
print('error_L2  =', error_L2)

interactive()
asked Jun 4, 2017 by fanronghong FEniCS User (1,680 points)

1 Answer

+1 vote
 
Best answer

Your code looks good. I think that the problem is that your domain includes the point (0.0, 0.0), in which your expression u_D tends to infinity.

answered Jun 5, 2017 by hernan_mella FEniCS Expert (19,460 points)
selected Jun 18, 2017 by fanronghong
...