I am new to Fenics and I am trying to solve some basic pdes, following the examples in the tutorial. I am solving a Poisson equation and my code look the same as the one in the tutorial. However, the 3D mesh is not showing when I run the cell. Could someone help me to fix the problem ? Thank you. Below is my code attempt
## Fenics implementation: The complete code
# Generate the mesh and define function space
mesh = UnitCubeMesh(10,10,10)
V = FunctionSpace(mesh, "P", 1)
# Boundary condition
u_D = Expression("1+x[0]*x[0] + 2*x[1]*x[1]", degree=2)
def boundary(x, on_boundary):
return on_boundary
bc = DirichletBC(V, u_D, boundary)
# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(-6.0)
a = dot(grad(u), grad(v))*dx
L = f*v*dx
# Compute solution
u = Function(V)
solve(a == L, u, bc)
# plot the solution and the mesh
plt.subplot(projection="3d")
plt.subplot()
plt.plot(mesh)
#plot(u)
#plot(mesh)
# Save solution to file in VTK format
vtkfile = File("poisson/solution.pvd")
vtkfile << u
I first used the plot command from matplotlib but still, no output.