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 delete the plot code because WSL cannot use it.
"""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 = 1 + x^2 + 2y^2 = u_D f = -6This is an extended version of the demo program poisson.py whichencapsulates the solver as a Python function."""from __future__ importprint_functionfromdolfinimport*importnumpyasnpdefsolver(f, u_D, Nx, Ny, degree=1):
""" Solve -Laplace(u) = f on [0,1] x [0,1] with 2*Nx*Ny Lagrange elements of specified degree and u = u_D (Expresssion) on the boundary. """# Create mesh and define function spacemesh=UnitSquareMesh(Nx, Ny)
V=FunctionSpace(mesh, 'P', degree)
# Define boundary conditiondefboundary(x, on_boundary):
returnon_boundarybc=DirichletBC(V, u_D, boundary)
# Define variational problemu=TrialFunction(V)
v=TestFunction(V)
a=dot(grad(u), grad(v))*dxL=f*v*dx# Compute solutionu=Function(V)
solve(a==L, u, bc)
returnudefrun_solver():
"Run solver to compute and post-process solution"# Set up problem parameters and call solveru_D=Expression('1 + x[0]*x[0] + 2*x[1]*x[1]', degree=2)
f=Constant(-6.0)
u=solver(f, u_D, 8, 8, 1)
# Plot solution and mesh# plot(u)# plot(u.function_space().mesh())# Save solution to file in VTK formatvtkfile=File('poisson_solver/solution.pvd')
vtkfile<<udeftest_solver():
"Test solver by reproducing u = 1 + x^2 + 2y^2"# Set up parameters for testingtol=1E-10u_D=Expression('1 + x[0]*x[0] + 2*x[1]*x[1]', degree=2)
f=Constant(-6.0)
# Iterate over mesh sizes and degreesforNx, Nyin [(3, 3), (3, 5), (5, 3), (20, 20)]:
fordegreein1, 2, 3:
print('Solving on a 2 x (%d x %d) mesh with P%d elements.'% (Nx, Ny, degree))
# Compute solutionu=solver(f, u_D, Nx, Ny, degree)
# Extract the meshmesh=u.function_space().mesh()
# Compute maximum error at verticesvertex_values_u_D=u_D.compute_vertex_values(mesh)
vertex_values_u=u.compute_vertex_values(mesh)
error_max=np.max(np.abs(vertex_values_u_D- \
vertex_values_u))
# Check maximum errormsg='error_max = %g'%error_maxasserterror_max<tol, msgif__name__=='__main__':
run_solver()
# interactive()
The text was updated successfully, but these errors were encountered:
Hello guys @cako@meg-simula@hplgit@pdenapo, why don't we update the outdated file in this tutorial repo? It looks like this repo has been in lack of maintenance for two years.
I use FEniCS installed in WSL of Windows 10.
The version is 2019.01.
Then I update demo files in the tutorial.
I delete the plot code because WSL cannot use it.
The text was updated successfully, but these errors were encountered: