API Reference
multipoles.MultipoleExpansion
Bases: object
Perform a multipole expansion for a given charge or mass distribution.
Determines the spherical multipole moments of the given distribution and can calculate the solution of the electrostatic or gravitational potential based on the multipole expansion.
__init__(charge_dist, l_max, exterior=None, interior=None)
Create a MultipoleExpansion object for a given charge or mass distribution.
Parameters: |
|
---|
Examples
As example for a discrete charge distribution we model two point charges with positive and negative unit charge located on the z-axis:
>>> from multipoles import MultipoleExpansion
Prepare the charge distribution dict for the MultipoleExpansion object:
>>> charge_dist = {'discrete': True, 'charges': [{'q': 1, 'xyz': (0, 0, 1)}, {'q': -1, 'xyz': (0, 0, -1)}]}
>>> l_max = 2
>>> Phi = MultipoleExpansion(charge_dist, l_max)
Then evaluate on any point desired using Phi(...) or Phi[]. See the docstrings of call and getitem, respectively.
As an example for a continuous charge distribution, we smear out the point charges from the previous example:
>>> from multipoles import MultipoleExpansion
>>> import numpy as np
First we set up our grid, a cube of length 10 centered at the origin:
>>> npoints = 101
>>> edge = 10
>>> x, y, z = [np.linspace(-edge/2., edge/2., npoints)]*3
>>> XYZ = np.meshgrid(x, y, z, indexing='ij')
We model our smeared out charges as gaussian functions:
>>> def gaussian(XYZ, xyz0, sigma):
>>> g = np.ones_like(XYZ[0])
>>> for k in range(3):
>>> g *= np.exp(-(XYZ[k] - xyz0[k])**2 / sigma**2)
>>> g *= (sigma**2*np.pi)**-1.5
>>> return g
The width of our gaussians:
>>> sigma = 1.5
Initialize the charge density rho, which is a 3D numpy array:
>>> rho = gaussian(XYZ, (0, 0, 1), sigma) - gaussian(XYZ, (0, 0, -1), sigma)
Prepare the charge distribution dict for the MultipoleExpansion object:
>>> charge_dist = {'discrete': False, 'rho': rho, 'xyz': XYZ}
The rest is the same as for the discrete case:
>>> l_max = 2
>>> Phi = MultipoleExpansion(charge_dist, l_max)
Then evaluate on any point desired using Phi(...) or Phi[]. See the docstrings of call and getitem, respectively.
__call__(*xyz, l_max=None)
Evaluate multipole expansion at a point with given coordinates.
Parameters: |
|
---|