From 447243d38fea6bb348a90568c7712b58124ce4dd Mon Sep 17 00:00:00 2001 From: YuLiu Date: Tue, 13 Jul 2021 17:34:55 +0800 Subject: [PATCH 1/2] add velocity in STRU --- source/module_cell/atom_spec.cpp | 2 ++ source/module_cell/atom_spec.h | 1 + source/module_cell/read_atoms.cpp | 10 ++++++ source/module_md/MD_basic.cpp | 13 ++++++- source/module_md/run_md_classic.cpp | 54 +++++++++++++++++++++++++++-- source/module_md/run_md_classic.h | 8 +++++ 6 files changed, 84 insertions(+), 4 deletions(-) diff --git a/source/module_cell/atom_spec.cpp b/source/module_cell/atom_spec.cpp index b3210dc03e..b50cf3ac33 100644 --- a/source/module_cell/atom_spec.cpp +++ b/source/module_cell/atom_spec.cpp @@ -13,6 +13,7 @@ Atom::Atom() stapos_wf = 0; tau = new Vector3[1]; taud = new Vector3[1]; + vel = new Vector3[1]; mag = new double[1]; l_nchi = new int[1]; iw2l = new int[1]; @@ -26,6 +27,7 @@ Atom::~Atom() { delete[] tau; delete[] taud; + delete[] vel; delete[] mag; delete[] l_nchi; delete[] iw2l; diff --git a/source/module_cell/atom_spec.h b/source/module_cell/atom_spec.h index 91635fc676..1b7ae470c1 100644 --- a/source/module_cell/atom_spec.h +++ b/source/module_cell/atom_spec.h @@ -33,6 +33,7 @@ class Atom: public Atom_pseudo string label; // atomic symbol Vector3 *tau;// Cartesian coordinates of each atom in this type. Vector3 *taud;// Direct coordinates of each atom in this type. + Vector3 *vel;// velocities of each atom in this type. double* mag; double angle1;//spin angle, added by zhengdy-soc diff --git a/source/module_cell/read_atoms.cpp b/source/module_cell/read_atoms.cpp index 49b15c1a13..649ed64e40 100644 --- a/source/module_cell/read_atoms.cpp +++ b/source/module_cell/read_atoms.cpp @@ -398,10 +398,12 @@ bool UnitCell_pseudo::read_atom_positions(ifstream &ifpos) { delete[] atoms[it].tau; delete[] atoms[it].taud; + delete[] atoms[it].vel; delete[] atoms[it].mbl; delete[] atoms[it].mag; atoms[it].tau = new Vector3[na]; atoms[it].taud = new Vector3[na]; + atoms[it].vel = new Vector3[na]; atoms[it].mbl = new Vector3[na]; atoms[it].mag = new double[na]; atoms[it].mass = this->atom_mass[it]; //mohan add 2011-11-07 @@ -436,6 +438,14 @@ bool UnitCell_pseudo::read_atom_positions(ifstream &ifpos) { ifpos >> v.x >> v.y >> v.z >> mv.x >> mv.y >> mv.z; + if(CALCULATION=="md" && INPUT.mdp.md_potential) + { + ifpos >> atoms[it].vel[ia].x >> atoms[it].vel[ia].y >> atoms[it].vel[ia].z; + } + else + { + atoms[it].vel[ia].set(0,0,0); + } string mags; std::getline( ifpos, mags ); // change string to double. diff --git a/source/module_md/MD_basic.cpp b/source/module_md/MD_basic.cpp index 881c70cf6b..805eb4e6fd 100644 --- a/source/module_md/MD_basic.cpp +++ b/source/module_md/MD_basic.cpp @@ -22,7 +22,18 @@ MD_basic::MD_basic(MD_parameters& MD_para_in, UnitCell_pseudo &unit_in): step_=0; // ucell.latvec=ucell.latvec; - vel=new Vector3[ucell.nat]; + vel=new Vector3[ucell.nat]; //initialize velocity of atoms from STRU Yu Liu 2021-07-14 + int iat=0; + for(int it=0; it[ucell.nat]; tauDirectChange=new Vector3[ucell.nat]; allmass=new double[ucell.nat]; diff --git a/source/module_md/run_md_classic.cpp b/source/module_md/run_md_classic.cpp index b48ff07392..cf296b053e 100644 --- a/source/module_md/run_md_classic.cpp +++ b/source/module_md/run_md_classic.cpp @@ -1,14 +1,62 @@ #include "run_md_classic.h" +#include "MD_basic.h" +#include "../src_pw/global.h" Run_MD_CLASSIC::Run_MD_CLASSIC() -{} +{ + pos_old1 = new double[1]; + pos_old2 = new double[1]; + pos_now = new double[1]; + pos_next = new double[1]; +} Run_MD_CLASSIC::~Run_MD_CLASSIC() -{} +{ + delete[] pos_old1; + delete[] pos_old2; + delete[] pos_now; + delete[] pos_next; +} void Run_MD_CLASSIC::md_cells_classic(void) { - cout << "Classic MD !!" << endl; + TITLE("Run_MD_CLASSIC", "md_cells_classic"); + timer::tick("Run_MD_CLASSIC", "md_cells_classic"); + + this->md_allocate_ions(); + + MD_basic mdb(INPUT.mdp, ucell); + int mdtype = INPUT.mdp.mdtype; + + this->istep = 1; + bool stop = false; + + while (istep <= NSTEP && !stop) + { + cout << "Step: " << istep << endl; + } + + timer::tick("Run_MD_CLASSIC", "md_cells_classic"); return; +} + +void Run_MD_CLASSIC::md_allocate_ions(void) +{ + pos_dim = ucell.nat * 3; + + delete[] this->pos_old1; + delete[] this->pos_old2; + delete[] this->pos_now; + delete[] this->pos_next; + + this->pos_old1 = new double[pos_dim]; + this->pos_old2 = new double[pos_dim]; + this->pos_now = new double[pos_dim]; + this->pos_next = new double[pos_dim]; + + ZEROS(pos_old1, pos_dim); + ZEROS(pos_old2, pos_dim); + ZEROS(pos_now, pos_dim); + ZEROS(pos_next, pos_dim); } \ No newline at end of file diff --git a/source/module_md/run_md_classic.h b/source/module_md/run_md_classic.h index b1781d7dcd..ece06cbdb0 100644 --- a/source/module_md/run_md_classic.h +++ b/source/module_md/run_md_classic.h @@ -10,8 +10,16 @@ class Run_MD_CLASSIC ~Run_MD_CLASSIC(); void md_cells_classic(void); + void md_allocate_ions(void); + private: + int istep; + double* pos_old1; + double* pos_old2; + double* pos_now; + double* pos_next; + int pos_dim; }; From 2cbdc263d43b8b1cf2bf59ef5e1bcaacc468eebb Mon Sep 17 00:00:00 2001 From: YuLiu Date: Wed, 14 Jul 2021 16:48:45 +0800 Subject: [PATCH 2/2] classic md --- source/module_cell/read_atoms.cpp | 18 ++++++++- source/module_cell/unitcell_pseudo.cpp | 1 - source/module_md/run_md.cpp | 15 ++++++- source/module_md/run_md.h | 1 - source/module_md/run_md_classic.cpp | 54 ++++++++++++++++++++++++-- source/module_md/run_md_classic.h | 4 ++ 6 files changed, 84 insertions(+), 9 deletions(-) diff --git a/source/module_cell/read_atoms.cpp b/source/module_cell/read_atoms.cpp index 649ed64e40..ebf6b2a2f6 100644 --- a/source/module_cell/read_atoms.cpp +++ b/source/module_cell/read_atoms.cpp @@ -685,7 +685,8 @@ void UnitCell_pseudo::print_stru_file(const string &fn, const int &type)const for(int ia=0; iaupdate_pos_classic(); + + time_t eend = time(NULL); + time_t fstart = time(NULL); + + if (mdtype == 1 || mdtype == 2) + { + mdb.runNVT(istep); + } + else if (mdtype == 0) + { + mdb.runNVE(istep); + } + else if (mdtype == -1) + { + stop = mdb.runFIRE(istep); + } + else + { + WARNING_QUIT("md_cells_classic", "mdtype should be -1~2!"); + } + + time_t fend = time(NULL); + ucell.save_cartesian_position(this->pos_next); + + ++istep; + } timer::tick("Run_MD_CLASSIC", "md_cells_classic"); return; @@ -59,4 +96,15 @@ void Run_MD_CLASSIC::md_allocate_ions(void) ZEROS(pos_old2, pos_dim); ZEROS(pos_now, pos_dim); ZEROS(pos_next, pos_dim); +} + +void Run_MD_CLASSIC::update_pos_classic(void) +{ + for(int i=0;ipos_old2[i] = this->pos_old1[i]; + this->pos_old1[i] = this->pos_now[i]; + } + ucell.save_cartesian_position(this->pos_now); + return; } \ No newline at end of file diff --git a/source/module_md/run_md_classic.h b/source/module_md/run_md_classic.h index ece06cbdb0..841b102a98 100644 --- a/source/module_md/run_md_classic.h +++ b/source/module_md/run_md_classic.h @@ -2,6 +2,7 @@ #define RUN_MD_CLASSIC_H #include "../src_pw/tools.h" +#include "../module_neighbor/sltk_grid_driver.h" class Run_MD_CLASSIC { @@ -9,8 +10,11 @@ class Run_MD_CLASSIC Run_MD_CLASSIC(); ~Run_MD_CLASSIC(); + Grid_Driver grid_neigh; + void md_cells_classic(void); void md_allocate_ions(void); + void update_pos_classic(void); private: