Skip to content

Fix geometric consistency during T1 remodelling to prevent divergence#25

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/fix-remodelling-issue
Draft

Fix geometric consistency during T1 remodelling to prevent divergence#25
Copilot wants to merge 4 commits intomainfrom
copilot/fix-remodelling-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 17, 2026

T1 mesh transitions (apical/basal intercalations) produced geometrically broken states that caused volume calculation errors, explosive energy gradients, and Newton-Raphson divergence. Two sessions of fixes address 9 distinct root causes.

Session 1: Face centre validity after intercalation

  • move_vertices_closer_to_ref_point() — replaced linear interpolation toward a reference point (centre = ref*(1-w) + old*w, w as small as 0.01) with mean(Y[edge_vertices]), which is always inside the convex polygon
  • post_intercalation() — after all smoothing/Z-snapping, reset every face centre to mean(Y[edge_vertices]) for all intercalated cells; Laplacian smoothing and Z-snapping both invalidate face centres but this was previously unchecked
  • post_intercalation() — wrapped update_measures() + convergence check in try/except; a negative-volume exception now returns has_converged=False instead of crashing
  • check_if_will_converge() — replaced 4× repeated g[Dofs.Free] indexing with local variables; unified NaN/Inf detection with np.isfinite()

Session 2: Flip operation robustness

  • do_flip32() — added guard for collinear input vertices: raises ValueError when ‖cross(v0−v1, v2−v1)‖ < 1e-10 instead of silently producing NaN vertex positions
  • post_flip() — wrapped add_and_rebuild_cells() in try/except; previously always returned has_converged=True regardless of failure
  • flip_nm() — wrapped y_flip_nm() in try/except so degenerate flip configurations don't propagate through the full call stack
  • get_best_new_tets_combination() — added new_volumes <= 0 rejection before the existing > 100×mean check; catches collapsed cells whose degenerate triangles were all silently skipped (volume summed to 0 without raising)
  • is_degenerated() — changed np.all(y1 == y2) to np.linalg.norm(y1 - y2) < 1e-10 to catch near-degenerate edges, not just bit-for-bit duplicates
  • compute_volume_fraction() — replaced print() with logger.warning() for degenerate triangle warnings
Original prompt

This section details on the original issue you should resolve

<issue_title>Remodelling does not work in some cases</issue_title>
<issue_description>Describe the bug
When remodelling (T1 transitions in either apical or basal side) creates unrealistic geometries that breaks the model.

To Reproduce
remodel_mesh with some given nodes creates geometries with overlapping cells (e.g.,). For instance, this is an example of a geometry breaking the model that we don't pursue:

INFO [2026/03/17 10:08:39 AM] pyVertexModel: |gr| after remodelling without changes: 0.2032623511104577
INFO [2026/03/17 10:08:39 AM] pyVertexModel: Surface: 3.8042568091598336e-07
INFO [2026/03/17 10:08:39 AM] pyVertexModel: Volume: 4.019410637345629e-05
INFO [2026/03/17 10:08:39 AM] pyVertexModel: TriEnergyBarrierAR: 0.0
INFO [2026/03/17 10:08:39 AM] pyVertexModel: Substrate: 5.235452690096614e-11
INFO [2026/03/17 10:08:54 AM] pyVertexModel: Surface: 7.272564485192353e-07
INFO [2026/03/17 10:08:54 AM] pyVertexModel: Volume: 3.0221638252798605e-06
INFO [2026/03/17 10:08:54 AM] pyVertexModel: TriEnergyBarrierAR: 0.0
INFO [2026/03/17 10:08:54 AM] pyVertexModel: Substrate: 7.366233917686376e-08
Previous gr: 0.0015257249860467159, dyr: 0.002161642007669984
INFO [2026/03/17 10:09:00 AM] pyVertexModel: Surface: 0.00011238803161118334
INFO [2026/03/17 10:09:00 AM] pyVertexModel: Volume: 0.4928484098610282
INFO [2026/03/17 10:09:00 AM] pyVertexModel: TriEnergyBarrierAR: 0.0
INFO [2026/03/17 10:09:00 AM] pyVertexModel: Substrate: 1.3526878191993357e-07
Previous gr: 0.0015257249860467159, dyr: 0.03850133846822275
INFO [2026/03/17 10:09:07 AM] pyVertexModel: Surface: 9518138875.266048
INFO [2026/03/17 10:09:07 AM] pyVertexModel: Volume: 7.304423118700364e+36
INFO [2026/03/17 10:09:07 AM] pyVertexModel: TriEnergyBarrierAR: 0.0
INFO [2026/03/17 10:09:07 AM] pyVertexModel: Substrate: 5.2844606127216585
Previous gr: 0.0015257249860467159, dyr: 802.652473318542
WARNING [2026/03/17 10:09:08 AM] pyVertexModel: /media/pablo/d7c61090-024c-469a-930c-f5ada47fb049/PabloVicenteMunuera/VertexModel/pyVertexModel/src/pyVertexModel/geometry/tris.py:8: RuntimeWarning: divide by zero encountered in scalar divide
WARNING [2026/03/17 10:09:08 AM] pyVertexModel: /media/pablo/d7c61090-024c-469a-930c-f5ada47fb049/PabloVicenteMunuera/VertexModel/pyVertexModel/src/pyVertexModel/geometry/tris.py:8: RuntimeWarning: divide by zero encountered in scalar divide
WARNING [2026/03/17 10:09:12 AM] pyVertexModel: /media/pablo/d7c61090-024c-469a-930c-f5ada47fb049/PabloVicenteMunuera/VertexModel/pyVertexModel/src/pyVertexModel/Kg/kgVolume.py:83: RuntimeWarning: overflow encountered in multiply
WARNING [2026/03/17 10:09:12 AM] pyVertexModel: /media/pablo/d7c61090-024c-469a-930c-f5ada47fb049/PabloVicenteMunuera/VertexModel/pyVertexModel/src/pyVertexModel/Kg/kgVolume.py:87: RuntimeWarning: overflow encountered in scalar power
WARNING [2026/03/17 10:09:12 AM] pyVertexModel: /media/pablo/d7c61090-024c-469a-930c-f5ada47fb049/PabloVicenteMunuera/VertexModel/pyVertexModel/src/pyVertexModel/Kg/kgVolume.py:89: RuntimeWarning: overflow encountered in scalar power
WARNING [2026/03/17 10:09:12 AM] pyVertexModel: /media/pablo/d7c61090-024c-469a-930c-f5ada47fb049/PabloVicenteMunuera/VertexModel/pyVertexModel/src/pyVertexModel/Kg/kgVolume.py:64: RuntimeWarning: overflow encountered in scalar divide
WARNING [2026/03/17 10:09:12 AM] pyVertexModel: /media/pablo/d7c61090-024c-469a-930c-f5ada47fb049/PabloVicenteMunuera/VertexModel/pyVertexModel/src/pyVertexModel/Kg/kgVolume.py:83: RuntimeWarning: invalid value encountered in multiply
WARNING [2026/03/17 10:09:12 AM] pyVertexModel: /media/pablo/d7c61090-024c-469a-930c-f5ada47fb049/PabloVicenteMunuera/VertexModel/pyVertexModel/src/pyVertexModel/Kg/kgVolume.py:83: RuntimeWarning: invalid value encountered in add
WARNING [2026/03/17 10:09:12 AM] pyVertexModel: /media/pablo/d7c61090-024c-469a-930c-f5ada47fb049/PabloVicenteMunuera/VertexModel/pyVertexModel/src/pyVertexModel/Kg/kgVolume.py:64: RuntimeWarning: overflow encountered in scalar power
INFO [2026/03/17 10:09:13 AM] pyVertexModel: Surface: 1.6651102821031814e+145
INFO [2026/03/17 10:09:13 AM] pyVertexModel: Volume: inf
INFO [2026/03/17 10:09:13 AM] pyVertexModel: TriEnergyBarrierAR: 0.0
INFO [2026/03/17 10:09:13 AM] pyVertexModel: Substrate: 1.4798267702208325e+71
Previous gr: 0.0015257249860467159, dyr: 1.8714531497011436e+36

Expected behavior
Once we remodel, every geometry should be ok with no energetic spikes. The geometry of each cell should not overlap, all their triangles should connected, and be consistent. It should also not break it energetically.</issue_description>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

…_converge

Co-authored-by: Pablo1990 <1974224+Pablo1990@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix remodelling that creates unrealistic geometries Fix remodelling divergence: detect inf values and growing gradients in convergence check Mar 17, 2026
Copilot AI requested a review from Pablo1990 March 17, 2026 11:37
… mean of edge vertices

Co-authored-by: Pablo1990 <1974224+Pablo1990@users.noreply.github.com>
Copilot AI changed the title Fix remodelling divergence: detect inf values and growing gradients in convergence check Fix T1 remodelling geometric consistency: prevent energy spikes from invalid face centres Mar 17, 2026
…es, collinear point guard

Co-authored-by: Pablo1990 <1974224+Pablo1990@users.noreply.github.com>
Copilot AI changed the title Fix T1 remodelling geometric consistency: prevent energy spikes from invalid face centres Fix geometric consistency during T1 remodelling to prevent divergence Mar 17, 2026
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.

Remodelling does not work in some cases

2 participants