Daniel:
> interpolation_n2.png
>
> Am I doing something wrong? Is there a different/better way to achieve
> what I need?
I haven't explored this in detail, but I think what you see is
ultimately a result of the fact that what you are doing is not a
well-defined problem (though I admit that it could be done better).
At its core, you are interpolating onto a continuous finite element
space that has its nodes at exactly those locations where the function
you are trying to interpolate is discontinuous. The algorithm behind
FETools::interpolate() has to somehow choose which of the possible
values of the input function it wants to assign each output DoF. The way
it does this is that it loops over all locally owned cells
https://github.com/dealii/dealii/blob/master/include/deal.II/fe/fe_tools_interpolate.templates.h#L146-L148
and for each DoF on these cells, if the DoF is locally owned
https://github.com/dealii/dealii/blob/master/include/deal.II/fe/fe_tools_interpolate.templates.h#L202-L206
it adds the value of the input function to the output vector (also
keeping track how often it added something to the output vector):
https://github.com/dealii/dealii/blob/master/include/deal.II/fe/fe_tools_interpolate.templates.h#L208-L212
In your case, this means that for every DoF in the interior of a
processor's subdomain, we write into the output vector more than once
and then we take the average of all of these values:
https://github.com/dealii/dealii/blob/master/include/deal.II/fe/fe_tools_interpolate.templates.h#L234-L249
This makes sure that the output vector has *averages* of the inputs at
node positions. But for DoFs that lie at the interfaces between
processes, we only get contributions from the MPI process that owns the
DoF, and so you're not averaging over the contributions from all
adjacent cells but only those adjacent cells owned by that process (see
line 206).
One could consider this undesirable: We should really be adding up from
all adjacent cells. You could try what happens if you remove the
if-condition in line 206. In the sequential case, this should make no
difference. In the parallel case, I think it should achieve what you are
trying to do. Would you want to try that out, and if it works as
suggested make that into a patch to deal.II?
Best
W.