Skip to content

Pickling a curved mesh.RefineHP-refined OCC mesh silently returns a wrong solution (6.2.2604) #250

Description

@mmlanger

Environment

  • ngsolve / netgen 6.2.2604 (pip)
  • macOS (Darwin, arm64), Python 3.14

Summary
pickle-ing a 2D OCC mesh that has curved boundaries and was refined with mesh.RefineHP(...) round-trips the topology and solves without any error, but the high-order curved geometry is not restored, so the FE solution is wrong (~25 %). It is the curved + RefineHP combination: a curved mesh without RefineHP pickles correctly (0 %), and a straight-edged RefineHP-refined mesh pickles correctly (0 %).

Minimal reproducer

import pickle
import ngsolve as ng
from netgen.occ import OCCGeometry, WorkPlane

ann = WorkPlane().Circle(0, 0, 1.0).Face() - WorkPlane().Circle(0, 0, 0.4).Face()
ann.faces.name = "m"
ann.edges.name = "b"
ann.edges[0].hpref = 1
mesh = ng.Mesh(OCCGeometry(ann, dim=2).GenerateMesh(maxh=0.2))
mesh.RefineHP(levels=2, factor=0.2)

def grad_at(m, pt=(0.7, 0.0)):
    m.Curve(4)
    fes = ng.H1(m, order=4, dirichlet="b")
    u, v = fes.TnT()
    a = ng.BilinearForm(ng.grad(u) * ng.grad(v) * ng.dx).Assemble()
    f = ng.LinearForm(1.0 * v * ng.dx).Assemble()
    gf = ng.GridFunction(fes)
    gf.vec.data = a.mat.Inverse(fes.FreeDofs()) * f.vec
    return float(ng.Norm(ng.grad(gf))(m(*pt)))

fresh = grad_at(mesh)
reload = grad_at(pickle.loads(pickle.dumps(mesh)))
print(fresh, reload)   # 0.02258 vs 0.02823  -> ~25% off

Observed

|grad u| fresh=0.02258  pickled=0.02823  rel-err=25.0%

The pickled mesh reports the same element count and solves cleanly; only the result is wrong.

Expected
A pickled mesh reproduces the solution (as the no-RefineHP and straight-edge cases do), or pickling fails loudly — not a silent wrong result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions