maroba / multipoles

A Python package for multipole expansions of electrostatic or gravitational potentials
MIT License
39 stars 10 forks source link

Phi(x,y,z) gives different answers if entire system is shifted #7

Closed rowanwalker96 closed 1 year ago

rowanwalker96 commented 1 year ago
charge_dist = {'discrete': True, 'charges': [{'q': 1, 'xyz': (0, 0, 0.5)}, {'q': -1, 'xyz': (0, 0, -1)}]}
l_max = 3
Phi = MultipoleExpansion(charge_dist, l_max)
Phi(0,0,0)

and

charge_dist = {'discrete': True, 'charges': [{'q': 1, 'xyz': (5, 5, 5.5)}, {'q': -1, 'xyz': (5, 5, 4)}]}
l_max = 3
Phi = MultipoleExpansion(charge_dist, l_max)
Phi(5,5,5)

give different answers despite being the same arrangement of charges around the evaluation point, is this correct?

maroba commented 1 year ago

@rowanwalker96 Well, you have found a bug! In the method MultipoleExpansion._calc_multipole_coef, in line 224, it reads

xyz = chg['xyz']

But it should be

xyz = chg['xyz'] - self.center_of_charge

If you want you can fix that, add a test and send me a pull request. Then you are one of the contributors. If you don't want or don't have time, no problem, then I can do it.

maroba commented 1 year ago

Version 0.3.1 deployed on pypi fixing this issue.