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

Add and remove a PointSource

0 votes

Is there a way to add and then remove a PointSource?

In 2 dimensions what I want is:

mesh_obj = UnitSquareMesh(100,100)
V = FunctionSpace( mesh_obj, "CG", 1 )
v = TestFunction( V )
L = Constant(0.0) * v * dx
b  = assemble ( L )

for pt in list_of_points:
    PointSource( V, Point( pt ), 1.0 ).apply( b )
    # Use this for some calculation.
    # remove the PointSource so I don't need to reassemble b.
asked Apr 5, 2016 by Yair Daon FEniCS User (1,350 points)

1 Answer

+2 votes
 
Best answer

Hi, consider applying the source with a negated amplitude

from dolfin import *

mesh = UnitSquareMesh(10 ,10)
V = FunctionSpace(mesh, 'CG', 1 )
v = TestFunction(V)
L = Constant(0.0)*v*dx
b = assemble(L)

list_of_points = Point(0.25, 0.25), Point(0.5, 0.5), Point(0.75, 0.75)
amp = 2.

for pt in list_of_points:
    print 'b before', b.norm('linf')
    source_add = PointSource(V, Point(pt), amp)
    source_add.apply(b)
    print 'b with add', b.norm('linf')
    # Use this for some calculation.
    # remove the PointSource so I don't need to reassemble b.
    source_remove = PointSource(V, Point(pt), -amp)
    source_remove.apply(b)
    print 'b after', b.norm('linf')
answered Apr 5, 2016 by MiroK FEniCS Expert (80,920 points)
selected Apr 5, 2016 by Yair Daon

I was hoping for a more "natural" interface - my worry was that this may accumulate numerical noise if performed many times. Currently it seems to work just fine, so thanks!

...