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.
"""FEniCS tutorial demo program: Nonlinear Poisson equation. -div(q(u)*grad(u)) = f in the unit square. u = u_D on the boundary."""from __future__ importprint_function# Warning: from fenics import * will import both `sym` and# `q` from FEniCS. We therefore import FEniCS first and then# overwrite these objects.fromfenicsimport*defq(u):
"Return nonlinear coefficient"return1+u**2# Use SymPy to compute f from the manufactured solution uimportsympyassymx, y=sym.symbols('x[0], x[1]')
u=1+x+2*yf=-sym.diff(q(u)*sym.diff(u, x), x) -sym.diff(q(u)*sym.diff(u, y), y)
f=sym.simplify(f)
u_code=sym.printing.ccode(u)
f_code=sym.printing.ccode(f)
print('u =', u_code)
print('f =', f_code)
# Create mesh and define function spacemesh=UnitSquareMesh(8, 8)
V=FunctionSpace(mesh, 'P', 1)
# Define boundary conditionu_D=Expression(u_code, degree=2)
defboundary(x, on_boundary):
returnon_boundarybc=DirichletBC(V, u_D, boundary)
# Define variational problemu=Function(V) # Note: not TrialFunction!v=TestFunction(V)
f=Expression(f_code, degree=2)
F=q(u)*dot(grad(u), grad(v))*dx-f*v*dx# Compute solutionsolve(F==0, u, bc)
# Plot solutionimportmatplotlib.pyplotaspltplot(u)
plt.savefig('u.png')
plt.cla# Compute maximum error at vertices. This computation illustrates# an alternative to using compute_vertex_values as in poisson.py.u_e=interpolate(u_D, V)
importnumpyasnperror_max=np.abs(u_e.vector().get_local() -u.vector().get_local()).max()
print('error_max = ', error_max)
# Hold plot# interactive()
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: