forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: move vdw classes to module_vdw and clean up (#1448)
* vdw: move source files from src_pw to module_vdw and clean up * vdw: combine calculate and get * vdw: downgrade to c++11 and clean up * vdw: replace old vdw classes with new ones * vdw: remove old files * vdw: fix deepks test compile
- Loading branch information
Showing
36 changed files
with
2,212 additions
and
2,179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -393,6 +393,7 @@ target_link_libraries(${ABACUS_BIN_NAME} | |
hamilt | ||
psi | ||
esolver | ||
vdw | ||
) | ||
|
||
if(ENABLE_LCAO) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
#include "vdw.h" | ||
#include "vdwd2.h" | ||
#include "vdwd3.h" | ||
|
||
namespace vdw | ||
{ | ||
|
||
std::unique_ptr<Vdw> make_vdw(const UnitCell_pseudo &ucell, const Input &input) | ||
{ | ||
if (INPUT.vdw_method == "d2") | ||
{ | ||
std::unique_ptr<Vdwd2> vdw_ptr = make_unique<Vdwd2>(ucell); | ||
vdw_ptr->parameter().initial_parameters(input); | ||
vdw_ptr->parameter().initset(ucell); | ||
return vdw_ptr; | ||
} | ||
else if (INPUT.vdw_method == "d3_0" || INPUT.vdw_method == "d3_bj") | ||
{ | ||
std::unique_ptr<Vdwd3> vdw_ptr = make_unique<Vdwd3>(ucell); | ||
vdw_ptr->parameter().initial_parameters(input); | ||
return vdw_ptr; | ||
} | ||
else | ||
{ | ||
return nullptr; | ||
} | ||
} | ||
|
||
} // namespace vdw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#ifndef VDW_H | ||
#define VDW_H | ||
|
||
#include <vector> | ||
#include "module_cell/unitcell_pseudo.h" | ||
#include "module_vdw/vdw_parameters.h" | ||
#include "module_vdw/vdwd2_parameters.h" | ||
#include "module_vdw/vdwd3_parameters.h" | ||
|
||
namespace vdw | ||
{ | ||
|
||
template<typename T, typename... Args> | ||
std::unique_ptr<T> make_unique(Args &&... args) { | ||
return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); | ||
} | ||
|
||
class Vdw | ||
{ | ||
public: | ||
Vdw(const UnitCell_pseudo &unit_in) : ucell_(unit_in) {}; | ||
|
||
virtual ~Vdw(){}; | ||
|
||
inline double get_energy(bool cal=true) { | ||
if (cal) { cal_energy(); } | ||
return energy_; | ||
} | ||
inline const std::vector<ModuleBase::Vector3<double>> &get_force(bool cal=true) { | ||
if (cal) { cal_force(); } | ||
return force_; | ||
} | ||
inline const ModuleBase::Matrix3 &get_stress(bool cal=true) { | ||
if (cal) { cal_stress(); } | ||
return stress_; | ||
} | ||
|
||
protected: | ||
const UnitCell_pseudo &ucell_; | ||
|
||
double energy_ = 0; | ||
std::vector<ModuleBase::Vector3<double>> force_; | ||
ModuleBase::Matrix3 stress_; | ||
|
||
virtual void cal_energy() { throw std::runtime_error("No cal_energy method in base Vdw class"); } | ||
virtual void cal_force() { throw std::runtime_error("No cal_energy method in base Vdw class"); } | ||
virtual void cal_stress() { throw std::runtime_error("No cal_energy method in base Vdw class"); } | ||
}; | ||
|
||
std::unique_ptr<Vdw> make_vdw(const UnitCell_pseudo &ucell, const Input &input); | ||
|
||
} // namespace vdw | ||
|
||
#endif // VDW_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef VDW_PARAMETERS_H | ||
#define VDW_PARAMETERS_H | ||
|
||
#include "module_base/vector3.h" | ||
|
||
#include <string> | ||
|
||
namespace vdw | ||
{ | ||
|
||
class VdwParameters | ||
{ | ||
public: | ||
VdwParameters() = default; | ||
virtual ~VdwParameters() = default; | ||
|
||
inline const std::string &model() const { return model_; } | ||
inline const ModuleBase::Vector3<int> &period() const { return period_; }; | ||
|
||
protected: | ||
std::string model_; | ||
ModuleBase::Vector3<int> period_; | ||
}; | ||
|
||
} // namespace vdw | ||
|
||
#endif // VDW_PARAMETERS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
//========================================================== | ||
// AUTHOR : Peize Lin | ||
// DATE : 2014-04-25 | ||
// UPDATE : 2019-04-26 | ||
//========================================================== | ||
|
||
#include "module_vdw/vdwd2.h" | ||
|
||
namespace vdw | ||
{ | ||
|
||
void Vdwd2::cal_energy() | ||
{ | ||
ModuleBase::TITLE("Vdwd2", "energy"); | ||
para_.initset(ucell_); | ||
energy_ = 0; | ||
|
||
auto energy = [&](double r, | ||
double R0_sum, | ||
double C6_product, | ||
double r_sqr, | ||
int, | ||
int, | ||
const ModuleBase::Vector3<double> &, | ||
const ModuleBase::Vector3<double> &) { | ||
const double tmp_damp_recip = 1 + exp(-para_.damping() * (r / R0_sum - 1)); | ||
energy_ -= C6_product / pow(r_sqr, 3) / tmp_damp_recip / 2; | ||
}; | ||
index_loops(energy); | ||
energy_ *= para_.scaling(); | ||
} | ||
|
||
void Vdwd2::cal_force() | ||
{ | ||
ModuleBase::TITLE("Vdwd2", "force"); | ||
para_.initset(ucell_); | ||
force_.clear(); | ||
force_.resize(ucell_.nat); | ||
|
||
auto force = [&](double r, | ||
double R0_sum, | ||
double C6_product, | ||
double r_sqr, | ||
int it1, | ||
int ia1, | ||
const ModuleBase::Vector3<double> &tau1, | ||
const ModuleBase::Vector3<double> &tau2) { | ||
const double tmp_exp = exp(-para_.damping() * (r / R0_sum - 1)); | ||
const double tmp_factor = C6_product / pow(r_sqr, 3) / r / (1 + tmp_exp) | ||
* (-6 / r + tmp_exp / (1 + tmp_exp) * para_.damping() / R0_sum); | ||
force_[ucell_.itia2iat(it1, ia1)] += tmp_factor * (tau1 - tau2); | ||
}; | ||
|
||
index_loops(force); | ||
std::for_each(force_.begin(), force_.end(), [&](ModuleBase::Vector3<double> &f) { | ||
f *= para_.scaling() / ucell_.lat0; | ||
}); | ||
} | ||
|
||
void Vdwd2::cal_stress() | ||
{ | ||
ModuleBase::TITLE("Vdwd2", "stress"); | ||
para_.initset(ucell_); | ||
stress_.Zero(); | ||
|
||
auto stress = [&](double r, | ||
double R0_sum, | ||
double C6_product, | ||
double r_sqr, | ||
int it1, | ||
int ia1, | ||
const ModuleBase::Vector3<double> &tau1, | ||
const ModuleBase::Vector3<double> &tau2) { | ||
const double tmp_exp = exp(-para_.damping() * (r / R0_sum - 1)); | ||
const double tmp_factor = C6_product / pow(r_sqr, 3) / r / (1 + tmp_exp) | ||
* (-6 / r + tmp_exp / (1 + tmp_exp) * para_.damping() / R0_sum); | ||
const ModuleBase::Vector3<double> dr = tau2 - tau1; | ||
stress_ += tmp_factor / 2 | ||
* ModuleBase::Matrix3(dr.x * dr.x, dr.x * dr.y, dr.x * dr.z, | ||
dr.y * dr.x, dr.y * dr.y, dr.y * dr.z, | ||
dr.z * dr.x, dr.z * dr.y, dr.z * dr.z); | ||
}; | ||
|
||
index_loops(stress); | ||
stress_ *= para_.scaling() / ucell_.omega; | ||
} | ||
|
||
} // namespace vdw |
Oops, something went wrong.