code_junkie

Algorithm for modeling expanding gases on a 2D grid

Nov 13th, 2011
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. begin loop forever
  2. For every x and y
  3. {
  4. b2[x,y] = (b1[x,y] + (b1[x+1,y]+b1[x-1,y]+b1[x,y+1]+b1[x,y-1])/8) / 2
  5. }
  6. swap b1 and b2
  7. end loop forever
  8.  
  9. concentration = startingConcentration/(2*iter + 1)**2
  10.  
  11. startingConcentration = 9
  12. iter = 0
  13. concentration = 9/(2*0 + 1)**2 = 9
  14.  
  15. iter = 1
  16. concentration = 9/(2*1 + 1)**2 = 1
  17.  
  18. iter = 2
  19. concentration = 9/(2*2 + 1)**2 = 9/25 = .35
Add Comment
Please, Sign In to add comment