Imagine that you have a particle in each coordinate of a 2D Cartesian plane. Each particle emits a substance that difuses in all directions, with a decay over distance based on a Bessel function, and the other particles each absorb this substance. Thus all particles at same distance from a given particle have the same influence on that particle. Something such as
I'm calculating such an interaction using this code:
EDIT:24/03
void acoplamento(int x, int y, double **xold,double *Acopl,double **Bess)
{
int j, i, h, k,xdist, ydist;
Nmeio=N/2;
for (i=0; i<=N; i++) {
for(j=0; j<=N; j++) {
h = x + i;
k = y + j;
ydist = j;
xdist = i;
if(i>Nmeio){
h = x +i;
xdist = (N+1) -h +x;
}
if (h>N) {
h = h-(N+1);
xdist = x-h;
if (xdist >Nmeio) {
xdist = i;
}
}
if (j > Nmeio) {
k = y +j;
ydist = (N+1) -k +y;
}
if (k > N) {
k = k-(N+1);
ydist = y-k;
if(ydist >Nmeio) {
ydist = j;
}
}
if (ydist!=0 || xdist!=0) {
X = X + Bess[xdist][ydist]*xold[h][k];
}
}
}
*Acopl = X;
}
And where i call this function.
for(t=0;t<=tmax;t++){
for(x=0;x<=N;x++){
for(y=0;y<=N;y++){
acoplamento(x,y,xold,&acopl,Bess);
xnew[x][y] = (a[x][y]/(1+xold[x][y]*xold[x][y])) +yold[x][y] + epsilon*C*acopl;
ynew[x][y] = yold[x][y] - sigma*xold[x][y] - beta;
xold[x][y] = xnew[x][y];
yold[x][y] = ynew[x][y];
}
}
}
Of course, have much more lines on my program, but the main core it is.
Bess[N][N] is the Bessel function for each radius.
The problem is that this is very slow for my target 70x70 system, and I want to know whether there is a way to modify it to improve its performance. I think if i can rewrite this without using if and else, will reduced the computational time.
Aucun commentaire:
Enregistrer un commentaire