Skip to content

[Ready to be merged] Make assembly and Lagrange spaces independent of the unit of length - #236

Open
sbadrian wants to merge 3 commits into
krcools:masterfrom
sbadrian:bugfix/small-elements
Open

sbadrian wants to merge 3 commits into
krcools:masterfrom
sbadrian:bugfix/small-elements

Conversation

@sbadrian

Copy link
Copy Markdown
Contributor

Make assembly and Lagrange spaces independent of the unit of length

Several geometric comparisons used the absolute tolerance sqrt(eps) ≈ 1.5e-8, so results depended on the unit of length and broke for small cells:

  • Mixed assembly: intersection pieces with an area below sqrt(eps) were skipped. With coordinates in metres, triangles with sides below about 0.2 mm were dropped, and the Gram matrix came out partly or entirely zero. The threshold is now relative to the areas of the intersected cells.
  • Global degrees of freedom (trace in src/bases/global/globaldofs.jl): vertices were matched with an absolute tolerance. For cells smaller than about 1e-8, every vertex matched the cell's first vertex, and lagrangec0 failed with a singular matrix. The tolerance is now relative to the cell's diameter.
  • Thin cells: several vertices can still fall within that tolerance. trace now takes an exact match first, otherwise the nearest vertex, and throws an ArgumentError for missing, ambiguous or duplicate matches, and for cells with coincident vertices, instead of building a wrong basis.

Tests

  • test/test_mixed_assembly_scale.jl: Gram matrices of two different meshes of a square at several scales; their entries must sum to the area.
  • test/test_lagrange_scale.jl:
    • Lagrange spaces of order 1 and 2, with and without Dirichlet conditions, at scales from 1e-12 to 1e3 (coefficients, positions, Gram matrix);
    • thin triangles down to an aspect ratio of 1e-9 in Float64, Float32 and Float16;
    • vertex matching in trace, including invalid correspondences.

Behaviour change

trace now throws for cells with coincident vertices.

Simon B. Adrian added 3 commits November 24, 2026 10:13
When the test and trial functions live on different meshes, the assembly
intersects their cells and integrates over the pieces. Pieces with an area
below sqrt(eps) ≈ 1.5e-8 were skipped, to ignore cells that only touch
along an edge. That threshold was absolute: with coordinates in metres,
any triangle with sides below about 0.2 mm was dropped without warning,
and the matrix came out partly or entirely zero.

Compare the area of a piece with the area of the cells it comes from
instead, so the result no longer depends on the unit of length.

The new test assembles the Gram matrix of two different meshes of a square
at three sizes; its entries must sum to the area of the square.
The global degrees of freedom identify the vertices of a node, an edge or a face
with those of a cell by their positions. The tolerance was absolute, sqrt(eps)
≈ 1.5e-8: for cells smaller than that, every vertex matched the first vertex of
the cell, and lagrangec0 failed with a singular matrix (for example for a port
of a few nanometres).

Compare the positions relative to the diameter of the cell instead, so the
spaces no longer depend on the unit of length.

The new test builds Lagrange spaces of order 1 and 2, with and without
Dirichlet conditions, on a mesh scaled from 1e-12 to 1e3, and checks that the
coefficients, positions and Gram matrix scale with the mesh.
The previous commit made the tolerance with which trace identifies the vertices
of a node, an edge or a face with those of a cell relative to the size of the
cell. In a very thin cell, with an aspect ratio below about sqrt(eps), several
vertices still lie within that tolerance of each other, and the first match
could be the wrong vertex, which collapsed the edge.

Take an exact match first, otherwise the nearest vertex within the tolerance.
Throw an ArgumentError when a vertex has no match or two equally close matches,
when two vertices map to the same one, or when the cell has coincident
vertices, instead of building a wrong basis.

The new tests build Lagrange spaces on triangles with aspect ratios down to
1e-9 in Float64, Float32 and Float16, and check trace against independently
constructed, slightly perturbed edges.

This branch has not been deployed

No deployments
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.

1 participant