Skip to content

Commit 984cf97

Browse files
committed
add update_vel for ucell
1 parent 6e9f01d commit 984cf97

File tree

8 files changed

+39
-24
lines changed

8 files changed

+39
-24
lines changed

source/module_cell/atom_spec.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ class Atom
3434

3535
std::string label = "\0"; // atomic symbol
3636
std::vector<ModuleBase::Vector3<double>> tau; // Cartesian coordinates of each atom in this type.
37-
std::vector<ModuleBase::Vector3<double>>
38-
dis; // direct displacements of each atom in this type in current step liuyu modift 2023-03-22
37+
std::vector<ModuleBase::Vector3<double>> dis; // direct displacements of each atom in this type in current step liuyu modift 2023-03-22
3938
std::vector<ModuleBase::Vector3<double>> taud; // Direct coordinates of each atom in this type.
4039
std::vector<ModuleBase::Vector3<double>> vel; // velocities of each atom in this type.
4140
std::vector<ModuleBase::Vector3<double>> force; // force acting on each atom in this type.

source/module_cell/test/support/mock_unitcell.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ bool UnitCell::read_atom_positions(std::ifstream& ifpos,
3434
return true;
3535
}
3636

37-
void UnitCell::update_vel(const ModuleBase::Vector3<double>* vel_in) {}
3837
bool UnitCell::judge_big_cell() const { return true; }
3938
void UnitCell::update_stress(ModuleBase::matrix& scs) {}
4039
void UnitCell::update_force(ModuleBase::matrix& fcs) {}

source/module_cell/test/unitcell_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ TEST_F(UcellTest, UpdateVel)
10211021
{
10221022
vel_in[iat].set(iat * 0.1, iat * 0.1, iat * 0.1);
10231023
}
1024-
ucell->update_vel(vel_in);
1024+
unitcell::update_vel(vel_in,ucell->ntype,ucell->nat,ucell->atoms);
10251025
for (int iat = 0; iat < ucell->nat; ++iat)
10261026
{
10271027
EXPECT_DOUBLE_EQ(vel_in[iat].x, 0.1 * iat);

source/module_cell/unitcell.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -314,18 +314,6 @@ std::vector<ModuleBase::Vector3<int>> UnitCell::get_constrain() const
314314
return constrain;
315315
}
316316

317-
void UnitCell::update_vel(const ModuleBase::Vector3<double>* vel_in) {
318-
int iat = 0;
319-
for (int it = 0; it < this->ntype; ++it) {
320-
Atom* atom = &this->atoms[it];
321-
for (int ia = 0; ia < atom->na; ++ia) {
322-
this->atoms[it].vel[ia] = vel_in[iat];
323-
++iat;
324-
}
325-
}
326-
assert(iat == this->nat);
327-
}
328-
329317
//==============================================================
330318
// Calculate various lattice related quantities for given latvec
331319
//==============================================================

source/module_cell/unitcell.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ class UnitCell {
200200
void print_cell(std::ofstream& ofs) const;
201201
void print_cell_xyz(const std::string& fn) const;
202202

203-
void update_vel(const ModuleBase::Vector3<double>* vel_in);
204203
bool judge_big_cell() const;
205204

206205
void update_stress(ModuleBase::matrix& scs); // updates stress

source/module_cell/update_cell.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,24 @@ void update_pos_taud(const Lattice& lat,
425425
bcast_atoms_tau(atoms, ntype);
426426
}
427427

428+
void update_vel(const ModuleBase::Vector3<double>* vel_in,
429+
const int ntype,
430+
const int nat,
431+
Atom* atoms)
432+
{
433+
int iat = 0;
434+
for (int it = 0; it < ntype; ++it)
435+
{
436+
Atom* atom = &atoms[it];
437+
for (int ia = 0; ia < atom->na; ++ia)
438+
{
439+
atoms[it].vel[ia] = vel_in[iat];
440+
++iat;
441+
}
442+
}
443+
assert(iat == nat);
444+
}
445+
428446
void periodic_boundary_adjustment(Atom* atoms,
429447
const ModuleBase::Matrix3& latvec,
430448
const int ntype)

source/module_cell/update_cell.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,23 @@ namespace unitcell
7373
* @param nat: the number of atoms [in]
7474
* @param atoms: the atoms to be updated [out]
7575
*/
76-
void update_pos_taud(const Lattice& lat,
77-
const ModuleBase::Vector3<double>* posd_in,
78-
const int ntype,
79-
const int nat,
80-
Atom* atoms);
76+
void update_pos_taud(const Lattice& lat,
77+
const ModuleBase::Vector3<double>* posd_in,
78+
const int ntype,
79+
const int nat,
80+
Atom* atoms);
81+
/**
82+
* @brief update the velocity of the atoms
83+
*
84+
* @param vel_in: the velocity of the atoms [in]
85+
* @param ntype: the number of types of the atoms [in]
86+
* @param nat: the number of atoms [in]
87+
* @param atoms: the atoms to be updated [out]
88+
*/
89+
void update_vel(const ModuleBase::Vector3<double>* vel_in,
90+
const int ntype,
91+
const int nat,
92+
Atom* atoms);
8193
}
8294
//
8395
#endif // UPDATE_CELL_H

source/module_md/run_md.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "msst.h"
1111
#include "nhchain.h"
1212
#include "verlet.h"
13-
13+
#include "module_cell/update_cell.h"
1414
namespace Run_MD
1515
{
1616

@@ -97,7 +97,7 @@ void md_line(UnitCell& unit_in, ModuleESolver::ESolver* p_esolver, const Paramet
9797

9898
if ((mdrun->step_ + mdrun->step_rst_) % param_in.mdp.md_restartfreq == 0)
9999
{
100-
unit_in.update_vel(mdrun->vel);
100+
unitcell::update_vel(mdrun->vel,unit_in.ntype,unit_in.nat,unit_in.atoms);
101101
std::stringstream file;
102102
file << PARAM.globalv.global_stru_dir << "STRU_MD_" << mdrun->step_ + mdrun->step_rst_;
103103
// changelog 20240509

0 commit comments

Comments
 (0)