Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //*************Ising Model Viewing***********************//
  2.  
  3. /* ISING MODEL
  4.  *
  5.  * Michael Stefferson
  6.  * Independent Study PHYS 492
  7.  * Advisor: D. Toussaint
  8.  * January 21, 2011
  9.  *
  10.  * Compiling: gcc -o isingmodel_view isingmodel_view.c /usr4/mws2/ISING/animation/libanimation.a -lX11 -lm
  11.  *
  12.  */
  13.  
  14. #include <stdio.h>
  15. #include <math.h>
  16. #include <stdlib.h>
  17. //#include "/usr4/mws2/ISING/animation/animation.h"
  18.  
  19. #define MAX_PARTICLES 64
  20.  
  21. double probab(double E);
  22. /*
  23. int n_particles;
  24.  
  25. float x[MAX_PARTICLES], y[MAX_PARTICLES], spin[MAX_PARTICLES];
  26. float LX, LY;
  27.  
  28. float dt, mytime, tmax;
  29.  
  30. int n_particles;
  31. */
  32.                                
  33. int main(void)
  34. {
  35.  
  36. int n_particles;
  37.  
  38. float x[MAX_PARTICLES], y[MAX_PARTICLES], spin[MAX_PARTICLES];
  39. float LX, LY;
  40.  
  41. float dt, mytime, tmax;
  42.  
  43.  
  44.   int atoms1D = 8, elements;
  45.  
  46.   // int atoms1D = sqrt(atoms1D);
  47.   int particle[atoms1D][atoms1D], part_position[atoms1D][atoms1D];
  48.   int i,j, k, k_end, R, l, t, b;
  49.  
  50.   //If I want to vary individual parameters
  51.   double kb, J, T, B;
  52.   int spinup = 1, spindown = -1, tot_spinup, tot_spindown, mag_spins, magnet_count;
  53.   double probE,energy, probup, R, aver_magnet, aver_energy;
  54.   int iter, counter, iter_end, iter_count;
  55.   int seed = 4;
  56.   int method;
  57.  
  58.   //animation
  59.   int anim_i;
  60.  
  61.  
  62.  
  63.   srand48(seed);
  64.  
  65.   //fprintf(stderr,"What do you want from me?\n1: matrices\n2: interations vs. max spin percent\n3: M vs. B\n4: M vs T (~1/B)\n5: Average E vs  B\n6: Average E vs. T\n");
  66.  
  67.   // scanf("%d", &method);
  68.  
  69.  
  70.  tot_spinup = 0;
  71.  tot_spindown = 0;
  72.  elements = 0;
  73.  mag_spins = 0;
  74.  
  75.  
  76.  n_particles = 64;
  77.  LX =  1.0;
  78.  LY = 1.0;
  79.  dt = 0.005;
  80.  
  81.  x[0] = 0; y[0] = 0;
  82.  
  83.  //position stuff
  84.  for(i = 1; i < n_particles; i++){
  85.      if( i % atoms1D == 0 ){
  86.        i == 0;
  87.      }
  88.      x[i] = (double)i * LX / atoms1D;
  89.    }
  90.  for(i = 1; i < n_particles; i++){
  91.    if( i % atoms1D == 0 ){
  92.      i == 0;
  93.    }
  94.    y[i] = (double)i *  LY / atoms1D;
  95.  }
  96.  
  97.  
  98.  /*
  99.  //position stuff
  100.  for(i = 1; i < n_particles; i++){
  101.    for(j = 1; j < n_particles; j++){
  102. posi
  103.  */
  104.  
  105.  
  106. //animation stuff
  107. //animation_start( 0.0, LX, 0.0, LY );
  108. //anim_i = add_many_particles(n_particles, x, y);
  109. //set_clock_tick(dt * 10.0);
  110. tmax = 500;
  111.  
  112.  
  113.   //initialize spins
  114.   for(i = 0; i < atoms1D; i++){
  115.     for(j = 0; j < atoms1D; j++){
  116.       tot_spinup ++;
  117.       elements ++;
  118.       particle[i][j] = spinup;
  119.       mag_spins += particle[i][j];
  120.       // printf("mag spins: %d", mag_spins);
  121.     }
  122.   }
  123.  
  124.  
  125.  
  126.   counter = 0 ;
  127.  
  128.   for(mytime = 0; mytime <= tmax; mytime += dt){
  129.   //right, left, above, below. periodic B.C.
  130.    
  131.     tot_spinup = 0;
  132.     tot_spindown = 0;
  133.     elements = 0;
  134.     mag_spins = 0;
  135.  
  136.  
  137.     for(i = 0; i < atoms1D; i++){    
  138.       for(j = 0; j < atoms1D; j++){
  139.     //energy/kbT for the ith, jth component. Average the neighbors.
  140.    
  141.     R = i + 1;
  142.     l = i - 1;
  143.     t = j + 1;
  144.     b = j - 1;
  145.  
  146.       //left edge
  147.     if( i == 0 )
  148.     {
  149.       l = atoms1D - 1;
  150.     }
  151.     //bottom edge
  152.     if( j == 0 )
  153.       {
  154.         b = atoms1D - 1;
  155.       }
  156.    
  157.     //right
  158.     if( i == (atoms1D - 1))
  159.       {
  160.         R = 0;
  161.       }
  162.    
  163.     //top
  164.     if( j == (atoms1D - 1) )
  165.       {
  166.         t = 0;
  167.       }
  168.    
  169.  
  170.     probE = -B  *( (double)particle[R][j] + (double)particle[l][j] + (double)particle[i][t] +  (double)particle[i][b] );
  171.    
  172.     probup = probab(probE);
  173.      
  174.       //  printf("E: %lf probup: %lf\n",E, probup);
  175.      
  176.       //monte carlo
  177.       R = drand48();
  178.      
  179.       //  printf("E: %lf probup: %lf R: %lf \n",E, probup, R);
  180.      
  181.       if(R <= probup){
  182.     particle[i][j] = spinup;
  183.       }
  184.       if(R > probup){
  185.     particle[i][j] = spindown;
  186.       }
  187.     mag_spins += particle[i][j];
  188.     //  printf("particle: %d mag_spins: %d\n", particle[i][j], mag_spins);
  189.       }
  190.     }// end spin determine LOOP
  191.  
  192.     i = 0; j = 0;
  193.     for(k = 0; k < n_particles; k++){
  194.       printf("%d %d\n", i,j);
  195.       spin[k] = particle[i][j];
  196.       printf("k: %d  spin:%d particle[%d][%d]: %d %d %d\n", k, spin[k], i, j, particle[i][j], i, j);
  197.       i ++;
  198.       if(i % atoms1D == 0){
  199.         j ++;
  200.         i = 0;
  201.       }
  202.     }
  203.    
  204.     // move_many_particles(n_particles, anim_i, x, y);
  205.  
  206.  
  207.     //animation
  208.  
  209.     for(i = 0; i < atoms1D; i++){
  210.       if(spin[k] == spinup){
  211.     printf("c %f %f 1\n", x[i], y[i]);
  212.       }
  213.  
  214.   if(spin[k] == spindown){
  215.     printf("d %f %f 1\n", x[i], y[i]);
  216.       }
  217.     }
  218.     printf("F/n");
  219.   }//end time LOOP
  220.  
  221.   return 0;
  222. }//end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement