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