multipoles
multipoles computes multipole expansions of the solutions of the Poisson equation, such as electrostatic or gravitational potentials. Instead of integrating over the whole charge or mass distribution for every point where you need the potential, you compute a few multipole moments once and evaluate the expansion cheaply anywhere outside (or, for the interior expansion, inside) the distribution.
Features
- Discrete (point charges) and continuous (charge density on a grid) distributions
- Exterior and interior expansions, about the center of charge or any point you choose
- The potential and its field E = -∇Φ, computed analytically, at single points or for whole arrays
- Spherical multipole moments, plus total charge, dipole vector and quadrupole tensor
- Warnings when you evaluate the expansion where it does not converge
Installation
pip install --upgrade multipoles
Quickstart
Two point charges +1 and -1 on the z-axis:
from multipoles import MultipoleExpansion
charge_dist = {
'discrete': True,
'charges': [
{'q': 1, 'xyz': (0, 0, 1)},
{'q': -1, 'xyz': (0, 0, -1)},
],
}
Phi = MultipoleExpansion(charge_dist, l_max=8)
Phi(0, 0, 10) # 0.0202020199..., exact: 1/9 - 1/11 = 0.0202020202...
Phi(0, 0, 10, l_max=1) # 0.02, only monopole and dipole
Phi.field(0, 0, 10) # [0, 0, 0.004081], the field E = -∇Φ
Phi.dipole_moment # [0, 0, 2]
For charge densities on a grid, gravity, the interior expansion and more, see the usage guide.
Units
multipoles computes Φ = Σ q / r, i.e. the potential in Gaussian units. Multiply by 1 / (4πε₀) for the electrostatic potential in SI units. For the gravitational potential, pass the masses as charges and multiply by -G.
Where to go next
- Usage: continuous charge distributions, evaluation on grids, the field, the multipole moments, the interior expansion, gravity
- Theory: the formulas behind the expansion, where it converges and how accurate it is
- Accuracy: a worked comparison with exact solutions
- API Reference
- Changelog