bath
05-14-2011, 12:50 PM
I've got a problem with the implementation of the Powell method: I've created a box which contains a certain amount of circles (in a simple case all of the same diameter). The positions are randomally allocated, so it is possible that they overlap.
Furthermore I wrote an energy function which draws the overlap as a feather energy.
The powell routine shall minimize the energy to find an optimal configuration. At first sight, it does, but when I let the program show me the forces on every particle, these are not all equal zero. It turns out that the circles at the left and bottom border are those particles with net force != 0.
Does anyone have an idea? All that I do is giving the function to calculate the energy, isn't it?
double TotalEnergy(VecDoub_I &particles)
{
double totalEnergy = 0.;
double distance;
double k = federkonstante;
int N = 3*amount;
double dx,dy;
double sigma=100;
for (int i=0; i<N; i+=3) {
for (int j=0; j<N; j+=3) {
dx = particles[j]-particles[i];
dy = particles[j+1]-particles[i+1];
while (dx < -X_MAX/2) dx = X_MAX + dx;
while (dx > X_MAX/2) dx = X_MAX - dx;
while (dy > Y_MAX/2) dy = Y_MAX - dy;
while (dy < -Y_MAX/2) dy = Y_MAX + dy;
distance = sqrt(pow(dx, 2.)+pow(dy, 2.));
if (distance <= sigma) {
totalEnergy+= k*pow((sigma-distance)/(2.*a), 2.);
}
}
}
return totalEnergy;
}
The particles vector is a vector in which all the x,y positions of every particle are written one after another
Furthermore I wrote an energy function which draws the overlap as a feather energy.
The powell routine shall minimize the energy to find an optimal configuration. At first sight, it does, but when I let the program show me the forces on every particle, these are not all equal zero. It turns out that the circles at the left and bottom border are those particles with net force != 0.
Does anyone have an idea? All that I do is giving the function to calculate the energy, isn't it?
double TotalEnergy(VecDoub_I &particles)
{
double totalEnergy = 0.;
double distance;
double k = federkonstante;
int N = 3*amount;
double dx,dy;
double sigma=100;
for (int i=0; i<N; i+=3) {
for (int j=0; j<N; j+=3) {
dx = particles[j]-particles[i];
dy = particles[j+1]-particles[i+1];
while (dx < -X_MAX/2) dx = X_MAX + dx;
while (dx > X_MAX/2) dx = X_MAX - dx;
while (dy > Y_MAX/2) dy = Y_MAX - dy;
while (dy < -Y_MAX/2) dy = Y_MAX + dy;
distance = sqrt(pow(dx, 2.)+pow(dy, 2.));
if (distance <= sigma) {
totalEnergy+= k*pow((sigma-distance)/(2.*a), 2.);
}
}
}
return totalEnergy;
}
The particles vector is a vector in which all the x,y positions of every particle are written one after another