is there a faster way to calculate electric fields due to nearby charges?

86 Views Asked by At

I need to calculate the electric field due to charges within some (small) distance of a site. Right now, my code loops over all charges and positions, calculates the position of each charge, and checks if the distance from the site is within the cutoff, and if so, it includes the corresponding charge in the electric field (n^2 for all n particles). To make this faster in one dimension, I could simply pre-sort (n*logn) the distances and loop over them until the distance > cutoff, and then break. I wonder if there is a way to do this in three dimensions and make the code many times faster. I'm a scientist, not a CS professional, so I may simply not know which data structure and/or algorithm is best for this kind of thing. Please enlighten me.

Thank you!

0

There are 0 best solutions below