← f_ notebook · ideas/f_nematic.md

f_nematic: an oriented-texture generator that outputs a tensor (working name) ​

Status: 🟡 level A built and benched, not closed (per .specify/plan.md, 2026-11-28; record .specify/f_nematic/tasks.md). Written as: ⚪ concept; NumPy spike run 2026-11-27, see "Spike result" below (levels B and C simulated, tensor emission checked in math, nothing in Max). Captured 2026-11-27 (Claude offline, docs only), from a conversation with Matt about a new generator near f_ks that makes good demo input for other modules. Not specced, not prototyped, not tried in Max. Physics is [memory] (not looked up); how it would fit f is [inferred] from the docs read this session: docs/f-reference/f_tensor_type.md, ideas/f_tf_backlog.md ("Producers from non-image sources"), ideas/optics_map.md and the module inventory. Names are placeholders. Matt has not decided on this; it is one candidate among several._

Why this is worth a note ​

Every module in the f_tf_ family reads structure out of an image: the only producer is f_tf_tensormap, a structure tensor of a scalar texture. ideas/f_tf_backlog.md lists producers from non-image sources (f_tf_jacobian, f_tf_motion, f_tf_hessian, f_tf_authored), but none of them is emergent: they are derived from a flow, a motion field, a scalar, or set by hand. A generator whose state is itself an oriented field, one that evolves on its own and never needs an image, would be a different kind of source. It would also be the first tensor source that could be the input for a demo with nothing patched in.

In the axes language (axes_of_investigation.md): emergent source, matter-and-dynamics stage (or optics, if rendered between polarizers), tensor output. Nothing of that combination exists in the inventory.

The phenomenon [memory] ​

A nematic liquid crystal is a fluid of rodlike molecules that align along a local axis, the director, which is unoriented (n and −n are the same). The state is naturally a tensor (the Q-tensor, a traceless symmetric 2x2 in 2D), with the order parameter S going to zero where alignment fails.

  • Defects. The director field cannot be smooth everywhere; it has point defects of winding ±1/2 ("comet" +1/2, "trefoil" −1/2 in the common description). They are where S vanishes.
  • Schlieren texture. Seen between crossed polarizers, intensity goes as sin²(2(θ − φ)) (θ the director angle, φ a polarizer angle), producing dark brushes around each defect (two for ±1/2, four for ±1). This is the classic look of a liquid crystal under a microscope. With birefringent color it becomes the Michel-Lévy interference palette (relates to spectral_rainbow_colormap.md).
  • Active nematics. If the molecules push the fluid (an "activity" term), +1/2 defects become self-propelled, defects nucleate and annihilate, and the flow turns chaotic ("active turbulence"). The same never-settling character as f_ks, with a different look: oriented streaks with drifting comet defects.

Why the fit with f_ is unusually direct [inferred] ​

  • The data type exists. f_tensor_type.md already defines a raw tensor (outlet 0: Jxx, Jxy, Jyy) and a packed form (outlet 1: cos 2θ, sin 2θ, trace, coherence). Packed is angle-doubled for exactly the reason a director needs it (θ and θ+180° are the same). The order parameter S maps to coherence, and S going to zero at a core matches what coherence does at an isotropic point.
  • Raw from packed (inferred math, not checked): with trace t, coherence c, angle θ, J = (t/2) [[1 + c cos2θ, c sin2θ], [c sin2θ, 1 − c cos2θ]].
  • Consumers are waiting for a source. f_tf_hatch, f_tf_aniso_blur, f_tf_glyph, f_tf_sharpen, f_tf_smooth and f_tf_axisflow (to reach vecfield consumers) all take a tensor. f_tf_backlog.md says each non-image producer "waits for the chain that needs it"; a demo source is such a need. (How this touches G-tensor-t3 in .specify/gates.md was not checked: only a truncated row was read.)
  • Optics. optics_map.md lists photoelastic stress-fringe interference as "Research" with no producer; a tensor generator and a crossed-polarizer render step would be one.

Three levels of ambition [inferred] ​

LevelWhat it isSelf-sustaining?Cost shape
A. Kinematic defect fieldAnalytic director field: θ = θ0 + Σ s_i atan2(y − y_i, x − x_i) with s_i = ±1/2, defects moved by LFO or drift (f_lfo's Drunk or Wobble)Only as long as the defects are drivenOne pass, no solver, no state. Exact tensor
B. Relaxational Q-tensorQ relaxes toward alignment: domains coarsen and defects pair upNo (settles or coarsens)A local stencil or spectral step, two state channels
C. Active nematic with flowQ coupled to an incompressible flow and an activity termYes, chaoticBiggest: a flow solver (f_vf_fluid has a spectral incompressible one) plus Q, coupled

Level A is not emergent, but it is the cheapest way to get a tensor source with defects that looks right, and it would test whether the consumers' looks hold up before paying for C. Level C is the only one with the f_ks property (alive with no input), and the one I know least how to make stable. All three would fit as modes of one module.

Candidate outlets (see f_solver_outlets.md) ​

Raw tensor, packed tensor (following f_tensor_type.md), a schlieren look (crossed-polarizer intensity, optionally with a birefringence palette), and S as a scalar. No vecfield outlet: the type doc's rule is that an axis must not be forced into a signed vector; if a vecfield is wanted, it goes through f_tf_axisflow.

Open questions ​

  1. Packed-angle convention. The type doc says packed θ is the gradient direction, across the edge, with the edge direction at θ + 90°. A director runs along the molecules. Which should the module emit, so f_tf_hatch and f_tf_aniso_blur strokes follow the director with no extra step? Decide against the consumers' docs.
  2. Is level C reachable at 256² in one step per frame? The flow and Q equations are coupled and stiffness is unknown. Needs a NumPy spike in the style of tests/records/spike_ks_stability.py before any commitment.
  3. Trace. What should the trace channel carry (constant, S, an energy)? Consumers gate on it (f_tf_glyph gates on trace).
  4. Defect cores. Orientation is undefined where S is zero. Fine for a tensor (it decodes to zero), awkward for a look. Feature or flaw?
  5. Resolution. Same internal-grid question as f_ks and f_wave_field.
  6. Overlap. jit.fx checked 2026-11-27 (offline docs, not Max): none generates a tensor; cf.kuwahara has an internal structure-tensor pass, derived from an image (jit_fx.md). Vsynth: Vsynth overlap checked 2026-11-27 (Claude, offline: docs/vsynth-reference/module-inventory.md, plus vs_chemical_osc.maxpat and its help in the installed package; nothing run in Max). No Vsynth module is a PDE solver, a complex-field generator or a tensor source. Closest: vs_chemical_osc (named for the Belousov-Zhabotinsky reaction, but by its object list a feedback video loop: slide, hue+sat, blur x2, rota, luma_key, fixed_sine; the pix code was not read), vs_feedback / vs_filter_temp / vs_frame_delay (frame memory, no spatial dynamics), the WFG and sources_* family (authored, stateless), and the vector subsystem (audio-rate XY, not textures). Verdict: no overlap found; vs_chemical_osc is the one to look at next to any reaction-type generator, as a feedback-loop look rather than a solver. Not checked against ideas/f_tensorfield.md beyond the passages named above.

Spike result (2026-11-27, Claude offline, NumPy only) ​

Script: ideas/f_nematic_spike.py (stages pass1, pass2, extra). Raw numbers and four PNGs: scratch/experiments/nematic_spike/ (gitignored: pass1.json, pass2.json, extra.json, fig1-fig4). Everything below is observed in NumPy float64 unless marked inferred; nothing was run in Max or on a GPU. Wall time: pass 1 about 30 s, pass 2 about 65 s (run three times while I fixed the tracking), extra about 60 s, on a 14-core Mac with other sessions running, so the cost figures carry some noise.

Model actually simulated (my conventions, from memory, not checked against a source).q = S (cos 2φ, sin 2φ), |q| = S. Level B: q_t = K lap q + A q (1 − |q|²). In 2D the cubic Landau-de Gennes term vanishes (tr Q³ = 0), so level B is the real-coefficient complex Ginzburg-Landau / XY relaxation, not anything more exotic. Level C adds an overdamped Stokes flow, (γ − η lap) u + grad p = ζ div Q, div u = 0, solved per Fourier bin, and q_t + u·grad q − 2Ω(−q2, q1) − λ(Exx, Exy) = .... Units: core size 1, relaxation time 1, dx = 0.5 (N = 128 is a 64 box, N = 256 a 128 box), γ = 0.1, η = 1, K = A = 1. Initial state: Gaussian noise, σ = 0.1 per component (a quench). Not modeled: elastic back-stress, dealiasing, other γ/η.

Run counts ​

Pass 1 (coarse): 12 semi-implicit dt-scan runs (2 grids × 6 dt, seed 0, T = 300); 2 explicit-FD bisections (10 trials × 400 steps each); 5 coarsening runs (128² seeds 0, 1, 2; 256² seeds 0, 1; T = 2000, dt = 0.5); 22 level C runs (128², dt = 0.05, T = 300, seed 0, ζ ∈ {0, ±0.5, ±1, ±2, ±4, ±8} × λ ∈ {0, 1}). Pass 2 (refinement, ζ = 2, λ = 0, dt = 0.05 unless stated): 2 developed snapshots (T = 200), dt_max bisection at 128² and 256² (8 trials each + a "usable" ladder), 4 long runs with defect tracking (128² seeds 0, 1, 2; 256² seed 0; T = 600), 2 twin (Lyapunov) pairs, float32 vs float64, tensor test, cost timing. Extra: 12 threshold runs (T = 600), 7 dt_max bisections at 128², 5 grid-spacing runs.

Claims, one by one ​

#Claim in the note (or implied)VerdictEvidence
1Level B: domains coarsen, defects pair up, and it settles (not self-sustaining)Confirmed+1/2 and −1/2 counts were equal at every record in all 27 B and C runs (net charge zero). All 5 B runs end at 0 defects, S = 1.000, energy 0.0000, the last by t = 1000 (128² seed 2 at t = 100; 128² seed 1 still 4 at t = 300). 256² seed 0: 88 defects at t = 10, 26 at 50, 12 at 100, 6 at 300, 0 at 1000. The free energy never rose (nonmonotone events: 0 at dt ≤ 1)
2B coarsening lawNot determinedFitted slopes of log N vs log t from t = 100 were −0.7, −1.0, n/a, −1.05, −1.45 on counts of 0 to 20; the boxes are too small and the counts too low
3B stable dt, semi-implicit spectralMeasuredLaplacian implicit per bin, bulk term explicit. dt ≤ 1 clean at both grids; dt = 2 is bounded but wrong (energy rises 5 to 6 times, S_late 0.84 to 0.90, qmax 1.3, defects left over); dt = 4 and 8 blow up. Usable ceiling about 1 relaxation time per step, independent of N
4B stable dt, explicit 5-point FDMeasureddt_max 0.0625 (128²) and 0.0621 (256²) = dx²/(4K), the textbook bound. So 16 substeps per relaxation time at dx = 0.5; it scales as dx², not with N
5Level C is reachable at 256² in one step per frame (Q2)Confirmed, with a limit set by activityFrom a developed state (ζ = 2, λ = 0): bounded dt_max 0.45 (256²) and 0.46 / 0.43 (128², two bisections); "usable" (defect count within 30% of the dt = 0.02 run over 60 time units) 0.35 at both grids. Across activity at 128²: ζ = 0.5 bounded to at least 2.0 (usable 1.0); ζ = 2, λ = 1: 0.76 (usable 0.5); ζ = 8, λ = 0: 0.051 (usable 0.05); ζ = 8, λ = 1: 0.17 (usable 0.12); ζ = −4, λ = 1: 0.081 (usable 0.05). At λ = 0, dt_max·
6Level C is stiffContradicted for moderate ζ, true for strong ζWith the elastic term implicit and one flow solve per step, ζ ≤ 2 runs at 0.35 time units per step. The note's fear (coupled stiffness, "least how to make stable") applies only above ζ ≈ 4 to 8, where one step per frame needs dt ≲ 0.05
7C is self-sustaining and chaoticSelf-sustaining: confirmed. Chaotic: confirmed for the one tested configurationPassive control (ζ = 0): from a developed state of 46 defects the count falls to 4 by t = 100 and does not recover. Active (ζ = 2, λ = 0), T = 600, 128² seeds 0, 1, 2: defect count after t = 100 stays in 34 to 66 (e.g. seed 0: 52, 46, 50, 48, 56, 52 at t = 100, 200, ..., 600; 256² seed 0: 174 to 230), no blow-up, no decay. Twin runs from the same snapshot with a 1e-6 perturbation: separation grows exponentially, fitted rate 0.39 per time unit over 23 points between 3e-6 and 3e-2 (doubling time about 1.8) and saturates at 0.77; the ζ = 0 twin shrinks to 4e-8. One snapshot, one pair, float64: this is one Lyapunov estimate, not a spectrum
8Activity thresholdMeasured, finite-size64 box, λ = 0, T = 600, 2 seeds each: ζ = 0.05 decays to 0 defects; ζ = 0.1 and 0.2 keep 0 to 4 defects (one pair circulating or pinned, not turbulence); ζ = 0.3 keeps 8 to 12 and fluctuates; ζ ≥ 0.5 gives about 15 and up. With λ = 1 the sign matters: ζ = −0.3 sustains 13 to 18 defects, ζ = +0.3 decays to 0, ζ = −0.1 decays
9+1/2 defects self-propel, −1/2 do notConfirmed for +1/2; −1/2 also move, but slowerζ = 2, λ = 0, 128² × 3 seeds + 256², cores tracked every 0.5 time units with sub-grid centroids. Mean core speed: +1/2 3.1, −1/2 1.4, against 0.18 for both signs in the ζ = 0 control from the same snapshot (grid and centroid noise floor). Direction: cosine between the +1/2 displacement and the core's orientation vector (window mean of div Q) averages 0.87 (seeds 0, 1, 2 and 256²: 0.873 to 0.879), 88% of steps with
10ζ sign (extensile vs contractile)Observed, mapping not verifiedAt λ = 0 the equations have a q → −q symmetry that flips ζ: ζ = ±1 gave identical counts (28.0 / 28.1) and u (0.910 / 0.910). The sign matters only with λ ≠ 0 (ζ = −2, λ = 1: 93 defects; ζ = +2, λ = 1: 24). Which sign is "extensile" in the literature convention was not checked
11Defect density scales with activityObserved128², λ = 0: late counts 15.6, 28, 49, 93, 177 at ζ = 0.5, 1, 2, 4, 8 (roughly linear in ζ, spacing about 1/√ζ); mean S falls from 0.91 to 0.53. λ = 1 with ζ > 0 roughly halves the count and the flow; with ζ < 0 it raises them (ζ = −4: 205 defects)
12Resolution (open question 5)Partly testedGrid spacing 0.5, 0.75, 1, 1.5, 2 core sizes per cell at N = 128, ζ = 2, T = 300: all bounded, all sustained, defects per 100 core areas 1.17, 1.23, 1.35, 1.44, 1.75, S_late 0.78 to 0.73. So the state survives down to 2 core sizes per pixel, but the defect density drifts upward as cores go under-resolved. Not looked at visually at coarse dx
13float32 is enoughPartly tested128², from the dt = 0.05 snapshot, T = 300: float32 N_late 53.0, S_late 0.767, bounded; float64 54.8, 0.765. Not tested at dt_max, nor in a GPU float32 pipeline
14The Q-tensor can be emitted directly as the f_ tensor typeConfirmed in mathSee "Tensor emission" below

Cost (NumPy float64, median of 30 steps, one process; GPU figures are inferred) ​

Step128²256²2-D real transforms per step
B semi-implicit spectral0.28 ms1.05 ms6
B explicit FD0.12 ms0.41 ms0
C (flow + q)0.79 ms2.9 ms11

The transform count is from reading the code (2 forward for q, 5 inverse for u and its gradients, 2 forward for the right-hand side, 2 inverse for q). f_ks's spectral spike step does 2 (one forward, one inverse). Inferred, not measured: a GPU level C step costs on the order of 5× an f_ks step at the same size, less if two real planes share one complex transform; level B semi-implicit about 3×. At the "usable" dt of 0.35 one step per frame is enough at ζ ≈ 2; stronger activity needs substeps, scaling as ζ.

Tensor emission ​

Tested on the 256² level C snapshot (105 + and 105 − defects). Emit J = ½ [[1 − q1, −q2], [−q2, 1 + q1]] with q clamped to |q| ≤ 1, as the raw tensor (outlet 0 encoding: R = Jxx, G = Jxy·0.5 + 0.5, B = Jyy, A = 1). Trace is a constant 1, the eigenvalues are (1 ± S)/2, so coherence (λ1−λ2)/(λ1+λ2) equals S exactly and the dominant eigenvector is perpendicular to the director. Round trip through the documented decode: coherence error 3e-16, axis error 4e-16 rad (float64 arithmetic only, so this checks the algebra, not a 32-bit texture). Packed outlet from the same tensor, decoded as the doc's rule 4 with the 1e-7 bias: axis error 5e-8 rad. Observations that matter:

  • Overshoot: 0.05% of pixels have |q| > 1 (max 1.008), so the clamp is needed to keep J positive semi-definite. With the clamp, all raw channels stay in 0.006 to 0.994.
  • Cores: no pixel had |q| < 1e-3 (the grid never lands exactly on a core), 0.38% had |q| < 0.1. Decoding there gives low coherence, not NaN; the atan2(0,0) trap of the type doc's rule 6 was not triggered but the bias should stay.
  • Q1 (packed-angle convention): emitting the dominant eigenvector perpendicular to the director is the f_tf_tensormap convention (gradient across an edge, edge along θ+90°), so a consumer that draws along the structure contour draws along the director. Inferred from f_tf_hatch.md's wording; not run in Max.
  • Q3 (trace): a constant trace makes cores read as isotropic (coherence 0), not absent. A trace equal to S would make f_tf_glyph drop them. Not tested in a consumer.
  • Q4 (cores): at the observed 1.2 defects per 100 core areas, cores are a visible fraction of the picture (see fig3_schlieren.png: dark brushes meet at each core); Matt looked at fig3 on 2026-11-27 (offline image, not in Max) and said the cores look fine, so treat them as a feature for now. Decisions the same day: level C goes to a spec. (The spec kit, .specify/f_nematic/, had already run a γ sweep; see the Update below.)

A schlieren look needs no extra state: crossed-polarizer intensity weighted by S² is (q2 cos 2φp − q1 sin 2φp)², a polynomial of the two components (fig3 is exactly that).

Recommendation ​

Build level C (with level B as its ζ = 0 limit and as the warm-up), skip B alone, keep A only as a deterministic fallback. B settles to a uniform field within 100 to 1000 time units in these boxes, so as a demo source it is a short transient; C stays alive for as long as it was run (600) with a steady defect population, and one step per frame fits at moderate activity. Cost is higher than f_ks (inferred about 5×) but a single stage.

Dials an f_ module would want, in order of effect on what modules react to:

  1. Activity ζ (0 to about 4; sustained above about 0.3, defect density roughly ∝ ζ, mean S 0.9 to 0.6). The step size must shrink with ζ (dt ≲ 0.9/ζ at λ = 0), so the dial should also set substeps or clamp the speed.
  2. Scale (core size in pixels, i.e. dx): state survives to 2 core sizes per cell; density drifts. Same role as f_ks scale.
  3. Flow alignment λ (−1 to 1 or a sign switch): changes the character (λ = 1 halves defect density at ζ > 0, raises it at ζ < 0) and makes the sign of ζ matter. Might be a mode rather than a dial.
  4. Speed (time per frame), capped by ζ as above.
  5. A reset/seed. This spike did not sweep γ or η (flow screening length). Update 2026-11-27: the spec kit's Phase 0 ran a γ sweep (0.05 to 1, ζ = 2), results in .specify/f_nematic/tasks.md "Phase 0 findings" (per the spec session's report; not opened here, not verified). The η sweep was not run. Use that file, not this note, for γ.

Outlets, in the order the note lists plus one it did not: raw tensor, packed tensor (both exact from the state), schlieren look, S as a scalar, and, new from this spike, the flow u as a real vecfield (incompressible, signed, already computed every step; u_rms about 1.6 in core units, so it needs a gain). Inferred: that fits the f_solver_outlets.md "motion" row; the type doc's "no vecfield from the axis" rule is untouched because u is a true vector, not the director.

Not tested (do not rely on these) ​

γ and η in this spike (γ later swept in the spec kit, η not at all); elastic back-stress; dealiasing; initial states other than the σ = 0.1 noise quench; runs longer than 600 time units; more than one Lyapunov pair; float32 at dt_max or on a GPU; non-periodic or non-square domains; the Q-tensor in a real consumer in Max; how any of it looks at video resolution. Level A was not tested (it is analytic). The extensile/contractile naming was not checked against a source.

axes_of_investigation.md, phenomena_survey.md, f_cgl.md, f_solver_outlets.md, f_tf_backlog.md, f_tensorfield.md, optics_map.md, docs/f-reference/f_tensor_type.md.