Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1. add Exx_LRI::cal_exx_stress() #235

Merged
merged 1 commit into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions source/module_ri/Exx_LRI.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Exx_LRI
private:
using TA = int;
using Tcell = int;
static const size_t Ndim = 3;
static constexpr std::size_t Ndim = 3;
using TC = std::array<Tcell,Ndim>;
using TAC = std::pair<TA,TC>;
using TatomR = std::array<double,Ndim>; // tmp
Expand All @@ -38,10 +38,12 @@ class Exx_LRI
void cal_exx_ions();
void cal_exx_elec(const Local_Orbital_Charge &loc, const Parallel_Orbitals &pv);
void cal_exx_force();
void cal_exx_stress();

std::vector< std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>> Hexxs;
Tdata Eexx;
ModuleBase::matrix Fexx;
ModuleBase::matrix force_exx;
ModuleBase::matrix stress_exx;

void write_Hexxs(const std::string &file_name) const;
void read_Hexxs(const std::string &file_name);
Expand Down
37 changes: 31 additions & 6 deletions source/module_ri/Exx_LRI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,21 +239,46 @@ void Exx_LRI<Tdata>::cal_exx_force()

this->exx_lri.set_csm_threshold(this->info.cauchy_grad_threshold);

this->Fexx.create(GlobalC::ucell.nat, Ndim);
this->force_exx.create(GlobalC::ucell.nat, Ndim);
for(int is=0; is<GlobalV::NSPIN; ++is)
{
this->exx_lri.cal_Fs({"","",std::to_string(is),"",""});
for(std::size_t ix=0; ix<Ndim; ++ix)
for(const auto &force_item : this->exx_lri.force[ix])
this->Fexx(force_item.first, ix) += std::real(force_item.second);
this->exx_lri.cal_force({"","",std::to_string(is),"",""});
for(std::size_t idim=0; idim<Ndim; ++idim)
for(const auto &force_item : this->exx_lri.force[idim])
this->force_exx(force_item.first, idim) += std::real(force_item.second);
}

const double SPIN_multiple = std::map<int,double>{{1,2}, {2,1}, {4,1}}.at(GlobalV::NSPIN); // why?
const double frac = -2 * SPIN_multiple; // why?
this->Fexx *= frac;
this->force_exx *= frac;
ModuleBase::timer::tick("Exx_LRI", "cal_exx_force");
}


template<typename Tdata>
void Exx_LRI<Tdata>::cal_exx_stress()
{
ModuleBase::TITLE("Exx_LRI","cal_exx_stress");
ModuleBase::timer::tick("Exx_LRI", "cal_exx_stress");

this->exx_lri.set_csm_threshold(this->info.cauchy_grad_threshold);

this->stress_exx.create(Ndim, Ndim);
for(int is=0; is<GlobalV::NSPIN; ++is)
{
this->exx_lri.cal_stress({"","",std::to_string(is),"",""});
for(std::size_t idim0=0; idim0<Ndim; ++idim0)
for(std::size_t idim1=0; idim1<Ndim; ++idim1)
this->stress_exx(idim0,idim1) += std::real(this->exx_lri.stress(idim0,idim1));
}

const double SPIN_multiple = std::map<int,double>{{1,2}, {2,1}, {4,1}}.at(GlobalV::NSPIN); // why?
const double frac = 2 * SPIN_multiple / GlobalC::ucell.omega * GlobalC::ucell.lat0; // why?
this->stress_exx *= frac;

ModuleBase::timer::tick("Exx_LRI", "cal_exx_stress");
}

template<typename Tdata>
void Exx_LRI<Tdata>::write_Hexxs(const std::string &file_name) const
{
Expand Down
10 changes: 5 additions & 5 deletions source/module_xc/xc_functional_vxc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional::v_xc_libxc(
const double * const * const rho_in,
const double * const rho_core_in)
{
ModuleBase::TITLE("XC_Functional","v_xc");
ModuleBase::timer::tick("XC_Functional","v_xc");
ModuleBase::TITLE("XC_Functional","v_xc_libxc");
ModuleBase::timer::tick("XC_Functional","v_xc_libxc");

const int nspin = GlobalV::NSPIN;

Expand Down Expand Up @@ -385,7 +385,7 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional::v_xc_libxc(

finish_func(funcs);

ModuleBase::timer::tick("XC_Functional","v_xc");
ModuleBase::timer::tick("XC_Functional","v_xc_libxc");
return std::make_tuple( etxc, vtxc, std::move(v) );
}

Expand All @@ -409,8 +409,8 @@ tuple<double,double,ModuleBase::matrix,ModuleBase::matrix> XC_Functional::v_xc_m
const double * const rho_core_in,
const double * const * const kin_r_in)
{
ModuleBase::TITLE("XC_Functional","v_xc");
ModuleBase::timer::tick("XC_Functional","v_xc");
ModuleBase::TITLE("XC_Functional","v_xc_meta");
ModuleBase::timer::tick("XC_Functional","v_xc_meta");

if(GlobalV::NSPIN==4)
{
Expand Down
44 changes: 35 additions & 9 deletions source/src_lcao/FORCE_STRESS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,20 +233,37 @@ void Force_Stress_LCAO::getForceStress(
}
}
}
//Force contribution from exx
#ifdef __EXX
ModuleBase::matrix fexx;
//Force and Stress contribution from exx
ModuleBase::matrix force_exx;
ModuleBase::matrix stress_exx;
if( GlobalC::exx_info.info_global.cal_exx )
{
if(GlobalV::GAMMA_ONLY_LOCAL)
if(isforce)
{
GlobalC::exx_lri_double.cal_exx_force();
fexx = GlobalC::exx_info.info_global.hybrid_alpha * GlobalC::exx_lri_double.Fexx;
if(GlobalV::GAMMA_ONLY_LOCAL)
{
GlobalC::exx_lri_double.cal_exx_force();
force_exx = GlobalC::exx_info.info_global.hybrid_alpha * GlobalC::exx_lri_double.force_exx;
}
else
{
GlobalC::exx_lri_complex.cal_exx_force();
force_exx = GlobalC::exx_info.info_global.hybrid_alpha * GlobalC::exx_lri_complex.force_exx;
}
}
else
if(isstress)
{
GlobalC::exx_lri_complex.cal_exx_force();
fexx = GlobalC::exx_info.info_global.hybrid_alpha * GlobalC::exx_lri_complex.Fexx;
if(GlobalV::GAMMA_ONLY_LOCAL)
{
GlobalC::exx_lri_double.cal_exx_stress();
stress_exx = GlobalC::exx_info.info_global.hybrid_alpha * GlobalC::exx_lri_double.stress_exx;
}
else
{
GlobalC::exx_lri_complex.cal_exx_stress();
stress_exx = GlobalC::exx_info.info_global.hybrid_alpha * GlobalC::exx_lri_complex.stress_exx;
}
}
}
#endif
Expand Down Expand Up @@ -282,7 +299,7 @@ void Force_Stress_LCAO::getForceStress(
// Force contribution from exx
if( GlobalC::exx_info.info_global.cal_exx )
{
fcs(iat,i) += fexx(iat,i);
fcs(iat,i) += force_exx(iat,i);
}
#endif
//VDW force of vdwd2 or vdwd3
Expand Down Expand Up @@ -517,6 +534,13 @@ void Force_Stress_LCAO::getForceStress(
{
scs(i, j) += stress_dftu(i, j);
}
#ifdef __EXX
// Stress contribution from exx
if( GlobalC::exx_info.info_global.cal_exx )
{
scs(i,j) += stress_exx(i,j);
}
#endif
}
}

Expand Down Expand Up @@ -763,6 +787,7 @@ void Force_Stress_LCAO::calForcePwPart(
ModuleBase::matrix &fcc,
ModuleBase::matrix &fscc)
{
ModuleBase::TITLE("Force_Stress_LCAO","calForcePwPart");
//--------------------------------------------------------
// local pseudopotential force:
// use charge density; plane wave; local pseudopotential;
Expand Down Expand Up @@ -863,6 +888,7 @@ void Force_Stress_LCAO::calStressPwPart(
ModuleBase::matrix& sigmaxc
)
{
ModuleBase::TITLE("Force_Stress_LCAO","calStressPwPart");
//--------------------------------------------------------
// local pseudopotential stress:
// use charge density; plane wave; local pseudopotential;
Expand Down
4 changes: 4 additions & 0 deletions source/src_pw/forces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ void Forces::print(const std::string& name, const ModuleBase::matrix& f, bool ry

void Forces::cal_force_loc(ModuleBase::matrix& forcelc, ModulePW::PW_Basis* rho_basis)
{
ModuleBase::TITLE("Forces", "cal_force_loc");
ModuleBase::timer::tick("Forces", "cal_force_loc");

std::complex<double>* aux = new std::complex<double>[rho_basis->nmaxgr];
Expand Down Expand Up @@ -480,6 +481,7 @@ void Forces::cal_force_loc(ModuleBase::matrix& forcelc, ModulePW::PW_Basis* rho_
#include "H_Ewald_pw.h"
void Forces::cal_force_ew(ModuleBase::matrix& forceion, ModulePW::PW_Basis* rho_basis)
{
ModuleBase::TITLE("Forces", "cal_force_ew");
ModuleBase::timer::tick("Forces", "cal_force_ew");

double fact = 2.0;
Expand Down Expand Up @@ -643,6 +645,7 @@ void Forces::cal_force_ew(ModuleBase::matrix& forceion, ModulePW::PW_Basis* rho_

void Forces::cal_force_cc(ModuleBase::matrix& forcecc, ModulePW::PW_Basis* rho_basis)
{
ModuleBase::TITLE("Forces", "cal_force_cc");
// recalculate the exchange-correlation potential.

ModuleBase::matrix v(GlobalV::NSPIN, rho_basis->nrxx);
Expand Down Expand Up @@ -924,6 +927,7 @@ void Forces::cal_force_nl(ModuleBase::matrix& forcenl, const psi::Psi<complex<do

void Forces::cal_force_scc(ModuleBase::matrix& forcescc, ModulePW::PW_Basis* rho_basis)
{
ModuleBase::TITLE("Forces", "cal_force_scc");
std::complex<double>* psic = new std::complex<double>[rho_basis->nmaxgr];

if (GlobalV::NSPIN == 1 || GlobalV::NSPIN == 4)
Expand Down
1 change: 1 addition & 0 deletions source/src_pw/stress_func_cc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//NLCC term, need to be tested
void Stress_Func::stress_cc(ModuleBase::matrix& sigma, ModulePW::PW_Basis* rho_basis, const bool is_pw)
{
ModuleBase::TITLE("Stress_Func","stress_cc");
ModuleBase::timer::tick("Stress_Func","stress_cc");

double fact=1.0;
Expand Down
5 changes: 3 additions & 2 deletions source/src_pw/stress_func_ewa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
//calcualte the Ewald stress term in PW and LCAO
void Stress_Func::stress_ewa(ModuleBase::matrix& sigma, ModulePW::PW_Basis* rho_basis, const bool is_pw)
{
ModuleBase::timer::tick("Stress_Func","stress_ew");
ModuleBase::TITLE("Stress_Func","stress_ewa");
ModuleBase::timer::tick("Stress_Func","stress_ewa");

double charge=0;
for(int it=0; it < GlobalC::ucell.ntype; it++)
Expand Down Expand Up @@ -152,7 +153,7 @@ void Stress_Func::stress_ewa(ModuleBase::matrix& sigma, ModulePW::PW_Basis* rho_
delete[] r2;
delete[] irr;
// this->print(GlobalV::ofs_running, "ewald stress", stression);
ModuleBase::timer::tick("Stress_Func","stress_ew");
ModuleBase::timer::tick("Stress_Func","stress_ewa");

return;
}
1 change: 1 addition & 0 deletions source/src_pw/stress_func_gga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//calculate the GGA stress correction in PW and LCAO
void Stress_Func::stress_gga(ModuleBase::matrix& sigma)
{
ModuleBase::TITLE("Stress_Func","stress_gga");
ModuleBase::timer::tick("Stress_Func","stress_gga");

int func_type = XC_Functional::get_func_type();
Expand Down
1 change: 1 addition & 0 deletions source/src_pw/stress_func_har.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//calculate the Hartree part in PW or LCAO base
void Stress_Func::stress_har(ModuleBase::matrix& sigma, ModulePW::PW_Basis* rho_basis, const bool is_pw)
{
ModuleBase::TITLE("Stress_Func","stress_har");
ModuleBase::timer::tick("Stress_Func","stress_har");
double shart;

Expand Down
4 changes: 4 additions & 0 deletions source/src_pw/stress_func_kin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
//calculate the kinetic stress in PW base
void Stress_Func::stress_kin(ModuleBase::matrix& sigma, const psi::Psi<complex<double>>* psi_in)
{
ModuleBase::TITLE("Stress_Func","stress_kin");
ModuleBase::timer::tick("Stress_Func","stress_kin");

double **gk;
gk=new double* [3];
int npw;
Expand Down Expand Up @@ -131,5 +134,6 @@ void Stress_Func::stress_kin(ModuleBase::matrix& sigma, const psi::Psi<complex<d
delete[] gk[2];
delete[] gk;

ModuleBase::timer::tick("Stress_Func","stress_kin");
return;
}
1 change: 1 addition & 0 deletions source/src_pw/stress_func_loc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//calculate local pseudopotential stress in PW or VL_dVL stress in LCAO
void Stress_Func::stress_loc(ModuleBase::matrix& sigma, ModulePW::PW_Basis* rho_basis, const bool is_pw)
{
ModuleBase::TITLE("Stress_Func","stress_loc");
ModuleBase::timer::tick("Stress_Func","stress_loc");

double *dvloc = new double[rho_basis->npw];
Expand Down
1 change: 0 additions & 1 deletion source/src_pw/stress_func_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ void Stress_Func::printstress_total(const ModuleBase::matrix& scs, bool ry)
unit_transform = ModuleBase::RYDBERG_SI / pow(ModuleBase::BOHR_RADIUS_SI,3) * 1.0e-8;
}
// std::cout.setf(ios::fixed);


//GlobalV::ofs_running << std::setiosflags(ios::right);
GlobalV::ofs_running << std::setprecision(6) << std::setiosflags(ios::showpos) << std::setiosflags(ios::fixed) << std::endl;
Expand Down