Skip to content

Instantly share code, notes, and snippets.

@nervoussystem
Created June 8, 2010 00:55
Show Gist options
  • Save nervoussystem/429453 to your computer and use it in GitHub Desktop.
Save nervoussystem/429453 to your computer and use it in GitHub Desktop.
float FNext[][] = new float[F.length][F[0].length];
float r = deltaT*diffusionRate/deltaXSq;
for(int i=0;i<F.length;++i) {
for(int j=0;j<F[0].length;++j) {
//get the neighboring values with boundary conditions
float iPrev, iNext, jNext, jPrev;
if(i==0) iPrev = F[i][j];
else iPrev = F[i-1][j];
if(i==F.length-1) iNext = F[i][j];
else iNext = F[i+1][j];
if(j==0) jPrev = F[i][j];
else jPrev = F[i][j-1];
if(j==F[0].length-1) jNext = F[i][j];
else jNext = F[i][j+1];
//Dufort-Frankel step
FNext[i][j] = (1-2*r)/(1+2*r)*(FPrev[i][j])+r/(1+2*r)*(iPrev+iNext+jPrev+jNext);
}
}
FPrev = F;
F = FNext;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment