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
Can use ufl.reconstruct to increase the element degree:
deferror_L2(uh, u_ex, degree_raise=3):
# Create higher order function spaceufl_el=uh.function_space.ufl_element()
new_el=ufl_el.reconstruct(degree=degree_raise+ufl_el.degree())
mesh=uh.function_space.meshW=fem.FunctionSpace(mesh, new_el)
# Interpolate approximate solutionu_W=fem.Function(W)
u_W.interpolate(uh)
# Interpolate exact solution, special handling if exact solution# is a ufl expression or a python lambda functionu_ex_W=fem.Function(W)
ifisinstance(u_ex, ufl.core.expr.Expr):
u_expr=fem.Expression(u_ex, W.element.interpolation_points())
u_ex_W.interpolate(u_expr)
else:
u_ex_W.interpolate(u_ex)
# Compute the error in the higher order function spacee_W=fem.Function(W)
e_W.x.array[:] =u_W.x.array-u_ex_W.x.array# Integrate the errorerror=fem.form(ufl.inner(e_W, e_W) *ufl.dx)
error_local=fem.assemble_scalar(error)
error_global=mesh.comm.allreduce(error_local, op=MPI.SUM)
returnnp.sqrt(error_global)
The text was updated successfully, but these errors were encountered:
Can use
ufl.reconstruct
to increase the element degree:The text was updated successfully, but these errors were encountered: