diff --git a/source/source_cell/module_symmetry/symm_analysis.cpp b/source/source_cell/module_symmetry/symm_analysis.cpp index ae5f4dd36a..9f4361a06d 100644 --- a/source/source_cell/module_symmetry/symm_analysis.cpp +++ b/source/source_cell/module_symmetry/symm_analysis.cpp @@ -36,20 +36,14 @@ void Symmetry::analy_sys(const Lattice& lat, const Statistics& st, Atom* atoms, assert(ntype>0); - this->na = new int[ntype]; - this->istart = new int[ntype]; // start number of atom. - this->index = new int [nat + 2]; // index of atoms - - ModuleBase::GlobalFunc::ZEROS(na, ntype); - ModuleBase::GlobalFunc::ZEROS(istart, ntype); - ModuleBase::GlobalFunc::ZEROS(index, nat+2); + this->na.assign(ntype, 0); + this->istart.assign(ntype, 0); // start number of atom. + this->index.assign(nat + 2, 0); // index of atoms // atom positions // used in checksym. - newpos = new double[3*nat]; // positions of atoms before rotation - rotpos = new double[3*nat]; // positions of atoms after rotation - ModuleBase::GlobalFunc::ZEROS(newpos, 3*nat); - ModuleBase::GlobalFunc::ZEROS(rotpos, 3*nat); + newpos.assign(3 * nat, 0.0); // positions of atoms before rotation + rotpos.assign(3 * nat, 0.0); // positions of atoms after rotation this->a1 = lat.a1; this->a2 = lat.a2; @@ -91,7 +85,7 @@ void Symmetry::analy_sys(const Lattice& lat, const Statistics& st, Atom* atoms, // s: the input lattice vectors, input // find the real_brav type accordiing to lattice vectors. this->lattice_type(this->a1, this->a2, this->a3, this->s1, this->s2, this->s3, - this->cel_const, this->pre_const, this->real_brav, ilattname, atoms, true, this->newpos, symmetry_prec); + this->cel_const, this->pre_const, this->real_brav, ilattname, atoms, true, this->newpos.data(), symmetry_prec); ofs_running << " For optimal symmetric configuration:" << std::endl; ModuleBase::GlobalFunc::OUT(ofs_running, "BRAVAIS TYPE", real_brav); @@ -104,7 +98,7 @@ void Symmetry::analy_sys(const Lattice& lat, const Statistics& st, Atom* atoms, optlat.e31 = a3.x; optlat.e32 = a3.y; optlat.e33 = a3.z; // count the number of primitive cells in the supercell - this->pricell(this->newpos, atoms); + this->pricell(this->newpos.data(), atoms); test_brav = true; // output the real ibrav and point group @@ -129,9 +123,9 @@ void Symmetry::analy_sys(const Lattice& lat, const Statistics& st, Atom* atoms, // get the real symmetry operations according to the input structure // nrot_out: the number of pure point group rotations // nrotk_out: the number of all space group operations - this->getgroup(nrot_out, nrotk_out, ofs_running, this->nop, this->symop, - this->gmatrix, this->gtrans, this->newpos, this->rotpos, this->index, - this->ntype, this->itmin_type, this->itmin_start, this->istart, this->na); + this->getgroup(nrot_out, nrotk_out, ofs_running, this->nop, this->symop, + this->gmatrix, this->gtrans, this->newpos.data(), this->rotpos.data(), this->index.data(), + this->ntype, this->itmin_type, this->itmin_start, this->istart.data(), this->na.data()); } }; @@ -309,11 +303,6 @@ void Symmetry::analy_sys(const Lattice& lat, const Statistics& st, Atom* atoms, } } - delete[] newpos; - delete[] na; - delete[] rotpos; - delete[] index; - delete[] istart; ModuleBase::timer::end("Symmetry","analy_sys"); return; } diff --git a/source/source_cell/module_symmetry/symm_magnetic.cpp b/source/source_cell/module_symmetry/symm_magnetic.cpp index c7439684de..c236a0fdad 100644 --- a/source/source_cell/module_symmetry/symm_magnetic.cpp +++ b/source/source_cell/module_symmetry/symm_magnetic.cpp @@ -70,10 +70,10 @@ void Symmetry::analyze_magnetic_group(const Atom* atoms, const Statistics& st, i } // 3. analyze the effective structure - this->getgroup(nrot_out, nrotk_out, GlobalV::ofs_running, - this->nop, this->symop, this->gmatrix, - this->gtrans, mag_pos.data(), this->rotpos, - this->index, mag_type_atoms.size(), mag_itmin_type, + this->getgroup(nrot_out, nrotk_out, GlobalV::ofs_running, + this->nop, this->symop, this->gmatrix, + this->gtrans, mag_pos.data(), this->rotpos.data(), + this->index.data(), mag_type_atoms.size(), mag_itmin_type, mag_itmin_start, mag_istart.data(), mag_na.data()); } diff --git a/source/source_cell/module_symmetry/symm_pricell.cpp b/source/source_cell/module_symmetry/symm_pricell.cpp index cd1eb40bad..6011667a66 100644 --- a/source/source_cell/module_symmetry/symm_pricell.cpp +++ b/source/source_cell/module_symmetry/symm_pricell.cpp @@ -20,7 +20,7 @@ void Symmetry::pricell(double* pos, const Atom* atoms) } //order original atomic positions for current species - this->atom_ordering_new(pos + istart[it] * 3, na[it], index + istart[it]); + this->atom_ordering_new(pos + istart[it] * 3, na[it], index.data() + istart[it]); //copy pos to rotpos for (int j = istart[it]; j < istart[it] + na[it]; ++j) { @@ -63,7 +63,7 @@ void Symmetry::pricell(double* pos, const Atom* atoms) this->check_boundary( rotpos[ia*3+2] ); } //order translated atomic positions for current species - this->atom_ordering_new(rotpos + istart[it] * 3, na[it], index + istart[it]); + this->atom_ordering_new(rotpos.data() + istart[it] * 3, na[it], index.data() + istart[it]); } no_diff = true; @@ -130,7 +130,7 @@ void Symmetry::pricell(double* pos, const Atom* atoms) ptrans_array[i*3+1]=ptrans[i].y; ptrans_array[i*3+2]=ptrans[i].z; } - this->atom_ordering_new(ptrans_array, ntrans, index); + this->atom_ordering_new(ptrans_array, ntrans, index.data()); // std::cout<<"final ptrans:"<isym_rotiat_[i].resize(this->nat, -1); } - double* pos = this->newpos; - double* rotpos = this->rotpos; - ModuleBase::GlobalFunc::ZEROS(pos, this->nat * 3); + std::fill(this->newpos.begin(), this->newpos.end(), 0.0); + double* pos = this->newpos.data(); + double* rotpos = this->rotpos.data(); int iat = 0; for (int it = 0; it < this->ntype; it++) { diff --git a/source/source_cell/module_symmetry/symmetry.h b/source/source_cell/module_symmetry/symmetry.h index e930839944..be36a23321 100644 --- a/source/source_cell/module_symmetry/symmetry.h +++ b/source/source_cell/module_symmetry/symmetry.h @@ -12,6 +12,8 @@ #include "source_base/constants.h" #include "symm_basic.h" +#include + namespace ModuleSymmetry { @@ -57,20 +59,20 @@ class Symmetry : public Symmetry_Basic int ntype=0; ///< the number of atomic species int nat =0; ///< the number of all atoms - int *na =nullptr;///< number of atoms for each species - int *istart=nullptr; ///< start number of atom + std::vector na; ///< number of atoms for each species + std::vector istart; ///< start number of atom int itmin_type=0; ///< the type has smallest number of atoms int itmin_start=0; /// @brief direct coordinates of atoms - double *newpos=nullptr; + std::vector newpos; /// @brief positions of atoms after rotation - double *rotpos=nullptr; + std::vector rotpos; std::vector> ptrans; ///< the translation vectors of the primitive cell in the input structure int ncell=1; ///< the number of primitive cells within one supercell - int *index=nullptr; + std::vector index; double cel_const[6]={0.0}; double pcel_const[6]={0.0}; ///< cel_const of primitive cell