SHARE
TWEET

Untitled

a guest Oct 29th, 2019 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. config const n = 6, epsilon = 1.0e-5, p = 2.0, t = 10.0;
  2.  
  3. const BigD = {0..n+1, 0..n+1},
  4. D = BigD[1..n, 1..n];
  5.  
  6. var A, Temp : [BigD] real;
  7. var red_odd: sparse subdomain(D);
  8. var red_even: sparse subdomain(D);
  9. var red: sparse subdomain(D);
  10.  
  11. red_odd+= {1..n, 1..n} by 2 align (1,1);
  12. red_even+= {1..n, 1..n} by 2 align (2,2);
  13. red = red_odd + red_even;
  14.  
  15. var black_odd: sparse subdomain(D);
  16. var black_even: sparse subdomain(D);
  17. var black: sparse subdomain(D);
  18.  
  19. black_odd+= {1..n, 1..n} by 2 align (1,2);
  20. black_even+= {1..n, 1..n} by 2 align (2,1);
  21. black= black_odd + black_even;
  22.  
  23. do {
  24.     forall (i, j) in red do
  25.         A[i,j] = (A[i-1,j] + A[i+1,j] + A[i,j-1] + A[i,j+1] + p/t ) / 4;
  26.     forall (i, j) in black do
  27.         A[i,j] = (A[i-1,j] + A[i+1,j] + A[i,j-1] + A[i,j+1] + p/t ) / 4;
  28.  
  29.     const delta = max reduce abs(A[D] - Temp[D]);
  30.     Temp[D] = A[D];
  31.    
  32. } while (delta > epsilon);
  33.  
  34. writeln(A);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top