Spatial coordinate in variational form

Issue #55 invalid
Mike Welland created an issue

According to https://answers.launchpad.net/fenics/+question/103102, I should be able to use spatial coordinates in my variational form. (FEniCS 1.4.0 compiled from source), but it complains "NameError: name 'x' is not defined" Is this not enabled?

MWE:

from dolfin import *

parameters["form_compiler"]["representation"] = "quadrature"

# Create mesh and define function space
mesh = IntervalMesh(10, 0, 1)
V = FunctionSpace(mesh, "Lagrange", 1)

# Define boundary condition
u0 = Function(V)
bc = DirichletBC(V, u0, "std::abs(x[0] -1) < DOLFIN_EPS")

#r = Expression('x[0]') #Works
r = x[0] #Doesn't work


# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
a = inner(grad(u), grad(v))*r*dx()
L = 1.*v*r*dx()

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

# 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 = LinearVariationalSolver(problem)
solver.solve()

# Plot solution(s)
plot(u, title="Solution on initial mesh")
interactive()

Comments (3)

  1. Log in to comment