Particle-in-cell methods (PIC)#
Basics#
PIC methods are well-suited for the discretization of conservation laws of the form
where \(\Omega\subset \mathbb R^n\) is open, \(q\) denotes a set of suitable coordinates in \(\Omega\), and we assume appropriate boundary conditions on \(\partial\Omega\). Here, \(f: (t,q) \mapsto \mathbb R^+\) is a positive density or “volume form”, \(\mathbf u: (t,q) \mapsto \mathbb R^n\) is the vector-field defining the flow, and \(S(f)\) is a (nonlinear) source term. Equation (1) can be re-written as
which represents an advection equation with a source term. The PIC ansatz for solving equation (1) is
where \(N \gg 1\) is a large number and \(\delta(q)\) stands for the Dirac delta-distribution. Moreover, \(q_k: \mathbb R \to \Omega\) denotes the trajectory of marker \(k\) in the domain \(\Omega\) and \(w_k: \mathbb R \to \mathbb R\) stands for its (time-dependent) “weight”. The equations for \(q_k(t)\) and \(w_k(t)\) are derived from the following principle:
The time derivative of the \(f_h\)-integral reads
Assuming that boundary terms vanish, the time derivative of the \(f\)-integral can be written as
These integrals are now viewed as Monte-Carlo integrals in the following way: assume \(s: (t,q) \mapsto \mathbb R^+\) to be a time-dependent probability distribution function (PDF) on \(\Omega\), and let \(\mathbb E(X)_s\) denote the expectation value of a random variable \(X\) distributed according to \(s\). Then,
At each time \(t\) we can estimate the above expectation values from the \(N\) samples \(q_k\):
We can compare this to equation (4) and since equation (3) holds for any \(\phi\), by comparing coefficients we deduce
Let us define the weights to be
which implies
and also
By comparing the equations (7) and (8) we find the equation that must be satisfied by the PDF \(s\):
Since, from equation (1),
we deduce
Therefore, with the choice of the weights made in equation (6), the PDF \(s\) must satisfy
This means that \(s\) is a density (or volume form) advected by the flow of \(\mathbf u\). For incompressible flow, \(\nabla_q \cdot \mathbf u = 0\), the PDF \(s\) is constant along the flow of \(\mathbf u\) and the PIC solution (2) is obtained by solving
where the \(q_{k0}\) are drawn according to the PDF \(s(t=0)\). On the other hand, for compressible flow \(\nabla_q \cdot \mathbf u \neq 0\) the weights update is more complicated:
Note that when there is no source, \(S(f) = 0\), the weights are constant for compressible and incompressible flow.
PIC methods are popular for solving these types of equations because
they do not suffer from the curse of dimensionality for large \(n\)
they and can be easily parallelized.
However, a disadvantage is their slow convergence \(\sim 1/\sqrt N\) with the number of particles (also called markers) and the associated noise that is present in simulations. Often times noise-reduction techniques such as the Control variate method have to be employed to reduce simulation cost.
Monte-Carlo integrals#
At the core of the PIC method is the approximation of integrals
by Mont-Carlo (MC) integration. The first expecation value in equation (5) is an example of this. In Struphy, such integrals are calculated in non-Cartesian coordinates \(q \in \mathbb R^n\), and we denote by
the volume element, including the Jacobian determinant from the mapping to Cartesian (straight) space. Thus, we could also write the integral as
We have seen that \(s\) satisfies the transport equation s_eq,
and that it is normalized, thus
In MC integration, we view the integral \(I\) as an expectation value:
with respect to the PDF \(s|J|\). Having access to \(N\) samples \(q_k(t)\) of \(s\) at each time \(t\) allows us to estimate this expectation via
using the definition of the weights in equation (6). The error in this approximation is of order \(N^{-1/2}\).
The weights are implemented in struphy.pic.base.Particles.initialize_weights().
Equation (13) can be obtained directly from (12) by inserting
the PIC ansatz (2), with \(f|J| \approx f_h\).
In Struphy, Monte-Carlo integrals of the form (13) are implemented via accums.
PIC algorithm#
The PIC algorithm can be summarized in the following steps:
Draw \(N\gg 1\) markers \((q_{k0})_k\) according to \(s_{\textnormal{in}}|J|\). The initial marker distribution is implemented in
struphy.pic.base.Particles.draw_markers(). In Struphy, it is always a Gaussian in velocity space (see docstring).Compute the weights \((w_{k0})_k\) according to equation (6). The initial condition of the kinetic equation enters here.
Solve the characteristic equations (9) for each marker.
Whenever necessary, compute integrals according to (13).
Particle binning#
The aim of particle binning is to obtain a “grid-representation” of either \(f^0(t, q)\) or \(f^\textrm{vol}(t, q)\), which are represented by markers in Struphy. The approximation is obtained by integration of \(f^{0/\textrm{vol}}(t, q)\) over small volumes of phase space, called “bins”. These bins are not necessarily related to the FE grid used for fluid/field variables (but they can be). Moreover, bins do not have to be defined in all \(n\) directions of the phase space; one could do just 1D or 2D binning, integrating over the other coordinates entirely.
For example, let’s say we want to do 2D binning in the \((\eta_1,v_1)\) subspace of the full \((\eta,v) \in \mathbb R^6\) phase space. In this case we want an approximate representation of the “reduced” 2D density
where \(k \in \{0, \textrm{vol}\}\) such that \(f^k\) is either the 0-form or the volume form in logical space (here integrated over a submanifold, which is technically not allowed - but serves to get an approximation via numerical binning). If we define bin edges \((\eta_{1i})_i\) and \((v_{1j})_j\) in the \((\eta_1, v_1)\) subspace, we can approximate \(f^{k,\textnormal{red}}\) restricted to a bin \(\Omega_{ij} = (\eta_{1i}, \eta_{1i+1}) \times (v_{1j}, v_{1j+1})\) by its mean value over over that bin:
where \(|\Omega_{ij}|\) is the volume of the \(ij\)-th bin (in 2D):
Note that \(R^k_{ij}\) has the same dimension as \(f^{k,\textnormal{red}}\), due to the one-over-volume prefactor. The integrals \(R^k_{ij}\) are then approximated by Monte-Carlo integration, using the indicator function \(\textnormal{id}_{ij}(x_1, v_1)\) of the \(ij\)-th bin (it is 1 inside \(\Omega_{ij}\) and zero otherwise). Depending on the value of \(k \in \{0, \textrm{vol}\}\), there are two different integrals to approximate:
Here, the sum runs over all markers that are in the bin \(\Omega_{ij}\).
The values \(R^0_{ij}\) computed in (15) are discrete approximations of \(f^0\),
and values \(R^\textrm{vol}_{ij}\) are discrete approximations of \(f^\textrm{vol}\).
This binning algorithm is implemented in struphy.pic.base.Particles.binning().
Control variate method#
This noise reduction technique relies on
The ability to compute (without Monte-Carlo) the integral (11) for a known distribution function \(f^0 = \mathcal M^0\):
The assumption that \(f^0(t)\) is close to \(\mathcal M^0(t)\) for all \(t\).
In that case we can decompose (11) as
where we have introduced the time-dependent weights
This algorithm is implemented in struphy.pic.base.Particles.update_weights().