Skip to content

evaluate() is off by up to 4e-5 for a field the P2 space holds exactly, at points near a node #799

Open

Description

@lmoresi

Symptom

A P2 field set to x^2 + 3xy - y (which P2 represents exactly) is evaluated with uw.function.evaluate (serial) at every P2 node moved a fixed distance in a random direction, six directions per node, on UnstructuredSimplexBox(cellSize=0.1):

offset points max error points off by more than 1e-10
1.5e-3 11838 2.7e-5 20
3e-3 11838 3.9e-5 13
6e-3 11838 3.8e-5 4
1e-2 11838 1.0e-5 2
2e-2 11838 1.7e-5 3

Any cell's polynomial gives the exact value, so a correct evaluation is exact to round-off wherever the point is located; a few points take a different value. The same points are off in parallel (global_evaluate, np 4) by the same amounts, so this is the serial evaluation, not the parallel routing. Candidate: the face-slab locator (_EVAL_FACE_TOL = 1e-2) and the reference-coordinate clamp, or the exterior (rbf) path taking points it should not.

Reproduction

~/+Simulations/forward_nodes/strand_scan.py (serial: python strand_scan.py).

Underworld development team with AI support from Claude Code

Activity

  1. added
    bug
    on Sep 27, 2026
  2. lmoresi commented on Nov 13, 2026

    @lmoresi
    MemberAuthor

    Probe-pass verdict from H3 (a review session, on a 96-thread Linux workstation: single system image; Intel Xeon Gold 6240R, AVX-512; MPICH): fixed by PR #1117, still live on development. It is #1115 under another name: the face-tolerance locator gives a point near a face to the neighbouring cell, and the reference-coordinate clamp then moves it onto the shared face. #1117 gives the cell that contains the point priority.

    The probe, serial, is this issue's case with the points kept inside the box:

    # #799: P2 field x^2+3xy-y on UnstructuredSimplexBox(cellSize=0.1); every P2 node moved a fixed distance, 6 random directions
    import numpy as np, underworld3 as uw
    mesh = uw.meshing.UnstructuredSimplexBox(minCoords=(0., 0.), maxCoords=(1., 1.), cellSize=0.1)
    T = uw.discretisation.MeshVariable("T", mesh, 1, degree=2)
    f = lambda X: X[:, 0]**2 + 3*X[:, 0]*X[:, 1] - X[:, 1]
    X = np.asarray(T.coords); T.array[:, 0, 0] = f(X)
    rng = np.random.default_rng(0)
    for off in (1.5e-3, 3e-3, 6e-3, 1e-2, 2e-2):
        P = np.repeat(X, 6, axis=0); d = rng.normal(size=P.shape); d /= np.linalg.norm(d, axis=1)[:, None]
        P = P + off * d; P = P[(P.min(1) > 0) & (P.max(1) < 1)]
        e = np.abs(np.asarray(uw.function.evaluate(T.sym[0], P)).ravel() - f(P))
        print(f"offset {off:.1e}: {len(P)} points, max error {e.max():.1e}, off by >1e-10: {(e > 1e-10).sum()}")
    offset development 01dec8d: max error (points off by > 1e-10) PR #1117 at a8e3a2f
    1.5e-3 3.7e-6 (1) 1.8e-15 (0)
    3e-3 1.8e-5 (2) 1.3e-15 (0)
    6e-3 5.7e-6 (2) 1.3e-15 (0)
    1e-2 1.4e-6 (1) 1.8e-15 (0)
    2e-2 2.5e-6 (1) 1.3e-15 (0)

    Labelled fixed-in-PR; it becomes fixed-in-development when #1117 merges.

    Underworld development team with AI support from Claude Code

  3. added
    fixed-in-PR
    fixed-in-development
    and removed
    fixed-in-PR
    on Nov 13, 2026
  4. lmoresi commented on Nov 13, 2026

    @lmoresi
    MemberAuthor

    Fixed in development by PR #1117 (merge commit 116fc45): evaluate and global_evaluate now take the cell that contains a point before admitting a neighbour within the face tolerance, so fields the element represents exactly are exact near edges, faces and vertices (the review measured 3.6e-15 where the previous development gave 4.9e-5; test_0511 fails on the previous code). This is the interim fix; a rework of the point locator (a face-crossing walk with an exact containment test, which also removes the remaining absolute tolerances and the 50-candidate cap of #1123) is planned. The issue stays open until development is released to main.

    Underworld development team with AI support from Claude Code


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfixed-in-development

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions