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

How to solve simple 2D electrostatics problems using FEniCS?

–1 vote

For example, one charged particle is situated in uniform electric field. How to calculate the potential function? I don't understand how to make boudary conditions of Laplace equation in this case.

asked Apr 20, 2016 by Illusion FEniCS Novice (290 points)

Hi, you are more likely to get an answer if you state your problem in terms of equations. Is it $-\Delta \phi = \delta_0$ in the 2d domain where $\phi$ is the potential and $\delta$ the particle charge?

I would write equation if I know how to write in TeX on this site.

Yes. But we can understand the particle as point charge, so \delta=0.

1 Answer

0 votes

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) 
answered Apr 21, 2016 by Tristan FEniCS Novice (680 points)
...