-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing the error computation in the partitioned-heat-equation tutorial (
#14) * working on a fix for the partitioned-heat-equation tutorial * working on a fix for the partitioned-heat-equation tutorial * Trying out solutions for L2 error computation from the Discourse * Error computation in working state * Formatting * Calculate relative error instead of absolute error and clean up script * Formatting Co-authored-by: Ishaan Desai <ishaandesai@gmail.com>
- Loading branch information
1 parent
d7a2491
commit 26678c1
Showing
4 changed files
with
25 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 12 additions & 10 deletions
22
tutorials/partitioned-heat-conduction/fenicsx/errorcomputation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
from fenics import inner, assemble, dx, project, sqrt | ||
from ufl import dx | ||
from dolfinx.fem import assemble_scalar, form | ||
import numpy as np | ||
from mpi4py import MPI | ||
|
||
|
||
def compute_errors(u_approx, u_ref, v, total_error_tol=10 ** -4): | ||
# compute pointwise L2 error | ||
error_normalized = (u_ref - u_approx) / u_ref | ||
# project onto function space | ||
error_pointwise = project(abs(error_normalized), v) | ||
# determine L2 norm to estimate total error | ||
error_total = sqrt(assemble(inner(error_pointwise, error_pointwise) * dx)) | ||
error_pointwise.rename("error", " ") | ||
def compute_errors(u_approx, u_ref, total_error_tol=10 ** -4): | ||
mesh = u_ref.function_space.mesh | ||
|
||
# compute total L2 error between reference and calculated solution | ||
error_pointwise = form(((u_approx - u_ref) / u_ref) ** 2 * dx) | ||
error_total = np.sqrt(mesh.comm.allreduce(assemble_scalar(error_pointwise), MPI.SUM)) | ||
|
||
assert (error_total < total_error_tol) | ||
|
||
return error_total, error_pointwise | ||
# return error_total, error_pointwise | ||
return error_total |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters