Advertisement
demeshko0

Untitled

Nov 21st, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. class MD {
  5.     std::string s;
  6.     std::ifstream f;
  7.     std::ofstream fout;
  8.     double x_min;
  9.     double x_max;
  10.     double y_min;
  11.     double y_max;
  12.     int index;
  13.     double *x;
  14.     double *y;
  15.     double *rho;
  16.     int N;
  17.     int N_dx = 100;
  18. public:
  19.     MD(std::string fname);
  20.     ~MD();
  21.     void read_head();
  22.     void read_state();
  23.     void obr_state();
  24.     void dump(int, std::string);
  25. };
  26. MD::MD(std::string fname){
  27.     f.open(fname);
  28.     read_head();
  29.     x=new double[N];
  30.     y=new double[N];
  31.     rho = new double [N_dx];
  32.     read_state();
  33. }
  34. MD::~MD(){
  35.     delete [] x;
  36.     delete [] y;
  37.     delete [] rho;
  38.     f.close();
  39. }
  40.  
  41.  
  42. void MD::read_head ()
  43. {
  44.     int n;
  45.     f>>s;f>>s;
  46.     f>>s;
  47.     f>>s;f>>s;f>>s;f>>s;
  48.     f>>n;                               // number of atoms
  49.     f>>s;f>>s;f>>s;f>>s;f>>s;f>>s;
  50.     f>>x_min;                           // chtenie razmerov
  51.     f>>x_max;                           // chtenie razmerov
  52.     f>>y_min;                           // chtenie razmerov
  53.     f>>y_max;  
  54.     f>>s;f>>s;
  55.     f>>s;f>>s;f>>s;f>>s;f>>s;
  56.     N=n;
  57. }
  58.  
  59. void MD::read_state (){
  60.    
  61.     for (int i=0; i<N; i++){
  62.         f>>index;
  63.         f>>x[index];
  64.         f>>y[index];
  65.     }
  66.  
  67. }
  68.  
  69. void MD::obr_state(){
  70.     double X;
  71.     double Y;
  72.     double dx;
  73.  
  74.     X=(x_max-x_min);
  75.     Y=(y_max-y_min);
  76.     dx= X/N_dx;                
  77.    
  78.     for (int i=0;i<N;i++){
  79.        auto id = static_cast<int>((x[1]-x_min)/dx);
  80.        if (id<X) rho[id]++;
  81.     }
  82. }
  83.  
  84. void MD::dump(int n, std::string folname){
  85.     std::string num = std::to_string(n);
  86.     std::string fname_out = folname + "\\dump" + num + ".txt";
  87.     std::ofstream fout(fname_out);
  88.     for (int i=0; i<N_dx; i++){
  89.         fout << rho[i];
  90.         fout << "\n";
  91.     }
  92.     fout.close();
  93. }
  94.  
  95. int main()
  96. {
  97.     std::string Filename = "dump.melt";
  98.     std::string Foldername = "f_out";
  99.  
  100.     MD Melt(Filename);
  101.     int N_times = 1000;
  102.  
  103.     for (int i=0; i<N_times; i++){
  104.         Melt.read_head();
  105.         Melt.read_state ();
  106.         Melt.obr_state ();
  107.         Melt.dump(i, Foldername);
  108.     }
  109.  
  110.     std::cout<< "done";
  111.     return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement