Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change pointers to vectors in bessel_basis.cpp #3993

Merged
merged 5 commits into from
Apr 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 30 additions & 21 deletions source/module_io/bessel_basis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "module_base/parallel_common.h"
#include "module_base/timer.h"
#include "module_hamilt_pw/hamilt_pwdft/global.h"
#include <vector>

Bessel_Basis::Bessel_Basis()
{
Expand Down Expand Up @@ -194,13 +195,20 @@ void Bessel_Basis::init_TableOne(
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "dr",dr);

// allocate rmesh and Jlk and eigenvalue of Jlq
double *r = new double[rmesh];
double *rab = new double[rmesh];
double *jle = new double[rmesh];
double *jlk = new double[rmesh];
double *g = new double[rmesh]; // smooth function
double *function = new double[rmesh];
double *en = new double[ecut_number];
// double *r = new double[rmesh];
// double *rab = new double[rmesh];
// double *jle = new double[rmesh];
// double *jlk = new double[rmesh];
// double *g = new double[rmesh]; // smooth function
// double *function = new double[rmesh];
// double *en = new double[ecut_number];
std::vector<double> r(rmesh);
std::vector<double> rab(rmesh);
std::vector<double> jle(rmesh);
std::vector<double> jlk(rmesh);
std::vector<double> g(rmesh);
std::vector<double> function(rmesh);
std::vector<double> en(ecut_number);

for(int ir=0; ir<rmesh; ir++)
{
Expand Down Expand Up @@ -250,12 +258,12 @@ void Bessel_Basis::init_TableOne(
// init eigenvalue of Jl
for(int l=0; l<lmax+1; l++)
{
ModuleBase::GlobalFunc::ZEROS(en, ecut_number);
ModuleBase::GlobalFunc::ZEROS(jle, rmesh);
ModuleBase::GlobalFunc::ZEROS(jlk, rmesh);
ModuleBase::GlobalFunc::ZEROS(en.data(), ecut_number);
ModuleBase::GlobalFunc::ZEROS(jle.data(), rmesh);
ModuleBase::GlobalFunc::ZEROS(jlk.data(), rmesh);

// calculate eigenvalue for l
ModuleBase::Sphbes::Spherical_Bessel_Roots(ecut_number, l, tolerence, en, rcut);
ModuleBase::Sphbes::Spherical_Bessel_Roots(ecut_number, l, tolerence, en.data(), rcut);
// for (int ie=0; ie<ecut_number; ie++)
// {
// std::cout << "\n en[" << ie << "]=" << en[ie];
Expand All @@ -265,7 +273,7 @@ void Bessel_Basis::init_TableOne(
for (int ie=0; ie<ecut_number; ie++)
{
// calculate J_{l}( en[ir]*r)
ModuleBase::Sphbes::Spherical_Bessel(rmesh, r, en[ie], l, jle);
ModuleBase::Sphbes::Spherical_Bessel(rmesh, r.data(), en[ie], l, jle.data());

//caoyu add 2021-3-10
//=========output .orb format=============
Expand Down Expand Up @@ -306,7 +314,8 @@ void Bessel_Basis::init_TableOne(
for(int ik=0; ik<kmesh; ik++)
{
// calculate J_{l}( ik*dk*r )
ModuleBase::Sphbes::Spherical_Bessel(rmesh, r, ik*dk, l, jlk);
// ModuleBase::Sphbes::Spherical_Bessel(rmesh, r, ik*dk, l, jlk);
ModuleBase::Sphbes::Spherical_Bessel(rmesh, r.data(), ik*dk, l, jlk.data());

// calculate the function will be integrated
for(int ir=0; ir<rmesh; ir++)
Expand All @@ -315,7 +324,7 @@ void Bessel_Basis::init_TableOne(
}

// make table value
ModuleBase::Integral::Simpson_Integral(rmesh, function, rab, this->TableOne(l, ie, ik) );
ModuleBase::Integral::Simpson_Integral(rmesh, function.data(), rab.data(), this->TableOne(l, ie, ik) );
}

}// end ie
Expand All @@ -326,13 +335,13 @@ void Bessel_Basis::init_TableOne(
ofs.close(); //caoyu add 2020-3-10
}

delete[] en;
delete[] jle;
delete[] jlk;
delete[] rab;
delete[] g;
delete[] r;
delete[] function;
// delete[] en;
// delete[] jle;
// delete[] jlk;
// delete[] rab;
// delete[] g;
// delete[] r;
// delete[] function;
ModuleBase::timer::tick("Spillage","TableONe");
return;
}
Expand Down