@@ -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
0 commit comments