Linear combination of point sources

Hi! I only recently learned that there is a canonical way to define point sources for the right hand side of PDEs, being

f = LinearForm(fes)
v = fes.TrialFunction()
f += v(0.7, 0.5)
f.Assemble()

for a point source centered in (0.7,0.5). Let us assume I now want my right hand side to be an arbitrary linear combination of point sources. However, a code on the form

f = LinearForm(fes)
v = fes.TrialFunction()
f += 3 * v(0.7, 0.5) + v(-0.3,0.6)
f.Assemble()

does not work, as apparently PointEval functions can be neither multiplied by floats nor added together (meaning just adding them one by one in a loop is also out, as my weights are not all 1).

I can make this work by defining a secondary LinearForm, adding a point source to it, then adding a multiple of its vector to f, i.e.

f = LinearForm(fes)
v = fes.TrialFunction()

f0 = LinearForm(fes)
f0 += v(0.7, 0.5)
f0.Assemble()

f.vec.data += 3 * f0.vec.data

f0 = LinearForm(fes)
f0 += v(-0.3, 0.6)
f0.Assemble()

f.vec.data += f0.vec.data

does work, but seems very clunky and slow due to the need to constantly assemble and redefine the utility-LinearForm f0, even though it’s at least loopable. Is there a better way?

For reference, I am presumably going to be adding a very large number of point sources together, possibly as a complex linear combination.

Cheers,
Christian

Hi,
you can scale them before the point-evaluation:

f += (3*v)(0.5, 0.7)

Then you can add many of them in a loop.

Oh, that really is an easy fix, thanks so much! Out of curiosity, why is the syntax 3*v(x,y) not possible and not equivalent to (3*v)(x,y)?

A second question, too: How close is this form of “pointwise evaluation” to a true pointwise evaluation/delta Dirac? Does it use some trick to provide an “actual” pointwise evaluation, or is it approximated by a high-order local integral?

Oh, that really is an easy fix, thanks so much! Out of curiosity, why is the syntax 3*v(x,y) not possible and not equivalent to (3*v)(x,y)?

simple answer: no particular rison, just not implemented

A second question, too: How close is this form of “pointwise evaluation” to a true pointwise evaluation/delta Dirac? Does it use some trick to provide an “actual” pointwise evaluation, or is it approximated by a high-order local integral?

it is exact point evaluation. We search for the triangle containing the point, compute local coordinates of the point, and evaluate the finite element basis functions there