Guest User

Untitled

a guest
Feb 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <math.h>
  5. #include <algorithm>
  6. #include <boost/random/linear_congruential.hpp>
  7. #include <boost/random/uniform_int.hpp>
  8. #include <boost/random/uniform_real.hpp>
  9. #include <boost/random/variate_generator.hpp>
  10. #include <boost/random/mersenne_twister.hpp>
  11. #include <boost/random/normal_distribution.hpp>
  12. // constnatns (attractive)
  13. #define jump 0.05//this is how many time steps it takes to change alpha,for the radicle jump this is twice this size
  14. #define time_jump 100
  15. #define N 100 //number of particles
  16. #define time_end 10000
  17. #define ensambles 1
  18.  
  19. //int time_end=100000;
  20. using namespace std;
  21. typedef boost::mt19937 base_generator_type;
  22. typedef boost::variate_generator< base_generator_type&, boost::uniform_int<> > gen_type;
  23. typedef boost::variate_generator< base_generator_type&, boost::uniform_real<> > gen_type1;
  24.  
  25. //defning the random numbers generators
  26. unsigned int s=time(NULL);
  27. base_generator_type generator(s);
  28. boost::uniform_real<> uni_distq(0,1);
  29. gen_type1 uniq( generator, uni_distq );
  30. boost::uniform_int<> uni_dist(0,N-1);
  31. gen_type uni( generator, uni_dist );
  32.  
  33. void dissipation(double energy[][5][time_end],int n1,int n2,int i,int t,double alpha){
  34. double temp;
  35. temp=energy[n1][i][t]+energy[n2][i][t];
  36. double z=uniq();
  37. energy[n1][i][t]=z*alpha*temp;
  38. energy[n2][i][t]=(1-z)*alpha*temp;
  39. for(int k=0;k<N;k++){if(k!=n1 &&k!=n2)
  40. energy[k][i][t]+=(1-alpha)*temp/(N-2);
  41. }
  42. }
  43. void print_alpha(double energy[][5][time_end],int i,int t){
  44. string f_type = "alpha.txt";
  45. char f_name[8];
  46. sprintf(f_name,"%02d",i);
  47. string file = f_name + f_type;
  48. ofstream myfile ( file.c_str() );
  49. for(int k=0;k<N;k++)
  50. myfile<<(double) energy[k][i][t]<<" ";
  51. myfile.close();
  52. }
  53. void alpha_change(double *alpha,t){
  54. if((max(t,100) % min(t,100))==0){
  55. *alpha[0]+=jump;
  56. *alpha[2]=uniq();
  57. }
  58. if((max(t,150) % min(t,150))==0){
  59. cout<<t<<" the current time "<<endl;
  60. *alpha[1]+=0.06*jump;
  61. *alpha[3]=0.3*alpha[2];
  62. for(int g=0;g<5;g++)
  63. print_alpha(energy,g,t);
  64. }
  65. int main(int argc, char *argv[]){
  66.  
  67. for(int n=0; n<ensambles ; n++) { //ensambles
  68. //prepering the paramters and the files output;
  69. double energy[N][5][time_end]; /* 0&1-dist slow/fast,2&3-rand slow/fast,4-boltzman*/
  70. double alpha[4];
  71. //giving them the inital energy
  72. for(int j=0;j<5;j++){
  73. alpha[j]=0;
  74. for(int i=0;i<N;i++)
  75. energy[i][j][0]=1;
  76. }
  77. for(int t=0;t<time_end;t++)
  78. { //time
  79. //getting the particles
  80. int n1=uni();
  81. int n2=uni();
  82. if(n1==n2){
  83. if(n1==N)
  84. n2=N-uni();
  85. else
  86. n2=abs(n1-N);
  87. }
  88. //the disspation procceses
  89. for(int i=0;i<5;i++){
  90. dissipation(energy,n1,n2,i,t,alpha[i]);
  91. }
  92. //changing the alpha
  93. alpha_change(alpha,t);
  94.  
  95. } //time
  96.  
  97. } //ensambles
  98. system("pause");
  99. return EXIT_SUCCESS;
  100.  
  101. } ;
Add Comment
Please, Sign In to add comment