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

Applying the Dirac Delta Function w/o using the Fenics PointSource function

+2 votes

Good evening,

I am working on a problem where Dirac has to be applied. I am already aware of the option, assembling the system and then applying the Dirac with the PointSource function on the right hand side vector. My question is, is there another way of applying the Dirac Delta function before or without the system being assembled (before any linear algebra ops take place), eg if I'm using the solve( a == L, u, bcs) function.

Thanks in advance

asked Aug 27, 2015 by chanik FEniCS Novice (180 points)
edited Aug 28, 2015 by chanik

Hi, could you pls. tell me what problem are you working on? Thanks.

Hi, it's a Poisson problem uxx+uyy=f, in a rectangular domain, Dirichlet BC everywhere but the right side, where Neumann apply, with a point source in the interior of the domain.

1 Answer

+1 vote
 
Best answer

Hi, you could use some of the limit definitions of the delta function in the Expression. For example

from dolfin import *

class Delta(Expression):
    def __init__(self, eps):
        self.eps = eps
    def eval(self, values, x):
        eps = self.eps
        values[0] = eps/pi/(x[0]**2 + eps**2) 

mesh = IntervalMesh(1000, -1, 1)
V = FunctionSpace(mesh, 'CG', 1)
bc = DirichletBC(V, Constant(0), 'on_boundary')
u = TrialFunction(V)
v = TestFunction(V)

a = inner(grad(u), grad(v))*dx 
delta = Delta(1E-4)
L = inner(delta, v)*dx

u = Function(V)
if True:
    solve(a == L, u, bc)
else:
    A, b = assemble_system(a, L, bc)
    b.zero()
    PointSource(V, Point(0), 100).apply(b)
    solve(A, u.vector(), b)

plot(delta, mesh=mesh)
plot(u, interactive=True)

Note that in the example I did not tune the parameters of delta or the point source to make the solutions match.

answered Aug 29, 2015 by MiroK FEniCS Expert (80,920 points)
selected Sep 2, 2015 by chanik

Thanks for your reply MiroK!

...