Hello,
(my apologies if this appears twice - I can't seem to find the original post).
In any case, I am solving a simple laplace equation with dirichlet BCs applied to the left/right sides of the mesh.
My antiquated version of dolfin would permit the weak form
form = inner(grad(u)*grad(v)*dx)
a,L=lhs(form),rhs(form)
while the current version fails with 'Expecting a completed form with domains at this point."' unless I include a Neumann condition acting on the boundaries, like
form = inner(grad(u)*grad(v)*dx)
form+= Constant(0.)*v*ds
a,L=lhs(form),rhs(form)
Is there something simple I am missing with either my definition of the boundaries or how the weak form is being defined? My full script is below
Thanks!
Pete
from dolfin import *
# Define Dirichlet boundary (x = 0 or x = 1)
class LeftBoundary(SubDomain):
def inside(self, x, on_boundary):
return ( on_boundary and \
(x[0] < 0.5))
class RightBoundary(SubDomain):
def inside(self, x, on_boundary):
return ( on_boundary and \
(x[0] > 0.5))
# Create mesh and define function space
if 1:
mesh = UnitCubeMesh(8,8,8)
V = FunctionSpace(mesh,"CG",1)
# Initialize mesh function for interior domains
domains = CellFunction("size_t", mesh)
domains.set_all(0)
# Initialize mesh function for boundary domains
boundaries = FacetFunction("size_t", mesh)
boundaries.set_all(0)
# Define boundary condition
bcs=[]
leftBoundary = LeftBoundary()
lMarker = 2
leftBoundary.mark(boundaries,lMarker)
bc3 = DirichletBC(V, Constant(1.),boundaries,lMarker)
bcs.append(bc3)
rightBoundary = RightBoundary()
rMarker = 3
rightBoundary.mark(boundaries,rMarker)
bc4 = DirichletBC(V, Constant(0.),boundaries,rMarker)
bcs.append(bc4)
# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
# Define measures associated w interior domains and boundaries
dx = Measure("dx")[domains]
dxs = dx(domain=mesh,subdomain_data=domains)
ds = Measure("ds")[boundaries]
dss = ds(domain=mesh,subdomain_data=boundaries)
D = Constant(1.)
form = D*inner(grad(u), grad(v))*dxs
form+= Constant(0.) * v * dss(lMarker)
a = lhs(form)
L = rhs(form)
# Compute solution
u = Function(V)
solve(a == L, u, bcs)