---
title: Learned Energy-Constrained Stencils
url: https://www.emergentmind.com/topics/energy-constrained-learned-stencils
type: topic
---

# Learned Energy-Constrained Stencils

Energy-constrained learned stencils are data-driven spatial discretizations tailored for the one-dimensional Maxwell system that preserve discrete electromagnetic energy through explicit enforcement of skew-adjointness. These stencils are designed by learning convolution operators from high-fidelity spectral data, subject to rigorous linear constraints that guarantee exact conservation properties under implicit time discretization schemes such as Crank–Nicolson. The approach connects data-driven numerical methods with the classical structure-preserving finite-difference time-domain (FDTD) paradigm by marrying data fit with structural constraints that ensure energy conservation at the semi-discrete level [2601.01902].

## 1. Formulation of the Data-Driven Stencil Learning Problem

Let $w \in \mathbb{R}^{2R+1}$ denote the convolution stencil weights representing the discrete spatial derivative, with support width $R$. The learning problem is formulated as a convex quadratic program:

\[
\min_{w \in \mathbb{R}^{2R+1}} \;\; \frac{1}{2}\|A w - b\|_2^2 + \frac{\lambda}{2}\|w\|_2^2
\]
subject to
\[
C w = d, \qquad -M \leq w_\ell \leq M, \;\; \ell=-R,\ldots,+R
\]

Here, $A$ is the design matrix that compiles all sliding window patches from training data for $E$ and $H$ fields, $b$ contains target temporal derivatives, and $\lambda$ implements Tikhonov regularization. The linear constraint $Cw=d$ enforces discrete skew-adjointness via

- $w_0 = 0$
- $w_{-\ell} + w_{+\ell} = 0$ for $\ell = 1,\ldots,R$

This is both necessary and sufficient for a discrete operator $D$ to satisfy $\langle Du, v \rangle = -\langle u, Dv \rangle$ in the grid $L^2$ inner product. The box constraints $|w_\ell| \leq M$ bound the coefficients.

## 2. Skew-Symmetric Convolutions and Discrete Energy Conservation

Consider the semi-discrete Maxwell system on a uniform grid with $N$ points and mesh spacing $\Delta x$:

\[
\partial_t E = D H, \qquad \partial_t H = D E
\]

where $D$ is the convolution operator defined by learned stencil $w$. The discrete electromagnetic energy is

\[
\mathcal{E}(t) = \frac{1}{2}\|E(t)\|^2 + \frac{1}{2}\|H(t)\|^2
\]

Differentiation yields

\[
\frac{d}{dt}\mathcal{E}(t) = \langle D H, E \rangle + \langle D E, H \rangle
\]

If $D$ is skew-adjoint ($D^T = -D$), the two terms cancel exactly, so $d\mathcal{E}/dt = 0$: the discrete system preserves electromagnetic energy identically. This condition is extended to Crank–Nicolson time stepping: the implicit midpoint update

\[
\frac{U^{n+1} - U^n}{\Delta t} = A \frac{U^{n+1} + U^n}{2}
\]
for
\[
A = \begin{pmatrix} 0 & D \\ D^T & 0 \end{pmatrix}, \qquad A^T = -A, \qquad U^n = (H^n, E^n)^T
\]
ensures
\[
\mathcal{E}^{n+1} = \mathcal{E}^n, \quad \forall n
\]
by virtue of the skew-adjointness constraint. Thus, discrete energy is conserved to machine precision.

## 3. Fourier Symbol, Numerical Wave Speed, and CFL Condition

The periodic convolution stencil has the Fourier symbol

\[
\mu(\theta) = \sum_{k=-R}^{R} w_k\,e^{ik\theta}, \qquad \theta \in [-\pi, \pi]
\]

This symbol determines the eigenvalues for each mode as $\lambda(\theta) = \pm i |\mu(\theta)|$, and therefore the numerical wave speed

\[
c(\theta) = | \mu(\theta) |
\]

The maximum wave speed $c_{\max}$ is

\[
c_{\max} = \max_{\theta \in [-\pi, \pi]} | \mu(\theta) |
\]

When using explicit time-stepping (e.g., the leapfrog scheme), the CFL condition for stability is

\[
\Delta t \leq \frac{2}{c_{\max}}
\]

The learned stencil’s Fourier symbol therefore sets both propagation speeds and stability boundaries in the discrete solver.

## 4. Comparison of Convex Optimization Solvers

Several convex solvers are evaluated for the quadratic program:

- **Projected Gradient (PG)** and **Nesterov-Accelerated Gradient (NAG)**: Solve equality-constrained problems with updates projected onto $Cw=d$. They enforce constraints to machine precision (residual $\lesssim 10^{-16}$) and are computationally inexpensive, but for larger stencil radii $R$, they plateau at suboptimal objective values.
- **ADMM (Alternating Direction Method of Multipliers)**: Employs variable splitting ($w=z$), accomplishing constraint fulfillment in $w$-updates and box clipping in $z$-updates. ADMM reaches the same objective as interior-point solvers in 1–2 iterations, equality violations $\lesssim 10^{-13}$, and data-fit error remains low as $R$ increases.
- **Interior-Point (CVXPY+SCS)**: Used as a reference; achieves lowest objectives nearly identical to ADMM to 6–7 digits, with residuals $\lesssim 10^{-7}$, but incurs higher runtime.

Numerical tests for $R=1$ (with $\Delta x=1/64$) yield stencils $\approx [-32.906114, 0, +32.906114]$ (compared to exact centered-difference $[-32,0,+32]$), and all methods deliver final-time electric-field $L^2$ error $\approx 5 \times 10^{-3}$. For $R \geq 2$, PG and NAG errors rise to $O(1)$, while ADMM and CVX remain at $\approx (3$–$6) \times 10^{-3}$.

## 5. Discrete Energy Conservation under Crank–Nicolson Schemes

Crank–Nicolson applied to $dU/dt = A U$ with $A^T = -A$ yields an update that preserves the discrete energy invariant:

\[
\frac{U^{n+1} - U^n}{\Delta t} = A\,\frac{U^{n+1}+U^n}{2}
\]

Defining $\mathcal{E}^n = \frac{1}{2}\|U^n\|_2^2$, the update guarantees

\[
\mathcal{E}^{n+1} - \mathcal{E}^n = 0
\]

Numerically, the drift after $N_t = 300$ CN steps with $\Delta t = 0.5 \Delta x$ is $|\mathcal{E}^n - \mathcal{E}^0| \lesssim 10^{-14}$ for both learned and standard stencils, matching machine roundoff.

## 6. Quantitative Comparison with Classical Central-Difference Stencils

For a grid spacing $\Delta x=1/64$ and $R=1$:

- **Centered-Difference Stencil**: $w_\text{CD} = [-1/(2\Delta x),0,+1/(2\Delta x)] = [-32,0,+32]$
- **Learned Energy-Constrained (ADMM)**: $w = [-32.906114,0,+32.906114]$; observed $c_\text{max}=32.906114$ (vs. $32$ for CD)
- **Electric Field $L^2$ Error**: $\text{err}_\text{CD} \approx 5.05 \times 10^{-3}$; $\text{err}_\text{learned} \approx 5.12 \times 10^{-3}$
- **Discrete Energy Drift**: $\max_n |\mathcal{E}^n - \mathcal{E}^0| \lesssim 10^{-14}$

For wider stencils ($R > 1$), learned stencils produce accuracy at least comparable to central differences for $R=1$ and show modest improvement for $R>1$, all while exactly preserving energy under CN.

## 7. Structural Significance and Implications

Energy-constrained learned stencils provide a framework that bridges traditional structure-preserving discretizations and modern data-driven schemes. By learning spatial discretizations subject to essential physical constraints, the methodology enables exact conservation of semi-discrete invariants while leveraging training data for enhanced accuracy. The Fourier analytic characterization links the learned stencil to propagation and stability traits, and efficient convex solvers enable practical deployment in simulation pipelines. A plausible implication is the extension of such physically-constrained learning approaches to broader PDE classes, where invariants such as energy, mass, or momentum are fundamental.

*For implementation details and further mathematical development, see "Energy Conserving Data Driven Discretizations for Maxwells Equations" [2601.01902].*

Source: https://www.emergentmind.com/topics/energy-constrained-learned-stencils