1 Introduction

Illumination optics deals with the design of optical components for various applications, like LED lighting [28] and automotive headlamps [10, 36]. The design of these optical components requires a different approach than used in imaging optics, as imaging effects are highly undesirable [9]. Light propagation through an optical system is usually computed using ray tracing [14]. This means computing the evolution of many rays through an optical system, where upon hitting an optical interface Snell’s law of refraction or the law of specular reflection have to be applied. Typical optical interfaces are lenses or mirrors. Ray tracing is commonly employed to directly obtain the illuminance or intensity on a target. Although, forward quasi-Monte Carlo ray tracing converges rather slowly with rates close to \(\mathcal {O} \left( N_{RT} ^{-1} \right) \) where \(N_{RT}\) denotes the number of rays, it is the industry standard. For details on quasi-Monte Carlo integration, see e.g. [24].

The analysis of light propagation using a phase space description provides a new approach to understanding optical systems [17, 29, 35]. Phase space, being defined as the collection of all positions and direction coordinates of rays, provides a complete description of the spatial and angular distribution of light. A point in phase space evolves according to a Hamiltonian, describing the evolution of one single light ray, whenever the refractive index is smooth. When a ray hits an optical interface the laws for refraction or reflection have to be applied. In [11,12,13] new ray tracing methods are presented based on the phase space description. These methods allow for tracing of fewer rays to achieve the same accuracy as classical ray tracing.

An alternative approach to ray tracing is based on directly obtaining an energy distribution on phase space, rather than its integrated quantities such as the illuminance or luminous intensity. The propagation of an energy distribution, related to the luminance, through an optical system is governed by Liouville’s equation for geometrical optics on phase space. Recently, numerical schemes for Liouville’s equation were developed that incorporate the optical interfaces. In [33] van Lith et al. derived a first-order upwind finite difference scheme and in [32] van Lith et al. introduced a third-order active flux finite volume scheme on moving meshes. The third-order active flux scheme was proved to be faster and more accurate compared to classical ray tracing for obtaining an energy distribution on phase space. Additionally in [31] van Lith made use of the discontinuous Galerkin spectral element method to solve Liouville’s equation.

The discontinuous Galerkin spectral element method (DGSEM) discussed by Kopriva in [21] is a collocation scheme for the semi-discretisation of the spatial domain for conservation laws, leaving the time-like variable continuous. In terms of Liouville’s equation this entails discretising phase space. The phase space domain is partitioned into elements with each element having interior nodes placed at collocation points. The solution is approximated using a polynomial, where the polynomial degree determines the number of interior nodes used for each element. Consequently the method has an extraordinary flexibility as it is an hp-method, where h refers to the mesh size and p to the polynomial degree, i.e. the accuracy can be increased by decreasing the mesh size or by increasing the polynomial degree. Additionally, the method does not enforce continuity across the boundary of each element, making it particularly suitable for the discontinuous solutions across optical interfaces.

At an optical interface Liouville’s equation is not valid. Instead, Snell’s law of refraction or the law of specular reflection describe the discontinuous change in the direction coordinate, i.e., a jump in phase space. In what follows, we will see that this results in non-local boundary conditions for the energy distribution in phase space. Our contribution consists of describing the treatment of these optical interfaces so that they obey energy conservation. In the DGSEM the elements communicate using numerical fluxes. Snell’s law and the law of specular reflection are incorporated in these numerical fluxes at an optical interface. In addition to the discontinuous change in the direction coordinate described by these laws, a single element before the optical interface might contribute to multiple elements after the optical interface. This connection to multiple elements is similar to fully non-conforming geometries when using subdomain refinement [3, 4]. Kopriva et al. outlined such a strategy for the DGSEM in [23]. In [5] an analysis of this method is presented by Bui-Thanh and Ghattas. Across an optical interface the numerical fluxes are discontinuous and therefore we have to take a different approach. Inspired by [23], we present a method that directly incorporates the laws of optics and obeys energy conservation.

The article is outlined as follows: in Sect. 2 we discuss the conserved quantities in an optical system and Liouville’s equation, and in Sect. 3 we discuss the DGSEM. In Sect. 4 we discuss the energy conservative treatment of the optical interfaces, and in Sect. 5 we present numerical experiments proving energy conservation for two examples. The first example features a smooth refractive index field, while the second example is a test case featuring a discontinuity in the refractive index described by van Lith et al. in [33]. In the latter example, we compare the DGSEM for solving Liouville’s equation to quasi-Monte Carlo ray tracing for obtaining the illuminance. Finally we present our conclusions in Sect. 6.

2 Conserved Quantities and Liouville’s Equation

In optics we consider the transfer of luminous flux between surfaces. A source emits a beam of radiation or light, carrying a finite amount of luminous flux denoted by \(\varPhi \). In the absence of losses by absorption or scattering in an optical system, the total flux \(\varPhi \) is conserved, i.e., energy throughout the optical system is conserved. A related quantity is the luminance denoted by \(\rho ^*\), which is defined as [9, 25]

$$\begin{aligned} \rho ^* := \frac{ \mathrm {d}\varPhi }{ \mathrm {d}A \cos \theta \, \mathrm {d}\omega }, \end{aligned}$$
(1)

where \(\mathrm {d}\varPhi \) is an infinitesimal amount of flux carried by an infinitesimal beam, \(\mathrm {d}\omega \) is an element of solid angle subtended at the center of the source by the area at the detector \(\mathrm {d}A\), and \(\mathrm {d}A \cos \theta \) the projected area perpendicular to the beam, i.e., \(\mathrm {d}A\) is an element of the surface area of the detector and \(\theta \) describes the angle between the normal of the detector and the beam. The solid angle describes a cone on the unit sphere with the center of the source as its vertex and \(\mathrm {d}\omega \) the area on the unit sphere subtended by the cone.

Another important quantity that is also conserved in an optical system is étendue, which is defined by [9]

$$\begin{aligned} \mathrm {d} \mathcal {U} := n^2 \mathrm {d}A \cos \theta \, \mathrm {d}\omega , \end{aligned}$$
(2)

where n is the refractive index in which the beam is immersed. This allows us to write the luminance as

$$\begin{aligned} \rho ^* = n^2 \frac{ \mathrm {d}\varPhi }{ \mathrm {d} \mathcal {U} }. \end{aligned}$$
(3)

When a beam is propagating through a homogeneous medium the luminance \(\rho ^*\) is conserved, as is implied by conservation of energy and conservation of étendue. When a beam of light strikes an optical interface, e.g., a lens or a mirror, the beam is subject to Snell’s law of refraction or the law of specular reflection. In the case where the beam is refracted, e.g., a transition from a medium with refractive index \(n_1\) to a medium with refractive index \(n_2\), the luminance is not conserved. Assuming no Fresnel reflections, and applying conservation of energy and étendue, we obtain [25, 26]

$$\begin{aligned} \frac{\rho _\text {i} ^*}{n_1^2} = \frac{\rho _\text {t} ^*}{n_2^2}, \end{aligned}$$
(4)

where \(\rho _\text {i}^*\) and \(\rho _\text {t}^*\) describe the incident and transmitted luminance, respectively. The quantity \(\rho ^* / n^2\), known as basic luminance is conserved for refractions, cf. (4). A similar result can be derived for reflections, where the refractive indices are equal. Relation (4) will be referred to as basic luminance invariance. For a complete derivation including Fresnel reflections see [9, 25, 26].

The definitions of luminance, étendue and basic luminance invariance described above hold for three-dimensional optics, whereas in two-dimensional optics the definitions are slightly altered. For more details, see [9]. In summary, we denote the basic luminance for both two- and three-dimensional optics by \(\rho \), which is defined by

$$\begin{aligned} \rho := \frac{ \mathrm {d}\varPhi }{ \mathrm {d} \mathcal {U} }, \end{aligned}$$
(5)

where the étendue \(\mathrm {d}\mathcal {U}\) for two- and three-dimensional systems reads [9]

$$\begin{aligned} \mathrm {d} \mathcal {U} = {\left\{ \begin{array}{ll} n^2 \mathrm {d}A \cos \theta \, \mathrm {d}\omega \quad &{} \text {for 3D optics}, \\ n \; \mathrm {d}l \cos \theta \, \mathrm {d}\theta \quad &{} \text {for 2D optics}, \end{array}\right. } \end{aligned}$$
(6)

where for 2D optics \(\theta \) denotes the angle between the normal of the detector and the beam, and \(\mathrm {d}\theta \) an element of angle subtended at the center of the source by the infinitesimal line segment at the detector \(\mathrm {d}l\). The basic luminance is related to the luminance by \(\rho = \rho ^* / n^2\) for three-dimensional optics, whereas for two-dimensional optics \(\rho = \rho ^* / n\).

2.1 Liouville’s Equation

In geometrical optics the evolution of light rays in a beam of light can be cast in a Hamiltonian system, where we denote with \({\varvec{q}} \in \mathbb {R}^d\) the position and \({\varvec{p}} \in \mathbb {R}^d\) the momentum coordinates [35]. For two-dimensional optics \(d = 1\), while for three-dimensional optics \(d = 2\). Both terms together describe a point \(({\varvec{q}}, {\varvec{p}})\) in phase space, where the phase space \(\mathcal {P}\) is defined as the collection of all positions \({\varvec{q}}\) and momenta \({\varvec{p}}\) at a certain position along the optical axis denoted by the z-coordinate. A point in phase space evolves when we move along the optical axis.

The momentum \(\mathbf {{p}} = (\varvec{p}, p_z) \in \mathbb {R}^3\) is restricted to Descartes’ sphere \(\left| \mathbf {{p}} \right| = n(z, {\varvec{q}})\) where n is the refractive index field as a function of the three-dimensional position coordinates \(\mathbf {{q}} = (\varvec{q}, z)\) [35]. This restriction invites us to use spherical coordinates to represent the momentum vector \(\mathbf \mathbf{{p}}\) as

$$\begin{aligned} \mathbf {{p}} = \left( \varvec{p}, p_z\right) = n \left( \sin \theta \cos \varphi , \sin \theta \sin \varphi , \cos \theta \right) , \end{aligned}$$
(7)

where \(\theta \) represents the polar angle, describing the angle between the z-axis and \(\mathbf {{p}}\) measured from the z-axis, and \(\varphi \) the azimuthal angle for describing the direction in the \(\varvec{q}\)-plane. Therefore, at a given position \(z_0\) along the optical axis, one can visualise the phase space coordinates on the screen that is perpendicular to the z-axis and intersects the z-axis at \(z_0\), where \({\varvec{q}}\) is the position on the screen and \({\varvec{p}}\) describes the projection of \(\mathbf {{p}}\) on the screen [32]. The restriction of the momentum for physical rays \(\mathbf {{p}}\) to Descartes’ sphere also implies that the two-dimensional momentum vector is restricted by \(\left| {\varvec{p}} \right| \le n\), describing a region known as Descartes’ disc [35].

The phase space coordinates of a light ray evolve as a function of the distance along the optical axis according to Hamilton’s equations, which read

$$\begin{aligned} \frac{\mathrm {d} \varvec{q}}{\mathrm {d} z}&= \frac{\partial h}{\partial \varvec{p}}, \end{aligned}$$
(8a)
$$\begin{aligned} \frac{\mathrm {d} \varvec{p}}{\mathrm {d} z}&= -\frac{\partial h}{\partial \varvec{q}}, \end{aligned}$$
(8b)

with \(h = h(z, \varvec{q}, \varvec{p})\) the optical Hamiltonian given by

$$\begin{aligned} h(z, \varvec{q}, \varvec{p}) = -\sigma \sqrt{n(z, \varvec{q})^2 - \left| \varvec{p} \right| ^2}. \end{aligned}$$
(9)

Here, \(\sigma \in \{-1, 0, +1\}\) denotes the direction of the light ray travelling along the optical axis, with \(\sigma = 0\) being marginal rays that travel perpendicular to the optical axis [35]. For simplicity, we assume that all rays travel in the positive z-direction given by \(\sigma = +1\).

Hamilton’s Eqs. (8) hold for a single light ray, however, this may be generalised to a beam of light carrying a finite amount of energy in terms of luminous flux. The flow generated by Hamilton’s equations describes canonical transformations, otherwise known as symplectic transformations, on phase space. These transformations preserve the symplectic structure of phase space [1]. In other words the phase space volume element \(\mathrm {d}q_1 \mathrm {d}q_2 \mathrm {d}p_1 \mathrm {d}p_2\) is constant. In the context of optics this has the equivalent meaning of étendue conservation. In fact \(\mathrm {d} \mathcal {U} = \mathrm {d}q_1 \mathrm {d}q_2 \mathrm {d}p_1 \mathrm {d}p_2\), which can be obtained from the first two components of the three-dimensional momentum vector described by expression (7). The Jacobian determinant of \(\varvec{p}\) with respect to the polar and azimuthal angles \(\theta \) and \(\varphi \), can be computed as

$$\begin{aligned} \mathrm {d}p_1 \mathrm {d}p_2 = \det \left( \frac{\partial \left( p_1, p_2\right) }{\partial (\theta , \varphi ) } \right) \mathrm {d}\theta \mathrm {d}\varphi = n^2 \cos \theta \mathrm {d}\theta \sin \theta \mathrm {d}\varphi = n^2 \cos \theta \mathrm {d}\omega , \end{aligned}$$
(10)

with \(\mathrm {d}\omega = \sin \theta \mathrm {d}\theta \mathrm {d}\varphi \) an element of solid angle. Noting that the differential area on a screen can be written as \(\mathrm {d}A = \mathrm {d}q_1 \mathrm {d}q_2\) and substituting (10) into relation (6) for 3D optics, we obtain

$$\begin{aligned} \mathrm {d} \mathcal {U} = \mathrm {d}q_1 \mathrm {d}q_2 \mathrm {d}p_1 \mathrm {d}p_2. \end{aligned}$$
(11)

The basic luminance invariance (4) implies that \(\rho \) remains constant if we move an arbitrary distance \(\varDelta z\) along the optical axis, i.e.,

$$\begin{aligned} \rho \left( z + \varDelta z, \varvec{q}(z + \varDelta z), \varvec{p}(z + \varDelta z) \right) = \rho (z, \varvec{q}(z), \varvec{p}(z) ). \end{aligned}$$
(12)

Note that this relation also holds when a beam of light is reflected or refracted. If the solution is sufficiently smooth, one can derive Liouville’s equation by subtracting the right-hand side of (12) from its left-hand side and dividing by \(\varDelta z\) and subsequently taking the limit \(\varDelta z \rightarrow 0\), resulting in

$$\begin{aligned} \frac{\partial \rho }{\partial z} + \frac{\partial h}{\partial \varvec{p}} \varvec{\cdot } \frac{\partial \rho }{\partial \varvec{q}} - \frac{\partial h}{\partial \varvec{q}} \varvec{\cdot } \frac{\partial \rho }{\partial \varvec{p}} = 0. \end{aligned}$$
(13)

Here, we have already applied Hamilton’s equations (8). The advective form of Liouville’s equation (13) may be written in conservative form by assuming that h is twice differentiable, upon which we obtain

$$\begin{aligned} \frac{\partial \rho }{\partial z} + \nabla \varvec{\cdot } \varvec{f} = 0, \end{aligned}$$
(14a)

with \(\nabla = ( \frac{\partial }{\partial \varvec{q}}, \frac{\partial }{\partial \varvec{p}} )^\mathrm{T}\) and the flux vector \(\varvec{f} = \varvec{f}(\varvec{q}, \varvec{p})\) defined as

$$\begin{aligned}&\varvec{f} := \rho \varvec{u} = \rho \begin{pmatrix} \frac{\partial h}{\partial \varvec{p}} \\ -\frac{\partial h}{\partial \varvec{q}} \end{pmatrix}, \end{aligned}$$
(14b)

where we have used that the velocity field \(\varvec{u}\) is divergence-free, and the superscript T denotes transpose. Note that an optical interface causes the Hamiltonian to be discontinuous. Therefore, at an optical interface, Liouville’s equation does not hold and we must apply (12) together with Snell’s law and/or the law of specular reflection, in the limit \(\varDelta z \rightarrow 0\).

Solving Liouville’s equation on phase space at any point z along the optical axis tells us how the basic luminance changes when light propagates through an optical system, allowing us to compute at each z-coordinate the related integral quantities such as luminous flux on the screen. The total luminous flux \(\varPhi \) in the optical system at \(z = \mathrm {const}\) reads

$$\begin{aligned} \varPhi (z) = \int _{\mathcal {P}(z)} \rho (z, \varvec{q}, \varvec{p}) \, \mathrm {d} \mathcal {U}. \end{aligned}$$
(15)

Here, the phase space dependence on the z-coordinate is denoted explicitly, since the momentum domain is restricted according to Descartes’ disc. Assuming the optical system is lossless the total luminous flux should be constant, i.e., \(\varPhi (z) = \varPhi (0)\).

An infinitesimal element of illuminance E is defined by

$$\begin{aligned} \mathrm {d}E := \frac{ \mathrm {d}\varPhi }{ \mathrm {d}A }. \end{aligned}$$
(16)

Applying definition (5) for the basic luminance and relation (11), \(\mathrm {d}E\) (16) can be rewritten as

$$\begin{aligned} \mathrm {d}E = \rho \, \mathrm {d}p_1 \mathrm {d}p_2. \end{aligned}$$

Next, integrating over momentum space results in the illuminance \(E(z, \varvec{q})\), i.e.,

$$\begin{aligned} E(z, \varvec{q}) = \int _{P(z)} \rho (z, \varvec{q}, \varvec{p}) \, \mathrm {d}p_1 \mathrm {d}p_2, \end{aligned}$$
(17)

where \(\varvec{p} = (p_1, p_2) \in P(z)\) in which P(z) denotes the two-dimensional momentum space at a certain position z along the optical axis. Alternatively, an infinitesimal element of luminous intensity I is defined by

$$\begin{aligned} \mathrm {d}I := \frac{ \mathrm {d}\varPhi }{ \mathrm {d}\omega }. \end{aligned}$$
(18)

Applying again definition (5) for the basic luminance and definition (6) for the étendue, \(\mathrm {d}I\) (18) can be written as

$$\begin{aligned} \mathrm {d}I = \rho \, n^2 \cos \theta \, \mathrm {d}A. \end{aligned}$$

Subsequently using the relation for \(p_z\) defined in (7) and \(\mathrm {d}A = \mathrm {d}q_1 \mathrm {d}q_2\), followed by integration over the position coordinates on the screen, denoted by \(\varvec{q} = (q_1, q_2) \in Q(z)\), we obtain

$$\begin{aligned} I(z, \varvec{p}) = \int _{Q(z)} \rho (z, \varvec{q}, \varvec{p}) p_z(z, \varvec{q}, \varvec{p}) n(z, \varvec{q}) \, \mathrm {d}q_1 \mathrm {d}q_2. \end{aligned}$$
(19)

With these definitions, the main quantities of interest in optics can thus be easily computed from the basic luminance, satisfying Liouville’s equation. In the next section, we explore a method for solving Liouville’s equation.

3 Derivation of DGSEM

In what follows, we restrict ourselves to two-dimensional optical systems, hence reducing the complexity from a four-dimensional phase space to a two-dimensional phase space with position coordinate q and momentum coordinate p, and the distance along the optical axis denoted by z. Note that the position and momentum are now scalar quantities, therefore we omit the bold-face notation for these quantities. Next, we outline a spatial semi-discretisation of Liouville’s equation, leaving only z continuous. For the semi-discretisation we apply the discontinuous Galerkin spectral element method (DGSEM) described by Kopriva in [21], to the two-dimensional Liouville equation for \(\rho = \rho (z, q, p)\) in conservative form

$$\begin{aligned}&\frac{\partial \rho }{\partial z} + \nabla \varvec{\cdot } \varvec{f} = 0, \end{aligned}$$
(20a)

where \(\nabla = \left( \frac{\partial }{\partial q}, \frac{\partial }{\partial p} \right) ^\text {T}\) and the flux vector \(\varvec{f}\) now reads

$$\begin{aligned}&\varvec{f} = \rho \varvec{u} = \rho \begin{pmatrix} \frac{\partial h}{\partial p} \\ -\frac{\partial h}{\partial q} \end{pmatrix} . \end{aligned}$$
(20b)

The Hamiltonian h for two-dimensional optics reduces to

$$\begin{aligned} h(z, q, p) = -\sqrt{ n(z, q)^2 - p^2 }, \end{aligned}$$
(21)

and consequently the velocity \(\varvec{u}\) reads

$$\begin{aligned} \varvec{u} = \frac{1}{ \sqrt{ n^2 - p^2} } \begin{pmatrix} p \\ n \frac{\partial n}{\partial q} \end{pmatrix} . \end{aligned}$$
(22)

For phase space discretisation, the two-dimensional phase space domain \(\mathcal {P}\) is covered with straight-sided quadrilaterals \(\varOmega ^k \subset \mathcal {P}\) with k the index of the element. In a more general discretisation, the boundaries of quadrilaterals are allowed to be curved, such that curved boundaries from physical constraints can be modelled appropriately. In fact, when the refractive index field changes continuously as a function of \({\varvec{q}}\), then the maximum allowed momentum varies as a function of q due to the restriction of \({\varvec{p}}\) to Descartes’ sphere. This restriction can be accommodated by curved boundaries when solving Liouville’s equation, see [31]. For a discussion on DGSEM with curved quadrilateral elements, see for example [8, 18, 21, 22]. In this paper we only consider straight-sided quadrilaterals.

Each quadrilateral \(\varOmega ^k\) has four vertices \(\{ \varvec{x}_1, \varvec{x}_2, \varvec{x}_3, \varvec{x}_4 \}\) labelled in counter-clockwise direction where \(\varvec{x} = \left( q, p \right) ^\text {T}\) and we have omitted the element index (superscript k), see Fig. 1. For ease of computation, the reference square \(\chi = [-1, 1]^2\) is mapped to each quadrilateral \(\varOmega ^k\), transforming a point in the reference domain \((\xi , \eta ) \in \chi \) to a point in physical space \(\varvec{x}(\xi , \eta ) \in \mathcal {P}\) using the following bilinear transformation

$$\begin{aligned} \begin{aligned} \varvec{x}(\xi , \eta ) = \frac{1}{4}&\left[ (1 - \xi ) (1 - \eta ) \varvec{x}_1 + (1 + \xi ) (1 - \eta ) \varvec{x}_2 \right. \\&+ \left. (1 + \xi ) (1 + \eta ) \varvec{x}_3 + (1 - \xi ) (1 + \eta ) \varvec{x}_4 \right] . \end{aligned} \end{aligned}$$
(23)

The Jacobian of the transformation is given by \(\frac{\partial (q, p)}{\partial (\xi , \eta )} = \left( \frac{\partial \varvec{x}}{\partial \xi }, \frac{\partial \varvec{x}}{\partial \eta } \right) \), where the columns read

$$\begin{aligned} \frac{\partial \varvec{x}}{\partial \xi }&= \begin{pmatrix} \frac{\partial q}{\partial \xi } \\ \frac{\partial p}{\partial \xi } \end{pmatrix} = \frac{1}{4} \left[ (1 - \eta ) \left( \varvec{x}_2 - \varvec{x}_1 \right) + (1 + \eta ) \left( \varvec{x}_3 - \varvec{x}_4 \right) \right] , \end{aligned}$$
(24a)
$$\begin{aligned} \frac{\partial \varvec{x}}{\partial \eta }&= \begin{pmatrix} \frac{\partial q}{\partial \eta } \\ \frac{\partial p}{\partial \eta } \end{pmatrix} = \frac{1}{4} \left[ (1 - \xi ) \left( \varvec{x}_4 - \varvec{x}_1 \right) + (1 + \xi ) \left( \varvec{x}_3 - \varvec{x}_2 \right) \right] . \end{aligned}$$
(24b)

The divergence term in (20a) can be rewritten by applying the chain rule resulting in

$$\begin{aligned} \nabla \varvec{\cdot } \varvec{f} = \frac{1}{\mathcal {J}} \nabla _{\varvec{\xi }} \varvec{\cdot } \widetilde{ \varvec{f} }, \end{aligned}$$
(25)

where \(\mathcal {J} = \frac{\partial q}{\partial \xi } \frac{\partial p}{\partial \eta } - \frac{\partial q}{\partial \eta } \frac{\partial p}{\partial \xi }\) denotes the Jacobian determinant, \(\nabla _{\varvec{\xi }} = \left( \frac{\partial }{\partial \xi }, \frac{\partial }{\partial \eta } \right) ^\text {T}\) and \(\widetilde{\varvec{f}}\) is an auxiliary flux defined by the product of the adjoint Jacobian matrix and the flux \(\varvec{f}\), i.e.,

$$\begin{aligned} \widetilde{\varvec{f}} := \begin{pmatrix} \frac{\partial p}{\partial \eta } &{} -\frac{\partial q}{\partial \eta } \\ -\frac{\partial p}{\partial \xi } &{} \frac{\partial q}{\partial \xi } \end{pmatrix} \varvec{f}. \end{aligned}$$
(26)
Fig. 1
figure 1

Mapping from reference square \(\chi \) to a quadrilateral \(\varOmega ^k\)

Applying the transformation (25) to Liouville’s Eq. (20a), we obtain

$$\begin{aligned} \frac{\partial \rho }{\partial z} + \frac{1}{\mathcal {J}} \nabla _{\varvec{\xi }} \varvec{\cdot } \widetilde{\varvec{f}} = 0, \end{aligned}$$
(27)

where \(\rho = \rho (z, \xi , \eta )\).

The weak formulation of Liouville’s equation is obtained by first multiplying the PDE (27) by the Jacobian determinant \(\mathcal {J}\) and by a smooth test function \(\phi \), and subsequently integrating over the reference domain \(\chi \). This results in

$$\begin{aligned} \int _{\chi } \phi \mathcal {J} \frac{\partial \rho }{\partial z} \, \mathrm {d}A_{\varvec{\xi }} + \int _\chi \phi \nabla _{\varvec{\xi }} \varvec{\cdot } \widetilde{\varvec{f}} \, \mathrm {d}A_{\varvec{\xi }} = 0. \end{aligned}$$
(28)

The second term is rewritten by applying the product rule and Gauss’s theorem, so that

$$\begin{aligned} \int _\chi \phi \nabla _{\varvec{\xi }} \varvec{\cdot } \widetilde{\varvec{f}} \, \mathrm {d}A_{\varvec{\xi }}&= \int _\chi \left( \nabla _{\varvec{\xi }} \varvec{\cdot } \left( \phi \widetilde{\varvec{f}} \right) - \left( \nabla _{\varvec{\xi }} \phi \right) \varvec{\cdot } \widetilde{\varvec{f}} \right) \, \mathrm {d}A_{\varvec{\xi }} \\ {}&= \oint _{\partial \chi } \phi \widetilde{\varvec{f}} \varvec{\cdot }\hat{\varvec{n}} \; \mathrm {d}\sigma - \int _\chi \left( \nabla _{\varvec{\xi }} \phi \right) \varvec{\cdot } \widetilde{\varvec{f}} \, \mathrm {d}A_{\varvec{\xi }}, \end{aligned}$$

where \(\hat{\varvec{n}}\) is the outward unit normal on \(\partial \chi \) and the orientation of the closed curve \(\partial \chi \) is counter-clockwise. Using this, we obtain the weak formulation of Liouville’s equation on the reference domain

$$\begin{aligned} \int _{\chi } \phi \mathcal {J} \frac{\partial \rho }{\partial z} \, \mathrm {d}A_{\varvec{\xi }} + \oint _{\partial \chi } \phi \widetilde{\varvec{f}} \varvec{\cdot }\hat{\varvec{n}} \; \mathrm {d}\sigma - \int _\chi \left( \nabla _{\varvec{\xi }} \phi \right) \varvec{\cdot } \widetilde{\varvec{f}} \, \mathrm {d}A_{\varvec{\xi }} = 0. \end{aligned}$$
(29)

Note that for strong solutions we require the flux to be differentiable, hence, h(zqp) should be twice differentiable. However, the DGSEM uses the weak form of the solution and only requires the flux to be continuous, therefore, h(zqp) being once continuously differentiable is sufficient. For typical optical interfaces this is not sufficient since the refractive index field is discontinuous and, therefore, h(zqp) and also the flux are discontinuous. In particular, for these interfaces we require a special treatment of the fluxes which we will discuss in Sect. 4.

3.1 Tools for Approximating the Solution

The solution \(\rho \) in Eq. (29) is approximated by an expansion in basis functions [21]. We choose one-dimensional basis-functions \(\varphi _i\), \(i = 0, ..., N\), for which \(\varphi _i(\xi _j) = \delta _{ij}\) holds for chosen points \(\xi _j\). Moreover, we require that the basis-functions form an orthogonal basis with respect to the standard \(L^2\)-inner product. A suitable choice are the Lagrange polynomials defined on Gauss-Legendre nodes. In the following, we will replace \(\rho \) by the approximation

$$\begin{aligned} \rho (z, \xi , \eta ) \approx \rho ^\text {h}(z, \xi , \eta ) = \sum _{i,j=0}^N \rho _{ij}(z) \varphi _i(\xi ) \varphi _j(\eta ), \end{aligned}$$
(30)

where \(\rho _{ij}(z)\) are the expansion coefficients for the chosen basis. In this paper we will restrict ourselves to using the same basis functions in both directions with an equal number of expansion coefficients, although in general this restriction is not necessary.

The quadrature rule defined by Gauss-Legendre nodes \(\{ \xi _i \}_{i=0}^N\) and corresponding weights \(\{ w_i \}_{i=0}^N\) allows us to approximate the integral of any function g, i.e.,

$$\begin{aligned} \int _{-1}^1 g(\xi ) \, \mathrm {d}\xi \approx \sum _{i=0}^N g\left( \xi _i\right) w_i, \end{aligned}$$
(31)

with \(-1< \xi _i < 1\) and \(w_i > 0\). The quadrature rule on the reference domain has a tensor product structure, hence,

$$\begin{aligned} \int _{-1}^1 \int _{-1}^1 g(\xi , \eta ) \, \mathrm {d}\xi \mathrm {d}\eta \approx \sum _{i,j=0}^N g(\xi _i, \eta _j) w_i w_j. \end{aligned}$$
(32)

Thus, we place nodes inside the reference domain at the Gauss-Legendre nodes \((\xi _i, \eta _j)\). Furthermore, for one-dimensional integrals the Gauss-Legendre quadrature gives exact integration for at least all polynomials of degree \(2N + 1\).

Focusing on one dimension, the Lagrange polynomials on the Gauss-Legendre nodes read

$$\begin{aligned} \ell _i(\xi ) = \prod ^N_{\begin{array}{c} j=0 \\ j \ne i \end{array} } \frac{ \xi - \xi _j }{ \xi _i - \xi _j }, \end{aligned}$$
(33)

which satisfy the Kronecker property, i.e.,

$$\begin{aligned} \ell _i(\xi _j) = \delta _{ij} = {\left\{ \begin{array}{ll} 1 &{} \text { if } i = j, \\ 0 &{} \text { if } i \ne j. \end{array}\right. } \end{aligned}$$
(34)

It can be readily verified, that the Lagrange polynomials defined on the Gauss-Legendre nodes are orthogonal with respect to the standard \(L^2\)-inner product, i.e.,

$$\begin{aligned} \int _{-1}^1 \ell _i(\xi ) \ell _j(\xi ) \, \mathrm {d}\xi = \sum _{n = 0}^N \ell _i(\xi _n) \ell _j(\xi _n) w_n = \delta _{ij} w_i, \end{aligned}$$
(35)

where the integration is exact since \(\ell _i(\xi ) \ell _j(\xi )\) is a polynomial of degree at most 2N.

A very useful property of Lagrange polynomials is that the polynomial interpolation of any function g is rather easy, i.e.,

$$\begin{aligned} g_N(\xi ) = \left( \mathcal {I}_N g \right) (\xi ) = \sum _{j=0}^N \ell _j(\xi ) g(\xi _j), \end{aligned}$$
(36)

where \(\mathcal {I}_N\) is the polynomial interpolation operator using \(N + 1\) nodes. The approximation of the derivative of g is defined as the derivative of the interpolant, i.e.,

$$\begin{aligned} \frac{\mathrm {d} g_N}{\mathrm {d} \xi } (\xi ) = \sum _{j=0}^N \frac{\mathrm {d} \ell _j}{\mathrm {d} \xi } (\xi ) g(\xi _j). \end{aligned}$$
(37)

Note that if g is a polynomial of degree N or less, both the interpolant and the derivative are exact. In what follows, we require the derivative at the nodes, i.e.,

$$\begin{aligned} \frac{\mathrm {d} g_N}{\mathrm {d} \xi } (\xi _i) = \sum _{j=0}^N \frac{\mathrm {d} \ell _j}{\mathrm {d} \xi } (\xi _i) g(\xi _j) = \sum _{j=0}^N D_{ij} g(\xi _j), \end{aligned}$$
(38)

where \(D_{ij} = \frac{\mathrm {d} \ell _j}{\mathrm {d} \xi } (\xi _i)\). The elements of the differentiation matrix \(\varvec{D} = ( D_{ij} )\) can be found by differentiating the Lagrange polynomial followed by evaluation at the node, and thus read

$$\begin{aligned} D_{ij}&= \sum _{ \begin{array}{c} n = 0 \\ n \ne j \end{array} }^N \frac{1}{ \xi _j - \xi _n } \prod _{ \begin{array}{c} m = 0 \\ m \ne n, m \ne j \end{array} }^N \frac{ \xi _i - \xi _m }{ \xi _j - \xi _m } \quad \text {for } i \ne j, \end{aligned}$$
(39a)

and the diagonal elements read

$$\begin{aligned} D_{ii}&= -\sum _{ \begin{array}{c} n = 0 \\ n \ne i \end{array} }^N D_{in}, \end{aligned}$$
(39b)

due to the fact that the derivative of a constant function vanishes.

3.2 Approximating the Solution

To derive an approximation of the solution, we expand both the solution and the flux in Lagrange polynomials. The expansions read

$$\begin{aligned} \rho (z, \xi , \eta ) \approx \rho ^\text {h} (z, \xi , \eta )&= \sum _{i,j=0}^N \rho _{ij}(z) \ell _i(\xi ) \ell _j(\eta ), \end{aligned}$$
(40a)
$$\begin{aligned} \widetilde{\varvec{f}}(z, \xi , \eta ) \approx \widetilde{\varvec{f}}^\text {h} (z, \xi , \eta )&= \sum _{i,j=0}^N \widetilde{\varvec{f}}_{ij}(z) \ell _i(\xi ) \ell _j(\eta ). \end{aligned}$$
(40b)

The coefficients, indicated by the index-subscript ij, in each expansion are related to the position of an element’s interior node \((q_{ij}, p_{ij})\), by \(\rho _{ij}(z) = \rho (z, q_{ij}, p_{ij})\) and \(\widetilde{\varvec{f}}_{ij}(z) = \widetilde{\varvec{f}}(z, q_{ij}, p_{ij})\). The auxiliary flux coefficients \(\widetilde{\varvec{f}}_{ij}(z)\) are related to \(\rho \) by

$$\begin{aligned} \widetilde{\varvec{f}}_{ij}(z) := \widetilde{\varvec{u}}_{ij}(z) \rho _{ij}(z), \end{aligned}$$
(41)

with \(\widetilde{\varvec{u}}_{ij}\) the transformed velocity, similarly defined to (26). Here the velocity \(\widetilde{\varvec{u}}_{ij}(z) = \widetilde{\varvec{u}}(z, q_{ij}, p_{ij})\) depends on z if the refractive index n depends on z. In the following, we omit \(\widetilde{\varvec{f}}_{ij}\)’s dependence on z for ease of notation.

Next, we have to approximate the integrals in Eq. (29). The test function \(\phi \) is chosen to be in the same basis as the solution \(\rho \), resulting in a Galerkin method. Therefore, taking

$$\begin{aligned} \phi (\xi , \eta ) = \ell _i(\xi ) \ell _j(\eta ), \end{aligned}$$
(42)

allows us to derive \((N+1)^2\) equations for the \((N+1)^2\) coefficients \(\rho _{ij}\). Combining this together with the approximations (40a) and (40b) for \(\rho \) and \(\widetilde{\varvec{f}}\) we can approximate the integrals using the Gauss-Legendre quadrature rules. Therefore, substituting the approximation (40a) in the first term of (29), we obtain

$$\begin{aligned} \int _{\chi } \phi \mathcal {J} \frac{\partial \rho ^\text {h} }{\partial z} \, \mathrm {d}A_{\varvec{\xi }}&= \int _{\chi } \ell _i(\xi ) \ell _j(\eta ) \mathcal {J}(\xi , \eta ) \left( \sum _{k,l=0}^N \frac{\mathrm {d} \rho _{kl}(z)}{\mathrm {d} z} \ell _k(\xi ) \ell _l(\eta ) \right) \, \mathrm {d}A_{\varvec{\xi }} \\ {}&= \sum _{n,m=0}^N w_n w_m \ell _i(\xi _n) \ell _j(\eta _m) \mathcal {J}(\xi _n, \eta _m) \left( \sum _{k,l=0}^N \frac{\mathrm {d} \rho _{kl}(z)}{\mathrm {d} z} \ell _k(\xi _n) \ell _l(\eta _m) \right) .\end{aligned}$$

Applying the Kronecker property (34) of the Lagrange polynomials, the sums reduce to

$$\begin{aligned} \int _{\chi } \phi \mathcal {J} \frac{\partial \rho ^\text {h} }{\partial z} \, \mathrm {d}A_{\varvec{\xi }} = w_i w_j \mathcal {J}_{ij} \frac{\mathrm {d} \rho _{ij}(z)}{\mathrm {d} z},\end{aligned}$$
(43)

where \(\mathcal {J}_{ij} := \mathcal {J}(\xi _i, \eta _j)\). Note that the integral is exact for the given combination of a bilinear mapping \(\varvec{x}(\xi , \eta )\) and Lagrangian polynomials, since then the integrand is a polynomial of degree \(2N+1\) in \(\xi \) and in \(\eta \). The Gauss-Legendre quadrature rule is exact for this bivariate polynomial.

For the third term in (29), we substitute the approximation (40b) and denote \(\widetilde{\varvec{f}} = (\widetilde{f}, \widetilde{g})\), resulting in

$$\begin{aligned} \int _\chi \left( \nabla _{\varvec{\xi }} \phi \right) \varvec{\cdot } \widetilde{\varvec{f}}^\text {h} \, \mathrm {d}A_{\varvec{\xi }}&= \int _\chi \left( \ell _i'(\xi ) \ell _j(\eta ) \widetilde{f}(\xi , \eta ) + \ell _i(\xi ) \ell _j'(\eta ) \widetilde{g}(\xi , \eta ) \right) \, \mathrm {d}A_{\varvec{\xi }}\\&= \sum _{n,m=0}^N w_n w_m \left( \ell _i'(\xi _n) \ell _j(\eta _m) \widetilde{f}(\xi _n, \eta _m) + \ell _i(\xi _n) \ell _j'(\eta _m) \widetilde{g}(\xi _n, \eta _m) \right) \\&= w_j \sum _{n=0}^N w_n D_{ni} \widetilde{f}_{nj} + w_i \sum _{m=0}^N w_m D_{mj} \widetilde{g}_{im}, \end{aligned}$$

where we have used the definition of the differentiation matrix (39). Furthermore, we introduce the following auxiliary matrix

$$\begin{aligned} \widehat{D}_{ij} := D_{ji} \frac{w_j}{w_i}, \end{aligned}$$
(44)

for ease of computation. The third term then reads

$$\begin{aligned} \int _\chi \left( \nabla _{\varvec{\xi }} \phi \right) \varvec{\cdot } \widetilde{\varvec{f}}^\text {h} \, \mathrm {d}A_{\varvec{\xi }} = w_i w_j \left( \sum _{n=0}^N \widehat{D}_{in} \widetilde{f}_{nj} + \sum _{m=0}^N \widehat{D}_{jm} \widetilde{g}_{im} \right) . \end{aligned}$$
(45)

In what follows, we will replace the flux appearing in the boundary integral from Eq. (29) with a numerical flux \(\widetilde{\varvec{F}} = \left( \widetilde{F}, \widetilde{G} \right) \). The boundary integral can be split into four parts and evaluated for each boundary segment, see Fig. 2. Along each segment the numerical flux \(\widetilde{\varvec{F}}\) is described by an Nth degree polynomial at the boundary nodes shown in the figure. For the bottom part, with \(\eta = -1\), the integral can be exactly evaluated using Gauss-Legendre quadrature, such that we obtain

$$\begin{aligned} \int _{-1}^1 \ell _i(\xi ) \ell _j(-1) \widetilde{\varvec{F}}(\xi , -1) \varvec{\cdot } \left( -\hat{\varvec{\eta }} \right) \, \mathrm {d}\xi = -w_i \ell _j(-1) \widetilde{G} \left( \xi _i, -1 \right) . \end{aligned}$$
(46)

Similarly, we can compute the other components and the result for the full boundary integral reads

$$\begin{aligned} \begin{aligned} \oint _{\partial \chi } \phi \widetilde{\varvec{F}} \varvec{\cdot }\hat{\varvec{n}} \; \mathrm {d}\sigma =&w_j \left( \ell _i(1) \widetilde{F} \left( 1, \eta _j \right) - \ell _i(-1) \widetilde{F} \left( -1, \eta _j \right) \right) \\&+ w_i \left( \ell _j(1) \widetilde{G} \left( \xi _i, 1 \right) - \ell _j(-1) \widetilde{G} \left( \xi _i, -1 \right) \right) . \end{aligned} \end{aligned}$$
(47)

In the discontinuous Galerkin spectral element method the elements communicate by fluxes through the faces of each element. The solution on the boundary between two elements is allowed to be discontinuous, thus the limit towards the boundary of an element can have two values, one for each element it touches. The flux on the boundary must be replaced by a numerical flux so that the neighbouring elements can communicate. The numerical flux depends on the values of \(\rho \) just left and right of the boundary, i.e., \(\rho _\text {L}\) and \(\rho _\text {R}\), which are computed by evaluating the interior solution (40a) at the boundary. For the numerical flux we take the upwind flux. Due to the transformation (26) of the flux to the reference domain, the physical upwind flux F is scaled at an edge by \(\varDelta l / 2\) with \(\varDelta l\) the length of the edge, such that the upwind flux \(\widetilde{F} = \tfrac{1}{2} \varDelta l F\) over an edge reads

$$\begin{aligned} \widetilde{F} = \frac{\varDelta l}{2} \left( \varvec{u} \varvec{\cdot }\hat{\varvec{n}} \right) {\left\{ \begin{array}{ll} \rho _\text {L} \quad &{}{} \text{ if } \varvec{u} \varvec{\cdot }\hat{\varvec{n}} \ge 0, \\ \rho _\text {R} \quad &{}{} \text{ if } \varvec{u} \varvec{\cdot }\hat{\varvec{n}} < 0, \end{array}\right. } \end{aligned}$$
(48)

where \(\hat{\varvec{n}}\) denotes the outward normal vector w.r.t. the element left of the boundary.

Fig. 2
figure 2

Reference square with polynomial degree \(N = 4\). The normals are denoted by arrows, interior nodes are denoted by filled circles and boundary points by open squares

Next, we substitute expressions (43), (45) and (47) in equation (29), so that we obtain the semi-discrete ODE system for the expansion coefficients \(\rho _{ij}(z)\):

$$\begin{aligned} \begin{aligned}&\mathcal {J}_{ij} \frac{\mathrm {d} \rho _{ij}(z)}{\mathrm {d} z} = \sum _{n=0}^N \widehat{D}_{in} \widetilde{f}_{nj} + \sum _{m=0}^N \widehat{D}_{jm} \widetilde{g}_{im}\\&\quad - \left[ \frac{\ell _i(1)}{w_i} \widetilde{F}(1, \eta _j) - \frac{\ell _i(-1)}{w_i} \widetilde{F}(-1, \eta _j) + \frac{\ell _j(1)}{w_j} \widetilde{G}(\xi _i, 1) - \frac{\ell _j(-1)}{w_j} \widetilde{G}(\xi _i, -1) \right] , \end{aligned} \end{aligned}$$
(49)

with the numerical fluxes \(\widetilde{\varvec{F}} = \big ( \widetilde{F}, \widetilde{G} \big )\) given by (48). This ODE system can be solved using any numerical time integrator, e.g., the classical fourth order Runge–Kutta method. Other popular choices in the literature are explicit low-storage Runge-Kutta methods, see [6, 19, 34].

The discontinuous Galerkin spectral element method approximates the exact solution by an Nth degree polynomial, so the global spatial error e for a typical mesh size \(\varDelta x\) behaves as

$$\begin{aligned} e = \mathcal {O}(\varDelta x^{N+1}). \end{aligned}$$
(50)

Furthermore, the scheme is restricted by stability in terms of a CFL condition. For discontinuous Galerkin methods on quadrilaterals there is no direct known bound for the CFL condition. For triangular grids the relation between the Courant number and the shape of the triangles is studied in [7, 30].

4 Optical Interfaces

In the phase space representation, the flow of \(\rho \) describes a beam of light propagating through an optical system. When the beam hits an optical interface, the momentum p changes discontinuously according to the law of specular reflection or Snell’s law of refraction. Furthermore, from the discussion in Sect. 2 we know that the total luminous flux should remain constant throughout the optical system. The numerical solution should respect the actual physics, therefore, the discontinuity at optical interfaces coupled with conservation of energy should be incorporated into the DGSEM when we solve Liouville’s equation.

In the DGSEM the solution is allowed to be discontinuous across the boundary connecting two or multiple elements. Therefore, the mesh in phase space is aligned such that elements adjacent to the interface have edges that coincide with the optical interface, across which the solution is discontinuous [31]. The elements in the DGSEM communicate through numerical fluxes, hence, we have to incorporate both Snell’s law and the energy conservation constraint in the numerical flux when integrating (49). In particular, for a beam of light moving towards an optical interface, i.e., the velocity is directed towards the interface, we have to leave \(\rho \) free, whilst for a beam moving away from an optical interface, i.e., the velocity is directed away from the interface, we have a Dirichlet boundary condition for \(\rho \) due to Snell’s law or the law of specular reflection [31].

Refraction or reflection causes the elements to be connected in a non-trivial manner at the optical interface. For example, one single element, on the side where light is moving towards the interface, can contribute to multiple elements on the other side. This occurs because both Snell’s law and the law of reflection are non-linear in the momentum p. Therefore, this requires special treatment of the numerical fluxes to ensure that the scheme obeys energy conservation.

Van Lith et al. present Snell’s function in [33], which is an explicit version of Snell’s law and the law of specular reflection combined on phase space. Snell’s function \(\mathcal {S}\) relates the momentum p of an incident ray to the outgoing momentum \(\bar{p}\) of the ray. Let \(n_1\) be the refractive index of the incident medium and \(n_2\) the index of the transmitted medium. Then for a generic two-dimensional optical interface in the (qz)-plane with surface unit normal \({\mathbf {\nu }} = ({{\nu }_q}, {{\nu }_z})\) directed towards the incident medium, Snell’s function reads

$$\begin{aligned}&\bar{p} = \mathcal {S}(p; n_1, n_2, \mathbf {\nu }) := {\left\{ \begin{array}{ll} p - (\psi + {{\,\mathrm{sgn}\,}}(n_2) \sqrt{\delta }) {{\nu }_q} \quad &{} \text {if } \delta \ge 0, \\ p - 2 \psi {{\nu }_q} \quad &{} \text {if } \delta < 0, \end{array}\right. } \end{aligned}$$
(51a)

with the auxiliary variables \(\delta \) and \(\psi \) defined by

$$\begin{aligned}&\delta := n_2^2 - n_1^2 + \psi ^2, \quad \psi := \begin{pmatrix} p \\ \pm \sqrt{n_1^2 - p^2} \end{pmatrix} \varvec{\cdot }\begin{pmatrix} {{\nu }_q} \\ {{\nu }_z} \end{pmatrix}. \end{aligned}$$
(51b)

In the expression for \(\psi \) the plus sign should be taken for rays that propagate in the positive z-direction, while the minus sign should be taken for rays that propagate in the negative z-direction. Furthermore, the sign of \(n_2\), i.e., \({{\,\mathrm{sgn}\,}}(n_2)\), in the first case of (51a) can be used to accommodate embedded mirrors in a medium of refractive index \(n_1 \ge 1\) by taking \(n_2 = -n_1\), see [32]. Note that there is a so-called critical momentum \(p_\text {c}\) when \(n_1 \ge n_2\) so that \(\delta = 0\). For \(\delta < 0\) all light will be reflected, referred to as total internal reflection (TIR), while for \(\delta \ge 0\) light will be refracted. The outgoing momentum is computed as \(\bar{p} = \mathcal {S}(p; n_1, n_2, \mathbf {\nu })\), for which we will frequently use the shorthand notation \(\bar{p} = \mathcal {S}(p)\) and take the other parameters as given. Furthermore, the inverse of Snell’s function will also be frequently used, for which we will use the shorthand notation \(p = \mathcal {S}^{-1}(\bar{p})\). This means, find the momentum p such that \(\bar{p} = \mathcal {S}(p)\). For example, for refraction the inverse reads [33]

$$\begin{aligned} p = \mathcal {S}^{-1}(\bar{p}) = -\mathcal {S}\left( -\bar{p}; n_2, n_1, -\mathbf {\nu } \right) . \end{aligned}$$
(52)

Snell’s function (51) combined with (12) results in [33]

$$\begin{aligned} \rho \left( z^-, q^-, p^-\right) = \rho \left( z^+, q^+, p^+\right) , \end{aligned}$$
(53)

where \(p^+ = \mathcal {S}(p^-; n_1, n_2, \mathbf {\nu })\) and the ± denote one-sided limits towards the optical interface. This relation allows us to relate the basic luminance \(\rho \) on both sides of the interface.

To elaborate the energy conservation constraint, we consider the following flat optical interface parallel to the z-axis

$$\begin{aligned} n(q) = {\left\{ \begin{array}{ll} n_1 \quad &{} \text {for } q \le q_0, \\ n_2 \quad &{} \text {for } q > q_0. \end{array}\right. } \end{aligned}$$
(54)

Note that the optical interface in phase space is represented by a line parallel to the p-axis. The optical interface has two sides where on one side the normal in phase space is directed towards \(q < q_0\) and describes the part with refractive index \(n_1\), whereas on the other side the normal is directed towards \(q > q_0\) and describes the part with refractive index \(n_2\). The normal in phase space is given by \(\hat{\varvec{n}} = ( \pm 1, 0 )\) with the plus sign for the direction towards \(q > q_0\). Since the optical interface is represented by a line parallel to the p-axis at some constant q-value, only the q-component of the flux (20b) needs to be considered, i.e.,

$$\begin{aligned} f(z, q, p) = \rho (z, q, p) \frac{p}{ \sqrt{n(z, q)^2 - p^2} }, \end{aligned}$$
(55)

cf. (22).

In what follows, we assume that light is initially in the medium with refractive index \(n_1\). We partition the optical interface, represented in phase space, into line segments for both sides of the optical interface. The partitioning is based on whether light is moving towards or away from the optical interface.

The line segment on the side of the optical interface with velocity directed towards the optical interface is denoted L. The line segment L describes the incoming momentum of light from the medium with refractive index \(n_1\), due to the assumption of light being initially in this medium.

The line segments just on the optical interface with velocity directed away from the optical interface is denoted R. The line segments R describe the outgoing momentum of light, and is further split into two parts, i.e., \(R = R_\text {R} \cup R_\text {T}\). The line segment denoted \(R_\text {R}\) represents the momentum of light after total internal reflection, and is part of the optical interface where the refractive index is \(n_1\), while the line segment denoted \(R_\text {T}\) is in the medium with refractive index \(n_2\), and represents the momentum after transmission.

To distinguish the momentum taken from either side of the optical interface, we write \(p \in L\) and \(\bar{p} \in R\). First, consider the integral of the flux entering an arbitrary momentum interval \([\bar{p}_1, \bar{p}_2] \subseteq R_\text {T}\). The integral reads

$$\begin{aligned} \int _{\bar{p}_1}^{\bar{p}_2} \rho (z^+, q_0^+, \bar{p}) \frac{\bar{p}}{ \sqrt{n_2^2 - \bar{p}^2} } \, \mathrm {d}\bar{p}, \end{aligned}$$
(56)

where \(q_0^+\) denotes the limit towards the optical interface from the line segment \(R_\text {T}\). Relation (53) implies

$$\begin{aligned} \int _{\bar{p}_1}^{\bar{p}_2} \rho \left( z^+, q_0^+, \bar{p}\right) \frac{\bar{p}}{ \sqrt{n_2^2 - \bar{p}^2} } \, \mathrm {d}\bar{p} = \int _{\bar{p}_1}^{\bar{p}_2} \rho \left( z^-, q_0^-, \mathcal {S}^{-1}(\bar{p}) \right) \frac{\bar{p}}{ \sqrt{n_2^2 - \bar{p}^2} } \, \mathrm {d}\bar{p}, \end{aligned}$$
(57)

where \(q_0^-\) denotes the limit towards the optical interface from the line segment L. Subsequently, we transform the integral using \(\bar{p} = \mathcal {S}(p) = \mathcal {S}(p; n_1, n_2, \mathbf {\nu })\) resulting in

$$\begin{aligned} \int _{\bar{p}_1}^{\bar{p}_2} \rho \left( z^+, q_0^+, \bar{p}\right) \frac{\bar{p}}{ \sqrt{n_2^2 - \bar{p}^2} } \, \mathrm {d}\bar{p} = \int _{p_1}^{p_2} \rho \left( z^-, q_0^-, p \right) \frac{ \mathcal {S}(p) }{ \sqrt{n_2^2 - \mathcal {S}(p)^2} } \frac{\mathrm {d} \mathcal {S}(p)}{\mathrm {d} p} \, \mathrm {d}p, \end{aligned}$$
(58)

where \(\bar{p}_i = \mathcal {S}(p_i)\) for \(i = 1, 2\), and \([p_1, p_2] \subseteq L\).

The relation for reflection can be derived similarly by considering the integral of the flux entering an arbitrary momentum interval \([\bar{p}_3, \bar{p}_4] \subseteq R_\text {R}\). We obtain the relation

$$\begin{aligned} \int _{\bar{p}_3}^{\bar{p}_4} \rho \left( z^+, q_0^+, \bar{p}\right) \frac{\bar{p}}{ \sqrt{n_1^2 - \bar{p}^2} } \, \mathrm {d}\bar{p} = \int _{p_3}^{p_4} \rho \left( z^-, q_0^-, p \right) \frac{ \mathcal {S}(p) }{ \sqrt{n_1^2 - \mathcal {S}(p)^2} } \frac{\mathrm {d} \mathcal {S}(p)}{\mathrm {d} p} \, \mathrm {d}p, \end{aligned}$$
(59)

with \(\bar{p}_i = \mathcal {S}(p_i)\) for \(i = 3, 4\), and \([p_3, p_4] \subseteq L\). The relations (58) and (59) describe how the fluxes leaving L are related to the fluxes entering \(R_\text {T}\) or \(R_\text {R}\), respectively. Henceforth, they are known as energy conservation constraints.

For the particular optical interface (54) the constraints can be simplified. Since, we assumed that light was initially in the medium with refractive index \(n_1\), the optical interface normal on the full position space is equal to \(\mathbf {\nu } = ({{\nu }_q}, {{\nu }_z}) = (-1, 0)\). Snell’s function (51) reduces for this flat interface to

$$\begin{aligned} \bar{p} = \mathcal {S}(p; n_1, n_2, \mathbf {\nu }) = {\left\{ \begin{array}{ll} \sqrt{n_2^2 - n_1^2 + p^2} \quad &{}{} \text{ if } p \ge p_\text {c} , \\ -p \quad &{}{} \text{ if } p < p_\text {c} , \end{array}\right. } \end{aligned}$$
(60)

with \(p_\text {c} = \sqrt{n_1^2 - n_2^2}\). Then, the energy conservation constraint for \(R_\text {T}\), given by (58), can be simplified by noting that for refraction the following relations hold

$$\begin{aligned} \frac{\mathrm {d} \mathcal {S}(p)}{\mathrm {d} p} = \frac{p}{\mathcal {S}(p)}, \quad \sqrt{n_2^2 - \mathcal {S}(p)^2} = \sqrt{n_1^2 - p^2}. \end{aligned}$$

Hence, we obtain

$$\begin{aligned} \int _{\bar{p}_1}^{\bar{p}_2} \rho \left( z^+, q_0^+, \bar{p}\right) \frac{\bar{p}}{ \sqrt{n_2^2 - \bar{p}^2} } \, \mathrm {d}\bar{p} = \int _{p_1}^{p_2} \rho \left( z^-, q_0^-, p \right) \frac{ p }{ \sqrt{n_1^2 - p^2} } \, \mathrm {d}p, \end{aligned}$$
(61a)

and similarly for reflection the constraint for \(R_\text {R}\), given by (59), reduces to

$$\begin{aligned} \int _{\bar{p}_3}^{\bar{p}_4} \rho \left( z^+, q_0^+, \bar{p}\right) \frac{\bar{p}}{ \sqrt{n_1^2 - \bar{p}^2} } \, \mathrm {d}\bar{p} = \int _{p_3}^{p_4} \rho \left( z^-, q_0^-, p \right) \frac{ p }{ \sqrt{n_1^2 - p^2} } \, \mathrm {d}p. \end{aligned}$$
(61b)

The balances (61) have to be combined with relation (53) to ensure the scheme conserves energy. However, the coupling between the line segments L and R is not straightforward, which will be discussed in the next section.

Fig. 3
figure 3

Conservative handling of fluxes. The incident and transmitted momenta are related by \(\bar{p} = \mathcal {S}(p)\)

4.1 Conservative Handling of Fluxes

First, consider only the refractive part of the optical interface. Elements adjacent to the optical interface in phase space are shown in Fig. 3a. These elements have edges on the optical interface and these edges are denoted by \(L_i\) (\(i = 1, 2\)) and \(R_j\) (\(j = 1, 2, 3, 4\)). Due to refraction, the value of \(\rho \) in the elements that contain \(R_j\) as an edge is determined by the flow through the elements that contain \(L_1\) and \(L_2\). In fact, taking a closer look at how Snell’s function connects the line segments from L to R in momentum space at the optical interface, we obtain for example Fig. 3b. In Fig. 3b \(L_i\) and \(R_j\) denote line segments along the optical interface. The basic luminance \(\rho \) along the line segments \(L_i\) and \(R_j\) are represented by their inner-element solution evaluated at the optical interface. To simplify notation, we denote these polynomials along the optical interface by \(\rho ^{L_i}(p)\) with \(i = 1, 2\) and \(\rho ^{R_j}(p)\) with \(j = 1, 2, 3, 4\). For example:

$$\begin{aligned} \rho ^{L_i}(p) = \sum _{j=0}^N \rho _j^{L_i} \ell _j(\zeta (p)), \end{aligned}$$
(62)

where \(\zeta = \zeta (p)\) denotes the line segment’s local reference coordinate along the interface.

In Fig. 3b also virtual line segments \(\bar{L}_i\) are shown. The virtual line segment \(\bar{L}_i\) is the image of \(L_i\) under \(\mathcal {S}\), i.e.,

$$\begin{aligned} \bar{L}_i = \mathcal {S} \left( L_i \right) . \end{aligned}$$
(63)

Hence, the endpoints of these line segments are found applying Snell’s function to the endpoints of \(L_i\), i.e., \(\bar{p}_i^L = \mathcal {S}(p_i^L)\). Note that due to Snell’s function, the line segments \(L_i\) are stretched or compressed in the momentum direction. Computing the endpoints \(\bar{p}_i^L\) allows us to determine which line segments before the optical interface contribute to a single line segment after the optical interface. From the figure we see that part of \(L_1\) contributes to \(R_2\) (the blue coloured region). Therefore, a relation connecting \(\rho ^{L_1}(p)\) and \(\rho ^{R_2}(p)\) on opposite sides of the optical interface must be found. Hence, as a first step applying relation (53) to a polynomial on \(L_i\), allows us to find the corresponding \(\rho \) on \(\bar{L}_i\), i.e.,

$$\begin{aligned} \rho ^{L_i}( p ) = \rho ^{L_i}\left( \mathcal {S}^{-1}(\bar{p}) \right) = \rho ^{\bar{L}_i}( \bar{p} ), \end{aligned}$$
(64)

with \(\bar{p} = \mathcal {S}(p)\).

The coupling between line segments that do not exactly match, as shown in Fig. 3b, is similar to what is known as a geometrically non-conforming mesh [20, 23]. In [23] the authors describe a discontinuous Galerkin method for non-conforming meshes, applied to Maxwell’s equations that form a hyperbolic system of PDEs. In their approach to treating non-conforming interfaces the solutions are first transferred to an intermediate construct called a ‘mortar’, and on this mortar the numerical fluxes are computed and transferred back to the corresponding elements. The transfer of the solutions and numerical fluxes is done using a least-squares matching, with integrals evaluated using Gauss-Legendre quadrature [5].

We will take a slightly different approach since in Liouville’s equation for optics the flux \(\varvec{f}\) is discontinuous across an optical interface. Instead, relation (53) and Snell’s function together describe how \(\rho \) transforms across an optical interface, cf. (64), therefore, a least-squares matching of the polynomials describing \(\rho \) along either side of the interface is used with Snell’s function directly incorporated and an additional constraint is used to satisfy energy conservation.

For the reflective part of a flat interface that is parallel to the z-axis, Snell’s function reduces to \(\bar{p} = -p\), see (60). The conservative treatment of these types of optical interfaces is easily accommodated by choosing a mesh such that the elements and nodes are symmetric with respect to the line \(p = 0\) and, therefore, the constraint (61b) is easily satisfied. Due to this choice of mesh each node \(\bar{p}_j \in R_\text {R}\) will exactly correspond to \(-\bar{p}_j = p_j \in L\) and a point-by-point transfer of \(\rho \) can be made. Henceforth, the following exposition of the method describes the method considering only refraction.

4.2 Contribution from One Element

From Fig. 3b we see that the line segment \(R_2\) only depends on the solution in \(L_1\). The polynomial \(\rho ^{R_2}\) must thus be computed from the polynomial \(\rho ^{L_1}\) with the additional constraint of energy conservation. That is, the integral of the flux within the blue interval on either side of the optical interface should be equal analogous to equation (61a). Therefore, the constrained least-squares approximation reads

$$\begin{aligned}&\min _{\rho ^{R_2} \in \mathbb {P}_N} \quad \int _{\bar{p}_2^R}^{\bar{p}_3^R} \left[ \rho ^{R_2}( \bar{p} ) - \rho ^{\bar{L}_1}( \bar{p} ) \right] ^2 \, \mathrm {d}\bar{p}, \end{aligned}$$
(65a)
$$\begin{aligned}&\text {subject to} \quad \int _{\bar{p}_2^R}^{\bar{p}_3^R} F^{R_2}( \bar{p} ) \mathrm {d}\bar{p} = \int _{p_2^R}^{p_3^R} F^{L_1}(p) \, \mathrm {d}p. \end{aligned}$$
(65b)

Here, \([p_2^R, p_3^R] \subseteq L_1 = [p_1^L, p_2^L]\) and the momenta on both sides are related by \(p_i^R := \mathcal {S}^{-1}(\bar{p}_i^R)\), see Fig. 3b. Furthermore, the numerical fluxes are defined as expansions in the Lagrange polynomial basis on Gauss-Legendre nodes, similar to (62), with flux coefficients \(F_j := u_j \rho _j\). The minimisation of the integral in (65a) requires finding a polynomial that matches in the least-squares sense, while the constraint (65b) ensures that the scheme conserves energy.

The integrals in the constrained minimisation problem (65) are transformed to reference line segments, so that we can compute the integrals using Gauss-Legendre quadrature. To be more specific, the integral on the LHS of (65b) and the integral in (65a) are transformed to the reference line segment along \(R_2\), while the integral on the RHS of (65b) is transformed to the reference line segment along \(L_1\). Omitting the element’s subscripts, applying relation (64) and introducing an auxiliary function \(\varXi \) for ease of notation, we obtain

$$\begin{aligned} \begin{aligned} \min _{\rho ^R \in \mathbb {P}_N}&\quad \int _{-1}^{1} \left[ \rho ^R( \zeta ) - \rho ^{L}( \varXi (\zeta ) ) \right] ^2 \, \mathrm {d}\zeta , \\ \text {subject to}&\quad \varDelta \bar{p}^R \int _{-1}^{1} F^R(\zeta ) \mathrm {d}\zeta = \varDelta p^L \int _{\sigma ^L}^{\sigma ^L + \lambda ^L} F^L(\zeta ) \, \mathrm {d}\zeta , \end{aligned} \end{aligned}$$
(66)

where \(\varDelta \bar{p}^R := \bar{p}_3^R - \bar{p}_2^R\) and \(\varDelta p^L := p_2^L - p_1^L\). Furthermore, the coefficients \(\sigma ^L \in [-1, 1]\) and \(\lambda ^L \in [0, 2]\) denote the offset and scaling in \(L_1\)’s reference frame, such that \(p(\sigma ^L) = p_2^R\) and \(p(\sigma ^L + \lambda ^L) = p_3^R\) in \(L_1\). Finally, the auxiliary function \(\varXi \) reads

$$\begin{aligned} \varXi \left( \zeta ; p^L, \varDelta p^L, \bar{p}^R, \varDelta \bar{p}^R\right) = 2 \frac{ \mathcal {S}^{-1}\left( \bar{p}^R + \tfrac{1}{2} \varDelta \bar{p}^R (1 + \zeta ) \right) - p^L }{ \varDelta p^L } - 1. \end{aligned}$$
(67)

This function relates the reference frame coordinates for a momentum interval \([\bar{p}^R, \bar{p}^R + \varDelta \bar{p}^R]\) past the optical interface to the reference frame coordinates on a momentum interval \([p^L, p^L + \varDelta p^L]\) before the optical interface.

Next, we write the constrained minimisation problem (66) in terms of a Lagrange function \(\mathcal {L}\) with a Lagrange multiplier \(\mu \) for the energy conservation constraint, i.e.,

$$\begin{aligned} \begin{aligned} \mathcal {L}&= \frac{1}{2} \int _{-1}^{1} \left[ \rho ^R( \zeta ) - \rho ^{L}( \varXi (\zeta ) ) \right] ^2 \, \mathrm {d}\zeta \\&\quad + \mu \left[ \varDelta \bar{p}^R \int _{-1}^{1} F^R(\zeta ) \, \mathrm {d}\zeta - \varDelta p^L \int _{\sigma ^L}^{\sigma ^L + \lambda ^L} F^L(\zeta ) \, \mathrm {d}\zeta \right] . \end{aligned} \end{aligned}$$
(68)

The coefficients \(\rho ^R_j\) for the polynomial \(\rho ^R \in \mathbb {P}_N\) can then be computed by solving

$$\begin{aligned} \frac{\partial \mathcal {L}}{\partial \rho ^R_i}&= 0, \quad \text {for } i = 0, 1, ..., N, \end{aligned}$$
(69a)
$$\begin{aligned} \frac{\partial \mathcal {L}}{\partial \mu }&= 0. \end{aligned}$$
(69b)

Recalling that both \(F^L\) and \(F^R\) are written as expansions in the Lagrange polynomial basis on Gauss-Legendre nodes, we obtain for the energy conservation constraint (69b)

$$\begin{aligned} \varDelta \bar{p}^R \int _{-1}^{1} \sum _{j=0}^N u_j^R \rho _j^R \ell _j(\zeta ) \, \mathrm {d}\zeta = \varDelta p^L \int _{\sigma ^L}^{\sigma ^L + \lambda ^L} \sum _{j=0}^N u_j^L \rho _j^L \ell _j(\zeta ) \, \mathrm {d}\zeta , \end{aligned}$$
(70)

where we have used \(F_j = u_j \rho _j\).

To evaluate the second integral, we transform it to the reference interval \([-1, 1]\) using \(\zeta (\xi ) = \sigma ^L + \frac{1}{2} \lambda ^L \left( 1 + \xi \right) \). Next, we replace both integrals with Gauss-Legendre quadrature to find the exact values, since both integrands are at most Nth degree polynomials, therefore we obtain

$$\begin{aligned} \varDelta \bar{p}^R \sum _{j=0}^N w_j u_j^R \rho _j^R = \varDelta p^L \frac{\lambda ^L}{2} \sum _{j=0}^N u_j^L \rho _j^L \sum _{k=0}^N w_k \ell _j \left( \sigma ^L + \frac{1}{2} \lambda ^L \left( 1 + \xi _k \right) \right) , \end{aligned}$$
(71)

with \(\xi _k\) and \(w_k\) the Gauss-Legendre nodes and weights, respectively.

Recalling again that the polynomials \(\rho ^L\) and \(\rho ^R\) are written as an expansion in a Lagrange polynomial basis, cf. (62), we can rewrite the equations (69a) to

$$\begin{aligned} 0 = \int _{-1}^{1} \left[ \rho ^R( \zeta ) - \rho ^{L}( \varXi (\zeta ) ) \right] \ell _i(\zeta ) \, \mathrm {d}\zeta + \mu \varDelta \bar{p}^R \int _{-1}^{1} u_i^R \ell _i(\zeta ) \, \mathrm {d}\zeta , \quad \text {for } i = 0, 1, ..., N. \end{aligned}$$
(72)

For the evaluation of the first integral, we introduce a generic auxiliary variable \(S_{ij}\), given by

$$\begin{aligned} S_{ij}\left( \sigma ^R, \lambda ^R \right) := \int _{ \sigma ^R }^{ \sigma ^R + \lambda ^R } \ell _i(\zeta ) \ell _j( \varXi (\zeta ) ) \, \mathrm {d}\zeta , \end{aligned}$$
(73)

with \(\varXi \) defined in (67). The integral is evaluated by transforming to the reference interval and subsequently applying Gauss-Legendre quadrature. The integration interval \([\sigma ^R, \sigma ^R + \lambda ^R]\) of \(S_{ij}\) depends on how large \(R_j\) is compared to \(\bar{L}_i\). In this case, the entire line segment \(R_2\) fits in \(\bar{L}_1\), therefore, the integral over \(R_2\) is transformed to a reference line segment \([-1, +1]\), corresponding to \(\sigma ^R = -1\) and \(\lambda ^R = 2\).

The integrals in (72) are evaluated using Gauss-Legendre quadrature resulting in

$$\begin{aligned} \sum _{j=0}^N M_{ij} \rho _j^R + \mu \varDelta \bar{p}^R u_i^R w_i = \sum _{j=0}^N S_{ij}\left( -1, 2 \right) \rho _j^L, \quad \text {for } i = 0, 1, ..., N, \end{aligned}$$
(74a)

with

$$\begin{aligned} M_{ij} = \int _{-1}^{1} \ell _i(\zeta ) \ell _j(\zeta ) \, \mathrm {d}\zeta , \end{aligned}$$
(74b)

and \(S_{ij}\) given by (73). The integral \(M_{ij}\) describes the orthogonality of the Lagrange polynomials on Gauss-Legendre nodes, and therefore, is easily evaluated, cf. (35), to be

$$\begin{aligned} M_{ij} = w_i \delta _{ij}. \end{aligned}$$
(75)

The coefficients \(M_{ij}\) and \(S_{ij}\) are elements of the matrices \(\varvec{M}, \varvec{S} \in \mathbb {R}^{(N+1) \times (N+1)}\). The matrix \(\varvec{M}\) is simply a diagonal matrix containing the Gauss-Legendre quadrature weights, i.e., \(\varvec{M} = {{\,\mathrm{diag}\,}}( \varvec{w} )\) with \(\varvec{w} = (w_0, w_1, ..., w_N)^\text {T}\).

By defining

$$\begin{aligned} \alpha _j^R := \varDelta \bar{p}^R u_j^R, \quad \beta _j^L := \varDelta p^L \frac{\lambda ^L}{2} u_j^L \sum _{k=0}^N w_k \ell _j \left( \sigma ^L + \frac{1}{2} \lambda ^L \left( 1 + \xi _k \right) \right) , \end{aligned}$$
(76)

as the components of the vectors \(\varvec{\alpha }^R\) and \(\varvec{\beta }^L\), we can write the linear system given by (74) and (71) for \(\varvec{\rho }^R = (\rho _0^R, \rho _1^R, ..., \rho _N^R)^\text {T}\) and \(\mu \) compactly in matrix-vector form:

$$\begin{aligned} \begin{pmatrix} {{\,\mathrm {diag}\,}}\left( \varvec{w} \right) &{} {} \varvec{\alpha }^R \circ \varvec{w} \\ \left( \varvec{\alpha }^R \circ \varvec{w} \right) ^\text {T} &{}{} \qquad \,\,\, 0 \end{pmatrix} \begin{pmatrix} \varvec{\rho }^R \\ \mu \end{pmatrix} = \begin{pmatrix} \varvec{S} \\ \left( \varvec{\beta }^L \right) ^\text {T} \end{pmatrix} \varvec{\rho }^L , \end{aligned}$$
(77)

where we take the arguments for \(\varvec{S}\) as understood. Furthermore, \(\circ \) denotes the Hadamard product for vectors \(\varvec{a} = \left( a_0, a_1, ..., a_N \right) ^\text {T}\) and \(\varvec{b} = \left( b_0, b_1, ..., b_N \right) ^\text {T}\), i.e., \(\varvec{a} \circ \varvec{b} = \left( a_0 b_0, a_1 b_1, ..., a_N b_N \right) ^\text {T}\). Let us denote the matrix on the LHS by \(\varvec{A}\):

$$\begin{aligned} \varvec{A} := \begin{pmatrix} {{\,\mathrm {diag}\,}}\left( \varvec{w} \right) &{} {} \varvec{\alpha }^R \circ \varvec{w} \\ \left( \varvec{\alpha }^R \circ \varvec{w} \right) ^\text {T} &{}{}\qquad \,\,\, 0 \end{pmatrix} . \end{aligned}$$
(78)

The determinant of this matrix reads

$$\begin{aligned} \det (\varvec{A}) = -\left( \sum _{i=0}^N \left( \alpha _i^R \right) ^2 w_i \right) \prod _{i=0}^N w_i, \end{aligned}$$
(79)

see Appendix A for details. Therefore, the matrix is only singular if all coefficients \(\alpha _i^R = 0\), or equivalent if all velocities \(u_i = 0\), which would mean no flux can enter the element from that side. Hence, we can safely assume that the matrix \(\varvec{A}\) is regular.

An analytical inverse for the matrix \(\varvec{A}\) is derived in Appendix A, and reads

$$\begin{aligned} \varvec{A}^{-1} = \frac{1}{r} \begin{pmatrix} \varvec{B} &{}{} -\varvec{\alpha }^R \\ \left( -\varvec{\alpha }^R \right) ^\text {T} &{}{} 1 \end{pmatrix} , \quad r := -\sum _{i=0}^N \left( \alpha _i^R \right) ^2 w_i, \end{aligned}$$
(80)

where the coefficients of the matrix \(\varvec{B}\) read

$$\begin{aligned} B_{ij} := {\left\{ \begin{array}{ll} \left( \alpha _i^R \right) ^2 + \frac{r}{w_i} \quad &{} \text {if } i = j, \\ \alpha _i^R \alpha _j^R \quad &{} \text {if } i \ne j. \end{array}\right. } \end{aligned}$$
(81)

Now, we can directly obtain an expression for the Dirichlet boundary condition values \(\varvec{\rho }^R\) in terms of \(\varvec{\rho }^L\), i.e.,

$$\begin{aligned} \varvec{\rho }^R = \frac{1}{r} \begin{pmatrix} \varvec{B}&\; -\varvec{\alpha }^R \end{pmatrix} \begin{pmatrix} \varvec{S} \\ \left( \varvec{\beta }^L \right) ^\text {T} \end{pmatrix} \varvec{\rho }^L =: \varvec{C} \varvec{\rho }^L. \end{aligned}$$
(82)

Note that for problems where the refractive index n does not depend on z, the coefficient matrix \(\varvec{C}\) relating \(\varvec{\rho }^R\) and \(\varvec{\rho }^L\) can be pre-computed and re-used during integration along the z-axis.

4.3 Contributions from Multiple Elements

From Fig. 3b we see that the element \(R_3\) depends on both \(\bar{L}_1\) and \(\bar{L}_2\). The idea remains the same, i.e., to use a least-squares matching with a constraint to ensure that the scheme is energy conservative. The constrained least-squares problem for \(R_3\) reads

$$\begin{aligned} \min _{\rho ^{R_3} \in \mathbb {P}_N}&\quad \int _{\bar{p}_3^R}^{\bar{p}_4^R} \left[ \rho ^{R_3}( \bar{p} ) - \rho ^{\bar{L}}( \bar{p} ) \right] ^2 \, \mathrm {d}\bar{p}, \end{aligned}$$
(83a)
$$\begin{aligned} \text {subject to}&\quad \int _{\bar{p}_3^R}^{\bar{p}_4^R} F^{R_3}( \bar{p} ) \, \mathrm {d}\bar{p} = \int _{p_3^R}^{p_{34}^R} F^{L_1}(p) \, \mathrm {d}p + \int _{p_{34}^R}^{p_4^R} F^{L_2}(p) \, \mathrm {d}p, \end{aligned}$$
(83b)

where \(p_{34}^R := \mathcal {S}^{-1}(\bar{p}_{34}^R)\) and \(\bar{p}_{34}^R\) is the momentum value where the intervals \(\bar{L}_1\) and \(\bar{L}_2\) meet, see Fig. 3b. Furthermore, \(\rho ^{\bar{L}}\) contains the contributions from \(\rho ^{L_1}\) and \(\rho ^{L_2}\), and is defined by

$$\begin{aligned} \rho ^{\bar{L}}(\bar{p}) := {\left\{ \begin{array}{ll} \rho ^{L_1}( \mathcal {S}^{-1}(\bar{p}) ) \quad &{} \text {for } \bar{p}_3^R \le \bar{p} \le \bar{p}_{34}^R,\\ \rho ^{L_2}( \mathcal {S}^{-1}(\bar{p}) ) \quad &{} \text {for } \bar{p}_{34}^R < \bar{p} \le \bar{p}_4^R. \end{array}\right. } \end{aligned}$$
(84)

The integrals in (83) are transformed to their respective line segments, e.g., the integral on the LHS of (83b) and the integral in (83a) are transformed to the reference interval \([-1, 1]\) along \(R_3\), such that we obtain

$$\begin{aligned} \begin{aligned} \min _{\rho ^R \in \mathbb {P}_N}&\quad \int _{-1}^{1} \left[ \rho ^R( \zeta ) - \rho ^L \left( \varXi ^L(\zeta ) \right) \right] ^2 \, \mathrm {d}\zeta \\ \text {subject to}&\quad \varDelta \bar{p}^R \int _{-1}^{1} F^R(\zeta ) \, \mathrm {d}\zeta = \varDelta p^{L_1} \int _{\sigma ^{L_1}}^{\sigma ^{L_1} + \lambda ^{L_1}} F^{L_1}(\zeta ) \, \mathrm {d}\zeta \\&\qquad + \varDelta p^{L_2} \int _{\sigma ^{L_2}}^{\sigma ^{L_2} + \lambda ^{L_2}} F^{L_2}(\zeta ) \, \mathrm {d}\zeta , \end{aligned} \end{aligned}$$
(85a)

with

$$\begin{aligned} \varXi ^L(\zeta ) :=&{\left\{ \begin{array}{ll} \varXi \left( \zeta ; p_1^L, \, \varDelta p^{L_1}, \, \bar{p}_3^R, \; \bar{p}_{34}^R - \bar{p}_3^R \right) \quad &{} \text {for } -1 \le \zeta \le \kappa , \\ \varXi \left( \zeta ; p_2^L, \, \varDelta p^{L_2}, \, \bar{p}_{34}^R, \; \bar{p}_4^R - \bar{p}_{34}^R \right) \quad &{} \text {for } \kappa < \zeta \le 1, \end{array}\right. } \end{aligned}$$
(85b)

where we write R instead of \(R_3\) for brevity, and \(\kappa \) is defined such that \(p(\kappa ) = \bar{p}_{34}^R\) in \(R_3\) and \(\varDelta \bar{p}^R := \bar{p}_4^R - \bar{p}_3^R\), \(\varDelta p^{L_1} := p_2^L - p_1^L\) and \(\varDelta p^{L_2} := p_3^L - p_2^L\). Note that \(\sigma ^{L_1} + \lambda ^{L_1} = 1\) and \(\sigma ^{L_2} = -1\), however, for illustration purposes we will keep using the variables rather than these values. The Lagrange function \(\mathcal {L}\) for this constrained minimisation problem reads

$$\begin{aligned} \begin{aligned} \mathcal {L} =&\frac{1}{2} \int _{-1}^{1} \left[ \rho ^R( \zeta ) - \rho ^L \left( \varXi ^L(\zeta ) \right) \right] ^2 \, \mathrm {d}\zeta + \mu \left[ \varDelta \bar{p}^R \int _{-1}^{1} F^R(\zeta ) \, \mathrm {d}\zeta \right. \\&\quad \left. - \varDelta p^{L_1} \int _{\sigma ^{L_1}}^{\sigma ^{L_1} + \lambda ^{L_1}} F^{L_1}(\zeta ) \, \mathrm {d}\zeta - \varDelta p^{L_2} \int _{\sigma ^{L_2}}^{\sigma ^{L_2} + \lambda ^{L_2}} F^{L_2}(\zeta ) \, \mathrm {d}\zeta \right] . \end{aligned} \end{aligned}$$
(86)

The coefficients \(\rho _j^R\) for the polynomial \(\rho ^R \in \mathbb {P}_N\) can be found by solving

$$\begin{aligned} \frac{\partial \mathcal {L}}{\partial \rho ^R_i} = 0 \quad \text {for } i = 0, 1, ..., N, \quad \frac{\partial \mathcal {L}}{\partial \mu } = 0. \end{aligned}$$

Following the same steps as in Sect. 4.2, we obtain the following system of equations

$$\begin{aligned}&\sum _{j=0}^N M_{ij} \rho _j^R + \mu w_i \alpha _i^R = \sum _{j=0}^N \left[ S_{ij}\left( -1, 1 + \kappa \right) \rho _j^{L_1} + S_{ij}\left( \kappa , 1 - \kappa \right) \rho _j^{L_2} \right] , \nonumber \\&\quad \text {for } i = 0, 1, ..., N, \end{aligned}$$
(87a)
$$\begin{aligned}&\sum _{j=0}^N w_j \alpha _j^R \rho _j^R = \sum _{j=0}^N \beta _j^{L_1} \rho _j^{L_1} + \sum _{j=0}^N \beta _j^{L_2} \rho _j^{L_2}, \end{aligned}$$
(87b)

with

$$\begin{aligned}&\alpha _j^R := \varDelta \bar{p}^R u_j^R, \quad \beta _j^{L_1} := \varDelta p^{L_1} \frac{\lambda ^{L_1}}{2} u_j^{L_1} \sum _{k=0}^N w_k \ell _j \left( \sigma ^{L_1} + \frac{1}{2} \lambda ^{L_1} \left( 1 + \xi _k \right) \right) , \end{aligned}$$
(87c)
$$\begin{aligned}&\beta _j^{L_2} := \varDelta p^{L_2} \frac{\lambda ^{L_2}}{2} u_j^{L_2} \sum _{k=0}^N w_k \ell _j \left( \sigma ^{L_2} + \frac{1}{2} \lambda ^{L_2} \left( 1 + \xi _k \right) \right) . \end{aligned}$$
(87d)

The linear system described by (87) can once again be assembled into a matrix-vector form:

$$\begin{aligned} \begin{pmatrix} {{\,\mathrm {diag}\,}}\left( \varvec{w} \right) &{}{} \varvec{\alpha }^R \circ \varvec{w} \\ \left( \varvec{\alpha }^R \circ \varvec{w} \right) ^\text {T} &{}{} \qquad \,\,\, 0 \end{pmatrix} \begin{pmatrix} \varvec{\rho }^R \\ \mu \end{pmatrix} = \begin{pmatrix} \varvec{S}^{L_1} \\ \left( \varvec{\beta }^{L_1} \right) ^\text {T} \end{pmatrix} \varvec{\rho }^{L_1} + \begin{pmatrix} \varvec{S}^{L_2} \\ \left( \varvec{\beta }^{L_2} \right) ^\text {T} \end{pmatrix} \varvec{\rho }^{L_2} , \end{aligned}$$
(88)

where we have used the shorthand notation \(\varvec{S}^{L_1} = \big ( S_{ij}( -1, 1 + \kappa ) \big )\) and \(\varvec{S}^{L_2} = \big ( S_{ij}( \kappa , 1 - \kappa ) \big )\). Note that the matrix on the LHS is exactly the same as the matrix obtained in the previous section, except for possibly different values for \(\alpha _j^R\). Therefore, we can again solve the linear system explicitly for the Dirichlet boundary condition values \(\varvec{\rho ^R}\), resulting in

$$\begin{aligned} \varvec{\rho }^R = \frac{1}{r} \begin{pmatrix} \varvec{B}&\; -\varvec{\alpha }^R \end{pmatrix} \left[ \begin{pmatrix} \varvec{S}^{L_1} \\ \left( \varvec{\beta }^{L_1} \right) ^\text {T} \end{pmatrix} \varvec{\rho }^{L_1} + \begin{pmatrix} \varvec{S}^{L_2} \\ \left( \varvec{\beta }^{L_2} \right) ^\text {T} \end{pmatrix} \varvec{\rho }^{L_2} \right] , \end{aligned}$$
(89)

cf. (82). This result can of course be generalised to K elements contributing to \(\varvec{\rho }^R\), resulting in

$$\begin{aligned} \varvec{\rho }^R = \frac{1}{r} \begin{pmatrix} \varvec{B}&\; -\varvec{\alpha }^R \end{pmatrix} \left[ \sum _{k=1}^K \begin{pmatrix} \varvec{S}^{L_k} \\ \left( \varvec{\beta }^{L_k} \right) ^\text {T} \end{pmatrix} \varvec{\rho }^{L_k} \right] . \end{aligned}$$
(90)

4.4 Overview

To summarise, during a z-step the numerical fluxes over the optical interface are evaluated as follows. First, the elements are identified that have an edge on the optical interface. Those elements are separated into elements with velocities directed towards the optical interface, denoted L, and elements with velocities directed away from the optical interface, denoted R. For the elements from L the solution is evaluated at edges on the optical interface. The numerical flux over the edges for the elements L can be directly computed as there is no constraint on \(\rho \). For each element from R there is a Dirichlet boundary condition on the edge at the optical interface given by (53), that is incorporated into the numerical flux.

The value for the Dirichlet boundary condition is determined from the elements L, as follows. To determine which elements from L contribute to a single R element, Snell’s function is applied to the momentum boundaries of the elements L. Subsequently, the geometric quantities relating the element sizes are computed. Next, the momenta p at the quadrature nodes, for evaluation of the integral \(S_{ij}\), are determined. Subsequently, we apply \(\mathcal {S}^{-1}\) to these nodes, and compute \(\varXi \) using (67). Hereafter, the integrals \(S_{ij}\) are evaluated and the coefficients \(\alpha _j^L\), \(\alpha _j^R\) are computed. Finally, the values for the Dirichlet boundary condition can be found from their contributing L-elements by applying (90).

5 Results

Numerical experiments were performed for two examples. The first example features light propagating through a gradient-index medium. The smooth refractive index field of the medium fits naturally into the DGSEM for solving Liouville’s equation. For such optical systems ray-tracers usually have to resort to difficult to obtain closed-form expressions for the trajectory of the rays [2], or use symplectic integrators to solve Hamilton’s equations for every ray [27]. Solving Liouville’s equation with the DGSEM provides directly the energy distribution, i.e., the basic luminance \(\rho \) for the optical system. Furthermore, the method conserves energy by design.

The second example features a single optical interface. The problem exhibits both total internal reflection and refraction. At the optical interface we apply the strategy outlined in Sect. 4. Furthermore, a comparison is made between solving Liouville’s equation using the DGSEM and applying quasi-Monte Carlo ray tracing [14]. The illuminance is solved using both methods and the performance of both methods is tested.

5.1 Elliptic Waveguide

As a first example, we consider the elliptic waveguide [35] which features a smooth refractive index field given by

$$\begin{aligned} n(q) = {\left\{ \begin{array}{ll} \sqrt{n_0^2 - \kappa ^2 q^2} &{} \text {if } \kappa \left| q \right| \le \sqrt{n_0^2 - 1}, \\ 1 &{} \text {otherwise}. \end{array}\right. } \end{aligned}$$
(91)

The parameters \(n_0\) and \(\kappa \) are taken to be \(n_0 = 1.4\) and \(\kappa = \sqrt{n_0^2 - 1}\). The refractive index field and several rays are shown in Fig. 4. We observe that the elliptic waveguide contains light much like an optical fibre. Hamilton’s equations (8) for rays inside the elliptic waveguide read

$$\begin{aligned} \begin{aligned} \frac{\mathrm {d} q}{\mathrm {d} z}&= -\frac{p}{h}, \\ \frac{\mathrm {d} p}{\mathrm {d} z}&= \frac{\kappa ^2}{h} q. \end{aligned} \end{aligned}$$
(92)

Since the refractive index field does not depend on z, the Hamiltonian h remains constant for each ray. The solution of (92) reads

$$\begin{aligned} \begin{aligned} q(z)&= q_0 \cos \left( \frac{\kappa }{h} z \right) - \frac{p_0}{\kappa } \sin \left( \frac{\kappa }{h} z \right) , \\ p(z)&= p_0 \cos \left( \frac{\kappa }{h} z \right) + \kappa q_0 \sin \left( \frac{\kappa }{h} z \right) , \end{aligned} \end{aligned}$$
(93)

where the initial conditions are given by \(( q(0), p(0) ) = (q_0, p_0)\). Note that from the refractive index field n and the Hamiltonian h we obtain [35]

$$\begin{aligned} \kappa ^2 q^2 + p^2 = n_0^2 - h^2, \end{aligned}$$
(94)

where the right-hand side is constant when we move along the z-axis. We can readily see that the trajectories follow an elliptical path in phase space, hence, the name elliptic waveguide.

Fig. 4
figure 4

Elliptic waveguide: background colour indicates the refractive index value n(q), and the solid lines represent ray trajectories. Arrows indicate the direction of the ray, i.e., the momenta \((p_z, p)\)

Let the function \(\varphi _m\) be defined as

$$\begin{aligned} \varphi _m(x) := {\left\{ \begin{array}{ll} \cos ^{m+1} \left( \frac{\pi }{2} x^2 \right) \quad &{} \text {if } \left| x \right| < 1, \\ 0 \quad &{} \text {otherwise}, \end{array}\right. } \end{aligned}$$
(95)

which is a \(C_0^m\)-function, meaning its first m derivatives are continuous and has compact support. The function \(\varphi _m\) is plotted in Fig. 5 for \(m = 7, 28\). We solve Liouville’s equation (20a) with the following initial condition

$$\begin{aligned} \rho _0(q, p) = \varphi _m \left( \frac{q}{\sigma _q} \right) \varphi _m \left( \frac{p}{\sigma _p} \right) , \end{aligned}$$
(96)

at \(z = 0\) and on the boundary of the domain we leave \(\rho \) free whenever the velocity field is pointing out of the domain, otherwise we prescribe \(\rho = 0\). In (96) we take \(m = 7\), \(\sigma _q = 0.25\) and \(\sigma _p = 0.1\).

Fig. 5
figure 5

Function \(\varphi _m\) for \(m = 7\) and \(m = 28\)

The ODE system (49) is integrated using the low-storage 4th order Runge-Kutta method by Zingg and Chisholm [37]. The numerical solution is integrated from \(z = 0\) to \(z = Z = 3\). The result using a 6th degree polynomial (\(N = 6\)) and \(K = 16 \times 16 = 256\) elements is shown in Fig. 6, together with the initial condition. The numerical solution at \(z = Z\) has roughly the same phase space area and is approximately a rotation of the initial condition. The scheme is also energy conservative up to machine precision, as can be seen in the plot of Fig. 7. Here, the relative error in the total luminous flux is plotted as a function of z. The total luminous flux is computed according to its definition (15) by applying a quadrature rule in agreement with the chosen polynomial degree.

Fig. 6
figure 6

Elliptic waveguide: basic luminance distributions \(\rho (z, q, p)\). Parameters are \(N = 6\), \(K = 256\), \(Z = 3\)

Fig. 7
figure 7

Elliptic waveguide: relative error in luminous flux

Furthermore, a convergence test is performed for this example by changing the number of elements K and varying the polynomial degree from \(N = 1, 2, ..., 6\). The numerical solution is compared to the exact solution, which can be found from the trajectory of the rays given by expressions (93). The expressions describe the evolution of a ray, given the initial conditions of the ray. For the analytical solution to Liouville’s equation at an arbitrary z we want to know where the ray originated from, since the phase space coordinates on the mesh are known. This amounts to tracing the ray backwards starting from an arbitrary z to \(z = 0\), resulting in

$$\begin{aligned} \rho (z, q, p) = \rho _0( q(-z), p(-z) ), \end{aligned}$$
(97)

with q(z) and p(z) given in (93).

Using the exact solution (97) we can evaluate the discretisation error for which we take the \(L^1\)-norm, i.e.,

$$\begin{aligned} e_\text {DG} := \int _{\mathcal {P}} \left| \rho _\text {DG}(Z, q, p) - \rho (Z, q, p) \right| \, \mathrm {d}q \mathrm {d}p, \end{aligned}$$
(98)

where \(\rho _\text {DG}\) denotes the numerical solution and \(\rho \) denotes the exact solution (97). The integrals in (98) are evaluated using Gauss-Legendre quadrature with \(N + 3\) nodes. The convergence order \(\gamma _\text {DG}\) is estimated from the empirical relation

$$\begin{aligned} e_\text {DG} = C_\text {DG} K^{-\gamma _\text {DG} / 2}, \end{aligned}$$
(99)

with \(C_\text {DG} > 0\) an arbitrary constant.

The convergence data is shown in Table 1. The spatial discretisation is done using an Nth degree polynomial, and therefore the spatial order of accuracy is \(N + 1\). The temporal discretisation is done using a 4th order explicit Runge-Kutta method, where we choose \(\varDelta z\) to be the maximum allowable step such that the temporal integration is stable. Furthermore, a uniform rectangular mesh is used, where upon mesh refinement the mesh size in each direction is halved and similarly \(\varDelta z\) is halved to ensure stability.

The global error depends on whether the spatial or temporal discretisation errors dominate. From Table 1, we observe that the spatial discretisation error dominates for the polynomial degrees \(N = 1\) to \(N = 6\). Choosing a smaller \(\varDelta z\)-step in the numerical experiments did not influence the discretisation error. The results show that we obtain the expected \(N + 1\) order of convergence.

Table 1 Elliptic waveguide: convergence data

5.2 Bucket of Water

To illustrate that the strategy outlined in Sect 4 for handling optical interfaces is energy conservative, we apply it to a test case. The test case ‘bucket of water’ introduced by van Lith et al. [32, 33] is a suitable choice. The refractive index for this problem is given by

$$\begin{aligned} n(q) = {\left\{ \begin{array}{ll} n_1, \quad &{} \text {if } q \le 0, \\ n_2, \quad &{} \text {if } q > 0, \end{array}\right. } \end{aligned}$$
(100)

where we take \(n_1 = 1.4\) and \(n_2 = 1\). Using an initial basic luminance \(\rho _0\) that has support \(\mathcal {D}\) where \(q < 0\) and \(p > 0\) for all \((q, p) \in \mathcal {D}\), the solution features both refraction and total internal reflection in two separate quadrants of phase space. The exact solution reads [33]

$$\begin{aligned} \rho (z,q,p) = \left\{ {\begin{array}{*{20}l} {\rho _{0} \left( {q - z\frac{p}{{\sqrt{n_{1}^{2} - p^{2} } }},p} \right) \quad } &{} {{\text {if }}q< 0,p \ge 0,} \\ {\rho _{0} \left( {z\frac{p}{{\sqrt{n_{1}^{2} - p^{2} } }} - q, - p} \right) \quad } &{} {{\text {if }}q< 0, - p_{c}< p < 0,} \\ {\rho _{0} \left( {(\delta z - z)\frac{{\bar{p}}}{{\sqrt{n_{1}^{2} - \bar{p}^{2} } }},\bar{p}} \right) \quad }&{} {{\text {if }}q > 0,p \ge 0,} \\ {{\text { }}0\quad } &{} {{\text {otherwise, }}} \\ \end{array} } \right. \end{aligned}$$
(101a)

where \(p_\text {c} = \sqrt{n_1^2 - n_2^2}\), \(\bar{p} = -\mathcal {S}(-p; n_2, n_1, -\mathbf {\nu })\) with \(\mathbf {\nu } = (-1, 0)\), and

$$\begin{aligned}&\delta z = \frac{q}{p} \sqrt{n_2^2 - p^2}. \end{aligned}$$
(101b)

The region described by \(\{q < 0, p \ge 0\}\) features propagation through the medium with refractive index \(n_1\). The region \(\{q< 0, -p_\text {c}< p < 0\}\) describes light that was reflected at the optical interface, and the region \(\{q > 0, p \ge 0\}\) describes light that was refracted.

As an initial condition we use

$$\begin{aligned} \rho _0(q, p) := \varphi _m \left( \frac{q - q_0}{\sigma _q} \right) \left[ \varphi _m \left( \frac{p - p_0}{\sigma _{p,0}} \right) + \varphi _m \left( \frac{p - p_1}{\sigma _{p,1}} \right) \right] , \end{aligned}$$
(102)

with \(\varphi _m\) defined in (95) and on the part of the boundary of the domain that is not on the optical interface, we prescribe \(\rho = 0\) whenever the velocity field is pointing into the domain, otherwise we leave \(\rho \) free. Since the q-position is restricted to \(q \in [-1, 1]\), this means that at \(q = \pm 1\) we place virtual detectors that capture any luminous flux leaving the system. For the parameters in (102), we take \(q_0 = -0.35\), \(\sigma _q = 0.25\), \(p_0 = 0.45\), \(\sigma _{p,0} = 0.45\), \(p_1 = \tfrac{1}{2} (1.3 + p_\text {c} )\) and \(\sigma _{p,1} = 1.3 - p_1\). Furthermore, we take \(m = 7\) unless specified otherwise.

Again, the explicit 4th order RK method from the previous example is used with a constant \(\varDelta z\)-step as determined by the stability of the temporal integration. The numerical solution is integrated from \(z = 0\) to \(z = Z = 0.7\) and \(z = 2Z\), and is shown in Fig. 8, together with the used initial condition. The result was obtained using a 6th degree polynomial (\(N = 6\)) and \(K = 480\) elements. The mesh uses only rectangular elements and is almost uniform. To easily treat the optical interface, we have shifted the elements below and above the critical momentum \(p_\text {c} \approx 0.98\) in the p-direction such that the critical momentum is aligned with the edges of these elements. The mesh spacings for \(K = 480\) are \(\varDelta q = 0.1\) and \(\varDelta p \approx 0.1\).

In Fig. 8 the quadrants featuring reflection and refraction can be clearly distinguished, while the solution is, as expected, perfectly discontinuous along the optical interface. Furthermore, at \(z = 2Z\) some of the solution has passed \(q = 1\), meaning some energy has hit the detectors. We observe that a total 7.5 % of the initial luminous flux has hit the detectors at \(z = 2Z\). Taking into account the luminous flux on the detectors, we compute the relative error in the total luminous flux as a function of z which is plotted in Fig. 9a. The plot shows that the method obeys energy conservation up to machine precision.

Fig. 8
figure 8

Bucket of water: basic luminance distributions \(\rho (z, q, p)\). Parameters are \(N = 6\), \(K = 480\), \(Z = 0.7\)

Furthermore, to show that the optical interface treatment does not incur any penalty on the convergence order, we compute the discretisation error for this example defined in (98). The convergence data for \(N = 1, 2, ..., 6\) is shown in Table 2. Also for this example, we observe that the spatial discretisation error is dominant and choosing smaller \(\varDelta z\)-steps did not result in different discretisation errors. Moreover, the expected spatial order of convergence \(N + 1\) is obtained.

Next, we verify the exponential convergence of DGSEM by increasing the polynomial degree, whilst keeping the number of elements fixed to \(K = 1920\) and choosing \(m = 28\) in (102). For temporal integration a fixed number of \(2 \cdot 10^4\) z-steps are performed, chosen such that the temporal integration error does not interfere with the convergence test. The result is shown in Fig. 9b and exponential convergence is observed.

Fig. 9
figure 9

Bucket of water

Table 2 Bucket of water: convergence data

5.2.1 Comparison with Ray Tracing

We compare forward ray tracing with bin-counting to solving Liouville’s equation using the DGSEM. Solving Liouville’s equation already has two advantages, i.e., it conserves energy and provides a more complete picture due to solving the luminance instead of its integrated quantities, the illuminance or luminous intensity. The latter advantage also comes at a price of having to solve a two-dimensional problem in phase space followed by integration to compute these quantities. Ray tracing on the other hand can directly use bins on a one-dimensional grid to compute either the illuminance or luminous intensity.

For a fair comparison, we compute the illuminance E, defined by (17), for this test case using both quasi-Monte Carlo ray tracing and the DGSEM. For quasi-Monte Carlo ray tracing we fix the number of bins to \(B = 1000\) and employ a uniform grid on \(q \in [-1, 1]\), i.e.,

$$\begin{aligned} Q_j = (j - 1) \varDelta q - 1, \quad j = 1, ..., B + 1, \end{aligned}$$
(103)

with \(\varDelta q = \frac{2}{B}\). The jth bin is defined by \([Q_j, Q_{j+1}]\) with midpoint \(q_j = \tfrac{1}{2}(Q_j + Q_{j+1})\). The global error for quasi-Monte Carlo integration using a 2D Sobol sequence behaves as \(\mathcal {O}( \log (M)^2 / M )\) with M the number of 2D points [11]. The 2D points are in our case the initial phase space coordinates \((q_i, p_i) \in \mathcal {P}\) of each ray. For more details on quasi-Monte Carlo integration, see [24]. In the bucket of water example \(M = N_\text {RT}\) denotes the number of rays and we use a fixed number of bins.

For the DGSEM we compute the luminance followed by integration such that we obtain the illuminance. Ray tracing defines an average illuminance on each bin, hence, for a fair comparison we also average the illuminance for the DGSEM when computing the discretisation error. For the discretisation error we take the \(L^1\)-norm and compare the numerical solution to the exact illuminance, which is computed by integrating the exact luminance (101) numerically up to machine precision.

Once again we take the initial condition (102) and (95) with \(m = 7\). The illuminance computed using ray tracing with \(N_\text {RT} = 0.64 \cdot 10^6\) rays and the illuminance obtained with DGSEM on a mesh with \(K = 480\) elements and \(N = 4\) are shown in Fig. 10a, together with the exact solution. The ray tracing (RT) solution is noisy, which is inherent in the method due to the quasi-random Monte Carlo process, while the DGSEM solution is almost indistinguishable from the exact solution.

The discretisation error for ray tracing for increasing number of rays is shown in Table 3, while the results for the DGSEM with increasing number of elements K is shown in Table 4. In the tables \(e_\text {RT}\) and \(e_\text {DG}\) denote the errors for ray tracing and solving Liouville’s equation using the DGSEM, respectively, while \(t_\text {RT}\) and \(t_\text {DG}\) denote their respective computation times using only a single core. Furthermore, \(\gamma _\text {RT}\) is estimated from the empirical relation

$$\begin{aligned} e_\text {RT} = C_\text {RT} N_\text {RT} ^{-\gamma _\text {RT} }. \end{aligned}$$
(104)

while \(\gamma _\text {DG}\) is estimated from the empirical relation (99).

From the tables we observe that ray tracing uses \(2.62 \cdot 10^9\) rays taking almost an hour and a half, while the DGSEM achieves roughly the same accuracy in only 8.0 seconds when using 1920 elements. Varying the polynomial degrees results in the performance graph shown in Fig. 10b. It can be observed that the DGSEM always achieves a better accuracy for \(N \ge 1\), compared to quasi-Monte Carlo ray tracing in the same amount of time. The DGSEM significantly outperforms ray tracing and, moreover, can achieve high accuracies in reasonable time.

Table 3 Bucket of water: discretisation error using ray tracing (RT) for computing the illuminance. Number of bins is fixed to \(B = 1000\)
Table 4 Bucket of water: discretisation error using the DGSEM (DG) with \(N = 4\) for computing the illuminance
Fig. 10
figure 10

Left: the illuminance computed using ray tracing (RT) with \(N_\text {RT} = 0.64 \cdot 10^6\) rays and the DGSEM with \(K = 480\) and \(N = 4\) (DG). Right: the error as a function of the computation time for both methods. Both results were computed at \(z = Z = 0.7\)

6 Conclusions

We have solved Liouville’s equation for geometrical optics, using the discontinuous Galerkin spectral element method. For smooth refractive index fields the scheme obeys energy conservation by design. At optical interfaces Snell’s law of refraction or the law of specular reflection needs to be applied. Together with the basic luminance invariance, this corresponds to non-local boundary conditions in phase space. A method was presented to treat the non-local boundary conditions along the optical interface such that the scheme remains energy conservative in the presence of optical interfaces.

Energy conservation is verified in an example. Moreover, in the same example the scheme was compared with forward ray tracing when computing the illuminance. Ray tracing uses bins on a one-dimensional grid to compute the illuminance, while the DGSEM has to solve a two-dimensional problem followed by integration. This still resulted in a better performance compared to ray tracing. In particular, for a fourth degree polynomial, the DGSEM has a computation time of 8.0 seconds, while ray tracing took 1 hour and 26 minutes to achieve almost the same accuracy.

At the moment Fresnel reflections [15, 16] were not included. Therefore, an obvious next step will be to include this in the method by modifying the basic luminance invariance over an optical interface (53), see [26]. Moreover, only two-dimensional optics was considered in this paper. Hence, for future research we intend to extend the method to a three-dimensional optics settings. This requires a four-dimensional phase space together with the propagation along the z-coordinate, making it a five-dimensional problem. Despite the increased computational complexity due to the high dimensionality of the problem, the high convergence rates of DGSEM will still be an advantage over ray tracing, where in theory the DGSEM might achieve a better performance [31].