Skip to content

Commit

Permalink
replace with vector (#3972)
Browse files Browse the repository at this point in the history
* replace with vector

* replace with vector
  • Loading branch information
jwsyzy committed Apr 14, 2024
1 parent c1621de commit 4154ec3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
28 changes: 13 additions & 15 deletions source/module_hamilt_pw/hamilt_pwdft/stress_func_loc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void Stress_Func<FPTYPE, Device>::stress_loc(ModuleBase::matrix& sigma,
ModuleBase::TITLE("Stress_Func","stress_loc");
ModuleBase::timer::tick("Stress_Func","stress_loc");

FPTYPE *dvloc = new FPTYPE[rho_basis->npw];
std::vector<FPTYPE> dvloc(rho_basis->npw);
FPTYPE evloc=0.0;
FPTYPE fact=1.0;

Expand All @@ -26,7 +26,7 @@ void Stress_Func<FPTYPE, Device>::stress_loc(ModuleBase::matrix& sigma,



std::complex<FPTYPE> *aux = new std::complex<FPTYPE> [rho_basis->nmaxgr];
std::vector<std::complex<FPTYPE>> aux(rho_basis->nmaxgr);

/*
blocking rho_basis->nrxx for data locality.
Expand Down Expand Up @@ -58,7 +58,7 @@ void Stress_Func<FPTYPE, Device>::stress_loc(ModuleBase::matrix& sigma,
}
}
}
rho_basis->real2recip(aux,aux);
rho_basis->real2recip(aux.data(),aux.data());

// if(INPUT.gamma_only==1) fact=2.0;
// else fact=1.0;
Expand Down Expand Up @@ -87,7 +87,7 @@ void Stress_Func<FPTYPE, Device>::stress_loc(ModuleBase::matrix& sigma,
//
// special case: pseudopotential is coulomb 1/r potential
//
this->dvloc_coulomb (atom->ncpp.zv, dvloc, rho_basis);
this->dvloc_coulomb (atom->ncpp.zv, dvloc.data(), rho_basis);
//
}
else
Expand All @@ -96,7 +96,7 @@ void Stress_Func<FPTYPE, Device>::stress_loc(ModuleBase::matrix& sigma,
// normal case: dvloc contains dV_loc(G)/dG
//
this->dvloc_of_g ( atom->ncpp.msh, atom->ncpp.rab, atom->ncpp.r,
atom->ncpp.vloc_at, atom->ncpp.zv, dvloc, rho_basis);
atom->ncpp.vloc_at, atom->ncpp.zv, dvloc.data(), rho_basis);
//
}
#ifndef _OPENMP
Expand Down Expand Up @@ -156,8 +156,7 @@ void Stress_Func<FPTYPE, Device>::stress_loc(ModuleBase::matrix& sigma,
sigma(m,l) = sigma(l,m);
}
}
delete[] dvloc;
delete[] aux;



ModuleBase::timer::tick("Stress_Func","stress_loc");
Expand Down Expand Up @@ -185,14 +184,14 @@ ModulePW::PW_Basis* rho_basis
//FPTYPE dvloc[ngl];
// the fourier transform dVloc/dG
//
FPTYPE *aux1;


int igl0;
// counter on erf functions or gaussians
// counter on g shells vectors
// first shell with g != 0

aux1 = new FPTYPE[msh];
std::vector<FPTYPE> aux1(msh);

// the G=0 component is not computed
if (rho_basis->gg_uniq[0] < 1.0e-8)
Expand Down Expand Up @@ -223,8 +222,7 @@ ModulePW::PW_Basis* rho_basis
aux1[i] = r [i] * vloc_at [i] + zp * ModuleBase::e2 * erf(r[i]);
}

FPTYPE *aux;
aux = new FPTYPE[msh];
std::vector<FPTYPE> aux(msh);
aux[0] = 0.0;
#ifdef _OPENMP
#pragma omp for
Expand All @@ -247,19 +245,19 @@ ModulePW::PW_Basis* rho_basis
}
FPTYPE vlcp=0;
// simpson (msh, aux, rab, vlcp);
ModuleBase::Integral::Simpson_Integral(msh, aux, rab, vlcp );
ModuleBase::Integral::Simpson_Integral(msh, aux.data(), rab, vlcp );
// DV(g^2)/Dg^2 = (DV(g)/Dg)/2g
vlcp *= ModuleBase::FOUR_PI / GlobalC::ucell.omega / 2.0 / gx;
// subtract the long-range term
FPTYPE g2a = gx2 / 4.0;
vlcp += ModuleBase::FOUR_PI / GlobalC::ucell.omega * zp * ModuleBase::e2 * ModuleBase::libm::exp ( - g2a) * (g2a + 1) / pow(gx2 , 2);
dvloc [igl] = vlcp;
}
delete[] aux;

#ifdef _OPENMP
}
#endif
delete[] aux1;


return;
}
Expand Down
39 changes: 21 additions & 18 deletions source/module_io/berryphase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ double berryphase::stringPhase(int index_str,

std::complex<double> det(1.0,0.0);
int info = 0;
int *ipiv = new int[nbands];
LapackConnector::zgetrf(nbands, nbands, mat, nbands, ipiv, &info);
std::vector<int> ipiv(nbands);
LapackConnector::zgetrf(nbands, nbands, mat, nbands, ipiv.data(), &info);
for (int ib = 0; ib < nbands; ib++)
{
if (ipiv[ib] != (ib+1)) det = -det * mat(ib,ib);
Expand All @@ -328,7 +328,7 @@ double berryphase::stringPhase(int index_str,

zeta = zeta*det;

delete[] ipiv;
// delete[] ipiv;
}
#ifdef __LCAO
else if(GlobalV::BASIS_TYPE=="lcao")
Expand Down Expand Up @@ -395,12 +395,12 @@ void berryphase::Berry_Phase(int nbands,
const K_Vectors& kv)
{
std::complex<double> cave = 0.0;

std::vector<double> phik(total_string);
double phik_ave = 0.0;
std::vector<std::complex<double>> cphik(total_string);
std::vector<double> wistring(total_string);



// electron polarization

// get weight of every std::string
Expand Down Expand Up @@ -452,7 +452,6 @@ void berryphase::Berry_Phase(int nbands,
mod_elec_tot = 1;
}





Expand Down Expand Up @@ -490,14 +489,18 @@ void berryphase::Macroscopic_polarization(const int npwx,
ModuleBase::Vector3<double> rcell_1(GlobalC::ucell.G.e11,GlobalC::ucell.G.e12,GlobalC::ucell.G.e13);
ModuleBase::Vector3<double> rcell_2(GlobalC::ucell.G.e21,GlobalC::ucell.G.e22,GlobalC::ucell.G.e23);
ModuleBase::Vector3<double> rcell_3(GlobalC::ucell.G.e31,GlobalC::ucell.G.e32,GlobalC::ucell.G.e33);
int *mod_ion = new int[GlobalC::ucell.nat];
double *pdl_ion_R1 = new double[GlobalC::ucell.nat];
double *pdl_ion_R2 = new double[GlobalC::ucell.nat];
double *pdl_ion_R3 = new double[GlobalC::ucell.nat];
ModuleBase::GlobalFunc::ZEROS(mod_ion,GlobalC::ucell.nat);
ModuleBase::GlobalFunc::ZEROS(pdl_ion_R1,GlobalC::ucell.nat);
ModuleBase::GlobalFunc::ZEROS(pdl_ion_R2,GlobalC::ucell.nat);
ModuleBase::GlobalFunc::ZEROS(pdl_ion_R3,GlobalC::ucell.nat);
//int *mod_ion = new int[GlobalC::ucell.nat];
std::vector<int> mod_ion(GlobalC::ucell.nat);
//double *pdl_ion_R1 = new double[GlobalC::ucell.nat];
std::vector<double> pdl_ion_R1(GlobalC::ucell.nat);
//double *pdl_ion_R2 = new double[GlobalC::ucell.nat];
std::vector<double> pdl_ion_R2(GlobalC::ucell.nat);
//double *pdl_ion_R3 = new double[GlobalC::ucell.nat];
std::vector<double> pdl_ion_R3(GlobalC::ucell.nat);
ModuleBase::GlobalFunc::ZEROS(mod_ion.data(),GlobalC::ucell.nat);
ModuleBase::GlobalFunc::ZEROS(pdl_ion_R1.data(),GlobalC::ucell.nat);
ModuleBase::GlobalFunc::ZEROS(pdl_ion_R2.data(),GlobalC::ucell.nat);
ModuleBase::GlobalFunc::ZEROS(pdl_ion_R3.data(),GlobalC::ucell.nat);

bool lodd = false;
int atom_index = 0;
Expand Down Expand Up @@ -566,10 +569,10 @@ void berryphase::Macroscopic_polarization(const int npwx,
polarization_ion[2] = polarization_ion[2] - 2.0 * round(polarization_ion[2] / 2.0);
}

delete[] mod_ion;
delete[] pdl_ion_R1;
delete[] pdl_ion_R2;
delete[] pdl_ion_R3;
// delete[] mod_ion;
// delete[] pdl_ion_R1;
// delete[] pdl_ion_R2;
// delete[] pdl_ion_R3;

// ion polarization end

Expand Down

0 comments on commit 4154ec3

Please sign in to comment.