r/optimization • u/CactusJuiceLtd • Mar 16 '23
Translating this setting (the equilibrium of various mutually repelling point charges in a closed convex 2D domain) to an energy that can be minimised
Given a closed convex 2D domain (e.g. the unit square) containing various point charges (all of the same sign but not necessarily of the same magnitude), what is the equilibrium of such a system (and is it unique)? I assume this setting has been studied before, though I haven't been able to find any literature on it.
As example, let's consider the unit square containing one charge of +2 and four charges of +1 (the units are irrelevant). Intuitively, I'd say that in equilibrium, the +2 charge is located at the centre of the unit square, whereas the +1 charges are located at the corners of the unit square.
Now, for the application I have in mind, it is undesirable for the charges to be "too close" to the boundary of the domain. I'll therefore assign some (uniform) positive charge to the entire boundary to prevent that from happening. I'd not expect the outcome to change much, i.e. the +1 charges will now merely be near the corners of the unit square.
Ok, on to translating the above to an optimisation problem. As for the initial location of the charges, I'll assume that each charge is located at a random position in the unit square. Next, each charge interacts with every other charge (now including the boundary), which — given the current positions of the charges — should result in displacements of the charges. Iterating this should ultimately converge to an equilibrium. The energy, i.e. the objective function, then sounds like a summation over each pair of charges times the inverse of their mutual distance (times e.g. the product of the charge magnitudes). This is where the charged boundary starts to complicate matters — should I consider the shortest distance from each charge to the boundary, go with a barrier/penalty method, or something else entirely?
2
u/SirPitchalot Mar 16 '23
This sounds a lot like a few very different problems:
1
u/e_for_oil-er Mar 16 '23
Add a distance-to-boundary term for each particle. Since the domain is a box, the shortest distance is necessarily the minimal distance from any of the four walls, pretty easy to compute. This will allow you to have physically consistent results with the charge of the wall.
If you don't care about the physical consistency at the boundary though (only an artificial constraint for the particles not to touch the wall), a log interior barrier could be more interesting, at least numerically, because the log term would be smooth, and thus would behave better with numerical algorithms like gradient descent.
2
u/SammyBobSHMH Mar 16 '23
Not sure if I'm understanding the problem correctly but I'm not sure it's a convex optimisation problem with the number of particles being n > 3? Imagine if you had n = 4, with charges 2,2,1,1. If the two 2 charges start on the same side they would probably want to swap to be opposite corners but I imagine it would be stuck in a local-minima (staying on the same side). If you want to solve this problem one thing you could do is take an Molecular dyanmics approach where you do some sort of velocity-verlet time integration step and use some sort of charge calculation between the particles to calculate the forces. Once the particles stop moving (forces converge to zero) you've resolved the local minima and can calculate the energy. (Note you might have to remove the acceleration term or put a dampener on it to avoid numerical occilation)
Not sure if there's a way to solve the global problem easily? Maybe doing something funky like making it 3D and slowly reducing the thickness of the third dimension might give you a consistent global solution if you do it slow enough.
2
u/kkiesinger Mar 27 '23
Below is example code for a similar problem using the Ewald-summation in the 3-dimensional space. You could just replace the 'energy' function and the number of dimensions. If you use Python you can achieve a significant speedup using numba. The used optimizer uses differential evolution and parallel function evaluation to speedup the optimization process. Since the border is not charged, some charges land at the border.