Skip to content

Rheology

vertax.rheology

Bulk-driven shear rheometry for periodic vertex-model meshes.

Measure a tissue's linear elastic response without deforming the periodic box, by driving the bulk with a cosine body force and reading the amplitude of the relaxed displacement mode. This module carries no optimizer coupling.

The method

Apply a force along one axis, modulated sinusoidally along another,

\[ f_x(y) = a\cos(q y),\qquad q = q_n = 2\pi n/H, \]

which puts \(+a\) at \(y=0\) and \(-a\) at \(y=H/2\): two counter-driven bands per box, hence two shear slabs, one interior and one closed through the periodic boundary. The total force vanishes by symmetry, so no wall and no reaction boundary is needed. This is the periodic perturbation method of non-equilibrium molecular dynamics (Gosling 1973; Hess 2002; GROMACS cos-acceleration; LAMMPS fix accelerate/cos), not a new construction.

VertAX minimises an energy, so the drive is applied as the Lagrangian potential

\[ \mathcal E_{\rm drive}(\mathbf X;a) = -a\sum_i \hat c_i\,\Delta x_i , \qquad \hat c_i = \cos(q y^0_i) - \tfrac1N\textstyle\sum_j\cos(q y^0_j), \]

with the weights frozen on the material points of the undriven reference state and \(\Delta x_i\) the minimum-image displacement from \(x^0_i\).

Two details are load-bearing, and both are asserted rather than assumed (see make_shear_mode and min_image_delta_x):

  • Mean removal is mandatory. Without it the drive carries a net force along the polarisation axis, the uniform translation mode is unbounded below, and the inner minimisation runs away.
  • Minimum image is mandatory. geo.update_pbc re-wraps any vertex leaving the box at every inner iteration, so a term linear in the raw coordinate jumps by \(\pm a\hat c_i W\) whenever a vertex crosses the seam.

Because the observable is a linear functional of vertex positions with no parameter dependence, \(\partial_{\bm\theta}\mathcal C|_{\mathbf X}=0\) exactly. That is what makes the existing centered-EP core correct for this problem unmodified. A \(\bm\theta\)-dependent outer cost would instead need the implicit \(\partial\mathbf X/\partial\bm\theta\) term at the equilibrium; dropping it silently would corrupt the estimator, which is why this cost is kept purely positional.

Conventions and gotchas

  • Everything here assumes float64. Call require_float64 in any driver. Enable x64 before the first JAX array is created and PbcMesh.vertices is then built in float64 too (meshes follow JAX's default float dtype); no cast after construction is needed.
  • Unsliced tables only. opt._jit_minimize calls the inner loss as L_in(vt[selected_verts], ..., fp[selected_faces]) while taking its gradient on the unsliced tables. The drive term indexes vertices positionally, so a partial selected_verts would silently mis-pair weights and vertices. make_drive_energy therefore raises on a row-count mismatch rather than broadcasting.
  • Report G, optimise J. \(G=\rho_v/(Jq^2)\) is hyperbolic in the stiff limit (\(U\to0\)); the compliance is linear in the vertex positions.
  • T1 transitions are enabled, not frozen — physically because they are the fluidity mechanism, numerically because freezing them drives \(\eta\lambda_{\max}\) to the SGD stability bound (measured directly). With T1 on, a compliance measured across an event is a secant, possibly plastic compliance, not a linear elastic constant. Use topology_signature / t1_event_count to stratify; never pool.

The drive is linear in X and contributes nothing to the Hessian, so a0 cannot move the stability bound. The EP nudge term is quadratic and adds a small positive rank-one piece, so \(\eta\lambda_{\max}\) must be checked at the nudged level too.

MAX_EDGES_IN_ANY_FACE module-attribute

MAX_EDGES_IN_ANY_FACE = 20

Face-walk bound, matching energy.MAX_EDGES_IN_ANY_FACE. The walk latches once it returns to its starting half-edge (geo._sum_edges), so an over-estimate costs time, not correctness.

ShearMode dataclass

ShearMode(c: Array, r0: Array, q: float, n: int, width: float, height: float, mod_axis: int, pol_axis: int, rho_v: float, c_sq: float, c_sq_ratio: float)

A single Fourier drive mode: which axis is modulated, which is driven, and the weights.

mod_axis selects the modulation direction (0 = \(\cos(qx)\), 1 = \(\cos(qy)\)) and pol_axis the polarisation of the force and of the observed displacement. The four combinations give three independent constants of an orthotropic 2D tissue:

modulation polarisation character constant
cos(qy) x transverse C66 = G
cos(qx) y transverse C66 (consistency check)
cos(qy) y longitudinal C22
cos(qx) x longitudinal C11

Attributes:

Name Type Description
c Array

Mean-removed weights \(\hat c_i\), one per vertex, frozen on the reference state.

r0 Array

Reference vertex positions, shape (N, 2).

q float

Wavevector \(2\pi n/L_{\rm mod}\).

n int

Mode index.

width float

Box dimensions.

height float

Box dimensions.

mod_axis int

See above.

pol_axis int

See above.

rho_v float

Vertex number density \(N/(WH)\) — the force-balance calibration constant.

c_sq float

\(\sum_i\hat c_i^2\).

c_sq_ratio float

\(2\sum\hat c_i^2/N\). Finite-size diagnostic, not a correction factor. The continuum calibration \(G=\rho_v/(Jq^2)\) follows from force balance (\(f_x(y)=a\rho_v\cos qy\)) and is the definition used here. Equating the discrete drive energy \(-aU\sum\hat c_i^2\) to the continuum \(-\tfrac12 FUWH\) instead gives \(F=2a\sum\hat c_i^2/(WH)\), i.e. the same thing multiplied by this ratio. The two routes agree exactly only for a uniform vertex distribution, so a ratio far from 1 measures the density fluctuation the continuum calibration neglects, at \(O(N^{-1/2})\). Report it; do not silently divide by it.

pol_period property

pol_period: float

Box length along the polarisation axis — the period for the minimum-image wrap.

mod_period property

mod_period: float

Box length along the modulation axis.

label property

label: str

Short human-readable tag, e.g. n1_cosy_polx.

require_float64

require_float64() -> None

Raise unless JAX x64 is enabled. Standing rule: all Hessian/equilibrium work in float64.

make_shear_mode

make_shear_mode(vertices: Array, width: float, height: float, n: int = 1, mod_axis: int = 1, pol_axis: int = 0, *, mean_tol: float = 1e-12) -> ShearMode

Build a drive mode from the undriven reference configuration.

The weights are attached to material points, so vertices must be the relaxed \(a=0\) state, and the mode must be re-referenced whenever that state moves appreciably (the drift diagnostic is drive_drift).

Parameters:

Name Type Description Default
vertices Array

Reference positions, shape (N, 2) — the relaxed a = 0 state.

required
width float

Box width.

required
height float

Box height.

required
n int

Mode index; q = 2*pi*n / L_mod.

1
mod_axis int

0 for cos(qx), 1 for cos(qy).

1
pol_axis int

0 to drive/observe x, 1 to drive/observe y.

0
mean_tol float

Tolerance on \(|\sum_i\hat c_i|\).

1e-12

Raises:

Type Description
ValueError

If the mean-removal assertion fails, or the axes are not in {0, 1}, or n < 1.

min_image_delta_x

min_image_delta_x(x: Array, x0: Array, period: float) -> Array

Minimum-image displacement x - x0 wrapped into the half-open \([-L/2, +L/2)\).

Spelled d - L*floor(d/L + 1/2). Three properties matter, and V0 checks all three:

  • Its derivative is exactly 1 everywhere in JAX, because jnp.floor carries a zero JVP. No stop_gradient is needed, and none is used: the image index floor(d/L + 1/2) is an integer label of the periodic image, piecewise constant, with derivative zero almost everywhere.
  • It is exactly invariant under a lattice translation, at every point including the tie. The obvious spelling d - L*round(d/L) is not: round is half-to-even, so it maps both \(\pm L/2\) to themselves, the interval comes out closed, and the two representatives at exactly \(d=L/2\) differ by one lattice vector, \(|\Delta|=L\). The physics is untouched -- either representative is a valid minimum image -- but an exact invariance is worth more than a caveat, which is why the half-open interval is used here.
  • It is not a nine-image jnp.min reduction, deliberately: that form has a kink whose AD path is the one geo.min_image_sq_dist documents as having produced NaN gradients on real meshes.

make_drive_energy

make_drive_energy(base_energy: Callable[[Array, Array, Array, Array, Array, Array], Array], mode: ShearMode, a: float) -> Callable[[Array, Array, Array, Array, Array, Array], Array]

Wrap an inner loss with the cosine drive potential at amplitude a.

Parameters:

Name Type Description Default
base_energy Callable[[Array, Array, Array, Array, Array, Array], Array]

A callable with the exact six-argument inner-loss signature (vertTable, heTable, faceTable, vert_params, he_params, face_params), as opt.InnerLossFunction requires. width/height are static_argnums throughout the library and are therefore closed over by the caller, not passed here.

required
mode ShearMode

The drive mode; its weights and reference state are captured by closure.

required
a float

Drive amplitude. a = 0 returns the undriven energy up to a term that is identically zero, so it is a valid way to build the free condition.

required

Returns:

Type Description
Callable[[Array, Array, Array, Array, Array, Array], Array]

A callable with the same six-argument signature, adding \(-a\sum_i\hat c_i\Delta r_i^{\rm pol}\).

The returned energy raises on a vertex-row-count mismatch. That converts the one silent failure mode of this construction — a partial selected_verts, which slices vertTable and so mis-pairs weights with vertices — into a loud one.

mode_amplitude

mode_amplitude(vertices: Array, mode: ShearMode) -> Array

Amplitude of the driven Fourier component of the displacement field, \(U=\sum_i\hat c_i\Delta r_i/\sum_i\hat c_i^2\) — a linear functional of the positions.

compliance

compliance(u_plus: Array | float, u_minus: Array | float, a0: float) -> Array

Mode compliance \(J=(U_+-U_-)/(2a_0)\) from the antisymmetric pair.

The pair removes the \(a=0\) offset that any finite disordered mesh carries, and with it the leading \(O(a_0^2)\) nonlinearity. Note \(\Delta r^+_i-\Delta r^-_i=r^+_i-r^-_i\) exactly, so J does not depend on the reference positions at all — only the weights do.

modulus_from_compliance

modulus_from_compliance(j: Array | float, mode: ShearMode) -> Array

Apparent modulus at the mode's wavevector, \(G_n=\rho_v/(Jq_n^2)\).

This is the force-balance calibration. See ShearMode.c_sq_ratio for the discrete-vs-continuum diagnostic that must be reported beside it rather than folded into it. G diverges as \(J\to0\), which is exactly why the outer cost is written on J.

target_compliance

target_compliance(g_target: float, mode: ShearMode) -> float

Compliance target \(J_{\rm tgt}=\rho_v/(G_{\rm tgt}q^2)\) for a modulus target.

make_compliance_cost

make_compliance_cost(mode: ShearMode, j_target: float, a0: float, partner_amplitude: float, sign: Literal[1, -1]) -> Callable[..., Array]

Outer loss \(\mathcal C=(\hat J/J_{\rm tgt}-1)^2\) for one condition of the pair.

The partner condition's amplitude is frozen and captured by closure, which is what makes the block-coordinate alternation expressible against the library's one-mesh outer loss. sign = +1 for the \(+a_0\) condition, -1 for \(-a_0\).

Returns a callable with the exact twelve-argument opt.OuterLossFunction signature. It uses only vertTable: the cost has no parameter dependence, by construction, which is the property that keeps the implemented centered-EP estimator correct.

half_edge_vectors

half_edge_vectors(vertices: Array, edges: Array, width: float, height: float) -> Array

Per-half-edge vector \(\mathbf d_{he}=(\mathbf x_{\rm tgt}+\mathbf n L)-\mathbf x_{\rm src}\).

Columns 3/4 of heTable are source/target vertex, 6/7 the \(\pm1\) box offsets — the same convention geo.get_length uses, and read from the same columns so the two cannot drift.

face_areas

face_areas(vertices: Array, edges: Array, faces: Array, width: float, height: float) -> Array

Per-face area, via geo.get_area so the shoelace/offset convention is the library's.

face_perimeters

face_perimeters(vertices: Array, edges: Array, faces: Array, width: float, height: float) -> Array

Per-face perimeter, via geo.get_perimeter.

half_edge_lengths

half_edge_lengths(vertices: Array, edges: Array, width: float, height: float) -> Array

Per-half-edge length, via geo.get_length.

virial_stress

virial_stress(vertices: Array, edges: Array, faces: Array, width: float, height: float, he_tensions: Array, iso_coeff: Array | float) -> Array

Assemble \(A\,\sigma_{ij}=\sum_{he}T_{he}\,d_i d_j/\ell + \delta_{ij}c_{\rm iso}\).

Why the naive definition vanishes. \(\bm\sigma=A^{-1}\mathbf X^\top\nabla_1\mathcal E\) is correct for an affine strain of the stored coordinates alone — and it is identically zero at any relaxed configuration, because that is what \(\nabla_1\mathcal E=0\) means. Under PBC an affine strain must act on the box vectors too, and the missing term \(\mathbf h^\top\partial\mathcal E/\partial\mathbf h\) is the entire signal. The Born/virial form used here is that term, written per edge: it is the derivative with respect to the edge vectors, which do respond to a box strain.

he_tensions is \(\partial\mathcal E/\partial\ell_{he}\) per half-edge, so the factor conventions of the energy (the leading 1/2 that cancels the half-edge double count in E2; the two-faces-per-edge sum in E1) are inherited from the energy rather than re-derived here. iso_coeff is the \(\delta_{ij}\) coefficient from the area terms.

Returns the (2, 2) stress. The normalising area is the box area \(WH\); compare it against face_areas(...).sum() as a mesh-consistency check.

virial_stress_e2

virial_stress_e2(vertices: Array, edges: Array, faces: Array, width: float, height: float, he_params: Array, face_params: Array, k_areas: float) -> Array

Virial stress for the periodic E2 energy of energy.make_energy_line_tensions.

\(\mathcal E_2=\tfrac12\sum_{he}\Lambda_{he}\ell_{he}+\tfrac K2\sum_\alpha(A_\alpha-A^0_\alpha)^2\) gives \(\partial\mathcal E/\partial\ell_{he}=\tfrac12\Lambda_{he}\) and, from a uniform dilation \(A\to(1+\varepsilon)^2A\), the isotropic coefficient \(K\sum_\alpha(A_\alpha-A^0_\alpha)A_\alpha\). The latter is \(-\sum_\alpha P_\alpha A_\alpha\) with the cell pressure \(P_\alpha=-K(A_\alpha-A^0_\alpha)\): the Batchelor tissue stress, ported to periodic tables.

virial_stress_e1

virial_stress_e1(vertices: Array, edges: Array, faces: Array, width: float, height: float, face_params: Array) -> Array

Virial stress for the periodic E1 energy (energy.energy_shape_factor_*).

\(\mathcal E_1=\sum_\alpha[(A_\alpha-1)^2+(P_\alpha-p^0_\alpha)^2]\) gives an effective half-edge tension \(2(P_{\alpha(he)}-p^0_{\alpha(he)})\), where \(\alpha(he)\) is the face owning the half-edge (column 5). Summing over half-edges therefore reproduces the per-edge \(T_e^{\rm eff}=\sum_{\alpha\ni e}2(P_\alpha-p^0_\alpha)\) automatically, since an edge's two half-edges belong to its two adjacent faces. The isotropic coefficient is \(2\sum_\alpha(A_\alpha-1)A_\alpha\).

face_params may be a scalar (the homogeneous case) or one value per face.

stress_profile_xy

stress_profile_xy(vertices: Array, edges: Array, width: float, height: float, he_tensions: Array, n_bins: int = 12, n_quad: int = 16) -> tuple[Array, Array]

Profile of \(\sigma_{xy}\) across the modulation axis, for V1.

Force balance requires \(\partial_y\sigma_{xy}=-f_x(y)\), hence \(\sigma_{xy}(y)=-(a\rho_v/q)\sin(qy)\) — parameter-free, so it validates the drive, the stress and the calibration constant \(\rho_v\) at once.

Binning is a sub-segment quadrature of the Irving–Kirkwood line integral: each half-edge is split into n_quad equal pieces and each piece's midpoint deposits \(1/n_{\rm quad}\) of that half-edge's \(T d_x d_y/\ell\) into the bin containing it (wrapped modulo the box). This is what makes the discrete profile satisfy the continuum balance: depositing the whole contribution at the edge midpoint instead smears the profile at \(O(\ell^2/\Delta y^2)\), which at these bin widths is not negligible. Convergence in n_quad is cheap to check and should be reported.

Returns:

Type Description
tuple[Array, Array]

(bin_centres, sigma_xy), each of length n_bins; sigma_xy is normalised by the bin volume \(W\,\Delta y\).

hessian_spectrum

hessian_spectrum(energy: Callable[[Array, Array, Array, Array, Array, Array], Array], vertices: Array, edges: Array, faces: Array, vert_params: Array | None, he_params: Array | None, face_params: Array | None) -> tuple[np.ndarray, np.ndarray]

Eigendecomposition of the inner Hessian \(\partial^2\mathcal E/\partial\mathbf X^2\).

Dense, symmetrised, float64, and deliberately general: a box/energy-specialised \(\lambda_{\max}\) primitive already exists elsewhere for the square-box E1 case, so this one is written to be reused rather than triplicating the method. At 72 cells the matrix is about 288 x 288, so a dense eigvalsh is cheaper than a power iteration and returns the whole spectrum, which V2 needs anyway.

Returns:

Type Description
tuple[ndarray, ndarray]

(eigenvalues ascending, eigenvectors) as numpy arrays over the flattened (N, 2) degrees of freedom, C-ordered: dof 2i + k is vertex i, component k.

hessian_lambda_max

hessian_lambda_max(energy: Callable[[Array, Array, Array, Array, Array, Array], Array], vertices: Array, edges: Array, faces: Array, vert_params: Array | None = None, he_params: Array | None = None, face_params: Array | None = None) -> float

Largest Hessian eigenvalue — the SGD stability precondition is \(\eta\lambda_{\max}<2\).

Check it, never assume it. Unrolled AD carries \(|1-\eta\lambda|^k\) over k inner steps; at \(\eta\lambda=2.13\) and 1000 steps that is \(10^{51}\) per epoch, and the failure is silent in the direction that matters — the iterate and the recorded metrics stay finite and plausible while the sensitivity diverges. The rheology plan refuses to launch above \(\eta\lambda_{\max}=1\).

top_mode_participation

top_mode_participation(energy: Callable[[Array, Array, Array, Array, Array, Array], Array], vertices: Array, edges: Array, faces: Array, vert_params: Array | None = None, he_params: Array | None = None, face_params: Array | None = None) -> dict[str, float]

How localised is the stiffest Hessian mode?

Returns the participation ratio \(1/\sum_i w_i^2\) of the per-vertex weights \(w_i=v_{2i}^2+v_{2i+1}^2\) of the top eigenvector, i.e. an effective number of participating vertices, together with \(\lambda_{\max}\) and the largest single-vertex weight.

This discriminates the two reasons \(\lambda_{\max}\) can be large, which call for opposite responses. A participation ratio of order the system size means the mesh is uniformly stiff and the fix is the step size \(\eta\). A ratio of order one means a single junction is nearly collapsed and dominates the spectrum — reducing \(\eta\) then merely hides it, and the honest response is to report the configuration. Note the E1 NaN investigation established that \(\lambda_{\max}\) does not track the minimum edge length on its meshes, so the two diagnostics are not interchangeable and both are reported.

hessian_compliance

hessian_compliance(energy: Callable[[Array, Array, Array, Array, Array, Array], Array], vertices: Array, edges: Array, faces: Array, mode: ShearMode, vert_params: Array | None = None, he_params: Array | None = None, face_params: Array | None = None, *, rel_cut: float = 1e-08) -> dict[str, float]

Exact linear-response compliance \(J=(\hat{\mathbf c}^\top\mathbf H^{-1}\hat{\mathbf c})/(\hat{\mathbf c}^\top\hat{\mathbf c})\), for V2.

H is singular: the two uniform translations are exact zero modes under PBC. The drive vector is mean-removed along the polarisation axis and identically zero on the other, so it is orthogonal to both by construction — the inverse is taken on the complement, and the leaked overlap is returned rather than assumed away.

This is a linear-response identity and applies only in the T1-free regime; once events fire the nonlinear relaxation is not measuring the same object.

Returns a dict with J_exact, lambda_max, lambda_min_kept, n_dropped, dropped_overlap (fraction of \(\|\hat c\|^2\) in the discarded subspace — should be ~1e-16), and cond_kept.

grad_x_norm

grad_x_norm(energy: Callable[[Array, Array, Array, Array, Array, Array], Array], vertices: Array, edges: Array, faces: Array, vert_params: Array | None = None, he_params: Array | None = None, face_params: Array | None = None) -> float

\(\|\nabla_{\mathbf X}\mathcal E\|_2\) — report it for every solve before interpreting any compliance. A modulus attached to an unconverged equilibrium is not a modulus.

topology_signature

topology_signature(edges: Array) -> tuple[tuple[int, int], ...]

Relabelling-invariant signature of the mesh topology: the sorted multiset of unordered face pairs, one per half-edge.

A T1 transition swaps which two faces share an edge, so it changes this multiset; a mere re-indexing of half-edges does not. That distinction is the point. A counter keyed on raw half-edge rows would conflate T1 events with index relabelling, which is why this signature is keyed on face pairs instead. Face labels are assumed stable across a T1, which is true of this implementation but is an assumption, not a theorem.

t1_event_count

t1_event_count(sig_before: tuple, sig_after: tuple) -> int

Number of edges whose face-pair changed between two signatures, halved (each event moves the pair on both half-edges of the edge). A lower bound on the event count: two T1s that undo one another within the same solve are invisible to any before/after comparison.

connectivity_hash

connectivity_hash(edges: Array) -> str

Stable hash of the full half-edge table, for the EP validity check.

EP's paired cancellation requires the \(+\beta\) and \(-\beta\) solves to cross the same events. A hash mismatch invalidates that outer step, and it is recorded as invalid — not repaired. Unlike topology_signature this is sensitive to relabelling, which is what makes it the right tool for comparing two solves from a common starting state and the wrong tool for counting events.

drive_drift

drive_drift(vertices: Array, mode: ShearMode) -> float

Drift diagnostic \(\max_i|\cos(qr_i)-\overline{\cos(qr)}-\hat c_i|\).

The weights are attached to material points, so after substantial rearrangement they no longer coincide with the Eulerian field. Re-reference the mode from the \(a=0\) relaxed state at each outer epoch, and treat the reference as a constant of the estimator within the epoch.