Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- class MD {
- std::string s;
- std::ifstream f;
- std::ofstream fout;
- double x_min;
- double x_max;
- double y_min;
- double y_max;
- int index;
- double *x;
- double *y;
- double *rho;
- int N;
- int N_dx = 100;
- public:
- MD(std::string fname);
- ~MD();
- void read_head();
- void read_state();
- void obr_state();
- void dump(int, std::string);
- };
- MD::MD(std::string fname){
- f.open(fname);
- read_head();
- x=new double[N];
- y=new double[N];
- rho = new double [N_dx];
- read_state();
- }
- MD::~MD(){
- delete [] x;
- delete [] y;
- delete [] rho;
- f.close();
- }
- void MD::read_head ()
- {
- int n;
- f>>s;f>>s;
- f>>s;
- f>>s;f>>s;f>>s;f>>s;
- f>>n; // number of atoms
- f>>s;f>>s;f>>s;f>>s;f>>s;f>>s;
- f>>x_min; // chtenie razmerov
- f>>x_max; // chtenie razmerov
- f>>y_min; // chtenie razmerov
- f>>y_max;
- f>>s;f>>s;
- f>>s;f>>s;f>>s;f>>s;f>>s;
- N=n;
- }
- void MD::read_state (){
- for (int i=0; i<N; i++){
- f>>index;
- f>>x[index];
- f>>y[index];
- }
- }
- void MD::obr_state(){
- double X;
- double Y;
- double dx;
- X=(x_max-x_min);
- Y=(y_max-y_min);
- dx= X/N_dx;
- for (int i=0;i<N;i++){
- auto id = static_cast<int>((x[1]-x_min)/dx);
- if (id<X) rho[id]++;
- }
- }
- void MD::dump(int n, std::string folname){
- std::string num = std::to_string(n);
- std::string fname_out = folname + "\\dump" + num + ".txt";
- std::ofstream fout(fname_out);
- for (int i=0; i<N_dx; i++){
- fout << rho[i];
- fout << "\n";
- }
- fout.close();
- }
- int main()
- {
- std::string Filename = "dump.melt";
- std::string Foldername = "f_out";
- MD Melt(Filename);
- int N_times = 1000;
- for (int i=0; i<N_times; i++){
- Melt.read_head();
- Melt.read_state ();
- Melt.obr_state ();
- Melt.dump(i, Foldername);
- }
- std::cout<< "done";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement