parkipy.ewald.laplace

parkipy.ewald.laplace(trg, src, charge, options)

Compute the Laplace potential.

\[\boldsymbol{u}(\boldsymbol{x}_i) = \sum_{j=1}^{N} \sum_{p \in P} \frac{q_j}{|\boldsymbol{x_j} - \boldsymbol{x_i} + P|}\]

where P is the specified periodicity.

We assume charge nutrality (i.e., \(\sum_j q_j = 0\)).

Warning

Currently only supported for \(P=3\).

Parameters:
  • trg (ndarray) – Array of target values \(\boldsymbol{x}_i\) to compute the Stokes potential. Array should be shape (3,nt) with the default ordering (i.e., 'C' ordering for cupy and 'F' ordering for numpy.

  • src (ndarray) – Array of source values \(\boldsymbol{y}_j\) of shape (3, ns) with default ordering.

  • charge (ndarray) – Array of point charges for the source points of shape (ns) with default ordering. Our error estimates assume charge neutrality, i.e., charges.mean < eps, where eps is small.

  • options (EwaldOptions) – Dataclass specifying Ewald parameters.

Returns:

  • potential (ndarray) – Array containing the Ewald approximation for the Laplace potential at the target points \(\boldsymbol{u}(\boldsymbol{x}_i)\).

  • walltimes (dict, optional) – Dictionary containing the wall-time for each stage of the Ewald summation. Only returned if options.return_walltime == True.

  • params (SEParams, optional) – SEParams dataclass containing derived Ewald parameters for the Ewald summation run. Only returned if options.return_params == True.

Raises:

NotImplementedError – If options.periodicity is not 3, if options.p2p_method is not 'GM-1D', or if options.p2g_method is not 'HYBRID'.

Notes

Parameter selection based off [1].

References

Examples

>>> import parkipy
>>> import numpy as np
>>> nt = ns = 10000
>>> trg = src = np.random.rand(3, nt)
>>> charge = np.random.randn(ns)
>>> charge -= np.mean(charge)
>>> options = parkipy.ewald.EwaldOptions(
... box=[1,1,1], periodicity=3, tolerance=1e-4,
... execution_space="openmp", cell_size=224, return_walltime=True
... )
>>> pot, walltime = parkipy.ewald.laplace(trg, src, charge, options)
>>> walltime
{'p2p': {'args': 4.291534423828125e-06, 'sort': 0.008143424987792969, 'kernel': 0.2980661392211914, 'tot': 0.3062138557434082}, 'p2g': {'args': 6.604194641113281e-05, 'sort': 0.0052490234375, 'kernel': 0.35875630378723145, 'tot': 0.3640713691711426}, 'fft': {'tot': 0.0070722103118896484}, 'cnv': {'tot': 0.016383886337280273}, 'ifft': {'tot': 0.0004782676696777344}, 'g2p': {'args': 3.647804260253906e-05, 'sort': 0.0011799335479736328, 'kernel': 0.24137353897094727, 'adj': 4.0531158447265625e-06, 'tot': 0.24259400367736816}}