Skip to content

Commit

Permalink
[pre-commit.ci lite] apply automatic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci-lite[bot] authored Jul 12, 2024
1 parent 75a547f commit 59da825
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 39 deletions.
6 changes: 4 additions & 2 deletions source/module_elecstate/module_dm/density_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,9 @@ void DensityMatrix<double, double>::write_DMK(const std::string directory, const
{
for (int j = 0; j < this->_paraV->ncol; ++j)
{
if (j % 8 == 0)
if (j % 8 == 0) {
ofs << "\n";
}
ofs << " " << this->_DMK[ik + this->_nks * (ispin - 1)][i * this->_paraV->ncol + j];
}
}
Expand Down Expand Up @@ -829,8 +830,9 @@ void DensityMatrix<std::complex<double>, double>::write_DMK(const std::string di
{
for (int j = 0; j < this->_paraV->ncol; ++j)
{
if (j % 8 == 0)
if (j % 8 == 0) {
ofs << "\n";
}
ofs << " " << this->_DMK[ik + this->_nks * (ispin - 1)][i * this->_paraV->ncol + j].real();
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/module_esolver/esolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ESolver
// get conv_elec used in current scf
virtual bool get_conv_elec()
{
return 0;
return false;
}
std::string classname;
};
Expand All @@ -74,7 +74,7 @@ class ESolver
*
* @return [out] std::string The type of ESolver
*/
std::string determine_type(void);
std::string determine_type();

/**
* @brief Determine and initialize an ESolver based on input information.
Expand Down
88 changes: 58 additions & 30 deletions source/module_hamilt_general/module_xc/xc_functional_gradcorr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v,
{
ModuleBase::TITLE("XC_Functional","gradcorr");

if(func_type == 0 || func_type == 1) return; // none or LDA functional
if(func_type == 0 || func_type == 1) { return; // none or LDA functional
}

bool igcc_is_lyp = false;
if( func_id[1] == XC_GGA_C_LYP) igcc_is_lyp = true;
if( func_id[1] == XC_GGA_C_LYP) { igcc_is_lyp = true;
}

int nspin0 = GlobalV::NSPIN;
if(GlobalV::NSPIN==4) nspin0 =1;
if(GlobalV::NSPIN==4&&(GlobalV::DOMAG||GlobalV::DOMAG_Z)) nspin0 = 2;
if(GlobalV::NSPIN==4) { nspin0 =1;
}
if(GlobalV::NSPIN==4&&(GlobalV::DOMAG||GlobalV::DOMAG_Z)) { nspin0 = 2;
}

assert(nspin0>0);
const double fac = 1.0/ nspin0;
Expand Down Expand Up @@ -87,7 +91,8 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v,
}

gdr1 = new ModuleBase::Vector3<double>[rhopw->nrxx];
if(!is_stress) h1 = new ModuleBase::Vector3<double>[rhopw->nrxx];
if(!is_stress) { h1 = new ModuleBase::Vector3<double>[rhopw->nrxx];
}

XC_Functional::grad_rho( rhogsum1 , gdr1, rhopw, ucell->tpiba);

Expand All @@ -113,7 +118,8 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v,
}

gdr2 = new ModuleBase::Vector3<double>[rhopw->nrxx];
if(!is_stress) h2 = new ModuleBase::Vector3<double>[rhopw->nrxx];
if(!is_stress) { h2 = new ModuleBase::Vector3<double>[rhopw->nrxx];
}

XC_Functional::grad_rho( rhogsum2 , gdr2, rhopw, ucell->tpiba);
}
Expand Down Expand Up @@ -156,7 +162,8 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v,
}
}
vgg = new double* [nspin0];
for(int is = 0;is<nspin0;is++)vgg[is] = new double[rhopw->nrxx];
for(int is = 0;is<nspin0;is++) {vgg[is] = new double[rhopw->nrxx];
}
}
noncolin_rho(rhotmp1,rhotmp2,neg,chr->rho,rhopw->nrxx,ucell->magnet.ux_,ucell->magnet.lsign_);
rhopw->real2recip(rhotmp1, rhogsum1);
Expand Down Expand Up @@ -228,15 +235,17 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v,
for(int ir=0; ir<rhopw->nrxx; ir++)
{
const double arho = std::abs( rhotmp1[ir] );
if(!is_stress) h1[ir].x = h1[ir].y = h1[ir].z = 0.0;
if(!is_stress) { h1[ir].x = h1[ir].y = h1[ir].z = 0.0;
}

if(arho > epsr)
{
grho2a = gdr1[ir].norm2();

//normally values in rhotmp can either be >= 0 or < 0.
if( rhotmp1[ir] >= 0.0 ) segno = 1.0;
else segno = -1.0;
if( rhotmp1[ir] >= 0.0 ) { segno = 1.0;
} else { segno = -1.0;
}
if (use_libxc && is_stress)
{
#ifdef USE_LIBXC
Expand Down Expand Up @@ -380,7 +389,8 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v,
else
{
double zeta = ( rhotmp1[ir] - rhotmp2[ir] ) / rh;
if(GlobalV::NSPIN==4&&(GlobalV::DOMAG||GlobalV::DOMAG_Z)) zeta = fabs(zeta) * neg[ir];
if(GlobalV::NSPIN==4&&(GlobalV::DOMAG||GlobalV::DOMAG_Z)) { zeta = fabs(zeta) * neg[ir];
}
const double grh2 = (gdr1[ir]+gdr2[ir]).norm2();
XC_Functional::gcc_spin(rh, zeta, grh2, sc, v1cup, v1cdw, v2c);
v2cup = v2c;
Expand Down Expand Up @@ -498,30 +508,35 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v,

for(int is=0; is<nspin0; is++)
{
if(is==0)XC_Functional::grad_dot(h1,dh,rhopw,ucell->tpiba);
if(is==1)XC_Functional::grad_dot(h2,dh,rhopw,ucell->tpiba);
if(is==0) {XC_Functional::grad_dot(h1,dh,rhopw,ucell->tpiba);
}
if(is==1) {XC_Functional::grad_dot(h2,dh,rhopw,ucell->tpiba);
}
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 1024)
#endif
for(int ir=0; ir<rhopw->nrxx; ir++)
for(int ir=0; ir<rhopw->nrxx; ir++) {
v(is, ir) -= dh[ir];
}

double sum = 0.0;
if(is==0)
{
#ifdef _OPENMP
#pragma omp parallel for reduction(+:sum) schedule(static, 256)
#endif
for(int ir=0; ir<rhopw->nrxx; ir++)
for(int ir=0; ir<rhopw->nrxx; ir++) {
sum += dh[ir] * rhotmp1[ir];
}
}
else if(is==1)
{
#ifdef _OPENMP
#pragma omp parallel for reduction(+:sum) schedule(static, 256)
#endif
for(int ir=0; ir<rhopw->nrxx; ir++)
for(int ir=0; ir<rhopw->nrxx; ir++) {
sum += dh[ir] * rhotmp2[ir];
}
}
vtxcgc -= sum;
}
Expand All @@ -540,7 +555,8 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v,
{
for(int ir=0;ir<rhopw->nrxx;ir++)
{
if(is<nspin0) vgg[is][ir] = v(is,ir);
if(is<nspin0) { vgg[is][ir] = v(is,ir);
}
v(is,ir) = vsave[is][ir];
}
}
Expand All @@ -553,8 +569,9 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v,
double amag = sqrt(pow(chr->rho[1][ir],2)+pow(chr->rho[2][ir],2)+pow(chr->rho[3][ir],2));
if(amag>1e-12)
{
for(int i=1;i<4;i++)
for(int i=1;i<4;i++) {
v(i,ir)+= neg[ir] * 0.5 *(vgg[0][ir]-vgg[1][ir])*chr->rho[i][ir]/amag;
}
}
}
}
Expand All @@ -563,23 +580,27 @@ void XC_Functional::gradcorr(double &etxc, double &vtxc, ModuleBase::matrix &v,
delete[] rhotmp1;
delete[] rhogsum1;
delete[] gdr1;
if(!is_stress) delete[] h1;
if(!is_stress) { delete[] h1;
}

if(GlobalV::NSPIN==2)
{
delete[] rhotmp2;
delete[] rhogsum2;
delete[] gdr2;
if(!is_stress) delete[] h2;
if(!is_stress) { delete[] h2;
}
}
if(GlobalV::NSPIN == 4 && (GlobalV::DOMAG||GlobalV::DOMAG_Z))
{
delete[] neg;
if(!is_stress)
{
for(int i=0; i<nspin0; i++) delete[] vgg[i];
for(int i=0; i<nspin0; i++) { delete[] vgg[i];
}
delete[] vgg;
for(int i=0; i<GlobalV::NSPIN; i++) delete[] vsave[i];
for(int i=0; i<GlobalV::NSPIN; i++) { delete[] vsave[i];
}
delete[] vsave;
delete[] h2;
}
Expand Down Expand Up @@ -645,8 +666,9 @@ void XC_Functional::grad_rho(const std::complex<double>* rhog,
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 1024)
#endif
for(int ig=0; ig<rho_basis->npw; ig++)
for(int ig=0; ig<rho_basis->npw; ig++) {
gdrtmp[ig] = ModuleBase::IMAG_UNIT * rhog[ig] * rho_basis->gcar[ig][i];
}

// bring the gdr from G --> R
rho_basis->recip2real(gdrtmp, gdrtmp);
Expand All @@ -655,8 +677,9 @@ void XC_Functional::grad_rho(const std::complex<double>* rhog,
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 1024)
#endif
for(int ir=0; ir<rho_basis->nrxx; ir++)
for(int ir=0; ir<rho_basis->nrxx; ir++) {
gdr[ir][i] = gdrtmp[ir].real() * tpiba;
}
}

delete[] gdrtmp;
Expand All @@ -674,8 +697,9 @@ void XC_Functional::grad_dot(const ModuleBase::Vector3<double>* h, double* dh, c
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 1024)
#endif
for(int ir = 0; ir < rho_basis->nrxx; ++ir)
for(int ir = 0; ir < rho_basis->nrxx; ++ir) {
aux[ir] = std::complex<double>( h[ir][i], 0.0);
}

// bring to G space.
rho_basis->real2recip(aux,aux);
Expand All @@ -684,16 +708,18 @@ void XC_Functional::grad_dot(const ModuleBase::Vector3<double>* h, double* dh, c
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 1024)
#endif
for(int ig = 0; ig < rho_basis->npw; ++ig)
for(int ig = 0; ig < rho_basis->npw; ++ig) {
gaux[ig] = ModuleBase::IMAG_UNIT * aux[ig] * rho_basis->gcar[ig][i];
}
}
else
{
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 1024)
#endif
for(int ig = 0; ig < rho_basis->npw; ++ig)
for(int ig = 0; ig < rho_basis->npw; ++ig) {
gaux[ig] += ModuleBase::IMAG_UNIT * aux[ig] * rho_basis->gcar[ig][i];
}
}
}

Expand All @@ -703,8 +729,9 @@ void XC_Functional::grad_dot(const ModuleBase::Vector3<double>* h, double* dh, c
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 1024)
#endif
for(int ir=0; ir<rho_basis->nrxx; ir++)
for(int ir=0; ir<rho_basis->nrxx; ir++) {
dh[ir] = aux[ir].real() * tpiba;
}

delete[] aux;
delete[] gaux;
Expand Down Expand Up @@ -732,8 +759,9 @@ void XC_Functional::noncolin_rho(double *rhoout1, double *rhoout2, double *neg,
#endif
for(int ir = 0;ir<nrxx;ir++)
{
if(rho[1][ir]*ux_[0] + rho[2][ir]*ux_[1] + rho[3][ir]*ux_[2]>0) neg[ir] = 1.0;
else neg[ir] = -1.0;
if(rho[1][ir]*ux_[0] + rho[2][ir]*ux_[1] + rho[3][ir]*ux_[2]>0) { neg[ir] = 1.0;
} else { neg[ir] = -1.0;
}
}
}
#ifdef _OPENMP
Expand Down
15 changes: 10 additions & 5 deletions source/module_lr/operator_casida/operator_lr_exx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ namespace LR
{
ModuleBase::TITLE("OperatorLREXX", "allocate_Ds_onebase");
this->Ds_onebase.resize(this->nspin);
for (int is = 0;is < this->nspin;++is)
for (int iat1 = 0;iat1 < ucell.nat;++iat1)
for (int iat2 = 0;iat2 < ucell.nat;++iat2)
for (auto cell : this->BvK_cells)
for (int is = 0;is < this->nspin;++is) {
for (int iat1 = 0;iat1 < ucell.nat;++iat1) {
for (int iat2 = 0;iat2 < ucell.nat;++iat2) {
for (auto cell : this->BvK_cells) {
this->Ds_onebase[is][iat1][std::make_pair(iat2, cell)] =
RI::Tensor<T>({ static_cast<size_t>(ucell.atoms[ucell.iat2it[iat1]].nw), static_cast<size_t>(ucell.atoms[ucell.iat2it[iat2]].nw) });
}
}
}
}
}

template<>
Expand Down Expand Up @@ -86,7 +90,8 @@ namespace LR
std::vector<std::vector<T>> DMk_trans_vector = this->DM_trans[ib]->get_DMK_vector();
assert(DMk_trans_vector.size() == nks);
std::vector<const std::vector<T>*> DMk_trans_pointer(nks);
for (int is = 0;is < nks;++is) DMk_trans_pointer[is] = &DMk_trans_vector[is];
for (int is = 0;is < nks;++is) { DMk_trans_pointer[is] = &DMk_trans_vector[is];
}
// if multi-k, DM_trans(TR=double) -> Ds_trans(TR=T=complex<double>)
std::vector<std::map<TA, std::map<TAC, RI::Tensor<T>>>> Ds_trans =
RI_2D_Comm::split_m2D_ktoR<T>(this->kv, DMk_trans_pointer, *this->pmat);
Expand Down

0 comments on commit 59da825

Please sign in to comment.