Can an array of values be assigned to the source term?

2.:
I’d recommend using pyvista4dolfinx (Pyvista4dolfinx). Then simply:

import pyvista4dolfinx as p4d
p4d.plot(f, show=True)

1.:
To confirm my hypothesis? I’d compute a second uh with that constant body force, and substract the results. Below your lines of code:

# Second computation
f.x.array[:] = 250
problem2 = LinearProblem(a=a,L=L,bcs = [uD]) 
uh_250_dif = problem2.solve()
uh_250_dif.name = 'diff'
uh_250_dif.x.array[:] -= uh.x.array[:]

# Plot
import pyvista4dolfinx as p4d
plotter = p4d.Plotter(shape=(1, 2))
p4d.plot(uh, plotter=plotter, subplot=(0,0))
p4d.plot(uh_250_dif, plotter=plotter, subplot=(0,1), show=True)

3.:
f_size_local is the number of degrees of freedom being worked on by the current process. If you run on 1 core, it will simply be the number of dofs of the space. For a DG0 space, this is 1 dof per element. You have a mesh of 20x20x2 elements (x2 because triangles), so 800 dofs.

4.: That’s a good question, and I guess your main challenge. I don’t have a good answer for you. I would honestly not simply assign values to dofs of a DG space, but somehow try to actually interpolate the data that you have to change it from discrete to continuous. But the strategy for operating on an array of measurement data is not really related to FEniCs. If the array is structured in x and y, then I believe numpy has some functionality for interpolating between datapoints. Once you have some representation of your data that can be querried at all (x,y), then you can simply use the f.interpolate functionality of fenics (Interpolation and IO — DOLFINx 0.9.0 documentation)

1 Like