Skip to content

Fix 2D/3D L1 error quadrature sampling only the diagonal#14

Merged
JulienLoiseau merged 3 commits into
lanl:mainfrom
yrasool:fix-2d-3d-l1-quadrature
Jul 13, 2026
Merged

Fix 2D/3D L1 error quadrature sampling only the diagonal#14
JulienLoiseau merged 3 commits into
lanl:mainfrom
yrasool:fix-2d-3d-l1-quadrature

Conversation

@yrasool

@yrasool yrasool commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

This fixes the 2D and 3D L1 error calculation in compute_l1_error_fvm.

The old nested simple_quad calls passed whole quadrature-point arrays into the analytical function. In 2D and 3D that paired x_i with y_i and z_i, so the integral was sampled along the cell diagonal and then scaled by the weight sum.

For example, using the old path:

  • integral x*y dx dy over [0, 1]^2 gives 1/3, but the correct value is 1/4.
  • integral x*y*z dx dy dz over [0, 1]^3 gives 1/4, but the correct value is 1/8.

The patch adds explicit tensor-product Gauss-Legendre helpers for 2D and 3D and keeps the analytical callable contract the same: it still receives equal-length coordinate arrays.

Checks

  • Added tools/test_verify_lib.py with 2D and 3D exact-cell-average regression tests.
  • python tools/test_verify_lib.py
  • Reproduced the old diagonal-sampling values above.
  • Checked the new helpers against exact 2D/3D polynomial integrals on asymmetric boxes.
  • Checked sin(x + y) against its exact 2D integral.
  • Checked an asymmetric 3D non-polynomial integral against a dense independent reference.
  • Checked end-to-end 2D L1 error for exact cell averages: 0.
  • git diff --check
  • ruff check tools/verify_lib.py tools/test_verify_lib.py

yrasool and others added 2 commits July 8, 2026 15:38
simple_quad passes the whole array of quadrature points to f at once.
In the nested 2D/3D calls the outer lambda therefore received an array
of y points, and analytical([x, y]) paired x_i with y_i elementwise, so
the cell integral was evaluated only along the cell diagonal and then
rescaled by the weight sum. For f(x,y) = x*y over the unit square this
gives 1/3 instead of 1/4.

Replace the nested calls with tensor-product quadrature helpers. The
analytical callable still receives equal length coordinate arrays.
@yrasool

yrasool commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Added a small standalone regression test in tools/test_verify_lib.py for the 2D and 3D cell-integral paths. I tested this on my own locally with python tools/test_verify_lib.py, and reran ruff plus git diff --check.

The existing checks use square cells and integrands that are symmetric
in x and y, so a swapped argument pair or a mixed up axis would still
pass. Add direct checks of simple_quad_2d and simple_quad_3d on
asymmetric boxes against closed form integrals.
@AndresYague

Copy link
Copy Markdown
Contributor

This is a very useful patch. Thank you for spotting the error, doing the verification work and adding a test.

@yrasool

yrasool commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

This is a very useful patch. Thank you for spotting the error, doing the verification work and adding a test.

Thankyou for your kind response. I appreciate it and I hope to learn and contribute more . Honestly was good fun this one.

@JulienLoiseau JulienLoiseau merged commit 3f86c70 into lanl:main Jul 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants