spectral_galerkin_heat.io_utils.compute_L2_error
Compute the L2 norm error between two XDMF solution files at their last
time step, and optionally output an error.xdmf / error.h5 file
for ParaView visualisation.
Supported grid combinations
Both structured (
3DRectMesh/VXVYVZ): If the grids match exactly (same dimensions AND same coordinate vectors up to tolerance), a direct pointwise comparison is done. Otherwise the finer grid is interpolated onto the coarser one usingRegularGridInterpolator(trilinear).One structured + one unstructured (
Tetrahedron/XYZ): The structured field is interpolated at the unstructured mesh vertices usingRegularGridInterpolator(fast trilinear). This avoids the slow Delaunay triangulation entirely. L2 integration uses vertex volumes computed from the tetrahedral connectivity (lumped mass approach).Both unstructured: requires
--resolutionto create a common structured grid and usesLinearNDInterpolatorfor both fields.
Numerical integration
Structured grids: composite trapezoidal rule (second-order accurate)
Unstructured evaluation: lumped mass integration using vertex volumes computed from the tetrahedral mesh connectivity
Usage
python compute_L2_error.py file_A.xdmf file_B.xdmf [options]
# Compare spectral output vs FE validation:
python compute_L2_error.py \
../out/sim/fields/field_step000200.xmf \
validation.xdmf \
--attr-a temperature --attr-b Temperature
# Fast convergence study (skip error output):
python compute_L2_error.py spectral.xmf fe.xdmf --no-error-output
Functions
|
Compute error norms on a structured grid using trapezoidal rule. |
|
Compute error norms on unstructured vertices using lumped mass. |
|
Full comparison pipeline: load -> align/interpolate -> L2 -> write. |
Module Contents
- spectral_galerkin_heat.io_utils.compute_L2_error.compute_L2_structured(T_a, T_b, x, y, z)
Compute error norms on a structured grid using trapezoidal rule.
- Parameters:
T_a (numpy.ndarray)
T_b (numpy.ndarray)
x (numpy.ndarray)
y (numpy.ndarray)
z (numpy.ndarray)
- Return type:
dict[str, float]
- spectral_galerkin_heat.io_utils.compute_L2_error.compute_L2_unstructured(T_a, T_b, vertex_volumes)
Compute error norms on unstructured vertices using lumped mass.
- Parameters:
T_a (numpy.ndarray)
T_b (numpy.ndarray)
vertex_volumes (numpy.ndarray)
- Return type:
dict[str, float]
- spectral_galerkin_heat.io_utils.compute_L2_error.compare(path_a, path_b, attr_a=None, attr_b=None, output_base=Path('research/error'), resolution=None, write_error=True)
Full comparison pipeline: load -> align/interpolate -> L2 -> write.
- Parameters:
path_a (str) – Paths to XDMF files. File A is treated as the reference.
path_b (str) – Paths to XDMF files. File A is treated as the reference.
attr_a (str, optional) – Attribute names to load from each file.
attr_b (str, optional) – Attribute names to load from each file.
output_base (str) – Base name for error output files.
resolution (tuple, optional) – Grid resolution for both-unstructured case.
write_error (bool) – If False, skip writing error XDMF/H5 files (faster).
- Return type:
dict[str, float]