Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions chapter1/fundamentals_code.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@
"(error-norm)=\n",
"## Computing the error\n",
"Finally, we want to compute the error to check the accuracy of the solution.\n",
"We do this by comparing the finite element solution `u` with the exact solution.\n",
"We do this by comparing the finite element solution `uh` with the exact solution.\n",
"First we interpolate the exact solution into a function space that contains it"
]
},
Expand All @@ -402,8 +402,8 @@
"outputs": [],
"source": [
"V2 = fem.functionspace(domain, (\"Lagrange\", 2))\n",
"uex = fem.Function(V2, name=\"u_exact\")\n",
"uex.interpolate(lambda x: 1 + x[0] ** 2 + 2 * x[1] ** 2)"
"ue = fem.Function(V2, name=\"u_exact\")\n",
"ue.interpolate(lambda x: 1 + x[0] ** 2 + 2 * x[1] ** 2)"
]
},
{
Expand All @@ -412,7 +412,7 @@
"metadata": {},
"source": [
"We compute the error in two different ways.\n",
"First, we compute the $L^2$-norm of the error, defined by $E=\\sqrt{\\int_\\Omega (u_D-u_h)^2\\mathrm{d} x}$.\n",
"First, we compute the $L^2$-norm of the error, defined by $E=\\sqrt{\\int_\\Omega (u_e-u_h)^2\\mathrm{d} x}$.\n",
"We use UFL to express the $L^2$-error, and use {py:func}`dolfinx.fem.assemble_scalar` to compute the scalar value.\n",
"In DOLFINx, {py:func}`assemble_scalar<dolfinx.fem.assemble_scalar>`\n",
"only assembles over the cells on the local process.\n",
Expand All @@ -428,7 +428,7 @@
"metadata": {},
"outputs": [],
"source": [
"L2_error = fem.form(ufl.inner(uh - uex, uh - uex) * ufl.dx)\n",
"L2_error = fem.form(ufl.inner(uh - ue, uh - ue) * ufl.dx)\n",
"error_local = fem.assemble_scalar(L2_error)\n",
"error_L2 = numpy.sqrt(domain.comm.allreduce(error_local, op=MPI.SUM))"
]
Expand Down
10 changes: 5 additions & 5 deletions chapter1/fundamentals_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,23 +268,23 @@
# (error-norm)=
# ## Computing the error
# Finally, we want to compute the error to check the accuracy of the solution.
# We do this by comparing the finite element solution `u` with the exact solution.
# We do this by comparing the finite element solution `uh` with the exact solution.
# First we interpolate the exact solution into a function space that contains it

V2 = fem.functionspace(domain, ("Lagrange", 2))
uex = fem.Function(V2, name="u_exact")
uex.interpolate(lambda x: 1 + x[0] ** 2 + 2 * x[1] ** 2)
ue = fem.Function(V2, name="u_exact")
ue.interpolate(lambda x: 1 + x[0] ** 2 + 2 * x[1] ** 2)

# We compute the error in two different ways.
# First, we compute the $L^2$-norm of the error, defined by $E=\sqrt{\int_\Omega (u_D-u_h)^2\mathrm{d} x}$.
# First, we compute the $L^2$-norm of the error, defined by $E=\sqrt{\int_\Omega (u_e-u_h)^2\mathrm{d} x}$.
# We use UFL to express the $L^2$-error, and use {py:func}`dolfinx.fem.assemble_scalar` to compute the scalar value.
# In DOLFINx, {py:func}`assemble_scalar<dolfinx.fem.assemble_scalar>`
# only assembles over the cells on the local process.
# This means that if we use 2 processes to solve our problem,
# we need to accumulate the local contributions to get the global error (on one or all processes).
# We can do this with the {py:meth}`Comm.allreduce<mpi4py.MPI.Comm.allreduce>` function.

L2_error = fem.form(ufl.inner(uh - uex, uh - uex) * ufl.dx)
L2_error = fem.form(ufl.inner(uh - ue, uh - ue) * ufl.dx)
error_local = fem.assemble_scalar(L2_error)
error_L2 = numpy.sqrt(domain.comm.allreduce(error_local, op=MPI.SUM))

Expand Down