From 8badc4cc062eb043461d4492df41cf55a9ba4d35 Mon Sep 17 00:00:00 2001 From: wenfei-li Date: Mon, 30 Aug 2021 21:45:43 +0800 Subject: [PATCH] module cell:replace all GlobalC::ORB by passing variable; replace GlobalV::running_scf in setup_cell --- source/module_cell/read_atoms.cpp | 30 ++++-- source/module_cell/unitcell_pseudo.cpp | 126 +++++++++++++++---------- source/module_cell/unitcell_pseudo.h | 16 ++++ source/module_md/MD_func.cpp | 4 + source/module_md/run_md_classic.cpp | 6 +- source/run_lcao.cpp | 4 + source/run_pw.cpp | 4 + source/src_ions/ions_move_methods.cpp | 4 + 8 files changed, 133 insertions(+), 61 deletions(-) diff --git a/source/module_cell/read_atoms.cpp b/source/module_cell/read_atoms.cpp index 7601fa5797f..9daade4c1f3 100644 --- a/source/module_cell/read_atoms.cpp +++ b/source/module_cell/read_atoms.cpp @@ -8,7 +8,11 @@ #endif #include // Peize Lin fix bug about strcmp 2016-08-02 +#ifdef __LCAO +void UnitCell_pseudo::read_atom_species(std::ifstream &ifa, std::ofstream &ofs_running, LCAO_Orbitals &orb ) +#else void UnitCell_pseudo::read_atom_species(std::ifstream &ifa, std::ofstream &ofs_running) +#endif { ModuleBase::TITLE("UnitCell_pseudo","read_atom_species"); @@ -53,7 +57,7 @@ void UnitCell_pseudo::read_atom_species(std::ifstream &ifa, std::ofstream &ofs_r { if( ModuleBase::GlobalFunc::SCAN_BEGIN(ifa, "NUMERICAL_ORBITAL") ) { - GlobalC::ORB.read_in_flag = true; + orb.read_in_flag = true; for(int i=0; i> GlobalC::ORB.descriptor_file; + ifa >> orb.descriptor_file; } } // Peize Lin add 2016-09-23 +#ifndef __CELL if( Exx_Global::Hybrid_Type::HF == GlobalC::exx_lcao.info.hybrid_type || Exx_Global::Hybrid_Type::PBE0 == GlobalC::exx_lcao.info.hybrid_type || Exx_Global::Hybrid_Type::HSE == GlobalC::exx_lcao.info.hybrid_type ) @@ -108,6 +113,7 @@ void UnitCell_pseudo::read_atom_species(std::ifstream &ifa, std::ofstream &ofs_r } } } +#endif #endif //========================== // read in lattice constant @@ -338,7 +344,11 @@ void UnitCell_pseudo::read_atom_species(std::ifstream &ifa, std::ofstream &ofs_r // Read atomic positions // return 1: no problem. // return 0: some problems. +#ifdef __LCAO +bool UnitCell_pseudo::read_atom_positions(std::ifstream &ifpos, std::ofstream &ofs_running, std::ofstream &ofs_warning, LCAO_Orbitals &orb) +#else bool UnitCell_pseudo::read_atom_positions(std::ifstream &ifpos, std::ofstream &ofs_running, std::ofstream &ofs_warning) +#endif { ModuleBase::TITLE("UnitCell_pseudo","read_atom_positions"); @@ -452,13 +462,13 @@ bool UnitCell_pseudo::read_atom_positions(std::ifstream &ifpos, std::ofstream &o #ifdef __LCAO if (GlobalV::BASIS_TYPE == "lcao" || GlobalV::BASIS_TYPE == "lcao_in_pw") { - std::ifstream ifs(GlobalC::ORB.orbital_file[it].c_str(), ios::in); // pengfei 2014-10-13 + std::ifstream ifs(orb.orbital_file[it].c_str(), ios::in); // pengfei 2014-10-13 // mohan add return 2021-04-26 if (!ifs) { std::cout << " Element index " << it+1 << std::endl; - std::cout << " orbital file: " << GlobalC::ORB.orbital_file[it] << std::endl; + std::cout << " orbital file: " << orb.orbital_file[it] << std::endl; ModuleBase::WARNING("read_atom_positions","ABACUS Cannot find the ORBITAL file (basis sets)"); return 0; // means something wrong } @@ -820,7 +830,11 @@ bool UnitCell_pseudo::check_tau(void)const return 1; } +#ifdef __LCAO +void UnitCell_pseudo::print_stru_file(const std::string &fn, const LCAO_Orbitals &orb, const int &type)const +#else void UnitCell_pseudo::print_stru_file(const std::string &fn, const int &type)const +#endif { ModuleBase::TITLE("UnitCell_pseudo","print_stru_file"); @@ -847,9 +861,9 @@ void UnitCell_pseudo::print_stru_file(const std::string &fn, const int &type)con // Turn off the read in NONLOCAL file // function since 2013-08-02 by mohan //----------------------------------- -// ofs << GlobalC::ORB.orbital_file[it] << " " << GlobalC::ORB.nonlocal_file[it] << " #local_orbital; non-local projector" << std::endl; +// ofs << orb.orbital_file[it] << " " << orb.nonlocal_file[it] << " #local_orbital; non-local projector" << std::endl; //modified by zhengdy 2015-07-24 - ofs << GlobalC::ORB.orbital_file[it] << std::endl; + ofs << orb.orbital_file[it] << std::endl; } } #endif diff --git a/source/module_cell/unitcell_pseudo.cpp b/source/module_cell/unitcell_pseudo.cpp index 19a252697da..a2742cc0063 100644 --- a/source/module_cell/unitcell_pseudo.cpp +++ b/source/module_cell/unitcell_pseudo.cpp @@ -24,6 +24,9 @@ UnitCell_pseudo::~UnitCell_pseudo() //Calculate various lattice related quantities for given latvec //============================================================== void UnitCell_pseudo::setup_cell( +#ifdef __LCAO + LCAO_Orbitals &orb, +#endif const std::string &s_pseudopot_dir, output &outp, const std::string &fn, @@ -62,32 +65,40 @@ void UnitCell_pseudo::setup_cell( if(ok) { - GlobalV::ofs_running << "\n\n\n\n"; - GlobalV::ofs_running << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl; - GlobalV::ofs_running << " | |" << std::endl; - GlobalV::ofs_running << " | Reading atom information in unitcell: |" << std::endl; - GlobalV::ofs_running << " | From the input file and the structure file we know the number of |" << std::endl; - GlobalV::ofs_running << " | different elments in this unitcell, then we list the detail |" << std::endl; - GlobalV::ofs_running << " | information for each element, especially the zeta and polar atomic |" << std::endl; - GlobalV::ofs_running << " | orbital number for each element. The total atom number is counted. |" << std::endl; - GlobalV::ofs_running << " | We calculate the nearest atom distance for each atom and show the |" << std::endl; - GlobalV::ofs_running << " | Cartesian and Direct coordinates for each atom. We list the file |" << std::endl; - GlobalV::ofs_running << " | address for atomic orbitals. The volume and the lattice vectors |" << std::endl; - GlobalV::ofs_running << " | in real and reciprocal space is also shown. |" << std::endl; - GlobalV::ofs_running << " | |" << std::endl; - GlobalV::ofs_running << " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl; - GlobalV::ofs_running << "\n\n\n\n"; - - GlobalV::ofs_running << " READING UNITCELL INFORMATION" << std::endl; + log << "\n\n\n\n"; + log << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl; + log << " | |" << std::endl; + log << " | Reading atom information in unitcell: |" << std::endl; + log << " | From the input file and the structure file we know the number of |" << std::endl; + log << " | different elments in this unitcell, then we list the detail |" << std::endl; + log << " | information for each element, especially the zeta and polar atomic |" << std::endl; + log << " | orbital number for each element. The total atom number is counted. |" << std::endl; + log << " | We calculate the nearest atom distance for each atom and show the |" << std::endl; + log << " | Cartesian and Direct coordinates for each atom. We list the file |" << std::endl; + log << " | address for atomic orbitals. The volume and the lattice vectors |" << std::endl; + log << " | in real and reciprocal space is also shown. |" << std::endl; + log << " | |" << std::endl; + log << " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl; + log << "\n\n\n\n"; + + log << " READING UNITCELL INFORMATION" << std::endl; //======================== // call read_atom_species //======================== - this->read_atom_species(ifa, GlobalV::ofs_running); +#ifdef __LCAO + this->read_atom_species(ifa, log, orb); +#else + this->read_atom_species(ifa, log); +#endif //========================== // call read_atom_positions //========================== - ok2 = this->read_atom_positions(ifa, GlobalV::ofs_running, GlobalV::ofs_warning); +#ifdef __LCAO + ok2 = this->read_atom_positions(ifa, log, GlobalV::ofs_warning, orb); +#else + ok2 = this->read_atom_positions(ifa, log, GlobalV::ofs_warning); +#endif if(ok2) { @@ -121,7 +132,7 @@ void UnitCell_pseudo::setup_cell( // mohan add 2010-09-29 #ifdef __LCAO - GlobalC::ORB.bcast_files(ntype, GlobalV::MY_RANK); + orb.bcast_files(ntype, GlobalV::MY_RANK); #endif #endif @@ -138,9 +149,9 @@ void UnitCell_pseudo::setup_cell( } else { - GlobalV::ofs_running << std::endl; - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Volume (Bohr^3)", this->omega); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Volume (A^3)", this->omega * pow(ModuleBase::BOHR_TO_A, 3)); + log << std::endl; + ModuleBase::GlobalFunc::OUT(log,"Volume (Bohr^3)", this->omega); + ModuleBase::GlobalFunc::OUT(log,"Volume (A^3)", this->omega * pow(ModuleBase::BOHR_TO_A, 3)); } //========================================================== @@ -158,31 +169,31 @@ void UnitCell_pseudo::setup_cell( this->GGT0 = G * GT; this->invGGT0 = GGT.Inverse(); - GlobalV::ofs_running << std::endl; - outp.printM3(GlobalV::ofs_running,"Lattice vectors: (Cartesian coordinate: in unit of a_0)",latvec); - outp.printM3(GlobalV::ofs_running,"Reciprocal vectors: (Cartesian coordinate: in unit of 2 pi/a_0)",G); -// OUT(GlobalV::ofs_running,"lattice center x",latcenter.x); -// OUT(GlobalV::ofs_running,"lattice center y",latcenter.y); -// OUT(GlobalV::ofs_running,"lattice center z",latcenter.z); + log << std::endl; + outp.printM3(log,"Lattice vectors: (Cartesian coordinate: in unit of a_0)",latvec); + outp.printM3(log,"Reciprocal vectors: (Cartesian coordinate: in unit of 2 pi/a_0)",G); +// OUT(log,"lattice center x",latcenter.x); +// OUT(log,"lattice center y",latcenter.y); +// OUT(log,"lattice center z",latcenter.z); // read in non-local pseudopotential and ouput the projectors. - GlobalV::ofs_running << "\n\n\n\n"; - GlobalV::ofs_running << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl; - GlobalV::ofs_running << " | |" << std::endl; - GlobalV::ofs_running << " | Reading pseudopotentials files: |" << std::endl; - GlobalV::ofs_running << " | The pseudopotential file is in UPF format. The 'NC' indicates that |" << std::endl; - GlobalV::ofs_running << " | the type of pseudopotential is 'norm conserving'. Functional of |" << std::endl; - GlobalV::ofs_running << " | exchange and correlation is decided by 4 given parameters in UPF |" << std::endl; - GlobalV::ofs_running << " | file. We also read in the 'core correction' if there exists. |" << std::endl; - GlobalV::ofs_running << " | Also we can read the valence electrons number and the maximal |" << std::endl; - GlobalV::ofs_running << " | angular momentum used in this pseudopotential. We also read in the |" << std::endl; - GlobalV::ofs_running << " | trail wave function, trail atomic density and local-pseudopotential|" << std::endl; - GlobalV::ofs_running << " | on logrithmic grid. The non-local pseudopotential projector is also|" << std::endl; - GlobalV::ofs_running << " | read in if there is any. |" << std::endl; - GlobalV::ofs_running << " | |" << std::endl; - GlobalV::ofs_running << " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl; - GlobalV::ofs_running << "\n\n\n\n"; + log << "\n\n\n\n"; + log << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl; + log << " | |" << std::endl; + log << " | Reading pseudopotentials files: |" << std::endl; + log << " | The pseudopotential file is in UPF format. The 'NC' indicates that |" << std::endl; + log << " | the type of pseudopotential is 'norm conserving'. Functional of |" << std::endl; + log << " | exchange and correlation is decided by 4 given parameters in UPF |" << std::endl; + log << " | file. We also read in the 'core correction' if there exists. |" << std::endl; + log << " | Also we can read the valence electrons number and the maximal |" << std::endl; + log << " | angular momentum used in this pseudopotential. We also read in the |" << std::endl; + log << " | trail wave function, trail atomic density and local-pseudopotential|" << std::endl; + log << " | on logrithmic grid. The non-local pseudopotential projector is also|" << std::endl; + log << " | read in if there is any. |" << std::endl; + log << " | |" << std::endl; + log << " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl; + log << "\n\n\n\n"; this->read_cell_pseudopots(s_pseudopot_dir); @@ -306,6 +317,9 @@ void UnitCell_pseudo::setup_cell( } void UnitCell_pseudo::setup_cell_classic( +#ifdef __LCAO + LCAO_Orbitals &orb, +#endif const std::string &fn, std::ofstream &ofs_running, std::ofstream &ofs_warning) @@ -352,11 +366,19 @@ void UnitCell_pseudo::setup_cell_classic( //======================== // call read_atom_species //======================== +#ifdef __LCAO + this->read_atom_species(ifa, ofs_running, orb); +#else this->read_atom_species(ifa, ofs_running); +#endif //========================== // call read_atom_positions //========================== +#ifdef __LCAO + ok2 = this->read_atom_positions(ifa, ofs_running, ofs_warning, orb); +#else ok2 = this->read_atom_positions(ifa, ofs_running, ofs_warning); +#endif if(ok2) { for(int i=0;intype;i++) @@ -658,9 +680,9 @@ void UnitCell_pseudo::setup_cell_after_vc( } else { - GlobalV::ofs_running << std::endl; - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "Volume (Bohr^3)", this->omega); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "Volume (A^3))", this->omega * pow(ModuleBase::BOHR_TO_A, 3)); + log << std::endl; + ModuleBase::GlobalFunc::OUT(log, "Volume (Bohr^3)", this->omega); + ModuleBase::GlobalFunc::OUT(log, "Volume (A^3))", this->omega * pow(ModuleBase::BOHR_TO_A, 3)); } //========================================================== @@ -698,9 +720,9 @@ Parallel_Common::bcast_double( atom->taud[ia].z ); } #endif - GlobalV::ofs_running << std::endl; - outp.printM3(GlobalV::ofs_running,"Lattice vectors: (Cartesian coordinate: in unit of a_0)",latvec); - outp.printM3(GlobalV::ofs_running,"Reciprocal vectors: (Cartesian coordinate: in unit of 2 pi/a_0)",G); + log << std::endl; + outp.printM3(log,"Lattice vectors: (Cartesian coordinate: in unit of a_0)",latvec); + outp.printM3(log,"Reciprocal vectors: (Cartesian coordinate: in unit of 2 pi/a_0)",G); return; } @@ -728,4 +750,4 @@ bool UnitCell_pseudo::if_cell_can_change()const return 1; } return 0; -} \ No newline at end of file +} diff --git a/source/module_cell/unitcell_pseudo.h b/source/module_cell/unitcell_pseudo.h index c5b13c06e23..b4a3b0a9a45 100644 --- a/source/module_cell/unitcell_pseudo.h +++ b/source/module_cell/unitcell_pseudo.h @@ -5,6 +5,7 @@ #include "../src_pw/tools.h" #include "../src_io/output.h" #include "unitcell.h" +#include "../module_orbital/ORB_read.h" class UnitCell_pseudo : public UnitCell { @@ -32,19 +33,34 @@ class UnitCell_pseudo : public UnitCell UnitCell_pseudo(); ~UnitCell_pseudo(); void setup_cell( +#ifdef __LCAO + LCAO_Orbitals &orb, +#endif const std::string &s_pseudopot_dir, output &outp, const std::string &fn, std::ofstream &log); void setup_cell_classic( +#ifdef __LCAO + LCAO_Orbitals &orb, +#endif const std::string &fn, std::ofstream &ofs_running, std::ofstream &ofs_warning); // liuyu 2021-07-13, RX changed ofs_running and ofs_warning from globalV to inputs. 2021-07-24 +#ifdef __LCAO + void read_atom_species(std::ifstream &ifa, std::ofstream &ofs_running, LCAO_Orbitals &orb); + bool read_atom_positions(std::ifstream &ifpos, std::ofstream &ofs_running, std::ofstream &ofs_warning, LCAO_Orbitals &orb); // read in atomic positions +#else void read_atom_species(std::ifstream &ifa, std::ofstream &ofs_running); // read in the atom information for each type of atom bool read_atom_positions(std::ifstream &ifpos, std::ofstream &ofs_running, std::ofstream &ofs_warning); // read in atomic positions +#endif int find_type(const std::string &label); void print_tau(void)const; +#ifdef __LCAO + void print_stru_file(const std::string &fn, const LCAO_Orbitals &orb, const int &type=1)const; // mohan add 2011-03-22 +#else void print_stru_file(const std::string &fn, const int &type=1)const; // mohan add 2011-03-22 +#endif void check_dtau(void); void setup_cell_after_vc(const std::string &s_pseudopot_dir, output &outp, const std::string &fn, std::ofstream &log); //LiuXh add 20180515 diff --git a/source/module_md/MD_func.cpp b/source/module_md/MD_func.cpp index 28b5cfe31b5..089cb061f01 100644 --- a/source/module_md/MD_func.cpp +++ b/source/module_md/MD_func.cpp @@ -285,7 +285,11 @@ void MD_func::printpos(const std::string& file, const int& iter, const int& reco ss << GlobalV::global_out_dir << "STRU_MD"; //zhengdy modify 2015-05-06, outputfile "STRU_Restart" +#ifdef __LCAO + unit_in.print_stru_file(ss.str(),GlobalC::ORB,2); +#else unit_in.print_stru_file(ss.str(),2); +#endif return; } diff --git a/source/module_md/run_md_classic.cpp b/source/module_md/run_md_classic.cpp index 0ecdc190a15..97f0afd376c 100644 --- a/source/module_md/run_md_classic.cpp +++ b/source/module_md/run_md_classic.cpp @@ -33,7 +33,11 @@ void Run_MD_CLASSIC::classic_md_line(void) ModuleBase::timer::tick("Run_MD_CLASSIC", "classic_md_line"); // Setup the unitcell. +#ifdef __LCAO + ucell_c.setup_cell_classic(GlobalC::ORB, GlobalV::global_atom_card, GlobalV::ofs_running, GlobalV::ofs_warning); +#else ucell_c.setup_cell_classic(GlobalV::global_atom_card, GlobalV::ofs_running, GlobalV::ofs_warning); +#endif ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "SETUP UNITCELL"); this->md_allocate_ions(); @@ -192,4 +196,4 @@ void Run_MD_CLASSIC::update_pos_classic(void) } this->ucell_c.save_cartesian_position(this->pos_now); return; -} \ No newline at end of file +} diff --git a/source/run_lcao.cpp b/source/run_lcao.cpp index 203a980b5b9..8a3c00a868b 100644 --- a/source/run_lcao.cpp +++ b/source/run_lcao.cpp @@ -22,7 +22,11 @@ void Run_lcao::lcao_line(void) // Setup the unitcell. // improvement: a) separating the first reading of the atom_card and subsequent // cell relaxation. b) put GlobalV::NLOCAL and GlobalV::NBANDS as input parameters +#ifdef __LCAO + GlobalC::ucell.setup_cell( GlobalC::ORB, GlobalV::global_pseudo_dir, GlobalC::out, GlobalV::global_atom_card, GlobalV::ofs_running); +#else GlobalC::ucell.setup_cell( GlobalV::global_pseudo_dir, GlobalC::out, GlobalV::global_atom_card, GlobalV::ofs_running); +#endif if(INPUT.test_just_neighbor) { //test_search_neighbor(); diff --git a/source/run_pw.cpp b/source/run_pw.cpp index 908e81fea5d..140fb862e9f 100644 --- a/source/run_pw.cpp +++ b/source/run_pw.cpp @@ -23,7 +23,11 @@ void Run_pw::plane_wave_line(void) // Setup the unitcell. // improvement: a) separating the first reading of the atom_card and subsequent // cell relaxation. b) put GlobalV::NLOCAL and GlobalV::NBANDS as input parameters +#ifdef __LCAO + GlobalC::ucell.setup_cell( GlobalC::ORB, GlobalV::global_pseudo_dir, GlobalC::out, GlobalV::global_atom_card, GlobalV::ofs_running); +#else GlobalC::ucell.setup_cell( GlobalV::global_pseudo_dir, GlobalC::out, GlobalV::global_atom_card, GlobalV::ofs_running); +#endif //GlobalC::ucell.setup_cell( GlobalV::global_pseudo_dir , GlobalV::global_atom_card , GlobalV::ofs_running, GlobalV::NLOCAL, GlobalV::NBANDS); // setup GlobalV::NBANDS diff --git a/source/src_ions/ions_move_methods.cpp b/source/src_ions/ions_move_methods.cpp index 2d74e5eecfe..52f14dc3323 100644 --- a/source/src_ions/ions_move_methods.cpp +++ b/source/src_ions/ions_move_methods.cpp @@ -78,7 +78,11 @@ void Ions_Move_Methods::cal_movement(const int &istep, const int &force_step, co //xiaohui modify 2015-03-15, cancel outputfile "STRU_ION" //GlobalC::ucell.print_stru_file(ss.str(),1); ss << "_D"; +#ifdef __LCAO + GlobalC::ucell.print_stru_file(ss.str(),GlobalC::ORB,2); +#else GlobalC::ucell.print_stru_file(ss.str(),2); +#endif return; }