Plot of solution only showing at nodal values

I am using Fenics to extract the FEM matrices and to plot the finite element solution. I am using another language to solve the resulting time dependent system.

The domain of the PDE is a complicated shape with different portions of the boundary subject to various boundary conditions.

I am doing a simple experiment in which I supply the nodal values of the FEM solution, i.e.

unodalVals = 10*np.ones(1357)

Then converting it to a vector object via

u.vector().set_local(unodalVals)

And subsequently plotting the FEM solution in my domain with a complicated shape.

plot(u)

However, below is a snippet of how the plot looks like:

I was expecting to see a single color just covering the whole domain. Instead, what I get are blobs of the same intensity at the nodes of the mesh.

I am new to Fenics and did not encounter this issue with the heat equation example in the tutorial.

Any suggestions how to resolve this? Help appreciated.

A minimal working example would help diagnose the issue. But it looks like you’re providing the wrong / not enough data to a high order space.

Hi nate, thanks for getting back. Are you saying that the dimension of the nodal values I provided, 1357, is not enough? The resulting matrices I get from assemble in fenics have this dimension so I am not sure what you mean…

Another issue is that the inputs to FunctionSpace are xml.gz files.

It’s very difficult for me to help/debug without having a minimal working example.

Hi Nate,

Yes, that’s fair. Here’s a minimal working example. I really appreciate your help looking into this:

Here’s my code:
import numpy as np
import dolfin as df
import fenics as fe
import matplotlib.pyplot as plt

mesh_file = 'ref3_mesh_fenics.xml.gz'
gamma_numbers_file = 'ref3_gamma_numbers_fenics.xml.gz'

# set matrix reordering off
df.parameters['reorder_dofs_serial'] = False

# read mesh file and mesh function for gamma numbers
mesh = df.Mesh(mesh_file)
gamma_numbers = df.MeshFunction('size_t', mesh, gamma_numbers_file)

# define function space linear lagrange elements P1
V = df.FunctionSpace(mesh, 'Lagrange', 1)

u = df.Function(V)
unodalVals = 10*np.ones(1357) 
u.vector().set_local(unodalVals)
fe.plot(u)
plt.show()

The files included above can be downloaded from this link

I hope it’s more clear now…

Just as I said, you’re not providing enough data:

import dolfin as df
import matplotlib.pyplot as plt

mesh_file = 'ref3_mesh_fenics.xml.gz'
df.parameters['reorder_dofs_serial'] = False
mesh = df.Mesh(mesh_file)
V = df.FunctionSpace(mesh, 'Lagrange', 1)

u = df.Function(V)
unodalVals = 10*np.ones(1357) 
u.vector().set_local(unodalVals)

print(f"Number of DoFs: {V.dim()}, mesh vertices: {mesh.num_vertices()}, size of unodalVals: {unodalVals.shape}")

df.plot(u)
plt.show()

Number of DoFs: 5177, mesh vertices: 5177, size of unodalVals: (1357,)

Accounting for this, I get what I assume is your expected result:

image

Nate, thank you for your reply. However, I do not see what changes you made to my script. Did I overlook it? May I know what was the missing piece?

Choose your data correctly. It’s underprescribed. E.g. you could make the following change:

unodalVals = 10*np.ones(V.dim())

Hi Nate,

Yes, I just realized it now. Thank you so much. It turns out that the error is that I mismatched the file with the number of nodes. I should have used the file in the other directory for the 1357 degrees of freedom. This is really a stupid mistake from my end. Thanks for your patience!