In lecture notes related to the Discontinuous Galerkin method, there is mention of a magic formula which AFAIK first appeared on a paper1 by Douglas Arnold (at least in this context).

It has been proven and all, but it’s still called magic because its reasoning is not apparent at first glance. The magic formula is actually a superset of the divergence theorem, generalized to discontinuous fields. But to make that generalization, we need to abandon the standard formulation which starts by creating a triangular mesh, and consider arbitrary partitionings of a domain.

A domain $\Omega$ is partitioned into parts $P^i$, $i=1,\dots,n$ as follows:

We call the set of parts $\mathcal{P}$ a partition of $\Omega$.

# Broken Hilbert Spaces

We allow the vector field $\boldsymbol{u}$ to be discontinuous at boundaries $\partial P^i$ and continuous in $P^i$, $i=1,\dots,n$. To this end, we define the broken Hilbert space over partition $\mathcal{P}$

It can be seen that $H^m(\mathcal{P})\subseteq H^m(\Omega)$.

# Part Boundaries

Topologically, a part may share boundary with $\Omega$, like $P^4$. In that case, the boundary of the part is divided into an interior boundary and exterior boundary:

If a part has an exterior boundary, it is said to be an external part ($P^3$, $P^4$, $P^5$, $P^6$). If it does not have any exterior boundary, it is said to be an internal part.($P^1$, $P^2$).

# Divergence theorem over parts

For a vector field $\boldsymbol{v}\in H^1(\mathcal{P})$, $i=1,\dots,n$, we can write the following integral as a sum and apply the divergence theorem afterward

We define the portion $\Gamma^{ij}$ of the boundary that part $P^i$ shares with $P^j$ as the interface between $P^i$ and $P^j$.

If $P^i$ and $P^j$ are not neighbors, we simply have $\Gamma^{ij}=\emptyset$.

# Integrals over interior boundaries

For opposing parts $P^i$ and $P^j$,

we have different values of the function $\boldsymbol{v}^{ij} = \boldsymbol{v}|_{\Gamma^{ij}}$ and conjugate normal vectors at the interface $\Gamma^{ij}$:

Since

we can rearrange the integral over interior boundaries as

# The jump operator

Integrals over the same interface can be grouped together:

Defining the jump of $\boldsymbol{v}$ across $\Gamma^{ij}$

The jump of a function measures its discontinuity across interfaces. We can write

We may drop the superscripts where there is no confusion.

# Interfaces and external boundaries

It is convenient to group the interfaces:

which allows us to write

It’s obvious that the union of part external boundaries equals the domain boundary:

which allows us to write

With the results obtained, we put forward a generalized version of the divergence theorem: Let $\boldsymbol{v}\in H^1(\mathcal{P})$ be a vector field. Then we have

Verbally, the integral of the divergence of a vector field over a domain $\Omega$ equals its integral over the domain boundary $\partial\Omega$, plus the integral of its jump over part interfaces $\mathcal{I}$.

In the case of a continuous field, the jumps vanish and this reduces to the regular divergence theorem.

# The Magic Formula

There are different versions of the magic formula for scalar, vector and tensor fields, and for different IBVPs. I won’t try to derive them all, but give an example: If we were substitute a linear mapping $\boldsymbol{A}\boldsymbol{v}$ instead of $\boldsymbol{v}$, we would have the jump $\llbracket \boldsymbol{A}\boldsymbol{v} \rrbracket$ on the right-hand side.

We introduce the vector and tensor average operator $\{\cdot\}$

and tensor jump operator $\llbracket\cdot\rrbracket$

We also note the boundary jump/average property which is used on the integral over $\partial\Omega$

(This property is used implicitly in many places, and often causes confusion).

These definitions allow us to write the identity

which is easily proven when expanded.

The different versions of the magic formula are obtained by substituting the identities above—or their analogs—in the discontinuous divergence theorem.

1. Douglas N. Arnold. An interior penalty finite element method with discontinuous elements. SIAM J. Numer. Anal., 19(4):742–760, 1982.