Results visualization and interpolation - the "glowing" effect

I’ve encountered this issue when visualizing data. I know that solutions are associated with nodes. This is the nature of FEM. That is great!
And if I’d like to read values at some other points, the FEniCS will interpolate it.
This can be visualized on plot as shown below.

But this is also the problem.

I’ll give you an example:
I’m solving for magnetic field, and i have domain which has air properties (low magnetic permeability), ferromagnetic material (high magnetic permeability). The magnetic flux (the result) should be all contained within ferromagnetic material, but from the standpoint of visualization it looks as if it’s leaking outside.


Visualization in ParaView:

Material and results overlayed:

When visualizing magnetic flux, the transition should be steep between high-permeability and low-permeability regions.
I know, that from the numerical point of view the results are correct, the solution is at the nodes. The solution at nodes outside the ferromagnetic core is zero, the solution inside the ferromagnetic is a lot higher. But the issue is with the interpolation of data at those regions. You have high values at the edge (boundary between domains) and then zero a bit further away. The interpolation creates this glowing effect!

This will create two problems when solving any PDE equation:

  1. When reading values and interpolating data between different meshes might create unwanted values at some domains.
    At first i thought about solution such that when interpolating data, check whether the point belongs to certain region and then interpolate or not. But this is sort of cheating and wrong by itself. The user has to decide - even more error. And how do you even know what decision to make in the first place?!
  2. When communicating with the audience, or even visualizing data for your own purposes using surfaces, instead of solutions at points might cause confusion (but it’s the right way for FEM). Certain things shouldn’t “leak” outside certain domains when visualizing them.

Below, I’m adding visualization of a similar problem but made with commercial software, where such steep transition is present:

Is there a way to address these issues - both in code and with visualizing in ParaView or anything else?

I’ve found some solution when it comes to visualization in ParaView at least.

But the question is - how to obtain similar thing in FEniCS, using build in plot() function? :slight_smile: