Skip to content

Commit eb60634

Browse files
committed
change ucell in module_io
1 parent 5f1b128 commit eb60634

File tree

4 files changed

+44
-41
lines changed

4 files changed

+44
-41
lines changed

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep)
12681268
orb_); // additional step before calling
12691269
// macroscopic_polarization (why capitalize
12701270
// the function name?)
1271-
bp.Macroscopic_polarization(this->pw_wfc->npwk_max, this->psi, this->pw_rho, this->pw_wfc, this->kv);
1271+
bp.Macroscopic_polarization(ucell,this->pw_wfc->npwk_max, this->psi, this->pw_rho, this->pw_wfc, this->kv);
12721272
std::cout << FmtCore::format(" >> Finish %s.\n * * * * * *\n", "Berry phase calculation");
12731273
}
12741274
}

source/module_esolver/esolver_ks_pw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ void ESolver_KS_PW<T, Device>::after_scf(UnitCell& ucell, const int istep)
593593
{
594594
std::cout << FmtCore::format("\n * * * * * *\n << Start %s.\n", "Berry phase polarization");
595595
berryphase bp;
596-
bp.Macroscopic_polarization(this->pw_wfc->npwk_max, this->psi, this->pw_rho, this->pw_wfc, this->kv);
596+
bp.Macroscopic_polarization(ucell,this->pw_wfc->npwk_max, this->psi, this->pw_rho, this->pw_wfc, this->kv);
597597
std::cout << FmtCore::format(" >> Finish %s.\n * * * * * *\n", "Berry phase polarization");
598598
}
599599
}

source/module_io/berryphase.cpp

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,8 @@ void berryphase::Berry_Phase(int nbands,
463463
// GlobalV::ofs_running << "Berry_Phase end " << std::endl;
464464
}
465465

466-
void berryphase::Macroscopic_polarization(const int npwx,
466+
void berryphase::Macroscopic_polarization(const UnitCell& ucell,
467+
const int npwx,
467468
const psi::Psi<std::complex<double>>* psi_in,
468469
const ModulePW::PW_Basis* rhopw,
469470
const ModulePW::PW_Basis_K* wfcpw,
@@ -486,30 +487,30 @@ void berryphase::Macroscopic_polarization(const int npwx,
486487
double polarization_ion[3]; // means three lattice vector directions R1,R2,R3
487488
ModuleBase::GlobalFunc::ZEROS(polarization_ion, 3);
488489
// reciprocal lattice
489-
ModuleBase::Vector3<double> rcell_1(GlobalC::ucell.G.e11, GlobalC::ucell.G.e12, GlobalC::ucell.G.e13);
490-
ModuleBase::Vector3<double> rcell_2(GlobalC::ucell.G.e21, GlobalC::ucell.G.e22, GlobalC::ucell.G.e23);
491-
ModuleBase::Vector3<double> rcell_3(GlobalC::ucell.G.e31, GlobalC::ucell.G.e32, GlobalC::ucell.G.e33);
492-
// int *mod_ion = new int[GlobalC::ucell.nat];
493-
std::vector<int> mod_ion(GlobalC::ucell.nat);
494-
// double *pdl_ion_R1 = new double[GlobalC::ucell.nat];
495-
std::vector<double> pdl_ion_R1(GlobalC::ucell.nat);
496-
// double *pdl_ion_R2 = new double[GlobalC::ucell.nat];
497-
std::vector<double> pdl_ion_R2(GlobalC::ucell.nat);
498-
// double *pdl_ion_R3 = new double[GlobalC::ucell.nat];
499-
std::vector<double> pdl_ion_R3(GlobalC::ucell.nat);
500-
ModuleBase::GlobalFunc::ZEROS(mod_ion.data(), GlobalC::ucell.nat);
501-
ModuleBase::GlobalFunc::ZEROS(pdl_ion_R1.data(), GlobalC::ucell.nat);
502-
ModuleBase::GlobalFunc::ZEROS(pdl_ion_R2.data(), GlobalC::ucell.nat);
503-
ModuleBase::GlobalFunc::ZEROS(pdl_ion_R3.data(), GlobalC::ucell.nat);
490+
ModuleBase::Vector3<double> rcell_1(ucell.G.e11, ucell.G.e12, ucell.G.e13);
491+
ModuleBase::Vector3<double> rcell_2(ucell.G.e21, ucell.G.e22, ucell.G.e23);
492+
ModuleBase::Vector3<double> rcell_3(ucell.G.e31, ucell.G.e32, ucell.G.e33);
493+
// int *mod_ion = new int[ucell.nat];
494+
std::vector<int> mod_ion(ucell.nat);
495+
// double *pdl_ion_R1 = new double[ucell.nat];
496+
std::vector<double> pdl_ion_R1(ucell.nat);
497+
// double *pdl_ion_R2 = new double[ucell.nat];
498+
std::vector<double> pdl_ion_R2(ucell.nat);
499+
// double *pdl_ion_R3 = new double[ucell.nat];
500+
std::vector<double> pdl_ion_R3(ucell.nat);
501+
ModuleBase::GlobalFunc::ZEROS(mod_ion.data(), ucell.nat);
502+
ModuleBase::GlobalFunc::ZEROS(pdl_ion_R1.data(), ucell.nat);
503+
ModuleBase::GlobalFunc::ZEROS(pdl_ion_R2.data(), ucell.nat);
504+
ModuleBase::GlobalFunc::ZEROS(pdl_ion_R3.data(), ucell.nat);
504505

505506
bool lodd = false;
506507
int atom_index = 0;
507-
for (int it = 0; it < GlobalC::ucell.ntype; it++)
508+
for (int it = 0; it < ucell.ntype; it++)
508509
{
509-
for (int ia = 0; ia < GlobalC::ucell.atoms[it].na; ia++)
510+
for (int ia = 0; ia < ucell.atoms[it].na; ia++)
510511
{
511512
// should consider fractional electron number
512-
if (int(GlobalC::ucell.atoms[it].ncpp.zv) % 2 == 1)
513+
if (int(ucell.atoms[it].ncpp.zv) % 2 == 1)
513514
{
514515
mod_ion[atom_index] = 1;
515516
lodd = true;
@@ -524,18 +525,18 @@ void berryphase::Macroscopic_polarization(const int npwx,
524525
}
525526

526527
atom_index = 0;
527-
for (int it = 0; it < GlobalC::ucell.ntype; it++)
528+
for (int it = 0; it < ucell.ntype; it++)
528529
{
529-
for (int ia = 0; ia < GlobalC::ucell.atoms[it].na; ia++)
530+
for (int ia = 0; ia < ucell.atoms[it].na; ia++)
530531
{
531-
pdl_ion_R1[atom_index] = GlobalC::ucell.atoms[it].ncpp.zv * (GlobalC::ucell.atoms[it].tau[ia] * rcell_1);
532-
pdl_ion_R2[atom_index] = GlobalC::ucell.atoms[it].ncpp.zv * (GlobalC::ucell.atoms[it].tau[ia] * rcell_2);
533-
pdl_ion_R3[atom_index] = GlobalC::ucell.atoms[it].ncpp.zv * (GlobalC::ucell.atoms[it].tau[ia] * rcell_3);
532+
pdl_ion_R1[atom_index] = ucell.atoms[it].ncpp.zv * (ucell.atoms[it].tau[ia] * rcell_1);
533+
pdl_ion_R2[atom_index] = ucell.atoms[it].ncpp.zv * (ucell.atoms[it].tau[ia] * rcell_2);
534+
pdl_ion_R3[atom_index] = ucell.atoms[it].ncpp.zv * (ucell.atoms[it].tau[ia] * rcell_3);
534535
atom_index++;
535536
}
536537
}
537538

538-
for (int i = 0; i < GlobalC::ucell.nat; i++)
539+
for (int i = 0; i < ucell.nat; i++)
539540
{
540541
if (mod_ion[i] == 1)
541542
{
@@ -596,10 +597,10 @@ void berryphase::Macroscopic_polarization(const int npwx,
596597
int mod_elec_tot = 0;
597598
Berry_Phase(occ_nbands, pdl_elec_tot, mod_elec_tot, npwx, psi_in, rhopw, wfcpw, kv);
598599

599-
const double rmod = GlobalC::ucell.a1.norm() * GlobalC::ucell.lat0;
600+
const double rmod = ucell.a1.norm() * ucell.lat0;
600601
const double unit1 = rmod;
601-
const double unit2 = rmod / GlobalC::ucell.omega;
602-
const double unit3 = (rmod / GlobalC::ucell.omega) * (1.60097e-19 / pow(5.29177e-11, 2));
602+
const double unit2 = rmod / ucell.omega;
603+
const double unit3 = (rmod / ucell.omega) * (1.60097e-19 / pow(5.29177e-11, 2));
603604

604605
GlobalV::ofs_running << " VALUES OF POLARIZATION" << std::endl;
605606
GlobalV::ofs_running << std::endl;
@@ -613,7 +614,7 @@ void berryphase::Macroscopic_polarization(const int npwx,
613614
// calculate total polarization,add electron part and ions part
614615
double total_polarization = pdl_elec_tot + polarization_ion[0];
615616

616-
ModuleBase::Vector3<double> polarization_xyz = GlobalC::ucell.a1;
617+
ModuleBase::Vector3<double> polarization_xyz = ucell.a1;
617618
polarization_xyz.normalize();
618619
polarization_xyz = total_polarization * polarization_xyz;
619620

@@ -642,10 +643,10 @@ void berryphase::Macroscopic_polarization(const int npwx,
642643
int mod_elec_tot = 0;
643644
Berry_Phase(occ_nbands, pdl_elec_tot, mod_elec_tot, npwx, psi_in, rhopw, wfcpw, kv);
644645

645-
const double rmod = GlobalC::ucell.a2.norm() * GlobalC::ucell.lat0;
646+
const double rmod = ucell.a2.norm() * ucell.lat0;
646647
const double unit1 = rmod;
647-
const double unit2 = rmod / GlobalC::ucell.omega;
648-
const double unit3 = (rmod / GlobalC::ucell.omega) * (1.60097e-19 / pow(5.29177e-11, 2));
648+
const double unit2 = rmod / ucell.omega;
649+
const double unit3 = (rmod / ucell.omega) * (1.60097e-19 / pow(5.29177e-11, 2));
649650

650651
GlobalV::ofs_running << " VALUES OF POLARIZATION" << std::endl;
651652
GlobalV::ofs_running << std::endl;
@@ -659,7 +660,7 @@ void berryphase::Macroscopic_polarization(const int npwx,
659660
// calculate total polarization,add electron part and ions part
660661
double total_polarization = pdl_elec_tot + polarization_ion[1];
661662

662-
ModuleBase::Vector3<double> polarization_xyz = GlobalC::ucell.a2;
663+
ModuleBase::Vector3<double> polarization_xyz = ucell.a2;
663664
polarization_xyz.normalize();
664665
polarization_xyz = total_polarization * polarization_xyz;
665666

@@ -688,10 +689,10 @@ void berryphase::Macroscopic_polarization(const int npwx,
688689
int mod_elec_tot = 0;
689690
Berry_Phase(occ_nbands, pdl_elec_tot, mod_elec_tot, npwx, psi_in, rhopw, wfcpw, kv);
690691

691-
const double rmod = GlobalC::ucell.a3.norm() * GlobalC::ucell.lat0;
692+
const double rmod = ucell.a3.norm() * ucell.lat0;
692693
const double unit1 = rmod;
693-
const double unit2 = rmod / GlobalC::ucell.omega;
694-
const double unit3 = (rmod / GlobalC::ucell.omega) * (1.60097e-19 / pow(5.29177e-11, 2));
694+
const double unit2 = rmod / ucell.omega;
695+
const double unit3 = (rmod / ucell.omega) * (1.60097e-19 / pow(5.29177e-11, 2));
695696

696697
GlobalV::ofs_running << " VALUES OF POLARIZATION" << std::endl;
697698
GlobalV::ofs_running << std::endl;
@@ -705,7 +706,7 @@ void berryphase::Macroscopic_polarization(const int npwx,
705706
// calculate total polarization,add electron part and ions part
706707
double total_polarization = pdl_elec_tot + polarization_ion[2];
707708

708-
ModuleBase::Vector3<double> polarization_xyz = GlobalC::ucell.a3;
709+
ModuleBase::Vector3<double> polarization_xyz = ucell.a3;
709710
polarization_xyz.normalize();
710711
polarization_xyz = total_polarization * polarization_xyz;
711712

source/module_io/berryphase.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,17 @@ class berryphase
5858
const ModulePW::PW_Basis_K* wfcpw,
5959
const K_Vectors& kv);
6060

61-
void Macroscopic_polarization(const int npwx,
61+
void Macroscopic_polarization(const UnitCell& ucell,
62+
const int npwx,
6263
const psi::Psi<double>* psi_in,
6364
const ModulePW::PW_Basis* rhopw,
6465
const ModulePW::PW_Basis_K* wfcpw,
6566
const K_Vectors& kv)
6667
{
6768
throw std::logic_error("berry phase supports only multi-k");
6869
};
69-
void Macroscopic_polarization(const int npwx,
70+
void Macroscopic_polarization(const UnitCell& ucell,
71+
const int npwx,
7072
const psi::Psi<std::complex<double>>* psi_in,
7173
const ModulePW::PW_Basis* rhopw,
7274
const ModulePW::PW_Basis_K* wfcpw,

0 commit comments

Comments
 (0)