Skip to content
Merged
Show file tree
Hide file tree
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
59 changes: 59 additions & 0 deletions ABACUS.develop/source/src_global/global_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,63 @@ inline const void* MAP_EXIST( const T_map &ms, const T_key1 &key1, const T_key_t
//==========================================================
size_t MemAvailable();


//==========================================================
// GLOBAL FUNCTION :
// NAME : DELETE_MUL_PTR
// delete Multi-dimensional array pointer
// example:
// int*** v;
// DELETE_MUL_PTR(v,N1,N2);
// -> for(int i1=0; i1<N1; ++i1){
// for(int i2=0; i2<N2; ++i2){
// delete[] v[i1][i2]; v[i1][i2]=nullptr; }
// delete[] v[i1]; v[i1]=nullptr; }
// delete[] v; v=nullptr;
// Peize Lin add 2021-05-09
//==========================================================
template <typename T_element>
static inline void DELETE_MUL_PTR(T_element* v)
{
delete[] v;
v = nullptr;
}
template <typename T_element, typename T_N_first, typename... T_N_tail>
static inline void DELETE_MUL_PTR(T_element* v, const T_N_first N_first, const T_N_tail... N_tail)
{
for(T_N_first i=0; i<N_first; ++i)
DELETE_MUL_PTR(v[i],N_tail...);
delete[] v;
v = nullptr;
}

//==========================================================
// GLOBAL FUNCTION :
// NAME : FREE_MUL_PTR
// delete Multi-dimensional array pointer
// example:
// int*** v;
// DELETE_MUL_PTR(v,N1,N2);
// -> for(int i1=0; i1<N1; ++i1){
// for(int i2=0; i2<N2; ++i2){
// free(v[i1][i2]); v[i1][i2]=nullptr; }
// free(v[i1]); v[i1]=nullptr; }
// free(v); v=nullptr;
// Peize Lin add 2021-05-09
//==========================================================
template <typename T_element>
static inline void FREE_MUL_PTR(T_element* v)
{
free(v);
v = nullptr;
}
template <typename T_element, typename T_N_first, typename... T_N_tail>
static inline void FREE_MUL_PTR(T_element* v, const T_N_first N_first, const T_N_tail... N_tail)
{
for(T_N_first i=0; i<N_first; ++i)
FREE_MUL_PTR(v[i],N_tail...);
free(v);
v = nullptr;
}

#endif
20 changes: 11 additions & 9 deletions ABACUS.develop/source/src_global/ylm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

using namespace std;
int Ylm::nlm = 0;
vector<double> Ylm::ylmcoef(100);
std::vector<double> Ylm::ylmcoef(100);

// here Lmax == max angular momentum + 1
void Ylm::get_ylm_real( const int &Lmax, const Vector3<double> &vec, double ylmr[] )
Expand Down Expand Up @@ -486,9 +486,11 @@ void Ylm::sph_harm
const double& xdr,
const double& ydr,
const double& zdr,
double rly[]
std::vector<double> &rly
)
{
rly.resize( (Lmax+1)*(Lmax+1) );

//begin calculation
/***************************
L = 0
Expand Down Expand Up @@ -623,7 +625,7 @@ void Ylm::rl_sph_harm
const double& x,
const double& y,
const double& z,
vector<double>& rly
std::vector<double>& rly
)
{
rly.resize( (Lmax+1)*(Lmax+1) );
Expand Down Expand Up @@ -762,12 +764,12 @@ void Ylm::grad_rl_sph_harm
const double& x,
const double& y,
const double& z,
vector<double>& rly,
vector<vector<double>>& grly
std::vector<double>& rly,
std::vector<std::vector<double>>& grly
)
{
rly.resize( (Lmax+1)*(Lmax+1) );
grly.resize( (Lmax+1)*(Lmax+1), vector<double>(3) );
grly.resize( (Lmax+1)*(Lmax+1), std::vector<double>(3) );

double radius2 = x*x+y*y+z*z;
double tx = 2.0*x;
Expand Down Expand Up @@ -1105,7 +1107,7 @@ void Ylm::test1 (void)
int nu = 100;

// Peize Lin change rlya 2016-08-26
vector<double> rlya;
std::vector<double> rlya;
double rlyb[400];
ZEROS( rlyb, 400);

Expand Down Expand Up @@ -1136,10 +1138,10 @@ void Ylm::test2 (void)

//int nu = 100;

vector<double> rlya;
std::vector<double> rlya;
double rlyb[400];

vector<vector<double>> grlya;
std::vector<std::vector<double>> grlya;
double grlyb[400][3];

Ylm::grad_rl_sph_harm (9, R.x, R.y, R.z, rlya, grlya);
Expand Down
8 changes: 4 additions & 4 deletions ABACUS.develop/source/src_global/ylm.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Ylm
const double& xdr,
const double& ydr,
const double& zdr,
double rly[]);
std::vector<double> &rly);

// (6) used in getting overlap.
// Peize Lin change rly 2016-08-26
Expand All @@ -57,7 +57,7 @@ class Ylm
const double& x,
const double& y,
const double& z,
vector<double>& rly);
std::vector<double>& rly);

// (6) used in getting derivative of overlap.
// Peize Lin change rly, grly 2016-08-26
Expand All @@ -66,8 +66,8 @@ class Ylm
const double& x,
const double& y,
const double& z,
vector<double>& rly,
vector<vector<double>>& grly);
std::vector<double>& rly,
std::vector<std::vector<double>>& grly);

static void set_coefficients ();
static std::vector<double> ylmcoef;
Expand Down
2 changes: 1 addition & 1 deletion ABACUS.develop/source/src_lcao/gint_gamma.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class Gint_Gamma : public Grid_Base_Beta
void setVindex(const int ncyz, const int ibx, const int jby, const int kbz, int* vindex) const;

void cal_psir_ylm_rho(int size, int grid_index, double delta_r,
double** distance, double* ylma,
double** distance,
int* at, int* block_index, int* block_iw, int* block_size,
int** cal_flag, double** psir_ylm);

Expand Down
5 changes: 1 addition & 4 deletions ABACUS.develop/source/src_lcao/gint_gamma_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ void Gint_Gamma::gamma_envelope(const double* wfc, double* rho)
}
}

double* ylma = new double[nnnmax]; // Ylm for each atom: [bxyz, nnnmax]
ZEROS(ylma, nnnmax);

double mt[3]={0,0,0};
double *vldr3 = new double[pw.bxyz];
double v1 = 0.0;
Expand Down Expand Up @@ -136,6 +133,7 @@ void Gint_Gamma::gamma_envelope(const double* wfc, double* rho)
continue;
}

std::vector<double> ylma;
//if(distance[id] > GridT.orbital_rmax) continue;
// Ylm::get_ylm_real(this->nnn[it], this->dr[id], ylma);
if (distance[ib][id] < 1.0E-9) distance[ib][id] += 1.0E-9;
Expand Down Expand Up @@ -244,7 +242,6 @@ void Gint_Gamma::gamma_envelope(const double* wfc, double* rho)
}// i

delete[] vindex;
delete[] ylma;
delete[] vldr3;

if(max_size!=0)
Expand Down
5 changes: 1 addition & 4 deletions ABACUS.develop/source/src_lcao/gint_gamma_mull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ void Gint_Gamma::gamma_mulliken(double** mulliken)
}
}

double* ylma = new double[nnnmax]; // Ylm for each atom: [bxyz, nnnmax]
ZEROS(ylma, nnnmax);

double mt[3]={0,0,0};
double *vldr3 = new double[pw.bxyz];
double v1 = 0.0;
Expand Down Expand Up @@ -141,6 +138,7 @@ void Gint_Gamma::gamma_mulliken(double** mulliken)
continue;
}

std::vector<double> ylma;
//if(distance[id] > GridT.orbital_rmax) continue;
// Ylm::get_ylm_real(this->nnn[it], this->dr[id], ylma);
if (distance[ib][id] < 1.0E-9) distance[ib][id] += 1.0E-9;
Expand Down Expand Up @@ -291,7 +289,6 @@ void Gint_Gamma::gamma_mulliken(double** mulliken)
}// j
}// i

delete[] ylma;
delete[] vldr3;

if(max_size!=0)
Expand Down
12 changes: 4 additions & 8 deletions ABACUS.develop/source/src_lcao/gint_gamma_rho.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ void Gint_Gamma::cal_psir_ylm_rho(
int size, // number of atoms on this grid
int grid_index,
double delta_r, // delta_r of uniform grid
double** distance,
double* ylma,
double** distance,
int* at,
int* block_index,
int* block_iw,
Expand Down Expand Up @@ -90,6 +89,7 @@ void Gint_Gamma::cal_psir_ylm_rho(

cal_flag[ib][id]=1;

std::vector<double> ylma;
//if(distance[id] > GridT.orbital_rmax) continue;
// Ylm::get_ylm_real(this->nnn[it], this->dr[id], ylma);
if (distance[ib][id] < 1.0E-9) distance[ib][id] += 1.0E-9;
Expand Down Expand Up @@ -363,10 +363,7 @@ double Gint_Gamma::gamma_charge(void) // Peize Lin update OpenMP 2020.09.28
}

int *block_iw=new int[max_size]; // index of wave functions of each block;

double* ylma = new double[nnnmax]; // Ylm for each atom: [bxyz, nnnmax]
ZEROS(ylma, nnnmax);


double v1 = 0.0;
int* vindex=new int[pw.bxyz];
ZEROS(vindex, pw.bxyz);
Expand Down Expand Up @@ -399,7 +396,7 @@ double Gint_Gamma::gamma_charge(void) // Peize Lin update OpenMP 2020.09.28
if(size==0) continue;
this->setVindex(ncyz, ibx, jby, kbz, vindex);

this->cal_psir_ylm_rho(size, grid_index_thread, delta_r, distance, ylma,
this->cal_psir_ylm_rho(size, grid_index_thread, delta_r, distance,
at, block_index, block_iw, block_size,
cal_flag, psir_ylm);

Expand All @@ -411,7 +408,6 @@ double Gint_Gamma::gamma_charge(void) // Peize Lin update OpenMP 2020.09.28
}// i

delete[] vindex;
delete[] ylma;

delete[] block_iw;
//OUT(ofs_running, "block_iw deleted");
Expand Down
7 changes: 2 additions & 5 deletions ABACUS.develop/source/src_lcao/gint_gamma_vl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ inline void cal_psir_ylm(
double*** dr, // dr[ bxyz ; atoms_on_this_big_cell; xyz ]
double** distance, // [ bxyz ; atoms_on_this_big_cell]
const Numerical_Orbital_Lm* pointer, // pointer for ORB.Phi[it].PhiLN
double* ylma, // spherical harmonic functions
int* colidx, // count total number of atomis orbitals
int* block_iw, // seems not belong to this subroutine
int* bsize, // ??
Expand Down Expand Up @@ -118,6 +117,7 @@ inline void cal_psir_ylm(

cal_flag[ib][id]=1;

std::vector<double> ylma;
//if(distance[id] > GridT.orbital_rmax) continue;
// Ylm::get_ylm_real(this->nnn[it], this->dr[id], ylma);
if (distance[ib][id] < 1.0E-9) distance[ib][id] += 1.0E-9;
Expand Down Expand Up @@ -511,8 +511,6 @@ void Gint_Gamma::gamma_vlocal(void) // Peize Lin update OpenMP 2020.09.27
//------------------------------------------------------
// spherical harmonic functions Ylm
//------------------------------------------------------
double* ylma=new double[nnnmax];
ZEROS(ylma, nnnmax);
double *vldr3=new double[pw.bxyz];
ZEROS(vldr3, pw.bxyz);
int* vindex=new int[pw.bxyz];
Expand Down Expand Up @@ -628,7 +626,7 @@ void Gint_Gamma::gamma_vlocal(void) // Peize Lin update OpenMP 2020.09.27
// compute atomic basis phi(r) with both radial and angular parts
//------------------------------------------------------------------
cal_psir_ylm(size, grid_index_thread, delta_r, phi, mt, dr,
distance, pointer, ylma, colidx, block_iw, bsize, psir_ylm, cal_flag);
distance, pointer, colidx, block_iw, bsize, psir_ylm, cal_flag);

//------------------------------------------------------------------
// calculate <phi_i|V|phi_j>
Expand Down Expand Up @@ -675,7 +673,6 @@ void Gint_Gamma::gamma_vlocal(void) // Peize Lin update OpenMP 2020.09.27
}
delete[] cal_flag;
delete[] vindex;
delete[] ylma;
delete[] vldr3;
delete[] block_iw;
delete[] psir_vlbr3;
Expand Down
5 changes: 2 additions & 3 deletions ABACUS.develop/source/src_lcao/gint_k.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1150,8 +1150,7 @@ void Gint_k::set_ijk_atom(
double*** psir_ylm,
double*** dr,
bool** cal_flag,
double** distance,
double* ylma,
double** distance,
const double &delta_r)
{
const Numerical_Orbital_Lm* pointer;
Expand Down Expand Up @@ -1201,7 +1200,7 @@ void Gint_k::set_ijk_atom(

if (distance[ib][id] < 1.0E-9) distance[ib][id] += 1.0E-9;


std::vector<double> ylma;
Ylm::sph_harm ( ucell.atoms[it].nwl,
dr[ib][id][0] / distance[ib][id],
dr[ib][id][1] / distance[ib][id],
Expand Down
2 changes: 1 addition & 1 deletion ABACUS.develop/source/src_lcao/gint_k.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Gint_k : public Gint_k_init
// set the orbital/Ylm information on each real space grid.
void set_ijk_atom(const int &grid_index, const int &size,
double*** psir_ylm, double*** dr, bool** cal_flag,
double** distance, double* ylma, const double &delta_r);
double** distance, const double &delta_r);

//------------------------------------------------------
// in gint_k_vl.cpp
Expand Down
9 changes: 3 additions & 6 deletions ABACUS.develop/source/src_lcao/gint_k_rho.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ inline void setVindex(const int ncyz, const int ibx, const int jby, const int kb
}


inline void cal_psir_ylm(int size, int grid_index, double delta_r, double* ylma,
inline void cal_psir_ylm(int size, int grid_index, double delta_r,
int* at, int* uc, int* block_index, int* block_iw, int* block_size,
bool** cal_flag, double** psir_ylm)
{
Expand Down Expand Up @@ -84,6 +84,7 @@ inline void cal_psir_ylm(int size, int grid_index, double delta_r, double* ylma,

cal_flag[ib][id]=true;

std::vector<double> ylma;
//if(distance[id] > GridT.orbital_rmax) continue;
// Ylm::get_ylm_real(this->nnn[it], this->dr[id], ylma);
if (distance < 1.0E-9) distance += 1.0E-9;
Expand Down Expand Up @@ -381,7 +382,6 @@ void Gint_k::calculate_charge(void)
int *at;
int *uc;
int *block_index;
double* ylma;
int* vindex;
bool** cal_flag;
//int** AllOffset;
Expand All @@ -406,8 +406,6 @@ void Gint_k::calculate_charge(void)
{
nn = max(nn,(ucell.atoms[it].nwl+1)*(ucell.atoms[it].nwl+1));
}
ylma = new double[nn];
ZEROS(ylma, nn);

vindex = new int[pw.bxyz];
ZEROS(vindex, pw.bxyz);
Expand Down Expand Up @@ -442,7 +440,7 @@ void Gint_k::calculate_charge(void)
if(size==0) continue;
setVindex(ncyz, ibx, jby, kbz, vindex);
//timer::tick("Gint_k","cal_psir_ylm",'G');
cal_psir_ylm(size, grid_index, delta_r, ylma,
cal_psir_ylm(size, grid_index, delta_r,
at, uc, block_index, block_iw, block_size,
cal_flag, psir_ylm);
//timer::tick("Gint_k","cal_psir_ylm",'G');
Expand All @@ -468,7 +466,6 @@ void Gint_k::calculate_charge(void)
delete[] block_index;
delete[] cal_flag;

delete[] ylma;
delete[] vindex;
}

Expand Down
Loading