I found this:
http://fenicsproject.org/qa/2893/point-source-in-rhs-of-heat-eq
I think the syntax for RectangleMesh has changed. So use:
mesh = RectangleMesh(Point(-1,-1), Point(1, 1), 100, 100, "right/left")
For the uniform electric field, you can add Dirichlet boundary conditions on two of the boundaries with the desired values.
from dolfin import *
mesh = RectangleMesh(Point(-1,-1), Point(1, 1), 100, 100, "right/left")
V = FunctionSpace(mesh, "CG", 1)
u = TrialFunction(V)
v = TestFunction(V)
class Left(SubDomain):
def inside(self, x , on_boundary):
return near(x[1], -1.0)
class Right(SubDomain):
def inside(self, x , on_boundary):
return near(x[1], 1.0)
bcs = [DirichletBC(V, Constant(0), Left()),
DirichletBC(V, Constant(100), Right())]
a = inner(grad(u), grad(v))*dx
L = Constant(0)*v*dx
A, b = assemble_system(a, L, bcs)
delta = PointSource(V, Point(0., 0.,), 100)
delta.apply(b)
u = Function(V)
solve(A, u.vector(), b)
plot(u, interactive=True)