diff --git a/source/driver_run.cpp b/source/driver_run.cpp index 1019887df5..9955503d90 100644 --- a/source/driver_run.cpp +++ b/source/driver_run.cpp @@ -40,10 +40,10 @@ void Driver::driver_run() // the life of ucell should begin here, mohan 2024-05-12 UnitCell ucell; ucell.setup(PARAM.inp.latname, - PARAM.inp.ntype, - PARAM.inp.lmaxmax, - PARAM.inp.init_vel, - PARAM.inp.fixed_axes); + PARAM.inp.ntype, + PARAM.inp.lmaxmax, + PARAM.inp.init_vel, + PARAM.inp.fixed_axes); ucell.setup_cell(PARAM.globalv.global_in_stru, GlobalV::ofs_running); Check_Atomic_Stru::check_atomic_stru(ucell, PARAM.inp.min_dist_coef); diff --git a/source/module_basis/module_ao/test/ORB_unittest.cpp b/source/module_basis/module_ao/test/ORB_unittest.cpp index 60891bb9db..adec0796c3 100644 --- a/source/module_basis/module_ao/test/ORB_unittest.cpp +++ b/source/module_basis/module_ao/test/ORB_unittest.cpp @@ -28,7 +28,6 @@ void test_orb::TearDown() } ooo.clear_after_ions(OGT, ORB, 0, nproj); delete[] nproj; - delete[] orbital_fn; return; } @@ -75,7 +74,7 @@ void test_orb::set_orbs() ORB.init(ofs_running, ntype_read, "./", - orbital_fn, + orbital_fn.data(), descriptor_file, lmax, lcao_ecut, @@ -114,7 +113,7 @@ void test_orb::set_files() ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "NUMERICAL_ORBITAL"); - orbital_fn = new std::string[ntype_read]; + orbital_fn.resize(ntype_read); for (int it = 0; it < ntype_read; it++) { diff --git a/source/module_basis/module_ao/test/ORB_unittest.h b/source/module_basis/module_ao/test/ORB_unittest.h index 0352c63912..509a72541c 100644 --- a/source/module_basis/module_ao/test/ORB_unittest.h +++ b/source/module_basis/module_ao/test/ORB_unittest.h @@ -51,7 +51,7 @@ class test_orb : public testing::Test double randr(double Rmax); void gen_table_center2(); - bool force_flag = 0; + bool force_flag = false; int my_rank = 0; int ntype_read; @@ -66,7 +66,7 @@ class test_orb : public testing::Test int lmax = 1; double lat0 = 1.0; std::string case_dir = "./GaAs/"; - std::string* orbital_fn; + std::vector orbital_fn; std::string descriptor_file; }; #endif diff --git a/source/module_cell/bcast_cell.cpp b/source/module_cell/bcast_cell.cpp index f591f3c156..9fee31ef0c 100644 --- a/source/module_cell/bcast_cell.cpp +++ b/source/module_cell/bcast_cell.cpp @@ -1,5 +1,10 @@ #include "unitcell.h" - +#include "module_base/parallel_common.h" +#include "module_parameter/parameter.h" +#ifdef __EXX +#include "module_ri/serialization_cereal.h" +#include "module_hamilt_pw/hamilt_pwdft/global.h" +#endif namespace unitcell { void bcast_atoms_tau(Atom* atoms, @@ -12,4 +17,105 @@ namespace unitcell } #endif } + + void bcast_atoms_pseudo(Atom* atoms, + const int ntype) + { + #ifdef __MPI + MPI_Barrier(MPI_COMM_WORLD); + for (int i = 0; i < ntype; i++) + { + atoms[i].bcast_atom2(); + } + #endif + } + + void bcast_Lattice(Lattice& lat) + { + #ifdef __MPI + MPI_Barrier(MPI_COMM_WORLD); + // distribute lattice parameters. + ModuleBase::Matrix3& latvec = lat.latvec; + ModuleBase::Matrix3& latvec_supercell = lat.latvec_supercell; + Parallel_Common::bcast_string(lat.Coordinate); + Parallel_Common::bcast_double(lat.lat0); + Parallel_Common::bcast_double(lat.lat0_angstrom); + Parallel_Common::bcast_double(lat.tpiba); + Parallel_Common::bcast_double(lat.tpiba2); + Parallel_Common::bcast_double(lat.omega); + Parallel_Common::bcast_string(lat.latName); + + // distribute lattice vectors. + Parallel_Common::bcast_double(latvec.e11); + Parallel_Common::bcast_double(latvec.e12); + Parallel_Common::bcast_double(latvec.e13); + Parallel_Common::bcast_double(latvec.e21); + Parallel_Common::bcast_double(latvec.e22); + Parallel_Common::bcast_double(latvec.e23); + Parallel_Common::bcast_double(latvec.e31); + Parallel_Common::bcast_double(latvec.e32); + Parallel_Common::bcast_double(latvec.e33); + + // distribute lattice vectors. + for (int i = 0; i < 3; i++) + { + Parallel_Common::bcast_double(lat.a1[i]); + Parallel_Common::bcast_double(lat.a2[i]); + Parallel_Common::bcast_double(lat.a3[i]); + Parallel_Common::bcast_double(lat.latcenter[i]); + Parallel_Common::bcast_int(lat.lc[i]); + } + + // distribute superlattice vectors. + Parallel_Common::bcast_double(latvec_supercell.e11); + Parallel_Common::bcast_double(latvec_supercell.e12); + Parallel_Common::bcast_double(latvec_supercell.e13); + Parallel_Common::bcast_double(latvec_supercell.e21); + Parallel_Common::bcast_double(latvec_supercell.e22); + Parallel_Common::bcast_double(latvec_supercell.e23); + Parallel_Common::bcast_double(latvec_supercell.e31); + Parallel_Common::bcast_double(latvec_supercell.e32); + Parallel_Common::bcast_double(latvec_supercell.e33); + + // distribute Change the lattice vectors or not + #endif + } + + void bcast_magnetism(Magnetism& magnet, const int ntype) + { + #ifdef __MPI + MPI_Barrier(MPI_COMM_WORLD); + Parallel_Common::bcast_double(magnet.start_magnetization, ntype); + if (PARAM.inp.nspin == 4) + { + Parallel_Common::bcast_double(magnet.ux_[0]); + Parallel_Common::bcast_double(magnet.ux_[1]); + Parallel_Common::bcast_double(magnet.ux_[2]); + } + #endif + } + + void bcast_unitcell(UnitCell& ucell) + { + #ifdef __MPI + const int ntype = ucell.ntype; + Parallel_Common::bcast_int(ucell.nat); + + bcast_Lattice(ucell.lat); + bcast_magnetism(ucell.magnet,ntype); + bcast_atoms_tau(ucell.atoms,ntype); + + for (int i = 0; i < ntype; i++) + { + Parallel_Common::bcast_string(ucell.orbital_fn[i]); + } + + #ifdef __EXX + ModuleBase::bcast_data_cereal(GlobalC::exx_info.info_ri.files_abfs, + MPI_COMM_WORLD, + 0); + #endif + return; + #endif + } } \ No newline at end of file diff --git a/source/module_cell/bcast_cell.h b/source/module_cell/bcast_cell.h index 4cee843a3d..65c6d0a477 100644 --- a/source/module_cell/bcast_cell.h +++ b/source/module_cell/bcast_cell.h @@ -1,10 +1,50 @@ #ifndef BCAST_CELL_H #define BCAST_CELL_H +#include "module_cell/unitcell.h" namespace unitcell { + /** + * @brief broadcast the tau array of the atoms + * + * @param atoms: the atoms to be broadcasted [in/out] + * @param ntype: the number of types of the atoms [in] + */ void bcast_atoms_tau(Atom* atoms, + const int ntype); + + /** + * @brief broadcast the pseduo of the atoms + * + * @param atoms: the atoms to be broadcasted [in/out] + * @param ntype: the number of types of the atoms [in] + */ + void bcast_atoms_pseudo(Atom* atoms, + const int ntype); + /** + * @brief broadcast the lattice + * + * @param lat: the lattice to be broadcasted [in/out] + */ + void bcast_Lattice(Lattice& lat); + + /** + * @brief broadcast the magnetism + * + * @param magnet: the magnetism to be broadcasted [in/out] + * @param nytpe: the number of types of the atoms [in] + */ + void bcast_magnetism(Magnetism& magnet, const int ntype); + + /** + * @brief broadcast the unitcell + * + * @param ucell: the unitcell to be broadcasted [in/out] + */ + void bcast_unitcell(UnitCell& ucell); + + } #endif // BCAST_CELL_H \ No newline at end of file diff --git a/source/module_cell/module_neighbor/test/prepare_unitcell.h b/source/module_cell/module_neighbor/test/prepare_unitcell.h index e3a2e80e04..e29339ed1a 100644 --- a/source/module_cell/module_neighbor/test/prepare_unitcell.h +++ b/source/module_cell/module_neighbor/test/prepare_unitcell.h @@ -80,13 +80,13 @@ class UcellTestPrepare delete[] ucell->atom_mass; delete[] ucell->pseudo_fn; delete[] ucell->pseudo_type; - delete[] ucell->orbital_fn; + delete[] ucell->magnet.start_magnetization; //mag set here ucell->atom_label = new std::string[ucell->ntype]; ucell->atom_mass = new double[ucell->ntype]; ucell->pseudo_fn = new std::string[ucell->ntype]; ucell->pseudo_type = new std::string[ucell->ntype]; - ucell->orbital_fn = new std::string[ucell->ntype]; + ucell->orbital_fn.resize(ucell->ntype); ucell->magnet.start_magnetization = new double[ucell->ntype]; //mag set here ucell->magnet.ux_[0] = 0.0; // ux_ set here ucell->magnet.ux_[1] = 0.0; diff --git a/source/module_cell/read_atoms.cpp b/source/module_cell/read_atoms.cpp index 736a0aec06..acf54c4e7d 100644 --- a/source/module_cell/read_atoms.cpp +++ b/source/module_cell/read_atoms.cpp @@ -20,12 +20,10 @@ int UnitCell::read_atom_species(std::ifstream &ifa, std::ofstream &ofs_running) delete[] atom_mass; delete[] pseudo_fn; delete[] pseudo_type; - delete[] orbital_fn; this->atom_mass = new double[ntype]; //atom masses this->atom_label = new std::string[ntype]; //atom labels this->pseudo_fn = new std::string[ntype]; //file name of pseudopotential this->pseudo_type = new std::string[ntype]; // type of pseudopotential - this->orbital_fn = new std::string[ntype]; // filename of orbitals std::string word; //========================================== diff --git a/source/module_cell/test/prepare_unitcell.h b/source/module_cell/test/prepare_unitcell.h index 3890670e18..173537ffdc 100644 --- a/source/module_cell/test/prepare_unitcell.h +++ b/source/module_cell/test/prepare_unitcell.h @@ -79,13 +79,13 @@ class UcellTestPrepare delete[] ucell->atom_mass; delete[] ucell->pseudo_fn; delete[] ucell->pseudo_type; - delete[] ucell->orbital_fn; + delete[] ucell->magnet.start_magnetization; //mag set here ucell->atom_label = new std::string[ucell->ntype]; ucell->atom_mass = new double[ucell->ntype]; ucell->pseudo_fn = new std::string[ucell->ntype]; ucell->pseudo_type = new std::string[ucell->ntype]; - ucell->orbital_fn = new std::string[ucell->ntype]; + ucell->orbital_fn.resize(ucell->ntype); ucell->magnet.start_magnetization = new double[ucell->ntype]; //mag set here ucell->magnet.ux_[0] = 0.0; // ux_ set here ucell->magnet.ux_[1] = 0.0; diff --git a/source/module_cell/test/support/mock_unitcell.cpp b/source/module_cell/test/support/mock_unitcell.cpp index c619a1f90a..d944dc7868 100644 --- a/source/module_cell/test/support/mock_unitcell.cpp +++ b/source/module_cell/test/support/mock_unitcell.cpp @@ -17,7 +17,6 @@ UnitCell::~UnitCell() { delete[] atom_mass; delete[] pseudo_fn; delete[] pseudo_type; - delete[] orbital_fn; if (set_atom_flag) { delete[] atoms; } @@ -37,10 +36,6 @@ bool UnitCell::read_atom_positions(std::ifstream& ifpos, bool UnitCell::judge_big_cell() const { return true; } void UnitCell::update_stress(ModuleBase::matrix& scs) {} void UnitCell::update_force(ModuleBase::matrix& fcs) {} -#ifdef __MPI -void UnitCell::bcast_unitcell() {} -void UnitCell::bcast_unitcell2() {} -#endif void UnitCell::set_iat2itia() {} void UnitCell::setup_cell(const std::string& fn, std::ofstream& log) {} void UnitCell::read_orb_file(int it, diff --git a/source/module_cell/test/unitcell_test.cpp b/source/module_cell/test/unitcell_test.cpp index 738ee8714f..30b0c299c9 100644 --- a/source/module_cell/test/unitcell_test.cpp +++ b/source/module_cell/test/unitcell_test.cpp @@ -1094,8 +1094,23 @@ TEST_F(UcellDeathTest, ReadOrbFileWarning) ofs_running.close(); remove("tmp_readorbfile"); } +class UcellTestReadStru : public ::testing::Test +{ + protected: + std::unique_ptr ucell{new UnitCell}; + std::string output; + void SetUp() override + { + ucell->ntype = 2; + ucell->orbital_fn.resize(ucell->ntype); + } + void TearDown() override + { + ucell->orbital_fn.shrink_to_fit(); + } +}; -TEST_F(UcellTest, ReadAtomSpecies) +TEST_F(UcellTestReadStru, ReadAtomSpecies) { std::string fn = "./support/STRU_MgO"; std::ifstream ifa(fn.c_str()); @@ -1191,7 +1206,7 @@ TEST_F(UcellDeathTest, ReadAtomSpeciesWarning4) remove("read_atom_species.tmp"); } -TEST_F(UcellTest, ReadAtomSpeciesLatName) +TEST_F(UcellTestReadStru, ReadAtomSpeciesLatName) { ucell->ntype = 2; ucell->atoms = new Atom[ucell->ntype]; @@ -1249,7 +1264,7 @@ TEST_F(UcellDeathTest, ReadAtomSpeciesWarning5) remove("read_atom_species.tmp"); } -TEST_F(UcellTest, ReadAtomPositionsS1) +TEST_F(UcellTestReadStru, ReadAtomPositionsS1) { std::string fn = "./support/STRU_MgO"; std::ifstream ifa(fn.c_str()); @@ -1280,7 +1295,7 @@ TEST_F(UcellTest, ReadAtomPositionsS1) remove("read_atom_positions.warn"); } -TEST_F(UcellTest, ReadAtomPositionsS2) +TEST_F(UcellTestReadStru, ReadAtomPositionsS2) { std::string fn = "./support/STRU_MgO"; std::ifstream ifa(fn.c_str()); @@ -1311,7 +1326,7 @@ TEST_F(UcellTest, ReadAtomPositionsS2) remove("read_atom_positions.warn"); } -TEST_F(UcellTest, ReadAtomPositionsS4Noncolin) +TEST_F(UcellTestReadStru, ReadAtomPositionsS4Noncolin) { std::string fn = "./support/STRU_MgO"; std::ifstream ifa(fn.c_str()); @@ -1343,7 +1358,7 @@ TEST_F(UcellTest, ReadAtomPositionsS4Noncolin) remove("read_atom_positions.warn"); } -TEST_F(UcellTest, ReadAtomPositionsS4Colin) +TEST_F(UcellTestReadStru, ReadAtomPositionsS4Colin) { std::string fn = "./support/STRU_MgO"; std::ifstream ifa(fn.c_str()); @@ -1375,7 +1390,7 @@ TEST_F(UcellTest, ReadAtomPositionsS4Colin) remove("read_atom_positions.warn"); } -TEST_F(UcellTest, ReadAtomPositionsC) +TEST_F(UcellTestReadStru, ReadAtomPositionsC) { std::string fn = "./support/STRU_MgO_c"; std::ifstream ifa(fn.c_str()); @@ -1406,7 +1421,7 @@ TEST_F(UcellTest, ReadAtomPositionsC) remove("read_atom_positions.warn"); } -TEST_F(UcellTest, ReadAtomPositionsCA) +TEST_F(UcellTestReadStru, ReadAtomPositionsCA) { std::string fn = "./support/STRU_MgO_ca"; std::ifstream ifa(fn.c_str()); @@ -1437,7 +1452,7 @@ TEST_F(UcellTest, ReadAtomPositionsCA) remove("read_atom_positions.warn"); } -TEST_F(UcellTest, ReadAtomPositionsCACXY) +TEST_F(UcellTestReadStru, ReadAtomPositionsCACXY) { std::string fn = "./support/STRU_MgO_cacxy"; std::ifstream ifa(fn.c_str()); @@ -1468,7 +1483,7 @@ TEST_F(UcellTest, ReadAtomPositionsCACXY) remove("read_atom_positions.warn"); } -TEST_F(UcellTest, ReadAtomPositionsCACXZ) +TEST_F(UcellTestReadStru, ReadAtomPositionsCACXZ) { std::string fn = "./support/STRU_MgO_cacxz"; std::ifstream ifa(fn.c_str()); @@ -1499,7 +1514,7 @@ TEST_F(UcellTest, ReadAtomPositionsCACXZ) remove("read_atom_positions.warn"); } -TEST_F(UcellTest, ReadAtomPositionsCACYZ) +TEST_F(UcellTestReadStru, ReadAtomPositionsCACYZ) { std::string fn = "./support/STRU_MgO_cacyz"; std::ifstream ifa(fn.c_str()); @@ -1530,7 +1545,7 @@ TEST_F(UcellTest, ReadAtomPositionsCACYZ) remove("read_atom_positions.warn"); } -TEST_F(UcellTest, ReadAtomPositionsCACXYZ) +TEST_F(UcellTestReadStru, ReadAtomPositionsCACXYZ) { std::string fn = "./support/STRU_MgO_cacxyz"; std::ifstream ifa(fn.c_str()); @@ -1561,7 +1576,7 @@ TEST_F(UcellTest, ReadAtomPositionsCACXYZ) remove("read_atom_positions.warn"); } -TEST_F(UcellTest, ReadAtomPositionsCAU) +TEST_F(UcellTestReadStru, ReadAtomPositionsCAU) { std::string fn = "./support/STRU_MgO_cau"; std::ifstream ifa(fn.c_str()); @@ -1593,7 +1608,7 @@ TEST_F(UcellTest, ReadAtomPositionsCAU) remove("read_atom_positions.warn"); } -TEST_F(UcellTest, ReadAtomPositionsAutosetMag) +TEST_F(UcellTestReadStru, ReadAtomPositionsAutosetMag) { std::string fn = "./support/STRU_MgO"; std::ifstream ifa(fn.c_str()); @@ -1647,7 +1662,7 @@ TEST_F(UcellTest, ReadAtomPositionsAutosetMag) remove("read_atom_positions.warn"); } -TEST_F(UcellTest, ReadAtomPositionsWarning1) +TEST_F(UcellTestReadStru, ReadAtomPositionsWarning1) { std::string fn = "./support/STRU_MgO_WarningC1"; std::ifstream ifa(fn.c_str()); @@ -1690,7 +1705,7 @@ TEST_F(UcellTest, ReadAtomPositionsWarning1) remove("read_atom_positions.warn"); } -TEST_F(UcellTest, ReadAtomPositionsWarning2) +TEST_F(UcellTestReadStru, ReadAtomPositionsWarning2) { std::string fn = "./support/STRU_MgO_WarningC2"; std::ifstream ifa(fn.c_str()); @@ -1727,7 +1742,7 @@ TEST_F(UcellTest, ReadAtomPositionsWarning2) remove("read_atom_positions.warn"); } -TEST_F(UcellTest, ReadAtomPositionsWarning3) +TEST_F(UcellTestReadStru, ReadAtomPositionsWarning3) { std::string fn = "./support/STRU_MgO_WarningC3"; std::ifstream ifa(fn.c_str()); @@ -1773,6 +1788,7 @@ TEST_F(UcellDeathTest, ReadAtomPositionsWarning4) // mandatory preliminaries ucell->ntype = 2; ucell->atoms = new Atom[ucell->ntype]; + ucell->orbital_fn.resize(ucell->ntype); ucell->set_atom_flag = true; PARAM.input.test_pseudo_cell = 2; PARAM.input.basis_type = "lcao"; @@ -1795,7 +1811,7 @@ TEST_F(UcellDeathTest, ReadAtomPositionsWarning4) remove("read_atom_positions.warn"); } -TEST_F(UcellTest, ReadAtomPositionsWarning5) +TEST_F(UcellTestReadStru, ReadAtomPositionsWarning5) { std::string fn = "./support/STRU_MgO"; std::ifstream ifa(fn.c_str()); diff --git a/source/module_cell/test/unitcell_test_para.cpp b/source/module_cell/test/unitcell_test_para.cpp index a69b7655aa..e6ba733fa0 100644 --- a/source/module_cell/test/unitcell_test_para.cpp +++ b/source/module_cell/test/unitcell_test_para.cpp @@ -94,23 +94,28 @@ class UcellTest : public ::testing::Test }; #ifdef __MPI -TEST_F(UcellTest, BcastUnitcell2) + +TEST_F(UcellTest, BcastUnitcell) { - elecstate::read_cell_pseudopots(pp_dir, ofs, *ucell); - ucell->bcast_unitcell2(); + PARAM.input.nspin = 4; + unitcell::bcast_unitcell(*ucell); if (GlobalV::MY_RANK != 0) { - EXPECT_EQ(ucell->atoms[0].ncpp.nbeta, 4); - EXPECT_EQ(ucell->atoms[0].ncpp.nchi, 2); - EXPECT_EQ(ucell->atoms[1].ncpp.nbeta, 3); - EXPECT_EQ(ucell->atoms[1].ncpp.nchi, 1); + EXPECT_EQ(ucell->Coordinate, "Direct"); + EXPECT_DOUBLE_EQ(ucell->a1.x, 10.0); + EXPECT_EQ(ucell->atoms[0].na, 1); + EXPECT_EQ(ucell->atoms[1].na, 2); + /// this is to ensure all processes have the atom label info + auto atom_labels = ucell->get_atomLabels(); + std::string atom_type1_expected = "C"; + std::string atom_type2_expected = "H"; + EXPECT_EQ(atom_labels[0], atom_type1_expected); + EXPECT_EQ(atom_labels[1], atom_type2_expected); } } - -TEST_F(UcellTest, BcastUnitcell) +TEST_F(UcellTest, BcastLattice) { - PARAM.input.nspin = 4; - ucell->bcast_unitcell(); + unitcell::bcast_Lattice(ucell->lat); if (GlobalV::MY_RANK != 0) { EXPECT_EQ(ucell->Coordinate, "Direct"); @@ -125,6 +130,22 @@ TEST_F(UcellTest, BcastUnitcell) EXPECT_EQ(atom_labels[1], atom_type2_expected); } } + +TEST_F(UcellTest, BcastMagnitism) +{ + unitcell::bcast_magnetism(ucell->magnet, ucell->ntype); + PARAM.input.nspin = 4; + if (GlobalV::MY_RANK != 0) + { + EXPECT_DOUBLE_EQ(ucell->magnet.start_magnetization[0], 0.0); + EXPECT_DOUBLE_EQ(ucell->magnet.start_magnetization[1], 0.0); + for (int i = 0; i < 3; ++i) + { + EXPECT_DOUBLE_EQ(ucell->magnet.ux_[i], 0.0); + } + } +} + TEST_F(UcellTest, UpdatePosTau) { double* pos_in = new double[ucell->nat * 3]; @@ -236,7 +257,6 @@ TEST_F(UcellTest, ReadPseudo) EXPECT_EQ(error2, 0); } // read_cell_pseudopots - // bcast_unitcell2 EXPECT_FALSE(ucell->atoms[0].ncpp.has_so); EXPECT_FALSE(ucell->atoms[1].ncpp.has_so); EXPECT_EQ(ucell->atoms[0].ncpp.nbeta, 4); diff --git a/source/module_cell/unitcell.cpp b/source/module_cell/unitcell.cpp index 3d383c565a..ac1fe740ca 100755 --- a/source/module_cell/unitcell.cpp +++ b/source/module_cell/unitcell.cpp @@ -7,6 +7,7 @@ #include "module_base/global_function.h" #include "module_base/global_variable.h" #include "unitcell.h" +#include "bcast_cell.h" #include "module_parameter/parameter.h" #ifdef __LCAO @@ -22,17 +23,10 @@ #ifdef USE_PAW #include "module_cell/module_paw/paw_cell.h" #endif -#ifdef __EXX -#include "module_hamilt_pw/hamilt_pwdft/global.h" -#include "module_ri/serialization_cereal.h" -#endif #include "update_cell.h" UnitCell::UnitCell() { - if (test_unitcell) { - ModuleBase::TITLE("unitcell", "Constructor"); -} itia2iat.create(1, 1); } @@ -41,108 +35,13 @@ UnitCell::~UnitCell() { delete[] atom_mass; delete[] pseudo_fn; delete[] pseudo_type; - delete[] orbital_fn; if (set_atom_flag) { delete[] atoms; } } -#include "module_base/parallel_common.h" -#ifdef __MPI -void UnitCell::bcast_unitcell() { - if (test_unitcell) { - ModuleBase::TITLE("UnitCell", "bcast_unitcell"); -} - Parallel_Common::bcast_string(Coordinate); - Parallel_Common::bcast_int(nat); - - Parallel_Common::bcast_double(lat0); - Parallel_Common::bcast_double(lat0_angstrom); - Parallel_Common::bcast_double(tpiba); - Parallel_Common::bcast_double(tpiba2); - - // distribute lattice vectors. - Parallel_Common::bcast_double(latvec.e11); - Parallel_Common::bcast_double(latvec.e12); - Parallel_Common::bcast_double(latvec.e13); - Parallel_Common::bcast_double(latvec.e21); - Parallel_Common::bcast_double(latvec.e22); - Parallel_Common::bcast_double(latvec.e23); - Parallel_Common::bcast_double(latvec.e31); - Parallel_Common::bcast_double(latvec.e32); - Parallel_Common::bcast_double(latvec.e33); - - Parallel_Common::bcast_int(lc[0]); - Parallel_Common::bcast_int(lc[1]); - Parallel_Common::bcast_int(lc[2]); - - if(this->orbital_fn == nullptr) - { - this->orbital_fn = new std::string[ntype]; - } - for (int i = 0; i < ntype; i++) - { - Parallel_Common::bcast_string(orbital_fn[i]); - } - - // distribute lattice vectors. - Parallel_Common::bcast_double(a1.x); - Parallel_Common::bcast_double(a1.y); - Parallel_Common::bcast_double(a1.z); - Parallel_Common::bcast_double(a2.x); - Parallel_Common::bcast_double(a2.y); - Parallel_Common::bcast_double(a2.z); - Parallel_Common::bcast_double(a3.x); - Parallel_Common::bcast_double(a3.y); - Parallel_Common::bcast_double(a3.z); - - // distribute latcenter - Parallel_Common::bcast_double(latcenter.x); - Parallel_Common::bcast_double(latcenter.y); - Parallel_Common::bcast_double(latcenter.z); - - // distribute superlattice vectors. - Parallel_Common::bcast_double(latvec_supercell.e11); - Parallel_Common::bcast_double(latvec_supercell.e12); - Parallel_Common::bcast_double(latvec_supercell.e13); - Parallel_Common::bcast_double(latvec_supercell.e21); - Parallel_Common::bcast_double(latvec_supercell.e22); - Parallel_Common::bcast_double(latvec_supercell.e23); - Parallel_Common::bcast_double(latvec_supercell.e31); - Parallel_Common::bcast_double(latvec_supercell.e32); - Parallel_Common::bcast_double(latvec_supercell.e33); - Parallel_Common::bcast_double(magnet.start_magnetization, ntype); - - if (PARAM.inp.nspin == 4) { - Parallel_Common::bcast_double(magnet.ux_[0]); - Parallel_Common::bcast_double(magnet.ux_[1]); - Parallel_Common::bcast_double(magnet.ux_[2]); - } - - for (int i = 0; i < ntype; i++) { - atoms[i].bcast_atom(); // init tau and mbl array - } - -#ifdef __EXX - ModuleBase::bcast_data_cereal(GlobalC::exx_info.info_ri.files_abfs, - MPI_COMM_WORLD, - 0); -#endif - return; -} - -void UnitCell::bcast_unitcell2() { - for (int i = 0; i < ntype; i++) { - atoms[i].bcast_atom2(); - } - return; -} -#endif void UnitCell::print_cell(std::ofstream& ofs) const { - if (test_unitcell) { - ModuleBase::TITLE("UnitCell", "print_cell"); -} ModuleBase::GlobalFunc::OUT(ofs, "print_unitcell()"); @@ -166,8 +65,6 @@ void UnitCell::print_cell(std::ofstream& ofs) const { /* void UnitCell::print_cell_xyz(const std::string& fn) const { - if (test_unitcell) - ModuleBase::TITLE("UnitCell", "print_cell_xyz"); if (GlobalV::MY_RANK != 0) return; // xiaohui add 2015-03-15 @@ -335,6 +232,7 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log) { bool ok2 = true; // (3) read in atom information + orbital_fn.resize(ntype); if (GlobalV::MY_RANK == 0) { // open "atom_unitcell" file. std::ifstream ifa(fn.c_str(), std::ios::in); @@ -414,7 +312,7 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log) { } #ifdef __MPI - this->bcast_unitcell(); + unitcell::bcast_unitcell(*this); #endif //======================================================== @@ -830,8 +728,7 @@ void UnitCell::setup(const std::string& latname_in, void UnitCell::compare_atom_labels(std::string label1, std::string label2) { - if (label1 - != label2) //'!( "Ag" == "Ag" || "47" == "47" || "Silver" == Silver" )' + if (label1!= label2) //'!( "Ag" == "Ag" || "47" == "47" || "Silver" == Silver" )' { atom_in ai; if (!(std::to_string(ai.atom_Z[label1]) == label2 diff --git a/source/module_cell/unitcell.h b/source/module_cell/unitcell.h index 7b10a18767..0132f29360 100644 --- a/source/module_cell/unitcell.h +++ b/source/module_cell/unitcell.h @@ -78,7 +78,6 @@ class UnitCell { private: std::vector iat2iwt; // iat ==> iwt, the first global index for orbital of this atom int npol = 1; // number of spin polarizations, initialized in set_iat2iwt - const int test_unitcell = 0; // ----------------- END of iat2iwt part ----------------- public: @@ -210,14 +209,8 @@ class UnitCell { std::string* pseudo_fn = new std::string[1]; std::string* pseudo_type = new std::string[1]; // pseudopotential types for each elements, // sunliang added 2022-09-15. - std::string* orbital_fn = nullptr; // filenames of orbitals, liuyu add 2022-10-19 - std::string - descriptor_file; // filenames of descriptor_file, liuyu add 2023-04-06 - -#ifdef __MPI - void bcast_unitcell(); - void bcast_unitcell2(); -#endif + std::vector orbital_fn; // filenames of orbitals, liuyu add 2022-10-19 + std::string descriptor_file; // filenames of descriptor_file, liuyu add 2023-04-06 void set_iat2itia(); diff --git a/source/module_cell/update_cell.cpp b/source/module_cell/update_cell.cpp index 759389b9d8..69cad55823 100644 --- a/source/module_cell/update_cell.cpp +++ b/source/module_cell/update_cell.cpp @@ -332,7 +332,7 @@ void setup_cell_after_vc(UnitCell& ucell, std::ofstream& log) { } #ifdef __MPI - ucell.bcast_unitcell(); + bcast_unitcell(ucell); #endif log << std::endl; diff --git a/source/module_elecstate/module_dm/test/prepare_unitcell.h b/source/module_elecstate/module_dm/test/prepare_unitcell.h index fcc98db9fa..e4bee46903 100644 --- a/source/module_elecstate/module_dm/test/prepare_unitcell.h +++ b/source/module_elecstate/module_dm/test/prepare_unitcell.h @@ -77,13 +77,13 @@ class UcellTestPrepare delete[] ucell.atom_mass; delete[] ucell.pseudo_fn; delete[] ucell.pseudo_type; - delete[] ucell.orbital_fn; + delete[] ucell.magnet.start_magnetization; // mag set here ucell.atom_label = new std::string[ucell.ntype]; ucell.atom_mass = new double[ucell.ntype]; ucell.pseudo_fn = new std::string[ucell.ntype]; ucell.pseudo_type = new std::string[ucell.ntype]; - ucell.orbital_fn = new std::string[ucell.ntype]; + ucell.orbital_fn.resize(ucell.ntype); ucell.magnet.start_magnetization = new double[ucell.ntype]; // mag set here ucell.magnet.ux_[0] = 0.0; // ux_ set here ucell.magnet.ux_[1] = 0.0; diff --git a/source/module_elecstate/read_pseudo.cpp b/source/module_elecstate/read_pseudo.cpp index ee11fd2ee7..3a1a5e0b9b 100644 --- a/source/module_elecstate/read_pseudo.cpp +++ b/source/module_elecstate/read_pseudo.cpp @@ -2,6 +2,7 @@ #include "module_parameter/parameter.h" #include "module_base/global_file.h" #include "module_cell/read_pp.h" +#include "module_cell/bcast_cell.h" #include "module_base/element_elec_config.h" #include "module_base/parallel_common.h" @@ -135,7 +136,7 @@ void read_pseudo(std::ofstream& ofs, UnitCell& ucell) { } #ifdef __MPI - ucell.bcast_unitcell2(); + unitcell::bcast_atoms_pseudo(ucell.atoms,ucell.ntype); #endif for (int it = 0; it < ucell.ntype; it++) { diff --git a/source/module_elecstate/test/prepare_unitcell.h b/source/module_elecstate/test/prepare_unitcell.h index f7bfc924e5..6bf9357f55 100644 --- a/source/module_elecstate/test/prepare_unitcell.h +++ b/source/module_elecstate/test/prepare_unitcell.h @@ -64,13 +64,12 @@ class UcellTestPrepare delete[] ucell->atom_mass; delete[] ucell->pseudo_fn; delete[] ucell->pseudo_type; - delete[] ucell->orbital_fn; delete[] ucell->magnet.start_magnetization; //mag set here ucell->atom_label = new std::string[ucell->ntype]; ucell->atom_mass = new double[ucell->ntype]; ucell->pseudo_fn = new std::string[ucell->ntype]; ucell->pseudo_type = new std::string[ucell->ntype]; - ucell->orbital_fn = new std::string[ucell->ntype]; + ucell->orbital_fn.resize(ucell->ntype); ucell->magnet.start_magnetization = new double[ucell->ntype]; //mag set here ucell->magnet.ux_[0] = 0.0; // ux_ set here ucell->magnet.ux_[1] = 0.0; @@ -190,7 +189,7 @@ class UcellTestPrepare } ucell->nat = this->natom.sum(); return ucell; - } + }; }; UcellTestPrepare::UcellTestPrepare(std::string latname_in, diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_init_basis.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_init_basis.cpp index bdb93bc996..d2b6d46323 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_init_basis.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_init_basis.cpp @@ -45,7 +45,7 @@ void init_basis_lcao(Parallel_Orbitals& pv, // * reading the localized orbitals/projectors // * construct the interpolation tables. - two_center_bundle.build_orb(ucell.ntype, ucell.orbital_fn); + two_center_bundle.build_orb(ucell.ntype, ucell.orbital_fn.data()); two_center_bundle.build_alpha(PARAM.globalv.deepks_setorb, &ucell.descriptor_file); two_center_bundle.build_orb_onsite(onsite_radius); // currently deepks only use one descriptor file, so cast bool to int is diff --git a/source/module_hamilt_lcao/module_deepks/test/LCAO_deepks_test_prep.cpp b/source/module_hamilt_lcao/module_deepks/test/LCAO_deepks_test_prep.cpp index 51c5148746..0687eb2e00 100644 --- a/source/module_hamilt_lcao/module_deepks/test/LCAO_deepks_test_prep.cpp +++ b/source/module_hamilt_lcao/module_deepks/test/LCAO_deepks_test_prep.cpp @@ -171,7 +171,7 @@ void test_deepks::set_orbs() ORB.init(GlobalV::ofs_running, ucell.ntype, PARAM.inp.orbital_dir, - ucell.orbital_fn, + ucell.orbital_fn.data(), ucell.descriptor_file, ucell.lmax, lcao_ecut, @@ -185,11 +185,7 @@ void test_deepks::set_orbs() ucell.infoNL.setupNonlocal(ucell.ntype, ucell.atoms, GlobalV::ofs_running, ORB); - std::vector file_orb(ntype); - std::transform(ucell.orbital_fn, ucell.orbital_fn + ntype, file_orb.begin(), [](const std::string& file) { - return PARAM.inp.orbital_dir + file; - }); - orb_.build(ntype, file_orb.data()); + orb_.build(ntype, ucell.orbital_fn.data()); std::string file_alpha = PARAM.inp.orbital_dir + ucell.descriptor_file; alpha_.build(1, &file_alpha); diff --git a/source/module_hamilt_lcao/module_deltaspin/test/prepare_unitcell.h b/source/module_hamilt_lcao/module_deltaspin/test/prepare_unitcell.h index aa8221a8fe..bbfbcc924f 100644 --- a/source/module_hamilt_lcao/module_deltaspin/test/prepare_unitcell.h +++ b/source/module_hamilt_lcao/module_deltaspin/test/prepare_unitcell.h @@ -82,7 +82,7 @@ class UcellTestPrepare ucell.atom_mass = new double[ucell.ntype]; ucell.pseudo_fn = new std::string[ucell.ntype]; ucell.pseudo_type = new std::string[ucell.ntype]; - ucell.orbital_fn = new std::string[ucell.ntype]; + ucell.orbital_fn.resize(ucell.ntype); ucell.magnet.start_magnetization = new double[ucell.ntype]; // mag set here ucell.magnet.ux_[0] = 0.0; // ux_ set here ucell.magnet.ux_[1] = 0.0; diff --git a/source/module_hamilt_lcao/module_hcontainer/test/prepare_unitcell.h b/source/module_hamilt_lcao/module_hcontainer/test/prepare_unitcell.h index dd4d27e2eb..913f0d910f 100644 --- a/source/module_hamilt_lcao/module_hcontainer/test/prepare_unitcell.h +++ b/source/module_hamilt_lcao/module_hcontainer/test/prepare_unitcell.h @@ -76,13 +76,12 @@ class UcellTestPrepare delete[] ucell.atom_mass; delete[] ucell.pseudo_fn; delete[] ucell.pseudo_type; - delete[] ucell.orbital_fn; delete[] ucell.magnet.start_magnetization; // mag set here ucell.atom_label = new std::string[ucell.ntype]; ucell.atom_mass = new double[ucell.ntype]; ucell.pseudo_fn = new std::string[ucell.ntype]; ucell.pseudo_type = new std::string[ucell.ntype]; - ucell.orbital_fn = new std::string[ucell.ntype]; + ucell.orbital_fn.resize(ucell.ntype); ucell.magnet.start_magnetization = new double[ucell.ntype]; // mag set here ucell.magnet.ux_[0] = 0.0; // ux_ set here ucell.magnet.ux_[1] = 0.0; diff --git a/source/module_io/json_output/init_info.cpp b/source/module_io/json_output/init_info.cpp index f9ce429568..b967b157d6 100644 --- a/source/module_io/json_output/init_info.cpp +++ b/source/module_io/json_output/init_info.cpp @@ -66,7 +66,7 @@ void gen_stru(UnitCell* ucell) std::string* pseudo_fn = ucell->pseudo_fn; // array of orbital file - std::string* orbital_fn = ucell->orbital_fn; + std::string* orbital_fn = ucell->orbital_fn.data(); // add atom element,orbital file and pseudopotential file for (int i = 0; i < ntype; i++) diff --git a/source/module_io/json_output/test/para_json_test.cpp b/source/module_io/json_output/test/para_json_test.cpp index cc529ce4a3..92675f8698 100644 --- a/source/module_io/json_output/test/para_json_test.cpp +++ b/source/module_io/json_output/test/para_json_test.cpp @@ -338,7 +338,7 @@ TEST(AbacusJsonTest, Init_stru_test) double lat0 = 10.0; ucell.ntype = 1; ucell.pseudo_fn = new std::string[1]; - ucell.orbital_fn = new std::string[1]; + ucell.orbital_fn.resize(1); ucell.atoms = atomlist; ucell.atom_label = new std::string[1]; ucell.lat0 = lat0; diff --git a/source/module_io/test/prepare_unitcell.h b/source/module_io/test/prepare_unitcell.h index a7c070ebe7..d03ff49eac 100644 --- a/source/module_io/test/prepare_unitcell.h +++ b/source/module_io/test/prepare_unitcell.h @@ -80,13 +80,12 @@ class UcellTestPrepare delete[] ucell->atom_mass; delete[] ucell->pseudo_fn; delete[] ucell->pseudo_type; - delete[] ucell->orbital_fn; delete[] ucell->magnet.start_magnetization; //mag set here ucell->atom_label = new std::string[ucell->ntype]; ucell->atom_mass = new double[ucell->ntype]; ucell->pseudo_fn = new std::string[ucell->ntype]; ucell->pseudo_type = new std::string[ucell->ntype]; - ucell->orbital_fn = new std::string[ucell->ntype]; + ucell->orbital_fn.resize(ucell->ntype); ucell->magnet.start_magnetization = new double[ucell->ntype]; //mag set here ucell->magnet.ux_[0] = 0.0; // ux_ set here ucell->magnet.ux_[1] = 0.0; diff --git a/source/module_io/test/to_qo_test.cpp b/source/module_io/test/to_qo_test.cpp index 1013ad93cf..e05d7fc76c 100644 --- a/source/module_io/test/to_qo_test.cpp +++ b/source/module_io/test/to_qo_test.cpp @@ -49,7 +49,7 @@ void define_fcc_cell(UnitCell& ucell) ucell.GT = ucell.latvec.Inverse(); ucell.G = ucell.GT.Transpose(); ucell.GGT = ucell.G * ucell.GT; - ucell.orbital_fn = new std::string[2]; + ucell.orbital_fn.resize(2); ucell.orbital_fn[0] = "../../../../tests/PP_ORB/Si_gga_8au_100Ry_2s2p1d.orb"; ucell.orbital_fn[1] = "../../../../tests/PP_ORB/C_gga_8au_100Ry_2s2p1d.orb"; ucell.pseudo_fn = new std::string[2]; @@ -86,7 +86,7 @@ void define_sc_cell(UnitCell& ucell) ucell.GT = ucell.latvec.Inverse(); ucell.G = ucell.GT.Transpose(); ucell.GGT = ucell.G * ucell.GT; - ucell.orbital_fn = new std::string[1]; + ucell.orbital_fn.resize(1); ucell.orbital_fn[0] = "../../../../tests/PP_ORB/Si_gga_8au_100Ry_2s2p1d.orb"; ucell.pseudo_fn = new std::string[1]; ucell.pseudo_fn[0] = "../../../../tests/PP_ORB/Si_dojo_soc.upf"; @@ -180,7 +180,7 @@ TEST_F(toQOTest, BuildNao) std::vector> kvecs_d; kvecs_d.push_back(ModuleBase::Vector3(0.0, 0.0, 0.0)); // Gamma point tqo.read_structures(&ucell, kvecs_d, 0, 1); - tqo.build_nao(ucell.ntype, "./", ucell.orbital_fn, 0); + tqo.build_nao(ucell.ntype, "./", ucell.orbital_fn.data(), 0); EXPECT_EQ(tqo.p_nao()->nchi(), 10); // not (l, m)-resoluted EXPECT_EQ(tqo.nphi(), 26); // (l, m)-resoluted } @@ -195,9 +195,9 @@ TEST_F(toQOTest, RadialCollectionIndexing) std::vector> kvecs_d; kvecs_d.push_back(ModuleBase::Vector3(0.0, 0.0, 0.0)); // Gamma point tqo.read_structures(&ucell, kvecs_d, 0, 1); - tqo.build_nao(ucell.ntype, "./", ucell.orbital_fn, 0); - // ucell.orbital_fn[0] = "../../../../tests/PP_ORB/Si_gga_8au_100Ry_2s2p1d.orb"; - // ucell.orbital_fn[1] = "../../../../tests/PP_ORB/C_gga_8au_100Ry_2s2p1d.orb"; + tqo.build_nao(ucell.ntype, "./", ucell.orbital_fn.data(), 0); + // ucell.orbital_fn.data()[0] = "../../../../tests/PP_ORB/Si_gga_8au_100Ry_2s2p1d.orb"; + // ucell.orbital_fn.data()[1] = "../../../../tests/PP_ORB/C_gga_8au_100Ry_2s2p1d.orb"; // test1 1Si, 1C std::vector natoms = {1, 1}; std::map,int> index; @@ -407,7 +407,7 @@ TEST_F(toQOTest, ScanSupercellForAtom) tqo.read_structures(&ucell, kvecs_d, 0, 1); tqo.build_nao(ucell.ntype, // ntype "./", // orbital_dir - ucell.orbital_fn,// orbital_fn + ucell.orbital_fn.data(),// orbital_fn 0); // rank std::vector nmax = std::vector(ucell.ntype); for(int itype = 0; itype < ucell.ntype; itype++) @@ -461,7 +461,7 @@ TEST_F(toQOTest, ScanSupercellFCC) tqo.read_structures(&ucell, kvecs_d, 0, 1); tqo.build_nao(ucell.ntype, "./", - ucell.orbital_fn, + ucell.orbital_fn.data(), 0); tqo.build_ao(ucell.ntype, "./", @@ -486,7 +486,7 @@ TEST_F(toQOTest, ScanSupercellSC1) tqo.read_structures(&ucell, kvecs_d, 0, 1); tqo.build_nao(ucell.ntype, "./", - ucell.orbital_fn, + ucell.orbital_fn.data(), 0); PARAM.input.qo_thr = 1e-6; tqo.build_ao(ucell.ntype, @@ -512,7 +512,7 @@ TEST_F(toQOTest, AllocateOvlpMinimal) tqo.read_structures(&ucell, kvecs_d, 0, 1); tqo.build_nao(ucell.ntype, "./", - ucell.orbital_fn, + ucell.orbital_fn.data(), 0); std::vector nmax = std::vector(ucell.ntype); for(int itype = 0; itype < ucell.ntype; itype++) @@ -1143,7 +1143,7 @@ TEST_F(toQOTest, ScanSupercellSC2) tqo.read_structures(&ucell, kvecs_d, 0, 1); tqo.build_nao(ucell.ntype, "./", - ucell.orbital_fn, + ucell.orbital_fn.data(), 0); PARAM.input.qo_screening_coeff[0] = 0.1; // use this to control the tailing of radial function PARAM.input.qo_thr = 1e-6; @@ -1169,7 +1169,7 @@ TEST_F(toQOTest, ScanSupercellSC3) tqo.read_structures(&ucell, kvecs_d, 0, 1); tqo.build_nao(ucell.ntype, "./", - ucell.orbital_fn, + ucell.orbital_fn.data(), 0); PARAM.input.qo_screening_coeff[0] = 0.25; // use this to control the tailing of radial function PARAM.input.qo_thr = 1e-6; @@ -1196,7 +1196,7 @@ TEST_F(toQOTest, ScanSupercellSC4) tqo.read_structures(&ucell, kvecs_d, 0, 1); tqo.build_nao(ucell.ntype, "./", - ucell.orbital_fn, + ucell.orbital_fn.data(), 0); PARAM.input.qo_screening_coeff[0] = 0.5; // use this to control the tailing of radial function PARAM.input.qo_thr = 1e-6; @@ -1221,8 +1221,8 @@ TEST_F(toQOTest, CalculateSelfOvlpRPswfc) PARAM.input.qo_screening_coeff); std::vector> kvecs_d; kvecs_d.push_back(ModuleBase::Vector3(0.0, 0.0, 0.0)); // Gamma point - ucell.orbital_fn[0] = "Si_special_use_unittest.orb"; // generated in unittest BuildAo - ucell.orbital_fn[1] = "C_special_use_unittest.orb"; // generated in unittest BuildAo + ucell.orbital_fn.data()[0] = "Si_special_use_unittest.orb"; // generated in unittest BuildAo + ucell.orbital_fn.data()[1] = "C_special_use_unittest.orb"; // generated in unittest BuildAo ucell.atoms[1].nwl = 1; // only s and p for C //PARAM.input.qo_thr = 1e-10; tqo.initialize(PARAM.sys.global_out_dir, diff --git a/source/module_io/test_serial/prepare_unitcell.h b/source/module_io/test_serial/prepare_unitcell.h index 13b96cce5c..6dd2fa7e4c 100644 --- a/source/module_io/test_serial/prepare_unitcell.h +++ b/source/module_io/test_serial/prepare_unitcell.h @@ -80,13 +80,12 @@ class UcellTestPrepare delete[] ucell->atom_mass; delete[] ucell->pseudo_fn; delete[] ucell->pseudo_type; - delete[] ucell->orbital_fn; delete[] ucell->magnet.start_magnetization; //mag set here ucell->atom_label = new std::string[ucell->ntype]; ucell->atom_mass = new double[ucell->ntype]; ucell->pseudo_fn = new std::string[ucell->ntype]; ucell->pseudo_type = new std::string[ucell->ntype]; - ucell->orbital_fn = new std::string[ucell->ntype]; + ucell->orbital_fn.resize(ucell->ntype); ucell->magnet.start_magnetization = new double[ucell->ntype]; //mag set here ucell->magnet.ux_[0] = 0.0; // ux_ set here ucell->magnet.ux_[1] = 0.0; diff --git a/source/module_io/to_qo_kernel.cpp b/source/module_io/to_qo_kernel.cpp index 13f5b7c06b..77e1d029f1 100644 --- a/source/module_io/to_qo_kernel.cpp +++ b/source/module_io/to_qo_kernel.cpp @@ -42,8 +42,9 @@ void toQO::initialize(const std::string& out_dir, init_info += "qo_basis: " + qo_basis_ + "\n"; init_info += "qo_thr: " + std::to_string(qo_thr_) + "\n"; init_info += "qo_strategies: "; - for (auto s: strategies_) + for (auto s: strategies_) { init_info += s + " "; +} init_info += "\n"; init_info += "Output directory: " + out_dir + "\n"; init_info += "Pseudopotential directory: " + pseudo_dir + "\n"; @@ -80,7 +81,7 @@ void toQO::initialize(const std::string& out_dir, // build two-center overlap calculator overlap_calculator_ = std::unique_ptr(new TwoCenterIntegrator); // build the numerical atomic orbital basis - build_nao(ntype_, orbital_dir_, p_ucell_->orbital_fn, iproc_); + build_nao(ntype_, orbital_dir_, p_ucell_->orbital_fn.data(), iproc_); // build another atomic orbital build_ao(ntype_, pseudo_dir_, p_ucell_->pseudo_fn, screening_coeffs_, qo_thr_, ofs_running, iproc_); @@ -159,33 +160,36 @@ bool toQO::orbital_filter_out(const int& itype, const int& l, const int& izeta) // means for the first atom type, use s and p orbitals, for the second, use // s, p, d, and f orbitals // default is `all` for all types, and for each type, all orbitals are used - if (strategies_[itype] == "all") + if (strategies_[itype] == "all") { return false; - else if (l >= l2symbol.size()) + } else if (l >= l2symbol.size()) { return true; - else if (strategies_[itype].find_first_of(l2symbol[l]) != std::string::npos) + } else if (strategies_[itype].find_first_of(l2symbol[l]) != std::string::npos) { return false; - else + } else { return true; +} } else if (qo_basis_ == "szv") { // use two individual logic branch allows them have different orbital filtering logic, // although presently they are almost the same - if (izeta != 0) + if (izeta != 0) { return true; // filter out - else if (strategies_[itype] == "all") + } else if (strategies_[itype] == "all") { return false; // keep - else if (l >= l2symbol.size()) + } else if (l >= l2symbol.size()) { return true; // filter out - else if (strategies_[itype].find_first_of(l2symbol[l]) != std::string::npos) + } else if (strategies_[itype].find_first_of(l2symbol[l]) != std::string::npos) { return false; // keep - else + } else { return true; // filter out +} } - else + else { return false; } +} void toQO::build_hydrogen(const int ntype, const double* const charges, @@ -283,8 +287,9 @@ void toQO::build_ao(const int ntype, qo_thr, /// qo_thr rank); /// rank } - else if (qo_basis_ == "szv") + else if (qo_basis_ == "szv") { build_szv(); +} if (rank == 0) { std::string ao_build_info = "toQO::build_ao: built atomic orbitals for calculating QO overlap integrals\n"; @@ -370,10 +375,12 @@ void toQO::calculate_ovlpk(int ik) MPI_Barrier(MPI_COMM_WORLD); #endif // ik == -1 corresponds to the case of those processes with less kpoints than others - if (ik != -1) + if (ik != -1) { read_ovlp(out_dir_, nchi_, nphi_, true, barrier_iR); - if (ik != -1) +} + if (ik != -1) { append_ovlpR_eiRk(ik, barrier_iR); +} } } @@ -390,8 +397,9 @@ void toQO::calculate() // while for zero_out overlap, it can be not so strictly synchronized zero_out_ovlps(false); calculate_ovlpk(ik); - if (ik != -1) + if (ik != -1) { write_ovlp>(out_dir_, ovlpk_, nchi_, nphi_, false, ik); +} } #ifdef __MPI // once the calculation of S(k) is finished, prone to delete all QO_ovlpR_*.dat files. But the most @@ -420,17 +428,19 @@ void toQO::append_ovlpR_eiRk(int ik, int iR) ModuleBase::libm::sincos(arg, &sinp, &cosp); std::complex phase = std::complex(cosp, sinp); // add all values of ovlpR_ to ovlpk_ with multiplication of phase - for (int i = 0; i < nchi_ * nphi_; i++) + for (int i = 0; i < nchi_ * nphi_; i++) { ovlpk_[i] += ovlpR_[i] * phase; } +} void toQO::allocate_ovlp(const bool& is_R) { - if (is_R) + if (is_R) { ovlpR_.resize(nchi_ * nphi_, 0.0); - else + } else { ovlpk_.resize(nchi_ * nphi_, std::complex(0.0, 0.0)); } +} void toQO::deallocate_ovlp(const bool& is_R) { @@ -448,11 +458,12 @@ void toQO::deallocate_ovlp(const bool& is_R) void toQO::zero_out_ovlps(const bool& is_R) { - if (is_R) + if (is_R) { std::fill(ovlpR_.begin(), ovlpR_.end(), 0.0); - else + } else { std::fill(ovlpk_.begin(), ovlpk_.end(), std::complex(0.0, 0.0)); } +} void toQO::radialcollection_indexing(const RadialCollection& radcol, const std::vector& natoms, @@ -475,15 +486,17 @@ void toQO::radialcollection_indexing(const RadialCollection& radcol, for (int m_abs = 0; m_abs <= l; m_abs++) { ms.push_back(m_abs); - if (m_abs != 0) + if (m_abs != 0) { ms.push_back(-m_abs); +} } for (int izeta = 0; izeta < radcol.nzeta(itype, l); izeta++) { // usually, the orbital is distinguished by it, l and zeta, the ia and m are not // commonly used. - if (orbital_filter_out(itype, l, izeta) && with_filter) + if (orbital_filter_out(itype, l, izeta) && with_filter) { continue; +} for (int m: ms) { index_map[std::make_tuple(itype, iatom, l, izeta, m)] = index; @@ -554,12 +567,14 @@ std::complex str2complex(const std::string& str) { std::string real_str, imag_str; int i = 1; // skip '(' - while (str[i] != ',') + while (str[i] != ',') { real_str += str[i]; +} i++; i++; // skip ',' - while (str[i] != ')') + while (str[i] != ')') { imag_str += str[i]; +} i++; return std::complex(std::stod(real_str), std::stod(imag_str)); } @@ -586,20 +601,22 @@ void toQO::read_ovlp(const std::string& dir, const int& nrows, const int& ncols, double val; ifs >> val; inum++; - if (inum <= nchi_ * nphi_) + if (inum <= nchi_ * nphi_) { ovlpR_[inum - 1] = val; - else + } else { break; +} } else { std::string val_str; ifs >> val_str; inum++; - if (inum <= nchi_ * nphi_) + if (inum <= nchi_ * nphi_) { ovlpk_[inum - 1] = str2complex(val_str); - else + } else { break; +} } } } diff --git a/source/module_lr/esolver_lrtd_lcao.cpp b/source/module_lr/esolver_lrtd_lcao.cpp index 5fdbca8f94..d42ce5244b 100644 --- a/source/module_lr/esolver_lrtd_lcao.cpp +++ b/source/module_lr/esolver_lrtd_lcao.cpp @@ -287,7 +287,7 @@ LR::ESolver_LR::ESolver_LR(const Input_para& inp, UnitCell& ucell) : inpu this->parameter_check(); /// read orbitals and build the interpolation table - two_center_bundle_.build_orb(ucell.ntype, ucell.orbital_fn); + two_center_bundle_.build_orb(ucell.ntype, ucell.orbital_fn.data()); LCAO_Orbitals orb; two_center_bundle_.to_LCAO_Orbitals(orb, inp.lcao_ecut, inp.lcao_dk, inp.lcao_dr, inp.lcao_rmax); diff --git a/source/module_psi/psi_initializer_nao.cpp b/source/module_psi/psi_initializer_nao.cpp index c2b0f83c04..f9b446b03d 100644 --- a/source/module_psi/psi_initializer_nao.cpp +++ b/source/module_psi/psi_initializer_nao.cpp @@ -171,7 +171,7 @@ void psi_initializer_nao::initialize(Structure_Factor* sf, // allocate this->allocate_table(); - this->read_external_orbs(this->p_ucell_->orbital_fn, rank); + this->read_external_orbs(this->p_ucell_->orbital_fn.data(), rank); // then for generate random number to fill in the wavefunction this->ixy2is_.clear(); @@ -198,7 +198,7 @@ void psi_initializer_nao::initialize(Structure_Factor* sf, // allocate this->allocate_table(); - this->read_external_orbs(this->p_ucell_->orbital_fn, 0); + this->read_external_orbs(this->p_ucell_->orbital_fn.data(), 0); // then for generate random number to fill in the wavefunction this->ixy2is_.clear(); diff --git a/source/module_psi/test/psi_initializer_unit_test.cpp b/source/module_psi/test/psi_initializer_unit_test.cpp index 3f74fdc44d..b42e5cb5b4 100644 --- a/source/module_psi/test/psi_initializer_unit_test.cpp +++ b/source/module_psi/test/psi_initializer_unit_test.cpp @@ -193,9 +193,8 @@ class PsiIntializerUnitTest : public ::testing::Test { this->p_ucell->atoms[0].ncpp.jchi[1] = 1.5; // atom numerical orbital this->p_ucell->lmax = 2; - if(this->p_ucell->orbital_fn != nullptr) { delete[] this->p_ucell->orbital_fn; -} - this->p_ucell->orbital_fn = new std::string[1]; + p_ucell->orbital_fn.shrink_to_fit(); + p_ucell->orbital_fn.resize(1); this->p_ucell->orbital_fn[0] = "Si_gga_8au_60Ry_2s2p1d.orb"; this->p_ucell->atoms[0].nwl = 2; this->p_ucell->atoms[0].l_nchi.resize(3); diff --git a/source/module_relax/relax_old/test/for_test.h b/source/module_relax/relax_old/test/for_test.h index 10ee140b79..be61eb9ea2 100644 --- a/source/module_relax/relax_old/test/for_test.h +++ b/source/module_relax/relax_old/test/for_test.h @@ -47,7 +47,7 @@ UnitCell::UnitCell() atom_mass = nullptr; pseudo_fn = new std::string[1]; pseudo_type = new std::string[1]; - orbital_fn = new std::string[1]; + orbital_fn.resize(1); atoms = new Atom[ntype]; set_atom_flag = true; @@ -68,7 +68,7 @@ UnitCell::UnitCell() UnitCell::~UnitCell() { } -void UnitCell::print_tau(void) const +void UnitCell::print_tau() const { } Magnetism::Magnetism()