You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use FEniCS installed in WSL of Windows 10.
The version is 2019.01.
Then I update demo files in the tutorial.
I change the plot code because WSL cannot use GUI but it can save figure.
"""FEniCS tutorial demo program: Poisson equation with Dirichlet conditions.Test problem is chosen to give an exact solution at all nodes of the mesh. -Laplace(u) = f in the unit square u = u_D on the boundary u_D = 1 + x^2 + 2y^2 f = -6"""# from __future__ import print_functionfromdolfinimport*# Create mesh and define function spacemesh=UnitSquareMesh(8, 8)
V=FunctionSpace(mesh, 'P', 1)
# Define boundary conditionu_D=Expression('1 + x[0]*x[0] + 2*x[1]*x[1]', degree=2)
defboundary(x, on_boundary):
returnon_boundarybc=DirichletBC(V, u_D, boundary)
# Define variational problemu=TrialFunction(V)
v=TestFunction(V)
f=Constant(-6.0)
a=dot(grad(u), grad(v))*dxL=f*v*dx# Compute solutionu=Function(V)
solve(a==L, u, bc)
# Plot solution and mesh# plot(u)# plot(mesh)importmatplotlib.pyplotaspltplot(mesh)
plt.savefig('mesh.pdf')
plt.cla()
plot(u)
plt.savefig('u.pdf')
plt.cla()
# Save solution to file in VTK formatvtkfile=File('poisson/solution.pvd')
vtkfile<<u# Compute error in L2 normerror_L2=errornorm(u_D, u, 'L2')
# Compute maximum error at verticesvertex_values_u_D=u_D.compute_vertex_values(mesh)
vertex_values_u=u.compute_vertex_values(mesh)
importnumpyasnperror_max=np.max(np.abs(vertex_values_u_D-vertex_values_u))
# Print errorsprint('error_L2 =', error_L2)
print('error_max =', error_max)
# Hold plot# interactive()
The text was updated successfully, but these errors were encountered:
I would add plt.switch_backend('agg') just after importing matplotlib to ensure it uses the non-interactive backend. Useful reference in the docs can be found here
I use FEniCS installed in WSL of Windows 10.
The version is 2019.01.
Then I update demo files in the tutorial.
I change the plot code because WSL cannot use GUI but it can save figure.
The text was updated successfully, but these errors were encountered: