Skip to content

Commit

Permalink
Fix: Remove redundant vdw calculations (#1487)
Browse files Browse the repository at this point in the history
* Fix: Remove redundant vdw calculations

* Vdw: Add timer
  • Loading branch information
xinyangd committed Nov 9, 2022
1 parent 7df238e commit 7fd881d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
7 changes: 7 additions & 0 deletions source/module_vdw/vdwd2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
//==========================================================

#include "module_vdw/vdwd2.h"
#include "module_base/timer.h"

namespace vdw
{

void Vdwd2::cal_energy()
{
ModuleBase::TITLE("Vdwd2", "energy");
ModuleBase::timer::tick("Vdwd2", "energy");
para_.initset(ucell_);
energy_ = 0;

Expand All @@ -28,11 +30,13 @@ void Vdwd2::cal_energy()
};
index_loops(energy);
energy_ *= para_.scaling();
ModuleBase::timer::tick("Vdwd2", "energy");
}

void Vdwd2::cal_force()
{
ModuleBase::TITLE("Vdwd2", "force");
ModuleBase::timer::tick("Vdwd2", "force");
para_.initset(ucell_);
force_.clear();
force_.resize(ucell_.nat);
Expand All @@ -55,11 +59,13 @@ void Vdwd2::cal_force()
std::for_each(force_.begin(), force_.end(), [&](ModuleBase::Vector3<double> &f) {
f *= para_.scaling() / ucell_.lat0;
});
ModuleBase::timer::tick("Vdwd2", "force");
}

void Vdwd2::cal_stress()
{
ModuleBase::TITLE("Vdwd2", "stress");
ModuleBase::timer::tick("Vdwd2", "stress");
para_.initset(ucell_);
stress_.Zero();

Expand All @@ -83,6 +89,7 @@ void Vdwd2::cal_stress()

index_loops(stress);
stress_ *= para_.scaling() / ucell_.omega;
ModuleBase::timer::tick("Vdwd2", "stress");
}

} // namespace vdw
8 changes: 8 additions & 0 deletions source/module_vdw/vdwd3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "module_base/constants.h"
#include "module_base/element_name.h"
#include "module_base/global_function.h"
#include "module_base/timer.h"

namespace vdw
{
Expand Down Expand Up @@ -78,6 +79,7 @@ std::vector<double> Vdwd3::atom_kind()
void Vdwd3::cal_energy()
{
ModuleBase::TITLE("Vdwd3", "cal_energy");
ModuleBase::timer::tick("Vdwd3", "cal_energy");
init();

int ij;
Expand Down Expand Up @@ -235,11 +237,13 @@ void Vdwd3::cal_energy()
pbc_three_body(iz_, lat_, xyz_, rep_cn_, cc6ab, eabc);
}
energy_ = (-para_.s6() * e6 - para_.s18() * e8 - eabc) * 2;
ModuleBase::timer::tick("Vdwd3", "cal_energy");
}

void Vdwd3::cal_force()
{
ModuleBase::TITLE("Vdwd3", "cal_force");
ModuleBase::timer::tick("Vdwd3", "cal_force");
init();

force_.clear();
Expand All @@ -254,11 +258,14 @@ void Vdwd3::cal_force()

for (size_t iat = 0; iat != ucell_.nat; iat++)
force_[iat] = -2.0 * g[iat];

ModuleBase::timer::tick("Vdwd3", "cal_force");
}

void Vdwd3::cal_stress()
{
ModuleBase::TITLE("Vdwd3", "cal_stress");
ModuleBase::timer::tick("Vdwd3", "cal_stress");
init();

std::vector<ModuleBase::Vector3<double>> g;
Expand All @@ -272,6 +279,7 @@ void Vdwd3::cal_stress()
2.0 * smearing_sigma(1, 0), 2.0 * smearing_sigma(1, 1), 2.0 * smearing_sigma(1, 2),
2.0 * smearing_sigma(2, 0), 2.0 * smearing_sigma(2, 1), 2.0 * smearing_sigma(2, 2))
/ ucell_.omega;
ModuleBase::timer::tick("Vdwd3", "cal_stress");
}

void Vdwd3::get_c6(int iat, int jat, double nci, double ncj, double &c6)
Expand Down
7 changes: 4 additions & 3 deletions source/src_lcao/FORCE_STRESS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,12 @@ void Force_Stress_LCAO::getForceStress(
if(isforce)
{
force_vdw.create(nat,3);
const std::vector<ModuleBase::Vector3<double>> &force_vdw_temp = vdw_solver->get_force();
for(int iat=0; iat<GlobalC::ucell.nat; ++iat)
{
force_vdw(iat,0) = vdw_solver->get_force()[iat].x;
force_vdw(iat,1) = vdw_solver->get_force()[iat].y;
force_vdw(iat,2) = vdw_solver->get_force()[iat].z;
force_vdw(iat,0) = force_vdw_temp[iat].x;
force_vdw(iat,1) = force_vdw_temp[iat].y;
force_vdw(iat,2) = force_vdw_temp[iat].z;
}
}
if(isstress)
Expand Down
7 changes: 4 additions & 3 deletions source/src_pw/forces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ void Forces::init(ModuleBase::matrix& force, const ModuleBase::matrix& wg, const
auto vdw_solver = vdw::make_vdw(GlobalC::ucell, INPUT);
if (vdw_solver != nullptr)
{
const std::vector<ModuleBase::Vector3<double>> &force_vdw_temp = vdw_solver->get_force();
for (int iat = 0; iat < GlobalC::ucell.nat; ++iat)
{
force_vdw(iat, 0) = vdw_solver->get_force()[iat].x;
force_vdw(iat, 1) = vdw_solver->get_force()[iat].y;
force_vdw(iat, 2) = vdw_solver->get_force()[iat].z;
force_vdw(iat, 0) = force_vdw_temp[iat].x;
force_vdw(iat, 1) = force_vdw_temp[iat].y;
force_vdw(iat, 2) = force_vdw_temp[iat].z;
}
if (GlobalV::TEST_FORCE)
{
Expand Down

0 comments on commit 7fd881d

Please sign in to comment.