diff --git a/source/source_base/complexarray.h b/source/source_base/complexarray.h index 831f42ee02d..26ae234680c 100644 --- a/source/source_base/complexarray.h +++ b/source/source_base/complexarray.h @@ -14,94 +14,94 @@ namespace ModuleBase class ComplexArray { public: - std::complex *ptr=nullptr; // data array - - ComplexArray(const int bnd1=0, const int bnd2=1, const int bnd3=1, const int bnd4=1); - - ~ComplexArray(); - - void freemem(); - - void create(const int bnd1=0, const int bnd2=1, const int bnd3=1, const int bnd4=1); - - ComplexArray(const ComplexArray &cd); - ComplexArray(ComplexArray &&cd); - - /**************************************************** - * OPERATOR FUNCTIONS - ***************************************************/ - ComplexArray& operator=(ComplexArray &&cd); - ComplexArray &operator=(const ComplexArray &cd); - /// Assignment of scalar: all entries set to c. - void operator=(std::complex c); - /// Add two ComplexArray - ComplexArray operator+(const ComplexArray &cd) const; - /// Accumulate sum of ComplexArray - void operator+=(const ComplexArray &cd); - /// Subtract two ComplexArray - ComplexArray operator-(const ComplexArray &cd) const; - /// Accumulate difference of arrays - void operator-=(const ComplexArray &cd); - /// Scale a ComplexArray by real r - ComplexArray operator*(const double r) const; - /// Scale a ComplexArray by a std::complex number c - ComplexArray operator*(const std::complex c) const; - /// Scale a ComplexArray by real number in place - void operator*=(const double r); - /// Scale a ComplexArray by std::complex c in place - void operator*=(const std::complex c); - /// accumulate pointwise multiply - void operator*=(const ComplexArray &cd); - /// Judge if two ComplexArray is equal - bool operator== (const ComplexArray &cd2)const; - /// Judge if two ComplexArray is not equal - bool operator!= (const ComplexArray &cd2)const; - - /// overloaded subscript operator for non-const std::complex Array const reference return creates an lvakue - std::complex &operator() - (const int ind1=0, const int ind2=0, const int ind3=0, const int ind4=0) - { - assert(ind1>=0); assert(ind1=0); assert(ind2=0); assert(ind3=0); assert(ind4 &operator()(int, int, int, int, int); - /// overloaded subscript operator for const std::complex Array const reference return creates an cvakue - const std::complex &operator() - (const int ind1=0, const int ind2=0, const int ind3=0, const int ind4=0) const - { - assert(ind1>=0); assert(ind1=0); assert(ind2=0); assert(ind3=0); assert(ind4 &operator()(int, int, int, int, int)const; - - /**************************************************** - * MEMBER FUNCTIONS - ***************************************************/ - /// set all elements to be {0.0,0.0} - void zero_out(void); - - /// Negates all the entries in the array - void negate(void); - - /// set all elements to a random number whose real/image is between [-0.5,0.5). - void randomize(void); - int getBound1()const{ return bound1; } - int getBound2()const{ return bound2; } - int getBound3()const{ return bound3; } - int getBound4()const{ return bound4; } - int getSize()const{ return bound1*bound2*bound3*bound4; } + std::complex *ptr=nullptr; // data array + + ComplexArray(const int bnd1=0, const int bnd2=1, const int bnd3=1, const int bnd4=1); + + ~ComplexArray(); + + void freemem(); + + void create(const int bnd1=0, const int bnd2=1, const int bnd3=1, const int bnd4=1); + + ComplexArray(const ComplexArray &cd); + ComplexArray(ComplexArray &&cd); + + /**************************************************** + * OPERATOR FUNCTIONS + ***************************************************/ + ComplexArray& operator=(ComplexArray &&cd); + ComplexArray &operator=(const ComplexArray &cd); + /// Assignment of scalar: all entries set to c. + void operator=(std::complex c); + /// Add two ComplexArray + ComplexArray operator+(const ComplexArray &cd) const; + /// Accumulate sum of ComplexArray + void operator+=(const ComplexArray &cd); + /// Subtract two ComplexArray + ComplexArray operator-(const ComplexArray &cd) const; + /// Accumulate difference of arrays + void operator-=(const ComplexArray &cd); + /// Scale a ComplexArray by real r + ComplexArray operator*(const double r) const; + /// Scale a ComplexArray by a std::complex number c + ComplexArray operator*(const std::complex c) const; + /// Scale a ComplexArray by real number in place + void operator*=(const double r); + /// Scale a ComplexArray by std::complex c in place + void operator*=(const std::complex c); + /// accumulate pointwise multiply + void operator*=(const ComplexArray &cd); + /// Judge if two ComplexArray is equal + bool operator== (const ComplexArray &cd2)const; + /// Judge if two ComplexArray is not equal + bool operator!= (const ComplexArray &cd2)const; + + /// overloaded subscript operator for non-const std::complex Array const reference return creates an lvakue + std::complex &operator() + (const int ind1=0, const int ind2=0, const int ind3=0, const int ind4=0) + { + assert(ind1>=0); assert(ind1=0); assert(ind2=0); assert(ind3=0); assert(ind4 &operator()(int, int, int, int, int); + /// overloaded subscript operator for const std::complex Array const reference return creates an cvakue + const std::complex &operator() + (const int ind1=0, const int ind2=0, const int ind3=0, const int ind4=0) const + { + assert(ind1>=0); assert(ind1=0); assert(ind2=0); assert(ind3=0); assert(ind4 &operator()(int, int, int, int, int)const; + + /**************************************************** + * MEMBER FUNCTIONS + ***************************************************/ + /// set all elements to be {0.0,0.0} + void zero_out(void); + + /// Negates all the entries in the array + void negate(void); + + /// set all elements to a random number whose real/image is between [-0.5,0.5). + void randomize(void); + int getBound1()const{ return bound1; } + int getBound2()const{ return bound2; } + int getBound3()const{ return bound3; } + int getBound4()const{ return bound4; } + int getSize()const{ return bound1*bound2*bound3*bound4; } private: - int bound1, bound2, bound3, bound4; - void init(const int size); + int bound1, bound2, bound3, bound4; + void init(const int size); }; /// Scale a ComplexArray cd by real r ComplexArray operator*(const double r, const ComplexArray &cd); @@ -140,16 +140,16 @@ void point_mult(ComplexArray &a1, ComplexArray &in2, ComplexArray &out); template void zeros(std::complex *u, int n) { - if (n == 0 || u == 0) - { - std::cout << "\n error in zeros(),n or u = 0"; - return; - } - - for (int i = 0;i < n;i++) - { - u[i] = std::complex (0.0, 0.0); - } + if (n == 0 || u == 0) + { + std::cout << "\n error in zeros(),n or u = 0"; + return; + } + + for (int i = 0;i < n;i++) + { + u[i] = std::complex (0.0, 0.0); + } } } diff --git a/source/source_base/complexmatrix.cpp b/source/source_base/complexmatrix.cpp index 217ebaf0dd7..6c07014ee50 100644 --- a/source/source_base/complexmatrix.cpp +++ b/source/source_base/complexmatrix.cpp @@ -14,268 +14,268 @@ namespace ModuleBase { // constructor with sizes ComplexMatrix::ComplexMatrix(const int nrows, const int ncols, const bool flag_zero) - :nr(nrows), - nc(ncols), - size(nrows*ncols), - c(nullptr) + :nr(nrows), + nc(ncols), + size(nrows*ncols), + c(nullptr) { - if( size ) - { - c = new std::complex[size]; - if(flag_zero) zero_out(); - } + if( size ) + { + c = new std::complex[size]; + if(flag_zero) zero_out(); + } } // zero out the ComplexMatrix void ComplexMatrix::zero_out(void) { - for (int i=0; i(0.0,0.0); + for (int i=0; i(0.0,0.0); } /* void need_more_memory() { - std::cout << "\n Sorry to crash... but the running need more momory! Exit." << std::endl; - exit(0); + std::cout << "\n Sorry to crash... but the running need more momory! Exit." << std::endl; + exit(0); } */ // Copy constructor ComplexMatrix::ComplexMatrix(const ComplexMatrix &m1) - :nr(m1.nr), - nc(m1.nc), - size(m1.size), - c(nullptr) + :nr(m1.nr), + nc(m1.nc), + size(m1.size), + c(nullptr) { - if(size) - { - c = new std::complex[size]; - memcpy( c, m1.c, size*sizeof(std::complex) ); - } + if(size) + { + c = new std::complex[size]; + memcpy( c, m1.c, size*sizeof(std::complex) ); + } } // Peize Lin add 2016-08-05 ComplexMatrix::ComplexMatrix( ComplexMatrix && m1 ) - :nr(m1.nr), - nc(m1.nc), - size(m1.size), - c(m1.c) + :nr(m1.nr), + nc(m1.nc), + size(m1.size), + c(m1.c) { - m1.nr = m1.nc = m1.size = 0; - m1.c = nullptr; + m1.nr = m1.nc = m1.size = 0; + m1.c = nullptr; } // Peize Lin add 2017-03-29 ComplexMatrix::ComplexMatrix(const matrix &m) - :nr(m.nr), - nc(m.nc), - size(m.nr*m.nc), - c(nullptr) + :nr(m.nr), + nc(m.nc), + size(m.nr*m.nc), + c(nullptr) { - if( size ) - { - c = new std::complex[size]; - for( int i=0; i[size]; + for( int i=0; i[size_in]; - } - } - else - { - c = new std::complex[nr_in * nc_in]; - } - - nr = nr_in; - nc = nc_in; - size = nr*nc; - if(flag_zero) zero_out(); - } - else - { - if(c) delete[] c; - c = nullptr; - nr = nr_in; - nc = nc_in; - size = nr*nc; - } + if( nr_in && nc_in ) + { + if(c) + { + const int size_in=nr_in*nc_in; + if( size_in!=nr*nc ) + { + delete[] c; + c = new std::complex[size_in]; + } + } + else + { + c = new std::complex[nr_in * nc_in]; + } + + nr = nr_in; + nc = nc_in; + size = nr*nc; + if(flag_zero) zero_out(); + } + else + { + if(c) delete[] c; + c = nullptr; + nr = nr_in; + nc = nc_in; + size = nr*nc; + } } void ComplexMatrix::set_as_identity_matrix(void) { - for(int i=0; i(1.0, 0.0); - else c[nc * i + j] = std::complex(0.0, 0.0); - } - } - return; + for(int i=0; i(1.0, 0.0); + else c[nc * i + j] = std::complex(0.0, 0.0); + } + } + return; } // Adding matrices, as a friend ComplexMatrix operator+(const ComplexMatrix &m1, const ComplexMatrix &m2) { - assert(m1.nr == m2.nr); - assert(m2.nc == m2.nc); - - ComplexMatrix tm(m1); - tm+=m2; - return tm; + assert(m1.nr == m2.nr); + assert(m2.nc == m2.nc); + + ComplexMatrix tm(m1); + tm+=m2; + return tm; } // Subtracting matrices, as a friend ComplexMatrix operator-(const ComplexMatrix &m1, const ComplexMatrix &m2) { - assert(m1.nr == m2.nr); - assert(m2.nc == m2.nc); - - ComplexMatrix tm(m1); - tm-=m2; - return tm; + assert(m1.nr == m2.nr); + assert(m2.nc == m2.nc); + + ComplexMatrix tm(m1); + tm-=m2; + return tm; } // Multiplying matrices, as a friend // mprod = m1 * m2 ComplexMatrix operator*(const ComplexMatrix &m1, const ComplexMatrix &m2) { - assert(m1.nc == m2.nr); - ComplexMatrix mprod(m1.nr, m2.nc); + assert(m1.nc == m2.nr); + ComplexMatrix mprod(m1.nr, m2.nc); // mohan add 2021-04-05 #ifdef __NORMAL - std::complex z; - for (int i = 0;i < m1.nr;i++) - { - for (int j = 0;j < m2.nc;j++) - { - z = std::complex(0,0); - for (int k = 0;k < m1.nc;k++) - { - z += m1(i, k) * m2(k, j); - } - mprod(i, j) = z; - } - } + std::complex z; + for (int i = 0;i < m1.nr;i++) + { + for (int j = 0;j < m2.nc;j++) + { + z = std::complex(0,0); + for (int k = 0;k < m1.nc;k++) + { + z += m1(i, k) * m2(k, j); + } + mprod(i, j) = z; + } + } #else - // Peize Lin accelerate 2017-10-27 - BlasConnector::gemm('N', 'N', m1.nr, m2.nc, m1.nc, - 1, m1.c, m1.nc, m2.c, m2.nc, - 0, mprod.c, mprod.nc); + // Peize Lin accelerate 2017-10-27 + BlasConnector::gemm('N', 'N', m1.nr, m2.nc, m1.nc, + 1, m1.c, m1.nc, m2.c, m2.nc, + 0, mprod.c, mprod.nc); #endif - return mprod; + return mprod; } // Scale a ComplexMatrix ComplexMatrix operator*(const std::complex &c,const ComplexMatrix &m) { - ComplexMatrix sm(m); - for (int i=0 ;i &c) { - ComplexMatrix sm(m); - for (int i = 0;i < m.size;i++) sm.c[i] *= c; - return sm; + ComplexMatrix sm(m); + for (int i = 0;i < m.size;i++) sm.c[i] *= c; + return sm; } ComplexMatrix operator*(const double &r,const ComplexMatrix &m) { - ComplexMatrix sm(m); - for(int i=0; icreate(m.nr, m.nc, false); - memcpy( c, m.c, size*sizeof(std::complex) ); - return *this; + this->create(m.nr, m.nc, false); + memcpy( c, m.c, size*sizeof(std::complex) ); + return *this; } // Peize Lin add 2016-08-05 ComplexMatrix& ComplexMatrix::operator=( ComplexMatrix && m ) { - nr = m.nr; nc = m.nc; size = m.size; - if(c) delete[] c; - c = m.c; - m.nr = m.nc = m.size = 0; - m.c = nullptr; - return *this; + nr = m.nr; nc = m.nc; size = m.size; + if(c) delete[] c; + c = m.c; + m.nr = m.nc = m.size = 0; + m.c = nullptr; + return *this; } ComplexMatrix& ComplexMatrix::operator*=(const std::complex &s) { - for (int i = 0;i < this->size;i++) c[i] *= s; - return *this; + for (int i = 0;i < this->size;i++) c[i] *= s; + return *this; } // Accumulate to a ComplexMatrix in place ComplexMatrix& ComplexMatrix::operator+=(const ComplexMatrix &m) { - for(int i=0; ic[i] += m.c[i]; - return *this; + for(int i=0; ic[i] += m.c[i]; + return *this; } // decumulate to a ComplexMatrix in place ComplexMatrix& ComplexMatrix::operator-=(const ComplexMatrix &m) { - for(int i=0; ic[i] -= m.c[i]; - return *this; + for(int i=0; ic[i] -= m.c[i]; + return *this; } // Peize Lin add 2017-03-29 matrix ComplexMatrix::real() const { - matrix m(nr,nc,false); - for( int i=0; isize; ++i) m.c[i] = c[i].real(); - return m; + matrix m(nr,nc,false); + for( int i=0; isize; ++i) m.c[i] = c[i].real(); + return m; } // Returns trace of ComplexMatrix std::complex trace(const ComplexMatrix &m) { - std::complex tr=std::complex(0,0); - assert(m.nr == m.nc); - for (int i=0; i tr=std::complex(0,0); + assert(m.nr == m.nc); + for (int i=0; i &s, const ComplexMatrix &min, ComplexMatrix &mout) { - assert(min.nr == mout.nr); - assert(min.nc == mout.nc); - for (int j=0; j=0); - for (int i=0; i=0); + for (int i=0; i &s1, const ComplexMatrix &m2, ComplexMatrix &mout) { - assert(m1.nr == m2.nr); - assert(m1.nr == mout.nr); - assert(m1.nc == m2.nc); - assert(m1.nc == mout.nc); + assert(m1.nr == m2.nr); + assert(m1.nr == mout.nr); + assert(m1.nc == m2.nc); + assert(m1.nc == mout.nc); - for(int i=0; i0); - for(int i=0; i0); + for(int i=0; i z; - for(int ic=0;ic z; + for(int ic=0;ic z; - for(int ir=0;ir z; + for(int ir=0;ir z; + double r=0.0; + std::complex z; - for (int i = 0;i < m.size;i++) - { - z = m.c[i]; - r += z.real() * z.real() + z.imag() * z.imag(); - } - return r; + for (int i = 0;i < m.size;i++) + { + z = m.c[i]; + r += z.real() * z.real() + z.imag() * z.imag(); + } + return r; } // Same for an array of matrices double abs2(const int nmat, ComplexMatrix **m) { - double r = 0.0; - for (int i = 0;i < nmat;i++) - { - r += abs2(*m[i]); - } - return r; + double r = 0.0; + for (int i = 0;i < nmat;i++) + { + r += abs2(*m[i]); + } + return r; } ComplexMatrix transpose(const ComplexMatrix &m, const bool &conjugate) { - ComplexMatrix tm(m.nc, m.nr, false); - if(conjugate) - for (int i = 0;i < m.nr;i++) - for (int j = 0;j < m.nc;j++) - tm(j, i) = conj ( m(i, j) ); - else - for (int i = 0;i < m.nr;i++) - for (int j = 0;j < m.nc;j++) - tm(j, i) = m(i, j); - return tm; + ComplexMatrix tm(m.nc, m.nr, false); + if(conjugate) + for (int i = 0;i < m.nr;i++) + for (int j = 0;j < m.nc;j++) + tm(j, i) = conj ( m(i, j) ); + else + for (int i = 0;i < m.nr;i++) + for (int j = 0;j < m.nc;j++) + tm(j, i) = m(i, j); + return tm; } ComplexMatrix conj(const ComplexMatrix &m) { - ComplexMatrix cm( m.nr, m.nc, false ); - for(int i=0; i!=m.size; ++i) - cm.c[i] = conj(m.c[i]); - return cm; + ComplexMatrix cm( m.nr, m.nc, false ); + for(int i=0; i!=m.size; ++i) + cm.c[i] = conj(m.c[i]); + return cm; } // Peize Lin add 2021.09.08 std::ostream & ComplexMatrix::print( std::ostream & os, const double threshold_abs, const double threshold_imag ) const { - for( int ir=0; ir!=this->nr; ++ir ) - { - for( int ic=0; ic!=this->nc; ++ic ) - { - const std::complex & data = (*this)(ir,ic); - if(std::abs(data)>threshold_abs) - { - if(std::abs(std::imag(data))>threshold_imag) - os<nr; ++ir ) + { + for( int ic=0; ic!=this->nc; ++ic ) + { + const std::complex & data = (*this)(ir,ic); + if(std::abs(data)>threshold_abs) + { + if(std::abs(std::imag(data))>threshold_imag) + os<nr;i++) - { - for(int j=0;jnc;j++) - { - if(std::imag((*this)(i,j)) > tiny) - { - return 0; - } - } - } - return 1; + const double tiny = 1e-12; + for(int i=0;inr;i++) + { + for(int j=0;jnc;j++) + { + if(std::imag((*this)(i,j)) > tiny) + { + return 0; + } + } + } + return 1; } } \ No newline at end of file diff --git a/source/source_base/complexmatrix.h b/source/source_base/complexmatrix.h index df1585e4c18..9dc890198d3 100644 --- a/source/source_base/complexmatrix.h +++ b/source/source_base/complexmatrix.h @@ -14,56 +14,56 @@ class ComplexMatrix public: - int nr=0; - int nc=0; - int size=0; - std::complex *c=nullptr; - - ComplexMatrix(): nr(0), nc(0), size(0), c(nullptr){} - ComplexMatrix(const int nrows,const int ncols,const bool flag_zero=true); // Peize Lin add flag_zero 2019-05-13 - ComplexMatrix(const ComplexMatrix &m1); - ComplexMatrix(ComplexMatrix && m1); // Peize Lin add 2016-08-05 - explicit ComplexMatrix(const matrix &m); // Peize Lin add 2017-03-29 - ~ComplexMatrix(); - - void create(const int nrow,const int ncol,const bool flag_zero=true); // Peize Lin add flag_zero 2019-05-13 - ComplexMatrix& operator=(const ComplexMatrix &m); - ComplexMatrix& operator=(ComplexMatrix && m); // Peize Lin add 2016-08-05 - - //============ - // Operators - //============ - std::complex &operator()(const int ir,const int ic) - { - assert(ir>=0); assert(ir=0); assert(ic &operator()(const int ir,const int ic)const - { - assert(ir>=0); assert(ir=0); assert(ic &s); - ComplexMatrix& operator+=(const ComplexMatrix &m); - ComplexMatrix& operator-=(const ComplexMatrix &m); - //return a matrix whose element is the real part of element of the ComplexMatrix. - matrix real() const; // Peize Lin add 2017-03-29 - - //================== - // member function: - //================== - //set all elements to be std::complex {0.0,0.0} - void zero_out(void); - //set to be a unit matrix, - void set_as_identity_matrix(void); - - std::ostream & print( std::ostream & os, const double threshold_abs=0.0, const double threshold_imag=0.0 ) const; // Peize Lin add 2021.09.08 - - // check if all the elements are real - bool checkreal(void) const; - - using type=std::complex; // Peiae Lin add 2022.08.08 for template + int nr=0; + int nc=0; + int size=0; + std::complex *c=nullptr; + + ComplexMatrix(): nr(0), nc(0), size(0), c(nullptr){} + ComplexMatrix(const int nrows,const int ncols,const bool flag_zero=true); // Peize Lin add flag_zero 2019-05-13 + ComplexMatrix(const ComplexMatrix &m1); + ComplexMatrix(ComplexMatrix && m1); // Peize Lin add 2016-08-05 + explicit ComplexMatrix(const matrix &m); // Peize Lin add 2017-03-29 + ~ComplexMatrix(); + + void create(const int nrow,const int ncol,const bool flag_zero=true); // Peize Lin add flag_zero 2019-05-13 + ComplexMatrix& operator=(const ComplexMatrix &m); + ComplexMatrix& operator=(ComplexMatrix && m); // Peize Lin add 2016-08-05 + + //============ + // Operators + //============ + std::complex &operator()(const int ir,const int ic) + { + assert(ir>=0); assert(ir=0); assert(ic &operator()(const int ir,const int ic)const + { + assert(ir>=0); assert(ir=0); assert(ic &s); + ComplexMatrix& operator+=(const ComplexMatrix &m); + ComplexMatrix& operator-=(const ComplexMatrix &m); + //return a matrix whose element is the real part of element of the ComplexMatrix. + matrix real() const; // Peize Lin add 2017-03-29 + + //================== + // member function: + //================== + //set all elements to be std::complex {0.0,0.0} + void zero_out(void); + //set to be a unit matrix, + void set_as_identity_matrix(void); + + std::ostream & print( std::ostream & os, const double threshold_abs=0.0, const double threshold_imag=0.0 ) const; // Peize Lin add 2021.09.08 + + // check if all the elements are real + bool checkreal(void) const; + + using type=std::complex; // Peiae Lin add 2022.08.08 for template }; ComplexMatrix operator+(const ComplexMatrix &m1, const ComplexMatrix &m2); @@ -94,32 +94,32 @@ ComplexMatrix conj(const ComplexMatrix &m); // Peize Lin add 2019-05-13 //do mout += s*min void scale_accumulate( - const std::complex &s, - const ComplexMatrix &min, - ComplexMatrix &mout); + const std::complex &s, + const ComplexMatrix &min, + ComplexMatrix &mout); //do (*mout[i]) += s * (*min[i]); int i &s, - ComplexMatrix **min, - ComplexMatrix **mout); + const int &nmat, + const std::complex &s, + ComplexMatrix **min, + ComplexMatrix **mout); // Do mout = s1*m1 + s2*m2 void scaled_sum( - const std::complex &s1, - const ComplexMatrix &m1, - const std::complex &s2, - const ComplexMatrix &m2, - ComplexMatrix &mout); + const std::complex &s1, + const ComplexMatrix &m1, + const std::complex &s2, + const ComplexMatrix &m2, + ComplexMatrix &mout); // Do (*mout[i]) = s1 * (*m1[i]) + s2 * (*m2[i]) void scaled_sum( - const int &nmat, - const std::complex &s1, - ComplexMatrix **m1, - const std::complex &s2, - ComplexMatrix **m2, - ComplexMatrix **mout); + const int &nmat, + const std::complex &s1, + ComplexMatrix **m1, + const std::complex &s2, + ComplexMatrix **m2, + ComplexMatrix **mout); } #endif diff --git a/source/source_base/container_operator.h b/source/source_base/container_operator.h index ec1f3fbc237..fb9fc16ed10 100644 --- a/source/source_base/container_operator.h +++ b/source/source_base/container_operator.h @@ -8,59 +8,59 @@ template< typename T> std::vector operator + ( const std::vector & x1, const std::vector & x2 ) { - assert(x1.size()==x2.size()); - std::vector x; - for(std::size_t i=0; i!=x1.size(); ++i ) - x.push_back(x1[i]+x2[i]); - return x; + assert(x1.size()==x2.size()); + std::vector x; + for(std::size_t i=0; i!=x1.size(); ++i ) + x.push_back(x1[i]+x2[i]); + return x; } template< typename T> std::vector operator - ( const std::vector & x1, const std::vector & x2 ) { - assert(x1.size()==x2.size()); - std::vector x; - for(std::size_t i=0; i!=x1.size(); ++i ) - x.push_back(x1[i]-x2[i]); - return x; + assert(x1.size()==x2.size()); + std::vector x; + for(std::size_t i=0; i!=x1.size(); ++i ) + x.push_back(x1[i]-x2[i]); + return x; } template< typename T1, typename T2 > std::map operator + ( const std::map & x1, const std::map & x2 ) { - assert(x1.size()==x2.size()); - std::map x; - for( const auto &x1i : x1 ) - x.insert(std::make_pair( x1i.first, x1i.second + x2.at(x1i.first) )); - return x; + assert(x1.size()==x2.size()); + std::map x; + for( const auto &x1i : x1 ) + x.insert(std::make_pair( x1i.first, x1i.second + x2.at(x1i.first) )); + return x; } template< typename T1, typename T2 > std::map operator - ( const std::map & x1, const std::map & x2 ) { - assert(x1.size()==x2.size()); - std::map x; - for( const auto &x1i : x1 ) - x.insert(std::make_pair( x1i.first, x1i.second - x2.at(x1i.first) )); - return x; + assert(x1.size()==x2.size()); + std::map x; + for( const auto &x1i : x1 ) + x.insert(std::make_pair( x1i.first, x1i.second - x2.at(x1i.first) )); + return x; } template< typename T1, typename T2 > std::vector operator * ( const T1 & x1, const std::vector & x2 ) { - std::vector x; - for(std::size_t i=0; i!=x2.size(); ++i ) - x.push_back(x1*x2[i]); - return x; + std::vector x; + for(std::size_t i=0; i!=x2.size(); ++i ) + x.push_back(x1*x2[i]); + return x; } template< typename T1, typename T21, typename T22 > std::map operator * ( const T1 & x1, const std::map & x2 ) { - std::map x; - for( const auto & x2i : x2 ) - x.insert(std::make_pair( x2i.first, x1*x2i.second )); - return x; + std::map x; + for( const auto & x2i : x2 ) + x.insert(std::make_pair( x2i.first, x1*x2i.second )); + return x; } #endif // CONTAINER_OPERATOR_H diff --git a/source/source_base/element_basis_index.cpp b/source/source_base/element_basis_index.cpp index 32eafd01e1d..46fe192c97f 100644 --- a/source/source_base/element_basis_index.cpp +++ b/source/source_base/element_basis_index.cpp @@ -11,30 +11,30 @@ namespace ModuleBase Element_Basis_Index::IndexLNM Element_Basis_Index::construct_index( const Range &range ) { - IndexLNM index; - index.resize( range.size() ); - for( std::size_t T=0; T!=range.size(); ++T ) - { - std::size_t count=0; - index[T].resize( range[T].size() ); - for( std::size_t L=0; L!=range[T].size(); ++L ) - { - index[T][L].resize( range[T][L].N ); - for( std::size_t N=0; N!=range[T][L].N; ++N ) - { - index[T][L][N].resize( range[T][L].M ); - for( std::size_t M=0; M!=range[T][L].M; ++M ) - { - index[T][L][N][M] = count; - ++count; - } - } - index[T][L].N = range[T][L].N; - index[T][L].M = range[T][L].M; - } - index[T].count_size = count; - } - return index; + IndexLNM index; + index.resize( range.size() ); + for( std::size_t T=0; T!=range.size(); ++T ) + { + std::size_t count=0; + index[T].resize( range[T].size() ); + for( std::size_t L=0; L!=range[T].size(); ++L ) + { + index[T][L].resize( range[T][L].N ); + for( std::size_t N=0; N!=range[T][L].N; ++N ) + { + index[T][L][N].resize( range[T][L].M ); + for( std::size_t M=0; M!=range[T][L].M; ++M ) + { + index[T][L][N][M] = count; + ++count; + } + } + index[T][L].N = range[T][L].N; + index[T][L].M = range[T][L].M; + } + index[T].count_size = count; + } + return index; } } \ No newline at end of file diff --git a/source/source_base/element_basis_index.h b/source/source_base/element_basis_index.h index bb81ebf40e9..22bfd2c7f0a 100644 --- a/source/source_base/element_basis_index.h +++ b/source/source_base/element_basis_index.h @@ -16,32 +16,32 @@ namespace Element_Basis_Index { //private: - struct NM - { - public: - std::size_t N; - std::size_t M; - }; - - class Index_TL: public std::vector> - { - public: - std::size_t N; - std::size_t M; - }; - - class Index_T: public std::vector - { - public: - std::size_t count_size; - }; + struct NM + { + public: + std::size_t N; + std::size_t M; + }; + + class Index_TL: public std::vector> + { + public: + std::size_t N; + std::size_t M; + }; + + class Index_T: public std::vector + { + public: + std::size_t count_size; + }; //public: - typedef std::vector> Range; // range[T][L] - typedef std::vector IndexLNM; // index[T][L][N][M] + typedef std::vector> Range; // range[T][L] + typedef std::vector IndexLNM; // index[T][L][N][M] - extern IndexLNM construct_index( const Range &range ); + extern IndexLNM construct_index( const Range &range ); } } diff --git a/source/source_base/export.cpp b/source/source_base/export.cpp index 413673a8495..947f12ffb91 100644 --- a/source/source_base/export.cpp +++ b/source/source_base/export.cpp @@ -13,20 +13,20 @@ /* void ModuleBase::IF_MATCH(const std::string &name,const std::string &name2) { - if(name!=name2) - { - if(GlobalV::MY_RANK == 0) - { - std::cout<<"\n Can not match : "< void ModuleBase::GlobalFunc::AUTO_SET(std::ofstream &ofs,const std::string &name,const T &a) { - ofs<<" AUTO_SET "< void IF_MATCH(const T &a,const T &b) { - if(a!=b) - { - if(GlobalV::MY_RANK == 0) - { - std::cout<<"\n Can not match : "<0) {break; + if(make_dir>0) {break; } - ++times; - } + ++times; + } #ifdef __MPI - if(make_dir==0) - { - std::cout << " CAN NOT MAKE THE OUT DIR......." << std::endl; - ModuleBase::QUIT(); - } - MPI_Barrier(MPI_COMM_WORLD); + if(make_dir==0) + { + std::cout << " CAN NOT MAKE THE OUT DIR......." << std::endl; + ModuleBase::QUIT(); + } + MPI_Barrier(MPI_COMM_WORLD); #endif if(calculation == "md") @@ -287,20 +287,20 @@ void ModuleBase::Global_File::make_dir_out( // mohan add 2010-09-12 if(out_alllog) { - open_log(GlobalV::ofs_running, log_file, calculation, restart, global_out_dir); + open_log(GlobalV::ofs_running, log_file, calculation, restart, global_out_dir); #if defined(__CUDA) || defined(__ROCM) open_log(GlobalV::ofs_device, "device" + std::to_string(rank) + ".log", calculation, restart, global_out_dir); #endif } else { - if(rank==0) - { - open_log(GlobalV::ofs_running, log_file, calculation, restart, global_out_dir); + if(rank==0) + { + open_log(GlobalV::ofs_running, log_file, calculation, restart, global_out_dir); #if defined(__CUDA) || defined(__ROCM) open_log(GlobalV::ofs_device, "device.log", calculation, restart, global_out_dir); #endif - } + } } if(rank==0) @@ -350,10 +350,10 @@ void ModuleBase::Global_File::open_log(std::ofstream &ofs, const std::string &fn void ModuleBase::Global_File::close_log( std::ofstream &ofs,const std::string &fn) { - if(ofs) - { - ofs.close(); - } + if(ofs) + { + ofs.close(); + } //ofs << "CLOSE "<> SearchName) - { - if (SearchName == TargetName) - { - find = true; - //std::cout << " search name = " << SearchName << std::endl; - return find; - } - } - } + { + if (SearchName == TargetName) + { + find = true; + //std::cout << " search name = " << SearchName << std::endl; + return find; + } + } + } if (!find && ifwarn) { @@ -225,16 +225,16 @@ void OUT_TIME(const std::string &name, time_t &start, time_t &end) double mini = difftime(end, start) / 60.0; if (mini > 0.1) { - if(GlobalV::ofs_warning) - { - GlobalV::ofs_warning << std::setprecision(2); - GlobalV::ofs_warning << " -------------------------------------------------------" << std::endl; - GlobalV::ofs_warning << " NAME < " << name << " > = " << std::endl; - GlobalV::ofs_warning << " -> " << ctime(&start) << " -> " << ctime(&end); - GlobalV::ofs_warning << " TIME = " << mini << " [Minutes]" << std::endl; - GlobalV::ofs_warning << " -------------------------------------------------------" << std::endl; - GlobalV::ofs_warning << std::setprecision(6); - } + if(GlobalV::ofs_warning) + { + GlobalV::ofs_warning << std::setprecision(2); + GlobalV::ofs_warning << " -------------------------------------------------------" << std::endl; + GlobalV::ofs_warning << " NAME < " << name << " > = " << std::endl; + GlobalV::ofs_warning << " -> " << ctime(&start) << " -> " << ctime(&end); + GlobalV::ofs_warning << " TIME = " << mini << " [Minutes]" << std::endl; + GlobalV::ofs_warning << " -------------------------------------------------------" << std::endl; + GlobalV::ofs_warning << std::setprecision(6); + } } } diff --git a/source/source_base/gram_schmidt_orth.h b/source/source_base/gram_schmidt_orth.h index 897e3c7a98d..bc69dfa6283 100644 --- a/source/source_base/gram_schmidt_orth.h +++ b/source/source_base/gram_schmidt_orth.h @@ -16,21 +16,21 @@ class Gram_Schmidt_Orth { public: - enum class Coordinate { Cartesian, Sphere }; - - Gram_Schmidt_Orth( const std::vector &rab, const Coordinate &coordinate ); - - std::vector> cal_orth( - const std::vector> &func, - const Func_Type norm_threshold = std::numeric_limits::min() ); - + enum class Coordinate { Cartesian, Sphere }; + + Gram_Schmidt_Orth( const std::vector &rab, const Coordinate &coordinate ); + + std::vector> cal_orth( + const std::vector> &func, + const Func_Type norm_threshold = std::numeric_limits::min() ); + private: - const Coordinate coordinate; - const std::vector &rab; - std::vector radial_2; + const Coordinate coordinate; + const std::vector &rab; + std::vector radial_2; - Func_Type cal_norm( const std::vector &f ); + Func_Type cal_norm( const std::vector &f ); }; diff --git a/source/source_base/gram_schmidt_orth_inl.h b/source/source_base/gram_schmidt_orth_inl.h index 809f9fbb391..90eb08cb6e4 100644 --- a/source/source_base/gram_schmidt_orth_inl.h +++ b/source/source_base/gram_schmidt_orth_inl.h @@ -16,90 +16,90 @@ namespace ModuleBase template Gram_Schmidt_Orth::Gram_Schmidt_Orth( const std::vector &rab_in, const Coordinate &coordinate_in ) - :rab(rab_in), - coordinate(coordinate_in) + :rab(rab_in), + coordinate(coordinate_in) { - if( Coordinate::Sphere == coordinate ) - { - std::vector radial( rab.size() ); - radial[0] = 0; - for( int ir=1; ir!=radial.size(); ++ir ) - radial[ir] = radial[ir-1] + rab[ir-1]; - this->radial_2 = Mathzone::Pointwise_Product( radial, radial ); - } + if( Coordinate::Sphere == coordinate ) + { + std::vector radial( rab.size() ); + radial[0] = 0; + for( int ir=1; ir!=radial.size(); ++ir ) + radial[ir] = radial[ir-1] + rab[ir-1]; + this->radial_2 = Mathzone::Pointwise_Product( radial, radial ); + } } template std::vector> Gram_Schmidt_Orth::cal_orth( - const std::vector> &func, - const Func_Type norm_threshold ) + const std::vector> &func, + const Func_Type norm_threshold ) { - // Schmidt: hn to en - // e1 = h1 / ||h1|| - // gn = hn - \sum{i=1 to n-1}(hn,ei)ei - // en = gn / ||gn|| - - std::vector> func_new; - - for( size_t if1=0; if1!=func.size(); ++if1 ) - { - //use CGS2 algorithm to do twice orthogonalization - //DOI 10.1007/s00211-005-0615-4 - std::vector func_try = func[if1]; - for(int niter=0;niter<3;niter++) - { - std::vector func_tmp = func_try; - for( size_t if_minus=0; if_minus!=func_new.size(); ++if_minus ) - { - // (hn,ei) - const std::vector && mul_func = Mathzone::Pointwise_Product( func_tmp, func_new[if_minus] ); - const Func_Type in_product = cal_norm(mul_func); + // Schmidt: hn to en + // e1 = h1 / ||h1|| + // gn = hn - \sum{i=1 to n-1}(hn,ei)ei + // en = gn / ||gn|| + + std::vector> func_new; + + for( size_t if1=0; if1!=func.size(); ++if1 ) + { + //use CGS2 algorithm to do twice orthogonalization + //DOI 10.1007/s00211-005-0615-4 + std::vector func_try = func[if1]; + for(int niter=0;niter<3;niter++) + { + std::vector func_tmp = func_try; + for( size_t if_minus=0; if_minus!=func_new.size(); ++if_minus ) + { + // (hn,ei) + const std::vector && mul_func = Mathzone::Pointwise_Product( func_tmp, func_new[if_minus] ); + const Func_Type in_product = cal_norm(mul_func); - // hn - (hn,ei)ei - BlasConnector::axpy( mul_func.size(), -in_product, ModuleBase::GlobalFunc::VECTOR_TO_PTR(func_new[if_minus]), 1, ModuleBase::GlobalFunc::VECTOR_TO_PTR(func_try), 1); - } - } - - // ||gn|| - const std::vector && func_2 = Mathzone::Pointwise_Product( func_try, func_try ); - const Func_Type norm = sqrt(cal_norm(func_2)); - - // en = gn / ||gn|| - // if ||gn|| too small, filter out - if( norm >= norm_threshold ) - { - BlasConnector::scal( func_try.size(), 1.0/norm, ModuleBase::GlobalFunc::VECTOR_TO_PTR(func_try), 1 ); - func_new.push_back( func_try ); - } - } - return func_new; + // hn - (hn,ei)ei + BlasConnector::axpy( mul_func.size(), -in_product, ModuleBase::GlobalFunc::VECTOR_TO_PTR(func_new[if_minus]), 1, ModuleBase::GlobalFunc::VECTOR_TO_PTR(func_try), 1); + } + } + + // ||gn|| + const std::vector && func_2 = Mathzone::Pointwise_Product( func_try, func_try ); + const Func_Type norm = sqrt(cal_norm(func_2)); + + // en = gn / ||gn|| + // if ||gn|| too small, filter out + if( norm >= norm_threshold ) + { + BlasConnector::scal( func_try.size(), 1.0/norm, ModuleBase::GlobalFunc::VECTOR_TO_PTR(func_try), 1 ); + func_new.push_back( func_try ); + } + } + return func_new; } // cal ||f|| template Func_Type Gram_Schmidt_Orth::cal_norm( const std::vector &f ) { - Func_Type norm = 0.0; - switch( this->coordinate ) - { - case Coordinate::Cartesian: - { - Integral::Simpson_Integral( f.size(), ModuleBase::GlobalFunc::VECTOR_TO_PTR(f), ModuleBase::GlobalFunc::VECTOR_TO_PTR(rab), norm); - break; - } - case Coordinate::Sphere: - { - const std::vector &&tmp_func = Mathzone::Pointwise_Product( f, radial_2 ); - Integral::Simpson_Integral( f.size(), ModuleBase::GlobalFunc::VECTOR_TO_PTR(tmp_func), ModuleBase::GlobalFunc::VECTOR_TO_PTR(rab), norm); - break; - } - default: - { - throw std::invalid_argument("coordinate must be Cartesian or Sphere "+std::string(__FILE__)+" line "+std::to_string(__LINE__)); - break; - } - } - return norm; + Func_Type norm = 0.0; + switch( this->coordinate ) + { + case Coordinate::Cartesian: + { + Integral::Simpson_Integral( f.size(), ModuleBase::GlobalFunc::VECTOR_TO_PTR(f), ModuleBase::GlobalFunc::VECTOR_TO_PTR(rab), norm); + break; + } + case Coordinate::Sphere: + { + const std::vector &&tmp_func = Mathzone::Pointwise_Product( f, radial_2 ); + Integral::Simpson_Integral( f.size(), ModuleBase::GlobalFunc::VECTOR_TO_PTR(tmp_func), ModuleBase::GlobalFunc::VECTOR_TO_PTR(rab), norm); + break; + } + default: + { + throw std::invalid_argument("coordinate must be Cartesian or Sphere "+std::string(__FILE__)+" line "+std::to_string(__LINE__)); + break; + } + } + return norm; } } diff --git a/source/source_base/inverse_matrix.cpp b/source/source_base/inverse_matrix.cpp index 66ced1c46e9..89916533778 100644 --- a/source/source_base/inverse_matrix.cpp +++ b/source/source_base/inverse_matrix.cpp @@ -9,68 +9,68 @@ namespace ModuleBase Inverse_Matrix_Complex::Inverse_Matrix_Complex() { - allocate=false; + allocate=false; } Inverse_Matrix_Complex::~Inverse_Matrix_Complex() { - if(allocate) - { - delete[] e; //mohan fix bug 2012-04-02 - delete[] work2; - delete[] rwork; - allocate=false; - } + if(allocate) + { + delete[] e; //mohan fix bug 2012-04-02 + delete[] work2; + delete[] rwork; + allocate=false; + } } void Inverse_Matrix_Complex::init(const int &dim_in) { // GlobalV::ofs_running << " allocate=" << allocate << std::endl; - if(allocate) - { - delete[] e; //mohan fix bug 2012-04-02 - delete[] work2; - delete[] rwork; - allocate=false; - } + if(allocate) + { + delete[] e; //mohan fix bug 2012-04-02 + delete[] work2; + delete[] rwork; + allocate=false; + } - this->dim = dim_in; + this->dim = dim_in; - assert(dim>0); - this->e = new double[dim]; - this->lwork = 2*dim; + assert(dim>0); + this->e = new double[dim]; + this->lwork = 2*dim; - assert(lwork>0); - this->work2 = new std::complex[lwork]; + assert(lwork>0); + this->work2 = new std::complex[lwork]; - assert(3*dim-2>0); - this->rwork = new double[3*dim-2]; - this->info = 0; - this->A.create(dim, dim); - this->EA.create(dim, dim); + assert(3*dim-2>0); + this->rwork = new double[3*dim-2]; + this->info = 0; + this->A.create(dim, dim); + this->EA.create(dim, dim); - this->allocate = true; + this->allocate = true; - return; + return; } void Inverse_Matrix_Complex::using_zheev( const ModuleBase::ComplexMatrix &Sin, ModuleBase::ComplexMatrix &Sout) { - ModuleBase::timer::start("Inverse","using_zheev"); - this->A = Sin; + ModuleBase::timer::start("Inverse","using_zheev"); + this->A = Sin; LapackConnector::zheev('V', 'U', dim, this->A, dim, e, work2, lwork, rwork, &info); - - for(int i=0; iA(j,i) ) / e[i] ; - } - } + + for(int i=0; iA(j,i) ) / e[i] ; + } + } Sout = this->A * this->EA; - ModuleBase::timer::end("Inverse","using_zheev"); + ModuleBase::timer::end("Inverse","using_zheev"); return; } diff --git a/source/source_base/inverse_matrix.h b/source/source_base/inverse_matrix.h index bac2e5b979a..e9213ba9a34 100644 --- a/source/source_base/inverse_matrix.h +++ b/source/source_base/inverse_matrix.h @@ -8,26 +8,26 @@ namespace ModuleBase class Inverse_Matrix_Complex { - public: + public: - Inverse_Matrix_Complex(); - ~Inverse_Matrix_Complex(); - - ModuleBase::ComplexMatrix A; + Inverse_Matrix_Complex(); + ~Inverse_Matrix_Complex(); + + ModuleBase::ComplexMatrix A; - void using_zheev(const ModuleBase::ComplexMatrix &in, ModuleBase::ComplexMatrix &out); - void init( const int &dim_in); + void using_zheev(const ModuleBase::ComplexMatrix &in, ModuleBase::ComplexMatrix &out); + void init( const int &dim_in); - private: - int dim=0; - double *e=nullptr; - int lwork=0; - std::complex *work2=nullptr; - double* rwork=nullptr; - int info=0; - bool allocate=false; //mohan add 2012-04-02 + private: + int dim=0; + double *e=nullptr; + int lwork=0; + std::complex *work2=nullptr; + double* rwork=nullptr; + int info=0; + bool allocate=false; //mohan add 2012-04-02 - ModuleBase::ComplexMatrix EA; + ModuleBase::ComplexMatrix EA; }; /** diff --git a/source/source_base/kernels/cuda/sph_harm_gpu.cuh b/source/source_base/kernels/cuda/sph_harm_gpu.cuh index caf29795d61..3ccf7708998 100644 --- a/source/source_base/kernels/cuda/sph_harm_gpu.cuh +++ b/source/source_base/kernels/cuda/sph_harm_gpu.cuh @@ -174,224 +174,224 @@ __device__ static void grad_rl_sph_harm( double tz = z * 2; //begin calculation - /*************************** - L = 0 - ***************************/ - rly[0] = ylmcoef[0]; //l=0, m=0 - grly[0] = grly[1] = grly[2] = 0.0; - if (nwl == 0) return; - - /*************************** - L = 1 - ***************************/ - rly[1] = ylmcoef[1]*z; //l=1, m=0 - grly[3] = grly[4] = 0.0; - grly[5] = ylmcoef[1]; - - rly[2] = -ylmcoef[1]*x; //l=1, m=1 - grly[7] = grly[8] = 0.0; - grly[6] = -ylmcoef[1]; - - rly[3] = -ylmcoef[1]*y; //l=1, m=-1 - grly[9] = grly[11] = 0.0; - grly[10] = -ylmcoef[1]; - - if (nwl == 1) return; - - /*************************** - L = 2 - ***************************/ - rly[4] = ylmcoef[2]*z*rly[1]-ylmcoef[3]*rly[0]*r2;//l=2, m=0 - grly[12] = ylmcoef[2]*z*grly[3]-ylmcoef[3]*(grly[0]*r2+rly[0]*tx);//l=2, m=0 - grly[13] = ylmcoef[2]*z*grly[4]-ylmcoef[3]*(grly[1]*r2+rly[0]*ty);//l=2, m=0 - grly[14] = ylmcoef[2]*(z*grly[5]+rly[1])-ylmcoef[3]*(grly[2]*r2+rly[0]*tz);//l=2, m=0 - - - double tmp0 = ylmcoef[4]*z; - rly[5] = tmp0*rly[2];//l=2,m=1 - grly[15] = tmp0*grly[6]; - grly[16] = tmp0*grly[7]; - grly[17] = ylmcoef[4]*(rly[2]+z*grly[8]); - - rly[6] = tmp0*rly[3];//l=2,m=-1 - grly[18] = tmp0*grly[9]; - grly[19] = tmp0*grly[10]; - grly[20] = ylmcoef[4]*(rly[3]+z*grly[11]); - - double tmp2 = ylmcoef[4]*x; - rly[7]= ylmcoef[5]*rly[4]-ylmcoef[6]*rly[0]*r2 - tmp2*rly[2];//l=2,m=2 - grly[21] = ylmcoef[5]*grly[12]-ylmcoef[6]*(rly[0]*tx+grly[0]*r2)-ylmcoef[4]*(x*grly[6]+rly[2]); - - grly[22] = ylmcoef[5]*grly[13]-ylmcoef[6]*(rly[0]*ty+grly[1]*r2)-tmp2*grly[7]; - grly[23] = ylmcoef[5]*grly[14]-ylmcoef[6]*(rly[0]*tz+grly[2]*r2)-tmp2*grly[8]; - - rly[8] = -tmp2*rly[3]; - grly[24] = -ylmcoef[4]*(rly[3]+x*grly[9]); - grly[25] = -tmp2*grly[10]; - grly[26] = -tmp2*grly[11]; - if (nwl == 2) return; - - /*************************** - L = 3 - ***************************/ - rly[9] = ylmcoef[7]*z*rly[4]-ylmcoef[8]*rly[1]*r2; //l=3, m=0 - grly[27] = ylmcoef[7]*z*grly[12]-ylmcoef[8]*(rly[1]*tx+grly[3]*r2); - grly[28] = ylmcoef[7]*z*grly[13]-ylmcoef[8]*(rly[1]*ty+grly[4]*r2); - grly[29] = ylmcoef[7]*(rly[4]+z*grly[14])-ylmcoef[8]*(rly[1]*tz+grly[5]*r2); - - double tmp3 = ylmcoef[9]*z; - rly[10] = tmp3*rly[5]-ylmcoef[10]*rly[2]*r2;//l=3,m=1 - grly[30] = tmp3*grly[15]-ylmcoef[10]*(grly[6]*r2+rly[2]*tx); - grly[31] = tmp3*grly[16]-ylmcoef[10]*(grly[7]*r2+rly[2]*ty); - grly[32] = ylmcoef[9]*(z*grly[17]+rly[5])-ylmcoef[10]*(grly[8]*r2+rly[2]*tz); - - rly[11] = tmp3*rly[6]-ylmcoef[10]*rly[3]*r2;//l=3,m=-1 - grly[33] = tmp3*grly[18]-ylmcoef[10]*(grly[9]*r2+rly[3]*tx); - grly[34] = tmp3*grly[19]-ylmcoef[10]*(grly[10]*r2+rly[3]*ty); - grly[35] = ylmcoef[9]*(z*grly[20]+rly[6])-ylmcoef[10]*(grly[11]*r2+rly[3]*tz); - - double tmp4 = ylmcoef[11]*z; - rly[12] = tmp4*rly[7];//l=3,m=2 - grly[36] = tmp4*grly[21]; - grly[37] = tmp4*grly[22]; - grly[38] = ylmcoef[11]*(z*grly[23]+rly[7]); - - rly[13] = tmp4*rly[8];//l=3,m=-2 - grly[39] = tmp4*grly[24]; - grly[40] = tmp4*grly[25]; - grly[41] = ylmcoef[11]*(z*grly[26]+rly[8]); - - double tmp5 = ylmcoef[14]*x; - rly[14] = ylmcoef[12]*rly[10]-ylmcoef[13]*rly[2]*r2-tmp5*rly[7];//l=3,m=3 - grly[42] = ylmcoef[12]*grly[30]-ylmcoef[13]*(rly[2]*tx+grly[6]*r2)-ylmcoef[14]*(rly[7]+x*grly[21]); - grly[43] = ylmcoef[12]*grly[31]-ylmcoef[13]*(rly[2]*ty+grly[7]*r2)-tmp5*grly[22]; - grly[44] = ylmcoef[12]*grly[32]-ylmcoef[13]*(rly[2]*tz+grly[8]*r2)-tmp5*grly[23]; - - rly[15] = ylmcoef[12]*rly[11]-ylmcoef[13]*rly[3]*r2-tmp5*rly[8];//l=3,m=-3 - grly[45] = ylmcoef[12]*grly[33]-ylmcoef[13]*(rly[3]*tx+grly[9]*r2)-ylmcoef[14]*(rly[8]+x*grly[24]); - grly[46] = ylmcoef[12]*grly[34]-ylmcoef[13]*(rly[3]*ty+grly[10]*r2)-tmp5*grly[25]; - grly[47] = ylmcoef[12]*grly[35]-ylmcoef[13]*(rly[3]*tz+grly[11]*r2)-tmp5*grly[26]; - if (nwl == 3) return; - - /*************************** - L = 4 - ***************************/ - rly[16] = ylmcoef[15]*z*rly[9]-ylmcoef[16]*rly[4]*r2;//l=4,m=0 - grly[48] = ylmcoef[15]*z*grly[27]-ylmcoef[16]*(rly[4]*tx+grly[12]*r2); - grly[49] = ylmcoef[15]*z*grly[28]-ylmcoef[16]*(rly[4]*ty+grly[13]*r2); - grly[50] = ylmcoef[15]*(z*grly[29]+rly[9])-ylmcoef[16]*(rly[4]*tz+grly[14]*r2); - - double tmp6 = ylmcoef[17]*z; - rly[17] = tmp6*rly[10]-ylmcoef[18]*rly[5]*r2;//l=4,m=1 - grly[51] = tmp6*grly[30]-ylmcoef[18]*(rly[5]*tx+grly[15]*r2); - grly[52] = tmp6*grly[31]-ylmcoef[18]*(rly[5]*ty+grly[16]*r2); - grly[53] = ylmcoef[17]*(z*grly[32]+rly[10])-ylmcoef[18]*(rly[5]*tz+grly[17]*r2); - - rly[18] = tmp6*rly[11]-ylmcoef[18]*rly[6]*r2;//l=4,m=-1 - grly[54] = tmp6*grly[33]-ylmcoef[18]*(rly[6]*tx+grly[18]*r2); - grly[55] = tmp6*grly[34]-ylmcoef[18]*(rly[6]*ty+grly[19]*r2); - grly[56] = ylmcoef[17]*(z*grly[35]+rly[11])-ylmcoef[18]*(rly[6]*tz+grly[20]*r2); - - double tmp7 = ylmcoef[19]*z; - rly[19] = tmp7*rly[12]-ylmcoef[20]*rly[7]*r2;//l=4,m=2 - grly[57] = tmp7*grly[36]-ylmcoef[20]*(rly[7]*tx+grly[21]*r2); - grly[58] = tmp7*grly[37]-ylmcoef[20]*(rly[7]*ty+grly[22]*r2); - grly[59] = ylmcoef[19]*(z*grly[38]+rly[12])-ylmcoef[20]*(rly[7]*tz+grly[23]*r2); - - rly[20] = tmp7*rly[13]-ylmcoef[20]*rly[8]*r2;//l=4,m=-2 - grly[60] = tmp7*grly[39]-ylmcoef[20]*(rly[8]*tx+grly[24]*r2); - grly[61] = tmp7*grly[40]-ylmcoef[20]*(rly[8]*ty+grly[25]*r2); - grly[62] = ylmcoef[19]*(z*grly[41]+rly[13])-ylmcoef[20]*(rly[8]*tz+grly[26]*r2); - - double tmp8 = 3.0*z; - rly[21] = tmp8*rly[14];//l=4,m=3 - grly[63] = tmp8*grly[42]; - grly[64] = tmp8*grly[43]; - grly[65] = 3.0*(z*grly[44]+rly[14]); - - - rly[22] = tmp8*rly[15];//l=4,m=-3 - grly[66] = tmp8*grly[45]; - grly[67] = tmp8*grly[46]; - grly[68] = 3.0*(z*grly[47]+rly[15]); - - double tmp9 = ylmcoef[23]*x; - rly[23] = ylmcoef[21]*rly[19]-ylmcoef[22]*rly[7]*r2-tmp9*rly[14];//l=4,m=4 - grly[69] = ylmcoef[21]*grly[57]-ylmcoef[22]*(rly[7]*tx+grly[21]*r2)-ylmcoef[23]*(x*grly[42]+rly[14]); - grly[70] = ylmcoef[21]*grly[58]-ylmcoef[22]*(rly[7]*ty+grly[22]*r2)-tmp9*grly[43]; - grly[71] = ylmcoef[21]*grly[59]-ylmcoef[22]*(rly[7]*tz+grly[23]*r2)-tmp9*grly[44]; - - rly[24] = ylmcoef[21]*rly[20]-ylmcoef[22]*rly[8]*r2-tmp9*rly[15];//l=4,m=-4 - grly[72] = ylmcoef[21]*grly[60]-ylmcoef[22]*(rly[8]*tx+grly[24]*r2)-ylmcoef[23]*(x*grly[45]+rly[15]); - grly[73] = ylmcoef[21]*grly[61]-ylmcoef[22]*(rly[8]*ty+grly[25]*r2)-tmp9*grly[46]; - grly[74] = ylmcoef[21]*grly[62]-ylmcoef[22]*(rly[8]*tz+grly[26]*r2)-tmp9*grly[47]; - - if (nwl == 4) return; - - /*************************** - L = 5 - ***************************/ - rly[25] = ylmcoef[24]*z*rly[16]-ylmcoef[25]*rly[9]*r2;//l=5,m=0 - grly[75] = ylmcoef[24]*z*grly[48]-ylmcoef[25]*(rly[9]*tx+grly[27]*r2); - grly[76] = ylmcoef[24]*z*grly[49]-ylmcoef[25]*(rly[9]*ty+grly[28]*r2); - grly[77] = ylmcoef[24]*(z*grly[50]+rly[16])-ylmcoef[25]*(rly[9]*tz+grly[29]*r2); - - double tmp10 = ylmcoef[26]*z; - rly[26] = tmp10*rly[17]-ylmcoef[27]*rly[10]*r2;//l=5,m=1 - grly[78] = tmp10*grly[51]-ylmcoef[27]*(rly[10]*tx+grly[30]*r2); - grly[79] = tmp10*grly[52]-ylmcoef[27]*(rly[10]*ty+grly[31]*r2); - grly[80] = ylmcoef[26]*(z*grly[53]+rly[17])-ylmcoef[27]*(rly[10]*tz+grly[32]*r2); - - rly[27] = tmp10*rly[18]-ylmcoef[27]*rly[11]*r2;//l=5,m=-1 - grly[81] = tmp10*grly[54]-ylmcoef[27]*(rly[11]*tx+grly[33]*r2); - grly[82] = tmp10*grly[55]-ylmcoef[27]*(rly[11]*ty+grly[34]*r2); - grly[83] = ylmcoef[26]*(z*grly[56]+rly[18])-ylmcoef[27]*(rly[11]*tz+grly[35]*r2); - - double tmp11 = ylmcoef[28]*z; - rly[28] = tmp11*rly[19]-ylmcoef[29]*rly[12]*r2;//l=5,m=2 - grly[84] = tmp11*grly[57]-ylmcoef[29]*(rly[12]*tx+grly[36]*r2); - grly[85] = tmp11*grly[58]-ylmcoef[29]*(rly[12]*ty+grly[37]*r2); - grly[86] = ylmcoef[28]*(z*grly[59]+rly[19])-ylmcoef[29]*(rly[12]*tz+grly[38]*r2); - - rly[29] = tmp11*rly[20]-ylmcoef[29]*rly[13]*r2;//l=5,m=-2 - grly[87] = tmp11*grly[60]-ylmcoef[29]*(rly[13]*tx+grly[39]*r2); - grly[88] = tmp11*grly[61]-ylmcoef[29]*(rly[13]*ty+grly[40]*r2); - grly[89] = ylmcoef[28]*(z*grly[62]+rly[20])-ylmcoef[29]*(rly[13]*tz+grly[41]*r2); - - double tmp12 = ylmcoef[30]*z; - rly[30] = tmp12*rly[21]-ylmcoef[31]*rly[14]*r2;//l=5,m=3 - grly[90] = tmp12*grly[63]-ylmcoef[31]*(grly[42]*r2+rly[14]*tx); - grly[91] = tmp12*grly[64]-ylmcoef[31]*(grly[43]*r2+rly[14]*ty); - grly[92] = ylmcoef[30]*(z*grly[65]+rly[21])-ylmcoef[31]*(grly[44]*r2+rly[14]*tz); - - rly[31] = tmp12*rly[22]-ylmcoef[31]*rly[15]*r2;//l=5,m=-3 - grly[93] = tmp12*grly[66]-ylmcoef[31]*(grly[45]*r2+rly[15]*tx); - grly[94] = tmp12*grly[67]-ylmcoef[31]*(grly[46]*r2+rly[15]*ty); - grly[95] = ylmcoef[30]*(z*grly[68]+rly[22])-ylmcoef[31]*(grly[47]*r2+rly[15]*tz); - - double tmp13 = ylmcoef[32]*z; - rly[32] = tmp13*rly[23];//l=5,m=4 - grly[96] = tmp13*grly[69]; - grly[97] = tmp13*grly[70]; - grly[98] = ylmcoef[32]*(rly[23]+z*grly[71]); - - rly[33] = tmp13*rly[24];//l=5,m=-4 - grly[99] = tmp13*grly[72]; - grly[100] = tmp13*grly[73]; - grly[101] = ylmcoef[32]*(rly[24]+z*grly[74]); - - double tmp14 = ylmcoef[35]*x; - rly[34] = ylmcoef[33]*rly[30]-ylmcoef[34]*rly[14]*r2-tmp14*rly[23];//l=5,m=5 - grly[102] = ylmcoef[33]*grly[90]-ylmcoef[34]*(rly[14]*tx+grly[42]*r2)-ylmcoef[35]*(x*grly[69]+rly[23]); - grly[103] = ylmcoef[33]*grly[91]-ylmcoef[34]*(rly[14]*ty+grly[43]*r2)-tmp14*grly[70]; - grly[104] = ylmcoef[33]*grly[92]-ylmcoef[34]*(rly[14]*tz+grly[44]*r2)-tmp14*grly[71]; - - rly[35] = ylmcoef[33]*rly[31]-ylmcoef[34]*rly[15]*r2-tmp14*rly[24];//l=5,m=-5 - grly[105] = ylmcoef[33]*grly[93]-ylmcoef[34]*(rly[15]*tx+grly[45]*r2)-ylmcoef[35]*(x*grly[72]+rly[24]); - grly[106] = ylmcoef[33]*grly[94]-ylmcoef[34]*(rly[15]*ty+grly[46]*r2)-tmp14*grly[73]; - grly[107] = ylmcoef[33]*grly[95]-ylmcoef[34]*(rly[15]*tz+grly[47]*r2)-tmp14*grly[74]; - - if (nwl == 5) return; + /*************************** + L = 0 + ***************************/ + rly[0] = ylmcoef[0]; //l=0, m=0 + grly[0] = grly[1] = grly[2] = 0.0; + if (nwl == 0) return; + + /*************************** + L = 1 + ***************************/ + rly[1] = ylmcoef[1]*z; //l=1, m=0 + grly[3] = grly[4] = 0.0; + grly[5] = ylmcoef[1]; + + rly[2] = -ylmcoef[1]*x; //l=1, m=1 + grly[7] = grly[8] = 0.0; + grly[6] = -ylmcoef[1]; + + rly[3] = -ylmcoef[1]*y; //l=1, m=-1 + grly[9] = grly[11] = 0.0; + grly[10] = -ylmcoef[1]; + + if (nwl == 1) return; + + /*************************** + L = 2 + ***************************/ + rly[4] = ylmcoef[2]*z*rly[1]-ylmcoef[3]*rly[0]*r2;//l=2, m=0 + grly[12] = ylmcoef[2]*z*grly[3]-ylmcoef[3]*(grly[0]*r2+rly[0]*tx);//l=2, m=0 + grly[13] = ylmcoef[2]*z*grly[4]-ylmcoef[3]*(grly[1]*r2+rly[0]*ty);//l=2, m=0 + grly[14] = ylmcoef[2]*(z*grly[5]+rly[1])-ylmcoef[3]*(grly[2]*r2+rly[0]*tz);//l=2, m=0 + + + double tmp0 = ylmcoef[4]*z; + rly[5] = tmp0*rly[2];//l=2,m=1 + grly[15] = tmp0*grly[6]; + grly[16] = tmp0*grly[7]; + grly[17] = ylmcoef[4]*(rly[2]+z*grly[8]); + + rly[6] = tmp0*rly[3];//l=2,m=-1 + grly[18] = tmp0*grly[9]; + grly[19] = tmp0*grly[10]; + grly[20] = ylmcoef[4]*(rly[3]+z*grly[11]); + + double tmp2 = ylmcoef[4]*x; + rly[7]= ylmcoef[5]*rly[4]-ylmcoef[6]*rly[0]*r2 - tmp2*rly[2];//l=2,m=2 + grly[21] = ylmcoef[5]*grly[12]-ylmcoef[6]*(rly[0]*tx+grly[0]*r2)-ylmcoef[4]*(x*grly[6]+rly[2]); + + grly[22] = ylmcoef[5]*grly[13]-ylmcoef[6]*(rly[0]*ty+grly[1]*r2)-tmp2*grly[7]; + grly[23] = ylmcoef[5]*grly[14]-ylmcoef[6]*(rly[0]*tz+grly[2]*r2)-tmp2*grly[8]; + + rly[8] = -tmp2*rly[3]; + grly[24] = -ylmcoef[4]*(rly[3]+x*grly[9]); + grly[25] = -tmp2*grly[10]; + grly[26] = -tmp2*grly[11]; + if (nwl == 2) return; + + /*************************** + L = 3 + ***************************/ + rly[9] = ylmcoef[7]*z*rly[4]-ylmcoef[8]*rly[1]*r2; //l=3, m=0 + grly[27] = ylmcoef[7]*z*grly[12]-ylmcoef[8]*(rly[1]*tx+grly[3]*r2); + grly[28] = ylmcoef[7]*z*grly[13]-ylmcoef[8]*(rly[1]*ty+grly[4]*r2); + grly[29] = ylmcoef[7]*(rly[4]+z*grly[14])-ylmcoef[8]*(rly[1]*tz+grly[5]*r2); + + double tmp3 = ylmcoef[9]*z; + rly[10] = tmp3*rly[5]-ylmcoef[10]*rly[2]*r2;//l=3,m=1 + grly[30] = tmp3*grly[15]-ylmcoef[10]*(grly[6]*r2+rly[2]*tx); + grly[31] = tmp3*grly[16]-ylmcoef[10]*(grly[7]*r2+rly[2]*ty); + grly[32] = ylmcoef[9]*(z*grly[17]+rly[5])-ylmcoef[10]*(grly[8]*r2+rly[2]*tz); + + rly[11] = tmp3*rly[6]-ylmcoef[10]*rly[3]*r2;//l=3,m=-1 + grly[33] = tmp3*grly[18]-ylmcoef[10]*(grly[9]*r2+rly[3]*tx); + grly[34] = tmp3*grly[19]-ylmcoef[10]*(grly[10]*r2+rly[3]*ty); + grly[35] = ylmcoef[9]*(z*grly[20]+rly[6])-ylmcoef[10]*(grly[11]*r2+rly[3]*tz); + + double tmp4 = ylmcoef[11]*z; + rly[12] = tmp4*rly[7];//l=3,m=2 + grly[36] = tmp4*grly[21]; + grly[37] = tmp4*grly[22]; + grly[38] = ylmcoef[11]*(z*grly[23]+rly[7]); + + rly[13] = tmp4*rly[8];//l=3,m=-2 + grly[39] = tmp4*grly[24]; + grly[40] = tmp4*grly[25]; + grly[41] = ylmcoef[11]*(z*grly[26]+rly[8]); + + double tmp5 = ylmcoef[14]*x; + rly[14] = ylmcoef[12]*rly[10]-ylmcoef[13]*rly[2]*r2-tmp5*rly[7];//l=3,m=3 + grly[42] = ylmcoef[12]*grly[30]-ylmcoef[13]*(rly[2]*tx+grly[6]*r2)-ylmcoef[14]*(rly[7]+x*grly[21]); + grly[43] = ylmcoef[12]*grly[31]-ylmcoef[13]*(rly[2]*ty+grly[7]*r2)-tmp5*grly[22]; + grly[44] = ylmcoef[12]*grly[32]-ylmcoef[13]*(rly[2]*tz+grly[8]*r2)-tmp5*grly[23]; + + rly[15] = ylmcoef[12]*rly[11]-ylmcoef[13]*rly[3]*r2-tmp5*rly[8];//l=3,m=-3 + grly[45] = ylmcoef[12]*grly[33]-ylmcoef[13]*(rly[3]*tx+grly[9]*r2)-ylmcoef[14]*(rly[8]+x*grly[24]); + grly[46] = ylmcoef[12]*grly[34]-ylmcoef[13]*(rly[3]*ty+grly[10]*r2)-tmp5*grly[25]; + grly[47] = ylmcoef[12]*grly[35]-ylmcoef[13]*(rly[3]*tz+grly[11]*r2)-tmp5*grly[26]; + if (nwl == 3) return; + + /*************************** + L = 4 + ***************************/ + rly[16] = ylmcoef[15]*z*rly[9]-ylmcoef[16]*rly[4]*r2;//l=4,m=0 + grly[48] = ylmcoef[15]*z*grly[27]-ylmcoef[16]*(rly[4]*tx+grly[12]*r2); + grly[49] = ylmcoef[15]*z*grly[28]-ylmcoef[16]*(rly[4]*ty+grly[13]*r2); + grly[50] = ylmcoef[15]*(z*grly[29]+rly[9])-ylmcoef[16]*(rly[4]*tz+grly[14]*r2); + + double tmp6 = ylmcoef[17]*z; + rly[17] = tmp6*rly[10]-ylmcoef[18]*rly[5]*r2;//l=4,m=1 + grly[51] = tmp6*grly[30]-ylmcoef[18]*(rly[5]*tx+grly[15]*r2); + grly[52] = tmp6*grly[31]-ylmcoef[18]*(rly[5]*ty+grly[16]*r2); + grly[53] = ylmcoef[17]*(z*grly[32]+rly[10])-ylmcoef[18]*(rly[5]*tz+grly[17]*r2); + + rly[18] = tmp6*rly[11]-ylmcoef[18]*rly[6]*r2;//l=4,m=-1 + grly[54] = tmp6*grly[33]-ylmcoef[18]*(rly[6]*tx+grly[18]*r2); + grly[55] = tmp6*grly[34]-ylmcoef[18]*(rly[6]*ty+grly[19]*r2); + grly[56] = ylmcoef[17]*(z*grly[35]+rly[11])-ylmcoef[18]*(rly[6]*tz+grly[20]*r2); + + double tmp7 = ylmcoef[19]*z; + rly[19] = tmp7*rly[12]-ylmcoef[20]*rly[7]*r2;//l=4,m=2 + grly[57] = tmp7*grly[36]-ylmcoef[20]*(rly[7]*tx+grly[21]*r2); + grly[58] = tmp7*grly[37]-ylmcoef[20]*(rly[7]*ty+grly[22]*r2); + grly[59] = ylmcoef[19]*(z*grly[38]+rly[12])-ylmcoef[20]*(rly[7]*tz+grly[23]*r2); + + rly[20] = tmp7*rly[13]-ylmcoef[20]*rly[8]*r2;//l=4,m=-2 + grly[60] = tmp7*grly[39]-ylmcoef[20]*(rly[8]*tx+grly[24]*r2); + grly[61] = tmp7*grly[40]-ylmcoef[20]*(rly[8]*ty+grly[25]*r2); + grly[62] = ylmcoef[19]*(z*grly[41]+rly[13])-ylmcoef[20]*(rly[8]*tz+grly[26]*r2); + + double tmp8 = 3.0*z; + rly[21] = tmp8*rly[14];//l=4,m=3 + grly[63] = tmp8*grly[42]; + grly[64] = tmp8*grly[43]; + grly[65] = 3.0*(z*grly[44]+rly[14]); + + + rly[22] = tmp8*rly[15];//l=4,m=-3 + grly[66] = tmp8*grly[45]; + grly[67] = tmp8*grly[46]; + grly[68] = 3.0*(z*grly[47]+rly[15]); + + double tmp9 = ylmcoef[23]*x; + rly[23] = ylmcoef[21]*rly[19]-ylmcoef[22]*rly[7]*r2-tmp9*rly[14];//l=4,m=4 + grly[69] = ylmcoef[21]*grly[57]-ylmcoef[22]*(rly[7]*tx+grly[21]*r2)-ylmcoef[23]*(x*grly[42]+rly[14]); + grly[70] = ylmcoef[21]*grly[58]-ylmcoef[22]*(rly[7]*ty+grly[22]*r2)-tmp9*grly[43]; + grly[71] = ylmcoef[21]*grly[59]-ylmcoef[22]*(rly[7]*tz+grly[23]*r2)-tmp9*grly[44]; + + rly[24] = ylmcoef[21]*rly[20]-ylmcoef[22]*rly[8]*r2-tmp9*rly[15];//l=4,m=-4 + grly[72] = ylmcoef[21]*grly[60]-ylmcoef[22]*(rly[8]*tx+grly[24]*r2)-ylmcoef[23]*(x*grly[45]+rly[15]); + grly[73] = ylmcoef[21]*grly[61]-ylmcoef[22]*(rly[8]*ty+grly[25]*r2)-tmp9*grly[46]; + grly[74] = ylmcoef[21]*grly[62]-ylmcoef[22]*(rly[8]*tz+grly[26]*r2)-tmp9*grly[47]; + + if (nwl == 4) return; + + /*************************** + L = 5 + ***************************/ + rly[25] = ylmcoef[24]*z*rly[16]-ylmcoef[25]*rly[9]*r2;//l=5,m=0 + grly[75] = ylmcoef[24]*z*grly[48]-ylmcoef[25]*(rly[9]*tx+grly[27]*r2); + grly[76] = ylmcoef[24]*z*grly[49]-ylmcoef[25]*(rly[9]*ty+grly[28]*r2); + grly[77] = ylmcoef[24]*(z*grly[50]+rly[16])-ylmcoef[25]*(rly[9]*tz+grly[29]*r2); + + double tmp10 = ylmcoef[26]*z; + rly[26] = tmp10*rly[17]-ylmcoef[27]*rly[10]*r2;//l=5,m=1 + grly[78] = tmp10*grly[51]-ylmcoef[27]*(rly[10]*tx+grly[30]*r2); + grly[79] = tmp10*grly[52]-ylmcoef[27]*(rly[10]*ty+grly[31]*r2); + grly[80] = ylmcoef[26]*(z*grly[53]+rly[17])-ylmcoef[27]*(rly[10]*tz+grly[32]*r2); + + rly[27] = tmp10*rly[18]-ylmcoef[27]*rly[11]*r2;//l=5,m=-1 + grly[81] = tmp10*grly[54]-ylmcoef[27]*(rly[11]*tx+grly[33]*r2); + grly[82] = tmp10*grly[55]-ylmcoef[27]*(rly[11]*ty+grly[34]*r2); + grly[83] = ylmcoef[26]*(z*grly[56]+rly[18])-ylmcoef[27]*(rly[11]*tz+grly[35]*r2); + + double tmp11 = ylmcoef[28]*z; + rly[28] = tmp11*rly[19]-ylmcoef[29]*rly[12]*r2;//l=5,m=2 + grly[84] = tmp11*grly[57]-ylmcoef[29]*(rly[12]*tx+grly[36]*r2); + grly[85] = tmp11*grly[58]-ylmcoef[29]*(rly[12]*ty+grly[37]*r2); + grly[86] = ylmcoef[28]*(z*grly[59]+rly[19])-ylmcoef[29]*(rly[12]*tz+grly[38]*r2); + + rly[29] = tmp11*rly[20]-ylmcoef[29]*rly[13]*r2;//l=5,m=-2 + grly[87] = tmp11*grly[60]-ylmcoef[29]*(rly[13]*tx+grly[39]*r2); + grly[88] = tmp11*grly[61]-ylmcoef[29]*(rly[13]*ty+grly[40]*r2); + grly[89] = ylmcoef[28]*(z*grly[62]+rly[20])-ylmcoef[29]*(rly[13]*tz+grly[41]*r2); + + double tmp12 = ylmcoef[30]*z; + rly[30] = tmp12*rly[21]-ylmcoef[31]*rly[14]*r2;//l=5,m=3 + grly[90] = tmp12*grly[63]-ylmcoef[31]*(grly[42]*r2+rly[14]*tx); + grly[91] = tmp12*grly[64]-ylmcoef[31]*(grly[43]*r2+rly[14]*ty); + grly[92] = ylmcoef[30]*(z*grly[65]+rly[21])-ylmcoef[31]*(grly[44]*r2+rly[14]*tz); + + rly[31] = tmp12*rly[22]-ylmcoef[31]*rly[15]*r2;//l=5,m=-3 + grly[93] = tmp12*grly[66]-ylmcoef[31]*(grly[45]*r2+rly[15]*tx); + grly[94] = tmp12*grly[67]-ylmcoef[31]*(grly[46]*r2+rly[15]*ty); + grly[95] = ylmcoef[30]*(z*grly[68]+rly[22])-ylmcoef[31]*(grly[47]*r2+rly[15]*tz); + + double tmp13 = ylmcoef[32]*z; + rly[32] = tmp13*rly[23];//l=5,m=4 + grly[96] = tmp13*grly[69]; + grly[97] = tmp13*grly[70]; + grly[98] = ylmcoef[32]*(rly[23]+z*grly[71]); + + rly[33] = tmp13*rly[24];//l=5,m=-4 + grly[99] = tmp13*grly[72]; + grly[100] = tmp13*grly[73]; + grly[101] = ylmcoef[32]*(rly[24]+z*grly[74]); + + double tmp14 = ylmcoef[35]*x; + rly[34] = ylmcoef[33]*rly[30]-ylmcoef[34]*rly[14]*r2-tmp14*rly[23];//l=5,m=5 + grly[102] = ylmcoef[33]*grly[90]-ylmcoef[34]*(rly[14]*tx+grly[42]*r2)-ylmcoef[35]*(x*grly[69]+rly[23]); + grly[103] = ylmcoef[33]*grly[91]-ylmcoef[34]*(rly[14]*ty+grly[43]*r2)-tmp14*grly[70]; + grly[104] = ylmcoef[33]*grly[92]-ylmcoef[34]*(rly[14]*tz+grly[44]*r2)-tmp14*grly[71]; + + rly[35] = ylmcoef[33]*rly[31]-ylmcoef[34]*rly[15]*r2-tmp14*rly[24];//l=5,m=-5 + grly[105] = ylmcoef[33]*grly[93]-ylmcoef[34]*(rly[15]*tx+grly[45]*r2)-ylmcoef[35]*(x*grly[72]+rly[24]); + grly[106] = ylmcoef[33]*grly[94]-ylmcoef[34]*(rly[15]*ty+grly[46]*r2)-tmp14*grly[73]; + grly[107] = ylmcoef[33]*grly[95]-ylmcoef[34]*(rly[15]*tz+grly[47]*r2)-tmp14*grly[74]; + + if (nwl == 5) return; } } // namespace ModuleBase diff --git a/source/source_base/main.cpp b/source/source_base/main.cpp index 9a32f11d289..857b99423ed 100644 --- a/source/source_base/main.cpp +++ b/source/source_base/main.cpp @@ -9,11 +9,11 @@ void calculate(); int main(int argc, char **argv) { - std::cout << "Hello, this is the 'base' module of ABACUS." << std::endl; + std::cout << "Hello, this is the 'base' module of ABACUS." << std::endl; - std::cout << "The module searchs for the neighboring atoms for a given atomic position" << std::endl; + std::cout << "The module searchs for the neighboring atoms for a given atomic position" << std::endl; - std::cout << "Right now, the module is still empty, soon we will have more tests." << std::endl; + std::cout << "Right now, the module is still empty, soon we will have more tests." << std::endl; calculate(); @@ -23,41 +23,41 @@ int main(int argc, char **argv) void calculate() { - std::ofstream ofs("log.txt"); + std::ofstream ofs("log.txt"); // ooo.set_orb_tables(); - ofs.close(); + ofs.close(); - std::cout << "--------------------" << std::endl; - std::cout << " Have a great day! " << std::endl; - std::cout << "--------------------" << std::endl; + std::cout << "--------------------" << std::endl; + std::cout << " Have a great day! " << std::endl; + std::cout << "--------------------" << std::endl; /* - time_t time_start = std::time(NULL); + time_t time_start = std::time(NULL); // ModuleBase::timer::start(); - //---------------------------------------------------------- - // main program for doing electronic structure calculations - //---------------------------------------------------------- + //---------------------------------------------------------- + // main program for doing electronic structure calculations + //---------------------------------------------------------- // Driver DD; // DD.init(); - time_t time_finish= std::time(NULL); + time_t time_finish= std::time(NULL); - // print out information before ABACUS ends - std::cout << "\n START Time : " << ctime(&time_start); - std::cout << " FINISH Time : " << ctime(&time_finish); - std::cout << " TOTAL Time : " << difftime(time_finish, time_start) << std::endl; + // print out information before ABACUS ends + std::cout << "\n START Time : " << ctime(&time_start); + std::cout << " FINISH Time : " << ctime(&time_finish); + std::cout << " TOTAL Time : " << difftime(time_finish, time_start) << std::endl; - double total_time = difftime(time_finish, time_start); - int hour = total_time / 3600; - int mins = ( total_time - 3600 * hour ) / 60; - int secs = total_time - 3600 * hour - 60 * mins ; - std::cout << " Total Time : " << hour << " h " - << mins << " mins " - << secs << " secs "<< std::endl; + double total_time = difftime(time_finish, time_start); + int hour = total_time / 3600; + int mins = ( total_time - 3600 * hour ) / 60; + int secs = total_time - 3600 * hour - 60 * mins ; + std::cout << " Total Time : " << hour << " h " + << mins << " mins " + << secs << " secs "<< std::endl; */ return; diff --git a/source/source_base/math_integral.h b/source/source_base/math_integral.h index 4e32889e5f0..3163a1dce76 100644 --- a/source/source_base/math_integral.h +++ b/source/source_base/math_integral.h @@ -8,7 +8,7 @@ namespace ModuleBase class Integral { - public: + public: Integral(); ~Integral(); @@ -41,13 +41,13 @@ class Integral * @author Peize Lin * @date 2017-10-02 */ - static void Simpson_Integral - ( - const int mesh, - const double * const func, - const double dr, - double &asum - ); + static void Simpson_Integral + ( + const int mesh, + const double * const func, + const double dr, + double &asum + ); /** * @brief simpson integral. diff --git a/source/source_base/math_polyint.cpp b/source/source_base/math_polyint.cpp index ca62ebb72c2..6f09e8703ed 100644 --- a/source/source_base/math_polyint.cpp +++ b/source/source_base/math_polyint.cpp @@ -19,11 +19,11 @@ void PolyInt::Polynomial_Interpolation assert(table_interval>0.0); const double position = x / table_interval; const int iq = static_cast(position); - if(iq>=table_length-4) - { - std::cout << "\n x = " << x; - std::cout << "\n iq = " << iq << " table_length = " << table_length << std::endl; - } + if(iq>=table_length-4) + { + std::cout << "\n x = " << x; + std::cout << "\n iq = " << iq << " table_length = " << table_length << std::endl; + } assert(iq < table_length-4); const double x0 = position - static_cast(iq); @@ -86,7 +86,7 @@ double PolyInt::Polynomial_Interpolation // pengfei Li 2018-3-23 const ModuleBase::realArray &table, const int &dim1, const int &dim2, - const int &dim3, + const int &dim3, const int &table_length, const double &table_interval, const double &x // input value @@ -97,13 +97,13 @@ double PolyInt::Polynomial_Interpolation // pengfei Li 2018-3-23 const double position = x / table_interval; const int iq = static_cast(position); - if(iq>table_length-4) - { - std::cout << "\n x = " << x; - std::cout << "\n table_interval = " << table_interval; - std::cout << "\n iq=" << iq << " table_length = " << table_length << std::endl; - } - assert(iq < table_length-4); + if(iq>table_length-4) + { + std::cout << "\n x = " << x; + std::cout << "\n table_interval = " << table_interval; + std::cout << "\n iq=" << iq << " table_length = " << table_length << std::endl; + } + assert(iq < table_length-4); const double x0 = position - static_cast(iq); const double x1 = 1.0 - x0; const double x2 = 2.0 - x0; @@ -144,11 +144,11 @@ double PolyInt::Polynomial_Interpolation /* const double y= - table[iq] * x1 * x2 * x3 / 6.0 + - table[iq+1] * x0 * x2 * x3 / 2.0 - - table[iq+2] * x1 * x0 * x3 / 2.0 + - table[iq+3] * x1 * x2 * x0 / 6.0 ; - */ + table[iq] * x1 * x2 * x3 / 6.0 + + table[iq+1] * x0 * x2 * x3 / 2.0 - + table[iq+2] * x1 * x0 * x3 / 2.0 + + table[iq+3] * x1 * x2 * x0 / 6.0 ; + */ return x1*x2*(table[iq]*x3+table[iq+3]*x0)/6.0 + x0*x3*(table[iq+1]*x2-table[iq+2]*x1)/2.0; diff --git a/source/source_base/math_polyint.h b/source/source_base/math_polyint.h index b15f50678c3..da6f33c7dcb 100644 --- a/source/source_base/math_polyint.h +++ b/source/source_base/math_polyint.h @@ -10,10 +10,10 @@ namespace ModuleBase class PolyInt { - public: + public: - PolyInt(); - ~PolyInt(); + PolyInt(); + ~PolyInt(); //======================================================== // Polynomial_Interpolation @@ -98,8 +98,8 @@ class PolyInt * @param x [in] the position to be predicted * @return double the predicted value */ - static double Polynomial_Interpolation - ( + static double Polynomial_Interpolation + ( const double *table, const int &table_length, const double &table_interval, diff --git a/source/source_base/math_sphbes.cpp b/source/source_base/math_sphbes.cpp index 300d7de0324..832f1191a62 100644 --- a/source/source_base/math_sphbes.cpp +++ b/source/source_base/math_sphbes.cpp @@ -42,9 +42,9 @@ void Sphbes::BESSJY(double x, double xnu, double *rj, double *ry, double *rjp, d if (x <= 0.0 || xnu < 0.0) { - std::cout << "Sphbes::BESSJY, bad arguments" << std::endl; + std::cout << "Sphbes::BESSJY, bad arguments" << std::endl; //ModuleBase::WARNING_QUIT("Sphbes::BESSJY","bad arguments"); - exit(0); // mohan add 2021-05-06 + exit(0); // mohan add 2021-05-06 } @@ -58,9 +58,9 @@ void Sphbes::BESSJY(double x, double xnu, double *rj, double *ry, double *rjp, d h = xnu * xi; if (h < FPMIN) - { - h = FPMIN; - } + { + h = FPMIN; + } b = xi2 * xnu; @@ -91,9 +91,9 @@ void Sphbes::BESSJY(double x, double xnu, double *rj, double *ry, double *rjp, d } if (i > MAXIT) - { - std::cout << "x too large in bessjy; try asymptotic expansion" << std::endl; - } + { + std::cout << "x too large in bessjy; try asymptotic expansion" << std::endl; + } rjl = isign * FPMIN; @@ -114,9 +114,9 @@ void Sphbes::BESSJY(double x, double xnu, double *rj, double *ry, double *rjp, d } if (rjl == 0.0) - { - rjl = EPS; - } + { + rjl = EPS; + } f = rjpl / rjl; @@ -286,16 +286,16 @@ void Sphbes::BESCHB(double x, double *gam1, double *gam2, double *gampl, double double Sphbes::CHEBEV(double a, double b, double c[], int m, double x) { double d = 0.0; - double dd = 0.0; - double sv = 0.0; - double y = 0.0; - double y2 = 0.0; + double dd = 0.0; + double sv = 0.0; + double y = 0.0; + double y2 = 0.0; int j=0; if ((x - a)*(x - b) > 0.0) - { - std::cout << "x not in range in routine chebev" << std::endl; - } + { + std::cout << "x not in range in routine chebev" << std::endl; + } y2 = 2.0 * (y = (2.0 * x - a - b) / (b - a)); @@ -321,9 +321,9 @@ double Sphbes::Spherical_Bessel_7(const int n, const double &x) if (n < 0 || x <= 0.0) { - std::cout << "Spherical_Bessel_7, bad arguments in sphbes" << std::endl; + std::cout << "Spherical_Bessel_7, bad arguments in sphbes" << std::endl; //ModuleBase::WARNING_QUIT("Sphbes::Spherical_Bessel_7","bad arguments in sphbes"); - exit(0); + exit(0); } order = n + 0.5; @@ -350,17 +350,17 @@ void Sphbes::Spherical_Bessel_Roots { //ModuleBase::TITLE("Sphbes","Spherical_Bessel_Roots"); if (num<=0) - { - std::cout << "Spherical_Bessel_Roots, num<=0" << std::endl; - //ModuleBase::WARNING_QUIT("Sphbes::Spherical_Bessel_Roots","num<=0"); - exit(0); - } + { + std::cout << "Spherical_Bessel_Roots, num<=0" << std::endl; + //ModuleBase::WARNING_QUIT("Sphbes::Spherical_Bessel_Roots","num<=0"); + exit(0); + } if (rcut<=0.0) - { - std::cout << "Spherical_Bessel_Roots, rcut<=0" << std::endl; - //ModuleBase::WARNING_QUIT("Sphbes::Spherical_Bessel_Roots","rcut<=0.0"); - exit(0); - } + { + std::cout << "Spherical_Bessel_Roots, rcut<=0" << std::endl; + //ModuleBase::WARNING_QUIT("Sphbes::Spherical_Bessel_Roots","rcut<=0.0"); + exit(0); + } double min = 0.0; double max = 2*ModuleBase::PI + (num + (l+0.5)/2 + 0.75)*ModuleBase::PI/2 + @@ -444,8 +444,8 @@ void Sphbes::Spherical_Bessel double x1=0.0; int i=0; - int ir=0; - int ir0=0; + int ir=0; + int ir0=0; if (l>=7) { @@ -609,7 +609,7 @@ void Sphbes::Spherical_Bessel else { std::cout << "\n error in sph_bes, l out of {-1 ... 6},l = " << l ; - exit(0); + exit(0); } } @@ -619,23 +619,23 @@ void Sphbes::Spherical_Bessel void Sphbes::Spherical_Bessel ( - const int &msh, //number of grid points - const double *r,//radial grid - const double &q, // - const int &l, //angular momentum - double *sj, //jl(1:msh) = j_l(q*r(i)),spherical bessel function - double *sjp + const int &msh, //number of grid points + const double *r,//radial grid + const double &q, // + const int &l, //angular momentum + double *sj, //jl(1:msh) = j_l(q*r(i)),spherical bessel function + double *sjp ) { - //calculate jlx first - Spherical_Bessel (msh, r, q, l, sj); + //calculate jlx first + Spherical_Bessel (msh, r, q, l, sj); - for (int ir = 0; ir < msh; ir++) - { - sjp[ir] = 1.0; - } - return; + for (int ir = 0; ir < msh; ir++) + { + sjp[ir] = 1.0; + } + return; } void Sphbes::dSpherical_Bessel_dx @@ -649,8 +649,8 @@ void Sphbes::dSpherical_Bessel_dx { if (l < 0 ) { - std::cout << "We temporarily only calculate derivative of l >= 0." << std::endl; - exit(0); + std::cout << "We temporarily only calculate derivative of l >= 0." << std::endl; + exit(0); } double djl0 = 0; diff --git a/source/source_base/math_sphbes.h b/source/source_base/math_sphbes.h index 7aa9c78a48c..c14829af56f 100644 --- a/source/source_base/math_sphbes.h +++ b/source/source_base/math_sphbes.h @@ -11,7 +11,7 @@ namespace ModuleBase class Sphbes { - public: + public: Sphbes(); ~Sphbes(); @@ -62,25 +62,25 @@ class Sphbes * @param jl [out] jl spherical bessel function * @param sjp [out] sjp[i] is assigned to be 1.0. i < msh. */ - static void Spherical_Bessel - ( - const int &msh, - const double *r, - const double &q, - const int &l, - double *sj, - double *sjp - ); - - /** - * @brief return num eigenvalues of spherical bessel function - * - * @param num [in] the number of eigenvalues - * @param l [in] angular number - * @param epsilon [in] the accuracy - * @param eigenvalue [out] the calculated eigenvalues - * @param rcut [in] the cutoff the radial function - */ + static void Spherical_Bessel + ( + const int &msh, + const double *r, + const double &q, + const int &l, + double *sj, + double *sjp + ); + + /** + * @brief return num eigenvalues of spherical bessel function + * + * @param num [in] the number of eigenvalues + * @param l [in] angular number + * @param epsilon [in] the accuracy + * @param eigenvalue [out] the calculated eigenvalues + * @param rcut [in] the cutoff the radial function + */ static void Spherical_Bessel_Roots ( const int &num, @@ -144,7 +144,7 @@ class Sphbes static double Spherical_Bessel_7(const int n, const double &x); - // Peize Lin change double to void 2019-05-01 + // Peize Lin change double to void 2019-05-01 static void BESSJY(double x, double xnu, double *rj, double *ry, double *rjp, double *ryp); static void BESCHB(double x, double *gam1, double *gam2, double *gampl, double *gammi); diff --git a/source/source_base/math_ylmreal.cpp b/source/source_base/math_ylmreal.cpp index 47415de44d1..acb158b3809 100644 --- a/source/source_base/math_ylmreal.cpp +++ b/source/source_base/math_ylmreal.cpp @@ -23,220 +23,220 @@ void YlmReal::rlylm const int lmax, const double& x, const double& y, - const double& z, // g_cartesian_vec(x,y,z) + const double& z, // g_cartesian_vec(x,y,z) double* rly // output ) { - ModuleBase::timer::start("YlmReal","rlylm"); - - assert(lmax >= 0); - - //get xy_dependence - assert(lmax <= 19); - - double Am[20]; - double Bm[20]; - - // mohan add 2021-05-07 - for(int i=0; i<20; ++i) - { - Am[i]=0.0; - Bm[i]=0.0; - } - - //ZEROS(Am, 20); - //ZEROS(Bm, 20); - - double x2, x3, x4, x5; - double y2, y3, y4, y5; - - x2 = x * x; - x3 = x2 * x; - x4 = x3 * x; - x5 = x4 * x; - - y2 = y * y; - y3 = y2 * y; - y4 = y3 * y; - y5 = y4 * y; - - //x-y dependence - //Am - //Bm - for(int im = 0; im < lmax+1; im++) - { - if(im == 0) - { - Am[0] = 1.0; - Bm[0] = 0.0; - } - else if(im == 1) - { - Am[1] = x; - Bm[1] = y; - } - else if(im == 2) - { - Am[2] = x2- y2; - Bm[2] = 2.0 * x * y; - } - else if(im == 3) - { - Am[3] = x3 - 3.0 * x * y2; - Bm[3] = 3.0 * x2 * y - y3; - } - else if(im == 4) - { - Am[4] = x4 - 6.0 * x2 * y2 + y4; - Bm[4] = 4.0 * (x3 * y - x * y3); - } - else if(im == 5) - { - Am[5] = x5 - 10.0 * x3 * y2 + 5.0 * x * y4; - Bm[5] = 5.0 * x4 * y - 10.0 * x2 * y3 + y5; - } - else - { - for(int ip = 0; ip <= im; ip++) - { - double aux = Fact(im) / Fact(ip) / Fact(im - ip); - Am[im] += aux * pow(x, ip) * pow(y, im-ip) * cos( (im-ip) * ModuleBase::PI / 2.0 ); - Bm[im] += aux * pow(x, ip) * pow(y, im-ip) * sin( (im-ip) * ModuleBase::PI / 2.0 ); - } - } - } - - //z dependence - double zdep[20][20]; - - for(int il = 0; il < 20; il++) - { - for(int jl=0; jl < 20; jl++) - { - zdep[il][jl]=0.0; // mohan add 2021-05-07 - } + ModuleBase::timer::start("YlmReal","rlylm"); + + assert(lmax >= 0); + + //get xy_dependence + assert(lmax <= 19); + + double Am[20]; + double Bm[20]; + + // mohan add 2021-05-07 + for(int i=0; i<20; ++i) + { + Am[i]=0.0; + Bm[i]=0.0; + } + + //ZEROS(Am, 20); + //ZEROS(Bm, 20); + + double x2, x3, x4, x5; + double y2, y3, y4, y5; + + x2 = x * x; + x3 = x2 * x; + x4 = x3 * x; + x5 = x4 * x; + + y2 = y * y; + y3 = y2 * y; + y4 = y3 * y; + y5 = y4 * y; + + //x-y dependence + //Am + //Bm + for(int im = 0; im < lmax+1; im++) + { + if(im == 0) + { + Am[0] = 1.0; + Bm[0] = 0.0; + } + else if(im == 1) + { + Am[1] = x; + Bm[1] = y; + } + else if(im == 2) + { + Am[2] = x2- y2; + Bm[2] = 2.0 * x * y; + } + else if(im == 3) + { + Am[3] = x3 - 3.0 * x * y2; + Bm[3] = 3.0 * x2 * y - y3; + } + else if(im == 4) + { + Am[4] = x4 - 6.0 * x2 * y2 + y4; + Bm[4] = 4.0 * (x3 * y - x * y3); + } + else if(im == 5) + { + Am[5] = x5 - 10.0 * x3 * y2 + 5.0 * x * y4; + Bm[5] = 5.0 * x4 * y - 10.0 * x2 * y3 + y5; + } + else + { + for(int ip = 0; ip <= im; ip++) + { + double aux = Fact(im) / Fact(ip) / Fact(im - ip); + Am[im] += aux * pow(x, ip) * pow(y, im-ip) * cos( (im-ip) * ModuleBase::PI / 2.0 ); + Bm[im] += aux * pow(x, ip) * pow(y, im-ip) * sin( (im-ip) * ModuleBase::PI / 2.0 ); + } + } + } + + //z dependence + double zdep[20][20]; + + for(int il = 0; il < 20; il++) + { + for(int jl=0; jl < 20; jl++) + { + zdep[il][jl]=0.0; // mohan add 2021-05-07 + } // ZEROS(zdep[il], 20); - } - - double z2 = z * z; - double z3 = z2 * z; - double z4 = z3 * z; - //double z5 = z4 * z; - - double r = sqrt(x*x + y*y + z*z); - double r2 = r * r; - double r3 = r2 * r; - double r4 = r3 * r; - - for(int il = 0; il < lmax + 1; il++) - { - if(il == 0) - { - zdep[0][0] = 1.0; - } - else if(il == 1) - { - zdep[1][0] = z; - zdep[1][1] = 1.0; - } - else if(il == 2) - { - zdep[2][0] = 0.5 * (3.0 * z2 - r2); - zdep[2][1] = sqrt(3.0) * z; - zdep[2][2] = sqrt(3.0) * 0.5; - } - else if(il == 3) - { - zdep[3][0] = 2.5 * z3 - 1.5 * z * r2; - zdep[3][1] = 0.25 * sqrt(6.0) * (5.0 * z2 - r2); - zdep[3][2] = 0.5 * sqrt(15.0) * z; - zdep[3][3] = 0.25 * sqrt(10.0); - } - else if(il == 4) - { - zdep[4][0] = 0.125 * (35.0 * z4 - 30.0 * r2 * z2 + 3.0 * r4); - zdep[4][1] = sqrt(10.0) * 0.25 * z * (7.0 * z2 - 3.0 * r2); - zdep[4][2] = sqrt(5.0) * 0.25 * (7.0 * z2 - r2); - zdep[4][3] = sqrt(70.0) * 0.25 * z; - zdep[4][4] = sqrt(35.0) * 0.125; - } - else if(il == 5) - { - zdep[5][0] = 0.125 * z *( 63.0 * z4 - 70.0 * z2 * r2 + 15.0 * r4); - zdep[5][1] = 0.125 * sqrt(15.0) * (21.0 * z4 - 14.0 * z2 * r2 + r4); - zdep[5][2] = 0.25 * sqrt(105.0) * z * (3.0 * z2 - r2); - zdep[5][3] = 0.0625 * sqrt(70.0) * (9.0 * z2 - r2); - zdep[5][4] = 0.375 * sqrt(35.0) * z; - zdep[5][5] = 0.1875 * sqrt(14.0); - } - else - { - for(int im = 0; im <= il; im++) - { - int kmax = static_cast( (il - im) / 2 ); - for(int ik = 0; ik <= kmax; ik++) - { - int twok = 2 * ik; - - double gamma = 0.0; - double aux0, aux1, aux2, aux3; - - aux0 = pow(-1.0, ik) * pow(2.0, -il); - aux1 = Fact(il) / Fact(ik) / Fact(il-ik); - aux2 = Fact(2*il - twok) / Fact(il) / Fact(il - twok); - aux3 = Fact(il - twok) / Fact(il - twok - im); - - gamma = aux0 * aux1 * aux2 * aux3; - - assert(il - twok - im >= 0); - zdep[il][im] += pow(r, twok) * pow(z, il-twok-im) * gamma; - } - - if(im >= 1) - { - zdep[il][im] *= sqrt(2 * Fact(il - im) / Fact(il + im)); - - } - } - } - } - - //calc - int ic = 0; - - //special case for r=0 - double rpi = r; - const double tiny = 1.0E-10; - if (rpi < tiny) rpi += tiny; - - for(int il = 0; il <= lmax; il++) - { - double fac = sqrt( (2.0 * il + 1.0) / ModuleBase::FOUR_PI ); - - double rl = pow(rpi, il); - - //m=0 - rly[ic] = Am[0] * zdep[il][0] * fac / rl; - - ic++; - - //m ! = 0 - for(int im = 1; im <= il; im++) - { - //m>0 - rly[ic] = Am[im] * zdep[il][im] * pow(-1.0, im) * fac / rl; - - ic++; - - //m<0 - rly[ic] = Bm[im] * zdep[il][im] * pow(-1.0, im) * fac / rl; - - ic++; - } - } - - ModuleBase::timer::end("YlmReal","rlylm"); - return; + } + + double z2 = z * z; + double z3 = z2 * z; + double z4 = z3 * z; + //double z5 = z4 * z; + + double r = sqrt(x*x + y*y + z*z); + double r2 = r * r; + double r3 = r2 * r; + double r4 = r3 * r; + + for(int il = 0; il < lmax + 1; il++) + { + if(il == 0) + { + zdep[0][0] = 1.0; + } + else if(il == 1) + { + zdep[1][0] = z; + zdep[1][1] = 1.0; + } + else if(il == 2) + { + zdep[2][0] = 0.5 * (3.0 * z2 - r2); + zdep[2][1] = sqrt(3.0) * z; + zdep[2][2] = sqrt(3.0) * 0.5; + } + else if(il == 3) + { + zdep[3][0] = 2.5 * z3 - 1.5 * z * r2; + zdep[3][1] = 0.25 * sqrt(6.0) * (5.0 * z2 - r2); + zdep[3][2] = 0.5 * sqrt(15.0) * z; + zdep[3][3] = 0.25 * sqrt(10.0); + } + else if(il == 4) + { + zdep[4][0] = 0.125 * (35.0 * z4 - 30.0 * r2 * z2 + 3.0 * r4); + zdep[4][1] = sqrt(10.0) * 0.25 * z * (7.0 * z2 - 3.0 * r2); + zdep[4][2] = sqrt(5.0) * 0.25 * (7.0 * z2 - r2); + zdep[4][3] = sqrt(70.0) * 0.25 * z; + zdep[4][4] = sqrt(35.0) * 0.125; + } + else if(il == 5) + { + zdep[5][0] = 0.125 * z *( 63.0 * z4 - 70.0 * z2 * r2 + 15.0 * r4); + zdep[5][1] = 0.125 * sqrt(15.0) * (21.0 * z4 - 14.0 * z2 * r2 + r4); + zdep[5][2] = 0.25 * sqrt(105.0) * z * (3.0 * z2 - r2); + zdep[5][3] = 0.0625 * sqrt(70.0) * (9.0 * z2 - r2); + zdep[5][4] = 0.375 * sqrt(35.0) * z; + zdep[5][5] = 0.1875 * sqrt(14.0); + } + else + { + for(int im = 0; im <= il; im++) + { + int kmax = static_cast( (il - im) / 2 ); + for(int ik = 0; ik <= kmax; ik++) + { + int twok = 2 * ik; + + double gamma = 0.0; + double aux0, aux1, aux2, aux3; + + aux0 = pow(-1.0, ik) * pow(2.0, -il); + aux1 = Fact(il) / Fact(ik) / Fact(il-ik); + aux2 = Fact(2*il - twok) / Fact(il) / Fact(il - twok); + aux3 = Fact(il - twok) / Fact(il - twok - im); + + gamma = aux0 * aux1 * aux2 * aux3; + + assert(il - twok - im >= 0); + zdep[il][im] += pow(r, twok) * pow(z, il-twok-im) * gamma; + } + + if(im >= 1) + { + zdep[il][im] *= sqrt(2 * Fact(il - im) / Fact(il + im)); + + } + } + } + } + + //calc + int ic = 0; + + //special case for r=0 + double rpi = r; + const double tiny = 1.0E-10; + if (rpi < tiny) rpi += tiny; + + for(int il = 0; il <= lmax; il++) + { + double fac = sqrt( (2.0 * il + 1.0) / ModuleBase::FOUR_PI ); + + double rl = pow(rpi, il); + + //m=0 + rly[ic] = Am[0] * zdep[il][0] * fac / rl; + + ic++; + + //m ! = 0 + for(int im = 1; im <= il; im++) + { + //m>0 + rly[ic] = Am[im] * zdep[il][im] * pow(-1.0, im) * fac / rl; + + ic++; + + //m<0 + rly[ic] = Bm[im] * zdep[il][im] * pow(-1.0, im) * fac / rl; + + ic++; + } + } + + ModuleBase::timer::end("YlmReal","rlylm"); + return; } @@ -276,19 +276,19 @@ void YlmReal::Ylm_Real2 //---------------------------------------------------------- // Start CALC //---------------------------------------------------------- - std::vector rly(lmax2); - - for (int ig = 0; ig < ng; ig++) - { - rlylm (lmax, g[ig].x, g[ig].y, g[ig].z, rly.data()); - - for (int lm = 0; lm < lmax2; lm++) - { - ylm (lm, ig) = rly[lm]; - } - } - - return; + std::vector rly(lmax2); + + for (int ig = 0; ig < ng; ig++) + { + rlylm (lmax, g[ig].x, g[ig].y, g[ig].z, rly.data()); + + for (int lm = 0; lm < lmax2; lm++) + { + ylm (lm, ig) = rly[lm]; + } + } + + return; } //========================================================== @@ -406,8 +406,8 @@ void YlmReal::Ylm_Real // NAME : cost = cos(theta),theta and phi are polar angles // NAME : phi //---------------------------------------------------------- - std::vector cost(ng); - std::vector phi(ng); + std::vector cost(ng); + std::vector phi(ng); #ifdef _OPENMP #pragma omp parallel for @@ -529,10 +529,10 @@ void YlmReal::Ylm_Real #endif for (int i=0;i *g, - matrix &ylm, + matrix &ylm, matrix &dylmx, - matrix &dylmy, - matrix &dylmz + matrix &dylmy, + matrix &dylmz ) { - ModuleBase::Ylm::set_coefficients(); - const int lmax = int(sqrt( double(lmax2) ) + 0.1) - 1; - std::vector tmpylm((lmax2+1) * (lmax2+1)); - std::vector tmpgylm((lmax2+1) * (lmax2+1) * 3); + ModuleBase::Ylm::set_coefficients(); + const int lmax = int(sqrt( double(lmax2) ) + 0.1) - 1; + std::vector tmpylm((lmax2+1) * (lmax2+1)); + std::vector tmpgylm((lmax2+1) * (lmax2+1) * 3); - for (int ig = 0;ig < ng;ig++) + for (int ig = 0;ig < ng;ig++) { - ModuleBase::Vector3 gg = g[ig]; + ModuleBase::Vector3 gg = g[ig]; double gmod = gg.norm(); if (gmod < 1.0e-9) { - for(int lm = 0 ; lm < lmax2 ; ++lm) - { - if(lm == 0) - ylm(lm,ig) = ModuleBase::SQRT_INVERSE_FOUR_PI; - else - ylm(lm,ig) = 0; - dylmx(lm,ig) = dylmy(lm,ig) = dylmz(lm,ig) = 0; - } - } - else - { - Ylm::grad_rl_sph_harm(lmax2, gg.x, gg.y, gg.z, tmpylm.data(), tmpgylm.data()); - int lm = 0; - for(int il = 0 ; il <= lmax ; ++il) - { - for(int im = 0; im < 2*il+1; ++im, ++lm) - { - double rlylm = tmpylm[lm]; - ylm(lm,ig) = rlylm / pow(gmod,il); - dylmx(lm,ig) = ( tmpgylm[lm*3] - il*rlylm * gg.x / pow(gmod,2) )/pow(gmod,il); - dylmy(lm,ig) = ( tmpgylm[lm*3 + 1] - il*rlylm * gg.y / pow(gmod,2) )/pow(gmod,il); - dylmz(lm,ig) = ( tmpgylm[lm*3 + 2] - il*rlylm * gg.z / pow(gmod,2) )/pow(gmod,il); - } - } - - } - } - return; + for(int lm = 0 ; lm < lmax2 ; ++lm) + { + if(lm == 0) + ylm(lm,ig) = ModuleBase::SQRT_INVERSE_FOUR_PI; + else + ylm(lm,ig) = 0; + dylmx(lm,ig) = dylmy(lm,ig) = dylmz(lm,ig) = 0; + } + } + else + { + Ylm::grad_rl_sph_harm(lmax2, gg.x, gg.y, gg.z, tmpylm.data(), tmpgylm.data()); + int lm = 0; + for(int il = 0 ; il <= lmax ; ++il) + { + for(int im = 0; im < 2*il+1; ++im, ++lm) + { + double rlylm = tmpylm[lm]; + ylm(lm,ig) = rlylm / pow(gmod,il); + dylmx(lm,ig) = ( tmpgylm[lm*3] - il*rlylm * gg.x / pow(gmod,2) )/pow(gmod,il); + dylmy(lm,ig) = ( tmpgylm[lm*3 + 1] - il*rlylm * gg.y / pow(gmod,2) )/pow(gmod,il); + dylmz(lm,ig) = ( tmpgylm[lm*3 + 2] - il*rlylm * gg.z / pow(gmod,2) )/pow(gmod,il); + } + } + + } + } + return; } diff --git a/source/source_base/math_ylmreal.h b/source/source_base/math_ylmreal.h index 9643196a21e..b84dc911260 100644 --- a/source/source_base/math_ylmreal.h +++ b/source/source_base/math_ylmreal.h @@ -9,19 +9,19 @@ namespace ModuleBase class YlmReal { - public: + public: YlmReal(); ~YlmReal(); - /** - * @brief spherical harmonic function (real form) an array of vectors - * - * @param lmax2 [in] lmax2 = (lmax + 1)^2 ; lmax = angular quantum number - * @param ng [in] the number of vectors - * @param g [in] an array of vectors - * @param ylm [out] Ylm; column index represent vector, row index represent Y00, Y10, Y11, Y1-1, Y20,Y21,Y2-1,Y22.Y2-2,...; - */ + /** + * @brief spherical harmonic function (real form) an array of vectors + * + * @param lmax2 [in] lmax2 = (lmax + 1)^2 ; lmax = angular quantum number + * @param ng [in] the number of vectors + * @param g [in] an array of vectors + * @param ylm [out] Ylm; column index represent vector, row index represent Y00, Y10, Y11, Y1-1, Y20,Y21,Y2-1,Y22.Y2-2,...; + */ static void Ylm_Real ( const int lmax2, @@ -31,71 +31,71 @@ class YlmReal ); /** - * @brief spherical harmonic function (real form) an array - * - * @param lmax2 [in] lmax2 = (lmax + 1)^2 ; lmax = angular quantum number - * @param ng [in] the number of vectors - * @param g [in] an array of vectors - * @param ylm [out] Ylm; column index represent vector, row index represent Y00, Y10, Y11, Y1-1, Y20,Y21,Y2-1,Y22.Y2-2,...; - */ - template + * @brief spherical harmonic function (real form) an array + * + * @param lmax2 [in] lmax2 = (lmax + 1)^2 ; lmax = angular quantum number + * @param ng [in] the number of vectors + * @param g [in] an array of vectors + * @param ylm [out] Ylm; column index represent vector, row index represent Y00, Y10, Y11, Y1-1, Y20,Y21,Y2-1,Y22.Y2-2,...; + */ + template static void Ylm_Real(Device * ctx, const int lmax2, const int ng, const FPTYPE *g, FPTYPE * ylm); - /** - * @brief gradient of spherical harmonic function (real form) an array of vectors - * - * @param lmax2 [in] lmax2 = (lmax + 1)^2 ; lmax = angular quantum number - * @param ng [in] the number of vectors - * @param g [in] an array of vectors - * @param ylm [out] Ylm; column index represent vector, row index represent Y00, Y10, Y11, Y1-1, Y20,Y21,Y2-1,Y22.Y2-2,...; - * @param dylmx/dylmy/dylmz [out] \nabla Ylm; column index represent vector, row index represent dY00/dxyz, dY10/dxyz,...; - */ + /** + * @brief gradient of spherical harmonic function (real form) an array of vectors + * + * @param lmax2 [in] lmax2 = (lmax + 1)^2 ; lmax = angular quantum number + * @param ng [in] the number of vectors + * @param g [in] an array of vectors + * @param ylm [out] Ylm; column index represent vector, row index represent Y00, Y10, Y11, Y1-1, Y20,Y21,Y2-1,Y22.Y2-2,...; + * @param dylmx/dylmy/dylmz [out] \nabla Ylm; column index represent vector, row index represent dY00/dxyz, dY10/dxyz,...; + */ static void grad_Ylm_Real ( const int lmax2, const int ng, const ModuleBase::Vector3 *g, - matrix &ylm, + matrix &ylm, matrix &dylmx, - matrix &dylmy, - matrix &dylmz + matrix &dylmy, + matrix &dylmz + ); + + /** + * @brief spherical harmonic function (Herglotz generating form) of an array of vectors + * + * @param lmax2 [in] lmax2 = (lmax + 1)^2 ; lmax = angular quantum number + * @param ng [in] the number of vectors + * @param g [in] an array of vectors + * @param ylm [out] Ylm; column index represent vector, row index represent Y00, Y10, Y11, Y1-1, Y20,Y21,Y2-1,Y22.Y2-2,...; + */ + static void Ylm_Real2 + ( + const int lmax2, + const int ng, + const ModuleBase::Vector3 *g, + matrix &ylm ); - - /** - * @brief spherical harmonic function (Herglotz generating form) of an array of vectors - * - * @param lmax2 [in] lmax2 = (lmax + 1)^2 ; lmax = angular quantum number - * @param ng [in] the number of vectors - * @param g [in] an array of vectors - * @param ylm [out] Ylm; column index represent vector, row index represent Y00, Y10, Y11, Y1-1, Y20,Y21,Y2-1,Y22.Y2-2,...; - */ - static void Ylm_Real2 - ( - const int lmax2, - const int ng, - const ModuleBase::Vector3 *g, - matrix &ylm - ); - /** - * @brief spherical harmonic function (Herglotz generating form) of a vector - * - * @param lmax [in] maximum angular quantum number - * @param x [in] x part of the vector - * @param y [in] y part of the vector - * @param z [in] z part of the vector - * @param rly [in] Ylm, Y00, Y10, Y11, Y1-1, Y20,Y21,Y2-1,Y22.Y2-2,... - */ - static void rlylm - ( - const int lmax, - const double& x, - const double& y, - const double& z, - double* rly - ); + /** + * @brief spherical harmonic function (Herglotz generating form) of a vector + * + * @param lmax [in] maximum angular quantum number + * @param x [in] x part of the vector + * @param y [in] y part of the vector + * @param z [in] z part of the vector + * @param rly [in] Ylm, Y00, Y10, Y11, Y1-1, Y20,Y21,Y2-1,Y22.Y2-2,... + */ + static void rlylm + ( + const int lmax, + const double& x, + const double& y, + const double& z, + double* rly + ); - private: + private: static long double Fact(const int n); static int Semi_Fact(const int n); diff --git a/source/source_base/mathzone_add1.cpp b/source/source_base/mathzone_add1.cpp index 7f05961265e..67f1afff785 100644 --- a/source/source_base/mathzone_add1.cpp +++ b/source/source_base/mathzone_add1.cpp @@ -40,376 +40,376 @@ Mathzone_Add1::~Mathzone_Add1() double Mathzone_Add1::factorial (const int& l) { - if (l == 0 || l == 1) return 1.0; - else return l*factorial(l-1); + if (l == 0 || l == 1) return 1.0; + else return l*factorial(l-1); } double Mathzone_Add1::dualfac (const int& l) { - if (l == -1 || l == 0) return 1.0; - else return l * dualfac (l-2); + if (l == -1 || l == 0) return 1.0; + else return l * dualfac (l-2); } void Mathzone_Add1::SplineD2 // modified by pengfei 13-8-8 add second derivative as a condition ( - const double *rad, - const double *rad_f, - const int& mesh, - const double &yp1, // if yp1 > ypmax, consider the second derivative - const double &ypn, - double* y2 + const double *rad, + const double *rad_f, + const int& mesh, + const double &yp1, // if yp1 > ypmax, consider the second derivative + const double &ypn, + double* y2 ) { - ModuleBase::timer::start("Mathzone_Add1","SplineD2"); - - double dx1 = 0.0, dx2 = 0.0, dy1 = 0.0, dy2 = 0.0, p = 0.0, qn = 0.0, sig = 0.0, un = 0.0; - double * u = nullptr; - - u = new double[mesh-1]; - const double ypmax = 99999.00; - - if (yp1 > ypmax) - { - y2[0] = 0.0; - u[0] = 0.0; - } - else - { - y2[0] = -0.5; - - dx1 = rad[1] - rad[0]; - dy1 = rad_f[1] - rad_f[0]; - - u[0] = ( 3.0 / dx1 ) * (dy1 / dx1 - yp1); - } - - for(int i = 1; i < mesh-1 ; i++) - { - dx1 = rad[i] - rad[i-1]; - dx2 = rad[i+1] - rad[i-1]; - dy1 = rad_f[i+1] - rad_f[i]; - dy2 = rad_f[i] - rad_f[i-1]; - - sig = dx1 / dx2; - - p = sig * y2[i-1] + 2.0; - y2[i] = (sig - 1.0) / p; - - u[i] = dy1 / (dx2 - dx1) - dy2 / dx1; - u[i] = (6.0 * u[i] / dx2 - sig * u[i-1]) / p; - } - - if (ypn > ypmax) - { - qn = un = 0.0; - } - else - { - dx1 = rad[mesh-1] - rad[mesh-2]; - dy1 = rad_f[mesh-1] - rad_f[mesh-2]; - - qn = 0.5; - un = 3.0 / dx1 * (ypn - dy1 / dx1); - } - - y2[mesh-1] = (un - qn * u[mesh-2]) / (qn * y2[mesh-2] + 1.0); - - for(int i = mesh-2; i >= 0; i--) - { - y2[i] = y2[i] * y2[i+1] + u[i]; - } - - delete[] u; - - ModuleBase::timer::end("Mathzone_Add1","SplineD2"); + ModuleBase::timer::start("Mathzone_Add1","SplineD2"); + + double dx1 = 0.0, dx2 = 0.0, dy1 = 0.0, dy2 = 0.0, p = 0.0, qn = 0.0, sig = 0.0, un = 0.0; + double * u = nullptr; + + u = new double[mesh-1]; + const double ypmax = 99999.00; + + if (yp1 > ypmax) + { + y2[0] = 0.0; + u[0] = 0.0; + } + else + { + y2[0] = -0.5; + + dx1 = rad[1] - rad[0]; + dy1 = rad_f[1] - rad_f[0]; + + u[0] = ( 3.0 / dx1 ) * (dy1 / dx1 - yp1); + } + + for(int i = 1; i < mesh-1 ; i++) + { + dx1 = rad[i] - rad[i-1]; + dx2 = rad[i+1] - rad[i-1]; + dy1 = rad_f[i+1] - rad_f[i]; + dy2 = rad_f[i] - rad_f[i-1]; + + sig = dx1 / dx2; + + p = sig * y2[i-1] + 2.0; + y2[i] = (sig - 1.0) / p; + + u[i] = dy1 / (dx2 - dx1) - dy2 / dx1; + u[i] = (6.0 * u[i] / dx2 - sig * u[i-1]) / p; + } + + if (ypn > ypmax) + { + qn = un = 0.0; + } + else + { + dx1 = rad[mesh-1] - rad[mesh-2]; + dy1 = rad_f[mesh-1] - rad_f[mesh-2]; + + qn = 0.5; + un = 3.0 / dx1 * (ypn - dy1 / dx1); + } + + y2[mesh-1] = (un - qn * u[mesh-2]) / (qn * y2[mesh-2] + 1.0); + + for(int i = mesh-2; i >= 0; i--) + { + y2[i] = y2[i] * y2[i+1] + u[i]; + } + + delete[] u; + + ModuleBase::timer::end("Mathzone_Add1","SplineD2"); } // Peize Lin add openmp 2019-12-13 void Mathzone_Add1::Cubic_Spline_Interpolation ( - const double * const rad, - const double * const rad_f, - const double * const y2, - const int& mesh, - const double * const r, - const int& rsize, - double * const y, - double * const dy + const double * const rad, + const double * const rad_f, + const double * const y2, + const int& mesh, + const double * const r, + const int& rsize, + double * const y, + double * const dy ) { - ModuleBase::timer::start("Mathzone","cubic_spline"); + ModuleBase::timer::start("Mathzone","cubic_spline"); #ifdef _OPENMP - #pragma omp parallel for schedule(static) + #pragma omp parallel for schedule(static) #endif - for(int m = 0; m < rsize ; m++) - { - int klo = 0; - int khi = mesh-1; - while (khi - klo > 1) - { - const int k = (khi + klo) / 2 ; - if(rad[k] > r[m]) khi = k; - else klo = k; - } - - const double h = rad[khi] - rad[klo]; - if(h == 0.0) - { - std::cout << "Cubic_Spline_Interpolation, h == 0.0 so that cannot be divided" << std::endl; - //ModuleBase::WARNING_QUIT("Cubic_Spline_Interpolation","h == 0.0 so that cannot be divided"); - exit(0); - } - - const double a = (rad[khi] - r[m]) / h; - const double b = (r[m] - rad[klo]) / h; - - const double dy_tmp = (rad_f[khi] - rad_f[klo]) / h - - (3.0 * a * a - 1.0) / 6.0 * h * y2[klo] + - ( 3.0 * b * b - 1.0) / 6.0 * h * y2[khi]; - dy[m] = dy_tmp; - const double y_tmp = a * rad_f[klo] + b * rad_f[khi] + ((a*a*a - a) * y2[klo] + (b*b*b - b) * y2[khi]) * (h*h) / 6.0; - y[m] = y_tmp; - //const double ddy_tmp = a * y2[klo] + b * y2 [khi]; - //ddy[m] = ddy_tmp; - } - - ModuleBase::timer::end("Mathzone","cubic_spline"); + for(int m = 0; m < rsize ; m++) + { + int klo = 0; + int khi = mesh-1; + while (khi - klo > 1) + { + const int k = (khi + klo) / 2 ; + if(rad[k] > r[m]) khi = k; + else klo = k; + } + + const double h = rad[khi] - rad[klo]; + if(h == 0.0) + { + std::cout << "Cubic_Spline_Interpolation, h == 0.0 so that cannot be divided" << std::endl; + //ModuleBase::WARNING_QUIT("Cubic_Spline_Interpolation","h == 0.0 so that cannot be divided"); + exit(0); + } + + const double a = (rad[khi] - r[m]) / h; + const double b = (r[m] - rad[klo]) / h; + + const double dy_tmp = (rad_f[khi] - rad_f[klo]) / h - + (3.0 * a * a - 1.0) / 6.0 * h * y2[klo] + + ( 3.0 * b * b - 1.0) / 6.0 * h * y2[khi]; + dy[m] = dy_tmp; + const double y_tmp = a * rad_f[klo] + b * rad_f[khi] + ((a*a*a - a) * y2[klo] + (b*b*b - b) * y2[khi]) * (h*h) / 6.0; + y[m] = y_tmp; + //const double ddy_tmp = a * y2[klo] + b * y2 [khi]; + //ddy[m] = ddy_tmp; + } + + ModuleBase::timer::end("Mathzone","cubic_spline"); } /// Interpolation for Numerical Orbitals double Mathzone_Add1::Uni_RadialF ( - const double* old_phi, - const int& msh, - const double& dr, - const double& newr + const double* old_phi, + const int& msh, + const double& dr, + const double& newr ) { - double h1 = 0.0, h2 = 0.0, h3 = 0.0, f1 = 0.0, f2 = 0.0, f3 = 0.0, f4 = 0.0; - double g1 = 0.0, g2 = 0.0, x1 = 0.0, x2 = 0.0, y1 = 0.0, y2 = 0.0, f = 0.0; - double result = 0.0; - double rmax = (msh-1) * dr; - - if (newr < 0.0) - { - throw std::runtime_error("newr should >= 0. "+std::string(__FILE__)+" line "+std::to_string(__LINE__)); - - } - else if ( rmax <= newr ) - { - f = 0.0; - } - else - { - // the old position. - const int m = static_cast (newr / dr) + 1; + double h1 = 0.0, h2 = 0.0, h3 = 0.0, f1 = 0.0, f2 = 0.0, f3 = 0.0, f4 = 0.0; + double g1 = 0.0, g2 = 0.0, x1 = 0.0, x2 = 0.0, y1 = 0.0, y2 = 0.0, f = 0.0; + double result = 0.0; + double rmax = (msh-1) * dr; + + if (newr < 0.0) + { + throw std::runtime_error("newr should >= 0. "+std::string(__FILE__)+" line "+std::to_string(__LINE__)); + + } + else if ( rmax <= newr ) + { + f = 0.0; + } + else + { + // the old position. + const int m = static_cast (newr / dr) + 1; // Spline like interpolation - if (m == 1) - { - h2 = dr; - h3 = dr; - - f2 = old_phi[m-1]; - f3 = old_phi[m]; - f4 = old_phi[m+1]; - - h1 = -(h2+h3); - f1 = f4; - } - else if (m == (msh-1)) - { - h1 = dr; - h2 = dr; - - f1 = old_phi[m-2]; - f2 = old_phi[m-1]; - f3 = old_phi[m]; - - h3 = -(h1+h2); - f4 = f1; - } - else - { - h1 = dr; - h2 = dr; - h3 = dr; - - f1 = old_phi[m-2]; - f2 = old_phi[m-1]; - f3 = old_phi[m]; - f4 = old_phi[m+1]; - } + if (m == 1) + { + h2 = dr; + h3 = dr; + + f2 = old_phi[m-1]; + f3 = old_phi[m]; + f4 = old_phi[m+1]; + + h1 = -(h2+h3); + f1 = f4; + } + else if (m == (msh-1)) + { + h1 = dr; + h2 = dr; + + f1 = old_phi[m-2]; + f2 = old_phi[m-1]; + f3 = old_phi[m]; + + h3 = -(h1+h2); + f4 = f1; + } + else + { + h1 = dr; + h2 = dr; + h3 = dr; + + f1 = old_phi[m-2]; + f2 = old_phi[m-1]; + f3 = old_phi[m]; + f4 = old_phi[m+1]; + } // Calculate the value at newr - g1 = ((f3-f2)*h1/h2 + (f2-f1)*h2/h1)/(h1+h2); - g2 = ((f4-f3)*h2/h3 + (f3-f2)*h3/h2)/(h2+h3); + g1 = ((f3-f2)*h1/h2 + (f2-f1)*h2/h1)/(h1+h2); + g2 = ((f4-f3)*h2/h3 + (f3-f2)*h3/h2)/(h2+h3); - x1 = newr - (m-1)*dr; - x2 = newr - m*dr; - y1 = x1/h2; - y2 = x2/h2; + x1 = newr - (m-1)*dr; + x2 = newr - m*dr; + y1 = x1/h2; + y2 = x2/h2; - f = y2*y2*(3.0*f2 + h2*g1 + (2.0*f2 + h2*g1)*y2) - + y1*y1*(3.0*f3 - h2*g2 - (2.0*f3 - h2*g2)*y1); - } - result = f; + f = y2*y2*(3.0*f2 + h2*g1 + (2.0*f2 + h2*g1)*y2) + + y1*y1*(3.0*f3 - h2*g2 - (2.0*f3 - h2*g2)*y1); + } + result = f; - return result; + return result; } void Mathzone_Add1::Uni_Deriv_Phi ( - const double *radf, - const int &mesh, - const double &dr, - const int &nd, - double *phind + const double *radf, + const int &mesh, + const double &dr, + const int &nd, + double *phind ) { - ModuleBase::timer::start("Mathzone_Add1", "Uni_Deriv_Phi"); - int FFT_NR = 2*mesh-1; // FFT_NR = 16019 - // std::cout << "\n mesh=" << mesh << ", radf[8010]=" << radf[8010] << ", radf[8009]=" << radf[8009] ; - // mesh=8010, radf[8010]=4.396478951532926e-01, radf[8009]=0.000000000000000e+00 + ModuleBase::timer::start("Mathzone_Add1", "Uni_Deriv_Phi"); + int FFT_NR = 2*mesh-1; // FFT_NR = 16019 + // std::cout << "\n mesh=" << mesh << ", radf[8010]=" << radf[8010] << ", radf[8009]=" << radf[8009] ; + // mesh=8010, radf[8010]=4.396478951532926e-01, radf[8009]=0.000000000000000e+00 fftw_complex *fft_phir = new fftw_complex[FFT_NR]; fftw_complex *fft_phik = new fftw_complex[FFT_NR]; fftw_complex *fft_ndphik = new fftw_complex[FFT_NR]; fftw_complex *fft_ndphir = new fftw_complex[FFT_NR]; - fftw_plan p1; - fftw_plan p2; - - ////CAREFUL: POINT 0 is OF GOOD IMPORTANCE - //for (int ir = 0; ir < FFT_NR/2; ++ir) - //{ - //fft_phir[ir].re = radf[ir]; - //fft_phir[ir].im = 0.0; - //} - - //for (int ir = FFT_NR/2; ir < FFT_NR; ++ir) - //{ - //int jr = FFT_NR - ir; - //fft_phir[ir].re = radf[jr]; - //fft_phir[ir].im = 0.0; - //} - // - // second call: different value at [8010]; FFT_NR = 16019, FFT_NR/2=8009 :: - // CAREFUL: POINT 0 is OF GOOD IMPORTANCE - for (int ir = 0; ir < FFT_NR/2; ++ir) // ik = 0 1 ... 8008 - { - c_re(fft_phir[ir]) = radf[ir]; - c_im(fft_phir[ir]) = 0.0; - } - - for (int ir = FFT_NR/2; ir < FFT_NR; ++ir) // ir = 8009 8010 ... 16018 - { - //int jr = FFT_NR - ir ; // jr = 8010 8009 ... 1 - int jr = FFT_NR - ir -1 ; // -> 8009 8008 ... 0 - c_re(fft_phir[ir]) = radf[jr]; - c_im(fft_phir[ir]) = 0.0; - } - - // FFTW + fftw_plan p1; + fftw_plan p2; + + ////CAREFUL: POINT 0 is OF GOOD IMPORTANCE + //for (int ir = 0; ir < FFT_NR/2; ++ir) + //{ + //fft_phir[ir].re = radf[ir]; + //fft_phir[ir].im = 0.0; + //} + + //for (int ir = FFT_NR/2; ir < FFT_NR; ++ir) + //{ + //int jr = FFT_NR - ir; + //fft_phir[ir].re = radf[jr]; + //fft_phir[ir].im = 0.0; + //} + // + // second call: different value at [8010]; FFT_NR = 16019, FFT_NR/2=8009 :: + // CAREFUL: POINT 0 is OF GOOD IMPORTANCE + for (int ir = 0; ir < FFT_NR/2; ++ir) // ik = 0 1 ... 8008 + { + c_re(fft_phir[ir]) = radf[ir]; + c_im(fft_phir[ir]) = 0.0; + } + + for (int ir = FFT_NR/2; ir < FFT_NR; ++ir) // ir = 8009 8010 ... 16018 + { + //int jr = FFT_NR - ir ; // jr = 8010 8009 ... 1 + int jr = FFT_NR - ir -1 ; // -> 8009 8008 ... 0 + c_re(fft_phir[ir]) = radf[jr]; + c_im(fft_phir[ir]) = 0.0; + } + + // FFTW #if defined __FFTW3 - //std::cout << "\n Call FFTW3 "; - p1 = fftw_plan_dft_1d(FFT_NR, fft_phir, fft_phik, FFTW_FORWARD, FFTW_ESTIMATE); - fftw_execute(p1); - //fftw_destroy_plan(p1); + //std::cout << "\n Call FFTW3 "; + p1 = fftw_plan_dft_1d(FFT_NR, fft_phir, fft_phik, FFTW_FORWARD, FFTW_ESTIMATE); + fftw_execute(p1); + //fftw_destroy_plan(p1); #elif defined __FFTW2 - //std::cout << "\n Call FFTW2 "; - p1 = fftw_create_plan(FFT_NR, FFTW_FORWARD, FFTW_ESTIMATE); - fftw_one(p1, fft_phir, fft_phik); - //fftw_destroy_plan(p1); + //std::cout << "\n Call FFTW2 "; + p1 = fftw_create_plan(FFT_NR, FFTW_FORWARD, FFTW_ESTIMATE); + fftw_one(p1, fft_phir, fft_phik); + //fftw_destroy_plan(p1); #endif - - double dk_uniform = ModuleBase::TWO_PI / FFT_NR / dr; - - //for (int ik = 0; ik < FFT_NR/2; ik++) - //{ - //double kp = ik * dk_uniform; - //fft_ndphik[ik].re = pow(kp, nd) * fft_phik[ik].re; - //fft_ndphik[ik].im = 0.0; - //} - - //for (int ik = FFT_NR/2; ik < FFT_NR; ik++) - //{ - //double kp = -(FFT_NR - ik)* dk_uniform; - //fft_ndphik[ik].re = pow(kp, nd) * fft_phik[ik].re; - //fft_ndphik[ik].im = 0.0; - //} - - for (int ik = 0; ik < FFT_NR/2; ik++) // ik = 0 1 ... 8008 - { - double kp = ik * dk_uniform; - c_re(fft_ndphik[ik]) = pow(kp, nd) * c_re(fft_phik[ik]); - c_im(fft_ndphik[ik]) = 0.0; - } - for (int ik = FFT_NR/2; ik < FFT_NR; ik++) // ik = 8009 8010 ... 16018 - { - //double kp = -(FFT_NR - ik )* dk_uniform; //(...) = 8010 8009 ... 1 - double kp = -(FFT_NR - ik -1)* dk_uniform; //(...) -> 8009 8008 ... 0 - c_re(fft_ndphik[ik]) = pow(kp, nd) * c_re(fft_phik[ik]); - c_im(fft_ndphik[ik]) = 0.0; - } + + double dk_uniform = ModuleBase::TWO_PI / FFT_NR / dr; + + //for (int ik = 0; ik < FFT_NR/2; ik++) + //{ + //double kp = ik * dk_uniform; + //fft_ndphik[ik].re = pow(kp, nd) * fft_phik[ik].re; + //fft_ndphik[ik].im = 0.0; + //} + + //for (int ik = FFT_NR/2; ik < FFT_NR; ik++) + //{ + //double kp = -(FFT_NR - ik)* dk_uniform; + //fft_ndphik[ik].re = pow(kp, nd) * fft_phik[ik].re; + //fft_ndphik[ik].im = 0.0; + //} + + for (int ik = 0; ik < FFT_NR/2; ik++) // ik = 0 1 ... 8008 + { + double kp = ik * dk_uniform; + c_re(fft_ndphik[ik]) = pow(kp, nd) * c_re(fft_phik[ik]); + c_im(fft_ndphik[ik]) = 0.0; + } + for (int ik = FFT_NR/2; ik < FFT_NR; ik++) // ik = 8009 8010 ... 16018 + { + //double kp = -(FFT_NR - ik )* dk_uniform; //(...) = 8010 8009 ... 1 + double kp = -(FFT_NR - ik -1)* dk_uniform; //(...) -> 8009 8008 ... 0 + c_re(fft_ndphik[ik]) = pow(kp, nd) * c_re(fft_phik[ik]); + c_im(fft_ndphik[ik]) = 0.0; + } #if defined __FFTW3 - p2 = fftw_plan_dft_1d(FFT_NR, fft_ndphik, fft_ndphir, FFTW_BACKWARD, FFTW_ESTIMATE); - fftw_execute(p2); - //fftw_destroy_plan(p2); + p2 = fftw_plan_dft_1d(FFT_NR, fft_ndphik, fft_ndphir, FFTW_BACKWARD, FFTW_ESTIMATE); + fftw_execute(p2); + //fftw_destroy_plan(p2); #elif defined __FFTW2 - p2 = fftw_create_plan(FFT_NR, FFTW_BACKWARD, FFTW_ESTIMATE); - fftw_one(p2, fft_ndphik, fft_ndphir); - //fftw_destroy_plan(p2); + p2 = fftw_create_plan(FFT_NR, FFTW_BACKWARD, FFTW_ESTIMATE); + fftw_one(p2, fft_ndphik, fft_ndphir); + //fftw_destroy_plan(p2); #endif - bool is_re = true; - double fac = 0.0; - if (nd % 4 == 0) - { - is_re = true; - fac = 1.0; - } - else if (nd % 4 == 1) - { - is_re = false; - fac = -1.0; - } - else if (nd % 4 == 2) - { - is_re = true; - fac = -1.0; - } - else - { - is_re = false; - fac = 1.0; - } - - for (int ir = 0; ir < mesh; ir++) - { - if (is_re) - { - phind[ir] = fac * c_re(fft_ndphir[ir]) / FFT_NR; - } - else - { - phind[ir] = fac * c_im(fft_ndphir[ir]) / FFT_NR; - } - } - - fftw_destroy_plan (p1); - fftw_destroy_plan (p2); + bool is_re = true; + double fac = 0.0; + if (nd % 4 == 0) + { + is_re = true; + fac = 1.0; + } + else if (nd % 4 == 1) + { + is_re = false; + fac = -1.0; + } + else if (nd % 4 == 2) + { + is_re = true; + fac = -1.0; + } + else + { + is_re = false; + fac = 1.0; + } + + for (int ir = 0; ir < mesh; ir++) + { + if (is_re) + { + phind[ir] = fac * c_re(fft_ndphir[ir]) / FFT_NR; + } + else + { + phind[ir] = fac * c_im(fft_ndphir[ir]) / FFT_NR; + } + } + + fftw_destroy_plan (p1); + fftw_destroy_plan (p2); delete [] fft_phir; delete [] fft_phik; delete [] fft_ndphik; delete [] fft_ndphir; - - ModuleBase::timer::end("Mathzone_Add1", "Uni_Deriv_Phi"); + + ModuleBase::timer::end("Mathzone_Add1", "Uni_Deriv_Phi"); } } diff --git a/source/source_base/matrix.cpp b/source/source_base/matrix.cpp index eaa7c304061..fb036438ce5 100644 --- a/source/source_base/matrix.cpp +++ b/source/source_base/matrix.cpp @@ -34,73 +34,73 @@ void matrixAlloc() /*create a matrix with nrows*ncols size */ matrix::matrix( const int nrows, const int ncols, const bool flag_zero ) - :nr(nrows), - nc(ncols), - c(nullptr) + :nr(nrows), + nc(ncols), + c(nullptr) { - if( nr && nc ) - { - auto handler_old = std::set_new_handler(matrixAlloc); - c = new double[nr*nc]; - std::set_new_handler(handler_old); - if(flag_zero) this->zero_out(); - } + if( nr && nc ) + { + auto handler_old = std::set_new_handler(matrixAlloc); + c = new double[nr*nc]; + std::set_new_handler(handler_old); + if(flag_zero) this->zero_out(); + } } matrix::matrix( const matrix &m_in ) - :nr(m_in.nr), - nc(m_in.nc), - c(nullptr) + :nr(m_in.nr), + nc(m_in.nc), + c(nullptr) { - if( nr && nc ) - { - auto handler_old = std::set_new_handler(matrixAlloc); - c = new double[nr*nc]; - std::set_new_handler(handler_old); - memcpy( c, m_in.c, nr*nc*sizeof(double) ); - } + if( nr && nc ) + { + auto handler_old = std::set_new_handler(matrixAlloc); + c = new double[nr*nc]; + std::set_new_handler(handler_old); + memcpy( c, m_in.c, nr*nc*sizeof(double) ); + } } // Peize Lin add 2016-08-05 matrix::matrix( matrix && m_in ) - :nr(m_in.nr), - nc(m_in.nc) + :nr(m_in.nr), + nc(m_in.nc) { - c = m_in.c; - m_in.nr = m_in.nc = 0; - m_in.c = nullptr; + c = m_in.c; + m_in.nr = m_in.nc = 0; + m_in.c = nullptr; } // Peize Lin change 2018-07-02 matrix& matrix::operator=( const matrix & m_in ) { - this->create( m_in.nr, m_in.nc, false ); - memcpy( c, m_in.c, nr*nc*sizeof(double) ); - return *this; + this->create( m_in.nr, m_in.nc, false ); + memcpy( c, m_in.c, nr*nc*sizeof(double) ); + return *this; } // Peize Lin add 2016-08-05 matrix& matrix::operator=( matrix && m_in ) { - nr = m_in.nr; nc = m_in.nc; - if(c) delete[] c; - c = m_in.c; - m_in.nr = m_in.nc = 0; - m_in.c = nullptr; - return *this; + nr = m_in.nr; nc = m_in.nc; + if(c) delete[] c; + c = m_in.c; + m_in.nr = m_in.nc = 0; + m_in.c = nullptr; + return *this; } /* double & matrix::operator()(const int ir,const int ic) { - assert(ir>=0); assert(ir=0); assert(ic=0); assert(ir=0); assert(ic=0); assert(ir=0); assert(ic=0); assert(ir=0); assert(ic zero_out(); + if(flag_zero) this-> zero_out(); } double trace_on(const matrix &A, const matrix &B) { - assert(A.nr == B.nc); - assert(A.nc == B.nr); + assert(A.nr == B.nc); + assert(A.nc == B.nr); double tr = 0.0; for (int i = 0; i < A.nr; ++i) @@ -376,18 +376,18 @@ double mdot(const matrix &A, const matrix &B) // Peize Lin add 2016-09-08 std::ostream & operator<<( std::ostream & os, const matrix & m ) { - for( int ir=0; ir!=m.nr; ++ir ) - { - for( int ic=0; ic!=m.nc; ++ic ) - { - if(std::abs(m(ir,ic))>1E-10) - os<1E-10) + os<nr; ++ir ) - { - for( int ic=0; ic!=this->nc; ++ic ) - { - if(std::abs((*this)(ir,ic))>threshold) - os<<(*this)(ir,ic)<<"\t"; - else - os<<0<<"\t"; - } - os<nr; ++ir ) + { + for( int ic=0; ic!=this->nc; ++ic ) + { + if(std::abs((*this)(ir,ic))>threshold) + os<<(*this)(ir,ic)<<"\t"; + else + os<<0<<"\t"; + } + os<::min(); - const int size = nr * nc; - for( int i=0; i::min(); + const int size = nr * nc; + for( int i=0; i::max(); - const int size = nr * nc; - for( int i=0; i::max(); + const int size = nr * nc; + for( int i=0; i=0); assert(ir=0); assert(ic=0); assert(ir=0); assert(ic=0); assert(ir=0); assert(ic=0); assert(ir=0); assert(iczero_out(); - } + if(flag_zero) this->zero_out(); + } } inline matrix::matrix( const matrix &m_in ) { std::cout<<__FILE__<<__LINE__<create( m_in.nr, m_in.nc, false ); + this->create( m_in.nr, m_in.nc, false ); std::cout<<__FILE__<<__LINE__<=0); assert(ir=0); assert(ic=0); assert(ir=0); assert(ic=0); assert(ir=0); assert(ic=0); assert(ir=0); assert(ic #ifdef WIN32 - #define __FUNCTION__ __FILE__ + #define __FUNCTION__ __FILE__ #endif #ifndef MCD_QUIET - #ifndef WIN32 - #warning - Building with memory checking. - #warning expect lower performance. - - #endif + #ifndef WIN32 + #warning - Building with memory checking. + #warning expect lower performance. - + #endif #endif //warn about redefinitions (sometimes these can be #defined) #ifdef malloc #undef malloc - #ifndef WIN32 - #warning ------ Redefining malloc() ------ - #endif + #ifndef WIN32 + #warning ------ Redefining malloc() ------ + #endif #endif #ifdef calloc #undef calloc - #ifndef WIN32 - #warning ------ Redefining calloc() ------ - #endif + #ifndef WIN32 + #warning ------ Redefining calloc() ------ + #endif #endif #ifdef realloc #undef realloc - #ifndef WIN32 - #warning ------ Redefining realloc() ------ - #endif + #ifndef WIN32 + #warning ------ Redefining realloc() ------ + #endif #endif #ifdef free #undef free - #ifndef WIN32 - #warning ------ Redefining free() ------ - #endif + #ifndef WIN32 + #warning ------ Redefining free() ------ + #endif #endif #ifdef strdup #undef strdup - #ifndef WIN32 - #warning ------- Redefining strdup() -------- - #endif + #ifndef WIN32 + #warning ------- Redefining strdup() -------- + #endif #endif #ifdef strndup #undef strndup - #ifndef WIN32 - #warning ------- Redefining strndup() ------- - #endif + #ifndef WIN32 + #warning ------- Redefining strndup() ------- + #endif #endif #ifdef asprintf #undef asprintf - #ifndef WIN32 - #warning ------ Redefining asprintf() ------ - #endif + #ifndef WIN32 + #warning ------ Redefining asprintf() ------ + #endif #endif #ifdef vasprintf #undef vasprintf - #ifndef WIN32 - #warning ------ Redefining vasprintf() ------ - #endif + #ifndef WIN32 + #warning ------ Redefining vasprintf() ------ + #endif #endif #ifdef scanf #undef scanf - #ifndef WIN32 - #warning ------ Redefining scanf() ------ - #endif + #ifndef WIN32 + #warning ------ Redefining scanf() ------ + #endif #endif #ifdef fscanf #undef fscanf - #ifndef WIN32 - #warning ------ Redefining fscanf() ------ - #endif + #ifndef WIN32 + #warning ------ Redefining fscanf() ------ + #endif #endif #ifdef sscanf #undef sscanf - #ifndef WIN32 - #warning ------ Redefining sscanf() ------ - #endif + #ifndef WIN32 + #warning ------ Redefining sscanf() ------ + #endif #endif #ifdef getcwd #undef getcwd - #ifndef WIN32 - #warning ------ Redefining getcwd() ------ - #endif + #ifndef WIN32 + #warning ------ Redefining getcwd() ------ + #endif #endif #define strdup(p) MCD_strdup(p,__FUNCTION__,__FILE__,__LINE__) @@ -180,11 +180,11 @@ void MCD_free(void *p,char*,char*,int); void showMemStats(void); /* --- to send realtime stats somewhere other than stderr, - put an opened fp in here --- */ + put an opened fp in here --- */ void _MCD_RealTimeLog(FILE*); /* --- to send showMemStats() somewhere other than stdout, - put an opened fp in here --- */ + put an opened fp in here --- */ void _MCD_MemStatLog(FILE*); #else //MCD is gone @@ -204,15 +204,15 @@ void _MCD_MemStatLog(FILE*); #ifdef __cplusplus /* Some C++ new/delete operator overloading */ #ifndef WIN32 - #warning C++ Extentions Enabled + #warning C++ Extentions Enabled #endif #ifdef new - #undef new + #undef new #endif #ifdef delete - #undef delete + #undef delete #endif extern char *_MCD_LastSetFile,*_MCD_LastSetFun; @@ -220,21 +220,21 @@ extern int _MCD_LastSetLine; inline void setFileFunLineState(char*file,char*fun,int line) { - _MCD_LastSetLine=line; - _MCD_LastSetFile=file; - _MCD_LastSetFun=fun; + _MCD_LastSetLine=line; + _MCD_LastSetFile=file; + _MCD_LastSetFun=fun; } inline void* operator new (unsigned int size,char *file, char*fun,int line) { - return MCD_malloc(size,file,fun,line); + return MCD_malloc(size,file,fun,line); } inline void* operator new[] (unsigned int size,char*file, char*fun,int line) { - return MCD_malloc(size,file,fun,line); + return MCD_malloc(size,file,fun,line); } // currently, passing args to delete operator is not working at all... @@ -246,7 +246,7 @@ char*fun=__FILE__,int line=__LINE__) char*fun=__FUNCTION__,int line=__LINE__) #endif { - MCD_free(buf,_MCD_LastSetFile,_MCD_LastSetFun,_MCD_LastSetLine); + MCD_free(buf,_MCD_LastSetFile,_MCD_LastSetFun,_MCD_LastSetLine); } // ...so we have these here for the day they work, which isn't today. inline void operator delete[] (void * buf,char*file=__FILE__, @@ -256,18 +256,18 @@ char*fun=__FILE__,int line=__LINE__) char*fun=__FUNCTION__,int line=__LINE__) #endif { - MCD_free(buf,_MCD_LastSetFile,_MCD_LastSetFun,_MCD_LastSetLine); + MCD_free(buf,_MCD_LastSetFile,_MCD_LastSetFun,_MCD_LastSetLine); } #endif // win32 default delete params inline void operator delete (void * buf) { - MCD_free(buf,0,0,0); + MCD_free(buf,0,0,0); } inline void operator delete[] (void * buf) { - MCD_free(buf,0,0,0); + MCD_free(buf,0,0,0); } #ifdef WIN32 diff --git a/source/source_base/memory_recorder.cpp b/source/source_base/memory_recorder.cpp index f122a6156a3..773063db816 100644 --- a/source/source_base/memory_recorder.cpp +++ b/source/source_base/memory_recorder.cpp @@ -51,451 +51,451 @@ Memory::~Memory() double Memory::calculate_mem(const long &n_in,const std::string &type) { - double n = static_cast(n_in); - double mem = 0.0; - - double factor = 1.0/1024.0/1024.0; - double complex_matrix_mem = complex_matrix_memory * factor; - double double_mem = double_memory * factor; - double int_mem = int_memory * factor; - double bool_mem = bool_memory * factor; - double float_mem = float_memory * factor; - double short_mem = short_memory * factor; - - if(type=="ModuleBase::ComplexMatrix" || type=="complexmatrix" || type=="cdouble") - { - mem = complex_matrix_mem; - } - else if(type=="real" || type=="double") - { - mem = double_mem; - } - else if(type=="int") - { - mem = int_mem; - } - else if(type=="bool") - { - mem = bool_mem; - } - else if(type=="short") - { - mem = short_mem; - } - else if(type=="float") - { - mem = float_mem; - } - else if(type=="AtomLink") - { - mem = int_mem * 2 + double_mem * 3; - } - else if(type=="ModuleBase::Vector3") - { - mem = 3 * double_mem; - } - else - { - std::cout<<"not this type in memory storage : "<(n_in); + double mem = 0.0; + + double factor = 1.0/1024.0/1024.0; + double complex_matrix_mem = complex_matrix_memory * factor; + double double_mem = double_memory * factor; + double int_mem = int_memory * factor; + double bool_mem = bool_memory * factor; + double float_mem = float_memory * factor; + double short_mem = short_memory * factor; + + if(type=="ModuleBase::ComplexMatrix" || type=="complexmatrix" || type=="cdouble") + { + mem = complex_matrix_mem; + } + else if(type=="real" || type=="double") + { + mem = double_mem; + } + else if(type=="int") + { + mem = int_mem; + } + else if(type=="bool") + { + mem = bool_mem; + } + else if(type=="short") + { + mem = short_mem; + } + else if(type=="float") + { + mem = float_mem; + } + else if(type=="AtomLink") + { + mem = int_mem * 2 + double_mem * 3; + } + else if(type=="ModuleBase::Vector3") + { + mem = 3 * double_mem; + } + else + { + std::cout<<"not this type in memory storage : "<= n_memory) - { - std::cout<<" Error! Too many memories required."; - return 0.0; - } - - consume[find] = Memory::calculate_mem(n_in,type); - - if(consume[find] > memory_warning_threshold_mb) - { - print(name[find], consume[find]); - } - return consume[find]; + if(!Memory::init_flag) + { + name = new std::string[n_memory]; + class_name = new std::string[n_memory]; + consume = new double[n_memory]; + for(int i=0;i= n_memory) + { + std::cout<<" Error! Too many memories required."; + return 0.0; + } + + consume[find] = Memory::calculate_mem(n_in,type); + + if(consume[find] > memory_warning_threshold_mb) + { + print(name[find], consume[find]); + } + return consume[find]; } void Memory::record ( - const std::string &name_in, - const long &n_in, - const bool accumulate + const std::string &name_in, + const long &n_in, + const bool accumulate ) { - if(!Memory::init_flag) - { - name = new std::string[n_memory]; - class_name = new std::string[n_memory]; - consume = new double[n_memory]; - for(int i=0;i= n_memory) - { - std::cout<<" Error! Too many memories has been recorded."; - return; - } - - const double factor = 1.0/1024.0/1024.0; - double size_mb = n_in * factor; - - if(accumulate) - { - consume[find] += size_mb; - Memory::total += size_mb; - } - else - { - if(consume[find] < size_mb) - { - Memory::total += size_mb - consume[find]; - consume[find] = size_mb; - if(consume[find] > memory_warning_threshold_mb) - { - print(name[find], consume[find]); - } - } - } - - return; + if(!Memory::init_flag) + { + name = new std::string[n_memory]; + class_name = new std::string[n_memory]; + consume = new double[n_memory]; + for(int i=0;i= n_memory) + { + std::cout<<" Error! Too many memories has been recorded."; + return; + } + + const double factor = 1.0/1024.0/1024.0; + double size_mb = n_in * factor; + + if(accumulate) + { + consume[find] += size_mb; + Memory::total += size_mb; + } + else + { + if(consume[find] < size_mb) + { + Memory::total += size_mb - consume[find]; + consume[find] = size_mb; + if(consume[find] > memory_warning_threshold_mb) + { + print(name[find], consume[find]); + } + } + } + + return; } #if defined(__CUDA) || defined(__ROCM) double Memory::record_gpu ( - const std::string &class_name_in, - const std::string &name_in, - const long &n_in, - const std::string &type, - const bool accumulate + const std::string &class_name_in, + const std::string &name_in, + const long &n_in, + const std::string &type, + const bool accumulate ) { - if(!Memory::init_flag_gpu) - { - name_gpu = new std::string[n_memory]; - class_name_gpu = new std::string[n_memory]; - consume_gpu = new double[n_memory]; - for(int i=0;i= n_memory) - { - std::cout<<" Error! Too many gpu memories required."; - return 0.0; - } - - consume_gpu[find] = Memory::calculate_mem(n_in,type); - - if(consume_gpu[find] > memory_warning_threshold_mb) - { - print(name_gpu[find], consume_gpu[find]); - } - return consume_gpu[find]; + if(!Memory::init_flag_gpu) + { + name_gpu = new std::string[n_memory]; + class_name_gpu = new std::string[n_memory]; + consume_gpu = new double[n_memory]; + for(int i=0;i= n_memory) + { + std::cout<<" Error! Too many gpu memories required."; + return 0.0; + } + + consume_gpu[find] = Memory::calculate_mem(n_in,type); + + if(consume_gpu[find] > memory_warning_threshold_mb) + { + print(name_gpu[find], consume_gpu[find]); + } + return consume_gpu[find]; } void Memory::record_gpu ( - const std::string &name_in, - const size_t &n_in, - const bool accumulate + const std::string &name_in, + const size_t &n_in, + const bool accumulate ) { - if(!Memory::init_flag_gpu) - { - name_gpu = new std::string[n_memory]; - class_name_gpu = new std::string[n_memory]; - consume_gpu = new double[n_memory]; - for(int i=0;i= n_memory) - { - std::cout<<" Error! Too many gpu memories has been recorded."; - return; - } - - const double factor = 1.0/1024.0/1024.0; - double size_mb = n_in * factor; - - if(accumulate) - { - consume_gpu[find] += size_mb; - Memory::total_gpu += size_mb; - } - else - { - if(consume_gpu[find] < size_mb) - { - Memory::total_gpu += size_mb - consume_gpu[find]; - consume_gpu[find] = size_mb; - if(consume_gpu[find] > memory_warning_threshold_mb) - { - print(name_gpu[find], consume_gpu[find]); - } - } - } - return; + if(!Memory::init_flag_gpu) + { + name_gpu = new std::string[n_memory]; + class_name_gpu = new std::string[n_memory]; + consume_gpu = new double[n_memory]; + for(int i=0;i= n_memory) + { + std::cout<<" Error! Too many gpu memories has been recorded."; + return; + } + + const double factor = 1.0/1024.0/1024.0; + double size_mb = n_in * factor; + + if(accumulate) + { + consume_gpu[find] += size_mb; + Memory::total_gpu += size_mb; + } + else + { + if(consume_gpu[find] < size_mb) + { + Memory::total_gpu += size_mb - consume_gpu[find]; + consume_gpu[find] = size_mb; + if(consume_gpu[find] > memory_warning_threshold_mb) + { + print(name_gpu[find], consume_gpu[find]); + } + } + } + return; } #endif void Memory::print(const std::string& mem_name, double size_mb) { - GlobalV::ofs_running <<"\n *** Memory Allocation Warning *** " - <<" "<< mem_name <<" "<< size_mb <<" MB" << std::endl; - return; + GlobalV::ofs_running <<"\n *** Memory Allocation Warning *** " + <<" "<< mem_name <<" "<< size_mb <<" MB" << std::endl; + return; } void Memory::finish(std::ofstream &ofs) { - print_all(ofs); - if(init_flag) - { - delete[] name; - delete[] class_name; - delete[] consume; - init_flag = false; - } + print_all(ofs); + if(init_flag) + { + delete[] name; + delete[] class_name; + delete[] consume; + init_flag = false; + } #if defined(__CUDA) || defined(__ROCM) - if(init_flag_gpu) - { - delete[] name_gpu; - delete[] class_name_gpu; - delete[] consume_gpu; - init_flag_gpu = false; - } + if(init_flag_gpu) + { + delete[] name_gpu; + delete[] class_name_gpu; + delete[] consume_gpu; + init_flag_gpu = false; + } #endif - return; + return; } void Memory::print_all(std::ofstream &ofs) { - if(!init_flag) - { - return; - } + if(!init_flag) + { + return; + } - const double small = 1.0; // unit is MB + const double small = 1.0; // unit is MB #ifdef __MPI - Parallel_Reduce::reduce_all(Memory::total); + Parallel_Reduce::reduce_all(Memory::total); #if defined(__CUDA) || defined(__ROCM) - Parallel_Reduce::reduce_all(Memory::total_gpu); + Parallel_Reduce::reduce_all(Memory::total_gpu); #endif #endif - ofs <<"\n NAME-------------------------|MEMORY(MB)------------------" << std::endl; + ofs <<"\n NAME-------------------------|MEMORY(MB)------------------" << std::endl; ofs << std::right; - ofs << std::setw(30)<< "total" << std::setw(15) <0); - bool *print_flag = new bool[n_memory]; + bool *print_flag = new bool[n_memory]; - for(int i=0; i0); - bool *print_flag_gpu = new bool[n_memory]; + bool *print_flag_gpu = new bool[n_memory]; - for(int i=0; i>::value, "Type not supported"); - if (std::is_same::value) { + if (std::is_same::value) { Cigebs2d(ConTxt, scope, top, m, n, reinterpret_cast(A), lda); } - if (std::is_same::value) { + if (std::is_same::value) { Csgebs2d(ConTxt, scope, top, m, n, reinterpret_cast(A), lda); } - if (std::is_same::value) { + if (std::is_same::value) { Cdgebs2d(ConTxt, scope, top, m, n, reinterpret_cast(A), lda); } - if (std::is_same>::value) { + if (std::is_same>::value) { Ccgebs2d(ConTxt, scope, top, m, n, reinterpret_cast*>(A), lda); } - if (std::is_same>::value) { + if (std::is_same>::value) { Czgebs2d(ConTxt, scope, top, m, n, reinterpret_cast*>(A), lda); } } @@ -101,19 +101,19 @@ void Cxgebr2d(int ConTxt, char *scope, char *top, int m, int n, T *A, int lda, i std::is_same>::value, "Type not supported"); - if (std::is_same::value) { + if (std::is_same::value) { Cigebr2d(ConTxt, scope, top, m, n, reinterpret_cast(A), lda, rsrc, csrc); } - if (std::is_same::value) { + if (std::is_same::value) { Csgebr2d(ConTxt, scope, top, m, n, reinterpret_cast(A), lda, rsrc, csrc); } - if (std::is_same::value) { + if (std::is_same::value) { Cdgebr2d(ConTxt, scope, top, m, n, reinterpret_cast(A), lda, rsrc, csrc); } - if (std::is_same>::value) { + if (std::is_same>::value) { Ccgebr2d(ConTxt, scope, top, m, n, reinterpret_cast*>(A), lda, rsrc, csrc); } - if (std::is_same>::value) { + if (std::is_same>::value) { Czgebr2d(ConTxt, scope, top, m, n, reinterpret_cast*>(A), lda, rsrc, csrc); } } diff --git a/source/source_base/module_external/blas_connector.h b/source/source_base/module_external/blas_connector.h index 0e34c42f08e..22f9f99212d 100644 --- a/source/source_base/module_external/blas_connector.h +++ b/source/source_base/module_external/blas_connector.h @@ -203,165 +203,165 @@ class BlasConnector { public: - // Peize Lin add 2016-08-04 - // y=a*x+y - static - void axpy( const int n, const float alpha, const float *X, const int incX, float *Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + // Peize Lin add 2016-08-04 + // y=a*x+y + static + void axpy( const int n, const float alpha, const float *X, const int incX, float *Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - static - void axpy( const int n, const double alpha, const double *X, const int incX, double *Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + static + void axpy( const int n, const double alpha, const double *X, const int incX, double *Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - static - void axpy( const int n, const std::complex alpha, const std::complex *X, const int incX, std::complex *Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + static + void axpy( const int n, const std::complex alpha, const std::complex *X, const int incX, std::complex *Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - static - void axpy( const int n, const std::complex alpha, const std::complex *X, const int incX, std::complex *Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + static + void axpy( const int n, const std::complex alpha, const std::complex *X, const int incX, std::complex *Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - // Peize Lin add 2016-08-04 - // x=a*x - static - void scal( const int n, const float alpha, float *X, const int incX, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + // Peize Lin add 2016-08-04 + // x=a*x + static + void scal( const int n, const float alpha, float *X, const int incX, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - static - void scal( const int n, const double alpha, double *X, const int incX, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + static + void scal( const int n, const double alpha, double *X, const int incX, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - static - void scal( const int n, const std::complex alpha, std::complex *X, const int incX, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + static + void scal( const int n, const std::complex alpha, std::complex *X, const int incX, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - static - void scal( const int n, const std::complex alpha, std::complex *X, const int incX, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + static + void scal( const int n, const std::complex alpha, std::complex *X, const int incX, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - // Peize Lin add 2017-10-27 - // d=x*y - static - float dot( const int n, const float*const X, const int incX, const float*const Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + // Peize Lin add 2017-10-27 + // d=x*y + static + float dot( const int n, const float*const X, const int incX, const float*const Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - static - double dot( const int n, const double*const X, const int incX, const double*const Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + static + double dot( const int n, const double*const X, const int incX, const double*const Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - // d=x*y - static - float dotu( const int n, const float*const X, const int incX, const float*const Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + // d=x*y + static + float dotu( const int n, const float*const X, const int incX, const float*const Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - static - double dotu( const int n, const double*const X, const int incX, const double*const Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + static + double dotu( const int n, const double*const X, const int incX, const double*const Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - static - std::complex dotu( const int n, const std::complex*const X, const int incX, const std::complex*const Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + static + std::complex dotu( const int n, const std::complex*const X, const int incX, const std::complex*const Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - static - std::complex dotu( const int n, const std::complex*const X, const int incX, const std::complex*const Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + static + std::complex dotu( const int n, const std::complex*const X, const int incX, const std::complex*const Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - // d=x.conj()*y - static - float dotc( const int n, const float*const X, const int incX, const float*const Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + // d=x.conj()*y + static + float dotc( const int n, const float*const X, const int incX, const float*const Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - static - double dotc( const int n, const double*const X, const int incX, const double*const Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + static + double dotc( const int n, const double*const X, const int incX, const double*const Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - static - std::complex dotc( const int n, const std::complex*const X, const int incX, const std::complex*const Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + static + std::complex dotc( const int n, const std::complex*const X, const int incX, const std::complex*const Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - static - std::complex dotc( const int n, const std::complex*const X, const int incX, const std::complex*const Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + static + std::complex dotc( const int n, const std::complex*const X, const int incX, const std::complex*const Y, const int incY, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - // Peize Lin add 2017-10-27, fix bug trans 2019-01-17 - // C = a * A.? * B.? + b * C - // Row Major by default - static - void gemm(const char transa, const char transb, const int m, const int n, const int k, - const float alpha, const float *a, const int lda, const float *b, const int ldb, - const float beta, float *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + // Peize Lin add 2017-10-27, fix bug trans 2019-01-17 + // C = a * A.? * B.? + b * C + // Row Major by default + static + void gemm(const char transa, const char transb, const int m, const int n, const int k, + const float alpha, const float *a, const int lda, const float *b, const int ldb, + const float beta, float *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - static - void gemm(const char transa, const char transb, const int m, const int n, const int k, - const double alpha, const double *a, const int lda, const double *b, const int ldb, - const double beta, double *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + static + void gemm(const char transa, const char transb, const int m, const int n, const int k, + const double alpha, const double *a, const int lda, const double *b, const int ldb, + const double beta, double *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); static void gemm(const char transa, const char transb, const int m, const int n, const int k, const std::complex alpha, const std::complex *a, const int lda, const std::complex *b, const int ldb, const std::complex beta, std::complex *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - static - void gemm(const char transa, const char transb, const int m, const int n, const int k, - const std::complex alpha, const std::complex *a, const int lda, const std::complex *b, const int ldb, - const std::complex beta, std::complex *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + static + void gemm(const char transa, const char transb, const int m, const int n, const int k, + const std::complex alpha, const std::complex *a, const int lda, const std::complex *b, const int ldb, + const std::complex beta, std::complex *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - // Col-Major if you need to use it + // Col-Major if you need to use it - static - void gemm_cm(const char transa, const char transb, const int m, const int n, const int k, - const float alpha, const float *a, const int lda, const float *b, const int ldb, - const float beta, float *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + static + void gemm_cm(const char transa, const char transb, const int m, const int n, const int k, + const float alpha, const float *a, const int lda, const float *b, const int ldb, + const float beta, float *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - static - void gemm_cm(const char transa, const char transb, const int m, const int n, const int k, - const double alpha, const double *a, const int lda, const double *b, const int ldb, - const double beta, double *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + static + void gemm_cm(const char transa, const char transb, const int m, const int n, const int k, + const double alpha, const double *a, const int lda, const double *b, const int ldb, + const double beta, double *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); static void gemm_cm(const char transa, const char transb, const int m, const int n, const int k, const std::complex alpha, const std::complex *a, const int lda, const std::complex *b, const int ldb, const std::complex beta, std::complex *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - static - void gemm_cm(const char transa, const char transb, const int m, const int n, const int k, - const std::complex alpha, const std::complex *a, const int lda, const std::complex *b, const int ldb, - const std::complex beta, std::complex *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + static + void gemm_cm(const char transa, const char transb, const int m, const int n, const int k, + const std::complex alpha, const std::complex *a, const int lda, const std::complex *b, const int ldb, + const std::complex beta, std::complex *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - // side=='L': C = a * A * B + b * C. - // side=='R': C = a * B * A + b * C. - // A == A^T - // Because you cannot pack symm or hemm into a row-major kernel by exchanging parameters, so only col-major functions are provided. - static - void symm_cm(const char side, const char uplo, const int m, const int n, - const float alpha, const float *a, const int lda, const float *b, const int ldb, - const float beta, float *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + // side=='L': C = a * A * B + b * C. + // side=='R': C = a * B * A + b * C. + // A == A^T + // Because you cannot pack symm or hemm into a row-major kernel by exchanging parameters, so only col-major functions are provided. + static + void symm_cm(const char side, const char uplo, const int m, const int n, + const float alpha, const float *a, const int lda, const float *b, const int ldb, + const float beta, float *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - static - void symm_cm(const char side, const char uplo, const int m, const int n, - const double alpha, const double *a, const int lda, const double *b, const int ldb, - const double beta, double *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + static + void symm_cm(const char side, const char uplo, const int m, const int n, + const double alpha, const double *a, const int lda, const double *b, const int ldb, + const double beta, double *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); static void symm_cm(const char side, const char uplo, const int m, const int n, const std::complex alpha, const std::complex *a, const int lda, const std::complex *b, const int ldb, const std::complex beta, std::complex *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - static - void symm_cm(const char side, const char uplo, const int m, const int n, - const std::complex alpha, const std::complex *a, const int lda, const std::complex *b, const int ldb, - const std::complex beta, std::complex *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - - // side=='L': C = a * A * B + b * C. - // side=='R': C = a * B * A + b * C. - // A == A^H - static - void hemm_cm(const char side, const char uplo, const int m, const int n, - const float alpha, const float *a, const int lda, const float *b, const int ldb, - const float beta, float *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - - static - void hemm_cm(const char side, const char uplo, const int m, const int n, - const double alpha, const double *a, const int lda, const double *b, const int ldb, - const double beta, double *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - - static + static + void symm_cm(const char side, const char uplo, const int m, const int n, + const std::complex alpha, const std::complex *a, const int lda, const std::complex *b, const int ldb, + const std::complex beta, std::complex *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + + // side=='L': C = a * A * B + b * C. + // side=='R': C = a * B * A + b * C. + // A == A^H + static + void hemm_cm(const char side, const char uplo, const int m, const int n, + const float alpha, const float *a, const int lda, const float *b, const int ldb, + const float beta, float *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + + static + void hemm_cm(const char side, const char uplo, const int m, const int n, + const double alpha, const double *a, const int lda, const double *b, const int ldb, + const double beta, double *c, const int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + + static void hemm_cm(char side, char uplo, int m, int n, std::complex alpha, std::complex *a, int lda, std::complex *b, int ldb, std::complex beta, std::complex *c, int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - static - void hemm_cm(char side, char uplo, int m, int n, - std::complex alpha, std::complex *a, int lda, std::complex *b, int ldb, - std::complex beta, std::complex *c, int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + static + void hemm_cm(char side, char uplo, int m, int n, + std::complex alpha, std::complex *a, int lda, std::complex *b, int ldb, + std::complex beta, std::complex *c, int ldc, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - // y = A*x + beta*y - static - void gemv(const char trans, const int m, const int n, + // y = A*x + beta*y + static + void gemv(const char trans, const int m, const int n, const float alpha, const float* A, const int lda, const float* X, const int incx, const float beta, float* Y, const int incy, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); @@ -380,67 +380,67 @@ class BlasConnector const std::complex alpha, const std::complex *A, const int lda, const std::complex *X, const int incx, const std::complex beta, std::complex *Y, const int incy, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - // Peize Lin add 2018-06-12 - // out = ||x||_2 - static - float nrm2( const int n, const float *X, const int, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice ); - - static - double nrm2( const int n, const double *X, const int incX, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice ); - - static - double nrm2( const int n, const std::complex *X, const int incX, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice ); - - - // copies a into b - static - void copy(const int n, const double *a, const int incx, double *b, const int incy, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - - static - void copy(const int n, const float *a, const int incx, float *b, const int incy, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - - static - void copy(const int n, const std::complex *a, const int incx, std::complex *b, const int incy, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - - static - void copy(const int n, const std::complex *a, const int incx, std::complex *b, const int incy, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); - - // There is some other operators needed, so implemented manually here - template - static - void vector_mul_vector(const int& dim, - T* result, - const T* vector1, - const Operand* vector2, - base_device::AbacusDevice_t device_type); - - template - static - void vector_div_vector(const int& dim, - T* result, - const T* vector1, - const Operand* vector2, - base_device::AbacusDevice_t device_type); - - // result = constant1 * vector1 + constant2 * vector2 - template - static - void vector_add_vector(const int& dim, - T* result, - const T* vector1, - const Scalar constant1, - const T* vector2, - const Scalar constant2, - base_device::AbacusDevice_t device_type); + // Peize Lin add 2018-06-12 + // out = ||x||_2 + static + float nrm2( const int n, const float *X, const int, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice ); + + static + double nrm2( const int n, const double *X, const int incX, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice ); + + static + double nrm2( const int n, const std::complex *X, const int incX, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice ); + + + // copies a into b + static + void copy(const int n, const double *a, const int incx, double *b, const int incy, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + + static + void copy(const int n, const float *a, const int incx, float *b, const int incy, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + + static + void copy(const int n, const std::complex *a, const int incx, std::complex *b, const int incy, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + + static + void copy(const int n, const std::complex *a, const int incx, std::complex *b, const int incy, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice); + + // There is some other operators needed, so implemented manually here + template + static + void vector_mul_vector(const int& dim, + T* result, + const T* vector1, + const Operand* vector2, + base_device::AbacusDevice_t device_type); + + template + static + void vector_div_vector(const int& dim, + T* result, + const T* vector1, + const Operand* vector2, + base_device::AbacusDevice_t device_type); + + // result = constant1 * vector1 + constant2 * vector2 + template + static + void vector_add_vector(const int& dim, + T* result, + const T* vector1, + const Scalar constant1, + const T* vector2, + const Scalar constant2, + base_device::AbacusDevice_t device_type); #ifdef __DSP - /// @brief Inject the DSP cluster id used by mt-allocator BLAS kernels. - /// Caller-injected (typically once after input parameters are read). - /// Defaults to 0 if never set. - static void set_dsp_cluster_id(int id); + /// @brief Inject the DSP cluster id used by mt-allocator BLAS kernels. + /// Caller-injected (typically once after input parameters are read). + /// Defaults to 0 if never set. + static void set_dsp_cluster_id(int id); private: - static int dsp_cluster_id_; + static int dsp_cluster_id_; #endif }; @@ -454,17 +454,17 @@ class BlasConnector namespace BlasUtils{ - static cublasHandle_t cublas_handle = nullptr; + static cublasHandle_t cublas_handle = nullptr; - void createGpuBlasHandle(); // Create a cublas/hipblas handle. + void createGpuBlasHandle(); // Create a cublas/hipblas handle. - void destoryBLAShandle(); // Destroy the cublas/hipblas handle. Do this when the software is about to end. + void destoryBLAShandle(); // Destroy the cublas/hipblas handle. Do this when the software is about to end. - cublasOperation_t judge_trans(bool is_complex, const char& trans, const char* name); // Translate a normal transpose parameter to a cublas/hipblas type. + cublasOperation_t judge_trans(bool is_complex, const char& trans, const char* name); // Translate a normal transpose parameter to a cublas/hipblas type. - cublasSideMode_t judge_side(const char& trans); // Translate a normal side parameter to a cublas/hipblas type. + cublasSideMode_t judge_side(const char& trans); // Translate a normal side parameter to a cublas/hipblas type. - cublasFillMode_t judge_fill(const char& trans); // Translate a normal fill parameter to a cublas/hipblas type. + cublasFillMode_t judge_fill(const char& trans); // Translate a normal fill parameter to a cublas/hipblas type. } diff --git a/source/source_base/module_external/blas_connector_base.cpp b/source/source_base/module_external/blas_connector_base.cpp index b07f8a3a780..be0bc342c00 100644 --- a/source/source_base/module_external/blas_connector_base.cpp +++ b/source/source_base/module_external/blas_connector_base.cpp @@ -11,66 +11,66 @@ namespace BlasUtils{ - void createGpuBlasHandle(){ - if (cublas_handle == nullptr) { - CHECK_CUBLAS(cublasCreate(&cublas_handle)); - } - } + void createGpuBlasHandle(){ + if (cublas_handle == nullptr) { + CHECK_CUBLAS(cublasCreate(&cublas_handle)); + } + } - void destoryBLAShandle(){ - if (cublas_handle != nullptr) { - CHECK_CUBLAS(cublasDestroy(cublas_handle)); - cublas_handle = nullptr; - } - } + void destoryBLAShandle(){ + if (cublas_handle != nullptr) { + CHECK_CUBLAS(cublasDestroy(cublas_handle)); + cublas_handle = nullptr; + } + } - cublasOperation_t judge_trans(bool is_complex, const char& trans, const char* name) - { - if (trans == 'N') - { - return CUBLAS_OP_N; - } - else if(trans == 'T') - { - return CUBLAS_OP_T; - } - else if(is_complex && trans == 'C') - { - return CUBLAS_OP_C; - } - return CUBLAS_OP_N; - } + cublasOperation_t judge_trans(bool is_complex, const char& trans, const char* name) + { + if (trans == 'N') + { + return CUBLAS_OP_N; + } + else if(trans == 'T') + { + return CUBLAS_OP_T; + } + else if(is_complex && trans == 'C') + { + return CUBLAS_OP_C; + } + return CUBLAS_OP_N; + } - cublasSideMode_t judge_side(const char& trans) - { - if (trans == 'L') - { - return CUBLAS_SIDE_LEFT; - } - else if (trans == 'R') - { - return CUBLAS_SIDE_RIGHT; - } - return CUBLAS_SIDE_LEFT; - } + cublasSideMode_t judge_side(const char& trans) + { + if (trans == 'L') + { + return CUBLAS_SIDE_LEFT; + } + else if (trans == 'R') + { + return CUBLAS_SIDE_RIGHT; + } + return CUBLAS_SIDE_LEFT; + } - cublasFillMode_t judge_fill(const char& trans) - { - if (trans == 'F') - { - return CUBLAS_FILL_MODE_FULL; - } - else if (trans == 'U') - { - return CUBLAS_FILL_MODE_UPPER; - } - else if (trans == 'D') - { - return CUBLAS_FILL_MODE_LOWER; - } - return CUBLAS_FILL_MODE_FULL; - } + cublasFillMode_t judge_fill(const char& trans) + { + if (trans == 'F') + { + return CUBLAS_FILL_MODE_FULL; + } + else if (trans == 'U') + { + return CUBLAS_FILL_MODE_UPPER; + } + else if (trans == 'D') + { + return CUBLAS_FILL_MODE_LOWER; + } + return CUBLAS_FILL_MODE_FULL; + } } // namespace BlasUtils diff --git a/source/source_base/module_external/blas_connector_matrix.cpp b/source/source_base/module_external/blas_connector_matrix.cpp index 1e819d56ae0..964ce5cd9db 100644 --- a/source/source_base/module_external/blas_connector_matrix.cpp +++ b/source/source_base/module_external/blas_connector_matrix.cpp @@ -24,31 +24,31 @@ void BlasConnector::set_dsp_cluster_id(int id) // C = a * A.? * B.? + b * C // Row-Major part void BlasConnector::gemm(const char transa, const char transb, const int m, const int n, const int k, - const float alpha, const float *a, const int lda, const float *b, const int ldb, - const float beta, float *c, const int ldc, base_device::AbacusDevice_t device_type) + const float alpha, const float *a, const int lda, const float *b, const int ldb, + const float beta, float *c, const int ldc, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - sgemm_(&transb, &transa, &n, &m, &k, - &alpha, b, &ldb, a, &lda, - &beta, c, &ldc); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + sgemm_(&transb, &transa, &n, &m, &k, + &alpha, b, &ldb, a, &lda, + &beta, c, &ldc); + } #ifdef __DSP - else if (device_type == base_device::AbacusDevice_t::DspDevice){ - mtfunc::sgemm_mth_(&transb, &transa, &n, &m, &k, - &alpha, b, &ldb, a, &lda, - &beta, c, &ldc, BlasConnector::dsp_cluster_id_); - } + else if (device_type == base_device::AbacusDevice_t::DspDevice){ + mtfunc::sgemm_mth_(&transb, &transa, &n, &m, &k, + &alpha, b, &ldb, a, &lda, + &beta, c, &ldc, BlasConnector::dsp_cluster_id_); + } #endif #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice) { - cublasOperation_t cutransA = BlasUtils::judge_trans(false, transa, "gemm_op"); - cublasOperation_t cutransB = BlasUtils::judge_trans(false, transb, "gemm_op"); - CHECK_CUBLAS(cublasSgemm(BlasUtils::cublas_handle, cutransA, cutransB, n, m, k, &alpha, b, ldb, a, lda, &beta, c, ldc)); - } -#endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice) { + cublasOperation_t cutransA = BlasUtils::judge_trans(false, transa, "gemm_op"); + cublasOperation_t cutransB = BlasUtils::judge_trans(false, transb, "gemm_op"); + CHECK_CUBLAS(cublasSgemm(BlasUtils::cublas_handle, cutransA, cutransB, n, m, k, &alpha, b, ldb, a, lda, &beta, c, ldc)); + } +#endif + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::gemm(const char transa, @@ -85,9 +85,9 @@ void BlasConnector::gemm(const char transa, cublasDgemm(BlasUtils::cublas_handle, cutransA, cutransB, n, m, k, &alpha, b, ldb, a, lda, &beta, c, ldc)); #endif } - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::gemm(const char transa, @@ -138,9 +138,9 @@ void BlasConnector::gemm(const char transa, ldc)); #endif } - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::gemm(const char transa, @@ -191,38 +191,38 @@ void BlasConnector::gemm(const char transa, ldc)); #endif } - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } // Col-Major part void BlasConnector::gemm_cm(const char transa, const char transb, const int m, const int n, const int k, - const float alpha, const float *a, const int lda, const float *b, const int ldb, - const float beta, float *c, const int ldc, base_device::AbacusDevice_t device_type) + const float alpha, const float *a, const int lda, const float *b, const int ldb, + const float beta, float *c, const int ldc, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - sgemm_(&transa, &transb, &m, &n, &k, - &alpha, a, &lda, b, &ldb, - &beta, c, &ldc); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + sgemm_(&transa, &transb, &m, &n, &k, + &alpha, a, &lda, b, &ldb, + &beta, c, &ldc); + } #ifdef __DSP - else if (device_type == base_device::AbacusDevice_t::DspDevice){ - mtfunc::sgemm_mth_(&transb, &transa, &m, &n, &k, - &alpha, a, &lda, b, &ldb, - &beta, c, &ldc, BlasConnector::dsp_cluster_id_); - } + else if (device_type == base_device::AbacusDevice_t::DspDevice){ + mtfunc::sgemm_mth_(&transb, &transa, &m, &n, &k, + &alpha, a, &lda, b, &ldb, + &beta, c, &ldc, BlasConnector::dsp_cluster_id_); + } #endif #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice) { - cublasOperation_t cutransA = BlasUtils::judge_trans(false, transa, "gemm_op"); - cublasOperation_t cutransB = BlasUtils::judge_trans(false, transb, "gemm_op"); - CHECK_CUBLAS(cublasSgemm(BlasUtils::cublas_handle, cutransA, cutransB, m, n, k, &alpha, a, lda, b, ldb, &beta, c, ldc)); - } -#endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice) { + cublasOperation_t cutransA = BlasUtils::judge_trans(false, transa, "gemm_op"); + cublasOperation_t cutransB = BlasUtils::judge_trans(false, transb, "gemm_op"); + CHECK_CUBLAS(cublasSgemm(BlasUtils::cublas_handle, cutransA, cutransB, m, n, k, &alpha, a, lda, b, ldb, &beta, c, ldc)); + } +#endif + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::gemm_cm(const char transa, @@ -259,9 +259,9 @@ void BlasConnector::gemm_cm(const char transa, cublasDgemm(BlasUtils::cublas_handle, cutransA, cutransB, m, n, k, &alpha, a, lda, b, ldb, &beta, c, ldc)); } #endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::gemm_cm(const char transa, @@ -312,9 +312,9 @@ void BlasConnector::gemm_cm(const char transa, ldc)); } #endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::gemm_cm(const char transa, @@ -365,160 +365,160 @@ void BlasConnector::gemm_cm(const char transa, ldc)); } #endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } // Symm and Hemm part. Only col-major is supported. void BlasConnector::symm_cm(const char side, const char uplo, const int m, const int n, - const float alpha, const float *a, const int lda, const float *b, const int ldb, - const float beta, float *c, const int ldc, base_device::AbacusDevice_t device_type) + const float alpha, const float *a, const int lda, const float *b, const int ldb, + const float beta, float *c, const int ldc, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - ssymm_(&side, &uplo, &m, &n, - &alpha, a, &lda, b, &ldb, - &beta, c, &ldc); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + ssymm_(&side, &uplo, &m, &n, + &alpha, a, &lda, b, &ldb, + &beta, c, &ldc); + } #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice) { - cublasSideMode_t sideMode = BlasUtils::judge_side(side); - cublasFillMode_t fillMode = BlasUtils::judge_fill(uplo); - CHECK_CUBLAS(cublasSsymm(BlasUtils::cublas_handle, sideMode, fillMode, m, n, &alpha, a, lda, b, ldb, &beta, c, ldc)); - } -#endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice) { + cublasSideMode_t sideMode = BlasUtils::judge_side(side); + cublasFillMode_t fillMode = BlasUtils::judge_fill(uplo); + CHECK_CUBLAS(cublasSsymm(BlasUtils::cublas_handle, sideMode, fillMode, m, n, &alpha, a, lda, b, ldb, &beta, c, ldc)); + } +#endif + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::symm_cm(const char side, const char uplo, const int m, const int n, - const double alpha, const double *a, const int lda, const double *b, const int ldb, - const double beta, double *c, const int ldc, base_device::AbacusDevice_t device_type) + const double alpha, const double *a, const int lda, const double *b, const int ldb, + const double beta, double *c, const int ldc, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - dsymm_(&side, &uplo, &m, &n, - &alpha, a, &lda, b, &ldb, - &beta, c, &ldc); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + dsymm_(&side, &uplo, &m, &n, + &alpha, a, &lda, b, &ldb, + &beta, c, &ldc); + } #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice) { - cublasSideMode_t sideMode = BlasUtils::judge_side(side); - cublasFillMode_t fillMode = BlasUtils::judge_fill(uplo); - CHECK_CUBLAS(cublasDsymm(BlasUtils::cublas_handle, sideMode, fillMode, m, n, &alpha, a, lda, b, ldb, &beta, c, ldc)); - } -#endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice) { + cublasSideMode_t sideMode = BlasUtils::judge_side(side); + cublasFillMode_t fillMode = BlasUtils::judge_fill(uplo); + CHECK_CUBLAS(cublasDsymm(BlasUtils::cublas_handle, sideMode, fillMode, m, n, &alpha, a, lda, b, ldb, &beta, c, ldc)); + } +#endif + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::symm_cm(const char side, const char uplo, const int m, const int n, const std::complex alpha, const std::complex *a, const int lda, const std::complex *b, const int ldb, const std::complex beta, std::complex *c, const int ldc, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - csymm_(&side, &uplo, &m, &n, - &alpha, a, &lda, b, &ldb, - &beta, c, &ldc); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + csymm_(&side, &uplo, &m, &n, + &alpha, a, &lda, b, &ldb, + &beta, c, &ldc); + } #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice) { - cublasSideMode_t sideMode = BlasUtils::judge_side(side); - cublasFillMode_t fillMode = BlasUtils::judge_fill(uplo); - CHECK_CUBLAS(cublasCsymm(BlasUtils::cublas_handle, sideMode, fillMode, m, n, (float2*)&alpha, (float2*)a, lda, (float2*)b, ldb, (float2*)&beta, (float2*)c, ldc)); - } -#endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice) { + cublasSideMode_t sideMode = BlasUtils::judge_side(side); + cublasFillMode_t fillMode = BlasUtils::judge_fill(uplo); + CHECK_CUBLAS(cublasCsymm(BlasUtils::cublas_handle, sideMode, fillMode, m, n, (float2*)&alpha, (float2*)a, lda, (float2*)b, ldb, (float2*)&beta, (float2*)c, ldc)); + } +#endif + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::symm_cm(const char side, const char uplo, const int m, const int n, - const std::complex alpha, const std::complex *a, const int lda, const std::complex *b, const int ldb, - const std::complex beta, std::complex *c, const int ldc, base_device::AbacusDevice_t device_type) + const std::complex alpha, const std::complex *a, const int lda, const std::complex *b, const int ldb, + const std::complex beta, std::complex *c, const int ldc, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - zsymm_(&side, &uplo, &m, &n, - &alpha, a, &lda, b, &ldb, - &beta, c, &ldc); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + zsymm_(&side, &uplo, &m, &n, + &alpha, a, &lda, b, &ldb, + &beta, c, &ldc); + } #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice) { - cublasSideMode_t sideMode = BlasUtils::judge_side(side); - cublasFillMode_t fillMode = BlasUtils::judge_fill(uplo); - CHECK_CUBLAS(cublasZsymm(BlasUtils::cublas_handle, sideMode, fillMode, m, n, (double2*)&alpha, (double2*)a, lda, (double2*)b, ldb, (double2*)&beta, (double2*)c, ldc)); - } -#endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice) { + cublasSideMode_t sideMode = BlasUtils::judge_side(side); + cublasFillMode_t fillMode = BlasUtils::judge_fill(uplo); + CHECK_CUBLAS(cublasZsymm(BlasUtils::cublas_handle, sideMode, fillMode, m, n, (double2*)&alpha, (double2*)a, lda, (double2*)b, ldb, (double2*)&beta, (double2*)c, ldc)); + } +#endif + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::hemm_cm(const char side, const char uplo, const int m, const int n, - const float alpha, const float *a, const int lda, const float *b, const int ldb, - const float beta, float *c, const int ldc, base_device::AbacusDevice_t device_type) + const float alpha, const float *a, const int lda, const float *b, const int ldb, + const float beta, float *c, const int ldc, base_device::AbacusDevice_t device_type) { - symm_cm(side, uplo, m, n, alpha, a, lda, b, ldb, beta, c, ldc, device_type); + symm_cm(side, uplo, m, n, alpha, a, lda, b, ldb, beta, c, ldc, device_type); } void BlasConnector::hemm_cm(const char side, const char uplo, const int m, const int n, - const double alpha, const double *a, const int lda, const double *b, const int ldb, - const double beta, double *c, const int ldc, base_device::AbacusDevice_t device_type) + const double alpha, const double *a, const int lda, const double *b, const int ldb, + const double beta, double *c, const int ldc, base_device::AbacusDevice_t device_type) { - symm_cm(side, uplo, m, n, alpha, a, lda, b, ldb, beta, c, ldc, device_type); + symm_cm(side, uplo, m, n, alpha, a, lda, b, ldb, beta, c, ldc, device_type); } void BlasConnector::hemm_cm(char side, char uplo, int m, int n, std::complex alpha, std::complex *a, int lda, std::complex *b, int ldb, std::complex beta, std::complex *c, int ldc, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - chemm_(&side, &uplo, &m, &n, - &alpha, a, &lda, b, &ldb, - &beta, c, &ldc); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + chemm_(&side, &uplo, &m, &n, + &alpha, a, &lda, b, &ldb, + &beta, c, &ldc); + } #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice) { - cublasSideMode_t sideMode = BlasUtils::judge_side(side); - cublasFillMode_t fillMode = BlasUtils::judge_fill(uplo); - CHECK_CUBLAS(cublasChemm(BlasUtils::cublas_handle, sideMode, fillMode, m, n, (float2*)&alpha, (float2*)a, lda, (float2*)b, ldb, (float2*)&beta, (float2*)c, ldc)); - } -#endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice) { + cublasSideMode_t sideMode = BlasUtils::judge_side(side); + cublasFillMode_t fillMode = BlasUtils::judge_fill(uplo); + CHECK_CUBLAS(cublasChemm(BlasUtils::cublas_handle, sideMode, fillMode, m, n, (float2*)&alpha, (float2*)a, lda, (float2*)b, ldb, (float2*)&beta, (float2*)c, ldc)); + } +#endif + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::hemm_cm(char side, char uplo, int m, int n, - std::complex alpha, std::complex *a, int lda, std::complex *b, int ldb, - std::complex beta, std::complex *c, int ldc, base_device::AbacusDevice_t device_type) + std::complex alpha, std::complex *a, int lda, std::complex *b, int ldb, + std::complex beta, std::complex *c, int ldc, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - zhemm_(&side, &uplo, &m, &n, - &alpha, a, &lda, b, &ldb, - &beta, c, &ldc); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + zhemm_(&side, &uplo, &m, &n, + &alpha, a, &lda, b, &ldb, + &beta, c, &ldc); + } #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice) { - cublasSideMode_t sideMode = BlasUtils::judge_side(side); - cublasFillMode_t fillMode = BlasUtils::judge_fill(uplo); - CHECK_CUBLAS(cublasZhemm(BlasUtils::cublas_handle, sideMode, fillMode, m, n, (double2*)&alpha, (double2*)a, lda, (double2*)b, ldb, (double2*)&beta, (double2*)c, ldc)); - } -#endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice) { + cublasSideMode_t sideMode = BlasUtils::judge_side(side); + cublasFillMode_t fillMode = BlasUtils::judge_fill(uplo); + CHECK_CUBLAS(cublasZhemm(BlasUtils::cublas_handle, sideMode, fillMode, m, n, (double2*)&alpha, (double2*)a, lda, (double2*)b, ldb, (double2*)&beta, (double2*)c, ldc)); + } +#endif + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::gemv(const char trans, const int m, const int n, const float alpha, const float* A, const int lda, const float* X, const int incx, const float beta, float* Y, const int incy, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - sgemv_(&trans, &m, &n, &alpha, A, &lda, X, &incx, &beta, Y, &incy); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + sgemv_(&trans, &m, &n, &alpha, A, &lda, X, &incx, &beta, Y, &incy); + } #ifdef __DSP else if (device_type == base_device::AbacusDevice_t::DspDevice) { mtfunc::sgemv_mth_(&trans, @@ -536,23 +536,23 @@ void BlasConnector::gemv(const char trans, const int m, const int n, } #endif #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice) { - cublasOperation_t cutransA = BlasUtils::judge_trans(false, trans, "gemv_op"); - CHECK_CUBLAS(cublasSgemv(BlasUtils::cublas_handle, cutransA, m, n, &alpha, A, lda, X, incx, &beta, Y, incy)); - } -#endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice) { + cublasOperation_t cutransA = BlasUtils::judge_trans(false, trans, "gemv_op"); + CHECK_CUBLAS(cublasSgemv(BlasUtils::cublas_handle, cutransA, m, n, &alpha, A, lda, X, incx, &beta, Y, incy)); + } +#endif + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::gemv(const char trans, const int m, const int n, const double alpha, const double* A, const int lda, const double* X, const int incx, const double beta, double* Y, const int incy, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - dgemv_(&trans, &m, &n, &alpha, A, &lda, X, &incx, &beta, Y, &incy); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + dgemv_(&trans, &m, &n, &alpha, A, &lda, X, &incx, &beta, Y, &incy); + } #ifdef __DSP else if (device_type == base_device::AbacusDevice_t::DspDevice) { mtfunc::dgemv_mth_(&trans, @@ -570,23 +570,23 @@ void BlasConnector::gemv(const char trans, const int m, const int n, } #endif #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice) { - cublasOperation_t cutransA = BlasUtils::judge_trans(false, trans, "gemv_op"); - CHECK_CUBLAS(cublasDgemv(BlasUtils::cublas_handle, cutransA, m, n, &alpha, A, lda, X, incx, &beta, Y, incy)); - } -#endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice) { + cublasOperation_t cutransA = BlasUtils::judge_trans(false, trans, "gemv_op"); + CHECK_CUBLAS(cublasDgemv(BlasUtils::cublas_handle, cutransA, m, n, &alpha, A, lda, X, incx, &beta, Y, incy)); + } +#endif + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::gemv(const char trans, const int m, const int n, const std::complex alpha, const std::complex *A, const int lda, const std::complex *X, const int incx, const std::complex beta, std::complex *Y, const int incy, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - cgemv_(&trans, &m, &n, &alpha, A, &lda, X, &incx, &beta, Y, &incy); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + cgemv_(&trans, &m, &n, &alpha, A, &lda, X, &incx, &beta, Y, &incy); + } #ifdef __DSP else if (device_type == base_device::AbacusDevice_t::DspDevice) { mtfunc::cgemv_mth_(&trans, @@ -604,25 +604,25 @@ void BlasConnector::gemv(const char trans, const int m, const int n, } #endif #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice) { - cuFloatComplex alpha_cu = make_cuFloatComplex(alpha.real(), alpha.imag()); - cuFloatComplex beta_cu = make_cuFloatComplex(beta.real(), beta.imag()); - cublasOperation_t cutransA = BlasUtils::judge_trans(true, trans, "gemv_op"); - CHECK_CUBLAS(cublasCgemv(BlasUtils::cublas_handle, cutransA, m, n, &alpha_cu, (cuFloatComplex*)A, lda, (cuFloatComplex*)X, incx, &beta_cu, (cuFloatComplex*)Y, incy)); - } -#endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice) { + cuFloatComplex alpha_cu = make_cuFloatComplex(alpha.real(), alpha.imag()); + cuFloatComplex beta_cu = make_cuFloatComplex(beta.real(), beta.imag()); + cublasOperation_t cutransA = BlasUtils::judge_trans(true, trans, "gemv_op"); + CHECK_CUBLAS(cublasCgemv(BlasUtils::cublas_handle, cutransA, m, n, &alpha_cu, (cuFloatComplex*)A, lda, (cuFloatComplex*)X, incx, &beta_cu, (cuFloatComplex*)Y, incy)); + } +#endif + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::gemv(const char trans, const int m, const int n, const std::complex alpha, const std::complex *A, const int lda, const std::complex *X, const int incx, const std::complex beta, std::complex *Y, const int incy, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - zgemv_(&trans, &m, &n, &alpha, A, &lda, X, &incx, &beta, Y, &incy); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + zgemv_(&trans, &m, &n, &alpha, A, &lda, X, &incx, &beta, Y, &incy); + } #ifdef __DSP else if (device_type == base_device::AbacusDevice_t::DspDevice) { mtfunc::zgemv_mth_(&trans, @@ -640,14 +640,14 @@ void BlasConnector::gemv(const char trans, const int m, const int n, } #endif #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice) { - cuDoubleComplex alpha_cu = make_cuDoubleComplex(alpha.real(), alpha.imag()); - cuDoubleComplex beta_cu = make_cuDoubleComplex(beta.real(), beta.imag()); - cublasOperation_t cutransA = BlasUtils::judge_trans(true, trans, "gemv_op"); - CHECK_CUBLAS(cublasZgemv(BlasUtils::cublas_handle, cutransA, m, n, &alpha_cu, (cuDoubleComplex*)A, lda, (cuDoubleComplex*)X, incx, &beta_cu, (cuDoubleComplex*)Y, incy)); - } -#endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice) { + cuDoubleComplex alpha_cu = make_cuDoubleComplex(alpha.real(), alpha.imag()); + cuDoubleComplex beta_cu = make_cuDoubleComplex(beta.real(), beta.imag()); + cublasOperation_t cutransA = BlasUtils::judge_trans(true, trans, "gemv_op"); + CHECK_CUBLAS(cublasZgemv(BlasUtils::cublas_handle, cutransA, m, n, &alpha_cu, (cuDoubleComplex*)A, lda, (cuDoubleComplex*)X, incx, &beta_cu, (cuDoubleComplex*)Y, incy)); + } +#endif + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } \ No newline at end of file diff --git a/source/source_base/module_external/blas_connector_vector.cpp b/source/source_base/module_external/blas_connector_vector.cpp index 7aa7296a96b..37b4c327660 100644 --- a/source/source_base/module_external/blas_connector_vector.cpp +++ b/source/source_base/module_external/blas_connector_vector.cpp @@ -17,349 +17,349 @@ void BlasConnector::axpy( const int n, const float alpha, const float *X, const int incX, float *Y, const int incY, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - saxpy_(&n, &alpha, X, &incX, Y, &incY); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + saxpy_(&n, &alpha, X, &incX, Y, &incY); + } #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice) { - CHECK_CUBLAS(cublasSaxpy(BlasUtils::cublas_handle, n, &alpha, X, incX, Y, incY)); - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice) { + CHECK_CUBLAS(cublasSaxpy(BlasUtils::cublas_handle, n, &alpha, X, incX, Y, incY)); + } #endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::axpy( const int n, const double alpha, const double *X, const int incX, double *Y, const int incY, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - daxpy_(&n, &alpha, X, &incX, Y, &incY); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + daxpy_(&n, &alpha, X, &incX, Y, &incY); + } #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice) { - CHECK_CUBLAS(cublasDaxpy(BlasUtils::cublas_handle, n, &alpha, X, incX, Y, incY)); - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice) { + CHECK_CUBLAS(cublasDaxpy(BlasUtils::cublas_handle, n, &alpha, X, incX, Y, incY)); + } #endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::axpy( const int n, const std::complex alpha, const std::complex *X, const int incX, std::complex *Y, const int incY, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - caxpy_(&n, &alpha, X, &incX, Y, &incY); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + caxpy_(&n, &alpha, X, &incX, Y, &incY); + } #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice) { - CHECK_CUBLAS(cublasCaxpy(BlasUtils::cublas_handle, n, (float2*)&alpha, (float2*)X, incX, (float2*)Y, incY)); - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice) { + CHECK_CUBLAS(cublasCaxpy(BlasUtils::cublas_handle, n, (float2*)&alpha, (float2*)X, incX, (float2*)Y, incY)); + } #endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::axpy( const int n, const std::complex alpha, const std::complex *X, const int incX, std::complex *Y, const int incY, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - zaxpy_(&n, &alpha, X, &incX, Y, &incY); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + zaxpy_(&n, &alpha, X, &incX, Y, &incY); + } #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice) { - CHECK_CUBLAS(cublasZaxpy(BlasUtils::cublas_handle, n, (double2*)&alpha, (double2*)X, incX, (double2*)Y, incY)); - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice) { + CHECK_CUBLAS(cublasZaxpy(BlasUtils::cublas_handle, n, (double2*)&alpha, (double2*)X, incX, (double2*)Y, incY)); + } #endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } // x=a*x void BlasConnector::scal( const int n, const float alpha, float *X, const int incX, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - sscal_(&n, &alpha, X, &incX); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + sscal_(&n, &alpha, X, &incX); + } #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice) { - CHECK_CUBLAS(cublasSscal(BlasUtils::cublas_handle, n, &alpha, X, incX)); - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice) { + CHECK_CUBLAS(cublasSscal(BlasUtils::cublas_handle, n, &alpha, X, incX)); + } #endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::scal( const int n, const double alpha, double *X, const int incX, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - dscal_(&n, &alpha, X, &incX); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + dscal_(&n, &alpha, X, &incX); + } #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice) { - CHECK_CUBLAS(cublasDscal(BlasUtils::cublas_handle, n, &alpha, X, incX)); - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice) { + CHECK_CUBLAS(cublasDscal(BlasUtils::cublas_handle, n, &alpha, X, incX)); + } #endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::scal( const int n, const std::complex alpha, std::complex *X, const int incX, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - cscal_(&n, &alpha, X, &incX); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + cscal_(&n, &alpha, X, &incX); + } #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice) { - CHECK_CUBLAS(cublasCscal(BlasUtils::cublas_handle, n, (float2*)&alpha, (float2*)X, incX)); - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice) { + CHECK_CUBLAS(cublasCscal(BlasUtils::cublas_handle, n, (float2*)&alpha, (float2*)X, incX)); + } #endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::scal( const int n, const std::complex alpha, std::complex *X, const int incX, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - zscal_(&n, &alpha, X, &incX); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + zscal_(&n, &alpha, X, &incX); + } #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice) { - CHECK_CUBLAS(cublasZscal(BlasUtils::cublas_handle, n, (double2*)&alpha, (double2*)X, incX)); - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice) { + CHECK_CUBLAS(cublasZscal(BlasUtils::cublas_handle, n, (double2*)&alpha, (double2*)X, incX)); + } #endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } // d=x*y float BlasConnector::dot( const int n, const float*const X, const int incX, const float*const Y, const int incY, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - return sdot_(&n, X, &incX, Y, &incY); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + return sdot_(&n, X, &incX, Y, &incY); + } #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice){ - float result = 0.0; - CHECK_CUBLAS(cublasSdot(BlasUtils::cublas_handle, n, X, incX, Y, incY, &result)); - return result; - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice){ + float result = 0.0; + CHECK_CUBLAS(cublasSdot(BlasUtils::cublas_handle, n, X, incX, Y, incY, &result)); + return result; + } #endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } double BlasConnector::dot( const int n, const double*const X, const int incX, const double*const Y, const int incY, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - return ddot_(&n, X, &incX, Y, &incY); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + return ddot_(&n, X, &incX, Y, &incY); + } #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice){ - double result = 0.0; - CHECK_CUBLAS(cublasDdot(BlasUtils::cublas_handle, n, X, incX, Y, incY, &result)); - return result; - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice){ + double result = 0.0; + CHECK_CUBLAS(cublasDdot(BlasUtils::cublas_handle, n, X, incX, Y, incY, &result)); + return result; + } #endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } // d=x*y float BlasConnector::dotu(const int n, const float*const X, const int incX, const float*const Y, const int incY, base_device::AbacusDevice_t device_type) { - return BlasConnector::dot(n, X, incX, Y, incY, device_type); + return BlasConnector::dot(n, X, incX, Y, incY, device_type); } double BlasConnector::dotu(const int n, const double*const X, const int incX, const double*const Y, const int incY, base_device::AbacusDevice_t device_type) { - return BlasConnector::dot(n, X, incX, Y, incY, device_type); + return BlasConnector::dot(n, X, incX, Y, incY, device_type); } std::complex BlasConnector::dotu(const int n, const std::complex*const X, const int incX, const std::complex*const Y, const int incY, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - const int incX2 = 2 * incX; - const int incY2 = 2 * incY; - const float*const x = reinterpret_cast(X); - const float*const y = reinterpret_cast(Y); - //Re(result)=Re(x)*Re(y)-Im(x)*Im(y) - //Im(result)=Re(x)*Im(y)+Im(x)*Re(y) - return std::complex( - BlasConnector::dot(n, x, incX2, y, incY2, device_type) - dot(n, x+1, incX2, y+1, incY2, device_type), - BlasConnector::dot(n, x, incX2, y+1, incY2, device_type) + dot(n, x+1, incX2, y, incY2, device_type)); - } - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + const int incX2 = 2 * incX; + const int incY2 = 2 * incY; + const float*const x = reinterpret_cast(X); + const float*const y = reinterpret_cast(Y); + //Re(result)=Re(x)*Re(y)-Im(x)*Im(y) + //Im(result)=Re(x)*Im(y)+Im(x)*Re(y) + return std::complex( + BlasConnector::dot(n, x, incX2, y, incY2, device_type) - dot(n, x+1, incX2, y+1, incY2, device_type), + BlasConnector::dot(n, x, incX2, y+1, incY2, device_type) + dot(n, x+1, incX2, y, incY2, device_type)); + } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } std::complex BlasConnector::dotu(const int n, const std::complex*const X, const int incX, const std::complex*const Y, const int incY, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - const int incX2 = 2 * incX; - const int incY2 = 2 * incY; - const double*const x = reinterpret_cast(X); - const double*const y = reinterpret_cast(Y); - //Re(result)=Re(x)*Re(y)-Im(x)*Im(y) - //Im(result)=Re(x)*Im(y)+Im(x)*Re(y) - return std::complex( - BlasConnector::dot(n, x, incX2, y, incY2, device_type) - dot(n, x+1, incX2, y+1, incY2, device_type), - BlasConnector::dot(n, x, incX2, y+1, incY2, device_type) + dot(n, x+1, incX2, y, incY2, device_type)); - } - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + const int incX2 = 2 * incX; + const int incY2 = 2 * incY; + const double*const x = reinterpret_cast(X); + const double*const y = reinterpret_cast(Y); + //Re(result)=Re(x)*Re(y)-Im(x)*Im(y) + //Im(result)=Re(x)*Im(y)+Im(x)*Re(y) + return std::complex( + BlasConnector::dot(n, x, incX2, y, incY2, device_type) - dot(n, x+1, incX2, y+1, incY2, device_type), + BlasConnector::dot(n, x, incX2, y+1, incY2, device_type) + dot(n, x+1, incX2, y, incY2, device_type)); + } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } // d = x.conj() * Vy float BlasConnector::dotc(const int n, const float*const X, const int incX, const float*const Y, const int incY, base_device::AbacusDevice_t device_type) { - return BlasConnector::dot(n, X, incX, Y, incY, device_type); + return BlasConnector::dot(n, X, incX, Y, incY, device_type); } double BlasConnector::dotc(const int n, const double*const X, const int incX, const double*const Y, const int incY, base_device::AbacusDevice_t device_type) { - return BlasConnector::dot(n, X, incX, Y, incY, device_type); + return BlasConnector::dot(n, X, incX, Y, incY, device_type); } std::complex BlasConnector::dotc(const int n, const std::complex*const X, const int incX, const std::complex*const Y, const int incY, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - const int incX2 = 2 * incX; - const int incY2 = 2 * incY; - const float*const x = reinterpret_cast(X); - const float*const y = reinterpret_cast(Y); - // Re(result)=Re(X)*Re(Y)+Im(X)*Im(Y) - // Im(result)=Re(X)*Im(Y)-Im(X)*Re(Y) - return std::complex( - BlasConnector::dot(n, x, incX2, y, incY2, device_type) + dot(n, x+1, incX2, y+1, incY2, device_type), - BlasConnector::dot(n, x, incX2, y+1, incY2, device_type) - dot(n, x+1, incX2, y, incY2, device_type)); - } - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + const int incX2 = 2 * incX; + const int incY2 = 2 * incY; + const float*const x = reinterpret_cast(X); + const float*const y = reinterpret_cast(Y); + // Re(result)=Re(X)*Re(Y)+Im(X)*Im(Y) + // Im(result)=Re(X)*Im(Y)-Im(X)*Re(Y) + return std::complex( + BlasConnector::dot(n, x, incX2, y, incY2, device_type) + dot(n, x+1, incX2, y+1, incY2, device_type), + BlasConnector::dot(n, x, incX2, y+1, incY2, device_type) - dot(n, x+1, incX2, y, incY2, device_type)); + } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } std::complex BlasConnector::dotc(const int n, const std::complex*const X, const int incX, const std::complex*const Y, const int incY, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - const int incX2 = 2 * incX; - const int incY2 = 2 * incY; - const double*const x = reinterpret_cast(X); - const double*const y = reinterpret_cast(Y); - // Re(result)=Re(X)*Re(Y)+Im(X)*Im(Y) - // Im(result)=Re(X)*Im(Y)-Im(X)*Re(Y) - return std::complex( - BlasConnector::dot(n, x, incX2, y, incY2, device_type) + dot(n, x+1, incX2, y+1, incY2, device_type), - BlasConnector::dot(n, x, incX2, y+1, incY2, device_type) - dot(n, x+1, incX2, y, incY2, device_type)); - } - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + const int incX2 = 2 * incX; + const int incY2 = 2 * incY; + const double*const x = reinterpret_cast(X); + const double*const y = reinterpret_cast(Y); + // Re(result)=Re(X)*Re(Y)+Im(X)*Im(Y) + // Im(result)=Re(X)*Im(Y)-Im(X)*Re(Y) + return std::complex( + BlasConnector::dot(n, x, incX2, y, incY2, device_type) + dot(n, x+1, incX2, y+1, incY2, device_type), + BlasConnector::dot(n, x, incX2, y+1, incY2, device_type) - dot(n, x+1, incX2, y, incY2, device_type)); + } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } // out = ||x||_2 float BlasConnector::nrm2( const int n, const float *X, const int incX, base_device::AbacusDevice_t device_type ) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - return snrm2_( &n, X, &incX ); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + return snrm2_( &n, X, &incX ); + } #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice){ - float result = 0.0; - CHECK_CUBLAS(cublasSnrm2(BlasUtils::cublas_handle, n, X, incX, &result)); - return result; - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice){ + float result = 0.0; + CHECK_CUBLAS(cublasSnrm2(BlasUtils::cublas_handle, n, X, incX, &result)); + return result; + } #endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } double BlasConnector::nrm2( const int n, const double *X, const int incX, base_device::AbacusDevice_t device_type ) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - return dnrm2_( &n, X, &incX ); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + return dnrm2_( &n, X, &incX ); + } #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice){ - double result = 0.0; - CHECK_CUBLAS(cublasDnrm2(BlasUtils::cublas_handle, n, X, incX, &result)); - return result; - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice){ + double result = 0.0; + CHECK_CUBLAS(cublasDnrm2(BlasUtils::cublas_handle, n, X, incX, &result)); + return result; + } #endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } double BlasConnector::nrm2( const int n, const std::complex *X, const int incX, base_device::AbacusDevice_t device_type ) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - return dznrm2_( &n, X, &incX ); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + return dznrm2_( &n, X, &incX ); + } #ifdef __CUDA - else if (device_type == base_device::AbacusDevice_t::GpuDevice){ - double result = 0.0; - CHECK_CUBLAS(cublasDznrm2(BlasUtils::cublas_handle, n, (double2*)X, incX, &result)); - return result; - } + else if (device_type == base_device::AbacusDevice_t::GpuDevice){ + double result = 0.0; + CHECK_CUBLAS(cublasDznrm2(BlasUtils::cublas_handle, n, (double2*)X, incX, &result)); + return result; + } #endif - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } // copies a into b void BlasConnector::copy(const int n, const float *a, const int incx, float *b, const int incy, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - scopy_(&n, a, &incx, b, &incy); - } - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + scopy_(&n, a, &incx, b, &incy); + } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::copy(const int n, const double *a, const int incx, double *b, const int incy, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - dcopy_(&n, a, &incx, b, &incy); - } - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + dcopy_(&n, a, &incx, b, &incy); + } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::copy(const int n, const std::complex *a, const int incx, std::complex *b, const int incy, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - ccopy_(&n, a, &incx, b, &incy); - } - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + ccopy_(&n, a, &incx, b, &incy); + } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } void BlasConnector::copy(const int n, const std::complex *a, const int incx, std::complex *b, const int incy, base_device::AbacusDevice_t device_type) { - if (device_type == base_device::AbacusDevice_t::CpuDevice) { - zcopy_(&n, a, &incx, b, &incy); - } - else { - throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } + if (device_type == base_device::AbacusDevice_t::CpuDevice) { + zcopy_(&n, a, &incx, b, &incy); + } + else { + throw std::invalid_argument("device_type = " + std::to_string(device_type) + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } } diff --git a/source/source_base/module_external/lapack_connector.h b/source/source_base/module_external/lapack_connector.h index c71e926eb84..ce381affe9f 100644 --- a/source/source_base/module_external/lapack_connector.h +++ b/source/source_base/module_external/lapack_connector.h @@ -439,29 +439,29 @@ namespace LapackConnector } } - // Peize Lin add 2015-12-27 - static inline - char change_uplo(const char &uplo) - { - switch(uplo) - { - case 'U': return 'L'; - case 'L': return 'U'; - default: throw std::invalid_argument("uplo must be 'U' or 'L'"); - } - } - - // Peize Lin add 2019-04-14 - static inline - char change_trans_NC(const char &trans) - { - switch(trans) - { - case 'N': return 'C'; - case 'C': return 'N'; - default: throw std::invalid_argument("trans must be 'N' or 'C'"); - } - } + // Peize Lin add 2015-12-27 + static inline + char change_uplo(const char &uplo) + { + switch(uplo) + { + case 'U': return 'L'; + case 'L': return 'U'; + default: throw std::invalid_argument("uplo must be 'U' or 'L'"); + } + } + + // Peize Lin add 2019-04-14 + static inline + char change_trans_NC(const char &trans) + { + switch(trans) + { + case 'N': return 'C'; + case 'C': return 'N'; + default: throw std::invalid_argument("trans must be 'N' or 'C'"); + } + } // wrap function of fortran lapack routine zheev. static inline @@ -504,95 +504,95 @@ namespace LapackConnector return; } - // Peize Lin add 2016-07-09 - static inline - void potrf( const char &uplo, const int &n, float*const A, const int &lda, int &info ) - { - const char uplo_changed = change_uplo(uplo); - spotrf_( &uplo_changed, &n, A, &lda, &info ); - } - static inline - void potrf( const char &uplo, const int &n, double*const A, const int &lda, int &info ) - { - const char uplo_changed = change_uplo(uplo); - dpotrf_( &uplo_changed, &n, A, &lda, &info ); - } - static inline - void potrf( const char &uplo, const int &n, std::complex*const A, const int &lda, int &info ) - { - const char uplo_changed = change_uplo(uplo); - cpotrf_( &uplo_changed, &n, A, &lda, &info ); - } - static inline - void potrf( const char &uplo, const int &n, std::complex*const A, const int &lda, int &info ) - { - const char uplo_changed = change_uplo(uplo); - zpotrf_( &uplo_changed, &n, A, &lda, &info ); - } - - - // Peize Lin add 2016-07-09 - static inline - void potri( const char &uplo, const int &n, float*const A, const int &lda, int &info ) - { - const char uplo_changed = change_uplo(uplo); - spotri_( &uplo_changed, &n, A, &lda, &info); - } - static inline - void potri( const char &uplo, const int &n, double*const A, const int &lda, int &info ) - { - const char uplo_changed = change_uplo(uplo); - dpotri_( &uplo_changed, &n, A, &lda, &info); - } - static inline - void potri( const char &uplo, const int &n, std::complex*const A, const int &lda, int &info ) - { - const char uplo_changed = change_uplo(uplo); - cpotri_( &uplo_changed, &n, A, &lda, &info); - } - static inline - void potri( const char &uplo, const int &n, std::complex*const A, const int &lda, int &info ) - { - const char uplo_changed = change_uplo(uplo); - zpotri_( &uplo_changed, &n, A, &lda, &info); - } - - // Peize Lin add 2016-07-09 - static inline - void potrf( const char &uplo, const int &n, ModuleBase::matrix &A, const int &lda, int &info ) - { - potrf( uplo, n, A.c, lda, info ); - } - static inline - void potrf( const char &uplo, const int &n, ModuleBase::ComplexMatrix &A, const int &lda, int &info ) - { - potrf( uplo, n, A.c, lda, info ); - } - - // Peize Lin add 2016-07-09 - static inline - void potri( const char &uplo, const int &n, ModuleBase::matrix &A, const int &lda, int &info ) - { - potri( uplo, n, A.c, lda, info); - } - static inline - void potri( const char &uplo, const int &n, ModuleBase::ComplexMatrix &A, const int &lda, int &info ) - { - potri( uplo, n, A.c, lda, info); - } - - // Peize Lin add 2019-04-14 - // if trans=='N': C = a * A * A.H + b * C - // if trans=='C': C = a * A.H * A + b * C - static inline + // Peize Lin add 2016-07-09 + static inline + void potrf( const char &uplo, const int &n, float*const A, const int &lda, int &info ) + { + const char uplo_changed = change_uplo(uplo); + spotrf_( &uplo_changed, &n, A, &lda, &info ); + } + static inline + void potrf( const char &uplo, const int &n, double*const A, const int &lda, int &info ) + { + const char uplo_changed = change_uplo(uplo); + dpotrf_( &uplo_changed, &n, A, &lda, &info ); + } + static inline + void potrf( const char &uplo, const int &n, std::complex*const A, const int &lda, int &info ) + { + const char uplo_changed = change_uplo(uplo); + cpotrf_( &uplo_changed, &n, A, &lda, &info ); + } + static inline + void potrf( const char &uplo, const int &n, std::complex*const A, const int &lda, int &info ) + { + const char uplo_changed = change_uplo(uplo); + zpotrf_( &uplo_changed, &n, A, &lda, &info ); + } + + + // Peize Lin add 2016-07-09 + static inline + void potri( const char &uplo, const int &n, float*const A, const int &lda, int &info ) + { + const char uplo_changed = change_uplo(uplo); + spotri_( &uplo_changed, &n, A, &lda, &info); + } + static inline + void potri( const char &uplo, const int &n, double*const A, const int &lda, int &info ) + { + const char uplo_changed = change_uplo(uplo); + dpotri_( &uplo_changed, &n, A, &lda, &info); + } + static inline + void potri( const char &uplo, const int &n, std::complex*const A, const int &lda, int &info ) + { + const char uplo_changed = change_uplo(uplo); + cpotri_( &uplo_changed, &n, A, &lda, &info); + } + static inline + void potri( const char &uplo, const int &n, std::complex*const A, const int &lda, int &info ) + { + const char uplo_changed = change_uplo(uplo); + zpotri_( &uplo_changed, &n, A, &lda, &info); + } + + // Peize Lin add 2016-07-09 + static inline + void potrf( const char &uplo, const int &n, ModuleBase::matrix &A, const int &lda, int &info ) + { + potrf( uplo, n, A.c, lda, info ); + } + static inline + void potrf( const char &uplo, const int &n, ModuleBase::ComplexMatrix &A, const int &lda, int &info ) + { + potrf( uplo, n, A.c, lda, info ); + } + + // Peize Lin add 2016-07-09 + static inline + void potri( const char &uplo, const int &n, ModuleBase::matrix &A, const int &lda, int &info ) + { + potri( uplo, n, A.c, lda, info); + } + static inline + void potri( const char &uplo, const int &n, ModuleBase::ComplexMatrix &A, const int &lda, int &info ) + { + potri( uplo, n, A.c, lda, info); + } + + // Peize Lin add 2019-04-14 + // if trans=='N': C = a * A * A.H + b * C + // if trans=='C': C = a * A.H * A + b * C + static inline void herk(const char uplo, const char trans, const int n, const int k, - const double alpha, const std::complex *A, const int lda, - const double beta, std::complex *C, const int ldc) - { - const char uplo_changed = change_uplo(uplo); - const char trans_changed = change_trans_NC(trans); - zherk_(&uplo_changed, &trans_changed, &n, &k, &alpha, A, &lda, &beta, C, &ldc); - } + const double alpha, const std::complex *A, const int lda, + const double beta, std::complex *C, const int ldc) + { + const char uplo_changed = change_uplo(uplo); + const char trans_changed = change_trans_NC(trans); + zherk_(&uplo_changed, &trans_changed, &n, &k, &alpha, A, &lda, &beta, C, &ldc); + } static inline void herk(const char uplo, const char trans, const int n, const int k, const float alpha, const std::complex* A, const int lda, diff --git a/source/source_base/module_external/scalapack_connector.h b/source/source_base/module_external/scalapack_connector.h index a6e2ef5ea44..35673385b67 100644 --- a/source/source_base/module_external/scalapack_connector.h +++ b/source/source_base/module_external/scalapack_connector.h @@ -24,243 +24,243 @@ extern "C" { - int numroc_( const int *n, const int *nb, const int *iproc, const int *srcproc, const int *nprocs ); - void descinit_( - int *desc, - const int *m, const int *n, const int *mb, const int *nb, const int *irsrc, const int *icsrc, - const int *ictxt, const int *lld, int *info); - - void pddot_(int* n, double* dot, double* x, int* ix, int* jx, int* descx, int* incx, - double* y, int* iy, int* jy, int* descy, int* incy); - void pzdotc_(int* n, std::complex* dot, std::complex* x, int* ix, int* jx, int* descx, int* incx, - std::complex* y, int* iy, int* jy, int* descy, int* incy); - - void pdpotrf_(char *uplo, int *n, double *a, int *ia, int *ja, int *desca, int *info); + int numroc_( const int *n, const int *nb, const int *iproc, const int *srcproc, const int *nprocs ); + void descinit_( + int *desc, + const int *m, const int *n, const int *mb, const int *nb, const int *irsrc, const int *icsrc, + const int *ictxt, const int *lld, int *info); + + void pddot_(int* n, double* dot, double* x, int* ix, int* jx, int* descx, int* incx, + double* y, int* iy, int* jy, int* descy, int* incy); + void pzdotc_(int* n, std::complex* dot, std::complex* x, int* ix, int* jx, int* descx, int* incx, + std::complex* y, int* iy, int* jy, int* descy, int* incy); + + void pdpotrf_(char *uplo, int *n, double *a, int *ia, int *ja, int *desca, int *info); // void pzpotrf_(char *uplo, int *n, double _Complex *a, int *ia, int *ja, int *desca, int *info); - void pzpotrf_(char *uplo, int *n, std::complex *a, int *ia, int *ja, int *desca, int *info); + void pzpotrf_(char *uplo, int *n, std::complex *a, int *ia, int *ja, int *desca, int *info); void pdtran_(const int* m, const int* n, const double* alpha, const double* a, const int* ia, const int* ja, const int* desca, const double* beta, double* c, const int* ic, const int* jc, const int* descc); - void pztranu_(const int *m,const int*n, + void pztranu_(const int *m,const int*n, const std::complex* alpha, const std::complex* a, const int* ia, const int* ja, const int* desca, - const std::complex *beta , std::complex *c, const int *ic, const int *jc, const int *descc); - void pztranc_(const int *m, const int *n, - const std::complex *alpha, const std::complex *a, const int *ia, const int *ja, const int *desca, - const std::complex *beta, std::complex *c, const int *ic, const int *jc, const int *descc); - - double pdlange_(const char* norm, - const int* m, const int* n, - const double* a, const int* ia, const int* ja, const int* desca, - double* work); - - double pzlange_(const char* norm, - const int* m, const int* n, - const std::complex* a, const int* ia, const int* ja, const int* desca, - double* work); - - void pzgemv_( - const char *transa, - const int *M, const int *N, - const double *alpha, - const std::complex *A, const int *IA, const int *JA, const int *DESCA, - const std::complex *B, const int *IB, const int *JB, const int *DESCB, const int *K, - const double *beta, std::complex *C, const int *IC, const int *JC, const int *DESCC,const int *L); - void pdgemv_( - const char *transa, - const int *M, const int *N, - const double *alpha, - const double *A, const int *IA, const int *JA, const int *DESCA, - const double *B, const int *IB, const int *JB, const int *DESCB, const int *K, - const double *beta, double *C, const int *IC, const int *JC, const int *DESCC,const int *L); - // C = a * A.? * B.? + b * C - void pdgemm_( - const char *transa, const char *transb, - const int *M, const int *N, const int *K, - const double *alpha, - const double *A, const int *IA, const int *JA, const int *DESCA, - const double *B, const int *IB, const int *JB, const int *DESCB, - const double *beta, - double *C, const int *IC, const int *JC, const int *DESCC); - void pzgemm_( - const char *transa, const char *transb, - const int *M, const int *N, const int *K, - const std::complex *alpha, - const std::complex *A, const int *IA, const int *JA, const int *DESCA, - const std::complex *B, const int *IB, const int *JB, const int *DESCB, - const std::complex *beta, - std::complex *C, const int *IC, const int *JC, const int *DESCC); - void pdsymm_(char *side , char *uplo , int *m , int *n , - double *alpha , double *a , int *ia , int *ja , int *desca , - double *b , int *ib , int *jb , int *descb , - double *beta , double *c , int *ic , int *jc , int *descc ); - void pdtrmm_(char *side , char *uplo , char *transa , char *diag , int *m , int *n , - double *alpha , double *a , int *ia , int *ja , int *desca , - double *b , int *ib , int *jb , int *descb ); + const std::complex *beta , std::complex *c, const int *ic, const int *jc, const int *descc); + void pztranc_(const int *m, const int *n, + const std::complex *alpha, const std::complex *a, const int *ia, const int *ja, const int *desca, + const std::complex *beta, std::complex *c, const int *ic, const int *jc, const int *descc); + + double pdlange_(const char* norm, + const int* m, const int* n, + const double* a, const int* ia, const int* ja, const int* desca, + double* work); + + double pzlange_(const char* norm, + const int* m, const int* n, + const std::complex* a, const int* ia, const int* ja, const int* desca, + double* work); + + void pzgemv_( + const char *transa, + const int *M, const int *N, + const double *alpha, + const std::complex *A, const int *IA, const int *JA, const int *DESCA, + const std::complex *B, const int *IB, const int *JB, const int *DESCB, const int *K, + const double *beta, std::complex *C, const int *IC, const int *JC, const int *DESCC,const int *L); + void pdgemv_( + const char *transa, + const int *M, const int *N, + const double *alpha, + const double *A, const int *IA, const int *JA, const int *DESCA, + const double *B, const int *IB, const int *JB, const int *DESCB, const int *K, + const double *beta, double *C, const int *IC, const int *JC, const int *DESCC,const int *L); + // C = a * A.? * B.? + b * C + void pdgemm_( + const char *transa, const char *transb, + const int *M, const int *N, const int *K, + const double *alpha, + const double *A, const int *IA, const int *JA, const int *DESCA, + const double *B, const int *IB, const int *JB, const int *DESCB, + const double *beta, + double *C, const int *IC, const int *JC, const int *DESCC); + void pzgemm_( + const char *transa, const char *transb, + const int *M, const int *N, const int *K, + const std::complex *alpha, + const std::complex *A, const int *IA, const int *JA, const int *DESCA, + const std::complex *B, const int *IB, const int *JB, const int *DESCB, + const std::complex *beta, + std::complex *C, const int *IC, const int *JC, const int *DESCC); + void pdsymm_(char *side , char *uplo , int *m , int *n , + double *alpha , double *a , int *ia , int *ja , int *desca , + double *b , int *ib , int *jb , int *descb , + double *beta , double *c , int *ic , int *jc , int *descc ); + void pdtrmm_(char *side , char *uplo , char *transa , char *diag , int *m , int *n , + double *alpha , double *a , int *ia , int *ja , int *desca , + double *b , int *ib , int *jb , int *descb ); // void pztrmm_(char *side , char *uplo , char *transa , char *diag , int *m , int *n , // double *alpha , double _Complex *a , int *ia , int *ja , int *desca , // double _Complex *b , int *ib , int *jb , int *descb ); - void pztrmm_(char *side , char *uplo , char *transa , char *diag , int *m , int *n , - std::complex *alpha , std::complex *a , int *ia , int *ja , int *desca , - std::complex *b , int *ib , int *jb , int *descb ); - void pzhemm_(char* side , char* uplo , int* m , int* n , - std::complex* alpha , std::complex* a , int* ia , int* ja , int* desca , - std::complex* b , int* ib , int* jb , int* descb , - std::complex* beta , std::complex* c , int* ic , int* jc , int* descc ); - void pzgetrf_( - const int *M, const int *N, - std::complex *A, const int *IA, const int *JA, const int *DESCA, - int *ipiv, int *info); - - void pzgesv_( - const int *n, const int *nrhs, - const std::complex *A, const int *ia, const int *ja, const int *desca, - int *ipiv, std::complex* B, const int* ib, const int* jb, const int*descb, const int *info - ); - - void pdsygvx_(const int* itype, const char* jobz, const char* range, const char* uplo, - const int* n, double* A, const int* ia, const int* ja, const int*desca, double* B, const int* ib, const int* jb, const int*descb, - const double* vl, const double* vu, const int* il, const int* iu, - const double* abstol, int* m, int* nz, double* w, const double*orfac, double* Z, const int* iz, const int* jz, const int*descz, - double* work, int* lwork, int*iwork, int*liwork, int* ifail, int*iclustr, double*gap, int* info); - - void pzhegvx_(const int* itype, const char* jobz, const char* range, const char* uplo, - const int* n, std::complex* A, const int* ia, const int* ja, const int*desca, std::complex* B, const int* ib, const int* jb, const int*descb, - const double* vl, const double* vu, const int* il, const int* iu, - const double* abstol, int* m, int* nz, double* w, const double*orfac, std::complex* Z, const int* iz, const int* jz, const int*descz, - std::complex* work, int* lwork, double* rwork, int* lrwork, int*iwork, int*liwork, int* ifail, int*iclustr, double*gap, int* info); - - void pssygvx_(const int* itype, const char* jobz, const char* range, const char* uplo, - const int* n, float* A, const int* ia, const int* ja, const int*desca, float* B, const int* ib, const int* jb, const int*descb, - const float* vl, const float* vu, const int* il, const int* iu, - const float* abstol, int* m, int* nz, float* w, const float*orfac, float* Z, const int* iz, const int* jz, const int*descz, - float* work, int* lwork, int*iwork, int*liwork, int* ifail, int*iclustr, float*gap, int* info); - - void pchegvx_(const int* itype, const char* jobz, const char* range, const char* uplo, - const int* n, std::complex* A, const int* ia, const int* ja, const int*desca, std::complex* B, const int* ib, const int* jb, const int*descb, - const float* vl, const float* vu, const int* il, const int* iu, - const float* abstol, int* m, int* nz, float* w, const float*orfac, std::complex* Z, const int* iz, const int* jz, const int*descz, - std::complex* work, int* lwork, float* rwork, int* lrwork, int*iwork, int*liwork, int* ifail, int*iclustr, float*gap, int* info); - - - void pzgetri_( - const int *n, - const std::complex *A, const int *ia, const int *ja, const int *desca, - int *ipiv, const std::complex *work, const int *lwork, const int *iwork, const int *liwork, const int *info); + void pztrmm_(char *side , char *uplo , char *transa , char *diag , int *m , int *n , + std::complex *alpha , std::complex *a , int *ia , int *ja , int *desca , + std::complex *b , int *ib , int *jb , int *descb ); + void pzhemm_(char* side , char* uplo , int* m , int* n , + std::complex* alpha , std::complex* a , int* ia , int* ja , int* desca , + std::complex* b , int* ib , int* jb , int* descb , + std::complex* beta , std::complex* c , int* ic , int* jc , int* descc ); + void pzgetrf_( + const int *M, const int *N, + std::complex *A, const int *IA, const int *JA, const int *DESCA, + int *ipiv, int *info); + + void pzgesv_( + const int *n, const int *nrhs, + const std::complex *A, const int *ia, const int *ja, const int *desca, + int *ipiv, std::complex* B, const int* ib, const int* jb, const int*descb, const int *info + ); + + void pdsygvx_(const int* itype, const char* jobz, const char* range, const char* uplo, + const int* n, double* A, const int* ia, const int* ja, const int*desca, double* B, const int* ib, const int* jb, const int*descb, + const double* vl, const double* vu, const int* il, const int* iu, + const double* abstol, int* m, int* nz, double* w, const double*orfac, double* Z, const int* iz, const int* jz, const int*descz, + double* work, int* lwork, int*iwork, int*liwork, int* ifail, int*iclustr, double*gap, int* info); + + void pzhegvx_(const int* itype, const char* jobz, const char* range, const char* uplo, + const int* n, std::complex* A, const int* ia, const int* ja, const int*desca, std::complex* B, const int* ib, const int* jb, const int*descb, + const double* vl, const double* vu, const int* il, const int* iu, + const double* abstol, int* m, int* nz, double* w, const double*orfac, std::complex* Z, const int* iz, const int* jz, const int*descz, + std::complex* work, int* lwork, double* rwork, int* lrwork, int*iwork, int*liwork, int* ifail, int*iclustr, double*gap, int* info); + + void pssygvx_(const int* itype, const char* jobz, const char* range, const char* uplo, + const int* n, float* A, const int* ia, const int* ja, const int*desca, float* B, const int* ib, const int* jb, const int*descb, + const float* vl, const float* vu, const int* il, const int* iu, + const float* abstol, int* m, int* nz, float* w, const float*orfac, float* Z, const int* iz, const int* jz, const int*descz, + float* work, int* lwork, int*iwork, int*liwork, int* ifail, int*iclustr, float*gap, int* info); + + void pchegvx_(const int* itype, const char* jobz, const char* range, const char* uplo, + const int* n, std::complex* A, const int* ia, const int* ja, const int*desca, std::complex* B, const int* ib, const int* jb, const int*descb, + const float* vl, const float* vu, const int* il, const int* iu, + const float* abstol, int* m, int* nz, float* w, const float*orfac, std::complex* Z, const int* iz, const int* jz, const int*descz, + std::complex* work, int* lwork, float* rwork, int* lrwork, int*iwork, int*liwork, int* ifail, int*iclustr, float*gap, int* info); + + + void pzgetri_( + const int *n, + const std::complex *A, const int *ia, const int *ja, const int *desca, + int *ipiv, const std::complex *work, const int *lwork, const int *iwork, const int *liwork, const int *info); void pzgeadd_( - const char *transa, - const int *m, const int *n, - const std::complex *alpha, - const std::complex *a, const int *ia, const int *ja, const int *desca, - const std::complex *beta, - const std::complex *c, const int *ic, const int *jc, const int *descc); + const char *transa, + const int *m, const int *n, + const std::complex *alpha, + const std::complex *a, const int *ia, const int *ja, const int *desca, + const std::complex *beta, + const std::complex *c, const int *ic, const int *jc, const int *descc); void pdgemr2d_(const int *M, const int *N, - double *A, const int *IA, const int *JA, const int *DESCA, - double *B, const int *IB, const int *JB, const int *DESCB, - const int *ICTXT); - + double *A, const int *IA, const int *JA, const int *DESCA, + double *B, const int *IB, const int *JB, const int *DESCB, + const int *ICTXT); + void pzgemr2d_(const int *M, const int *N, - std::complex *A, const int *IA, const int *JA, const int *DESCA, - std::complex *B, const int *IB, const int *JB, const int *DESCB, - const int *ICTXT); - - // Scalapack wrappers to copy 2D blocks of data - // more info: - // https://netlib.org/scalapack/explore-html/da/db5/pigemr_8c.html - // https://netlib.org/scalapack/explore-html/dd/dcd/pdgemr_8c.html - // https://netlib.org/scalapack/explore-html/d5/dd4/pzgemr_8c.html - // https://netlib.org/scalapack/explore-html/d5/deb/psgemr_8c.html - // https://netlib.org/scalapack/explore-html/d4/dad/pcgemr_8c.html - void Cpigemr2d (int m, int n, int *ptrmyblock, int ia, int ja, int *ma, int *ptrmynewblock, int ib, int jb, int *mb, int globcontext); - void Cpdgemr2d (int m, int n, double *ptrmyblock, int ia, int ja, int *ma, double *ptrmynewblock, int ib, int jb, int *mb, int globcontext); - void Cpzgemr2d (int m, int n, std::complex *ptrmyblock, int ia, int ja, int *ma, std::complex *ptrmynewblock, int ib, int jb, int *mb, int globcontext); - void Cpsgemr2d (int m, int n, float *ptrmyblock, int ia, int ja, int *ma, float *ptrmynewblock, int ib, int jb, int *mb, int globcontext); - void Cpcgemr2d (int m, int n, std::complex *ptrmyblock, int ia, int ja, int *ma, std::complex *ptrmynewblock, int ib, int jb, int *mb, int globcontext); + std::complex *A, const int *IA, const int *JA, const int *DESCA, + std::complex *B, const int *IB, const int *JB, const int *DESCB, + const int *ICTXT); + + // Scalapack wrappers to copy 2D blocks of data + // more info: + // https://netlib.org/scalapack/explore-html/da/db5/pigemr_8c.html + // https://netlib.org/scalapack/explore-html/dd/dcd/pdgemr_8c.html + // https://netlib.org/scalapack/explore-html/d5/dd4/pzgemr_8c.html + // https://netlib.org/scalapack/explore-html/d5/deb/psgemr_8c.html + // https://netlib.org/scalapack/explore-html/d4/dad/pcgemr_8c.html + void Cpigemr2d (int m, int n, int *ptrmyblock, int ia, int ja, int *ma, int *ptrmynewblock, int ib, int jb, int *mb, int globcontext); + void Cpdgemr2d (int m, int n, double *ptrmyblock, int ia, int ja, int *ma, double *ptrmynewblock, int ib, int jb, int *mb, int globcontext); + void Cpzgemr2d (int m, int n, std::complex *ptrmyblock, int ia, int ja, int *ma, std::complex *ptrmynewblock, int ib, int jb, int *mb, int globcontext); + void Cpsgemr2d (int m, int n, float *ptrmyblock, int ia, int ja, int *ma, float *ptrmynewblock, int ib, int jb, int *mb, int globcontext); + void Cpcgemr2d (int m, int n, std::complex *ptrmyblock, int ia, int ja, int *ma, std::complex *ptrmynewblock, int ib, int jb, int *mb, int globcontext); } - template - struct block2d_data_type - { - constexpr static bool value = std::is_same::value || std::is_same>::value || std::is_same::value || std::is_same>::value || std::is_same::value; - }; - - - /** - * Copies a 2D block of data from matrix A to matrix B using the Scalapack library. - * This function supports different data types: double, std::complex, float, std::complex, and int. - * - * @tparam T The data type of the matrices A and B. - * @param M The number of rows of matrix A. - * @param N The number of columns of matrix A. - * @param A Pointer to the source matrix A. - * @param IA The starting row index of the block in matrix A. - * @param JA The starting column index of the block in matrix A. - * @param DESCA Descriptor array for matrix A. - * @param B Pointer to the destination matrix B. - * @param IB The starting row index of the block in matrix B. - * @param JB The starting column index of the block in matrix B. - * @param DESCB Descriptor array for matrix B. - * @param ICTXT The context identifier. - */ - template - typename std::enable_if::value,void>::type Cpxgemr2d(int M, int N, T *A, int IA, int JA, int *DESCA, T *B, int IB, int JB, int *DESCB, int ICTXT) - { - if (std::is_same::value) Cpdgemr2d(M, N, reinterpret_cast(A),IA, JA, DESCA,reinterpret_cast(B),IB,JB, DESCB,ICTXT); - if (std::is_same>::value) Cpzgemr2d(M, N, reinterpret_cast*>(A),IA, JA, DESCA,reinterpret_cast*>(B),IB,JB, DESCB,ICTXT); - if (std::is_same::value) Cpsgemr2d(M, N, reinterpret_cast(A),IA, JA, DESCA,reinterpret_cast(B),IB,JB, DESCB,ICTXT); - if (std::is_same>::value) Cpcgemr2d(M, N, reinterpret_cast*>(A),IA, JA, DESCA,reinterpret_cast*>(B),IB,JB, DESCB,ICTXT); - if (std::is_same::value) Cpigemr2d(M, N, reinterpret_cast(A),IA, JA, DESCA,reinterpret_cast(B),IB,JB, DESCB,ICTXT); - }; - + template + struct block2d_data_type + { + constexpr static bool value = std::is_same::value || std::is_same>::value || std::is_same::value || std::is_same>::value || std::is_same::value; + }; + + + /** + * Copies a 2D block of data from matrix A to matrix B using the Scalapack library. + * This function supports different data types: double, std::complex, float, std::complex, and int. + * + * @tparam T The data type of the matrices A and B. + * @param M The number of rows of matrix A. + * @param N The number of columns of matrix A. + * @param A Pointer to the source matrix A. + * @param IA The starting row index of the block in matrix A. + * @param JA The starting column index of the block in matrix A. + * @param DESCA Descriptor array for matrix A. + * @param B Pointer to the destination matrix B. + * @param IB The starting row index of the block in matrix B. + * @param JB The starting column index of the block in matrix B. + * @param DESCB Descriptor array for matrix B. + * @param ICTXT The context identifier. + */ + template + typename std::enable_if::value,void>::type Cpxgemr2d(int M, int N, T *A, int IA, int JA, int *DESCA, T *B, int IB, int JB, int *DESCB, int ICTXT) + { + if (std::is_same::value) Cpdgemr2d(M, N, reinterpret_cast(A),IA, JA, DESCA,reinterpret_cast(B),IB,JB, DESCB,ICTXT); + if (std::is_same>::value) Cpzgemr2d(M, N, reinterpret_cast*>(A),IA, JA, DESCA,reinterpret_cast*>(B),IB,JB, DESCB,ICTXT); + if (std::is_same::value) Cpsgemr2d(M, N, reinterpret_cast(A),IA, JA, DESCA,reinterpret_cast(B),IB,JB, DESCB,ICTXT); + if (std::is_same>::value) Cpcgemr2d(M, N, reinterpret_cast*>(A),IA, JA, DESCA,reinterpret_cast*>(B),IB,JB, DESCB,ICTXT); + if (std::is_same::value) Cpigemr2d(M, N, reinterpret_cast(A),IA, JA, DESCA,reinterpret_cast(B),IB,JB, DESCB,ICTXT); + }; + class ScalapackConnector { public: - static inline - void geadd( - const char transa, - const int m, const int n, - const std::complex alpha, - const std::complex *a, const int ia, const int ja, const int *desca, - const std::complex beta, - const std::complex *c, const int ic, const int jc, const int *descc) - { - pzgeadd_(&transa, &m, &n, &alpha, a, &ia, &ja, desca, &beta, c, &ic, &jc, descc); - } - - static inline - void dot(int n, - double& dot, - double* a, - int ia, - int ja, - int inca, - double* b, - int ib, - int jb, - int incb, - int* desc) - { - pddot_(&n, &dot, a, &ia, &ja, desc, &inca, b, &ib, &jb, desc, &incb); - } - - static inline - void dot(int n, - std::complex& dotc, - std::complex* a, - int ia, - int ja, - int inca, - std::complex* b, - int ib, - int jb, - int incb, - int* desc) - { - pzdotc_(&n, &dotc, a, &ia, &ja, desc, &inca, b, &ib, &jb, desc, &incb); - } + static inline + void geadd( + const char transa, + const int m, const int n, + const std::complex alpha, + const std::complex *a, const int ia, const int ja, const int *desca, + const std::complex beta, + const std::complex *c, const int ic, const int jc, const int *descc) + { + pzgeadd_(&transa, &m, &n, &alpha, a, &ia, &ja, desca, &beta, c, &ic, &jc, descc); + } + + static inline + void dot(int n, + double& dot, + double* a, + int ia, + int ja, + int inca, + double* b, + int ib, + int jb, + int incb, + int* desc) + { + pddot_(&n, &dot, a, &ia, &ja, desc, &inca, b, &ib, &jb, desc, &incb); + } + + static inline + void dot(int n, + std::complex& dotc, + std::complex* a, + int ia, + int ja, + int inca, + std::complex* b, + int ib, + int jb, + int incb, + int* desc) + { + pzdotc_(&n, &dotc, a, &ia, &ja, desc, &inca, b, &ib, &jb, desc, &incb); + } static inline void gemm( @@ -277,157 +277,157 @@ class ScalapackConnector } static inline - void gemm( - const char transa, const char transb, - const int M, const int N, const int K, - const std::complex alpha, - const std::complex *A, const int IA, const int JA, const int *DESCA, - const std::complex *B, const int IB, const int JB, const int *DESCB, - const std::complex beta, - std::complex *C, const int IC, const int JC, const int *DESCC) - { - pzgemm_(&transa, &transb, &M, &N, &K, &alpha, A, &IA, &JA, DESCA, - B, &IB, &JB, DESCB, &beta, C, &IC, &JC, DESCC); - } - - static inline - void gemm(char transa, char transb, int M, int N, int K, - double alpha, - double* A, - double* B, - double beta, - double* C, - int* DESC) - { - int isrc = 1; - pdgemm_(&transa, - &transb, - &M, - &N, - &K, - &alpha, - A, - &isrc, - &isrc, - DESC, - B, - &isrc, - &isrc, - DESC, - &beta, - C, - &isrc, - &isrc, - DESC); - } + void gemm( + const char transa, const char transb, + const int M, const int N, const int K, + const std::complex alpha, + const std::complex *A, const int IA, const int JA, const int *DESCA, + const std::complex *B, const int IB, const int JB, const int *DESCB, + const std::complex beta, + std::complex *C, const int IC, const int JC, const int *DESCC) + { + pzgemm_(&transa, &transb, &M, &N, &K, &alpha, A, &IA, &JA, DESCA, + B, &IB, &JB, DESCB, &beta, C, &IC, &JC, DESCC); + } + + static inline + void gemm(char transa, char transb, int M, int N, int K, + double alpha, + double* A, + double* B, + double beta, + double* C, + int* DESC) + { + int isrc = 1; + pdgemm_(&transa, + &transb, + &M, + &N, + &K, + &alpha, + A, + &isrc, + &isrc, + DESC, + B, + &isrc, + &isrc, + DESC, + &beta, + C, + &isrc, + &isrc, + DESC); + } + + static inline + void gemm(char transa, char transb, int M, int N, int K, + std::complex alpha, + std::complex* A, + std::complex* B, + std::complex beta, + std::complex* C, + int* DESC) + { + + int isrc = 1; + pzgemm_(&transa, + &transb, + &M, + &N, + &K, + &alpha, + A, + &isrc, + &isrc, + DESC, + B, + &isrc, + &isrc, + DESC, + &beta, + C, + &isrc, + &isrc, + DESC); + } + + static inline + void symm(char side, + char uplo, + int m, + int n, + double alpha, + double* a, + double* b, + double beta, + double* c, + int* desc) + { + int isrc = 1; + pdsymm_(&side, &uplo, &m, &n, &alpha, a, &isrc, &isrc, desc, b, &isrc, &isrc, desc, &beta, c, &isrc, &isrc, desc); + } + + static inline + void getrf( + const int M, const int N, + std::complex *A, const int IA, const int JA, const int *DESCA, + int *ipiv, int *info) //fix a bug: info is output and we must use int* + { + pzgetrf_(&M, &N, A, &IA, &JA, DESCA, ipiv, info); + } + + static inline + void getri( + const int n, + const std::complex *A, const int ia, const int ja, const int *desca, int *ipiv, + const std::complex *work, const int *lwork, const int *iwork, const int *liwork, int *info) + { + pzgetri_(&n, A, &ia, &ja, desca, ipiv, work, lwork, iwork, liwork, info); + } static inline - void gemm(char transa, char transb, int M, int N, int K, - std::complex alpha, - std::complex* A, - std::complex* B, - std::complex beta, - std::complex* C, - int* DESC) - { - - int isrc = 1; - pzgemm_(&transa, - &transb, - &M, - &N, - &K, - &alpha, - A, - &isrc, - &isrc, - DESC, - B, - &isrc, - &isrc, - DESC, - &beta, - C, - &isrc, - &isrc, - DESC); - } - - static inline - void symm(char side, - char uplo, - int m, - int n, - double alpha, - double* a, - double* b, - double beta, - double* c, - int* desc) - { - int isrc = 1; - pdsymm_(&side, &uplo, &m, &n, &alpha, a, &isrc, &isrc, desc, b, &isrc, &isrc, desc, &beta, c, &isrc, &isrc, desc); - } + void gesv( + const int n, const int nrhs, + const std::complex *A, const int ia, const int ja, const int *desca, + int *ipiv, std::complex* B, const int ib, const int jb, const int*descb, int *info) + { + pzgesv_(&n, &nrhs, A, &ia, &ja, desca, ipiv, B, &ib, &jb, descb, info); + } static inline - void getrf( - const int M, const int N, - std::complex *A, const int IA, const int JA, const int *DESCA, - int *ipiv, int *info) //fix a bug: info is output and we must use int* - { - pzgetrf_(&M, &N, A, &IA, &JA, DESCA, ipiv, info); - } - - static inline - void getri( - const int n, - const std::complex *A, const int ia, const int ja, const int *desca, int *ipiv, - const std::complex *work, const int *lwork, const int *iwork, const int *liwork, int *info) - { - pzgetri_(&n, A, &ia, &ja, desca, ipiv, work, lwork, iwork, liwork, info); - } - - static inline - void gesv( - const int n, const int nrhs, - const std::complex *A, const int ia, const int ja, const int *desca, - int *ipiv, std::complex* B, const int ib, const int jb, const int*descb, int *info) - { - pzgesv_(&n, &nrhs, A, &ia, &ja, desca, ipiv, B, &ib, &jb, descb, info); - } - - static inline - void tranu( - const int m, const int n, - const double alpha, double *a, const int ia, const int ja, const int *desca, - const double beta, double *c, const int ic, const int jc, const int *descc) - { - pdtran_(&m, &n, &alpha, a, &ia, &ja, desca, &beta, c, &ic, &jc, descc); - } - static inline - void tranu( - const int m, const int n, - const std::complex alpha, std::complex *a, const int ia, const int ja, const int *desca, - const std::complex beta, std::complex *c, const int ic, const int jc, const int *descc) - { - pztranu_(&m, &n, &alpha, a, &ia, &ja, desca, &beta, c, &ic, &jc, descc); - } - static inline - void tranc( - const int m, const int n, - const double alpha, double *a, const int ia, const int ja, const int *desca, - const double beta, double *c, const int ic, const int jc, const int *descc) - { - pdtran_(&m, &n, &alpha, a, &ia, &ja, desca, &beta, c, &ic, &jc, descc); - } - static inline - void tranc( - const int m, const int n, - const std::complex alpha, std::complex *a, const int ia, const int ja, const int *desca, - const std::complex beta, std::complex *c, const int ic, const int jc, const int *descc) - { - pztranc_(&m, &n, &alpha, a, &ia, &ja, desca, &beta, c, &ic, &jc, descc); - } + void tranu( + const int m, const int n, + const double alpha, double *a, const int ia, const int ja, const int *desca, + const double beta, double *c, const int ic, const int jc, const int *descc) + { + pdtran_(&m, &n, &alpha, a, &ia, &ja, desca, &beta, c, &ic, &jc, descc); + } + static inline + void tranu( + const int m, const int n, + const std::complex alpha, std::complex *a, const int ia, const int ja, const int *desca, + const std::complex beta, std::complex *c, const int ic, const int jc, const int *descc) + { + pztranu_(&m, &n, &alpha, a, &ia, &ja, desca, &beta, c, &ic, &jc, descc); + } + static inline + void tranc( + const int m, const int n, + const double alpha, double *a, const int ia, const int ja, const int *desca, + const double beta, double *c, const int ic, const int jc, const int *descc) + { + pdtran_(&m, &n, &alpha, a, &ia, &ja, desca, &beta, c, &ic, &jc, descc); + } + static inline + void tranc( + const int m, const int n, + const std::complex alpha, std::complex *a, const int ia, const int ja, const int *desca, + const std::complex beta, std::complex *c, const int ic, const int jc, const int *descc) + { + pztranc_(&m, &n, &alpha, a, &ia, &ja, desca, &beta, c, &ic, &jc, descc); + } static inline double lange( @@ -448,87 +448,87 @@ class ScalapackConnector return pzlange_(&norm, &m, &n, a, &ia, &ja, desca, work); } - static inline - int potrf(char uplo, int na, double* U, int* desc) - { - int isrc = 1; - int info; - pdpotrf_(&uplo, &na, U, &isrc, &isrc, desc, &info); - return info; - } - - static inline - int potrf(char uplo, int na, std::complex* U, int* desc) - { - int isrc = 1; - int info; - pzpotrf_(&uplo, &na, U, &isrc, &isrc, desc, &info); - return info; - } - - static inline - void trmm(char side, - char uplo, - char trans, - char diag, - int m, - int n, - double alpha, - double* a, - double* b, - int* desc) - { - int isrc = 1; - pdtrmm_(&side, &uplo, &trans, &diag, &m, &n, &alpha, a, &isrc, &isrc, desc, b, &isrc, &isrc, desc); - } - - static inline - void trmm(char side, - char uplo, - char trans, - char diag, - int m, - int n, - std::complex alpha, - std::complex* a, - std::complex* b, - int* desc) - { - int isrc = 1; - pztrmm_(&side, &uplo, &trans, &diag, &m, &n, &alpha, a, &isrc, &isrc, desc, b, &isrc, &isrc, desc); - } - - static inline - void hemm(char side, - char uplo, - int na, - std::complex alpha, - std::complex* a, - std::complex* b, - std::complex beta, - std::complex* c, - int* desc) - { - int isrc = 1; - pzhemm_(&side, - &uplo, - &na, - &na, - &alpha, - a, - &isrc, - &isrc, - desc, - b, - &isrc, - &isrc, - desc, - &beta, - c, - &isrc, - &isrc, - desc); - } + static inline + int potrf(char uplo, int na, double* U, int* desc) + { + int isrc = 1; + int info; + pdpotrf_(&uplo, &na, U, &isrc, &isrc, desc, &info); + return info; + } + + static inline + int potrf(char uplo, int na, std::complex* U, int* desc) + { + int isrc = 1; + int info; + pzpotrf_(&uplo, &na, U, &isrc, &isrc, desc, &info); + return info; + } + + static inline + void trmm(char side, + char uplo, + char trans, + char diag, + int m, + int n, + double alpha, + double* a, + double* b, + int* desc) + { + int isrc = 1; + pdtrmm_(&side, &uplo, &trans, &diag, &m, &n, &alpha, a, &isrc, &isrc, desc, b, &isrc, &isrc, desc); + } + + static inline + void trmm(char side, + char uplo, + char trans, + char diag, + int m, + int n, + std::complex alpha, + std::complex* a, + std::complex* b, + int* desc) + { + int isrc = 1; + pztrmm_(&side, &uplo, &trans, &diag, &m, &n, &alpha, a, &isrc, &isrc, desc, b, &isrc, &isrc, desc); + } + + static inline + void hemm(char side, + char uplo, + int na, + std::complex alpha, + std::complex* a, + std::complex* b, + std::complex beta, + std::complex* c, + int* desc) + { + int isrc = 1; + pzhemm_(&side, + &uplo, + &na, + &na, + &alpha, + a, + &isrc, + &isrc, + desc, + b, + &isrc, + &isrc, + desc, + &beta, + c, + &isrc, + &isrc, + desc); + } }; #endif // __MPI diff --git a/source/source_base/module_fft/fft_cpu.cpp b/source/source_base/module_fft/fft_cpu.cpp index 75854a93980..281ec21895b 100644 --- a/source/source_base/module_fft/fft_cpu.cpp +++ b/source/source_base/module_fft/fft_cpu.cpp @@ -11,7 +11,7 @@ void FFT_CPU::initfft(int nx_in, int rixy_in, int ns_in, int nplane_in, - int nproc_in, + int nproc_in, bool gamma_only_in, bool xprime_in) { diff --git a/source/source_base/module_fft/fft_cpu.h b/source/source_base/module_fft/fft_cpu.h index ec47768d8e9..5c6f18b5c8d 100644 --- a/source/source_base/module_fft/fft_cpu.h +++ b/source/source_base/module_fft/fft_cpu.h @@ -40,10 +40,10 @@ class FFT_CPU : public FFT_BASE bool gamma_only_in, bool xprime_in = true) override; - ABACUS_FFT_WEAK + ABACUS_FFT_WEAK void setupFFT() override; - // void initplan(const unsigned int& flag = 0); + // void initplan(const unsigned int& flag = 0); ABACUS_FFT_WEAK void cleanFFT() override; diff --git a/source/source_base/module_fft/fft_cuda.h b/source/source_base/module_fft/fft_cuda.h index 7734caffa9d..0b7a7aacf6e 100644 --- a/source/source_base/module_fft/fft_cuda.h +++ b/source/source_base/module_fft/fft_cuda.h @@ -13,7 +13,7 @@ class FFT_CUDA : public FFT_BASE FFT_CUDA(){}; ~FFT_CUDA(){}; - void setupFFT() override; + void setupFFT() override; void clear() override; diff --git a/source/source_base/module_fft/fft_dsp.h b/source/source_base/module_fft/fft_dsp.h index a735fd1c500..f29ed85f8e3 100644 --- a/source/source_base/module_fft/fft_dsp.h +++ b/source/source_base/module_fft/fft_dsp.h @@ -20,7 +20,7 @@ class FFT_DSP : public FFT_BASE FFT_DSP(){}; ~FFT_DSP(){}; - void setupFFT() override; + void setupFFT() override; void clear() override; diff --git a/source/source_base/module_mixing/broyden_mixing.cpp b/source/source_base/module_mixing/broyden_mixing.cpp index e189010a464..f8211412387 100644 --- a/source/source_base/module_mixing/broyden_mixing.cpp +++ b/source/source_base/module_mixing/broyden_mixing.cpp @@ -106,14 +106,14 @@ void Broyden_Mixing::tem_cal_coef(const Mixing_Data& mdata, std::function(dF); FPTYPE* FP_F = static_cast(F); diff --git a/source/source_base/module_out/csr_reader.cpp b/source/source_base/module_out/csr_reader.cpp index ad38a574227..7697f057bbf 100644 --- a/source/source_base/module_out/csr_reader.cpp +++ b/source/source_base/module_out/csr_reader.cpp @@ -131,54 +131,54 @@ void csrFileReader::parseFile() // std::cout << " ss1: " << ss.str() << std::endl; readLine(); - size_t count1 = 0; + size_t count1 = 0; while (count1 < nonZero) { if (ss.eof() || ss.fail()) { readLine(); - } + } if (ss >> csr_values[count1]) { count1++; } - } + } // std::cout << "count1=" << count1 << std::endl; // read CSR column indices readLine(); // std::cout << " ss2: " << ss.str() << std::endl; - size_t count2 = 0; + size_t count2 = 0; while (count2 < nonZero) { if (ss.eof() || ss.fail()) { readLine(); - } + } if (ss >> csr_col_ind[count2]) { count2++; } - } + } // std::cout << "count2=" << count2 << std::endl; // read row pointers readLine(); // std::cout << " ss3: " << ss.str() << std::endl; - size_t count3 = 0; + size_t count3 = 0; while (count3 < matrixDimension + 1) { if (ss.eof() || ss.fail()) { readLine(); - } + } if (ss >> csr_row_ptr[count3]) { count3++; } - } + } // std::cout << "count3=" << count3 << std::endl; // create sparse matrix diff --git a/source/source_base/module_out/filename.cpp b/source/source_base/module_out/filename.cpp index c7818642f6f..4dd86dc2bea 100644 --- a/source/source_base/module_out/filename.cpp +++ b/source/source_base/module_out/filename.cpp @@ -6,17 +6,17 @@ namespace ModuleIO { std::string filename_output( - const std::string &directory, - const std::string &property, - const std::string &basis, - const int ik_local, // the ik index within each pool - const std::vector &ik2iktot, - const int nspin, - const int nkstot, - const int out_type, - const bool out_app_flag, - const bool gamma_only, - const int istep, + const std::string &directory, + const std::string &property, + const std::string &basis, + const int ik_local, // the ik index within each pool + const std::vector &ik2iktot, + const int nspin, + const int nkstot, + const int out_type, + const bool out_app_flag, + const bool gamma_only, + const int istep, const int iter) { // output filename = "{global_out_dir}/property{s}{spin index} @@ -24,57 +24,57 @@ std::string filename_output( // + {".txt"/".dat"}" std::set valid_properties = { "wf", "chg", "hk", "sk", "tk", "vxc", "vxck", "vlk", "vnlk", "vhk", "vexxk" }; - if (valid_properties.find(property) == valid_properties.end()) - { - ModuleBase::WARNING_QUIT("ModuleIO::filename_output", "unknown property in filename function"); - } + if (valid_properties.find(property) == valid_properties.end()) + { + ModuleBase::WARNING_QUIT("ModuleIO::filename_output", "unknown property in filename function"); + } - std::set valid_basis = {"pw", "nao"}; - if (valid_basis.find(basis) == valid_basis.end()) - { - ModuleBase::WARNING_QUIT("ModuleIO::filename_output", "unknown basis in filename function"); - } + std::set valid_basis = {"pw", "nao"}; + if (valid_basis.find(basis) == valid_basis.end()) + { + ModuleBase::WARNING_QUIT("ModuleIO::filename_output", "unknown basis in filename function"); + } assert(ik_local>=0); // mohan update 2025.05.07, if KPAR>1, "<" works - assert(ik2iktot.size() <= nkstot); + assert(ik2iktot.size() <= nkstot); assert(nspin>0); - // spin index - int is0 = -1; - // ik0 is the k-point index, starting from 0 - int ik0 = ik2iktot[ik_local]; + // spin index + int is0 = -1; + // ik0 is the k-point index, starting from 0 + int ik0 = ik2iktot[ik_local]; - // spin part - std::string spin_block; + // spin part + std::string spin_block; // mohan add 2026-01-04, overlap matrix is the same for any spin - if(property != "sk") - { - if(nspin == 1) - { - // do nothing - } - else if(nspin == 2) - { - const int half_k = nkstot/2; - if(ik0 >= half_k) - { - is0 = 2; - ik0 -= half_k; - } - else - { - is0 = 1; - } - spin_block = "s" + std::to_string(is0); - } - else if(nspin==4) - { - is0 = 4; - spin_block = "s" + std::to_string(is0); - } - } + if(property != "sk") + { + if(nspin == 1) + { + // do nothing + } + else if(nspin == 2) + { + const int half_k = nkstot/2; + if(ik0 >= half_k) + { + is0 = 2; + ik0 -= half_k; + } + else + { + is0 = 1; + } + spin_block = "s" + std::to_string(is0); + } + else if(nspin==4) + { + is0 = 4; + spin_block = "s" + std::to_string(is0); + } + } // k-point part @@ -86,14 +86,14 @@ std::string filename_output( else { // mohan add 20250921 - if(property=="hk" || property=="sk" || property=="tk") - { - kpoint_block = std::to_string(ik0+1); - } - else - { - kpoint_block = "k" + std::to_string(ik0+1); - } + if(property=="hk" || property=="sk" || property=="tk") + { + kpoint_block = std::to_string(ik0+1); + } + else + { + kpoint_block = "k" + std::to_string(ik0+1); + } } std::string istep_block diff --git a/source/source_base/module_out/filename.h b/source/source_base/module_out/filename.h index 895bf29ef05..d76970c769f 100644 --- a/source/source_base/module_out/filename.h +++ b/source/source_base/module_out/filename.h @@ -26,14 +26,14 @@ std::string filename_output( const std::string &directory, const std::string &property, const std::string &basis, - const int ik_local, - const std::vector &ik2iktot, - const int nspin, - const int nkstot, + const int ik_local, + const std::vector &ik2iktot, + const int nspin, + const int nkstot, const int out_type, - const bool out_app_flag, - const bool gamma_only, - const int istep=-1, + const bool out_app_flag, + const bool gamma_only, + const int istep=-1, const int iter=-1); } diff --git a/source/source_base/module_out/sparse_matrix.cpp b/source/source_base/module_out/sparse_matrix.cpp index 535f2bb93b6..c0b3357762b 100644 --- a/source/source_base/module_out/sparse_matrix.cpp +++ b/source/source_base/module_out/sparse_matrix.cpp @@ -41,8 +41,8 @@ void SparseMatrix::printToCSR(std::ostream& ofs, int precision) size_t count1 = 0; for (const auto &element : elements) { - if(count1%6==0) ofs << '\n'; - count1++; + if(count1%6==0) ofs << '\n'; + count1++; ofs << " " << element.second; } ofs << '\n'; @@ -51,8 +51,8 @@ void SparseMatrix::printToCSR(std::ostream& ofs, int precision) size_t count2 = 0; for (const auto &element : elements) { - if(count2%16==0) ofs << '\n'; - count2++; + if(count2%16==0) ofs << '\n'; + count2++; ofs << " " << element.first.second; int row = element.first.first; csr_row_ptr[row + 1]++; diff --git a/source/source_base/name_angular.h b/source/source_base/name_angular.h index 48b9dae1520..75bfb453164 100644 --- a/source/source_base/name_angular.h +++ b/source/source_base/name_angular.h @@ -3,14 +3,14 @@ namespace ModuleBase { - const std::string Name_Angular[5][11] = - { - {"s"}, - {"pz", "px", "py"}, - {"dz^2", "dxz", "dyz", "dx^2-y^2", "dxy"}, - {"fz^3", "fxz^2", "fyz^2", "fzx^2-zy^2", "fxyz", "fx^3-3*xy^2", "f3yx^2-y^3"}, - {"g1", "g2", "g3", "g4", "g5", "g6", "g7", "g8", "g9"} - }; // name of atomic orbital jiyy add 2022-05-10 + const std::string Name_Angular[5][11] = + { + {"s"}, + {"pz", "px", "py"}, + {"dz^2", "dxz", "dyz", "dx^2-y^2", "dxy"}, + {"fz^3", "fxz^2", "fyz^2", "fzx^2-zy^2", "fxyz", "fx^3-3*xy^2", "f3yx^2-y^3"}, + {"g1", "g2", "g3", "g4", "g5", "g6", "g7", "g8", "g9"} + }; // name of atomic orbital jiyy add 2022-05-10 } #endif diff --git a/source/source_base/ndarray.h b/source/source_base/ndarray.h index 5f76fb9e282..b4da1feea52 100644 --- a/source/source_base/ndarray.h +++ b/source/source_base/ndarray.h @@ -1,5 +1,5 @@ /** - * @file NDArray.h + * @file ndarray.h * @author your name (you@domain.com) * @brief under the restriction of C++11, a simple alternative to std::vector + std::mdspan. In source_base/module_container/ATen/tensor.h, tensor class provides a cross-device container, but std::string is not supported. Therefore, this class is to provide a general (but CPU-only) container for multi-dimensional data. It can easily convert to ontainer::Tensor. * @version 0.1 diff --git a/source/source_base/output.cpp b/source/source_base/output.cpp index 7512e0bfe2e..2de3882c7aa 100644 --- a/source/source_base/output.cpp +++ b/source/source_base/output.cpp @@ -14,17 +14,17 @@ void output::printrm(std::ofstream &ofs,const std::string &s, const ModuleBase:: { if (j % 8 == 0) ofs << "\n "; - if (std::abs(m(i,j)) > limit) - { - ofs << std::setprecision(6) << std::setw(12) << m(i,j); + if (std::abs(m(i,j)) > limit) + { + ofs << std::setprecision(6) << std::setw(12) << m(i,j); + } + else + { + ofs << std::setw(12) << "0"; } - else - { - ofs << std::setw(12) << "0"; - } } } - ofs << std::endl; + ofs << std::endl; return; } @@ -37,16 +37,16 @@ void output::printrm(const std::string &s, const ModuleBase::matrix &m, const do for (int i = 0;i < b1;i++) { - //std::cout << "\n row=" << i; + //std::cout << "\n row=" << i; for (int j = 0;j < b2;j++) { - if (j % 8 == 0) std::cout << "\n "; + if (j % 8 == 0) std::cout << "\n "; if (std::abs(m(i,j)) > limit) std::cout << std::setprecision(6) << std::setw(12) << m(i,j); else std::cout< 1); - for(int i=0; i( std::rand() ) / RAND_MAX; - } - } - - static double betweenMinus2and2(void) - { - return 2.0*betweenMinus1and1(); - } - - static double betweenMinus1and1(void) - { - const int a = std::rand() % 2; - if(a==0) return between0and1(); - else if(a==1) return betweenMinus1and0(); - else throw(std::string(__FILE__)+" line "+std::to_string(__LINE__)); // Peize Lin add to fix warning 2019-05-01 - } - - static double between0and1(void) - { - return static_cast( std::rand() )/RAND_MAX; - } - - static double betweenMinus1and0(void) - { - return -static_cast( std::rand() )/RAND_MAX; - } + public: + Random(); + ~Random(); + + static void between0and1( double *v, const int &num ) + { + assert( v!= NULL); + assert( num > 1); + for(int i=0; i( std::rand() ) / RAND_MAX; + } + } + + static double betweenMinus2and2(void) + { + return 2.0*betweenMinus1and1(); + } + + static double betweenMinus1and1(void) + { + const int a = std::rand() % 2; + if(a==0) return between0and1(); + else if(a==1) return betweenMinus1and0(); + else throw(std::string(__FILE__)+" line "+std::to_string(__LINE__)); // Peize Lin add to fix warning 2019-05-01 + } + + static double between0and1(void) + { + return static_cast( std::rand() )/RAND_MAX; + } + + static double betweenMinus1and0(void) + { + return -static_cast( std::rand() )/RAND_MAX; + } }; diff --git a/source/source_base/realarray.cpp b/source/source_base/realarray.cpp index b9983ed804e..e179a582d46 100644 --- a/source/source_base/realarray.cpp +++ b/source/source_base/realarray.cpp @@ -13,60 +13,60 @@ int realArray::arrayCount = 0; void realArrayAlloc() { - std::cout << "\n Allocation error for realArray " << std::endl; - exit(0); + std::cout << "\n Allocation error for realArray " << std::endl; + exit(0); } realArray::realArray(const int d1,const int d2,const int d3) { - dim = 3; - bound1 = (d1 <= 0) ? 1 : d1; - bound2 = (d2 <= 0) ? 1 : d2; - bound3 = (d3 <= 0) ? 1 : d3; - bound4 = 0; + dim = 3; + bound1 = (d1 <= 0) ? 1 : d1; + bound2 = (d2 <= 0) ? 1 : d2; + bound3 = (d3 <= 0) ? 1 : d3; + bound4 = 0; - size = bound1 * bound2 * bound3 ; //* sizeof(float); + size = bound1 * bound2 * bound3 ; //* sizeof(float); - auto handler_old = std::set_new_handler(realArrayAlloc); - ptr = new double[size]; - std::set_new_handler(handler_old); - zero_out(); - assert(ptr != 0); + auto handler_old = std::set_new_handler(realArrayAlloc); + ptr = new double[size]; + std::set_new_handler(handler_old); + zero_out(); + assert(ptr != 0); - ++arrayCount; + ++arrayCount; } realArray::realArray(const int d1,const int d2,const int d3,const int d4) { - dim = 4; - bound1 = (d1 <= 0) ? 1 : d1; - bound2 = (d2 <= 0) ? 1 : d2; - bound3 = (d3 <= 0) ? 1 : d3; - bound4 = (d4 <= 0) ? 1 : d4; + dim = 4; + bound1 = (d1 <= 0) ? 1 : d1; + bound2 = (d2 <= 0) ? 1 : d2; + bound3 = (d3 <= 0) ? 1 : d3; + bound4 = (d4 <= 0) ? 1 : d4; - size = bound1 * bound2 * bound3 * bound4 ; //* sizeof(float); + size = bound1 * bound2 * bound3 * bound4 ; //* sizeof(float); - auto handler_old = std::set_new_handler(realArrayAlloc); - ptr = new double[size]; - std::set_new_handler(handler_old); - zero_out(); + auto handler_old = std::set_new_handler(realArrayAlloc); + ptr = new double[size]; + std::set_new_handler(handler_old); + zero_out(); - ++arrayCount; + ++arrayCount; } realArray::realArray(const realArray &cd) { - this->size = cd.getSize(); - this->ptr = new double[size]; - for (int i = 0; i < size; i++) - this->ptr[i] = cd.ptr[i]; - this->dim = cd.dim; - this->bound1 = cd.bound1; - this->bound2 = cd.bound2; - this->bound3 = cd.bound3; - this->bound4 = cd.bound4; + this->size = cd.getSize(); + this->ptr = new double[size]; + for (int i = 0; i < size; i++) + this->ptr[i] = cd.ptr[i]; + this->dim = cd.dim; + this->bound1 = cd.bound1; + this->bound2 = cd.bound2; + this->bound3 = cd.bound3; + this->bound4 = cd.bound4; - ++arrayCount; + ++arrayCount; } @@ -82,43 +82,43 @@ realArray ::~realArray() void realArray::freemem() { - delete [] ptr; - ptr = NULL; + delete [] ptr; + ptr = NULL; } void realArray::create(const int d1,const int d2,const int d3,const int d4) { - size = d1 * d2 * d3 * d4; - assert(size>0); + size = d1 * d2 * d3 * d4; + assert(size>0); - dim = 4; + dim = 4; - bound1 = d1; - bound2 = d2; - bound3 = d3; - bound4 = d4; + bound1 = d1; + bound2 = d2; + bound3 = d3; + bound4 = d4; - delete [] ptr; - ptr = new double[size]; + delete [] ptr; + ptr = new double[size]; - zero_out(); // mohan modify 2009-09-17 - - assert(ptr != 0); + zero_out(); // mohan modify 2009-09-17 + + assert(ptr != 0); } void realArray::create(const int d1,const int d2,const int d3) { - size = d1 * d2 * d3; - assert(size>0); + size = d1 * d2 * d3; + assert(size>0); - dim = 3; + dim = 3; - bound1 = d1; - bound2 = d2; - bound3 = d3; - bound4 = 1; + bound1 = d1; + bound2 = d2; + bound3 = d3; + bound4 = 1; - delete [] ptr; + delete [] ptr; ptr = new double[size]; zero_out(); assert(ptr != 0); @@ -126,14 +126,14 @@ void realArray::create(const int d1,const int d2,const int d3) const realArray &realArray::operator=(const realArray &right) { - for (int i = 0;i < size;i++) ptr[i] = right.ptr[i]; - return *this;// enables x = y = z; + for (int i = 0;i < size;i++) ptr[i] = right.ptr[i]; + return *this;// enables x = y = z; } const realArray &realArray::operator=(const double &right) { - for (int i = 0;i < size;i++) ptr[i] = right; - return *this;// enables x = y = z; + for (int i = 0;i < size;i++) ptr[i] = right; + return *this;// enables x = y = z; } //******************************************************** @@ -144,20 +144,20 @@ const realArray &realArray::operator=(const double &right) const double &realArray::operator() (const int ind1,const int ind2,const int ind3)const { - assert(ind1>=0); assert(ind1=0); assert(ind2=0); assert(ind3=0); assert(ind1=0); assert(ind2=0); assert(ind3=0); assert(ind1=0); assert(ind2=0); assert(ind3=0); assert(ind4=0); assert(ind1=0); assert(ind2=0); assert(ind3=0); assert(ind4=0); assert(ind1=0); assert(ind2=0); assert(ind3=0); assert(ind1=0); assert(ind2=0); assert(ind3=0); assert(ind1=0); assert(ind2=0); assert(ind3=0); assert(ind4=0); assert(ind1=0); assert(ind2=0); assert(ind3=0); assert(ind4 Sph_Bessel_Recursive_Pool::D1::sb_pool; void Sph_Bessel_Recursive::D1::set_dx( const double dx_in ) { - if(finish_set_dx && dx_in!=dx) - throw std::runtime_error("Sph_Bessel_Recursive::set_dx, dx can only set once"); - else - { - dx = dx_in; - finish_set_dx = true; - } + if(finish_set_dx && dx_in!=dx) + throw std::runtime_error("Sph_Bessel_Recursive::set_dx, dx can only set once"); + else + { + dx = dx_in; + finish_set_dx = true; + } } const std::vector> & Sph_Bessel_Recursive::D1::cal_jlx( const int lmax, const size_t ix_size ) { - if(lmax<0) - throw std::invalid_argument("Sph_Bessel_Recursive::jlx l<0"); - cal_jlx_0( lmax+1 ); - cal_jlx_smallx( lmax+1, ix_size ); - cal_jlx_recursive( lmax+1, ix_size ); - return jlx; + if(lmax<0) + throw std::invalid_argument("Sph_Bessel_Recursive::jlx l<0"); + cal_jlx_0( lmax+1 ); + cal_jlx_smallx( lmax+1, ix_size ); + cal_jlx_recursive( lmax+1, ix_size ); + return jlx; } void Sph_Bessel_Recursive::D1::cal_jlx_0( const int l_size ) { - if(jlx.size() < static_cast(l_size)) - jlx.resize(l_size); - - for( int l=0; l!=l_size; ++l ) - { - if(jlx[l].size()<1) - { - jlx[l].resize(1); - if(0==l) - jlx[l][0] = 1.0; - else - jlx[l][0] = 0.0; - } - } + if(jlx.size() < static_cast(l_size)) + jlx.resize(l_size); + + for( int l=0; l!=l_size; ++l ) + { + if(jlx[l].size()<1) + { + jlx[l].resize(1); + if(0==l) + jlx[l][0] = 1.0; + else + jlx[l][0] = 0.0; + } + } } void Sph_Bessel_Recursive::D1::cal_jlx_smallx( const int l_size, const size_t ix_size ) { - if(jlx.size() < static_cast(l_size)) - jlx.resize(l_size); - - for( int l=0; l!=l_size; ++l ) - { - if(jlx[l].size()threshold/coeff*(l+1.5)*4, 1.0/(l+2) ); - - const size_t ix_size_begin = static_cast(jlx[l].size()); - const size_t ix_size_end = std::min( ix_size, static_cast(smallx_range/dx) ); - if(jlx[l].size()(l_size)) + jlx.resize(l_size); + + for( int l=0; l!=l_size; ++l ) + { + if(jlx[l].size()threshold/coeff*(l+1.5)*4, 1.0/(l+2) ); + + const size_t ix_size_begin = static_cast(jlx[l].size()); + const size_t ix_size_end = std::min( ix_size, static_cast(smallx_range/dx) ); + if(jlx[l].size()(l_size)) - jlx.resize(l_size); - - for( int l=0; l!=l_size; ++l ) - { - if(jlx[l].size()(jlx[l].size()); - jlx[l].resize(ix_size); - switch(l) - { - case 0: - for( size_t ix=ix_size_begin; ix(l_size)) + jlx.resize(l_size); + + for( int l=0; l!=l_size; ++l ) + { + if(jlx[l].size()(jlx[l].size()); + jlx[l].resize(ix_size); + switch(l) + { + case 0: + for( size_t ix=ix_size_begin; ix(jlx[l].size()); - jlx[l].resize(ix_size); - switch(l) - { - case 0: - { - for( size_t ix=ix_size_begin; ix(0.14/dx)+1 ); - for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); - for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); - for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); - for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); - for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); - for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); - for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); - for( size_t ix=ix_size_begin; ix(jlx[l].size()); + jlx[l].resize(ix_size); + switch(l) + { + case 0: + { + for( size_t ix=ix_size_begin; ix(0.14/dx)+1 ); + for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); + for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); + for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); + for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); + for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); + for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); + for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); + for( size_t ix=ix_size_begin; ix6"); - } - } + jlx[l][ix] = sin(x1)*( (1.0 +(-3003.0 +(1351350.0/x5 +(-192972780.0 +(9820936125.0 +(-151242416325.0 +316234143225.0/x2)/x2)/x2)/x2)/x2)/x2)/x1 ) + + cos(x1)*( (78.0 +(-75075.0 +(18378360.0 +(-1571349780.0 +(45831035250.0 -316234143225.0/x2)/x2)/x2)/x2)/x2)/x2 ); + } + break; + } + default: + throw std::invalid_argument("Sph_Bessel_Recursive::jlx l<0 or l>6"); + } + } //timeval t_end; gettimeofday( &t_end, NULL); //std::cout< Sph_Bessel_Recursive_Pool::D2::sb_pool; void Sph_Bessel_Recursive::D2::set_dx( const double dx_in ) { - if(finish_set_dx && dx_in!=dx) - throw std::runtime_error("Sph_Bessel_Recursive::set_dx, dx can only set once"); - else - { - dx = dx_in; - finish_set_dx = true; - } + if(finish_set_dx && dx_in!=dx) + throw std::runtime_error("Sph_Bessel_Recursive::set_dx, dx can only set once"); + else + { + dx = dx_in; + finish_set_dx = true; + } } const std::vector>> & Sph_Bessel_Recursive::D2::cal_jlx( const int lmax, const size_t ix1_size, const size_t ix2_size ) { - if(lmax<0) - throw std::invalid_argument("Sph_Bessel_Recursive::jlx l<0"); - cal_jlx_0( lmax+1, ix1_size, ix2_size ); - cal_jlx_smallx( lmax+1, ix1_size, ix2_size ); - cal_jlx_recursive( lmax+1, ix1_size, ix2_size ); - ModuleBase::Memory::record("ORB::Jl(x)", sizeof(double) * (lmax+1) * ix1_size * ix2_size); - return jlx; + if(lmax<0) + throw std::invalid_argument("Sph_Bessel_Recursive::jlx l<0"); + cal_jlx_0( lmax+1, ix1_size, ix2_size ); + cal_jlx_smallx( lmax+1, ix1_size, ix2_size ); + cal_jlx_recursive( lmax+1, ix1_size, ix2_size ); + ModuleBase::Memory::record("ORB::Jl(x)", sizeof(double) * (lmax+1) * ix1_size * ix2_size); + return jlx; } void Sph_Bessel_Recursive::D2::cal_jlx_0( const int l_size, const size_t ix1_size, const size_t ix2_size ) { - if(jlx.size() < static_cast(l_size)) - jlx.resize(l_size); - - for( int l=0; l(l_size)) + jlx.resize(l_size); + + for( int l=0; l(1,jlx0)); - - if( jlx[l][0].size()(1,jlx0)); + + if( jlx[l][0].size()(l_size)) - jlx.resize(l_size); - - for( int l=0; l!=l_size; ++l ) - { - const double coeff = sqrt(ModuleBase::PI)/tgamma(l+1.5)/pow(2,l+1); - const double smallx_range = pow( this->threshold/coeff*(l+1.5)*4, 1.0/(l+2) ); - - if(jlx[l].size()(1), jlx[l][ix1].size() ); - const size_t ix2_size_end = std::min( ix2_size, static_cast(smallx_range/dx)/ix1 ); - if(jlx[l][ix1].size()(l_size)) + jlx.resize(l_size); + + for( int l=0; l!=l_size; ++l ) + { + const double coeff = sqrt(ModuleBase::PI)/tgamma(l+1.5)/pow(2,l+1); + const double smallx_range = pow( this->threshold/coeff*(l+1.5)*4, 1.0/(l+2) ); + + if(jlx[l].size()(1), jlx[l][ix1].size() ); + const size_t ix2_size_end = std::min( ix2_size, static_cast(smallx_range/dx)/ix1 ); + if(jlx[l][ix1].size()(l_size)) - jlx.resize(l_size); - - for( int l=0; l!=l_size; ++l ) - { - switch(l) - { - case 0: - if(jlx[l].size()(1), jlx[l][ix1].size() ); - if(jlx[l][ix1].size()(1), jlx[l][ix1].size() ); - if(jlx[l][ix1].size()(1), jlx[l][ix1].size() ); - if(jlx[l][ix1].size()(l_size)) + jlx.resize(l_size); + + for( int l=0; l!=l_size; ++l ) + { + switch(l) + { + case 0: + if(jlx[l].size()(1), jlx[l][ix1].size() ); + if(jlx[l][ix1].size()(1), jlx[l][ix1].size() ); + if(jlx[l][ix1].size()(1), jlx[l][ix1].size() ); + if(jlx[l][ix1].size()(jlx[l].size()); - jlx[l].resize(ix_size); - switch(l) - { - case 0: - { - for( size_t ix=ix_size_begin; ix(0.14/dx)+1 ); - for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); - for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); - for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); - for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); - for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); - for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); - for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); - for( size_t ix=ix_size_begin; ix(jlx[l].size()); + jlx[l].resize(ix_size); + switch(l) + { + case 0: + { + for( size_t ix=ix_size_begin; ix(0.14/dx)+1 ); + for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); + for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); + for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); + for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); + for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); + for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); + for( size_t ix=ix_size_begin; ix(0.29/dx)+1 ); + for( size_t ix=ix_size_begin; ix6"); - } - } + jlx[l][ix] = sin(x1)*( (1.0 +(-3003.0 +(1351350.0/x5 +(-192972780.0 +(9820936125.0 +(-151242416325.0 +316234143225.0/x2)/x2)/x2)/x2)/x2)/x2)/x1 ) + + cos(x1)*( (78.0 +(-75075.0 +(18378360.0 +(-1571349780.0 +(45831035250.0 -316234143225.0/x2)/x2)/x2)/x2)/x2)/x2 ); + } + break; + } + default: + throw std::invalid_argument("Sph_Bessel_Recursive::jlx l<0 or l>6"); + } + } //timeval t_end; gettimeofday( &t_end, NULL); //std::cout<> & cal_jlx( const int lmax, const size_t ix_size ); - const std::vector> & get_jlx()const{ return jlx; } - - void set_dx(const double dx_in); - double get_dx()const{ return dx; } + const std::vector> & cal_jlx( const int lmax, const size_t ix_size ); + const std::vector> & get_jlx()const{ return jlx; } + + void set_dx(const double dx_in); + double get_dx()const{ return dx; } private: - std::vector> jlx; // jlx[l][x] - double dx = 0.0; - bool finish_set_dx = false; - - void cal_jlx_0( const int l_size ); - void cal_jlx_smallx( const int l_size, const size_t ix_size ); - void cal_jlx_recursive( const int l_size, const size_t ix_size ); - - - double threshold = 1e-8; // Peize Lin test + std::vector> jlx; // jlx[l][x] + double dx = 0.0; + bool finish_set_dx = false; + + void cal_jlx_0( const int l_size ); + void cal_jlx_smallx( const int l_size, const size_t ix_size ); + void cal_jlx_recursive( const int l_size, const size_t ix_size ); + + + double threshold = 1e-8; // Peize Lin test }; @@ -48,23 +48,23 @@ class Sph_Bessel_Recursive::D1 class Sph_Bessel_Recursive::D2 { public: - const std::vector>> & cal_jlx( const int lmax, const size_t ix1_size, const size_t ix2_size ); - const std::vector>> & get_jlx()const{ return jlx; } - - void set_dx(const double dx_in); - double get_dx()const{ return dx; } + const std::vector>> & cal_jlx( const int lmax, const size_t ix1_size, const size_t ix2_size ); + const std::vector>> & get_jlx()const{ return jlx; } + + void set_dx(const double dx_in); + double get_dx()const{ return dx; } private: - std::vector>> jlx; // jlx[l][x1][x2] - double dx = 0.0; - bool finish_set_dx = false; - - void cal_jlx_0( const int l_size, const size_t ix1_size, const size_t ix2_size ); - void cal_jlx_smallx( const int l_size, const size_t ix1_size, const size_t ix2_size ); - void cal_jlx_recursive( const int l_size, const size_t ix1_size, const size_t ix2_size ); - - - double threshold = 1e-8; // Peize Lin test + std::vector>> jlx; // jlx[l][x1][x2] + double dx = 0.0; + bool finish_set_dx = false; + + void cal_jlx_0( const int l_size, const size_t ix1_size, const size_t ix2_size ); + void cal_jlx_smallx( const int l_size, const size_t ix1_size, const size_t ix2_size ); + void cal_jlx_recursive( const int l_size, const size_t ix1_size, const size_t ix2_size ); + + + double threshold = 1e-8; // Peize Lin test }; @@ -72,16 +72,16 @@ class Sph_Bessel_Recursive::D2 class Sph_Bessel_Recursive_Pool { public: - class D1 - { - public: - static std::vector sb_pool; - }; - class D2 - { - public: - static std::vector sb_pool; - }; + class D1 + { + public: + static std::vector sb_pool; + }; + class D2 + { + public: + static std::vector sb_pool; + }; }; } diff --git a/source/source_base/tool_check.cpp b/source/source_base/tool_check.cpp index dab7dd5f213..1549fdbebeb 100644 --- a/source/source_base/tool_check.cpp +++ b/source/source_base/tool_check.cpp @@ -10,81 +10,81 @@ void CHECK_NAME(std::ifstream &ifs,const std::string &name_in,bool quit) ifs >> name; if ( name != name_in) { - if(quit) - { - //GlobalV::ofs_warning << "\n name = " <> v_in; - if( v!= v_in) - { - if(quit) - { - std::cout << "\n value = " << v_in; - std::cout << "\n should be = " << v; - WARNING_QUIT("CHECK_INT","Some parameter name is wrong!"); - } - else - { - std::cout <<"\n Can not match well: "<> v_in; + if( v!= v_in) + { + if(quit) + { + std::cout << "\n value = " << v_in; + std::cout << "\n should be = " << v; + WARNING_QUIT("CHECK_INT","Some parameter name is wrong!"); + } + else + { + std::cout <<"\n Can not match well: "<> v_in; - if( fabs(v - v_in) > tiny ) - { - if(quit) - { - std::cout << " read in value = " << v_in << std::endl; - std::cout << " the value should be = " << v << std::endl; - WARNING_QUIT("CHECK_DOUBLE","the name of parameter wrong!"); - } - else - { - std::cout <<" can not match well (1.0e-5): "<< v_in <<"(readin) "<> v_in; + if( fabs(v - v_in) > tiny ) + { + if(quit) + { + std::cout << " read in value = " << v_in << std::endl; + std::cout << " the value should be = " << v << std::endl; + WARNING_QUIT("CHECK_DOUBLE","the name of parameter wrong!"); + } + else + { + std::cout <<" can not match well (1.0e-5): "<< v_in <<"(readin) "<> v_in; - if( v_in != v ) - { - if(quit) - { - std::cout << " read in value = " << v_in << std::endl; - std::cout << " the value should be = " << v << std::endl; - WARNING_QUIT("CHECK_STRING","the name of parameter wrong!"); - } - else - { - std::cout <<" can not match well : "<> v_in; + if( v_in != v ) + { + if(quit) + { + std::cout << " read in value = " << v_in << std::endl; + std::cout << " the value should be = " << v << std::endl; + WARNING_QUIT("CHECK_STRING","the name of parameter wrong!"); + } + else + { + std::cout <<" can not match well : "< "< "< "< "< "< "< &vec, double ylmr[] ) { - //ModuleBase::timer::start("Ylm","get_ylm_real"); - //1e-9 is too large - const double cut0 = 1e-12; - // allocate space. - Ylm::nlm = Lmax * Lmax; - if(Lmax==1) - { - for(int i=0; i 1.0 - cut0) - { - cost = sgn(cost) * (1.0 - cut0); - // std::cout << "\n" << "cost = " << cost << std::endl; - } - sint = sqrt(1.0 - cost*cost); - - if(vec.x > cut0) - { - phi = std::atan( vec.y / vec.x ); - } - else if( vec.x < -cut0 ) - { - phi = std::atan( vec.y / vec.x ) + ModuleBase::PI; - } - else - { - phi = ModuleBase::PI_HALF * ((vec.y >= 0.0) ? 1.0 : -1.0); - } - - //=============================== - // NAME : p(Legendre Polynomials) - //=============================== - double p[20][20]; - assert(Lmax <= 20); - - int m=0; - double x1=0.0; // x2; - int lm = -1; // must initialized! - - for (int l=0; l(l)) ;//liaochen modify 2009-09-06 - if (l%2 == 1) - { - x1 = -x1; - } - p[l][l] = x1; - } // end if - - // Y_lm, m = 0 - ++lm; - ylmr[lm] = c*p[0][l]; - - for(m=1;m<=l;m++) - { - // Y_lm, m > 0 - const double same = c * sqrt - ( - static_cast( Ylm::Fact(l - m)) / - static_cast( Ylm::Fact(l + m)) - ) - *ModuleBase::SQRT2; - - ++lm; - ylmr[lm] = same * p[m][l] * cos(m * phi); - - // Y_lm, m < 0 - ++lm; - ylmr[lm] = same * p[m][l] * sin(m * phi); - } - }// end do - - //ModuleBase::timer::end("Ylm", "get_ylm_real"); - return; + //ModuleBase::timer::start("Ylm","get_ylm_real"); + //1e-9 is too large + const double cut0 = 1e-12; + // allocate space. + Ylm::nlm = Lmax * Lmax; + if(Lmax==1) + { + for(int i=0; i 1.0 - cut0) + { + cost = sgn(cost) * (1.0 - cut0); + // std::cout << "\n" << "cost = " << cost << std::endl; + } + sint = sqrt(1.0 - cost*cost); + + if(vec.x > cut0) + { + phi = std::atan( vec.y / vec.x ); + } + else if( vec.x < -cut0 ) + { + phi = std::atan( vec.y / vec.x ) + ModuleBase::PI; + } + else + { + phi = ModuleBase::PI_HALF * ((vec.y >= 0.0) ? 1.0 : -1.0); + } + + //=============================== + // NAME : p(Legendre Polynomials) + //=============================== + double p[20][20]; + assert(Lmax <= 20); + + int m=0; + double x1=0.0; // x2; + int lm = -1; // must initialized! + + for (int l=0; l(l)) ;//liaochen modify 2009-09-06 + if (l%2 == 1) + { + x1 = -x1; + } + p[l][l] = x1; + } // end if + + // Y_lm, m = 0 + ++lm; + ylmr[lm] = c*p[0][l]; + + for(m=1;m<=l;m++) + { + // Y_lm, m > 0 + const double same = c * sqrt + ( + static_cast( Ylm::Fact(l - m)) / + static_cast( Ylm::Fact(l + m)) + ) + *ModuleBase::SQRT2; + + ++lm; + ylmr[lm] = same * p[m][l] * cos(m * phi); + + // Y_lm, m < 0 + ++lm; + ylmr[lm] = same * p[m][l] * sin(m * phi); + } + }// end do + + //ModuleBase::timer::end("Ylm", "get_ylm_real"); + return; } void Ylm::get_ylm_real( const int &Lmax, const ModuleBase::Vector3 &vec, double ylmr[], double dylmdr[][3] ) { - //1e-9 is too large - const double cut0 = 1e-12; - // allocate space. - Ylm::nlm = Lmax * Lmax; - if(Lmax==1) - { - for(int i=0; i 1.0-cut0) - { - cost = sgn(cost) * (1.0 - cut0); - } - sint = sqrt(1.0 - cost*cost); - - if(vec.x > cut0) - { - phi = std::atan( vec.y / vec.x ); - } - else if( vec.x < -cut0 ) - { - phi = std::atan( vec.y / vec.x ) + ModuleBase::PI; - } - else - { - phi = ModuleBase::PI_HALF * ((vec.y >= 0.0) ? 1.0 : -1.0); - } - - //=============================== - // NAME : p(Legendre Polynomials) - //=============================== - double p[20][20]; - double dp[20][20]; - assert(Lmax <= 20); - - int m = 0; - int lm = -1; // must initialized! - for (int l=0; l(l)) ; - if (l%2 == 1) - { - p[l][l] = -p[l][l]; - } - } - - for(m=0; m <= l; m++) - { - if( m == l ) - { - dp[l][l] = l * cost * p[l][l] / sint; - } - else - { - dp[m][l] = (l * cost * p[m][l] - (l+m) * p[m][l-1]) / sint; - } - } - - // Y_lm, m = 0 - ++lm; - ylmr[lm] = c*p[0][l]; - - dylmdr[lm][0] = c * dp[0][l] * cost * cos(phi) / vnorm; - dylmdr[lm][1] = c * dp[0][l] * cost * sin(phi) / vnorm; - dylmdr[lm][2] = -c * dp[0][l] * sint / vnorm; - - for(m=1; m <= l; m++) - { - // Y_lm, m > 0 - const double same = c * sqrt - ( - static_cast( Ylm::Fact(l - m)) / - static_cast( Ylm::Fact(l + m)) - ) - *ModuleBase::SQRT2; - - ++lm; - ylmr[lm] = same * p[m][l] * cos(m * phi); - - dylmdr[lm][0] = same * dp[m][l] * cos(m * phi) * cost * cos(phi) / vnorm - + same * p[m][l] * m * sin(m * phi) * sin(phi) / sint / vnorm; - dylmdr[lm][1] = same * dp[m][l] * cos(m * phi) * cost * sin(phi) / vnorm - - same * p[m][l] * m * sin(m * phi) * cos(phi) / sint / vnorm; - dylmdr[lm][2] = -same * dp[m][l] * cos(m * phi) * sint / vnorm; - - // Y_lm, m < 0 - ++lm; - ylmr[lm] = same * p[m][l] * sin(m * phi); - - dylmdr[lm][0] = same * dp[m][l] * sin(m * phi) * cost * cos(phi) / vnorm - - same * p[m][l] * m * cos(m * phi) * sin(phi) / sint / vnorm; - dylmdr[lm][1] = same * dp[m][l] * sin(m * phi) * cost * sin(phi) / vnorm - + same * p[m][l] * m * cos(m * phi) * cos(phi) / sint / vnorm; - dylmdr[lm][2] = -same * dp[m][l] * sin(m * phi) * sint / vnorm; - } - }// end do - - return; + //1e-9 is too large + const double cut0 = 1e-12; + // allocate space. + Ylm::nlm = Lmax * Lmax; + if(Lmax==1) + { + for(int i=0; i 1.0-cut0) + { + cost = sgn(cost) * (1.0 - cut0); + } + sint = sqrt(1.0 - cost*cost); + + if(vec.x > cut0) + { + phi = std::atan( vec.y / vec.x ); + } + else if( vec.x < -cut0 ) + { + phi = std::atan( vec.y / vec.x ) + ModuleBase::PI; + } + else + { + phi = ModuleBase::PI_HALF * ((vec.y >= 0.0) ? 1.0 : -1.0); + } + + //=============================== + // NAME : p(Legendre Polynomials) + //=============================== + double p[20][20]; + double dp[20][20]; + assert(Lmax <= 20); + + int m = 0; + int lm = -1; // must initialized! + for (int l=0; l(l)) ; + if (l%2 == 1) + { + p[l][l] = -p[l][l]; + } + } + + for(m=0; m <= l; m++) + { + if( m == l ) + { + dp[l][l] = l * cost * p[l][l] / sint; + } + else + { + dp[m][l] = (l * cost * p[m][l] - (l+m) * p[m][l-1]) / sint; + } + } + + // Y_lm, m = 0 + ++lm; + ylmr[lm] = c*p[0][l]; + + dylmdr[lm][0] = c * dp[0][l] * cost * cos(phi) / vnorm; + dylmdr[lm][1] = c * dp[0][l] * cost * sin(phi) / vnorm; + dylmdr[lm][2] = -c * dp[0][l] * sint / vnorm; + + for(m=1; m <= l; m++) + { + // Y_lm, m > 0 + const double same = c * sqrt + ( + static_cast( Ylm::Fact(l - m)) / + static_cast( Ylm::Fact(l + m)) + ) + *ModuleBase::SQRT2; + + ++lm; + ylmr[lm] = same * p[m][l] * cos(m * phi); + + dylmdr[lm][0] = same * dp[m][l] * cos(m * phi) * cost * cos(phi) / vnorm + + same * p[m][l] * m * sin(m * phi) * sin(phi) / sint / vnorm; + dylmdr[lm][1] = same * dp[m][l] * cos(m * phi) * cost * sin(phi) / vnorm + - same * p[m][l] * m * sin(m * phi) * cos(phi) / sint / vnorm; + dylmdr[lm][2] = -same * dp[m][l] * cos(m * phi) * sint / vnorm; + + // Y_lm, m < 0 + ++lm; + ylmr[lm] = same * p[m][l] * sin(m * phi); + + dylmdr[lm][0] = same * dp[m][l] * sin(m * phi) * cost * cos(phi) / vnorm + - same * p[m][l] * m * cos(m * phi) * sin(phi) / sint / vnorm; + dylmdr[lm][1] = same * dp[m][l] * sin(m * phi) * cost * sin(phi) / vnorm + + same * p[m][l] * m * cos(m * phi) * cos(phi) / sint / vnorm; + dylmdr[lm][2] = -same * dp[m][l] * sin(m * phi) * sint / vnorm; + } + }// end do + + return; } /*************************** @@ -286,1739 +286,1739 @@ void Ylm::get_ylm_real( const int &Lmax, const ModuleBase::Vector3 &vec, * *************************/ void Ylm::rlylm ( - const int Lmax, //max momentum of l + 1 - const double x, - const double y, - const double z, - double rly[] + const int Lmax, //max momentum of l + 1 + const double x, + const double y, + const double z, + double rly[] ) { // ModuleBase::TITLE("Ylm","rlylm"); // ModuleBase::timer::start("Ylm","rlylm"); - int MaxL = Lmax - 1; + int MaxL = Lmax - 1; - assert(MaxL >= 0); + assert(MaxL >= 0); - //get xy_dependence - assert(MaxL <= 19); + //get xy_dependence + assert(MaxL <= 19); - double Am[20]; - double Bm[20]; + double Am[20]; + double Bm[20]; // ZEROS(Am, 20); // ZEROS(Bm, 20); - double x2, x3, x4, x5; - double y2, y3, y4, y5; - - x2 = x * x; - x3 = x2 * x; - x4 = x3 * x; - x5 = x4 * x; - - y2 = y * y; - y3 = y2 * y; - y4 = y3 * y; - y5 = y4 * y; - - //x-y dependence - //Am - //Bm - for(int im = 0; im < MaxL+1; im++) - { - if(im == 0) - { - Am[0] = 1.0; - Bm[0] = 0.0; - } - else if(im == 1) - { - Am[1] = x; - Bm[1] = y; - } - else if(im == 2) - { - Am[2] = x2- y2; - Bm[2] = 2.0 * x * y; - } - else if(im == 3) - { - Am[3] = x3 - 3.0 * x * y2; - Bm[3] = 3.0 * x2 * y - y3; - } - else if(im == 4) - { - Am[4] = x4 - 6.0 * x2 * y2 + y4; - Bm[4] = 4.0 * (x3 * y - x * y3); - } - else if(im == 5) - { - Am[5] = x5 - 10.0 * x3 * y2 + 5.0 * x * y4; - Bm[5] = 5.0 * x4 * y - 10.0 * x2 * y3 + y5; - } - else - { - for(int ip = 0; ip <= im; ip++) - { - double aux = Fact(im) / Fact(ip) / Fact(im - ip); - Am[im] += aux * pow(x, ip) * pow(y, im-ip) * cos( (im-ip) * ModuleBase::PI / 2.0 ); - Bm[im] += aux * pow(x, ip) * pow(y, im-ip) * sin( (im-ip) * ModuleBase::PI / 2.0 ); - } - } - } - - //z dependence - double zdep[20][20]; + double x2, x3, x4, x5; + double y2, y3, y4, y5; + + x2 = x * x; + x3 = x2 * x; + x4 = x3 * x; + x5 = x4 * x; + + y2 = y * y; + y3 = y2 * y; + y4 = y3 * y; + y5 = y4 * y; + + //x-y dependence + //Am + //Bm + for(int im = 0; im < MaxL+1; im++) + { + if(im == 0) + { + Am[0] = 1.0; + Bm[0] = 0.0; + } + else if(im == 1) + { + Am[1] = x; + Bm[1] = y; + } + else if(im == 2) + { + Am[2] = x2- y2; + Bm[2] = 2.0 * x * y; + } + else if(im == 3) + { + Am[3] = x3 - 3.0 * x * y2; + Bm[3] = 3.0 * x2 * y - y3; + } + else if(im == 4) + { + Am[4] = x4 - 6.0 * x2 * y2 + y4; + Bm[4] = 4.0 * (x3 * y - x * y3); + } + else if(im == 5) + { + Am[5] = x5 - 10.0 * x3 * y2 + 5.0 * x * y4; + Bm[5] = 5.0 * x4 * y - 10.0 * x2 * y3 + y5; + } + else + { + for(int ip = 0; ip <= im; ip++) + { + double aux = Fact(im) / Fact(ip) / Fact(im - ip); + Am[im] += aux * pow(x, ip) * pow(y, im-ip) * cos( (im-ip) * ModuleBase::PI / 2.0 ); + Bm[im] += aux * pow(x, ip) * pow(y, im-ip) * sin( (im-ip) * ModuleBase::PI / 2.0 ); + } + } + } + + //z dependence + double zdep[20][20]; // for(int il = 0; il < 20; il++) // { // ZEROS(zdep[il], 20); // } - double z2 = z * z; - double z3 = z2 * z; - double z4 = z3 * z; - //double z5 = z4 * z; - - double r = sqrt(x*x + y*y + z*z); - double r2 = r * r; - double r3 = r2 * r; - double r4 = r3 * r; - - for(int il = 0; il < MaxL+1; il++) - { - if(il == 0) - { - zdep[0][0] = 1.0; - } - else if(il == 1) - { - zdep[1][0] = z; - zdep[1][1] = 1.0; - } - else if(il == 2) - { - zdep[2][0] = 0.5 * (3.0 * z2 - r2); - zdep[2][1] = sqrt(3.0) * z; - zdep[2][2] = sqrt(3.0) * 0.5; - } - else if(il == 3) - { - zdep[3][0] = 2.5 * z3 - 1.5 * z * r2; - zdep[3][1] = 0.25 * sqrt(6.0) * (5.0 * z2 - r2); - zdep[3][2] = 0.5 * sqrt(15.0) * z; - zdep[3][3] = 0.25 * sqrt(10.0); - } - else if(il == 4) - { - zdep[4][0] = 0.125 * (35.0 * z4 - 30.0 * r2 * z2 + 3.0 * r4); - zdep[4][1] = sqrt(10.0) * 0.25 * z * (7.0 * z2 - 3.0 * r2); - zdep[4][2] = sqrt(5.0) * 0.25 * (7.0 * z2 - r2); - zdep[4][3] = sqrt(70.0) * 0.25 * z; - zdep[4][4] = sqrt(35.0) * 0.125; - } - else if(il == 5) - { - zdep[5][0] = 0.125 * z *( 63.0 * z4 - 70.0 * z2 * r2 + 15.0 * r4); - zdep[5][1] = 0.125 * sqrt(15.0) * (21.0 * z4 - 14.0 * z2 * r2 + r4); - zdep[5][2] = 0.25 * sqrt(105.0) * z * (3.0 * z2 - r2); - zdep[5][3] = 0.0625 * sqrt(70.0) * (9.0 * z2 - r2); - zdep[5][4] = 0.375 * sqrt(35.0) * z; - zdep[5][5] = 0.1875 * sqrt(14.0); - } - else - { - for(int im = 0; im <= il; im++) - { - int kmax = static_cast( (il - im) / 2 ); - for(int ik = 0; ik <= kmax; ik++) - { - int twok = 2 * ik; - - double gamma = 0.0; - double aux0, aux1, aux2, aux3; - - aux0 = pow(-1.0, ik) * pow(2.0, -il); - aux1 = Fact(il) / Fact(ik) / Fact(il-ik); - aux2 = Fact(2*il - twok) / Fact(il) / Fact(il - twok); - aux3 = Fact(il - twok) / Fact(il - twok - im); - - gamma = aux0 * aux1 * aux2 * aux3; - - assert(il - twok - im >= 0); - zdep[il][im] += pow(r, twok) * pow(z, il-twok-im) * gamma; - } - - if(im >= 1) - { - zdep[il][im] *= sqrt(2 * Fact(il - im) / Fact(il + im)); - } - } - } - } - - //calc - int ic = 0; - for(int il = 0; il <= MaxL; il++) - { - double fac = sqrt( (2.0 * il + 1.0) / ModuleBase::FOUR_PI ); - - //m=0 - rly[ic] = Am[0] * zdep[il][0] * fac; - - ic++; - - //m ! = 0 - for(int im = 1; im <= il; im++) - { - //m>0 - rly[ic] = Am[im] * zdep[il][im] * pow(-1.0, im) * fac; - - ic++; - - //m<0 - rly[ic] = Bm[im] * zdep[il][im] * pow(-1.0, im) * fac; - - ic++; - } - } + double z2 = z * z; + double z3 = z2 * z; + double z4 = z3 * z; + //double z5 = z4 * z; + + double r = sqrt(x*x + y*y + z*z); + double r2 = r * r; + double r3 = r2 * r; + double r4 = r3 * r; + + for(int il = 0; il < MaxL+1; il++) + { + if(il == 0) + { + zdep[0][0] = 1.0; + } + else if(il == 1) + { + zdep[1][0] = z; + zdep[1][1] = 1.0; + } + else if(il == 2) + { + zdep[2][0] = 0.5 * (3.0 * z2 - r2); + zdep[2][1] = sqrt(3.0) * z; + zdep[2][2] = sqrt(3.0) * 0.5; + } + else if(il == 3) + { + zdep[3][0] = 2.5 * z3 - 1.5 * z * r2; + zdep[3][1] = 0.25 * sqrt(6.0) * (5.0 * z2 - r2); + zdep[3][2] = 0.5 * sqrt(15.0) * z; + zdep[3][3] = 0.25 * sqrt(10.0); + } + else if(il == 4) + { + zdep[4][0] = 0.125 * (35.0 * z4 - 30.0 * r2 * z2 + 3.0 * r4); + zdep[4][1] = sqrt(10.0) * 0.25 * z * (7.0 * z2 - 3.0 * r2); + zdep[4][2] = sqrt(5.0) * 0.25 * (7.0 * z2 - r2); + zdep[4][3] = sqrt(70.0) * 0.25 * z; + zdep[4][4] = sqrt(35.0) * 0.125; + } + else if(il == 5) + { + zdep[5][0] = 0.125 * z *( 63.0 * z4 - 70.0 * z2 * r2 + 15.0 * r4); + zdep[5][1] = 0.125 * sqrt(15.0) * (21.0 * z4 - 14.0 * z2 * r2 + r4); + zdep[5][2] = 0.25 * sqrt(105.0) * z * (3.0 * z2 - r2); + zdep[5][3] = 0.0625 * sqrt(70.0) * (9.0 * z2 - r2); + zdep[5][4] = 0.375 * sqrt(35.0) * z; + zdep[5][5] = 0.1875 * sqrt(14.0); + } + else + { + for(int im = 0; im <= il; im++) + { + int kmax = static_cast( (il - im) / 2 ); + for(int ik = 0; ik <= kmax; ik++) + { + int twok = 2 * ik; + + double gamma = 0.0; + double aux0, aux1, aux2, aux3; + + aux0 = pow(-1.0, ik) * pow(2.0, -il); + aux1 = Fact(il) / Fact(ik) / Fact(il-ik); + aux2 = Fact(2*il - twok) / Fact(il) / Fact(il - twok); + aux3 = Fact(il - twok) / Fact(il - twok - im); + + gamma = aux0 * aux1 * aux2 * aux3; + + assert(il - twok - im >= 0); + zdep[il][im] += pow(r, twok) * pow(z, il-twok-im) * gamma; + } + + if(im >= 1) + { + zdep[il][im] *= sqrt(2 * Fact(il - im) / Fact(il + im)); + } + } + } + } + + //calc + int ic = 0; + for(int il = 0; il <= MaxL; il++) + { + double fac = sqrt( (2.0 * il + 1.0) / ModuleBase::FOUR_PI ); + + //m=0 + rly[ic] = Am[0] * zdep[il][0] * fac; + + ic++; + + //m ! = 0 + for(int im = 1; im <= il; im++) + { + //m>0 + rly[ic] = Am[im] * zdep[il][im] * pow(-1.0, im) * fac; + + ic++; + + //m<0 + rly[ic] = Bm[im] * zdep[il][im] * pow(-1.0, im) * fac; + + ic++; + } + } // ModuleBase::timer::end("Ylm", "rlylm"); - return; + return; } //return ylm, not rlylm void Ylm::sph_harm ( - const int Lmax, //max momentum of l - const double xdr, - const double ydr, - const double zdr, - std::vector &rly + const int Lmax, //max momentum of l + const double xdr, + const double ydr, + const double zdr, + std::vector &rly ) { - rly.resize( (Lmax+1)*(Lmax+1) ); - - //begin calculation - /*************************** - L = 0 - ***************************/ - rly[0] = ylmcoef[0]; //l=0, m=0 - if (Lmax == 0) return; - - /*************************** - L = 1 - ***************************/ - rly[1] = ylmcoef[1]*zdr; //l=1, m=0 - rly[2] = -ylmcoef[1]*xdr; //l=1, m=1 - rly[3] = -ylmcoef[1]*ydr; //l=1, m=-1 - if (Lmax == 1) return; - - /*************************** - L = 2 - ***************************/ - rly[4] = ylmcoef[2]*zdr*rly[1]-ylmcoef[3]*rly[0];//l=2, m=0 - - double tmp0 = ylmcoef[4]*zdr; - rly[5] = tmp0*rly[2];//l=2,m=1 - rly[6] = tmp0*rly[3];//l=2,m=-1 - - double tmp2 = ylmcoef[4]*xdr; - rly[7]= ylmcoef[5]*rly[4]-ylmcoef[6]*rly[0] - tmp2*rly[2];//l=2,m=2 - rly[8] = -tmp2*rly[3]; + rly.resize( (Lmax+1)*(Lmax+1) ); + + //begin calculation + /*************************** + L = 0 + ***************************/ + rly[0] = ylmcoef[0]; //l=0, m=0 + if (Lmax == 0) return; + + /*************************** + L = 1 + ***************************/ + rly[1] = ylmcoef[1]*zdr; //l=1, m=0 + rly[2] = -ylmcoef[1]*xdr; //l=1, m=1 + rly[3] = -ylmcoef[1]*ydr; //l=1, m=-1 + if (Lmax == 1) return; + + /*************************** + L = 2 + ***************************/ + rly[4] = ylmcoef[2]*zdr*rly[1]-ylmcoef[3]*rly[0];//l=2, m=0 + + double tmp0 = ylmcoef[4]*zdr; + rly[5] = tmp0*rly[2];//l=2,m=1 + rly[6] = tmp0*rly[3];//l=2,m=-1 + + double tmp2 = ylmcoef[4]*xdr; + rly[7]= ylmcoef[5]*rly[4]-ylmcoef[6]*rly[0] - tmp2*rly[2];//l=2,m=2 + rly[8] = -tmp2*rly[3]; // rly[8] = tmp1+tmp2*rly[3];//l=2,m=-2 - if (Lmax == 2) return; - - /*************************** - L = 3 - ***************************/ - rly[9] = ylmcoef[7]*zdr*rly[4]-ylmcoef[8]*rly[1]; //l=3, m=0 - - double tmp3 = ylmcoef[9]*zdr; - rly[10] = tmp3*rly[5]-ylmcoef[10]*rly[2];//l=3,m=1 - rly[11] = tmp3*rly[6]-ylmcoef[10]*rly[3];//l=3,m=-1 - - double tmp4 = ylmcoef[11]*zdr; - rly[12] = tmp4*rly[7];//l=3,m=2 - rly[13] = tmp4*rly[8];//l=3,m=-2 - - double tmp5 = ylmcoef[14]*xdr; - rly[14] = ylmcoef[12]*rly[10]-ylmcoef[13]*rly[2]-tmp5*rly[7];//l=3,m=3 - rly[15] = ylmcoef[12]*rly[11]-ylmcoef[13]*rly[3]-tmp5*rly[8];//l=3,m=-3 - if (Lmax == 3) return; - - /*************************** - L = 4 - ***************************/ - rly[16] = ylmcoef[15]*zdr*rly[9]-ylmcoef[16]*rly[4];//l=4,m=0 - - double tmp6 = ylmcoef[17]*zdr; - rly[17] = tmp6*rly[10]-ylmcoef[18]*rly[5];//l=4,m=1 - rly[18] = tmp6*rly[11]-ylmcoef[18]*rly[6];//l=4,m=-1 - - double tmp7 = ylmcoef[19]*zdr; - rly[19] = tmp7*rly[12]-ylmcoef[20]*rly[7];//l=4,m=2 - rly[20] = tmp7*rly[13]-ylmcoef[20]*rly[8];//l=4,m=-2 - - double tmp8 = 3.0*zdr; - rly[21] = tmp8*rly[14];//l=4,m=3 - rly[22] = tmp8*rly[15];//l=4,m=-3 - - double tmp9 = ylmcoef[23]*xdr; - rly[23] = ylmcoef[21]*rly[19]-ylmcoef[22]*rly[7]-tmp9*rly[14];//l=4,m=4 - rly[24] = ylmcoef[21]*rly[20]-ylmcoef[22]*rly[8]-tmp9*rly[15];//l=4,m=-4 - if (Lmax == 4) return; - - /*************************** - L = 5 - ***************************/ - rly[25] = ylmcoef[24]*zdr*rly[16]-ylmcoef[25]*rly[9];//l=5,m=0 - - double tmp10 = ylmcoef[26]*zdr; - rly[26] = tmp10*rly[17]-ylmcoef[27]*rly[10];//l=5,m=1 - rly[27] = tmp10*rly[18]-ylmcoef[27]*rly[11];//l=5,m=-1 - - double tmp11 = ylmcoef[28]*zdr; - rly[28] = tmp11*rly[19]-ylmcoef[29]*rly[12];//l=5,m=2 - rly[29] = tmp11*rly[20]-ylmcoef[29]*rly[13];//l=5,m=-2 - - double tmp12 = ylmcoef[30]*zdr; - rly[30] = tmp12*rly[21]-ylmcoef[31]*rly[14];//l=5,m=3 - rly[31] = tmp12*rly[22]-ylmcoef[31]*rly[15];//l=5,m=-3 - - double tmp13 = ylmcoef[32]*zdr; - rly[32] = tmp13*rly[23];//l=5,m=4 - rly[33] = tmp13*rly[24];//l=5,m=-4 - - double tmp14 = ylmcoef[35]*xdr; - rly[34] = ylmcoef[33]*rly[30]-ylmcoef[34]*rly[14]-tmp14*rly[23];//l=5,m=5 - rly[35] = ylmcoef[33]*rly[31]-ylmcoef[34]*rly[15]-tmp14*rly[24];//l=5,m=-5 - if (Lmax == 5) return; - - //if Lmax > 5 - for (int il = 6; il <= Lmax; il++) - { - int istart = il*il; - int istart1 = (il-1)*(il-1); - int istart2 = (il-2)*(il-2); - - double fac2 = sqrt(4.0*istart-1.0); - double fac4 = sqrt(4.0*istart1-1.0); - - for (int im = 0; im < 2*il-1; im++) - { - int imm = (im+1)/2; + if (Lmax == 2) return; + + /*************************** + L = 3 + ***************************/ + rly[9] = ylmcoef[7]*zdr*rly[4]-ylmcoef[8]*rly[1]; //l=3, m=0 + + double tmp3 = ylmcoef[9]*zdr; + rly[10] = tmp3*rly[5]-ylmcoef[10]*rly[2];//l=3,m=1 + rly[11] = tmp3*rly[6]-ylmcoef[10]*rly[3];//l=3,m=-1 + + double tmp4 = ylmcoef[11]*zdr; + rly[12] = tmp4*rly[7];//l=3,m=2 + rly[13] = tmp4*rly[8];//l=3,m=-2 + + double tmp5 = ylmcoef[14]*xdr; + rly[14] = ylmcoef[12]*rly[10]-ylmcoef[13]*rly[2]-tmp5*rly[7];//l=3,m=3 + rly[15] = ylmcoef[12]*rly[11]-ylmcoef[13]*rly[3]-tmp5*rly[8];//l=3,m=-3 + if (Lmax == 3) return; + + /*************************** + L = 4 + ***************************/ + rly[16] = ylmcoef[15]*zdr*rly[9]-ylmcoef[16]*rly[4];//l=4,m=0 + + double tmp6 = ylmcoef[17]*zdr; + rly[17] = tmp6*rly[10]-ylmcoef[18]*rly[5];//l=4,m=1 + rly[18] = tmp6*rly[11]-ylmcoef[18]*rly[6];//l=4,m=-1 + + double tmp7 = ylmcoef[19]*zdr; + rly[19] = tmp7*rly[12]-ylmcoef[20]*rly[7];//l=4,m=2 + rly[20] = tmp7*rly[13]-ylmcoef[20]*rly[8];//l=4,m=-2 + + double tmp8 = 3.0*zdr; + rly[21] = tmp8*rly[14];//l=4,m=3 + rly[22] = tmp8*rly[15];//l=4,m=-3 + + double tmp9 = ylmcoef[23]*xdr; + rly[23] = ylmcoef[21]*rly[19]-ylmcoef[22]*rly[7]-tmp9*rly[14];//l=4,m=4 + rly[24] = ylmcoef[21]*rly[20]-ylmcoef[22]*rly[8]-tmp9*rly[15];//l=4,m=-4 + if (Lmax == 4) return; + + /*************************** + L = 5 + ***************************/ + rly[25] = ylmcoef[24]*zdr*rly[16]-ylmcoef[25]*rly[9];//l=5,m=0 + + double tmp10 = ylmcoef[26]*zdr; + rly[26] = tmp10*rly[17]-ylmcoef[27]*rly[10];//l=5,m=1 + rly[27] = tmp10*rly[18]-ylmcoef[27]*rly[11];//l=5,m=-1 + + double tmp11 = ylmcoef[28]*zdr; + rly[28] = tmp11*rly[19]-ylmcoef[29]*rly[12];//l=5,m=2 + rly[29] = tmp11*rly[20]-ylmcoef[29]*rly[13];//l=5,m=-2 + + double tmp12 = ylmcoef[30]*zdr; + rly[30] = tmp12*rly[21]-ylmcoef[31]*rly[14];//l=5,m=3 + rly[31] = tmp12*rly[22]-ylmcoef[31]*rly[15];//l=5,m=-3 + + double tmp13 = ylmcoef[32]*zdr; + rly[32] = tmp13*rly[23];//l=5,m=4 + rly[33] = tmp13*rly[24];//l=5,m=-4 + + double tmp14 = ylmcoef[35]*xdr; + rly[34] = ylmcoef[33]*rly[30]-ylmcoef[34]*rly[14]-tmp14*rly[23];//l=5,m=5 + rly[35] = ylmcoef[33]*rly[31]-ylmcoef[34]*rly[15]-tmp14*rly[24];//l=5,m=-5 + if (Lmax == 5) return; + + //if Lmax > 5 + for (int il = 6; il <= Lmax; il++) + { + int istart = il*il; + int istart1 = (il-1)*(il-1); + int istart2 = (il-2)*(il-2); + + double fac2 = sqrt(4.0*istart-1.0); + double fac4 = sqrt(4.0*istart1-1.0); + + for (int im = 0; im < 2*il-1; im++) + { + int imm = (im+1)/2; // if (im % 2 == 0) imm *= -1; - rly[istart+im] = fac2/sqrt((double)istart-imm*imm)* - (zdr*rly[istart1+im] - sqrt((double)istart1-imm*imm)/fac4*rly[istart2+im]); - } + rly[istart+im] = fac2/sqrt((double)istart-imm*imm)* + (zdr*rly[istart1+im] - sqrt((double)istart1-imm*imm)/fac4*rly[istart2+im]); + } - double bl1 = sqrt(2.0*il/(2.0*il+1.0)); - double bl2 = sqrt((2.0*il-2.0)/(2.0*il-1.0)); - double bl3 = sqrt(2.0)/fac2; + double bl1 = sqrt(2.0*il/(2.0*il+1.0)); + double bl2 = sqrt((2.0*il-2.0)/(2.0*il-1.0)); + double bl3 = sqrt(2.0)/fac2; - rly[istart+2*il-1] = (bl3*rly[istart+2*il-5]-bl2*rly[istart2+2*il-5]-2.0*xdr*rly[istart1+2*il-3]) / bl1; - rly[istart+2*il] = (bl3*rly[istart+2*il-4]-bl2*rly[istart2+2*il-4]-2.0*xdr*rly[istart1+2*il-2]) / bl1; - } + rly[istart+2*il-1] = (bl3*rly[istart+2*il-5]-bl2*rly[istart2+2*il-5]-2.0*xdr*rly[istart1+2*il-3]) / bl1; + rly[istart+2*il] = (bl3*rly[istart+2*il-4]-bl2*rly[istart2+2*il-4]-2.0*xdr*rly[istart1+2*il-2]) / bl1; + } - return; + return; } // Peize Lin change rly 2016-08-26 void Ylm::rl_sph_harm ( - const int Lmax, //max momentum of L - const double x, - const double y, - const double z, - std::vector& rly + const int Lmax, //max momentum of L + const double x, + const double y, + const double z, + std::vector& rly ) { - rly.resize( (Lmax+1)*(Lmax+1) ); - - double radius2 = x*x+y*y+z*z; - - //begin calculation - /*************************** - L = 0 - ***************************/ - rly[0] = ylmcoef[0]; //l=0, m=0 - if (Lmax == 0) return; - - /*************************** - L = 1 - ***************************/ - rly[1] = ylmcoef[1]*z; //l=1, m=0 - rly[2] = -ylmcoef[1]*x; //l=1, m=1 - rly[3] = -ylmcoef[1]*y; //l=1, m=-1 - if (Lmax == 1) return; - - /*************************** - L = 2 - ***************************/ - rly[4] = ylmcoef[2]*z*rly[1]-ylmcoef[3]*rly[0]*radius2;//l=2, m=0 - - double tmp0 = ylmcoef[4]*z; - rly[5] = tmp0*rly[2];//l=2,m=1 - rly[6] = tmp0*rly[3];//l=2,m=-1 - - double tmp2 = ylmcoef[4]*x; - rly[7]= ylmcoef[5]*rly[4]-ylmcoef[6]*rly[0]*radius2 - tmp2*rly[2];//l=2,m=2 - rly[8] = -tmp2*rly[3]; + rly.resize( (Lmax+1)*(Lmax+1) ); + + double radius2 = x*x+y*y+z*z; + + //begin calculation + /*************************** + L = 0 + ***************************/ + rly[0] = ylmcoef[0]; //l=0, m=0 + if (Lmax == 0) return; + + /*************************** + L = 1 + ***************************/ + rly[1] = ylmcoef[1]*z; //l=1, m=0 + rly[2] = -ylmcoef[1]*x; //l=1, m=1 + rly[3] = -ylmcoef[1]*y; //l=1, m=-1 + if (Lmax == 1) return; + + /*************************** + L = 2 + ***************************/ + rly[4] = ylmcoef[2]*z*rly[1]-ylmcoef[3]*rly[0]*radius2;//l=2, m=0 + + double tmp0 = ylmcoef[4]*z; + rly[5] = tmp0*rly[2];//l=2,m=1 + rly[6] = tmp0*rly[3];//l=2,m=-1 + + double tmp2 = ylmcoef[4]*x; + rly[7]= ylmcoef[5]*rly[4]-ylmcoef[6]*rly[0]*radius2 - tmp2*rly[2];//l=2,m=2 + rly[8] = -tmp2*rly[3]; // rly[8] = tmp1+tmp2*rly[3];//l=2,m=-2 - if (Lmax == 2) return; - - /*************************** - L = 3 - ***************************/ - rly[9] = ylmcoef[7]*z*rly[4]-ylmcoef[8]*rly[1]*radius2; //l=3, m=0 - - double tmp3 = ylmcoef[9]*z; - rly[10] = tmp3*rly[5]-ylmcoef[10]*rly[2]*radius2;//l=3,m=1 - rly[11] = tmp3*rly[6]-ylmcoef[10]*rly[3]*radius2;//l=3,m=-1 - - double tmp4 = ylmcoef[11]*z; - rly[12] = tmp4*rly[7];//l=3,m=2 - rly[13] = tmp4*rly[8];//l=3,m=-2 - - double tmp5 = ylmcoef[14]*x; - rly[14] = ylmcoef[12]*rly[10]-ylmcoef[13]*rly[2]*radius2-tmp5*rly[7];//l=3,m=3 - rly[15] = ylmcoef[12]*rly[11]-ylmcoef[13]*rly[3]*radius2-tmp5*rly[8];//l=3,m=-3 - if (Lmax == 3) return; - - /*************************** - L = 4 - ***************************/ - rly[16] = ylmcoef[15]*z*rly[9]-ylmcoef[16]*rly[4]*radius2;//l=4,m=0 - - double tmp6 = ylmcoef[17]*z; - rly[17] = tmp6*rly[10]-ylmcoef[18]*rly[5]*radius2;//l=4,m=1 - rly[18] = tmp6*rly[11]-ylmcoef[18]*rly[6]*radius2;//l=4,m=-1 - - double tmp7 = ylmcoef[19]*z; - rly[19] = tmp7*rly[12]-ylmcoef[20]*rly[7]*radius2;//l=4,m=2 - rly[20] = tmp7*rly[13]-ylmcoef[20]*rly[8]*radius2;//l=4,m=-2 - - double tmp8 = 3.0*z; - rly[21] = tmp8*rly[14];//l=4,m=3 - rly[22] = tmp8*rly[15];//l=4,m=-3 - - double tmp9 = ylmcoef[23]*x; - rly[23] = ylmcoef[21]*rly[19]-ylmcoef[22]*rly[7]*radius2-tmp9*rly[14];//l=4,m=4 - rly[24] = ylmcoef[21]*rly[20]-ylmcoef[22]*rly[8]*radius2-tmp9*rly[15];//l=4,m=-4 - if (Lmax == 4) return; - - /*************************** - L = 5 - ***************************/ - rly[25] = ylmcoef[24]*z*rly[16]-ylmcoef[25]*rly[9]*radius2;//l=5,m=0 - - double tmp10 = ylmcoef[26]*z; - rly[26] = tmp10*rly[17]-ylmcoef[27]*rly[10]*radius2;//l=5,m=1 - rly[27] = tmp10*rly[18]-ylmcoef[27]*rly[11]*radius2;//l=5,m=-1 - - double tmp11 = ylmcoef[28]*z; - rly[28] = tmp11*rly[19]-ylmcoef[29]*rly[12]*radius2;//l=5,m=2 - rly[29] = tmp11*rly[20]-ylmcoef[29]*rly[13]*radius2;//l=5,m=-2 - - double tmp12 = ylmcoef[30]*z; - rly[30] = tmp12*rly[21]-ylmcoef[31]*rly[14]*radius2;//l=5,m=3 - rly[31] = tmp12*rly[22]-ylmcoef[31]*rly[15]*radius2;//l=5,m=-3 - - double tmp13 = ylmcoef[32]*z; - rly[32] = tmp13*rly[23];//l=5,m=4 - rly[33] = tmp13*rly[24];//l=5,m=-4 - - double tmp14 = ylmcoef[35]*x; - rly[34] = ylmcoef[33]*rly[30]-ylmcoef[34]*rly[14]*radius2-tmp14*rly[23];//l=5,m=5 - rly[35] = ylmcoef[33]*rly[31]-ylmcoef[34]*rly[15]*radius2-tmp14*rly[24];//l=5,m=-5 - if (Lmax == 5) return; - - //if Lmax > 5 - for (int il = 6; il <= Lmax; il++) - { - int istart = il*il; - int istart1 = (il-1)*(il-1); - int istart2 = (il-2)*(il-2); - - double fac2 = sqrt(4.0*istart-1); - double fac4 = sqrt(4.0*istart1-1); - - for (int im = 0; im < 2*il-1; im++) - { - int imm = (im+1)/2; + if (Lmax == 2) return; + + /*************************** + L = 3 + ***************************/ + rly[9] = ylmcoef[7]*z*rly[4]-ylmcoef[8]*rly[1]*radius2; //l=3, m=0 + + double tmp3 = ylmcoef[9]*z; + rly[10] = tmp3*rly[5]-ylmcoef[10]*rly[2]*radius2;//l=3,m=1 + rly[11] = tmp3*rly[6]-ylmcoef[10]*rly[3]*radius2;//l=3,m=-1 + + double tmp4 = ylmcoef[11]*z; + rly[12] = tmp4*rly[7];//l=3,m=2 + rly[13] = tmp4*rly[8];//l=3,m=-2 + + double tmp5 = ylmcoef[14]*x; + rly[14] = ylmcoef[12]*rly[10]-ylmcoef[13]*rly[2]*radius2-tmp5*rly[7];//l=3,m=3 + rly[15] = ylmcoef[12]*rly[11]-ylmcoef[13]*rly[3]*radius2-tmp5*rly[8];//l=3,m=-3 + if (Lmax == 3) return; + + /*************************** + L = 4 + ***************************/ + rly[16] = ylmcoef[15]*z*rly[9]-ylmcoef[16]*rly[4]*radius2;//l=4,m=0 + + double tmp6 = ylmcoef[17]*z; + rly[17] = tmp6*rly[10]-ylmcoef[18]*rly[5]*radius2;//l=4,m=1 + rly[18] = tmp6*rly[11]-ylmcoef[18]*rly[6]*radius2;//l=4,m=-1 + + double tmp7 = ylmcoef[19]*z; + rly[19] = tmp7*rly[12]-ylmcoef[20]*rly[7]*radius2;//l=4,m=2 + rly[20] = tmp7*rly[13]-ylmcoef[20]*rly[8]*radius2;//l=4,m=-2 + + double tmp8 = 3.0*z; + rly[21] = tmp8*rly[14];//l=4,m=3 + rly[22] = tmp8*rly[15];//l=4,m=-3 + + double tmp9 = ylmcoef[23]*x; + rly[23] = ylmcoef[21]*rly[19]-ylmcoef[22]*rly[7]*radius2-tmp9*rly[14];//l=4,m=4 + rly[24] = ylmcoef[21]*rly[20]-ylmcoef[22]*rly[8]*radius2-tmp9*rly[15];//l=4,m=-4 + if (Lmax == 4) return; + + /*************************** + L = 5 + ***************************/ + rly[25] = ylmcoef[24]*z*rly[16]-ylmcoef[25]*rly[9]*radius2;//l=5,m=0 + + double tmp10 = ylmcoef[26]*z; + rly[26] = tmp10*rly[17]-ylmcoef[27]*rly[10]*radius2;//l=5,m=1 + rly[27] = tmp10*rly[18]-ylmcoef[27]*rly[11]*radius2;//l=5,m=-1 + + double tmp11 = ylmcoef[28]*z; + rly[28] = tmp11*rly[19]-ylmcoef[29]*rly[12]*radius2;//l=5,m=2 + rly[29] = tmp11*rly[20]-ylmcoef[29]*rly[13]*radius2;//l=5,m=-2 + + double tmp12 = ylmcoef[30]*z; + rly[30] = tmp12*rly[21]-ylmcoef[31]*rly[14]*radius2;//l=5,m=3 + rly[31] = tmp12*rly[22]-ylmcoef[31]*rly[15]*radius2;//l=5,m=-3 + + double tmp13 = ylmcoef[32]*z; + rly[32] = tmp13*rly[23];//l=5,m=4 + rly[33] = tmp13*rly[24];//l=5,m=-4 + + double tmp14 = ylmcoef[35]*x; + rly[34] = ylmcoef[33]*rly[30]-ylmcoef[34]*rly[14]*radius2-tmp14*rly[23];//l=5,m=5 + rly[35] = ylmcoef[33]*rly[31]-ylmcoef[34]*rly[15]*radius2-tmp14*rly[24];//l=5,m=-5 + if (Lmax == 5) return; + + //if Lmax > 5 + for (int il = 6; il <= Lmax; il++) + { + int istart = il*il; + int istart1 = (il-1)*(il-1); + int istart2 = (il-2)*(il-2); + + double fac2 = sqrt(4.0*istart-1); + double fac4 = sqrt(4.0*istart1-1); + + for (int im = 0; im < 2*il-1; im++) + { + int imm = (im+1)/2; // if (im % 2 == 0) imm *= -1; - rly[istart+im] = fac2/sqrt((double)istart-imm*imm)* - (z*rly[istart1+im] - sqrt((double)istart1-imm*imm)/fac4*rly[istart2+im]*radius2); - } + rly[istart+im] = fac2/sqrt((double)istart-imm*imm)* + (z*rly[istart1+im] - sqrt((double)istart1-imm*imm)/fac4*rly[istart2+im]*radius2); + } - double bl1 = sqrt(2.0*il/(2.0*il+1.0)); - double bl2 = sqrt((2.0*il-2.0)/(2.0*il-1.0)); - double bl3 = sqrt(2.0)/fac2; + double bl1 = sqrt(2.0*il/(2.0*il+1.0)); + double bl2 = sqrt((2.0*il-2.0)/(2.0*il-1.0)); + double bl3 = sqrt(2.0)/fac2; - rly[istart+2*il-1] = (bl3*rly[istart+2*il-5]-bl2*rly[istart2+2*il-5]*radius2-2.0*x*rly[istart1+2*il-3]) / bl1; - rly[istart+2*il] = (bl3*rly[istart+2*il-4]-bl2*rly[istart2+2*il-4]*radius2-2.0*x*rly[istart1+2*il-2]) / bl1; - } + rly[istart+2*il-1] = (bl3*rly[istart+2*il-5]-bl2*rly[istart2+2*il-5]*radius2-2.0*x*rly[istart1+2*il-3]) / bl1; + rly[istart+2*il] = (bl3*rly[istart+2*il-4]-bl2*rly[istart2+2*il-4]*radius2-2.0*x*rly[istart1+2*il-2]) / bl1; + } - return; + return; } void Ylm::grad_rl_sph_harm ( - const int Lmax, //max momentum of L - const double x, - const double y, - const double z, - double* rly, - double* grly_flat + const int Lmax, //max momentum of L + const double x, + const double y, + const double z, + double* rly, + double* grly_flat ) { - // Alias the flat buffer as a pointer-to-array-of-3-doubles so the body - // below can continue to use the natural grly[lm][xyz] indexing without - // any performance penalty — the memory layout is unchanged. - double (*grly)[3] = reinterpret_cast(grly_flat); - double radius2 = x*x+y*y+z*z; - double tx = 2.0*x; - double ty = 2.0*y; - double tz = 2.0*z; - - //begin calculation - /*************************** - L = 0 - ***************************/ - rly[0] = ylmcoef[0]; //l=0, m=0 - grly[0][0] = grly[0][1] = grly[0][2] = 0.0; - if (Lmax == 0) return; - - /*************************** - L = 1 - ***************************/ - rly[1] = ylmcoef[1]*z; //l=1, m=0 - grly[1][0] = grly[1][1] = 0.0; - grly[1][2] = ylmcoef[1]; - - rly[2] = -ylmcoef[1]*x; //l=1, m=1 - grly[2][1] = grly[2][2] = 0.0; - grly[2][0] = -ylmcoef[1]; - - rly[3] = -ylmcoef[1]*y; //l=1, m=-1 - grly[3][0] = grly[3][2] = 0.0; - grly[3][1] = -ylmcoef[1]; - - if (Lmax == 1) return; - - /*************************** - L = 2 - ***************************/ - rly[4] = ylmcoef[2]*z*rly[1]-ylmcoef[3]*rly[0]*radius2;//l=2, m=0 - grly[4][0] = ylmcoef[2]*z*grly[1][0]-ylmcoef[3]*(grly[0][0]*radius2+rly[0]*tx);//l=2, m=0 - grly[4][1] = ylmcoef[2]*z*grly[1][1]-ylmcoef[3]*(grly[0][1]*radius2+rly[0]*ty);//l=2, m=0 - grly[4][2] = ylmcoef[2]*(z*grly[1][2]+rly[1])-ylmcoef[3]*(grly[0][2]*radius2+rly[0]*tz);//l=2, m=0 - - - double tmp0 = ylmcoef[4]*z; - rly[5] = tmp0*rly[2];//l=2,m=1 - grly[5][0] = tmp0*grly[2][0]; - grly[5][1] = tmp0*grly[2][1]; - grly[5][2] = ylmcoef[4]*(rly[2]+z*grly[2][2]); - - rly[6] = tmp0*rly[3];//l=2,m=-1 - grly[6][0] = tmp0*grly[3][0]; - grly[6][1] = tmp0*grly[3][1]; - grly[6][2] = ylmcoef[4]*(rly[3]+z*grly[3][2]); - - double tmp2 = ylmcoef[4]*x; - rly[7]= ylmcoef[5]*rly[4]-ylmcoef[6]*rly[0]*radius2 - tmp2*rly[2];//l=2,m=2 - grly[7][0] = ylmcoef[5]*grly[4][0]-ylmcoef[6]*(rly[0]*tx+grly[0][0]*radius2)-ylmcoef[4]*(x*grly[2][0]+rly[2]); + // Alias the flat buffer as a pointer-to-array-of-3-doubles so the body + // below can continue to use the natural grly[lm][xyz] indexing without + // any performance penalty — the memory layout is unchanged. + double (*grly)[3] = reinterpret_cast(grly_flat); + double radius2 = x*x+y*y+z*z; + double tx = 2.0*x; + double ty = 2.0*y; + double tz = 2.0*z; + + //begin calculation + /*************************** + L = 0 + ***************************/ + rly[0] = ylmcoef[0]; //l=0, m=0 + grly[0][0] = grly[0][1] = grly[0][2] = 0.0; + if (Lmax == 0) return; + + /*************************** + L = 1 + ***************************/ + rly[1] = ylmcoef[1]*z; //l=1, m=0 + grly[1][0] = grly[1][1] = 0.0; + grly[1][2] = ylmcoef[1]; + + rly[2] = -ylmcoef[1]*x; //l=1, m=1 + grly[2][1] = grly[2][2] = 0.0; + grly[2][0] = -ylmcoef[1]; + + rly[3] = -ylmcoef[1]*y; //l=1, m=-1 + grly[3][0] = grly[3][2] = 0.0; + grly[3][1] = -ylmcoef[1]; + + if (Lmax == 1) return; + + /*************************** + L = 2 + ***************************/ + rly[4] = ylmcoef[2]*z*rly[1]-ylmcoef[3]*rly[0]*radius2;//l=2, m=0 + grly[4][0] = ylmcoef[2]*z*grly[1][0]-ylmcoef[3]*(grly[0][0]*radius2+rly[0]*tx);//l=2, m=0 + grly[4][1] = ylmcoef[2]*z*grly[1][1]-ylmcoef[3]*(grly[0][1]*radius2+rly[0]*ty);//l=2, m=0 + grly[4][2] = ylmcoef[2]*(z*grly[1][2]+rly[1])-ylmcoef[3]*(grly[0][2]*radius2+rly[0]*tz);//l=2, m=0 + + + double tmp0 = ylmcoef[4]*z; + rly[5] = tmp0*rly[2];//l=2,m=1 + grly[5][0] = tmp0*grly[2][0]; + grly[5][1] = tmp0*grly[2][1]; + grly[5][2] = ylmcoef[4]*(rly[2]+z*grly[2][2]); + + rly[6] = tmp0*rly[3];//l=2,m=-1 + grly[6][0] = tmp0*grly[3][0]; + grly[6][1] = tmp0*grly[3][1]; + grly[6][2] = ylmcoef[4]*(rly[3]+z*grly[3][2]); + + double tmp2 = ylmcoef[4]*x; + rly[7]= ylmcoef[5]*rly[4]-ylmcoef[6]*rly[0]*radius2 - tmp2*rly[2];//l=2,m=2 + grly[7][0] = ylmcoef[5]*grly[4][0]-ylmcoef[6]*(rly[0]*tx+grly[0][0]*radius2)-ylmcoef[4]*(x*grly[2][0]+rly[2]); // std::cout << "\np1 = "<< ylmcoef[5]*grly[4][0] << " p2 = " << -ylmcoef[6]*rly[0]*tx // << " p3 = " << -ylmcoef[4]*x*grly[2][0] << " p4 = " << -ylmcoef[4]*rly[2] << std::endl; - grly[7][1] = ylmcoef[5]*grly[4][1]-ylmcoef[6]*(rly[0]*ty+grly[0][1]*radius2)-tmp2*grly[2][1]; - grly[7][2] = ylmcoef[5]*grly[4][2]-ylmcoef[6]*(rly[0]*tz+grly[0][2]*radius2)-tmp2*grly[2][2]; + grly[7][1] = ylmcoef[5]*grly[4][1]-ylmcoef[6]*(rly[0]*ty+grly[0][1]*radius2)-tmp2*grly[2][1]; + grly[7][2] = ylmcoef[5]*grly[4][2]-ylmcoef[6]*(rly[0]*tz+grly[0][2]*radius2)-tmp2*grly[2][2]; - rly[8] = -tmp2*rly[3]; - grly[8][0] = -ylmcoef[4]*(rly[3]+x*grly[3][0]); - grly[8][1] = -tmp2*grly[3][1]; - grly[8][2] = -tmp2*grly[3][2]; + rly[8] = -tmp2*rly[3]; + grly[8][0] = -ylmcoef[4]*(rly[3]+x*grly[3][0]); + grly[8][1] = -tmp2*grly[3][1]; + grly[8][2] = -tmp2*grly[3][2]; // rly[8] = tmp1+tmp2*rly[3];//l=2,m=-2 - if (Lmax == 2) return; - - /*************************** - L = 3 - ***************************/ - rly[9] = ylmcoef[7]*z*rly[4]-ylmcoef[8]*rly[1]*radius2; //l=3, m=0 - grly[9][0] = ylmcoef[7]*z*grly[4][0]-ylmcoef[8]*(rly[1]*tx+grly[1][0]*radius2); - grly[9][1] = ylmcoef[7]*z*grly[4][1]-ylmcoef[8]*(rly[1]*ty+grly[1][1]*radius2); - grly[9][2] = ylmcoef[7]*(rly[4]+z*grly[4][2])-ylmcoef[8]*(rly[1]*tz+grly[1][2]*radius2); - - double tmp3 = ylmcoef[9]*z; - rly[10] = tmp3*rly[5]-ylmcoef[10]*rly[2]*radius2;//l=3,m=1 - grly[10][0] = tmp3*grly[5][0]-ylmcoef[10]*(grly[2][0]*radius2+rly[2]*tx); - grly[10][1] = tmp3*grly[5][1]-ylmcoef[10]*(grly[2][1]*radius2+rly[2]*ty); - grly[10][2] = ylmcoef[9]*(z*grly[5][2]+rly[5])-ylmcoef[10]*(grly[2][2]*radius2+rly[2]*tz); - - rly[11] = tmp3*rly[6]-ylmcoef[10]*rly[3]*radius2;//l=3,m=-1 - grly[11][0] = tmp3*grly[6][0]-ylmcoef[10]*(grly[3][0]*radius2+rly[3]*tx); - grly[11][1] = tmp3*grly[6][1]-ylmcoef[10]*(grly[3][1]*radius2+rly[3]*ty); - grly[11][2] = ylmcoef[9]*(z*grly[6][2]+rly[6])-ylmcoef[10]*(grly[3][2]*radius2+rly[3]*tz); - - double tmp4 = ylmcoef[11]*z; - rly[12] = tmp4*rly[7];//l=3,m=2 - grly[12][0] = tmp4*grly[7][0]; - grly[12][1] = tmp4*grly[7][1]; - grly[12][2] = ylmcoef[11]*(z*grly[7][2]+rly[7]); - - rly[13] = tmp4*rly[8];//l=3,m=-2 - grly[13][0] = tmp4*grly[8][0]; - grly[13][1] = tmp4*grly[8][1]; - grly[13][2] = ylmcoef[11]*(z*grly[8][2]+rly[8]); - - double tmp5 = ylmcoef[14]*x; - rly[14] = ylmcoef[12]*rly[10]-ylmcoef[13]*rly[2]*radius2-tmp5*rly[7];//l=3,m=3 - grly[14][0] = ylmcoef[12]*grly[10][0]-ylmcoef[13]*(rly[2]*tx+grly[2][0]*radius2)-ylmcoef[14]*(rly[7]+x*grly[7][0]); - grly[14][1] = ylmcoef[12]*grly[10][1]-ylmcoef[13]*(rly[2]*ty+grly[2][1]*radius2)-tmp5*grly[7][1]; - grly[14][2] = ylmcoef[12]*grly[10][2]-ylmcoef[13]*(rly[2]*tz+grly[2][2]*radius2)-tmp5*grly[7][2]; - - rly[15] = ylmcoef[12]*rly[11]-ylmcoef[13]*rly[3]*radius2-tmp5*rly[8];//l=3,m=-3 - grly[15][0] = ylmcoef[12]*grly[11][0]-ylmcoef[13]*(rly[3]*tx+grly[3][0]*radius2)-ylmcoef[14]*(rly[8]+x*grly[8][0]); - grly[15][1] = ylmcoef[12]*grly[11][1]-ylmcoef[13]*(rly[3]*ty+grly[3][1]*radius2)-tmp5*grly[8][1]; - grly[15][2] = ylmcoef[12]*grly[11][2]-ylmcoef[13]*(rly[3]*tz+grly[3][2]*radius2)-tmp5*grly[8][2]; - if (Lmax == 3) return; - - /*************************** - L = 4 - ***************************/ - rly[16] = ylmcoef[15]*z*rly[9]-ylmcoef[16]*rly[4]*radius2;//l=4,m=0 - grly[16][0] = ylmcoef[15]*z*grly[9][0]-ylmcoef[16]*(rly[4]*tx+grly[4][0]*radius2); - grly[16][1] = ylmcoef[15]*z*grly[9][1]-ylmcoef[16]*(rly[4]*ty+grly[4][1]*radius2); - grly[16][2] = ylmcoef[15]*(z*grly[9][2]+rly[9])-ylmcoef[16]*(rly[4]*tz+grly[4][2]*radius2); - - double tmp6 = ylmcoef[17]*z; - rly[17] = tmp6*rly[10]-ylmcoef[18]*rly[5]*radius2;//l=4,m=1 - grly[17][0] = tmp6*grly[10][0]-ylmcoef[18]*(rly[5]*tx+grly[5][0]*radius2); - grly[17][1] = tmp6*grly[10][1]-ylmcoef[18]*(rly[5]*ty+grly[5][1]*radius2); - grly[17][2] = ylmcoef[17]*(z*grly[10][2]+rly[10])-ylmcoef[18]*(rly[5]*tz+grly[5][2]*radius2); - - rly[18] = tmp6*rly[11]-ylmcoef[18]*rly[6]*radius2;//l=4,m=-1 - grly[18][0] = tmp6*grly[11][0]-ylmcoef[18]*(rly[6]*tx+grly[6][0]*radius2); - grly[18][1] = tmp6*grly[11][1]-ylmcoef[18]*(rly[6]*ty+grly[6][1]*radius2); - grly[18][2] = ylmcoef[17]*(z*grly[11][2]+rly[11])-ylmcoef[18]*(rly[6]*tz+grly[6][2]*radius2); - - double tmp7 = ylmcoef[19]*z; - rly[19] = tmp7*rly[12]-ylmcoef[20]*rly[7]*radius2;//l=4,m=2 - grly[19][0] = tmp7*grly[12][0]-ylmcoef[20]*(rly[7]*tx+grly[7][0]*radius2); - grly[19][1] = tmp7*grly[12][1]-ylmcoef[20]*(rly[7]*ty+grly[7][1]*radius2); - grly[19][2] = ylmcoef[19]*(z*grly[12][2]+rly[12])-ylmcoef[20]*(rly[7]*tz+grly[7][2]*radius2); - - rly[20] = tmp7*rly[13]-ylmcoef[20]*rly[8]*radius2;//l=4,m=-2 - grly[20][0] = tmp7*grly[13][0]-ylmcoef[20]*(rly[8]*tx+grly[8][0]*radius2); - grly[20][1] = tmp7*grly[13][1]-ylmcoef[20]*(rly[8]*ty+grly[8][1]*radius2); - grly[20][2] = ylmcoef[19]*(z*grly[13][2]+rly[13])-ylmcoef[20]*(rly[8]*tz+grly[8][2]*radius2); - - double tmp8 = 3.0*z; - rly[21] = tmp8*rly[14];//l=4,m=3 - grly[21][0] = tmp8*grly[14][0]; - grly[21][1] = tmp8*grly[14][1]; - grly[21][2] = 3.0*(z*grly[14][2]+rly[14]); - - - rly[22] = tmp8*rly[15];//l=4,m=-3 - grly[22][0] = tmp8*grly[15][0]; - grly[22][1] = tmp8*grly[15][1]; - grly[22][2] = 3.0*(z*grly[15][2]+rly[15]); - - double tmp9 = ylmcoef[23]*x; - rly[23] = ylmcoef[21]*rly[19]-ylmcoef[22]*rly[7]*radius2-tmp9*rly[14];//l=4,m=4 - grly[23][0] = ylmcoef[21]*grly[19][0]-ylmcoef[22]*(rly[7]*tx+grly[7][0]*radius2)-ylmcoef[23]*(x*grly[14][0]+rly[14]); - grly[23][1] = ylmcoef[21]*grly[19][1]-ylmcoef[22]*(rly[7]*ty+grly[7][1]*radius2)-tmp9*grly[14][1]; - grly[23][2] = ylmcoef[21]*grly[19][2]-ylmcoef[22]*(rly[7]*tz+grly[7][2]*radius2)-tmp9*grly[14][2]; - - rly[24] = ylmcoef[21]*rly[20]-ylmcoef[22]*rly[8]*radius2-tmp9*rly[15];//l=4,m=-4 - grly[24][0] = ylmcoef[21]*grly[20][0]-ylmcoef[22]*(rly[8]*tx+grly[8][0]*radius2)-ylmcoef[23]*(x*grly[15][0]+rly[15]); - grly[24][1] = ylmcoef[21]*grly[20][1]-ylmcoef[22]*(rly[8]*ty+grly[8][1]*radius2)-tmp9*grly[15][1]; - grly[24][2] = ylmcoef[21]*grly[20][2]-ylmcoef[22]*(rly[8]*tz+grly[8][2]*radius2)-tmp9*grly[15][2]; - - if (Lmax == 4) return; - - /*************************** - L = 5 - ***************************/ - rly[25] = ylmcoef[24]*z*rly[16]-ylmcoef[25]*rly[9]*radius2;//l=5,m=0 - grly[25][0] = ylmcoef[24]*z*grly[16][0]-ylmcoef[25]*(rly[9]*tx+grly[9][0]*radius2); - grly[25][1] = ylmcoef[24]*z*grly[16][1]-ylmcoef[25]*(rly[9]*ty+grly[9][1]*radius2); - grly[25][2] = ylmcoef[24]*(z*grly[16][2]+rly[16])-ylmcoef[25]*(rly[9]*tz+grly[9][2]*radius2); - - double tmp10 = ylmcoef[26]*z; - rly[26] = tmp10*rly[17]-ylmcoef[27]*rly[10]*radius2;//l=5,m=1 - grly[26][0] = tmp10*grly[17][0]-ylmcoef[27]*(rly[10]*tx+grly[10][0]*radius2); - grly[26][1] = tmp10*grly[17][1]-ylmcoef[27]*(rly[10]*ty+grly[10][1]*radius2); - grly[26][2] = ylmcoef[26]*(z*grly[17][2]+rly[17])-ylmcoef[27]*(rly[10]*tz+grly[10][2]*radius2); - - rly[27] = tmp10*rly[18]-ylmcoef[27]*rly[11]*radius2;//l=5,m=-1 - grly[27][0] = tmp10*grly[18][0]-ylmcoef[27]*(rly[11]*tx+grly[11][0]*radius2); - grly[27][1] = tmp10*grly[18][1]-ylmcoef[27]*(rly[11]*ty+grly[11][1]*radius2); - grly[27][2] = ylmcoef[26]*(z*grly[18][2]+rly[18])-ylmcoef[27]*(rly[11]*tz+grly[11][2]*radius2); - - double tmp11 = ylmcoef[28]*z; - rly[28] = tmp11*rly[19]-ylmcoef[29]*rly[12]*radius2;//l=5,m=2 - grly[28][0] = tmp11*grly[19][0]-ylmcoef[29]*(rly[12]*tx+grly[12][0]*radius2); - grly[28][1] = tmp11*grly[19][1]-ylmcoef[29]*(rly[12]*ty+grly[12][1]*radius2); - grly[28][2] = ylmcoef[28]*(z*grly[19][2]+rly[19])-ylmcoef[29]*(rly[12]*tz+grly[12][2]*radius2); - - rly[29] = tmp11*rly[20]-ylmcoef[29]*rly[13]*radius2;//l=5,m=-2 - grly[29][0] = tmp11*grly[20][0]-ylmcoef[29]*(rly[13]*tx+grly[13][0]*radius2); - grly[29][1] = tmp11*grly[20][1]-ylmcoef[29]*(rly[13]*ty+grly[13][1]*radius2); - grly[29][2] = ylmcoef[28]*(z*grly[20][2]+rly[20])-ylmcoef[29]*(rly[13]*tz+grly[13][2]*radius2); - - double tmp12 = ylmcoef[30]*z; - rly[30] = tmp12*rly[21]-ylmcoef[31]*rly[14]*radius2;//l=5,m=3 - grly[30][0] = tmp12*grly[21][0]-ylmcoef[31]*(grly[14][0]*radius2+rly[14]*tx); - grly[30][1] = tmp12*grly[21][1]-ylmcoef[31]*(grly[14][1]*radius2+rly[14]*ty); - grly[30][2] = ylmcoef[30]*(z*grly[21][2]+rly[21])-ylmcoef[31]*(grly[14][2]*radius2+rly[14]*tz); - - rly[31] = tmp12*rly[22]-ylmcoef[31]*rly[15]*radius2;//l=5,m=-3 - grly[31][0] = tmp12*grly[22][0]-ylmcoef[31]*(grly[15][0]*radius2+rly[15]*tx); - grly[31][1] = tmp12*grly[22][1]-ylmcoef[31]*(grly[15][1]*radius2+rly[15]*ty); - grly[31][2] = ylmcoef[30]*(z*grly[22][2]+rly[22])-ylmcoef[31]*(grly[15][2]*radius2+rly[15]*tz); - - double tmp13 = ylmcoef[32]*z; - rly[32] = tmp13*rly[23];//l=5,m=4 - grly[32][0] = tmp13*grly[23][0]; - grly[32][1] = tmp13*grly[23][1]; - grly[32][2] = ylmcoef[32]*(rly[23]+z*grly[23][2]); - - rly[33] = tmp13*rly[24];//l=5,m=-4 - grly[33][0] = tmp13*grly[24][0]; - grly[33][1] = tmp13*grly[24][1]; - grly[33][2] = ylmcoef[32]*(rly[24]+z*grly[24][2]); - - double tmp14 = ylmcoef[35]*x; - rly[34] = ylmcoef[33]*rly[30]-ylmcoef[34]*rly[14]*radius2-tmp14*rly[23];//l=5,m=5 - grly[34][0] = ylmcoef[33]*grly[30][0]-ylmcoef[34]*(rly[14]*tx+grly[14][0]*radius2)-ylmcoef[35]*(x*grly[23][0]+rly[23]); - grly[34][1] = ylmcoef[33]*grly[30][1]-ylmcoef[34]*(rly[14]*ty+grly[14][1]*radius2)-tmp14*grly[23][1]; - grly[34][2] = ylmcoef[33]*grly[30][2]-ylmcoef[34]*(rly[14]*tz+grly[14][2]*radius2)-tmp14*grly[23][2]; - - rly[35] = ylmcoef[33]*rly[31]-ylmcoef[34]*rly[15]*radius2-tmp14*rly[24];//l=5,m=-5 - grly[35][0] = ylmcoef[33]*grly[31][0]-ylmcoef[34]*(rly[15]*tx+grly[15][0]*radius2)-ylmcoef[35]*(x*grly[24][0]+rly[24]); - grly[35][1] = ylmcoef[33]*grly[31][1]-ylmcoef[34]*(rly[15]*ty+grly[15][1]*radius2)-tmp14*grly[24][1]; - grly[35][2] = ylmcoef[33]*grly[31][2]-ylmcoef[34]*(rly[15]*tz+grly[15][2]*radius2)-tmp14*grly[24][2]; - - if (Lmax == 5) return; - - //if Lmax > 5 - for (int il = 6; il <= Lmax; il++) - { - int istart = il*il; - int istart1 = (il-1)*(il-1); - int istart2 = (il-2)*(il-2); - - double fac2 = sqrt(4.0*istart-1.0); - double fac4 = sqrt(4.0*istart1-1.0); - - for (int im = 0; im < 2*il-1; im++) - { - int imm = (im+1)/2; + if (Lmax == 2) return; + + /*************************** + L = 3 + ***************************/ + rly[9] = ylmcoef[7]*z*rly[4]-ylmcoef[8]*rly[1]*radius2; //l=3, m=0 + grly[9][0] = ylmcoef[7]*z*grly[4][0]-ylmcoef[8]*(rly[1]*tx+grly[1][0]*radius2); + grly[9][1] = ylmcoef[7]*z*grly[4][1]-ylmcoef[8]*(rly[1]*ty+grly[1][1]*radius2); + grly[9][2] = ylmcoef[7]*(rly[4]+z*grly[4][2])-ylmcoef[8]*(rly[1]*tz+grly[1][2]*radius2); + + double tmp3 = ylmcoef[9]*z; + rly[10] = tmp3*rly[5]-ylmcoef[10]*rly[2]*radius2;//l=3,m=1 + grly[10][0] = tmp3*grly[5][0]-ylmcoef[10]*(grly[2][0]*radius2+rly[2]*tx); + grly[10][1] = tmp3*grly[5][1]-ylmcoef[10]*(grly[2][1]*radius2+rly[2]*ty); + grly[10][2] = ylmcoef[9]*(z*grly[5][2]+rly[5])-ylmcoef[10]*(grly[2][2]*radius2+rly[2]*tz); + + rly[11] = tmp3*rly[6]-ylmcoef[10]*rly[3]*radius2;//l=3,m=-1 + grly[11][0] = tmp3*grly[6][0]-ylmcoef[10]*(grly[3][0]*radius2+rly[3]*tx); + grly[11][1] = tmp3*grly[6][1]-ylmcoef[10]*(grly[3][1]*radius2+rly[3]*ty); + grly[11][2] = ylmcoef[9]*(z*grly[6][2]+rly[6])-ylmcoef[10]*(grly[3][2]*radius2+rly[3]*tz); + + double tmp4 = ylmcoef[11]*z; + rly[12] = tmp4*rly[7];//l=3,m=2 + grly[12][0] = tmp4*grly[7][0]; + grly[12][1] = tmp4*grly[7][1]; + grly[12][2] = ylmcoef[11]*(z*grly[7][2]+rly[7]); + + rly[13] = tmp4*rly[8];//l=3,m=-2 + grly[13][0] = tmp4*grly[8][0]; + grly[13][1] = tmp4*grly[8][1]; + grly[13][2] = ylmcoef[11]*(z*grly[8][2]+rly[8]); + + double tmp5 = ylmcoef[14]*x; + rly[14] = ylmcoef[12]*rly[10]-ylmcoef[13]*rly[2]*radius2-tmp5*rly[7];//l=3,m=3 + grly[14][0] = ylmcoef[12]*grly[10][0]-ylmcoef[13]*(rly[2]*tx+grly[2][0]*radius2)-ylmcoef[14]*(rly[7]+x*grly[7][0]); + grly[14][1] = ylmcoef[12]*grly[10][1]-ylmcoef[13]*(rly[2]*ty+grly[2][1]*radius2)-tmp5*grly[7][1]; + grly[14][2] = ylmcoef[12]*grly[10][2]-ylmcoef[13]*(rly[2]*tz+grly[2][2]*radius2)-tmp5*grly[7][2]; + + rly[15] = ylmcoef[12]*rly[11]-ylmcoef[13]*rly[3]*radius2-tmp5*rly[8];//l=3,m=-3 + grly[15][0] = ylmcoef[12]*grly[11][0]-ylmcoef[13]*(rly[3]*tx+grly[3][0]*radius2)-ylmcoef[14]*(rly[8]+x*grly[8][0]); + grly[15][1] = ylmcoef[12]*grly[11][1]-ylmcoef[13]*(rly[3]*ty+grly[3][1]*radius2)-tmp5*grly[8][1]; + grly[15][2] = ylmcoef[12]*grly[11][2]-ylmcoef[13]*(rly[3]*tz+grly[3][2]*radius2)-tmp5*grly[8][2]; + if (Lmax == 3) return; + + /*************************** + L = 4 + ***************************/ + rly[16] = ylmcoef[15]*z*rly[9]-ylmcoef[16]*rly[4]*radius2;//l=4,m=0 + grly[16][0] = ylmcoef[15]*z*grly[9][0]-ylmcoef[16]*(rly[4]*tx+grly[4][0]*radius2); + grly[16][1] = ylmcoef[15]*z*grly[9][1]-ylmcoef[16]*(rly[4]*ty+grly[4][1]*radius2); + grly[16][2] = ylmcoef[15]*(z*grly[9][2]+rly[9])-ylmcoef[16]*(rly[4]*tz+grly[4][2]*radius2); + + double tmp6 = ylmcoef[17]*z; + rly[17] = tmp6*rly[10]-ylmcoef[18]*rly[5]*radius2;//l=4,m=1 + grly[17][0] = tmp6*grly[10][0]-ylmcoef[18]*(rly[5]*tx+grly[5][0]*radius2); + grly[17][1] = tmp6*grly[10][1]-ylmcoef[18]*(rly[5]*ty+grly[5][1]*radius2); + grly[17][2] = ylmcoef[17]*(z*grly[10][2]+rly[10])-ylmcoef[18]*(rly[5]*tz+grly[5][2]*radius2); + + rly[18] = tmp6*rly[11]-ylmcoef[18]*rly[6]*radius2;//l=4,m=-1 + grly[18][0] = tmp6*grly[11][0]-ylmcoef[18]*(rly[6]*tx+grly[6][0]*radius2); + grly[18][1] = tmp6*grly[11][1]-ylmcoef[18]*(rly[6]*ty+grly[6][1]*radius2); + grly[18][2] = ylmcoef[17]*(z*grly[11][2]+rly[11])-ylmcoef[18]*(rly[6]*tz+grly[6][2]*radius2); + + double tmp7 = ylmcoef[19]*z; + rly[19] = tmp7*rly[12]-ylmcoef[20]*rly[7]*radius2;//l=4,m=2 + grly[19][0] = tmp7*grly[12][0]-ylmcoef[20]*(rly[7]*tx+grly[7][0]*radius2); + grly[19][1] = tmp7*grly[12][1]-ylmcoef[20]*(rly[7]*ty+grly[7][1]*radius2); + grly[19][2] = ylmcoef[19]*(z*grly[12][2]+rly[12])-ylmcoef[20]*(rly[7]*tz+grly[7][2]*radius2); + + rly[20] = tmp7*rly[13]-ylmcoef[20]*rly[8]*radius2;//l=4,m=-2 + grly[20][0] = tmp7*grly[13][0]-ylmcoef[20]*(rly[8]*tx+grly[8][0]*radius2); + grly[20][1] = tmp7*grly[13][1]-ylmcoef[20]*(rly[8]*ty+grly[8][1]*radius2); + grly[20][2] = ylmcoef[19]*(z*grly[13][2]+rly[13])-ylmcoef[20]*(rly[8]*tz+grly[8][2]*radius2); + + double tmp8 = 3.0*z; + rly[21] = tmp8*rly[14];//l=4,m=3 + grly[21][0] = tmp8*grly[14][0]; + grly[21][1] = tmp8*grly[14][1]; + grly[21][2] = 3.0*(z*grly[14][2]+rly[14]); + + + rly[22] = tmp8*rly[15];//l=4,m=-3 + grly[22][0] = tmp8*grly[15][0]; + grly[22][1] = tmp8*grly[15][1]; + grly[22][2] = 3.0*(z*grly[15][2]+rly[15]); + + double tmp9 = ylmcoef[23]*x; + rly[23] = ylmcoef[21]*rly[19]-ylmcoef[22]*rly[7]*radius2-tmp9*rly[14];//l=4,m=4 + grly[23][0] = ylmcoef[21]*grly[19][0]-ylmcoef[22]*(rly[7]*tx+grly[7][0]*radius2)-ylmcoef[23]*(x*grly[14][0]+rly[14]); + grly[23][1] = ylmcoef[21]*grly[19][1]-ylmcoef[22]*(rly[7]*ty+grly[7][1]*radius2)-tmp9*grly[14][1]; + grly[23][2] = ylmcoef[21]*grly[19][2]-ylmcoef[22]*(rly[7]*tz+grly[7][2]*radius2)-tmp9*grly[14][2]; + + rly[24] = ylmcoef[21]*rly[20]-ylmcoef[22]*rly[8]*radius2-tmp9*rly[15];//l=4,m=-4 + grly[24][0] = ylmcoef[21]*grly[20][0]-ylmcoef[22]*(rly[8]*tx+grly[8][0]*radius2)-ylmcoef[23]*(x*grly[15][0]+rly[15]); + grly[24][1] = ylmcoef[21]*grly[20][1]-ylmcoef[22]*(rly[8]*ty+grly[8][1]*radius2)-tmp9*grly[15][1]; + grly[24][2] = ylmcoef[21]*grly[20][2]-ylmcoef[22]*(rly[8]*tz+grly[8][2]*radius2)-tmp9*grly[15][2]; + + if (Lmax == 4) return; + + /*************************** + L = 5 + ***************************/ + rly[25] = ylmcoef[24]*z*rly[16]-ylmcoef[25]*rly[9]*radius2;//l=5,m=0 + grly[25][0] = ylmcoef[24]*z*grly[16][0]-ylmcoef[25]*(rly[9]*tx+grly[9][0]*radius2); + grly[25][1] = ylmcoef[24]*z*grly[16][1]-ylmcoef[25]*(rly[9]*ty+grly[9][1]*radius2); + grly[25][2] = ylmcoef[24]*(z*grly[16][2]+rly[16])-ylmcoef[25]*(rly[9]*tz+grly[9][2]*radius2); + + double tmp10 = ylmcoef[26]*z; + rly[26] = tmp10*rly[17]-ylmcoef[27]*rly[10]*radius2;//l=5,m=1 + grly[26][0] = tmp10*grly[17][0]-ylmcoef[27]*(rly[10]*tx+grly[10][0]*radius2); + grly[26][1] = tmp10*grly[17][1]-ylmcoef[27]*(rly[10]*ty+grly[10][1]*radius2); + grly[26][2] = ylmcoef[26]*(z*grly[17][2]+rly[17])-ylmcoef[27]*(rly[10]*tz+grly[10][2]*radius2); + + rly[27] = tmp10*rly[18]-ylmcoef[27]*rly[11]*radius2;//l=5,m=-1 + grly[27][0] = tmp10*grly[18][0]-ylmcoef[27]*(rly[11]*tx+grly[11][0]*radius2); + grly[27][1] = tmp10*grly[18][1]-ylmcoef[27]*(rly[11]*ty+grly[11][1]*radius2); + grly[27][2] = ylmcoef[26]*(z*grly[18][2]+rly[18])-ylmcoef[27]*(rly[11]*tz+grly[11][2]*radius2); + + double tmp11 = ylmcoef[28]*z; + rly[28] = tmp11*rly[19]-ylmcoef[29]*rly[12]*radius2;//l=5,m=2 + grly[28][0] = tmp11*grly[19][0]-ylmcoef[29]*(rly[12]*tx+grly[12][0]*radius2); + grly[28][1] = tmp11*grly[19][1]-ylmcoef[29]*(rly[12]*ty+grly[12][1]*radius2); + grly[28][2] = ylmcoef[28]*(z*grly[19][2]+rly[19])-ylmcoef[29]*(rly[12]*tz+grly[12][2]*radius2); + + rly[29] = tmp11*rly[20]-ylmcoef[29]*rly[13]*radius2;//l=5,m=-2 + grly[29][0] = tmp11*grly[20][0]-ylmcoef[29]*(rly[13]*tx+grly[13][0]*radius2); + grly[29][1] = tmp11*grly[20][1]-ylmcoef[29]*(rly[13]*ty+grly[13][1]*radius2); + grly[29][2] = ylmcoef[28]*(z*grly[20][2]+rly[20])-ylmcoef[29]*(rly[13]*tz+grly[13][2]*radius2); + + double tmp12 = ylmcoef[30]*z; + rly[30] = tmp12*rly[21]-ylmcoef[31]*rly[14]*radius2;//l=5,m=3 + grly[30][0] = tmp12*grly[21][0]-ylmcoef[31]*(grly[14][0]*radius2+rly[14]*tx); + grly[30][1] = tmp12*grly[21][1]-ylmcoef[31]*(grly[14][1]*radius2+rly[14]*ty); + grly[30][2] = ylmcoef[30]*(z*grly[21][2]+rly[21])-ylmcoef[31]*(grly[14][2]*radius2+rly[14]*tz); + + rly[31] = tmp12*rly[22]-ylmcoef[31]*rly[15]*radius2;//l=5,m=-3 + grly[31][0] = tmp12*grly[22][0]-ylmcoef[31]*(grly[15][0]*radius2+rly[15]*tx); + grly[31][1] = tmp12*grly[22][1]-ylmcoef[31]*(grly[15][1]*radius2+rly[15]*ty); + grly[31][2] = ylmcoef[30]*(z*grly[22][2]+rly[22])-ylmcoef[31]*(grly[15][2]*radius2+rly[15]*tz); + + double tmp13 = ylmcoef[32]*z; + rly[32] = tmp13*rly[23];//l=5,m=4 + grly[32][0] = tmp13*grly[23][0]; + grly[32][1] = tmp13*grly[23][1]; + grly[32][2] = ylmcoef[32]*(rly[23]+z*grly[23][2]); + + rly[33] = tmp13*rly[24];//l=5,m=-4 + grly[33][0] = tmp13*grly[24][0]; + grly[33][1] = tmp13*grly[24][1]; + grly[33][2] = ylmcoef[32]*(rly[24]+z*grly[24][2]); + + double tmp14 = ylmcoef[35]*x; + rly[34] = ylmcoef[33]*rly[30]-ylmcoef[34]*rly[14]*radius2-tmp14*rly[23];//l=5,m=5 + grly[34][0] = ylmcoef[33]*grly[30][0]-ylmcoef[34]*(rly[14]*tx+grly[14][0]*radius2)-ylmcoef[35]*(x*grly[23][0]+rly[23]); + grly[34][1] = ylmcoef[33]*grly[30][1]-ylmcoef[34]*(rly[14]*ty+grly[14][1]*radius2)-tmp14*grly[23][1]; + grly[34][2] = ylmcoef[33]*grly[30][2]-ylmcoef[34]*(rly[14]*tz+grly[14][2]*radius2)-tmp14*grly[23][2]; + + rly[35] = ylmcoef[33]*rly[31]-ylmcoef[34]*rly[15]*radius2-tmp14*rly[24];//l=5,m=-5 + grly[35][0] = ylmcoef[33]*grly[31][0]-ylmcoef[34]*(rly[15]*tx+grly[15][0]*radius2)-ylmcoef[35]*(x*grly[24][0]+rly[24]); + grly[35][1] = ylmcoef[33]*grly[31][1]-ylmcoef[34]*(rly[15]*ty+grly[15][1]*radius2)-tmp14*grly[24][1]; + grly[35][2] = ylmcoef[33]*grly[31][2]-ylmcoef[34]*(rly[15]*tz+grly[15][2]*radius2)-tmp14*grly[24][2]; + + if (Lmax == 5) return; + + //if Lmax > 5 + for (int il = 6; il <= Lmax; il++) + { + int istart = il*il; + int istart1 = (il-1)*(il-1); + int istart2 = (il-2)*(il-2); + + double fac2 = sqrt(4.0*istart-1.0); + double fac4 = sqrt(4.0*istart1-1.0); + + for (int im = 0; im < 2*il-1; im++) + { + int imm = (im+1)/2; // if (im % 2 == 0) imm *= -1; - double var1 = fac2/sqrt((double)istart-imm*imm); - double var2 = sqrt((double)istart1-imm*imm)/fac4; + double var1 = fac2/sqrt((double)istart-imm*imm); + double var2 = sqrt((double)istart1-imm*imm)/fac4; - rly[istart+im] = var1*(z*rly[istart1+im] - var2*rly[istart2+im]*radius2); + rly[istart+im] = var1*(z*rly[istart1+im] - var2*rly[istart2+im]*radius2); - grly[istart+im][0]=var1*(z*grly[istart1+im][0]-var2*(rly[istart2+im]*tx+grly[istart2+im][0]*radius2)); - grly[istart+im][1]=var1*(z*grly[istart1+im][1]-var2*(rly[istart2+im]*ty+grly[istart2+im][1]*radius2)); - grly[istart+im][2]=var1*(z*grly[istart1+im][2]+rly[istart1+im]-var2*(rly[istart2+im]*tz+grly[istart2+im][2]*radius2)); + grly[istart+im][0]=var1*(z*grly[istart1+im][0]-var2*(rly[istart2+im]*tx+grly[istart2+im][0]*radius2)); + grly[istart+im][1]=var1*(z*grly[istart1+im][1]-var2*(rly[istart2+im]*ty+grly[istart2+im][1]*radius2)); + grly[istart+im][2]=var1*(z*grly[istart1+im][2]+rly[istart1+im]-var2*(rly[istart2+im]*tz+grly[istart2+im][2]*radius2)); - } + } - double bl1 = sqrt(2.0*il/(2.0*il+1.0)); - double bl2 = sqrt((2.0*il-2.0)/(2.0*il-1.0)); - double bl3 = sqrt(2.0)/fac2; + double bl1 = sqrt(2.0*il/(2.0*il+1.0)); + double bl2 = sqrt((2.0*il-2.0)/(2.0*il-1.0)); + double bl3 = sqrt(2.0)/fac2; - int id1 = istart+2*il-1; - int id2 = istart+2*il-5; - int id3 = istart2+2*il-5; - int id4 = istart1+2*il-3; + int id1 = istart+2*il-1; + int id2 = istart+2*il-5; + int id3 = istart2+2*il-5; + int id4 = istart1+2*il-3; - rly[id1] = (bl3*rly[id2]-bl2*rly[id3]*radius2-2.0*x*rly[id4]) / bl1; - grly[id1][0] = (bl3*grly[id2][0]-bl2*(grly[id3][0]*radius2+rly[id3]*tx)-2.0*(rly[id4]+x*grly[id4][0]))/bl1; - grly[id1][1] = (bl3*grly[id2][1]-bl2*(grly[id3][1]*radius2+rly[id3]*ty)-2.0*x*grly[id4][1])/bl1; - grly[id1][2] = (bl3*grly[id2][2]-bl2*(grly[id3][2]*radius2+rly[id3]*tz)-2.0*x*grly[id4][2])/bl1; + rly[id1] = (bl3*rly[id2]-bl2*rly[id3]*radius2-2.0*x*rly[id4]) / bl1; + grly[id1][0] = (bl3*grly[id2][0]-bl2*(grly[id3][0]*radius2+rly[id3]*tx)-2.0*(rly[id4]+x*grly[id4][0]))/bl1; + grly[id1][1] = (bl3*grly[id2][1]-bl2*(grly[id3][1]*radius2+rly[id3]*ty)-2.0*x*grly[id4][1])/bl1; + grly[id1][2] = (bl3*grly[id2][2]-bl2*(grly[id3][2]*radius2+rly[id3]*tz)-2.0*x*grly[id4][2])/bl1; - rly[id1+1] = (bl3*rly[id2+1]-bl2*rly[id3+1]*radius2-2.0*x*rly[id4+1]) / bl1; - grly[id1+1][0] = (bl3*grly[id2+1][0]-bl2*(grly[id3+1][0]*radius2+rly[id3+1]*tx)-2.0*(rly[id4+1]+x*grly[id4+1][0]))/bl1; - grly[id1+1][1] = (bl3*grly[id2+1][1]-bl2*(grly[id3+1][1]*radius2+rly[id3+1]*ty)-2.0*x*grly[id4+1][1])/bl1; - grly[id1+1][2] = (bl3*grly[id2+1][2]-bl2*(grly[id3+1][2]*radius2+rly[id3+1]*tz)-2.0*x*grly[id4+1][2])/bl1; - } + rly[id1+1] = (bl3*rly[id2+1]-bl2*rly[id3+1]*radius2-2.0*x*rly[id4+1]) / bl1; + grly[id1+1][0] = (bl3*grly[id2+1][0]-bl2*(grly[id3+1][0]*radius2+rly[id3+1]*tx)-2.0*(rly[id4+1]+x*grly[id4+1][0]))/bl1; + grly[id1+1][1] = (bl3*grly[id2+1][1]-bl2*(grly[id3+1][1]*radius2+rly[id3+1]*ty)-2.0*x*grly[id4+1][1])/bl1; + grly[id1+1][2] = (bl3*grly[id2+1][2]-bl2*(grly[id3+1][2]*radius2+rly[id3+1]*tz)-2.0*x*grly[id4+1][2])/bl1; + } - return; + return; } void Ylm::hes_rl_sph_harm ( - const int Lmax, //max momentum of L - const double x, - const double y, - const double z, - std::vector>& hrly + const int Lmax, //max momentum of L + const double x, + const double y, + const double z, + std::vector>& hrly ) { - hrly.resize( (Lmax+1)*(Lmax+1), std::vector(6) ); - - double radius2 = x*x+y*y+z*z; - double coeff = 0.0; - - //begin calculation - /*************************** - L = 0 - ***************************/ - hrly[0][0] = hrly[0][1] = hrly[0][2] = 0.0; - hrly[0][3] = hrly[0][4] = hrly[0][5] = 0.0; - if (Lmax == 0) return; - - /*************************** - L = 1 - ***************************/ - hrly[1][0] = hrly[1][1] = hrly[1][2] = 0.0; - hrly[1][3] = hrly[1][4] = hrly[1][5] = 0.0; - - hrly[2][0] = hrly[2][1] = hrly[2][2] = 0.0; - hrly[2][3] = hrly[2][4] = hrly[2][5] = 0.0; - - hrly[3][0] = hrly[3][1] = hrly[3][2] = 0.0; - hrly[3][3] = hrly[3][4] = hrly[3][5] = 0.0; - - if (Lmax == 1) return; - - /*************************** - L = 2 - ***************************/ - //m=0 : 3z^2-r^2 - coeff = sqrt(5.0 / ModuleBase::PI) / 4.0; - hrly[4][0] = hrly[4][3] = -2.0 * coeff; - hrly[4][5] = 4.0 * coeff; - hrly[4][1] = hrly[4][2] = hrly[4][4] = 0.0; - - //m=1 : xz - coeff = sqrt(15.0 / ModuleBase::PI) / 2.0; - hrly[5][2] = coeff; - hrly[5][0] = hrly[5][1] = 0.0; - hrly[5][3] = hrly[5][4] = hrly[5][5] = 0.0; - - //m=-1 : yz - hrly[6][4] = coeff; - hrly[6][0] = hrly[6][1] = 0.0; - hrly[6][2] = hrly[6][3] = hrly[6][5] = 0.0; - - //m=-2 : xy - hrly[8][1] = coeff; - hrly[8][0] = hrly[8][2] = 0.0; - hrly[8][3] = hrly[8][4] = hrly[8][5] = 0.0; - - //m=2 : (x^2-y^2) - coeff = sqrt(15.0 / ModuleBase::PI) / 4.0; - hrly[7][0] = 2.0 * coeff; - hrly[7][3] = -2.0 * coeff; - hrly[7][1] = hrly[7][2] = 0.0; - hrly[7][4] = hrly[7][5] = 0.0; - - if (Lmax == 2) return; - - /*************************** - L = 3 - ***************************/ - //m=0 : (5z^3-3zr^2) - coeff = sqrt(7.0 / ModuleBase::PI) / 4.0; - hrly[9][0] = hrly[9][3] = -6.0 * z * coeff; - hrly[9][1] = 0.0; - hrly[9][2] = -6.0 * x * coeff; - hrly[9][4] = -6.0 * y * coeff; - hrly[9][5] = 12.0 * z * coeff; - - //m=1 : x(5z^2-r^2) - coeff = sqrt(21.0 / 2.0 / ModuleBase::PI) / 4.0; - hrly[10][0] = -6.0 * x * coeff; - hrly[10][1] = -2.0 * y * coeff; - hrly[10][2] = 8.0 * z * coeff; - hrly[10][3] = -2.0 * x * coeff; - hrly[10][4] = 0.0; - hrly[10][5] = 8.0 * x * coeff; - - //m=-1 : y(5z^2-r^2) - hrly[11][0] = -2.0 * y * coeff; - hrly[11][1] = -2.0 * x * coeff; - hrly[11][2] = 0.0; - hrly[11][3] = -6.0 * y * coeff; - hrly[11][4] = 8.0 * z * coeff; - hrly[11][5] = 8.0 * y * coeff; - - //m=2 : (x^2-y^2)z - coeff = sqrt(105.0 / ModuleBase::PI) / 4.0; - hrly[12][0] = 2.0 * z * coeff; - hrly[12][1] = 0.0; - hrly[12][2] = 2.0 * x * coeff; - hrly[12][3] = -hrly[12][0]; - hrly[12][4] = -2.0 * y * coeff; - hrly[12][5] = 0.0; - - //m=-2 : xyz - coeff = sqrt(105.0 / ModuleBase::PI) / 2.0; - hrly[13][0] = 0.0; - hrly[13][1] = z * coeff; - hrly[13][2] = y * coeff; - hrly[13][3] = 0.0; - hrly[13][4] = x * coeff; - hrly[13][5] = 0.0; - - //m=3 : x(x^2-3y^2) - coeff = sqrt(35.0 / 2.0 / ModuleBase::PI) / 4.0; - hrly[14][0] = 6.0 * x * coeff; - hrly[14][1] = -6.0 * y * coeff; - hrly[14][2] = 0.0; - hrly[14][3] = -hrly[14][0]; - hrly[14][4] = 0.0; - hrly[14][5] = 0.0; - - //m=-3 : y(3x^2-y^2) - hrly[15][0] = 6.0 * y * coeff; - hrly[15][1] = 6.0 * x * coeff; - hrly[15][2] = 0.0; - hrly[15][3] = -hrly[15][0]; - hrly[15][4] = 0.0; - hrly[15][5] = 0.0; - - if (Lmax == 3) return; - - /*************************** - L = 4 - ***************************/ - //m=0 : (35z^4 - 30z^2r^2 + 3r^4) - coeff = sqrt(1.0 / ModuleBase::PI) * 3.0 / 16.0; - hrly[16][0] = 12.0 * (3.0 * x*x + y*y - 4.0 * z*z) * coeff; - hrly[16][1] = 24.0 * x * y * coeff; - hrly[16][2] = -96.0 * x * z * coeff; - hrly[16][3] = 12.0 * (x*x + 3.0 * y*y - 4.0 * z*z) * coeff; - hrly[16][4] = -96.0 * y * z * coeff; - hrly[16][5] = -48.0 * (x*x + y*y -2.0 * z*z) * coeff; - - //m=1 : x(7z^3 - 3zr^2) - coeff = 3.0 / 4.0 * sqrt(5.0 / 2.0 / ModuleBase::PI); - hrly[17][0] = -18.0 * x * z * coeff; - hrly[17][1] = -6.0 * y * z * coeff; - hrly[17][2] = -3.0 * (3.0 * x*x + y*y - 4.0 * z*z) * coeff; - hrly[17][3] = -6.0 * x * z * coeff; - hrly[17][4] = -6.0 * x * y * coeff; - hrly[17][5] = 24.0 * x * z * coeff; - - //m=-1 : y(7z^3 - 3zr^2) - hrly[18][0] = -6.0 * y * z * coeff; - hrly[18][1] = -6.0 * x * z * coeff; - hrly[18][2] = -6.0 * x * y * coeff; - hrly[18][3] = -18.0 * y * z * coeff; - hrly[18][4] = -3.0 * (x*x + 3.0 * y*y - 4.0 * z*z) * coeff; - hrly[18][5] = 24.0 * y * z * coeff; - - //m=2 : (x^2 - y^2)(7z^2 - r^2) - coeff = 3.0 / 8.0 * sqrt(5.0 / ModuleBase::PI); - hrly[19][0] = -12.0 * (x*x - z*z) * coeff; - hrly[19][1] = 0.0; - hrly[19][2] = 24.0 * x * z * coeff; - hrly[19][3] = 12.0 * (y*y - z*z) * coeff; - hrly[19][4] = -24.0 * y * z * coeff; - hrly[19][5] = 12.0 * (x*x - y*y) * coeff; - - //m=-2 : xy(7z^2 - r^2) - coeff = 3.0 / 4.0 * sqrt(5.0 / ModuleBase::PI); - hrly[20][0] = -6.0 * x * y * coeff; - hrly[20][1] = -3.0 * (x*x + y*y - 2.0 * z*z) * coeff; - hrly[20][2] = 2.0 * y * z * coeff; - hrly[20][3] = hrly[20][0]; - hrly[20][4] = 12.0 * x * z * coeff; - hrly[20][5] = 12.0 * x * y * coeff; - - //m=3 : x(x^2-3y^2)z - coeff = 3.0 / 4.0 * sqrt(35.0 / 2.0 / ModuleBase::PI); - hrly[21][0] = 6.0 * x * z * coeff; - hrly[21][1] = -6.0 * y * z * coeff; - hrly[21][2] = 3.0 * (x*x - y*y) * coeff; - hrly[21][3] = -6.0 * x * z * coeff; - hrly[21][4] = -6.0 * x * y * coeff; - hrly[21][5] = 0.0; - - //m=-3 : y(3x^2-y^2)z - hrly[22][0] = 6.0 * y * z * coeff; - hrly[22][1] = 6.0 * x * z * coeff; - hrly[22][2] = 6.0 * x * y * coeff; - hrly[22][3] = -6.0 * y * z * coeff; - hrly[22][4] = 3.0 * (x*x - y*y) * coeff; - hrly[22][5] = 0.0; - - //m=4 : x^4 + y^4 - 6 x^2y^2 - coeff = 3.0 / 16.0 * sqrt(35.0 / ModuleBase::PI); - hrly[23][0] = 12.0 * (x*x - y*y) * coeff; - hrly[23][1] = -24.0 * x * y * coeff; - hrly[23][2] = 0.0; - hrly[23][3] = -hrly[23][0]; - hrly[23][4] = 0.0; - hrly[23][5] = 0.0; - - //m=-4 : xy(x^2 - y^2) - coeff = 3.0 / 4.0 * sqrt(35.0 / ModuleBase::PI); - hrly[24][0] = 6.0 * x * y * coeff; - hrly[24][1] = 3.0 * (x*x - y*y) * coeff; - hrly[24][2] = 0.0; - hrly[24][3] = -hrly[24][0]; - hrly[24][4] = 0.0; - hrly[24][5] = 0.0; - - if (Lmax == 4) return; - - /*************************** - L = 5 - ***************************/ - //m=0 : (63z^5 - 70z^3*r^2 + 15z*r^4) - coeff = sqrt(11.0 / ModuleBase::PI) / 16.0; - hrly[25][0] = (180*x*x*z + 60*y*y*z - 80*z*z*z) * coeff; - hrly[25][1] = (120*x*y*z) * coeff; - hrly[25][2] = (60*x*x*x + 60*x*y*y - 240*x*z*z) * coeff; - hrly[25][3] = (60*x*x*z + 180*y*y*z - 80*z*z*z) * coeff; - hrly[25][4] = (60*x*x*y + 60*y*y*y - 240*y*z*z) * coeff; - hrly[25][5] = (-240*x*x*z - 240*y*y*z + 160*z*z*z) * coeff; - - //m=1 : x(21z^4 - 14z^2*r^2 + r^4) - coeff = sqrt(165.0 / 2.0 / ModuleBase::PI) / 16.0; - hrly[26][0] = (20*x*x*x + 12*x*y*y - 72*x*z*z) * coeff; - hrly[26][1] = (12*x*x*y + 4*y*y*y - 24*y*z*z) * coeff; - hrly[26][2] = (-72*x*x*z - 24*y*y*z + 32*z*z*z) * coeff; - hrly[26][3] = (4*x*x*x + 12*x*y*y - 24*x*z*z) * coeff; - hrly[26][4] = (-48*x*y*z) * coeff; - hrly[26][5] = (-24*x*x*x - 24*x*y*y + 96*x*z*z) * coeff; - - //m=-1 : y(21z^4 - 14z^2*r^2 + r^4) - hrly[27][0] = (12*x*x*y + 4*y*y*y - 24*y*z*z) * coeff; - hrly[27][1] = (4*x*x*x + 12*x*y*y - 24*x*z*z) * coeff; - hrly[27][2] = (-48*x*y*z) * coeff; - hrly[27][3] = (12*x*x*y + 20*y*y*y - 72*y*z*z) * coeff; - hrly[27][4] = (-24*x*x*z - 72*y*y*z + 32*z*z*z) * coeff; - hrly[27][5] = (-24*x*x*y - 24*y*y*y + 96*y*z*z) * coeff; - - //m=2 : (x^2 - y^2)(3z^3 - z*r^2) - coeff = sqrt(1155.0 / ModuleBase::PI) / 8.0; - hrly[28][0] = (-12*x*x*z + 4*z*z*z) * coeff; - hrly[28][1] = 0.0; - hrly[28][2] = (-4*x*x*x + 12*x*z*z) * coeff; - hrly[28][3] = (12*y*y*z - 4*z*z*z) * coeff; - hrly[28][4] = (4*y*y*y - 12*y*z*z) * coeff; - hrly[28][5] = (12*x*x*z - 12*y*y*z) * coeff; - - //m=-2 : xy(3z^3 - z*r^2) - hrly[29][0] = (-6*x*y*z) * coeff; - hrly[29][1] = (-3*x*x*z - 3*y*y*z + 2*z*z*z) * coeff; - hrly[29][2] = (-3*x*x*y - y*y*y + 6*y*z*z) * coeff; - hrly[29][3] = (-6*x*y*z) * coeff; - hrly[29][4] = (-x*x*x - 3*x*y*y + 6*x*z*z) * coeff; - hrly[29][5] = (12*x*y*z) * coeff; - - //m=3 : x(x^2 - 3y^2)(9z^2 - r^2) - coeff = sqrt(385.0 / 2.0 / ModuleBase::PI) / 16.0; - hrly[30][0] = (-20*x*x*x + 12*x*y*y + 48*x*z*z) * coeff; - hrly[30][1] = (12*x*x*y + 12*y*y*y - 48*y*z*z) * coeff; - hrly[30][2] = (48*x*x*z - 48*y*y*z) * coeff; - hrly[30][3] = (4*x*x*x + 36*x*y*y - 48*x*z*z) * coeff; - hrly[30][4] = (-96*x*y*z) * coeff; - hrly[30][5] = (16*x*x*x - 48*x*y*y) * coeff; - - //m=-3 : y(3x^2 - y^2)(9z^2 - r^2) - hrly[31][0] = (-36*x*x*y - 4*y*y*y + 48*y*z*z) * coeff; - hrly[31][1] = (-12*x*x*x - 12*x*y*y + 48*x*z*z) * coeff; - hrly[31][2] = (96*x*y*z) * coeff; - hrly[31][3] = (-12*x*x*y + 20*y*y*y - 48*y*z*z) * coeff; - hrly[31][4] = (48*x*x*z - 48*y*y*z) * coeff; - hrly[31][5] = (48*x*x*y - 16*y*y*y) * coeff; - - //m=4 : (x^4 - 6x^2*y^2 + y^4) * z - coeff = sqrt(385.0 / ModuleBase::PI) / 16.0; - hrly[32][0] = (12*x*x*z - 12*y*y*z) * coeff; - hrly[32][1] = (-24*x*y*z) * coeff; - hrly[32][2] = (4*x*x*x - 12*x*y*y) * coeff; - hrly[32][3] = (-12*x*x*z + 12*y*y*z) * coeff; - hrly[32][4] = (-12*x*x*y + 4*y*y*y) * coeff; - hrly[32][5] = 0.0; - - //m=-4 : xy(x^2 - y^2) * z - hrly[33][0] = (6*x*y*z) * coeff; - hrly[33][1] = (3*x*x*z - 3*y*y*z) * coeff; - hrly[33][2] = (3*x*x*y - y*y*y) * coeff; - hrly[33][3] = (-6*x*y*z) * coeff; - hrly[33][4] = (x*x*x - 3*x*y*y) * coeff; - hrly[33][5] = 0.0; - - //m=5 : x(x^4 - 10x^2*y^2 + 5y^4) - coeff = sqrt(77.0 / 2.0 / ModuleBase::PI) / 16.0; - hrly[34][0] = (20.0 * x*x*x - 60.0 * x * y*y) * coeff; - hrly[34][1] = (-60.0 * x*x * y + 20.0 * y*y*y) * coeff; - hrly[34][2] = 0.0; - hrly[34][3] = (-20.0 * x*x*x + 60.0 * x * y*y) * coeff; - hrly[34][4] = 0.0; - hrly[34][5] = 0.0; - - //m=-5 : y(5x^4 - 10x^2*y^2 + y^4) - hrly[35][0] = (60.0 * x*x * y - 20.0 * y*y*y) * coeff; - hrly[35][1] = (20.0 * x*x*x - 60.0 * x * y*y) * coeff; - hrly[35][2] = 0.0; - hrly[35][3] = (-60.0 * x*x * y + 20.0 * y*y*y) * coeff; - hrly[35][4] = 0.0; - hrly[35][5] = 0.0; - - if (Lmax == 5) return; - - /*************************** - L = 6 - ***************************/ - //m=0 : (231z^6 - 315z^4*r^2 + 105z^2*r^4 - 5r^6) - coeff = sqrt(13.0 / ModuleBase::PI) / 32.0; - hrly[36][0] = (-150*x*x*x*x - 180*x*x*y*y + 1080*x*x*z*z - 30*y*y*y*y + 360*y*y*z*z - 240*z*z*z*z) * coeff; - hrly[36][1] = (-120*x*x*x*y - 120*x*y*y*y + 720*x*y*z*z) * coeff; - hrly[36][2] = (720*x*x*x*z + 720*x*y*y*z - 960*x*z*z*z) * coeff; - hrly[36][3] = (-30*x*x*x*x - 180*x*x*y*y + 360*x*x*z*z - 150*y*y*y*y + 1080*y*y*z*z - 240*z*z*z*z) * coeff; - hrly[36][4] = (720*x*x*y*z + 720*y*y*y*z - 960*y*z*z*z) * coeff; - hrly[36][5] = (180*x*x*x*x + 360*x*x*y*y - 1440*x*x*z*z + 180*y*y*y*y - 1440*y*y*z*z + 480*z*z*z*z) * coeff; - - //m=1 : x(33z^5 - 30z^3*r^2 + 5z*r^4) - coeff = sqrt(273.0 / 2.0 / ModuleBase::PI) / 16.0; - hrly[37][0] = (100*x*x*x*z + 60*x*y*y*z - 120*x*z*z*z) * coeff; - hrly[37][1] = (60*x*x*y*z + 20*y*y*y*z - 40*y*z*z*z) * coeff; - hrly[37][2] = (25*x*x*x*x + 30*x*x*y*y - 180*x*x*z*z + 5*y*y*y*y - 60*y*y*z*z + 40*z*z*z*z) * coeff; - hrly[37][3] = (20*x*x*x*z + 60*x*y*y*z - 40*x*z*z*z) * coeff; - hrly[37][4] = (20*x*x*x*y + 20*x*y*y*y - 120*x*y*z*z) * coeff; - hrly[37][5] = (-120*x*x*x*z - 120*x*y*y*z + 160*x*z*z*z) * coeff; - - //m=-1 : y(33z^5 - 30z^3*r^2 + 5z*r^4) - hrly[38][0] = (60*x*x*y*z + 20*y*y*y*z - 40*y*z*z*z) * coeff; - hrly[38][1] = (20*x*x*x*z + 60*x*y*y*z - 40*x*z*z*z) * coeff; - hrly[38][2] = (20*x*x*x*y + 20*x*y*y*y - 120*x*y*z*z) * coeff; - hrly[38][3] = (60*x*x*y*z + 100*y*y*y*z - 120*y*z*z*z) * coeff; - hrly[38][4] = (5*x*x*x*x + 30*x*x*y*y - 60*x*x*z*z + 25*y*y*y*y - 180*y*y*z*z + 40*z*z*z*z) * coeff; - hrly[38][5] = (-120*x*x*y*z - 120*y*y*y*z + 160*y*z*z*z) * coeff; - - //m=2 : (x^2 - y^2)(33z^4 - 18z^2*r^2 + r^4) - coeff = sqrt(1365.0 / ModuleBase::PI) / 32.0; - hrly[39][0] = (30*x*x*x*x + 12*x*x*y*y - 192*x*x*z*z - 2*y*y*y*y + 32*z*z*z*z) * coeff; - hrly[39][1] = (8*x*x*x*y - 8*x*y*y*y) * coeff; - hrly[39][2] = (-128*x*x*x*z + 128*x*z*z*z) * coeff; - hrly[39][3] = (2*x*x*x*x - 12*x*x*y*y - 30*y*y*y*y + 192*y*y*z*z - 32*z*z*z*z) * coeff; - hrly[39][4] = (128*y*y*y*z - 128*y*z*z*z) * coeff; - hrly[39][5] = (-32*x*x*x*x + 192*x*x*z*z + 32*y*y*y*y - 192*y*y*z*z) * coeff; - - //m=-2 : xy(33z^4 - 18z^2*r^2 + r^4) - hrly[40][0] = (20*x*x*x*y + 12*x*y*y*y - 96*x*y*z*z) * coeff; - hrly[40][1] = (20*x*x*x*x + 36*x*x*y*y - 96*x*x*z*z + 20*y*y*y*y - 96*y*y*z*z + 32*z*z*z*z) * coeff; - hrly[40][2] = (-96*x*x*y*z - 32*y*y*y*z + 64*y*z*z*z) * coeff; - hrly[40][3] = (12*x*x*x*y + 20*x*y*y*y - 96*x*y*z*z) * coeff; - hrly[40][4] = (-32*x*x*x*z - 96*x*y*y*z + 64*x*z*z*z) * coeff; - hrly[40][5] = (-32*x*x*x*y - 32*x*y*y*y + 192*x*y*z*z) * coeff; - - //m=3 : x(x^2 - 3y^2)(11z^3 - 3z*r^2) - coeff = sqrt(1365.0 / ModuleBase::PI) / 16.0; - hrly[41][0] = (-60*x*x*x*z + 36*x*y*y*z + 48*x*z*z*z) * coeff; - hrly[41][1] = (36*x*x*y*z + 36*y*y*y*z - 48*y*z*z*z) * coeff; - hrly[41][2] = (-30*x*x*x*x + 36*x*x*y*y + 72*x*x*z*z + 18*y*y*y*y - 72*y*y*z*z) * coeff; - hrly[41][3] = (12*x*x*x*z + 108*x*y*y*z - 48*x*z*z*z) * coeff; - hrly[41][4] = (12*x*x*x*y + 36*x*y*y*y - 144*x*y*z*z) * coeff; - hrly[41][5] = (48*x*x*x*z - 144*x*y*y*z) * coeff; - - //m=-3 : y(3x^2 - y^2)(11z^3 - 3z*r^2) - hrly[42][0] = (-108*x*x*y*z - 12*y*y*y*z + 48*y*z*z*z) * coeff; - hrly[42][1] = (-36*x*x*x*z - 36*x*y*y*z + 48*x*z*z*z) * coeff; - hrly[42][2] = (-36*x*x*x*y - 12*x*y*y*y + 144*x*y*z*z) * coeff; - hrly[42][3] = (-36*x*x*y*z + 60*y*y*y*z - 48*y*z*z*z) * coeff; - hrly[42][4] = (-18*x*x*x*x - 36*x*x*y*y + 72*x*x*z*z + 30*y*y*y*y - 72*y*y*z*z) * coeff; - hrly[42][5] = (144*x*x*y*z - 48*y*y*y*z) * coeff; - - //m=4 : (x^4 - 6x^2*y^2 + y^4)(11z^2 - r^2) - coeff = sqrt(91.0 / ModuleBase::PI) / 32.0; - hrly[43][0] = (-30*x*x*x*x + 60*x*x*y*y + 120*x*x*z*z + 10*y*y*y*y - 120*y*y*z*z) * coeff; - hrly[43][1] = (40*x*x*x*y + 40*x*y*y*y - 240*x*y*z*z) * coeff; - hrly[43][2] = (80*x*x*x*z - 240*x*y*y*z) * coeff; - hrly[43][3] = (10*x*x*x*x + 60*x*x*y*y - 120*x*x*z*z - 30*y*y*y*y + 120*y*y*z*z) * coeff; - hrly[43][4] = (-240*x*x*y*z + 80*y*y*y*z) * coeff; - hrly[43][5] = (20*x*x*x*x - 120*x*x*y*y + 20*y*y*y*y) * coeff; - - //m=-4 : xy(x^2 - y^2)(11z^2 - r^2) - hrly[44][0] = (-20*x*x*x*y + 60*x*y*z*z) * coeff; - hrly[44][1] = (-5*x*x*x*x + 30*x*x*z*z + 5*y*y*y*y - 30*y*y*z*z) * coeff; - hrly[44][2] = (60*x*x*y*z - 20*y*y*y*z) * coeff; - hrly[44][3] = (20*x*y*y*y - 60*x*y*z*z) * coeff; - hrly[44][4] = (20*x*x*x*z - 60*x*y*y*z) * coeff; - hrly[44][5] = (20*x*x*x*y - 20*x*y*y*y) * coeff; - - //m=5 : x(x^4 - 10x^2*y^2 + 5y^4) * z - coeff = sqrt(1001.0 / 2.0 / ModuleBase::PI) / 16.0; - hrly[45][0] = (20*x*x*x*z - 60*x*y*y*z) * coeff; - hrly[45][1] = (-60*x*x*y*z + 20*y*y*y*z) * coeff; - hrly[45][2] = (5*x*x*x*x - 30*x*x*y*y + 5*y*y*y*y) * coeff; - hrly[45][3] = (-20*x*x*x*z + 60*x*y*y*z) * coeff; - hrly[45][4] = (-20*x*x*x*y + 20*x*y*y*y) * coeff; - hrly[45][5] = 0.0; - - //m=-5 : y(5x^4 - 10x^2*y^2 + y^4) * z - hrly[46][0] = (60*x*x*y*z - 20*y*y*y*z) * coeff; - hrly[46][1] = (20*x*x*x*z - 60*x*y*y*z) * coeff; - hrly[46][2] = (20*x*x*x*y - 20*x*y*y*y) * coeff; - hrly[46][3] = (-60*x*x*y*z + 20*y*y*y*z) * coeff; - hrly[46][4] = (5*x*x*x*x - 30*x*x*y*y + 5*y*y*y*y) * coeff; - hrly[46][5] = 0.0; - - //m=6 : (x^6 - 15x^4*y^2 + 15x^2*y^4 - y^6) - coeff = sqrt(3003.0 / ModuleBase::PI) / 32.0; - hrly[47][0] = (30*x*x*x*x - 180*x*x*y*y + 30*y*y*y*y) * coeff; - hrly[47][1] = (-120*x*x*x*y + 120*x*y*y*y) * coeff; - hrly[47][2] = 0.0; - hrly[47][3] = (-30*x*x*x*x + 180*x*x*y*y - 30*y*y*y*y) * coeff; - hrly[47][4] = 0.0; - hrly[47][5] = 0.0; - - //m=-6 : xy(3x^4 - 10x^2*y^2 + 3y^4) - hrly[48][0] = (60*x*x*x*y - 60*x*y*y*y) * coeff; - hrly[48][1] = (15*x*x*x*x - 90*x*x*y*y + 15*y*y*y*y) * coeff; - hrly[48][2] = 0.0; - hrly[48][3] = (-60*x*x*x*y + 60*x*y*y*y) * coeff; - hrly[48][4] = 0.0; - hrly[48][5] = 0.0; - - if (Lmax == 6) return; - - /*************************** - L > 6 - ***************************/ - ModuleBase::WARNING_QUIT("hes_rl_sph_harm","l>6 not implemented!"); - - - return; + hrly.resize( (Lmax+1)*(Lmax+1), std::vector(6) ); + + double radius2 = x*x+y*y+z*z; + double coeff = 0.0; + + //begin calculation + /*************************** + L = 0 + ***************************/ + hrly[0][0] = hrly[0][1] = hrly[0][2] = 0.0; + hrly[0][3] = hrly[0][4] = hrly[0][5] = 0.0; + if (Lmax == 0) return; + + /*************************** + L = 1 + ***************************/ + hrly[1][0] = hrly[1][1] = hrly[1][2] = 0.0; + hrly[1][3] = hrly[1][4] = hrly[1][5] = 0.0; + + hrly[2][0] = hrly[2][1] = hrly[2][2] = 0.0; + hrly[2][3] = hrly[2][4] = hrly[2][5] = 0.0; + + hrly[3][0] = hrly[3][1] = hrly[3][2] = 0.0; + hrly[3][3] = hrly[3][4] = hrly[3][5] = 0.0; + + if (Lmax == 1) return; + + /*************************** + L = 2 + ***************************/ + //m=0 : 3z^2-r^2 + coeff = sqrt(5.0 / ModuleBase::PI) / 4.0; + hrly[4][0] = hrly[4][3] = -2.0 * coeff; + hrly[4][5] = 4.0 * coeff; + hrly[4][1] = hrly[4][2] = hrly[4][4] = 0.0; + + //m=1 : xz + coeff = sqrt(15.0 / ModuleBase::PI) / 2.0; + hrly[5][2] = coeff; + hrly[5][0] = hrly[5][1] = 0.0; + hrly[5][3] = hrly[5][4] = hrly[5][5] = 0.0; + + //m=-1 : yz + hrly[6][4] = coeff; + hrly[6][0] = hrly[6][1] = 0.0; + hrly[6][2] = hrly[6][3] = hrly[6][5] = 0.0; + + //m=-2 : xy + hrly[8][1] = coeff; + hrly[8][0] = hrly[8][2] = 0.0; + hrly[8][3] = hrly[8][4] = hrly[8][5] = 0.0; + + //m=2 : (x^2-y^2) + coeff = sqrt(15.0 / ModuleBase::PI) / 4.0; + hrly[7][0] = 2.0 * coeff; + hrly[7][3] = -2.0 * coeff; + hrly[7][1] = hrly[7][2] = 0.0; + hrly[7][4] = hrly[7][5] = 0.0; + + if (Lmax == 2) return; + + /*************************** + L = 3 + ***************************/ + //m=0 : (5z^3-3zr^2) + coeff = sqrt(7.0 / ModuleBase::PI) / 4.0; + hrly[9][0] = hrly[9][3] = -6.0 * z * coeff; + hrly[9][1] = 0.0; + hrly[9][2] = -6.0 * x * coeff; + hrly[9][4] = -6.0 * y * coeff; + hrly[9][5] = 12.0 * z * coeff; + + //m=1 : x(5z^2-r^2) + coeff = sqrt(21.0 / 2.0 / ModuleBase::PI) / 4.0; + hrly[10][0] = -6.0 * x * coeff; + hrly[10][1] = -2.0 * y * coeff; + hrly[10][2] = 8.0 * z * coeff; + hrly[10][3] = -2.0 * x * coeff; + hrly[10][4] = 0.0; + hrly[10][5] = 8.0 * x * coeff; + + //m=-1 : y(5z^2-r^2) + hrly[11][0] = -2.0 * y * coeff; + hrly[11][1] = -2.0 * x * coeff; + hrly[11][2] = 0.0; + hrly[11][3] = -6.0 * y * coeff; + hrly[11][4] = 8.0 * z * coeff; + hrly[11][5] = 8.0 * y * coeff; + + //m=2 : (x^2-y^2)z + coeff = sqrt(105.0 / ModuleBase::PI) / 4.0; + hrly[12][0] = 2.0 * z * coeff; + hrly[12][1] = 0.0; + hrly[12][2] = 2.0 * x * coeff; + hrly[12][3] = -hrly[12][0]; + hrly[12][4] = -2.0 * y * coeff; + hrly[12][5] = 0.0; + + //m=-2 : xyz + coeff = sqrt(105.0 / ModuleBase::PI) / 2.0; + hrly[13][0] = 0.0; + hrly[13][1] = z * coeff; + hrly[13][2] = y * coeff; + hrly[13][3] = 0.0; + hrly[13][4] = x * coeff; + hrly[13][5] = 0.0; + + //m=3 : x(x^2-3y^2) + coeff = sqrt(35.0 / 2.0 / ModuleBase::PI) / 4.0; + hrly[14][0] = 6.0 * x * coeff; + hrly[14][1] = -6.0 * y * coeff; + hrly[14][2] = 0.0; + hrly[14][3] = -hrly[14][0]; + hrly[14][4] = 0.0; + hrly[14][5] = 0.0; + + //m=-3 : y(3x^2-y^2) + hrly[15][0] = 6.0 * y * coeff; + hrly[15][1] = 6.0 * x * coeff; + hrly[15][2] = 0.0; + hrly[15][3] = -hrly[15][0]; + hrly[15][4] = 0.0; + hrly[15][5] = 0.0; + + if (Lmax == 3) return; + + /*************************** + L = 4 + ***************************/ + //m=0 : (35z^4 - 30z^2r^2 + 3r^4) + coeff = sqrt(1.0 / ModuleBase::PI) * 3.0 / 16.0; + hrly[16][0] = 12.0 * (3.0 * x*x + y*y - 4.0 * z*z) * coeff; + hrly[16][1] = 24.0 * x * y * coeff; + hrly[16][2] = -96.0 * x * z * coeff; + hrly[16][3] = 12.0 * (x*x + 3.0 * y*y - 4.0 * z*z) * coeff; + hrly[16][4] = -96.0 * y * z * coeff; + hrly[16][5] = -48.0 * (x*x + y*y -2.0 * z*z) * coeff; + + //m=1 : x(7z^3 - 3zr^2) + coeff = 3.0 / 4.0 * sqrt(5.0 / 2.0 / ModuleBase::PI); + hrly[17][0] = -18.0 * x * z * coeff; + hrly[17][1] = -6.0 * y * z * coeff; + hrly[17][2] = -3.0 * (3.0 * x*x + y*y - 4.0 * z*z) * coeff; + hrly[17][3] = -6.0 * x * z * coeff; + hrly[17][4] = -6.0 * x * y * coeff; + hrly[17][5] = 24.0 * x * z * coeff; + + //m=-1 : y(7z^3 - 3zr^2) + hrly[18][0] = -6.0 * y * z * coeff; + hrly[18][1] = -6.0 * x * z * coeff; + hrly[18][2] = -6.0 * x * y * coeff; + hrly[18][3] = -18.0 * y * z * coeff; + hrly[18][4] = -3.0 * (x*x + 3.0 * y*y - 4.0 * z*z) * coeff; + hrly[18][5] = 24.0 * y * z * coeff; + + //m=2 : (x^2 - y^2)(7z^2 - r^2) + coeff = 3.0 / 8.0 * sqrt(5.0 / ModuleBase::PI); + hrly[19][0] = -12.0 * (x*x - z*z) * coeff; + hrly[19][1] = 0.0; + hrly[19][2] = 24.0 * x * z * coeff; + hrly[19][3] = 12.0 * (y*y - z*z) * coeff; + hrly[19][4] = -24.0 * y * z * coeff; + hrly[19][5] = 12.0 * (x*x - y*y) * coeff; + + //m=-2 : xy(7z^2 - r^2) + coeff = 3.0 / 4.0 * sqrt(5.0 / ModuleBase::PI); + hrly[20][0] = -6.0 * x * y * coeff; + hrly[20][1] = -3.0 * (x*x + y*y - 2.0 * z*z) * coeff; + hrly[20][2] = 2.0 * y * z * coeff; + hrly[20][3] = hrly[20][0]; + hrly[20][4] = 12.0 * x * z * coeff; + hrly[20][5] = 12.0 * x * y * coeff; + + //m=3 : x(x^2-3y^2)z + coeff = 3.0 / 4.0 * sqrt(35.0 / 2.0 / ModuleBase::PI); + hrly[21][0] = 6.0 * x * z * coeff; + hrly[21][1] = -6.0 * y * z * coeff; + hrly[21][2] = 3.0 * (x*x - y*y) * coeff; + hrly[21][3] = -6.0 * x * z * coeff; + hrly[21][4] = -6.0 * x * y * coeff; + hrly[21][5] = 0.0; + + //m=-3 : y(3x^2-y^2)z + hrly[22][0] = 6.0 * y * z * coeff; + hrly[22][1] = 6.0 * x * z * coeff; + hrly[22][2] = 6.0 * x * y * coeff; + hrly[22][3] = -6.0 * y * z * coeff; + hrly[22][4] = 3.0 * (x*x - y*y) * coeff; + hrly[22][5] = 0.0; + + //m=4 : x^4 + y^4 - 6 x^2y^2 + coeff = 3.0 / 16.0 * sqrt(35.0 / ModuleBase::PI); + hrly[23][0] = 12.0 * (x*x - y*y) * coeff; + hrly[23][1] = -24.0 * x * y * coeff; + hrly[23][2] = 0.0; + hrly[23][3] = -hrly[23][0]; + hrly[23][4] = 0.0; + hrly[23][5] = 0.0; + + //m=-4 : xy(x^2 - y^2) + coeff = 3.0 / 4.0 * sqrt(35.0 / ModuleBase::PI); + hrly[24][0] = 6.0 * x * y * coeff; + hrly[24][1] = 3.0 * (x*x - y*y) * coeff; + hrly[24][2] = 0.0; + hrly[24][3] = -hrly[24][0]; + hrly[24][4] = 0.0; + hrly[24][5] = 0.0; + + if (Lmax == 4) return; + + /*************************** + L = 5 + ***************************/ + //m=0 : (63z^5 - 70z^3*r^2 + 15z*r^4) + coeff = sqrt(11.0 / ModuleBase::PI) / 16.0; + hrly[25][0] = (180*x*x*z + 60*y*y*z - 80*z*z*z) * coeff; + hrly[25][1] = (120*x*y*z) * coeff; + hrly[25][2] = (60*x*x*x + 60*x*y*y - 240*x*z*z) * coeff; + hrly[25][3] = (60*x*x*z + 180*y*y*z - 80*z*z*z) * coeff; + hrly[25][4] = (60*x*x*y + 60*y*y*y - 240*y*z*z) * coeff; + hrly[25][5] = (-240*x*x*z - 240*y*y*z + 160*z*z*z) * coeff; + + //m=1 : x(21z^4 - 14z^2*r^2 + r^4) + coeff = sqrt(165.0 / 2.0 / ModuleBase::PI) / 16.0; + hrly[26][0] = (20*x*x*x + 12*x*y*y - 72*x*z*z) * coeff; + hrly[26][1] = (12*x*x*y + 4*y*y*y - 24*y*z*z) * coeff; + hrly[26][2] = (-72*x*x*z - 24*y*y*z + 32*z*z*z) * coeff; + hrly[26][3] = (4*x*x*x + 12*x*y*y - 24*x*z*z) * coeff; + hrly[26][4] = (-48*x*y*z) * coeff; + hrly[26][5] = (-24*x*x*x - 24*x*y*y + 96*x*z*z) * coeff; + + //m=-1 : y(21z^4 - 14z^2*r^2 + r^4) + hrly[27][0] = (12*x*x*y + 4*y*y*y - 24*y*z*z) * coeff; + hrly[27][1] = (4*x*x*x + 12*x*y*y - 24*x*z*z) * coeff; + hrly[27][2] = (-48*x*y*z) * coeff; + hrly[27][3] = (12*x*x*y + 20*y*y*y - 72*y*z*z) * coeff; + hrly[27][4] = (-24*x*x*z - 72*y*y*z + 32*z*z*z) * coeff; + hrly[27][5] = (-24*x*x*y - 24*y*y*y + 96*y*z*z) * coeff; + + //m=2 : (x^2 - y^2)(3z^3 - z*r^2) + coeff = sqrt(1155.0 / ModuleBase::PI) / 8.0; + hrly[28][0] = (-12*x*x*z + 4*z*z*z) * coeff; + hrly[28][1] = 0.0; + hrly[28][2] = (-4*x*x*x + 12*x*z*z) * coeff; + hrly[28][3] = (12*y*y*z - 4*z*z*z) * coeff; + hrly[28][4] = (4*y*y*y - 12*y*z*z) * coeff; + hrly[28][5] = (12*x*x*z - 12*y*y*z) * coeff; + + //m=-2 : xy(3z^3 - z*r^2) + hrly[29][0] = (-6*x*y*z) * coeff; + hrly[29][1] = (-3*x*x*z - 3*y*y*z + 2*z*z*z) * coeff; + hrly[29][2] = (-3*x*x*y - y*y*y + 6*y*z*z) * coeff; + hrly[29][3] = (-6*x*y*z) * coeff; + hrly[29][4] = (-x*x*x - 3*x*y*y + 6*x*z*z) * coeff; + hrly[29][5] = (12*x*y*z) * coeff; + + //m=3 : x(x^2 - 3y^2)(9z^2 - r^2) + coeff = sqrt(385.0 / 2.0 / ModuleBase::PI) / 16.0; + hrly[30][0] = (-20*x*x*x + 12*x*y*y + 48*x*z*z) * coeff; + hrly[30][1] = (12*x*x*y + 12*y*y*y - 48*y*z*z) * coeff; + hrly[30][2] = (48*x*x*z - 48*y*y*z) * coeff; + hrly[30][3] = (4*x*x*x + 36*x*y*y - 48*x*z*z) * coeff; + hrly[30][4] = (-96*x*y*z) * coeff; + hrly[30][5] = (16*x*x*x - 48*x*y*y) * coeff; + + //m=-3 : y(3x^2 - y^2)(9z^2 - r^2) + hrly[31][0] = (-36*x*x*y - 4*y*y*y + 48*y*z*z) * coeff; + hrly[31][1] = (-12*x*x*x - 12*x*y*y + 48*x*z*z) * coeff; + hrly[31][2] = (96*x*y*z) * coeff; + hrly[31][3] = (-12*x*x*y + 20*y*y*y - 48*y*z*z) * coeff; + hrly[31][4] = (48*x*x*z - 48*y*y*z) * coeff; + hrly[31][5] = (48*x*x*y - 16*y*y*y) * coeff; + + //m=4 : (x^4 - 6x^2*y^2 + y^4) * z + coeff = sqrt(385.0 / ModuleBase::PI) / 16.0; + hrly[32][0] = (12*x*x*z - 12*y*y*z) * coeff; + hrly[32][1] = (-24*x*y*z) * coeff; + hrly[32][2] = (4*x*x*x - 12*x*y*y) * coeff; + hrly[32][3] = (-12*x*x*z + 12*y*y*z) * coeff; + hrly[32][4] = (-12*x*x*y + 4*y*y*y) * coeff; + hrly[32][5] = 0.0; + + //m=-4 : xy(x^2 - y^2) * z + hrly[33][0] = (6*x*y*z) * coeff; + hrly[33][1] = (3*x*x*z - 3*y*y*z) * coeff; + hrly[33][2] = (3*x*x*y - y*y*y) * coeff; + hrly[33][3] = (-6*x*y*z) * coeff; + hrly[33][4] = (x*x*x - 3*x*y*y) * coeff; + hrly[33][5] = 0.0; + + //m=5 : x(x^4 - 10x^2*y^2 + 5y^4) + coeff = sqrt(77.0 / 2.0 / ModuleBase::PI) / 16.0; + hrly[34][0] = (20.0 * x*x*x - 60.0 * x * y*y) * coeff; + hrly[34][1] = (-60.0 * x*x * y + 20.0 * y*y*y) * coeff; + hrly[34][2] = 0.0; + hrly[34][3] = (-20.0 * x*x*x + 60.0 * x * y*y) * coeff; + hrly[34][4] = 0.0; + hrly[34][5] = 0.0; + + //m=-5 : y(5x^4 - 10x^2*y^2 + y^4) + hrly[35][0] = (60.0 * x*x * y - 20.0 * y*y*y) * coeff; + hrly[35][1] = (20.0 * x*x*x - 60.0 * x * y*y) * coeff; + hrly[35][2] = 0.0; + hrly[35][3] = (-60.0 * x*x * y + 20.0 * y*y*y) * coeff; + hrly[35][4] = 0.0; + hrly[35][5] = 0.0; + + if (Lmax == 5) return; + + /*************************** + L = 6 + ***************************/ + //m=0 : (231z^6 - 315z^4*r^2 + 105z^2*r^4 - 5r^6) + coeff = sqrt(13.0 / ModuleBase::PI) / 32.0; + hrly[36][0] = (-150*x*x*x*x - 180*x*x*y*y + 1080*x*x*z*z - 30*y*y*y*y + 360*y*y*z*z - 240*z*z*z*z) * coeff; + hrly[36][1] = (-120*x*x*x*y - 120*x*y*y*y + 720*x*y*z*z) * coeff; + hrly[36][2] = (720*x*x*x*z + 720*x*y*y*z - 960*x*z*z*z) * coeff; + hrly[36][3] = (-30*x*x*x*x - 180*x*x*y*y + 360*x*x*z*z - 150*y*y*y*y + 1080*y*y*z*z - 240*z*z*z*z) * coeff; + hrly[36][4] = (720*x*x*y*z + 720*y*y*y*z - 960*y*z*z*z) * coeff; + hrly[36][5] = (180*x*x*x*x + 360*x*x*y*y - 1440*x*x*z*z + 180*y*y*y*y - 1440*y*y*z*z + 480*z*z*z*z) * coeff; + + //m=1 : x(33z^5 - 30z^3*r^2 + 5z*r^4) + coeff = sqrt(273.0 / 2.0 / ModuleBase::PI) / 16.0; + hrly[37][0] = (100*x*x*x*z + 60*x*y*y*z - 120*x*z*z*z) * coeff; + hrly[37][1] = (60*x*x*y*z + 20*y*y*y*z - 40*y*z*z*z) * coeff; + hrly[37][2] = (25*x*x*x*x + 30*x*x*y*y - 180*x*x*z*z + 5*y*y*y*y - 60*y*y*z*z + 40*z*z*z*z) * coeff; + hrly[37][3] = (20*x*x*x*z + 60*x*y*y*z - 40*x*z*z*z) * coeff; + hrly[37][4] = (20*x*x*x*y + 20*x*y*y*y - 120*x*y*z*z) * coeff; + hrly[37][5] = (-120*x*x*x*z - 120*x*y*y*z + 160*x*z*z*z) * coeff; + + //m=-1 : y(33z^5 - 30z^3*r^2 + 5z*r^4) + hrly[38][0] = (60*x*x*y*z + 20*y*y*y*z - 40*y*z*z*z) * coeff; + hrly[38][1] = (20*x*x*x*z + 60*x*y*y*z - 40*x*z*z*z) * coeff; + hrly[38][2] = (20*x*x*x*y + 20*x*y*y*y - 120*x*y*z*z) * coeff; + hrly[38][3] = (60*x*x*y*z + 100*y*y*y*z - 120*y*z*z*z) * coeff; + hrly[38][4] = (5*x*x*x*x + 30*x*x*y*y - 60*x*x*z*z + 25*y*y*y*y - 180*y*y*z*z + 40*z*z*z*z) * coeff; + hrly[38][5] = (-120*x*x*y*z - 120*y*y*y*z + 160*y*z*z*z) * coeff; + + //m=2 : (x^2 - y^2)(33z^4 - 18z^2*r^2 + r^4) + coeff = sqrt(1365.0 / ModuleBase::PI) / 32.0; + hrly[39][0] = (30*x*x*x*x + 12*x*x*y*y - 192*x*x*z*z - 2*y*y*y*y + 32*z*z*z*z) * coeff; + hrly[39][1] = (8*x*x*x*y - 8*x*y*y*y) * coeff; + hrly[39][2] = (-128*x*x*x*z + 128*x*z*z*z) * coeff; + hrly[39][3] = (2*x*x*x*x - 12*x*x*y*y - 30*y*y*y*y + 192*y*y*z*z - 32*z*z*z*z) * coeff; + hrly[39][4] = (128*y*y*y*z - 128*y*z*z*z) * coeff; + hrly[39][5] = (-32*x*x*x*x + 192*x*x*z*z + 32*y*y*y*y - 192*y*y*z*z) * coeff; + + //m=-2 : xy(33z^4 - 18z^2*r^2 + r^4) + hrly[40][0] = (20*x*x*x*y + 12*x*y*y*y - 96*x*y*z*z) * coeff; + hrly[40][1] = (20*x*x*x*x + 36*x*x*y*y - 96*x*x*z*z + 20*y*y*y*y - 96*y*y*z*z + 32*z*z*z*z) * coeff; + hrly[40][2] = (-96*x*x*y*z - 32*y*y*y*z + 64*y*z*z*z) * coeff; + hrly[40][3] = (12*x*x*x*y + 20*x*y*y*y - 96*x*y*z*z) * coeff; + hrly[40][4] = (-32*x*x*x*z - 96*x*y*y*z + 64*x*z*z*z) * coeff; + hrly[40][5] = (-32*x*x*x*y - 32*x*y*y*y + 192*x*y*z*z) * coeff; + + //m=3 : x(x^2 - 3y^2)(11z^3 - 3z*r^2) + coeff = sqrt(1365.0 / ModuleBase::PI) / 16.0; + hrly[41][0] = (-60*x*x*x*z + 36*x*y*y*z + 48*x*z*z*z) * coeff; + hrly[41][1] = (36*x*x*y*z + 36*y*y*y*z - 48*y*z*z*z) * coeff; + hrly[41][2] = (-30*x*x*x*x + 36*x*x*y*y + 72*x*x*z*z + 18*y*y*y*y - 72*y*y*z*z) * coeff; + hrly[41][3] = (12*x*x*x*z + 108*x*y*y*z - 48*x*z*z*z) * coeff; + hrly[41][4] = (12*x*x*x*y + 36*x*y*y*y - 144*x*y*z*z) * coeff; + hrly[41][5] = (48*x*x*x*z - 144*x*y*y*z) * coeff; + + //m=-3 : y(3x^2 - y^2)(11z^3 - 3z*r^2) + hrly[42][0] = (-108*x*x*y*z - 12*y*y*y*z + 48*y*z*z*z) * coeff; + hrly[42][1] = (-36*x*x*x*z - 36*x*y*y*z + 48*x*z*z*z) * coeff; + hrly[42][2] = (-36*x*x*x*y - 12*x*y*y*y + 144*x*y*z*z) * coeff; + hrly[42][3] = (-36*x*x*y*z + 60*y*y*y*z - 48*y*z*z*z) * coeff; + hrly[42][4] = (-18*x*x*x*x - 36*x*x*y*y + 72*x*x*z*z + 30*y*y*y*y - 72*y*y*z*z) * coeff; + hrly[42][5] = (144*x*x*y*z - 48*y*y*y*z) * coeff; + + //m=4 : (x^4 - 6x^2*y^2 + y^4)(11z^2 - r^2) + coeff = sqrt(91.0 / ModuleBase::PI) / 32.0; + hrly[43][0] = (-30*x*x*x*x + 60*x*x*y*y + 120*x*x*z*z + 10*y*y*y*y - 120*y*y*z*z) * coeff; + hrly[43][1] = (40*x*x*x*y + 40*x*y*y*y - 240*x*y*z*z) * coeff; + hrly[43][2] = (80*x*x*x*z - 240*x*y*y*z) * coeff; + hrly[43][3] = (10*x*x*x*x + 60*x*x*y*y - 120*x*x*z*z - 30*y*y*y*y + 120*y*y*z*z) * coeff; + hrly[43][4] = (-240*x*x*y*z + 80*y*y*y*z) * coeff; + hrly[43][5] = (20*x*x*x*x - 120*x*x*y*y + 20*y*y*y*y) * coeff; + + //m=-4 : xy(x^2 - y^2)(11z^2 - r^2) + hrly[44][0] = (-20*x*x*x*y + 60*x*y*z*z) * coeff; + hrly[44][1] = (-5*x*x*x*x + 30*x*x*z*z + 5*y*y*y*y - 30*y*y*z*z) * coeff; + hrly[44][2] = (60*x*x*y*z - 20*y*y*y*z) * coeff; + hrly[44][3] = (20*x*y*y*y - 60*x*y*z*z) * coeff; + hrly[44][4] = (20*x*x*x*z - 60*x*y*y*z) * coeff; + hrly[44][5] = (20*x*x*x*y - 20*x*y*y*y) * coeff; + + //m=5 : x(x^4 - 10x^2*y^2 + 5y^4) * z + coeff = sqrt(1001.0 / 2.0 / ModuleBase::PI) / 16.0; + hrly[45][0] = (20*x*x*x*z - 60*x*y*y*z) * coeff; + hrly[45][1] = (-60*x*x*y*z + 20*y*y*y*z) * coeff; + hrly[45][2] = (5*x*x*x*x - 30*x*x*y*y + 5*y*y*y*y) * coeff; + hrly[45][3] = (-20*x*x*x*z + 60*x*y*y*z) * coeff; + hrly[45][4] = (-20*x*x*x*y + 20*x*y*y*y) * coeff; + hrly[45][5] = 0.0; + + //m=-5 : y(5x^4 - 10x^2*y^2 + y^4) * z + hrly[46][0] = (60*x*x*y*z - 20*y*y*y*z) * coeff; + hrly[46][1] = (20*x*x*x*z - 60*x*y*y*z) * coeff; + hrly[46][2] = (20*x*x*x*y - 20*x*y*y*y) * coeff; + hrly[46][3] = (-60*x*x*y*z + 20*y*y*y*z) * coeff; + hrly[46][4] = (5*x*x*x*x - 30*x*x*y*y + 5*y*y*y*y) * coeff; + hrly[46][5] = 0.0; + + //m=6 : (x^6 - 15x^4*y^2 + 15x^2*y^4 - y^6) + coeff = sqrt(3003.0 / ModuleBase::PI) / 32.0; + hrly[47][0] = (30*x*x*x*x - 180*x*x*y*y + 30*y*y*y*y) * coeff; + hrly[47][1] = (-120*x*x*x*y + 120*x*y*y*y) * coeff; + hrly[47][2] = 0.0; + hrly[47][3] = (-30*x*x*x*x + 180*x*x*y*y - 30*y*y*y*y) * coeff; + hrly[47][4] = 0.0; + hrly[47][5] = 0.0; + + //m=-6 : xy(3x^4 - 10x^2*y^2 + 3y^4) + hrly[48][0] = (60*x*x*x*y - 60*x*y*y*y) * coeff; + hrly[48][1] = (15*x*x*x*x - 90*x*x*y*y + 15*y*y*y*y) * coeff; + hrly[48][2] = 0.0; + hrly[48][3] = (-60*x*x*x*y + 60*x*y*y*y) * coeff; + hrly[48][4] = 0.0; + hrly[48][5] = 0.0; + + if (Lmax == 6) return; + + /*************************** + L > 6 + ***************************/ + ModuleBase::WARNING_QUIT("hes_rl_sph_harm","l>6 not implemented!"); + + + return; } void Ylm::set_coefficients (){}; /* void Ylm::test1 (void) { - ModuleBase::Vector3 R (20.0, 0.0, 0.0); - double xdr = R.x/R.norm(); - double ydr = R.y/R.norm(); - double zdr = R.z/R.norm(); - const int L = 9; - const double rl = std::pow( R.norm(), L); - std::cout << " rl=" << rl << std::endl; - Ylm::set_coefficients(); - - int nu = 100; - - // Peize Lin change rlya 2016-08-26 - std::vector rlya; - double rlyb[400]; - ZEROS( rlyb, 400); + ModuleBase::Vector3 R (20.0, 0.0, 0.0); + double xdr = R.x/R.norm(); + double ydr = R.y/R.norm(); + double zdr = R.z/R.norm(); + const int L = 9; + const double rl = std::pow( R.norm(), L); + std::cout << " rl=" << rl << std::endl; + Ylm::set_coefficients(); + + int nu = 100; + + // Peize Lin change rlya 2016-08-26 + std::vector rlya; + double rlyb[400]; + ZEROS( rlyb, 400); // Ylm::sph_harm (9, xdr, ydr, zdr, rlya); - Ylm::rl_sph_harm (L, xdr, ydr, zdr, rlya); + Ylm::rl_sph_harm (L, xdr, ydr, zdr, rlya); // Ylm::rlylm (10, R.x, R.y, R.z, rlyb); - Ylm::get_ylm_real (L+1, R, rlyb); - - for (int i=0; i < nu; i++) - { - // std::cout << "\ni= " << i << " rlya = " << rlya[i] << " rlyb = " << rlyb[i] << std::endl; - double diff = fabs(rlya[i]-rlyb[i]); - if (diff > 1e-8) - { - std::cout << "Ylm::test1, error is too large!" << std::endl; - //WARNING_QUIT ("Ylm::test1","error is too large!"); - exit(0); - } - } - return; + Ylm::get_ylm_real (L+1, R, rlyb); + + for (int i=0; i < nu; i++) + { + // std::cout << "\ni= " << i << " rlya = " << rlya[i] << " rlyb = " << rlyb[i] << std::endl; + double diff = fabs(rlya[i]-rlyb[i]); + if (diff > 1e-8) + { + std::cout << "Ylm::test1, error is too large!" << std::endl; + //WARNING_QUIT ("Ylm::test1","error is too large!"); + exit(0); + } + } + return; } */ /* void Ylm::test2 (void) { - ModuleBase::Vector3 R (0.1,-0.2,0.5); - Ylm::set_coefficients(); - - //int nu = 100; - - std::vector rlya; - double rlyb[400]; - - std::vector> grlya; - double grlyb[400][3]; - - Ylm::grad_rl_sph_harm (9, R.x, R.y, R.z, rlya, grlya); - Ylm::rlylm (10, R.x, R.y, R.z, rlyb, grlyb); - - for (int i = 0; i < 100; i++) - { - double diffx = fabs(grlya[i][2]-grlyb[i][2]); - if (diffx > 1e-8) - { - std::cout << "Ylm::test2, Large error in Direv X!" << std::endl; - //WARNING_QUIT ("Ylm::test2","Large error in Direv X!"); - exit(0); - } - } - return; + ModuleBase::Vector3 R (0.1,-0.2,0.5); + Ylm::set_coefficients(); + + //int nu = 100; + + std::vector rlya; + double rlyb[400]; + + std::vector> grlya; + double grlyb[400][3]; + + Ylm::grad_rl_sph_harm (9, R.x, R.y, R.z, rlya, grlya); + Ylm::rlylm (10, R.x, R.y, R.z, rlyb, grlyb); + + for (int i = 0; i < 100; i++) + { + double diffx = fabs(grlya[i][2]-grlyb[i][2]); + if (diffx > 1e-8) + { + std::cout << "Ylm::test2, Large error in Direv X!" << std::endl; + //WARNING_QUIT ("Ylm::test2","Large error in Direv X!"); + exit(0); + } + } + return; } */ void Ylm::rlylm ( - const int Lmax, //max momentum of l + 1 - const double x, - const double y, - const double z, - double rly[], - double grly[][3] + const int Lmax, //max momentum of l + 1 + const double x, + const double y, + const double z, + double rly[], + double grly[][3] ) { - int MaxL = Lmax - 1; - - assert(MaxL >= 0); - - //get xy_dependence - assert(MaxL <= 19); - - double Am[20]; - double Bm[20]; - double Gx_Am[20]; - double Gx_Bm[20]; - double Gy_Am[20]; - double Gy_Bm[20]; - - ZEROS(Am, 20); - ZEROS(Bm, 20); - ZEROS(Gx_Am, 20); - ZEROS(Gy_Am, 20); - - double x2, x3, x4, x5; - double y2, y3, y4, y5; - - x2 = x * x; - x3 = x2 * x; - x4 = x3 * x; - x5 = x4 * x; - - y2 = y * y; - y3 = y2 * y; - y4 = y3 * y; - y5 = y4 * y; - - //x-y dependence - //Am - //Bm - for(int im = 0; im < MaxL+1; im++) - { - if(im == 0) - { - Am[0] = 1.0; - Bm[0] = 0.0; - - Gx_Am[0] = 0.0; - Gy_Am[0] = 0.0; - - Gx_Bm[0] = 0.0; - Gy_Bm[0] = 0.0; - } - else if(im == 1) - { - Am[1] = x; - Bm[1] = y; - - Gx_Am[1] = 1.0; - Gy_Am[1] = 0.0; - - Gx_Bm[1] = 0.0; - Gy_Bm[1] = 1.0; - } - else if(im == 2) - { - Am[2] = x2- y2; - Bm[2] = 2.0 * x * y; - - Gx_Am[2] = 2.0 * x; - Gy_Am[2] = -2.0 * y; - - Gx_Bm[2] = 2.0 * y; - Gy_Bm[2] = 2.0 * x; - } - else if(im == 3) - { - Am[3] = x3 - 3.0 * x * y2; - Bm[3] = 3.0 * x2 * y - y3; - - Gx_Am[3] = 3.0 * (x2 - y2); - Gy_Am[3] = -6.0 * x * y; - - Gx_Bm[3] = 6.0 * x * y; - Gy_Bm[3] = 3.0 * (x2 - y2); - } - else if(im == 4) - { - Am[4] = x4 - 6.0 * x2 * y2 + y4; - Bm[4] = 4.0 * (x3 * y - x * y3); - - Gx_Am[4] = 4.0 * x3 - 12.0 * x * y2; - Gy_Am[4] = -12.0 * x2 * y + 4.0 * y3; - - Gx_Bm[4] = 12.0 * x2 * y - 4.0 * y3; - Gy_Bm[4] = 4.0 * x3 - 12.0 * x * y2; - } - else if(im == 5) - { - Am[5] = x5 - 10.0 * x3 * y2 + 5.0 * x * y4; - Bm[5] = 5.0 * x4 * y - 10.0 * x2 * y3 + y5; - - Gx_Am[5] = 5.0 * x4 - 30.0 * x2 * y2 + 5.0 * y4; - Gy_Am[5] = 20.0 * (x * y3 - x3 * y); - - Gx_Bm[5] = 20.0 * (x3 * y - x * y3); - Gy_Bm[5] = 5.0 * x4 - 30.0 * x2 * y2 + 5.0 * y4; - } - else - { - for(int ip = 0; ip <= im; ip++) - { - double aux = Fact(im) / Fact(ip) / Fact(im - ip); - Am[im] += aux * pow(x, ip) * pow(y, im-ip) * cos( (im-ip) * ModuleBase::PI / 2.0 ); - Bm[im] += aux * pow(x, ip) * pow(y, im-ip) * sin( (im-ip) * ModuleBase::PI / 2.0 ); - - if(ip > 0) - { - Gx_Am[im] += aux * ip * pow(x, ip-1) * pow(y, im-ip) * cos( (im-ip) * ModuleBase::PI / 2.0 ); - Gx_Bm[im] += aux * ip * pow(x, ip-1) * pow(y, im-ip) * sin( (im-ip) * ModuleBase::PI / 2.0 ); - } - - if(ip < im) - { - Gy_Am[im] += aux * pow(x, ip) * (im - ip) * pow(y, im-ip-1) * cos( (im-ip) * ModuleBase::PI / 2.0 ); - Gy_Bm[im] += aux * pow(x, ip) * (im - ip) * pow(y, im-ip-1) * sin( (im-ip) * ModuleBase::PI / 2.0 ); - } - } - } - } - - //z dependence - double zdep[20][20]; - double Gx_dep[20][20]; - double Gy_dep[20][20]; - double Gz_dep[20][20]; - - for(int il = 0; il < 20; il++) - { - ZEROS(zdep[il], 20); - ZEROS(Gx_dep[il], 20); - ZEROS(Gy_dep[il], 20); - ZEROS(Gz_dep[il], 20); - } - - double z2 = z * z; - double z3 = z2 * z; - double z4 = z3 * z; - //double z5 = z4 * z; - - double r = sqrt(x*x + y*y + z*z); - double r2 = r * r; - double r3 = r2 * r; - double r4 = r3 * r; - - for(int il = 0; il < MaxL+1; il++) - { - if(il == 0) - { - zdep[0][0] = 1.0; - } - else if(il == 1) - { - zdep[1][0] = z; - zdep[1][1] = 1.0; - - Gz_dep[1][0] = 1.0; - } - else if(il == 2) - { - zdep[2][0] = 0.5 * (3.0 * z2 - r2); - Gx_dep[2][0] = -x; - Gy_dep[2][0] = -y; - Gz_dep[2][0] = 2.0 * z; - - zdep[2][1] = sqrt(3.0) * z; - Gz_dep[2][1] = sqrt(3.0); - - zdep[2][2] = sqrt(3.0) * 0.5; - } - else if(il == 3) - { - zdep[3][0] = 2.5 * z3 - 1.5 * z * r2; - Gx_dep[3][0] = -3.0 * x * z; - Gy_dep[3][0] = -3.0 * y * z; - Gz_dep[3][0] = 1.5 * (3.0 * z2 - r2); - - zdep[3][1] = 0.25 * sqrt(6.0) * (5.0 * z2 - r2); - Gx_dep[3][1] = -0.5 * sqrt(6.0) * x; - Gy_dep[3][1] = -0.5 * sqrt(6.0) * y; - Gz_dep[3][1] = sqrt(6.0) * 2.0 * z; - - zdep[3][2] = 0.5 * sqrt(15.0) * z; - Gz_dep[3][2] = 0.5 * sqrt(15.0); - - zdep[3][3] = 0.25 * sqrt(10.0); - } - else if(il == 4) - { - zdep[4][0] = 0.125 * (35.0 * z4 - 30.0 * r2 * z2 + 3.0 * r4); - Gx_dep[4][0] = -7.5 * x * z2 + 1.5 * x * r2; - Gy_dep[4][0] = -7.5 * y * z2 + 1.5 * y * r2; - Gz_dep[4][0] = 10.0 * z3 - 6.0 * r2 * z; - - zdep[4][1] = sqrt(10.0) * 0.25 * z * (7.0 * z2 - 3.0 * r2); - Gx_dep[4][1] = -1.5 * sqrt(10.0) * x * z; - Gy_dep[4][1] = -1.5 * sqrt(10.0) * y * z; - Gz_dep[4][1] = 0.75 * sqrt(10.0) * (5.0 * z2 - r2); - - zdep[4][2] = sqrt(5.0) * 0.25 * (7.0 * z2 - r2); - Gx_dep[4][2] = -0.5 * sqrt(5.0) * x; - Gy_dep[4][2] = -0.5 * sqrt(5.0) * y; - Gz_dep[4][2] = 3.0 * sqrt(5.0) * z; - - zdep[4][3] = sqrt(70.0) * 0.25 * z; - Gz_dep[4][3] = 0.25 * sqrt(70.0); - - zdep[4][4] = sqrt(35.0) * 0.125; - } - else if(il == 5) - { - zdep[5][0] = 0.125 * z *( 63.0 * z4 - 70.0 * z2 * r2 + 15.0 * r4); - Gx_dep[5][0] = -17.5 * x * z3 + 7.5 * x * z * r2; - Gy_dep[5][0] = -17.5 * y * z3 + 7.5 * y * z * r2; - Gz_dep[5][0] = 175.0 * 0.125 * z4 + 15.0 * 0.125 * r4 - 150.0 * 0.125 * r2 * z2; - - zdep[5][1] = 0.125 * sqrt(15.0) * (21.0 * z4 - 14.0 * z2 * r2 + r4); - Gx_dep[5][1] = -3.5 * sqrt(15.0) * x * z2 + 0.5 * sqrt(15.0) * x * r2; - Gy_dep[5][1] = -3.5 * sqrt(15.0) * y * z2 + 0.5 * sqrt(15.0) * y * r2; - Gz_dep[5][1] = 7.0 * sqrt(15.0) * z3 - 3.0 * sqrt(15.0) * r2 * z; - - zdep[5][2] = 0.25 * sqrt(105.0) * z * (3.0 * z2 - r2); - Gx_dep[5][2] = -0.5 * sqrt(105.0) * x * z; - Gy_dep[5][2] = -0.5 * sqrt(105.0) * y * z; - Gz_dep[5][2] = 0.25 * sqrt(105.0) * (7.0 * z2 - r2); - - zdep[5][3] = 0.0625 * sqrt(70.0) * (9.0 * z2 - r2); - Gx_dep[5][3] = -0.125 * sqrt(70.0) * x; - Gy_dep[5][3] = -0.125 * sqrt(70.0) * y; - Gz_dep[5][3] = sqrt(70.0) * z; - - zdep[5][4] = 0.375 * sqrt(35.0) * z; - Gz_dep[5][4] = 0.375 * sqrt(35.0); - - zdep[5][5] = 0.1875 * sqrt(14.0); - } - else - { - for(int im = 0; im <= il; im++) - { - int kmax = static_cast( (il - im) / 2 ); - for(int ik = 0; ik <= kmax; ik++) - { - int twok = 2 * ik; - - double gamma = 0.0; - double aux0, aux1, aux2, aux3; - - aux0 = pow(-1.0, ik) * pow(2.0, -il); - aux1 = Fact(il) / Fact(ik) / Fact(il-ik); - aux2 = Fact(2*il - twok) / Fact(il) / Fact(il - twok); - aux3 = Fact(il - twok) / Fact(il - twok - im); - - gamma = aux0 * aux1 * aux2 * aux3; - - assert(il - twok - im >= 0); - zdep[il][im] += pow(r, twok) * pow(z, il-twok-im) * gamma; - - if(ik > 0) - { - Gx_dep[il][im] += (ik * pow(r2, ik-1) * 2.0 * x) * pow(z, il-twok-im) * gamma; - Gy_dep[il][im] += (ik * pow(r2, ik-1) * 2.0 * y) * pow(z, il-twok-im) * gamma; - } - - if(ik == 0) - { - if(il > im) - { - Gz_dep[il][im] += (il-im) * pow(z, il-im-1) * gamma; - } - } - else - { - if(il - twok - im == 0) - { - Gz_dep[il][im] += gamma * ik * pow(r2, ik-1) * 2.0 * z; - } - else - { - Gz_dep[il][im] += gamma * (ik * pow(r2, ik-1) * 2.0 * z * pow(z, il-twok-im) - + pow(r, twok) * (il-twok-im) * pow(z, il-twok-im-1)); - } - } - } - - if(im >= 1) - { - zdep[il][im] *= sqrt(2 * Fact(il - im) / Fact(il + im)); - Gx_dep[il][im] *= sqrt(2 * Fact(il - im) / Fact(il + im)); - Gy_dep[il][im] *= sqrt(2 * Fact(il - im) / Fact(il + im)); - Gz_dep[il][im] *= sqrt(2 * Fact(il - im) / Fact(il + im)); - - } - } - } - } - - //calc - int ic = 0; - for(int il = 0; il <= MaxL; il++) - { - double fac = sqrt( (2.0 * il + 1.0) / ModuleBase::FOUR_PI ); - - //m=0 - rly[ic] = Am[0] * zdep[il][0] * fac; - grly[ic][0] = (Gx_dep[il][0] * Am[0] + zdep[il][0] * Gx_Am[0]) * fac; - grly[ic][1] = (Gy_dep[il][0] * Am[0] + zdep[il][0] * Gy_Am[0]) * fac; - grly[ic][2] = Gz_dep[il][0] * Am[0] * fac; - - ic++; - - //m ! = 0 - for(int im = 1; im <= il; im++) - { - //m>0 - rly[ic] = Am[im] * zdep[il][im] * pow(-1.0, im) * fac; - grly[ic][0] = (Gx_dep[il][im] * Am[im] + zdep[il][im] * Gx_Am[im]) * pow(-1.0, im) * fac; - grly[ic][1] = (Gy_dep[il][im] * Am[im] + zdep[il][im] * Gy_Am[im]) * pow(-1.0, im) * fac; - grly[ic][2] = Gz_dep[il][im] * Am[im] * pow(-1.0, im) * fac; - - ic++; - - //m<0 - rly[ic] = Bm[im] * zdep[il][im] * pow(-1.0, im) * fac; - grly[ic][0] = (Gx_dep[il][im] * Bm[im] + zdep[il][im] * Gx_Bm[im]) * pow(-1.0, im) * fac; - grly[ic][1] = (Gy_dep[il][im] * Bm[im] + zdep[il][im] * Gy_Bm[im]) * pow(-1.0, im) * fac; - grly[ic][2] = Gz_dep[il][im] * Bm[im] * pow(-1.0, im) * fac; - - ic++; - } - } - - return; + int MaxL = Lmax - 1; + + assert(MaxL >= 0); + + //get xy_dependence + assert(MaxL <= 19); + + double Am[20]; + double Bm[20]; + double Gx_Am[20]; + double Gx_Bm[20]; + double Gy_Am[20]; + double Gy_Bm[20]; + + ZEROS(Am, 20); + ZEROS(Bm, 20); + ZEROS(Gx_Am, 20); + ZEROS(Gy_Am, 20); + + double x2, x3, x4, x5; + double y2, y3, y4, y5; + + x2 = x * x; + x3 = x2 * x; + x4 = x3 * x; + x5 = x4 * x; + + y2 = y * y; + y3 = y2 * y; + y4 = y3 * y; + y5 = y4 * y; + + //x-y dependence + //Am + //Bm + for(int im = 0; im < MaxL+1; im++) + { + if(im == 0) + { + Am[0] = 1.0; + Bm[0] = 0.0; + + Gx_Am[0] = 0.0; + Gy_Am[0] = 0.0; + + Gx_Bm[0] = 0.0; + Gy_Bm[0] = 0.0; + } + else if(im == 1) + { + Am[1] = x; + Bm[1] = y; + + Gx_Am[1] = 1.0; + Gy_Am[1] = 0.0; + + Gx_Bm[1] = 0.0; + Gy_Bm[1] = 1.0; + } + else if(im == 2) + { + Am[2] = x2- y2; + Bm[2] = 2.0 * x * y; + + Gx_Am[2] = 2.0 * x; + Gy_Am[2] = -2.0 * y; + + Gx_Bm[2] = 2.0 * y; + Gy_Bm[2] = 2.0 * x; + } + else if(im == 3) + { + Am[3] = x3 - 3.0 * x * y2; + Bm[3] = 3.0 * x2 * y - y3; + + Gx_Am[3] = 3.0 * (x2 - y2); + Gy_Am[3] = -6.0 * x * y; + + Gx_Bm[3] = 6.0 * x * y; + Gy_Bm[3] = 3.0 * (x2 - y2); + } + else if(im == 4) + { + Am[4] = x4 - 6.0 * x2 * y2 + y4; + Bm[4] = 4.0 * (x3 * y - x * y3); + + Gx_Am[4] = 4.0 * x3 - 12.0 * x * y2; + Gy_Am[4] = -12.0 * x2 * y + 4.0 * y3; + + Gx_Bm[4] = 12.0 * x2 * y - 4.0 * y3; + Gy_Bm[4] = 4.0 * x3 - 12.0 * x * y2; + } + else if(im == 5) + { + Am[5] = x5 - 10.0 * x3 * y2 + 5.0 * x * y4; + Bm[5] = 5.0 * x4 * y - 10.0 * x2 * y3 + y5; + + Gx_Am[5] = 5.0 * x4 - 30.0 * x2 * y2 + 5.0 * y4; + Gy_Am[5] = 20.0 * (x * y3 - x3 * y); + + Gx_Bm[5] = 20.0 * (x3 * y - x * y3); + Gy_Bm[5] = 5.0 * x4 - 30.0 * x2 * y2 + 5.0 * y4; + } + else + { + for(int ip = 0; ip <= im; ip++) + { + double aux = Fact(im) / Fact(ip) / Fact(im - ip); + Am[im] += aux * pow(x, ip) * pow(y, im-ip) * cos( (im-ip) * ModuleBase::PI / 2.0 ); + Bm[im] += aux * pow(x, ip) * pow(y, im-ip) * sin( (im-ip) * ModuleBase::PI / 2.0 ); + + if(ip > 0) + { + Gx_Am[im] += aux * ip * pow(x, ip-1) * pow(y, im-ip) * cos( (im-ip) * ModuleBase::PI / 2.0 ); + Gx_Bm[im] += aux * ip * pow(x, ip-1) * pow(y, im-ip) * sin( (im-ip) * ModuleBase::PI / 2.0 ); + } + + if(ip < im) + { + Gy_Am[im] += aux * pow(x, ip) * (im - ip) * pow(y, im-ip-1) * cos( (im-ip) * ModuleBase::PI / 2.0 ); + Gy_Bm[im] += aux * pow(x, ip) * (im - ip) * pow(y, im-ip-1) * sin( (im-ip) * ModuleBase::PI / 2.0 ); + } + } + } + } + + //z dependence + double zdep[20][20]; + double Gx_dep[20][20]; + double Gy_dep[20][20]; + double Gz_dep[20][20]; + + for(int il = 0; il < 20; il++) + { + ZEROS(zdep[il], 20); + ZEROS(Gx_dep[il], 20); + ZEROS(Gy_dep[il], 20); + ZEROS(Gz_dep[il], 20); + } + + double z2 = z * z; + double z3 = z2 * z; + double z4 = z3 * z; + //double z5 = z4 * z; + + double r = sqrt(x*x + y*y + z*z); + double r2 = r * r; + double r3 = r2 * r; + double r4 = r3 * r; + + for(int il = 0; il < MaxL+1; il++) + { + if(il == 0) + { + zdep[0][0] = 1.0; + } + else if(il == 1) + { + zdep[1][0] = z; + zdep[1][1] = 1.0; + + Gz_dep[1][0] = 1.0; + } + else if(il == 2) + { + zdep[2][0] = 0.5 * (3.0 * z2 - r2); + Gx_dep[2][0] = -x; + Gy_dep[2][0] = -y; + Gz_dep[2][0] = 2.0 * z; + + zdep[2][1] = sqrt(3.0) * z; + Gz_dep[2][1] = sqrt(3.0); + + zdep[2][2] = sqrt(3.0) * 0.5; + } + else if(il == 3) + { + zdep[3][0] = 2.5 * z3 - 1.5 * z * r2; + Gx_dep[3][0] = -3.0 * x * z; + Gy_dep[3][0] = -3.0 * y * z; + Gz_dep[3][0] = 1.5 * (3.0 * z2 - r2); + + zdep[3][1] = 0.25 * sqrt(6.0) * (5.0 * z2 - r2); + Gx_dep[3][1] = -0.5 * sqrt(6.0) * x; + Gy_dep[3][1] = -0.5 * sqrt(6.0) * y; + Gz_dep[3][1] = sqrt(6.0) * 2.0 * z; + + zdep[3][2] = 0.5 * sqrt(15.0) * z; + Gz_dep[3][2] = 0.5 * sqrt(15.0); + + zdep[3][3] = 0.25 * sqrt(10.0); + } + else if(il == 4) + { + zdep[4][0] = 0.125 * (35.0 * z4 - 30.0 * r2 * z2 + 3.0 * r4); + Gx_dep[4][0] = -7.5 * x * z2 + 1.5 * x * r2; + Gy_dep[4][0] = -7.5 * y * z2 + 1.5 * y * r2; + Gz_dep[4][0] = 10.0 * z3 - 6.0 * r2 * z; + + zdep[4][1] = sqrt(10.0) * 0.25 * z * (7.0 * z2 - 3.0 * r2); + Gx_dep[4][1] = -1.5 * sqrt(10.0) * x * z; + Gy_dep[4][1] = -1.5 * sqrt(10.0) * y * z; + Gz_dep[4][1] = 0.75 * sqrt(10.0) * (5.0 * z2 - r2); + + zdep[4][2] = sqrt(5.0) * 0.25 * (7.0 * z2 - r2); + Gx_dep[4][2] = -0.5 * sqrt(5.0) * x; + Gy_dep[4][2] = -0.5 * sqrt(5.0) * y; + Gz_dep[4][2] = 3.0 * sqrt(5.0) * z; + + zdep[4][3] = sqrt(70.0) * 0.25 * z; + Gz_dep[4][3] = 0.25 * sqrt(70.0); + + zdep[4][4] = sqrt(35.0) * 0.125; + } + else if(il == 5) + { + zdep[5][0] = 0.125 * z *( 63.0 * z4 - 70.0 * z2 * r2 + 15.0 * r4); + Gx_dep[5][0] = -17.5 * x * z3 + 7.5 * x * z * r2; + Gy_dep[5][0] = -17.5 * y * z3 + 7.5 * y * z * r2; + Gz_dep[5][0] = 175.0 * 0.125 * z4 + 15.0 * 0.125 * r4 - 150.0 * 0.125 * r2 * z2; + + zdep[5][1] = 0.125 * sqrt(15.0) * (21.0 * z4 - 14.0 * z2 * r2 + r4); + Gx_dep[5][1] = -3.5 * sqrt(15.0) * x * z2 + 0.5 * sqrt(15.0) * x * r2; + Gy_dep[5][1] = -3.5 * sqrt(15.0) * y * z2 + 0.5 * sqrt(15.0) * y * r2; + Gz_dep[5][1] = 7.0 * sqrt(15.0) * z3 - 3.0 * sqrt(15.0) * r2 * z; + + zdep[5][2] = 0.25 * sqrt(105.0) * z * (3.0 * z2 - r2); + Gx_dep[5][2] = -0.5 * sqrt(105.0) * x * z; + Gy_dep[5][2] = -0.5 * sqrt(105.0) * y * z; + Gz_dep[5][2] = 0.25 * sqrt(105.0) * (7.0 * z2 - r2); + + zdep[5][3] = 0.0625 * sqrt(70.0) * (9.0 * z2 - r2); + Gx_dep[5][3] = -0.125 * sqrt(70.0) * x; + Gy_dep[5][3] = -0.125 * sqrt(70.0) * y; + Gz_dep[5][3] = sqrt(70.0) * z; + + zdep[5][4] = 0.375 * sqrt(35.0) * z; + Gz_dep[5][4] = 0.375 * sqrt(35.0); + + zdep[5][5] = 0.1875 * sqrt(14.0); + } + else + { + for(int im = 0; im <= il; im++) + { + int kmax = static_cast( (il - im) / 2 ); + for(int ik = 0; ik <= kmax; ik++) + { + int twok = 2 * ik; + + double gamma = 0.0; + double aux0, aux1, aux2, aux3; + + aux0 = pow(-1.0, ik) * pow(2.0, -il); + aux1 = Fact(il) / Fact(ik) / Fact(il-ik); + aux2 = Fact(2*il - twok) / Fact(il) / Fact(il - twok); + aux3 = Fact(il - twok) / Fact(il - twok - im); + + gamma = aux0 * aux1 * aux2 * aux3; + + assert(il - twok - im >= 0); + zdep[il][im] += pow(r, twok) * pow(z, il-twok-im) * gamma; + + if(ik > 0) + { + Gx_dep[il][im] += (ik * pow(r2, ik-1) * 2.0 * x) * pow(z, il-twok-im) * gamma; + Gy_dep[il][im] += (ik * pow(r2, ik-1) * 2.0 * y) * pow(z, il-twok-im) * gamma; + } + + if(ik == 0) + { + if(il > im) + { + Gz_dep[il][im] += (il-im) * pow(z, il-im-1) * gamma; + } + } + else + { + if(il - twok - im == 0) + { + Gz_dep[il][im] += gamma * ik * pow(r2, ik-1) * 2.0 * z; + } + else + { + Gz_dep[il][im] += gamma * (ik * pow(r2, ik-1) * 2.0 * z * pow(z, il-twok-im) + + pow(r, twok) * (il-twok-im) * pow(z, il-twok-im-1)); + } + } + } + + if(im >= 1) + { + zdep[il][im] *= sqrt(2 * Fact(il - im) / Fact(il + im)); + Gx_dep[il][im] *= sqrt(2 * Fact(il - im) / Fact(il + im)); + Gy_dep[il][im] *= sqrt(2 * Fact(il - im) / Fact(il + im)); + Gz_dep[il][im] *= sqrt(2 * Fact(il - im) / Fact(il + im)); + + } + } + } + } + + //calc + int ic = 0; + for(int il = 0; il <= MaxL; il++) + { + double fac = sqrt( (2.0 * il + 1.0) / ModuleBase::FOUR_PI ); + + //m=0 + rly[ic] = Am[0] * zdep[il][0] * fac; + grly[ic][0] = (Gx_dep[il][0] * Am[0] + zdep[il][0] * Gx_Am[0]) * fac; + grly[ic][1] = (Gy_dep[il][0] * Am[0] + zdep[il][0] * Gy_Am[0]) * fac; + grly[ic][2] = Gz_dep[il][0] * Am[0] * fac; + + ic++; + + //m ! = 0 + for(int im = 1; im <= il; im++) + { + //m>0 + rly[ic] = Am[im] * zdep[il][im] * pow(-1.0, im) * fac; + grly[ic][0] = (Gx_dep[il][im] * Am[im] + zdep[il][im] * Gx_Am[im]) * pow(-1.0, im) * fac; + grly[ic][1] = (Gy_dep[il][im] * Am[im] + zdep[il][im] * Gy_Am[im]) * pow(-1.0, im) * fac; + grly[ic][2] = Gz_dep[il][im] * Am[im] * pow(-1.0, im) * fac; + + ic++; + + //m<0 + rly[ic] = Bm[im] * zdep[il][im] * pow(-1.0, im) * fac; + grly[ic][0] = (Gx_dep[il][im] * Bm[im] + zdep[il][im] * Gx_Bm[im]) * pow(-1.0, im) * fac; + grly[ic][1] = (Gy_dep[il][im] * Bm[im] + zdep[il][im] * Gy_Bm[im]) * pow(-1.0, im) * fac; + grly[ic][2] = Gz_dep[il][im] * Bm[im] * pow(-1.0, im) * fac; + + ic++; + } + } + + return; } /* void Ylm::test(void) { - ModuleBase::Vector3 R(0.0, 0.0, 1.0); - - double r,r2,r3,r4,r5,r6,r7; - r = R.norm(); - r2 = r * r; - r3 = r2 * r; - r4 = r3 * r; - r5 = r4 * r; - r6 = r5 * r; - r7 = r6 * r; - - //Max L = 7; - double ylm[64]; - double dylmdr[64][3]; - - double rly[64]; - double grly[64][3]; + ModuleBase::Vector3 R(0.0, 0.0, 1.0); + + double r,r2,r3,r4,r5,r6,r7; + r = R.norm(); + r2 = r * r; + r3 = r2 * r; + r4 = r3 * r; + r5 = r4 * r; + r6 = r5 * r; + r7 = r6 * r; + + //Max L = 7; + double ylm[64]; + double dylmdr[64][3]; + + double rly[64]; + double grly[64][3]; // std::cout << R.x << " " << R.y << " " << R.z << std::endl; - get_ylm_real(8, R, ylm, dylmdr); - rlylm(8, R.x, R.y, R.z, rly, grly); + get_ylm_real(8, R, ylm, dylmdr); + rlylm(8, R.x, R.y, R.z, rly, grly); // std::cout << R.x << " " << R.y << " " << R.z << std::endl; - for(int i = 0; i < 64; i++) - { - if(i >= 1 && i <= 3) - { - dylmdr[i][0] = dylmdr[i][0] * r + ylm[i] * R.x / r; - dylmdr[i][1] = dylmdr[i][1] * r + ylm[i] * R.y / r; - dylmdr[i][2] = dylmdr[i][2] * r + ylm[i] * R.z / r; - - ylm[i] *= r; - } - if(i >= 4 && i <= 8) - { - dylmdr[i][0] = dylmdr[i][0] * r2 + ylm[i] * R.x * 2.0; - dylmdr[i][1] = dylmdr[i][1] * r2 + ylm[i] * R.y * 2.0; - dylmdr[i][2] = dylmdr[i][2] * r2 + ylm[i] * R.z * 2.0; - - ylm[i] *= r2; - } - if(i >= 9 && i <= 15) - { - dylmdr[i][0] = dylmdr[i][0] * r3 + ylm[i] * R.x * 3.0 * r; - dylmdr[i][1] = dylmdr[i][1] * r3 + ylm[i] * R.y * 3.0 * r; - dylmdr[i][2] = dylmdr[i][2] * r3 + ylm[i] * R.z * 3.0 * r; - - ylm[i] *= pow(R.norm(),3); - } - if(i >= 16 && i <=24) - { - dylmdr[i][0] = dylmdr[i][0] * r4 + ylm[i] * R.x * 4.0 * r2; - dylmdr[i][1] = dylmdr[i][1] * r4 + ylm[i] * R.y * 4.0 * r2; - dylmdr[i][2] = dylmdr[i][2] * r4 + ylm[i] * R.z * 4.0 * r2; - - ylm[i] *= pow(R.norm(), 4); - } - if(i >= 25 && i <= 35) - { - dylmdr[i][0] = dylmdr[i][0] * r5 + ylm[i] * R.x * 5.0 * r3; - dylmdr[i][1] = dylmdr[i][1] * r5 + ylm[i] * R.y * 5.0 * r3; - dylmdr[i][2] = dylmdr[i][2] * r5 + ylm[i] * R.z * 5.0 * r3; - - ylm[i] *= pow(R.norm(), 5); - } - if(i >= 36 && i <= 48) - { - dylmdr[i][0] = dylmdr[i][0] * r6 + ylm[i] * R.x * 6.0 * r4; - dylmdr[i][1] = dylmdr[i][1] * r6 + ylm[i] * R.y * 6.0 * r4; - dylmdr[i][2] = dylmdr[i][2] * r6 + ylm[i] * R.z * 6.0 * r4; - ylm[i] *= pow(R.norm(), 6); - } - if(i >= 49 && i <= 63) - { - dylmdr[i][0] = dylmdr[i][0] * r7 + ylm[i] * R.x * 7.0 * r5; - dylmdr[i][1] = dylmdr[i][1] * r7 + ylm[i] * R.y * 7.0 * r5; - dylmdr[i][2] = dylmdr[i][2] * r7 + ylm[i] * R.z * 7.0 * r5; - ylm[i] *= pow(R.norm(), 7); - } - - std::cout << grly[i][0] << std::setw(20) << grly[i][1] << std::setw(20) << grly[i][2] << std::endl; - } - - return; + for(int i = 0; i < 64; i++) + { + if(i >= 1 && i <= 3) + { + dylmdr[i][0] = dylmdr[i][0] * r + ylm[i] * R.x / r; + dylmdr[i][1] = dylmdr[i][1] * r + ylm[i] * R.y / r; + dylmdr[i][2] = dylmdr[i][2] * r + ylm[i] * R.z / r; + + ylm[i] *= r; + } + if(i >= 4 && i <= 8) + { + dylmdr[i][0] = dylmdr[i][0] * r2 + ylm[i] * R.x * 2.0; + dylmdr[i][1] = dylmdr[i][1] * r2 + ylm[i] * R.y * 2.0; + dylmdr[i][2] = dylmdr[i][2] * r2 + ylm[i] * R.z * 2.0; + + ylm[i] *= r2; + } + if(i >= 9 && i <= 15) + { + dylmdr[i][0] = dylmdr[i][0] * r3 + ylm[i] * R.x * 3.0 * r; + dylmdr[i][1] = dylmdr[i][1] * r3 + ylm[i] * R.y * 3.0 * r; + dylmdr[i][2] = dylmdr[i][2] * r3 + ylm[i] * R.z * 3.0 * r; + + ylm[i] *= pow(R.norm(),3); + } + if(i >= 16 && i <=24) + { + dylmdr[i][0] = dylmdr[i][0] * r4 + ylm[i] * R.x * 4.0 * r2; + dylmdr[i][1] = dylmdr[i][1] * r4 + ylm[i] * R.y * 4.0 * r2; + dylmdr[i][2] = dylmdr[i][2] * r4 + ylm[i] * R.z * 4.0 * r2; + + ylm[i] *= pow(R.norm(), 4); + } + if(i >= 25 && i <= 35) + { + dylmdr[i][0] = dylmdr[i][0] * r5 + ylm[i] * R.x * 5.0 * r3; + dylmdr[i][1] = dylmdr[i][1] * r5 + ylm[i] * R.y * 5.0 * r3; + dylmdr[i][2] = dylmdr[i][2] * r5 + ylm[i] * R.z * 5.0 * r3; + + ylm[i] *= pow(R.norm(), 5); + } + if(i >= 36 && i <= 48) + { + dylmdr[i][0] = dylmdr[i][0] * r6 + ylm[i] * R.x * 6.0 * r4; + dylmdr[i][1] = dylmdr[i][1] * r6 + ylm[i] * R.y * 6.0 * r4; + dylmdr[i][2] = dylmdr[i][2] * r6 + ylm[i] * R.z * 6.0 * r4; + ylm[i] *= pow(R.norm(), 6); + } + if(i >= 49 && i <= 63) + { + dylmdr[i][0] = dylmdr[i][0] * r7 + ylm[i] * R.x * 7.0 * r5; + dylmdr[i][1] = dylmdr[i][1] * r7 + ylm[i] * R.y * 7.0 * r5; + dylmdr[i][2] = dylmdr[i][2] * r7 + ylm[i] * R.z * 7.0 * r5; + ylm[i] *= pow(R.norm(), 7); + } + + std::cout << grly[i][0] << std::setw(20) << grly[i][1] << std::setw(20) << grly[i][2] << std::endl; + } + + return; } */ void Ylm::ZEROS(double u[], const int& n) { - for(int i = 0; i < n; i++) - { - u[i] = 0.0; - } - return; + for(int i = 0; i < n; i++) + { + u[i] = 0.0; + } + return; } @@ -2029,31 +2029,31 @@ void Ylm::ZEROS(double u[], const int& n) //========================================================== long double Ylm::Fact(const int n) { - long double f = 1; - for(int i=n; i>1; i--) - { - f *= i; - } - return f; + long double f = 1; + for(int i=n; i>1; i--) + { + f *= i; + } + return f; } int Ylm::Semi_Fact(const int n) { - int semif = 1; - for(int i=n; i>2; i -= 2) - { - semif *= i; - } - return semif; + int semif = 1; + for(int i=n; i>2; i -= 2) + { + semif *= i; + } + return semif; } double Ylm::sgn(const double x) { - if(x < 0.0) return -1.0; - if(x > 0.0) return 1.0; - return 0.0; + if(x < 0.0) return -1.0; + if(x > 0.0) return 1.0; + return 0.0; } } diff --git a/source/source_base/ylm.h b/source/source_base/ylm.h index ff25a56a912..45a0d0baec7 100644 --- a/source/source_base/ylm.h +++ b/source/source_base/ylm.h @@ -10,157 +10,157 @@ namespace ModuleBase class Ylm { - public: - Ylm(){}; - ~Ylm(){}; - - static int nlm; - - - /** - * @brief Get the ylm real object - * - * @param Lmax [in] maximum angular quantum number + 1 - * @param vec [in] the vector to be calculated - * @param ylmr [out] calculated Ylm, Y00, Y10, Y11, Y1-1, Y20, Y21, Y2-1, Y22, Y2-2... - */ - static void get_ylm_real( - const int &Lmax , - const ModuleBase::Vector3 &vec, - double ylmr[]); - - /** - * @brief Get the ylm real object and the gradient - * - * @param Lmax [in] maximum angular quantum number + l - * @param vec [in] the vector to be calculated - * @param ylmr [out] calculated Ylm, Y00, Y10, Y11, Y1-1, Y20, Y21, Y2-1, Y22, Y2-2... - * @param dylmdr [out] gradient of Ylm, [dY00/dx, dY00/dy, dY00/dz], [dY10/dx, dY10/dy, dY10/dz], [dY11/dx, dY11/dy, dY11/dz],... - */ - static void get_ylm_real( - const int &Lmax , - const ModuleBase::Vector3 &vec, - double ylmr[], - double dylmdr[][3]); - - /** - * @brief Get the ylm real (solid) object (not used anymore) - * - * @param Lmax [in] maximum angular quantum number + l - * @param x [in] x - * @param y [in] y - * @param z [in] z - * @param rly [in] calculated Ylm, Y00, Y10, Y11, Y1-1, Y20, Y21, Y2-1, Y22, Y2-2... - */ - static void rlylm( - const int Lmax, - const double x, - const double y, - const double z, - double rly[]); - - /** - * @brief Get the ylm real (solid) object and the gradient (not used anymore) - * - * @param Lmax [in] maximum angular quantum number + 1 - * @param x [in] x - * @param y [in] y - * @param z [in] z - * @param rly [in] calculated Ylm, Y00, Y10, Y11, Y1-1, Y20, Y21, Y2-1, Y22, Y2-2... - * @param grly [out] gradient of Ylm, [dY00/dx, dY00/dy, dY00/dz], [dY10/dx, dY10/dy, dY10/dz], [dY11/dx, dY11/dy, dY11/dz],... - */ - static void rlylm( - const int Lmax, - const double x, - const double y, - const double z, - double rly[], - double grly[][3]); - - /** - * @brief Get the ylm real object (used in grid integration) - * - * @param Lmax [in] maximum angular quantum number - * @param xdr [in] x/r - * @param ydr [in] y/r - * @param zdr [in] z/r - * @param rly [in] calculated Ylm, Y00, Y10, Y11, Y1-1, Y20, Y21, Y2-1, Y22, Y2-2... - */ - static void sph_harm( - const int Lmax, - const double xdr, - const double ydr, - const double zdr, - std::vector &rly); - - /** - * @brief Get the ylm real object (used in getting overlap) - * - * @param Lmax [in] maximum angular quantum number - * @param x [in] x/r - * @param y [in] y/r - * @param z [in] z/r - * @param rly [in] calculated Ylm, Y00, Y10, Y11, Y1-1, Y20, Y21, Y2-1, Y22, Y2-2... - * @author Peize Lin - * @date 2016-08-26 - */ - static void rl_sph_harm( - const int Lmax, - const double x, - const double y, - const double z, - std::vector& rly); - - /** - * @brief Get the ylm real object and the gradient (used in getting derivative of overlap) - * - * @param Lmax [in] maximum angular quantum number - * @param x [in] x/r - * @param y [in] y/r - * @param z [in] z/r - * @param rly [in] calculated Ylm, Y00, Y10, Y11, Y1-1, Y20, Y21, Y2-1, Y22, Y2-2... - * @param grly [out] gradient of Ylm, stored as a contiguous flat array of - * size (Lmax+1)^2 * 3 in row-major order: - * [dY00/dx, dY00/dy, dY00/dz, dY10/dx, dY10/dy, dY10/dz, ...] - */ - static void grad_rl_sph_harm( - const int Lmax, - const double x, - const double y, - const double z, - double* rly, - double* grly); - - /** - * @brief Get the hessian of r^l Ylm (used in getting derivative of overlap) - * - * @param Lmax [in] maximum angular quantum number - * @param x [in] x - * @param y [in] y - * @param z [in] z - * @param hrly [out] hessian of Ylm, [dY00/dx2, dY00/dxy, dY00/dxz, dY00/dyy, dY00/dyz, dY00/dzz] , ... - */ - static void hes_rl_sph_harm( - const int Lmax, - const double x, - const double y, - const double z, - std::vector>& hrly); - - //calculate the coefficient of Ylm, ylmcoef. - static void set_coefficients (); - - //static void test(); - //static void test1(); - //static void test2(); - - //set the first n elements of u to be 0.0 - static void ZEROS(double u[], const int& n); - - private: - static long double Fact(const int n); - static int Semi_Fact(const int n); - static double sgn(const double x); + public: + Ylm(){}; + ~Ylm(){}; + + static int nlm; + + + /** + * @brief Get the ylm real object + * + * @param Lmax [in] maximum angular quantum number + 1 + * @param vec [in] the vector to be calculated + * @param ylmr [out] calculated Ylm, Y00, Y10, Y11, Y1-1, Y20, Y21, Y2-1, Y22, Y2-2... + */ + static void get_ylm_real( + const int &Lmax , + const ModuleBase::Vector3 &vec, + double ylmr[]); + + /** + * @brief Get the ylm real object and the gradient + * + * @param Lmax [in] maximum angular quantum number + l + * @param vec [in] the vector to be calculated + * @param ylmr [out] calculated Ylm, Y00, Y10, Y11, Y1-1, Y20, Y21, Y2-1, Y22, Y2-2... + * @param dylmdr [out] gradient of Ylm, [dY00/dx, dY00/dy, dY00/dz], [dY10/dx, dY10/dy, dY10/dz], [dY11/dx, dY11/dy, dY11/dz],... + */ + static void get_ylm_real( + const int &Lmax , + const ModuleBase::Vector3 &vec, + double ylmr[], + double dylmdr[][3]); + + /** + * @brief Get the ylm real (solid) object (not used anymore) + * + * @param Lmax [in] maximum angular quantum number + l + * @param x [in] x + * @param y [in] y + * @param z [in] z + * @param rly [in] calculated Ylm, Y00, Y10, Y11, Y1-1, Y20, Y21, Y2-1, Y22, Y2-2... + */ + static void rlylm( + const int Lmax, + const double x, + const double y, + const double z, + double rly[]); + + /** + * @brief Get the ylm real (solid) object and the gradient (not used anymore) + * + * @param Lmax [in] maximum angular quantum number + 1 + * @param x [in] x + * @param y [in] y + * @param z [in] z + * @param rly [in] calculated Ylm, Y00, Y10, Y11, Y1-1, Y20, Y21, Y2-1, Y22, Y2-2... + * @param grly [out] gradient of Ylm, [dY00/dx, dY00/dy, dY00/dz], [dY10/dx, dY10/dy, dY10/dz], [dY11/dx, dY11/dy, dY11/dz],... + */ + static void rlylm( + const int Lmax, + const double x, + const double y, + const double z, + double rly[], + double grly[][3]); + + /** + * @brief Get the ylm real object (used in grid integration) + * + * @param Lmax [in] maximum angular quantum number + * @param xdr [in] x/r + * @param ydr [in] y/r + * @param zdr [in] z/r + * @param rly [in] calculated Ylm, Y00, Y10, Y11, Y1-1, Y20, Y21, Y2-1, Y22, Y2-2... + */ + static void sph_harm( + const int Lmax, + const double xdr, + const double ydr, + const double zdr, + std::vector &rly); + + /** + * @brief Get the ylm real object (used in getting overlap) + * + * @param Lmax [in] maximum angular quantum number + * @param x [in] x/r + * @param y [in] y/r + * @param z [in] z/r + * @param rly [in] calculated Ylm, Y00, Y10, Y11, Y1-1, Y20, Y21, Y2-1, Y22, Y2-2... + * @author Peize Lin + * @date 2016-08-26 + */ + static void rl_sph_harm( + const int Lmax, + const double x, + const double y, + const double z, + std::vector& rly); + + /** + * @brief Get the ylm real object and the gradient (used in getting derivative of overlap) + * + * @param Lmax [in] maximum angular quantum number + * @param x [in] x/r + * @param y [in] y/r + * @param z [in] z/r + * @param rly [in] calculated Ylm, Y00, Y10, Y11, Y1-1, Y20, Y21, Y2-1, Y22, Y2-2... + * @param grly [out] gradient of Ylm, stored as a contiguous flat array of + * size (Lmax+1)^2 * 3 in row-major order: + * [dY00/dx, dY00/dy, dY00/dz, dY10/dx, dY10/dy, dY10/dz, ...] + */ + static void grad_rl_sph_harm( + const int Lmax, + const double x, + const double y, + const double z, + double* rly, + double* grly); + + /** + * @brief Get the hessian of r^l Ylm (used in getting derivative of overlap) + * + * @param Lmax [in] maximum angular quantum number + * @param x [in] x + * @param y [in] y + * @param z [in] z + * @param hrly [out] hessian of Ylm, [dY00/dx2, dY00/dxy, dY00/dxz, dY00/dyy, dY00/dyz, dY00/dzz] , ... + */ + static void hes_rl_sph_harm( + const int Lmax, + const double x, + const double y, + const double z, + std::vector>& hrly); + + //calculate the coefficient of Ylm, ylmcoef. + static void set_coefficients (); + + //static void test(); + //static void test1(); + //static void test2(); + + //set the first n elements of u to be 0.0 + static void ZEROS(double u[], const int& n); + + private: + static long double Fact(const int n); + static int Semi_Fact(const int n); + static double sgn(const double x); }; } diff --git a/source/source_basis/module_ao/elem_basis_idx_orb.cpp b/source/source_basis/module_ao/elem_basis_idx_orb.cpp index a05da56f4f8..c3a441cf2a1 100644 --- a/source/source_basis/module_ao/elem_basis_idx_orb.cpp +++ b/source/source_basis/module_ao/elem_basis_idx_orb.cpp @@ -9,36 +9,36 @@ namespace ModuleBase ModuleBase::Element_Basis_Index::Range Element_Basis_Index::construct_range( const LCAO_Orbitals &orb ) { - ModuleBase::Element_Basis_Index::Range range; - range.resize( orb.get_ntype() ); - for( std::size_t T=0; T!=range.size(); ++T ) - { - range[T].resize( orb.Phi[T].getLmax()+1 ); - for( std::size_t L=0; L!=range[T].size(); ++L ) - { - range[T][L].N = orb.Phi[T].getNchi(L); - range[T][L].M = 2*L+1; - } - } - return range; + ModuleBase::Element_Basis_Index::Range range; + range.resize( orb.get_ntype() ); + for( std::size_t T=0; T!=range.size(); ++T ) + { + range[T].resize( orb.Phi[T].getLmax()+1 ); + for( std::size_t L=0; L!=range[T].size(); ++L ) + { + range[T][L].N = orb.Phi[T].getNchi(L); + range[T][L].M = 2*L+1; + } + } + return range; } ModuleBase::Element_Basis_Index::Range Element_Basis_Index::construct_range( const std::vector>> &orb ) { - ModuleBase::Element_Basis_Index::Range range; - range.resize( orb.size() ); - for( std::size_t T=0; T!=range.size(); ++T ) - { - range[T].resize( orb[T].size() ); - for( std::size_t L=0; L!=range[T].size(); ++L ) - { - range[T][L].N = orb[T][L].size(); - range[T][L].M = 2*L+1; - } - } - return range; + ModuleBase::Element_Basis_Index::Range range; + range.resize( orb.size() ); + for( std::size_t T=0; T!=range.size(); ++T ) + { + range[T].resize( orb[T].size() ); + for( std::size_t L=0; L!=range[T].size(); ++L ) + { + range[T][L].N = orb[T][L].size(); + range[T][L].M = 2*L+1; + } + } + return range; } } \ No newline at end of file diff --git a/source/source_basis/module_ao/elem_basis_idx_orb.h b/source/source_basis/module_ao/elem_basis_idx_orb.h index 7da100183ea..93468abc898 100644 --- a/source/source_basis/module_ao/elem_basis_idx_orb.h +++ b/source/source_basis/module_ao/elem_basis_idx_orb.h @@ -4,17 +4,17 @@ #include "../../source_base/element_basis_index.h" #include - class Numerical_Orbital_Lm; - class LCAO_Orbitals; + class Numerical_Orbital_Lm; + class LCAO_Orbitals; namespace ModuleBase { namespace Element_Basis_Index { - extern Range construct_range( const LCAO_Orbitals &orb ); + extern Range construct_range( const LCAO_Orbitals &orb ); - extern Range construct_range( const std::vector>> &orb ); // orb[T][L][N] + extern Range construct_range( const std::vector>> &orb ); // orb[T][L][N] } } diff --git a/source/source_basis/module_ao/orb_atomic.h b/source/source_basis/module_ao/orb_atomic.h index 4dea9ef3384..7905f3bdb89 100644 --- a/source/source_basis/module_ao/orb_atomic.h +++ b/source/source_basis/module_ao/orb_atomic.h @@ -10,34 +10,34 @@ class Numerical_Orbital_AtomRelation { public: - //========================================================== - // It's about two atoms relations, thread-safe interface - //========================================================== - double distance; - ModuleBase::Vector3 R1; - ModuleBase::Vector3 R2; //three-dimesion-coordinate of R - ModuleBase::Vector3 dR; // R1-R2 + //========================================================== + // It's about two atoms relations, thread-safe interface + //========================================================== + double distance; + ModuleBase::Vector3 R1; + ModuleBase::Vector3 R2; //three-dimesion-coordinate of R + ModuleBase::Vector3 dR; // R1-R2 - double& get_distance() - { - if(distance < 0.0) ModuleBase::WARNING_QUIT("NUMERICAL_ORBITAL","distance should be above zero!"); - return distance; - } - - double getX() { return R2.x - R1.x ; } - double getY() { return R2.y - R1.y ; } - double getZ() { return R2.z - R1.z ; } - ModuleBase::Vector3& getR1() { return R1; } - ModuleBase::Vector3& getR2() { return R2; } - ModuleBase::Vector3& getdR() { return dR; } + double& get_distance() + { + if(distance < 0.0) ModuleBase::WARNING_QUIT("NUMERICAL_ORBITAL","distance should be above zero!"); + return distance; + } + + double getX() { return R2.x - R1.x ; } + double getY() { return R2.y - R1.y ; } + double getZ() { return R2.z - R1.z ; } + ModuleBase::Vector3& getR1() { return R1; } + ModuleBase::Vector3& getR2() { return R2; } + ModuleBase::Vector3& getdR() { return dR; } - void set_position(const ModuleBase::Vector3 &R1_in, const ModuleBase::Vector3 &R2_in) - { - R1 = R1_in; - R2 = R2_in; - dR = R1-R2; - distance = dR.norm(); - } + void set_position(const ModuleBase::Vector3 &R1_in, const ModuleBase::Vector3 &R2_in) + { + R1 = R1_in; + R2 = R2_in; + dR = R1-R2; + distance = dR.norm(); + } }; /// @@ -50,82 +50,82 @@ class Numerical_Orbital_AtomRelation /// class Numerical_Orbital { - friend class LCAO_Orbitals; + friend class LCAO_Orbitals; public: - Numerical_Orbital(); - ~Numerical_Orbital(); + Numerical_Orbital(); + ~Numerical_Orbital(); - const int& getLmax() const { return this->lmax; } - const double& getRcut () const {return this->rcut; } - const int& getType() const { return this->type; } - const int& getTotal_nchi() const { return this->total_nchi; } - const int& getNchi(const int l) const { return this->nchi[l]; } - const std::string& getLabel() const { return this->label; } - - const inline Numerical_Orbital_Lm& PhiLN( const int &L, const int &N)const - { - return this->phiLN[ this->find_chi(L, N) ]; - } - - /// about the distance between two atoms. - static double& get_distance() - { - return NOAR.get_distance(); - } - - static double getX() { return NOAR.getX() ; } - static double getY() { return NOAR.getY() ; } - static double getZ() { return NOAR.getZ() ; } - static ModuleBase::Vector3& getR1() { return NOAR.getR1(); } - static ModuleBase::Vector3& getR2() { return NOAR.getR2(); } - static ModuleBase::Vector3& getdR() { return NOAR.getdR(); } + const int& getLmax() const { return this->lmax; } + const double& getRcut () const {return this->rcut; } + const int& getType() const { return this->type; } + const int& getTotal_nchi() const { return this->total_nchi; } + const int& getNchi(const int l) const { return this->nchi[l]; } + const std::string& getLabel() const { return this->label; } + + const inline Numerical_Orbital_Lm& PhiLN( const int &L, const int &N)const + { + return this->phiLN[ this->find_chi(L, N) ]; + } + + /// about the distance between two atoms. + static double& get_distance() + { + return NOAR.get_distance(); + } + + static double getX() { return NOAR.getX() ; } + static double getY() { return NOAR.getY() ; } + static double getZ() { return NOAR.getZ() ; } + static ModuleBase::Vector3& getR1() { return NOAR.getR1(); } + static ModuleBase::Vector3& getR2() { return NOAR.getR2(); } + static ModuleBase::Vector3& getdR() { return NOAR.getdR(); } - /// - /// set information about Numerical Orbital - /// - void set_orbital_info( - const int& type_in, - const std::string& label_in, - const int& lmax_in, - const int* nchi_in, - const int& total_nchi); + /// + /// set information about Numerical Orbital + /// + void set_orbital_info( + const int& type_in, + const std::string& label_in, + const int& lmax_in, + const int* nchi_in, + const int& total_nchi); - static void set_position(const ModuleBase::Vector3 &R1_in, const ModuleBase::Vector3 &R2_in) - { - NOAR.set_position(R1_in, R2_in); - } + static void set_position(const ModuleBase::Vector3 &R1_in, const ModuleBase::Vector3 &R2_in) + { + NOAR.set_position(R1_in, R2_in); + } - std::vector& chi() { return this->phiLN; } - + std::vector& chi() { return this->phiLN; } + private: - - //========================================================== - // MEMBER FUNCTION : - // NAME : label (atom type) - // NAME : lmax( max value of L angular momentum) - // NAME : nchi( number of chi for each L) - // NAME : total_nchi(total chi for this type of atom, total number of NAOs) - // NAME : max_nchi( max chi for certain L) - // NAME : find_chi(lmax+1, max_nchi). - //=========================================================== - std::string label; - - int type; - int lmax; - std::vector nchi; - int total_nchi; - int max_nchi; - ModuleBase::IntArray find_chi; - double rcut; + + //========================================================== + // MEMBER FUNCTION : + // NAME : label (atom type) + // NAME : lmax( max value of L angular momentum) + // NAME : nchi( number of chi for each L) + // NAME : total_nchi(total chi for this type of atom, total number of NAOs) + // NAME : max_nchi( max chi for certain L) + // NAME : find_chi(lmax+1, max_nchi). + //=========================================================== + std::string label; + + int type; + int lmax; + std::vector nchi; + int total_nchi; + int max_nchi; + ModuleBase::IntArray find_chi; + double rcut; - std::vector phiLN;// length: total_nchi (only store radial function ) + std::vector phiLN;// length: total_nchi (only store radial function ) - //========================================================== - // Keep the old interface - //========================================================== - static Numerical_Orbital_AtomRelation NOAR; + //========================================================== + // Keep the old interface + //========================================================== + static Numerical_Orbital_AtomRelation NOAR; }; #endif diff --git a/source/source_basis/module_ao/orb_atomic_lm.cpp b/source/source_basis/module_ao/orb_atomic_lm.cpp index 1ebd3e043c5..9d5e40a8612 100644 --- a/source/source_basis/module_ao/orb_atomic_lm.cpp +++ b/source/source_basis/module_ao/orb_atomic_lm.cpp @@ -14,21 +14,21 @@ Numerical_Orbital_Lm::Numerical_Orbital_Lm() { - label = ""; - index_atom_type = 0; - angular_momentum_l = 0; - index_chi = 0; + label = ""; + index_atom_type = 0; + angular_momentum_l = 0; + index_chi = 0; - nr=1; - nk=1; + nr=1; + nk=1; - rcut=0.0; - kcut=0.0; - dk=0.0; + rcut=0.0; + kcut=0.0; + dk=0.0; - nr_uniform = 1; - dr_uniform = -1.0; - zty = 0.0; + nr_uniform = 1; + dr_uniform = -1.0; + zty = 0.0; } Numerical_Orbital_Lm::~Numerical_Orbital_Lm() @@ -36,140 +36,140 @@ Numerical_Orbital_Lm::~Numerical_Orbital_Lm() void Numerical_Orbital_Lm::set_orbital_info ( - const std::string &label_in, - const int &index_atom_type_in, - const int &angular_momentum_l_in, - const int &index_chi_in, - const int &nr_in, - const double *rab_in, - const double *r_radial_in, - const Psi_Type &psi_type, // Peize Lin add 2017-12-12 - const double *psi_in, - const int &nk_in, - const double &dk_in, - // Peize Lin delete lat0 2016-02-03 - const double &dr_uniform_in, - bool flag_plot, // Peize Lin add flag_plot 2016-08-31 - bool flag_sbpool, // Peize Lin add flag_sbpool 2017-10-02 - const bool &force_flag // mohan add 2021-05-07 + const std::string &label_in, + const int &index_atom_type_in, + const int &angular_momentum_l_in, + const int &index_chi_in, + const int &nr_in, + const double *rab_in, + const double *r_radial_in, + const Psi_Type &psi_type, // Peize Lin add 2017-12-12 + const double *psi_in, + const int &nk_in, + const double &dk_in, + // Peize Lin delete lat0 2016-02-03 + const double &dr_uniform_in, + bool flag_plot, // Peize Lin add flag_plot 2016-08-31 + bool flag_sbpool, // Peize Lin add flag_sbpool 2017-10-02 + const bool &force_flag // mohan add 2021-05-07 ) { - copy_parameter( - label_in, - index_atom_type_in, - angular_momentum_l_in, - index_chi_in, - nr_in, - rab_in, - r_radial_in, - nk_in, - dk_in, - dr_uniform_in); - - switch(psi_type) - { - case Psi_Type::Psi: - for (int ir = 0; ir < nr; ir++) - { - this->psi[ir] = psi_in[ir]; - this->psir[ir] = psi[ir] * r_radial[ir]; //mohan 2010-04-19 - } - break; - case Psi_Type::Psif: - for( int ik=0; ik!=nk; ++ik ) - { - this->psif[ik] = psi_in[ik]; - this->psik[ik] = psif[ik] * k_radial[ik]; - this->psik2[ik] = psik[ik] * k_radial[ik]; - } - break; - case Psi_Type::Psik: - psif.resize(0); - for( int ik=0; ik!=nk; ++ik ) - { - this->psik[ik] = psi_in[ik]; - this->psik2[ik] = psik[ik] * k_radial[ik]; - } - break; - case Psi_Type::Psik2: - psif.resize(0); - psik.resize(0); - for( int ik=0; ik!=nk; ++ik ) - this->psik2[ik] = psi_in[ik]; - break; - default: - throw std::domain_error(std::string(__FILE__)+" line "+std::to_string(__LINE__)); - } - - switch(psi_type) - { - case Psi_Type::Psif: - case Psi_Type::Psik: - case Psi_Type::Psik2: - if( flag_sbpool ) - { - this->cal_rradial_sbpool(); - } - else - { - throw std::domain_error("flag_sbpool false not finished in Numerical_Orbital_Lm::set_orbital_info_k. "+std::string(__FILE__)+" line "+std::to_string(__LINE__)); - } - break; - default: break; - } - - //liaochen modify on 2010/4/7 - //we do SBT on regular mesh - //so we first generate psi_uniform first - //we put uniform in ahead of cal_kradial - - /* - bool uni = true; - if (uni) - { - this->extra_uniform(dr_uniform, force_flag); - } - else - { - this->use_uniform(dr_uniform); - } - */ - this->extra_uniform(dr_uniform, force_flag); - - switch(psi_type) - { - case Psi_Type::Psi: - if( flag_sbpool ) - { - this->cal_kradial_sbpool(); - } - else - { - this->cal_kradial(); - } - break; - default: break; - } + copy_parameter( + label_in, + index_atom_type_in, + angular_momentum_l_in, + index_chi_in, + nr_in, + rab_in, + r_radial_in, + nk_in, + dk_in, + dr_uniform_in); + + switch(psi_type) + { + case Psi_Type::Psi: + for (int ir = 0; ir < nr; ir++) + { + this->psi[ir] = psi_in[ir]; + this->psir[ir] = psi[ir] * r_radial[ir]; //mohan 2010-04-19 + } + break; + case Psi_Type::Psif: + for( int ik=0; ik!=nk; ++ik ) + { + this->psif[ik] = psi_in[ik]; + this->psik[ik] = psif[ik] * k_radial[ik]; + this->psik2[ik] = psik[ik] * k_radial[ik]; + } + break; + case Psi_Type::Psik: + psif.resize(0); + for( int ik=0; ik!=nk; ++ik ) + { + this->psik[ik] = psi_in[ik]; + this->psik2[ik] = psik[ik] * k_radial[ik]; + } + break; + case Psi_Type::Psik2: + psif.resize(0); + psik.resize(0); + for( int ik=0; ik!=nk; ++ik ) + this->psik2[ik] = psi_in[ik]; + break; + default: + throw std::domain_error(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + } + + switch(psi_type) + { + case Psi_Type::Psif: + case Psi_Type::Psik: + case Psi_Type::Psik2: + if( flag_sbpool ) + { + this->cal_rradial_sbpool(); + } + else + { + throw std::domain_error("flag_sbpool false not finished in Numerical_Orbital_Lm::set_orbital_info_k. "+std::string(__FILE__)+" line "+std::to_string(__LINE__)); + } + break; + default: break; + } + + //liaochen modify on 2010/4/7 + //we do SBT on regular mesh + //so we first generate psi_uniform first + //we put uniform in ahead of cal_kradial + + /* + bool uni = true; + if (uni) + { + this->extra_uniform(dr_uniform, force_flag); + } + else + { + this->use_uniform(dr_uniform); + } + */ + this->extra_uniform(dr_uniform, force_flag); + + switch(psi_type) + { + case Psi_Type::Psi: + if( flag_sbpool ) + { + this->cal_kradial_sbpool(); + } + else + { + this->cal_kradial(); + } + break; + default: break; + } // this->norm_test(); // Peize Lin delete 2016-08-31 - if( flag_plot ) - { - this->plot(); // Peize Lin add flag_plot 2016-08-31 - } - return; + if( flag_plot ) + { + this->plot(); // Peize Lin add flag_plot 2016-08-31 + } + return; } void Numerical_Orbital_Lm::copy_parameter( - const std::string &label_in, - const int &index_atom_type_in, - const int &angular_momentum_l_in, - const int &index_chi_in, - const int &nr_in, - const double *rab_in, - const double *r_radial_in, - const int &nk_in, - const double &dk_in, - const double &dr_uniform_in) + const std::string &label_in, + const int &index_atom_type_in, + const int &angular_momentum_l_in, + const int &index_chi_in, + const int &nr_in, + const double *rab_in, + const double *r_radial_in, + const int &nk_in, + const double &dk_in, + const double &dr_uniform_in) { this->label = label_in; this->index_atom_type = index_atom_type_in; @@ -188,216 +188,216 @@ void Numerical_Orbital_Lm::copy_parameter( assert(nk%2!=0); assert(dk_in>0); this->dk = dk_in; - this->dr_uniform=dr_uniform_in; + this->dr_uniform=dr_uniform_in; - /*********************************************************** - be careful! LiaoChen modify on 2010/4/21 - ************************************************************/ + /*********************************************************** + be careful! LiaoChen modify on 2010/4/21 + ************************************************************/ // this->dk = ModuleBase::PI / rcut / 2.0; // this->nk = this->nr; - r_radial.resize(nr); - rab.resize(nr); - psi.resize(nr); - psir.resize(nr); - for (int ir = 0; ir < nr; ir++) - { - this->r_radial[ir] = r_radial_in[ir]; - this->rab[ir] = rab_in[ir]; - } - - k_radial.resize(nk); - psif.resize(nk); - psik.resize(nk); - psik2.resize(nk); - for (int ik = 0; ik < nk; ik++) - { - this->k_radial[ik] = ik * this->dk; - } - this->kcut = (nk-1) * this->dk; + r_radial.resize(nr); + rab.resize(nr); + psi.resize(nr); + psir.resize(nr); + for (int ir = 0; ir < nr; ir++) + { + this->r_radial[ir] = r_radial_in[ir]; + this->rab[ir] = rab_in[ir]; + } + + k_radial.resize(nk); + psif.resize(nk); + psik.resize(nk); + psik2.resize(nk); + for (int ik = 0; ik < nk; ik++) + { + this->k_radial[ik] = ik * this->dk; + } + this->kcut = (nk-1) * this->dk; } #include "source_base/mathzone_add1.h" void Numerical_Orbital_Lm::extra_uniform(const double &dr_uniform_in, const bool &force_flag) { - ModuleBase::timer::start("NOrbital_Lm", "extra_uniform"); - - //--------------------------------------------- - // set the dr, fixed by liaochen. - // calculate the number of radial mesh points. - //--------------------------------------------- - assert(dr_uniform>0.0); - this->dr_uniform = dr_uniform_in; - this->nr_uniform = static_cast(rcut/dr_uniform) + 10; - - this->psi_uniform.resize(nr_uniform,0); - - // do interpolation here to make grid more dense + ModuleBase::timer::start("NOrbital_Lm", "extra_uniform"); + + //--------------------------------------------- + // set the dr, fixed by liaochen. + // calculate the number of radial mesh points. + //--------------------------------------------- + assert(dr_uniform>0.0); + this->dr_uniform = dr_uniform_in; + this->nr_uniform = static_cast(rcut/dr_uniform) + 10; + + this->psi_uniform.resize(nr_uniform,0); + + // do interpolation here to make grid more dense #ifdef _OPENMP - #pragma omp parallel for schedule(static) + #pragma omp parallel for schedule(static) #endif - for (int ir = 0; ir < this->nr_uniform; ir++) - { - const double psi_uniform_tmp = - ModuleBase::Mathzone_Add1::Uni_RadialF(ModuleBase::GlobalFunc::VECTOR_TO_PTR(this->psi), this->nr, this->rab[0], ir * dr_uniform); - this->psi_uniform[ir] = psi_uniform_tmp; + for (int ir = 0; ir < this->nr_uniform; ir++) + { + const double psi_uniform_tmp = + ModuleBase::Mathzone_Add1::Uni_RadialF(ModuleBase::GlobalFunc::VECTOR_TO_PTR(this->psi), this->nr, this->rab[0], ir * dr_uniform); + this->psi_uniform[ir] = psi_uniform_tmp; // this->psi_uniform[ir] = ModuleBase::Mathzone::Polynomial_Interpolation(this->psi, this->nr, this->rab[0], ir * dr_uniform); } - - //---------------------------------------------- - // calculate the dpsi_uniform - //---------------------------------------------- - this->dpsi_uniform.resize(this->nr_uniform); - this->ddpsi_uniform.resize(this->nr_uniform); - - double* y2 = new double[nr]; - - //-------------------------------------------------------------------------- - // old code to calculate the derivate dpsi/dr, - // has problem that the derivatives of orbitals oscillate a lot - // around r=0 - //-------------------------------------------------------------------------- - //ModuleBase::Mathzone_Add1::SplineD2 (r_radial, psi, nr, 100000.0, 100000.0, y2); - //double yp1=(this->psi[1]-this->psi[0])/this->r_radial[1]; - //std::cout<<"psi0="<<" "<psi[0]<<" "<<"psi1="<<" "<psi[1]<<" "<<"r1="<<" "<r_radial[1]<angular_momentum_l ) // added by pengfei 13-8-8 different l has different boundary conditions - { - case 0: ModuleBase::Mathzone_Add1::SplineD2 (ModuleBase::GlobalFunc::VECTOR_TO_PTR(r_radial), ModuleBase::GlobalFunc::VECTOR_TO_PTR(psi), nr, 0.0, 0.0, y2); break; - case 1: ModuleBase::Mathzone_Add1::SplineD2 (ModuleBase::GlobalFunc::VECTOR_TO_PTR(r_radial), ModuleBase::GlobalFunc::VECTOR_TO_PTR(psi), nr, 100000.0, 100000.0, y2); break; - case 2: ModuleBase::Mathzone_Add1::SplineD2 (ModuleBase::GlobalFunc::VECTOR_TO_PTR(r_radial), ModuleBase::GlobalFunc::VECTOR_TO_PTR(psi), nr, 0.0, 0.0, y2); break; - case 3: ModuleBase::Mathzone_Add1::SplineD2 (ModuleBase::GlobalFunc::VECTOR_TO_PTR(r_radial), ModuleBase::GlobalFunc::VECTOR_TO_PTR(psi), nr, 100000.0, 100000.0, y2); break; - case 4: ModuleBase::Mathzone_Add1::SplineD2 (ModuleBase::GlobalFunc::VECTOR_TO_PTR(r_radial), ModuleBase::GlobalFunc::VECTOR_TO_PTR(psi), nr, 0.0, 0.0, y2); break; - default: - //GlobalV::ofs_warning << " The angular momentum larger than 4 (g orbitals) may be error about eggbox. " << std::endl; - //GlobalV::ofs_warning << " Check file " << __FILE__ << " line " << __LINE__ <angular_momentum_l<psi_uniform), - this->nr_uniform, - dr_uniform, - angular_momentum_l, - tmp); - - this->zty = tmp[0]/ModuleBase::Mathzone_Add1::factorial (angular_momentum_l); - } - - delete [] y2; - delete [] rad; - delete [] tmp; - ModuleBase::timer::end("NOrbital_Lm", "extra_uniform"); + + //---------------------------------------------- + // calculate the dpsi_uniform + //---------------------------------------------- + this->dpsi_uniform.resize(this->nr_uniform); + this->ddpsi_uniform.resize(this->nr_uniform); + + double* y2 = new double[nr]; + + //-------------------------------------------------------------------------- + // old code to calculate the derivate dpsi/dr, + // has problem that the derivatives of orbitals oscillate a lot + // around r=0 + //-------------------------------------------------------------------------- + //ModuleBase::Mathzone_Add1::SplineD2 (r_radial, psi, nr, 100000.0, 100000.0, y2); + //double yp1=(this->psi[1]-this->psi[0])/this->r_radial[1]; + //std::cout<<"psi0="<<" "<psi[0]<<" "<<"psi1="<<" "<psi[1]<<" "<<"r1="<<" "<r_radial[1]<angular_momentum_l ) // added by pengfei 13-8-8 different l has different boundary conditions + { + case 0: ModuleBase::Mathzone_Add1::SplineD2 (ModuleBase::GlobalFunc::VECTOR_TO_PTR(r_radial), ModuleBase::GlobalFunc::VECTOR_TO_PTR(psi), nr, 0.0, 0.0, y2); break; + case 1: ModuleBase::Mathzone_Add1::SplineD2 (ModuleBase::GlobalFunc::VECTOR_TO_PTR(r_radial), ModuleBase::GlobalFunc::VECTOR_TO_PTR(psi), nr, 100000.0, 100000.0, y2); break; + case 2: ModuleBase::Mathzone_Add1::SplineD2 (ModuleBase::GlobalFunc::VECTOR_TO_PTR(r_radial), ModuleBase::GlobalFunc::VECTOR_TO_PTR(psi), nr, 0.0, 0.0, y2); break; + case 3: ModuleBase::Mathzone_Add1::SplineD2 (ModuleBase::GlobalFunc::VECTOR_TO_PTR(r_radial), ModuleBase::GlobalFunc::VECTOR_TO_PTR(psi), nr, 100000.0, 100000.0, y2); break; + case 4: ModuleBase::Mathzone_Add1::SplineD2 (ModuleBase::GlobalFunc::VECTOR_TO_PTR(r_radial), ModuleBase::GlobalFunc::VECTOR_TO_PTR(psi), nr, 0.0, 0.0, y2); break; + default: + //GlobalV::ofs_warning << " The angular momentum larger than 4 (g orbitals) may be error about eggbox. " << std::endl; + //GlobalV::ofs_warning << " Check file " << __FILE__ << " line " << __LINE__ <angular_momentum_l<psi_uniform), + this->nr_uniform, + dr_uniform, + angular_momentum_l, + tmp); + + this->zty = tmp[0]/ModuleBase::Mathzone_Add1::factorial (angular_momentum_l); + } + + delete [] y2; + delete [] rad; + delete [] tmp; + ModuleBase::timer::end("NOrbital_Lm", "extra_uniform"); } /* void Numerical_Orbital_Lm::use_uniform(const double &dr_uniform_in) { - assert(dr_uniform_in>0.0); - this->dr_uniform = dr_uniform_in; - // for save: +10, because in real space interpolation, - // there may be "one grid point" more than the cutoff. - this->nr_uniform = static_cast(rcut/dr_uniform)+10; - - this->psi_uniform.resize(nr_uniform,0); - - std::string orbital_type; - // Peize Lin update 2016-08-31 - if( 0==this->angular_momentum_l ) - { - orbital_type = 's'; - } - else if( 1==this->angular_momentum_l ) - { - orbital_type = 'p'; - } - else if( 2==this->angular_momentum_l ) - { - orbital_type = 'd'; - } - else if( 3<=this->angular_momentum_l && this->angular_momentum_l<=6 ) - { - orbital_type = 'f'+this->angular_momentum_l-3; - } - else if( 7<=this->angular_momentum_l && this->angular_momentum_l<=11 ) - { - orbital_type = 'k'+this->angular_momentum_l-7; - } - else - { - orbital_type = "L" + ModuleBase::GlobalFunc::TO_STRING(this->angular_momentum_l); - } - - std::cout << "===========================================================" << std::endl; - for(int i=0; ipsi_uniform[i] = - ModuleBase::Mathzone_Add1::Uni_RadialF(ModuleBase::GlobalFunc::VECTOR_TO_PTR(psi), this->nr, this->rab[0], i*dr_uniform); - } - - this->dpsi_uniform.resize(nr_uniform); - - ModuleBase::Mathzone_Add1::Uni_Deriv_Phi ( - ModuleBase::GlobalFunc::VECTOR_TO_PTR(psi_uniform), - nr_uniform, dr_uniform, - 1, - ModuleBase::GlobalFunc::VECTOR_TO_PTR(dpsi_uniform)); + assert(dr_uniform_in>0.0); + this->dr_uniform = dr_uniform_in; + // for save: +10, because in real space interpolation, + // there may be "one grid point" more than the cutoff. + this->nr_uniform = static_cast(rcut/dr_uniform)+10; + + this->psi_uniform.resize(nr_uniform,0); + + std::string orbital_type; + // Peize Lin update 2016-08-31 + if( 0==this->angular_momentum_l ) + { + orbital_type = 's'; + } + else if( 1==this->angular_momentum_l ) + { + orbital_type = 'p'; + } + else if( 2==this->angular_momentum_l ) + { + orbital_type = 'd'; + } + else if( 3<=this->angular_momentum_l && this->angular_momentum_l<=6 ) + { + orbital_type = 'f'+this->angular_momentum_l-3; + } + else if( 7<=this->angular_momentum_l && this->angular_momentum_l<=11 ) + { + orbital_type = 'k'+this->angular_momentum_l-7; + } + else + { + orbital_type = "L" + ModuleBase::GlobalFunc::TO_STRING(this->angular_momentum_l); + } + + std::cout << "===========================================================" << std::endl; + for(int i=0; ipsi_uniform[i] = + ModuleBase::Mathzone_Add1::Uni_RadialF(ModuleBase::GlobalFunc::VECTOR_TO_PTR(psi), this->nr, this->rab[0], i*dr_uniform); + } + + this->dpsi_uniform.resize(nr_uniform); + + ModuleBase::Mathzone_Add1::Uni_Deriv_Phi ( + ModuleBase::GlobalFunc::VECTOR_TO_PTR(psi_uniform), + nr_uniform, dr_uniform, + 1, + ModuleBase::GlobalFunc::VECTOR_TO_PTR(dpsi_uniform)); #ifdef __NORMAL #else - if(GlobalV::MY_RANK==0) - { - std::stringstream ss; - ss << ModuleBase::get_global_out_dir() << this->label << "/" - << this->label << "-" << orbital_type << ".ORBITAL_NOR_uniform.txt"; - - std::ofstream ofs(ss.str().c_str()); - - for(int i=0; ilabel << "/" + << this->label << "-" << orbital_type << ".ORBITAL_NOR_uniform.txt"; + + std::ofstream ofs(ss.str().c_str()); + + for(int i=0; inr > 0); - assert( this->nr_uniform > 0); - double *jl = new double[nr]; - double *integrated_func = new double[nr]; - - const double pref = sqrt( 2.0 / ModuleBase::PI ); - //Sbt method - - /* - double* rad = new double[nr_uniform]; - for (int ir = 0; ir < nr_uniform; ir++) - { - rad[ir] = dr_uniform * ir; - } - - //liaochen add - ModuleBase::Mathzone_Add1::Sbt_new (3, angular_momentum_l, - k_radial, dk, nk, - rad, dr_uniform, nr_uniform, - psi_uniform, 0, this->psik); - - for (int ik = 0; ik < nk; ik++) this->psik[ik] *= (pref*k_radial[ik]); - delete [] rad; - */ - - //integration directly - for (int ik = 0; ik < nk; ik++) - { - ModuleBase::Sphbes::Spherical_Bessel( - this->nr, - ModuleBase::GlobalFunc::VECTOR_TO_PTR(this->r_radial), - this->k_radial[ik], - this->angular_momentum_l, - jl); - - for (int ir = 0; ir < nr; ir++) - { - integrated_func[ir] = this->psir[ir] * this->r_radial[ir] * jl[ir]; - } - - ModuleBase::Integral::Simpson_Integral( - this->nr, - integrated_func, - ModuleBase::GlobalFunc::VECTOR_TO_PTR(this->rab), - this->psif[ik]); - this->psif[ik] *= pref; - this->psik[ik] = this->psif[ik] * k_radial[ik]; - this->psik2[ik] = this->psik[ik] * k_radial[ik]; - } - - delete[] integrated_func; - delete[] jl; + assert( this->nr > 0); + assert( this->nr_uniform > 0); + double *jl = new double[nr]; + double *integrated_func = new double[nr]; + + const double pref = sqrt( 2.0 / ModuleBase::PI ); + //Sbt method + + /* + double* rad = new double[nr_uniform]; + for (int ir = 0; ir < nr_uniform; ir++) + { + rad[ir] = dr_uniform * ir; + } + + //liaochen add + ModuleBase::Mathzone_Add1::Sbt_new (3, angular_momentum_l, + k_radial, dk, nk, + rad, dr_uniform, nr_uniform, + psi_uniform, 0, this->psik); + + for (int ik = 0; ik < nk; ik++) this->psik[ik] *= (pref*k_radial[ik]); + delete [] rad; + */ + + //integration directly + for (int ik = 0; ik < nk; ik++) + { + ModuleBase::Sphbes::Spherical_Bessel( + this->nr, + ModuleBase::GlobalFunc::VECTOR_TO_PTR(this->r_radial), + this->k_radial[ik], + this->angular_momentum_l, + jl); + + for (int ir = 0; ir < nr; ir++) + { + integrated_func[ir] = this->psir[ir] * this->r_radial[ir] * jl[ir]; + } + + ModuleBase::Integral::Simpson_Integral( + this->nr, + integrated_func, + ModuleBase::GlobalFunc::VECTOR_TO_PTR(this->rab), + this->psif[ik]); + this->psif[ik] *= pref; + this->psik[ik] = this->psif[ik] * k_radial[ik]; + this->psik2[ik] = this->psik[ik] * k_radial[ik]; + } + + delete[] integrated_func; + delete[] jl; } /* // Peize Lin add 2017-10-02 void Numerical_Orbital_Lm::cal_kradial_sbpool(void) { - assert( this->nr > 0); - assert( this->nr_uniform > 0); - - // dr must be all the same for Sph_Bessel_Recursive_Pool and Simpson_Integral - const double dr = this->rab[0]; - for( size_t ir=1; irnr; ++ir ) - assert( dr == this->rab[ir] ); - - ModuleBase::Sph_Bessel_Recursive::D2* pSB = nullptr; - for( auto & sb : Sph_Bessel_Recursive_Pool::D2::sb_pool ) - if( this->dk * dr == sb.get_dx() ) - { - pSB = &sb; - break; - } - if(!pSB) - { - Sph_Bessel_Recursive_Pool::D2::sb_pool.push_back({}); - pSB = &Sph_Bessel_Recursive_Pool::D2::sb_pool.back(); - } - pSB->set_dx( this->dk * dr ); - pSB->cal_jlx( this->angular_momentum_l, this->nk, this->nr ); - const std::vector> &jl = pSB->get_jlx()[this->angular_momentum_l]; - - std::vector integrated_func( this->nr ); - const double pref = sqrt( 2.0 / ModuleBase::PI ); - - std::vector psir2(nr); - for( size_t ir=0; ir!=nr; ++ir ) - psir2[ir] = this->psir[ir] * this->r_radial[ir]; - - for (int ik = 0; ik < nk; ik++) - { - const std::vector &jlk = jl[ik]; - for (int ir = 0; ir < nr; ir++) - integrated_func[ir] = psir2[ir] * jlk[ir]; - ModuleBase::Integral::Simpson_Integral( - this->nr, - ModuleBase::GlobalFunc::VECTOR_TO_PTR(integrated_func), - dr, - this->psik[ik]); - this->psik[ik] *= ( pref * k_radial[ik]); - } + assert( this->nr > 0); + assert( this->nr_uniform > 0); + + // dr must be all the same for Sph_Bessel_Recursive_Pool and Simpson_Integral + const double dr = this->rab[0]; + for( size_t ir=1; irnr; ++ir ) + assert( dr == this->rab[ir] ); + + ModuleBase::Sph_Bessel_Recursive::D2* pSB = nullptr; + for( auto & sb : Sph_Bessel_Recursive_Pool::D2::sb_pool ) + if( this->dk * dr == sb.get_dx() ) + { + pSB = &sb; + break; + } + if(!pSB) + { + Sph_Bessel_Recursive_Pool::D2::sb_pool.push_back({}); + pSB = &Sph_Bessel_Recursive_Pool::D2::sb_pool.back(); + } + pSB->set_dx( this->dk * dr ); + pSB->cal_jlx( this->angular_momentum_l, this->nk, this->nr ); + const std::vector> &jl = pSB->get_jlx()[this->angular_momentum_l]; + + std::vector integrated_func( this->nr ); + const double pref = sqrt( 2.0 / ModuleBase::PI ); + + std::vector psir2(nr); + for( size_t ir=0; ir!=nr; ++ir ) + psir2[ir] = this->psir[ir] * this->r_radial[ir]; + + for (int ik = 0; ik < nk; ik++) + { + const std::vector &jlk = jl[ik]; + for (int ir = 0; ir < nr; ir++) + integrated_func[ir] = psir2[ir] * jlk[ir]; + ModuleBase::Integral::Simpson_Integral( + this->nr, + ModuleBase::GlobalFunc::VECTOR_TO_PTR(integrated_func), + dr, + this->psik[ik]); + this->psik[ik] *= ( pref * k_radial[ik]); + } } */ // Peize Lin add 2017-10-27 void Numerical_Orbital_Lm::cal_kradial_sbpool(void) { - assert( this->nr > 0); - assert( this->nr_uniform > 0); - - // dr must be all the same for Sph_Bessel_Recursive_Pool - const double dr = this->rab[0]; - - for( int ir=1; irnr; ++ir ) - { - assert( dr == this->rab[ir] ); - } - - ModuleBase::Sph_Bessel_Recursive::D2* pSB = nullptr; - for( auto & sb : ModuleBase::Sph_Bessel_Recursive_Pool::D2::sb_pool ) - { - if( this->dk * dr == sb.get_dx() ) - { - pSB = &sb; - break; - } - } - - if(!pSB) - { - ModuleBase::Sph_Bessel_Recursive_Pool::D2::sb_pool.push_back({}); - pSB = &ModuleBase::Sph_Bessel_Recursive_Pool::D2::sb_pool.back(); - } - pSB->set_dx( this->dk * dr ); - pSB->cal_jlx( this->angular_momentum_l, this->nk, this->nr ); - const std::vector> &jl = pSB->get_jlx()[this->angular_momentum_l]; - - const double pref = sqrt( 2.0 / ModuleBase::PI ); - - std::vector r_tmp(nr); - for( int ir=0; ir!=nr; ++ir ) - { - r_tmp[ir] = this->psir[ir] * this->r_radial[ir] * this->rab[ir]; - } - - constexpr double one_three=1.0/3.0, two_three=2.0/3.0, four_three=4.0/3.0; - r_tmp[0]*=one_three; - r_tmp[nr-1]*=one_three; - - for( int ir=1; ir!=nr-1; ++ir ) - { - r_tmp[ir] *= (ir&1) ? four_three : two_three; - } + assert( this->nr > 0); + assert( this->nr_uniform > 0); + + // dr must be all the same for Sph_Bessel_Recursive_Pool + const double dr = this->rab[0]; + + for( int ir=1; irnr; ++ir ) + { + assert( dr == this->rab[ir] ); + } + + ModuleBase::Sph_Bessel_Recursive::D2* pSB = nullptr; + for( auto & sb : ModuleBase::Sph_Bessel_Recursive_Pool::D2::sb_pool ) + { + if( this->dk * dr == sb.get_dx() ) + { + pSB = &sb; + break; + } + } + + if(!pSB) + { + ModuleBase::Sph_Bessel_Recursive_Pool::D2::sb_pool.push_back({}); + pSB = &ModuleBase::Sph_Bessel_Recursive_Pool::D2::sb_pool.back(); + } + pSB->set_dx( this->dk * dr ); + pSB->cal_jlx( this->angular_momentum_l, this->nk, this->nr ); + const std::vector> &jl = pSB->get_jlx()[this->angular_momentum_l]; + + const double pref = sqrt( 2.0 / ModuleBase::PI ); + + std::vector r_tmp(nr); + for( int ir=0; ir!=nr; ++ir ) + { + r_tmp[ir] = this->psir[ir] * this->r_radial[ir] * this->rab[ir]; + } + + constexpr double one_three=1.0/3.0, two_three=2.0/3.0, four_three=4.0/3.0; + r_tmp[0]*=one_three; + r_tmp[nr-1]*=one_three; + + for( int ir=1; ir!=nr-1; ++ir ) + { + r_tmp[ir] *= (ir&1) ? four_three : two_three; + } #ifdef _OPENMP - #pragma omp parallel for schedule(static) + #pragma omp parallel for schedule(static) #endif - for (int ik = 0; ik < nk; ik++) - { + for (int ik = 0; ik < nk; ik++) + { #ifdef __NORMAL - double psi_f_tmp = 0.0; - for(int ir=0; irnr, ModuleBase::GlobalFunc::VECTOR_TO_PTR(r_tmp), 1, ModuleBase::GlobalFunc::VECTOR_TO_PTR(jl[ik]), 1 ) ; + const double psi_f_tmp = + pref * BlasConnector::dot( this->nr, ModuleBase::GlobalFunc::VECTOR_TO_PTR(r_tmp), 1, ModuleBase::GlobalFunc::VECTOR_TO_PTR(jl[ik]), 1 ) ; #endif - this->psif[ik] = psi_f_tmp; - this->psik[ik] = psi_f_tmp * k_radial[ik]; - this->psik2[ik] = this->psik[ik] * k_radial[ik]; - } - return; + this->psif[ik] = psi_f_tmp; + this->psik[ik] = psi_f_tmp * k_radial[ik]; + this->psik2[ik] = this->psik[ik] * k_radial[ik]; + } + return; } // Peize Lin add 2017-12-11 void Numerical_Orbital_Lm::cal_rradial_sbpool(void) { - // dr must be all the same for Sph_Bessel_Recursive_Pool - const double dr = this->rab[0]; + // dr must be all the same for Sph_Bessel_Recursive_Pool + const double dr = this->rab[0]; - for( int ir=1; irnr; ++ir ) - { - assert( dr == this->rab[ir] ); - } + for( int ir=1; irnr; ++ir ) + { + assert( dr == this->rab[ir] ); + } - ModuleBase::Sph_Bessel_Recursive::D2* pSB = nullptr; - for( auto & sb : ModuleBase::Sph_Bessel_Recursive_Pool::D2::sb_pool ) - { - if( dr * dk == sb.get_dx() ) - { - pSB = &sb; - break; - } - } + ModuleBase::Sph_Bessel_Recursive::D2* pSB = nullptr; + for( auto & sb : ModuleBase::Sph_Bessel_Recursive_Pool::D2::sb_pool ) + { + if( dr * dk == sb.get_dx() ) + { + pSB = &sb; + break; + } + } - if(!pSB) - { - ModuleBase::Sph_Bessel_Recursive_Pool::D2::sb_pool.push_back({}); - pSB = &ModuleBase::Sph_Bessel_Recursive_Pool::D2::sb_pool.back(); - } + if(!pSB) + { + ModuleBase::Sph_Bessel_Recursive_Pool::D2::sb_pool.push_back({}); + pSB = &ModuleBase::Sph_Bessel_Recursive_Pool::D2::sb_pool.back(); + } - pSB->set_dx( dr * dk ); - pSB->cal_jlx( this->angular_momentum_l, this->nr, this->nk ); + pSB->set_dx( dr * dk ); + pSB->cal_jlx( this->angular_momentum_l, this->nr, this->nk ); - const std::vector> &jl = pSB->get_jlx()[this->angular_momentum_l]; + const std::vector> &jl = pSB->get_jlx()[this->angular_momentum_l]; - const double pref = sqrt(2.0/ModuleBase::PI); + const double pref = sqrt(2.0/ModuleBase::PI); - std::vector k_tmp(nk); + std::vector k_tmp(nk); - for( int ik=0; ik!=nk; ++ik ) - { - k_tmp[ik] = this->psik2[ik] * dk; - } + for( int ik=0; ik!=nk; ++ik ) + { + k_tmp[ik] = this->psik2[ik] * dk; + } - constexpr double one_three=1.0/3.0, two_three=2.0/3.0, four_three=4.0/3.0; + constexpr double one_three=1.0/3.0, two_three=2.0/3.0, four_three=4.0/3.0; - k_tmp[0]*=one_three; - k_tmp[nk-1]*=one_three; + k_tmp[0]*=one_three; + k_tmp[nk-1]*=one_three; - for( int ik=1; ik!=nk-1; ++ik ) - { - k_tmp[ik] *= (ik&1) ? four_three : two_three; - } + for( int ik=1; ik!=nk-1; ++ik ) + { + k_tmp[ik] *= (ik&1) ? four_three : two_three; + } - for( int ir = 0; ir!=nr; ++ir ) - { + for( int ir = 0; ir!=nr; ++ir ) + { #ifdef __NORMAL - // mohan add 2021-05-08, test needed - double kj_dot = 0.0; - for( int ik=0; ikpsi[ir] = pref * kj_dot; + // mohan add 2021-05-08, test needed + double kj_dot = 0.0; + for( int ik=0; ikpsi[ir] = pref * kj_dot; #else - this->psi[ir] = pref * BlasConnector::dot( this->nk, ModuleBase::GlobalFunc::VECTOR_TO_PTR(k_tmp), 1, ModuleBase::GlobalFunc::VECTOR_TO_PTR(jl[ir]), 1 ); + this->psi[ir] = pref * BlasConnector::dot( this->nk, ModuleBase::GlobalFunc::VECTOR_TO_PTR(k_tmp), 1, ModuleBase::GlobalFunc::VECTOR_TO_PTR(jl[ir]), 1 ); #endif - this->psir[ir] = this->psi[ir] * r_radial[ir]; - } + this->psir[ir] = this->psi[ir] * r_radial[ir]; + } } //=============================================== @@ -657,118 +657,118 @@ void Numerical_Orbital_Lm::cal_rradial_sbpool(void) void Numerical_Orbital_Lm::norm_test(void)const { // ModuleBase::TITLE(ofs_onscaling, "Numerical_Orbital_Lm", "norm_test"); - //double asum_r = 0.0; - //double asum_k = 0.0; - - // note here psir = psi * r - double *f = new double[nr]; - for(int ir=0; irpsir[ir] * this->psir[ir]; - } + //double asum_r = 0.0; + //double asum_k = 0.0; + + // note here psir = psi * r + double *f = new double[nr]; + for(int ir=0; irpsir[ir] * this->psir[ir]; + } - double sumr = 0.0; - //double sumk = 0.0; + double sumr = 0.0; + //double sumk = 0.0; - ModuleBase::Integral::Simpson_Integral(this->nr, f, ModuleBase::GlobalFunc::VECTOR_TO_PTR(this->rab), sumr); + ModuleBase::Integral::Simpson_Integral(this->nr, f, ModuleBase::GlobalFunc::VECTOR_TO_PTR(this->rab), sumr); - delete[] f; - f = new double[nk]; - for(int ik=0; ikpsik[ik] * this->psik[ik]; - } + delete[] f; + f = new double[nk]; + for(int ik=0; ikpsik[ik] * this->psik[ik]; + } // ModuleBase::Integral::Simpson_Integral(this->nk, f, this->k_radial, sumk); - - //means nothing. - //GlobalV::ofs_running << std::setw(12) << sumk << std::endl; + + //means nothing. + //GlobalV::ofs_running << std::setw(12) << sumk << std::endl; - delete[] f; - return; + delete[] f; + return; } */ void Numerical_Orbital_Lm::plot(void)const { - ModuleBase::TITLE("Numerical_Orbital_Lm","plot"); - - std::string orbital_type; - // Peize Lin update 2016-08-31 - if( 0==this->angular_momentum_l ) - { - orbital_type = 's'; - } - else if( 1==this->angular_momentum_l ) - { - orbital_type = 'p'; - } - else if( 2==this->angular_momentum_l ) - { - orbital_type = 'd'; - } - else if( 3<=this->angular_momentum_l && this->angular_momentum_l<=6 ) - { - orbital_type = 'f' + this->angular_momentum_l - 3; - } - else if( 7<=this->angular_momentum_l && this->angular_momentum_l<=11 ) - { - orbital_type = 'k' + this->angular_momentum_l - 7; - } - else - { - orbital_type = "L" + ModuleBase::GlobalFunc::TO_STRING(this->angular_momentum_l); - } - - if(GlobalV::MY_RANK==0) - { - std::stringstream ssr, ssk, ssru ,ssdru; // 2013-08-10 pengfei - ssr << ModuleBase::get_global_out_dir() << this->label << "/" - << this->label << "-"<< orbital_type << index_chi+1 << "-orbital-r.dat"; - - ssk << ModuleBase::get_global_out_dir() << this->label << "/" - << this->label << "-" << orbital_type << index_chi+1 << "-orbital-k.dat"; - - ssru << ModuleBase::get_global_out_dir() << this->label << "/" - << this->label << "-" << orbital_type << index_chi+1 << "-orbital-ru.dat"; - - ssdru << ModuleBase::get_global_out_dir() << this->label << "/" // 2013-08-10 pengfei - << this->label << "-" << orbital_type << index_chi+1 << "-orbital-dru.dat"; - - std::ofstream ofsr(ssr.str().c_str()); - std::ofstream ofsk(ssk.str().c_str()); - std::ofstream ofsru(ssru.str().c_str()); - std::ofstream ofsdru(ssdru.str().c_str()); // 2013-08-10 pengfei - - if (!ofsk || !ofsr || !ofsru || !ofsdru) // 2013-08-10 pengfei - { - ModuleBase::WARNING("Numerical_Orbital_Lm : plot", "Can't open files !"); - } - - for (int i = 0; i < this->nr; i++) - { - ofsr << this->r_radial[i] << " " << psi[i] << std::endl; - } - - for (int i = 0; i < this->nk; i++) - { - ofsk << this->k_radial[i] << " " << psik[i] << std::endl; - } - - for (int i = 0; i < this->nr_uniform; i++) - { - ofsru << this->dr_uniform * i << " " << psi_uniform[i] << std::endl; - } - - for (int i = 0; i < this->nr_uniform; i++) - { - ofsdru << this->dr_uniform * i << " " << dpsi_uniform[i] << std::endl;// output dphi/dr 2013-08-10 pengfei - } - ofsr.close(); - ofsk.close(); - ofsru.close(); - ofsdru.close(); // 13-08-10 pengfei - } - - return; + ModuleBase::TITLE("Numerical_Orbital_Lm","plot"); + + std::string orbital_type; + // Peize Lin update 2016-08-31 + if( 0==this->angular_momentum_l ) + { + orbital_type = 's'; + } + else if( 1==this->angular_momentum_l ) + { + orbital_type = 'p'; + } + else if( 2==this->angular_momentum_l ) + { + orbital_type = 'd'; + } + else if( 3<=this->angular_momentum_l && this->angular_momentum_l<=6 ) + { + orbital_type = 'f' + this->angular_momentum_l - 3; + } + else if( 7<=this->angular_momentum_l && this->angular_momentum_l<=11 ) + { + orbital_type = 'k' + this->angular_momentum_l - 7; + } + else + { + orbital_type = "L" + ModuleBase::GlobalFunc::TO_STRING(this->angular_momentum_l); + } + + if(GlobalV::MY_RANK==0) + { + std::stringstream ssr, ssk, ssru ,ssdru; // 2013-08-10 pengfei + ssr << ModuleBase::get_global_out_dir() << this->label << "/" + << this->label << "-"<< orbital_type << index_chi+1 << "-orbital-r.dat"; + + ssk << ModuleBase::get_global_out_dir() << this->label << "/" + << this->label << "-" << orbital_type << index_chi+1 << "-orbital-k.dat"; + + ssru << ModuleBase::get_global_out_dir() << this->label << "/" + << this->label << "-" << orbital_type << index_chi+1 << "-orbital-ru.dat"; + + ssdru << ModuleBase::get_global_out_dir() << this->label << "/" // 2013-08-10 pengfei + << this->label << "-" << orbital_type << index_chi+1 << "-orbital-dru.dat"; + + std::ofstream ofsr(ssr.str().c_str()); + std::ofstream ofsk(ssk.str().c_str()); + std::ofstream ofsru(ssru.str().c_str()); + std::ofstream ofsdru(ssdru.str().c_str()); // 2013-08-10 pengfei + + if (!ofsk || !ofsr || !ofsru || !ofsdru) // 2013-08-10 pengfei + { + ModuleBase::WARNING("Numerical_Orbital_Lm : plot", "Can't open files !"); + } + + for (int i = 0; i < this->nr; i++) + { + ofsr << this->r_radial[i] << " " << psi[i] << std::endl; + } + + for (int i = 0; i < this->nk; i++) + { + ofsk << this->k_radial[i] << " " << psik[i] << std::endl; + } + + for (int i = 0; i < this->nr_uniform; i++) + { + ofsru << this->dr_uniform * i << " " << psi_uniform[i] << std::endl; + } + + for (int i = 0; i < this->nr_uniform; i++) + { + ofsdru << this->dr_uniform * i << " " << dpsi_uniform[i] << std::endl;// output dphi/dr 2013-08-10 pengfei + } + ofsr.close(); + ofsk.close(); + ofsru.close(); + ofsdru.close(); // 13-08-10 pengfei + } + + return; } diff --git a/source/source_basis/module_ao/orb_atomic_lm.h b/source/source_basis/module_ao/orb_atomic_lm.h index e984092f74a..c4bf2b3360d 100644 --- a/source/source_basis/module_ao/orb_atomic_lm.h +++ b/source/source_basis/module_ao/orb_atomic_lm.h @@ -19,140 +19,140 @@ using std::vector; class Numerical_Orbital_Lm { - friend class Numerical_Orbital; - /// the unit test drives cal_kradial(), cal_kradial_sbpool(), - /// cal_rradial_sbpool() and plot() directly - friend class NumericalOrbitalLmTest; - - public: - - std::vector psi_uniform;// mohan add 2009-5-10 - std::vector dpsi_uniform; //liaochen add 2010/5/11 - std::vector ddpsi_uniform; //wenfei add 2022/7/13 - - int nr_uniform;// mohan add 2009-5-10 - double dr_uniform;// mohan add 2009-5-10 - double zty; ///< the valus of psi at 0. - - Numerical_Orbital_Lm(); - ~Numerical_Orbital_Lm(); - - // Peize Lin add 2017-12-12 - enum class Psi_Type{ Psi, Psif, Psik, Psik2 }; - - /// EXPLAIN : set information about Numerical_Orbital_Lm - void set_orbital_info - ( - const std::string &label_in, - const int &index_atom_type_in, - const int &angular_momentum_l_in, - const int &index_chi_in, - const int &nr_in, - const double *rab_in, - const double *r_radial_in, - const Psi_Type &psi_type, // Peize Lin add 2017-12-12 - const double *psi_in, - const int &nk_in, - const double &dk_in, - // Peize Lin delete lat0 2016-02-03 - const double &dr_uniform, - bool flag_plot, // Peize Lin add flag_plot 2016-08-31 - bool flag_sbpool, // Peize Lin add flag_sbpool 2017-10-02 - const bool &force_flag // mohan add 2021-05-07 - ); + friend class Numerical_Orbital; + /// the unit test drives cal_kradial(), cal_kradial_sbpool(), + /// cal_rradial_sbpool() and plot() directly + friend class NumericalOrbitalLmTest; + + public: + + std::vector psi_uniform;// mohan add 2009-5-10 + std::vector dpsi_uniform; //liaochen add 2010/5/11 + std::vector ddpsi_uniform; //wenfei add 2022/7/13 + + int nr_uniform;// mohan add 2009-5-10 + double dr_uniform;// mohan add 2009-5-10 + double zty; ///< the valus of psi at 0. + + Numerical_Orbital_Lm(); + ~Numerical_Orbital_Lm(); + + // Peize Lin add 2017-12-12 + enum class Psi_Type{ Psi, Psif, Psik, Psik2 }; + + /// EXPLAIN : set information about Numerical_Orbital_Lm + void set_orbital_info + ( + const std::string &label_in, + const int &index_atom_type_in, + const int &angular_momentum_l_in, + const int &index_chi_in, + const int &nr_in, + const double *rab_in, + const double *r_radial_in, + const Psi_Type &psi_type, // Peize Lin add 2017-12-12 + const double *psi_in, + const int &nk_in, + const double &dk_in, + // Peize Lin delete lat0 2016-02-03 + const double &dr_uniform, + bool flag_plot, // Peize Lin add flag_plot 2016-08-31 + bool flag_sbpool, // Peize Lin add flag_sbpool 2017-10-02 + const bool &force_flag // mohan add 2021-05-07 + ); private: - void copy_parameter( - const std::string &label_in, - const int &index_atom_type_in, - const int &angular_momentum_l_in, - const int &index_chi_in, - const int &nr_in, - const double *rab_in, - const double *r_radial_in, - const int &nk_in, - const double &dk_in, - const double &dr_uniform_in); - - void cal_kradial(void); - void cal_kradial_sbpool(void); - void cal_rradial_sbpool(void); - //void norm_test()const; - void plot()const; - //void use_uniform(const double &dr_uniform_in); - void extra_uniform(const double &dr_uniform_in, const bool &force_flag); - - std::string label; - int index_atom_type; - int angular_momentum_l; - int index_chi; - - int nr; - int nk; - - double rcut; - double kcut; - double dk; - - std::vector r_radial; /// k_radial; - - std::vector rab; - - std::vector psi; ///< psi(r) - std::vector psir; ///< psi(r) * r - std::vector psif; ///< psi(k) - std::vector psik; ///< psi(k) * k - std::vector psik2; ///< psi(k) * k^2 + void copy_parameter( + const std::string &label_in, + const int &index_atom_type_in, + const int &angular_momentum_l_in, + const int &index_chi_in, + const int &nr_in, + const double *rab_in, + const double *r_radial_in, + const int &nk_in, + const double &dk_in, + const double &dr_uniform_in); + + void cal_kradial(void); + void cal_kradial_sbpool(void); + void cal_rradial_sbpool(void); + //void norm_test()const; + void plot()const; + //void use_uniform(const double &dr_uniform_in); + void extra_uniform(const double &dr_uniform_in, const bool &force_flag); + + std::string label; + int index_atom_type; + int angular_momentum_l; + int index_chi; + + int nr; + int nk; + + double rcut; + double kcut; + double dk; + + std::vector r_radial; /// k_radial; + + std::vector rab; + + std::vector psi; ///< psi(r) + std::vector psir; ///< psi(r) * r + std::vector psif; ///< psi(k) + std::vector psik; ///< psi(k) * k + std::vector psik2; ///< psi(k) * k^2 public: - const std::string& getLabel() const { return label; } - const int& getType() const { return index_atom_type; } - const int& getL() const { return angular_momentum_l; } - const int& getChi() const { return index_chi; } - - const double* getPsiuniform() const { return ModuleBase::GlobalFunc::VECTOR_TO_PTR(psi_uniform); } - const double* getDpsiuniform() const { return ModuleBase::GlobalFunc::VECTOR_TO_PTR(dpsi_uniform); } - const int& getNruniform() const { return nr_uniform; } - const double& getDruniform() const { return dr_uniform; } - - const int& getNr() const { return nr; } - const int& getNk() const { return nk; } - - const double& getRcut() const { return rcut; } - const double& getKcut() const { return kcut; } - - const double* getRadial() const { return ModuleBase::GlobalFunc::VECTOR_TO_PTR(r_radial); } - const std::vector& get_r_radial() const { return r_radial; } - const double& getRadial(const int ir) const { return r_radial[ir]; } - - const double* getRab() const { return ModuleBase::GlobalFunc::VECTOR_TO_PTR(rab); } - const std::vector& get_rab() const { return rab; } - const double& getRab(const int ir) const { return rab[ir]; } - - const double& getDk()const { return dk; } - const double* getKpoint() const { return ModuleBase::GlobalFunc::VECTOR_TO_PTR(k_radial); } - const double& getKpoint(const int ik) const { return k_radial[ik]; } - const std::vector& get_k_radial() const { return k_radial; } - - const double* getPsi() const { return ModuleBase::GlobalFunc::VECTOR_TO_PTR(psi);} - const double& getPsi(const int ir) const { return psi[ir];} - const std::vector& get_psi() const { return psi; } - const double* getPsi_r() const { return ModuleBase::GlobalFunc::VECTOR_TO_PTR(psir); } - const double& getPsi_r(const int ir) const { return psir[ir]; } - const std::vector& get_psir() const { return psir; } - - const double* getPsif() const { return ModuleBase::GlobalFunc::VECTOR_TO_PTR(psif); } - const double& getPsif(const int ik) const { return psif[ik]; } - const std::vector& get_psif() const { return psif; } - const double* getPsi_k() const { return ModuleBase::GlobalFunc::VECTOR_TO_PTR(psik); } - const double& getPsi_k(const int ik) const { return psik[ik]; } - const std::vector& get_psi_k() const { return psik; } - const double* getPsi_k2() const { return ModuleBase::GlobalFunc::VECTOR_TO_PTR(psik2); } - const double& getPsi_k2(const int ik) const { return psik2[ik]; } - const std::vector& get_psi_k2() const { return psik2; } + const std::string& getLabel() const { return label; } + const int& getType() const { return index_atom_type; } + const int& getL() const { return angular_momentum_l; } + const int& getChi() const { return index_chi; } + + const double* getPsiuniform() const { return ModuleBase::GlobalFunc::VECTOR_TO_PTR(psi_uniform); } + const double* getDpsiuniform() const { return ModuleBase::GlobalFunc::VECTOR_TO_PTR(dpsi_uniform); } + const int& getNruniform() const { return nr_uniform; } + const double& getDruniform() const { return dr_uniform; } + + const int& getNr() const { return nr; } + const int& getNk() const { return nk; } + + const double& getRcut() const { return rcut; } + const double& getKcut() const { return kcut; } + + const double* getRadial() const { return ModuleBase::GlobalFunc::VECTOR_TO_PTR(r_radial); } + const std::vector& get_r_radial() const { return r_radial; } + const double& getRadial(const int ir) const { return r_radial[ir]; } + + const double* getRab() const { return ModuleBase::GlobalFunc::VECTOR_TO_PTR(rab); } + const std::vector& get_rab() const { return rab; } + const double& getRab(const int ir) const { return rab[ir]; } + + const double& getDk()const { return dk; } + const double* getKpoint() const { return ModuleBase::GlobalFunc::VECTOR_TO_PTR(k_radial); } + const double& getKpoint(const int ik) const { return k_radial[ik]; } + const std::vector& get_k_radial() const { return k_radial; } + + const double* getPsi() const { return ModuleBase::GlobalFunc::VECTOR_TO_PTR(psi);} + const double& getPsi(const int ir) const { return psi[ir];} + const std::vector& get_psi() const { return psi; } + const double* getPsi_r() const { return ModuleBase::GlobalFunc::VECTOR_TO_PTR(psir); } + const double& getPsi_r(const int ir) const { return psir[ir]; } + const std::vector& get_psir() const { return psir; } + + const double* getPsif() const { return ModuleBase::GlobalFunc::VECTOR_TO_PTR(psif); } + const double& getPsif(const int ik) const { return psif[ik]; } + const std::vector& get_psif() const { return psif; } + const double* getPsi_k() const { return ModuleBase::GlobalFunc::VECTOR_TO_PTR(psik); } + const double& getPsi_k(const int ik) const { return psik[ik]; } + const std::vector& get_psi_k() const { return psik; } + const double* getPsi_k2() const { return ModuleBase::GlobalFunc::VECTOR_TO_PTR(psik2); } + const double& getPsi_k2(const int ik) const { return psik2[ik]; } + const std::vector& get_psi_k2() const { return psik2; } }; #endif diff --git a/source/source_basis/module_ao/orb_gaunt_table.cpp b/source/source_basis/module_ao/orb_gaunt_table.cpp index 8caddfc4743..26c3e9329fe 100644 --- a/source/source_basis/module_ao/orb_gaunt_table.cpp +++ b/source/source_basis/module_ao/orb_gaunt_table.cpp @@ -20,14 +20,14 @@ void ORB_gaunt_table::init_Gaunt(const int &lmax) ModuleBase::TITLE("ORB_gaunt_table", "init_Gaunt"); ModuleBase::timer::start("ORB_gaunt_table", "init_Gaunt"); - this->Lmax_Gaunt_Coefficients = lmax; - const int nlm = (lmax * 2 + 1) * (lmax * 2 + 1); - this->Gaunt_Coefficients.create(nlm, nlm, nlm); + this->Lmax_Gaunt_Coefficients = lmax; + const int nlm = (lmax * 2 + 1) * (lmax * 2 + 1); + this->Gaunt_Coefficients.create(nlm, nlm, nlm); - // Becaful! , L ends at 2*lmax+1 + // Becaful! , L ends at 2*lmax+1 for (int L = 0; L < 2*lmax + 1; L++) { - // m order is ( 0,0,1,-1,0,1,-1,2,-2...) + // m order is ( 0,0,1,-1,0,1,-1,2,-2...) for (int m = 0; m < 2*L + 1 ; m++) { const int dim = this->get_lm_index(L,m); @@ -44,10 +44,10 @@ void ORB_gaunt_table::init_Gaunt(const int &lmax) ///////////////////// ///call Calculate::Cal_G //////////////////// - - Gaunt_Coefficients(dim1, dim2, dim) = - this->Get_Gaunt_SH (L1, m1, L2, m2, L, m); - }// m2 + + Gaunt_Coefficients(dim1, dim2, dim) = + this->Get_Gaunt_SH (L1, m1, L2, m2, L, m); + }// m2 }// L2 }// m1 }// L1 @@ -62,96 +62,96 @@ void ORB_gaunt_table::init_Gaunt(const int &lmax) double ORB_gaunt_table::Cal_Gaunt_single ( const int &L1, - const int &m1, + const int &m1, const int &L2, - const int &m2, + const int &m2, const int &L, - const int &m, + const int &m, const double &s1, - const double &e1, + const double &e1, const double &s2, - const double &e2 + const double &e2 ) { - ModuleBase::timer::start("ORB_gaunt_table", "Cal_Gaunt_single"); - if ((L1 - L2 - L) % 2 != 0) - { - return 0.0; - } - - double result = 0.0; - static double absc[16] = { - -0.9894009349916499, -0.9445750230732326, -0.8656312023878318, -0.755404408355003, - -0.6178762444026438, -0.4580167776572274, -0.2816035507792589, -0.09501250983763744, - 0.09501250983763744, 0.2816035507792589, 0.4580167776572274, 0.6178762444026438, - 0.755404408355003, 0.8656312023878318, 0.9445750230732326, 0.9894009349916499 }; - - static double weight[16] = { - 0.02715245941175406, 0.06225352393864778, 0.0951585116824929, 0.1246289712555339, - 0.1495959888165768, 0.1691565193950026, 0.1826034150449236, 0.1894506104550685, - 0.1894506104550685, 0.1826034150449236, 0.1691565193950026, 0.1495959888165768, - 0.1246289712555339, 0.0951585116824929, 0.06225352393864778, 0.02715245941175406 }; - - for (int i = 0;i < 16;i++) - { - for (int j = 0;j < 16;j++) - { - double theta = ((s1 + e1) + (e1 - s1) * absc[i]) / 2; - - result += weight[i] * weight[j] * sin(theta) * - this->Ylm_Gaunt( this->get_lm_index(L1, m1), 16 * i + j) * - this->Ylm_Gaunt( this->get_lm_index(L2, m2), 16 * i + j) * - this->Ylm_Gaunt( this->get_lm_index(L, m), 16 * i + j); - } - } - - result *= ((e1 - s1) / 2) * ((e2 - s2) / 2); - ModuleBase::timer::end("ORB_gaunt_table", "Cal_Gaunt_single"); - return result; + ModuleBase::timer::start("ORB_gaunt_table", "Cal_Gaunt_single"); + if ((L1 - L2 - L) % 2 != 0) + { + return 0.0; + } + + double result = 0.0; + static double absc[16] = { + -0.9894009349916499, -0.9445750230732326, -0.8656312023878318, -0.755404408355003, + -0.6178762444026438, -0.4580167776572274, -0.2816035507792589, -0.09501250983763744, + 0.09501250983763744, 0.2816035507792589, 0.4580167776572274, 0.6178762444026438, + 0.755404408355003, 0.8656312023878318, 0.9445750230732326, 0.9894009349916499 }; + + static double weight[16] = { + 0.02715245941175406, 0.06225352393864778, 0.0951585116824929, 0.1246289712555339, + 0.1495959888165768, 0.1691565193950026, 0.1826034150449236, 0.1894506104550685, + 0.1894506104550685, 0.1826034150449236, 0.1691565193950026, 0.1495959888165768, + 0.1246289712555339, 0.0951585116824929, 0.06225352393864778, 0.02715245941175406 }; + + for (int i = 0;i < 16;i++) + { + for (int j = 0;j < 16;j++) + { + double theta = ((s1 + e1) + (e1 - s1) * absc[i]) / 2; + + result += weight[i] * weight[j] * sin(theta) * + this->Ylm_Gaunt( this->get_lm_index(L1, m1), 16 * i + j) * + this->Ylm_Gaunt( this->get_lm_index(L2, m2), 16 * i + j) * + this->Ylm_Gaunt( this->get_lm_index(L, m), 16 * i + j); + } + } + + result *= ((e1 - s1) / 2) * ((e2 - s2) / 2); + ModuleBase::timer::end("ORB_gaunt_table", "Cal_Gaunt_single"); + return result; } */ /* void ORB_gaunt_table::init_Ylm_Gaunt ( - const int &lmax, + const int &lmax, const double &s1, - const double &e1, + const double &e1, const double &s2, - const double &e2 + const double &e2 ) { - ModuleBase::TITLE("ORB_gaunt_table", "init_Ylm_Gaunt"); - ModuleBase::timer::start("ORB_gaunt_table", "inite_Ylm_Gaunt"); + ModuleBase::TITLE("ORB_gaunt_table", "init_Ylm_Gaunt"); + ModuleBase::timer::start("ORB_gaunt_table", "inite_Ylm_Gaunt"); - const int nlm = (2*lmax+1) * (2*lmax+1); + const int nlm = (2*lmax+1) * (2*lmax+1); - static double absc[16] = { - -0.9894009349916499, -0.9445750230732326, -0.8656312023878318, -0.755404408355003, - -0.6178762444026438, -0.4580167776572274, -0.2816035507792589, -0.09501250983763744, - 0.09501250983763744, 0.2816035507792589, 0.4580167776572274, 0.6178762444026438, - 0.755404408355003, 0.8656312023878318, 0.9445750230732326, 0.9894009349916499 }; + static double absc[16] = { + -0.9894009349916499, -0.9445750230732326, -0.8656312023878318, -0.755404408355003, + -0.6178762444026438, -0.4580167776572274, -0.2816035507792589, -0.09501250983763744, + 0.09501250983763744, 0.2816035507792589, 0.4580167776572274, 0.6178762444026438, + 0.755404408355003, 0.8656312023878318, 0.9445750230732326, 0.9894009349916499 }; - //initialization of ylm_map + //initialization of ylm_map - ModuleBase::Vector3 g_gaunt[256]; + ModuleBase::Vector3 g_gaunt[256]; - this->Ylm_Gaunt.create(nlm , 256); + this->Ylm_Gaunt.create(nlm , 256); - for (int i = 0; i < 16; i++) - { - for (int j = 0; j < 16; j++) - { - const double theta = ((s1 + e1) + (e1 - s1) * absc[i]) / 2; - const double phi = ((s2 + e2) + (e2 - s2) * absc[j]) / 2; - ModuleBase::Vector3 u(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta)); - g_gaunt[16*i+j] = u; - } - } + for (int i = 0; i < 16; i++) + { + for (int j = 0; j < 16; j++) + { + const double theta = ((s1 + e1) + (e1 - s1) * absc[i]) / 2; + const double phi = ((s2 + e2) + (e2 - s2) * absc[j]) / 2; + ModuleBase::Vector3 u(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta)); + g_gaunt[16*i+j] = u; + } + } - ModuleBase::YlmReal::Ylm_Real(nlm, 256, &g_gaunt[0], this->Ylm_Gaunt); + ModuleBase::YlmReal::Ylm_Real(nlm, 256, &g_gaunt[0], this->Ylm_Gaunt); - ModuleBase::timer::start("ORB_gaunt_table", "init_Ylm_Gaunt"); - return; + ModuleBase::timer::start("ORB_gaunt_table", "init_Ylm_Gaunt"); + return; } */ @@ -159,294 +159,294 @@ void ORB_gaunt_table::init_Ylm_Gaunt ///effective pointers int ORB_gaunt_table::EP_EL(const int& L) { - if(L % 2 == 0) return (L+2) * (L+4) * (3*L*L+14*L+24) / 192; - else return (L+1) * (L+3) * (L+5) * (3*L+5) / 192; + if(L % 2 == 0) return (L+2) * (L+4) * (3*L*L+14*L+24) / 192; + else return (L+1) * (L+3) * (L+5) * (3*L+5) / 192; } int ORB_gaunt_table::index_func ( - const int& l1, - const int& l2, - const int& l3, - const int& m3 + const int& l1, + const int& l2, + const int& l3, + const int& m3 ) { - const int aux1 = l1*(l1*l1*l1+6*l1*l1+11*l1+6)/24; - const int aux2 = l2*(l2*l2+3*l2+2)/6; - const int aux3 = l3*(l3+1)/2; - - return aux1 + aux2 + aux3 + m3; + const int aux1 = l1*(l1*l1*l1+6*l1*l1+11*l1+6)/24; + const int aux2 = l2*(l2*l2+3*l2+2)/6; + const int aux3 = l3*(l3+1)/2; + + return aux1 + aux2 + aux3 + m3; } void ORB_gaunt_table::init_Gaunt_CH(const int& Lmax) { - ModuleBase::TITLE("ORB_gaunt_table","init_Gaunt_CH"); - ModuleBase::timer::start("ORB_gaunt_table","init_Gaunt_CH"); - - this->Lmax_Gaunt_CH = Lmax; - int L = 2*Lmax + 1; - int Eff_Np = this->EP_EL(L); - - ModuleBase::Memory::record("ORB::Gaunt_CH", sizeof(double) * Eff_Np * 30); - - int ic1 = 0; - for(int l1 = 0; l1 <= L; l1++) - { - for(int l2 = 0; l2 <= l1; l2++) - { - for(int l3 = 0; l3 <= l2; l3++) - { - for(int m3 = 0; m3 <= l3; m3++) - { - int idx = index_func(l1, l2, l3, m3); - assert(ic1 == idx); - - int l_sum = l1 + l2 + l3; - if((l_sum % 2 == 0) && (l2 + l3 >= l1)) - { - int uplmt_m2 = l1 - m3 > l2 ? l2 : l1 - m3; - - int ic2 = 0; - for(int m2 = -l2; m2 <= uplmt_m2; m2++) - { - //m1 + m2 + m3 == 0 - int m1 = -m2 - m3; - assert(std::abs(m1) <= l1); - - Gaunt_CH[ic1][ic2] = Calc_Gaunt_CH(l1, m1, l2, m2, l3, m3); - ic2++; - } - } - - ic1++; - }// m3 - }// l3 - }// l2 - } // l1 - - ModuleBase::timer::end("ORB_gaunt_table","init_Gaunt_CH"); - return; + ModuleBase::TITLE("ORB_gaunt_table","init_Gaunt_CH"); + ModuleBase::timer::start("ORB_gaunt_table","init_Gaunt_CH"); + + this->Lmax_Gaunt_CH = Lmax; + int L = 2*Lmax + 1; + int Eff_Np = this->EP_EL(L); + + ModuleBase::Memory::record("ORB::Gaunt_CH", sizeof(double) * Eff_Np * 30); + + int ic1 = 0; + for(int l1 = 0; l1 <= L; l1++) + { + for(int l2 = 0; l2 <= l1; l2++) + { + for(int l3 = 0; l3 <= l2; l3++) + { + for(int m3 = 0; m3 <= l3; m3++) + { + int idx = index_func(l1, l2, l3, m3); + assert(ic1 == idx); + + int l_sum = l1 + l2 + l3; + if((l_sum % 2 == 0) && (l2 + l3 >= l1)) + { + int uplmt_m2 = l1 - m3 > l2 ? l2 : l1 - m3; + + int ic2 = 0; + for(int m2 = -l2; m2 <= uplmt_m2; m2++) + { + //m1 + m2 + m3 == 0 + int m1 = -m2 - m3; + assert(std::abs(m1) <= l1); + + Gaunt_CH[ic1][ic2] = Calc_Gaunt_CH(l1, m1, l2, m2, l3, m3); + ic2++; + } + } + + ic1++; + }// m3 + }// l3 + }// l2 + } // l1 + + ModuleBase::timer::end("ORB_gaunt_table","init_Gaunt_CH"); + return; } //using wigner 3j expression double ORB_gaunt_table::Calc_Gaunt_CH ( - const int& l1, - const int& m1, - const int& l2, - const int& m2, - const int& l3, - const int& m3 + const int& l1, + const int& m1, + const int& l2, + const int& m2, + const int& l3, + const int& m3 ) { - ModuleBase::timer::start("ORB_gaunt_table","Calc_Gaunt_CH"); - - double fac = sqrt((2*l1+1) * (2*l2+1) * (2*l3+1) / ModuleBase::FOUR_PI); + ModuleBase::timer::start("ORB_gaunt_table","Calc_Gaunt_CH"); + + double fac = sqrt((2*l1+1) * (2*l2+1) * (2*l3+1) / ModuleBase::FOUR_PI); - int g = (l1+l2+l3)/2; - double triangle_f = sqrt( Fact(l1+l2-l3) * Fact(l1-l2+l3) * Fact(-l1+l2+l3) / Fact(2*g+1) ); + int g = (l1+l2+l3)/2; + double triangle_f = sqrt( Fact(l1+l2-l3) * Fact(l1-l2+l3) * Fact(-l1+l2+l3) / Fact(2*g+1) ); - fac *= pow(-1.0, g) * triangle_f * Fact(g) / Fact(g-l1) / Fact(g-l2) / Fact(g-l3); + fac *= pow(-1.0, g) * triangle_f * Fact(g) / Fact(g-l1) / Fact(g-l2) / Fact(g-l3); - double aux1 = sqrt(Fact(l1+m1) * Fact(l1-m1) * Fact(l2+m2) * Fact(l2-m2) * Fact(l3+m3) * Fact(l3-m3)); + double aux1 = sqrt(Fact(l1+m1) * Fact(l1-m1) * Fact(l2+m2) * Fact(l2-m2) * Fact(l3+m3) * Fact(l3-m3)); - int kmin = 0; + int kmin = 0; int kmax = 0; - - kmin = (l2-l3-m1) > (l1-l3+m2) ? (l2-l3-m1) : (l1-l3+m2); - kmin = kmin > 0 ? kmin : 0; - - kmax = (l1+l2-l3) > (l1-m1) ? (l1-m1) : (l1+l2-l3); - kmax = kmax > (l2+m2) ? (l2+m2) : kmax; - - double aux2 = 0.0; - for(int k = kmin; k <= kmax; k++) - { - aux2 += pow(-1.0, k) / Fact(k) / Fact(l1+l2-l3-k) / Fact(l1-m1-k) / Fact(l2+m2-k) - / Fact(l3-l2+m1+k) / Fact(l3-l1+k-m2); - } - - ModuleBase::timer::end("ORB_gaunt_table","Calc_Gaunt_CH"); - return fac * pow(-1.0, l1-l2-m3) * triangle_f * aux1 * aux2; + + kmin = (l2-l3-m1) > (l1-l3+m2) ? (l2-l3-m1) : (l1-l3+m2); + kmin = kmin > 0 ? kmin : 0; + + kmax = (l1+l2-l3) > (l1-m1) ? (l1-m1) : (l1+l2-l3); + kmax = kmax > (l2+m2) ? (l2+m2) : kmax; + + double aux2 = 0.0; + for(int k = kmin; k <= kmax; k++) + { + aux2 += pow(-1.0, k) / Fact(k) / Fact(l1+l2-l3-k) / Fact(l1-m1-k) / Fact(l2+m2-k) + / Fact(l3-l2+m1+k) / Fact(l3-l1+k-m2); + } + + ModuleBase::timer::end("ORB_gaunt_table","Calc_Gaunt_CH"); + return fac * pow(-1.0, l1-l2-m3) * triangle_f * aux1 * aux2; } - + double ORB_gaunt_table::Get_Gaunt_CH ( - const int& l1, - const int& m1, - const int& l2, - const int& m2, - const int& l3, - const int& m3 + const int& l1, + const int& m1, + const int& l2, + const int& m2, + const int& l3, + const int& m3 ) { - assert(l1 >= 0); - assert(l2 >= 0); - assert(l3 >= 0); - - int l_sum = l1 + l2 + l3; - - if(l_sum % 2 == 1) return 0.0; - - if(std::abs(m1) > l1 || std::abs(m2) > l2 || std::abs(m3) > l3) return 0.0; - - if( (m1 + m2 + m3) != 0) return 0.0; + assert(l1 >= 0); + assert(l2 >= 0); + assert(l3 >= 0); + + int l_sum = l1 + l2 + l3; + + if(l_sum % 2 == 1) return 0.0; + + if(std::abs(m1) > l1 || std::abs(m2) > l2 || std::abs(m3) > l3) return 0.0; + + if( (m1 + m2 + m3) != 0) return 0.0; int L1 = l1; - int M1 = m1; - int L2 = l2; + int M1 = m1; + int L2 = l2; int M2 = m2; - Swap(L1, M1, L2, M2); - - int L3 = l3; - int M3 = m3; - Swap(L1, M1, L3, M3); - - Swap(L2, M2, L3, M3); - - if(M3 < 0) - { - M1 = -M1; - M2 = -M2; - M3 = -M3; - } - - int ic1 = index_func(L1, L2, L3, M3); - int ic2 = M2 + L2; - - try - { - return Gaunt_CH.at(ic1).at(ic2); - } // Peize Lin add 2016-08-26 - catch( std::out_of_range ) - { - return 0; - } + Swap(L1, M1, L2, M2); + + int L3 = l3; + int M3 = m3; + Swap(L1, M1, L3, M3); + + Swap(L2, M2, L3, M3); + + if(M3 < 0) + { + M1 = -M1; + M2 = -M2; + M3 = -M3; + } + + int ic1 = index_func(L1, L2, L3, M3); + int ic2 = M2 + L2; + + try + { + return Gaunt_CH.at(ic1).at(ic2); + } // Peize Lin add 2016-08-26 + catch( std::out_of_range ) + { + return 0; + } } - + ///Input value, ///m1, m2, m3 are restricted within 0 to 2l+1, ///and should be transformed first. double ORB_gaunt_table::Get_Gaunt_SH ( - const int& l1, - const int& mm1, - const int& l2, - const int& mm2, - const int& l3, - const int& mm3 + const int& l1, + const int& mm1, + const int& l2, + const int& mm2, + const int& l3, + const int& mm3 ) { - - //Tranform M index - int m1 = Index_M(mm1); - int m2 = Index_M(mm2); - int m3 = Index_M(mm3); - - if(m1 >= 0 && m2 >= 0 && m3 >= 0) - { - if(m1 * m2 * m3 > 0) - { - if(m1 == m2 + m3) return pow(-1.0, m1) * sqrt(2.0) / 2.0 - * Get_Gaunt_CH(l1, -m1, l2, m2, l3, m3); - else if(m2 == m1 + m3) return pow(-1.0, m2) * sqrt(2.0) / 2.0 - * Get_Gaunt_CH(l1, m1, l2, -m2, l3, m3); - else if(m3 == m1 + m2) return pow(-1.0, m3) * sqrt(2.0) / 2.0 - * Get_Gaunt_CH(l1, m1, l2, m2, l3, -m3); - else return 0.0; - } - else - { - if(m1 == 0 && m2 == 0 && m3 == 0) return Get_Gaunt_CH(l1, 0, l2, 0, l3, 0); - else if( (m1 == 0) && (m2 == m3)) return pow(-1.0, m2) * Get_Gaunt_CH(l1, 0, l2, m2, l3, -m2); - else if( (m2 == 0) && (m3 == m1)) return pow(-1.0, m1) * Get_Gaunt_CH(l2, 0, l1, m1, l3, -m1); - else if( (m3 == 0) && (m1 == m2)) return pow(-1.0, m2) * Get_Gaunt_CH(l3, 0, l2, m2, l1, -m2); - else return 0.0; - } - } - else - { - if(m1 >= 0 && m2 < 0 && m3 < 0) - { - if((m1 == 0) && (m2 == m3)) return pow(-1.0, m2) * Get_Gaunt_CH(l1, 0, l2, m2, l3, -m2); - else if(m1 > 0 && (m2 == m1+m3)) - return pow(-1.0, m3) * sqrt(2.0) / 2.0 * Get_Gaunt_CH(l1, m1, l2, -m2, l3, m3); - else if(m1 > 0 && (m3 == m1+m2)) - return pow(-1.0, m2) * sqrt(2.0) / 2.0 * Get_Gaunt_CH(l1, m1, l2, m2, l3, -m3); - else if(m1 > 0 && ( (m1+m2+m3) == 0)) - return pow(-1.0, m1+1) * sqrt(2.0) / 2.0 * Get_Gaunt_CH(l1, m1, l2, m2, l3, m3); - else return 0.0; - } - else if(m2 >= 0 && m1 < 0 && m3 < 0) - { - if((m2 == 0) && (m1 == m3)) return pow(-1.0, m1) * Get_Gaunt_CH(l2, 0, l1, m1, l3, -m1); - else if(m2 > 0 && (m1 == (m2 + m3))) - return pow(-1.0, m3) * sqrt(2.0) / 2.0 * Get_Gaunt_CH(l2, m2, l1, -m1, l3, m3); - else if(m2 > 0 && (m3 == (m2 + m1))) - return pow(-1.0, m1) * sqrt(2.0) / 2.0 * Get_Gaunt_CH(l2, m2, l1, m1, l3, -m3); - else if(m2 > 0 && ((m1+m2+m3) == 0)) - return pow(-1.0, m2+1) * sqrt(2.0) / 2.0 * Get_Gaunt_CH(l2, m2, l1, m1, l3, m3); - else return 0.0; - - } - else if(m3 >= 0 && m1 < 0 && m2 < 0) - { - if((m3 == 0) && (m1 == m2)) return pow(-1.0, m1) * Get_Gaunt_CH(l3, 0, l1, m1, l2, -m1); - else if(m3 > 0 && (m1 == m3+m2)) - return pow(-1.0, m2) * sqrt(2.0) / 2.0 * Get_Gaunt_CH(l3, m3, l1, -m1, l2, m2); - else if(m3 > 0 && (m2 == m3+m1)) - return pow(-1.0, m1) * sqrt(2.0) / 2.0 * Get_Gaunt_CH(l3, m3, l1, m1, l2, -m2); - else if(m3 > 0 && ( (m1+m2+m3) == 0)) - return pow(-1.0, m3+1) * sqrt(2.0) / 2.0 * Get_Gaunt_CH(l3, m3, l1, m1, l2, m2); - else return 0.0; - } - else return 0.0; - } + + //Tranform M index + int m1 = Index_M(mm1); + int m2 = Index_M(mm2); + int m3 = Index_M(mm3); + + if(m1 >= 0 && m2 >= 0 && m3 >= 0) + { + if(m1 * m2 * m3 > 0) + { + if(m1 == m2 + m3) return pow(-1.0, m1) * sqrt(2.0) / 2.0 + * Get_Gaunt_CH(l1, -m1, l2, m2, l3, m3); + else if(m2 == m1 + m3) return pow(-1.0, m2) * sqrt(2.0) / 2.0 + * Get_Gaunt_CH(l1, m1, l2, -m2, l3, m3); + else if(m3 == m1 + m2) return pow(-1.0, m3) * sqrt(2.0) / 2.0 + * Get_Gaunt_CH(l1, m1, l2, m2, l3, -m3); + else return 0.0; + } + else + { + if(m1 == 0 && m2 == 0 && m3 == 0) return Get_Gaunt_CH(l1, 0, l2, 0, l3, 0); + else if( (m1 == 0) && (m2 == m3)) return pow(-1.0, m2) * Get_Gaunt_CH(l1, 0, l2, m2, l3, -m2); + else if( (m2 == 0) && (m3 == m1)) return pow(-1.0, m1) * Get_Gaunt_CH(l2, 0, l1, m1, l3, -m1); + else if( (m3 == 0) && (m1 == m2)) return pow(-1.0, m2) * Get_Gaunt_CH(l3, 0, l2, m2, l1, -m2); + else return 0.0; + } + } + else + { + if(m1 >= 0 && m2 < 0 && m3 < 0) + { + if((m1 == 0) && (m2 == m3)) return pow(-1.0, m2) * Get_Gaunt_CH(l1, 0, l2, m2, l3, -m2); + else if(m1 > 0 && (m2 == m1+m3)) + return pow(-1.0, m3) * sqrt(2.0) / 2.0 * Get_Gaunt_CH(l1, m1, l2, -m2, l3, m3); + else if(m1 > 0 && (m3 == m1+m2)) + return pow(-1.0, m2) * sqrt(2.0) / 2.0 * Get_Gaunt_CH(l1, m1, l2, m2, l3, -m3); + else if(m1 > 0 && ( (m1+m2+m3) == 0)) + return pow(-1.0, m1+1) * sqrt(2.0) / 2.0 * Get_Gaunt_CH(l1, m1, l2, m2, l3, m3); + else return 0.0; + } + else if(m2 >= 0 && m1 < 0 && m3 < 0) + { + if((m2 == 0) && (m1 == m3)) return pow(-1.0, m1) * Get_Gaunt_CH(l2, 0, l1, m1, l3, -m1); + else if(m2 > 0 && (m1 == (m2 + m3))) + return pow(-1.0, m3) * sqrt(2.0) / 2.0 * Get_Gaunt_CH(l2, m2, l1, -m1, l3, m3); + else if(m2 > 0 && (m3 == (m2 + m1))) + return pow(-1.0, m1) * sqrt(2.0) / 2.0 * Get_Gaunt_CH(l2, m2, l1, m1, l3, -m3); + else if(m2 > 0 && ((m1+m2+m3) == 0)) + return pow(-1.0, m2+1) * sqrt(2.0) / 2.0 * Get_Gaunt_CH(l2, m2, l1, m1, l3, m3); + else return 0.0; + + } + else if(m3 >= 0 && m1 < 0 && m2 < 0) + { + if((m3 == 0) && (m1 == m2)) return pow(-1.0, m1) * Get_Gaunt_CH(l3, 0, l1, m1, l2, -m1); + else if(m3 > 0 && (m1 == m3+m2)) + return pow(-1.0, m2) * sqrt(2.0) / 2.0 * Get_Gaunt_CH(l3, m3, l1, -m1, l2, m2); + else if(m3 > 0 && (m2 == m3+m1)) + return pow(-1.0, m1) * sqrt(2.0) / 2.0 * Get_Gaunt_CH(l3, m3, l1, m1, l2, -m2); + else if(m3 > 0 && ( (m1+m2+m3) == 0)) + return pow(-1.0, m3+1) * sqrt(2.0) / 2.0 * Get_Gaunt_CH(l3, m3, l1, m1, l2, m2); + else return 0.0; + } + else return 0.0; + } } double ORB_gaunt_table::Fact(const int& n) { - double val = 1.0; - for(int i = 1; i <= n; i++) - { - val *= static_cast(i); - } - return val; + double val = 1.0; + for(int i = 1; i <= n; i++) + { + val *= static_cast(i); + } + return val; } void ORB_gaunt_table::Swap( - int& l1, - int& m1, - int& l2, - int & m2) + int& l1, + int& m1, + int& l2, + int & m2) { - int tmp1=0, tmp2=0; - if(l1 >= l2) return; - else - { - tmp1 = l2; - tmp2 = m2; - - l2 = l1; - m2 = m1; - - l1 = tmp1; - m1 = tmp2; - } - return; + int tmp1=0, tmp2=0; + if(l1 >= l2) return; + else + { + tmp1 = l2; + tmp2 = m2; + + l2 = l1; + m2 = m1; + + l1 = tmp1; + m1 = tmp2; + } + return; } int ORB_gaunt_table::Index_M(const int& m) { - if(m % 2 == 0) return (- m / 2); - else return ((m+1) / 2); + if(m % 2 == 0) return (- m / 2); + else return ((m+1) / 2); } diff --git a/source/source_basis/module_ao/orb_gaunt_table.h b/source/source_basis/module_ao/orb_gaunt_table.h index 0e9aefdb701..a9d9b5c2f7e 100644 --- a/source/source_basis/module_ao/orb_gaunt_table.h +++ b/source/source_basis/module_ao/orb_gaunt_table.h @@ -7,126 +7,126 @@ class ORB_gaunt_table { - public: - - ORB_gaunt_table(); - ~ORB_gaunt_table(); - - /** - * Method 2: - * using WIgner 3j symbols - * \f$ Y(l1,m1), Y(l2,m2), Y(L,M) \f$ - */ - - void init_Gaunt_CH(const int& Lmax); - double Get_Gaunt_CH( - const int& l1, - const int& m1, - const int& l2, - const int& m2, - const int& l3, - const int& m3 ); - - ///M defined here are restricted within 0 to 2l+1 - /// - ///should be transformed first - double Get_Gaunt_SH( - const int& l1, - const int& mm1, - const int& l2, - const int& mm2, - const int& l3, - const int& mm3 ); - - double Calc_Gaunt_CH( - const int& l1, - const int& m1, - const int& l2, - const int& m2, - const int& l3, - const int& m3 ); - - - /** - * MEthod 2 - * - * Directly Calculate integral of - * \f$ S(l_1,m_1), S(l_2,m_2), S(L,M) \f$ - */ - ModuleBase::realArray Gaunt_Coefficients; - - /// (1) Make Ylm_Gaunt Table. - ///---------------- + public: + + ORB_gaunt_table(); + ~ORB_gaunt_table(); + + /** + * Method 2: + * using WIgner 3j symbols + * \f$ Y(l1,m1), Y(l2,m2), Y(L,M) \f$ + */ + + void init_Gaunt_CH(const int& Lmax); + double Get_Gaunt_CH( + const int& l1, + const int& m1, + const int& l2, + const int& m2, + const int& l3, + const int& m3 ); + + ///M defined here are restricted within 0 to 2l+1 + /// + ///should be transformed first + double Get_Gaunt_SH( + const int& l1, + const int& mm1, + const int& l2, + const int& mm2, + const int& l3, + const int& mm3 ); + + double Calc_Gaunt_CH( + const int& l1, + const int& m1, + const int& l2, + const int& m2, + const int& l3, + const int& m3 ); + + + /** + * MEthod 2 + * + * Directly Calculate integral of + * \f$ S(l_1,m_1), S(l_2,m_2), S(L,M) \f$ + */ + ModuleBase::realArray Gaunt_Coefficients; + + /// (1) Make Ylm_Gaunt Table. + ///---------------- /* - void init_Ylm_Gaunt( - const int &lmax, - const double &s1, - const double &e1, - const double &s2, - const double &e2); + void init_Ylm_Gaunt( + const int &lmax, + const double &s1, + const double &e1, + const double &s2, + const double &e2); */ - /// (2) Use Ylm_Gaunt to calculate Gaunt Coefficinets element - ///------ + /// (2) Use Ylm_Gaunt to calculate Gaunt Coefficinets element + ///------ /* - double Cal_Gaunt_single( - const int &l1, - const int &m1, - const int &l2, - const int &m2, - const int &l, - const int &m, - const double &s1, - const double &e1, - const double &s2, - const double &e2); + double Cal_Gaunt_single( + const int &l1, + const int &m1, + const int &l2, + const int &m2, + const int &l, + const int &m, + const double &s1, + const double &e1, + const double &s2, + const double &e2); */ - /// (3) Make the whole Gaunt Coefficients table - /// ------------------------------------ - void init_Gaunt(const int &lmax); - - static inline int get_lm_index(const int l, const int m) - { - return l*l+m; - } - - static int Index_M(const int& m); - - int get_Lmax_Gaunt_Coefficients() const { return Lmax_Gaunt_Coefficients; } - int get_Lmax_Gaunt_CH() const { return Lmax_Gaunt_CH; } - - private: - - // Index Function - // Yu's mehtod - // Peize Lin delete void ModuleBase::GlobalFunc::ZEROS(); 2016-08-26 - - //int P_EL(const int& L); - - int EP_EL(const int& L); - - int index_func( - const int& l1, - const int& l2, - const int& l3, - const int& m3 ); - - double Fact(const int& n); - - void Swap( - int& l1, - int& m1, - int& l2, - int& m2 ); - - //2*Lmax+1 - std::map> Gaunt_CH; // Peize Lin update 2016-08-26 - - //direct integral - ModuleBase::matrix Ylm_Gaunt; - - int Lmax_Gaunt_Coefficients = -1; - int Lmax_Gaunt_CH = -1; + /// (3) Make the whole Gaunt Coefficients table + /// ------------------------------------ + void init_Gaunt(const int &lmax); + + static inline int get_lm_index(const int l, const int m) + { + return l*l+m; + } + + static int Index_M(const int& m); + + int get_Lmax_Gaunt_Coefficients() const { return Lmax_Gaunt_Coefficients; } + int get_Lmax_Gaunt_CH() const { return Lmax_Gaunt_CH; } + + private: + + // Index Function + // Yu's mehtod + // Peize Lin delete void ModuleBase::GlobalFunc::ZEROS(); 2016-08-26 + + //int P_EL(const int& L); + + int EP_EL(const int& L); + + int index_func( + const int& l1, + const int& l2, + const int& l3, + const int& m3 ); + + double Fact(const int& n); + + void Swap( + int& l1, + int& m1, + int& l2, + int& m2 ); + + //2*Lmax+1 + std::map> Gaunt_CH; // Peize Lin update 2016-08-26 + + //direct integral + ModuleBase::matrix Ylm_Gaunt; + + int Lmax_Gaunt_Coefficients = -1; + int Lmax_Gaunt_CH = -1; }; #endif diff --git a/source/source_basis/module_ao/orb_nonlocal.cpp b/source/source_basis/module_ao/orb_nonlocal.cpp index 45398deef34..03fcee98624 100644 --- a/source/source_basis/module_ao/orb_nonlocal.cpp +++ b/source/source_basis/module_ao/orb_nonlocal.cpp @@ -3,66 +3,66 @@ Numerical_Nonlocal::Numerical_Nonlocal() { - //make std::pair of new and delete - //question remains - this->type = 0; - this->lmax = 0; - this->rcut_max = 0.0; - this->Proj = new Numerical_Nonlocal_Lm[1]; - this->nproj = -1; - //zhengdy-soc, for optimize nonlocal part + //make std::pair of new and delete + //question remains + this->type = 0; + this->lmax = 0; + this->rcut_max = 0.0; + this->Proj = new Numerical_Nonlocal_Lm[1]; + this->nproj = -1; + //zhengdy-soc, for optimize nonlocal part } Numerical_Nonlocal::~Numerical_Nonlocal() { - delete[] Proj; + delete[] Proj; } void Numerical_Nonlocal::set_type_info ( - const int& type_in, - const std::string& label_in, - const std::string& type_ps_in, - const int& lmax_in, - const int& nproj_in, - const Numerical_Nonlocal_Lm* Proj_in + const int& type_in, + const std::string& label_in, + const std::string& type_ps_in, + const int& lmax_in, + const int& nproj_in, + const Numerical_Nonlocal_Lm* Proj_in ) { - //ModuleBase::TITLE("Numerical_Nonlocal","set_type_info"); + //ModuleBase::TITLE("Numerical_Nonlocal","set_type_info"); - this->type = type_in; - this->label = label_in; - this->type_ps = type_ps_in; + this->type = type_in; + this->label = label_in; + this->type_ps = type_ps_in; - if (lmax_in < -1 || lmax_in > 20) - { - ModuleBase::WARNING_QUIT("Numerical_Nonlocal", "bad input of lmax : should be between -1 and 20"); - } + if (lmax_in < -1 || lmax_in > 20) + { + ModuleBase::WARNING_QUIT("Numerical_Nonlocal", "bad input of lmax : should be between -1 and 20"); + } - this->lmax = lmax_in; + this->lmax = lmax_in; - this->nproj = nproj_in; + this->nproj = nproj_in; - assert(nproj >= 0); + assert(nproj >= 0); //---------------------------------------------------------- // EXPLAIN : non_local pseudopotential projector for each l //---------------------------------------------------------- - //only store radial function - delete[] Proj; - this->Proj = nullptr; - this->Proj = new Numerical_Nonlocal_Lm[this->nproj]; + //only store radial function + delete[] Proj; + this->Proj = nullptr; + this->Proj = new Numerical_Nonlocal_Lm[this->nproj]; - for (int p1=0; p1Proj[p1] = Proj_in[p1]; - } + for (int p1=0; p1Proj[p1] = Proj_in[p1]; + } - this->rcut_max = 0.0; - for(int p1=0; p1rcut_max = std::max( this->Proj[p1].getRcut(), rcut_max ); - } - return; + this->rcut_max = 0.0; + for(int p1=0; p1rcut_max = std::max( this->Proj[p1].getRcut(), rcut_max ); + } + return; } diff --git a/source/source_basis/module_ao/orb_nonlocal.h b/source/source_basis/module_ao/orb_nonlocal.h index 79f1dbef61a..28ec152fb27 100644 --- a/source/source_basis/module_ao/orb_nonlocal.h +++ b/source/source_basis/module_ao/orb_nonlocal.h @@ -21,49 +21,49 @@ class Numerical_Nonlocal { public: - Numerical_Nonlocal(); - ~Numerical_Nonlocal(); + Numerical_Nonlocal(); + ~Numerical_Nonlocal(); - // This class owns the raw Proj array; copying it would alias the buffer - // and cause double free, so copy semantics are explicitly forbidden. - Numerical_Nonlocal(const Numerical_Nonlocal&) = delete; - Numerical_Nonlocal& operator=(const Numerical_Nonlocal&) = delete; + // This class owns the raw Proj array; copying it would alias the buffer + // and cause double free, so copy semantics are explicitly forbidden. + Numerical_Nonlocal(const Numerical_Nonlocal&) = delete; + Numerical_Nonlocal& operator=(const Numerical_Nonlocal&) = delete; - const int& getLmax() const { return this->lmax; } + const int& getLmax() const { return this->lmax; } - const int& getType() const { return this->type; } + const int& getType() const { return this->type; } - const std::string& getLabel() const { return this->label; } + const std::string& getLabel() const { return this->label; } - const std::string& getType_ps() const { return this->type_ps; } + const std::string& getType_ps() const { return this->type_ps; } - void set_type_info( - const int& type_in, - const std::string& label_in, - const std::string& type_ps_in, - const int& lmax_in, - const int& nproj_in, - const Numerical_Nonlocal_Lm* ps_orbital_in); + void set_type_info( + const int& type_in, + const std::string& label_in, + const std::string& type_ps_in, + const int& lmax_in, + const int& nproj_in, + const Numerical_Nonlocal_Lm* ps_orbital_in); - Numerical_Nonlocal_Lm* Proj = nullptr; ///< length: nproj(only store radial function ) + Numerical_Nonlocal_Lm* Proj = nullptr; ///< length: nproj(only store radial function ) - const double& get_rcut_max() const { return rcut_max; } + const double& get_rcut_max() const { return rcut_max; } const int& get_nproj() const { return nproj; } - private: - - std::string label=""; /// renew(); + label = ""; + index_atom_type = 0; + angular_momentum_l = 0; + index_proj = 0; + + nr = 1; + nk = 1; + + rcut = 0.0; + kcut = 0.0; + dk = 0.0; + + nr_uniform = 1; + dr_uniform = -1.0; + this->renew(); } Numerical_Nonlocal_Lm::~Numerical_Nonlocal_Lm() { - this->freemem(); + this->freemem(); } void Numerical_Nonlocal_Lm::renew() { - assert(nr_uniform>0); - assert(nr>0); - assert(nk>0); - this->r_radial = new double[nr]; - this->rab = new double[nr]; - this->beta_r = new double[nr]; - this->beta_uniform = new double[nr_uniform]; - this->dbeta_uniform = new double[nr_uniform]; - this->k_radial = new double[nk]; - this->beta_k = new double[nk]; - ModuleBase::GlobalFunc::ZEROS(r_radial, nr); - ModuleBase::GlobalFunc::ZEROS(rab, nr); - ModuleBase::GlobalFunc::ZEROS(beta_r, nr); - ModuleBase::GlobalFunc::ZEROS(beta_uniform, nr_uniform); - ModuleBase::GlobalFunc::ZEROS(dbeta_uniform, nr_uniform); - ModuleBase::GlobalFunc::ZEROS(k_radial, nk); - ModuleBase::GlobalFunc::ZEROS(beta_k, nk); + assert(nr_uniform>0); + assert(nr>0); + assert(nk>0); + this->r_radial = new double[nr]; + this->rab = new double[nr]; + this->beta_r = new double[nr]; + this->beta_uniform = new double[nr_uniform]; + this->dbeta_uniform = new double[nr_uniform]; + this->k_radial = new double[nk]; + this->beta_k = new double[nk]; + ModuleBase::GlobalFunc::ZEROS(r_radial, nr); + ModuleBase::GlobalFunc::ZEROS(rab, nr); + ModuleBase::GlobalFunc::ZEROS(beta_r, nr); + ModuleBase::GlobalFunc::ZEROS(beta_uniform, nr_uniform); + ModuleBase::GlobalFunc::ZEROS(dbeta_uniform, nr_uniform); + ModuleBase::GlobalFunc::ZEROS(k_radial, nk); + ModuleBase::GlobalFunc::ZEROS(beta_k, nk); } void Numerical_Nonlocal_Lm::freemem() { - delete[] this->r_radial; - delete[] this->rab; - delete[] this->beta_r; - delete[] this->beta_uniform; - delete[] this->dbeta_uniform; - delete[] this->k_radial; - delete[] this->beta_k; + delete[] this->r_radial; + delete[] this->rab; + delete[] this->beta_r; + delete[] this->beta_uniform; + delete[] this->dbeta_uniform; + delete[] this->k_radial; + delete[] this->beta_k; r_radial = nullptr; rab = nullptr; @@ -83,49 +83,49 @@ Numerical_Nonlocal_Lm& Numerical_Nonlocal_Lm::operator= const Numerical_Nonlocal_Lm & nol ) { - this->label = nol.label; - this->index_atom_type = nol.index_atom_type; - this->angular_momentum_l = nol.angular_momentum_l; + this->label = nol.label; + this->index_atom_type = nol.index_atom_type; + this->angular_momentum_l = nol.angular_momentum_l; this->index_proj = nol.index_proj; - this->nr = nol.nr; - this->nk = nol.nk; + this->nr = nol.nr; + this->nk = nol.nk; - this->nr_uniform = nol.nr_uniform; - this->dr_uniform = nol.dr_uniform; + this->nr_uniform = nol.nr_uniform; + this->dr_uniform = nol.dr_uniform; - this->rcut = nol.rcut; - this->kcut = nol.kcut; + this->rcut = nol.rcut; + this->kcut = nol.kcut; - this->dk = nol.dk; + this->dk = nol.dk; - this->freemem(); - this->renew(); + this->freemem(); + this->renew(); - for (int ir = 0; ir < nol.nr; ir++) - { - this->r_radial[ir] = nol.r_radial[ir]; - this->rab[ir] = nol.rab[ir]; - this->beta_r[ir] = nol.beta_r[ir]; - } + for (int ir = 0; ir < nol.nr; ir++) + { + this->r_radial[ir] = nol.r_radial[ir]; + this->rab[ir] = nol.rab[ir]; + this->beta_r[ir] = nol.beta_r[ir]; + } - for (int ir = 0; ir < nr_uniform; ir++) - { - this->beta_uniform[ir] = nol.beta_uniform[ir]; - this->dbeta_uniform[ir] = nol.dbeta_uniform[ir]; - } + for (int ir = 0; ir < nr_uniform; ir++) + { + this->beta_uniform[ir] = nol.beta_uniform[ir]; + this->dbeta_uniform[ir] = nol.dbeta_uniform[ir]; + } - for (int ik = 0; ik < nol.nk; ik++) - { - this->k_radial[ik] = nol.k_radial[ik]; - this->beta_k[ik] = nol.beta_k[ik]; - } + for (int ik = 0; ik < nol.nk; ik++) + { + this->k_radial[ik] = nol.k_radial[ik]; + this->beta_k[ik] = nol.beta_k[ik]; + } - return *this; + return *this; } void Numerical_Nonlocal_Lm::set_NL_proj( - const std::string &label_in, + const std::string &label_in, const int &index_atom_type_in, const int &angular_momentum_l_in, const int &nr_in, @@ -134,51 +134,51 @@ void Numerical_Nonlocal_Lm::set_NL_proj( const double *beta_r_in, const int &nk_in, const double &dk_in, - const double &dr_uniform_in) + const double &dr_uniform_in) { - this->label = label_in; - this->index_atom_type = index_atom_type_in; - - this->angular_momentum_l = angular_momentum_l_in; - assert(angular_momentum_l_in>=-1); // -1 means no angular momentum. - - this->dr_uniform = dr_uniform_in; - - this->nr = nr_in; - assert(nr_in>1 && nr_in <10000); - assert(nr%2!=0); + this->label = label_in; + this->index_atom_type = index_atom_type_in; + + this->angular_momentum_l = angular_momentum_l_in; + assert(angular_momentum_l_in>=-1); // -1 means no angular momentum. + + this->dr_uniform = dr_uniform_in; + + this->nr = nr_in; + assert(nr_in>1 && nr_in <10000); + assert(nr%2!=0); - this->rcut = r_radial_in[nr-1]; + this->rcut = r_radial_in[nr-1]; assert(rcut>=0.0); - this->nk = nk_in; - assert(nk%2!=0); + this->nk = nk_in; + assert(nk%2!=0); - this->dk = dk_in; - assert(dk>0.0); + this->dk = dk_in; + assert(dk>0.0); this->freemem(); this->renew(); - - for (int ir = 0; ir < nr; ir++) - { - this->r_radial[ir] = r_radial_in[ir]; - this->rab[ir] = rab_in[ir]; - this->beta_r[ir] = beta_r_in[ir]; - } - - for (int ik = 0; ik < nk; ik++) - { - this->k_radial[ik] = ik * this->dk; - } - this->kcut = (nk-1) * this->dk; - - // (1) extra the uniform mesh - //this->extra_uniform(dr_uniform); - // (2) get the beta_k - this->get_kradial(); - - return; + + for (int ir = 0; ir < nr; ir++) + { + this->r_radial[ir] = r_radial_in[ir]; + this->rab[ir] = rab_in[ir]; + this->beta_r[ir] = beta_r_in[ir]; + } + + for (int ik = 0; ik < nk; ik++) + { + this->k_radial[ik] = ik * this->dk; + } + this->kcut = (nk-1) * this->dk; + + // (1) extra the uniform mesh + //this->extra_uniform(dr_uniform); + // (2) get the beta_k + this->get_kradial(); + + return; } void Numerical_Nonlocal_Lm::get_kradial() @@ -200,7 +200,7 @@ void Numerical_Nonlocal_Lm::get_kradial() for (int ir = 0; ir < nr; ir++) { - // beta_r is beta*r; + // beta_r is beta*r; integrated_func[ir] = this->beta_r[ir] * this->r_radial[ir] * jl[ir]; } @@ -220,60 +220,60 @@ void Numerical_Nonlocal_Lm::get_kradial() void Numerical_Nonlocal_Lm::plot(const int &my_rank)const { - std::string orbital_type; - switch( this->angular_momentum_l ) - { - case 0: orbital_type = "s"; break; - case 1: orbital_type = "p"; break; - case 2: orbital_type = "d"; break; - case 3: orbital_type = "f"; break; - case 4: orbital_type = "g"; break; - default: ModuleBase::WARNING_QUIT("Numerical_Orbital_Lm::plot","Please check in functoin."); - } + std::string orbital_type; + switch( this->angular_momentum_l ) + { + case 0: orbital_type = "s"; break; + case 1: orbital_type = "p"; break; + case 2: orbital_type = "d"; break; + case 3: orbital_type = "f"; break; + case 4: orbital_type = "g"; break; + default: ModuleBase::WARNING_QUIT("Numerical_Orbital_Lm::plot","Please check in functoin."); + } #ifdef __NORMAL #else - if(my_rank==0) - { - std::stringstream ssr, ssk, ssru; - ssr << ModuleBase::get_global_out_dir() << this->label << "/" - << this->label << "-" << orbital_type << "-proj-r.dat"; - - ssk << ModuleBase::get_global_out_dir() << this->label << "/" - << this->label << "-" << orbital_type << "-proj-k.dat"; - - ssru << ModuleBase::get_global_out_dir() << this->label << "/" - << this->label << "-" << orbital_type << "-proj-ru.dat"; - - std::ofstream ofsr(ssr.str().c_str()); - std::ofstream ofsk(ssk.str().c_str()); - std::ofstream ofsru(ssru.str().c_str()); - - if (!ofsk || !ofsr || !ofsru) - { - ModuleBase::WARNING_QUIT("Numerical_Orbital_Lm::plot", "Can't open files!"); - } - - for (int i = 0; i < this->nr; i++) - { - ofsr << this->r_radial[i] << " " << this->beta_r[i] << std::endl; - } - - for (int i = 0; i < this->nk; i++) - { - ofsk << this->k_radial[i] << " " << this->beta_k[i] << std::endl; - } - - for (int i = 0; i < this->nr_uniform; i++) - { - ofsru << i * this->dr_uniform << " " << this->beta_uniform[i] << std::endl; - } - - ofsr.close(); - ofsk.close(); - ofsru.close(); - } + if(my_rank==0) + { + std::stringstream ssr, ssk, ssru; + ssr << ModuleBase::get_global_out_dir() << this->label << "/" + << this->label << "-" << orbital_type << "-proj-r.dat"; + + ssk << ModuleBase::get_global_out_dir() << this->label << "/" + << this->label << "-" << orbital_type << "-proj-k.dat"; + + ssru << ModuleBase::get_global_out_dir() << this->label << "/" + << this->label << "-" << orbital_type << "-proj-ru.dat"; + + std::ofstream ofsr(ssr.str().c_str()); + std::ofstream ofsk(ssk.str().c_str()); + std::ofstream ofsru(ssru.str().c_str()); + + if (!ofsk || !ofsr || !ofsru) + { + ModuleBase::WARNING_QUIT("Numerical_Orbital_Lm::plot", "Can't open files!"); + } + + for (int i = 0; i < this->nr; i++) + { + ofsr << this->r_radial[i] << " " << this->beta_r[i] << std::endl; + } + + for (int i = 0; i < this->nk; i++) + { + ofsk << this->k_radial[i] << " " << this->beta_k[i] << std::endl; + } + + for (int i = 0; i < this->nr_uniform; i++) + { + ofsru << i * this->dr_uniform << " " << this->beta_uniform[i] << std::endl; + } + + ofsr.close(); + ofsk.close(); + ofsru.close(); + } #endif - return; + return; } diff --git a/source/source_basis/module_ao/orb_nonlocal_lm.h b/source/source_basis/module_ao/orb_nonlocal_lm.h index 4a95d3aaca8..914683022e2 100644 --- a/source/source_basis/module_ao/orb_nonlocal_lm.h +++ b/source/source_basis/module_ao/orb_nonlocal_lm.h @@ -19,83 +19,83 @@ class NumericalNonlocalLmTest; class Numerical_Nonlocal_Lm { - /// the unit test drives freemem(), renew() and get_kradial() directly, and - /// reads label/kcut/index_proj/rab, which have no public accessor - friend class NumericalNonlocalLmTest; + /// the unit test drives freemem(), renew() and get_kradial() directly, and + /// reads label/kcut/index_proj/rab, which have no public accessor + friend class NumericalNonlocalLmTest; - public: + public: - double* beta_uniform = nullptr; - double* dbeta_uniform = nullptr; - int nr_uniform; - double dr_uniform; + double* beta_uniform = nullptr; + double* dbeta_uniform = nullptr; + int nr_uniform; + double dr_uniform; - public: + public: - Numerical_Nonlocal_Lm(); - ~Numerical_Nonlocal_Lm(); + Numerical_Nonlocal_Lm(); + ~Numerical_Nonlocal_Lm(); - const int& getL() const { return this->angular_momentum_l; } - const int& getType() const { return this->index_atom_type; } - const double& getRcut() const { return this->rcut; } + const int& getL() const { return this->angular_momentum_l; } + const int& getType() const { return this->index_atom_type; } + const double& getRcut() const { return this->rcut; } const int& getNr() const { return this->nr; } - const double* getRadial() const { return this->r_radial; } - const double& getRadial(const int &ir) const { return this->r_radial[ir]; } - const double* getBeta_r() const { return this->beta_r; } - const double& getBeta_r(const int &ir) const { return this->beta_r[ir]; } - - const double& getDk()const { return this->dk; } - const double* getKpoint()const { return this->k_radial; } - const double& getKpoint(const int &ik) const { return this->k_radial[ik]; } - const double* getBeta_k() const { return this->beta_k; } - const double& getBeta_k(const int &ik) const { return this->beta_k[ik]; } - - const int& getNk() const { return nk; } - const double& getDruniform() const { return dr_uniform; } - + const double* getRadial() const { return this->r_radial; } + const double& getRadial(const int &ir) const { return this->r_radial[ir]; } + const double* getBeta_r() const { return this->beta_r; } + const double& getBeta_r(const int &ir) const { return this->beta_r[ir]; } + + const double& getDk()const { return this->dk; } + const double* getKpoint()const { return this->k_radial; } + const double& getKpoint(const int &ik) const { return this->k_radial[ik]; } + const double* getBeta_k() const { return this->beta_k; } + const double& getBeta_k(const int &ik) const { return this->beta_k[ik]; } + + const int& getNk() const { return nk; } + const double& getDruniform() const { return dr_uniform; } + // enables deep copy - Numerical_Nonlocal_Lm& operator= (const Numerical_Nonlocal_Lm& nol ); - - void set_NL_proj( - const std::string &label, - const int &index_atom_type_in, - const int &angular_momentum_l_in, - const int &nr_in, - const double *rab_in, - const double *r_radial_in, - const double *beta_r_in, - const int &nk_in, - const double &dk_in, - const double &dr_uniform_in); - - void plot(const int &my_rank)const; - - private: - - void freemem(void); - void renew(void); - //void extra_uniform(const double &dr_uniform); - void get_kradial(void); - - std::string label; - int index_atom_type; - int angular_momentum_l; - int index_proj; - - int nr; - int nk; - - double rcut; - double kcut; - double dk; - - double* r_radial = nullptr; //points of r - double* k_radial = nullptr; - - double* rab = nullptr; - double* beta_r = nullptr; // |beta(r) * r> - double* beta_k = nullptr; + Numerical_Nonlocal_Lm& operator= (const Numerical_Nonlocal_Lm& nol ); + + void set_NL_proj( + const std::string &label, + const int &index_atom_type_in, + const int &angular_momentum_l_in, + const int &nr_in, + const double *rab_in, + const double *r_radial_in, + const double *beta_r_in, + const int &nk_in, + const double &dk_in, + const double &dr_uniform_in); + + void plot(const int &my_rank)const; + + private: + + void freemem(void); + void renew(void); + //void extra_uniform(const double &dr_uniform); + void get_kradial(void); + + std::string label; + int index_atom_type; + int angular_momentum_l; + int index_proj; + + int nr; + int nk; + + double rcut; + double kcut; + double dk; + + double* r_radial = nullptr; //points of r + double* k_radial = nullptr; + + double* rab = nullptr; + double* beta_r = nullptr; // |beta(r) * r> + double* beta_k = nullptr; }; #endif diff --git a/source/source_basis/module_ao/orb_read.h b/source/source_basis/module_ao/orb_read.h index bc46359f02d..f12772fad2b 100644 --- a/source/source_basis/module_ao/orb_read.h +++ b/source/source_basis/module_ao/orb_read.h @@ -16,10 +16,10 @@ class LCAO_Orbitals { - public: + public: - LCAO_Orbitals(); - ~LCAO_Orbitals(); + LCAO_Orbitals(); + ~LCAO_Orbitals(); void init( std::ofstream& ofs_in, @@ -39,98 +39,98 @@ class LCAO_Orbitals const int& my_rank ); - void Read_Orbitals( - std::ofstream &ofs_in, // mohan add 2021-05-07 - const int &ntype_in, - const int &lmax_in, - const bool &deepks_setorb, // mohan add 2021-04-25 - const int &out_mat_r, // mohan add 2021-04-26 - const bool &out_element_info, - const bool &force_flag, // mohan add 2021-05-07 - const int &my_rank); // mohan add 2021-04-26 + void Read_Orbitals( + std::ofstream &ofs_in, // mohan add 2021-05-07 + const int &ntype_in, + const int &lmax_in, + const bool &deepks_setorb, // mohan add 2021-04-25 + const int &out_mat_r, // mohan add 2021-04-26 + const bool &out_element_info, + const bool &force_flag, // mohan add 2021-05-07 + const int &my_rank); // mohan add 2021-04-26 - void Read_PAO( - std::ofstream &ofs_in, - const int& it, - const bool &out_element_info, - const bool &force_flag, // mohan add 2021-05-07 - const int& my_rank); // mohan add 2021-04-26 + void Read_PAO( + std::ofstream &ofs_in, + const int& it, + const bool &out_element_info, + const bool &force_flag, // mohan add 2021-05-07 + const int& my_rank); // mohan add 2021-04-26 - void Read_Descriptor( - std::ofstream &ofs_in, - const bool &out_element_info, - const bool &force_flag, // mohan add 2021-05-07 - const int &my_rank); //caoyu add 2020-3-16 + void Read_Descriptor( + std::ofstream &ofs_in, + const bool &out_element_info, + const bool &force_flag, // mohan add 2021-05-07 + const int &my_rank); //caoyu add 2020-3-16 #ifdef __MPI - void bcast_files(const int &ntype_in, const int &my_rank); + void bcast_files(const int &ntype_in, const int &my_rank); #endif - const double& get_ecutwfc() const {return ecutwfc;} - const int& get_kmesh() const{return kmesh;} - const double& get_dk() const {return dk;} - const double& get_dR() const {return dR;} - const double& get_Rmax() const {return Rmax;} - const int& get_lmax() const {return lmax;} - const int& get_lmax_d() const { return lmax_d; } /// cutoffs() const; - /// numerical atomic orbitals - Numerical_Orbital* Phi = nullptr; - - - //caoyu add 2021-3-10 - /// descriptor bases, saved as one-type atom orbital - Numerical_Orbital* Alpha = nullptr; - - // initialized in input.cpp - double ecutwfc; - double dk; - double dR; - double Rmax; - - double dr_uniform; - - // initalized in UnitCell - // assume ntype < 20. - bool read_in_flag; - std::vector orbital_file; - std::vector nonlocal_file; - std::string descriptor_file; //caoyu add 2020-3-16 + /// numerical atomic orbitals + Numerical_Orbital* Phi = nullptr; + + + //caoyu add 2021-3-10 + /// descriptor bases, saved as one-type atom orbital + Numerical_Orbital* Alpha = nullptr; + + // initialized in input.cpp + double ecutwfc; + double dk; + double dR; + double Rmax; + + double dr_uniform; + + // initalized in UnitCell + // assume ntype < 20. + bool read_in_flag; + std::vector orbital_file; + std::vector nonlocal_file; + std::string descriptor_file; //caoyu add 2020-3-16 private: - int ntype; // number of elements - int kmesh; // number of points on kmesh + int ntype; // number of elements + int kmesh; // number of points on kmesh - int lmax; - int nchimax; + int lmax; + int nchimax; - int lmax_d; //max l of descriptor orbitals - int nchimax_d; //max number of descriptor orbitals per l + int lmax_d; //max l of descriptor orbitals + int nchimax_d; //max number of descriptor orbitals per l - double rcutmax_Phi; //caoyu add 2021-05-24 + double rcutmax_Phi; //caoyu add 2021-05-24 - void read_orb_file( - std::ofstream &ofs_in, - std::ifstream &ifs, - const int &it, - int &lmax, - int &nchimax, - Numerical_Orbital* ao, - const bool &out_element_info, - const bool &force_flag, // mohan add 2021-05-07 - const int &my_rank); //caoyu add 2021-04-26 + void read_orb_file( + std::ofstream &ofs_in, + std::ifstream &ifs, + const int &it, + int &lmax, + int &nchimax, + Numerical_Orbital* ao, + const bool &out_element_info, + const bool &force_flag, // mohan add 2021-05-07 + const int &my_rank); //caoyu add 2021-04-26 friend class TwoCenterBundle; // for the sake of TwoCenterBundle::to_LCAO_Orbitals }; diff --git a/source/source_basis/module_ao/parallel_orbitals.h b/source/source_basis/module_ao/parallel_orbitals.h index aecde685b5a..048c2cd9df5 100644 --- a/source/source_basis/module_ao/parallel_orbitals.h +++ b/source/source_basis/module_ao/parallel_orbitals.h @@ -31,8 +31,8 @@ class Parallel_Orbitals : public Parallel_2D /// on all adjacent atoms-pairs(2D division) ///------------------------------------- int nnr=1; - std::vector nlocdim; - std::vector nlocstart; + std::vector nlocdim; + std::vector nlocstart; #ifdef __MPI int desc_wfc[9]; //for wfc, nlocal*nbands diff --git a/source/source_basis/module_nao/two_center_integrator.cpp b/source/source_basis/module_nao/two_center_integrator.cpp index 436f3885ed8..4c4e61abedd 100644 --- a/source/source_basis/module_nao/two_center_integrator.cpp +++ b/source/source_basis/module_nao/two_center_integrator.cpp @@ -29,7 +29,7 @@ void TwoCenterIntegrator::calculate(const int itype1, const int l2, const int izeta2, const int m2, - const ModuleBase::Vector3& vR, // R = R2 - R1 + const ModuleBase::Vector3& vR, // R = R2 - R1 double* out, double* grad_out, double* hess_out) const @@ -67,8 +67,8 @@ void TwoCenterIntegrator::calculate(const int itype1, // generate all necessary real (solid) spherical harmonics const int lmax = l1 + l2; - std::vector Rl_Y((lmax+1) * (lmax+1)); - std::vector grad_Rl_Y((lmax+1) * (lmax+1) * 3); + std::vector Rl_Y((lmax+1) * (lmax+1)); + std::vector grad_Rl_Y((lmax+1) * (lmax+1) * 3); std::vector> hess_Rl_Y; // R^l * Y is necessary anyway @@ -88,7 +88,7 @@ void TwoCenterIntegrator::calculate(const int itype1, // look up S/R^l, (d/dR)(S/R^l), and (d²/dR²)(S/R^l) from the radial table table_.lookup(itype1, l1, izeta1, itype2, l2, izeta2, l, R, S_by_Rl, d_S_by_Rl, d2_S_by_Rl); - for (int m = -l; m <= l; ++m) + for (int m = -l; m <= l; ++m) { double G = RealGauntTable::instance()(l1, l2, l, m1, m2, m); int lm_idx = ylm_index(l, m); @@ -150,7 +150,7 @@ void TwoCenterIntegrator::snap(const int itype1, const int izeta1, const int m1, const int itype2, - const ModuleBase::Vector3& vR, + const ModuleBase::Vector3& vR, const bool deriv, std::vector>& out) const { @@ -172,11 +172,11 @@ void TwoCenterIntegrator::snap(const int itype1, return; } - for(size_t i = 0; i < out.size(); ++i) - { - out[i].resize(num_ket); + for(size_t i = 0; i < out.size(); ++i) + { + out[i].resize(num_ket); std::fill(out[i].begin(), out[i].end(), 0.0); - } + } int index = 0; double tmp[3] = {0.0, 0.0, 0.0}; diff --git a/source/source_basis/module_nao/two_center_integrator.h b/source/source_basis/module_nao/two_center_integrator.h index 285ffe8728c..9955ef22551 100644 --- a/source/source_basis/module_nao/two_center_integrator.h +++ b/source/source_basis/module_nao/two_center_integrator.h @@ -97,7 +97,7 @@ class TwoCenterIntegrator const int l2, const int izeta2, const int m2, - const ModuleBase::Vector3& vR, // vR = R2 - R1 + const ModuleBase::Vector3& vR, // vR = R2 - R1 double* out = nullptr, double* grad_out = nullptr, double* hess_out = nullptr @@ -114,7 +114,7 @@ class TwoCenterIntegrator const int izeta1, const int m1, const int itype2, - const ModuleBase::Vector3& vR, // vR = R2 - R1 + const ModuleBase::Vector3& vR, // vR = R2 - R1 const bool deriv, std::vector>& out ) const; diff --git a/source/source_basis/module_pw/pw_basis.cpp b/source/source_basis/module_pw/pw_basis.cpp index 549fec8e5a4..a079a3bdd4c 100644 --- a/source/source_basis/module_pw/pw_basis.cpp +++ b/source/source_basis/module_pw/pw_basis.cpp @@ -85,42 +85,42 @@ void PW_Basis::getstartgr() } //--------------------------------------------- - // sum : starting plane of FFT box. - //--------------------------------------------- + // sum : starting plane of FFT box. + //--------------------------------------------- delete[] this->numg; this->numg = new int[poolnproc]; - delete[] this->startg; this->startg = new int[poolnproc]; - delete[] this->startr; this->startr = new int[poolnproc]; - delete[] this->numr; this->numr = new int[poolnproc]; + delete[] this->startg; this->startg = new int[poolnproc]; + delete[] this->startr; this->startr = new int[poolnproc]; + delete[] this->numr; this->numr = new int[poolnproc]; - // Each processor has a set of full sticks, - // 'rank_use' processor send a piece(npps[ip]) of these sticks(nst_per[rank_use]) - // to all the other processors in this pool - for (int ip = 0;ip < poolnproc; ++ip) + // Each processor has a set of full sticks, + // 'rank_use' processor send a piece(npps[ip]) of these sticks(nst_per[rank_use]) + // to all the other processors in this pool + for (int ip = 0;ip < poolnproc; ++ip) { this->numg[ip] = this->nst_per[poolrank] * this->numz[ip]; } - // Each processor in a pool send a piece of each stick(nst_per[ip]) to - // other processors in this pool - // rank_use processor receive datas in npps[rank_p] planes. - for (int ip = 0;ip < poolnproc; ++ip) + // Each processor in a pool send a piece of each stick(nst_per[ip]) to + // other processors in this pool + // rank_use processor receive datas in npps[rank_p] planes. + for (int ip = 0;ip < poolnproc; ++ip) { this->numr[ip] = this->nst_per[ip] * this->numz[poolrank]; } - // startg record the starting 'numg' position in each processor. - this->startg[0] = 0; - for (int ip = 1;ip < poolnproc; ++ip) + // startg record the starting 'numg' position in each processor. + this->startg[0] = 0; + for (int ip = 1;ip < poolnproc; ++ip) { this->startg[ip] = this->startg[ip-1] + this->numg[ip-1]; } - // startr record the starting 'numr' position - this->startr[0] = 0; - for (int ip = 1;ip < poolnproc; ++ip) + // startr record the starting 'numr' position + this->startr[0] = 0; + for (int ip = 1;ip < poolnproc; ++ip) { this->startr[ip] = this->startr[ip-1] + this->numr[ip-1]; } diff --git a/source/source_basis/module_pw/pw_basis.h b/source/source_basis/module_pw/pw_basis.h index 6a1f93c80d3..7a0638496f7 100644 --- a/source/source_basis/module_pw/pw_basis.h +++ b/source/source_basis/module_pw/pw_basis.h @@ -124,7 +124,7 @@ class PW_Basis //real space int nrxx=0; //num. of real space grids int *startz=nullptr; //startz[ip]: starting z plane in the ip-th proc. in current POOL_WORLD - int *numz=nullptr; //numz[ip]: num. of z planes in the ip-th proc. in current POOL_WORLD + int *numz=nullptr; //numz[ip]: num. of z planes in the ip-th proc. in current POOL_WORLD int *numg=nullptr; //numg[ip] : nst_per[poolrank] * numz[ip] int *numr=nullptr; //numr[ip] : numz[poolrank] * nst_per[ip] int *startg=nullptr; // startg[ip] = numg[ip-1] + startg[ip-1] @@ -136,7 +136,7 @@ class PW_Basis ModuleBase::Vector3 *gcar=nullptr; //G vectors in cartesian corrdinate double *gg=nullptr; // modulus (G^2) of G vectors [npw] //gg[ng]=ig[ng]*GGT*ig[ng]/(lat0*lat0)=g[ng]*g[ng] (/lat0*lat0) - // gg_global dimension: [cutgg_num_now] (save memory skill is used) + // gg_global dimension: [cutgg_num_now] (save memory skill is used) int ig_gge0=-1; //ig when gg == 0 //distribute plane waves and grids and set up fft @@ -239,8 +239,8 @@ class PW_Basis // FFT //=============================================== public: - // FFT dimensions for wave functions. - int fftnx=0, fftny=0, fftnz=0, fftnxyz=0, fftnxy=0; + // FFT dimensions for wave functions. + int fftnx=0, fftny=0, fftnz=0, fftnxyz=0, fftnxy=0; int nx=0, ny=0, nz=0, nxyz=0, nxy=0; // Gamma_only: fftny = int(ny/2)-1 , others: fftny = ny int liy=0, riy=0;// liy: the left edge of the pw ball; riy: the right edge of the pw ball in the y direction int lix=0, rix=0;// lix: the left edge of the pw ball; rix: the right edge of the pw ball in the x direction diff --git a/source/source_basis/module_pw/pw_basis_big.h b/source/source_basis/module_pw/pw_basis_big.h index 987af787b3f..db989530efc 100644 --- a/source/source_basis/module_pw/pw_basis_big.h +++ b/source/source_basis/module_pw/pw_basis_big.h @@ -113,8 +113,8 @@ class PW_Basis_Big : public PW_Basis_Sup this->latvec = latvec_in; this->omega = std::abs(latvec.Det()) * lat0 * lat0 * lat0; this->GT = latvec.Inverse(); - this->G = GT.Transpose(); - this->GGT = G * GT; + this->G = GT.Transpose(); + this->GGT = G * GT; //------------------------------------------------------------ //-------------------------init grids------------------------- @@ -174,45 +174,45 @@ class PW_Basis_Big : public PW_Basis_Sup // Find the minimal FFT box size the factors into the primes (2,3,5,7). for (int i = 0; i < 3; i++) { - int b = 0; + int b = 0; int n2 = 0; int n3 = 0; int n5 = 0; //int n7 = 0; bool done_factoring = false; - + // increase ibox[i] by 1 until it is totally factorizable by (2,3,5,7) do { - b = ibox[i]; + b = ibox[i]; - //n2 = n3 = n5 = n7 = 0; - n2 = n3 = n5 = 0; - done_factoring = false; + //n2 = n3 = n5 = n7 = 0; + n2 = n3 = n5 = 0; + done_factoring = false; if ((this->full_pw && this->full_pw_dim == 2) && b % 2 != 0) done_factoring = true; // full_pw_dim = 2 means FFT dimensions should be even. - while (!done_factoring) - { - if (b % 2 == 0 && (!this->full_pw || this->full_pw_dim != 1)) // full_pw_dim = 1 means FFT dimension should be odd. - { - n2++; - b /= 2; - continue; - } - if (b % 3 == 0) - { - n3++; - b /= 3; - continue; - } - if (b % 5 == 0) - { - n5++; - b /= 5; - continue; - } - //if (b%7==0) { n7++; b /= 7; continue; } - done_factoring = true; - } + while (!done_factoring) + { + if (b % 2 == 0 && (!this->full_pw || this->full_pw_dim != 1)) // full_pw_dim = 1 means FFT dimension should be odd. + { + n2++; + b /= 2; + continue; + } + if (b % 3 == 0) + { + n3++; + b /= 3; + continue; + } + if (b % 5 == 0) + { + n5++; + b /= 5; + continue; + } + //if (b%7==0) { n7++; b /= 7; continue; } + done_factoring = true; + } ibox[i] += 1; } while (b != 1); @@ -279,8 +279,8 @@ class PW_Basis_Big : public PW_Basis_Sup this->latvec = latvec_in; this->omega = std::abs(latvec.Det()) * lat0 * lat0 * lat0; this->GT = latvec.Inverse(); - this->G = GT.Transpose(); - this->GGT = G * GT; + this->G = GT.Transpose(); + this->GGT = G * GT; this->nx = nx_in; this->ny = ny_in; this->nz = nz_in; diff --git a/source/source_basis/module_pw/pw_basis_k_big.h b/source/source_basis/module_pw/pw_basis_k_big.h index 128c1d937d2..1b9177675d0 100644 --- a/source/source_basis/module_pw/pw_basis_k_big.h +++ b/source/source_basis/module_pw/pw_basis_k_big.h @@ -14,8 +14,8 @@ class PW_Basis_K_Big: public PW_Basis_K public: // combine [bx,by,bz] FFT grids into a big one - // typical values are bx=2, by=2, bz=2 - // nbx=nx/bx, nby=ny/by, nbz=nz/bz, + // typical values are bx=2, by=2, bz=2 + // nbx=nx/bx, nby=ny/by, nbz=nz/bz, // Note: this class can only use initgrids(lat0_in, latvec_in, PW_Basis_Big::nx, PW_Basis_Big::ny, PW_Basis_Big::nz)!!! PW_Basis_K_Big(){ bx = 1; diff --git a/source/source_basis/module_pw/pw_init.cpp b/source/source_basis/module_pw/pw_init.cpp index 08c676d39f3..5240d35b12d 100644 --- a/source/source_basis/module_pw/pw_init.cpp +++ b/source/source_basis/module_pw/pw_init.cpp @@ -33,8 +33,8 @@ void PW_Basis:: initgrids( this->latvec = latvec_in; this->omega = std::abs(latvec.Det()) * lat0 * lat0 * lat0; this->GT = latvec.Inverse(); - this->G = GT.Transpose(); - this->GGT = G * GT; + this->G = GT.Transpose(); + this->GGT = G * GT; //------------------------------------------------------------ //-------------------------init grids------------------------- @@ -92,45 +92,45 @@ void PW_Basis:: initgrids( // Find the minimal FFT box size the factors into the primes (2,3,5,7). for (int i = 0; i < 3; i++) { - int b = 0; + int b = 0; int n2 = 0; int n3 = 0; int n5 = 0; //int n7 = 0; bool done_factoring = false; - + // increase ibox[i] by 1 until it is totally factorizable by (2,3,5,7) do { - b = ibox[i]; + b = ibox[i]; - //n2 = n3 = n5 = n7 = 0; - n2 = n3 = n5 = 0; - done_factoring = false; + //n2 = n3 = n5 = n7 = 0; + n2 = n3 = n5 = 0; + done_factoring = false; if ((this->full_pw && this->full_pw_dim == 2) && b % 2 != 0) done_factoring = true; // full_pw_dim = 2 means FFT dimensions should be even. - while (!done_factoring) - { - if (b % 2 == 0 && (!this->full_pw || this->full_pw_dim != 1)) // full_pw_dim = 1 means FFT dimension should be odd. - { - n2++; - b /= 2; - continue; - } - if (b % 3 == 0) - { - n3++; - b /= 3; - continue; - } - if (b % 5 == 0) - { - n5++; - b /= 5; - continue; - } - //if (b%7==0) { n7++; b /= 7; continue; } - done_factoring = true; - } + while (!done_factoring) + { + if (b % 2 == 0 && (!this->full_pw || this->full_pw_dim != 1)) // full_pw_dim = 1 means FFT dimension should be odd. + { + n2++; + b /= 2; + continue; + } + if (b % 3 == 0) + { + n3++; + b /= 3; + continue; + } + if (b % 5 == 0) + { + n5++; + b /= 5; + continue; + } + //if (b%7==0) { n7++; b /= 7; continue; } + done_factoring = true; + } ibox[i] += 1; } while (b != 1); @@ -164,8 +164,8 @@ void PW_Basis:: initgrids( this->latvec = latvec_in; this->omega = std::abs(latvec.Det()) * lat0 * lat0 * lat0; this->GT = latvec.Inverse(); - this->G = GT.Transpose(); - this->GGT = G * GT; + this->G = GT.Transpose(); + this->GGT = G * GT; this->nx = nx_in; this->ny = ny_in; this->nz = nz_in; diff --git a/source/source_cell/cal_ux.cpp b/source/source_cell/cal_ux.cpp index 06d7b0558a7..80201310323 100644 --- a/source/source_cell/cal_ux.cpp +++ b/source/source_cell/cal_ux.cpp @@ -22,10 +22,10 @@ void cal_ux(UnitCell& ucell, const int nspin) { ucell.magnet.lsign_ = false; ModuleBase::GlobalFunc::ZEROS(ucell.magnet.ux_, 3); - for (int it = 0; it < ucell.ntype; it++) - { - for (int ia = 0; ia < ucell.atoms[it].na; ia++) - { + for (int it = 0; it < ucell.ntype; it++) + { + for (int ia = 0; ia < ucell.atoms[it].na; ia++) + { // m_loc_: local magnetization vector for each atom amag = pow(ucell.atoms[it].m_loc_[ia].x, 2) + pow(ucell.atoms[it].m_loc_[ia].y, 2) @@ -33,61 +33,61 @@ void cal_ux(UnitCell& ucell, const int nspin) { // find the first atom (it,ia) whose magnetism is not zero // compute ux - if (amag > absolute_mag_thr) - { - ucell.magnet.ux_[0] = ucell.atoms[it].m_loc_[ia].x; - ucell.magnet.ux_[1] = ucell.atoms[it].m_loc_[ia].y; - ucell.magnet.ux_[2] = ucell.atoms[it].m_loc_[ia].z; + if (amag > absolute_mag_thr) + { + ucell.magnet.ux_[0] = ucell.atoms[it].m_loc_[ia].x; + ucell.magnet.ux_[1] = ucell.atoms[it].m_loc_[ia].y; + ucell.magnet.ux_[2] = ucell.atoms[it].m_loc_[ia].z; - starting_it = it; - starting_ia = ia; + starting_it = it; + starting_ia = ia; - ucell.magnet.lsign_ = true; - break; - } - } + ucell.magnet.lsign_ = true; + break; + } + } // if any atom has magnetism, then break the for iteration - if (ucell.magnet.lsign_) - { - break; - } - } + if (ucell.magnet.lsign_) + { + break; + } + } // whether the initial magnetizations is parallel - for (int it = starting_it; it < ucell.ntype; it++) - { - for (int ia = 0; ia < ucell.atoms[it].na; ia++) - { - if (it > starting_it || ia > starting_ia) - { - ucell.magnet.lsign_ - = ucell.magnet.lsign_ - && judge_parallel(ucell.magnet.ux_, ucell.atoms[it].m_loc_[ia]); - } - } - } + for (int it = starting_it; it < ucell.ntype; it++) + { + for (int ia = 0; ia < ucell.atoms[it].na; ia++) + { + if (it > starting_it || ia > starting_ia) + { + ucell.magnet.lsign_ + = ucell.magnet.lsign_ + && judge_parallel(ucell.magnet.ux_, ucell.atoms[it].m_loc_[ia]); + } + } + } // if all of the atoms have the same parallel magnetism direction, // then set the direction to a unit vector - if (ucell.magnet.lsign_) - { - uxmod = pow(ucell.magnet.ux_[0], 2) - + pow(ucell.magnet.ux_[1], 2) - + pow(ucell.magnet.ux_[2], 2); + if (ucell.magnet.lsign_) + { + uxmod = pow(ucell.magnet.ux_[0], 2) + + pow(ucell.magnet.ux_[1], 2) + + pow(ucell.magnet.ux_[2], 2); - if (uxmod < absolute_mag_thr) - { - ModuleBase::WARNING_QUIT("unitcell::cal_ux", "wrong uxmod"); - } + if (uxmod < absolute_mag_thr) + { + ModuleBase::WARNING_QUIT("unitcell::cal_ux", "wrong uxmod"); + } // reset the magnetism for each direction - for (int i = 0; i < 3; i++) - { - ucell.magnet.ux_[i] *= 1 / sqrt(uxmod); - } - } - return; + for (int i = 0; i < 3; i++) + { + ucell.magnet.ux_[i] *= 1 / sqrt(uxmod); + } + } + return; } bool judge_parallel(double a[3], ModuleBase::Vector3 b) { diff --git a/source/source_cell/cal_wfc.cpp b/source/source_cell/cal_wfc.cpp index bd9b2022ff4..b6307e5fc9e 100644 --- a/source/source_cell/cal_wfc.cpp +++ b/source/source_cell/cal_wfc.cpp @@ -133,38 +133,38 @@ namespace unitcell void cal_natomwfc(std::ofstream& log,int& natomwfc,const int ntype,const Atom* atoms,const int nspin) { natomwfc = 0; - for (int it = 0; it < ntype; it++) - { - //============================ - // Use pseudo-atomic orbitals - //============================ - int tmp = 0; - for (int l = 0; l < atoms[it].ncpp.nchi; l++) - { - if (atoms[it].ncpp.oc[l] >= 0) - { - if (nspin == 4) - { - if (atoms[it].ncpp.has_so) - { - tmp += 2 * atoms[it].ncpp.lchi[l]; - if (fabs(atoms[it].ncpp.jchi[l] - atoms[it].ncpp.lchi[l] - 0.5)< 1e-6) - { - tmp += 2; - } - } else - { - tmp += 2 * (2 * atoms[it].ncpp.lchi[l] + 1); - } - } else - { - tmp += 2 * atoms[it].ncpp.lchi[l] + 1; - } - } - } - natomwfc += tmp * atoms[it].na; - } - ModuleBase::GlobalFunc::OUT(log, "Number of pseudo atomic orbitals", natomwfc); - return; + for (int it = 0; it < ntype; it++) + { + //============================ + // Use pseudo-atomic orbitals + //============================ + int tmp = 0; + for (int l = 0; l < atoms[it].ncpp.nchi; l++) + { + if (atoms[it].ncpp.oc[l] >= 0) + { + if (nspin == 4) + { + if (atoms[it].ncpp.has_so) + { + tmp += 2 * atoms[it].ncpp.lchi[l]; + if (fabs(atoms[it].ncpp.jchi[l] - atoms[it].ncpp.lchi[l] - 0.5)< 1e-6) + { + tmp += 2; + } + } else + { + tmp += 2 * (2 * atoms[it].ncpp.lchi[l] + 1); + } + } else + { + tmp += 2 * atoms[it].ncpp.lchi[l] + 1; + } + } + } + natomwfc += tmp * atoms[it].na; + } + ModuleBase::GlobalFunc::OUT(log, "Number of pseudo atomic orbitals", natomwfc); + return; } } diff --git a/source/source_cell/module_symmetry/symm_rho.cpp b/source/source_cell/module_symmetry/symm_rho.cpp index 52f208d03dc..cbada24b38f 100644 --- a/source/source_cell/module_symmetry/symm_rho.cpp +++ b/source/source_cell/module_symmetry/symm_rho.cpp @@ -5,109 +5,109 @@ using namespace ModuleSymmetry; namespace { - // ------------------------------------------------------------------------ - // Rotating reciprocal-space FFT-grid vector (with PBC) - // The rotated vector is returned via ii, jj, kk. - // ------------------------------------------------------------------------ - //rotate function (different from real space, without scaling gmatrix) - static inline void rotate_recip(const ModuleBase::Matrix3& g, const ModuleBase::Vector3& g0, int& ii, int& jj, int& kk, - const int& nx, const int& ny, const int& nz) - { - ii = int(g.e11 * g0.x + g.e21 * g0.y + g.e31 * g0.z) ; - if (ii < 0) - { - ii += 10 * nx; - } - ii = ii%nx; - jj = int(g.e12 * g0.x + g.e22 * g0.y + g.e32 * g0.z) ; - if (jj < 0) - { - jj += 10 * ny; - } - jj = jj%ny; - kk = int(g.e13 * g0.x + g.e23 * g0.y + g.e33 * g0.z); - if (kk < 0) - { - kk += 10 * nz; - } - kk = kk%nz; - return; - } - - // ------------------------------------------------------------------------ - // Trying to group fft grids first. - // It iterates over each FFT-grid point and checks if it is within the - // PW-sphere. If it is, put all the FFT-grid points connected by the - // rotation operation into one group( the index is stored in int(*table_xyz)). - // The code marks the point as processed to avoid redundant calculations - // by using int* symflag. - // This grouping is purely spatial (depends only on kgmatrix/invmap and the - // FFT-grid geometry), so it is shared between rhog_symmetry and rhog_symmetry_nspin4; - // the differing spin/phase accumulation happens after this call. - // ------------------------------------------------------------------------ - static void group_fft_grids(const int& nrotk, const ModuleBase::Matrix3* kgmatrix, const std::vector& invmap, - int* ixyz2ipw, const int& nx, const int& ny, const int& nz, - const int& fftnx, const int& fftny, const int& fftnz, const bool gamma_only_pw, - int* symflag, int (*isymflag)[48], int (*table_xyz)[48], int* count_xyz, int& group_index) - { - ModuleBase::timer::start("Symmetry","group_fft_grids"); - for (int i = 0; i< fftnx; ++i) - { - //tmp variable - ModuleBase::Vector3 tmp_gdirect0(0, 0, 0); - tmp_gdirect0.x=(i>int(nx/2)+1)?(i-nx):i; - for (int j = 0; j< fftny; ++j) - { - tmp_gdirect0.y=(j>int(ny/2)+1)?(j-ny):j; - for (int k = 0; k< fftnz; ++k) - { - int ixyz0=(i*fftny+j)*fftnz+k; - if (symflag[ixyz0] == -1) - { - int ipw0=ixyz2ipw[ixyz0]; - //if a fft-grid is not in pw-sphere, just do not consider it. - if (ipw0 == -1) { - continue; - } - tmp_gdirect0.z=(k>int(nz/2)+1)?(k-nz):k; - int rot_count=0; - for (int isym = 0; isym < nrotk; ++isym) - { - if (invmap[isym] < 0 || invmap[isym] > nrotk) { continue; } - //tmp variables - int ii, jj, kk=0; - rotate_recip(kgmatrix[invmap[isym]], tmp_gdirect0, ii, jj, kk, nx, ny, nz); - if(ii>=fftnx || jj>=fftny || kk>= fftnz) - { - if(!gamma_only_pw) - { - std::cout << " ROTATE OUT OF FFT-GRID IN RHOG_SYMMETRY !" << std::endl; - ModuleBase::QUIT(); - } - // for gamma_only_pw, just do not consider this rotation. - continue; - } - int ixyz=(ii*fftny+jj)*fftnz+kk; - //fft-grid index to (ip, ig) - int ipw=ixyz2ipw[ixyz]; - if(ipw==-1) //not in pw-sphere - { - continue; //else, just skip it - } - symflag[ixyz] = group_index; - isymflag[group_index][rot_count] = invmap[isym]; - table_xyz[group_index][rot_count] = ixyz; - ++rot_count; - assert(rot_count <= nrotk); - count_xyz[group_index] = rot_count; - } - group_index++; - } - } - } - } - ModuleBase::timer::end("Symmetry","group_fft_grids"); - } + // ------------------------------------------------------------------------ + // Rotating reciprocal-space FFT-grid vector (with PBC) + // The rotated vector is returned via ii, jj, kk. + // ------------------------------------------------------------------------ + //rotate function (different from real space, without scaling gmatrix) + static inline void rotate_recip(const ModuleBase::Matrix3& g, const ModuleBase::Vector3& g0, int& ii, int& jj, int& kk, + const int& nx, const int& ny, const int& nz) + { + ii = int(g.e11 * g0.x + g.e21 * g0.y + g.e31 * g0.z) ; + if (ii < 0) + { + ii += 10 * nx; + } + ii = ii%nx; + jj = int(g.e12 * g0.x + g.e22 * g0.y + g.e32 * g0.z) ; + if (jj < 0) + { + jj += 10 * ny; + } + jj = jj%ny; + kk = int(g.e13 * g0.x + g.e23 * g0.y + g.e33 * g0.z); + if (kk < 0) + { + kk += 10 * nz; + } + kk = kk%nz; + return; + } + + // ------------------------------------------------------------------------ + // Trying to group fft grids first. + // It iterates over each FFT-grid point and checks if it is within the + // PW-sphere. If it is, put all the FFT-grid points connected by the + // rotation operation into one group( the index is stored in int(*table_xyz)). + // The code marks the point as processed to avoid redundant calculations + // by using int* symflag. + // This grouping is purely spatial (depends only on kgmatrix/invmap and the + // FFT-grid geometry), so it is shared between rhog_symmetry and rhog_symmetry_nspin4; + // the differing spin/phase accumulation happens after this call. + // ------------------------------------------------------------------------ + static void group_fft_grids(const int& nrotk, const ModuleBase::Matrix3* kgmatrix, const std::vector& invmap, + int* ixyz2ipw, const int& nx, const int& ny, const int& nz, + const int& fftnx, const int& fftny, const int& fftnz, const bool gamma_only_pw, + int* symflag, int (*isymflag)[48], int (*table_xyz)[48], int* count_xyz, int& group_index) + { + ModuleBase::timer::start("Symmetry","group_fft_grids"); + for (int i = 0; i< fftnx; ++i) + { + //tmp variable + ModuleBase::Vector3 tmp_gdirect0(0, 0, 0); + tmp_gdirect0.x=(i>int(nx/2)+1)?(i-nx):i; + for (int j = 0; j< fftny; ++j) + { + tmp_gdirect0.y=(j>int(ny/2)+1)?(j-ny):j; + for (int k = 0; k< fftnz; ++k) + { + int ixyz0=(i*fftny+j)*fftnz+k; + if (symflag[ixyz0] == -1) + { + int ipw0=ixyz2ipw[ixyz0]; + //if a fft-grid is not in pw-sphere, just do not consider it. + if (ipw0 == -1) { + continue; + } + tmp_gdirect0.z=(k>int(nz/2)+1)?(k-nz):k; + int rot_count=0; + for (int isym = 0; isym < nrotk; ++isym) + { + if (invmap[isym] < 0 || invmap[isym] > nrotk) { continue; } + //tmp variables + int ii, jj, kk=0; + rotate_recip(kgmatrix[invmap[isym]], tmp_gdirect0, ii, jj, kk, nx, ny, nz); + if(ii>=fftnx || jj>=fftny || kk>= fftnz) + { + if(!gamma_only_pw) + { + std::cout << " ROTATE OUT OF FFT-GRID IN RHOG_SYMMETRY !" << std::endl; + ModuleBase::QUIT(); + } + // for gamma_only_pw, just do not consider this rotation. + continue; + } + int ixyz=(ii*fftny+jj)*fftnz+kk; + //fft-grid index to (ip, ig) + int ipw=ixyz2ipw[ixyz]; + if(ipw==-1) //not in pw-sphere + { + continue; //else, just skip it + } + symflag[ixyz] = group_index; + isymflag[group_index][rot_count] = invmap[isym]; + table_xyz[group_index][rot_count] = ixyz; + ++rot_count; + assert(rot_count <= nrotk); + count_xyz[group_index] = rot_count; + } + group_index++; + } + } + } + } + ModuleBase::timer::end("Symmetry","group_fft_grids"); + } } // namespace void Symmetry::rho_symmetry( double *rho, @@ -336,41 +336,41 @@ void Symmetry::rhog_symmetry_nspin4(std::complex* rhogtot_x, std::comple const double* trs_inv, const ModuleBase::Matrix3* kgmatrix_in, const ModuleBase::Vector3* gtrans_in, const int nop) { - // Operation set: default = the nrotk unitary members; - // the nspin=4 magnetic caller passes the full Shubnikov list from density_sym_ops(). - // `trs_inv` is the time-reversal sign of each operation: Theta reverses the magnetization, - // so an antiunitary element contributes m -> -W(g) m. - const ModuleBase::Matrix3* kgmatrix_use = (kgmatrix_in != nullptr) ? kgmatrix_in : this->kgmatrix; - const ModuleBase::Vector3* gtrans_use = (gtrans_in != nullptr) ? gtrans_in : this->gtrans; - const int nrot_use = (nop > 0) ? nop : this->nrotk; - std::vector trs_inv_default; - if (trs_inv == nullptr) { trs_inv_default.assign(nrot_use, 1.0); } - const double* trs_invp = (trs_inv != nullptr) ? trs_inv : trs_inv_default.data(); - ModuleBase::timer::start("Symmetry","rhog_symmetry_nspin4"); - // The grouping of FFT grid points into symmetry-connected orbits is purely spatial and - // therefore identical to rhog_symmetry. Only the accumulation/write-back is changed: - // the three spin components are mixed by W(g) (rotated to the orbit-representative frame - // with W(g)^T on the way in, and back with W(g) on the way out), exactly as the scalar - // version uses the phase factor gphase. + // Operation set: default = the nrotk unitary members; + // the nspin=4 magnetic caller passes the full Shubnikov list from density_sym_ops(). + // `trs_inv` is the time-reversal sign of each operation: Theta reverses the magnetization, + // so an antiunitary element contributes m -> -W(g) m. + const ModuleBase::Matrix3* kgmatrix_use = (kgmatrix_in != nullptr) ? kgmatrix_in : this->kgmatrix; + const ModuleBase::Vector3* gtrans_use = (gtrans_in != nullptr) ? gtrans_in : this->gtrans; + const int nrot_use = (nop > 0) ? nop : this->nrotk; + std::vector trs_inv_default; + if (trs_inv == nullptr) { trs_inv_default.assign(nrot_use, 1.0); } + const double* trs_invp = (trs_inv != nullptr) ? trs_inv : trs_inv_default.data(); + ModuleBase::timer::start("Symmetry","rhog_symmetry_nspin4"); + // The grouping of FFT grid points into symmetry-connected orbits is purely spatial and + // therefore identical to rhog_symmetry. Only the accumulation/write-back is changed: + // the three spin components are mixed by W(g) (rotated to the orbit-representative frame + // with W(g)^T on the way in, and back with W(g) on the way out), exactly as the scalar + // version uses the phase factor gphase. const int nxyz = fftnx*fftny*fftnz; assert(nxyz>0); - int* symflag = new int[nxyz]; - int(*isymflag)[48] = new int[nxyz][48]; - int(*table_xyz)[48] = new int[nxyz][48]; - int* count_xyz = new int[nxyz]; + int* symflag = new int[nxyz]; + int(*isymflag)[48] = new int[nxyz][48]; + int(*table_xyz)[48] = new int[nxyz][48]; + int* count_xyz = new int[nxyz]; - for (int i = 0; i < nxyz; i++) - { - symflag[i] = -1; - } - int group_index = 0; + for (int i = 0; i < nxyz; i++) + { + symflag[i] = -1; + } + int group_index = 0; - assert(nrot_use >0 ); - assert(nrot_use <=48 ); + assert(nrot_use >0 ); + assert(nrot_use <=48 ); - //map the gmatrix to inv + //map the gmatrix to inv std::vectorinvmap(nrot_use, -1); this->gmatrix_invmap(kgmatrix_use, nrot_use, invmap.data()); @@ -383,110 +383,110 @@ void Symmetry::rhog_symmetry_nspin4(std::complex* rhogtot_x, std::comple #ifdef _OPENMP #pragma omp parallel for schedule(static) #endif - for (int g_index = 0; g_index < group_index; g_index++) - { - int *ipw_record = new int[nrot_use]; - int *ixyz_record = new int[nrot_use]; - int *sym_record = new int[nrot_use]; - std::complex* gphase_record = new std::complex [nrot_use]; - // orbit-representative-frame spin vector accumulated over the symmetry operations - std::complex sum_x(0, 0), sum_y(0, 0), sum_z(0, 0); - int rot_count=0; - - for (int c_index = 0; c_index < count_xyz[g_index]; ++c_index) - { - int ixyz0 = table_xyz[g_index][c_index]; - int ipw0 = ixyz2ipw[ixyz0]; - - if (symflag[ixyz0] == g_index) - { - int k = ixyz0%fftnz; - int j = ((ixyz0-k)/fftnz)%fftny; - int i = ((ixyz0-k)/fftnz-j)/fftny; - - ModuleBase::Vector3 tmp_gdirect_double(0.0, 0.0, 0.0); - tmp_gdirect_double.x=static_cast((i>int(nx/2)+1)?(i-nx):i); - tmp_gdirect_double.y=static_cast((j>int(ny/2)+1)?(j-ny):j); - tmp_gdirect_double.z=static_cast((k>int(nz/2)+1)?(k-nz):k); - - tmp_gdirect_double = tmp_gdirect_double * ModuleBase::TWO_PI; - - double cos_arg = 0.0, sin_arg = 0.0; - double arg_gtrans = tmp_gdirect_double * gtrans_use[isymflag[g_index][c_index]]; - - std::complex phase_gtrans (ModuleBase::libm::cos(arg_gtrans), - ModuleBase::libm::sin(arg_gtrans)); - - for (int ipt = 0;ipt < ((ModuleSymmetry::Symmetry::pricell_loop) ? this->ncell : 1);++ipt) - { - double arg = tmp_gdirect_double * ptrans[ipt]; - double tmp_cos = 0.0, tmp_sin = 0.0; - ModuleBase::libm::sincos(arg, &tmp_sin, &tmp_cos); - cos_arg += tmp_cos; - sin_arg += tmp_sin; - } - - cos_arg/=static_cast(ncell); - sin_arg/=static_cast(ncell); - - if (equal(cos_arg, 0.0) && equal(sin_arg, 0.0)) - { - continue; - } - - std::complex gphase(cos_arg, sin_arg); - gphase = phase_gtrans * gphase; - - if (equal(gphase.real(), 1.0) && equal(gphase.imag(), 0)) - { - gphase = std::complex(1.0, 0.0); - } - - // pull this orbit member back to the representative frame: multiply by gphase - // (removes the translation/phase, as in the scalar version) then by W(g)^T. - const int isym = isymflag[g_index][c_index]; - const ModuleBase::Matrix3& W = wspin[isym]; - const std::complex vx = rhogtot_x[ipw0] * gphase; - const std::complex vy = rhogtot_y[ipw0] * gphase; - const std::complex vz = rhogtot_z[ipw0] * gphase; - const double trs_sign = trs_invp[isym]; - sum_x += trs_sign * (W.e11 * vx + W.e21 * vy + W.e31 * vz); // trs_inv * (W^T v)_x - sum_y += trs_sign * (W.e12 * vx + W.e22 * vy + W.e32 * vz); // trs_inv * (W^T v)_y - sum_z += trs_sign * (W.e13 * vx + W.e23 * vy + W.e33 * vz); // trs_inv * (W^T v)_z - - gphase_record[rot_count]=gphase; - ipw_record[rot_count]=ipw0; - ixyz_record[rot_count]=ixyz0; - sym_record[rot_count]=isym; - ++rot_count; - }//end if section - }//end c_index loop - if (rot_count!=0) - { - sum_x/= rot_count; - sum_y/= rot_count; - sum_z/= rot_count; - } - for (int ir = 0; ir < rot_count; ++ir) - { - // push the representative-frame value back out to this member: W(g) * S / gphase. - const ModuleBase::Matrix3& W = wspin[sym_record[ir]]; - const std::complex inv_gphase = 1.0 / gphase_record[ir]; - const double trs_sign = trs_invp[sym_record[ir]]; - rhogtot_x[ipw_record[ir]] = trs_sign * (W.e11 * sum_x + W.e12 * sum_y + W.e13 * sum_z) * inv_gphase; - rhogtot_y[ipw_record[ir]] = trs_sign * (W.e21 * sum_x + W.e22 * sum_y + W.e23 * sum_z) * inv_gphase; - rhogtot_z[ipw_record[ir]] = trs_sign * (W.e31 * sum_x + W.e32 * sum_y + W.e33 * sum_z) * inv_gphase; - } - - delete[] ipw_record; - delete[] ixyz_record; - delete[] sym_record; - delete[] gphase_record; - }//end g_index loop - - delete[] symflag; - delete[] isymflag; - delete[] table_xyz; - delete[] count_xyz; - ModuleBase::timer::end("Symmetry","rhog_symmetry_nspin4"); + for (int g_index = 0; g_index < group_index; g_index++) + { + int *ipw_record = new int[nrot_use]; + int *ixyz_record = new int[nrot_use]; + int *sym_record = new int[nrot_use]; + std::complex* gphase_record = new std::complex [nrot_use]; + // orbit-representative-frame spin vector accumulated over the symmetry operations + std::complex sum_x(0, 0), sum_y(0, 0), sum_z(0, 0); + int rot_count=0; + + for (int c_index = 0; c_index < count_xyz[g_index]; ++c_index) + { + int ixyz0 = table_xyz[g_index][c_index]; + int ipw0 = ixyz2ipw[ixyz0]; + + if (symflag[ixyz0] == g_index) + { + int k = ixyz0%fftnz; + int j = ((ixyz0-k)/fftnz)%fftny; + int i = ((ixyz0-k)/fftnz-j)/fftny; + + ModuleBase::Vector3 tmp_gdirect_double(0.0, 0.0, 0.0); + tmp_gdirect_double.x=static_cast((i>int(nx/2)+1)?(i-nx):i); + tmp_gdirect_double.y=static_cast((j>int(ny/2)+1)?(j-ny):j); + tmp_gdirect_double.z=static_cast((k>int(nz/2)+1)?(k-nz):k); + + tmp_gdirect_double = tmp_gdirect_double * ModuleBase::TWO_PI; + + double cos_arg = 0.0, sin_arg = 0.0; + double arg_gtrans = tmp_gdirect_double * gtrans_use[isymflag[g_index][c_index]]; + + std::complex phase_gtrans (ModuleBase::libm::cos(arg_gtrans), + ModuleBase::libm::sin(arg_gtrans)); + + for (int ipt = 0;ipt < ((ModuleSymmetry::Symmetry::pricell_loop) ? this->ncell : 1);++ipt) + { + double arg = tmp_gdirect_double * ptrans[ipt]; + double tmp_cos = 0.0, tmp_sin = 0.0; + ModuleBase::libm::sincos(arg, &tmp_sin, &tmp_cos); + cos_arg += tmp_cos; + sin_arg += tmp_sin; + } + + cos_arg/=static_cast(ncell); + sin_arg/=static_cast(ncell); + + if (equal(cos_arg, 0.0) && equal(sin_arg, 0.0)) + { + continue; + } + + std::complex gphase(cos_arg, sin_arg); + gphase = phase_gtrans * gphase; + + if (equal(gphase.real(), 1.0) && equal(gphase.imag(), 0)) + { + gphase = std::complex(1.0, 0.0); + } + + // pull this orbit member back to the representative frame: multiply by gphase + // (removes the translation/phase, as in the scalar version) then by W(g)^T. + const int isym = isymflag[g_index][c_index]; + const ModuleBase::Matrix3& W = wspin[isym]; + const std::complex vx = rhogtot_x[ipw0] * gphase; + const std::complex vy = rhogtot_y[ipw0] * gphase; + const std::complex vz = rhogtot_z[ipw0] * gphase; + const double trs_sign = trs_invp[isym]; + sum_x += trs_sign * (W.e11 * vx + W.e21 * vy + W.e31 * vz); // trs_inv * (W^T v)_x + sum_y += trs_sign * (W.e12 * vx + W.e22 * vy + W.e32 * vz); // trs_inv * (W^T v)_y + sum_z += trs_sign * (W.e13 * vx + W.e23 * vy + W.e33 * vz); // trs_inv * (W^T v)_z + + gphase_record[rot_count]=gphase; + ipw_record[rot_count]=ipw0; + ixyz_record[rot_count]=ixyz0; + sym_record[rot_count]=isym; + ++rot_count; + }//end if section + }//end c_index loop + if (rot_count!=0) + { + sum_x/= rot_count; + sum_y/= rot_count; + sum_z/= rot_count; + } + for (int ir = 0; ir < rot_count; ++ir) + { + // push the representative-frame value back out to this member: W(g) * S / gphase. + const ModuleBase::Matrix3& W = wspin[sym_record[ir]]; + const std::complex inv_gphase = 1.0 / gphase_record[ir]; + const double trs_sign = trs_invp[sym_record[ir]]; + rhogtot_x[ipw_record[ir]] = trs_sign * (W.e11 * sum_x + W.e12 * sum_y + W.e13 * sum_z) * inv_gphase; + rhogtot_y[ipw_record[ir]] = trs_sign * (W.e21 * sum_x + W.e22 * sum_y + W.e23 * sum_z) * inv_gphase; + rhogtot_z[ipw_record[ir]] = trs_sign * (W.e31 * sum_x + W.e32 * sum_y + W.e33 * sum_z) * inv_gphase; + } + + delete[] ipw_record; + delete[] ixyz_record; + delete[] sym_record; + delete[] gphase_record; + }//end g_index loop + + delete[] symflag; + delete[] isymflag; + delete[] table_xyz; + delete[] count_xyz; + ModuleBase::timer::end("Symmetry","rhog_symmetry_nspin4"); } diff --git a/source/source_cell/read_pp_ucell.cpp b/source/source_cell/read_pp_ucell.cpp index b5f2fb61d93..633fc918f50 100644 --- a/source/source_cell/read_pp_ucell.cpp +++ b/source/source_cell/read_pp_ucell.cpp @@ -55,26 +55,26 @@ AtomsInfoResult read_pseudo(std::ofstream& ofs, UnitCell& ucell, const std::string dft_functional_ = dft_functional; read_cell_pseudopots(pseudo_dir_, ofs, ucell, global_out_dir_, dft_functional_, lspinorb, pseudo_rcut, soc_lambda); - if (GlobalV::MY_RANK == 0) - { - for (int it = 0; it < ucell.ntype; it++) - { - Atom* atom = &ucell.atoms[it]; - if (!(atom->label_orb.empty())) - { + if (GlobalV::MY_RANK == 0) + { + for (int it = 0; it < ucell.ntype; it++) + { + Atom* atom = &ucell.atoms[it]; + if (!(atom->label_orb.empty())) + { unitcell::compare_atom_labels(atom->label_orb, atom->ncpp.psd); } } - if (out_element_info_) - { - for (int i = 0; i < ucell.ntype; i++) - { - ModuleBase::Global_File::make_dir_atom(ucell.atoms[i].label, global_out_dir_); + if (out_element_info_) + { + for (int i = 0; i < ucell.ntype; i++) + { + ModuleBase::Global_File::make_dir_atom(ucell.atoms[i].label, global_out_dir_); } - for (int it = 0; it < ucell.ntype; it++) - { - Atom* atom = &ucell.atoms[it]; + for (int it = 0; it < ucell.ntype; it++) + { + Atom* atom = &ucell.atoms[it]; std::stringstream ss; ss << global_out_dir_ << atom->label << "/" << atom->label << ".NONLOCAL"; @@ -181,20 +181,20 @@ AtomsInfoResult read_pseudo(std::ofstream& ofs, UnitCell& ucell, basis_type, esolver_type, init_wfc, nbands); // Check whether the number of valence is minimum - if (GlobalV::MY_RANK == 0) - { - int abtype = 0; - for (int it = 0; it < ucell.ntype; it++) - { - if (ModuleBase::MinZval.find(ucell.atoms[it].ncpp.psd) - != ModuleBase::MinZval.end()) - { - if (ucell.atoms[it].ncpp.zv - > ModuleBase::MinZval.at(ucell.atoms[it].ncpp.psd)) - { + if (GlobalV::MY_RANK == 0) + { + int abtype = 0; + for (int it = 0; it < ucell.ntype; it++) + { + if (ModuleBase::MinZval.find(ucell.atoms[it].ncpp.psd) + != ModuleBase::MinZval.end()) + { + if (ucell.atoms[it].ncpp.zv + > ModuleBase::MinZval.at(ucell.atoms[it].ncpp.psd)) + { abtype += 1; - if (abtype == 1) - { + if (abtype == 1) + { std::cout << "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" "%%%%%%%%%%%%%%%%%%%%%%%%%%" @@ -219,9 +219,9 @@ AtomsInfoResult read_pseudo(std::ofstream& ofs, UnitCell& ucell, } } } - if (abtype > 0) - { - std::cout << " Pseudopotentials with additional electrons can " + if (abtype > 0) + { + std::cout << " Pseudopotentials with additional electrons can " "yield (more) accurate outcomes, but may be " "less efficient." << std::endl; @@ -347,7 +347,7 @@ void read_cell_pseudopots(const std::string& pp_dir, std::ofstream& log, UnitCel if (GlobalV::MY_RANK == 0) { - upf.complete_default(ucell.atoms[i].ncpp, pseudo_rcut_); + upf.complete_default(ucell.atoms[i].ncpp, pseudo_rcut_); log << std::endl; ModuleBase::GlobalFunc::OUT(log, "Pseudopotential file", ucell.pseudo_fn[i]); diff --git a/source/source_cell/unitcell.cpp b/source/source_cell/unitcell.cpp index 710f1db31cd..cc4db426946 100644 --- a/source/source_cell/unitcell.cpp +++ b/source/source_cell/unitcell.cpp @@ -94,7 +94,7 @@ std::map> UnitCell::get_lnchi_Counts() const { // Calculate various lattice related quantities for given latvec //============================================================== void UnitCell::setup_cell(const std::string& fn, std::ofstream& log, const double symmetry_prec, - const int dfthalf_type, const std::string& pseudo_dir, const int nspin, + const int dfthalf_type, const std::string& pseudo_dir, const int nspin, const std::string& basis_type, const std::string& orbital_dir, const std::string& init_wfc, const double onsite_radius, const bool deepks_setorb, const bool rpa, const bool fixed_atoms, const bool noncolin, const std::string& calculation, diff --git a/source/source_cell/unitcell.h b/source/source_cell/unitcell.h index d9b034f707a..89c1f098e9a 100644 --- a/source/source_cell/unitcell.h +++ b/source/source_cell/unitcell.h @@ -26,11 +26,11 @@ class UnitCell : public BaseCell { const std::string& fixed_axes_in); void setup_cell(const std::string& fn, std::ofstream& log, const double symmetry_prec, - const int dfthalf_type, const std::string& pseudo_dir, const int nspin, + const int dfthalf_type, const std::string& pseudo_dir, const int nspin, const std::string& basis_type, const std::string& orbital_dir, const std::string& init_wfc, const double onsite_radius, const bool deepks_setorb, const bool rpa, const bool fixed_atoms, const bool noncolin, const std::string& calculation, - const std::string& esolver_type, const int symmetry); + const std::string& esolver_type, const int symmetry); void set_iat2itia(); diff --git a/source/source_estate/elecstate_pw_cal_tau.cpp b/source/source_estate/elecstate_pw_cal_tau.cpp index 22f7fb76ecf..af0176c519e 100644 --- a/source/source_estate/elecstate_pw_cal_tau.cpp +++ b/source/source_estate/elecstate_pw_cal_tau.cpp @@ -9,9 +9,9 @@ void ElecStatePW::cal_tau(const psi::Psi& psi) { ModuleBase::TITLE("ElecStatePW", "cal_tau"); for(int is=0; iskin_r[is], 0, this->charge->nrxx); - } + } for (int ik = 0; ik < psi.get_nk(); ++ik) { diff --git a/source/source_estate/module_pot/pot_cosikr.cpp b/source/source_estate/module_pot/pot_cosikr.cpp index 66a5ef7849c..9baa91f30b9 100644 --- a/source/source_estate/module_pot/pot_cosikr.cpp +++ b/source/source_estate/module_pot/pot_cosikr.cpp @@ -11,43 +11,43 @@ namespace elecstate { Pot_Cosikr::Pot_Cosikr( - const ModulePW::PW_Basis* rho_basis_in, - const ModuleBase::Vector3 &kvec_d_in, - const std::vector &phase_in, - const std::vector &litude_in) - :kvec_d(kvec_d_in), - phase(phase_in), - amplitude(amplitude_in) + const ModulePW::PW_Basis* rho_basis_in, + const ModuleBase::Vector3 &kvec_d_in, + const std::vector &phase_in, + const std::vector &litude_in) + :kvec_d(kvec_d_in), + phase(phase_in), + amplitude(amplitude_in) { - this->rho_basis_ = rho_basis_in; - this->dynamic_mode = true; - this->fixed_mode = false; + this->rho_basis_ = rho_basis_in; + this->dynamic_mode = true; + this->fixed_mode = false; } void Pot_Cosikr::cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix &v_eff) { - ModuleBase::TITLE("Pot_Cosikr", "cal_v_eff"); - ModuleBase::timer::start("Pot_Cosikr", "cal_veff"); - assert(v_eff.nr == this->phase.size()); - assert(v_eff.nr == this->amplitude.size()); - int ir = 0; - for (int ix = 0; ix < this->rho_basis_->nx; ++ix) - { - const double phase_x = this->kvec_d.x * ix / this->rho_basis_->nx; - for (int iy = 0; iy < this->rho_basis_->ny; ++iy) - { - const double phase_xy = phase_x + this->kvec_d.y * iy / this->rho_basis_->ny; - for (int iz = this->rho_basis_->startz_current; iz < this->rho_basis_->startz_current + this->rho_basis_->nplane; ++iz) - { - const double phase_xyz = phase_xy + this->kvec_d.z * iz / this->rho_basis_->nz; - for(int is=0; isamplitude[is] * std::cos((phase_xyz + this->phase[is]) * ModuleBase::TWO_PI); - ++ir; - } - } - } - ModuleBase::timer::end("Pot_Cosikr", "cal_veff"); + ModuleBase::TITLE("Pot_Cosikr", "cal_v_eff"); + ModuleBase::timer::start("Pot_Cosikr", "cal_veff"); + assert(v_eff.nr == this->phase.size()); + assert(v_eff.nr == this->amplitude.size()); + int ir = 0; + for (int ix = 0; ix < this->rho_basis_->nx; ++ix) + { + const double phase_x = this->kvec_d.x * ix / this->rho_basis_->nx; + for (int iy = 0; iy < this->rho_basis_->ny; ++iy) + { + const double phase_xy = phase_x + this->kvec_d.y * iy / this->rho_basis_->ny; + for (int iz = this->rho_basis_->startz_current; iz < this->rho_basis_->startz_current + this->rho_basis_->nplane; ++iz) + { + const double phase_xyz = phase_xy + this->kvec_d.z * iz / this->rho_basis_->nz; + for(int is=0; isamplitude[is] * std::cos((phase_xyz + this->phase[is]) * ModuleBase::TWO_PI); + ++ir; + } + } + } + ModuleBase::timer::end("Pot_Cosikr", "cal_veff"); } } \ No newline at end of file diff --git a/source/source_estate/module_pot/pot_cosikr.h b/source/source_estate/module_pot/pot_cosikr.h index 1cdbd72c35e..0465a443c7d 100644 --- a/source/source_estate/module_pot/pot_cosikr.h +++ b/source/source_estate/module_pot/pot_cosikr.h @@ -17,18 +17,18 @@ namespace elecstate class Pot_Cosikr : public PotBase { public: - Pot_Cosikr( - const ModulePW::PW_Basis* rho_basis_in, - const ModuleBase::Vector3 &kvec_d_in, - const std::vector &phase_in, - const std::vector &litude_in); + Pot_Cosikr( + const ModulePW::PW_Basis* rho_basis_in, + const ModuleBase::Vector3 &kvec_d_in, + const std::vector &phase_in, + const std::vector &litude_in); - void cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix &v_eff) override; + void cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix &v_eff) override; private: - const ModuleBase::Vector3 kvec_d; - const std::vector phase; - const std::vector amplitude; + const ModuleBase::Vector3 kvec_d; + const std::vector phase; + const std::vector amplitude; }; } diff --git a/source/source_estate/update_pot.cpp b/source/source_estate/update_pot.cpp index 743b9d3f3bc..08fea3c3b89 100644 --- a/source/source_estate/update_pot.cpp +++ b/source/source_estate/update_pot.cpp @@ -2,8 +2,8 @@ #include "source_cell/cal_ux.h" void elecstate::update_pot(UnitCell& ucell, // unitcell - elecstate::ElecState* &pelec, // pointer of electrons - const Charge &chr, + elecstate::ElecState* &pelec, // pointer of electrons + const Charge &chr, const bool conv_esolver ) // charge density { diff --git a/source/source_estate/update_pot.h b/source/source_estate/update_pot.h index cce4c42428f..4b907bda8d0 100644 --- a/source/source_estate/update_pot.h +++ b/source/source_estate/update_pot.h @@ -8,8 +8,8 @@ namespace elecstate { void update_pot(UnitCell& ucell, // unitcell - elecstate::ElecState* &pelec, // pointer of electrons - const Charge &chr, + elecstate::ElecState* &pelec, // pointer of electrons + const Charge &chr, const bool conv_esolver); // charge density } diff --git a/source/source_hamilt/hamilt.h b/source/source_hamilt/hamilt.h index 3d554c0fe6b..0ba249553c3 100644 --- a/source/source_hamilt/hamilt.h +++ b/source/source_hamilt/hamilt.h @@ -31,13 +31,13 @@ class Hamilt : public HamiltBase void* get_ops() override { return static_cast(ops); } /// core function: for solving eigenvalues of Hamiltonian with iterative method - virtual void hPsi( - const T* psi_in, - T* hpsi, - const size_t size) const - { - return; - } + virtual void hPsi( + const T* psi_in, + T* hpsi, + const size_t size) const + { + return; + } virtual void sPsi(const T* psi_in, // psi T* spsi, // spsi @@ -49,14 +49,14 @@ class Hamilt : public HamiltBase syncmem_op()(spsi, psi_in, static_cast(nbands * nrow)); } - /// core function: return H(k) and S(k) matrixs for direct solving eigenvalues. - virtual void matrix( - MatrixBlock> &hk_in, - MatrixBlock> &sk_in){return;} + /// core function: return H(k) and S(k) matrixs for direct solving eigenvalues. + virtual void matrix( + MatrixBlock> &hk_in, + MatrixBlock> &sk_in){return;} - virtual void matrix( - MatrixBlock &hk_in, - MatrixBlock &sk_in){return;} + virtual void matrix( + MatrixBlock &hk_in, + MatrixBlock &sk_in){return;} virtual std::vector matrix() { return std::vector(); } diff --git a/source/source_hamilt/module_ewald/h_ewald_pw.cpp b/source/source_hamilt/module_ewald/h_ewald_pw.cpp index 459b77b2185..2511fe65170 100644 --- a/source/source_hamilt/module_ewald/h_ewald_pw.cpp +++ b/source/source_hamilt/module_ewald/h_ewald_pw.cpp @@ -79,7 +79,7 @@ double H_Ewald_pw::compute_ewald(const UnitCell& cell, ModuleBase::GlobalFunc::OUT(output_stream,"Total ionic charge",charge); } - // (2) calculate the converged value: alpha + // (2) calculate the converged value: alpha H_Ewald_pw::alpha = 2.90; do { @@ -112,17 +112,17 @@ double H_Ewald_pw::compute_ewald(const UnitCell& cell, ewaldg = 0.0; } - // in plane wave basis, only use k=0 point is not - // called "gamma_only", only if the wave functions - // are stored as double type, the gamma_only = true. - // I don't know why "gamma_only" in plane wave - // makes the fact below is 2, that's a little complicated - // to understand. I think that may because only half - // the G vectors are used. Unfortunately implement the - // function hasn't in my plan list yet. - // - // but that's not the term "gamma_only" I want to use in LCAO, - fact = 1.0; + // in plane wave basis, only use k=0 point is not + // called "gamma_only", only if the wave functions + // are stored as double type, the gamma_only = true. + // I don't know why "gamma_only" in plane wave + // makes the fact below is 2, that's a little complicated + // to understand. I think that may because only half + // the G vectors are used. Unfortunately implement the + // function hasn't in my plan list yet. + // + // but that's not the term "gamma_only" I want to use in LCAO, + fact = 1.0; //output_stream << "\n pwb.gstart = " << pwb.gstart << std::endl; const int ig0 = rho_basis->ig_gge0; @@ -148,14 +148,14 @@ double H_Ewald_pw::compute_ewald(const UnitCell& cell, // std::cout << "\n ewaldg = " << ewaldg; // Here add the other constant term - if (rho_basis->ig_gge0 >= 0) - { - for (int it = 0; it < cell.ntype;it++) - { + if (rho_basis->ig_gge0 >= 0) + { + for (int it = 0; it < cell.ntype;it++) + { { ewaldg = ewaldg - cell.atoms[it].na * cell.atoms[it].ncpp.zv * cell.atoms[it].ncpp.zv * sqrt(8.0 / ModuleBase::TWO_PI * alpha); } - } + } }//mohan modify 2007-11-7, 2010-07-26 // R-space sum here (only done for the processor that contains G=0) @@ -201,7 +201,7 @@ double H_Ewald_pw::compute_ewald(const UnitCell& cell, { it1 = cell.iat2it[na1]; ia1 = cell.iat2ia[na1]; - + for(int na2=0; na21) @@ -425,35 +425,35 @@ void H_Ewald_pw::rgen( ModuleBase::heapsort(nrm, r2, irr); } - // mohan fix bug 2011-06-07 - for(int i=0; iget_nbx(); - fraction.y = atom.taud[j].y * unitcell_info_->get_nby(); - fraction.z = atom.taud[j].z * unitcell_info_->get_nbz(); + fraction.y = atom.taud[j].y * unitcell_info_->get_nby(); + fraction.z = atom.taud[j].z * unitcell_info_->get_nbz(); const Vec3i atom_bgrid_idx(static_cast(fraction.x), static_cast(fraction.y), static_cast(fraction.z)); diff --git a/source/source_hamilt/module_gint/phi_operator.hpp b/source/source_hamilt/module_gint/phi_operator.hpp index 071a775d8ee..427bdf71141 100644 --- a/source/source_hamilt/module_gint/phi_operator.hpp +++ b/source/source_hamilt/module_gint/phi_operator.hpp @@ -196,9 +196,9 @@ void PhiOperator::phi_mul_phi( constexpr Tin alpha=1, beta=1; BlasConnector::gemm( 'T', 'N', n_i, n_j, len, - alpha, phi_i + start_idx * cols_ + atoms_startidx_[i], cols_, + alpha, phi_i + start_idx * cols_ + atoms_startidx_[i], cols_, phi_j + start_idx * cols_ + atoms_startidx_[j], cols_, - beta, tmp_hr.data(), n_j, + beta, tmp_hr.data(), n_j, base_device::AbacusDevice_t::CpuDevice); result->add_array_ts(tmp_hr.data()); diff --git a/source/source_hamilt/module_hcontainer/output_hcontainer.h b/source/source_hamilt/module_hcontainer/output_hcontainer.h index f8ba6b85273..2c895ccd9d6 100644 --- a/source/source_hamilt/module_hcontainer/output_hcontainer.h +++ b/source/source_hamilt/module_hcontainer/output_hcontainer.h @@ -14,9 +14,9 @@ class Output_HContainer { public: Output_HContainer(hamilt::HContainer* hcontainer, - std::ostream& ofs, - double sparse_threshold = -1, - int precision = -1); + std::ostream& ofs, + double sparse_threshold = -1, + int precision = -1); // write the matrices of all R vectors to the output stream void write(bool write_empty = false); diff --git a/source/source_hamilt/module_surchem/h_corr_pw.cpp b/source/source_hamilt/module_surchem/h_corr_pw.cpp index fa175aa36e2..9cdb503fa42 100644 --- a/source/source_hamilt/module_surchem/h_corr_pw.cpp +++ b/source/source_hamilt/module_surchem/h_corr_pw.cpp @@ -21,18 +21,18 @@ void surchem::v_correction(const UnitCell& cell, assert(rho_basis->nrxx>0); double* porter = new double[rho_basis->nrxx]; - for (int i = 0; i < rho_basis->nrxx; i++) - { - porter[i] = 0.0; - } + for (int i = 0; i < rho_basis->nrxx; i++) + { + porter[i] = 0.0; + } const int nspin0 = (nspin == 2) ? 2 : 1; - for (int is = 0; is < nspin0; is++) - { - for (int ir = 0; ir < rho_basis->nrxx; ir++) - { - porter[ir] += rho[is][ir]; - } - } + for (int is = 0; is < nspin0; is++) + { + for (int ir = 0; ir < rho_basis->nrxx; ir++) + { + porter[ir] += rho[is][ir]; + } + } std::complex* porter_g = new std::complex[rho_basis->npw]; ModuleBase::GlobalFunc::ZEROS(porter_g, rho_basis->npw); diff --git a/source/source_hamilt/module_surchem/sol_force.cpp b/source/source_hamilt/module_surchem/sol_force.cpp index 48f36309ad2..bd133594899 100644 --- a/source/source_hamilt/module_surchem/sol_force.cpp +++ b/source/source_hamilt/module_surchem/sol_force.cpp @@ -83,9 +83,9 @@ void surchem::force_cor_two(const UnitCell& cell, ModuleBase::GlobalFunc::ZEROS(Vcav_g, rho_basis->npw); ModuleBase::GlobalFunc::ZEROS(Vel_g, rho_basis->npw); for(int is=0; isnrxx; ir++) - { + { + for (int ir=0; irnrxx; ir++) + { Vcav_sum[ir] += this->Vcav(is, ir); } } @@ -159,7 +159,7 @@ void surchem::cal_force_sol(const UnitCell& cell, ModuleBase::timer::start("surchem", "cal_force_sol"); int nat = cell.nat; - ModuleBase::matrix force1(nat, 3); + ModuleBase::matrix force1(nat, 3); ModuleBase::matrix force2(nat, 3); force_cor_one(cell, rho_basis, vloc, force1); @@ -167,15 +167,15 @@ void surchem::cal_force_sol(const UnitCell& cell, int iat = 0; for (int it = 0;it < cell.ntype;it++) - { - for (int ia = 0;ia < cell.atoms[it].na;ia++) - { + { + for (int ia = 0;ia < cell.atoms[it].na;ia++) + { for(int ipol = 0; ipol < 3; ipol++) { forcesol(iat, ipol) = 0.5*force1(iat, ipol) + force2 (iat, ipol); } - - ++iat; + + ++iat; } } diff --git a/source/source_hamilt/module_xc/kernels/cuda/xc_functional_op.cu b/source/source_hamilt/module_xc/kernels/cuda/xc_functional_op.cu index 6ee81727c4e..687f5d4f795 100644 --- a/source/source_hamilt/module_xc/kernels/cuda/xc_functional_op.cu +++ b/source/source_hamilt/module_xc/kernels/cuda/xc_functional_op.cu @@ -13,7 +13,7 @@ __global__ void xc_functional_grad_wfc( const int pol, const int npw, const int npwx, - const T tpiba, + const T tpiba, const T* gcar, const T* kvec_c, const thrust::complex* rhog, @@ -21,12 +21,12 @@ __global__ void xc_functional_grad_wfc( { int idx = threadIdx.x + blockIdx.x * blockDim.x; if (idx >= npw) { return; } - // the formula is : rho(r)^prime = \int iG * rho(G)e^{iGr} dG - // double kplusg = wfc_basis->getgpluskcar(ik,ig)[ipol] * tpiba; + // the formula is : rho(r)^prime = \int iG * rho(G)e^{iGr} dG + // double kplusg = wfc_basis->getgpluskcar(ik,ig)[ipol] * tpiba; T kplusg = (gcar[(ik * npwx + idx) * 3 + pol] + kvec_c[ik * 3 + pol]) * tpiba; - // calculate the charge density gradient in reciprocal space. - porter[idx] = thrust::complex(0.0, kplusg) * rhog[idx]; + // calculate the charge density gradient in reciprocal space. + porter[idx] = thrust::complex(0.0, kplusg) * rhog[idx]; } template @@ -47,7 +47,7 @@ void xc_functional_grad_wfc_op::operator()( const int& pol, const int& npw, const int& npwx, - const Real& tpiba, + const Real& tpiba, const Real * gcar, const Real * kvec_c, const T * rhog, diff --git a/source/source_hamilt/module_xc/kernels/rocm/xc_functional_op.hip.cu b/source/source_hamilt/module_xc/kernels/rocm/xc_functional_op.hip.cu index 0e739276622..bce87f57d1b 100644 --- a/source/source_hamilt/module_xc/kernels/rocm/xc_functional_op.hip.cu +++ b/source/source_hamilt/module_xc/kernels/rocm/xc_functional_op.hip.cu @@ -14,7 +14,7 @@ __global__ void xc_functional_grad_wfc( const int pol, const int npw, const int npwx, - const T tpiba, + const T tpiba, const T* gcar, const T* kvec_c, const thrust::complex* rhog, @@ -22,12 +22,12 @@ __global__ void xc_functional_grad_wfc( { int idx = threadIdx.x + blockIdx.x * blockDim.x; if (idx >= npw) { return; } - // the formula is : rho(r)^prime = \int iG * rho(G)e^{iGr} dG - // double kplusg = wfc_basis->getgpluskcar(ik,ig)[ipol] * tpiba; + // the formula is : rho(r)^prime = \int iG * rho(G)e^{iGr} dG + // double kplusg = wfc_basis->getgpluskcar(ik,ig)[ipol] * tpiba; T kplusg = (gcar[(ik * npwx + idx) * 3 + pol] + kvec_c[ik * 3 + pol]) * tpiba; - // calculate the charge density gradient in reciprocal space. - porter[idx] = thrust::complex(0.0, kplusg) * rhog[idx]; + // calculate the charge density gradient in reciprocal space. + porter[idx] = thrust::complex(0.0, kplusg) * rhog[idx]; } template @@ -48,7 +48,7 @@ void xc_functional_grad_wfc_op::operator()( const int& pol, const int& npw, const int& npwx, - const Real& tpiba, + const Real& tpiba, const Real * gcar, const Real * kvec_c, const T * rhog, diff --git a/source/source_hamilt/module_xc/kernels/xc_functional_op.cpp b/source/source_hamilt/module_xc/kernels/xc_functional_op.cpp index 6095f45109f..ec67012675d 100644 --- a/source/source_hamilt/module_xc/kernels/xc_functional_op.cpp +++ b/source/source_hamilt/module_xc/kernels/xc_functional_op.cpp @@ -8,7 +8,7 @@ void xc_functional_grad_wfc_op::operator()( const int& pol, const int& npw, const int& npwx, - const Real& tpiba, + const Real& tpiba, const Real * gcar, const Real * kvec_c, const T * rhog, @@ -18,14 +18,14 @@ void xc_functional_grad_wfc_op::operator()( #pragma omp parallel for schedule(static, 1024) #endif for(int ig = 0; ig < npw; ig++) { - // the formula is : rho(r)^prime = \int iG * rho(G)e^{iGr} dG - // double kplusg = wfc_basis->getgpluskcar(ik,ig)[ipol] * tpiba; + // the formula is : rho(r)^prime = \int iG * rho(G)e^{iGr} dG + // double kplusg = wfc_basis->getgpluskcar(ik,ig)[ipol] * tpiba; Real kplusg = (gcar[(ik * npwx + ig) * 3 + pol] + kvec_c[ik * 3 + pol]) * tpiba; - // calculate the charge density gradient in reciprocal space. - porter[ig] = T(0.0, kplusg) * rhog[ig]; - } + // calculate the charge density gradient in reciprocal space. + porter[ig] = T(0.0, kplusg) * rhog[ig]; + } } template @@ -40,7 +40,7 @@ void xc_functional_grad_wfc_op::operator()( #endif for (int ir = 0; ir < nrxx; ++ir) { grad[ipol * nrxx + ir] = porter[ir]; - } + } } template struct xc_functional_grad_wfc_op, base_device::DEVICE_CPU>; diff --git a/source/source_hamilt/module_xc/libxc_mgga_wrap.cpp b/source/source_hamilt/module_xc/libxc_mgga_wrap.cpp index 6ebbd28d235..3fd7f34b53c 100644 --- a/source/source_hamilt/module_xc/libxc_mgga_wrap.cpp +++ b/source/source_hamilt/module_xc/libxc_mgga_wrap.cpp @@ -140,7 +140,7 @@ void XC_Functional_Libxc::tau_xc_spin( std::array v2xc = {0.0, 0.0, 0.0}; // call Libxc function: xc_mgga_exc_vxc xc_mgga_exc_vxc(&func, 1, rho.data(), grho.data(), lapl.data(), tau.data(), &s, - v1xc.data(), v2xc.data(), vlapl_out.data(), v3xc.data()); + v1xc.data(), v2xc.data(), vlapl_out.data(), v3xc.data()); #ifdef __EXX if (func.info->number == XC_MGGA_X_SCAN && XC_Functional::get_func_type() == 5) diff --git a/source/source_hamilt/module_xc/xc_gga_corr.cpp b/source/source_hamilt/module_xc/xc_gga_corr.cpp index b22f31ef64a..c34f0e11be0 100644 --- a/source/source_hamilt/module_xc/xc_gga_corr.cpp +++ b/source/source_hamilt/module_xc/xc_gga_corr.cpp @@ -237,9 +237,9 @@ void XC_Functional::perdew86_spin( //SdG: in the original paper 1.745*0.11=0.19195 is used double dd = pow((2.0) , third) * sqrt(pow(((1.0 + zeta) * 0.50) , (5.0 / 3.0)) - + pow(((1.0 - zeta) * 0.50) , (5.0 / 3.0))); + + pow(((1.0 - zeta) * 0.50) , (5.0 / 3.0))); double ddd = pow((2.0) , (- 4.0 / 3.0)) * 5.0 * (pow(((1.0 + zeta) * 0.50) , (2.0 / 3.0)) - - pow(((1.0 - zeta) * 0.50) , (2.0 / 3.0))) / (3.0 * dd); + - pow(((1.0 - zeta) * 0.50) , (2.0 / 3.0))) / (3.0 * dd); double ephi = exp(- phi); sc = grho / rho43 * cn * ephi / dd; v1cup = sc * ((1.0 + phi) * dcn / cn - ((4.0 / 3.0) - @@ -401,9 +401,9 @@ void XC_Functional::pbec_spin( double dh0up = be[iflag] * t * t * fz3 / s1 * (- 7.0 / 3.0 * xy - qy * (af * bfup / be[iflag] - 7.0 / 3.0)); double dh0dw = be[iflag] * t * t * fz3 / s1 * (- 7.0 / 3.0 * xy - qy * (af * bfdw / be[iflag] - 7.0 / 3.0)); double dh0zup = (3.0 * h0 / fz - be[iflag] * t * t * fz2 - / s1 * (2.0 * xy - qy * (3.0 * af * expe * ec / fz3 / be[iflag] + 2.0))) * dfz * (1.0 - zeta); + / s1 * (2.0 * xy - qy * (3.0 * af * expe * ec / fz3 / be[iflag] + 2.0))) * dfz * (1.0 - zeta); double dh0zdw = - (3.0 * h0 / fz - be[iflag] * t * t * fz2 - / s1 * (2.0 * xy - qy * (3.0 * af * expe * ec / fz3 / be[iflag] + 2.0))) * dfz * (1.0 + zeta); + / s1 * (2.0 * xy - qy * (3.0 * af * expe * ec / fz3 / be[iflag] + 2.0))) * dfz * (1.0 + zeta); double ddh0 = be[iflag] * fz / (2.0 * ks * ks * rho) * (xy - qy) / s1; sc = rho * h0; v1cup = h0 + dh0up + dh0zup; diff --git a/source/source_hamilt/operator.cpp b/source/source_hamilt/operator.cpp index dba9367f055..36bc9c804cf 100644 --- a/source/source_hamilt/operator.cpp +++ b/source/source_hamilt/operator.cpp @@ -80,21 +80,21 @@ typename Operator::hpsi_info Operator::hPsi(hpsi_info& inp psi_input->get_nbasis(), true); - switch (op->get_act_type()) - { - case 2: - op->act(psi_wrapper, *this->hpsi, nbands); - break; - default: - op->act(nbands, - psi_input->get_nbasis(), - psi_input->get_npol(), - tmpsi_in, - this->hpsi->get_pointer(), - psi_input->get_current_nbas(), - is_first_node); - break; - } + switch (op->get_act_type()) + { + case 2: + op->act(psi_wrapper, *this->hpsi, nbands); + break; + default: + op->act(nbands, + psi_input->get_nbasis(), + psi_input->get_npol(), + tmpsi_in, + this->hpsi->get_pointer(), + psi_input->get_current_nbas(), + is_first_node); + break; + } }; ModuleBase::timer::start("Operator", "hPsi"); diff --git a/source/source_hamilt/operator.h b/source/source_hamilt/operator.h index 0c27ded35c1..8848fcc7bac 100644 --- a/source/source_hamilt/operator.h +++ b/source/source_hamilt/operator.h @@ -100,10 +100,10 @@ class Operator /// developer-friendly interfaces for act() function /// interface type 2: input and change the Psi-type HPsi - // virtual void act(const psi::Psi& psi_in, psi::Psi& psi_out) const {}; - virtual void act(const psi::Psi& psi_in, - psi::Psi& psi_out, - const int nbands) const {}; + // virtual void act(const psi::Psi& psi_in, psi::Psi& psi_out) const {}; + virtual void act(const psi::Psi& psi_in, + psi::Psi& psi_out, + const int nbands) const {}; /// interface type 3: return a Psi-type HPsi // virtual psi::Psi act(const psi::Psi& psi_in) const { return psi_in; }; diff --git a/source/source_hsolver/hsolver_pw.cpp b/source/source_hsolver/hsolver_pw.cpp index a11edfd2732..1b316b567e0 100644 --- a/source/source_hsolver/hsolver_pw.cpp +++ b/source/source_hsolver/hsolver_pw.cpp @@ -219,8 +219,8 @@ void HSolverPW::solve(HSOperator& op, reinterpret_cast*>(pes)->psiToRho(psi); } - ModuleBase::timer::end("HSolverPW", "solve"); - return; + ModuleBase::timer::end("HSolverPW", "solve"); + return; } template diff --git a/source/source_hsolver/module_genelpa/pblas.h b/source/source_hsolver/module_genelpa/pblas.h index 51ac6f3671c..8acc1a3912d 100644 --- a/source/source_hsolver/module_genelpa/pblas.h +++ b/source/source_hsolver/module_genelpa/pblas.h @@ -1,12 +1,12 @@ #pragma once void pddot_(int* n, double* dot, double* x, int* ix, int* jx, int* descx, int* incx, - double* y, int* iy, int* jy, int* descy, int* incy); - + double* y, int* iy, int* jy, int* descy, int* incy); + void pzdotc_(int* n, double _Complex* dot, double _Complex* x, int* ix, int* jx, int* descx, int* incx, - double _Complex* y, int* iy, int* jy, int* descy, int* incy); + double _Complex* y, int* iy, int* jy, int* descy, int* incy); void pdsymv_(char* uplo, int* n, - double* alpha, double* a, int* ia, int* ja, int* desca, - double* x, int* ix, int* jx, int* descx, int* incx, + double* alpha, double* a, int* ia, int* ja, int* desca, + double* x, int* ix, int* jx, int* descx, int* incx, double* beta, double* y, int* iy, int* jy, int* descy, int* incy); void pdtran_(int* m , int* n , double* alpha , double* a , int* ia , int* ja , int* desca , @@ -18,7 +18,7 @@ void pdgemm_(char* transa , char* transb , int* m , int* n , int* k , double* beta , double* c , int* ic , int* jc , int* descc ); void pzgemm_(char* transa , char* transb , int* m , int* n , int* k , double _Complex* alpha , double _Complex* a , int* ia , int* ja , int* desca , - double _Complex* b , int* ib , int* jb , int* descb , + double _Complex* b , int* ib , int* jb , int* descb , double _Complex* beta , double _Complex* c , int* ic , int* jc , int* descc ); void pdsymm_(char* side , char* uplo , int* m , int* n , double* alpha , double* a , int* ia , int* ja , int* desca , @@ -26,15 +26,15 @@ void pdsymm_(char* side , char* uplo , int* m , int* n , double* beta , double* c , int* ic , int* jc , int* descc ); void pzsymm_(char* side , char* uplo , int* m , int* n , double _Complex* alpha , double _Complex* a , int* ia , int* ja , int* desca , - double _Complex* b , int* ib , int* jb , int* descb , + double _Complex* b , int* ib , int* jb , int* descb , double _Complex* beta , double _Complex* c , int* ic , int* jc , int* descc ); void pzhemm_(char* side , char* uplo , int* m , int* n , double _Complex* alpha , double _Complex* a , int* ia , int* ja , int* desca , - double _Complex* b , int* ib , int* jb , int* descb , + double _Complex* b , int* ib , int* jb , int* descb , double _Complex* beta , double _Complex* c , int* ic , int* jc , int* descc ); void pdtrmm_(char* side , char* uplo , char* transa , char* diag , int* m , int* n , double* alpha , double* a , int* ia , int* ja , int* desca , double* b , int* ib , int* jb , int* descb ); void pztrmm_(char* side , char* uplo , char* transa , char* diag , int* m , int* n , double _Complex* alpha , double _Complex* a , int* ia , int* ja , int* desca , - double _Complex* b , int* ib , int* jb , int* descb ); + double _Complex* b , int* ib , int* jb , int* descb ); diff --git a/source/source_hsolver/module_genelpa/scalapack.h b/source/source_hsolver/module_genelpa/scalapack.h index 39e18358e37..6e5db653286 100644 --- a/source/source_hsolver/module_genelpa/scalapack.h +++ b/source/source_hsolver/module_genelpa/scalapack.h @@ -7,6 +7,6 @@ void pzpotrf_(const char *UPLO, const int *N, double _Complex *A, const int *IA, void pdsyev_(const char *JOBZ, const char *UPLO, int *N, double *A, int *IA, int *JA, int *DESCA, double *W, double *Z, int *IZ, int *JZ, int *DESCZ, double *WORK, int *LWORK, int *INFO); void pdgemr2d_(int *M, int *N, double *A, int *IA, int *JA, int *DESCA, - double *B, int *IB, int *JB, int *DESCB, int *ICTXT); + double *B, int *IB, int *JB, int *DESCB, int *ICTXT); void pzgemr2d_(int *M, int *N, double _Complex *A, int *IA, int *JA, int *DESCA, - double _Complex *B, int *IB, int *JB, int *DESCB, int *ICTXT); + double _Complex *B, int *IB, int *JB, int *DESCB, int *ICTXT); diff --git a/source/source_io/module_bessel/bessel_basis.h b/source/source_io/module_bessel/bessel_basis.h index d46d7390fbd..8254d3ccaf7 100644 --- a/source/source_io/module_bessel/bessel_basis.h +++ b/source/source_io/module_bessel/bessel_basis.h @@ -17,173 +17,173 @@ class Bessel_Basis { public: - Bessel_Basis(); - ~Bessel_Basis(); - - /// @brief Initialization of Bessel function related matrices. - /// @details Used for a specific group of C4 coefficients. 2021-01-04, mohan added a new input parameter lmax_in, if we only generate numerical atomic orbitals based on spherical Bessel functions, lmax_in = ucell.lmax. However, if we want to generate Spherical Bessel functions (SBF) for descriptor, then the lmax_in is controlled by user. - /// @note This function is called in source_io/numerical_basis.cpp and source_io/numerical_descriptor.cpp - /// @param start_from_file whether read C4 coefficients stored in external files - /// @param ecutwfc cutoff for numerical atomic orbitals - /// @param ntype atom types - /// @param lmax_in maximal angular momentum for numerical orbitals - /// @param smooth whether smooth SBFs when perform integration to calculate value of matrix element of TableOne. For details, see J. Phys.: Condens. Matter 22 (2010) 445501 - /// @param sigma stddev of Gaussian function for smoothing SBFs - /// @param rcut_in cutoff radius for SBFs - /// @param tol_in accurancy control for SBFs - /// @param dk kspace grid - /// @param dr realspace grid - /// @param ucell UnitCell class object, ucell.nmax will be used in this function - void init( - const bool start_from_file, - const double &ecutwfc, - const int &ntype, - const int &lmax_in, - const bool &smooth, - const double &sigma, - const double &rcut_in, - const double &tol_in, - const UnitCell& ucell, - const double &dk = 0.01, - const double &dr = 0.01 - ); - /// @brief return number of SBFs used for one `chi` (see details for more information) - /// @details atomic orbital is constructed always with not only one set of SBFs. For different sets, they are marked with different `chi`(s), similar with concept of contracted GTOs. For one `chi`, it is 'q' the summation index, and q is in SBFs like: j_l(q*r), where l is the order of SBF. - /// @return number of SBFs - const int& get_ecut_number() const { return Ecut_number;} - - /// @brief Cubic spline interpolation for matrix Faln - /// @param it atom type index - /// @param l angular momentum - /// @param ic chi index - /// @param gnorm norm of G+k vector - /// @return interpolated value - double Polynomial_Interpolation(const int &it, const int &l, const int &ic, const double &gnorm)const; - /// @brief Cubic spline interpolation for matrix TableOne - /// @param l angular momentum - /// @param ie q index (see explanation in note of function BesselBasis::get_ecut_number()) - /// @param gnorm norm of G+k vector - /// @return interpolated value - double Polynomial_Interpolation2(const int &l, const int &ie, const double &gnorm)const; - - - /// @brief get energy cutoff, which is used to truncate SBF Jlq. - /// @param - /// @return energy cutoff in Ry - const double &get_ecut() const {return ecut;} - /// @brief cutoff radius of radial SBF Jlq. - /// @param - /// @return cutoff radius in a.u. - const double &get_rcut() const {return rcut;} - - const double &get_tolerence() const {return tolerence;} - - - /// @brief check if SBFs are smoothed (mohan add 2009-08-28) - /// @attention in this case, the Jlq are not the true Jlq. - /// @param - /// @return boolean whether SBFs are smoothed - const bool &get_smooth() const {return smooth;} - /// @brief get sigma the stddev (standard deviation) used in smooth function (Gaussian function) - /// @param - /// @return stddev of smooth function - const double &get_sigma() const {return sigma;} + Bessel_Basis(); + ~Bessel_Basis(); + + /// @brief Initialization of Bessel function related matrices. + /// @details Used for a specific group of C4 coefficients. 2021-01-04, mohan added a new input parameter lmax_in, if we only generate numerical atomic orbitals based on spherical Bessel functions, lmax_in = ucell.lmax. However, if we want to generate Spherical Bessel functions (SBF) for descriptor, then the lmax_in is controlled by user. + /// @note This function is called in source_io/numerical_basis.cpp and source_io/numerical_descriptor.cpp + /// @param start_from_file whether read C4 coefficients stored in external files + /// @param ecutwfc cutoff for numerical atomic orbitals + /// @param ntype atom types + /// @param lmax_in maximal angular momentum for numerical orbitals + /// @param smooth whether smooth SBFs when perform integration to calculate value of matrix element of TableOne. For details, see J. Phys.: Condens. Matter 22 (2010) 445501 + /// @param sigma stddev of Gaussian function for smoothing SBFs + /// @param rcut_in cutoff radius for SBFs + /// @param tol_in accurancy control for SBFs + /// @param dk kspace grid + /// @param dr realspace grid + /// @param ucell UnitCell class object, ucell.nmax will be used in this function + void init( + const bool start_from_file, + const double &ecutwfc, + const int &ntype, + const int &lmax_in, + const bool &smooth, + const double &sigma, + const double &rcut_in, + const double &tol_in, + const UnitCell& ucell, + const double &dk = 0.01, + const double &dr = 0.01 + ); + /// @brief return number of SBFs used for one `chi` (see details for more information) + /// @details atomic orbital is constructed always with not only one set of SBFs. For different sets, they are marked with different `chi`(s), similar with concept of contracted GTOs. For one `chi`, it is 'q' the summation index, and q is in SBFs like: j_l(q*r), where l is the order of SBF. + /// @return number of SBFs + const int& get_ecut_number() const { return Ecut_number;} + + /// @brief Cubic spline interpolation for matrix Faln + /// @param it atom type index + /// @param l angular momentum + /// @param ic chi index + /// @param gnorm norm of G+k vector + /// @return interpolated value + double Polynomial_Interpolation(const int &it, const int &l, const int &ic, const double &gnorm)const; + /// @brief Cubic spline interpolation for matrix TableOne + /// @param l angular momentum + /// @param ie q index (see explanation in note of function BesselBasis::get_ecut_number()) + /// @param gnorm norm of G+k vector + /// @return interpolated value + double Polynomial_Interpolation2(const int &l, const int &ie, const double &gnorm)const; + + + /// @brief get energy cutoff, which is used to truncate SBF Jlq. + /// @param + /// @return energy cutoff in Ry + const double &get_ecut() const {return ecut;} + /// @brief cutoff radius of radial SBF Jlq. + /// @param + /// @return cutoff radius in a.u. + const double &get_rcut() const {return rcut;} + + const double &get_tolerence() const {return tolerence;} + + + /// @brief check if SBFs are smoothed (mohan add 2009-08-28) + /// @attention in this case, the Jlq are not the true Jlq. + /// @param + /// @return boolean whether SBFs are smoothed + const bool &get_smooth() const {return smooth;} + /// @brief get sigma the stddev (standard deviation) used in smooth function (Gaussian function) + /// @param + /// @return stddev of smooth function + const double &get_sigma() const {return sigma;} private: - /// @brief the most important array to calculate spillage, has dimension (ntype, lmax+1, max_n, nk) - ModuleBase::realArray Faln; - - /// @brief Coefficients to be optimized! - ModuleBase::realArray C4; - - /// @brief matrix whose elements are int{dr r^2 j_l(qr)*j_l(kr)}, has dimension (lmax+1, nq, nk) - ModuleBase::realArray TableOne; - - /// @brief mesh of k vector, k is in j_l(k*r) - int kmesh=0; - /// @brief grid of k - double Dk; - /// @brief number of q vector, q is in j_l(q*r) - int Ecut_number; - /// @brief Cutoff radius (in a.u.) of SBFs, for any SBF j_l(qr), r>=rcut, j_l(q*r) = 0 (if not smoothed) - double rcut=0.0; - /// @brief energy cutoff for determining kmesh and number of SBFs - double ecut=0.0; - double tolerence=0.0; - /// @brief whether smooth SBFs around cutoff radius, resulting in non-zero values. For importance of smooth of SBFs, see J. Phys.: Condens. Matter 22 (2010) 445501, eqn 6. (mohan add 2009-01-18) - bool smooth=false; - /// @brief stddev of smooth function (Gaussian function, centered at rcut) - double sigma=0.0; - - /// @brief Allocate memory for C4 matrix and initialize all elements to one. - /// @param ntype number of atom types - /// @param lmax maximal angular momentum of localized orbitals - /// @param nmax maximal principal quantum number of localized orbitals - /// @param ecut_number number of SBFs - void allocate_C4( - const int &ntype, - const int &lmax, - const int &nmax, - const int &ecut_number, - const UnitCell& ucell - ); - - /// @brief Read C4 from external file. Presently an O(N^2) search algorithm is used. A HTML parser is needed in the future to improve performance. - /// @param name name of external file where C4-stored file information is contained - /// @param ntype number of atom types - /// @param ecut energy cutoff - /// @param rcut cutoff radius - /// @param ecut_number number of SBFs - /// @param tolerence accurancy of SBFs, here only used for consistency check - void readin_C4( - const std::string &name, - const int &ntype, - const int &ecut, - const int &rcut, - const int &ecut_number, - const double &tolerence, - const UnitCell& ucell - ); - - void init_TableOne(); - - /// @brief calculate F_{aln}(it, il, in, ik) = sum_{ie}{C4(it, il, in, ie)*TableOne(il, ie, ik)}, where TableOne is overlap integral between two spherical bessel functions (jle(r) and jlk(r)) - /// @param ntype number of atomtype - /// @param lmax maximal angular momentum - /// @param nmax maximal chi - /// @param ecut_number number of SBFs - void init_Faln( - const int &ntype, - const int &lmax, - const int &nmax, - const int &ecut_number, - const UnitCell& ucell - ); - - /// @brief number of localized wave functions - int nwfc=0; - - /// @brief calculate element value of TableOne matrix - /// @details (be called in Bessel_Basis::init(), used for outputing overlap Q matrix) initialize the table whose matrix element is the result of integral int{dr r^2 jle(r)*jlk(r)}, TableOne has three subscript (l, ie, ik), the first runs over orbitals' angular momentum and ie, ik run over ecut_number and kmesh SBFs - /// @param smooth_in whether jle(r) SBF is smoothed by a Gaussian function - /// @param sigma_in stddev for controlling smearing of Gaussian function for smoothing jle(r) - /// @param ecutwfc planewave kinetic energy cutoff for controlling kspace sampling - /// @param rcut cutoff radius of SBFs - /// @param dr realspace grid - /// @param dk kspace grid - /// @param lmax maximal angular momentum for SBFs - /// @param ecut_number number of SBFs - /// @param tolerence accurancy of SBFs - void init_TableOne( - const bool smooth_in, - const double &sigma_in, - const double &ecut, - const double &rcut, - const double &dr, - const double &dk, - const int &lmax, - const int &ecut_number, - const double &tolerence); + /// @brief the most important array to calculate spillage, has dimension (ntype, lmax+1, max_n, nk) + ModuleBase::realArray Faln; + + /// @brief Coefficients to be optimized! + ModuleBase::realArray C4; + + /// @brief matrix whose elements are int{dr r^2 j_l(qr)*j_l(kr)}, has dimension (lmax+1, nq, nk) + ModuleBase::realArray TableOne; + + /// @brief mesh of k vector, k is in j_l(k*r) + int kmesh=0; + /// @brief grid of k + double Dk; + /// @brief number of q vector, q is in j_l(q*r) + int Ecut_number; + /// @brief Cutoff radius (in a.u.) of SBFs, for any SBF j_l(qr), r>=rcut, j_l(q*r) = 0 (if not smoothed) + double rcut=0.0; + /// @brief energy cutoff for determining kmesh and number of SBFs + double ecut=0.0; + double tolerence=0.0; + /// @brief whether smooth SBFs around cutoff radius, resulting in non-zero values. For importance of smooth of SBFs, see J. Phys.: Condens. Matter 22 (2010) 445501, eqn 6. (mohan add 2009-01-18) + bool smooth=false; + /// @brief stddev of smooth function (Gaussian function, centered at rcut) + double sigma=0.0; + + /// @brief Allocate memory for C4 matrix and initialize all elements to one. + /// @param ntype number of atom types + /// @param lmax maximal angular momentum of localized orbitals + /// @param nmax maximal principal quantum number of localized orbitals + /// @param ecut_number number of SBFs + void allocate_C4( + const int &ntype, + const int &lmax, + const int &nmax, + const int &ecut_number, + const UnitCell& ucell + ); + + /// @brief Read C4 from external file. Presently an O(N^2) search algorithm is used. A HTML parser is needed in the future to improve performance. + /// @param name name of external file where C4-stored file information is contained + /// @param ntype number of atom types + /// @param ecut energy cutoff + /// @param rcut cutoff radius + /// @param ecut_number number of SBFs + /// @param tolerence accurancy of SBFs, here only used for consistency check + void readin_C4( + const std::string &name, + const int &ntype, + const int &ecut, + const int &rcut, + const int &ecut_number, + const double &tolerence, + const UnitCell& ucell + ); + + void init_TableOne(); + + /// @brief calculate F_{aln}(it, il, in, ik) = sum_{ie}{C4(it, il, in, ie)*TableOne(il, ie, ik)}, where TableOne is overlap integral between two spherical bessel functions (jle(r) and jlk(r)) + /// @param ntype number of atomtype + /// @param lmax maximal angular momentum + /// @param nmax maximal chi + /// @param ecut_number number of SBFs + void init_Faln( + const int &ntype, + const int &lmax, + const int &nmax, + const int &ecut_number, + const UnitCell& ucell + ); + + /// @brief number of localized wave functions + int nwfc=0; + + /// @brief calculate element value of TableOne matrix + /// @details (be called in Bessel_Basis::init(), used for outputing overlap Q matrix) initialize the table whose matrix element is the result of integral int{dr r^2 jle(r)*jlk(r)}, TableOne has three subscript (l, ie, ik), the first runs over orbitals' angular momentum and ie, ik run over ecut_number and kmesh SBFs + /// @param smooth_in whether jle(r) SBF is smoothed by a Gaussian function + /// @param sigma_in stddev for controlling smearing of Gaussian function for smoothing jle(r) + /// @param ecutwfc planewave kinetic energy cutoff for controlling kspace sampling + /// @param rcut cutoff radius of SBFs + /// @param dr realspace grid + /// @param dk kspace grid + /// @param lmax maximal angular momentum for SBFs + /// @param ecut_number number of SBFs + /// @param tolerence accurancy of SBFs + void init_TableOne( + const bool smooth_in, + const double &sigma_in, + const double &ecut, + const double &rcut, + const double &dr, + const double &dk, + const int &lmax, + const int &ecut_number, + const double &tolerence); }; #endif diff --git a/source/source_io/module_bessel/numerical_descriptor.cpp b/source/source_io/module_bessel/numerical_descriptor.cpp index f2ca03ec474..379d4384f94 100644 --- a/source/source_io/module_bessel/numerical_descriptor.cpp +++ b/source/source_io/module_bessel/numerical_descriptor.cpp @@ -7,70 +7,70 @@ Numerical_Descriptor::Numerical_Descriptor() { - this->init_label = false; - this->lmax = -1; - this->nmax = -1; + this->init_label = false; + this->lmax = -1; + this->nmax = -1; this->nlocal = 0; this->mu_index = nullptr; } Numerical_Descriptor::~Numerical_Descriptor() { - if(init_label==true) - { - delete[] mu_index; - } - return; + if(init_label==true) + { + delete[] mu_index; + } + return; } void Numerical_Descriptor::output_descriptor(const UnitCell& ucell, const psi::Psi> &psi, const int &lmax_in, const double &rcut_in, const double &tol_in, const int nks_in) { - ModuleBase::TITLE("Numerical_Descriptor","output_descriptor"); - ModuleBase::GlobalFunc::NEW_PART("DeepKS descriptor: D_{Inl}"); + ModuleBase::TITLE("Numerical_Descriptor","output_descriptor"); + ModuleBase::GlobalFunc::NEW_PART("DeepKS descriptor: D_{Inl}"); - //----------------------------------- - // 1. Initialize parameters - //----------------------------------- + //----------------------------------- + // 1. Initialize parameters + //----------------------------------- - //GlobalV::ofs_running << "D_{Inl}_m_m'=sum_{i}" << std::endl; - GlobalV::ofs_running << "input lmax = " << lmax_in << std::endl; - GlobalV::ofs_running << "input rcut = " << rcut_in << std::endl; - GlobalV::ofs_running << "input tolerence = " << tol_in << std::endl; - this->lmax = lmax_in; - assert(lmax>=0); + //GlobalV::ofs_running << "D_{Inl}_m_m'=sum_{i}" << std::endl; + GlobalV::ofs_running << "input lmax = " << lmax_in << std::endl; + GlobalV::ofs_running << "input rcut = " << rcut_in << std::endl; + GlobalV::ofs_running << "input tolerence = " << tol_in << std::endl; + this->lmax = lmax_in; + assert(lmax>=0); const int nks = nks_in; int ne = 0; - - // Peize Lin change 2022.12.15 + + // Peize Lin change 2022.12.15 // 0 stands for : 'Faln' is not used. this->bessel_basis.init( - false, - std::stod(PARAM.inp.bessel_descriptor_ecut), - ucell.ntype, - this->lmax, - PARAM.inp.bessel_descriptor_smooth, - PARAM.inp.bessel_descriptor_sigma, - rcut_in, - tol_in, + false, + std::stod(PARAM.inp.bessel_descriptor_ecut), + ucell.ntype, + this->lmax, + PARAM.inp.bessel_descriptor_smooth, + PARAM.inp.bessel_descriptor_sigma, + rcut_in, + tol_in, ucell ); - this->nmax = Numerical_Descriptor::bessel_basis.get_ecut_number(); + this->nmax = Numerical_Descriptor::bessel_basis.get_ecut_number(); this->init_mu_index(ucell); this->init_label = true; - assert(nmax>0); + assert(nmax>0); - // Currently we are not considering doing DeePKS in PW basis - // hence this subroutine is used only for generating projectors and save to jle.orb - // As a result, I will return here and the rest of the code is saved for future use - return; + // Currently we are not considering doing DeePKS in PW basis + // hence this subroutine is used only for generating projectors and save to jle.orb + // As a result, I will return here and the rest of the code is saved for future use + return; /* - //----------------------------------- - // 2. Open the file - //----------------------------------- + //----------------------------------- + // 2. Open the file + //----------------------------------- std::ofstream ofs; std::stringstream ss; ss << PARAM.inp.spillage_outdir << "/" << "descriptor.dat"; @@ -80,88 +80,88 @@ void Numerical_Descriptor::output_descriptor(const UnitCell& ucell, const psi::P } - //------------------------------------- - // 3. Initialize overlap_Q1 and Q2 - //------------------------------------- - // OVERLAP : < J_mu | Psi > + //------------------------------------- + // 3. Initialize overlap_Q1 and Q2 + //------------------------------------- + // OVERLAP : < J_mu | Psi > ModuleBase::realArray overlap_Q1(nks, PARAM.inp.nbands, this->nlocal ); ModuleBase::realArray overlap_Q2(nks, PARAM.inp.nbands, this->nlocal ); ModuleBase::GlobalFunc::ZEROS(overlap_Q1.ptr, overlap_Q1.getSize() ); ModuleBase::GlobalFunc::ZEROS(overlap_Q2.ptr, overlap_Q2.getSize() ); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"number of k points",overlap_Q1.getBound1()); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"number of bands",overlap_Q1.getBound2()); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"number of local orbitals",overlap_Q1.getBound3()); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"number of k points",overlap_Q1.getBound1()); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"number of bands",overlap_Q1.getBound2()); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"number of local orbitals",overlap_Q1.getBound3()); - //------------------------------------- - // 4. Compute overlap_Q1 and Q2 - //------------------------------------- + //------------------------------------- + // 4. Compute overlap_Q1 and Q2 + //------------------------------------- // nks now is the reduced k-points. for (int ik=0; ikngk[ik]; - GlobalV::ofs_running << " --------------------------------------------------------" << std::endl; - GlobalV::ofs_running << " Print the overlap matrixs Q and S for this kpoint"; + GlobalV::ofs_running << " --------------------------------------------------------" << std::endl; + GlobalV::ofs_running << " Print the overlap matrixs Q and S for this kpoint"; GlobalV::ofs_running << "\n " << std::setw(8) << "ik" << std::setw(8) << "npw"; GlobalV::ofs_running << "\n " << std::setw(8) << ik+1 << std::setw(8) << npw << std::endl; - GlobalV::ofs_running << " --------------------------------------------------------" << std::endl; + GlobalV::ofs_running << " --------------------------------------------------------" << std::endl; // search for all k-points. - psi.fix_k(ik); + psi.fix_k(ik); this->jlq3d_overlap(overlap_Q1, overlap_Q2, ik, ik, npw, psi); ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running,"jlq3d_overlap"); - } + } #ifdef __MPI Parallel_Reduce::reduce_double_pool( overlap_Q1.ptr, overlap_Q1.getSize() ); Parallel_Reduce::reduce_double_pool( overlap_Q2.ptr, overlap_Q2.getSize() ); #endif - // do not need to output here + // do not need to output here //this->output_overlap_Q( ofs, overlap_Q1, overlap_Q2 ); - - //------------------------------------- - // 5. Generate descriptors for each atom - //------------------------------------- - - for (int it=0; itgenerate_descriptor(overlap_Q1, overlap_Q2, it ,ia, d, nd); - - ofs << ucell.atoms[it].label << " atom_index " << ia+1 << " n_descriptor " << nd << std::endl; - for(int id=0; id0 && id%8==0) ofs << std::endl; - // if(std::abs(d[id]>1.0e-9)) ofs << d[id] << " "; - // else ofs << "0 "; - ofs << d[id] << " "; - } - ofs << std::endl; - - delete[] d; - } - } + + //------------------------------------- + // 5. Generate descriptors for each atom + //------------------------------------- + + for (int it=0; itgenerate_descriptor(overlap_Q1, overlap_Q2, it ,ia, d, nd); + + ofs << ucell.atoms[it].label << " atom_index " << ia+1 << " n_descriptor " << nd << std::endl; + for(int id=0; id0 && id%8==0) ofs << std::endl; + // if(std::abs(d[id]>1.0e-9)) ofs << d[id] << " "; + // else ofs << "0 "; + ofs << d[id] << " "; + } + ofs << std::endl; + + delete[] d; + } + } @@ -336,48 +336,48 @@ normalization 2015-12-29 for (int ie=0; ie < nmax; ie++) void Numerical_Descriptor::init_mu_index(const UnitCell& ucell) { - GlobalV::ofs_running << " Initialize the mu index for deepks" << std::endl; - GlobalV::ofs_running << " lmax = " << this->lmax << std::endl; - GlobalV::ofs_running << " nmax = " << this->nmax << std::endl; + GlobalV::ofs_running << " Initialize the mu index for deepks" << std::endl; + GlobalV::ofs_running << " lmax = " << this->lmax << std::endl; + GlobalV::ofs_running << " nmax = " << this->nmax << std::endl; Numerical_Descriptor::mu_index = new ModuleBase::IntArray[ucell.ntype]; - assert(lmax>=0); - assert(nmax>0); - - int mu=0; - for (int it=0; itmu_index[it].create( - ucell.atoms[it].na, - lmax+1, // l starts from 0 - nmax, - 2*lmax+1); // m ==> 2*l+1 - - GlobalV::ofs_running << "Type " << it+1 - << " number_of_atoms " << ucell.atoms[it].na - << " number_of_L " << lmax+1 - << " number_of_n " << nmax - << " number_of_m " << 2*lmax+1 << std::endl; + assert(lmax>=0); + assert(nmax>0); + + int mu=0; + for (int it=0; itmu_index[it].create( + ucell.atoms[it].na, + lmax+1, // l starts from 0 + nmax, + 2*lmax+1); // m ==> 2*l+1 + + GlobalV::ofs_running << "Type " << it+1 + << " number_of_atoms " << ucell.atoms[it].na + << " number_of_L " << lmax+1 + << " number_of_n " << nmax + << " number_of_m " << 2*lmax+1 << std::endl; for (int ia=0; iamu_index[it](ia,l,n,m) = mu; - mu++; - } - } - } - } - - } - - this->nlocal = mu; - GlobalV::ofs_running << " total number of atomic orbitals " << nlocal << std::endl; - - return; + { + for (int l=0; lmu_index[it](ia,l,n,m) = mu; + mu++; + } + } + } + } + + } + + this->nlocal = mu; + GlobalV::ofs_running << " total number of atomic orbitals " << nlocal << std::endl; + + return; } diff --git a/source/source_io/module_bessel/numerical_descriptor.h b/source/source_io/module_bessel/numerical_descriptor.h index 6cd76f1d1cc..27be396732f 100644 --- a/source/source_io/module_bessel/numerical_descriptor.h +++ b/source/source_io/module_bessel/numerical_descriptor.h @@ -15,30 +15,30 @@ //========================================================== class Numerical_Descriptor { - public: - Numerical_Descriptor(); - ~Numerical_Descriptor(); + public: + Numerical_Descriptor(); + ~Numerical_Descriptor(); - void output_descriptor(const UnitCell& ucell, const psi::Psi> &psi, const int &lmax_in, const double &rcut_in, const double &tol_in, const int nks); // mohan added 2021-01-03 + void output_descriptor(const UnitCell& ucell, const psi::Psi> &psi, const int &lmax_in, const double &rcut_in, const double &tol_in, const int nks); // mohan added 2021-01-03 - private: + private: - bool init_label; + bool init_label; - int lmax; // lmax for descriptor - int nmax; // nmax for descriptor - int nlocal; // total number of atomic orbitals + int lmax; // lmax for descriptor + int nmax; // nmax for descriptor + int nlocal; // total number of atomic orbitals - Bessel_Basis bessel_basis; + Bessel_Basis bessel_basis; - ModuleBase::IntArray * mu_index = nullptr; - void init_mu_index(const UnitCell& ucell);//mohan added 2021-01-03 + ModuleBase::IntArray * mu_index = nullptr; + void init_mu_index(const UnitCell& ucell);//mohan added 2021-01-03 - // void jlq3d_overlap(ModuleBase::realArray &overlap_Q1, ModuleBase::realArray &overlap_Q2, - // const int &ik_ibz, const int &ik, const int &np, const psi::Psi> &psi); + // void jlq3d_overlap(ModuleBase::realArray &overlap_Q1, ModuleBase::realArray &overlap_Q2, + // const int &ik_ibz, const int &ik, const int &np, const psi::Psi> &psi); - // void generate_descriptor(ModuleBase::realArray &overlap_Q1, ModuleBase::realArray &overlap_Q2, - // const int &it, const int &ia, double *d, const int &nd); + // void generate_descriptor(ModuleBase::realArray &overlap_Q1, ModuleBase::realArray &overlap_Q2, + // const int &it, const int &ia, double *d, const int &nd); }; diff --git a/source/source_io/module_chgpot/write_libxc_r.h b/source/source_io/module_chgpot/write_libxc_r.h index 58e2f215565..4573b70e791 100644 --- a/source/source_io/module_chgpot/write_libxc_r.h +++ b/source/source_io/module_chgpot/write_libxc_r.h @@ -17,35 +17,35 @@ namespace ModulePW{ class PW_Basis; } namespace ModuleIO { - extern void write_libxc_r( - const int order, - const std::vector &func_id, - const int &nrxx, // number of real-space grid - const double &omega, // volume of cell - const double tpiba, - const Charge &chr, - const ModulePW::PW_Basis_Big &pw_big, - const ModulePW::PW_Basis &pw_rhod); + extern void write_libxc_r( + const int order, + const std::vector &func_id, + const int &nrxx, // number of real-space grid + const double &omega, // volume of cell + const double tpiba, + const Charge &chr, + const ModulePW::PW_Basis_Big &pw_big, + const ModulePW::PW_Basis &pw_rhod); #ifdef __MPI - extern void write_cube_core( - std::ofstream &ofs_cube, - const int bz, - const int nbz, - const int nplane, - const int startz_current, - const double*const data, - const int nxy, - const int nz, - const int nld, - const int n_data_newline); + extern void write_cube_core( + std::ofstream &ofs_cube, + const int bz, + const int nbz, + const int nplane, + const int startz_current, + const double*const data, + const int nxy, + const int nz, + const int nld, + const int n_data_newline); #else - extern void write_cube_core( - std::ofstream &ofs_cube, - const double*const data, - const int nxy, - const int nz, - const int n_data_newline); + extern void write_cube_core( + std::ofstream &ofs_cube, + const double*const data, + const int nxy, + const int nz, + const int n_data_newline); #endif } diff --git a/source/source_io/module_dos/cal_dos.cpp b/source/source_io/module_dos/cal_dos.cpp index 2e3e7f869ce..a66e2aa2bd3 100644 --- a/source/source_io/module_dos/cal_dos.cpp +++ b/source/source_io/module_dos/cal_dos.cpp @@ -7,24 +7,24 @@ #include "source_io/module_parameter/parameter.h" void ModuleIO::prepare_dos(std::ofstream& ofs_running, - const elecstate::Efermi &energy_fermi, + const elecstate::Efermi &energy_fermi, const ModuleBase::matrix& ekb, const int nks, const int nbands, - const double& dos_edelta_ev, - const double& dos_scale, - double &emax, - double &emin) + const double& dos_edelta_ev, + const double& dos_scale, + double &emax, + double &emin) { - ofs_running << "\n >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl; - ofs_running << " | |" << std::endl; + ofs_running << "\n >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl; + ofs_running << " | |" << std::endl; ofs_running << " | #Calcualte Density of States (DOS)# |" << std::endl; - ofs_running << " | DOS stands for Density of States. It represents the number of |" << std::endl; - ofs_running << " | available electronic states per unit energy range. |" << std::endl; - ofs_running << " | By analyzing the DOS, we can gain insights into how electrons are |" << std::endl; - ofs_running << " | distributed among different energy levels within the material. |" << std::endl; - ofs_running << " | |" << std::endl; - ofs_running << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl; + ofs_running << " | DOS stands for Density of States. It represents the number of |" << std::endl; + ofs_running << " | available electronic states per unit energy range. |" << std::endl; + ofs_running << " | By analyzing the DOS, we can gain insights into how electrons are |" << std::endl; + ofs_running << " | distributed among different energy levels within the material. |" << std::endl; + ofs_running << " | |" << std::endl; + ofs_running << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl; ofs_running << std::setprecision(6); @@ -89,18 +89,18 @@ void ModuleIO::prepare_dos(std::ofstream& ofs_running, } bool ModuleIO::cal_dos(const int& is, // index for spin - const std::string& fn, // file name for DOS - const double& de_ev, // delta energy in ev - const double& emax_ev, // maximal energy in eV - const double& emin_ev, // minimal energy in ev. - const double& bcoeff, - const int& nks, // number of k points in this pool - const int& nkstot, // number of total kpoints - const std::vector& wk, // weight of k points - const std::vector& isk, // index of spin for each k-point - const int& nbands, // number of bands - const ModuleBase::matrix& ekb, // energy for each k point and each band - const ModuleBase::matrix& wg, // weight of k-points and bands + const std::string& fn, // file name for DOS + const double& de_ev, // delta energy in ev + const double& emax_ev, // maximal energy in eV + const double& emin_ev, // minimal energy in ev. + const double& bcoeff, + const int& nks, // number of k points in this pool + const int& nkstot, // number of total kpoints + const std::vector& wk, // weight of k points + const std::vector& isk, // index of spin for each k-point + const int& nbands, // number of bands + const ModuleBase::matrix& ekb, // energy for each k point and each band + const ModuleBase::matrix& wg, // weight of k-points and bands const int istep) // ionic step { ModuleBase::TITLE("ModuleIO", "cal_dos"); @@ -109,14 +109,14 @@ bool ModuleIO::cal_dos(const int& is, // index for spin if (GlobalV::MY_RANK == 0) { - if(PARAM.inp.out_app_flag==true) - { - ofs_dos.open(fn.c_str(), std::ios::app); - } - else - { - ofs_dos.open(fn.c_str()); - } + if(PARAM.inp.out_app_flag==true) + { + ofs_dos.open(fn.c_str(), std::ios::app); + } + else + { + ofs_dos.open(fn.c_str()); + } ofs_dos << istep+1 << " # ionic step" << std::endl; } diff --git a/source/source_io/module_dos/cal_dos.h b/source/source_io/module_dos/cal_dos.h index c56891f6dbf..d4da72427a4 100644 --- a/source/source_io/module_dos/cal_dos.h +++ b/source/source_io/module_dos/cal_dos.h @@ -8,29 +8,29 @@ namespace ModuleIO { - void prepare_dos(std::ofstream& ofs_running, - const elecstate::Efermi &energy_fermi, - const ModuleBase::matrix& ekb, - const int nks, - const int nbands, - const double& dos_edelta_ev, + void prepare_dos(std::ofstream& ofs_running, + const elecstate::Efermi &energy_fermi, + const ModuleBase::matrix& ekb, + const int nks, + const int nbands, + const double& dos_edelta_ev, const double& dos_scale, - double &emax, + double &emax, double &emin); - bool cal_dos(const int &is, - const std::string &fn,// file address for DOS. - const double &de_ev, // delta energy in ev. - const double &emax_ev,// maximal energy in ev. - const double &emin_ev,// minimal energy in ev. - const double &bcoeff, - const int &nks, //number of k points - const int &nkstot, // total number of k points - const std::vector &wk,//weight of k points - const std::vector &isk, - const int &nbands,// number of bands - const ModuleBase::matrix &ekb, //store energy for each k point and each band - const ModuleBase::matrix &wg, //weight of (kpoint,bands)) + bool cal_dos(const int &is, + const std::string &fn,// file address for DOS. + const double &de_ev, // delta energy in ev. + const double &emax_ev,// maximal energy in ev. + const double &emin_ev,// minimal energy in ev. + const double &bcoeff, + const int &nks, //number of k points + const int &nkstot, // total number of k points + const std::vector &wk,//weight of k points + const std::vector &isk, + const int &nbands,// number of bands + const ModuleBase::matrix &ekb, //store energy for each k point and each band + const ModuleBase::matrix &wg, //weight of (kpoint,bands)) const int istep_in); // ionic_step diff --git a/source/source_io/module_dos/cal_pdos_gamma.h b/source/source_io/module_dos/cal_pdos_gamma.h index bde8702e1b0..a18d43120a3 100644 --- a/source/source_io/module_dos/cal_pdos_gamma.h +++ b/source/source_io/module_dos/cal_pdos_gamma.h @@ -10,34 +10,34 @@ namespace ModuleIO { - void cal_pdos( - const psi::Psi* psi, - hamilt::Hamilt* p_ham, - const Parallel_Orbitals& pv, - const UnitCell& ucell, - const K_Vectors& kv, - const int nspin0, - const int nbands, - const ModuleBase::matrix& ekb, - const double& emax, - const double& emin, - const double& dos_edelta_ev, - const double& bcoeff); + void cal_pdos( + const psi::Psi* psi, + hamilt::Hamilt* p_ham, + const Parallel_Orbitals& pv, + const UnitCell& ucell, + const K_Vectors& kv, + const int nspin0, + const int nbands, + const ModuleBase::matrix& ekb, + const double& emax, + const double& emin, + const double& dos_edelta_ev, + const double& bcoeff); - void print_tdos_gamma( - const ModuleBase::matrix* pdos, - const int nlocal, - const int npoints, - const double& emin, - const double& dos_edelta_ev); + void print_tdos_gamma( + const ModuleBase::matrix* pdos, + const int nlocal, + const int npoints, + const double& emin, + const double& dos_edelta_ev); - void print_pdos_gamma( - const UnitCell& ucell, - const ModuleBase::matrix* pdos, - const int nlocal, - const int npoints, - const double& emin, - const double& dos_edelta_ev); + void print_pdos_gamma( + const UnitCell& ucell, + const ModuleBase::matrix* pdos, + const int nlocal, + const int npoints, + const double& emin, + const double& dos_edelta_ev); } diff --git a/source/source_io/module_dos/cal_pdos_multik.h b/source/source_io/module_dos/cal_pdos_multik.h index 2b59365c1a5..35e791080d2 100644 --- a/source/source_io/module_dos/cal_pdos_multik.h +++ b/source/source_io/module_dos/cal_pdos_multik.h @@ -11,34 +11,34 @@ namespace ModuleIO { // pdos for multi-k point - void cal_pdos( - const psi::Psi>* psi, - hamilt::Hamilt>* p_ham, - const Parallel_Orbitals& pv, - const UnitCell& ucell, - const K_Vectors& kv, - const int nspin0, - const int nbands, - const ModuleBase::matrix& ekb, - const double& emax, - const double& emin, - const double& dos_edelta_ev, - const double& bcoeff); + void cal_pdos( + const psi::Psi>* psi, + hamilt::Hamilt>* p_ham, + const Parallel_Orbitals& pv, + const UnitCell& ucell, + const K_Vectors& kv, + const int nspin0, + const int nbands, + const ModuleBase::matrix& ekb, + const double& emax, + const double& emin, + const double& dos_edelta_ev, + const double& bcoeff); - void print_tdos_multik( - const ModuleBase::matrix* pdos, - const int nlocal, - const int npoints, - const double& emin, - const double& dos_edelta_ev); + void print_tdos_multik( + const ModuleBase::matrix* pdos, + const int nlocal, + const int npoints, + const double& emin, + const double& dos_edelta_ev); - void print_pdos_multik( - const UnitCell& ucell, - const ModuleBase::matrix* pdos, - const int nlocal, - const int npoints, - const double& emin, - const double& dos_edelta_ev); + void print_pdos_multik( + const UnitCell& ucell, + const ModuleBase::matrix* pdos, + const int nlocal, + const int npoints, + const double& emin, + const double& dos_edelta_ev); } diff --git a/source/source_io/module_dos/write_dos_lcao.cpp b/source/source_io/module_dos/write_dos_lcao.cpp index 359b22fee4b..c2699649624 100644 --- a/source/source_io/module_dos/write_dos_lcao.cpp +++ b/source/source_io/module_dos/write_dos_lcao.cpp @@ -11,12 +11,12 @@ namespace ModuleIO template void write_dos_lcao( const psi::Psi* psi, - hamilt::Hamilt* p_ham, + hamilt::Hamilt* p_ham, const Parallel_Orbitals &pv, const UnitCell& ucell, - const K_Vectors& kv, - const int nbands, - const elecstate::Efermi &energy_fermi, + const K_Vectors& kv, + const int nbands, + const elecstate::Efermi &energy_fermi, const ModuleBase::matrix& ekb, const ModuleBase::matrix& wg, const double& dos_edelta_ev, @@ -33,15 +33,15 @@ void write_dos_lcao( double emax = 0.0; double emin = 0.0; - prepare_dos(ofs_running, - energy_fermi, - ekb, - kv.get_nks(), - nbands, - dos_edelta_ev, - dos_scale, - emax, - emin); + prepare_dos(ofs_running, + energy_fermi, + ekb, + kv.get_nks(), + nbands, + dos_edelta_ev, + dos_scale, + emax, + emin); // output the DOS file. for (int is = 0; is < nspin0; ++is) @@ -50,44 +50,44 @@ void write_dos_lcao( ss << PARAM.globalv.global_out_dir << "doss" << is + 1; - if(istep>=0) - { + if(istep>=0) + { ss << "g" << istep+1; - } + } ss << "_nao.txt"; - ModuleIO::cal_dos(is, - ss.str(), - dos_edelta_ev, - emax, - emin, - bcoeff, - kv.get_nks(), - kv.get_nkstot(), - kv.wk, - kv.isk, - nbands, - ekb, - wg, - istep); - } + ModuleIO::cal_dos(is, + ss.str(), + dos_edelta_ev, + emax, + emin, + bcoeff, + kv.get_nks(), + kv.get_nkstot(), + kv.wk, + kv.isk, + nbands, + ekb, + wg, + istep); + } if (PARAM.inp.out_dos == 2) { - cal_pdos(psi, - p_ham, - pv, - ucell, - kv, - nspin0, - nbands, - ekb, - emax, - emin, - dos_edelta_ev, - bcoeff); + cal_pdos(psi, + p_ham, + pv, + ucell, + kv, + nspin0, + nbands, + ekb, + emax, + emin, + dos_edelta_ev, + bcoeff); } if(PARAM.inp.out_dos == 3) @@ -108,12 +108,12 @@ void write_dos_lcao( template void write_dos_lcao( const psi::Psi* psi, - hamilt::Hamilt* p_ham, + hamilt::Hamilt* p_ham, const Parallel_Orbitals &pv, const UnitCell& ucell, - const K_Vectors& kv, - const int nbands, - const elecstate::Efermi &energy_fermi, + const K_Vectors& kv, + const int nbands, + const elecstate::Efermi &energy_fermi, const ModuleBase::matrix& ekb, const ModuleBase::matrix& wg, const double& dos_edelta_ev, @@ -126,12 +126,12 @@ template void write_dos_lcao( template void write_dos_lcao( const psi::Psi>* psi, - hamilt::Hamilt>* p_ham, + hamilt::Hamilt>* p_ham, const Parallel_Orbitals &pv, const UnitCell& ucell, - const K_Vectors& kv, - const int nbands, - const elecstate::Efermi &energy_fermi, + const K_Vectors& kv, + const int nbands, + const elecstate::Efermi &energy_fermi, const ModuleBase::matrix& ekb, const ModuleBase::matrix& wg, const double& dos_edelta_ev, diff --git a/source/source_io/module_dos/write_dos_lcao.h b/source/source_io/module_dos/write_dos_lcao.h index 88b186f3f9a..ad6f6bf92a3 100644 --- a/source/source_io/module_dos/write_dos_lcao.h +++ b/source/source_io/module_dos/write_dos_lcao.h @@ -11,18 +11,18 @@ namespace ModuleIO { - /// @brief calculate density of states(DOS), + /// @brief calculate density of states(DOS), /// partial density of states(PDOS), /// and mulliken charge for LCAO base template void write_dos_lcao( const psi::Psi* psi, // LCAO wave functions - hamilt::Hamilt* p_ham, // Hamiltonian + hamilt::Hamilt* p_ham, // Hamiltonian const Parallel_Orbitals &pv, // Parallel scheme for LCAO wave functions const UnitCell& ucell, // Unit cell information - const K_Vectors& kv, // k-point information in Brillouin zone - const int nbands, // Number of bands - const elecstate::Efermi &energy_fermi, // Fermi energy + const K_Vectors& kv, // k-point information in Brillouin zone + const int nbands, // Number of bands + const elecstate::Efermi &energy_fermi, // Fermi energy const ModuleBase::matrix& ekb, // Eigenvalues per k-point and band const ModuleBase::matrix& wg, // Weights of eigenvalues const double& dos_edelta_ev, // Delta energy diff --git a/source/source_io/module_dos/write_dos_pw.cpp b/source/source_io/module_dos/write_dos_pw.cpp index bfcc094d5cb..e1c9a388276 100644 --- a/source/source_io/module_dos/write_dos_pw.cpp +++ b/source/source_io/module_dos/write_dos_pw.cpp @@ -5,17 +5,17 @@ #include "source_io/module_parameter/parameter.h" void ModuleIO::write_dos_pw( - const UnitCell& ucell, - const ModuleBase::matrix& ekb, - const ModuleBase::matrix& wg, - const K_Vectors& kv, - const int nbands, + const UnitCell& ucell, + const ModuleBase::matrix& ekb, + const ModuleBase::matrix& wg, + const K_Vectors& kv, + const int nbands, const int istep_in, - const elecstate::Efermi &energy_fermi, - const double& dos_edelta_ev, - const double& dos_scale, - const double& bcoeff, - std::ofstream& ofs_running) + const elecstate::Efermi &energy_fermi, + const double& dos_edelta_ev, + const double& dos_scale, + const double& bcoeff, + std::ofstream& ofs_running) { ModuleBase::TITLE("ModuleIO", "write_dos_pw"); @@ -24,50 +24,50 @@ void ModuleIO::write_dos_pw( double emax = 0.0; double emin = 0.0; - prepare_dos(ofs_running, - energy_fermi, - ekb, - kv.get_nks(), - nbands, - dos_edelta_ev, + prepare_dos(ofs_running, + energy_fermi, + ekb, + kv.get_nks(), + nbands, + dos_edelta_ev, dos_scale, - emax, - emin); + emax, + emin); for (int is = 0; is < nspin0; ++is) { // DOS_ispin contains not smoothed dos - std::stringstream ss; - ss << PARAM.globalv.global_out_dir << "dos"; + std::stringstream ss; + ss << PARAM.globalv.global_out_dir << "dos"; - if(nspin0==2) - { - ss << "s" << is + 1; - } - else - { - // do nothing; - } + if(nspin0==2) + { + ss << "s" << is + 1; + } + else + { + // do nothing; + } - ss << ".txt"; + ss << ".txt"; ModuleBase::GlobalFunc::OUT(ofs_running, "DOS file", ss.str()); - ModuleIO::cal_dos(is, - ss.str(), - dos_edelta_ev, - emax, - emin, - bcoeff, - kv.get_nks(), - kv.get_nkstot(), - kv.wk, - kv.isk, - nbands, - ekb, - wg, - istep_in); - } + ModuleIO::cal_dos(is, + ss.str(), + dos_edelta_ev, + emax, + emin, + bcoeff, + kv.get_nks(), + kv.get_nkstot(), + kv.wk, + kv.isk, + nbands, + ekb, + wg, + istep_in); + } if (PARAM.inp.out_dos == 2) diff --git a/source/source_io/module_dos/write_dos_pw.h b/source/source_io/module_dos/write_dos_pw.h index 44f507d84e9..718b7fce1c5 100644 --- a/source/source_io/module_dos/write_dos_pw.h +++ b/source/source_io/module_dos/write_dos_pw.h @@ -8,18 +8,18 @@ namespace ModuleIO { - /// @brief calculate density of states(DOS) for PW base - void write_dos_pw( - const UnitCell& ucell, - const ModuleBase::matrix &ekb, - const ModuleBase::matrix &wg, - const K_Vectors& kv, - const int nbands, - const int istep_in, - const elecstate::Efermi &energy_fermi, - const double &dos_edelta_ev, - const double &dos_scale, - const double &bcoeff, - std::ofstream& ofs_running); + /// @brief calculate density of states(DOS) for PW base + void write_dos_pw( + const UnitCell& ucell, + const ModuleBase::matrix &ekb, + const ModuleBase::matrix &wg, + const K_Vectors& kv, + const int nbands, + const int istep_in, + const elecstate::Efermi &energy_fermi, + const double &dos_edelta_ev, + const double &dos_scale, + const double &bcoeff, + std::ofstream& ofs_running); } #endif diff --git a/source/source_io/module_energy/nscf_fermi_surf.cpp b/source/source_io/module_energy/nscf_fermi_surf.cpp index 99679f7f102..b81cfeefaa3 100644 --- a/source/source_io/module_energy/nscf_fermi_surf.cpp +++ b/source/source_io/module_energy/nscf_fermi_surf.cpp @@ -9,85 +9,85 @@ #endif void ModuleIO::nscf_fermi_surface(const std::string &out_band_dir, - const int &nband, - const double &ef, - const K_Vectors& kv, - const UnitCell& ucell, - const ModuleBase::matrix &ekb) + const int &nband, + const double &ef, + const K_Vectors& kv, + const UnitCell& ucell, + const ModuleBase::matrix &ekb) { - ModuleBase::TITLE("ModuleIO","nscf_fermi_surface"); - ModuleBase::timer::start("ModuleIO", "nscf_fermi_surface"); + ModuleBase::TITLE("ModuleIO","nscf_fermi_surface"); + ModuleBase::timer::start("ModuleIO", "nscf_fermi_surface"); #ifdef __MPI - const int start = 1; - const int end = PARAM.inp.nbands; + const int start = 1; + const int end = PARAM.inp.nbands; - std::ofstream ofs; - if(GlobalV::MY_RANK==0) - { - ofs.open(out_band_dir.c_str()); - ofs << std::setprecision(6); - ofs.close(); - } + std::ofstream ofs; + if(GlobalV::MY_RANK==0) + { + ofs.open(out_band_dir.c_str()); + ofs << std::setprecision(6); + ofs.close(); + } - for(int ik=0; ik& hR) - { - if (std::is_same::value) - { - hR.fix_gamma(); - } - }; - - auto all_band_energy = [&wg](const int ik, const std::vector& e_orb)->double - { - double e = 0; - for (int i = 0; i < e_orb.size(); ++i) { e += e_orb[i] * wg(ik, i); } - return e; - }; - - auto all_k_all_band_energy = [&wg, &all_band_energy](const std::vector>& e_orb)->double - { - double e = 0; - for (int ik = 0; ik < e_orb.size(); ++ik) - { - e += all_band_energy(ik, e_orb[ik]); - } - return e; - }; + auto if_gamma_fix = [](hamilt::HContainer& hR) + { + if (std::is_same::value) + { + hR.fix_gamma(); + } + }; + + auto all_band_energy = [&wg](const int ik, const std::vector& e_orb)->double + { + double e = 0; + for (int i = 0; i < e_orb.size(); ++i) { e += e_orb[i] * wg(ik, i); } + return e; + }; + + auto all_k_all_band_energy = [&wg, &all_band_energy](const std::vector>& e_orb)->double + { + double e = 0; + for (int ik = 0; ik < e_orb.size(); ++ik) + { + e += all_band_energy(ik, e_orb[ik]); + } + return e; + }; // 1. kinetic if (PARAM.inp.t_in_h) @@ -106,15 +106,15 @@ void write_eband_terms(const int nspin, if_gamma_fix(v_pp_local_R_ao); std::vector> e_orb_pp_local; - hamilt::Veff> v_pp_local_op( - &v_pp_local_k_ao, - kv.kvec_d, - &pot_local, - &v_pp_local_R_ao, - &ucell, - orb_cutoff, - &gd, - nspin); + hamilt::Veff> v_pp_local_op( + &v_pp_local_k_ao, + kv.kvec_d, + &pot_local, + &v_pp_local_R_ao, + &ucell, + orb_cutoff, + &gd, + nspin); v_pp_local_op.contributeHR(); for (int ik = 0;ik < kv.get_nks();++ik) diff --git a/source/source_io/module_energy/write_eig_occ.cpp b/source/source_io/module_energy/write_eig_occ.cpp index d5675e7e2de..79c9be48797 100644 --- a/source/source_io/module_energy/write_eig_occ.cpp +++ b/source/source_io/module_energy/write_eig_occ.cpp @@ -13,15 +13,15 @@ #endif void ModuleIO::write_eig_iter(const ModuleBase::matrix &ekb, - const ModuleBase::matrix &wg, - const K_Vectors& kv, - const int nbands, - const int nspin) + const ModuleBase::matrix &wg, + const K_Vectors& kv, + const int nbands, + const int nspin) { ModuleBase::TITLE("ModuleIO","write_eig_iter"); - ModuleBase::timer::start("ModuleIO", "write_eig_iter"); + ModuleBase::timer::start("ModuleIO", "write_eig_iter"); - GlobalV::ofs_running << "\n PRINT #EIGENVALUES# AND #OCCUPATIONS#" << std::endl; + GlobalV::ofs_running << "\n PRINT #EIGENVALUES# AND #OCCUPATIONS#" << std::endl; // Taoni fix bndpar on 2026-08-21 const Parallel::ParaBandOutput band_output(ekb.nc, nbands, Parallel::make_band_world()); @@ -29,7 +29,7 @@ void ModuleIO::write_eig_iter(const ModuleBase::matrix &ekb, const ModuleBase::matrix global_wg = band_output.gather_matrix(wg); const int nks = kv.get_nks(); - const int nkstot = kv.get_nkstot(); + const int nkstot = kv.get_nkstot(); const int nk_fac = nspin == 2 ? 2 : 1; const int nks_np = nks / nk_fac; const int nkstot_np = nkstot / nk_fac; @@ -71,7 +71,7 @@ void ModuleIO::write_eig_iter(const ModuleBase::matrix &ekb, } } - + // ============================================================= // MPI communication: // RANK 0 collect and print out #EIGENVALUES# AND #OCCUPATIONS# for all k-points @@ -161,28 +161,28 @@ void ModuleIO::write_eig_iter(const ModuleBase::matrix &ekb, } - ModuleBase::timer::end("ModuleIO", "write_eig_iter"); + ModuleBase::timer::end("ModuleIO", "write_eig_iter"); } void ModuleIO::write_eig_file(const ModuleBase::matrix &ekb, - const ModuleBase::matrix &wg, - const K_Vectors& kv, - const int nbands, - const int nspin, - const std::string& out_dir, - const int istep) + const ModuleBase::matrix &wg, + const K_Vectors& kv, + const int nbands, + const int nspin, + const std::string& out_dir, + const int istep) { - ModuleBase::TITLE("ModuleIO","write_eig_file"); - ModuleBase::timer::start("ModuleIO", "write_eig_file"); + ModuleBase::TITLE("ModuleIO","write_eig_file"); + ModuleBase::timer::start("ModuleIO", "write_eig_file"); /* - GlobalV::ofs_running << "\n"; - GlobalV::ofs_running << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl; - GlobalV::ofs_running << " | |" << std::endl; - GlobalV::ofs_running << " | #Print out the eigenvalues and occupations# |" << std::endl; - GlobalV::ofs_running << " | |" << std::endl; - GlobalV::ofs_running << " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl; - GlobalV::ofs_running << "\n"; + GlobalV::ofs_running << "\n"; + GlobalV::ofs_running << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl; + GlobalV::ofs_running << " | |" << std::endl; + GlobalV::ofs_running << " | #Print out the eigenvalues and occupations# |" << std::endl; + GlobalV::ofs_running << " | |" << std::endl; + GlobalV::ofs_running << " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl; + GlobalV::ofs_running << "\n"; */ // Taoni fix bndpar on 2026-08-21 @@ -190,22 +190,22 @@ void ModuleIO::write_eig_file(const ModuleBase::matrix &ekb, const ModuleBase::matrix global_ekb = band_output.gather_matrix(ekb); const ModuleBase::matrix global_wg = band_output.gather_matrix(wg); const int nks = kv.get_nks(); - const int nkstot = kv.get_nkstot(); + const int nkstot = kv.get_nkstot(); bool wrong = false; - for (int ik = 0; ik < nks; ++ik) - { - for (int ib = 0; ib < ekb.nc; ++ib) - { - if (std::abs(ekb(ik, ib)) > 1.0e10) - { - GlobalV::ofs_warning << " ik=" << ik + 1 << " ib=" << ib + 1 - << " " << ekb(ik, ib) << " Ry" << std::endl; - wrong = true; - } - } - } + for (int ik = 0; ik < nks; ++ik) + { + for (int ib = 0; ib < ekb.nc; ++ib) + { + if (std::abs(ekb(ik, ib)) > 1.0e10) + { + GlobalV::ofs_warning << " ik=" << ik + 1 << " ib=" << ib + 1 + << " " << ekb(ik, ib) << " Ry" << std::endl; + wrong = true; + } + } + } #ifdef __MPI MPI_Allreduce(MPI_IN_PLACE, &wrong, 1, MPI_C_BOOL, MPI_LOR, MPI_COMM_WORLD); @@ -232,14 +232,14 @@ void ModuleIO::write_eig_file(const ModuleBase::matrix &ekb, const bool append = istep > 0 || (inp.calculation == "md" && inp.mdp.md_restart); - if (append) - { - ofs_eig0.open(filename.c_str(), std::ios::app); - } - else - { - ofs_eig0.open(filename.c_str()); - } + if (append) + { + ofs_eig0.open(filename.c_str(), std::ios::app); + } + else + { + ofs_eig0.open(filename.c_str()); + } ofs_eig0 << istep+1 << " # ionic step" << std::endl; ofs_eig0 << " Electronic state energy (eV) and occupations" << std::endl; @@ -300,6 +300,6 @@ void ModuleIO::write_eig_file(const ModuleBase::matrix &ekb, #endif } - ModuleBase::timer::end("ModuleIO", "write_eig_file"); - return; + ModuleBase::timer::end("ModuleIO", "write_eig_file"); + return; } diff --git a/source/source_io/module_energy/write_eig_occ.h b/source/source_io/module_energy/write_eig_occ.h index 42b945aebe4..5a39a26f661 100644 --- a/source/source_io/module_energy/write_eig_occ.h +++ b/source/source_io/module_energy/write_eig_occ.h @@ -7,26 +7,26 @@ namespace ModuleIO { - /// @brief print eigenvalues and occupations to the running log - /// @param nbands number of bands requested by INPUT - /// @param nspin number of spin channels - void write_eig_iter(const ModuleBase::matrix &ekb, - const ModuleBase::matrix &wg, - const K_Vectors& kv, - const int nbands, - const int nspin); + /// @brief print eigenvalues and occupations to the running log + /// @param nbands number of bands requested by INPUT + /// @param nspin number of spin channels + void write_eig_iter(const ModuleBase::matrix &ekb, + const ModuleBase::matrix &wg, + const K_Vectors& kv, + const int nbands, + const int nspin); - /// @brief write eigenvalues and occupations to /eig_occ.txt - /// @param nbands number of bands requested by INPUT - /// @param nspin number of spin channels - /// @param out_dir directory the file is written into - void write_eig_file(const ModuleBase::matrix &ekb, - const ModuleBase::matrix &wg, - const K_Vectors& kv, - const int nbands, - const int nspin, - const std::string& out_dir, - const int istep); + /// @brief write eigenvalues and occupations to /eig_occ.txt + /// @param nbands number of bands requested by INPUT + /// @param nspin number of spin channels + /// @param out_dir directory the file is written into + void write_eig_file(const ModuleBase::matrix &ekb, + const ModuleBase::matrix &wg, + const K_Vectors& kv, + const int nbands, + const int nspin, + const std::string& out_dir, + const int istep); } #endif diff --git a/source/source_io/module_energy/write_proj_band_lcao.h b/source/source_io/module_energy/write_proj_band_lcao.h index af005ae5712..3dd4cfa8c4c 100644 --- a/source/source_io/module_energy/write_proj_band_lcao.h +++ b/source/source_io/module_energy/write_proj_band_lcao.h @@ -12,10 +12,10 @@ namespace ModuleIO template void write_proj_band_lcao( const psi::Psi* psi, - const Parallel_Orbitals &pv, - const elecstate::ElecState* pelec, - const K_Vectors& kv, - const UnitCell &ucell, + const Parallel_Orbitals &pv, + const elecstate::ElecState* pelec, + const K_Vectors& kv, + const UnitCell &ucell, hamilt::Hamilt* p_ham); } diff --git a/source/source_io/module_hs/output_mat_sparse.h b/source/source_io/module_hs/output_mat_sparse.h index 44d44826b81..1ed0f8f191a 100644 --- a/source/source_io/module_hs/output_mat_sparse.h +++ b/source/source_io/module_hs/output_mat_sparse.h @@ -52,8 +52,8 @@ void output_mat_sparse(const bool& out_mat_dh, UnitCell& ucell, const Grid_Driver& grid, const K_Vectors& kv, - hamilt::Hamilt* p_ham, - Plus_U_Base* p_dftu); + hamilt::Hamilt* p_ham, + Plus_U_Base* p_dftu); } // namespace ModuleIO #endif // OUTPUT_MAT_SPARSE_H diff --git a/source/source_io/module_hs/write_hs.h b/source/source_io/module_hs/write_hs.h index 25c1cecc0cd..dada00d9ae1 100644 --- a/source/source_io/module_hs/write_hs.h +++ b/source/source_io/module_hs/write_hs.h @@ -14,22 +14,22 @@ // mohan add this file 2010-09-10 namespace ModuleIO { - template - void write_hsk( - const std::string &global_out_dir, - const int nspin, - const int nks, - const int nkstot, - const std::vector &ik2iktot, - const std::vector &isk, - hamilt::Hamilt* p_hamilt, - const Parallel_Orbitals &pv, - const bool gamma_only, - const bool out_app_flag, - const int istep, - const int out_type, - const int precision, - std::ofstream &ofs_running); + template + void write_hsk( + const std::string &global_out_dir, + const int nspin, + const int nks, + const int nkstot, + const std::vector &ik2iktot, + const std::vector &isk, + hamilt::Hamilt* p_hamilt, + const Parallel_Orbitals &pv, + const bool gamma_only, + const bool out_app_flag, + const int istep, + const int out_type, + const int precision, + std::ofstream &ofs_running); /// @brief save a square matrix, such as H(k) and S(k) /// @param[in] istep : the step of the calculation diff --git a/source/source_io/module_hs/write_hs_sparse.cpp b/source/source_io/module_hs/write_hs_sparse.cpp index 00458fc9b46..8fc36c12143 100644 --- a/source/source_io/module_hs/write_hs_sparse.cpp +++ b/source/source_io/module_hs/write_hs_sparse.cpp @@ -215,24 +215,24 @@ void ModuleIO::save_dH_sparse(const int& istep, std::stringstream sshy[2]; std::stringstream sshz[2]; - if (PARAM.inp.calculation == "md" && !PARAM.inp.out_app_flag) - { - sshx[0] << PARAM.globalv.global_matrix_dir - << "d"<(&output_R_number), sizeof(int)); } - } - else - { - for (int ispin = 0; ispin < spin_loop; ++ispin) - { - if (PARAM.inp.calculation == "md" && PARAM.inp.out_app_flag && step) - { - g1x[ispin].open(sshx[ispin].str().c_str(), std::ios::app); + } + else + { + for (int ispin = 0; ispin < spin_loop; ++ispin) + { + if (PARAM.inp.calculation == "md" && PARAM.inp.out_app_flag && step) + { + g1x[ispin].open(sshx[ispin].str().c_str(), std::ios::app); g1y[ispin].open(sshy[ispin].str().c_str(), std::ios::app); g1z[ispin].open(sshz[ispin].str().c_str(), std::ios::app); - } - else - { - GlobalV::ofs_running << " dH/dRx data are in file: " << sshx[ispin].str() << std::endl; - GlobalV::ofs_running << " dH/dRy data are in file: " << sshy[ispin].str() << std::endl; - GlobalV::ofs_running << " dH/dRz data are in file: " << sshz[ispin].str() << std::endl; + } + else + { + GlobalV::ofs_running << " dH/dRx data are in file: " << sshx[ispin].str() << std::endl; + GlobalV::ofs_running << " dH/dRy data are in file: " << sshy[ispin].str() << std::endl; + GlobalV::ofs_running << " dH/dRz data are in file: " << sshz[ispin].str() << std::endl; g1x[ispin].open(sshx[ispin].str().c_str()); g1y[ispin].open(sshy[ispin].str().c_str()); g1z[ispin].open(sshz[ispin].str().c_str()); diff --git a/source/source_io/module_hs/write_vxc.hpp b/source/source_io/module_hs/write_vxc.hpp index 521db6f11ac..ab62c69b3a1 100644 --- a/source/source_io/module_hs/write_vxc.hpp +++ b/source/source_io/module_hs/write_vxc.hpp @@ -246,16 +246,16 @@ void write_Vxc(const int nspin, // write - // mohan add 2025-06-02 - const int istep = -1; - const int out_label = 1; // 1 means .txt while 2 means .dat - const bool out_app_flag = 0; + // mohan add 2025-06-02 + const int istep = -1; + const int out_label = 1; // 1 means .txt while 2 means .dat + const bool out_app_flag = 0; const bool gamma_only = PARAM.globalv.gamma_only_local; - std::string vxc_file = ModuleIO::filename_output( - PARAM.globalv.global_out_dir, - "vxc","nao",ik,kv.ik2iktot,nspin,kv.get_nkstot(), - out_label,out_app_flag,gamma_only,istep); + std::string vxc_file = ModuleIO::filename_output( + PARAM.globalv.global_out_dir, + "vxc","nao",ik,kv.ik2iktot,nspin,kv.get_nkstot(), + out_label,out_app_flag,gamma_only,istep); ModuleIO::save_mat(istep, vxc_tot_k_mo.data(), diff --git a/source/source_io/module_hs/write_vxc_lip.hpp b/source/source_io/module_hs/write_vxc_lip.hpp index 546320f91ea..22943d01ebc 100644 --- a/source/source_io/module_hs/write_vxc_lip.hpp +++ b/source/source_io/module_hs/write_vxc_lip.hpp @@ -67,10 +67,10 @@ namespace ModuleIO assert(nbands >= 0); #endif std::vector e(nbands, 0.0); - for (int i = 0; i < nbands; ++i) - { - e[i] = get_real(mat_mo[i * nbands + i]); - } + for (int i = 0; i < nbands; ++i) + { + e[i] = get_real(mat_mo[i * nbands + i]); + } return e; } @@ -79,11 +79,11 @@ namespace ModuleIO const std::vector>& mat_mo, const ModuleBase::matrix& wg) { FPTYPE e = 0.0; - for (int i = 0; i < nbands; ++i) - { - e += get_real(mat_mo[i * nbands + i]) * (FPTYPE)wg(ik, i); - } - return e; + for (int i = 0; i < nbands; ++i) + { + e += get_real(mat_mo[i * nbands + i]) * (FPTYPE)wg(ik, i); + } + return e; } template @@ -91,11 +91,11 @@ namespace ModuleIO const ModuleBase::matrix& wg) { FPTYPE e = 0.0; - for (int i = 0; i < orbital_energy.size(); ++i) - { - e += orbital_energy[i] * (FPTYPE)wg(ik, i); - } - return e; + for (int i = 0; i < orbital_energy.size(); ++i) + { + e += orbital_energy[i] * (FPTYPE)wg(ik, i); + } + return e; } /// @brief write the Vxc matrix in KS orbital representation, usefull for GW calculation @@ -189,14 +189,14 @@ namespace ModuleIO #if((defined __LCAO)&&(defined __EXX) && !(defined __CUDA)&& !(defined __ROCM)) if (cal_exx) { - for (int n = 0; n < naos; ++n) - { - for (int m = 0; m < naos; ++m) - { - vexx_k_ao[n * naos + m] += (T)hybrid_alpha - * exx_lip.get_exx_matrix()[ik][m][n]; - } - } + for (int n = 0; n < naos; ++n) + { + for (int m = 0; m < naos; ++m) + { + vexx_k_ao[n * naos + m] += (T)hybrid_alpha + * exx_lip.get_exx_matrix()[ik][m][n]; + } + } std::vector vexx_k_mo = cVc(vexx_k_ao.data(), &(exx_lip.get_hvec()(ik, 0, 0)), naos, nbands); Parallel_Reduce::reduce_pool(vexx_k_mo.data(), nbands * nbands); e_orb_exx.emplace_back(orbital_energy(ik, nbands, vexx_k_mo)); @@ -217,9 +217,9 @@ namespace ModuleIO out_label,out_app_flag,gamma_only,istep); ModuleIO::save_mat(istep, vxc_tot_k_mo.data(), nbands, - false, PARAM.inp.out_ndigits, true, - out_app_flag, vxc_file, - p2d_serial, drank, false); + false, PARAM.inp.out_ndigits, true, + out_app_flag, vxc_file, + p2d_serial, drank, false); e_orb_tot.emplace_back(orbital_energy(ik, nbands, vxc_tot_k_mo)); } diff --git a/source/source_io/module_ml/io_npz.cpp b/source/source_io/module_ml/io_npz.cpp index 87901676f3a..832b8fb2eb2 100644 --- a/source/source_io/module_ml/io_npz.cpp +++ b/source/source_io/module_ml/io_npz.cpp @@ -72,9 +72,9 @@ void read_mat_npz(const Parallel_Orbitals* paraV, temp = element.erase(temp); } else - { - temp++; - } + { + temp++; + } } int z = 0; for(int j=0; j!=ModuleBase::element_name.size(); j++) @@ -367,9 +367,9 @@ void output_mat_npz_impl(const UnitCell& ucell, std::string& zipname, const hami temp = element.erase(temp); } else - { - temp++; - } + { + temp++; + } } int z = 0; for(int j=0; j!=ModuleBase::element_name.size(); j++) diff --git a/source/source_io/module_mulliken/output_dmk.h b/source/source_io/module_mulliken/output_dmk.h index 6a3e7035e94..266c0511b08 100644 --- a/source/source_io/module_mulliken/output_dmk.h +++ b/source/source_io/module_mulliken/output_dmk.h @@ -11,9 +11,9 @@ class Output_DMK { public: Output_DMK(module_dm::DensityMatrix* p_DM, - Parallel_Orbitals* ParaV, - int nspin, - int nks); + Parallel_Orbitals* ParaV, + int nspin, + int nks); TK* get_dmk(int ik); diff --git a/source/source_io/module_mulliken/output_mulliken.cpp b/source/source_io/module_mulliken/output_mulliken.cpp index b1ebe272d01..d477c0fa1e5 100644 --- a/source/source_io/module_mulliken/output_mulliken.cpp +++ b/source/source_io/module_mulliken/output_mulliken.cpp @@ -20,7 +20,7 @@ Output_Mulliken::Output_Mulliken(Output_Sk* output_sk, const std::vector& isk, int nspin) : output_sk_(output_sk), output_dmk_(output_dmk), - ParaV_(ParaV), cell_index_(cell_index), isk_(isk), nspin_(nspin) + ParaV_(ParaV), cell_index_(cell_index), isk_(isk), nspin_(nspin) { this->set_nspin(nspin); this->set_ParaV(ParaV); @@ -87,9 +87,9 @@ void Output_Mulliken::write_mulliken_nspin1(int istep, { /// header of the table std::string atom_label = this->cell_index_->get_atom_label(iat); - os << " ------------------" << std::endl; - os << " Atom " << iat+1 << " is " << atom_label << std::endl; - os << " ------------------" << std::endl; + os << " ------------------" << std::endl; + os << " Atom " << iat+1 << " is " << atom_label << std::endl; + os << " ------------------" << std::endl; os << FmtCore::format("%14s", std::string("zeta")) << FmtCore::format("%10s", std::string("spin1")) << std::endl; @@ -102,7 +102,7 @@ void Output_Mulliken::write_mulliken_nspin1(int istep, for (int M = 0; M < (2 * L + 1); M++) { os << fmt_of_label.format(ModuleBase::Name_Angular[L][M]) - << fmt_of_Z.format(Z+1) + << fmt_of_Z.format(Z+1) << fmt_of_chg.format(orb_chg[std::vector{iat, 0, L, Z, M}]) << std::endl; } // sum over m @@ -160,14 +160,14 @@ void Output_Mulliken::write_mulliken_nspin2(int istep, { /// header of the table std::string atom_label = this->cell_index_->get_atom_label(iat); - os << " ------------------" << std::endl; - os << " Atom " << iat+1 << " is " << atom_label << std::endl; - os << " ------------------" << std::endl; + os << " ------------------" << std::endl; + os << " Atom " << iat+1 << " is " << atom_label << std::endl; + os << " ------------------" << std::endl; os << FmtCore::format("%14s", std::string("zeta")) << FmtCore::format("%10s", std::string("spin1")) - << FmtCore::format("%10s", std::string("spin2")) + << FmtCore::format("%10s", std::string("spin2")) << FmtCore::format("%10s", std::string("sum")) - << FmtCore::format("%10s", std::string("diff")) << std::endl; + << FmtCore::format("%10s", std::string("diff")) << std::endl; /// loop of L for (int L = 0; L <= this->cell_index_->get_maxL(iat); L++) @@ -178,7 +178,7 @@ void Output_Mulliken::write_mulliken_nspin2(int istep, for (int M = 0; M < (2 * L + 1); M++) { os << fmt_of_label.format(ModuleBase::Name_Angular[L][M]) - << fmt_of_Z.format(Z+1) // be careful, Z+1, modified by mohan 2026-02-21 + << fmt_of_Z.format(Z+1) // be careful, Z+1, modified by mohan 2026-02-21 << fmt_of_chg.format(orb_chg[std::vector{iat, 0, L, Z, M}]) << fmt_of_chg.format(orb_chg[std::vector{iat, 1, L, Z, M}]) << fmt_of_chg.format(orb_chg[std::vector{iat, 0, L, Z, M}] @@ -201,21 +201,21 @@ void Output_Mulliken::write_mulliken_nspin2(int istep, { os << fmt_of_sum.format(std::string(" sum m")) << fmt_of_chg.format(sum_over_m[0]) - << fmt_of_chg.format(sum_over_m[1]) + << fmt_of_chg.format(sum_over_m[1]) << fmt_of_chg.format(sum_over_m[0] + sum_over_m[1]) << fmt_of_chg.format(sum_over_m[0] - sum_over_m[1]) << std::endl; } } os << fmt_of_sum.format(std::string(" sum mz")) << fmt_of_chg.format(sum_over_m_and_z[0]) - << fmt_of_chg.format(sum_over_m_and_z[1]) + << fmt_of_chg.format(sum_over_m_and_z[1]) << fmt_of_chg.format(sum_over_m_and_z[0] + sum_over_m_and_z[1]) << fmt_of_chg.format(sum_over_m_and_z[0] - sum_over_m_and_z[1]) << std::endl; os << std::endl; } os << fmt_of_sum.format(std::string(" sum lmz")) << fmt_of_chg.format(atom_chg[iat][0]) - << fmt_of_chg.format(atom_chg[iat][1]) + << fmt_of_chg.format(atom_chg[iat][1]) << fmt_of_chg.format(atom_chg[iat][0] + atom_chg[iat][1]) << fmt_of_chg.format(atom_chg[iat][0] - atom_chg[iat][1]) << std::endl; os << std::endl; @@ -251,9 +251,9 @@ void Output_Mulliken::write_mulliken_nspin4(int istep, { /// header of the table std::string atom_label = this->cell_index_->get_atom_label(iat); - os << " ------------------" << std::endl; - os << " Atom " << iat+1 << " is " << atom_label << std::endl; - os << " ------------------" << std::endl; + os << " ------------------" << std::endl; + os << " Atom " << iat+1 << " is " << atom_label << std::endl; + os << " ------------------" << std::endl; os << FmtCore::format("%14s", std::string("zeta")) << FmtCore::format("%10s", std::string("spin1")) << FmtCore::format("%10s", std::string("spin2")) @@ -269,7 +269,7 @@ void Output_Mulliken::write_mulliken_nspin4(int istep, for (int M = 0; M < (2 * L + 1); M++) { os << fmt_of_label.format(ModuleBase::Name_Angular[L][M]) - << fmt_of_Z.format(Z+1) + << fmt_of_Z.format(Z+1) << fmt_of_chg.format(orb_chg[std::vector{iat, 0, L, Z, M}]) << fmt_of_chg.format(orb_chg[std::vector{iat, 1, L, Z, M}]) << fmt_of_chg.format(orb_chg[std::vector{iat, 2, L, Z, M}]) @@ -289,23 +289,23 @@ void Output_Mulliken::write_mulliken_nspin4(int istep, { os << fmt_of_sum.format(std::string(" sum m")) << fmt_of_chg.format(sum_over_m[0]) - << fmt_of_chg.format(sum_over_m[1]) + << fmt_of_chg.format(sum_over_m[1]) << fmt_of_chg.format(sum_over_m[2]) - << fmt_of_chg.format(sum_over_m[3]) << std::endl; + << fmt_of_chg.format(sum_over_m[3]) << std::endl; } } os << fmt_of_sum.format(std::string(" sum mz")) << fmt_of_chg.format(sum_over_m_and_z[0]) - << fmt_of_chg.format(sum_over_m_and_z[1]) + << fmt_of_chg.format(sum_over_m_and_z[1]) << fmt_of_chg.format(sum_over_m_and_z[2]) - << fmt_of_chg.format(sum_over_m_and_z[3]) << std::endl; + << fmt_of_chg.format(sum_over_m_and_z[3]) << std::endl; os << std::endl; } os << fmt_of_sum.format(std::string(" sum lmz")) << fmt_of_chg.format(atom_chg[iat][0]) - << fmt_of_chg.format(atom_chg[iat][1]) + << fmt_of_chg.format(atom_chg[iat][1]) << fmt_of_chg.format(atom_chg[iat][2]) - << fmt_of_chg.format(atom_chg[iat][3]) << std::endl; + << fmt_of_chg.format(atom_chg[iat][3]) << std::endl; os << std::endl; os << std::left << " total charge on atom " << iat+1 << " " << fmt_of_chg.format(atom_chg[iat][0]) << std::endl; diff --git a/source/source_io/module_output/cal_test.cpp b/source/source_io/module_output/cal_test.cpp index 44cbe5e40d2..2a7339bf1b9 100644 --- a/source/source_io/module_output/cal_test.cpp +++ b/source/source_io/module_output/cal_test.cpp @@ -46,80 +46,80 @@ double Cal_Test::meigts123=0.0; double Cal_Test::mtot=0.0; void Cal_Test::test_memory(const int nat, - const int ntype, - const ModuleBase::Matrix3& GGT, - const ModulePW::PW_Basis* rhopw, - const ModulePW::PW_Basis_K* wfcpw, - const std::string chr_mixing_mode, - const int chr_mixing_ndim) + const int ntype, + const ModuleBase::Matrix3& GGT, + const ModulePW::PW_Basis* rhopw, + const ModulePW::PW_Basis_K* wfcpw, + const std::string chr_mixing_mode, + const int chr_mixing_ndim) { - ModuleBase::TITLE("Cal_Test","test_memory"); - - const int ngmw = Cal_Test::cal_np(GGT,wfcpw->ggecut, rhopw->nx, rhopw->ny, rhopw->nz); - const int ngmc = Cal_Test::cal_np(GGT,rhopw->ggecut, rhopw->nx, rhopw->ny, rhopw->nz); - - std::cout << " number of atoms = " << nat << std::endl; - std::cout << " plane wave number for wave functions = " << ngmw << std::endl; - std::cout << " plane wave number for chage density = " << ngmc << std::endl; - - mporter = ModuleBase::Memory::calculate_mem ( rhopw->nxyz, "double"); - - mrho = mporter; - mrho_save = mrho; - mrho_core = mrho; - - // (2) memory for charge mixing - std::cout << " Mixing mode = " << chr_mixing_mode << std::endl; - if(chr_mixing_mode == "pulay") - { - std::cout << " Mixing dimension = " << chr_mixing_ndim << std::endl; - mRrho = chr_mixing_ndim * mrho; - mdRrho = (chr_mixing_ndim-1) * mrho; - mdrho = (chr_mixing_ndim-1) * mrho; - mrho_save2 = mrho; + ModuleBase::TITLE("Cal_Test","test_memory"); + + const int ngmw = Cal_Test::cal_np(GGT,wfcpw->ggecut, rhopw->nx, rhopw->ny, rhopw->nz); + const int ngmc = Cal_Test::cal_np(GGT,rhopw->ggecut, rhopw->nx, rhopw->ny, rhopw->nz); + + std::cout << " number of atoms = " << nat << std::endl; + std::cout << " plane wave number for wave functions = " << ngmw << std::endl; + std::cout << " plane wave number for chage density = " << ngmc << std::endl; + + mporter = ModuleBase::Memory::calculate_mem ( rhopw->nxyz, "double"); + + mrho = mporter; + mrho_save = mrho; + mrho_core = mrho; + + // (2) memory for charge mixing + std::cout << " Mixing mode = " << chr_mixing_mode << std::endl; + if(chr_mixing_mode == "pulay") + { + std::cout << " Mixing dimension = " << chr_mixing_ndim << std::endl; + mRrho = chr_mixing_ndim * mrho; + mdRrho = (chr_mixing_ndim-1) * mrho; + mdrho = (chr_mixing_ndim-1) * mrho; + mrho_save2 = mrho; // std::cout << " Memory for pulay mixing: " << mrho << " MB" << std::endl; - } - - mvltot = mrho; - mvr = mrho; - mvrs = mrho; - mvrs1 = mrho; - mvnew = mrho; - - mrhog = ModuleBase::Memory::calculate_mem( ngmc, "cdouble"); - mrhog_save = ModuleBase::Memory::calculate_mem( ngmc, "cdouble"); - mrhog_core = ModuleBase::Memory::calculate_mem( ngmc, "cdouble"); - - mhs = ModuleBase::Memory::calculate_mem( PARAM.globalv.nlocal*PARAM.globalv.nlocal, "double" ); - mwf = ModuleBase::Memory::calculate_mem( PARAM.globalv.nlocal*PARAM.inp.nbands, "double" ); - mnonzero = ModuleBase::Memory::calculate_mem( PARAM.globalv.nlocal*(PARAM.globalv.nlocal+1)/2, "bool"); + } + + mvltot = mrho; + mvr = mrho; + mvrs = mrho; + mvrs1 = mrho; + mvnew = mrho; + + mrhog = ModuleBase::Memory::calculate_mem( ngmc, "cdouble"); + mrhog_save = ModuleBase::Memory::calculate_mem( ngmc, "cdouble"); + mrhog_core = ModuleBase::Memory::calculate_mem( ngmc, "cdouble"); + + mhs = ModuleBase::Memory::calculate_mem( PARAM.globalv.nlocal*PARAM.globalv.nlocal, "double" ); + mwf = ModuleBase::Memory::calculate_mem( PARAM.globalv.nlocal*PARAM.inp.nbands, "double" ); + mnonzero = ModuleBase::Memory::calculate_mem( PARAM.globalv.nlocal*(PARAM.globalv.nlocal+1)/2, "bool"); // mohan comment out 2021-02-11 // mspar_hsrho = Memory::calculate_mem( Hnnz*3, "double"); - - mgvec = ModuleBase::Memory::calculate_mem( ngmc * 3 * 2, "double" ); - mig2fftw = ModuleBase::Memory::calculate_mem( ngmw , "int"); - mig2fftc = ModuleBase::Memory::calculate_mem( ngmc , "int"); - mgg = ModuleBase::Memory::calculate_mem( ngmc, "double"); - mig123 = ModuleBase::Memory::calculate_mem( ngmc*3, "int"); - mstrucFac = ModuleBase::Memory::calculate_mem( ntype*ngmc, "cdouble"); - meigts123 = ModuleBase::Memory::calculate_mem( nat * (2*rhopw->nx+1+2*rhopw->ny+1+2*rhopw->nz+1), "cdouble"); - - //(3) Memory for H,S matrix. - std::cout << " NLOCAL = " << PARAM.globalv.nlocal << std::endl; - std::cout << " NBANDS = " << PARAM.inp.nbands << std::endl; - - std::cout << " Memory for H,S matrix ( " - << PARAM.globalv.nlocal << ", " - << PARAM.globalv.nlocal << ") = " - << mhs << " MB" << std::endl; - - //(4) Memory for wave functions. - std::cout << " Memory for wave functions ( " - << PARAM.globalv.nlocal << ", " - << PARAM.inp.nbands << ") = " - << mwf << " MB" << std::endl; - - print_mem(1); + + mgvec = ModuleBase::Memory::calculate_mem( ngmc * 3 * 2, "double" ); + mig2fftw = ModuleBase::Memory::calculate_mem( ngmw , "int"); + mig2fftc = ModuleBase::Memory::calculate_mem( ngmc , "int"); + mgg = ModuleBase::Memory::calculate_mem( ngmc, "double"); + mig123 = ModuleBase::Memory::calculate_mem( ngmc*3, "int"); + mstrucFac = ModuleBase::Memory::calculate_mem( ntype*ngmc, "cdouble"); + meigts123 = ModuleBase::Memory::calculate_mem( nat * (2*rhopw->nx+1+2*rhopw->ny+1+2*rhopw->nz+1), "cdouble"); + + //(3) Memory for H,S matrix. + std::cout << " NLOCAL = " << PARAM.globalv.nlocal << std::endl; + std::cout << " NBANDS = " << PARAM.inp.nbands << std::endl; + + std::cout << " Memory for H,S matrix ( " + << PARAM.globalv.nlocal << ", " + << PARAM.globalv.nlocal << ") = " + << mhs << " MB" << std::endl; + + //(4) Memory for wave functions. + std::cout << " Memory for wave functions ( " + << PARAM.globalv.nlocal << ", " + << PARAM.inp.nbands << ") = " + << mwf << " MB" << std::endl; + + print_mem(1); // print_mem(8); // print_mem(16); @@ -129,15 +129,15 @@ void Cal_Test::test_memory(const int nat, // print_mem(64); // } - return; + return; } //! compute the number of plane waves int Cal_Test::cal_np(const ModuleBase::Matrix3& GGT, - const double &ggcut, - const int &n1, - const int &n2, - const int &n3) + const double &ggcut, + const int &n1, + const int &n2, + const int &n3) { /* @@ -151,78 +151,78 @@ int Cal_Test::cal_np(const ModuleBase::Matrix3& GGT, assert(n2>=0); assert(n3>=0); - int ibox[3]={0}; - - // set the center at origin point. - ibox[0] = int(n1 / 2.0) + 1; - ibox[1] = int(n2 / 2.0) + 1; - ibox[2] = int(n3 / 2.0) + 1; - // get the number of plane wave within 'gcut' - int ng = 0; - for (int i = -ibox[0]; i <= ibox[0]; i++) - { - for (int j = -ibox[1]; j <= ibox[1]; j++) - { - for (int k = -ibox[2]; k <= ibox[2]; k++) - { - ModuleBase::Vector3 f(i,j,k); - // g2= |f|^2 in the unit of (2Pi/lat0)^2 - double g2 = f * (GGT * f); - - // gcut is from input. - if (g2 <= ggcut) - { - ng++; - } - } - } - } - return ng; + int ibox[3]={0}; + + // set the center at origin point. + ibox[0] = int(n1 / 2.0) + 1; + ibox[1] = int(n2 / 2.0) + 1; + ibox[2] = int(n3 / 2.0) + 1; + // get the number of plane wave within 'gcut' + int ng = 0; + for (int i = -ibox[0]; i <= ibox[0]; i++) + { + for (int j = -ibox[1]; j <= ibox[1]; j++) + { + for (int k = -ibox[2]; k <= ibox[2]; k++) + { + ModuleBase::Vector3 f(i,j,k); + // g2= |f|^2 in the unit of (2Pi/lat0)^2 + double g2 = f * (GGT * f); + + // gcut is from input. + if (g2 <= ggcut) + { + ng++; + } + } + } + } + return ng; } void Cal_Test::print_mem(const int &nproc) { - std::cout << " ========================: " << std::endl; - mtot = 0.0; - - mtot += mporter + mrho + mrho_save + mrho_core + mRrho + - mdRrho + mdrho + mrho_save2 + mvltot + mvr + - mvrs + mvrs1 + mvnew + mrhog + mrhog_save + mrhog_core + - mgvec + mgg + mig2fftw + mig2fftc + mig123 + - mstrucFac + meigts123; - mtot += mwf + mhs; - - std::cout << " If you use " << nproc << " processors: " << std::endl; - std::cout << " MEMORY FOR porter : " << std::setw(15) << mporter/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR rho : " << std::setw(15) << mrho/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR rho_save : " << std::setw(15) << mrho_save/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR rho_core : " << std::setw(15) << mrho_core/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR Rrho : " << std::setw(15) << mRrho/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR dRrho : " << std::setw(15) << mdRrho/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR drho : " << std::setw(15) << mdrho/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR rho_save2 : " << std::setw(15) << mrho_save2/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR vltot : " << std::setw(15) << mvltot/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR vr : " << std::setw(15) << mvr/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR vrs : " << std::setw(15) << mvrs/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR vrs1 : " << std::setw(15) << mvrs1/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR vrnew : " << std::setw(15) << mvnew/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR rhog : " << std::setw(15) << mrhog/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR rhog_save : " << std::setw(15) << mrhog_save/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR rhog_core : " << std::setw(15) << mrhog_core/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR H, S matrix : " << std::setw(15) << mhs/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR wave function: " << std::setw(15) << mwf/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR spar H,S,rho : " << std::setw(15) << mspar_hsrho << " MB" << std::endl; - std::cout << " MEMORY FOR nonzero : " << std::setw(15) << mnonzero << " MB" << std::endl; - std::cout << " MEMORY FOR g vectors : " << std::setw(15) << mgvec/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR gg : " << std::setw(15) << mgg/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR fftw index : " << std::setw(15) << mig2fftw/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR fftc index : " << std::setw(15) << mig2fftc/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR ig123 : " << std::setw(15) << mig123/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR strucFac : " << std::setw(15) << mstrucFac/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR eigts1,2,3 : " << std::setw(15) << meigts123/nproc << " MB" << std::endl; - std::cout << " TOTAL MEMORY : " << std::setw(15) << mtot/nproc << " MB" << std::endl; - - std::cout << " MEMORY FOR nonzero : " << std::setw(15) + std::cout << " ========================: " << std::endl; + mtot = 0.0; + + mtot += mporter + mrho + mrho_save + mrho_core + mRrho + + mdRrho + mdrho + mrho_save2 + mvltot + mvr + + mvrs + mvrs1 + mvnew + mrhog + mrhog_save + mrhog_core + + mgvec + mgg + mig2fftw + mig2fftc + mig123 + + mstrucFac + meigts123; + mtot += mwf + mhs; + + std::cout << " If you use " << nproc << " processors: " << std::endl; + std::cout << " MEMORY FOR porter : " << std::setw(15) << mporter/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR rho : " << std::setw(15) << mrho/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR rho_save : " << std::setw(15) << mrho_save/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR rho_core : " << std::setw(15) << mrho_core/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR Rrho : " << std::setw(15) << mRrho/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR dRrho : " << std::setw(15) << mdRrho/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR drho : " << std::setw(15) << mdrho/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR rho_save2 : " << std::setw(15) << mrho_save2/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR vltot : " << std::setw(15) << mvltot/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR vr : " << std::setw(15) << mvr/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR vrs : " << std::setw(15) << mvrs/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR vrs1 : " << std::setw(15) << mvrs1/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR vrnew : " << std::setw(15) << mvnew/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR rhog : " << std::setw(15) << mrhog/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR rhog_save : " << std::setw(15) << mrhog_save/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR rhog_core : " << std::setw(15) << mrhog_core/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR H, S matrix : " << std::setw(15) << mhs/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR wave function: " << std::setw(15) << mwf/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR spar H,S,rho : " << std::setw(15) << mspar_hsrho << " MB" << std::endl; + std::cout << " MEMORY FOR nonzero : " << std::setw(15) << mnonzero << " MB" << std::endl; + std::cout << " MEMORY FOR g vectors : " << std::setw(15) << mgvec/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR gg : " << std::setw(15) << mgg/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR fftw index : " << std::setw(15) << mig2fftw/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR fftc index : " << std::setw(15) << mig2fftc/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR ig123 : " << std::setw(15) << mig123/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR strucFac : " << std::setw(15) << mstrucFac/nproc << " MB" << std::endl; + std::cout << " MEMORY FOR eigts1,2,3 : " << std::setw(15) << meigts123/nproc << " MB" << std::endl; + std::cout << " TOTAL MEMORY : " << std::setw(15) << mtot/nproc << " MB" << std::endl; + + std::cout << " MEMORY FOR nonzero : " << std::setw(15) << (double)PARAM.globalv.nlocal*(PARAM.globalv.nlocal+1)/1028/1028/2.0/nproc << " MB" << std::endl; } diff --git a/source/source_io/module_output/cal_test.h b/source/source_io/module_output/cal_test.h index 665d3f95c11..34fa69015aa 100644 --- a/source/source_io/module_output/cal_test.h +++ b/source/source_io/module_output/cal_test.h @@ -5,62 +5,62 @@ namespace Cal_Test { - void test_memory(const int nat, - const int ntype, - const ModuleBase::Matrix3& GGT, - const ModulePW::PW_Basis* rhopw, - const ModulePW::PW_Basis_K* wfcpw, - const std::string chr_mixing_mode, - const int chr_mixing_ndim); + void test_memory(const int nat, + const int ntype, + const ModuleBase::Matrix3& GGT, + const ModulePW::PW_Basis* rhopw, + const ModulePW::PW_Basis_K* wfcpw, + const std::string chr_mixing_mode, + const int chr_mixing_ndim); - int cal_np(const ModuleBase::Matrix3& GGT, - const double &ggcut, - const int &n1, - const int &n2, - const int &n3); + int cal_np(const ModuleBase::Matrix3& GGT, + const double &ggcut, + const int &n1, + const int &n2, + const int &n3); - void print_mem(const int &nproc); + void print_mem(const int &nproc); - extern double mporter; + extern double mporter; - // about charge density. - extern double mrho; - extern double mrho_save; - extern double mrho_core; + // about charge density. + extern double mrho; + extern double mrho_save; + extern double mrho_core; - // about pulay mixing. - extern double mRrho; - extern double mdRrho; - extern double mdrho; - extern double mrho_save2; + // about pulay mixing. + extern double mRrho; + extern double mdRrho; + extern double mdrho; + extern double mrho_save2; - // about potential on FFT grid. - extern double mvltot; - extern double mvr; - extern double mvrs; - extern double mvrs1; - extern double mvnew; + // about potential on FFT grid. + extern double mvltot; + extern double mvr; + extern double mvrs; + extern double mvrs1; + extern double mvnew; - // about charge in g space. - extern double mrhog; - extern double mrhog_save; - extern double mrhog_core; - - // about others. - extern double mhs; - extern double mwf; - extern double mnonzero; - extern double mspar_hsrho; - - extern double mgvec; - extern double mig2fftw; - extern double mig2fftc; - extern double mgg; - extern double mig123; - extern double mstrucFac; - extern double meigts123; + // about charge in g space. + extern double mrhog; + extern double mrhog_save; + extern double mrhog_core; + + // about others. + extern double mhs; + extern double mwf; + extern double mnonzero; + extern double mspar_hsrho; + + extern double mgvec; + extern double mig2fftw; + extern double mig2fftc; + extern double mgg; + extern double mig123; + extern double mstrucFac; + extern double meigts123; - extern double mtot; + extern double mtot; } #endif diff --git a/source/source_io/module_output/output_log.cpp b/source/source_io/module_output/output_log.cpp index 4c11edfe286..a642f8b7322 100644 --- a/source/source_io/module_output/output_log.cpp +++ b/source/source_io/module_output/output_log.cpp @@ -262,17 +262,17 @@ void print_force(std::ofstream& ofs_running, /*nrows=*/atom_label.size(), /*formats=*/{"%8s", "%20.10f", "%20.10f", "%20.10f"}, /*indent*/1, - {FmtTable::Align::RIGHT,FmtTable::Align::RIGHT}); + {FmtTable::Align::RIGHT,FmtTable::Align::RIGHT}); - fmt << atom_label << force_x << force_y << force_z; - table = fmt.str(); + fmt << atom_label << force_x << force_y << force_z; + table = fmt.str(); ofs_running << table; - if (PARAM.inp.test_force) - { - std::cout << table; - } + if (PARAM.inp.test_force) + { + std::cout << table; + } } void print_force(std::ofstream& ofs, const MDCell& cell, const std::string& name) diff --git a/source/source_io/module_output/output_log.h b/source/source_io/module_output/output_log.h index 0a12869a449..8b6c84cbe96 100644 --- a/source/source_io/module_output/output_log.h +++ b/source/source_io/module_output/output_log.h @@ -73,10 +73,10 @@ void print_force(std::ofstream& ofs, const MDCell& cell, const std::string& name /// @param f stress components /// @param ry true if the unit of force is a.u. void print_stress(const std::string& name, - const ModuleBase::matrix& scs, - const bool screen, - const bool ry, - std::ofstream &ofs); + const ModuleBase::matrix& scs, + const bool screen, + const bool ry, + std::ofstream &ofs); /// @brief write head for scf iteration /// @param ofs_running output stream diff --git a/source/source_io/module_output/print_info.h b/source/source_io/module_output/print_info.h index f7917da9fb9..3f4da0299a3 100644 --- a/source/source_io/module_output/print_info.h +++ b/source/source_io/module_output/print_info.h @@ -10,8 +10,8 @@ namespace ModuleIO { // print out to screen about the readin parameters void print_parameters( - const UnitCell& ucell, - K_Vectors& kv, + const UnitCell& ucell, + K_Vectors& kv, const Input_para& inp); void print_time(time_t& time_start, time_t& time_finish); diff --git a/source/source_io/module_output/read_cube.cpp b/source/source_io/module_output/read_cube.cpp index 3e3f17780e3..89301404607 100644 --- a/source/source_io/module_output/read_cube.cpp +++ b/source/source_io/module_output/read_cube.cpp @@ -173,13 +173,13 @@ bool ModuleIO::read_cube(const std::string& file, if (!ifs) { - return false; + return false; } comment.resize(2); for (auto& c : comment) { - std::getline(ifs, c); + std::getline(ifs, c); } ifs >> natom; diff --git a/source/source_io/module_output/write_orb_info.h b/source/source_io/module_output/write_orb_info.h index c759a3b2d88..3a035f5679a 100644 --- a/source/source_io/module_output/write_orb_info.h +++ b/source/source_io/module_output/write_orb_info.h @@ -4,7 +4,7 @@ namespace ModuleIO { - void write_orb_info(const UnitCell* ucell); + void write_orb_info(const UnitCell* ucell); } #endif diff --git a/source/source_io/module_parameter/parameter.h b/source/source_io/module_parameter/parameter.h index b6f54f7a28a..3ebfbd24f4d 100644 --- a/source/source_io/module_parameter/parameter.h +++ b/source/source_io/module_parameter/parameter.h @@ -53,9 +53,9 @@ extern Parameter PARAM; // temperarily put here namespace GlobalV { - extern int NPROC; - extern int MY_RANK; - extern std::ofstream ofs_running; - extern std::ofstream ofs_warning; + extern int NPROC; + extern int MY_RANK; + extern std::ofstream ofs_running; + extern std::ofstream ofs_warning; } // namespace GlobalV #endif diff --git a/source/source_io/module_parameter/read_inp_out.cpp b/source/source_io/module_parameter/read_inp_out.cpp index 212780882b8..c82ea2b70e4 100644 --- a/source/source_io/module_parameter/read_inp_out.cpp +++ b/source/source_io/module_parameter/read_inp_out.cpp @@ -99,15 +99,15 @@ In molecular dynamics simulations, the output frequency is controlled by out_fre [NOTE] In the 3.10-LTS version, the file names are SPIN1_CHG.cube and SPIN1_CHG_INI.cube, etc.)"; item.default_value = "0 3"; item.unit = ""; - item.read_value = [](const Input_Item& item, Parameter& para) { - const size_t count = item.get_size(); - if (count < 1) ModuleBase::WARNING_QUIT("ReadInput", "out_chg needs at least 1 value"); - para.input.out_chg[0] = std::stoi(item.str_values[0]); + item.read_value = [](const Input_Item& item, Parameter& para) { + const size_t count = item.get_size(); + if (count < 1) ModuleBase::WARNING_QUIT("ReadInput", "out_chg needs at least 1 value"); + para.input.out_chg[0] = std::stoi(item.str_values[0]); para.input.out_chg[1] = 3; - if (count >= 2) try { para.input.out_chg[1] = std::stoi(item.str_values[1]); } - catch (const std::invalid_argument&) { /* do nothing */ } - catch (const std::out_of_range&) {/* do nothing */} - }; + if (count >= 2) try { para.input.out_chg[1] = std::stoi(item.str_values[1]); } + catch (const std::invalid_argument&) { /* do nothing */ } + catch (const std::out_of_range&) {/* do nothing */} + }; // reset value in some special case item.reset_value = [](const Input_Item& item, Parameter& para) { para.input.out_chg[0] = (para.input.calculation == "get_wf" || para.input.calculation == "get_pchg") @@ -187,15 +187,15 @@ In molecular dynamics calculations, the output frequency is controlled by out_fr item.default_value = "False"; item.unit = ""; item.set_availability("basis_type==lcao"); - item.read_value = [](const Input_Item& item, Parameter& para) { - const size_t count = item.get_size(); - if (count < 1) ModuleBase::WARNING_QUIT("ReadInput", "out_dmk needs at least 1 value"); - para.input.out_dmk[0] = assume_as_boolean(item.str_values[0]); + item.read_value = [](const Input_Item& item, Parameter& para) { + const size_t count = item.get_size(); + if (count < 1) ModuleBase::WARNING_QUIT("ReadInput", "out_dmk needs at least 1 value"); + para.input.out_dmk[0] = assume_as_boolean(item.str_values[0]); para.input.out_dmk[1] = 8; - if (count >= 2) try { para.input.out_dmk[1] = std::stoi(item.str_values[1]); } - catch (const std::invalid_argument&) { /* do nothing */ } - catch (const std::out_of_range&) {/* do nothing */} - }; + if (count >= 2) try { para.input.out_dmk[1] = std::stoi(item.str_values[1]); } + catch (const std::invalid_argument&) { /* do nothing */ } + catch (const std::out_of_range&) {/* do nothing */} + }; item.reset_value = [](const Input_Item& item, Parameter& para) { if (para.input.calculation == "get_wf" || para.input.calculation == "get_pchg") { @@ -207,7 +207,7 @@ In molecular dynamics calculations, the output frequency is controlled by out_fr } { Input_Item item("out_dmr"); - item.annotation = "output density matrix DM(R) with respect to lattice vector R (with precision 8)"; + item.annotation = "output density matrix DM(R) with respect to lattice vector R (with precision 8)"; item.category = "Output information"; item.type = R"(Boolean \[Integer\](optional))"; item.description = R"(Whether to output the density matrix with Bravias lattice vector R index into files in the folder OUT.${suffix}. The files are named as dmr{s}{spin index}{g}{geometry index}{_nao} + {".csr"}. Here, 's' refers to spin, where s1 means spin up channel while s2 means spin down channel, and the sparse matrix format 'csr' is mentioned in out_hsr. Finally, if out_app_flag is set to false, the file name contains the optional 'g' index for each ionic step that may have different geometries, and if out_app_flag is set to true, the density matrix with respect to Bravias lattice vector R accumulates during ionic steps: @@ -219,29 +219,29 @@ In molecular dynamics calculations, the output frequency is controlled by out_fr item.unit = ""; item.set_availability("basis_type==lcao and gamma_only==0"); item.read_value = [](const Input_Item& item, Parameter& para) { - const size_t count = item.get_size(); - if (count < 1) ModuleBase::WARNING_QUIT("ReadInput", "out_dmr needs at least 1 value"); - para.input.out_dmr[0] = assume_as_boolean(item.str_values[0]); - para.input.out_dmr[1] = 8; - if (count >= 2) try { para.input.out_dmr[1] = std::stoi(item.str_values[1]); } - catch (const std::invalid_argument&) { /* do nothing */ } - catch (const std::out_of_range&) {/* do nothing */} - }; + const size_t count = item.get_size(); + if (count < 1) ModuleBase::WARNING_QUIT("ReadInput", "out_dmr needs at least 1 value"); + para.input.out_dmr[0] = assume_as_boolean(item.str_values[0]); + para.input.out_dmr[1] = 8; + if (count >= 2) try { para.input.out_dmr[1] = std::stoi(item.str_values[1]); } + catch (const std::invalid_argument&) { /* do nothing */ } + catch (const std::out_of_range&) {/* do nothing */} + }; item.reset_value = [](const Input_Item& item, Parameter& para) { if (para.input.calculation == "get_wf" || para.input.calculation == "get_pchg") { para.input.out_dmr[0] = 0; } }; - item.check_value = [](const Input_Item& item, const Parameter& para) { - if (para.sys.gamma_only_local == true && para.input.out_dmr[0]) - { - ModuleBase::WARNING_QUIT("ReadInput", "out_dmr is only valid for multi-k calculation"); - } - }; + item.check_value = [](const Input_Item& item, const Parameter& para) { + if (para.sys.gamma_only_local == true && para.input.out_dmr[0]) + { + ModuleBase::WARNING_QUIT("ReadInput", "out_dmr is only valid for multi-k calculation"); + } + }; - sync_intvec(input.out_dmr, 2, 0); - this->add_item(item); + sync_intvec(input.out_dmr, 2, 0); + this->add_item(item); } { Input_Item item("out_wfc_pw"); @@ -698,14 +698,14 @@ For binary output, each file uses the same basename as text output with a .dat s item.default_value = "False [8]"; item.unit = "Ry"; item.set_availability("basis_type==lcao"); - item.read_value = [](const Input_Item& item, Parameter& para) { - const size_t count = item.get_size(); - if (count < 1) ModuleBase::WARNING_QUIT("ReadInput", "out_mat_tk needs at least 1 value"); - para.input.out_mat_tk[0] = assume_as_boolean(item.str_values[0]); + item.read_value = [](const Input_Item& item, Parameter& para) { + const size_t count = item.get_size(); + if (count < 1) ModuleBase::WARNING_QUIT("ReadInput", "out_mat_tk needs at least 1 value"); + para.input.out_mat_tk[0] = assume_as_boolean(item.str_values[0]); para.input.out_mat_tk[1] = 8; - if (count >= 2) try { para.input.out_mat_tk[1] = std::stoi(item.str_values[1]); } - catch (const std::invalid_argument&) { /* do nothing */ } - catch (const std::out_of_range&) {/* do nothing */} + if (count >= 2) try { para.input.out_mat_tk[1] = std::stoi(item.str_values[1]); } + catch (const std::invalid_argument&) { /* do nothing */ } + catch (const std::out_of_range&) {/* do nothing */} }; sync_intvec(input.out_mat_tk, 2, 0); this->add_item(item); @@ -1261,14 +1261,14 @@ For binary output, each file uses the same basename as text output with a .dat s item.default_value = "False 8"; item.unit = ""; item.set_availability("basis_type==lcao"); - item.read_value = [](const Input_Item& item, Parameter& para) { - const size_t count = item.get_size(); - if (count < 1) ModuleBase::WARNING_QUIT("ReadInput", "out_mat_l needs at least 1 value"); - para.input.out_mat_l[0] = assume_as_boolean(item.str_values[0]); + item.read_value = [](const Input_Item& item, Parameter& para) { + const size_t count = item.get_size(); + if (count < 1) ModuleBase::WARNING_QUIT("ReadInput", "out_mat_l needs at least 1 value"); + para.input.out_mat_l[0] = assume_as_boolean(item.str_values[0]); para.input.out_mat_l[1] = 8; - if (count >= 2) try { para.input.out_mat_l[1] = std::stoi(item.str_values[1]); } - catch (const std::invalid_argument&) { /* do nothing */ } - catch (const std::out_of_range&) {/* do nothing */} + if (count >= 2) try { para.input.out_mat_l[1] = std::stoi(item.str_values[1]); } + catch (const std::invalid_argument&) { /* do nothing */ } + catch (const std::out_of_range&) {/* do nothing */} }; sync_intvec(input.out_mat_l, 2, 0); this->add_item(item); diff --git a/source/source_io/module_parameter/read_input.cpp b/source/source_io/module_parameter/read_input.cpp index a3d0359baaa..6257c6dbad3 100644 --- a/source/source_io/module_parameter/read_input.cpp +++ b/source/source_io/module_parameter/read_input.cpp @@ -98,40 +98,40 @@ bool ReadInput::check_mode = false; bool filter_nonascii_and_comment(std::ifstream& ifs, std::stringstream& out_ascii_stream) { - if (!ifs.is_open()) - { - if (!ifs) return false; + if (!ifs.is_open()) + { + if (!ifs) return false; } std::streampos old_pos = ifs.tellg(); ifs.clear(); ifs.seekg(0, std::ios::beg); - char c = '\0'; - while (ifs.get(c)) - { - // If comment start, skip until end of line (but keep the newline) - if (c == '#') - { - char d = '\0'; - bool newline_found = false; - while (ifs.get(d)) - { - if (d == '\n' || d == '\r') - { - // preserve line break in output - out_ascii_stream.put('\n'); - // If CRLF, consume the LF after CR (already wrote a single '\n') - if (d == '\r' && ifs.peek() == '\n') - { - ifs.get(d); // consume '\n' - } - newline_found = true; - break; - } + char c = '\0'; + while (ifs.get(c)) + { + // If comment start, skip until end of line (but keep the newline) + if (c == '#') + { + char d = '\0'; + bool newline_found = false; + while (ifs.get(d)) + { + if (d == '\n' || d == '\r') + { + // preserve line break in output + out_ascii_stream.put('\n'); + // If CRLF, consume the LF after CR (already wrote a single '\n') + if (d == '\r' && ifs.peek() == '\n') + { + ifs.get(d); // consume '\n' + } + newline_found = true; + break; + } } - if (!newline_found) - { + if (!newline_found) + { // reached EOF while skipping comment break; } @@ -139,15 +139,15 @@ bool filter_nonascii_and_comment(std::ifstream& ifs, } unsigned char uc = static_cast(c); - if (uc <= 0x7F) - { - // ASCII character + if (uc <= 0x7F) + { + // ASCII character out_ascii_stream.put(c); } - else - { - // replace non-ASCII with space character - out_ascii_stream.put(' '); + else + { + // replace non-ASCII with space character + out_ascii_stream.put(' '); } } @@ -329,21 +329,21 @@ void ReadInput::read_txt_input(Parameter& param, const std::string& filename) std::stringstream ascii_stream; - std::ifstream ifs(filename.c_str(), std::ios::in); + std::ifstream ifs(filename.c_str(), std::ios::in); - if (!ifs) - { - std::cout << " Can't find the INPUT file." << std::endl; - ModuleBase::WARNING_QUIT("Input::Init", "Error during readin parameters.", 1); - } + if (!ifs) + { + std::cout << " Can't find the INPUT file." << std::endl; + ModuleBase::WARNING_QUIT("Input::Init", "Error during readin parameters.", 1); + } - ifs.clear(); - ifs.seekg(0); + ifs.clear(); + ifs.seekg(0); - filter_nonascii_and_comment(ifs, ascii_stream); - ifs.clear(); + filter_nonascii_and_comment(ifs, ascii_stream); + ifs.clear(); - // file close after reading + // file close after reading int ierr = 0; ascii_stream.rdstate(); @@ -434,8 +434,8 @@ void ReadInput::read_txt_input(Parameter& param, const std::string& filename) { Input_Item* resetvalue_item = &(input_item.second); if (resetvalue_item->reset_value != nullptr) - { - resetvalue_item->reset_value(*resetvalue_item, param); + { + resetvalue_item->reset_value(*resetvalue_item, param); } } diff --git a/source/source_io/module_restart/restart.cpp b/source/source_io/module_restart/restart.cpp index 26c939bc627..9c16d420040 100644 --- a/source/source_io/module_restart/restart.cpp +++ b/source/source_io/module_restart/restart.cpp @@ -23,19 +23,19 @@ void Restart::write_file1(const std::string &file_name, const void*const ptr, const size_t size) const { - std::ofstream ofs(file_name, std::ofstream::binary|std::ofstream::trunc); - ofs.write(static_cast(ptr),size); + std::ofstream ofs(file_name, std::ofstream::binary|std::ofstream::trunc); + ofs.write(static_cast(ptr),size); } void Restart::read_file1(const std::string &file_name, void*const ptr, const size_t size) const { - std::ifstream ifs(file_name, std::ifstream::binary); - ifs.read(static_cast(ptr),size); + std::ifstream ifs(file_name, std::ifstream::binary); + ifs.read(static_cast(ptr),size); } bool Restart::write_file2(const std::string& file_name, const void* const ptr, const size_t size, const bool error_quit) const { - const int file = open(file_name.c_str(), O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR); + const int file = open(file_name.c_str(), O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR); if (-1 == file){ if (error_quit){ throw std::runtime_error("can't open restart save file. \nerrno=" + ModuleBase::GlobalFunc::TO_STRING(errno) + ".\n" + std::string(__FILE__) + " line " + std::to_string(__LINE__)); @@ -62,7 +62,7 @@ Restart restart; // Peize Lin add 2020.04.04 bool Restart::read_file2(const std::string& file_name, void* const ptr, const size_t size, const bool error_quit) const { - const int file = open(file_name.c_str(), O_RDONLY); + const int file = open(file_name.c_str(), O_RDONLY); if (-1 == file) { if (error_quit) { throw std::runtime_error("can't open restart load file. \nerrno=" + ModuleBase::GlobalFunc::TO_STRING(errno) + ".\n" + std::string(__FILE__) + " line " + std::to_string(__LINE__)); diff --git a/source/source_io/module_restart/restart.h b/source/source_io/module_restart/restart.h index 4fe2787ea6c..de869e4780f 100644 --- a/source/source_io/module_restart/restart.h +++ b/source/source_io/module_restart/restart.h @@ -10,24 +10,24 @@ class Restart { public: - struct Info_Save - { - bool save_charge = false; + struct Info_Save + { + bool save_charge = false; bool save_H = false; // save H means save Hexx now, will be changed in the future. - }; - Info_Save info_save; - - struct Info_Load - { - bool load_charge = false; - bool load_charge_finish = false; - bool load_H = false; - bool load_H_finish = false; + }; + Info_Save info_save; + + struct Info_Load + { + bool load_charge = false; + bool load_charge_finish = false; + bool load_H = false; + bool load_H_finish = false; bool restart_exx = false; // to avoid the repeated load in MD/Relax - }; - Info_Load info_load; - - std::string folder; + }; + Info_Load info_load; + + std::string folder; template bool save_disk(const std::string label, const int index, const int size, T* data, const bool error_quit = true) const @@ -48,8 +48,8 @@ class Restart error_quit); } private: - void write_file1(const std::string &file_name, const void*const ptr, const size_t size) const; - void read_file1(const std::string &file_name, void*const ptr, const size_t size) const; + void write_file1(const std::string &file_name, const void*const ptr, const size_t size) const; + void read_file1(const std::string &file_name, void*const ptr, const size_t size) const; bool write_file2(const std::string& file_name, const void* const ptr, const size_t size, const bool error_quit = true) const; bool read_file2(const std::string& file_name, void* const ptr, const size_t size, const bool error_quit = true) const; }; diff --git a/source/source_io/module_unk/berryphase.cpp b/source/source_io/module_unk/berryphase.cpp index e06f58861d4..6262b0c783d 100644 --- a/source/source_io/module_unk/berryphase.cpp +++ b/source/source_io/module_unk/berryphase.cpp @@ -519,12 +519,12 @@ void berryphase::Macroscopic_polarization(const UnitCell& ucell, // calculate Macroscopic polarization modulus because berry phase int modulus = 0; - if ((!lodd) && (PARAM.inp.nspin == 1)) - { - modulus = 2; - } else { - modulus = 1; - } + if ((!lodd) && (PARAM.inp.nspin == 1)) + { + modulus = 2; + } else { + modulus = 1; + } // test by jingan // GlobalV::ofs_running << "ion polarization end" << std::endl; diff --git a/source/source_io/module_unk/unk_overlap_lcao.cpp b/source/source_io/module_unk/unk_overlap_lcao.cpp index 99726117ffe..22aa6960316 100644 --- a/source/source_io/module_unk/unk_overlap_lcao.cpp +++ b/source/source_io/module_unk/unk_overlap_lcao.cpp @@ -180,50 +180,50 @@ void unkOverlap_lcao::init(const UnitCell& ucell, } for (auto& co1: center2_orb11) - { - for (auto& co2: co1.second) - { - for (auto& co3: co2.second) - { - for (auto& co4: co3.second) - { - for (auto& co5: co4.second) - { - for (auto& co6: co5.second) - { - co6.second.init_radial_table(); - } - } - } - } - } - } - - for (auto& co1: center2_orb21_r) - { - for (auto& co2: co1.second) - { - for (auto& co3: co2.second) - { - for (auto& co4: co3.second) - { - for (auto& co5: co4.second) - { - for (auto& co6: co5.second) - { - co6.second.init_radial_table(); - } - } - } - } - } - } - - rcut_orb_.resize(orb.get_ntype()); - for (int it = 0; it < orb.get_ntype(); ++it) - { - rcut_orb_[it] = orb.Phi[it].getRcut(); - } + { + for (auto& co2: co1.second) + { + for (auto& co3: co2.second) + { + for (auto& co4: co3.second) + { + for (auto& co5: co4.second) + { + for (auto& co6: co5.second) + { + co6.second.init_radial_table(); + } + } + } + } + } + } + + for (auto& co1: center2_orb21_r) + { + for (auto& co2: co1.second) + { + for (auto& co3: co2.second) + { + for (auto& co4: co3.second) + { + for (auto& co5: co4.second) + { + for (auto& co6: co5.second) + { + co6.second.init_radial_table(); + } + } + } + } + } + } + + rcut_orb_.resize(orb.get_ntype()); + for (int it = 0; it < orb.get_ntype(); ++it) + { + rcut_orb_[it] = orb.Phi[it].getRcut(); + } return; } @@ -444,10 +444,10 @@ void unkOverlap_lcao::cal_orb_overlap(const UnitCell& ucell) // if ( !pv.in_this_processor(iw1,iw2) ) continue; // iw1 and iw2 never have overlap - if (orb1_orb2_R[iw1][iw2].empty()) - { - continue; - } + if (orb1_orb2_R[iw1][iw2].empty()) + { + continue; + } int atomType1 = iw2it(ucell,iw1); int ia1 = iw2ia(ucell,iw1); diff --git a/source/source_io/module_wf/read_wf2rho_pw.cpp b/source/source_io/module_wf/read_wf2rho_pw.cpp index d66f5060514..50e31e733a3 100644 --- a/source/source_io/module_wf/read_wf2rho_pw.cpp +++ b/source/source_io/module_wf/read_wf2rho_pw.cpp @@ -242,22 +242,22 @@ void ModuleIO::read_wf2rho_pw_impl(const ModulePW::PW_Basis_K* pw_wfc, } void ModuleIO::read_wf2rho_pw( - const ModulePW::PW_Basis_K* pw_wfc, - ModuleSymmetry::Symmetry& symm, - Charge& chg, + const ModulePW::PW_Basis_K* pw_wfc, + ModuleSymmetry::Symmetry& symm, + Charge& chg, const std::string &readin_dir, - const int kpar, - const int my_pool, - const int my_rank, + const int kpar, + const int my_pool, + const int my_rank, const int nproc_in_pool, const int rank_in_pool, - const int nbands, - const int nspin, - const int npol, - const int nkstot, - const std::vector &ik2iktot, - const std::vector &isk, - std::ofstream &ofs_running) + const int nbands, + const int nspin, + const int npol, + const int nkstot, + const std::vector &ik2iktot, + const std::vector &isk, + std::ofstream &ofs_running) { #if defined(__CUDA) || defined(__ROCM) if (pw_wfc->get_device() == "gpu") @@ -274,38 +274,38 @@ void ModuleIO::read_wf2rho_pw( } template void ModuleIO::read_wf2rho_pw_impl( - const ModulePW::PW_Basis_K* pw_wfc, - ModuleSymmetry::Symmetry& symm, - Charge& chg, + const ModulePW::PW_Basis_K* pw_wfc, + ModuleSymmetry::Symmetry& symm, + Charge& chg, const std::string &readin_dir, - const int kpar, - const int my_pool, - const int my_rank, + const int kpar, + const int my_pool, + const int my_rank, const int nproc_in_pool, const int rank_in_pool, - const int nbands, - const int nspin, - const int npol, - const int nkstot, - const std::vector &ik2iktot, - const std::vector &isk, - std::ofstream &ofs_running); + const int nbands, + const int nspin, + const int npol, + const int nkstot, + const std::vector &ik2iktot, + const std::vector &isk, + std::ofstream &ofs_running); #if defined(__CUDA) || defined(__ROCM) template void ModuleIO::read_wf2rho_pw_impl( - const ModulePW::PW_Basis_K* pw_wfc, - ModuleSymmetry::Symmetry& symm, - Charge& chg, + const ModulePW::PW_Basis_K* pw_wfc, + ModuleSymmetry::Symmetry& symm, + Charge& chg, const std::string &readin_dir, - const int kpar, - const int my_pool, - const int my_rank, + const int kpar, + const int my_pool, + const int my_rank, const int nproc_in_pool, const int rank_in_pool, - const int nbands, - const int nspin, - const int npol, - const int nkstot, - const std::vector &ik2iktot, - const std::vector &isk, - std::ofstream &ofs_running); + const int nbands, + const int nspin, + const int npol, + const int nkstot, + const std::vector &ik2iktot, + const std::vector &isk, + std::ofstream &ofs_running); #endif diff --git a/source/source_io/module_wf/read_wf2rho_pw.h b/source/source_io/module_wf/read_wf2rho_pw.h index 0fc76b6fdc4..2205ff11a14 100644 --- a/source/source_io/module_wf/read_wf2rho_pw.h +++ b/source/source_io/module_wf/read_wf2rho_pw.h @@ -20,41 +20,41 @@ namespace ModuleIO */ void read_wf2rho_pw( - const ModulePW::PW_Basis_K* pw_wfc, - ModuleSymmetry::Symmetry& symm, - Charge& chg, + const ModulePW::PW_Basis_K* pw_wfc, + ModuleSymmetry::Symmetry& symm, + Charge& chg, const std::string &readin_dir, - const int kpar, - const int my_pool, - const int my_rank, + const int kpar, + const int my_pool, + const int my_rank, const int nproc_in_pool, const int rank_in_pool, - const int nbands, - const int nspin, - const int npol, - const int nkstot, - const std::vector &ik2iktot, - const std::vector &isk, - std::ofstream &ofs_running); + const int nbands, + const int nspin, + const int npol, + const int nkstot, + const std::vector &ik2iktot, + const std::vector &isk, + std::ofstream &ofs_running); template void read_wf2rho_pw_impl( - const ModulePW::PW_Basis_K* pw_wfc, - ModuleSymmetry::Symmetry& symm, - Charge& chg, + const ModulePW::PW_Basis_K* pw_wfc, + ModuleSymmetry::Symmetry& symm, + Charge& chg, const std::string &readin_dir, - const int kpar, - const int my_pool, - const int my_rank, + const int kpar, + const int my_pool, + const int my_rank, const int nproc_in_pool, const int rank_in_pool, - const int nbands, - const int nspin, - const int npol, - const int nkstot, - const std::vector &ik2iktot, - const std::vector &isk, - std::ofstream &ofs_running); + const int nbands, + const int nspin, + const int npol, + const int nkstot, + const std::vector &ik2iktot, + const std::vector &isk, + std::ofstream &ofs_running); } // namespace ModuleIO diff --git a/source/source_io/module_wf/read_wfc_nao.cpp b/source/source_io/module_wf/read_wfc_nao.cpp index 712c4e513ae..3148e2c0e2f 100644 --- a/source/source_io/module_wf/read_wfc_nao.cpp +++ b/source/source_io/module_wf/read_wfc_nao.cpp @@ -104,11 +104,11 @@ bool ModuleIO::read_wfc_nao( const std::string& global_readin_dir, const Parallel_Orbitals& ParaV, psi::Psi& psid, - ModuleBase::matrix& ekb, + ModuleBase::matrix& ekb, ModuleBase::matrix& wg, - const std::vector &ik2iktot, - const int nkstot, - const int nspin, + const std::vector &ik2iktot, + const int nkstot, + const int nspin, const bool binary, const int skip_band, const int istep) @@ -154,10 +154,10 @@ bool ModuleIO::read_wfc_nao( } // lambda function to read one file - auto read_one_file = [&](const std::string& ss, - std::stringstream& error_message, - const int ik, - std::vector& ctot) + auto read_one_file = [&](const std::string& ss, + std::stringstream& error_message, + const int ik, + std::vector& ctot) { std::ifstream ifs; const std::ios_base::openmode mode @@ -169,9 +169,9 @@ bool ModuleIO::read_wfc_nao( return false; } else - { + { std::cout << " Read NAO wave functions from " << ss << std::endl; - } + } const auto incomplete_file = [&](const std::string& field) { error_message << "The wave function file is incomplete or corrupted while reading " @@ -183,9 +183,9 @@ bool ModuleIO::read_wfc_nao( if (!gamma_only) { int ik_file = 0; - double kx = 0.0; - double ky = 0.0; - double kz = 0.0; + double kx = 0.0; + double ky = 0.0; + double kz = 0.0; if (!read_record_value(ifs, ik_file, binary)) { return incomplete_file("the k-point index"); @@ -282,15 +282,15 @@ bool ModuleIO::read_wfc_nao( std::string errors; - std::vector ctot; - if (myrank == 0) - { - ctot.resize(nbands * nlocal); - } - else - { - ctot.resize(0); - } + std::vector ctot; + if (myrank == 0) + { + ctot.resize(nbands * nlocal); + } + else + { + ctot.resize(0); + } for(int ik=0;ik(const std::string& global_readin_dir, const Parallel_Orbitals& ParaV, psi::Psi& psid, - ModuleBase::matrix& ekb, + ModuleBase::matrix& ekb, ModuleBase::matrix& wg, - const std::vector &ik2iktot, - const int nkstot, - const int nspin, + const std::vector &ik2iktot, + const int nkstot, + const int nspin, const bool binary, const int skip_band, const int istep); @@ -364,36 +364,36 @@ template bool ModuleIO::read_wfc_nao(const std::string& global_readin_di template bool ModuleIO::read_wfc_nao(const std::string& global_readin_dir, const Parallel_Orbitals& ParaV, psi::Psi& psid, - ModuleBase::matrix& ekb, + ModuleBase::matrix& ekb, ModuleBase::matrix& wg, - const std::vector &ik2iktot, - const int nkstot, - const int nspin, + const std::vector &ik2iktot, + const int nkstot, + const int nspin, const bool binary, const int skip_band, const int istep); template bool ModuleIO::read_wfc_nao>(const std::string& global_readin_dir, const Parallel_Orbitals& ParaV, - psi::Psi>& psid, - ModuleBase::matrix& ekb, + psi::Psi>& psid, + ModuleBase::matrix& ekb, ModuleBase::matrix& wg, - const std::vector &ik2iktot, - const int nkstot, - const int nspin, + const std::vector &ik2iktot, + const int nkstot, + const int nspin, const bool binary, - const int skip_band, + const int skip_band, const int istep); // mohan add 2025-10-19 template bool ModuleIO::read_wfc_nao>(const std::string& global_readin_dir, const Parallel_Orbitals& ParaV, - psi::Psi>& psid, - ModuleBase::matrix& ekb, + psi::Psi>& psid, + ModuleBase::matrix& ekb, ModuleBase::matrix& wg, - const std::vector &ik2iktot, - const int nkstot, - const int nspin, + const std::vector &ik2iktot, + const int nkstot, + const int nspin, const bool binary, - const int skip_band, + const int skip_band, const int istep); diff --git a/source/source_io/module_wf/read_wfc_nao.h b/source/source_io/module_wf/read_wfc_nao.h index 263b8de5403..0b3b23e11e2 100644 --- a/source/source_io/module_wf/read_wfc_nao.h +++ b/source/source_io/module_wf/read_wfc_nao.h @@ -43,11 +43,11 @@ bool read_wfc_nao( const std::string& global_readin_dir, const Parallel_Orbitals& ParaV, psi::Psi& psid, - ModuleBase::matrix& ekb, + ModuleBase::matrix& ekb, ModuleBase::matrix& wg, - const std::vector &ik2iktot, - const int nkstot, - const int nspin, + const std::vector &ik2iktot, + const int nkstot, + const int nspin, const bool binary, const int skip_band = 0, const int istep = -1); diff --git a/source/source_io/module_wf/read_wfc_pw.cpp b/source/source_io/module_wf/read_wfc_pw.cpp index 3850f2a42a6..0afaa5720b7 100644 --- a/source/source_io/module_wf/read_wfc_pw.cpp +++ b/source/source_io/module_wf/read_wfc_pw.cpp @@ -12,15 +12,15 @@ #include void ModuleIO::read_wfc_pw(const std::string& filename, - const ModulePW::PW_Basis_K* pw_wfc, - const int rank_in_pool, - const int nproc_in_pool, - const int nbands, - const int npol, - const int& ik, - const int& ikstot, - const int& nkstot, - ModuleBase::ComplexMatrix& wfc) + const ModulePW::PW_Basis_K* pw_wfc, + const int rank_in_pool, + const int nproc_in_pool, + const int nbands, + const int npol, + const int& ik, + const int& ikstot, + const int& nkstot, + ModuleBase::ComplexMatrix& wfc) { ModuleBase::TITLE("ModuleIO", "read_wfc_pw"); ModuleBase::timer::start("ModuleIO", "read_wfc_pw"); diff --git a/source/source_io/module_wf/read_wfc_pw.h b/source/source_io/module_wf/read_wfc_pw.h index fcd3023301d..d36a4113b63 100644 --- a/source/source_io/module_wf/read_wfc_pw.h +++ b/source/source_io/module_wf/read_wfc_pw.h @@ -20,15 +20,15 @@ namespace ModuleIO * @param wfc wave functions */ void read_wfc_pw(const std::string& filedir, - const ModulePW::PW_Basis_K* pw_wfc, - const int rank_in_pool, - const int nproc_in_pool, - const int nbands, - const int npol, - const int& ik, - const int& ikstot, - const int& nkstot, - ModuleBase::ComplexMatrix& wfc); + const ModulePW::PW_Basis_K* pw_wfc, + const int rank_in_pool, + const int nproc_in_pool, + const int nbands, + const int npol, + const int& ik, + const int& ikstot, + const int& nkstot, + ModuleBase::ComplexMatrix& wfc); } // namespace ModuleIO #endif diff --git a/source/source_io/module_wf/write_wfc_nao.cpp b/source/source_io/module_wf/write_wfc_nao.cpp index 216cb3e6bc8..2d28e96e60d 100644 --- a/source/source_io/module_wf/write_wfc_nao.cpp +++ b/source/source_io/module_wf/write_wfc_nao.cpp @@ -202,16 +202,16 @@ void wfc_nao_write2file_complex(const std::string& name, template void write_wfc_nao(const int out_type, - const bool out_app_flag, - const psi::Psi& psi, - const ModuleBase::matrix& ekb, - const ModuleBase::matrix& wg, - const std::vector>& kvec_c, - const std::vector &ik2iktot, - const int nkstot, - const Parallel_Orbitals& pv, - const int nspin, - const int istep) + const bool out_app_flag, + const psi::Psi& psi, + const ModuleBase::matrix& ekb, + const ModuleBase::matrix& wg, + const std::vector>& kvec_c, + const std::vector &ik2iktot, + const int nkstot, + const Parallel_Orbitals& pv, + const int nspin, + const int istep) { if (!out_type) { @@ -311,27 +311,27 @@ void write_wfc_nao(const int out_type, } template void write_wfc_nao(const int out_type, - const bool out_app_flag, - const psi::Psi& psi, - const ModuleBase::matrix& ekb, - const ModuleBase::matrix& wg, - const std::vector>& kvec_c, - const std::vector &ik2iktot, - const int nkstot, - const Parallel_Orbitals& pv, - const int nspin, - const int istep); + const bool out_app_flag, + const psi::Psi& psi, + const ModuleBase::matrix& ekb, + const ModuleBase::matrix& wg, + const std::vector>& kvec_c, + const std::vector &ik2iktot, + const int nkstot, + const Parallel_Orbitals& pv, + const int nspin, + const int istep); template void write_wfc_nao>(const int out_type, - const bool out_app_flag, - const psi::Psi>& psi, - const ModuleBase::matrix& ekb, - const ModuleBase::matrix& wg, - const std::vector>& kvec_c, - const std::vector &ik2iktot, - const int nkstot, - const Parallel_Orbitals& pv, - const int nspin, - const int istep); + const bool out_app_flag, + const psi::Psi>& psi, + const ModuleBase::matrix& ekb, + const ModuleBase::matrix& wg, + const std::vector>& kvec_c, + const std::vector &ik2iktot, + const int nkstot, + const Parallel_Orbitals& pv, + const int nspin, + const int istep); } // namespace ModuleIO diff --git a/source/source_io/module_wf/write_wfc_nao.h b/source/source_io/module_wf/write_wfc_nao.h index 48284d99113..152723b5109 100644 --- a/source/source_io/module_wf/write_wfc_nao.h +++ b/source/source_io/module_wf/write_wfc_nao.h @@ -9,7 +9,7 @@ namespace ModuleIO { - /** + /** * Writes the wavefunction coefficients for the LCAO method to a file. * Will loop all k-points by psi.get_nk(). * The nbands are determined by ekb.nc. @@ -25,16 +25,16 @@ namespace ModuleIO */ template void write_wfc_nao(const int out_type, - const bool out_app_flag, - const psi::Psi& psi, - const ModuleBase::matrix& ekb, - const ModuleBase::matrix& wg, - const std::vector>& kvec_c, - const std::vector &ik2iktot, - const int nkstot, - const Parallel_Orbitals& pv, - const int nspin, - const int istep=-1) ; + const bool out_app_flag, + const psi::Psi& psi, + const ModuleBase::matrix& ekb, + const ModuleBase::matrix& wg, + const std::vector>& kvec_c, + const std::vector &ik2iktot, + const int nkstot, + const Parallel_Orbitals& pv, + const int nspin, + const int istep=-1) ; void wfc_nao_write2file(const std::string& name, const double* ctot, diff --git a/source/source_io/module_wf/write_wfc_pw.cpp b/source/source_io/module_wf/write_wfc_pw.cpp index 7ad4ed137f2..450bb596988 100644 --- a/source/source_io/module_wf/write_wfc_pw.cpp +++ b/source/source_io/module_wf/write_wfc_pw.cpp @@ -32,10 +32,10 @@ void ModuleIO::write_wfc_pw( { ModuleBase::TITLE("ModuleIO", "write_wfc_pw"); - if(out_wfc_pw!=1 && out_wfc_pw!=2) - { - return; - } + if(out_wfc_pw!=1 && out_wfc_pw!=2) + { + return; + } const int nkstot = kv.get_nkstot(); const int nks = kv.get_nks(); @@ -61,23 +61,23 @@ void ModuleIO::write_wfc_pw( ofs_running << " Write G-space wave functions to file: " << fn << std::endl; - wfilename[ik_local] = fn; + wfilename[ik_local] = fn; - if (rank_in_pool == 0) - { - if (out_wfc_pw == 1) - { - std::ofstream ofs(fn.c_str()); // clear all wavefunc files. - ofs.close(); - } - else if (out_wfc_pw == 2) - { - Binstream wfs(fn, "w"); - wfs.close(); - } - } - } - } + if (rank_in_pool == 0) + { + if (out_wfc_pw == 1) + { + std::ofstream ofs(fn.c_str()); // clear all wavefunc files. + ofs.close(); + } + else if (out_wfc_pw == 2) + { + Binstream wfs(fn, "w"); + wfs.close(); + } + } + } + } #ifdef __MPI diff --git a/source/source_lcao/lcao_init_basis.cpp b/source/source_lcao/lcao_init_basis.cpp index 5a32f7def18..ad57ebb2ac7 100644 --- a/source/source_lcao/lcao_init_basis.cpp +++ b/source/source_lcao/lcao_init_basis.cpp @@ -13,7 +13,7 @@ void init_basis_lcao(Parallel_Orbitals& pv, const double &lcao_dk, const double &lcao_dr, const double &lcao_rmax, - UnitCell& ucell, + UnitCell& ucell, TwoCenterBundle& two_center_bundle, LCAO_Orbitals& orb ) diff --git a/source/source_lcao/lcao_set.cpp b/source/source_lcao/lcao_set.cpp index 8e881acf09d..9ccf22cad73 100644 --- a/source/source_lcao/lcao_set.cpp +++ b/source/source_lcao/lcao_set.cpp @@ -12,13 +12,13 @@ template void LCAO_domain::set_psi_occ_dm_chg( - const K_Vectors &kv, // k-points - psi::Psi* &psi, // coefficients of NAO basis - const Parallel_Orbitals &pv, // parallel scheme of NAO basis - elecstate::ElecState* pelec, // eigen values and weights - module_dm::Setup_DM &dmat, // density matrix - Charge &chr, // charge density - const Input_para &inp) // input parameters + const K_Vectors &kv, // k-points + psi::Psi* &psi, // coefficients of NAO basis + const Parallel_Orbitals &pv, // parallel scheme of NAO basis + elecstate::ElecState* pelec, // eigen values and weights + module_dm::Setup_DM &dmat, // density matrix + Charge &chr, // charge density + const Input_para &inp) // input parameters { //! 1) init electronic wave function psi @@ -54,14 +54,14 @@ void LCAO_domain::set_psi_occ_dm_chg( template void LCAO_domain::set_pot( UnitCell &ucell, // not const because of dftu - K_Vectors &kv, // not const due to exx - Structure_Factor& sf, // will be modified in potential - const ModulePW::PW_Basis &pw_rho, - const ModulePW::PW_Basis &pw_rhod, - elecstate::ElecState* pelec, - const LCAO_Orbitals& orb, - Parallel_Orbitals &pv, // not const due to deepks - pseudopot_cell_vl &locpp, + K_Vectors &kv, // not const due to exx + Structure_Factor& sf, // will be modified in potential + const ModulePW::PW_Basis &pw_rho, + const ModulePW::PW_Basis &pw_rhod, + elecstate::ElecState* pelec, + const LCAO_Orbitals& orb, + Parallel_Orbitals &pv, // not const due to deepks + pseudopot_cell_vl &locpp, Plus_U_Base &dftu, surchem& solvent, Exx_NAO &exx_nao, @@ -261,33 +261,33 @@ void LCAO_domain::init_chg_hr( template void LCAO_domain::set_psi_occ_dm_chg( - const K_Vectors &kv, // k-points - psi::Psi* &psi, // coefficients of NAO basis - const Parallel_Orbitals &pv, // parallel scheme of NAO basis - elecstate::ElecState* pelec, // eigen values and weights - module_dm::Setup_DM &dmat, // density matrix - Charge &chr, // charge density - const Input_para &inp); + const K_Vectors &kv, // k-points + psi::Psi* &psi, // coefficients of NAO basis + const Parallel_Orbitals &pv, // parallel scheme of NAO basis + elecstate::ElecState* pelec, // eigen values and weights + module_dm::Setup_DM &dmat, // density matrix + Charge &chr, // charge density + const Input_para &inp); template void LCAO_domain::set_psi_occ_dm_chg>( - const K_Vectors &kv, // k-points - psi::Psi>* &psi, // coefficients of NAO basis - const Parallel_Orbitals &pv, // parallel scheme of NAO basis - elecstate::ElecState* pelec, // eigen values and weights - module_dm::Setup_DM> &dmat, // density matrix - Charge &chr, // charge density - const Input_para &inp); + const K_Vectors &kv, // k-points + psi::Psi>* &psi, // coefficients of NAO basis + const Parallel_Orbitals &pv, // parallel scheme of NAO basis + elecstate::ElecState* pelec, // eigen values and weights + module_dm::Setup_DM> &dmat, // density matrix + Charge &chr, // charge density + const Input_para &inp); template void LCAO_domain::set_pot( UnitCell &ucell, - K_Vectors &kv, - Structure_Factor& sf, - const ModulePW::PW_Basis &pw_rho, - const ModulePW::PW_Basis &pw_rhod, - elecstate::ElecState* pelec, - const LCAO_Orbitals& orb, - Parallel_Orbitals &pv, - pseudopot_cell_vl &locpp, + K_Vectors &kv, + Structure_Factor& sf, + const ModulePW::PW_Basis &pw_rho, + const ModulePW::PW_Basis &pw_rhod, + elecstate::ElecState* pelec, + const LCAO_Orbitals& orb, + Parallel_Orbitals &pv, + pseudopot_cell_vl &locpp, Plus_U_Base &dftu, surchem& solvent, Exx_NAO &exx_nao, @@ -297,14 +297,14 @@ template void LCAO_domain::set_pot( template void LCAO_domain::set_pot>( UnitCell &ucell, - K_Vectors &kv, - Structure_Factor& sf, - const ModulePW::PW_Basis &pw_rho, - const ModulePW::PW_Basis &pw_rhod, - elecstate::ElecState* pelec, - const LCAO_Orbitals& orb, - Parallel_Orbitals &pv, - pseudopot_cell_vl &locpp, + K_Vectors &kv, + Structure_Factor& sf, + const ModulePW::PW_Basis &pw_rho, + const ModulePW::PW_Basis &pw_rhod, + elecstate::ElecState* pelec, + const LCAO_Orbitals& orb, + Parallel_Orbitals &pv, + pseudopot_cell_vl &locpp, Plus_U_Base &dftu, surchem& solvent, Exx_NAO> &exx_nao, diff --git a/source/source_lcao/lcao_set.h b/source/source_lcao/lcao_set.h index d9a192c4bdb..114246be22a 100644 --- a/source/source_lcao/lcao_set.h +++ b/source/source_lcao/lcao_set.h @@ -27,13 +27,13 @@ namespace LCAO_domain */ template void set_psi_occ_dm_chg( - const K_Vectors &kv, // k-points - psi::Psi* &psi, // coefficients of NAO basis - const Parallel_Orbitals &pv, // parallel scheme of NAO basis - elecstate::ElecState* pelec, // eigen values and weights - module_dm::Setup_DM &dmat, // density matrix - Charge &chr, // charge density - const Input_para& inp); // input parameters + const K_Vectors &kv, // k-points + psi::Psi* &psi, // coefficients of NAO basis + const Parallel_Orbitals &pv, // parallel scheme of NAO basis + elecstate::ElecState* pelec, // eigen values and weights + module_dm::Setup_DM &dmat, // density matrix + Charge &chr, // charge density + const Input_para& inp); // input parameters /** * @brief set up potentials, including local pseudopotentials, @@ -42,14 +42,14 @@ void set_psi_occ_dm_chg( template void set_pot( UnitCell &ucell, - K_Vectors &kv, - Structure_Factor& sf, - const ModulePW::PW_Basis &pw_rho, - const ModulePW::PW_Basis &pw_rhod, - elecstate::ElecState* pelec, - const LCAO_Orbitals& orb, - Parallel_Orbitals &pv, - pseudopot_cell_vl &locpp, + K_Vectors &kv, + Structure_Factor& sf, + const ModulePW::PW_Basis &pw_rho, + const ModulePW::PW_Basis &pw_rhod, + elecstate::ElecState* pelec, + const LCAO_Orbitals& orb, + Parallel_Orbitals &pv, + pseudopot_cell_vl &locpp, Plus_U_Base &dftu, surchem& solvent, Exx_NAO &exx_nao, @@ -64,11 +64,11 @@ void set_pot( */ template void init_dm_from_file( - const std::string& readin_dir, - const int nspin, - module_dm::Setup_DM& dmat, - const UnitCell& ucell, - const Parallel_Orbitals* pv); + const std::string& readin_dir, + const int nspin, + module_dm::Setup_DM& dmat, + const UnitCell& ucell, + const Parallel_Orbitals* pv); /** * @brief initialize charge density from density matrix file (init_chg=dm) @@ -82,22 +82,22 @@ void init_dm_from_file( */ template void init_chg_dm( - const std::string& readin_dir, - const int nspin, - module_dm::Setup_DM& dmat, - const UnitCell& ucell, - const Parallel_Orbitals* pv, - Charge* chr); + const std::string& readin_dir, + const int nspin, + module_dm::Setup_DM& dmat, + const UnitCell& ucell, + const Parallel_Orbitals* pv, + Charge* chr); /** * @brief read in HR from file, and save it into hmat */ template void init_hr_from_file( - const std::string hrfile, - hamilt::HContainer* hmat, - const UnitCell& ucell, - const Parallel_Orbitals* pv); + const std::string hrfile, + hamilt::HContainer* hmat, + const UnitCell& ucell, + const Parallel_Orbitals* pv); /** * @brief initialize charge density from Hamiltonian matrix file (init_chg=hr) @@ -119,16 +119,16 @@ void init_hr_from_file( */ template void init_chg_hr( - const std::string& readin_dir, - const int nspin, - hamilt::Hamilt* p_hamilt, - const UnitCell& ucell, - const Parallel_Orbitals* pv, - psi::Psi& psi, - elecstate::ElecState* pelec, - module_dm::DensityMatrix& dm, - Charge& chr, - const std::string& ks_solver); + const std::string& readin_dir, + const int nspin, + hamilt::Hamilt* p_hamilt, + const UnitCell& ucell, + const Parallel_Orbitals* pv, + psi::Psi& psi, + elecstate::ElecState* pelec, + module_dm::DensityMatrix& dm, + Charge& chr, + const std::string& ks_solver); } // end namespace #endif diff --git a/source/source_lcao/module_bse/molecular_lri.hpp b/source/source_lcao/module_bse/molecular_lri.hpp index d8e5d117dee..f11e4f49246 100644 --- a/source/source_lcao/module_bse/molecular_lri.hpp +++ b/source/source_lcao/module_bse/molecular_lri.hpp @@ -59,7 +59,7 @@ void MolecularLRI::init(TLRI& Cs_in, TLRI& Vs_in, TLRI& Ws_in, const { for (const TC R_original : this->kRlist.Rlist) { - const TC R = cell_nearest.cell_nearest_direction(i, j, R_original, dist); + const TC R = cell_nearest.cell_nearest_direction(i, j, R_original, dist); if (R != R_original) { BSE_Util::move_R_tensor(Cs_in, i, j, R_original, R); diff --git a/source/source_lcao/module_deltaspin/cal_mw_from_lambda.cpp b/source/source_lcao/module_deltaspin/cal_mw_from_lambda.cpp index aebb3005e9d..2b0d39992e3 100644 --- a/source/source_lcao/module_deltaspin/cal_mw_from_lambda.cpp +++ b/source/source_lcao/module_deltaspin/cal_mw_from_lambda.cpp @@ -89,8 +89,8 @@ */ template <> void spinconstrain::SpinConstrain>::cal_mw_from_lambda( - int i_step, - const ModuleBase::Vector3* delta_lambda) + int i_step, + const ModuleBase::Vector3* delta_lambda) { ModuleBase::TITLE("spinconstrain::SpinConstrain", "cal_mw_from_lambda"); ModuleBase::timer::start("spinconstrain::SpinConstrain", "cal_mw_from_lambda"); diff --git a/source/source_lcao/module_deltaspin/deltaspin_init.cpp b/source/source_lcao/module_deltaspin/deltaspin_init.cpp index e02584ce8f0..e410e2c7fee 100644 --- a/source/source_lcao/module_deltaspin/deltaspin_init.cpp +++ b/source/source_lcao/module_deltaspin/deltaspin_init.cpp @@ -90,23 +90,23 @@ void init_sc_state(const ScInitParams& params, const UnitCell& ucell, ScState& s template void spinconstrain::SpinConstrain::init_sc(double sc_thr_in, - int nsc_in, - int nsc_min_in, - double alpha_trial_in, - double sccut_in, - double sc_drop_thr_in, - const UnitCell& ucell, - bool direction_only_in, - Parallel_Orbitals* ParaV_in, - int nspin_in, - const K_Vectors& kv_in, - void* p_hamilt_in, - void* psi_in, + int nsc_in, + int nsc_min_in, + double alpha_trial_in, + double sccut_in, + double sc_drop_thr_in, + const UnitCell& ucell, + bool direction_only_in, + Parallel_Orbitals* ParaV_in, + int nspin_in, + const K_Vectors& kv_in, + void* p_hamilt_in, + void* psi_in, #ifdef __LCAO - module_dm::DensityMatrix* dm_in, // mohan add 2025-11-03 + module_dm::DensityMatrix* dm_in, // mohan add 2025-11-03 #endif - elecstate::ElecState* pelec_in, - ModulePW::PW_Basis_K* pw_wfc_in) + elecstate::ElecState* pelec_in, + ModulePW::PW_Basis_K* pw_wfc_in) { // Steps 1-6: solver-independent state initialization const spinconstrain::ScInitParams params{sc_thr_in, nsc_in, nsc_min_in, diff --git a/source/source_lcao/module_deltaspin/lambda_loop.cpp b/source/source_lcao/module_deltaspin/lambda_loop.cpp index 77d848b3415..8534ef44341 100644 --- a/source/source_lcao/module_deltaspin/lambda_loop.cpp +++ b/source/source_lcao/module_deltaspin/lambda_loop.cpp @@ -100,9 +100,9 @@ void spinconstrain::SpinConstrain>::run_lambda_loop(int out // Timer initialization (MPI or CPU) #ifdef __MPI - auto iterstart = MPI_Wtime(); + auto iterstart = MPI_Wtime(); #else - auto iterstart = std::chrono::system_clock::now(); + auto iterstart = std::chrono::system_clock::now(); #endif double inner_loop_duration = 0.0; @@ -179,9 +179,9 @@ void spinconstrain::SpinConstrain>::run_lambda_loop(int out add_scalar_multiply_2d(initial_lambda, dnu_last_step, one, this->state_.lambda_); this->update_psi_charge(dnu_last_step.data(), true, true); #ifdef __MPI - duration = (double)(MPI_Wtime() - iterstart); + duration = (double)(MPI_Wtime() - iterstart); #else - duration = + duration = (std::chrono::duration_cast(std::chrono::system_clock::now() - iterstart)).count() / static_cast(1e6); #endif @@ -253,9 +253,9 @@ void spinconstrain::SpinConstrain>::run_lambda_loop(int out // CHECK CONVERGENCE // ============================================================= #ifdef __MPI - duration = (double)(MPI_Wtime() - iterstart); + duration = (double)(MPI_Wtime() - iterstart); #else - duration = + duration = (std::chrono::duration_cast(std::chrono::system_clock::now() - iterstart)).count() / static_cast(1e6); #endif @@ -299,9 +299,9 @@ void spinconstrain::SpinConstrain>::run_lambda_loop(int out // Reset timer for next iteration #ifdef __MPI - iterstart = MPI_Wtime(); + iterstart = MPI_Wtime(); #else - iterstart = std::chrono::system_clock::now(); + iterstart = std::chrono::system_clock::now(); #endif // ============================================================= diff --git a/source/source_lcao/module_deltaspin/spin_constrain.h b/source/source_lcao/module_deltaspin/spin_constrain.h index 64d40eb7ebb..7dba0c2b89d 100644 --- a/source/source_lcao/module_deltaspin/spin_constrain.h +++ b/source/source_lcao/module_deltaspin/spin_constrain.h @@ -154,9 +154,9 @@ class SpinConstrain void* p_hamilt_in, void* psi_in, #ifdef __LCAO - module_dm::DensityMatrix *dm_in, // mohan add 2025-11-02 + module_dm::DensityMatrix *dm_in, // mohan add 2025-11-02 #endif - elecstate::ElecState* pelec_in, + elecstate::ElecState* pelec_in, ModulePW::PW_Basis_K* pw_wfc_in = nullptr); /** @@ -198,7 +198,7 @@ class SpinConstrain * @param delta_lambda Change in lambda from previous step (for incremental H correction) */ void cal_mw_from_lambda(int i_step, - const ModuleBase::Vector3* delta_lambda = nullptr); + const ModuleBase::Vector3* delta_lambda = nullptr); /** * @brief Calculate the spin constraint energy contribution: E_scon = -sum(lambda_i . Mi_i). @@ -228,8 +228,8 @@ class SpinConstrain * @param rerun If true, use full PW solver for final charge update */ void run_lambda_loop(int outer_step, - bool rerun, - std::ostream& ofs_running); + bool rerun, + std::ostream& ofs_running); /// @brief RMS error of the most recent lambda optimization loop (-1.0 if none has run). double get_last_rms_error() const { return last_rms_error_; } diff --git a/source/source_lcao/module_lr/lr_spectrum.cpp b/source/source_lcao/module_lr/lr_spectrum.cpp index abb5bd81765..7f38537eab1 100644 --- a/source/source_lcao/module_lr/lr_spectrum.cpp +++ b/source/source_lcao/module_lr/lr_spectrum.cpp @@ -192,10 +192,10 @@ void LR::LR_Spectrum::optical_absorption_method1(const std::vector& f std::vector& osc = this->oscillator_strength_; std::ofstream ofs(this->out_dir + "absorption.dat"); - if (this->my_rank == 0) - { - ofs << "Frequency (eV) | wave length(nm) | Absorption (a.u.)" << std::endl; - } + if (this->my_rank == 0) + { + ofs << "Frequency (eV) | wave length(nm) | Absorption (a.u.)" << std::endl; + } double FourPI_div_c = ModuleBase::FOUR_PI / 137.036; double fac = 4 * M_PI / ucell.omega * ModuleBase::e2 / this->nk; // e2 for Ry to Hartree in the denominator diff --git a/source/source_lcao/module_operator_lcao/td_ekinetic_lcao.cpp b/source/source_lcao/module_operator_lcao/td_ekinetic_lcao.cpp index bb35b607009..35987012d85 100644 --- a/source/source_lcao/module_operator_lcao/td_ekinetic_lcao.cpp +++ b/source/source_lcao/module_operator_lcao/td_ekinetic_lcao.cpp @@ -215,11 +215,11 @@ void TDEkinetic>::cal_HR_IJR(const int& iat1, hr_mat_p += (npol - 1) * col_indexes.size(); if (current_mat_p != nullptr) { - for (int dir = 0; dir < 3; dir++) - { - current_mat_p[dir] += (npol - 1) * col_indexes.size(); - } - } + for (int dir = 0; dir < 3; dir++) + { + current_mat_p[dir] += (npol - 1) * col_indexes.size(); + } + } } } //update vector potential for td_ekintic term diff --git a/source/source_lcao/module_ri/abfs.h b/source/source_lcao/module_ri/abfs.h index d3b774d9734..bdc6b94f79b 100644 --- a/source/source_lcao/module_ri/abfs.h +++ b/source/source_lcao/module_ri/abfs.h @@ -12,8 +12,8 @@ class Abfs { public: - - template class Vector3_Order; + + template class Vector3_Order; }; #endif // ABFS_H diff --git a/source/source_lcao/module_ri/abfs_construct_pca.cpp b/source/source_lcao/module_ri/abfs_construct_pca.cpp index b07e49fb1df..751f9405fa0 100644 --- a/source/source_lcao/module_ri/abfs_construct_pca.cpp +++ b/source/source_lcao/module_ri/abfs_construct_pca.cpp @@ -16,20 +16,20 @@ namespace PCA { template <> void tensor_syev(char jobz, char uplo, RI::Tensor& a, double* w, int& info) - { - assert(a.shape.size() == 2); - assert(a.shape[0] == a.shape[1]); + { + assert(a.shape.size() == 2); + assert(a.shape[0] == a.shape[1]); const int n = a.shape[0]; const int lda = a.shape[1]; double work_query = 0.0; - constexpr int minus_one = -1; + constexpr int minus_one = -1; dsyev_(&jobz, &uplo, &n, a.ptr(), &lda, w, &work_query, &minus_one, &info); const int lwork = static_cast(work_query); - std::vector work(std::max(1, lwork)); + std::vector work(std::max(1, lwork)); dsyev_(&jobz, &uplo, &n, a.ptr(), &lda, w, work.data(), &lwork, &info); } @@ -52,7 +52,7 @@ void tensor_syev(char jobz, char uplo, RI::Tensor& a, float* w, in std::vector work(std::max(1, lwork)); ssyev_(&jobz, &uplo, &n, a.ptr(), &lda, w, work.data(), &lwork, &info); - } + } template <> void tensor_syev>(char jobz, char uplo, RI::Tensor>& a, double* w, int& info) @@ -117,9 +117,9 @@ RI::Tensor get_sub_matrix(const RI::Tensor& m, // size: (lcaos, const std::size_t& L, const ModuleBase::Element_Basis_Index::Range& range, const ModuleBase::Element_Basis_Index::IndexLNM& index) - { - ModuleBase::TITLE("ABFs_Construct::PCA::get_sub_matrix"); - assert(m.shape.size() == 3); + { + ModuleBase::TITLE("ABFs_Construct::PCA::get_sub_matrix"); + assert(m.shape.size() == 3); RI::Tensor m_sub({m.shape[0], m.shape[1], range[T][L].N}); for (std::size_t ir = 0; ir != m.shape[0]; ++ir) { @@ -127,20 +127,20 @@ RI::Tensor get_sub_matrix(const RI::Tensor& m, // size: (lcaos, { for (std::size_t N = 0; N != range[T][L].N; ++N) { - m_sub(ir, jr, N) = m(ir, jr, index[T][L][N][0]); + m_sub(ir, jr, N) = m(ir, jr, index[T][L][N][0]); } } } m_sub = m_sub.reshape({m.shape[0] * m.shape[1], range[T][L].N}); - return m_sub; - } + return m_sub; + } RI::Tensor get_column_mean0_matrix(const RI::Tensor& m) - { - ModuleBase::TITLE("ABFs_Construct::PCA::get_column_mean0_matrix"); + { + ModuleBase::TITLE("ABFs_Construct::PCA::get_column_mean0_matrix"); RI::Tensor m_new(m.shape); for (std::size_t ic = 0; ic != m.shape[1]; ++ic) - { + { double sum = 0; for (std::size_t ir = 0; ir != m.shape[0]; ++ir) { @@ -151,19 +151,19 @@ RI::Tensor get_column_mean0_matrix(const RI::Tensor& m) { m_new(ir, ic) = m(ir, ic) - mean; } - } - return m_new; - } + } + return m_new; + } - std::vector, RI::Tensor>>> cal_PCA( + std::vector, RI::Tensor>>> cal_PCA( const UnitCell& ucell, const LCAO_Orbitals& orb, const std::vector>>& lcaos, const std::vector>>& abfs, const double kmesh_times) - { - ModuleBase::TITLE("ABFs_Construct::PCA::cal_PCA"); - + { + ModuleBase::TITLE("ABFs_Construct::PCA::cal_PCA"); + const ModuleBase::Element_Basis_Index::Range range_lcaos = ModuleBase::Element_Basis_Index::construct_range(lcaos); const ModuleBase::Element_Basis_Index::IndexLNM index_lcaos = ModuleBase::Element_Basis_Index::construct_index(range_lcaos); @@ -172,68 +172,68 @@ RI::Tensor get_column_mean0_matrix(const RI::Tensor& m) const ModuleBase::Element_Basis_Index::IndexLNM index_abfs = ModuleBase::Element_Basis_Index::construct_index(range_abfs); - Matrix_Orbs21 m_abfslcaos_lcaos; + Matrix_Orbs21 m_abfslcaos_lcaos; m_abfslcaos_lcaos.init(abfs, lcaos, lcaos, ucell, orb, kmesh_times); std::map>> delta_R; for (std::size_t it = 0; it != abfs.size(); ++it) { delta_R[it][it] = {0.0}; } - m_abfslcaos_lcaos.init_radial_table(delta_R); - + m_abfslcaos_lcaos.init_radial_table(delta_R); + std::vector, RI::Tensor>>> eig(abfs.size()); for (std::size_t T = 0; T != abfs.size(); ++T) - { + { const RI::Tensor A = m_abfslcaos_lcaos.cal_overlap_matrix(T, - T, + T, ModuleBase::Vector3{0, 0, 0}, ModuleBase::Vector3{0, 0, 0}, - index_abfs, - index_lcaos, - index_lcaos, - Matrix_Orbs21::Matrix_Order::A2BA1); - - eig[T].resize(abfs[T].size()); + index_abfs, + index_lcaos, + index_lcaos, + Matrix_Orbs21::Matrix_Order::A2BA1); + + eig[T].resize(abfs[T].size()); for (std::size_t L = 0; L != abfs[T].size(); ++L) - { + { const RI::Tensor A_sub = get_sub_matrix(A, T, L, range_abfs, index_abfs); - RI::Tensor mm = A_sub.transpose() * A_sub; - std::vector eig_value(mm.shape[0]); - + RI::Tensor mm = A_sub.transpose() * A_sub; + std::vector eig_value(mm.shape[0]); + int info = 1; tensor_syev('V', 'L', mm, eig_value.data(), info); if (info) - { - std::cout << std::endl << "info_dsyev = " << info << std::endl; + { + std::cout << std::endl << "info_dsyev = " << info << std::endl; auto tensor_print = [](RI::Tensor& m, std::ostream& os, const double threshold) { - for (int ir = 0; ir != m.shape[0]; ++ir) - { - for (int ic = 0; ic != m.shape[1]; ++ic) - { + for (int ir = 0; ir != m.shape[0]; ++ir) + { + for (int ic = 0; ic != m.shape[1]; ++ic) + { if (std::abs(m(ir, ic)) > threshold) { - os << m(ir, ic) << "\t"; + os << m(ir, ic) << "\t"; } else { - os << 0 << "\t"; + os << 0 << "\t"; } - } - os << std::endl; - } - os << std::endl; - }; - tensor_print(mm, GlobalV::ofs_warning, 0.0); + } + os << std::endl; + } + os << std::endl; + }; + tensor_print(mm, GlobalV::ofs_warning, 0.0); std::cout << "in file " << __FILE__ << " line " << __LINE__ << std::endl; - ModuleBase::QUIT(); - } + ModuleBase::QUIT(); + } eig[T][L] = std::make_pair(eig_value, mm); - } - } - - return eig; - } + } + } + + return eig; + } } // namespace PCA } // namespace ABFs_Construct diff --git a/source/source_lcao/module_ri/abfs_construct_pca.h b/source/source_lcao/module_ri/abfs_construct_pca.h index d6e5409710a..9bfc4d36a4c 100644 --- a/source/source_lcao/module_ri/abfs_construct_pca.h +++ b/source/source_lcao/module_ri/abfs_construct_pca.h @@ -16,7 +16,7 @@ namespace ABFs_Construct namespace PCA { extern std::vector, RI::Tensor>>> cal_PCA( - const UnitCell& ucell, + const UnitCell& ucell, const LCAO_Orbitals& orb, const std::vector>>& lcaos, const std::vector>>& abfs, // abfs must be orthonormal diff --git a/source/source_lcao/module_ri/abfs_vector3_order.h b/source/source_lcao/module_ri/abfs_vector3_order.h index 4857770ea0f..d37c35421ed 100644 --- a/source/source_lcao/module_ri/abfs_vector3_order.h +++ b/source/source_lcao/module_ri/abfs_vector3_order.h @@ -15,9 +15,9 @@ template class Abfs::Vector3_Order: public ModuleBase::Vector3 { public: - Vector3_Order(const ModuleBase::Vector3 &v):ModuleBase::Vector3(v){} - Vector3_Order(const T &x,const T &y,const T &z):ModuleBase::Vector3(x,y,z){} - Vector3_Order()=default; + Vector3_Order(const ModuleBase::Vector3 &v):ModuleBase::Vector3(v){} + Vector3_Order(const T &x,const T &y,const T &z):ModuleBase::Vector3(x,y,z){} + Vector3_Order()=default; }; template @@ -26,65 +26,65 @@ bool operator< ( const Abfs::Vector3_Order &v1, const Abfs::Vector3_Order template<> inline bool operator< ( const Abfs::Vector3_Order &v1, const Abfs::Vector3_Order &v2 ) { - // threshold is used when v1 and v2 are approximately equal with double numerical error, - // but a strange bug occurs at LRI_CV::dVws. - // Peize Lin change at 2023.04.29 - if ( v1.x < v2.x ) return true; - else if ( v1.x > v2.x ) return false; - if ( v1.y < v2.y ) return true; - else if ( v1.y > v2.y ) return false; - if ( v1.z < v2.z ) return true; - else if ( v1.z > v2.z ) return false; - return false; + // threshold is used when v1 and v2 are approximately equal with double numerical error, + // but a strange bug occurs at LRI_CV::dVws. + // Peize Lin change at 2023.04.29 + if ( v1.x < v2.x ) return true; + else if ( v1.x > v2.x ) return false; + if ( v1.y < v2.y ) return true; + else if ( v1.y > v2.y ) return false; + if ( v1.z < v2.z ) return true; + else if ( v1.z > v2.z ) return false; + return false; } template<> inline bool operator< ( const Abfs::Vector3_Order &v1, const Abfs::Vector3_Order &v2 ) { - if ( v1.x < v2.x ) return true; - else if ( v1.x > v2.x ) return false; - if ( v1.y < v2.y ) return true; - else if ( v1.y > v2.y ) return false; - if ( v1.z < v2.z ) return true; - else if ( v1.z > v2.z ) return false; - return false; + if ( v1.x < v2.x ) return true; + else if ( v1.x > v2.x ) return false; + if ( v1.y < v2.y ) return true; + else if ( v1.y > v2.y ) return false; + if ( v1.z < v2.z ) return true; + else if ( v1.z > v2.z ) return false; + return false; } /* template bool operator> ( const Abfs::Vector3_Order &v1, const Abfs::Vector3_Order &v2 ) { - if( v1.x>v2.x ) return true; - else if ( v1.xv2.y ) return true; - else if ( v1.yv2.z ) return true; - else if ( v1.zv2.x ) return true; + else if ( v1.xv2.y ) return true; + else if ( v1.yv2.z ) return true; + else if ( v1.z bool operator<= ( const Abfs::Vector3_Order &v1, const Abfs::Vector3_Order &v2 ) { - if( v1.xv2.x ) return false; - if( v1.yv2.y ) return false; - if( v1.zv2.z ) return false; - return true; + if( v1.xv2.x ) return false; + if( v1.yv2.y ) return false; + if( v1.zv2.z ) return false; + return true; } template bool operator>= ( const Abfs::Vector3_Order &v1, const Abfs::Vector3_Order &v2 ) { - if( v1.x>v2.x ) return true; - else if ( v1.xv2.y ) return true; - else if ( v1.yv2.z ) return true; - else if ( v1.zv2.x ) return true; + else if ( v1.xv2.y ) return true; + else if ( v1.yv2.z ) return true; + else if ( v1.z= ( const Abfs::Vector3_Order &v1, const Abfs::Vector3_Order template Abfs::Vector3_Order operator% ( const Abfs::Vector3_Order &v1, const Abfs::Vector3_Order &v2 ) { - auto mod = [](const int i, const int n){ return (i%n+3*n/2)%n-n/2; }; // [-n/2,n/2] + auto mod = [](const int i, const int n){ return (i%n+3*n/2)%n-n/2; }; // [-n/2,n/2] // auto mod = [](const int i, const int n){ return (i%n+n)%n; }; // [0,n] - return Abfs::Vector3_Order{ mod(v1.x,v2.x), mod(v1.y,v2.y), mod(v1.z,v2.z) }; + return Abfs::Vector3_Order{ mod(v1.x,v2.x), mod(v1.y,v2.y), mod(v1.z,v2.z) }; } #endif // ABFS_VECTOR3_ORDER_H diff --git a/source/source_lcao/module_ri/conv_coulomb_pot_k.cpp b/source/source_lcao/module_ri/conv_coulomb_pot_k.cpp index 3970b98f41d..6903b172154 100644 --- a/source/source_lcao/module_ri/conv_coulomb_pot_k.cpp +++ b/source/source_lcao/module_ri/conv_coulomb_pot_k.cpp @@ -5,146 +5,146 @@ namespace Conv_Coulomb_Pot_K { - std::vector cal_psi_fock_limits( - const std::vector & psif) - { - std::vector psik2_ccp(psif.size()); - for( size_t ik=0; ik cal_psi_fock_limits( + const std::vector & psif) + { + std::vector psik2_ccp(psif.size()); + for( size_t ik=0; ik cal_psi_fock_spencer( - const std::vector &psif, - const std::vector &k_radial, - const double rcut) - { - std::vector psik2_ccp(psif.size()); - for (size_t ik = 0; ik < psif.size(); ++ik) - { psik2_ccp[ik] = ModuleBase::FOUR_PI * psif[ik] * (1 - std::cos(k_radial[ik] * rcut)); } - return psik2_ccp; - } + // rongshi add 2022-07-27 + // Sphere truction -- Spencer + std::vector cal_psi_fock_spencer( + const std::vector &psif, + const std::vector &k_radial, + const double rcut) + { + std::vector psik2_ccp(psif.size()); + for (size_t ik = 0; ik < psif.size(); ++ik) + { psik2_ccp[ik] = ModuleBase::FOUR_PI * psif[ik] * (1 - std::cos(k_radial[ik] * rcut)); } + return psik2_ccp; + } - std::vector cal_psi_erfc_limits( - const std::vector & psif, - const std::vector & k_radial, - const double erfc_omega) - { - std::vector psik2_ccp(psif.size()); - for( size_t ik=0; ik cal_psi_erfc_limits( + const std::vector & psif, + const std::vector & k_radial, + const double erfc_omega) + { + std::vector psik2_ccp(psif.size()); + for( size_t ik=0; ik cal_psi_erfc_spencer( - const std::vector& psif, + std::vector cal_psi_erfc_spencer( + const std::vector& psif, const std::vector& k_radial, const double erfc_omega, const double rcut) - { - double eps = 1e-14; - std::vector psik2_ccp(psif.size()); - for (size_t ik = 0; ik < psif.size(); ++ik) - { - double temp0 = std::cos(k_radial[ik] * rcut) * std::erfc(erfc_omega * rcut); - double temp1 = std::exp(-(k_radial[ik] * k_radial[ik]) / (4 * erfc_omega * erfc_omega)); - std::complex temp2 = std::complex(0, 0); - std::complex temp3 = std::complex(0, 0); - if (temp1 >= eps) - { - temp2 = ModuleBase::ErrorFunc::erf(0.5 * (ModuleBase::IMAG_UNIT * k_radial[ik] + 2 * erfc_omega * erfc_omega * rcut) - / erfc_omega); - temp3 = ModuleBase::NEG_IMAG_UNIT - * ModuleBase::ErrorFunc::erfi(0.5 * k_radial[ik] / erfc_omega + ModuleBase::IMAG_UNIT * erfc_omega * rcut); - } - std::complex fock_part = -0.5 * (-2 + 2 * temp0 + temp1 * (temp2 + temp3)); - psik2_ccp[ik] = ModuleBase::FOUR_PI * psif[ik] * fock_part.real(); - } - return psik2_ccp; - } + { + double eps = 1e-14; + std::vector psik2_ccp(psif.size()); + for (size_t ik = 0; ik < psif.size(); ++ik) + { + double temp0 = std::cos(k_radial[ik] * rcut) * std::erfc(erfc_omega * rcut); + double temp1 = std::exp(-(k_radial[ik] * k_radial[ik]) / (4 * erfc_omega * erfc_omega)); + std::complex temp2 = std::complex(0, 0); + std::complex temp3 = std::complex(0, 0); + if (temp1 >= eps) + { + temp2 = ModuleBase::ErrorFunc::erf(0.5 * (ModuleBase::IMAG_UNIT * k_radial[ik] + 2 * erfc_omega * erfc_omega * rcut) + / erfc_omega); + temp3 = ModuleBase::NEG_IMAG_UNIT + * ModuleBase::ErrorFunc::erfi(0.5 * k_radial[ik] / erfc_omega + ModuleBase::IMAG_UNIT * erfc_omega * rcut); + } + std::complex fock_part = -0.5 * (-2 + 2 * temp0 + temp1 * (temp2 + temp3)); + psik2_ccp[ik] = ModuleBase::FOUR_PI * psif[ik] * fock_part.real(); + } + return psik2_ccp; + } - template<> - Numerical_Orbital_Lm cal_orbs_ccp( - const Numerical_Orbital_Lm &orbs, - const std::map>> &coulomb_param, - const double rmesh_times) - { - std::vector psik2_ccp(orbs.get_psif().size(), 0.0); + template<> + Numerical_Orbital_Lm cal_orbs_ccp( + const Numerical_Orbital_Lm &orbs, + const std::map>> &coulomb_param, + const double rmesh_times) + { + std::vector psik2_ccp(orbs.get_psif().size(), 0.0); - for(const auto ¶m_list : coulomb_param) - { - switch(param_list.first) - { - case Conv_Coulomb_Pot_K::Coulomb_Type::Fock: - { - for(const auto ¶m : param_list.second) - { - if(param.at("singularity_correction") == "limits" || param.at("singularity_correction") == "massidda" || param.at("singularity_correction") == "carrier") - { psik2_ccp = psik2_ccp + std::stod(param.at("alpha")) * cal_psi_fock_limits( orbs.get_psif() ); } - else if(param.at("singularity_correction") == "spencer" || param.at("singularity_correction") == "revised_spencer") - { psik2_ccp = psik2_ccp + std::stod(param.at("alpha")) * cal_psi_fock_spencer( orbs.get_psif(), orbs.get_k_radial(), std::stod(param.at("Rcut")) ); } - else - { throw std::invalid_argument( "singularity_correction = " + param.at("singularity_correction") + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__) ); } - } - break; - } - case Conv_Coulomb_Pot_K::Coulomb_Type::Erfc: - { - for(const auto ¶m : param_list.second) - { - if(param.at("singularity_correction") == "limits" || param.at("singularity_correction") == "massidda" || param.at("singularity_correction") == "carrier") - { psik2_ccp = psik2_ccp + std::stod(param.at("alpha")) * cal_psi_erfc_limits( orbs.get_psif(), orbs.get_k_radial(), std::stod(param.at("omega")) ); } - else if(param.at("singularity_correction") == "spencer" || param.at("singularity_correction") == "revised_spencer") - { psik2_ccp = psik2_ccp + std::stod(param.at("alpha")) * cal_psi_erfc_spencer( orbs.get_psif(), orbs.get_k_radial(), std::stod(param.at("omega")), std::stod(param.at("Rcut")) ); } - else - { throw std::invalid_argument( "singularity_correction = " + param.at("singularity_correction") + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__) ); } - } - break; - } - default: - { - throw std::invalid_argument( std::string(__FILE__) + " line " + std::to_string(__LINE__) ); - } - } - } + for(const auto ¶m_list : coulomb_param) + { + switch(param_list.first) + { + case Conv_Coulomb_Pot_K::Coulomb_Type::Fock: + { + for(const auto ¶m : param_list.second) + { + if(param.at("singularity_correction") == "limits" || param.at("singularity_correction") == "massidda" || param.at("singularity_correction") == "carrier") + { psik2_ccp = psik2_ccp + std::stod(param.at("alpha")) * cal_psi_fock_limits( orbs.get_psif() ); } + else if(param.at("singularity_correction") == "spencer" || param.at("singularity_correction") == "revised_spencer") + { psik2_ccp = psik2_ccp + std::stod(param.at("alpha")) * cal_psi_fock_spencer( orbs.get_psif(), orbs.get_k_radial(), std::stod(param.at("Rcut")) ); } + else + { throw std::invalid_argument( "singularity_correction = " + param.at("singularity_correction") + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__) ); } + } + break; + } + case Conv_Coulomb_Pot_K::Coulomb_Type::Erfc: + { + for(const auto ¶m : param_list.second) + { + if(param.at("singularity_correction") == "limits" || param.at("singularity_correction") == "massidda" || param.at("singularity_correction") == "carrier") + { psik2_ccp = psik2_ccp + std::stod(param.at("alpha")) * cal_psi_erfc_limits( orbs.get_psif(), orbs.get_k_radial(), std::stod(param.at("omega")) ); } + else if(param.at("singularity_correction") == "spencer" || param.at("singularity_correction") == "revised_spencer") + { psik2_ccp = psik2_ccp + std::stod(param.at("alpha")) * cal_psi_erfc_spencer( orbs.get_psif(), orbs.get_k_radial(), std::stod(param.at("omega")), std::stod(param.at("Rcut")) ); } + else + { throw std::invalid_argument( "singularity_correction = " + param.at("singularity_correction") + " in " + std::string(__FILE__) + " line " + std::to_string(__LINE__) ); } + } + break; + } + default: + { + throw std::invalid_argument( std::string(__FILE__) + " line " + std::to_string(__LINE__) ); + } + } + } - const double dr = orbs.get_rab().back(); - const int Nr = (static_cast(orbs.getNr()*rmesh_times)) | 1; + const double dr = orbs.get_rab().back(); + const int Nr = (static_cast(orbs.getNr()*rmesh_times)) | 1; - std::vector rab(Nr); - for( size_t ir=0; ir rab(Nr); + for( size_t ir=0; ir r_radial(Nr); - for( size_t ir=0; ir r_radial(Nr); + for( size_t ir=0; ir Numerical_Orbital_Lm cal_orbs_ccp_spencer( @@ -251,16 +251,16 @@ namespace Conv_Coulomb_Pot_K } template<> - double get_rmesh_proportion( - const Numerical_Orbital_Lm &orbs, - const double psi_threshold) - { - for(int ir=orbs.getNr()-1; ir>=0; --ir) - { - if(std::abs(orbs.getPsi(ir))>=psi_threshold) - { return static_cast(ir)/orbs.getNr(); } - } - return 0.0; - } + double get_rmesh_proportion( + const Numerical_Orbital_Lm &orbs, + const double psi_threshold) + { + for(int ir=orbs.getNr()-1; ir>=0; --ir) + { + if(std::abs(orbs.getPsi(ir))>=psi_threshold) + { return static_cast(ir)/orbs.getNr(); } + } + return 0.0; + } } diff --git a/source/source_lcao/module_ri/conv_coulomb_pot_k.h b/source/source_lcao/module_ri/conv_coulomb_pot_k.h index bae445b6070..1b5657767c1 100644 --- a/source/source_lcao/module_ri/conv_coulomb_pot_k.h +++ b/source/source_lcao/module_ri/conv_coulomb_pot_k.h @@ -7,43 +7,43 @@ namespace Conv_Coulomb_Pot_K { - // Constrains the scalar cal_orbs_ccp/cal_orbs_ccp_spencer overloads below: - // icpc cannot order them against the recursive std::vector overloads and - // reports an ambiguity, so the scalar overload is disabled for vectors. - template struct is_std_vector : std::false_type {}; - template struct is_std_vector> : std::true_type {}; - - template extern typename std::enable_if::value, T>::type cal_orbs_ccp( - const T &orbs, - const CoulombParam &coulomb_param, - const double rmesh_times); - - template extern typename std::enable_if::value, T>::type cal_orbs_ccp_spencer( - const T &orbs, - const CoulombParam &coulomb_param, - const double rmesh_times); + // Constrains the scalar cal_orbs_ccp/cal_orbs_ccp_spencer overloads below: + // icpc cannot order them against the recursive std::vector overloads and + // reports an ambiguity, so the scalar overload is disabled for vectors. + template struct is_std_vector : std::false_type {}; + template struct is_std_vector> : std::true_type {}; + + template extern typename std::enable_if::value, T>::type cal_orbs_ccp( + const T &orbs, + const CoulombParam &coulomb_param, + const double rmesh_times); + + template extern typename std::enable_if::value, T>::type cal_orbs_ccp_spencer( + const T &orbs, + const CoulombParam &coulomb_param, + const double rmesh_times); //private: - template< typename T > extern double get_rmesh_proportion( - const T &orbs, - const double psi_threshold); + template< typename T > extern double get_rmesh_proportion( + const T &orbs, + const double psi_threshold); //private: - extern std::vector cal_psi_fock_limits( - const std::vector & psif); - extern std::vector cal_psi_fock_spencer( - const std::vector &psif, - const std::vector &k_radial, - const double rcut); - extern std::vector cal_psi_erfc_limits( - const std::vector & psif, - const std::vector & k_radial, - const double erfc_omega); - extern std::vector cal_psi_erfc_spencer( - const std::vector & psif, - const std::vector & k_radial, - const double erfc_omega, - const double rcut); + extern std::vector cal_psi_fock_limits( + const std::vector & psif); + extern std::vector cal_psi_fock_spencer( + const std::vector &psif, + const std::vector &k_radial, + const double rcut); + extern std::vector cal_psi_erfc_limits( + const std::vector & psif, + const std::vector & k_radial, + const double erfc_omega); + extern std::vector cal_psi_erfc_spencer( + const std::vector & psif, + const std::vector & k_radial, + const double erfc_omega, + const double rcut); } #include "conv_coulomb_pot_k.hpp" diff --git a/source/source_lcao/module_ri/conv_coulomb_pot_k.hpp b/source/source_lcao/module_ri/conv_coulomb_pot_k.hpp index bfd07fc17b2..1c1627f1fb3 100644 --- a/source/source_lcao/module_ri/conv_coulomb_pot_k.hpp +++ b/source/source_lcao/module_ri/conv_coulomb_pot_k.hpp @@ -9,59 +9,59 @@ namespace Conv_Coulomb_Pot_K { - template< typename T > - std::vector cal_orbs_ccp( - const std::vector & orbs, - const std::map>> &coulomb_param, - const double rmesh_times) - { - std::vector orbs_ccp(orbs.size()); - for( size_t i=0; i!=orbs.size(); ++i ) - orbs_ccp[i] = cal_orbs_ccp(orbs[i], coulomb_param, rmesh_times); - return orbs_ccp; - } + template< typename T > + std::vector cal_orbs_ccp( + const std::vector & orbs, + const std::map>> &coulomb_param, + const double rmesh_times) + { + std::vector orbs_ccp(orbs.size()); + for( size_t i=0; i!=orbs.size(); ++i ) + orbs_ccp[i] = cal_orbs_ccp(orbs[i], coulomb_param, rmesh_times); + return orbs_ccp; + } - template< typename T > - double get_rmesh_proportion( - const std::vector & orbs, - const double psi_threshold) - { - double rmesh_proportion=0; - for( const auto &orb : orbs ) - rmesh_proportion = std::max(rmesh_proportion, get_rmesh_proportion(orb,psi_threshold)); - return rmesh_proportion; - } + template< typename T > + double get_rmesh_proportion( + const std::vector & orbs, + const double psi_threshold) + { + double rmesh_proportion=0; + for( const auto &orb : orbs ) + rmesh_proportion = std::max(rmesh_proportion, get_rmesh_proportion(orb,psi_threshold)); + return rmesh_proportion; + } - template< typename T > - std::vector cal_orbs_ccp_spencer( - const std::vector & orbs, - const std::map>> &coulomb_param, - const double rmesh_times) - { - std::vector orbs_ccp(orbs.size()); - for( size_t i=0; i!=orbs.size(); ++i ) - orbs_ccp[i] = cal_orbs_ccp_spencer(orbs[i], coulomb_param, rmesh_times); - return orbs_ccp; - } + template< typename T > + std::vector cal_orbs_ccp_spencer( + const std::vector & orbs, + const std::map>> &coulomb_param, + const double rmesh_times) + { + std::vector orbs_ccp(orbs.size()); + for( size_t i=0; i!=orbs.size(); ++i ) + orbs_ccp[i] = cal_orbs_ccp_spencer(orbs[i], coulomb_param, rmesh_times); + return orbs_ccp; + } - // for cal_orbs_ccp() - template - std::vector operator*(const T &s, const std::vector &v_in) - { - std::vector v(v_in.size()); - for(std::size_t i=0; i - std::vector operator+ (const std::vector &v1, const std::vector &v2) - { - assert(v1.size()==v2.size()); - std::vector v(v1.size()); - for(std::size_t i=0; i + std::vector operator*(const T &s, const std::vector &v_in) + { + std::vector v(v_in.size()); + for(std::size_t i=0; i + std::vector operator+ (const std::vector &v1, const std::vector &v2) + { + assert(v1.size()==v2.size()); + std::vector v(v1.size()); + for(std::size_t i=0; i::get_singular_chi(const UnitCell& ucell, const std::vecto double chi = 0.0; for(const auto ¶m : param_list) - { + { if(param.at("singularity_correction") == "carrier") - { + { chi = Singular_Value::cal_carrier(ucell, this->kvec_c, qdiv, 100, 30, 1e-6, 3); } else if(param.at("singularity_correction") == "massidda") - { + { chi = Singular_Value::cal_massidda(ucell, this->nmp, qdiv, 1, 5, 1e-4); } else @@ -413,7 +413,7 @@ auto Ewald_Vq::set_Vq_dVq_gauss(const UnitCell& ucell, std::map> Vq_dVq_gauss_out; for(const auto ¶m_list : this->coulomb_param) - { + { std::complex alpha; for(const auto ¶m : param_list.second) { diff --git a/source/source_lcao/module_ri/exx_abfs.h b/source/source_lcao/module_ri/exx_abfs.h index 0c5c84f1628..be6101af4c8 100644 --- a/source/source_lcao/module_ri/exx_abfs.h +++ b/source/source_lcao/module_ri/exx_abfs.h @@ -11,13 +11,13 @@ using std::map; class Exx_Abfs { public: - class Jle; - class IO; - class Construct_Orbs; - class PCA; - - int rmesh_times = 5; // Peize Lin test - int kmesh_times = 1; // Peize Lin test + class Jle; + class IO; + class Construct_Orbs; + class PCA; + + int rmesh_times = 5; // Peize Lin test + int kmesh_times = 1; // Peize Lin test }; #endif diff --git a/source/source_lcao/module_ri/exx_abfs_ctor_orbs.cpp b/source/source_lcao/module_ri/exx_abfs_ctor_orbs.cpp index 2c23f35e02f..3efac4ff9cb 100644 --- a/source/source_lcao/module_ri/exx_abfs_ctor_orbs.cpp +++ b/source/source_lcao/module_ri/exx_abfs_ctor_orbs.cpp @@ -8,435 +8,435 @@ #include "source_lcao/module_ri/test_code/exx_abfs_ctor_orbs_test.h" // Peize Lin test std::vector>> Exx_Abfs::Construct_Orbs::change_orbs( - const LCAO_Orbitals &orbs_in, - const double kmesh_times ) + const LCAO_Orbitals &orbs_in, + const double kmesh_times ) { ModuleBase::TITLE("Exx_Abfs::Construct_Orbs::change_orbs"); - std::vector>> orbs; - orbs.resize( orbs_in.get_ntype() ); - for (int T = 0; T < orbs_in.get_ntype() ; T++) - { - orbs[T].resize( orbs_in.Phi[T].getLmax()+1 ); - for (int L=0; L <= orbs_in.Phi[T].getLmax() ; L++) - { - orbs[T][L].resize( orbs_in.Phi[T].getNchi(L) ); - for (int N = 0; N < orbs_in.Phi[T].getNchi(L); ++N) - { - const auto &orb_origin = orbs_in.Phi[T].PhiLN(L,N); - orbs[T][L][N].set_orbital_info( - orb_origin.getLabel(), - orb_origin.getType(), - orb_origin.getL(), - orb_origin.getChi(), - orb_origin.getNr(), - orb_origin.getRab(), - orb_origin.getRadial(), - Numerical_Orbital_Lm::Psi_Type::Psi, - orb_origin.getPsi(), - static_cast(orb_origin.getNk() * kmesh_times) | 1, // Nk must be odd - orb_origin.getDk(), // Peize Lin change 2017-04-16 + std::vector>> orbs; + orbs.resize( orbs_in.get_ntype() ); + for (int T = 0; T < orbs_in.get_ntype() ; T++) + { + orbs[T].resize( orbs_in.Phi[T].getLmax()+1 ); + for (int L=0; L <= orbs_in.Phi[T].getLmax() ; L++) + { + orbs[T][L].resize( orbs_in.Phi[T].getNchi(L) ); + for (int N = 0; N < orbs_in.Phi[T].getNchi(L); ++N) + { + const auto &orb_origin = orbs_in.Phi[T].PhiLN(L,N); + orbs[T][L][N].set_orbital_info( + orb_origin.getLabel(), + orb_origin.getType(), + orb_origin.getL(), + orb_origin.getChi(), + orb_origin.getNr(), + orb_origin.getRab(), + orb_origin.getRadial(), + Numerical_Orbital_Lm::Psi_Type::Psi, + orb_origin.getPsi(), + static_cast(orb_origin.getNk() * kmesh_times) | 1, // Nk must be odd + orb_origin.getDk(), // Peize Lin change 2017-04-16 // orb_origin.getDk() / kmesh_times, - orb_origin.getDruniform(), - false, - true, PARAM.inp.cal_force); - } - } - } - - Exx_Abfs::Construct_Orbs::filter_empty_orbs(orbs); - return orbs; + orb_origin.getDruniform(), + false, + true, PARAM.inp.cal_force); + } + } + } + + Exx_Abfs::Construct_Orbs::filter_empty_orbs(orbs); + return orbs; } std::vector>> Exx_Abfs::Construct_Orbs::change_orbs( - const std::vector>> &orbs_in, - const double kmesh_times ) + const std::vector>> &orbs_in, + const double kmesh_times ) { - ModuleBase::TITLE("Exx_Abfs::Construct_Orbs::change_orbs"); - return orbital( get_psi(orbs_in), orbs_in, kmesh_times ); + ModuleBase::TITLE("Exx_Abfs::Construct_Orbs::change_orbs"); + return orbital( get_psi(orbs_in), orbs_in, kmesh_times ); } // P = u/r * Y /* template std::vector>> Exx_Abfs::Construct_Orbs::abfs_same_atom( - const Orbs_Type &orbs, - const double kmesh_times, - const double norm_threshold ) + const Orbs_Type &orbs, + const double kmesh_times, + const double norm_threshold ) { - const std::vector>>> - abfs_same_atom_psir = psir_mult_psir( orbs ); - const std::vector>>> - abfs_same_atom_psir_orth = orth( abfs_same_atom_psir, orbs, norm_threshold ); - const std::vector>>> - abfs_same_atom_psi_orth = div_r( abfs_same_atom_psir_orth, orbs.get_r_radial ); - const std::vector>> - abfs_same_atom = orbital( abfs_same_atom_psi_orth, orbs, kmesh_times ); - return abfs_same_atom; + const std::vector>>> + abfs_same_atom_psir = psir_mult_psir( orbs ); + const std::vector>>> + abfs_same_atom_psir_orth = orth( abfs_same_atom_psir, orbs, norm_threshold ); + const std::vector>>> + abfs_same_atom_psi_orth = div_r( abfs_same_atom_psir_orth, orbs.get_r_radial ); + const std::vector>> + abfs_same_atom = orbital( abfs_same_atom_psi_orth, orbs, kmesh_times ); + return abfs_same_atom; } */ // P = f * Y std::vector>> Exx_Abfs::Construct_Orbs::abfs_same_atom( - const UnitCell &ucell, + const UnitCell &ucell, const LCAO_Orbitals& orb, - const std::vector>> &orbs, - const double kmesh_times_mot, - const double times_threshold ) + const std::vector>> &orbs, + const double kmesh_times_mot, + const double times_threshold ) { - ModuleBase::TITLE("Exx_Abfs::Construct_Orbs::abfs_same_atom"); - if(times_threshold>1) - { return std::vector>>(orb.get_ntype()); } - - const std::vector>>> - abfs_same_atom_psi = psi_mult_psi( orbs ); - - const std::vector>>> - abfs_same_atom_orth_psi = orth( abfs_same_atom_psi, orbs ); - const std::vector>> - abfs_same_atom = orbital( abfs_same_atom_orth_psi, orbs, 1 ); - - #if TEST_EXX_LCAO==1 - print_orbs(abfs_same_atom_psi,"abfs_same_atom_psi.dat"); - print_orbs(abfs_same_atom_orth_psi,"abfs_same_atom_orth_psi.dat"); - #elif TEST_EXX_LCAO==-1 - #error "TEST_EXX_LCAO" - #endif - - const std::vector>>> - abfs_same_atom_pca_psi = pca(ucell,orb, abfs_same_atom, orbs, kmesh_times_mot, times_threshold ); - - #if TEST_EXX_LCAO==1 - print_orbs(abfs_same_atom_pca_psi,"abfs_same_atom_pca_psi.dat"); - #elif TEST_EXX_LCAO==-1 - #error "TEST_EXX_LCAO" - #endif + ModuleBase::TITLE("Exx_Abfs::Construct_Orbs::abfs_same_atom"); + if(times_threshold>1) + { return std::vector>>(orb.get_ntype()); } + + const std::vector>>> + abfs_same_atom_psi = psi_mult_psi( orbs ); + const std::vector>>> + abfs_same_atom_orth_psi = orth( abfs_same_atom_psi, orbs ); const std::vector>> - abfs_same_atom_pca = orbital( abfs_same_atom_pca_psi, orbs, 1 ); + abfs_same_atom = orbital( abfs_same_atom_orth_psi, orbs, 1 ); + + #if TEST_EXX_LCAO==1 + print_orbs(abfs_same_atom_psi,"abfs_same_atom_psi.dat"); + print_orbs(abfs_same_atom_orth_psi,"abfs_same_atom_orth_psi.dat"); + #elif TEST_EXX_LCAO==-1 + #error "TEST_EXX_LCAO" + #endif + + const std::vector>>> + abfs_same_atom_pca_psi = pca(ucell,orb, abfs_same_atom, orbs, kmesh_times_mot, times_threshold ); + + #if TEST_EXX_LCAO==1 + print_orbs(abfs_same_atom_pca_psi,"abfs_same_atom_pca_psi.dat"); + #elif TEST_EXX_LCAO==-1 + #error "TEST_EXX_LCAO" + #endif + + const std::vector>> + abfs_same_atom_pca = orbital( abfs_same_atom_pca_psi, orbs, 1 ); return abfs_same_atom_pca; } /* template<> std::vector>>> Exx_Abfs::Construct_Orbs::psi_mult_psi( - const LCAO_Orbitals &orbs ) + const LCAO_Orbitals &orbs ) { - std::vector>>> psi_mult_psi( orbs.get_ntype() ); - for( int T=0; T!=orbs.get_ntype(); ++T ) - { - psi_mult_psi[T].resize( 2*orbs.Phi[T].getLmax()+1 ); - for( int L1=0; L1<=orbs.Phi[T].getLmax(); ++L1 ) - { - for( int N1=0; N1!=orbs.Phi[T].getNchi(L1); ++N1 ) - { - for( int L2=L1; L2<=orbs.Phi[T].getLmax(); ++L2 ) - { - for( int N2=((L2==L1)?N1:0); N2!=orbs.Phi[T].getNchi(L2); ++N2 ) - { - assert( orbs.Phi[T].PhiLN(L1,N1).getNr()==orbs.Phi[T].PhiLN(L2,N2).getNr() ); - - std::vector mult_psir( orbs.Phi[T].PhiLN(L1,N1).getNr() ); - for( int ir=0; ir!=orbs.Phi[T].PhiLN(L1,N1).getNr(); ++ir) - { - mult_psir[ir] = orbs.Phi[T].PhiLN(L1,N1).getPsi(ir) * orbs.Phi[T].PhiLN(L2,N2).getPsi(ir) ; - } - for( int L_new=std::abs(L2-L1); L_new<=L1+L2; ++L_new ) - { - psi_mult_psi[T][L_new].push_back(mult_psir); - } - } - } - } - } - } - return psi_mult_psi; + std::vector>>> psi_mult_psi( orbs.get_ntype() ); + for( int T=0; T!=orbs.get_ntype(); ++T ) + { + psi_mult_psi[T].resize( 2*orbs.Phi[T].getLmax()+1 ); + for( int L1=0; L1<=orbs.Phi[T].getLmax(); ++L1 ) + { + for( int N1=0; N1!=orbs.Phi[T].getNchi(L1); ++N1 ) + { + for( int L2=L1; L2<=orbs.Phi[T].getLmax(); ++L2 ) + { + for( int N2=((L2==L1)?N1:0); N2!=orbs.Phi[T].getNchi(L2); ++N2 ) + { + assert( orbs.Phi[T].PhiLN(L1,N1).getNr()==orbs.Phi[T].PhiLN(L2,N2).getNr() ); + + std::vector mult_psir( orbs.Phi[T].PhiLN(L1,N1).getNr() ); + for( int ir=0; ir!=orbs.Phi[T].PhiLN(L1,N1).getNr(); ++ir) + { + mult_psir[ir] = orbs.Phi[T].PhiLN(L1,N1).getPsi(ir) * orbs.Phi[T].PhiLN(L2,N2).getPsi(ir) ; + } + for( int L_new=std::abs(L2-L1); L_new<=L1+L2; ++L_new ) + { + psi_mult_psi[T][L_new].push_back(mult_psir); + } + } + } + } + } + } + return psi_mult_psi; } */ std::vector>>> Exx_Abfs::Construct_Orbs::psi_mult_psi( - const std::vector>> &orbs ) + const std::vector>> &orbs ) { - std::vector>>> psi_mult_psi( orbs.size() ); - for( int T=0; T!=orbs.size(); ++T ) - { - psi_mult_psi[T].resize( 2*orbs[T].size()-1 ); - for( int L1=0; L1!=orbs[T].size(); ++L1 ) - { - for( int N1=0; N1!=orbs[T][L1].size(); ++N1 ) - { - for( int L2=L1; L2!=orbs[T].size(); ++L2 ) - { - for( int N2=((L2==L1)?N1:0); N2!=orbs[T][L2].size(); ++N2 ) - { - assert( orbs[T][L1][N1].getNr()==orbs[T][L2][N2].getNr() ); - - std::vector mult_psir( orbs[T][L1][N1].getNr() ); - for( int ir=0; ir!=orbs[T][L1][N1].getNr(); ++ir) - { - mult_psir[ir] = orbs[T][L1][N1].getPsi(ir) * orbs[T][L2][N2].getPsi(ir) ; - } - for( int L_new=std::abs(L1-L2); L_new<=L1+L2; ++L_new ) - { - psi_mult_psi[T][L_new].push_back(mult_psir); - } - } - } - } - } - } - return psi_mult_psi; + std::vector>>> psi_mult_psi( orbs.size() ); + for( int T=0; T!=orbs.size(); ++T ) + { + psi_mult_psi[T].resize( 2*orbs[T].size()-1 ); + for( int L1=0; L1!=orbs[T].size(); ++L1 ) + { + for( int N1=0; N1!=orbs[T][L1].size(); ++N1 ) + { + for( int L2=L1; L2!=orbs[T].size(); ++L2 ) + { + for( int N2=((L2==L1)?N1:0); N2!=orbs[T][L2].size(); ++N2 ) + { + assert( orbs[T][L1][N1].getNr()==orbs[T][L2][N2].getNr() ); + + std::vector mult_psir( orbs[T][L1][N1].getNr() ); + for( int ir=0; ir!=orbs[T][L1][N1].getNr(); ++ir) + { + mult_psir[ir] = orbs[T][L1][N1].getPsi(ir) * orbs[T][L2][N2].getPsi(ir) ; + } + for( int L_new=std::abs(L1-L2); L_new<=L1+L2; ++L_new ) + { + psi_mult_psi[T][L_new].push_back(mult_psir); + } + } + } + } + } + } + return psi_mult_psi; } /* template<> std::vector>>> Exx_Abfs::Construct_Orbs::psir_mult_psir( - const LCAO_Orbitals &orbs ) + const LCAO_Orbitals &orbs ) { - std::vector>>> psir_mult_psir( orbs.get_ntype() ); - for( int T=0; T!=orbs.get_ntype(); ++T ) - { - psir_mult_psir[T].resize( 2*orbs.Phi[T].getLmax()+1 ); - for( int L1=0; L1<=orbs.Phi[T].getLmax(); ++L1 ) - { - for( int N1=0; N1!=orbs.Phi[T].getNchi(L1); ++N1 ) - { - for( int L2=L1; L2<=orbs.Phi[T].getLmax(); ++L2 ) - { - for( int N2=((L2==L1)?N1:0); N2!=orbs.Phi[T].getNchi(L2); ++N2 ) - { - assert( orbs.Phi[T].PhiLN(L1,N1).getNr()==orbs.Phi[T].PhiLN(L2,N2).getNr() ); - - std::vector mult_psir( orbs.Phi[T].PhiLN(L1,N1).getNr() ); - for( int ir=0; ir!=orbs.Phi[T].PhiLN(L1,N1).getNr(); ++ir) - { - mult_psir[ir] = orbs.Phi[T].PhiLN(L1,N1).getPsi_r(ir) * orbs.Phi[T].PhiLN(L2,N2).getPsi_r(ir) ; - } - for( int L_new=std::abs(L1-L2); L_new<=L1+L2; ++L_new ) - { - psir_mult_psir[T][L_new].push_back(mult_psir); - } - } - } - } - } - } - return psir_mult_psir; + std::vector>>> psir_mult_psir( orbs.get_ntype() ); + for( int T=0; T!=orbs.get_ntype(); ++T ) + { + psir_mult_psir[T].resize( 2*orbs.Phi[T].getLmax()+1 ); + for( int L1=0; L1<=orbs.Phi[T].getLmax(); ++L1 ) + { + for( int N1=0; N1!=orbs.Phi[T].getNchi(L1); ++N1 ) + { + for( int L2=L1; L2<=orbs.Phi[T].getLmax(); ++L2 ) + { + for( int N2=((L2==L1)?N1:0); N2!=orbs.Phi[T].getNchi(L2); ++N2 ) + { + assert( orbs.Phi[T].PhiLN(L1,N1).getNr()==orbs.Phi[T].PhiLN(L2,N2).getNr() ); + + std::vector mult_psir( orbs.Phi[T].PhiLN(L1,N1).getNr() ); + for( int ir=0; ir!=orbs.Phi[T].PhiLN(L1,N1).getNr(); ++ir) + { + mult_psir[ir] = orbs.Phi[T].PhiLN(L1,N1).getPsi_r(ir) * orbs.Phi[T].PhiLN(L2,N2).getPsi_r(ir) ; + } + for( int L_new=std::abs(L1-L2); L_new<=L1+L2; ++L_new ) + { + psir_mult_psir[T][L_new].push_back(mult_psir); + } + } + } + } + } + } + return psir_mult_psir; } */ std::vector>>> Exx_Abfs::Construct_Orbs::psir_mult_psir( - const std::vector>> &orbs ) + const std::vector>> &orbs ) { - std::vector>>> psir_mult_psir( orbs.size() ); - for( int T=0; T!=orbs.size(); ++T ) - { - psir_mult_psir[T].resize( 2*orbs[T].size()-1 ); - for( int L1=0; L1!=orbs[T].size(); ++L1 ) - { - for( int N1=0; N1!=orbs[T][L1].size(); ++N1 ) - { - for( int L2=L1; L2!=orbs[T].size(); ++L2 ) - { - for( int N2=((L2==L1)?N1:0); N2!=orbs[T][L2].size(); ++N2 ) - { - assert( orbs[T][L1][N1].getNr()==orbs[T][L2][N2].getNr() ); - - std::vector mult_psir( orbs[T][L1][N1].getNr() ); - for( int ir=0; ir!=orbs[T][L1][N1].getNr(); ++ir) - { - mult_psir[ir] = orbs[T][L1][N1].getPsi_r(ir) * orbs[T][L2][N2].getPsi_r(ir) ; - } - for( int L_new=std::abs(L1-L2); L_new<=L1+L2; ++L_new ) - { - psir_mult_psir[T][L_new].push_back(mult_psir); - } - } - } - } - } - } - return psir_mult_psir; + std::vector>>> psir_mult_psir( orbs.size() ); + for( int T=0; T!=orbs.size(); ++T ) + { + psir_mult_psir[T].resize( 2*orbs[T].size()-1 ); + for( int L1=0; L1!=orbs[T].size(); ++L1 ) + { + for( int N1=0; N1!=orbs[T][L1].size(); ++N1 ) + { + for( int L2=L1; L2!=orbs[T].size(); ++L2 ) + { + for( int N2=((L2==L1)?N1:0); N2!=orbs[T][L2].size(); ++N2 ) + { + assert( orbs[T][L1][N1].getNr()==orbs[T][L2][N2].getNr() ); + + std::vector mult_psir( orbs[T][L1][N1].getNr() ); + for( int ir=0; ir!=orbs[T][L1][N1].getNr(); ++ir) + { + mult_psir[ir] = orbs[T][L1][N1].getPsi_r(ir) * orbs[T][L2][N2].getPsi_r(ir) ; + } + for( int L_new=std::abs(L1-L2); L_new<=L1+L2; ++L_new ) + { + psir_mult_psir[T][L_new].push_back(mult_psir); + } + } + } + } + } + } + return psir_mult_psir; } std::vector>>> Exx_Abfs::Construct_Orbs::pca( - const UnitCell &ucell, + const UnitCell &ucell, const LCAO_Orbitals& orb, - const std::vector>> &abfs, - const std::vector>> &orbs, - const double kmesh_times_mot, - const double times_threshold ) + const std::vector>> &abfs, + const std::vector>> &orbs, + const double kmesh_times_mot, + const double times_threshold ) { - if(times_threshold>1) - return std::vector>>>(abfs.size()); + if(times_threshold>1) + return std::vector>>>(abfs.size()); - const std::vector,RI::Tensor>>> - eig = ABFs_Construct::PCA::cal_PCA(ucell, orb, orbs, abfs, kmesh_times_mot ); + const std::vector,RI::Tensor>>> + eig = ABFs_Construct::PCA::cal_PCA(ucell, orb, orbs, abfs, kmesh_times_mot ); - const std::vector>>> psis = get_psi( abfs ); - std::vector>>> psis_new( psis.size() ); + const std::vector>>> psis = get_psi( abfs ); + std::vector>>> psis_new( psis.size() ); - for( size_t T=0; T!=eig.size(); ++T ) - { - double eig_value_max = 0; - for( size_t L=0; L!=eig[T].size(); ++L ) - for( size_t M=0; M!=eig[T][L].first.size(); ++M ) - { + for( size_t T=0; T!=eig.size(); ++T ) + { + double eig_value_max = 0; + for( size_t L=0; L!=eig[T].size(); ++L ) + for( size_t M=0; M!=eig[T][L].first.size(); ++M ) + { //ofs< &eig_value = eig[T][L].first; - const RI::Tensor &eig_vec = eig[T][L].second; - for( size_t M=0; M!=eig_value.size(); ++M ) - { - if( eig_value[M] > eig_value_threshold ) - { - std::vector psi_new( psis[T][L][0].size() ); - for( size_t N=0; N!=psis[T][L].size(); ++N ) - for( size_t ir=0; ir!=psi_new.size(); ++ir ) - psi_new[ir] += eig_vec(M,N) * psis[T][L][N][ir]; - psis_new[T][L].push_back( psi_new ); - } - } - } - } - else - { - ModuleBase::WARNING(std::string(__FILE__), - "Element "+ModuleBase::GlobalFunc::TO_STRING(T)+" , all training data (lcao[i]*lcao[j]) are all the same. So PCA randomly choose an abf as the result."); - psis_new[T].resize( psis[T].size() ); - for( size_t L=0; L!=psis[T].size(); ++L ) - if( !psis[T][L].empty() ) - { - psis_new[T][L].push_back(psis[T][L][0]); - break; - } - } - } + if(eig_value_max) + { + psis_new[T].resize( psis[T].size() ); + for( size_t L=0; L!=eig[T].size(); ++L ) + { + const std::vector &eig_value = eig[T][L].first; + const RI::Tensor &eig_vec = eig[T][L].second; + for( size_t M=0; M!=eig_value.size(); ++M ) + { + if( eig_value[M] > eig_value_threshold ) + { + std::vector psi_new( psis[T][L][0].size() ); + for( size_t N=0; N!=psis[T][L].size(); ++N ) + for( size_t ir=0; ir!=psi_new.size(); ++ir ) + psi_new[ir] += eig_vec(M,N) * psis[T][L][N][ir]; + psis_new[T][L].push_back( psi_new ); + } + } + } + } + else + { + ModuleBase::WARNING(std::string(__FILE__), + "Element "+ModuleBase::GlobalFunc::TO_STRING(T)+" , all training data (lcao[i]*lcao[j]) are all the same. So PCA randomly choose an abf as the result."); + psis_new[T].resize( psis[T].size() ); + for( size_t L=0; L!=psis[T].size(); ++L ) + if( !psis[T][L].empty() ) + { + psis_new[T][L].push_back(psis[T][L][0]); + break; + } + } + } //ofs.close(); - return psis_new; + return psis_new; } std::vector>>> Exx_Abfs::Construct_Orbs::orth( - const std::vector>>> &psis, - const std::vector>> &orbs, - const double norm_threshold ) + const std::vector>>> &psis, + const std::vector>> &orbs, + const double norm_threshold ) { - std::vector>>> psis_orth( psis.size() ); - for( int T=0; T!=psis.size(); ++T ) - { - const Numerical_Orbital_Lm &orb = orbs[T][0][0]; - ModuleBase::Gram_Schmidt_Orth gso( - orb.get_rab(), - ModuleBase::Gram_Schmidt_Orth::Coordinate::Sphere ); - psis_orth[T].resize( psis[T].size() ); - for( int L=0; L!=psis[T].size(); ++L ) - { - psis_orth[T][L] = gso.cal_orth( psis[T][L], norm_threshold ); // Peize Lin test 2016-10-08 + std::vector>>> psis_orth( psis.size() ); + for( int T=0; T!=psis.size(); ++T ) + { + const Numerical_Orbital_Lm &orb = orbs[T][0][0]; + ModuleBase::Gram_Schmidt_Orth gso( + orb.get_rab(), + ModuleBase::Gram_Schmidt_Orth::Coordinate::Sphere ); + psis_orth[T].resize( psis[T].size() ); + for( int L=0; L!=psis[T].size(); ++L ) + { + psis_orth[T][L] = gso.cal_orth( psis[T][L], norm_threshold ); // Peize Lin test 2016-10-08 // psis_orth[T][L] = gso.cal_orth( psis[T][L] ); // Peize Lin test 2016-10-08 - } - } - return psis_orth; + } + } + return psis_orth; } std::vector>>> Exx_Abfs::Construct_Orbs::div_r( - const std::vector>>> &psirs, - const std::vector &r_radial ) + const std::vector>>> &psirs, + const std::vector &r_radial ) { - std::vector>>> psis( psirs.size() ); - for( auto T=0; T!=psirs.size(); ++T ) - { - psis[T].resize( psirs[T].size() ); - for( auto L=0; L!=psirs[T].size(); ++L ) - { - psis[T][L].resize( psirs[T][L].size() ); - for( auto N=0; N!=psirs[T][L].size(); ++N ) - { - psis[T][L][N].resize( psirs[T][L][N].size() ); - psis[T][L][N][0] = 0; - for( auto ir=1; ir!=psirs[T][L][N].size(); ++ir ) - { - psis[T][L][N][ir] = psirs[T][L][N][ir] / r_radial[ir]; - } - } - } - } - return psis; + std::vector>>> psis( psirs.size() ); + for( auto T=0; T!=psirs.size(); ++T ) + { + psis[T].resize( psirs[T].size() ); + for( auto L=0; L!=psirs[T].size(); ++L ) + { + psis[T][L].resize( psirs[T][L].size() ); + for( auto N=0; N!=psirs[T][L].size(); ++N ) + { + psis[T][L][N].resize( psirs[T][L][N].size() ); + psis[T][L][N][0] = 0; + for( auto ir=1; ir!=psirs[T][L][N].size(); ++ir ) + { + psis[T][L][N][ir] = psirs[T][L][N][ir] / r_radial[ir]; + } + } + } + } + return psis; } std::vector>>> Exx_Abfs::Construct_Orbs::get_psi( - const std::vector>> &orbs ) + const std::vector>> &orbs ) { - std::vector>>> orbs_psi( orbs.size() ); - for( int T=0; T!=orbs.size(); ++T ) - { - orbs_psi[T].resize( orbs[T].size() ); - for( int L=0; L!=orbs[T].size(); ++L ) - { - orbs_psi[T][L].resize( orbs[T][L].size() ); - for( int N=0; N!=orbs[T][L].size(); ++N ) - { - orbs_psi[T][L][N] = orbs[T][L][N].get_psi(); - } - } - } - return orbs_psi; + std::vector>>> orbs_psi( orbs.size() ); + for( int T=0; T!=orbs.size(); ++T ) + { + orbs_psi[T].resize( orbs[T].size() ); + for( int L=0; L!=orbs[T].size(); ++L ) + { + orbs_psi[T][L].resize( orbs[T][L].size() ); + for( int N=0; N!=orbs[T][L].size(); ++N ) + { + orbs_psi[T][L][N] = orbs[T][L][N].get_psi(); + } + } + } + return orbs_psi; } std::vector>> Exx_Abfs::Construct_Orbs::orbital( - const std::vector>>> &psis, - const std::vector>> &orbs_info, - const double kmesh_times) + const std::vector>>> &psis, + const std::vector>> &orbs_info, + const double kmesh_times) { - std::vector>> orbs_new( psis.size() ); - for( int T=0; T!=psis.size(); ++T ) - { - const Numerical_Orbital_Lm &orb_info = orbs_info[T][0][0]; - orbs_new[T].resize( psis[T].size() ); - for( int L=0; L!=psis[T].size(); ++L ) - { - orbs_new[T][L].resize( psis[T][L].size() ); - for( int N=0; N!=psis[T][L].size(); ++N ) - { - orbs_new[T][L][N].set_orbital_info( - orb_info.getLabel(), - T, - L, - N, - orb_info.getNr(), - orb_info.getRab(), - orb_info.getRadial(), - Numerical_Orbital_Lm::Psi_Type::Psi, - ModuleBase::GlobalFunc::VECTOR_TO_PTR(psis[T][L][N]), - static_cast(orb_info.getNk() * kmesh_times) | 1, // Nk must be odd - orb_info.getDk(), // Peize Lin test 2017-04-16 + std::vector>> orbs_new( psis.size() ); + for( int T=0; T!=psis.size(); ++T ) + { + const Numerical_Orbital_Lm &orb_info = orbs_info[T][0][0]; + orbs_new[T].resize( psis[T].size() ); + for( int L=0; L!=psis[T].size(); ++L ) + { + orbs_new[T][L].resize( psis[T][L].size() ); + for( int N=0; N!=psis[T][L].size(); ++N ) + { + orbs_new[T][L][N].set_orbital_info( + orb_info.getLabel(), + T, + L, + N, + orb_info.getNr(), + orb_info.getRab(), + orb_info.getRadial(), + Numerical_Orbital_Lm::Psi_Type::Psi, + ModuleBase::GlobalFunc::VECTOR_TO_PTR(psis[T][L][N]), + static_cast(orb_info.getNk() * kmesh_times) | 1, // Nk must be odd + orb_info.getDk(), // Peize Lin test 2017-04-16 // orb_info.getDk() / kmesh_times, - orb_info.getDruniform(), - false, - true, PARAM.inp.cal_force); - } - } - } - return orbs_new; + orb_info.getDruniform(), + false, + true, PARAM.inp.cal_force); + } + } + } + return orbs_new; } /* std::vector>>> Exx_Abfs::Construct_Orbs::get_psi( - const LCAO_Orbitals &orbs ) + const LCAO_Orbitals &orbs ) { - std::vector>>> orbs_psi( orbs.get_ntype() ); - for( int T=0; T!=orbs.get_ntype(); ++T ) + std::vector>>> orbs_psi( orbs.get_ntype() ); + for( int T=0; T!=orbs.get_ntype(); ++T ) { orbs_psi[T].resize( orbs.Phi[T].getLmax()+1 ); for( int L=0; L<=orbs.Phi[T].getLmax(); ++L ) @@ -473,25 +473,25 @@ inline const Numerical_Orbital_Lm &Exx_Abfs::Construct_Orbs::get_orbital( */ void Exx_Abfs::Construct_Orbs::print_orbs_size( - const UnitCell& ucell, - const std::vector>> &orbs, - std::ostream &os) + const UnitCell& ucell, + const std::vector>> &orbs, + std::ostream &os) { - os<<" Auxiliary basis functions"< L_labels = {'s', 'p', 'd'}; - for(std::size_t T=0; T L_labels = {'s', 'p', 'd'}; + for(std::size_t T=0; T>> Exx_Abfs::Construct_Orbs::get_multipole( @@ -544,14 +544,14 @@ std::vector Exx_Abfs::Construct_Orbs::get_Rcut(const std::vector>> &orbs) { - for (int T=0; T=0 ; --L) - { - if (orbs[T][L].size()>0) - { break; } - else - { orbs[T].resize(L); } - } - } + for (int T=0; T=0 ; --L) + { + if (orbs[T][L].size()>0) + { break; } + else + { orbs[T].resize(L); } + } + } } diff --git a/source/source_lcao/module_ri/exx_abfs_ctor_orbs.h b/source/source_lcao/module_ri/exx_abfs_ctor_orbs.h index 5981e6704f6..f72c6830a1c 100644 --- a/source/source_lcao/module_ri/exx_abfs_ctor_orbs.h +++ b/source/source_lcao/module_ri/exx_abfs_ctor_orbs.h @@ -13,90 +13,90 @@ class LCAO_Orbitals; class Exx_Abfs::Construct_Orbs { public: - static std::vector>> change_orbs( - const LCAO_Orbitals &orb_in, - const double kmesh_times ); - static std::vector>> change_orbs( - const std::vector>> &orb_in, - const double kmesh_times ); + static std::vector>> change_orbs( + const LCAO_Orbitals &orb_in, + const double kmesh_times ); + static std::vector>> change_orbs( + const std::vector>> &orb_in, + const double kmesh_times ); - static std::vector>> abfs_same_atom( - const UnitCell &ucell, - const LCAO_Orbitals& orb, - const std::vector>> &lcaos, - const double kmesh_times_mot, - const double times_threshold=0); - - static void print_orbs_size( - const UnitCell& ucell, - const std::vector>> &orbs, - std::ostream &os); + static std::vector>> abfs_same_atom( + const UnitCell &ucell, + const LCAO_Orbitals& orb, + const std::vector>> &lcaos, + const double kmesh_times_mot, + const double times_threshold=0); + + static void print_orbs_size( + const UnitCell& ucell, + const std::vector>> &orbs, + std::ostream &os); - // get the max number of orbitals among all elements - // static int get_nmax_total(const - // std::vector>> &orb_in); get - // number of orbitals for each element static std::map - // get_nw(const std::vector>> - // &orb_in); + // get the max number of orbitals among all elements + // static int get_nmax_total(const + // std::vector>> &orb_in); get + // number of orbitals for each element static std::map + // get_nw(const std::vector>> + // &orb_in); - // get multipole of orbitals for each element and angular moment - static std::vector>> get_multipole( - const std::vector>> &orb_in); + // get multipole of orbitals for each element and angular moment + static std::vector>> get_multipole( + const std::vector>> &orb_in); - static std::vector get_Rcut( - const std::vector>> &orb_in); - static inline double get_Rmax(const std::vector& rcut) - { - return *std::max_element(rcut.begin(), rcut.end()); - } - static inline double get_Rmax( - const std::vector>> &orb_in) - { - std::vector rcut = get_Rcut(orb_in); - return get_Rmax(rcut); - } - template - static int get_Lmax(const std::vector> &orb) - { - return max_element(orb.begin(), orb.end(), - [](const std::vector &orb_A, const std::vector &orb_B){ return orb_A.size() < orb_B.size(); }) - ->size() - 1; - } + static std::vector get_Rcut( + const std::vector>> &orb_in); + static inline double get_Rmax(const std::vector& rcut) + { + return *std::max_element(rcut.begin(), rcut.end()); + } + static inline double get_Rmax( + const std::vector>> &orb_in) + { + std::vector rcut = get_Rcut(orb_in); + return get_Rmax(rcut); + } + template + static int get_Lmax(const std::vector> &orb) + { + return max_element(orb.begin(), orb.end(), + [](const std::vector &orb_A, const std::vector &orb_B){ return orb_A.size() < orb_B.size(); }) + ->size() - 1; + } - static void filter_empty_orbs( - std::vector>> &orbs); + static void filter_empty_orbs( + std::vector>> &orbs); private: - static std::vector>>> psi_mult_psi( - const std::vector>> &lcaos ); - - static std::vector>>> psir_mult_psir( - const std::vector>> &lcaos ); - - static std::vector>>> orth( - const std::vector>>> &psis, - const std::vector>> &lcaos, - const double norm_threshold = std::numeric_limits::min() ); + static std::vector>>> psi_mult_psi( + const std::vector>> &lcaos ); + + static std::vector>>> psir_mult_psir( + const std::vector>> &lcaos ); + + static std::vector>>> orth( + const std::vector>>> &psis, + const std::vector>> &lcaos, + const double norm_threshold = std::numeric_limits::min() ); - static std::vector>>> pca( - const UnitCell &ucell, - const LCAO_Orbitals& orb, - const std::vector>> &abfs, - const std::vector>> &orbs, - const double kmesh_times_mot, - const double times_threshold ); - - static std::vector>>> div_r( - const std::vector>>> &psirs, - const std::vector &r_radial ); - - static std::vector>> orbital( - const std::vector>>> &psis, - const std::vector>> &orbs_info, - const double kmesh_times); - - static std::vector>>> get_psi( - const std::vector>> &orbs ); + static std::vector>>> pca( + const UnitCell &ucell, + const LCAO_Orbitals& orb, + const std::vector>> &abfs, + const std::vector>> &orbs, + const double kmesh_times_mot, + const double times_threshold ); + + static std::vector>>> div_r( + const std::vector>>> &psirs, + const std::vector &r_radial ); + + static std::vector>> orbital( + const std::vector>>> &psis, + const std::vector>> &orbs_info, + const double kmesh_times); + + static std::vector>>> get_psi( + const std::vector>> &orbs ); }; #endif // EXX_ABFS_IO_ASA_H diff --git a/source/source_lcao/module_ri/exx_abfs_io.cpp b/source/source_lcao/module_ri/exx_abfs_io.cpp index 0c959dac6d8..0a525c1cfe7 100644 --- a/source/source_lcao/module_ri/exx_abfs_io.cpp +++ b/source/source_lcao/module_ri/exx_abfs_io.cpp @@ -10,250 +10,250 @@ std::vector>> Exx_Abfs::IO::construct_abfs( - const LCAO_Orbitals &orbs, - const std::vector &files_abfs, - const double kmesh_times ) + const LCAO_Orbitals &orbs, + const std::vector &files_abfs, + const double kmesh_times ) { - ModuleBase::TITLE("Exx_Abfs::IO::construct_abfs"); - std::vector>> abfs( files_abfs.size() ); - for( size_t T=0; T!=files_abfs.size(); ++T ) - abfs[T] = construct_abfs_T( - files_abfs[T], - T, - static_cast(orbs.get_kmesh() * kmesh_times) | 1, // Nk must be odd + ModuleBase::TITLE("Exx_Abfs::IO::construct_abfs"); + std::vector>> abfs( files_abfs.size() ); + for( size_t T=0; T!=files_abfs.size(); ++T ) + abfs[T] = construct_abfs_T( + files_abfs[T], + T, + static_cast(orbs.get_kmesh() * kmesh_times) | 1, // Nk must be odd // orbs.get_dk() / kmesh_times, - orbs.get_dk(), // Peize Lin change 2017-04-16 - orbs.get_dr_uniform() ); - - return abfs; + orbs.get_dk(), // Peize Lin change 2017-04-16 + orbs.get_dr_uniform() ); + + return abfs; } std::vector>> Exx_Abfs::IO::construct_abfs( - const std::vector>> & abfs_pre, - const LCAO_Orbitals &orbs, - const std::vector &files_abfs, - const double kmesh_times ) + const std::vector>> & abfs_pre, + const LCAO_Orbitals &orbs, + const std::vector &files_abfs, + const double kmesh_times ) { - std::vector>> - abfs = construct_abfs( orbs, files_abfs, kmesh_times ); - - assert( abfs.size() == abfs_pre.size() ); - for( size_t T=0; T!=abfs.size(); ++T ) - { - if( abfs[T].size() < abfs_pre[T].size() ) - abfs[T].resize( abfs_pre[T].size() ); - for( size_t L=0; L!=abfs_pre[T].size(); ++L ) - { - abfs[T][L].insert( abfs[T][L].begin(), abfs_pre[T][L].begin(), abfs_pre[T][L].end() ); - } - } - - return abfs; + std::vector>> + abfs = construct_abfs( orbs, files_abfs, kmesh_times ); + + assert( abfs.size() == abfs_pre.size() ); + for( size_t T=0; T!=abfs.size(); ++T ) + { + if( abfs[T].size() < abfs_pre[T].size() ) + abfs[T].resize( abfs_pre[T].size() ); + for( size_t L=0; L!=abfs_pre[T].size(); ++L ) + { + abfs[T][L].insert( abfs[T][L].begin(), abfs_pre[T][L].begin(), abfs_pre[T][L].end() ); + } + } + + return abfs; } std::vector> Exx_Abfs::IO::construct_abfs_T( - const std::string & file_name, - const int &T, - const int &nk, - const double &dk, - const double &dr_uniform) + const std::string & file_name, + const int &T, + const int &nk, + const double &dk, + const double &dr_uniform) { - std::string label; - size_t L_size; - std::map N_size; - size_t meshr; - double dr = 0.0; - std::map>> psis; - - /*---------------------- - 1.read abfs - ----------------------*/ - std::string word; - - std::ifstream ifs( file_name.c_str() ); - if(!ifs) - throw std::runtime_error(" Can't find the abfs ORBITAL file " + file_name); - - while( ifs.good() ) - { - ifs >> word; - - if( "Element"==word ) - { - ModuleBase::GlobalFunc::READ_VALUE( ifs, label ); - } - else if ( "Lmax"==word ) - { - ModuleBase::GlobalFunc::READ_VALUE( ifs, L_size ); - - if( L_size>=9 ) - { - std::stringstream ss; - ss<<"Lmax>=9 error in "<<__FILE__<<" line "<<__LINE__; - throw std::invalid_argument(ss.str()); - } - } - else if ( "Sorbital-->"==word ) - { - ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[0] ); - } - else if ( "Porbital-->"==word ) - { - ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[1] ); - } - else if ( "Dorbital-->"==word ) - { - ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[2] ); - } - else if ( "Forbital-->"==word ) - { - ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[3] ); - } - else if ( "Gorbital-->"==word ) - { - ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[4] ); - } - else if ( "Horbital-->"==word ) - { - ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[5] ); - } - else if ( "Iorbital-->"==word ) - { - ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[6] ); - } - else if ( "Jorbital-->"==word ) - { - ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[7] ); - } - else if ( "Korbital-->"==word ) - { - ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[8] ); - } - else if ( "Lorbital-->"==word ) - { - ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[9] ); - } - else if ( "Morbital-->"==word ) - { - ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[10] ); - } - else if ( "Norbital-->"==word ) - { - ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[11] ); - } - else if ( "END"==word ) - { - break; - } - } - - ModuleBase::CHECK_NAME(ifs, "Mesh"); - ifs >> meshr; - - ModuleBase::CHECK_NAME(ifs, "dr"); - ifs >> dr; + std::string label; + size_t L_size; + std::map N_size; + size_t meshr; + double dr = 0.0; + std::map>> psis; + + /*---------------------- + 1.read abfs + ----------------------*/ + std::string word; + + std::ifstream ifs( file_name.c_str() ); + if(!ifs) + throw std::runtime_error(" Can't find the abfs ORBITAL file " + file_name); + + while( ifs.good() ) + { + ifs >> word; + + if( "Element"==word ) + { + ModuleBase::GlobalFunc::READ_VALUE( ifs, label ); + } + else if ( "Lmax"==word ) + { + ModuleBase::GlobalFunc::READ_VALUE( ifs, L_size ); + + if( L_size>=9 ) + { + std::stringstream ss; + ss<<"Lmax>=9 error in "<<__FILE__<<" line "<<__LINE__; + throw std::invalid_argument(ss.str()); + } + } + else if ( "Sorbital-->"==word ) + { + ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[0] ); + } + else if ( "Porbital-->"==word ) + { + ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[1] ); + } + else if ( "Dorbital-->"==word ) + { + ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[2] ); + } + else if ( "Forbital-->"==word ) + { + ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[3] ); + } + else if ( "Gorbital-->"==word ) + { + ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[4] ); + } + else if ( "Horbital-->"==word ) + { + ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[5] ); + } + else if ( "Iorbital-->"==word ) + { + ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[6] ); + } + else if ( "Jorbital-->"==word ) + { + ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[7] ); + } + else if ( "Korbital-->"==word ) + { + ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[8] ); + } + else if ( "Lorbital-->"==word ) + { + ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[9] ); + } + else if ( "Morbital-->"==word ) + { + ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[10] ); + } + else if ( "Norbital-->"==word ) + { + ModuleBase::GlobalFunc::READ_VALUE( ifs, N_size[11] ); + } + else if ( "END"==word ) + { + break; + } + } + + ModuleBase::CHECK_NAME(ifs, "Mesh"); + ifs >> meshr; + + ModuleBase::CHECK_NAME(ifs, "dr"); + ifs >> dr; - while(ifs.good()) - { - ifs >> word; - if(word=="Type") - { - std::string s_L, s_N; - ifs >> s_L >> s_N; - - size_t T,L,N; - ifs >> T >> L >> N; - - psis[L][N].resize(meshr); - for(int ir=0; ir!=meshr; ir++) - { - ifs >> psis[L][N][ir]; - } - } + while(ifs.good()) + { + ifs >> word; + if(word=="Type") + { + std::string s_L, s_N; + ifs >> s_L >> s_N; + + size_t T,L,N; + ifs >> T >> L >> N; + + psis[L][N].resize(meshr); + for(int ir=0; ir!=meshr; ir++) + { + ifs >> psis[L][N][ir]; + } + } - } - ifs.close(); + } + ifs.close(); - - /*---------------------- - 2.check L,N orbital - ----------------------*/ - for( size_t L=0; L<=L_size; ++L ) - if( N_size.find(L) == N_size.end() ) - { throw std::domain_error("Can't find N of L="+std::to_string(L)+" in "+file_name); } - for( size_t L=0; L<=L_size; ++L ) - for( size_t N=0; N!=N_size[L]; ++N ) - if( psis.find(L)==psis.end() || psis[L].find(N)==psis[L].end() ) - { throw std::domain_error("Can't find abf of L="+std::to_string(L)+" T="+std::to_string(T)+" in "+file_name); } + + /*---------------------- + 2.check L,N orbital + ----------------------*/ + for( size_t L=0; L<=L_size; ++L ) + if( N_size.find(L) == N_size.end() ) + { throw std::domain_error("Can't find N of L="+std::to_string(L)+" in "+file_name); } + for( size_t L=0; L<=L_size; ++L ) + for( size_t N=0; N!=N_size[L]; ++N ) + if( psis.find(L)==psis.end() || psis[L].find(N)==psis[L].end() ) + { throw std::domain_error("Can't find abf of L="+std::to_string(L)+" T="+std::to_string(T)+" in "+file_name); } - - /*---------------------- - 3.rab, radial - ----------------------*/ - if(meshr%2==0) ++meshr; - - std::vector rab(meshr); - std::vector radial(meshr); - for( int ir=0; ir!=meshr; ++ir ) - { - rab[ir] = dr; - radial[ir] = ir*dr; //mohan 2010-04-19 - } + + /*---------------------- + 3.rab, radial + ----------------------*/ + if(meshr%2==0) ++meshr; + + std::vector rab(meshr); + std::vector radial(meshr); + for( int ir=0; ir!=meshr; ++ir ) + { + rab[ir] = dr; + radial[ir] = ir*dr; //mohan 2010-04-19 + } - - /*---------------------- - 4.normalize psi - ----------------------*/ - for( size_t L=0; L<=L_size; ++L ) - { - for( size_t N=0; N!=N_size[L]; ++N ) - { - std::vector psir(meshr); - std::vector inner(meshr); - psis[L][N].resize(meshr); - for( int ir=0; ir!=meshr; ++ir ) - { - psir[ir] = psis[L][N][ir] * radial[ir]; - inner[ir] = psir[ir] * psir[ir]; - } - double unit = 0.0; - ModuleBase::Integral::Simpson_Integral(meshr, ModuleBase::GlobalFunc::VECTOR_TO_PTR(inner), ModuleBase::GlobalFunc::VECTOR_TO_PTR(rab), unit); - for( int ir=0; ir!=meshr; ++ir ) - { - psis[L][N][ir] /= sqrt(unit); - } - } - } + + /*---------------------- + 4.normalize psi + ----------------------*/ + for( size_t L=0; L<=L_size; ++L ) + { + for( size_t N=0; N!=N_size[L]; ++N ) + { + std::vector psir(meshr); + std::vector inner(meshr); + psis[L][N].resize(meshr); + for( int ir=0; ir!=meshr; ++ir ) + { + psir[ir] = psis[L][N][ir] * radial[ir]; + inner[ir] = psir[ir] * psir[ir]; + } + double unit = 0.0; + ModuleBase::Integral::Simpson_Integral(meshr, ModuleBase::GlobalFunc::VECTOR_TO_PTR(inner), ModuleBase::GlobalFunc::VECTOR_TO_PTR(rab), unit); + for( int ir=0; ir!=meshr; ++ir ) + { + psis[L][N][ir] /= sqrt(unit); + } + } + } - - /*---------------------- - 5.construct abfs - ----------------------*/ - std::vector> abfs_T; + + /*---------------------- + 5.construct abfs + ----------------------*/ + std::vector> abfs_T; - abfs_T.resize(L_size+1); - for( size_t L=0; L<=L_size; ++L ) - { - abfs_T[L].resize(N_size[L]); - for( size_t N=0; N!=N_size[L]; ++N ) - { - abfs_T[L][N].set_orbital_info( - label, - T, //type - L, //angular momentum L - N, // number of orbitals of this L - meshr, // number of radial mesh - ModuleBase::GlobalFunc::VECTOR_TO_PTR(rab), - ModuleBase::GlobalFunc::VECTOR_TO_PTR(radial),// radial mesh value(a.u.) - Numerical_Orbital_Lm::Psi_Type::Psi, - ModuleBase::GlobalFunc::VECTOR_TO_PTR(psis[L][N]), // radial wave function - nk, - dk, - dr_uniform, - false, - true, PARAM.inp.cal_force); - } - } - - return abfs_T; + abfs_T.resize(L_size+1); + for( size_t L=0; L<=L_size; ++L ) + { + abfs_T[L].resize(N_size[L]); + for( size_t N=0; N!=N_size[L]; ++N ) + { + abfs_T[L][N].set_orbital_info( + label, + T, //type + L, //angular momentum L + N, // number of orbitals of this L + meshr, // number of radial mesh + ModuleBase::GlobalFunc::VECTOR_TO_PTR(rab), + ModuleBase::GlobalFunc::VECTOR_TO_PTR(radial),// radial mesh value(a.u.) + Numerical_Orbital_Lm::Psi_Type::Psi, + ModuleBase::GlobalFunc::VECTOR_TO_PTR(psis[L][N]), // radial wave function + nk, + dk, + dr_uniform, + false, + true, PARAM.inp.cal_force); + } + } + + return abfs_T; } diff --git a/source/source_lcao/module_ri/exx_abfs_io.h b/source/source_lcao/module_ri/exx_abfs_io.h index b95fc13235b..9b113a47dce 100644 --- a/source/source_lcao/module_ri/exx_abfs_io.h +++ b/source/source_lcao/module_ri/exx_abfs_io.h @@ -16,25 +16,25 @@ class LCAO_Orbitals; class Exx_Abfs::IO { public: - - static std::vector>> construct_abfs( - const LCAO_Orbitals &orbs, - const std::vector &files_abfs, - const double kmesh_times=1 ); // close dK, keep Kcut - - static std::vector>> construct_abfs( - const std::vector>> &abfs_pre, - const LCAO_Orbitals &orbs, - const std::vector &files_abfs, - const double kmesh_times=1 ); // close dK, keep Kcut + + static std::vector>> construct_abfs( + const LCAO_Orbitals &orbs, + const std::vector &files_abfs, + const double kmesh_times=1 ); // close dK, keep Kcut + + static std::vector>> construct_abfs( + const std::vector>> &abfs_pre, + const LCAO_Orbitals &orbs, + const std::vector &files_abfs, + const double kmesh_times=1 ); // close dK, keep Kcut private: - static std::vector> construct_abfs_T( - const std::string & file_name, - const int &T, - const int &nk, - const double &dk, - const double &dr_uniform); + static std::vector> construct_abfs_T( + const std::string & file_name, + const int &T, + const int &nk, + const double &dk, + const double &dr_uniform); }; #endif // EXX_ABFS_IO_H diff --git a/source/source_lcao/module_ri/exx_abfs_jle.cpp b/source/source_lcao/module_ri/exx_abfs_jle.cpp index 21d409df0d0..fe1182a01a9 100644 --- a/source/source_lcao/module_ri/exx_abfs_jle.cpp +++ b/source/source_lcao/module_ri/exx_abfs_jle.cpp @@ -9,58 +9,58 @@ std::vector>> Exx_Abfs::Jle::init_jle( - const Exx_Info_Opt_ABFs &info, - const double kmesh_times, - const UnitCell& ucell, - const LCAO_Orbitals& orb) + const Exx_Info_Opt_ABFs &info, + const double kmesh_times, + const UnitCell& ucell, + const LCAO_Orbitals& orb) { - ModuleBase::TITLE("Exx_Abfs::Jle","init_jle"); - std::vector>> jle( ucell.ntype ); + ModuleBase::TITLE("Exx_Abfs::Jle","init_jle"); + std::vector>> jle( ucell.ntype ); - for(int T=0; T0) - { jle[T].resize( info.abfs_Lmax+1 ); } - for(int L=0; L<=info.abfs_Lmax; ++L) - { - const size_t ecut_number - = static_cast( std::sqrt( info.ecut_exx ) * orb.Phi[T].getRcut() / ModuleBase::PI ); // Rydberg Unit. - if(ecut_number<=0) - { continue; } + for(int T=0; T0) + { jle[T].resize( info.abfs_Lmax+1 ); } + for(int L=0; L<=info.abfs_Lmax; ++L) + { + const size_t ecut_number + = static_cast( std::sqrt( info.ecut_exx ) * orb.Phi[T].getRcut() / ModuleBase::PI ); // Rydberg Unit. + if(ecut_number<=0) + { continue; } - jle[T][L].resize( ecut_number ); + jle[T][L].resize( ecut_number ); - std::vector en(ecut_number, 0.0); - ModuleBase::Sphbes::Spherical_Bessel_Roots(ecut_number, L, info.tolerence, en.data(), orb.Phi[T].getRcut()); + std::vector en(ecut_number, 0.0); + ModuleBase::Sphbes::Spherical_Bessel_Roots(ecut_number, L, info.tolerence, en.data(), orb.Phi[T].getRcut()); - for(size_t E=0; E jle_r( orb.Phi[T].PhiLN(0,0).getNr() ); - ModuleBase::Sphbes::Spherical_Bessel( - orb.Phi[T].PhiLN(0,0).getNr(), - orb.Phi[T].PhiLN(0,0).getRadial(), - en[E], - L, - jle_r.data()); - jle[T][L][E].set_orbital_info( - orb.Phi[T].PhiLN(0,0).getLabel(), - orb.Phi[T].PhiLN(0,0).getType(), - L, - E, // N? - orb.Phi[T].PhiLN(0,0).getNr(), - orb.Phi[T].PhiLN(0,0).getRab(), - orb.Phi[T].PhiLN(0,0).getRadial(), - Numerical_Orbital_Lm::Psi_Type::Psi, - jle_r.data(), - static_cast(orb.Phi[T].PhiLN(0,0).getNk() * kmesh_times) | 1, - orb.Phi[T].PhiLN(0,0).getDk(), - orb.Phi[T].PhiLN(0,0).getDruniform(), - false, - true, - PARAM.inp.cal_force); - } - } - } + for(size_t E=0; E jle_r( orb.Phi[T].PhiLN(0,0).getNr() ); + ModuleBase::Sphbes::Spherical_Bessel( + orb.Phi[T].PhiLN(0,0).getNr(), + orb.Phi[T].PhiLN(0,0).getRadial(), + en[E], + L, + jle_r.data()); + jle[T][L][E].set_orbital_info( + orb.Phi[T].PhiLN(0,0).getLabel(), + orb.Phi[T].PhiLN(0,0).getType(), + L, + E, // N? + orb.Phi[T].PhiLN(0,0).getNr(), + orb.Phi[T].PhiLN(0,0).getRab(), + orb.Phi[T].PhiLN(0,0).getRadial(), + Numerical_Orbital_Lm::Psi_Type::Psi, + jle_r.data(), + static_cast(orb.Phi[T].PhiLN(0,0).getNk() * kmesh_times) | 1, + orb.Phi[T].PhiLN(0,0).getDk(), + orb.Phi[T].PhiLN(0,0).getDruniform(), + false, + true, + PARAM.inp.cal_force); + } + } + } - return jle; + return jle; } diff --git a/source/source_lcao/module_ri/exx_abfs_jle.h b/source/source_lcao/module_ri/exx_abfs_jle.h index 4b31b5c0137..51e00d3b122 100644 --- a/source/source_lcao/module_ri/exx_abfs_jle.h +++ b/source/source_lcao/module_ri/exx_abfs_jle.h @@ -7,18 +7,18 @@ #include - class LCAO_Orbitals; - class UnitCell; + class LCAO_Orbitals; + class UnitCell; class Exx_Abfs::Jle { public: - static std::vector>> - init_jle( - const Exx_Info_Opt_ABFs &info, - const double kmesh_times, - const UnitCell& ucell, - const LCAO_Orbitals& orb); + static std::vector>> + init_jle( + const Exx_Info_Opt_ABFs &info, + const double kmesh_times, + const UnitCell& ucell, + const LCAO_Orbitals& orb); }; #endif // EXX_ABFS_JLE_H diff --git a/source/source_lcao/module_ri/exx_lri.h b/source/source_lcao/module_ri/exx_lri.h index 3085c9e571c..7cb927f982f 100644 --- a/source/source_lcao/module_ri/exx_lri.h +++ b/source/source_lcao/module_ri/exx_lri.h @@ -21,52 +21,52 @@ #include "module_exx_symmetry/symm_rotation.h" - class Parallel_Orbitals; + class Parallel_Orbitals; - template - class RPA_LRI; + template + class RPA_LRI; - template - class Exx_LRI_Interface; + template + class Exx_LRI_Interface; - namespace LR - { - template - class OperatorLREXX; - } + namespace LR + { + template + class OperatorLREXX; + } template class Exx_Obj { - // match with Conv_Coulomb_Pot_K::Coulomb_Method - public: - LRI_CV cv; - Ewald_Vq evq; - std::vector>> abfs_ccp; + // match with Conv_Coulomb_Pot_K::Coulomb_Method + public: + LRI_CV cv; + Ewald_Vq evq; + std::vector>> abfs_ccp; }; template class Exx_LRI { private: - using TA = int; - using Tcell = int; - static constexpr std::size_t Ndim = 3; - using TC = std::array; - using TAC = std::pair; - using TatomR = std::array; // tmp + using TA = int; + using Tcell = int; + static constexpr std::size_t Ndim = 3; + using TC = std::array; + using TAC = std::pair; + using TatomR = std::array; // tmp public: - Exx_LRI(const Exx_Info_RI& info_in) :info(info_in) {} - Exx_LRI operator=(const Exx_LRI&) = delete; - Exx_LRI operator=(Exx_LRI&&); - - void init( - const MPI_Comm &mpi_comm_in, - const UnitCell &ucell, - const K_Vectors &kv_in, - const LCAO_Orbitals& orb, - const std::vector>>& abfs_in = {}); + Exx_LRI(const Exx_Info_RI& info_in) :info(info_in) {} + Exx_LRI operator=(const Exx_LRI&) = delete; + Exx_LRI operator=(Exx_LRI&&); + + void init( + const MPI_Comm &mpi_comm_in, + const UnitCell &ucell, + const K_Vectors &kv_in, + const LCAO_Orbitals& orb, + const std::vector>>& abfs_in = {}); void init_spencer(const MPI_Comm& mpi_comm_in, const UnitCell& ucell, const K_Vectors& kv_in, @@ -74,76 +74,76 @@ class Exx_LRI const std::vector>>& abfs_in = {}); void cal_exx_ions(const UnitCell& ucell, const bool write_cv = false); void cal_cut_coulomb_cs( - std::map>>& Vs_cut_IJR, - std::map>>& Cs, - const UnitCell& ucell, - const bool write_cv = false); - void cal_ewald_coulomb( - std::map>>& Vs_full_IJR, - std::map>>& Cs, - const UnitCell& ucell, - const bool write_cv = false); - void cal_exx_elec( - const std::vector>>>& Ds, - const UnitCell& ucell, - const Parallel_Orbitals& pv, - const ModuleSymmetry::Symmetry_rotation* p_symrot = nullptr); - // (nspin=4) real-space symmetry EXX: the spinor H(R) rotation couples the 4 spin channels via - // the SU(2) part U(isym), so the 4 channels must be rotated together (not one-per-outer-loop). - // Gathers the irreducible Hs of all 4 channels, calls Symmetry_rotation::restore_HR_nspin4, then - // finishes energy/gather per channel. Called from cal_exx_elec when p_symrot && nspin==4. - void cal_exx_elec_soc( - const std::vector>>>& Ds, - const UnitCell& ucell, - const std::vector, std::set>>& judge, - const ModuleSymmetry::Symmetry_rotation* p_symrot); - void cal_exx_force(const int& nat); - void cal_exx_stress(const double& omega, const double& lat0); - void cal_exx_dHs(const std::vector>>>& Ds, - const UnitCell& ucell, - const Parallel_Orbitals& pv); - - void reset_Cs(const std::map>>& Cs_in) { this->exx_lri.set_Cs(Cs_in, this->info.C_threshold); } - void reset_Vs(const std::map>>& Vs_in) { this->exx_lri.set_Vs(Vs_in, this->info.V_threshold); } - //std::vector> get_abfs_nchis() const; - - std::vector< std::map>>> Hexxs; - std::array>>>>, 3> dHexxs; // direction, atom, spin, (i,j,R) - double Eexx; - ModuleBase::matrix force_exx; - ModuleBase::matrix stress_exx; - - int abfs_Lmax() const { return abfs_Lmax_; } - const Exx_Info_RI& get_info_ri() const { return info; } + std::map>>& Vs_cut_IJR, + std::map>>& Cs, + const UnitCell& ucell, + const bool write_cv = false); + void cal_ewald_coulomb( + std::map>>& Vs_full_IJR, + std::map>>& Cs, + const UnitCell& ucell, + const bool write_cv = false); + void cal_exx_elec( + const std::vector>>>& Ds, + const UnitCell& ucell, + const Parallel_Orbitals& pv, + const ModuleSymmetry::Symmetry_rotation* p_symrot = nullptr); + // (nspin=4) real-space symmetry EXX: the spinor H(R) rotation couples the 4 spin channels via + // the SU(2) part U(isym), so the 4 channels must be rotated together (not one-per-outer-loop). + // Gathers the irreducible Hs of all 4 channels, calls Symmetry_rotation::restore_HR_nspin4, then + // finishes energy/gather per channel. Called from cal_exx_elec when p_symrot && nspin==4. + void cal_exx_elec_soc( + const std::vector>>>& Ds, + const UnitCell& ucell, + const std::vector, std::set>>& judge, + const ModuleSymmetry::Symmetry_rotation* p_symrot); + void cal_exx_force(const int& nat); + void cal_exx_stress(const double& omega, const double& lat0); + void cal_exx_dHs(const std::vector>>>& Ds, + const UnitCell& ucell, + const Parallel_Orbitals& pv); + + void reset_Cs(const std::map>>& Cs_in) { this->exx_lri.set_Cs(Cs_in, this->info.C_threshold); } + void reset_Vs(const std::map>>& Vs_in) { this->exx_lri.set_Vs(Vs_in, this->info.V_threshold); } + //std::vector> get_abfs_nchis() const; + + std::vector< std::map>>> Hexxs; + std::array>>>>, 3> dHexxs; // direction, atom, spin, (i,j,R) + double Eexx; + ModuleBase::matrix force_exx; + ModuleBase::matrix stress_exx; + + int abfs_Lmax() const { return abfs_Lmax_; } + const Exx_Info_RI& get_info_ri() const { return info; } private: - Exx_Info_RI info; - int abfs_Lmax_ = 0; - MPI_Comm mpi_comm; - const K_Vectors *p_kv = nullptr; - std::shared_ptr MGT; - std::vector orb_cutoff_; - - std::vector>> lcaos; - std::vector>> abfs; - //std::vector>> abfs_ccp; - std::map> exx_objs; - //LRI_CV cv; - RI::Exx exx_lri; - std::map MGT; + std::vector orb_cutoff_; + + std::vector>> lcaos; + std::vector>> abfs; + //std::vector>> abfs_ccp; + std::map> exx_objs; + //LRI_CV cv; + RI::Exx exx_lri; + std::map>>>> coulomb_settings; - void post_process_Hexx( std::map>> &Hexxs_io ) const; - double post_process_Eexx(const double& Eexx_in) const; + void post_process_Hexx( std::map>> &Hexxs_io ) const; + double post_process_Eexx(const double& Eexx_in) const; - friend class RPA_LRI; - friend class RPA_LRI, Tdata>; - friend class Exx_LRI_Interface; - friend class Exx_LRI_Interface, Tdata>; - friend class LR::OperatorLREXX; - friend class LR::OperatorLREXX>; + friend class RPA_LRI; + friend class RPA_LRI, Tdata>; + friend class Exx_LRI_Interface; + friend class Exx_LRI_Interface, Tdata>; + friend class LR::OperatorLREXX; + friend class LR::OperatorLREXX>; }; #include "exx_lri.hpp" diff --git a/source/source_lcao/module_ri/exx_lri.hpp b/source/source_lcao/module_ri/exx_lri.hpp index 9cb8f75d720..8d5421b6841 100644 --- a/source/source_lcao/module_ri/exx_lri.hpp +++ b/source/source_lcao/module_ri/exx_lri.hpp @@ -32,935 +32,935 @@ template void Exx_LRI::init(const MPI_Comm &mpi_comm_in, - const UnitCell &ucell, - const K_Vectors &kv_in, - const LCAO_Orbitals& orb, - const std::vector>>& abfs_in) + const UnitCell &ucell, + const K_Vectors &kv_in, + const LCAO_Orbitals& orb, + const std::vector>>& abfs_in) { - ModuleBase::TITLE("Exx_LRI","init"); - ModuleBase::timer::start("Exx_LRI", "init"); - - this->mpi_comm = mpi_comm_in; - this->p_kv = &kv_in; - this->orb_cutoff_ = orb.cutoffs(); - - this->lcaos = Exx_Abfs::Construct_Orbs::change_orbs( orb, this->info.kmesh_times ); - Exx_Abfs::Construct_Orbs::filter_empty_orbs(this->lcaos); - - if(abfs_in.empty()) - { - const std::vector>> - abfs_same_atom = Exx_Abfs::Construct_Orbs::abfs_same_atom(ucell, orb, this->lcaos, this->info.kmesh_times, this->info.pca_threshold ); - if(this->info.files_abfs.empty()) - { this->abfs = abfs_same_atom;} - else - { this->abfs = Exx_Abfs::IO::construct_abfs( abfs_same_atom, orb, this->info.files_abfs, this->info.kmesh_times ); } - } - else - { - this->abfs = abfs_in; - } - Exx_Abfs::Construct_Orbs::filter_empty_orbs(this->abfs); - Exx_Abfs::Construct_Orbs::print_orbs_size(ucell, this->abfs, GlobalV::ofs_running); - - for( size_t T=0; T!=this->abfs.size(); ++T ) - { - this->abfs_Lmax_ = std::max(this->abfs_Lmax_, static_cast(this->abfs[T].size())-1); - } - - this->exx_objs.clear(); - this->coulomb_settings = RI_Util::update_coulomb_settings(this->info.coulomb_param, ucell, this->p_kv); - - this->MGT = std::make_shared(); - for(const auto &settings_list : this->coulomb_settings) - { - this->exx_objs[settings_list.first].abfs_ccp = Conv_Coulomb_Pot_K::cal_orbs_ccp(this->abfs, settings_list.second.second, this->info.ccp_rmesh_times); - this->exx_objs[settings_list.first].cv.set_orbitals(ucell, orb, - this->lcaos, this->abfs, this->exx_objs[settings_list.first].abfs_ccp, - this->info.kmesh_times, this->MGT, settings_list.second.first ); - this->exx_objs[settings_list.first].cv.set_info_ri(&this->info); - if (settings_list.first == Conv_Coulomb_Pot_K::Coulomb_Method::Ewald) - { - const int evq_abfs_Lmax = this->abfs_Lmax_; - this->exx_objs[settings_list.first].evq.init(ucell, orb, - this->mpi_comm, this->p_kv, this->lcaos, this->abfs, - settings_list.second.second, this->MGT, this->info.ccp_rmesh_times, this->info.kmesh_times, - evq_abfs_Lmax); - } - } - - ModuleBase::timer::end("Exx_LRI", "init"); + ModuleBase::TITLE("Exx_LRI","init"); + ModuleBase::timer::start("Exx_LRI", "init"); + + this->mpi_comm = mpi_comm_in; + this->p_kv = &kv_in; + this->orb_cutoff_ = orb.cutoffs(); + + this->lcaos = Exx_Abfs::Construct_Orbs::change_orbs( orb, this->info.kmesh_times ); + Exx_Abfs::Construct_Orbs::filter_empty_orbs(this->lcaos); + + if(abfs_in.empty()) + { + const std::vector>> + abfs_same_atom = Exx_Abfs::Construct_Orbs::abfs_same_atom(ucell, orb, this->lcaos, this->info.kmesh_times, this->info.pca_threshold ); + if(this->info.files_abfs.empty()) + { this->abfs = abfs_same_atom;} + else + { this->abfs = Exx_Abfs::IO::construct_abfs( abfs_same_atom, orb, this->info.files_abfs, this->info.kmesh_times ); } + } + else + { + this->abfs = abfs_in; + } + Exx_Abfs::Construct_Orbs::filter_empty_orbs(this->abfs); + Exx_Abfs::Construct_Orbs::print_orbs_size(ucell, this->abfs, GlobalV::ofs_running); + + for( size_t T=0; T!=this->abfs.size(); ++T ) + { + this->abfs_Lmax_ = std::max(this->abfs_Lmax_, static_cast(this->abfs[T].size())-1); + } + + this->exx_objs.clear(); + this->coulomb_settings = RI_Util::update_coulomb_settings(this->info.coulomb_param, ucell, this->p_kv); + + this->MGT = std::make_shared(); + for(const auto &settings_list : this->coulomb_settings) + { + this->exx_objs[settings_list.first].abfs_ccp = Conv_Coulomb_Pot_K::cal_orbs_ccp(this->abfs, settings_list.second.second, this->info.ccp_rmesh_times); + this->exx_objs[settings_list.first].cv.set_orbitals(ucell, orb, + this->lcaos, this->abfs, this->exx_objs[settings_list.first].abfs_ccp, + this->info.kmesh_times, this->MGT, settings_list.second.first ); + this->exx_objs[settings_list.first].cv.set_info_ri(&this->info); + if (settings_list.first == Conv_Coulomb_Pot_K::Coulomb_Method::Ewald) + { + const int evq_abfs_Lmax = this->abfs_Lmax_; + this->exx_objs[settings_list.first].evq.init(ucell, orb, + this->mpi_comm, this->p_kv, this->lcaos, this->abfs, + settings_list.second.second, this->MGT, this->info.ccp_rmesh_times, this->info.kmesh_times, + evq_abfs_Lmax); + } + } + + ModuleBase::timer::end("Exx_LRI", "init"); } template void Exx_LRI::init_spencer( - const MPI_Comm& mpi_comm_in, - const UnitCell& ucell, - const K_Vectors& kv_in, - const LCAO_Orbitals& orb, - const std::vector>>& abfs_in) + const MPI_Comm& mpi_comm_in, + const UnitCell& ucell, + const K_Vectors& kv_in, + const LCAO_Orbitals& orb, + const std::vector>>& abfs_in) { - ModuleBase::TITLE("Exx_LRI", "init_spencer"); - ModuleBase::timer::start("Exx_LRI", "init_spencer"); - - this->mpi_comm = mpi_comm_in; - this->p_kv = &kv_in; - this->orb_cutoff_ = orb.cutoffs(); - - this->lcaos = Exx_Abfs::Construct_Orbs::change_orbs(orb, this->info.kmesh_times); - Exx_Abfs::Construct_Orbs::filter_empty_orbs(this->lcaos); - - if (abfs_in.empty()) - { - const std::vector>> abfs_same_atom - = Exx_Abfs::Construct_Orbs::abfs_same_atom( - ucell, orb, this->lcaos, this->info.kmesh_times, this->info.pca_threshold); - if (this->info.files_abfs.empty()) - { this->abfs = abfs_same_atom; } - else - { this->abfs = Exx_Abfs::IO::construct_abfs(abfs_same_atom, orb, this->info.files_abfs, this->info.kmesh_times); } - } - else - { - this->abfs = abfs_in; - } - Exx_Abfs::Construct_Orbs::filter_empty_orbs(this->abfs); - Exx_Abfs::Construct_Orbs::print_orbs_size(ucell, this->abfs, GlobalV::ofs_running); - - for (size_t T = 0; T != this->abfs.size(); ++T) - { - this->abfs_Lmax_ = std::max(this->abfs_Lmax_, static_cast(this->abfs[T].size()) - 1); - } - - this->exx_objs.clear(); - this->coulomb_settings.clear(); - this->coulomb_settings[Conv_Coulomb_Pot_K::Coulomb_Method::Center2] = std::make_pair( - true, ExxLriDetail::build_center2_cut_coulomb_param(this->info.coulomb_param, ucell, kv_in)); - - this->MGT = std::make_shared(); - const auto center2_settings = this->coulomb_settings.find(Conv_Coulomb_Pot_K::Coulomb_Method::Center2); - if (center2_settings == this->coulomb_settings.end()) - { throw std::invalid_argument("Exx_LRI::init_spencer failed to prepare Center2 settings."); } - - this->exx_objs[Conv_Coulomb_Pot_K::Coulomb_Method::Center2].abfs_ccp = Conv_Coulomb_Pot_K::cal_orbs_ccp_spencer( - this->abfs, - center2_settings->second.second, - this->info.ccp_rmesh_times); - this->exx_objs[Conv_Coulomb_Pot_K::Coulomb_Method::Center2].cv.set_orbitals( - ucell, - orb, - this->lcaos, - this->abfs, - this->exx_objs[Conv_Coulomb_Pot_K::Coulomb_Method::Center2].abfs_ccp, - this->info.kmesh_times, - this->MGT, - center2_settings->second.first); - this->exx_objs[Conv_Coulomb_Pot_K::Coulomb_Method::Center2].cv.set_info_ri(&this->info); - - ModuleBase::timer::end("Exx_LRI", "init_spencer"); + ModuleBase::TITLE("Exx_LRI", "init_spencer"); + ModuleBase::timer::start("Exx_LRI", "init_spencer"); + + this->mpi_comm = mpi_comm_in; + this->p_kv = &kv_in; + this->orb_cutoff_ = orb.cutoffs(); + + this->lcaos = Exx_Abfs::Construct_Orbs::change_orbs(orb, this->info.kmesh_times); + Exx_Abfs::Construct_Orbs::filter_empty_orbs(this->lcaos); + + if (abfs_in.empty()) + { + const std::vector>> abfs_same_atom + = Exx_Abfs::Construct_Orbs::abfs_same_atom( + ucell, orb, this->lcaos, this->info.kmesh_times, this->info.pca_threshold); + if (this->info.files_abfs.empty()) + { this->abfs = abfs_same_atom; } + else + { this->abfs = Exx_Abfs::IO::construct_abfs(abfs_same_atom, orb, this->info.files_abfs, this->info.kmesh_times); } + } + else + { + this->abfs = abfs_in; + } + Exx_Abfs::Construct_Orbs::filter_empty_orbs(this->abfs); + Exx_Abfs::Construct_Orbs::print_orbs_size(ucell, this->abfs, GlobalV::ofs_running); + + for (size_t T = 0; T != this->abfs.size(); ++T) + { + this->abfs_Lmax_ = std::max(this->abfs_Lmax_, static_cast(this->abfs[T].size()) - 1); + } + + this->exx_objs.clear(); + this->coulomb_settings.clear(); + this->coulomb_settings[Conv_Coulomb_Pot_K::Coulomb_Method::Center2] = std::make_pair( + true, ExxLriDetail::build_center2_cut_coulomb_param(this->info.coulomb_param, ucell, kv_in)); + + this->MGT = std::make_shared(); + const auto center2_settings = this->coulomb_settings.find(Conv_Coulomb_Pot_K::Coulomb_Method::Center2); + if (center2_settings == this->coulomb_settings.end()) + { throw std::invalid_argument("Exx_LRI::init_spencer failed to prepare Center2 settings."); } + + this->exx_objs[Conv_Coulomb_Pot_K::Coulomb_Method::Center2].abfs_ccp = Conv_Coulomb_Pot_K::cal_orbs_ccp_spencer( + this->abfs, + center2_settings->second.second, + this->info.ccp_rmesh_times); + this->exx_objs[Conv_Coulomb_Pot_K::Coulomb_Method::Center2].cv.set_orbitals( + ucell, + orb, + this->lcaos, + this->abfs, + this->exx_objs[Conv_Coulomb_Pot_K::Coulomb_Method::Center2].abfs_ccp, + this->info.kmesh_times, + this->MGT, + center2_settings->second.first); + this->exx_objs[Conv_Coulomb_Pot_K::Coulomb_Method::Center2].cv.set_info_ri(&this->info); + + ModuleBase::timer::end("Exx_LRI", "init_spencer"); } template void Exx_LRI::cal_exx_ions(const UnitCell& ucell, - const bool write_cv) + const bool write_cv) { - ModuleBase::TITLE("Exx_LRI","cal_exx_ions"); - ModuleBase::timer::start("Exx_LRI", "cal_exx_ions"); - - // init_radial_table_ions( cal_atom_centres_core(atom_pairs_core_origin), atom_pairs_core_origin ); - - // this->m_abfsabfs.init_radial_table(Rradial); - // this->m_abfslcaos_lcaos.init_radial_table(Rradial); - - std::vector atoms(ucell.nat); - for(int iat=0; iat atoms_pos; - for(int iat=0; iat latvec - = {RI_Util::Vector3_to_array3(ucell.a1), - RI_Util::Vector3_to_array3(ucell.a2), - RI_Util::Vector3_to_array3(ucell.a3)}; - const std::array period = {this->p_kv->nmp[0], this->p_kv->nmp[1], this->p_kv->nmp[2]}; - - this->exx_lri.set_parallel(this->mpi_comm, atoms_pos, latvec, period); - - // std::max(3) for gamma_only, list_A2 should contain cell {-1,0,1}. In the future distribute will be neighbour. - const std::array period_Vs = LRI_CV_Tools::cal_latvec_range(1+this->info.ccp_rmesh_times, ucell, orb_cutoff_); - const std::pair, std::vector>>>> - list_As_Vs = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Vs, 2, false); - - std::map>> Vs; - std::map, Ndim>>> dVs; + ModuleBase::TITLE("Exx_LRI","cal_exx_ions"); + ModuleBase::timer::start("Exx_LRI", "cal_exx_ions"); + + // init_radial_table_ions( cal_atom_centres_core(atom_pairs_core_origin), atom_pairs_core_origin ); + + // this->m_abfsabfs.init_radial_table(Rradial); + // this->m_abfslcaos_lcaos.init_radial_table(Rradial); + + std::vector atoms(ucell.nat); + for(int iat=0; iat atoms_pos; + for(int iat=0; iat latvec + = {RI_Util::Vector3_to_array3(ucell.a1), + RI_Util::Vector3_to_array3(ucell.a2), + RI_Util::Vector3_to_array3(ucell.a3)}; + const std::array period = {this->p_kv->nmp[0], this->p_kv->nmp[1], this->p_kv->nmp[2]}; + + this->exx_lri.set_parallel(this->mpi_comm, atoms_pos, latvec, period); + + // std::max(3) for gamma_only, list_A2 should contain cell {-1,0,1}. In the future distribute will be neighbour. + const std::array period_Vs = LRI_CV_Tools::cal_latvec_range(1+this->info.ccp_rmesh_times, ucell, orb_cutoff_); + const std::pair, std::vector>>>> + list_As_Vs = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Vs, 2, false); + + std::map>> Vs; + std::map, Ndim>>> dVs; const bool cal_dCV = PARAM.inp.cal_force || PARAM.inp.cal_stress || PARAM.inp.out_mat_dh_exx[0]; - for(const auto &settings_list : this->coulomb_settings) - { - std::map>> - Vs_temp = this->exx_objs[settings_list.first].cv.cal_Vs(ucell, - list_As_Vs.first, list_As_Vs.second[0], - {{"writable_Vws",true}}); - this->exx_objs[settings_list.first].cv.Vws = LRI_CV_Tools::get_CVws(ucell,Vs_temp); - if (settings_list.first == Conv_Coulomb_Pot_K::Coulomb_Method::Ewald) - { - this->exx_objs[settings_list.first].evq.init_ions(ucell, period_Vs); - const auto &coulomb_param = settings_list.second.second; - std::map>> Vs_ewald; - for(const auto ¶m_list : coulomb_param) - { - std::map>> Vs_ewald_temp; - switch(param_list.first) - { - case Conv_Coulomb_Pot_K::Coulomb_Type::Fock: - { - double chi = this->exx_objs[settings_list.first].evq.get_singular_chi(ucell, param_list.second, 2.0); - Vs_ewald_temp = this->exx_objs[settings_list.first].evq.cal_Vs(ucell, chi, Vs_temp); - break; - } - default: - { - throw std::invalid_argument( std::string(__FILE__) + " line " + std::to_string(__LINE__) ); - } - } - // Vs_temp cannot be covered here - Vs_ewald = Vs_ewald.empty() ? Vs_ewald_temp : LRI_CV_Tools::add(Vs_ewald, Vs_ewald_temp); - } - Vs_temp = Vs_ewald; - } - Vs = Vs.empty() ? Vs_temp : LRI_CV_Tools::add(Vs, Vs_temp); + for(const auto &settings_list : this->coulomb_settings) + { + std::map>> + Vs_temp = this->exx_objs[settings_list.first].cv.cal_Vs(ucell, + list_As_Vs.first, list_As_Vs.second[0], + {{"writable_Vws",true}}); + this->exx_objs[settings_list.first].cv.Vws = LRI_CV_Tools::get_CVws(ucell,Vs_temp); + if (settings_list.first == Conv_Coulomb_Pot_K::Coulomb_Method::Ewald) + { + this->exx_objs[settings_list.first].evq.init_ions(ucell, period_Vs); + const auto &coulomb_param = settings_list.second.second; + std::map>> Vs_ewald; + for(const auto ¶m_list : coulomb_param) + { + std::map>> Vs_ewald_temp; + switch(param_list.first) + { + case Conv_Coulomb_Pot_K::Coulomb_Type::Fock: + { + double chi = this->exx_objs[settings_list.first].evq.get_singular_chi(ucell, param_list.second, 2.0); + Vs_ewald_temp = this->exx_objs[settings_list.first].evq.cal_Vs(ucell, chi, Vs_temp); + break; + } + default: + { + throw std::invalid_argument( std::string(__FILE__) + " line " + std::to_string(__LINE__) ); + } + } + // Vs_temp cannot be covered here + Vs_ewald = Vs_ewald.empty() ? Vs_ewald_temp : LRI_CV_Tools::add(Vs_ewald, Vs_ewald_temp); + } + Vs_temp = Vs_ewald; + } + Vs = Vs.empty() ? Vs_temp : LRI_CV_Tools::add(Vs, Vs_temp); if (cal_dCV) - { - std::map, Ndim>>> - dVs_temp = this->exx_objs[settings_list.first].cv.cal_dVs(ucell, - list_As_Vs.first, list_As_Vs.second[0], - {{"writable_dVws",true}}); - this->exx_objs[settings_list.first].cv.dVws = LRI_CV_Tools::get_dCVws(ucell,dVs_temp); - dVs = dVs.empty() ? dVs_temp : LRI_CV_Tools::add(dVs, dVs_temp); - } - } - if (write_cv && GlobalV::MY_RANK == 0) - { LRI_CV_Tools::write_Vs_abf(Vs, PARAM.globalv.global_out_dir + "Vs"); } - this->exx_lri.set_Vs(std::move(Vs), this->info.V_threshold); + { + std::map, Ndim>>> + dVs_temp = this->exx_objs[settings_list.first].cv.cal_dVs(ucell, + list_As_Vs.first, list_As_Vs.second[0], + {{"writable_dVws",true}}); + this->exx_objs[settings_list.first].cv.dVws = LRI_CV_Tools::get_dCVws(ucell,dVs_temp); + dVs = dVs.empty() ? dVs_temp : LRI_CV_Tools::add(dVs, dVs_temp); + } + } + if (write_cv && GlobalV::MY_RANK == 0) + { LRI_CV_Tools::write_Vs_abf(Vs, PARAM.globalv.global_out_dir + "Vs"); } + this->exx_lri.set_Vs(std::move(Vs), this->info.V_threshold); if (cal_dCV) - { - std::array>>, Ndim> - dVs_order = LRI_CV_Tools::change_order(std::move(dVs)); - this->exx_lri.set_dVs(std::move(dVs_order), this->info.V_grad_threshold); - if(PARAM.inp.cal_stress) - { - std::array>>,3>,3> dVRs = LRI_CV_Tools::cal_dMRs(ucell,dVs_order); - this->exx_lri.set_dVRs(std::move(dVRs), this->info.V_grad_R_threshold); - } - } - - const std::array period_Cs = LRI_CV_Tools::cal_latvec_range(2, ucell,orb_cutoff_); - const std::pair, std::vector>>>> - list_As_Cs = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Cs, 2, false); - - std::map>> Cs; - std::map, 3>>> dCs; - for(const auto &settings_list : this->coulomb_settings) - { - if(settings_list.second.first) - { - std::pair>>, - std::map, 3>>>> - Cs_dCs = this->exx_objs[settings_list.first].cv.cal_Cs_dCs( - ucell, - list_As_Cs.first, list_As_Cs.second[0], + { + std::array>>, Ndim> + dVs_order = LRI_CV_Tools::change_order(std::move(dVs)); + this->exx_lri.set_dVs(std::move(dVs_order), this->info.V_grad_threshold); + if(PARAM.inp.cal_stress) + { + std::array>>,3>,3> dVRs = LRI_CV_Tools::cal_dMRs(ucell,dVs_order); + this->exx_lri.set_dVRs(std::move(dVRs), this->info.V_grad_R_threshold); + } + } + + const std::array period_Cs = LRI_CV_Tools::cal_latvec_range(2, ucell,orb_cutoff_); + const std::pair, std::vector>>>> + list_As_Cs = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Cs, 2, false); + + std::map>> Cs; + std::map, 3>>> dCs; + for(const auto &settings_list : this->coulomb_settings) + { + if(settings_list.second.first) + { + std::pair>>, + std::map, 3>>>> + Cs_dCs = this->exx_objs[settings_list.first].cv.cal_Cs_dCs( + ucell, + list_As_Cs.first, list_As_Cs.second[0], { {"cal_dC",cal_dCV}, - {"writable_Cws",true}, {"writable_dCws",true}, {"writable_Vws",false}, {"writable_dVws",false}}); - std::map>> &Cs_temp = std::get<0>(Cs_dCs); - this->exx_objs[settings_list.first].cv.Cws = LRI_CV_Tools::get_CVws(ucell,Cs_temp); - Cs = Cs.empty() ? Cs_temp : LRI_CV_Tools::add(Cs, Cs_temp); + {"writable_Cws",true}, {"writable_dCws",true}, {"writable_Vws",false}, {"writable_dVws",false}}); + std::map>> &Cs_temp = std::get<0>(Cs_dCs); + this->exx_objs[settings_list.first].cv.Cws = LRI_CV_Tools::get_CVws(ucell,Cs_temp); + Cs = Cs.empty() ? Cs_temp : LRI_CV_Tools::add(Cs, Cs_temp); if (cal_dCV) - { - std::map, 3>>> &dCs_temp = std::get<1>(Cs_dCs); - this->exx_objs[settings_list.first].cv.dCws = LRI_CV_Tools::get_dCVws(ucell,dCs_temp); - dCs = dCs.empty() ? dCs_temp : LRI_CV_Tools::add(dCs, dCs_temp); - } - } - } - if (write_cv && GlobalV::MY_RANK == 0) - { LRI_CV_Tools::write_Cs_ao(Cs, PARAM.globalv.global_out_dir + "Cs"); } - this->exx_lri.set_Cs(std::move(Cs), this->info.C_threshold); + { + std::map, 3>>> &dCs_temp = std::get<1>(Cs_dCs); + this->exx_objs[settings_list.first].cv.dCws = LRI_CV_Tools::get_dCVws(ucell,dCs_temp); + dCs = dCs.empty() ? dCs_temp : LRI_CV_Tools::add(dCs, dCs_temp); + } + } + } + if (write_cv && GlobalV::MY_RANK == 0) + { LRI_CV_Tools::write_Cs_ao(Cs, PARAM.globalv.global_out_dir + "Cs"); } + this->exx_lri.set_Cs(std::move(Cs), this->info.C_threshold); if (cal_dCV) - { - std::array>>, Ndim> - dCs_order = LRI_CV_Tools::change_order(std::move(dCs)); - this->exx_lri.set_dCs(std::move(dCs_order), this->info.C_grad_threshold); - if(PARAM.inp.cal_stress) - { - std::array>>,3>,3> dCRs = LRI_CV_Tools::cal_dMRs(ucell,dCs_order); - this->exx_lri.set_dCRs(std::move(dCRs), this->info.C_grad_R_threshold); - } - } - ModuleBase::timer::end("Exx_LRI", "cal_exx_ions"); + { + std::array>>, Ndim> + dCs_order = LRI_CV_Tools::change_order(std::move(dCs)); + this->exx_lri.set_dCs(std::move(dCs_order), this->info.C_grad_threshold); + if(PARAM.inp.cal_stress) + { + std::array>>,3>,3> dCRs = LRI_CV_Tools::cal_dMRs(ucell,dCs_order); + this->exx_lri.set_dCRs(std::move(dCRs), this->info.C_grad_R_threshold); + } + } + ModuleBase::timer::end("Exx_LRI", "cal_exx_ions"); } - #if 0 - template - void Exx_LRI::cal_cut_coulomb_cs( - std::map>>& Vs_cut, - std::map>>& Cs, - const UnitCell& ucell, - const bool write_cv) + #if 0 + template + void Exx_LRI::cal_cut_coulomb_cs( + std::map>>& Vs_cut, + std::map>>& Cs, + const UnitCell& ucell, + const bool write_cv) { - ModuleBase::TITLE("Exx_LRI", "cal_cut_coulomb_cs"); - ModuleBase::timer::start("Exx_LRI", "cal_cut_coulomb_cs"); - - std::vector atoms(ucell.nat); - for(int iat=0; iat atoms_pos; - for(int iat=0; iat latvec - = {RI_Util::Vector3_to_array3(ucell.a1), - RI_Util::Vector3_to_array3(ucell.a2), - RI_Util::Vector3_to_array3(ucell.a3)}; - const std::array period = {this->p_kv->nmp[0], this->p_kv->nmp[1], this->p_kv->nmp[2]}; - - this->exx_lri.set_parallel(this->mpi_comm, atoms_pos, latvec, period); - - // std::max(3) for gamma_only, list_A2 should contain cell {-1,0,1}. In the future distribute will be neighbour. - const std::array period_Vs - = LRI_CV_Tools::cal_latvec_range(1 + this->info.ccp_rmesh_times, ucell, orb_cutoff_); - const std::pair, std::vector>>>> - list_As_Vs = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Vs, 2, false); - - std::map, Ndim>>> dVs; - for(const auto &settings_list : this->coulomb_settings) - { - if(!settings_list.second.first) continue; - std::map>> - Vs_temp = this->exx_objs[settings_list.first].cv.cal_Vs(ucell, - list_As_Vs.first, list_As_Vs.second[0], - {{"writable_Vws",true}}); - this->exx_objs[settings_list.first].cv.Vws = LRI_CV_Tools::get_CVws(ucell,Vs_temp); - - // ======rotate ABFs begin====== - int flag = 0; - for (const auto& IJRc: this->exx_objs[settings_list.first].cv.Vws) - { - const TA& I = IJRc.first; - const auto& JRc = IJRc.second; - for (const auto& JRc_tensor: JRc) - { - const TA& J = JRc_tensor.first; - const auto Rc = JRc_tensor.second; - for (const auto& Rc_tensor: Rc) - { - const auto& R = Rc_tensor.first; - flag += 1; - } - } - } - std::cout << "Coulomb: number of atom-pairs inside atomic overlap is " << flag << ". " << std::endl; - if (this->info.coul_moment == true) - { - double hf_Rcut = std::pow(0.75 * this->p_kv->get_nkstot_nospin() * ucell.omega / (ModuleBase::PI), 1.0 / 3.0); - // To cal Cs, we still cal all Vs(R) in r space - // moment_abfs->cal_VR(ucell, - // this->abfs, - // list_As_Vs, - // orb_cutoff_, - // hf_Rcut, - // this->exx_objs[settings_list.first].cv, - // Vs_cut); - delete moment_abfs; - moment_abfs = nullptr; - malloc_trim(0); - } - - flag = 0; - for (const auto& IJRc: this->exx_objs[settings_list.first].cv.Vws) - { - const auto& JRc = IJRc.second; - for (const auto& JRc_tensor: JRc) - { - const auto Rc = JRc_tensor.second; - for (const auto& Rc_tensor: Rc) - { - flag += 1; - } - } - } - std::cout << "Coulomb: number of all atom-pairs is " << flag << ". " << std::endl; - // ======rotate ABFs end====== - - Vs_cut = Vs.empty() ? Vs_temp : LRI_CV_Tools::add(Vs_cut, Vs_temp); - - if(PARAM.inp.cal_force || PARAM.inp.cal_stress) - { - std::map, Ndim>>> - dVs_temp = this->exx_objs[settings_list.first].cv.cal_dVs(ucell, - list_As_Vs.first, list_As_Vs.second[0], - {{"writable_dVws",true}}); - this->exx_objs[settings_list.first].cv.dVws = LRI_CV_Tools::get_dCVws(ucell,dVs_temp); - dVs = dVs.empty() ? dVs_temp : LRI_CV_Tools::add(dVs, dVs_temp); - } - } - - if (write_cv && GlobalV::MY_RANK == 0) - { - LRI_CV_Tools::write_Vs_abf(Vs_cut, PARAM.globalv.global_out_dir + "Vs_cut"); - } - this->exx_lri.set_Vs(std::move(Vs_cut), this->info.V_threshold); - - if(PARAM.inp.cal_force || PARAM.inp.cal_stress) - { - std::map,Ndim>>> dVs - = this->exx_objs[coulomb_method].cv.cal_dVs(ucell, - list_As_Vs.first, list_As_Vs.second[0], - {{"writable_dVws",true}}); - this->exx_objs[coulomb_method].cv.dVws = LRI_CV_Tools::get_dCVws(ucell,dVs); - - std::array>>,Ndim> dVs_order - = LRI_CV_Tools::change_order(std::move(dVs)); - this->exx_lri.set_dVs(std::move(dVs_order), this->info.V_grad_threshold); - if(PARAM.inp.cal_stress) - { - std::array>>,3>,3> dVRs - = LRI_CV_Tools::cal_dMRs(ucell,dVs_order); - this->exx_lri.set_dVRs(std::move(dVRs), this->info.V_grad_R_threshold); - } - } - - const std::array period_Cs = LRI_CV_Tools::cal_latvec_range(2, ucell,orb_cutoff_); - const std::pair, std::vector>>>> - list_As_Cs = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Cs, 2, false); - std::pair>>, - std::map,3>>>> - Cs_dCs = this->exx_objs[coulomb_method].cv.cal_Cs_dCs(ucell, - list_As_Cs.first, list_As_Cs.second[0], - {{"cal_dC",PARAM.inp.cal_force||PARAM.inp.cal_stress}, - {"writable_Cws",true}, - {"writable_dCws",true}, - {"writable_Vws",false}, - {"writable_dVws",false}}); - Cs = std::get<0>(Cs_dCs); - this->exx_objs[coulomb_method].cv.Cws = LRI_CV_Tools::get_CVws(ucell,Cs); - if(write_cv && GlobalV::MY_RANK==0) - { - LRI_CV_Tools::write_Cs_ao(Cs, PARAM.globalv.global_out_dir + "Cs"); - } - this->exx_lri.set_Cs(Cs, this->info.C_threshold); - - if(PARAM.inp.cal_force || PARAM.inp.cal_stress) - { - std::map,3>>>& dCs = std::get<1>(Cs_dCs); - this->exx_objs[coulomb_method].cv.dCws = LRI_CV_Tools::get_dCVws(ucell,dCs); - std::array>>,Ndim> dCs_order - = LRI_CV_Tools::change_order(std::move(dCs)); - this->exx_lri.set_dCs(std::move(dCs_order), this->info.C_grad_threshold); - if(PARAM.inp.cal_stress) - { - std::array>>,3>,3> dCRs - = LRI_CV_Tools::cal_dMRs(ucell,dCs_order); - this->exx_lri.set_dCRs(std::move(dCRs), this->info.C_grad_R_threshold); - } - } - ModuleBase::timer::end("Exx_LRI", "cal_cut_coulomb_cs"); + ModuleBase::TITLE("Exx_LRI", "cal_cut_coulomb_cs"); + ModuleBase::timer::start("Exx_LRI", "cal_cut_coulomb_cs"); + + std::vector atoms(ucell.nat); + for(int iat=0; iat atoms_pos; + for(int iat=0; iat latvec + = {RI_Util::Vector3_to_array3(ucell.a1), + RI_Util::Vector3_to_array3(ucell.a2), + RI_Util::Vector3_to_array3(ucell.a3)}; + const std::array period = {this->p_kv->nmp[0], this->p_kv->nmp[1], this->p_kv->nmp[2]}; + + this->exx_lri.set_parallel(this->mpi_comm, atoms_pos, latvec, period); + + // std::max(3) for gamma_only, list_A2 should contain cell {-1,0,1}. In the future distribute will be neighbour. + const std::array period_Vs + = LRI_CV_Tools::cal_latvec_range(1 + this->info.ccp_rmesh_times, ucell, orb_cutoff_); + const std::pair, std::vector>>>> + list_As_Vs = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Vs, 2, false); + + std::map, Ndim>>> dVs; + for(const auto &settings_list : this->coulomb_settings) + { + if(!settings_list.second.first) continue; + std::map>> + Vs_temp = this->exx_objs[settings_list.first].cv.cal_Vs(ucell, + list_As_Vs.first, list_As_Vs.second[0], + {{"writable_Vws",true}}); + this->exx_objs[settings_list.first].cv.Vws = LRI_CV_Tools::get_CVws(ucell,Vs_temp); + + // ======rotate ABFs begin====== + int flag = 0; + for (const auto& IJRc: this->exx_objs[settings_list.first].cv.Vws) + { + const TA& I = IJRc.first; + const auto& JRc = IJRc.second; + for (const auto& JRc_tensor: JRc) + { + const TA& J = JRc_tensor.first; + const auto Rc = JRc_tensor.second; + for (const auto& Rc_tensor: Rc) + { + const auto& R = Rc_tensor.first; + flag += 1; + } + } + } + std::cout << "Coulomb: number of atom-pairs inside atomic overlap is " << flag << ". " << std::endl; + if (this->info.coul_moment == true) + { + double hf_Rcut = std::pow(0.75 * this->p_kv->get_nkstot_nospin() * ucell.omega / (ModuleBase::PI), 1.0 / 3.0); + // To cal Cs, we still cal all Vs(R) in r space + // moment_abfs->cal_VR(ucell, + // this->abfs, + // list_As_Vs, + // orb_cutoff_, + // hf_Rcut, + // this->exx_objs[settings_list.first].cv, + // Vs_cut); + delete moment_abfs; + moment_abfs = nullptr; + malloc_trim(0); + } + + flag = 0; + for (const auto& IJRc: this->exx_objs[settings_list.first].cv.Vws) + { + const auto& JRc = IJRc.second; + for (const auto& JRc_tensor: JRc) + { + const auto Rc = JRc_tensor.second; + for (const auto& Rc_tensor: Rc) + { + flag += 1; + } + } + } + std::cout << "Coulomb: number of all atom-pairs is " << flag << ". " << std::endl; + // ======rotate ABFs end====== + + Vs_cut = Vs.empty() ? Vs_temp : LRI_CV_Tools::add(Vs_cut, Vs_temp); + + if(PARAM.inp.cal_force || PARAM.inp.cal_stress) + { + std::map, Ndim>>> + dVs_temp = this->exx_objs[settings_list.first].cv.cal_dVs(ucell, + list_As_Vs.first, list_As_Vs.second[0], + {{"writable_dVws",true}}); + this->exx_objs[settings_list.first].cv.dVws = LRI_CV_Tools::get_dCVws(ucell,dVs_temp); + dVs = dVs.empty() ? dVs_temp : LRI_CV_Tools::add(dVs, dVs_temp); + } + } + + if (write_cv && GlobalV::MY_RANK == 0) + { + LRI_CV_Tools::write_Vs_abf(Vs_cut, PARAM.globalv.global_out_dir + "Vs_cut"); + } + this->exx_lri.set_Vs(std::move(Vs_cut), this->info.V_threshold); + + if(PARAM.inp.cal_force || PARAM.inp.cal_stress) + { + std::map,Ndim>>> dVs + = this->exx_objs[coulomb_method].cv.cal_dVs(ucell, + list_As_Vs.first, list_As_Vs.second[0], + {{"writable_dVws",true}}); + this->exx_objs[coulomb_method].cv.dVws = LRI_CV_Tools::get_dCVws(ucell,dVs); + + std::array>>,Ndim> dVs_order + = LRI_CV_Tools::change_order(std::move(dVs)); + this->exx_lri.set_dVs(std::move(dVs_order), this->info.V_grad_threshold); + if(PARAM.inp.cal_stress) + { + std::array>>,3>,3> dVRs + = LRI_CV_Tools::cal_dMRs(ucell,dVs_order); + this->exx_lri.set_dVRs(std::move(dVRs), this->info.V_grad_R_threshold); + } + } + + const std::array period_Cs = LRI_CV_Tools::cal_latvec_range(2, ucell,orb_cutoff_); + const std::pair, std::vector>>>> + list_As_Cs = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Cs, 2, false); + std::pair>>, + std::map,3>>>> + Cs_dCs = this->exx_objs[coulomb_method].cv.cal_Cs_dCs(ucell, + list_As_Cs.first, list_As_Cs.second[0], + {{"cal_dC",PARAM.inp.cal_force||PARAM.inp.cal_stress}, + {"writable_Cws",true}, + {"writable_dCws",true}, + {"writable_Vws",false}, + {"writable_dVws",false}}); + Cs = std::get<0>(Cs_dCs); + this->exx_objs[coulomb_method].cv.Cws = LRI_CV_Tools::get_CVws(ucell,Cs); + if(write_cv && GlobalV::MY_RANK==0) + { + LRI_CV_Tools::write_Cs_ao(Cs, PARAM.globalv.global_out_dir + "Cs"); + } + this->exx_lri.set_Cs(Cs, this->info.C_threshold); + + if(PARAM.inp.cal_force || PARAM.inp.cal_stress) + { + std::map,3>>>& dCs = std::get<1>(Cs_dCs); + this->exx_objs[coulomb_method].cv.dCws = LRI_CV_Tools::get_dCVws(ucell,dCs); + std::array>>,Ndim> dCs_order + = LRI_CV_Tools::change_order(std::move(dCs)); + this->exx_lri.set_dCs(std::move(dCs_order), this->info.C_grad_threshold); + if(PARAM.inp.cal_stress) + { + std::array>>,3>,3> dCRs + = LRI_CV_Tools::cal_dMRs(ucell,dCs_order); + this->exx_lri.set_dCRs(std::move(dCRs), this->info.C_grad_R_threshold); + } + } + ModuleBase::timer::end("Exx_LRI", "cal_cut_coulomb_cs"); } template void Exx_LRI::cal_ewald_coulomb( - std::map>>& Vs_full, - std::map>>& Cs, - const UnitCell& ucell, - const bool write_cv) + std::map>>& Vs_full, + std::map>>& Cs, + const UnitCell& ucell, + const bool write_cv) { - ModuleBase::TITLE("Exx_LRI", "cal_ewald_coulomb"); - ModuleBase::timer::start("Exx_LRI", "cal_ewald_coulomb"); - - std::vector atoms(ucell.nat); - for (int iat = 0; iat < ucell.nat; ++iat) - atoms[iat] = iat; - std::map atoms_pos; - for (int iat = 0; iat < ucell.nat; ++iat) - atoms_pos[iat] = RI_Util::Vector3_to_array3(ucell.atoms[ucell.iat2it[iat]].tau[ucell.iat2ia[iat]]); - const std::array latvec = { - RI_Util::Vector3_to_array3(ucell.a1), - RI_Util::Vector3_to_array3(ucell.a2), - RI_Util::Vector3_to_array3(ucell.a3)}; - const std::array period = {this->p_kv->nmp[0], this->p_kv->nmp[1], this->p_kv->nmp[2]}; - - this->exx_lri.set_parallel(this->mpi_comm, atoms_pos, latvec, period); - - // std::max(3) for gamma_only, list_A2 should contain cell {-1,0,1}. In the future distribute will be neighbour. - const std::array period_Vs - = LRI_CV_Tools::cal_latvec_range(1 + this->info.ccp_rmesh_times, ucell, orb_cutoff_); - const std::pair, std::vector>>>> list_As_Vs - = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Vs, 2, false); - - std::map, Ndim>>> dVs; - for (const auto& settings_list: this->coulomb_settings) - { - if (!settings_list.second.first) - continue; - std::map>> Vs_temp - = this->exx_objs[settings_list.first].cv.cal_Vs( - ucell, - list_As_Vs.first, - list_As_Vs.second[0], - {{"writable_Vws", true}}); - this->exx_objs[settings_list.first].cv.Vws = LRI_CV_Tools::get_CVws(ucell, Vs_temp); - - // ======rotate ABFs begin====== - int flag = 0; - for (const auto& IJRc: this->exx_objs[settings_list.first].cv.Vws) - { - const TA& I = IJRc.first; - const auto& JRc = IJRc.second; - for (const auto& JRc_tensor: JRc) - { - const TA& J = JRc_tensor.first; - const auto Rc = JRc_tensor.second; - for (const auto& Rc_tensor: Rc) - { - const auto& R = Rc_tensor.first; - flag += 1; - } - } - } - std::cout << "Coulomb: number of atom-pairs inside atomic overlap is " << flag << ". " << std::endl; - if (this->info.coul_moment == true) - { - double hf_Rcut = std::pow(0.75 * this->p_kv->get_nkstot_nospin() * ucell.omega / (ModuleBase::PI), 1.0 / 3.0); - // To cal Cs, we still cal all Vs(R) in r space - // moment_abfs->cal_VR(ucell, - // this->abfs, - // list_As_Vs, - // orb_cutoff_, - // hf_Rcut, - // this->exx_objs[settings_list.first].cv, - // Vs_full); - delete moment_abfs; - moment_abfs = nullptr; - malloc_trim(0); - } - - flag = 0; - for (const auto& IJRc: this->exx_objs[settings_list.first].cv.Vws) - { - const auto& JRc = IJRc.second; - for (const auto& JRc_tensor: JRc) - { - const auto Rc = JRc_tensor.second; - for (const auto& Rc_tensor: Rc) - { - flag += 1; - } - } - } - std::cout << "Coulomb: number of all atom-pairs is " << flag << ". " << std::endl; - // ======rotate ABFs end====== - - if (settings_list.first == Conv_Coulomb_Pot_K::Coulomb_Method::Ewald) - { - this->exx_objs[settings_list.first].evq.init_ions(ucell, period_Vs); - const auto& coulomb_param = settings_list.second.second; - std::map>> Vs_ewald; - for (const auto& param_list: coulomb_param) - { - std::map>> Vs_ewald_temp; - switch (param_list.first) - { - case Conv_Coulomb_Pot_K::Coulomb_Type::Fock: { - double chi - = this->exx_objs[settings_list.first].evq.get_singular_chi(ucell, param_list.second, 2.0); - Vs_ewald_temp = this->exx_objs[settings_list.first].evq.cal_Vs(ucell, chi, Vs_temp); - break; - } - default: { - throw std::invalid_argument(std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } - } - // Vs_temp cannot be covered here - Vs_ewald = Vs_ewald.empty() ? Vs_ewald_temp : LRI_CV_Tools::add(Vs_ewald, Vs_ewald_temp); - } - Vs_temp = Vs_ewald; - } - - Vs_full = Vs.empty() ? Vs_temp : LRI_CV_Tools::add(Vs_full, Vs_temp); - } - - if (write_cv && GlobalV::MY_RANK == 0) - { - LRI_CV_Tools::write_Vs_abf(Vs_full, PARAM.globalv.global_out_dir + "Vs_full"); - } - // this->exx_lri.set_Vs(std::move(Vs_full), this->info.V_threshold); - - // const std::array period_Cs = LRI_CV_Tools::cal_latvec_range(2, ucell,orb_cutoff_); - // const std::pair, std::vector>>>> - // list_As_Cs = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Cs, 2, false); - // std::pair>>, - // std::map,3>>>> - // Cs_dCs = this->exx_objs[coulomb_method].cv.cal_Cs_dCs(ucell, - // list_As_Cs.first, list_As_Cs.second[0], - // {{"cal_dC",PARAM.inp.cal_force||PARAM.inp.cal_stress}, - // {"writable_Cws",true}, - // {"writable_dCws",true}, - // {"writable_Vws",false}, - // {"writable_dVws",false}}); - // Cs = std::get<0>(Cs_dCs); - // this->exx_objs[coulomb_method].cv.Cws = LRI_CV_Tools::get_CVws(ucell,Cs); - // if(write_cv && GlobalV::MY_RANK==0) - // { - // LRI_CV_Tools::write_Cs_ao(Cs, PARAM.globalv.global_out_dir + "Cs"); - // } - // this->exx_lri.set_Cs(Cs, this->info.C_threshold); - ModuleBase::timer::end("Exx_LRI", "cal_ewald_coulomb"); + ModuleBase::TITLE("Exx_LRI", "cal_ewald_coulomb"); + ModuleBase::timer::start("Exx_LRI", "cal_ewald_coulomb"); + + std::vector atoms(ucell.nat); + for (int iat = 0; iat < ucell.nat; ++iat) + atoms[iat] = iat; + std::map atoms_pos; + for (int iat = 0; iat < ucell.nat; ++iat) + atoms_pos[iat] = RI_Util::Vector3_to_array3(ucell.atoms[ucell.iat2it[iat]].tau[ucell.iat2ia[iat]]); + const std::array latvec = { + RI_Util::Vector3_to_array3(ucell.a1), + RI_Util::Vector3_to_array3(ucell.a2), + RI_Util::Vector3_to_array3(ucell.a3)}; + const std::array period = {this->p_kv->nmp[0], this->p_kv->nmp[1], this->p_kv->nmp[2]}; + + this->exx_lri.set_parallel(this->mpi_comm, atoms_pos, latvec, period); + + // std::max(3) for gamma_only, list_A2 should contain cell {-1,0,1}. In the future distribute will be neighbour. + const std::array period_Vs + = LRI_CV_Tools::cal_latvec_range(1 + this->info.ccp_rmesh_times, ucell, orb_cutoff_); + const std::pair, std::vector>>>> list_As_Vs + = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Vs, 2, false); + + std::map, Ndim>>> dVs; + for (const auto& settings_list: this->coulomb_settings) + { + if (!settings_list.second.first) + continue; + std::map>> Vs_temp + = this->exx_objs[settings_list.first].cv.cal_Vs( + ucell, + list_As_Vs.first, + list_As_Vs.second[0], + {{"writable_Vws", true}}); + this->exx_objs[settings_list.first].cv.Vws = LRI_CV_Tools::get_CVws(ucell, Vs_temp); + + // ======rotate ABFs begin====== + int flag = 0; + for (const auto& IJRc: this->exx_objs[settings_list.first].cv.Vws) + { + const TA& I = IJRc.first; + const auto& JRc = IJRc.second; + for (const auto& JRc_tensor: JRc) + { + const TA& J = JRc_tensor.first; + const auto Rc = JRc_tensor.second; + for (const auto& Rc_tensor: Rc) + { + const auto& R = Rc_tensor.first; + flag += 1; + } + } + } + std::cout << "Coulomb: number of atom-pairs inside atomic overlap is " << flag << ". " << std::endl; + if (this->info.coul_moment == true) + { + double hf_Rcut = std::pow(0.75 * this->p_kv->get_nkstot_nospin() * ucell.omega / (ModuleBase::PI), 1.0 / 3.0); + // To cal Cs, we still cal all Vs(R) in r space + // moment_abfs->cal_VR(ucell, + // this->abfs, + // list_As_Vs, + // orb_cutoff_, + // hf_Rcut, + // this->exx_objs[settings_list.first].cv, + // Vs_full); + delete moment_abfs; + moment_abfs = nullptr; + malloc_trim(0); + } + + flag = 0; + for (const auto& IJRc: this->exx_objs[settings_list.first].cv.Vws) + { + const auto& JRc = IJRc.second; + for (const auto& JRc_tensor: JRc) + { + const auto Rc = JRc_tensor.second; + for (const auto& Rc_tensor: Rc) + { + flag += 1; + } + } + } + std::cout << "Coulomb: number of all atom-pairs is " << flag << ". " << std::endl; + // ======rotate ABFs end====== + + if (settings_list.first == Conv_Coulomb_Pot_K::Coulomb_Method::Ewald) + { + this->exx_objs[settings_list.first].evq.init_ions(ucell, period_Vs); + const auto& coulomb_param = settings_list.second.second; + std::map>> Vs_ewald; + for (const auto& param_list: coulomb_param) + { + std::map>> Vs_ewald_temp; + switch (param_list.first) + { + case Conv_Coulomb_Pot_K::Coulomb_Type::Fock: { + double chi + = this->exx_objs[settings_list.first].evq.get_singular_chi(ucell, param_list.second, 2.0); + Vs_ewald_temp = this->exx_objs[settings_list.first].evq.cal_Vs(ucell, chi, Vs_temp); + break; + } + default: { + throw std::invalid_argument(std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } + } + // Vs_temp cannot be covered here + Vs_ewald = Vs_ewald.empty() ? Vs_ewald_temp : LRI_CV_Tools::add(Vs_ewald, Vs_ewald_temp); + } + Vs_temp = Vs_ewald; + } + + Vs_full = Vs.empty() ? Vs_temp : LRI_CV_Tools::add(Vs_full, Vs_temp); + } + + if (write_cv && GlobalV::MY_RANK == 0) + { + LRI_CV_Tools::write_Vs_abf(Vs_full, PARAM.globalv.global_out_dir + "Vs_full"); + } + // this->exx_lri.set_Vs(std::move(Vs_full), this->info.V_threshold); + + // const std::array period_Cs = LRI_CV_Tools::cal_latvec_range(2, ucell,orb_cutoff_); + // const std::pair, std::vector>>>> + // list_As_Cs = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Cs, 2, false); + // std::pair>>, + // std::map,3>>>> + // Cs_dCs = this->exx_objs[coulomb_method].cv.cal_Cs_dCs(ucell, + // list_As_Cs.first, list_As_Cs.second[0], + // {{"cal_dC",PARAM.inp.cal_force||PARAM.inp.cal_stress}, + // {"writable_Cws",true}, + // {"writable_dCws",true}, + // {"writable_Vws",false}, + // {"writable_dVws",false}}); + // Cs = std::get<0>(Cs_dCs); + // this->exx_objs[coulomb_method].cv.Cws = LRI_CV_Tools::get_CVws(ucell,Cs); + // if(write_cv && GlobalV::MY_RANK==0) + // { + // LRI_CV_Tools::write_Cs_ao(Cs, PARAM.globalv.global_out_dir + "Cs"); + // } + // this->exx_lri.set_Cs(Cs, this->info.C_threshold); + ModuleBase::timer::end("Exx_LRI", "cal_ewald_coulomb"); } - #endif + #endif template void Exx_LRI::cal_cut_coulomb_cs( - std::map>>& Vs_cut, - std::map>>& Cs, - const UnitCell& ucell, - const bool write_cv) + std::map>>& Vs_cut, + std::map>>& Cs, + const UnitCell& ucell, + const bool write_cv) { - ModuleBase::TITLE("Exx_LRI", "cal_cut_coulomb_cs"); - ModuleBase::timer::start("Exx_LRI", "cal_cut_coulomb_cs"); - - std::vector atoms(ucell.nat); - for (int iat = 0; iat < ucell.nat; ++iat) - { - atoms[iat] = iat; - } - std::map atoms_pos; - for (int iat = 0; iat < ucell.nat; ++iat) - { - atoms_pos[iat] = RI_Util::Vector3_to_array3(ucell.atoms[ucell.iat2it[iat]].tau[ucell.iat2ia[iat]]); - } - const std::array latvec = { - RI_Util::Vector3_to_array3(ucell.a1), - RI_Util::Vector3_to_array3(ucell.a2), - RI_Util::Vector3_to_array3(ucell.a3)}; - const std::array period = {this->p_kv->nmp[0], this->p_kv->nmp[1], this->p_kv->nmp[2]}; - - this->exx_lri.set_parallel(this->mpi_comm, atoms_pos, latvec, period); - - const auto center2_method = Conv_Coulomb_Pot_K::Coulomb_Method::Center2; - auto center2_obj_it = this->exx_objs.find(center2_method); - if (center2_obj_it == this->exx_objs.end()) - { - throw std::invalid_argument(std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } - - const std::array period_Vs - = LRI_CV_Tools::cal_latvec_range(1 + this->info.ccp_rmesh_times, ucell, orb_cutoff_); - const std::pair, std::vector>>>> list_As_Vs - = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Vs, 2, false); - - Vs_cut = center2_obj_it->second.cv.cal_Vs( - ucell, - list_As_Vs.first, - list_As_Vs.second[0], - {{"writable_Vws", true}}); - center2_obj_it->second.cv.Vws = LRI_CV_Tools::get_CVws(ucell, Vs_cut); - if (write_cv && GlobalV::MY_RANK == 0) - { - LRI_CV_Tools::write_Vs_abf(Vs_cut, PARAM.globalv.global_out_dir + "Vs_cut"); - } - this->exx_lri.set_Vs(Vs_cut, this->info.V_threshold); - - const std::array period_Cs = LRI_CV_Tools::cal_latvec_range(2, ucell, orb_cutoff_); - const std::pair, std::vector>>>> list_As_Cs - = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Cs, 2, false); - std::pair>>, - std::map, 3>>>> - Cs_dCs = center2_obj_it->second.cv.cal_Cs_dCs( - ucell, - list_As_Cs.first, - list_As_Cs.second[0], - {{"cal_dC", false}, - {"writable_Cws", true}, - {"writable_dCws", true}, - {"writable_Vws", false}, - {"writable_dVws", false}}); - Cs = std::get<0>(Cs_dCs); - center2_obj_it->second.cv.Cws = LRI_CV_Tools::get_CVws(ucell, Cs); - if (write_cv && GlobalV::MY_RANK == 0) - { - LRI_CV_Tools::write_Cs_ao(Cs, PARAM.globalv.global_out_dir + "Cs"); - } - this->exx_lri.set_Cs(Cs, this->info.C_threshold); - - ModuleBase::timer::end("Exx_LRI", "cal_cut_coulomb_cs"); + ModuleBase::TITLE("Exx_LRI", "cal_cut_coulomb_cs"); + ModuleBase::timer::start("Exx_LRI", "cal_cut_coulomb_cs"); + + std::vector atoms(ucell.nat); + for (int iat = 0; iat < ucell.nat; ++iat) + { + atoms[iat] = iat; + } + std::map atoms_pos; + for (int iat = 0; iat < ucell.nat; ++iat) + { + atoms_pos[iat] = RI_Util::Vector3_to_array3(ucell.atoms[ucell.iat2it[iat]].tau[ucell.iat2ia[iat]]); + } + const std::array latvec = { + RI_Util::Vector3_to_array3(ucell.a1), + RI_Util::Vector3_to_array3(ucell.a2), + RI_Util::Vector3_to_array3(ucell.a3)}; + const std::array period = {this->p_kv->nmp[0], this->p_kv->nmp[1], this->p_kv->nmp[2]}; + + this->exx_lri.set_parallel(this->mpi_comm, atoms_pos, latvec, period); + + const auto center2_method = Conv_Coulomb_Pot_K::Coulomb_Method::Center2; + auto center2_obj_it = this->exx_objs.find(center2_method); + if (center2_obj_it == this->exx_objs.end()) + { + throw std::invalid_argument(std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } + + const std::array period_Vs + = LRI_CV_Tools::cal_latvec_range(1 + this->info.ccp_rmesh_times, ucell, orb_cutoff_); + const std::pair, std::vector>>>> list_As_Vs + = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Vs, 2, false); + + Vs_cut = center2_obj_it->second.cv.cal_Vs( + ucell, + list_As_Vs.first, + list_As_Vs.second[0], + {{"writable_Vws", true}}); + center2_obj_it->second.cv.Vws = LRI_CV_Tools::get_CVws(ucell, Vs_cut); + if (write_cv && GlobalV::MY_RANK == 0) + { + LRI_CV_Tools::write_Vs_abf(Vs_cut, PARAM.globalv.global_out_dir + "Vs_cut"); + } + this->exx_lri.set_Vs(Vs_cut, this->info.V_threshold); + + const std::array period_Cs = LRI_CV_Tools::cal_latvec_range(2, ucell, orb_cutoff_); + const std::pair, std::vector>>>> list_As_Cs + = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Cs, 2, false); + std::pair>>, + std::map, 3>>>> + Cs_dCs = center2_obj_it->second.cv.cal_Cs_dCs( + ucell, + list_As_Cs.first, + list_As_Cs.second[0], + {{"cal_dC", false}, + {"writable_Cws", true}, + {"writable_dCws", true}, + {"writable_Vws", false}, + {"writable_dVws", false}}); + Cs = std::get<0>(Cs_dCs); + center2_obj_it->second.cv.Cws = LRI_CV_Tools::get_CVws(ucell, Cs); + if (write_cv && GlobalV::MY_RANK == 0) + { + LRI_CV_Tools::write_Cs_ao(Cs, PARAM.globalv.global_out_dir + "Cs"); + } + this->exx_lri.set_Cs(Cs, this->info.C_threshold); + + ModuleBase::timer::end("Exx_LRI", "cal_cut_coulomb_cs"); } template void Exx_LRI::cal_ewald_coulomb( - std::map>>& Vs_full, - std::map>>& Cs, - const UnitCell& ucell, - const bool write_cv) + std::map>>& Vs_full, + std::map>>& Cs, + const UnitCell& ucell, + const bool write_cv) { - ModuleBase::TITLE("Exx_LRI", "cal_ewald_coulomb"); - ModuleBase::timer::start("Exx_LRI", "cal_ewald_coulomb"); - - std::vector atoms(ucell.nat); - for (int iat = 0; iat < ucell.nat; ++iat) - { - atoms[iat] = iat; - } - std::map atoms_pos; - for (int iat = 0; iat < ucell.nat; ++iat) - { - atoms_pos[iat] = RI_Util::Vector3_to_array3(ucell.atoms[ucell.iat2it[iat]].tau[ucell.iat2ia[iat]]); - } - const std::array latvec = { - RI_Util::Vector3_to_array3(ucell.a1), - RI_Util::Vector3_to_array3(ucell.a2), - RI_Util::Vector3_to_array3(ucell.a3)}; - const std::array period = {this->p_kv->nmp[0], this->p_kv->nmp[1], this->p_kv->nmp[2]}; - - this->exx_lri.set_parallel(this->mpi_comm, atoms_pos, latvec, period); - - const std::array period_Vs - = LRI_CV_Tools::cal_latvec_range(1 + this->info.ccp_rmesh_times, ucell, orb_cutoff_); - const std::pair, std::vector>>>> list_As_Vs - = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Vs, 2, false); - - for (const auto& settings_list : this->coulomb_settings) - { - std::map>> Vs_temp - = this->exx_objs[settings_list.first].cv.cal_Vs( - ucell, - list_As_Vs.first, - list_As_Vs.second[0], - {{"writable_Vws", true}}); - this->exx_objs[settings_list.first].cv.Vws = LRI_CV_Tools::get_CVws(ucell, Vs_temp); - - if (settings_list.first == Conv_Coulomb_Pot_K::Coulomb_Method::Ewald) - { - this->exx_objs[settings_list.first].evq.init_ions(ucell, period_Vs); - std::map>> Vs_ewald; - for (const auto& param_list : settings_list.second.second) - { - std::map>> Vs_ewald_temp; - switch (param_list.first) - { - case Conv_Coulomb_Pot_K::Coulomb_Type::Fock: - { - double chi = this->exx_objs[settings_list.first].evq.get_singular_chi(ucell, param_list.second, 2.0); - Vs_ewald_temp = this->exx_objs[settings_list.first].evq.cal_Vs(ucell, chi, Vs_temp); - break; - } - default: - { - throw std::invalid_argument(std::string(__FILE__) + " line " + std::to_string(__LINE__)); - } - } - Vs_ewald = Vs_ewald.empty() ? Vs_ewald_temp : LRI_CV_Tools::add(Vs_ewald, Vs_ewald_temp); - } - Vs_temp = Vs_ewald; - } - - Vs_full = Vs_full.empty() ? Vs_temp : LRI_CV_Tools::add(Vs_full, Vs_temp); - } - - if (write_cv && GlobalV::MY_RANK == 0) - { - LRI_CV_Tools::write_Vs_abf(Vs_full, PARAM.globalv.global_out_dir + "Vs_full"); - } - - Cs.clear(); - ModuleBase::timer::end("Exx_LRI", "cal_ewald_coulomb"); + ModuleBase::TITLE("Exx_LRI", "cal_ewald_coulomb"); + ModuleBase::timer::start("Exx_LRI", "cal_ewald_coulomb"); + + std::vector atoms(ucell.nat); + for (int iat = 0; iat < ucell.nat; ++iat) + { + atoms[iat] = iat; + } + std::map atoms_pos; + for (int iat = 0; iat < ucell.nat; ++iat) + { + atoms_pos[iat] = RI_Util::Vector3_to_array3(ucell.atoms[ucell.iat2it[iat]].tau[ucell.iat2ia[iat]]); + } + const std::array latvec = { + RI_Util::Vector3_to_array3(ucell.a1), + RI_Util::Vector3_to_array3(ucell.a2), + RI_Util::Vector3_to_array3(ucell.a3)}; + const std::array period = {this->p_kv->nmp[0], this->p_kv->nmp[1], this->p_kv->nmp[2]}; + + this->exx_lri.set_parallel(this->mpi_comm, atoms_pos, latvec, period); + + const std::array period_Vs + = LRI_CV_Tools::cal_latvec_range(1 + this->info.ccp_rmesh_times, ucell, orb_cutoff_); + const std::pair, std::vector>>>> list_As_Vs + = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Vs, 2, false); + + for (const auto& settings_list : this->coulomb_settings) + { + std::map>> Vs_temp + = this->exx_objs[settings_list.first].cv.cal_Vs( + ucell, + list_As_Vs.first, + list_As_Vs.second[0], + {{"writable_Vws", true}}); + this->exx_objs[settings_list.first].cv.Vws = LRI_CV_Tools::get_CVws(ucell, Vs_temp); + + if (settings_list.first == Conv_Coulomb_Pot_K::Coulomb_Method::Ewald) + { + this->exx_objs[settings_list.first].evq.init_ions(ucell, period_Vs); + std::map>> Vs_ewald; + for (const auto& param_list : settings_list.second.second) + { + std::map>> Vs_ewald_temp; + switch (param_list.first) + { + case Conv_Coulomb_Pot_K::Coulomb_Type::Fock: + { + double chi = this->exx_objs[settings_list.first].evq.get_singular_chi(ucell, param_list.second, 2.0); + Vs_ewald_temp = this->exx_objs[settings_list.first].evq.cal_Vs(ucell, chi, Vs_temp); + break; + } + default: + { + throw std::invalid_argument(std::string(__FILE__) + " line " + std::to_string(__LINE__)); + } + } + Vs_ewald = Vs_ewald.empty() ? Vs_ewald_temp : LRI_CV_Tools::add(Vs_ewald, Vs_ewald_temp); + } + Vs_temp = Vs_ewald; + } + + Vs_full = Vs_full.empty() ? Vs_temp : LRI_CV_Tools::add(Vs_full, Vs_temp); + } + + if (write_cv && GlobalV::MY_RANK == 0) + { + LRI_CV_Tools::write_Vs_abf(Vs_full, PARAM.globalv.global_out_dir + "Vs_full"); + } + + Cs.clear(); + ModuleBase::timer::end("Exx_LRI", "cal_ewald_coulomb"); } template void Exx_LRI::cal_exx_elec(const std::vector>>>& Ds, - const UnitCell& ucell, - const Parallel_Orbitals& pv, - const ModuleSymmetry::Symmetry_rotation* p_symrot) + const UnitCell& ucell, + const Parallel_Orbitals& pv, + const ModuleSymmetry::Symmetry_rotation* p_symrot) { - ModuleBase::TITLE("Exx_LRI","cal_exx_elec"); - ModuleBase::timer::start("Exx_LRI", "cal_exx_elec"); - - const std::vector, std::set>> judge = RI_2D_Comm::get_2D_judge(ucell,pv); - - if(p_symrot) - { this->exx_lri.set_symmetry(true, p_symrot->get_irreducible_sector()); } - else - { this->exx_lri.set_symmetry(false, {}); } - - // (nspin=4) the spinor H(R) rotation mixes the 4 spin channels, so they cannot be rotated - // independently in the per-spin loop below; hand off to the SOC implementation. - if (p_symrot && PARAM.inp.nspin == 4) - { - this->cal_exx_elec_soc(Ds, ucell, judge, p_symrot); - this->exx_lri.set_symmetry(false, {}); - ModuleBase::timer::end("Exx_LRI", "cal_exx_elec"); - return; - } - - this->Hexxs.resize(PARAM.inp.nspin); - this->Eexx = 0; - for(int is=0; isexx_lri.set_Ds(Ds[is], this->info.dm_threshold, suffix); - this->exx_lri.cal_Hs({ "","",suffix }); - - if (!p_symrot) - { - this->Hexxs[is] = RI::Communicate_Tensors_Map_Judge::comm_map2_first( - this->mpi_comm, std::move(this->exx_lri.Hs), std::get<0>(judge[is]), std::get<1>(judge[is])); - } - else - { - // reduce but not repeat - auto Hs_a2D = this->exx_lri.post_2D.set_tensors_map2(this->exx_lri.Hs); - // rotate locally without repeat - Hs_a2D = p_symrot->restore_HR(ucell.symm, ucell.atoms, ucell.st, 'H', Hs_a2D); - // cal energy using full Hs without repeat - this->exx_lri.energy = this->exx_lri.post_2D.cal_energy( - this->exx_lri.post_2D.saves["Ds_" + suffix], - this->exx_lri.post_2D.set_tensors_map2(Hs_a2D)); - // get repeated full Hs for abacus - this->Hexxs[is] = RI::Communicate_Tensors_Map_Judge::comm_map2_first( - this->mpi_comm, std::move(Hs_a2D), std::get<0>(judge[is]), std::get<1>(judge[is])); - } - this->Eexx += std::real(this->exx_lri.energy); - post_process_Hexx(this->Hexxs[is]); - } - this->Eexx = post_process_Eexx(this->Eexx); - this->exx_lri.set_symmetry(false, {}); - ModuleBase::timer::end("Exx_LRI", "cal_exx_elec"); + ModuleBase::TITLE("Exx_LRI","cal_exx_elec"); + ModuleBase::timer::start("Exx_LRI", "cal_exx_elec"); + + const std::vector, std::set>> judge = RI_2D_Comm::get_2D_judge(ucell,pv); + + if(p_symrot) + { this->exx_lri.set_symmetry(true, p_symrot->get_irreducible_sector()); } + else + { this->exx_lri.set_symmetry(false, {}); } + + // (nspin=4) the spinor H(R) rotation mixes the 4 spin channels, so they cannot be rotated + // independently in the per-spin loop below; hand off to the SOC implementation. + if (p_symrot && PARAM.inp.nspin == 4) + { + this->cal_exx_elec_soc(Ds, ucell, judge, p_symrot); + this->exx_lri.set_symmetry(false, {}); + ModuleBase::timer::end("Exx_LRI", "cal_exx_elec"); + return; + } + + this->Hexxs.resize(PARAM.inp.nspin); + this->Eexx = 0; + for(int is=0; isexx_lri.set_Ds(Ds[is], this->info.dm_threshold, suffix); + this->exx_lri.cal_Hs({ "","",suffix }); + + if (!p_symrot) + { + this->Hexxs[is] = RI::Communicate_Tensors_Map_Judge::comm_map2_first( + this->mpi_comm, std::move(this->exx_lri.Hs), std::get<0>(judge[is]), std::get<1>(judge[is])); + } + else + { + // reduce but not repeat + auto Hs_a2D = this->exx_lri.post_2D.set_tensors_map2(this->exx_lri.Hs); + // rotate locally without repeat + Hs_a2D = p_symrot->restore_HR(ucell.symm, ucell.atoms, ucell.st, 'H', Hs_a2D); + // cal energy using full Hs without repeat + this->exx_lri.energy = this->exx_lri.post_2D.cal_energy( + this->exx_lri.post_2D.saves["Ds_" + suffix], + this->exx_lri.post_2D.set_tensors_map2(Hs_a2D)); + // get repeated full Hs for abacus + this->Hexxs[is] = RI::Communicate_Tensors_Map_Judge::comm_map2_first( + this->mpi_comm, std::move(Hs_a2D), std::get<0>(judge[is]), std::get<1>(judge[is])); + } + this->Eexx += std::real(this->exx_lri.energy); + post_process_Hexx(this->Hexxs[is]); + } + this->Eexx = post_process_Eexx(this->Eexx); + this->exx_lri.set_symmetry(false, {}); + ModuleBase::timer::end("Exx_LRI", "cal_exx_elec"); } template void Exx_LRI::cal_exx_elec_soc( - const std::vector>>>& Ds, - const UnitCell& ucell, - const std::vector, std::set>>& judge, - const ModuleSymmetry::Symmetry_rotation* p_symrot) + const std::vector>>>& Ds, + const UnitCell& ucell, + const std::vector, std::set>>& judge, + const ModuleSymmetry::Symmetry_rotation* p_symrot) { - ModuleBase::TITLE("Exx_LRI", "cal_exx_elec_soc"); - this->Hexxs.resize(PARAM.inp.nspin); // nspin==4 - this->Eexx = 0; - - // pass 1: compute the irreducible-sector Hs of all 4 spin channels. - // distinct suffix per channel keeps all 4 "Ds_*" saves alive for the energy in pass 3. - std::array>>, 4> Hs_irr; - std::array suffix; - for (int is = 0; is < 4; ++is) - { - suffix[is] = std::to_string(is); - this->exx_lri.set_Ds(Ds[is], this->info.dm_threshold, suffix[is]); - this->exx_lri.cal_Hs({ "","",suffix[is] }); - Hs_irr[is] = this->exx_lri.post_2D.set_tensors_map2(this->exx_lri.Hs); - } - - // pass 2: spinor-coupled rotation of the 4 channels from the irreducible sector to the full BZ - std::array>>, 4> Hs_full = - p_symrot->restore_HR_nspin4(ucell.symm, ucell.atoms, ucell.st, 'H', Hs_irr); - - // pass 3: per-channel energy (full Hs, no repeat), then gather the repeated full Hs for abacus - for (int is = 0; is < 4; ++is) - { - this->exx_lri.energy = this->exx_lri.post_2D.cal_energy( - this->exx_lri.post_2D.saves["Ds_" + suffix[is]], - this->exx_lri.post_2D.set_tensors_map2(Hs_full[is])); - this->Hexxs[is] = RI::Communicate_Tensors_Map_Judge::comm_map2_first( - this->mpi_comm, std::move(Hs_full[is]), std::get<0>(judge[is]), std::get<1>(judge[is])); - this->Eexx += std::real(this->exx_lri.energy); - post_process_Hexx(this->Hexxs[is]); - } - this->Eexx = post_process_Eexx(this->Eexx); + ModuleBase::TITLE("Exx_LRI", "cal_exx_elec_soc"); + this->Hexxs.resize(PARAM.inp.nspin); // nspin==4 + this->Eexx = 0; + + // pass 1: compute the irreducible-sector Hs of all 4 spin channels. + // distinct suffix per channel keeps all 4 "Ds_*" saves alive for the energy in pass 3. + std::array>>, 4> Hs_irr; + std::array suffix; + for (int is = 0; is < 4; ++is) + { + suffix[is] = std::to_string(is); + this->exx_lri.set_Ds(Ds[is], this->info.dm_threshold, suffix[is]); + this->exx_lri.cal_Hs({ "","",suffix[is] }); + Hs_irr[is] = this->exx_lri.post_2D.set_tensors_map2(this->exx_lri.Hs); + } + + // pass 2: spinor-coupled rotation of the 4 channels from the irreducible sector to the full BZ + std::array>>, 4> Hs_full = + p_symrot->restore_HR_nspin4(ucell.symm, ucell.atoms, ucell.st, 'H', Hs_irr); + + // pass 3: per-channel energy (full Hs, no repeat), then gather the repeated full Hs for abacus + for (int is = 0; is < 4; ++is) + { + this->exx_lri.energy = this->exx_lri.post_2D.cal_energy( + this->exx_lri.post_2D.saves["Ds_" + suffix[is]], + this->exx_lri.post_2D.set_tensors_map2(Hs_full[is])); + this->Hexxs[is] = RI::Communicate_Tensors_Map_Judge::comm_map2_first( + this->mpi_comm, std::move(Hs_full[is]), std::get<0>(judge[is]), std::get<1>(judge[is])); + this->Eexx += std::real(this->exx_lri.energy); + post_process_Hexx(this->Hexxs[is]); + } + this->Eexx = post_process_Eexx(this->Eexx); } template void Exx_LRI::post_process_Hexx( std::map>> &Hexxs_io ) const { - ModuleBase::TITLE("Exx_LRI","post_process_Hexx"); - constexpr Tdata frac = -1 * 2; // why? Hartree to Ry? - const std::function&)> - multiply_frac = [&frac](RI::Tensor &t) - { t = t*frac; }; - RI::Map_Operator::for_each( Hexxs_io, multiply_frac ); + ModuleBase::TITLE("Exx_LRI","post_process_Hexx"); + constexpr Tdata frac = -1 * 2; // why? Hartree to Ry? + const std::function&)> + multiply_frac = [&frac](RI::Tensor &t) + { t = t*frac; }; + RI::Map_Operator::for_each( Hexxs_io, multiply_frac ); } template double Exx_LRI::post_process_Eexx(const double& Eexx_in) const { - ModuleBase::TITLE("Exx_LRI","post_process_Eexx"); - const double SPIN_multiple = std::map{ {1,2}, {2,1}, {4,1} }.at(PARAM.inp.nspin); // why? - const double frac = -SPIN_multiple; - return frac * Eexx_in; + ModuleBase::TITLE("Exx_LRI","post_process_Eexx"); + const double SPIN_multiple = std::map{ {1,2}, {2,1}, {4,1} }.at(PARAM.inp.nspin); // why? + const double frac = -SPIN_multiple; + return frac * Eexx_in; } /* post_process_old { - // D - const std::map SPIN_multiple = {{1,0.5}, {2,1}, {4,1}}; // ??? - DR *= SPIN_multiple.at(NSPIN); + // D + const std::map SPIN_multiple = {{1,0.5}, {2,1}, {4,1}}; // ??? + DR *= SPIN_multiple.at(NSPIN); - // H - HR *= -2; + // H + HR *= -2; - // E - const std::map SPIN_multiple = {{1,2}, {2,1}, {4,1}}; // ??? - energy *= SPIN_multiple.at(PARAM.inp.nspin); // ? - energy /= 2; // /2 for Ry + // E + const std::map SPIN_multiple = {{1,2}, {2,1}, {4,1}}; // ??? + energy *= SPIN_multiple.at(PARAM.inp.nspin); // ? + energy /= 2; // /2 for Ry } */ template void Exx_LRI::cal_exx_force(const int& nat) { - ModuleBase::TITLE("Exx_LRI","cal_exx_force"); - ModuleBase::timer::start("Exx_LRI", "cal_exx_force"); - - this->force_exx.create(nat, Ndim); - for(int is=0; isexx_lri.cal_force({"","",std::to_string(is),"",""}); - for(std::size_t idim=0; idimexx_lri.force[idim]) { - this->force_exx(force_item.first, idim) += std::real(force_item.second); - } } - } - - const double SPIN_multiple = std::map{{1,2}, {2,1}, {4,1}}.at(PARAM.inp.nspin); // why? - const double frac = -2 * SPIN_multiple; // why? - this->force_exx *= frac; - ModuleBase::timer::end("Exx_LRI", "cal_exx_force"); + ModuleBase::TITLE("Exx_LRI","cal_exx_force"); + ModuleBase::timer::start("Exx_LRI", "cal_exx_force"); + + this->force_exx.create(nat, Ndim); + for(int is=0; isexx_lri.cal_force({"","",std::to_string(is),"",""}); + for(std::size_t idim=0; idimexx_lri.force[idim]) { + this->force_exx(force_item.first, idim) += std::real(force_item.second); + } } + } + + const double SPIN_multiple = std::map{{1,2}, {2,1}, {4,1}}.at(PARAM.inp.nspin); // why? + const double frac = -2 * SPIN_multiple; // why? + this->force_exx *= frac; + ModuleBase::timer::end("Exx_LRI", "cal_exx_force"); } template void Exx_LRI::cal_exx_stress(const double& omega, const double& lat0) { - ModuleBase::TITLE("Exx_LRI","cal_exx_stress"); - ModuleBase::timer::start("Exx_LRI", "cal_exx_stress"); - - this->stress_exx.create(Ndim, Ndim); - for(int is=0; isexx_lri.cal_stress({"","",std::to_string(is),"",""}); - for(std::size_t idim0=0; idim0stress_exx(idim0,idim1) += std::real(this->exx_lri.stress(idim0,idim1)); - } } - } - - const double SPIN_multiple = std::map{{1,2}, {2,1}, {4,1}}.at(PARAM.inp.nspin); // why? - const double frac = 2 * SPIN_multiple / omega * lat0; // why? - this->stress_exx *= frac; - - ModuleBase::timer::end("Exx_LRI", "cal_exx_stress"); + ModuleBase::TITLE("Exx_LRI","cal_exx_stress"); + ModuleBase::timer::start("Exx_LRI", "cal_exx_stress"); + + this->stress_exx.create(Ndim, Ndim); + for(int is=0; isexx_lri.cal_stress({"","",std::to_string(is),"",""}); + for(std::size_t idim0=0; idim0stress_exx(idim0,idim1) += std::real(this->exx_lri.stress(idim0,idim1)); + } } + } + + const double SPIN_multiple = std::map{{1,2}, {2,1}, {4,1}}.at(PARAM.inp.nspin); // why? + const double frac = 2 * SPIN_multiple / omega * lat0; // why? + this->stress_exx *= frac; + + ModuleBase::timer::end("Exx_LRI", "cal_exx_stress"); } template @@ -1034,7 +1034,7 @@ void Exx_LRI::cal_exx_dHs(const std::vector::cal_exx_dHs(const std::vector std::vector> Exx_LRI::get_abfs_nchis() const { - std::vector> abfs_nchis; - for (const auto& abfs_T : this->abfs) - { - std::vector abfs_nchi_T; - for (const auto& abfs_L : abfs_T) - { abfs_nchi_T.push_back(abfs_L.size()); } - abfs_nchis.push_back(abfs_nchi_T); - } - return abfs_nchis; + std::vector> abfs_nchis; + for (const auto& abfs_T : this->abfs) + { + std::vector abfs_nchi_T; + for (const auto& abfs_L : abfs_T) + { abfs_nchi_T.push_back(abfs_L.size()); } + abfs_nchis.push_back(abfs_nchi_T); + } + return abfs_nchis; } */ diff --git a/source/source_lcao/module_ri/exx_lri_detail.h b/source/source_lcao/module_ri/exx_lri_detail.h index e72e3852dc3..5d1da32ffe2 100644 --- a/source/source_lcao/module_ri/exx_lri_detail.h +++ b/source/source_lcao/module_ri/exx_lri_detail.h @@ -18,8 +18,8 @@ #include #endif - class UnitCell; - class K_Vectors; + class UnitCell; + class K_Vectors; namespace ExxLriDetail { @@ -29,7 +29,7 @@ using CoulombParam inline void trim_malloc_cache() { #if defined(__GLIBC__) - malloc_trim(0); + malloc_trim(0); #endif } diff --git a/source/source_lcao/module_ri/exx_lri_interface.h b/source/source_lcao/module_ri/exx_lri_interface.h index e9b824b437d..5f0b9062377 100644 --- a/source/source_lcao/module_ri/exx_lri_interface.h +++ b/source/source_lcao/module_ri/exx_lri_interface.h @@ -121,9 +121,9 @@ class Exx_LRI_Interface void exx_iter_finish(const K_Vectors& kv, const UnitCell& ucell, hamilt::Hamilt& hamilt, - elecstate::ElecState& elec, - module_dm::DensityMatrix* dm, // mohan add 2025-11-04 - const Parallel_Orbitals& pv, + elecstate::ElecState& elec, + module_dm::DensityMatrix* dm, // mohan add 2025-11-04 + const Parallel_Orbitals& pv, Charge_Mixing& chgmix, const double& scf_ene_thr, int& iter, diff --git a/source/source_lcao/module_ri/exx_lri_interface.hpp b/source/source_lcao/module_ri/exx_lri_interface.hpp index f6c0f63c330..f2508b741a6 100644 --- a/source/source_lcao/module_ri/exx_lri_interface.hpp +++ b/source/source_lcao/module_ri/exx_lri_interface.hpp @@ -274,16 +274,16 @@ void Exx_LRI_Interface::exx_hamilt2rho(elecstate::ElecState& elec, con template void Exx_LRI_Interface::exx_iter_finish(const K_Vectors& kv, - const UnitCell& ucell, - hamilt::Hamilt& hamilt, - elecstate::ElecState& elec, - module_dm::DensityMatrix* dm, // mohan add 2025-11-04 - const Parallel_Orbitals& pv, - Charge_Mixing& chgmix, - const double& scf_ene_thr, - int& iter, - const int istep, - bool& conv_esolver) + const UnitCell& ucell, + hamilt::Hamilt& hamilt, + elecstate::ElecState& elec, + module_dm::DensityMatrix* dm, // mohan add 2025-11-04 + const Parallel_Orbitals& pv, + Charge_Mixing& chgmix, + const double& scf_ene_thr, + int& iter, + const int istep, + bool& conv_esolver) { ModuleBase::TITLE("Exx_LRI_Interface","exx_iter_finish"); if (GlobalC::restart.info_save.save_H && (this->two_level_step > 0 || istep > 0) diff --git a/source/source_lcao/module_ri/exx_opt_orb.cpp b/source/source_lcao/module_ri/exx_opt_orb.cpp index 645650134b6..2a1ce87dea8 100644 --- a/source/source_lcao/module_ri/exx_opt_orb.cpp +++ b/source/source_lcao/module_ri/exx_opt_orb.cpp @@ -13,410 +13,410 @@ #include void Exx_Opt_Orb::generate_matrix( - const Exx_Info_Opt_ABFs &info, - const K_Vectors &kv, - const UnitCell &ucell, - const LCAO_Orbitals &orb) const + const Exx_Info_Opt_ABFs &info, + const K_Vectors &kv, + const UnitCell &ucell, + const LCAO_Orbitals &orb) const { - ModuleBase::TITLE("Exx_Opt_Orb::generate_matrix"); + ModuleBase::TITLE("Exx_Opt_Orb::generate_matrix"); - auto judge_orbs_empty = [](const std::vector>> &orbs) -> bool - { - for(const auto &orb_t : orbs) { - for(const auto &orb_tl : orb_t) { - if(orb_tl.size()>0) { - return false; - }}} - return true; - }; + auto judge_orbs_empty = [](const std::vector>> &orbs) -> bool + { + for(const auto &orb_t : orbs) { + for(const auto &orb_tl : orb_t) { + if(orb_tl.size()>0) { + return false; + }}} + return true; + }; - std::vector>> - lcaos = Exx_Abfs::Construct_Orbs::change_orbs( orb, info.kmesh_times ); - Exx_Abfs::Construct_Orbs::filter_empty_orbs(lcaos); + std::vector>> + lcaos = Exx_Abfs::Construct_Orbs::change_orbs( orb, info.kmesh_times ); + Exx_Abfs::Construct_Orbs::filter_empty_orbs(lcaos); - std::vector>> - abfs = Exx_Abfs::Construct_Orbs::abfs_same_atom(ucell,orb, lcaos, info.kmesh_times, info.pca_threshold ); - if(!info.files_abfs.empty()) - { abfs = Exx_Abfs::IO::construct_abfs( abfs, orb, info.files_abfs, info.kmesh_times ); } - Exx_Abfs::Construct_Orbs::filter_empty_orbs(abfs); + std::vector>> + abfs = Exx_Abfs::Construct_Orbs::abfs_same_atom(ucell,orb, lcaos, info.kmesh_times, info.pca_threshold ); + if(!info.files_abfs.empty()) + { abfs = Exx_Abfs::IO::construct_abfs( abfs, orb, info.files_abfs, info.kmesh_times ); } + Exx_Abfs::Construct_Orbs::filter_empty_orbs(abfs); - std::vector< std::vector< std::vector< Numerical_Orbital_Lm>>> - jle = Exx_Abfs::Jle::init_jle(info, info.kmesh_times, ucell , orb); - if(!info.files_jles.empty()) - { jle = Exx_Abfs::IO::construct_abfs( jle, orb, info.files_jles, info.kmesh_times ); } - Exx_Abfs::Construct_Orbs::filter_empty_orbs(jle); + std::vector< std::vector< std::vector< Numerical_Orbital_Lm>>> + jle = Exx_Abfs::Jle::init_jle(info, info.kmesh_times, ucell , orb); + if(!info.files_jles.empty()) + { jle = Exx_Abfs::IO::construct_abfs( jle, orb, info.files_jles, info.kmesh_times ); } + Exx_Abfs::Construct_Orbs::filter_empty_orbs(jle); - const ModuleBase::Element_Basis_Index::Range range_lcaos = ModuleBase::Element_Basis_Index::construct_range( lcaos ); - const ModuleBase::Element_Basis_Index::IndexLNM index_lcaos = ModuleBase::Element_Basis_Index::construct_index( range_lcaos ); + const ModuleBase::Element_Basis_Index::Range range_lcaos = ModuleBase::Element_Basis_Index::construct_range( lcaos ); + const ModuleBase::Element_Basis_Index::IndexLNM index_lcaos = ModuleBase::Element_Basis_Index::construct_index( range_lcaos ); - const ModuleBase::Element_Basis_Index::Range range_abfs = ModuleBase::Element_Basis_Index::construct_range( abfs ); - const ModuleBase::Element_Basis_Index::IndexLNM index_abfs = ModuleBase::Element_Basis_Index::construct_index( range_abfs ); + const ModuleBase::Element_Basis_Index::Range range_abfs = ModuleBase::Element_Basis_Index::construct_range( abfs ); + const ModuleBase::Element_Basis_Index::IndexLNM index_abfs = ModuleBase::Element_Basis_Index::construct_index( range_abfs ); - const ModuleBase::Element_Basis_Index::Range range_jys = ModuleBase::Element_Basis_Index::construct_range( jle ); - const ModuleBase::Element_Basis_Index::IndexLNM index_jys = ModuleBase::Element_Basis_Index::construct_index( range_jys ); + const ModuleBase::Element_Basis_Index::Range range_jys = ModuleBase::Element_Basis_Index::construct_range( jle ); + const ModuleBase::Element_Basis_Index::IndexLNM index_jys = ModuleBase::Element_Basis_Index::construct_index( range_jys ); - Exx_Abfs::Construct_Orbs::print_orbs_size(ucell, abfs, GlobalV::ofs_running); - Exx_Abfs::Construct_Orbs::print_orbs_size(ucell, jle, GlobalV::ofs_running); + Exx_Abfs::Construct_Orbs::print_orbs_size(ucell, abfs, GlobalV::ofs_running); + Exx_Abfs::Construct_Orbs::print_orbs_size(ucell, jle, GlobalV::ofs_running); - const std::map>> radial_R = get_radial_R(ucell); + const std::map>> radial_R = get_radial_R(ucell); - // < lcaos lcaos | lcaos lcaos > - const auto ms_lcaoslcaos_lcaoslcaos = [&]() -> std::map>>>> - { - if(judge_orbs_empty(lcaos)) { return {}; } - Matrix_Orbs22 m_lcaoslcaos_lcaoslcaos; - m_lcaoslcaos_lcaoslcaos.init( lcaos, lcaos, lcaos, lcaos, ucell,orb, info.kmesh_times ); - #if TEST_EXX_RADIAL>=1 - m_lcaoslcaos_lcaoslcaos.init_radial_table(radial_R); - #else - m_lcaoslcaos_lcaoslcaos.init_radial_table(); - #endif - return m_lcaoslcaos_lcaoslcaos.cal_overlap_matrix_all(ucell,index_lcaos, index_lcaos, index_lcaos, index_lcaos); - }(); + // < lcaos lcaos | lcaos lcaos > + const auto ms_lcaoslcaos_lcaoslcaos = [&]() -> std::map>>>> + { + if(judge_orbs_empty(lcaos)) { return {}; } + Matrix_Orbs22 m_lcaoslcaos_lcaoslcaos; + m_lcaoslcaos_lcaoslcaos.init( lcaos, lcaos, lcaos, lcaos, ucell,orb, info.kmesh_times ); + #if TEST_EXX_RADIAL>=1 + m_lcaoslcaos_lcaoslcaos.init_radial_table(radial_R); + #else + m_lcaoslcaos_lcaoslcaos.init_radial_table(); + #endif + return m_lcaoslcaos_lcaoslcaos.cal_overlap_matrix_all(ucell,index_lcaos, index_lcaos, index_lcaos, index_lcaos); + }(); - // < lcaos lcaos | jys > - const auto ms_lcaoslcaos_jys = [&]() -> std::map>>>>> - { - if(judge_orbs_empty(lcaos)) { return {}; } - if(judge_orbs_empty(jle)) { return {}; } - Matrix_Orbs21 m_jyslcaos_lcaos; - m_jyslcaos_lcaos.init( jle, lcaos, lcaos, ucell , orb, info.kmesh_times ); - #if TEST_EXX_RADIAL>=1 - m_jyslcaos_lcaos.init_radial_table( radial_R); - #else - m_jyslcaos_lcaos.init_radial_table(); - #endif - return m_jyslcaos_lcaos.cal_overlap_matrix_all(ucell,index_jys, index_lcaos, index_lcaos ); - }(); + // < lcaos lcaos | jys > + const auto ms_lcaoslcaos_jys = [&]() -> std::map>>>>> + { + if(judge_orbs_empty(lcaos)) { return {}; } + if(judge_orbs_empty(jle)) { return {}; } + Matrix_Orbs21 m_jyslcaos_lcaos; + m_jyslcaos_lcaos.init( jle, lcaos, lcaos, ucell , orb, info.kmesh_times ); + #if TEST_EXX_RADIAL>=1 + m_jyslcaos_lcaos.init_radial_table( radial_R); + #else + m_jyslcaos_lcaos.init_radial_table(); + #endif + return m_jyslcaos_lcaos.cal_overlap_matrix_all(ucell,index_jys, index_lcaos, index_lcaos ); + }(); - // < jys | jys > - const auto ms_jys_jys = [&]() -> std::map>>>> - { - if(judge_orbs_empty(jle)) { return {}; } - Matrix_Orbs11 m_jys_jys; - m_jys_jys.init( jle, jle, ucell,orb, info.kmesh_times ); - #if TEST_EXX_RADIAL>=1 - m_jys_jys.init_radial_table(radial_R); - #else - m_jys_jys.init_radial_table(); - #endif - return m_jys_jys.cal_overlap_matrix_all(ucell,index_jys, index_jys ); - }(); + // < jys | jys > + const auto ms_jys_jys = [&]() -> std::map>>>> + { + if(judge_orbs_empty(jle)) { return {}; } + Matrix_Orbs11 m_jys_jys; + m_jys_jys.init( jle, jle, ucell,orb, info.kmesh_times ); + #if TEST_EXX_RADIAL>=1 + m_jys_jys.init_radial_table(radial_R); + #else + m_jys_jys.init_radial_table(); + #endif + return m_jys_jys.cal_overlap_matrix_all(ucell,index_jys, index_jys ); + }(); - // < abfs | abfs > - const auto ms_abfs_abfs = [&]() -> std::map>>>> - { - if(judge_orbs_empty(abfs)) { return {}; } - Matrix_Orbs11 m_abfs_abfs; - m_abfs_abfs.init( abfs, abfs, ucell, orb, info.kmesh_times ); - #if TEST_EXX_RADIAL>=1 - m_abfs_abfs.init_radial_table(radial_R); - #else - m_abfs_abfs.init_radial_table(); - #endif - return m_abfs_abfs.cal_overlap_matrix_all(ucell,index_abfs, index_abfs ); - }(); + // < abfs | abfs > + const auto ms_abfs_abfs = [&]() -> std::map>>>> + { + if(judge_orbs_empty(abfs)) { return {}; } + Matrix_Orbs11 m_abfs_abfs; + m_abfs_abfs.init( abfs, abfs, ucell, orb, info.kmesh_times ); + #if TEST_EXX_RADIAL>=1 + m_abfs_abfs.init_radial_table(radial_R); + #else + m_abfs_abfs.init_radial_table(); + #endif + return m_abfs_abfs.cal_overlap_matrix_all(ucell,index_abfs, index_abfs ); + }(); - // < lcaos lcaos | abfs > - const auto ms_lcaoslcaos_abfs = [&]() -> std::map>>>>> - { - if(judge_orbs_empty(lcaos)) { return {}; } - if(judge_orbs_empty(abfs)) { return {}; } - Matrix_Orbs21 m_abfslcaos_lcaos; - m_abfslcaos_lcaos.init( abfs, lcaos, lcaos, ucell , orb, info.kmesh_times ); - #if TEST_EXX_RADIAL>=1 - m_abfslcaos_lcaos.init_radial_table(radial_R); - #else - m_abfslcaos_lcaos.init_radial_table(); - #endif - return m_abfslcaos_lcaos.cal_overlap_matrix_all(ucell,index_abfs, index_lcaos, index_lcaos ); - }(); + // < lcaos lcaos | abfs > + const auto ms_lcaoslcaos_abfs = [&]() -> std::map>>>>> + { + if(judge_orbs_empty(lcaos)) { return {}; } + if(judge_orbs_empty(abfs)) { return {}; } + Matrix_Orbs21 m_abfslcaos_lcaos; + m_abfslcaos_lcaos.init( abfs, lcaos, lcaos, ucell , orb, info.kmesh_times ); + #if TEST_EXX_RADIAL>=1 + m_abfslcaos_lcaos.init_radial_table(radial_R); + #else + m_abfslcaos_lcaos.init_radial_table(); + #endif + return m_abfslcaos_lcaos.cal_overlap_matrix_all(ucell,index_abfs, index_lcaos, index_lcaos ); + }(); - // < jys | abfs > - const auto ms_jys_abfs = [&]() -> std::map>>>> - { - if(judge_orbs_empty(jle)) { return {}; } - if(judge_orbs_empty(abfs)) { return {}; } - Matrix_Orbs11 m_jys_abfs; - m_jys_abfs.init( jle, abfs, ucell,orb, info.kmesh_times ); - #if TEST_EXX_RADIAL>=1 - m_jys_abfs.init_radial_table(radial_R); - #else - m_jys_abfs.init_radial_table(); - #endif - return m_jys_abfs.cal_overlap_matrix_all(ucell,index_jys, index_abfs ); - }(); + // < jys | abfs > + const auto ms_jys_abfs = [&]() -> std::map>>>> + { + if(judge_orbs_empty(jle)) { return {}; } + if(judge_orbs_empty(abfs)) { return {}; } + Matrix_Orbs11 m_jys_abfs; + m_jys_abfs.init( jle, abfs, ucell,orb, info.kmesh_times ); + #if TEST_EXX_RADIAL>=1 + m_jys_abfs.init_radial_table(radial_R); + #else + m_jys_abfs.init_radial_table(); + #endif + return m_jys_abfs.cal_overlap_matrix_all(ucell,index_jys, index_abfs ); + }(); - for( size_t TA=0; TA!=ucell.ntype; ++TA ) - { - for( size_t IA=0; IA!=ucell.atoms[TA].na; ++IA ) - { - for( size_t TB=0; TB!=ucell.ntype; ++TB ) - { - for( size_t IB=0; IB!=ucell.atoms[TB].na; ++IB ) - { - if( TA==TB && IA==IB ) - { - const size_t T=TA, I=IA; - if(!judge_orbs_empty(abfs)) - { - // < abfs | abfs >.I - const std::vector>> ms_abfs_abfs_I = cal_I( ms_abfs_abfs, T,I,T,I ); - // < lcaos lcaos | lcaos lcaos > - < lcaos lcaos | abfs > * < abfs | abfs >.I * < abfs | lcaos lcaos > - const RI::Tensor m_lcaoslcaos_lcaoslcaos_proj = - ms_lcaoslcaos_lcaoslcaos.at(T).at(I).at(T).at(I) - cal_mul_22( - ms_lcaoslcaos_abfs.at(T).at(I).at(T).at(I), - ms_abfs_abfs_I, - ms_lcaoslcaos_abfs.at(T).at(I).at(T).at(I)); - // < lcaos lcaos | jys > - < lcaos lcaos | abfs > * < abfs | abfs >.I * < abfs | jys > - const std::vector> m_lcaoslcaos_jys_proj = - {ms_lcaoslcaos_jys.at(T).at(I).at(T).at(I)[0] - cal_mul_21( - ms_lcaoslcaos_abfs.at(T).at(I).at(T).at(I), - ms_abfs_abfs_I, - {ms_jys_abfs.at(T).at(I).at(T).at(I)})}; - // < jys | jys > - < jys | abfs > * < abfs | abfs >.I * < abfs | jys > - const std::vector>> m_jys_jys_proj = - {{ms_jys_jys.at(T).at(I).at(T).at(I) - cal_mul_11( - {ms_jys_abfs.at(T).at(I).at(T).at(I)}, - ms_abfs_abfs_I, - {ms_jys_abfs.at(T).at(I).at(T).at(I)})}}; - print_matrix( - info, - ucell, - kv, - jle.at(T).size()-1, - {jle.at(T).at(0).size()}, - PARAM.globalv.global_out_dir+"/matrix-opt-abfs", - m_lcaoslcaos_jys_proj, - m_jys_jys_proj, - m_lcaoslcaos_lcaoslcaos_proj, - T, I, T, I, + for( size_t TA=0; TA!=ucell.ntype; ++TA ) + { + for( size_t IA=0; IA!=ucell.atoms[TA].na; ++IA ) + { + for( size_t TB=0; TB!=ucell.ntype; ++TB ) + { + for( size_t IB=0; IB!=ucell.atoms[TB].na; ++IB ) + { + if( TA==TB && IA==IB ) + { + const size_t T=TA, I=IA; + if(!judge_orbs_empty(abfs)) + { + // < abfs | abfs >.I + const std::vector>> ms_abfs_abfs_I = cal_I( ms_abfs_abfs, T,I,T,I ); + // < lcaos lcaos | lcaos lcaos > - < lcaos lcaos | abfs > * < abfs | abfs >.I * < abfs | lcaos lcaos > + const RI::Tensor m_lcaoslcaos_lcaoslcaos_proj = + ms_lcaoslcaos_lcaoslcaos.at(T).at(I).at(T).at(I) - cal_mul_22( + ms_lcaoslcaos_abfs.at(T).at(I).at(T).at(I), + ms_abfs_abfs_I, + ms_lcaoslcaos_abfs.at(T).at(I).at(T).at(I)); + // < lcaos lcaos | jys > - < lcaos lcaos | abfs > * < abfs | abfs >.I * < abfs | jys > + const std::vector> m_lcaoslcaos_jys_proj = + {ms_lcaoslcaos_jys.at(T).at(I).at(T).at(I)[0] - cal_mul_21( + ms_lcaoslcaos_abfs.at(T).at(I).at(T).at(I), + ms_abfs_abfs_I, + {ms_jys_abfs.at(T).at(I).at(T).at(I)})}; + // < jys | jys > - < jys | abfs > * < abfs | abfs >.I * < abfs | jys > + const std::vector>> m_jys_jys_proj = + {{ms_jys_jys.at(T).at(I).at(T).at(I) - cal_mul_11( + {ms_jys_abfs.at(T).at(I).at(T).at(I)}, + ms_abfs_abfs_I, + {ms_jys_abfs.at(T).at(I).at(T).at(I)})}}; + print_matrix( + info, + ucell, + kv, + jle.at(T).size()-1, + {jle.at(T).at(0).size()}, + PARAM.globalv.global_out_dir+"/matrix-opt-abfs", + m_lcaoslcaos_jys_proj, + m_jys_jys_proj, + m_lcaoslcaos_lcaoslcaos_proj, + T, I, T, I, orb.cutoffs(), - range_jys, index_jys ); - } - else - { - print_matrix( - info, - ucell, - kv, - jle.at(T).size()-1, - {jle.at(T).at(0).size()}, - PARAM.globalv.global_out_dir+"/matrix-opt-abfs", - ms_lcaoslcaos_jys.at(T).at(I).at(T).at(I), - {{ms_jys_jys.at(T).at(I).at(T).at(I)}}, - ms_lcaoslcaos_lcaoslcaos.at(T).at(I).at(T).at(I), - T, I, T, I, + range_jys, index_jys ); + } + else + { + print_matrix( + info, + ucell, + kv, + jle.at(T).size()-1, + {jle.at(T).at(0).size()}, + PARAM.globalv.global_out_dir+"/matrix-opt-abfs", + ms_lcaoslcaos_jys.at(T).at(I).at(T).at(I), + {{ms_jys_jys.at(T).at(I).at(T).at(I)}}, + ms_lcaoslcaos_lcaoslcaos.at(T).at(I).at(T).at(I), + T, I, T, I, orb.cutoffs(), - range_jys, index_jys ); - } - } - else - { - if(!judge_orbs_empty(abfs)) - { - // < abfs | abfs >.I - const std::vector>> ms_abfs_abfs_I = cal_I( ms_abfs_abfs, TA,IA,TB,IB ); - // < lcaos lcaos | lcaos lcaos > - < lcaos lcaos | abfs > * < abfs | abfs >.I * < abfs | lcaos lcaos > - const RI::Tensor m_lcaoslcaos_lcaoslcaos_proj = - ms_lcaoslcaos_lcaoslcaos.at(TA).at(IA).at(TB).at(IB) - cal_mul_22( - ms_lcaoslcaos_abfs.at(TA).at(IA).at(TB).at(IB), - ms_abfs_abfs_I, - ms_lcaoslcaos_abfs.at(TA).at(IA).at(TB).at(IB)); - // < lcaos lcaos | jys > - < lcaos lcaos | abfs > * < abfs | abfs >.I * < abfs | jys > - const std::vector> m_lcaoslcaos_jys_proj = - {ms_lcaoslcaos_jys.at(TA).at(IA).at(TB).at(IB)[0] - cal_mul_21( - ms_lcaoslcaos_abfs.at(TA).at(IA).at(TB).at(IB), - ms_abfs_abfs_I, - { ms_jys_abfs.at(TA).at(IA).at(TA).at(IA), ms_jys_abfs.at(TA).at(IA).at(TB).at(IB) }), - ms_lcaoslcaos_jys.at(TA).at(IA).at(TB).at(IB)[1] - cal_mul_21( - ms_lcaoslcaos_abfs.at(TA).at(IA).at(TB).at(IB), - ms_abfs_abfs_I, - { ms_jys_abfs.at(TB).at(IB).at(TA).at(IA), ms_jys_abfs.at(TB).at(IB).at(TB).at(IB) })}; - // < jys | jys > - < jys | abfs > * < abfs | abfs >.I * < abfs | jys > - const std::vector>> m_jys_jys_proj = - {{ms_jys_jys.at(TA).at(IA).at(TA).at(IA) - cal_mul_11( - { ms_jys_abfs.at(TA).at(IA).at(TA).at(IA), ms_jys_abfs.at(TA).at(IA).at(TB).at(IB) }, - ms_abfs_abfs_I, - { ms_jys_abfs.at(TA).at(IA).at(TA).at(IA), ms_jys_abfs.at(TA).at(IA).at(TB).at(IB) }), - ms_jys_jys.at(TA).at(IA).at(TB).at(IB) - cal_mul_11( - { ms_jys_abfs.at(TA).at(IA).at(TA).at(IA), ms_jys_abfs.at(TA).at(IA).at(TB).at(IB) }, - ms_abfs_abfs_I, - { ms_jys_abfs.at(TB).at(IB).at(TA).at(IA), ms_jys_abfs.at(TB).at(IB).at(TB).at(IB) }) }, - {ms_jys_jys.at(TB).at(IB).at(TA).at(IA) - cal_mul_11( - { ms_jys_abfs.at(TB).at(IB).at(TA).at(IA), ms_jys_abfs.at(TB).at(IB).at(TB).at(IB) }, - ms_abfs_abfs_I, - { ms_jys_abfs.at(TA).at(IA).at(TA).at(IA), ms_jys_abfs.at(TA).at(IA).at(TB).at(IB) }), - ms_jys_jys.at(TB).at(IB).at(TB).at(IB) - cal_mul_11( - { ms_jys_abfs.at(TB).at(IB).at(TA).at(IA), ms_jys_abfs.at(TB).at(IB).at(TB).at(IB) }, - ms_abfs_abfs_I, - { ms_jys_abfs.at(TB).at(IB).at(TA).at(IA), ms_jys_abfs.at(TB).at(IB).at(TB).at(IB) }) }}; - print_matrix( - info, - ucell, - kv, - std::max(jle.at(TA).size(), jle.at(TB).size())-1, - {jle.at(TA).at(0).size(), jle.at(TB).at(0).size()}, - PARAM.globalv.global_out_dir+"/matrix-opt-abfs", - m_lcaoslcaos_jys_proj, - m_jys_jys_proj, - m_lcaoslcaos_lcaoslcaos_proj, - TA, IA, TB, IB, + range_jys, index_jys ); + } + } + else + { + if(!judge_orbs_empty(abfs)) + { + // < abfs | abfs >.I + const std::vector>> ms_abfs_abfs_I = cal_I( ms_abfs_abfs, TA,IA,TB,IB ); + // < lcaos lcaos | lcaos lcaos > - < lcaos lcaos | abfs > * < abfs | abfs >.I * < abfs | lcaos lcaos > + const RI::Tensor m_lcaoslcaos_lcaoslcaos_proj = + ms_lcaoslcaos_lcaoslcaos.at(TA).at(IA).at(TB).at(IB) - cal_mul_22( + ms_lcaoslcaos_abfs.at(TA).at(IA).at(TB).at(IB), + ms_abfs_abfs_I, + ms_lcaoslcaos_abfs.at(TA).at(IA).at(TB).at(IB)); + // < lcaos lcaos | jys > - < lcaos lcaos | abfs > * < abfs | abfs >.I * < abfs | jys > + const std::vector> m_lcaoslcaos_jys_proj = + {ms_lcaoslcaos_jys.at(TA).at(IA).at(TB).at(IB)[0] - cal_mul_21( + ms_lcaoslcaos_abfs.at(TA).at(IA).at(TB).at(IB), + ms_abfs_abfs_I, + { ms_jys_abfs.at(TA).at(IA).at(TA).at(IA), ms_jys_abfs.at(TA).at(IA).at(TB).at(IB) }), + ms_lcaoslcaos_jys.at(TA).at(IA).at(TB).at(IB)[1] - cal_mul_21( + ms_lcaoslcaos_abfs.at(TA).at(IA).at(TB).at(IB), + ms_abfs_abfs_I, + { ms_jys_abfs.at(TB).at(IB).at(TA).at(IA), ms_jys_abfs.at(TB).at(IB).at(TB).at(IB) })}; + // < jys | jys > - < jys | abfs > * < abfs | abfs >.I * < abfs | jys > + const std::vector>> m_jys_jys_proj = + {{ms_jys_jys.at(TA).at(IA).at(TA).at(IA) - cal_mul_11( + { ms_jys_abfs.at(TA).at(IA).at(TA).at(IA), ms_jys_abfs.at(TA).at(IA).at(TB).at(IB) }, + ms_abfs_abfs_I, + { ms_jys_abfs.at(TA).at(IA).at(TA).at(IA), ms_jys_abfs.at(TA).at(IA).at(TB).at(IB) }), + ms_jys_jys.at(TA).at(IA).at(TB).at(IB) - cal_mul_11( + { ms_jys_abfs.at(TA).at(IA).at(TA).at(IA), ms_jys_abfs.at(TA).at(IA).at(TB).at(IB) }, + ms_abfs_abfs_I, + { ms_jys_abfs.at(TB).at(IB).at(TA).at(IA), ms_jys_abfs.at(TB).at(IB).at(TB).at(IB) }) }, + {ms_jys_jys.at(TB).at(IB).at(TA).at(IA) - cal_mul_11( + { ms_jys_abfs.at(TB).at(IB).at(TA).at(IA), ms_jys_abfs.at(TB).at(IB).at(TB).at(IB) }, + ms_abfs_abfs_I, + { ms_jys_abfs.at(TA).at(IA).at(TA).at(IA), ms_jys_abfs.at(TA).at(IA).at(TB).at(IB) }), + ms_jys_jys.at(TB).at(IB).at(TB).at(IB) - cal_mul_11( + { ms_jys_abfs.at(TB).at(IB).at(TA).at(IA), ms_jys_abfs.at(TB).at(IB).at(TB).at(IB) }, + ms_abfs_abfs_I, + { ms_jys_abfs.at(TB).at(IB).at(TA).at(IA), ms_jys_abfs.at(TB).at(IB).at(TB).at(IB) }) }}; + print_matrix( + info, + ucell, + kv, + std::max(jle.at(TA).size(), jle.at(TB).size())-1, + {jle.at(TA).at(0).size(), jle.at(TB).at(0).size()}, + PARAM.globalv.global_out_dir+"/matrix-opt-abfs", + m_lcaoslcaos_jys_proj, + m_jys_jys_proj, + m_lcaoslcaos_lcaoslcaos_proj, + TA, IA, TB, IB, orb.cutoffs(), - range_jys, index_jys ); - } - else - { - print_matrix( - info, - ucell, - kv, - std::max(jle.at(TA).size(), jle.at(TB).size())-1, - {jle.at(TA).at(0).size(), jle.at(TB).at(0).size()}, - PARAM.globalv.global_out_dir+"/matrix-opt-abfs", - ms_lcaoslcaos_jys.at(TA).at(IA).at(TB).at(IB), - {{ms_jys_jys.at(TA).at(IA).at(TA).at(IA), ms_jys_jys.at(TA).at(IA).at(TB).at(IB)}, - {ms_jys_jys.at(TB).at(IB).at(TA).at(IA), ms_jys_jys.at(TB).at(IB).at(TB).at(IB)}}, - ms_lcaoslcaos_lcaoslcaos.at(TA).at(IA).at(TB).at(IB), - TA, IA, TB, IB, + range_jys, index_jys ); + } + else + { + print_matrix( + info, + ucell, + kv, + std::max(jle.at(TA).size(), jle.at(TB).size())-1, + {jle.at(TA).at(0).size(), jle.at(TB).at(0).size()}, + PARAM.globalv.global_out_dir+"/matrix-opt-abfs", + ms_lcaoslcaos_jys.at(TA).at(IA).at(TB).at(IB), + {{ms_jys_jys.at(TA).at(IA).at(TA).at(IA), ms_jys_jys.at(TA).at(IA).at(TB).at(IB)}, + {ms_jys_jys.at(TB).at(IB).at(TA).at(IA), ms_jys_jys.at(TB).at(IB).at(TB).at(IB)}}, + ms_lcaoslcaos_lcaoslcaos.at(TA).at(IA).at(TB).at(IB), + TA, IA, TB, IB, orb.cutoffs(), - range_jys, index_jys ); - } - } - } - } - } - } + range_jys, index_jys ); + } + } + } + } + } + } } // m_left * m_middle * m_right.T RI::Tensor Exx_Opt_Orb::cal_mul_22( - const std::vector> & m_left, - const std::vector>> & m_middle, - const std::vector> & m_right ) const + const std::vector> & m_left, + const std::vector>> & m_middle, + const std::vector> & m_right ) const { - ModuleBase::TITLE("Exx_Opt_Orb::cal_mul_22"); - RI::Tensor m_mul; - for( size_t il=0; il!=m_left.size(); ++il ) - { - for( size_t ir=0; ir!=m_right.size(); ++ir ) - { - // m_mul += m_left[il] * m_middle[il][ir] * m_right[ir].T; - const RI::Tensor m_lm = RI::Tensor_Multiply::x0x1y1_x0x1a_ay1(m_left[il], m_middle[il][ir]); - const RI::Tensor m_lmr = RI::Tensor_Multiply::x0x1y0y1_x0x1a_y0y1a(m_lm, m_right[ir]); - if(m_mul.empty()) - { m_mul = std::move(m_lmr); } - else - { m_mul += m_lmr; } - } - } - return m_mul; + ModuleBase::TITLE("Exx_Opt_Orb::cal_mul_22"); + RI::Tensor m_mul; + for( size_t il=0; il!=m_left.size(); ++il ) + { + for( size_t ir=0; ir!=m_right.size(); ++ir ) + { + // m_mul += m_left[il] * m_middle[il][ir] * m_right[ir].T; + const RI::Tensor m_lm = RI::Tensor_Multiply::x0x1y1_x0x1a_ay1(m_left[il], m_middle[il][ir]); + const RI::Tensor m_lmr = RI::Tensor_Multiply::x0x1y0y1_x0x1a_y0y1a(m_lm, m_right[ir]); + if(m_mul.empty()) + { m_mul = std::move(m_lmr); } + else + { m_mul += m_lmr; } + } + } + return m_mul; } RI::Tensor Exx_Opt_Orb::cal_mul_21( - const std::vector> & m_left, - const std::vector>> & m_middle, - const std::vector> & m_right ) const + const std::vector> & m_left, + const std::vector>> & m_middle, + const std::vector> & m_right ) const { - ModuleBase::TITLE("Exx_Opt_Orb::cal_mul_21"); - RI::Tensor m_mul; - for( size_t il=0; il!=m_left.size(); ++il ) - { - for( size_t ir=0; ir!=m_right.size(); ++ir ) - { - // m_mul += m_left[il] * m_middle[il][ir] * m_right[ir].T; - const RI::Tensor m_lm = RI::Tensor_Multiply::x0x1y1_x0x1a_ay1(m_left[il], m_middle[il][ir]); - const RI::Tensor m_lmr = RI::Tensor_Multiply::x0x1y0_x0x1a_y0a(m_lm, m_right[ir]); - if(m_mul.empty()) - { m_mul = std::move(m_lmr); } - else - { m_mul += m_lmr; } - } - } - return m_mul; + ModuleBase::TITLE("Exx_Opt_Orb::cal_mul_21"); + RI::Tensor m_mul; + for( size_t il=0; il!=m_left.size(); ++il ) + { + for( size_t ir=0; ir!=m_right.size(); ++ir ) + { + // m_mul += m_left[il] * m_middle[il][ir] * m_right[ir].T; + const RI::Tensor m_lm = RI::Tensor_Multiply::x0x1y1_x0x1a_ay1(m_left[il], m_middle[il][ir]); + const RI::Tensor m_lmr = RI::Tensor_Multiply::x0x1y0_x0x1a_y0a(m_lm, m_right[ir]); + if(m_mul.empty()) + { m_mul = std::move(m_lmr); } + else + { m_mul += m_lmr; } + } + } + return m_mul; } RI::Tensor Exx_Opt_Orb::cal_mul_12( - const std::vector> & m_left, - const std::vector>> & m_middle, - const std::vector> & m_right ) const + const std::vector> & m_left, + const std::vector>> & m_middle, + const std::vector> & m_right ) const { - ModuleBase::TITLE("Exx_Opt_Orb::cal_mul_12"); - RI::Tensor m_mul; - for( size_t il=0; il!=m_left.size(); ++il ) - { - for( size_t ir=0; ir!=m_right.size(); ++ir ) - { - // m_mul += m_left[il] * m_middle[il][ir] * m_right[ir].T; - const RI::Tensor m_lm = RI::Tensor_Multiply::x0y1_x0a_ay1(m_left[il], m_middle[il][ir]); - const RI::Tensor m_lmr = RI::Tensor_Multiply::x0y0y1_x0a_y0y1a(m_lm, m_right[ir]); - if(m_mul.empty()) - { m_mul = std::move(m_lmr); } - else - { m_mul += m_lmr; } - } - } - return m_mul; + ModuleBase::TITLE("Exx_Opt_Orb::cal_mul_12"); + RI::Tensor m_mul; + for( size_t il=0; il!=m_left.size(); ++il ) + { + for( size_t ir=0; ir!=m_right.size(); ++ir ) + { + // m_mul += m_left[il] * m_middle[il][ir] * m_right[ir].T; + const RI::Tensor m_lm = RI::Tensor_Multiply::x0y1_x0a_ay1(m_left[il], m_middle[il][ir]); + const RI::Tensor m_lmr = RI::Tensor_Multiply::x0y0y1_x0a_y0y1a(m_lm, m_right[ir]); + if(m_mul.empty()) + { m_mul = std::move(m_lmr); } + else + { m_mul += m_lmr; } + } + } + return m_mul; } RI::Tensor Exx_Opt_Orb::cal_mul_11( - const std::vector> & m_left, - const std::vector>> & m_middle, - const std::vector> & m_right ) const + const std::vector> & m_left, + const std::vector>> & m_middle, + const std::vector> & m_right ) const { - ModuleBase::TITLE("Exx_Opt_Orb::cal_mul_11"); - RI::Tensor m_mul; - for( size_t il=0; il!=m_left.size(); ++il ) - { - for( size_t ir=0; ir!=m_right.size(); ++ir ) - { - // m_mul += m_left[il] * m_middle[il][ir] * m_right[ir].T; - const RI::Tensor m_lm = RI::Tensor_Multiply::x0y1_x0a_ay1(m_left[il], m_middle[il][ir]); - const RI::Tensor m_lmr = RI::Tensor_Multiply::x0y0_x0a_y0a(m_lm, m_right[ir]); - if(m_mul.empty()) - { m_mul = std::move(m_lmr); } - else - { m_mul += m_lmr; } - } - } - return m_mul; + ModuleBase::TITLE("Exx_Opt_Orb::cal_mul_11"); + RI::Tensor m_mul; + for( size_t il=0; il!=m_left.size(); ++il ) + { + for( size_t ir=0; ir!=m_right.size(); ++ir ) + { + // m_mul += m_left[il] * m_middle[il][ir] * m_right[ir].T; + const RI::Tensor m_lm = RI::Tensor_Multiply::x0y1_x0a_ay1(m_left[il], m_middle[il][ir]); + const RI::Tensor m_lmr = RI::Tensor_Multiply::x0y0_x0a_y0a(m_lm, m_right[ir]); + if(m_mul.empty()) + { m_mul = std::move(m_lmr); } + else + { m_mul += m_lmr; } + } + } + return m_mul; } std::vector>> Exx_Opt_Orb::cal_I( - const std::map>>>> &ms, - const size_t TA, const size_t IA, const size_t TB, const size_t IB ) const + const std::map>>>> &ms, + const size_t TA, const size_t IA, const size_t TB, const size_t IB ) const { - ModuleBase::TITLE("Exx_Opt_Orb::cal_I"); + ModuleBase::TITLE("Exx_Opt_Orb::cal_I"); - if( TA==TB && IA==IB ) - { - return {{LRI_CV_Tools::cal_I(RI::Tensor(ms.at(TA).at(IA).at(TA).at(IA)))}}; - } - else - { - std::vector>> m_in - {{ ms.at(TA).at(IA).at(TA).at(IA), - ms.at(TA).at(IA).at(TB).at(IB) }, - { ms.at(TB).at(IB).at(TA).at(IA), - ms.at(TB).at(IB).at(TB).at(IB) }}; - return LRI_CV_Tools::cal_I(m_in); - } + if( TA==TB && IA==IB ) + { + return {{LRI_CV_Tools::cal_I(RI::Tensor(ms.at(TA).at(IA).at(TA).at(IA)))}}; + } + else + { + std::vector>> m_in + {{ ms.at(TA).at(IA).at(TA).at(IA), + ms.at(TA).at(IA).at(TB).at(IB) }, + { ms.at(TB).at(IB).at(TA).at(IA), + ms.at(TB).at(IB).at(TB).at(IB) }}; + return LRI_CV_Tools::cal_I(m_in); + } } std::map>> Exx_Opt_Orb::get_radial_R(const UnitCell& ucell) const { - ModuleBase::TITLE("Exx_Opt_Orb::get_radial_R"); - std::map>> radial_R; - for( size_t TA=0; TA!=ucell.ntype; ++TA ) { - for( size_t IA=0; IA!=ucell.atoms[TA].na; ++IA ) { - for( size_t TB=0; TB!=ucell.ntype; ++TB ) { - for( size_t IB=0; IB!=ucell.atoms[TB].na; ++IB ) - { - const ModuleBase::Vector3 &tauA = ucell.atoms[TA].tau[IA]; - const ModuleBase::Vector3 &tauB = ucell.atoms[TB].tau[IB]; - const double delta_R = (-tauA+tauB).norm(); - radial_R[TA][TB].insert( delta_R ); - radial_R[TB][TA].insert( delta_R ); - } - } - } - } - return radial_R; + ModuleBase::TITLE("Exx_Opt_Orb::get_radial_R"); + std::map>> radial_R; + for( size_t TA=0; TA!=ucell.ntype; ++TA ) { + for( size_t IA=0; IA!=ucell.atoms[TA].na; ++IA ) { + for( size_t TB=0; TB!=ucell.ntype; ++TB ) { + for( size_t IB=0; IB!=ucell.atoms[TB].na; ++IB ) + { + const ModuleBase::Vector3 &tauA = ucell.atoms[TA].tau[IA]; + const ModuleBase::Vector3 &tauB = ucell.atoms[TB].tau[IB]; + const double delta_R = (-tauA+tauB).norm(); + radial_R[TA][TB].insert( delta_R ); + radial_R[TB][TA].insert( delta_R ); + } + } + } + } + return radial_R; } diff --git a/source/source_lcao/module_ri/exx_opt_orb.h b/source/source_lcao/module_ri/exx_opt_orb.h index 418db018fa7..d6070720911 100644 --- a/source/source_lcao/module_ri/exx_opt_orb.h +++ b/source/source_lcao/module_ri/exx_opt_orb.h @@ -14,45 +14,45 @@ class Exx_Opt_Orb { public: - void generate_matrix( - const Exx_Info_Opt_ABFs &info, - const K_Vectors &kv, - const UnitCell &ucell, - const LCAO_Orbitals &orb) const; + void generate_matrix( + const Exx_Info_Opt_ABFs &info, + const K_Vectors &kv, + const UnitCell &ucell, + const LCAO_Orbitals &orb) const; private: - std::vector>> cal_I( - const std::map>>>> &ms, - const size_t TA, const size_t IA, const size_t TB, const size_t IB ) const; - RI::Tensor cal_mul_22( - const std::vector> & m_left, - const std::vector>> & m_middle, - const std::vector> & m_right ) const; - RI::Tensor cal_mul_21( - const std::vector> & m_left, - const std::vector>> & m_middle, - const std::vector> & m_right ) const; - RI::Tensor cal_mul_12( - const std::vector> & m_left, - const std::vector>> & m_middle, - const std::vector> & m_right ) const; - RI::Tensor cal_mul_11( - const std::vector> & m_left, - const std::vector>> & m_middle, - const std::vector> & m_right ) const; - void print_matrix( - const Exx_Info_Opt_ABFs &info, - const UnitCell& ucell, - const K_Vectors &kv, - const int Lmax, - const std::vector &ecut_number, - const std::string& file_name, - const std::vector> &matrix_Q, - const std::vector>> &matrix_S, - const RI::Tensor &matrix_V, - const size_t TA, const size_t IA, const size_t TB, const size_t IB, - const std::vector& orb_cutoff, - const ModuleBase::Element_Basis_Index::Range &range_jles, - const ModuleBase::Element_Basis_Index::IndexLNM &index_jles) const; - std::map>> get_radial_R(const UnitCell& ucell) const; + std::vector>> cal_I( + const std::map>>>> &ms, + const size_t TA, const size_t IA, const size_t TB, const size_t IB ) const; + RI::Tensor cal_mul_22( + const std::vector> & m_left, + const std::vector>> & m_middle, + const std::vector> & m_right ) const; + RI::Tensor cal_mul_21( + const std::vector> & m_left, + const std::vector>> & m_middle, + const std::vector> & m_right ) const; + RI::Tensor cal_mul_12( + const std::vector> & m_left, + const std::vector>> & m_middle, + const std::vector> & m_right ) const; + RI::Tensor cal_mul_11( + const std::vector> & m_left, + const std::vector>> & m_middle, + const std::vector> & m_right ) const; + void print_matrix( + const Exx_Info_Opt_ABFs &info, + const UnitCell& ucell, + const K_Vectors &kv, + const int Lmax, + const std::vector &ecut_number, + const std::string& file_name, + const std::vector> &matrix_Q, + const std::vector>> &matrix_S, + const RI::Tensor &matrix_V, + const size_t TA, const size_t IA, const size_t TB, const size_t IB, + const std::vector& orb_cutoff, + const ModuleBase::Element_Basis_Index::Range &range_jles, + const ModuleBase::Element_Basis_Index::IndexLNM &index_jles) const; + std::map>> get_radial_R(const UnitCell& ucell) const; }; #endif diff --git a/source/source_lcao/module_ri/exx_opt_orb_print.cpp b/source/source_lcao/module_ri/exx_opt_orb_print.cpp index d974faf892e..6d76c46fb8c 100644 --- a/source/source_lcao/module_ri/exx_opt_orb_print.cpp +++ b/source/source_lcao/module_ri/exx_opt_orb_print.cpp @@ -4,207 +4,207 @@ #include void Exx_Opt_Orb::print_matrix( - const Exx_Info_Opt_ABFs &info, - const UnitCell& ucell, - const K_Vectors &kv, - const int Lmax, - const std::vector &ecut_number, - const std::string &file_name, - const std::vector> &matrix_Q, - const std::vector>> &matrix_S, - const RI::Tensor &matrix_V, - const std::size_t TA, const std::size_t IA, const std::size_t TB, const std::size_t IB, - const std::vector& orb_cutoff, - const ModuleBase::Element_Basis_Index::Range &range_jles, - const ModuleBase::Element_Basis_Index::IndexLNM &index_jles) const + const Exx_Info_Opt_ABFs &info, + const UnitCell& ucell, + const K_Vectors &kv, + const int Lmax, + const std::vector &ecut_number, + const std::string &file_name, + const std::vector> &matrix_Q, + const std::vector>> &matrix_S, + const RI::Tensor &matrix_V, + const std::size_t TA, const std::size_t IA, const std::size_t TB, const std::size_t IB, + const std::vector& orb_cutoff, + const ModuleBase::Element_Basis_Index::Range &range_jles, + const ModuleBase::Element_Basis_Index::IndexLNM &index_jles) const { - auto print_header = [&]( std::ofstream &ofs ) - { - ofs << ucell.lat0 << std::endl; + auto print_header = [&]( std::ofstream &ofs ) + { + ofs << ucell.lat0 << std::endl; - ofs << ucell.latvec.e11 << " " << ucell.latvec.e12 << " " << ucell.latvec.e13 << std::endl; - ofs << ucell.latvec.e21 << " " << ucell.latvec.e22 << " " << ucell.latvec.e23 << std::endl; - ofs << ucell.latvec.e31 << " " << ucell.latvec.e32 << " " << ucell.latvec.e33 << std::endl; - - if( TA==TB ) - { - ofs << 1 << " ntype" << std::endl; - ofs << ucell.atoms[TA].label << " label" << std::endl; - if( IA==IB ) - { - ofs << 1 << " na" << std::endl; - ofs << ucell.atoms[TA].tau[IA].x << " " - << ucell.atoms[TA].tau[IA].y << " " - << ucell.atoms[TA].tau[IA].z << std::endl; - } - else - { - ofs << 2 << " na" << std::endl; - ofs << ucell.atoms[TA].tau[IA].x << " " - << ucell.atoms[TA].tau[IA].y << " " - << ucell.atoms[TA].tau[IA].z << std::endl; - ofs << ucell.atoms[TB].tau[IB].x << " " - << ucell.atoms[TB].tau[IB].y << " " - << ucell.atoms[TB].tau[IB].z << std::endl; - } - } - else - { - ofs << 2 << " ntype" << std::endl; - ofs << ucell.atoms[TA].label << " label" << std::endl; - ofs << 1 << " na" << std::endl; - ofs << ucell.atoms[TA].tau[IA].x << " " - << ucell.atoms[TA].tau[IA].y << " " - << ucell.atoms[TA].tau[IA].z << std::endl; - ofs << ucell.atoms[TB].label << " label" << std::endl; - ofs << 1 << " na" << std::endl; - ofs << ucell.atoms[TB].tau[IB].x << " " - << ucell.atoms[TB].tau[IB].y << " " - << ucell.atoms[TB].tau[IB].z << std::endl; - } - - ofs << info.ecut_exx << " ecutwfc" << std::endl; + ofs << ucell.latvec.e11 << " " << ucell.latvec.e12 << " " << ucell.latvec.e13 << std::endl; + ofs << ucell.latvec.e21 << " " << ucell.latvec.e22 << " " << ucell.latvec.e23 << std::endl; + ofs << ucell.latvec.e31 << " " << ucell.latvec.e32 << " " << ucell.latvec.e33 << std::endl; + + if( TA==TB ) + { + ofs << 1 << " ntype" << std::endl; + ofs << ucell.atoms[TA].label << " label" << std::endl; + if( IA==IB ) + { + ofs << 1 << " na" << std::endl; + ofs << ucell.atoms[TA].tau[IA].x << " " + << ucell.atoms[TA].tau[IA].y << " " + << ucell.atoms[TA].tau[IA].z << std::endl; + } + else + { + ofs << 2 << " na" << std::endl; + ofs << ucell.atoms[TA].tau[IA].x << " " + << ucell.atoms[TA].tau[IA].y << " " + << ucell.atoms[TA].tau[IA].z << std::endl; + ofs << ucell.atoms[TB].tau[IB].x << " " + << ucell.atoms[TB].tau[IB].y << " " + << ucell.atoms[TB].tau[IB].z << std::endl; + } + } + else + { + ofs << 2 << " ntype" << std::endl; + ofs << ucell.atoms[TA].label << " label" << std::endl; + ofs << 1 << " na" << std::endl; + ofs << ucell.atoms[TA].tau[IA].x << " " + << ucell.atoms[TA].tau[IA].y << " " + << ucell.atoms[TA].tau[IA].z << std::endl; + ofs << ucell.atoms[TB].label << " label" << std::endl; + ofs << 1 << " na" << std::endl; + ofs << ucell.atoms[TB].tau[IB].x << " " + << ucell.atoms[TB].tau[IB].y << " " + << ucell.atoms[TB].tau[IB].z << std::endl; + } + + ofs << info.ecut_exx << " ecutwfc" << std::endl; - // this parameter determine the total number of jlq. - ofs << info.ecut_exx << " ecutwfc_jlq" << std::endl; + // this parameter determine the total number of jlq. + ofs << info.ecut_exx << " ecutwfc_jlq" << std::endl; - if(TA==TB) - { ofs << orb_cutoff[TA] << " rcut_Jlq" << std::endl; } - else - { ofs << orb_cutoff[TA] << " " << orb_cutoff[TB] << " rcut_Jlq" << std::endl; } + if(TA==TB) + { ofs << orb_cutoff[TA] << " rcut_Jlq" << std::endl; } + else + { ofs << orb_cutoff[TA] << " " << orb_cutoff[TB] << " rcut_Jlq" << std::endl; } - ofs << 0 << " smooth" << std::endl; - ofs << 0 << " smearing_sigma" << std::endl; + ofs << 0 << " smooth" << std::endl; + ofs << 0 << " smearing_sigma" << std::endl; - ofs << info.tolerence << " tolerence" << std::endl; + ofs << info.tolerence << " tolerence" << std::endl; - ofs << Lmax << " lmax" << std::endl; + ofs << Lmax << " lmax" << std::endl; - ofs << kv.get_nkstot() << " nks" << std::endl; - assert( matrix_V.shape[0]*matrix_V.shape[1] == matrix_V.shape[2]*matrix_V.shape[3] ); - ofs << matrix_V.shape[0]*matrix_V.shape[1] << " nbands" << std::endl; - - auto cal_sum_M = [&range_jles](std::size_t T) -> std::size_t - { - std::size_t sum_M = 0; - for( std::size_t L = 0; L!=range_jles[T].size(); ++L ) - { sum_M += range_jles[T][L].M; } - return sum_M; - }; - const std::size_t nwfc = (TA==TB && IA==IB) ? cal_sum_M(TA) : cal_sum_M(TA)+cal_sum_M(TB); - ofs << nwfc << " nwfc" << std::endl; - - for(const std::size_t ne : ecut_number) - { ofs << ne << " "; } - ofs << "ne" << std::endl; - - ofs << "" << std::endl; - for( int ik=0; ik!=kv.get_nkstot(); ++ik ) - { - ofs << kv.kvec_c[ik].x << " " << kv.kvec_c[ik].y << " " << kv.kvec_c[ik].z; - ofs << " " << kv.wk[ik] * 0.5 << std::endl; - } - ofs << "" << std::endl; + ofs << kv.get_nkstot() << " nks" << std::endl; + assert( matrix_V.shape[0]*matrix_V.shape[1] == matrix_V.shape[2]*matrix_V.shape[3] ); + ofs << matrix_V.shape[0]*matrix_V.shape[1] << " nbands" << std::endl; + + auto cal_sum_M = [&range_jles](std::size_t T) -> std::size_t + { + std::size_t sum_M = 0; + for( std::size_t L = 0; L!=range_jles[T].size(); ++L ) + { sum_M += range_jles[T][L].M; } + return sum_M; + }; + const std::size_t nwfc = (TA==TB && IA==IB) ? cal_sum_M(TA) : cal_sum_M(TA)+cal_sum_M(TB); + ofs << nwfc << " nwfc" << std::endl; + + for(const std::size_t ne : ecut_number) + { ofs << ne << " "; } + ofs << "ne" << std::endl; + + ofs << "" << std::endl; + for( int ik=0; ik!=kv.get_nkstot(); ++ik ) + { + ofs << kv.kvec_c[ik].x << " " << kv.kvec_c[ik].y << " " << kv.kvec_c[ik].z; + ofs << " " << kv.wk[ik] * 0.5 << std::endl; + } + ofs << "" << std::endl; - ofs << std::endl; - }; - - - auto print_Q = [&]( std::ofstream &ofs ) - { - //--------------------- - // < Psi | jY > - //--------------------- - ofs<< "" << std::endl; - for( std::size_t iw0=0; iw0!=matrix_V.shape[0]; ++iw0 ) - { - for( std::size_t iw1=0; iw1!=matrix_V.shape[1]; ++iw1 ) - { - for( std::size_t iat=0; iat!=matrix_Q.size(); ++iat ) - { - const std::size_t it = (iat==0) ? TA : TB; - for( std::size_t il=0; il!=range_jles[it].size(); ++il ) - { - for( std::size_t im=0; im!=range_jles[it][il].M; ++im ) - { - for( std::size_t iq=0; iq!=range_jles[it][il].N; ++iq ) - { - ofs<" << std::endl << std::endl; - }; - - - auto print_S = [&]( std::ofstream &ofs, const double scale=1 ) - { - //--------------------- - // < jY | jY > - //--------------------- - ofs<< "" <" << std::endl << std::endl; - }; - - - auto print_V = [&]( std::ofstream &ofs, const double scale=1 ) - { - //--------------------- - // < Psi | Psi > - //--------------------- - ofs << "" << std::endl; - for( std::size_t iw0=0; iw0!=matrix_V.shape[0]; ++iw0 ) - { - for( std::size_t iw1=0; iw1!=matrix_V.shape[1]; ++iw1 ) - { - for( std::size_t iw2=0; iw2!=matrix_V.shape[2]; ++iw2 ) - { - for( std::size_t iw3=0; iw3!=matrix_V.shape[3]; ++iw3 ) - { - ofs<" << std::endl << std::endl; - }; - - ModuleBase::TITLE("Exx_Opt_Orb","print_matrix"); - std::ofstream ofs(file_name+"_"+std::to_string(TA)+"_"+std::to_string(IA)+"_"+std::to_string(TB)+"_"+std::to_string(IB)); - print_header(ofs); - ofs< + //--------------------- + ofs<< "" << std::endl; + for( std::size_t iw0=0; iw0!=matrix_V.shape[0]; ++iw0 ) + { + for( std::size_t iw1=0; iw1!=matrix_V.shape[1]; ++iw1 ) + { + for( std::size_t iat=0; iat!=matrix_Q.size(); ++iat ) + { + const std::size_t it = (iat==0) ? TA : TB; + for( std::size_t il=0; il!=range_jles[it].size(); ++il ) + { + for( std::size_t im=0; im!=range_jles[it][il].M; ++im ) + { + for( std::size_t iq=0; iq!=range_jles[it][il].N; ++iq ) + { + ofs<" << std::endl << std::endl; + }; + + + auto print_S = [&]( std::ofstream &ofs, const double scale=1 ) + { + //--------------------- + // < jY | jY > + //--------------------- + ofs<< "" <" << std::endl << std::endl; + }; + + + auto print_V = [&]( std::ofstream &ofs, const double scale=1 ) + { + //--------------------- + // < Psi | Psi > + //--------------------- + ofs << "" << std::endl; + for( std::size_t iw0=0; iw0!=matrix_V.shape[0]; ++iw0 ) + { + for( std::size_t iw1=0; iw1!=matrix_V.shape[1]; ++iw1 ) + { + for( std::size_t iw2=0; iw2!=matrix_V.shape[2]; ++iw2 ) + { + for( std::size_t iw3=0; iw3!=matrix_V.shape[3]; ++iw3 ) + { + ofs<" << std::endl << std::endl; + }; + + ModuleBase::TITLE("Exx_Opt_Orb","print_matrix"); + std::ofstream ofs(file_name+"_"+std::to_string(TA)+"_"+std::to_string(IA)+"_"+std::to_string(TB)+"_"+std::to_string(IB)); + print_header(ofs); + ofs< class LRI_CV { private: - using TA = int; - using TC = std::array; - using TAC = std::pair; - using Tdata_real = RI::Global_Func::To_Real_t; + using TA = int; + using TC = std::array; + using TAC = std::pair; + using Tdata_real = RI::Global_Func::To_Real_t; public: - LRI_CV(); - ~LRI_CV(); + LRI_CV(); + ~LRI_CV(); - void set_info_ri(const Exx_Info_RI* p) { p_info_ri = p; } + void set_info_ri(const Exx_Info_RI* p) { p_info_ri = p; } - void set_orbitals( - const UnitCell &ucell, + void set_orbitals( + const UnitCell &ucell, const LCAO_Orbitals& orb, - const std::vector>> &lcaos_in, - const std::vector>> &abfs_in, - const std::vector>> &abfs_ccp_in, - const double &kmesh_times, - std::shared_ptr MGT, + const std::vector>> &lcaos_in, + const std::vector>> &abfs_in, + const std::vector>> &abfs_ccp_in, + const double &kmesh_times, + std::shared_ptr MGT, const bool& init_C); - inline std::map>> - cal_Vs( - const UnitCell &ucell, - const std::vector &list_A0, - const std::vector &list_A1, - const std::map &flags); // "writable_Vws" - inline std::map, 3>>> - cal_dVs( - const UnitCell &ucell, - const std::vector &list_A0, - const std::vector &list_A1, - const std::map &flags); // "writable_dVws" - std::pair>>, + inline std::map>> + cal_Vs( + const UnitCell &ucell, + const std::vector &list_A0, + const std::vector &list_A1, + const std::map &flags); // "writable_Vws" + inline std::map, 3>>> + cal_dVs( + const UnitCell &ucell, + const std::vector &list_A0, + const std::vector &list_A1, + const std::map &flags); // "writable_dVws" + std::pair>>, std::map, 3>>>> - cal_Cs_dCs( - const UnitCell &ucell, - const std::vector &list_A0, - const std::vector &list_A1, - const std::map &flags); // "cal_dC", "writable_Cws", "writable_dCws", "writable_Vws", "writable_dVws" + cal_Cs_dCs( + const UnitCell &ucell, + const std::vector &list_A0, + const std::vector &list_A1, + const std::map &flags); // "cal_dC", "writable_Cws", "writable_dCws", "writable_Vws", "writable_dVws" - size_t get_index_abfs_size(const size_t &iat){return this->index_abfs[iat].count_size; } + size_t get_index_abfs_size(const size_t &iat){return this->index_abfs[iat].count_size; } private: - std::vector>> lcaos; - std::vector>> abfs; - std::vector>> abfs_ccp; - ModuleBase::Element_Basis_Index::IndexLNM index_lcaos; - ModuleBase::Element_Basis_Index::IndexLNM index_abfs; - std::vector lcaos_rcut; + std::vector>> lcaos; + std::vector>> abfs; + std::vector>> abfs_ccp; + ModuleBase::Element_Basis_Index::IndexLNM index_lcaos; + ModuleBase::Element_Basis_Index::IndexLNM index_abfs; + std::vector lcaos_rcut; std::vector abfs_ccp_rcut; - const Exx_Info_RI* p_info_ri = nullptr; + const Exx_Info_RI* p_info_ri = nullptr; public: - std::map,RI::Tensor>>> Vws; - std::map,RI::Tensor>>> Cws; - std::map,std::array,3>>>> dVws; - std::map,std::array,3>>>> dCws; + std::map,RI::Tensor>>> Vws; + std::map,RI::Tensor>>> Cws; + std::map,std::array,3>>>> dVws; + std::map,std::array,3>>>> dCws; private: - pthread_rwlock_t rwlock_Vw; - pthread_rwlock_t rwlock_Cw; - pthread_rwlock_t rwlock_dVw; - pthread_rwlock_t rwlock_dCw; - - Matrix_Orbs11 m_abfs_abfs; - Matrix_Orbs21 m_abfslcaos_lcaos; - - template - using T_func_DPcal_data = std::function &R, - const std::map &flags)>; - using T_func_cal_Rcut = std::function; - template - std::map> - cal_datas( - const UnitCell &ucell, + pthread_rwlock_t rwlock_Vw; + pthread_rwlock_t rwlock_Cw; + pthread_rwlock_t rwlock_dVw; + pthread_rwlock_t rwlock_dCw; + + Matrix_Orbs11 m_abfs_abfs; + Matrix_Orbs21 m_abfslcaos_lcaos; + + template + using T_func_DPcal_data = std::function &R, + const std::map &flags)>; + using T_func_cal_Rcut = std::function; + template + std::map> + cal_datas( + const UnitCell &ucell, const std::vector& list_A0, const std::vector& list_A1, const std::map& flags, @@ -111,34 +111,34 @@ class LRI_CV inline double cal_V_Rcut(const int it0, const int it1); inline double cal_C_Rcut(const int it0, const int it1); - inline RI::Tensor - DPcal_V( - const int it0, - const int it1, - const Abfs::Vector3_Order &R, - const std::map &flags); // "writable_Vws" - inline std::array,3> - DPcal_dV( - const int it0, - const int it1, - const Abfs::Vector3_Order &R, - const std::map &flags); // "writable_dVws" - std::pair, std::array,3>> - DPcal_C_dC( - const int it0, - const int it1, - const Abfs::Vector3_Order &R, - const std::map &flags); // "cal_dC", "writable_Cws", "writable_dCws", "writable_Vws", "writable_dVws" - - template - To11 DPcal_o11( - const int it0, - const int it1, - const Abfs::Vector3_Order &R, - const bool &flag_writable_o11ws, - pthread_rwlock_t &rwlock_o11, - std::map,To11>>> &o11ws, - const Tfunc &func_cal_o11); + inline RI::Tensor + DPcal_V( + const int it0, + const int it1, + const Abfs::Vector3_Order &R, + const std::map &flags); // "writable_Vws" + inline std::array,3> + DPcal_dV( + const int it0, + const int it1, + const Abfs::Vector3_Order &R, + const std::map &flags); // "writable_dVws" + std::pair, std::array,3>> + DPcal_C_dC( + const int it0, + const int it1, + const Abfs::Vector3_Order &R, + const std::map &flags); // "cal_dC", "writable_Cws", "writable_dCws", "writable_Vws", "writable_dVws" + + template + To11 DPcal_o11( + const int it0, + const int it1, + const Abfs::Vector3_Order &R, + const bool &flag_writable_o11ws, + pthread_rwlock_t &rwlock_o11, + std::map,To11>>> &o11ws, + const Tfunc &func_cal_o11); }; #include "lri_cv.hpp" diff --git a/source/source_lcao/module_ri/lri_cv.hpp b/source/source_lcao/module_ri/lri_cv.hpp index e3eaa2d6148..49f197816c0 100644 --- a/source/source_lcao/module_ri/lri_cv.hpp +++ b/source/source_lcao/module_ri/lri_cv.hpp @@ -20,66 +20,66 @@ template LRI_CV::LRI_CV() { - pthread_rwlock_init(&rwlock_Vw,NULL); - pthread_rwlock_init(&rwlock_Cw,NULL); - pthread_rwlock_init(&rwlock_dVw,NULL); - pthread_rwlock_init(&rwlock_dCw,NULL); + pthread_rwlock_init(&rwlock_Vw,NULL); + pthread_rwlock_init(&rwlock_Cw,NULL); + pthread_rwlock_init(&rwlock_dVw,NULL); + pthread_rwlock_init(&rwlock_dCw,NULL); } template LRI_CV::~LRI_CV() { - pthread_rwlock_destroy(&rwlock_Vw); - pthread_rwlock_destroy(&rwlock_Cw); - pthread_rwlock_destroy(&rwlock_dVw); - pthread_rwlock_destroy(&rwlock_dCw); + pthread_rwlock_destroy(&rwlock_Vw); + pthread_rwlock_destroy(&rwlock_Cw); + pthread_rwlock_destroy(&rwlock_dVw); + pthread_rwlock_destroy(&rwlock_dCw); } template void LRI_CV::set_orbitals( - const UnitCell &ucell, - const LCAO_Orbitals& orb, - const std::vector>> &lcaos_in, - const std::vector>> &abfs_in, - const std::vector>> &abfs_ccp_in, - const double &kmesh_times, - std::shared_ptr MGT, + const UnitCell &ucell, + const LCAO_Orbitals& orb, + const std::vector>> &lcaos_in, + const std::vector>> &abfs_in, + const std::vector>> &abfs_ccp_in, + const double &kmesh_times, + std::shared_ptr MGT, const bool& init_C) { - ModuleBase::TITLE("LRI_CV", "set_orbitals"); - ModuleBase::timer::start("LRI_CV", "set_orbitals"); + ModuleBase::TITLE("LRI_CV", "set_orbitals"); + ModuleBase::timer::start("LRI_CV", "set_orbitals"); - this->lcaos = lcaos_in; - this->abfs = abfs_in; - this->abfs_ccp = abfs_ccp_in; + this->lcaos = lcaos_in; + this->abfs = abfs_in; + this->abfs_ccp = abfs_ccp_in; - this->lcaos_rcut = Exx_Abfs::Construct_Orbs::get_Rcut(this->lcaos); + this->lcaos_rcut = Exx_Abfs::Construct_Orbs::get_Rcut(this->lcaos); this->abfs_ccp_rcut = Exx_Abfs::Construct_Orbs::get_Rcut(this->abfs_ccp); - const ModuleBase::Element_Basis_Index::Range - range_lcaos = ModuleBase::Element_Basis_Index::construct_range( lcaos ); - this->index_lcaos = ModuleBase::Element_Basis_Index::construct_index( range_lcaos ); + const ModuleBase::Element_Basis_Index::Range + range_lcaos = ModuleBase::Element_Basis_Index::construct_range( lcaos ); + this->index_lcaos = ModuleBase::Element_Basis_Index::construct_index( range_lcaos ); - const ModuleBase::Element_Basis_Index::Range - range_abfs = ModuleBase::Element_Basis_Index::construct_range( abfs ); - this->index_abfs = ModuleBase::Element_Basis_Index::construct_index( range_abfs ); + const ModuleBase::Element_Basis_Index::Range + range_abfs = ModuleBase::Element_Basis_Index::construct_range( abfs ); + this->index_abfs = ModuleBase::Element_Basis_Index::construct_index( range_abfs ); - this->m_abfs_abfs.MGT = this->m_abfslcaos_lcaos.MGT = MGT; + this->m_abfs_abfs.MGT = this->m_abfslcaos_lcaos.MGT = MGT; this->m_abfs_abfs.init( - this->abfs_ccp, this->abfs, - ucell, orb, kmesh_times); + this->abfs_ccp, this->abfs, + ucell, orb, kmesh_times); if (init_C) this->m_abfslcaos_lcaos.init( - this->abfs_ccp, this->lcaos, this->lcaos, - ucell, orb, kmesh_times); + this->abfs_ccp, this->lcaos, this->lcaos, + ucell, orb, kmesh_times); this->m_abfs_abfs.init_radial_table(); if (init_C) { this->m_abfslcaos_lcaos.init_radial_table(); } - ModuleBase::timer::end("LRI_CV", "set_orbitals"); + ModuleBase::timer::end("LRI_CV", "set_orbitals"); } template @@ -95,7 +95,7 @@ double LRI_CV::cal_C_Rcut(const int it0, const int it1) { template template auto LRI_CV::cal_datas( - const UnitCell &ucell, + const UnitCell &ucell, const std::vector& list_A0, const std::vector& list_A1, const std::map& flags, @@ -103,111 +103,111 @@ auto LRI_CV::cal_datas( const T_func_DPcal_data& func_DPcal_data) -> std::map> { - ModuleBase::TITLE("LRI_CV","cal_datas"); - ModuleBase::timer::start("LRI_CV", "cal_datas"); - - std::map> Datas; - #pragma omp parallel - for(size_t i0=0; i0 tau0 = ucell.atoms[it0].tau[ia0]; - const ModuleBase::Vector3 tau1 = ucell.atoms[it1].tau[ia1]; - const double Rcut + ModuleBase::TITLE("LRI_CV","cal_datas"); + ModuleBase::timer::start("LRI_CV", "cal_datas"); + + std::map> Datas; + #pragma omp parallel + for(size_t i0=0; i0 tau0 = ucell.atoms[it0].tau[ia0]; + const ModuleBase::Vector3 tau1 = ucell.atoms[it1].tau[ia1]; + const double Rcut = std::min(func_cal_Rcut(it0, it1), func_cal_Rcut(it1, it0)); - const Abfs::Vector3_Order R_delta = -tau0+tau1+(RI_Util::array3_to_Vector3(cell1)*ucell.latvec); - if( R_delta.norm()*ucell.lat0 < Rcut ) - { - const Tresult Data = func_DPcal_data(it0, it1, R_delta, flags); - // if(Data.norm(std::numeric_limits::max()) > threshold) - // { - #pragma omp critical(LRI_CV_cal_datas) - Datas[list_A0[i0]][list_A1[i1]] = Data; - // } - } - } - } - ModuleBase::timer::end("LRI_CV", "cal_datas"); - return Datas; + const Abfs::Vector3_Order R_delta = -tau0+tau1+(RI_Util::array3_to_Vector3(cell1)*ucell.latvec); + if( R_delta.norm()*ucell.lat0 < Rcut ) + { + const Tresult Data = func_DPcal_data(it0, it1, R_delta, flags); + // if(Data.norm(std::numeric_limits::max()) > threshold) + // { + #pragma omp critical(LRI_CV_cal_datas) + Datas[list_A0[i0]][list_A1[i1]] = Data; + // } + } + } + } + ModuleBase::timer::end("LRI_CV", "cal_datas"); + return Datas; } template auto LRI_CV::cal_Vs( - const UnitCell &ucell, - const std::vector &list_A0, - const std::vector &list_A1, - const std::map &flags) // + "writable_Vws" + const UnitCell &ucell, + const std::vector &list_A0, + const std::vector &list_A1, + const std::map &flags) // + "writable_Vws" -> std::map>> { - ModuleBase::TITLE("LRI_CV","cal_Vs"); - const T_func_DPcal_data> - func_DPcal_V = std::bind( - &LRI_CV::DPcal_V, this, - std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4); - const T_func_cal_Rcut func_cal_Rcut = std::bind(&LRI_CV::cal_V_Rcut, + ModuleBase::TITLE("LRI_CV","cal_Vs"); + const T_func_DPcal_data> + func_DPcal_V = std::bind( + &LRI_CV::DPcal_V, this, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4); + const T_func_cal_Rcut func_cal_Rcut = std::bind(&LRI_CV::cal_V_Rcut, this, std::placeholders::_1, std::placeholders::_2); - return this->cal_datas(ucell,list_A0, list_A1, flags, func_cal_Rcut, func_DPcal_V); + return this->cal_datas(ucell,list_A0, list_A1, flags, func_cal_Rcut, func_DPcal_V); } template auto LRI_CV::cal_dVs( - const UnitCell &ucell, - const std::vector &list_A0, - const std::vector &list_A1, - const std::map &flags) // + "writable_dVws" + const UnitCell &ucell, + const std::vector &list_A0, + const std::vector &list_A1, + const std::map &flags) // + "writable_dVws" -> std::map, 3>>> { - ModuleBase::TITLE("LRI_CV","cal_dVs"); - const T_func_DPcal_data,3>> - func_DPcal_dV = std::bind( - &LRI_CV::DPcal_dV, this, - std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4); + ModuleBase::TITLE("LRI_CV","cal_dVs"); + const T_func_DPcal_data,3>> + func_DPcal_dV = std::bind( + &LRI_CV::DPcal_dV, this, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4); - const T_func_cal_Rcut func_cal_Rcut = std::bind(&LRI_CV::cal_V_Rcut, + const T_func_cal_Rcut func_cal_Rcut = std::bind(&LRI_CV::cal_V_Rcut, this, std::placeholders::_1, std::placeholders::_2); - return this->cal_datas(ucell,list_A0, list_A1, flags, func_cal_Rcut, func_DPcal_dV); + return this->cal_datas(ucell,list_A0, list_A1, flags, func_cal_Rcut, func_DPcal_dV); } template auto LRI_CV::cal_Cs_dCs( - const UnitCell &ucell, - const std::vector &list_A0, - const std::vector &list_A1, - const std::map &flags) // "cal_dC" + "writable_Cws", "writable_dCws", "writable_Vws", "writable_dVws" + const UnitCell &ucell, + const std::vector &list_A0, + const std::vector &list_A1, + const std::map &flags) // "cal_dC" + "writable_Cws", "writable_dCws", "writable_Vws", "writable_dVws" -> std::pair< std::map>>, std::map, 3>>>> { - ModuleBase::TITLE("LRI_CV","cal_Cs_dCs"); - const T_func_DPcal_data, std::array,3>>> - func_DPcal_C_dC = std::bind( - &LRI_CV::DPcal_C_dC, this, - std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4); + ModuleBase::TITLE("LRI_CV","cal_Cs_dCs"); + const T_func_DPcal_data, std::array,3>>> + func_DPcal_C_dC = std::bind( + &LRI_CV::DPcal_C_dC, this, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4); const T_func_cal_Rcut func_cal_Rcut = std::bind(&LRI_CV::cal_C_Rcut, this, std::placeholders::_1, std::placeholders::_2); - std::map, std::array,3>>>> - Cs_dCs_tmp = this->cal_datas(ucell,list_A0, list_A1, flags, func_cal_Rcut, func_DPcal_C_dC); + std::map, std::array,3>>>> + Cs_dCs_tmp = this->cal_datas(ucell,list_A0, list_A1, flags, func_cal_Rcut, func_DPcal_C_dC); - std::map>> Cs; + std::map>> Cs; std::map, 3>>> dCs; for (auto& Cs_dCs_A: Cs_dCs_tmp) for (auto& Cs_dCs_B: Cs_dCs_A.second) { @@ -217,140 +217,140 @@ auto LRI_CV::cal_Cs_dCs( dCs[Cs_dCs_A.first][Cs_dCs_B.first] = std::move(std::get<1>(Cs_dCs_B.second)); } - return std::make_pair(Cs, dCs); + return std::make_pair(Cs, dCs); } template template To11 LRI_CV::DPcal_o11( - const int it0, - const int it1, - const Abfs::Vector3_Order &R, - const bool &flag_writable_o11ws, - pthread_rwlock_t &rwlock_o11, - std::map,To11>>> &o11ws, - const Tfunc &func_cal_o11) + const int it0, + const int it1, + const Abfs::Vector3_Order &R, + const bool &flag_writable_o11ws, + pthread_rwlock_t &rwlock_o11, + std::map,To11>>> &o11ws, + const Tfunc &func_cal_o11) { - const Abfs::Vector3_Order Rm = -R; - pthread_rwlock_rdlock(&rwlock_o11); - const To11 o11_read = RI::Global_Func::find(o11ws, it0, it1, R); - pthread_rwlock_unlock(&rwlock_o11); - - if(LRI_CV_Tools::exist(o11_read)) - { - return o11_read; - } - else - { - pthread_rwlock_rdlock(&rwlock_o11); - const To11 o11_transform_read = RI::Global_Func::find(o11ws, it1, it0, Rm); - pthread_rwlock_unlock(&rwlock_o11); - - if(LRI_CV_Tools::exist(o11_transform_read)) - { - const To11 o11 = LRI_CV_Tools::transform_Rm(o11_transform_read); - if(flag_writable_o11ws) // such write may be deleted for memory saving with transform_Rm() every time - { - pthread_rwlock_wrlock(&rwlock_o11); - o11ws[it0][it1][R] = o11; - pthread_rwlock_unlock(&rwlock_o11); - } - return o11; - } - else - { - const To11 o11 = func_cal_o11( - it0, it1, ModuleBase::Vector3{0,0,0}, R, - this->index_abfs, this->index_abfs, - Matrix_Orbs11::Matrix_Order::AB); - if(flag_writable_o11ws) - { - pthread_rwlock_wrlock(&rwlock_o11); - o11ws[it0][it1][R] = o11; - pthread_rwlock_unlock(&rwlock_o11); - } - return o11; - } // end else (!exist(o11_transform_read)) - } // end else (!exist(o11_read)) + const Abfs::Vector3_Order Rm = -R; + pthread_rwlock_rdlock(&rwlock_o11); + const To11 o11_read = RI::Global_Func::find(o11ws, it0, it1, R); + pthread_rwlock_unlock(&rwlock_o11); + + if(LRI_CV_Tools::exist(o11_read)) + { + return o11_read; + } + else + { + pthread_rwlock_rdlock(&rwlock_o11); + const To11 o11_transform_read = RI::Global_Func::find(o11ws, it1, it0, Rm); + pthread_rwlock_unlock(&rwlock_o11); + + if(LRI_CV_Tools::exist(o11_transform_read)) + { + const To11 o11 = LRI_CV_Tools::transform_Rm(o11_transform_read); + if(flag_writable_o11ws) // such write may be deleted for memory saving with transform_Rm() every time + { + pthread_rwlock_wrlock(&rwlock_o11); + o11ws[it0][it1][R] = o11; + pthread_rwlock_unlock(&rwlock_o11); + } + return o11; + } + else + { + const To11 o11 = func_cal_o11( + it0, it1, ModuleBase::Vector3{0,0,0}, R, + this->index_abfs, this->index_abfs, + Matrix_Orbs11::Matrix_Order::AB); + if(flag_writable_o11ws) + { + pthread_rwlock_wrlock(&rwlock_o11); + o11ws[it0][it1][R] = o11; + pthread_rwlock_unlock(&rwlock_o11); + } + return o11; + } // end else (!exist(o11_transform_read)) + } // end else (!exist(o11_read)) } template RI::Tensor LRI_CV::DPcal_V( - const int it0, - const int it1, - const Abfs::Vector3_Order &R, - const std::map &flags) // "writable_Vws" + const int it0, + const int it1, + const Abfs::Vector3_Order &R, + const std::map &flags) // "writable_Vws" { - const auto cal_overlap_matrix = std::bind( - &Matrix_Orbs11::cal_overlap_matrix, - &this->m_abfs_abfs, - std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7); - return this->DPcal_o11(it0, it1, R, flags.at("writable_Vws"), this->rwlock_Vw, this->Vws, cal_overlap_matrix); + const auto cal_overlap_matrix = std::bind( + &Matrix_Orbs11::cal_overlap_matrix, + &this->m_abfs_abfs, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7); + return this->DPcal_o11(it0, it1, R, flags.at("writable_Vws"), this->rwlock_Vw, this->Vws, cal_overlap_matrix); } template std::array, 3> LRI_CV::DPcal_dV( - const int it0, - const int it1, - const Abfs::Vector3_Order &R, - const std::map &flags) // "writable_dVws" + const int it0, + const int it1, + const Abfs::Vector3_Order &R, + const std::map &flags) // "writable_dVws" { - if(ModuleBase::Vector3(0,0,0)==R) - { - assert(it0==it1); - const size_t size = this->index_abfs[it0].count_size; - const std::array, 3> dV = { RI::Tensor({size,size}), RI::Tensor({size,size}), RI::Tensor({size,size}) }; - if(flags.at("writable_dVws")) - { - pthread_rwlock_wrlock(&this->rwlock_dVw); - this->dVws[it0][it1][R] = dV; - pthread_rwlock_unlock(&this->rwlock_dVw); - } - return dV; - } - - const auto cal_grad_overlap_matrix = std::bind( - &Matrix_Orbs11::cal_grad_overlap_matrix, - &this->m_abfs_abfs, - std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7); - return this->DPcal_o11(it0, it1, R, flags.at("writable_dVws"), this->rwlock_dVw, this->dVws, cal_grad_overlap_matrix); + if(ModuleBase::Vector3(0,0,0)==R) + { + assert(it0==it1); + const size_t size = this->index_abfs[it0].count_size; + const std::array, 3> dV = { RI::Tensor({size,size}), RI::Tensor({size,size}), RI::Tensor({size,size}) }; + if(flags.at("writable_dVws")) + { + pthread_rwlock_wrlock(&this->rwlock_dVw); + this->dVws[it0][it1][R] = dV; + pthread_rwlock_unlock(&this->rwlock_dVw); + } + return dV; + } + + const auto cal_grad_overlap_matrix = std::bind( + &Matrix_Orbs11::cal_grad_overlap_matrix, + &this->m_abfs_abfs, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7); + return this->DPcal_o11(it0, it1, R, flags.at("writable_dVws"), this->rwlock_dVw, this->dVws, cal_grad_overlap_matrix); } template std::pair, std::array,3>> LRI_CV::DPcal_C_dC( - const int it0, - const int it1, - const Abfs::Vector3_Order &R, - const std::map &flags) // "cal_dC", "writable_Cws", "writable_dCws" + "writable_Vws", "writable_dVws" + const int it0, + const int it1, + const Abfs::Vector3_Order &R, + const std::map &flags) // "cal_dC", "writable_Cws", "writable_dCws" + "writable_Vws", "writable_dVws" { - using namespace LRI_CV_Tools; - - const Abfs::Vector3_Order Rm = -R; - pthread_rwlock_rdlock(&this->rwlock_Cw); - const RI::Tensor C_read = RI::Global_Func::find(this->Cws, it0, it1, R); - pthread_rwlock_unlock(&this->rwlock_Cw); - pthread_rwlock_rdlock(&this->rwlock_dCw); - const std::array,3> dC_read = RI::Global_Func::find(this->dCws, it0, it1, R); - pthread_rwlock_unlock(&this->rwlock_dCw); - const bool flag_finish_dC = (!flags.at("cal_dC")) || LRI_CV_Tools::exist(dC_read); - - if(!C_read.empty() && flag_finish_dC) - { - return std::make_pair(C_read, dC_read); - } - else - { - if( (ModuleBase::Vector3(0,0,0)==R) && (it0==it1) ) - { - const RI::Tensor - A = this->m_abfslcaos_lcaos.template cal_overlap_matrix( - it0, it1, {0,0,0}, {0,0,0}, - this->index_abfs, this->index_lcaos, this->index_lcaos, - Matrix_Orbs21::Matrix_Order::A1A2B); + using namespace LRI_CV_Tools; + + const Abfs::Vector3_Order Rm = -R; + pthread_rwlock_rdlock(&this->rwlock_Cw); + const RI::Tensor C_read = RI::Global_Func::find(this->Cws, it0, it1, R); + pthread_rwlock_unlock(&this->rwlock_Cw); + pthread_rwlock_rdlock(&this->rwlock_dCw); + const std::array,3> dC_read = RI::Global_Func::find(this->dCws, it0, it1, R); + pthread_rwlock_unlock(&this->rwlock_dCw); + const bool flag_finish_dC = (!flags.at("cal_dC")) || LRI_CV_Tools::exist(dC_read); + + if(!C_read.empty() && flag_finish_dC) + { + return std::make_pair(C_read, dC_read); + } + else + { + if( (ModuleBase::Vector3(0,0,0)==R) && (it0==it1) ) + { + const RI::Tensor + A = this->m_abfslcaos_lcaos.template cal_overlap_matrix( + it0, it1, {0,0,0}, {0,0,0}, + this->index_abfs, this->index_lcaos, this->index_lcaos, + Matrix_Orbs21::Matrix_Order::A1A2B); const RI::Tensor V = this->DPcal_V(it0, it0, {0, 0, 0}, {{"writable_Vws", true}}); RI::Tensor L; const double cs_inv_thr = this->p_info_ri != nullptr ? this->p_info_ri->Cs_inv_thr : 0.0; @@ -359,109 +359,109 @@ LRI_CV::DPcal_C_dC( else L = LRI_CV_Tools::cal_I(V); - const RI::Tensor C = RI::Global_Func::convert(0.5) * LRI_CV_Tools::mul1(L,A); // Attention 0.5! - if(flags.at("writable_Cws")) - { - pthread_rwlock_wrlock(&this->rwlock_Cw); - this->Cws[it0][it1][{0,0,0}] = C; - pthread_rwlock_unlock(&this->rwlock_Cw); - } - - if(flag_finish_dC) - { - return std::make_pair(C, dC_read); - } - else - { - const RI::Shape_Vector sizes = {this->index_abfs[it0].count_size, - this->index_lcaos[it0].count_size, - this->index_lcaos[it0].count_size}; - const std::array,3> - dC({RI::Tensor({sizes}), RI::Tensor({sizes}), RI::Tensor({sizes})}); - if(flags.at("writable_dCws")) - { - pthread_rwlock_wrlock(&this->rwlock_dCw); - this->dCws[it0][it1][{0,0,0}] = dC; - pthread_rwlock_unlock(&this->rwlock_dCw); - } - return std::make_pair(C, dC); - } - } // end if( (ModuleBase::Vector3(0,0,0)==R) && (it0==it1) ) - else - { - const std::vector> - A = {this->m_abfslcaos_lcaos.template cal_overlap_matrix( - it0, it1, {0,0,0}, R, - this->index_abfs, this->index_lcaos, this->index_lcaos, - Matrix_Orbs21::Matrix_Order::A1A2B), - this->m_abfslcaos_lcaos.template cal_overlap_matrix( - it1, it0, {0,0,0}, Rm, - this->index_abfs, this->index_lcaos, this->index_lcaos, - Matrix_Orbs21::Matrix_Order::A1BA2)}; - - const std::vector>> - V = {{DPcal_V(it0, it0, {0,0,0}, {{"writable_Vws",true}}), - DPcal_V(it0, it1, R, flags)}, - {DPcal_V(it1, it0, Rm, flags), - DPcal_V(it1, it1, {0,0,0}, {{"writable_Vws",true}})}}; + const RI::Tensor C = RI::Global_Func::convert(0.5) * LRI_CV_Tools::mul1(L,A); // Attention 0.5! + if(flags.at("writable_Cws")) + { + pthread_rwlock_wrlock(&this->rwlock_Cw); + this->Cws[it0][it1][{0,0,0}] = C; + pthread_rwlock_unlock(&this->rwlock_Cw); + } + + if(flag_finish_dC) + { + return std::make_pair(C, dC_read); + } + else + { + const RI::Shape_Vector sizes = {this->index_abfs[it0].count_size, + this->index_lcaos[it0].count_size, + this->index_lcaos[it0].count_size}; + const std::array,3> + dC({RI::Tensor({sizes}), RI::Tensor({sizes}), RI::Tensor({sizes})}); + if(flags.at("writable_dCws")) + { + pthread_rwlock_wrlock(&this->rwlock_dCw); + this->dCws[it0][it1][{0,0,0}] = dC; + pthread_rwlock_unlock(&this->rwlock_dCw); + } + return std::make_pair(C, dC); + } + } // end if( (ModuleBase::Vector3(0,0,0)==R) && (it0==it1) ) + else + { + const std::vector> + A = {this->m_abfslcaos_lcaos.template cal_overlap_matrix( + it0, it1, {0,0,0}, R, + this->index_abfs, this->index_lcaos, this->index_lcaos, + Matrix_Orbs21::Matrix_Order::A1A2B), + this->m_abfslcaos_lcaos.template cal_overlap_matrix( + it1, it0, {0,0,0}, Rm, + this->index_abfs, this->index_lcaos, this->index_lcaos, + Matrix_Orbs21::Matrix_Order::A1BA2)}; + + const std::vector>> + V = {{DPcal_V(it0, it0, {0,0,0}, {{"writable_Vws",true}}), + DPcal_V(it0, it1, R, flags)}, + {DPcal_V(it1, it0, Rm, flags), + DPcal_V(it1, it1, {0,0,0}, {{"writable_Vws",true}})}}; std::vector>> L; const double cs_inv_thr = this->p_info_ri != nullptr ? this->p_info_ri->Cs_inv_thr : 0.0; if (cs_inv_thr > 0) L = LRI_CV_Tools::cal_I(V, Inverse_Matrix::Method::syev, cs_inv_thr); else - L = LRI_CV_Tools::cal_I(V); - - const std::vector> C = LRI_CV_Tools::mul2(L,A); - if(flags.at("writable_Cws")) - { - pthread_rwlock_wrlock(&this->rwlock_Cw); - this->Cws[it0][it1][R] = C[0]; - this->Cws[it1][it0][Rm] = LRI_CV_Tools::transpose12(C[1]); - pthread_rwlock_unlock(&this->rwlock_Cw); - } - - if(flag_finish_dC) - { - return std::make_pair(C[0], dC_read); - } - else - { - const std::vector,3>> - dA = {this->m_abfslcaos_lcaos.template cal_grad_overlap_matrix( - it0, it1, {0,0,0}, R, - this->index_abfs, this->index_lcaos, this->index_lcaos, - Matrix_Orbs21::Matrix_Order::A1A2B), - LRI_CV_Tools::negative( - this->m_abfslcaos_lcaos.template cal_grad_overlap_matrix( - it1, it0, {0,0,0}, Rm, - this->index_abfs, this->index_lcaos, this->index_lcaos, - Matrix_Orbs21::Matrix_Order::A1BA2))}; - - const std::array,3> dV_01 = DPcal_dV(it0, it1, R, flags); - const std::array,3> dV_10 = LRI_CV_Tools::negative(DPcal_dV(it1, it0, Rm, flags)); - - std::array>,3> // dC = L*(dA-dV*C) - dC_tmp = LRI_CV_Tools::mul2( - L, - LRI_CV_Tools::change_order( LRI_CV_Tools::minus( - dA, - std::vector,3>>{ - LRI_CV_Tools::mul1(dV_01, C[1]), - LRI_CV_Tools::mul1(dV_10, C[0])}))); - const std::vector,3>> - dC = LRI_CV_Tools::change_order(std::move(dC_tmp)); - if(flags.at("writable_dCws")) - { - pthread_rwlock_wrlock(&this->rwlock_dCw); - this->dCws[it0][it1][R] = dC[0]; - this->dCws[it1][it0][Rm] = LRI_CV_Tools::negative(LRI_CV_Tools::transpose12(dC[1])); - pthread_rwlock_unlock(&this->rwlock_dCw); - } - return std::make_pair(C[0], dC[0]); - } // end else (!flag_finish_dC) - } // end else ( (ModuleBase::Vector3(0,0,0)!=R) || (it0!=it1) ) - } // end else (!(C_read && flag_finish_dC)) + L = LRI_CV_Tools::cal_I(V); + + const std::vector> C = LRI_CV_Tools::mul2(L,A); + if(flags.at("writable_Cws")) + { + pthread_rwlock_wrlock(&this->rwlock_Cw); + this->Cws[it0][it1][R] = C[0]; + this->Cws[it1][it0][Rm] = LRI_CV_Tools::transpose12(C[1]); + pthread_rwlock_unlock(&this->rwlock_Cw); + } + + if(flag_finish_dC) + { + return std::make_pair(C[0], dC_read); + } + else + { + const std::vector,3>> + dA = {this->m_abfslcaos_lcaos.template cal_grad_overlap_matrix( + it0, it1, {0,0,0}, R, + this->index_abfs, this->index_lcaos, this->index_lcaos, + Matrix_Orbs21::Matrix_Order::A1A2B), + LRI_CV_Tools::negative( + this->m_abfslcaos_lcaos.template cal_grad_overlap_matrix( + it1, it0, {0,0,0}, Rm, + this->index_abfs, this->index_lcaos, this->index_lcaos, + Matrix_Orbs21::Matrix_Order::A1BA2))}; + + const std::array,3> dV_01 = DPcal_dV(it0, it1, R, flags); + const std::array,3> dV_10 = LRI_CV_Tools::negative(DPcal_dV(it1, it0, Rm, flags)); + + std::array>,3> // dC = L*(dA-dV*C) + dC_tmp = LRI_CV_Tools::mul2( + L, + LRI_CV_Tools::change_order( LRI_CV_Tools::minus( + dA, + std::vector,3>>{ + LRI_CV_Tools::mul1(dV_01, C[1]), + LRI_CV_Tools::mul1(dV_10, C[0])}))); + const std::vector,3>> + dC = LRI_CV_Tools::change_order(std::move(dC_tmp)); + if(flags.at("writable_dCws")) + { + pthread_rwlock_wrlock(&this->rwlock_dCw); + this->dCws[it0][it1][R] = dC[0]; + this->dCws[it1][it0][Rm] = LRI_CV_Tools::negative(LRI_CV_Tools::transpose12(dC[1])); + pthread_rwlock_unlock(&this->rwlock_dCw); + } + return std::make_pair(C[0], dC[0]); + } // end else (!flag_finish_dC) + } // end else ( (ModuleBase::Vector3(0,0,0)!=R) || (it0!=it1) ) + } // end else (!(C_read && flag_finish_dC)) } diff --git a/source/source_lcao/module_ri/lri_cv_tools.hpp b/source/source_lcao/module_ri/lri_cv_tools.hpp index 37b35445c60..1f96ec8c33d 100644 --- a/source/source_lcao/module_ri/lri_cv_tools.hpp +++ b/source/source_lcao/module_ri/lri_cv_tools.hpp @@ -365,46 +365,46 @@ std::map>> template std::array LRI_CV_Tools::cal_latvec_range(const double& rcut_times, - const UnitCell &ucell, - const std::vector& orb_cutoff) { + const UnitCell &ucell, + const std::vector& orb_cutoff) { double Rcut_max = 0; for(int T=0; T proj = ModuleBase::Mathzone::latvec_projection( - std::array,3>{ucell.a1, ucell.a2, ucell.a3}); - const ModuleBase::Vector3 latvec_times = Rcut_max * rcut_times / (proj * ucell.lat0); + Rcut_max = std::max(Rcut_max, orb_cutoff[T]); + const ModuleBase::Vector3 proj = ModuleBase::Mathzone::latvec_projection( + std::array,3>{ucell.a1, ucell.a2, ucell.a3}); + const ModuleBase::Vector3 latvec_times = Rcut_max * rcut_times / (proj * ucell.lat0); const ModuleBase::Vector3 latvec_times_ceil = {static_cast(std::ceil(latvec_times.x)), static_cast(std::ceil(latvec_times.y)), static_cast(std::ceil(latvec_times.z))}; const ModuleBase::Vector3 period = 2 * latvec_times_ceil + ModuleBase::Vector3{1,1,1}; - return std::array{period.x, period.y, period.z}; + return std::array{period.x, period.y, period.z}; } template std::map,RI::Tensor>>> LRI_CV_Tools::get_CVws( - const UnitCell &ucell, - const std::map>,RI::Tensor>> &CVs) + const UnitCell &ucell, + const std::map>,RI::Tensor>> &CVs) { - std::map,RI::Tensor>>> CVws; - for(const auto &CVs_A : CVs) - { - const TA iat0 = CVs_A.first; - const int it0 = ucell.iat2it[iat0]; - const int ia0 = ucell.iat2ia[iat0]; - const ModuleBase::Vector3 tau0 = ucell.atoms[it0].tau[ia0]; - for(const auto &CVs_B : CVs_A.second) - { - const TA iat1 = CVs_B.first.first; - const int it1 = ucell.iat2it[iat1]; - const int ia1 = ucell.iat2ia[iat1]; - const std::array &cell1 = CVs_B.first.second; - const ModuleBase::Vector3 tau1 = ucell.atoms[it1].tau[ia1]; - const Abfs::Vector3_Order R_delta = -tau0+tau1+(RI_Util::array3_to_Vector3(cell1)*ucell.latvec); - CVws[it0][it1][R_delta] = CVs_B.second; - } - } - return CVws; + std::map,RI::Tensor>>> CVws; + for(const auto &CVs_A : CVs) + { + const TA iat0 = CVs_A.first; + const int it0 = ucell.iat2it[iat0]; + const int ia0 = ucell.iat2ia[iat0]; + const ModuleBase::Vector3 tau0 = ucell.atoms[it0].tau[ia0]; + for(const auto &CVs_B : CVs_A.second) + { + const TA iat1 = CVs_B.first.first; + const int it1 = ucell.iat2it[iat1]; + const int ia1 = ucell.iat2ia[iat1]; + const std::array &cell1 = CVs_B.first.second; + const ModuleBase::Vector3 tau1 = ucell.atoms[it1].tau[ia1]; + const Abfs::Vector3_Order R_delta = -tau0+tau1+(RI_Util::array3_to_Vector3(cell1)*ucell.latvec); + CVws[it0][it1][R_delta] = CVs_B.second; + } + } + return CVws; } template @@ -521,42 +521,42 @@ std::array, N> template std::array,RI::Tensor>>,3>,3> LRI_CV_Tools::cal_dMRs( - const UnitCell &ucell, - const std::array,RI::Tensor>>,3> &dMs) + const UnitCell &ucell, + const std::array,RI::Tensor>>,3> &dMs) { - auto get_R_delta = [&](const TA &iat0, const std::pair &A1) -> std::array - { - const TA iat1 = A1.first; - const TC &cell1 = A1.second; - const int it0 = ucell.iat2it[iat0]; - const int ia0 = ucell.iat2ia[iat0]; - const int it1 = ucell.iat2it[iat1]; - const int ia1 = ucell.iat2ia[iat1]; - const ModuleBase::Vector3 tau0 = ucell.atoms[it0].tau[ia0]; - const ModuleBase::Vector3 tau1 = ucell.atoms[it1].tau[ia1]; - const Abfs::Vector3_Order R_delta = -tau0+tau1+(RI_Util::array3_to_Vector3(cell1)*ucell.latvec); - return std::array{R_delta.x, R_delta.y, R_delta.z}; - }; - constexpr int Npos = 3; - std::array,RI::Tensor>>,Npos>,Npos> dMRs; - for(int ipos0=0; ipos0 A1 = dMs_B.first; - const RI::Tensor &dM = dMs_B.second; - const std::array R_delta = get_R_delta(iat0, A1); - dMRs[ipos0][ipos1][iat0][A1] = dM * R_delta[ipos1]; - } - } - } - } - return dMRs; + auto get_R_delta = [&](const TA &iat0, const std::pair &A1) -> std::array + { + const TA iat1 = A1.first; + const TC &cell1 = A1.second; + const int it0 = ucell.iat2it[iat0]; + const int ia0 = ucell.iat2ia[iat0]; + const int it1 = ucell.iat2it[iat1]; + const int ia1 = ucell.iat2ia[iat1]; + const ModuleBase::Vector3 tau0 = ucell.atoms[it0].tau[ia0]; + const ModuleBase::Vector3 tau1 = ucell.atoms[it1].tau[ia1]; + const Abfs::Vector3_Order R_delta = -tau0+tau1+(RI_Util::array3_to_Vector3(cell1)*ucell.latvec); + return std::array{R_delta.x, R_delta.y, R_delta.z}; + }; + constexpr int Npos = 3; + std::array,RI::Tensor>>,Npos>,Npos> dMRs; + for(int ipos0=0; ipos0 A1 = dMs_B.first; + const RI::Tensor &dM = dMs_B.second; + const std::array R_delta = get_R_delta(iat0, A1); + dMRs[ipos0][ipos1][iat0][A1] = dM * R_delta[ipos1]; + } + } + } + } + return dMRs; } #endif diff --git a/source/source_lcao/module_ri/matrix_orbs11.hpp b/source/source_lcao/module_ri/matrix_orbs11.hpp index 8a0d553d94c..2d6dff345f7 100644 --- a/source/source_lcao/module_ri/matrix_orbs11.hpp +++ b/source/source_lcao/module_ri/matrix_orbs11.hpp @@ -11,150 +11,150 @@ template RI::Tensor Matrix_Orbs11::cal_overlap_matrix( - const size_t TA, - const size_t TB, - const ModuleBase::Vector3 &tauA, - const ModuleBase::Vector3 &tauB, - const ModuleBase::Element_Basis_Index::IndexLNM &index_A, - const ModuleBase::Element_Basis_Index::IndexLNM &index_B, - const Matrix_Order &matrix_order) const + const size_t TA, + const size_t TB, + const ModuleBase::Vector3 &tauA, + const ModuleBase::Vector3 &tauB, + const ModuleBase::Element_Basis_Index::IndexLNM &index_A, + const ModuleBase::Element_Basis_Index::IndexLNM &index_B, + const Matrix_Order &matrix_order) const { - RI::Tensor m; - const double lat0 = *this->lat0; - const size_t sizeA = index_A[TA].count_size; - const size_t sizeB = index_B[TB].count_size; - switch(matrix_order) - { - case Matrix_Order::AB: m = RI::Tensor({sizeA, sizeB}); break; - case Matrix_Order::BA: m = RI::Tensor({sizeB, sizeA}); break; - default: throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); - } + RI::Tensor m; + const double lat0 = *this->lat0; + const size_t sizeA = index_A[TA].count_size; + const size_t sizeB = index_B[TB].count_size; + switch(matrix_order) + { + case Matrix_Order::AB: m = RI::Tensor({sizeA, sizeB}); break; + case Matrix_Order::BA: m = RI::Tensor({sizeB, sizeA}); break; + default: throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + } - for( const auto &co3 : center2_orb11_s.at(TA).at(TB) ) - { - const int LA = co3.first; - for( const auto &co4 : co3.second ) - { - const size_t NA = co4.first; - for( size_t MA=0; MA!=2*LA+1; ++MA ) - { - for( const auto &co5 : co4.second ) - { - const int LB = co5.first; - for( const auto &co6 : co5.second ) - { - const size_t NB = co6.first; - for( size_t MB=0; MB!=2*LB+1; ++MB ) - { - const Tdata overlap = co6.second.cal_overlap( tauA*lat0, tauB*lat0, MA, MB ); - const size_t iA = index_A[TA][LA][NA][MA]; - const size_t iB = index_B[TB][LB][NB][MB]; - switch(matrix_order) - { - case Matrix_Order::AB: m(iA,iB) = overlap; break; - case Matrix_Order::BA: m(iB,iA) = overlap; break; - default: throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); - } - } - } - } - } - } - } - return m; + for( const auto &co3 : center2_orb11_s.at(TA).at(TB) ) + { + const int LA = co3.first; + for( const auto &co4 : co3.second ) + { + const size_t NA = co4.first; + for( size_t MA=0; MA!=2*LA+1; ++MA ) + { + for( const auto &co5 : co4.second ) + { + const int LB = co5.first; + for( const auto &co6 : co5.second ) + { + const size_t NB = co6.first; + for( size_t MB=0; MB!=2*LB+1; ++MB ) + { + const Tdata overlap = co6.second.cal_overlap( tauA*lat0, tauB*lat0, MA, MB ); + const size_t iA = index_A[TA][LA][NA][MA]; + const size_t iB = index_B[TB][LB][NB][MB]; + switch(matrix_order) + { + case Matrix_Order::AB: m(iA,iB) = overlap; break; + case Matrix_Order::BA: m(iB,iA) = overlap; break; + default: throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + } + } + } + } + } + } + } + return m; } template std::array,3> Matrix_Orbs11::cal_grad_overlap_matrix( - const size_t TA, - const size_t TB, - const ModuleBase::Vector3 &tauA, - const ModuleBase::Vector3 &tauB, - const ModuleBase::Element_Basis_Index::IndexLNM &index_A, - const ModuleBase::Element_Basis_Index::IndexLNM &index_B, - const Matrix_Order &matrix_order) const + const size_t TA, + const size_t TB, + const ModuleBase::Vector3 &tauA, + const ModuleBase::Vector3 &tauB, + const ModuleBase::Element_Basis_Index::IndexLNM &index_A, + const ModuleBase::Element_Basis_Index::IndexLNM &index_B, + const Matrix_Order &matrix_order) const { - std::array,3> m; - const double lat0 = *this->lat0; - const size_t sizeA = index_A[TA].count_size; - const size_t sizeB = index_B[TB].count_size; - for(int i=0; i({sizeA, sizeB}); break; - case Matrix_Order::BA: m[i] = RI::Tensor({sizeB, sizeA}); break; - default: throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); - } - } + std::array,3> m; + const double lat0 = *this->lat0; + const size_t sizeA = index_A[TA].count_size; + const size_t sizeB = index_B[TB].count_size; + for(int i=0; i({sizeA, sizeB}); break; + case Matrix_Order::BA: m[i] = RI::Tensor({sizeB, sizeA}); break; + default: throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + } + } - for( const auto &co3 : center2_orb11_s.at(TA).at(TB) ) - { - const int LA = co3.first; - for( const auto &co4 : co3.second ) - { - const size_t NA = co4.first; - for( size_t MA=0; MA!=2*LA+1; ++MA ) - { - for( const auto &co5 : co4.second ) - { - const int LB = co5.first; - for( const auto &co6 : co5.second ) - { - const size_t NB = co6.first; - for( size_t MB=0; MB!=2*LB+1; ++MB ) - { - const std::array grad_overlap = RI_Util::Vector3_to_array3(co6.second.cal_grad_overlap( tauA*lat0, tauB*lat0, MA, MB )); - const size_t iA = index_A[TA][LA][NA][MA]; - const size_t iB = index_B[TB][LB][NB][MB]; - for(size_t i=0; i grad_overlap = RI_Util::Vector3_to_array3(co6.second.cal_grad_overlap( tauA*lat0, tauB*lat0, MA, MB )); + const size_t iA = index_A[TA][LA][NA][MA]; + const size_t iB = index_B[TB][LB][NB][MB]; + for(size_t i=0; i std::map>>>> Matrix_Orbs11::cal_overlap_matrix_all( - const UnitCell &ucell, - const ModuleBase::Element_Basis_Index::IndexLNM &index_r, - const ModuleBase::Element_Basis_Index::IndexLNM &index_c ) const + const UnitCell &ucell, + const ModuleBase::Element_Basis_Index::IndexLNM &index_r, + const ModuleBase::Element_Basis_Index::IndexLNM &index_c ) const { - ModuleBase::TITLE("Matrix_Orbs11","cal_overlap_matrix"); + ModuleBase::TITLE("Matrix_Orbs11","cal_overlap_matrix"); - std::map>>>> matrixes; + std::map>>>> matrixes; - for( const auto &co1 : center2_orb11_s ) - { - const size_t TA = co1.first; - for (size_t IA=0; IA!=ucell.atoms[TA].na; ++IA) - { - const ModuleBase::Vector3 &tauA( ucell.atoms[TA].tau[IA] ); + for( const auto &co1 : center2_orb11_s ) + { + const size_t TA = co1.first; + for (size_t IA=0; IA!=ucell.atoms[TA].na; ++IA) + { + const ModuleBase::Vector3 &tauA( ucell.atoms[TA].tau[IA] ); - for( const auto &co2 : co1.second ) - { - const size_t TB = co2.first; - for (size_t IB=0; IB!=ucell.atoms[TB].na; ++IB) - { - const ModuleBase::Vector3 &tauB( ucell.atoms[TB].tau[IB] ); + for( const auto &co2 : co1.second ) + { + const size_t TB = co2.first; + for (size_t IB=0; IB!=ucell.atoms[TB].na; ++IB) + { + const ModuleBase::Vector3 &tauB( ucell.atoms[TB].tau[IB] ); - matrixes[TA][IA][TB][IB] = cal_overlap_matrix( TA, TB, tauA, tauB, index_r, index_c, Matrix_Order::AB ); - } - } - } - } - return matrixes; + matrixes[TA][IA][TB][IB] = cal_overlap_matrix( TA, TB, tauA, tauB, index_r, index_c, Matrix_Order::AB ); + } + } + } + } + return matrixes; } #endif diff --git a/source/source_lcao/module_ri/matrix_orbs21.hpp b/source/source_lcao/module_ri/matrix_orbs21.hpp index 11018b8bb74..b6f464d7440 100644 --- a/source/source_lcao/module_ri/matrix_orbs21.hpp +++ b/source/source_lcao/module_ri/matrix_orbs21.hpp @@ -11,210 +11,210 @@ template RI::Tensor Matrix_Orbs21::cal_overlap_matrix( - const size_t TA, - const size_t TB, - const ModuleBase::Vector3 &tauA, - const ModuleBase::Vector3 &tauB, - const ModuleBase::Element_Basis_Index::IndexLNM &index_A1, - const ModuleBase::Element_Basis_Index::IndexLNM &index_A2, - const ModuleBase::Element_Basis_Index::IndexLNM &index_B, - const Matrix_Order &matrix_order) const + const size_t TA, + const size_t TB, + const ModuleBase::Vector3 &tauA, + const ModuleBase::Vector3 &tauB, + const ModuleBase::Element_Basis_Index::IndexLNM &index_A1, + const ModuleBase::Element_Basis_Index::IndexLNM &index_A2, + const ModuleBase::Element_Basis_Index::IndexLNM &index_B, + const Matrix_Order &matrix_order) const { - RI::Tensor m; - const double lat0 = *this->lat0; - const size_t sizeA1 = index_A1[TA].count_size; - const size_t sizeA2 = index_A2[TA].count_size; - const size_t sizeB = index_B[TB].count_size; - switch(matrix_order) - { - case Matrix_Order::A1A2B: m = RI::Tensor({sizeA1, sizeA2, sizeB}); break; - case Matrix_Order::A1BA2: m = RI::Tensor({sizeA1, sizeB, sizeA2}); break; - case Matrix_Order::BA1A2: m = RI::Tensor({sizeB, sizeA1, sizeA2}); break; - case Matrix_Order::BA2A1: m = RI::Tensor({sizeB, sizeA2, sizeA1}); break; - case Matrix_Order::A2A1B: m = RI::Tensor({sizeA2, sizeA1, sizeB}); break; - case Matrix_Order::A2BA1: m = RI::Tensor({sizeA2, sizeB, sizeA1}); break; - default: throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); - } + RI::Tensor m; + const double lat0 = *this->lat0; + const size_t sizeA1 = index_A1[TA].count_size; + const size_t sizeA2 = index_A2[TA].count_size; + const size_t sizeB = index_B[TB].count_size; + switch(matrix_order) + { + case Matrix_Order::A1A2B: m = RI::Tensor({sizeA1, sizeA2, sizeB}); break; + case Matrix_Order::A1BA2: m = RI::Tensor({sizeA1, sizeB, sizeA2}); break; + case Matrix_Order::BA1A2: m = RI::Tensor({sizeB, sizeA1, sizeA2}); break; + case Matrix_Order::BA2A1: m = RI::Tensor({sizeB, sizeA2, sizeA1}); break; + case Matrix_Order::A2A1B: m = RI::Tensor({sizeA2, sizeA1, sizeB}); break; + case Matrix_Order::A2BA1: m = RI::Tensor({sizeA2, sizeB, sizeA1}); break; + default: throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + } - for( const auto &co3 : center2_orb21_s.at(TA).at(TB) ) - { - const int LA1 = co3.first; - for( const auto &co4 : co3.second ) - { - const size_t NA1 = co4.first; - for( size_t MA1=0; MA1!=2*LA1+1; ++MA1 ) - { - for( const auto &co5 : co4.second ) - { - const int LA2 = co5.first; - for( const auto &co6 : co5.second ) - { - const size_t NA2 = co6.first; - for( size_t MA2=0; MA2!=2*LA2+1; ++MA2 ) - { - for( const auto &co7 : co6.second ) - { - const int LB = co7.first; - for( const auto &co8 : co7.second ) - { - const size_t NB = co8.first; - for( size_t MB=0; MB!=2*LB+1; ++MB ) - { - const Tdata overlap = co8.second.cal_overlap( tauA*lat0, tauB*lat0, MA1, MA2, MB ); - const size_t iA1 = index_A1[TA][LA1][NA1][MA1]; - const size_t iA2 = index_A2[TA][LA2][NA2][MA2]; - const size_t iB = index_B[TB][LB][NB][MB]; - switch(matrix_order) - { - case Matrix_Order::A1A2B: m(iA1,iA2,iB) = overlap; break; - case Matrix_Order::A1BA2: m(iA1,iB,iA2) = overlap; break; - case Matrix_Order::A2A1B: m(iA2,iA1,iB) = overlap; break; - case Matrix_Order::A2BA1: m(iA2,iB,iA1) = overlap; break; - case Matrix_Order::BA1A2: m(iB,iA1,iA2) = overlap; break; - case Matrix_Order::BA2A1: m(iB,iA2,iA1) = overlap; break; - default: throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); - } - } - } - } - } - } - } - } - } - } - return m; + for( const auto &co3 : center2_orb21_s.at(TA).at(TB) ) + { + const int LA1 = co3.first; + for( const auto &co4 : co3.second ) + { + const size_t NA1 = co4.first; + for( size_t MA1=0; MA1!=2*LA1+1; ++MA1 ) + { + for( const auto &co5 : co4.second ) + { + const int LA2 = co5.first; + for( const auto &co6 : co5.second ) + { + const size_t NA2 = co6.first; + for( size_t MA2=0; MA2!=2*LA2+1; ++MA2 ) + { + for( const auto &co7 : co6.second ) + { + const int LB = co7.first; + for( const auto &co8 : co7.second ) + { + const size_t NB = co8.first; + for( size_t MB=0; MB!=2*LB+1; ++MB ) + { + const Tdata overlap = co8.second.cal_overlap( tauA*lat0, tauB*lat0, MA1, MA2, MB ); + const size_t iA1 = index_A1[TA][LA1][NA1][MA1]; + const size_t iA2 = index_A2[TA][LA2][NA2][MA2]; + const size_t iB = index_B[TB][LB][NB][MB]; + switch(matrix_order) + { + case Matrix_Order::A1A2B: m(iA1,iA2,iB) = overlap; break; + case Matrix_Order::A1BA2: m(iA1,iB,iA2) = overlap; break; + case Matrix_Order::A2A1B: m(iA2,iA1,iB) = overlap; break; + case Matrix_Order::A2BA1: m(iA2,iB,iA1) = overlap; break; + case Matrix_Order::BA1A2: m(iB,iA1,iA2) = overlap; break; + case Matrix_Order::BA2A1: m(iB,iA2,iA1) = overlap; break; + default: throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + } + } + } + } + } + } + } + } + } + } + return m; } template std::array,3> Matrix_Orbs21::cal_grad_overlap_matrix( - const size_t TA, - const size_t TB, - const ModuleBase::Vector3 &tauA, - const ModuleBase::Vector3 &tauB, - const ModuleBase::Element_Basis_Index::IndexLNM &index_A1, - const ModuleBase::Element_Basis_Index::IndexLNM &index_A2, - const ModuleBase::Element_Basis_Index::IndexLNM &index_B, - const Matrix_Order &matrix_order) const + const size_t TA, + const size_t TB, + const ModuleBase::Vector3 &tauA, + const ModuleBase::Vector3 &tauB, + const ModuleBase::Element_Basis_Index::IndexLNM &index_A1, + const ModuleBase::Element_Basis_Index::IndexLNM &index_A2, + const ModuleBase::Element_Basis_Index::IndexLNM &index_B, + const Matrix_Order &matrix_order) const { - std::array,3> m; - const double lat0 = *this->lat0; - const size_t sizeA1 = index_A1[TA].count_size; - const size_t sizeA2 = index_A2[TA].count_size; - const size_t sizeB = index_B[TB].count_size; - for(int i=0; i({sizeA1, sizeA2, sizeB}); break; - case Matrix_Order::A1BA2: m[i] = RI::Tensor({sizeA1, sizeB, sizeA2}); break; - case Matrix_Order::BA1A2: m[i] = RI::Tensor({sizeB, sizeA1, sizeA2}); break; - case Matrix_Order::BA2A1: m[i] = RI::Tensor({sizeB, sizeA2, sizeA1}); break; - case Matrix_Order::A2A1B: m[i] = RI::Tensor({sizeA2, sizeA1, sizeB}); break; - case Matrix_Order::A2BA1: m[i] = RI::Tensor({sizeA2, sizeB, sizeA1}); break; - default: throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); - } - } + std::array,3> m; + const double lat0 = *this->lat0; + const size_t sizeA1 = index_A1[TA].count_size; + const size_t sizeA2 = index_A2[TA].count_size; + const size_t sizeB = index_B[TB].count_size; + for(int i=0; i({sizeA1, sizeA2, sizeB}); break; + case Matrix_Order::A1BA2: m[i] = RI::Tensor({sizeA1, sizeB, sizeA2}); break; + case Matrix_Order::BA1A2: m[i] = RI::Tensor({sizeB, sizeA1, sizeA2}); break; + case Matrix_Order::BA2A1: m[i] = RI::Tensor({sizeB, sizeA2, sizeA1}); break; + case Matrix_Order::A2A1B: m[i] = RI::Tensor({sizeA2, sizeA1, sizeB}); break; + case Matrix_Order::A2BA1: m[i] = RI::Tensor({sizeA2, sizeB, sizeA1}); break; + default: throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + } + } - for( const auto &co3 : center2_orb21_s.at(TA).at(TB) ) - { - const int LA1 = co3.first; - for( const auto &co4 : co3.second ) - { - const size_t NA1 = co4.first; - for( size_t MA1=0; MA1!=2*LA1+1; ++MA1 ) - { - for( const auto &co5 : co4.second ) - { - const int LA2 = co5.first; - for( const auto &co6 : co5.second ) - { - const size_t NA2 = co6.first; - for( size_t MA2=0; MA2!=2*LA2+1; ++MA2 ) - { - for( const auto &co7 : co6.second ) - { - const int LB = co7.first; - for( const auto &co8 : co7.second ) - { - const size_t NB = co8.first; - for( size_t MB=0; MB!=2*LB+1; ++MB ) - { - const std::array grad_overlap = RI_Util::Vector3_to_array3(co8.second.cal_grad_overlap( tauA*lat0, tauB*lat0, MA1, MA2, MB )); - const size_t iA1 = index_A1[TA][LA1][NA1][MA1]; - const size_t iA2 = index_A2[TA][LA2][NA2][MA2]; - const size_t iB = index_B[TB][LB][NB][MB]; - for(size_t i=0; i grad_overlap = RI_Util::Vector3_to_array3(co8.second.cal_grad_overlap( tauA*lat0, tauB*lat0, MA1, MA2, MB )); + const size_t iA1 = index_A1[TA][LA1][NA1][MA1]; + const size_t iA2 = index_A2[TA][LA2][NA2][MA2]; + const size_t iB = index_B[TB][LB][NB][MB]; + for(size_t i=0; i std::map>>>>> Matrix_Orbs21::cal_overlap_matrix_all( - const UnitCell &ucell, - const ModuleBase::Element_Basis_Index::IndexLNM &index_A1, - const ModuleBase::Element_Basis_Index::IndexLNM &index_A2, - const ModuleBase::Element_Basis_Index::IndexLNM &index_B) const + const UnitCell &ucell, + const ModuleBase::Element_Basis_Index::IndexLNM &index_A1, + const ModuleBase::Element_Basis_Index::IndexLNM &index_A2, + const ModuleBase::Element_Basis_Index::IndexLNM &index_B) const { - ModuleBase::TITLE("Matrix_Orbs21","cal_overlap_matrix"); + ModuleBase::TITLE("Matrix_Orbs21","cal_overlap_matrix"); - std::map>>>>> matrixes; + std::map>>>>> matrixes; - for( const auto &co1 : center2_orb21_s ) - { - const size_t TA = co1.first; - for( size_t IA=0; IA!=ucell.atoms[TA].na; ++IA ) - { - const ModuleBase::Vector3 &tauA( ucell.atoms[TA].tau[IA] ); + for( const auto &co1 : center2_orb21_s ) + { + const size_t TA = co1.first; + for( size_t IA=0; IA!=ucell.atoms[TA].na; ++IA ) + { + const ModuleBase::Vector3 &tauA( ucell.atoms[TA].tau[IA] ); - for( const auto &co2 : co1.second ) - { - const size_t TB = co2.first; - for( size_t IB=0; IB!=ucell.atoms[TB].na; ++IB ) - { - const ModuleBase::Vector3 &tauB( ucell.atoms[TB].tau[IB] ); + for( const auto &co2 : co1.second ) + { + const size_t TB = co2.first; + for( size_t IB=0; IB!=ucell.atoms[TB].na; ++IB ) + { + const ModuleBase::Vector3 &tauB( ucell.atoms[TB].tau[IB] ); - const RI::Tensor &&m = cal_overlap_matrix( TA, TB, tauA, tauB, index_A1, index_A2, index_B, Matrix_Order::A2BA1 ); - matrixes[TA][IA][TB][IB].resize(2); - matrixes[TA][IA][TB][IB][0] = std::move(m); - const RI::Tensor &&n = cal_overlap_matrix( TA, TB, tauA, tauB, index_A1, index_A2, index_B, Matrix_Order::BA2A1 ); - matrixes[TB][IB][TA][IA].resize(2); - matrixes[TB][IB][TA][IA][1] = std::move(n); + const RI::Tensor &&m = cal_overlap_matrix( TA, TB, tauA, tauB, index_A1, index_A2, index_B, Matrix_Order::A2BA1 ); + matrixes[TA][IA][TB][IB].resize(2); + matrixes[TA][IA][TB][IB][0] = std::move(m); + const RI::Tensor &&n = cal_overlap_matrix( TA, TB, tauA, tauB, index_A1, index_A2, index_B, Matrix_Order::BA2A1 ); + matrixes[TB][IB][TA][IA].resize(2); + matrixes[TB][IB][TA][IA][1] = std::move(n); } - } - } + } + } } - // matrixes[T][I][T][I][0] = matrixes[T][I][T][I][1], so delete repeat + // matrixes[T][I][T][I][0] = matrixes[T][I][T][I][1], so delete repeat for (auto m1 : matrixes) - { - const size_t T = m1.first; - for( auto m2 : m1.second ) - { - const size_t I = m2.first; - matrixes[T][I][T][I].resize(1); - } - } + { + const size_t T = m1.first; + for( auto m2 : m1.second ) + { + const size_t I = m2.first; + matrixes[T][I][T][I].resize(1); + } + } - return matrixes; + return matrixes; } #endif diff --git a/source/source_lcao/module_ri/matrix_orbs22.hpp b/source/source_lcao/module_ri/matrix_orbs22.hpp index 8df841616d8..972f61e0add 100644 --- a/source/source_lcao/module_ri/matrix_orbs22.hpp +++ b/source/source_lcao/module_ri/matrix_orbs22.hpp @@ -11,302 +11,302 @@ template RI::Tensor Matrix_Orbs22::cal_overlap_matrix( - const size_t TA, - const size_t TB, - const ModuleBase::Vector3 &tauA, - const ModuleBase::Vector3 &tauB, - const ModuleBase::Element_Basis_Index::IndexLNM &index_A1, - const ModuleBase::Element_Basis_Index::IndexLNM &index_A2, - const ModuleBase::Element_Basis_Index::IndexLNM &index_B1, - const ModuleBase::Element_Basis_Index::IndexLNM &index_B2, - const Matrix_Order &matrix_order) const + const size_t TA, + const size_t TB, + const ModuleBase::Vector3 &tauA, + const ModuleBase::Vector3 &tauB, + const ModuleBase::Element_Basis_Index::IndexLNM &index_A1, + const ModuleBase::Element_Basis_Index::IndexLNM &index_A2, + const ModuleBase::Element_Basis_Index::IndexLNM &index_B1, + const ModuleBase::Element_Basis_Index::IndexLNM &index_B2, + const Matrix_Order &matrix_order) const { - const double lat0 = *this->lat0; - RI::Tensor m; - const size_t sizeA1 = index_A1[TA].count_size; - const size_t sizeA2 = index_A2[TA].count_size; - const size_t sizeB1 = index_B1[TB].count_size; - const size_t sizeB2 = index_B2[TB].count_size; - switch(matrix_order) - { - case Matrix_Order::A1A2B1B2: m = RI::Tensor({sizeA1, sizeA2, sizeB1, sizeB2}); break; - case Matrix_Order::A1A2B2B1: m = RI::Tensor({sizeA1, sizeA2, sizeB2, sizeB1}); break; - case Matrix_Order::A1B1A2B2: m = RI::Tensor({sizeA1, sizeB1, sizeA2, sizeB2}); break; - case Matrix_Order::A1B1B2A2: m = RI::Tensor({sizeA1, sizeB1, sizeB2, sizeA2}); break; - case Matrix_Order::A1B2A2B1: m = RI::Tensor({sizeA1, sizeB2, sizeA2, sizeB1}); break; - case Matrix_Order::A1B2B1A2: m = RI::Tensor({sizeA1, sizeB2, sizeB1, sizeA2}); break; - case Matrix_Order::A2A1B1B2: m = RI::Tensor({sizeA2, sizeA1, sizeB1, sizeB2}); break; - case Matrix_Order::A2A1B2B1: m = RI::Tensor({sizeA2, sizeA1, sizeB2, sizeB1}); break; - case Matrix_Order::A2B1A1B2: m = RI::Tensor({sizeA2, sizeB1, sizeA1, sizeB2}); break; - case Matrix_Order::A2B1B2A1: m = RI::Tensor({sizeA2, sizeB1, sizeB2, sizeA1}); break; - case Matrix_Order::A2B2A1B1: m = RI::Tensor({sizeA2, sizeB2, sizeA1, sizeB1}); break; - case Matrix_Order::A2B2B1A1: m = RI::Tensor({sizeA2, sizeB2, sizeB1, sizeA1}); break; - case Matrix_Order::B1A1A2B2: m = RI::Tensor({sizeB1, sizeA1, sizeA2, sizeB2}); break; - case Matrix_Order::B1A1B2A2: m = RI::Tensor({sizeB1, sizeA1, sizeB2, sizeA2}); break; - case Matrix_Order::B1A2A1B2: m = RI::Tensor({sizeB1, sizeA2, sizeA1, sizeB2}); break; - case Matrix_Order::B1A2B2A1: m = RI::Tensor({sizeB1, sizeA2, sizeB2, sizeA1}); break; - case Matrix_Order::B1B2A1A2: m = RI::Tensor({sizeB1, sizeB2, sizeA1, sizeA2}); break; - case Matrix_Order::B1B2A2A1: m = RI::Tensor({sizeB1, sizeB2, sizeA2, sizeA1}); break; - case Matrix_Order::B2A1A2B1: m = RI::Tensor({sizeB2, sizeA1, sizeA2, sizeB1}); break; - case Matrix_Order::B2A1B1A2: m = RI::Tensor({sizeB2, sizeA1, sizeB1, sizeA2}); break; - case Matrix_Order::B2A2A1B1: m = RI::Tensor({sizeB2, sizeA2, sizeA1, sizeB1}); break; - case Matrix_Order::B2A2B1A1: m = RI::Tensor({sizeB2, sizeA2, sizeB1, sizeA1}); break; - case Matrix_Order::B2B1A1A2: m = RI::Tensor({sizeB2, sizeB1, sizeA1, sizeA2}); break; - case Matrix_Order::B2B1A2A1: m = RI::Tensor({sizeB2, sizeB1, sizeA2, sizeA1}); break; - default: throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); - } + const double lat0 = *this->lat0; + RI::Tensor m; + const size_t sizeA1 = index_A1[TA].count_size; + const size_t sizeA2 = index_A2[TA].count_size; + const size_t sizeB1 = index_B1[TB].count_size; + const size_t sizeB2 = index_B2[TB].count_size; + switch(matrix_order) + { + case Matrix_Order::A1A2B1B2: m = RI::Tensor({sizeA1, sizeA2, sizeB1, sizeB2}); break; + case Matrix_Order::A1A2B2B1: m = RI::Tensor({sizeA1, sizeA2, sizeB2, sizeB1}); break; + case Matrix_Order::A1B1A2B2: m = RI::Tensor({sizeA1, sizeB1, sizeA2, sizeB2}); break; + case Matrix_Order::A1B1B2A2: m = RI::Tensor({sizeA1, sizeB1, sizeB2, sizeA2}); break; + case Matrix_Order::A1B2A2B1: m = RI::Tensor({sizeA1, sizeB2, sizeA2, sizeB1}); break; + case Matrix_Order::A1B2B1A2: m = RI::Tensor({sizeA1, sizeB2, sizeB1, sizeA2}); break; + case Matrix_Order::A2A1B1B2: m = RI::Tensor({sizeA2, sizeA1, sizeB1, sizeB2}); break; + case Matrix_Order::A2A1B2B1: m = RI::Tensor({sizeA2, sizeA1, sizeB2, sizeB1}); break; + case Matrix_Order::A2B1A1B2: m = RI::Tensor({sizeA2, sizeB1, sizeA1, sizeB2}); break; + case Matrix_Order::A2B1B2A1: m = RI::Tensor({sizeA2, sizeB1, sizeB2, sizeA1}); break; + case Matrix_Order::A2B2A1B1: m = RI::Tensor({sizeA2, sizeB2, sizeA1, sizeB1}); break; + case Matrix_Order::A2B2B1A1: m = RI::Tensor({sizeA2, sizeB2, sizeB1, sizeA1}); break; + case Matrix_Order::B1A1A2B2: m = RI::Tensor({sizeB1, sizeA1, sizeA2, sizeB2}); break; + case Matrix_Order::B1A1B2A2: m = RI::Tensor({sizeB1, sizeA1, sizeB2, sizeA2}); break; + case Matrix_Order::B1A2A1B2: m = RI::Tensor({sizeB1, sizeA2, sizeA1, sizeB2}); break; + case Matrix_Order::B1A2B2A1: m = RI::Tensor({sizeB1, sizeA2, sizeB2, sizeA1}); break; + case Matrix_Order::B1B2A1A2: m = RI::Tensor({sizeB1, sizeB2, sizeA1, sizeA2}); break; + case Matrix_Order::B1B2A2A1: m = RI::Tensor({sizeB1, sizeB2, sizeA2, sizeA1}); break; + case Matrix_Order::B2A1A2B1: m = RI::Tensor({sizeB2, sizeA1, sizeA2, sizeB1}); break; + case Matrix_Order::B2A1B1A2: m = RI::Tensor({sizeB2, sizeA1, sizeB1, sizeA2}); break; + case Matrix_Order::B2A2A1B1: m = RI::Tensor({sizeB2, sizeA2, sizeA1, sizeB1}); break; + case Matrix_Order::B2A2B1A1: m = RI::Tensor({sizeB2, sizeA2, sizeB1, sizeA1}); break; + case Matrix_Order::B2B1A1A2: m = RI::Tensor({sizeB2, sizeB1, sizeA1, sizeA2}); break; + case Matrix_Order::B2B1A2A1: m = RI::Tensor({sizeB2, sizeB1, sizeA2, sizeA1}); break; + default: throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + } - for( const auto &co3 : center2_orb22_s.at(TA).at(TB) ) - { - const int LA1 = co3.first; - for( const auto &co4 : co3.second ) - { - const size_t NA1 = co4.first; - for( size_t MA1=0; MA1!=2*LA1+1; ++MA1 ) - { - for( const auto &co5 : co4.second ) - { - const int LA2 = co5.first; - for( const auto &co6 : co5.second ) - { - const size_t NA2 = co6.first; - for( size_t MA2=0; MA2!=2*LA2+1; ++MA2 ) - { - for( const auto &co7 : co6.second ) - { - const int LB1 = co7.first; - for( const auto &co8 : co7.second ) - { - const size_t NB1 = co8.first; - for( size_t MB1=0; MB1!=2*LB1+1; ++MB1 ) - { - for( const auto &co9 : co8.second ) - { - const int LB2 = co9.first; - for( const auto &co10 : co9.second ) - { - const size_t NB2 = co10.first; - for( size_t MB2=0; MB2!=2*LB2+1; ++MB2 ) - { - const Tdata overlap = co10.second.cal_overlap( tauA*lat0, tauB*lat0, MA1, MA2, MB1, MB2 ); - const size_t iA1 = index_A1[TA][LA1][NA1][MA1]; - const size_t iA2 = index_A2[TA][LA2][NA2][MA2]; - const size_t iB1 = index_B1[TB][LB1][NB1][MB1]; - const size_t iB2 = index_B2[TB][LB2][NB2][MB2]; - switch(matrix_order) - { - case Matrix_Order::A1A2B1B2: m(iA1,iA2,iB1,iB2) = overlap; break; - case Matrix_Order::A1A2B2B1: m(iA1,iA2,iB2,iB1) = overlap; break; - case Matrix_Order::A1B1A2B2: m(iA1,iB1,iA2,iB2) = overlap; break; - case Matrix_Order::A1B1B2A2: m(iA1,iB1,iB2,iA2) = overlap; break; - case Matrix_Order::A1B2A2B1: m(iA1,iB2,iA2,iB1) = overlap; break; - case Matrix_Order::A1B2B1A2: m(iA1,iB2,iB1,iA2) = overlap; break; - case Matrix_Order::A2A1B1B2: m(iA2,iA1,iB1,iB2) = overlap; break; - case Matrix_Order::A2A1B2B1: m(iA2,iA1,iB2,iB1) = overlap; break; - case Matrix_Order::A2B1A1B2: m(iA2,iB1,iA1,iB2) = overlap; break; - case Matrix_Order::A2B1B2A1: m(iA2,iB1,iB2,iA1) = overlap; break; - case Matrix_Order::A2B2A1B1: m(iA2,iB2,iA1,iB1) = overlap; break; - case Matrix_Order::A2B2B1A1: m(iA2,iB2,iB1,iA1) = overlap; break; - case Matrix_Order::B1A1A2B2: m(iB1,iA1,iA2,iB2) = overlap; break; - case Matrix_Order::B1A1B2A2: m(iB1,iA1,iB2,iA2) = overlap; break; - case Matrix_Order::B1A2A1B2: m(iB1,iA2,iA1,iB2) = overlap; break; - case Matrix_Order::B1A2B2A1: m(iB1,iA2,iB2,iA1) = overlap; break; - case Matrix_Order::B1B2A1A2: m(iB1,iB2,iA1,iA2) = overlap; break; - case Matrix_Order::B1B2A2A1: m(iB1,iB2,iA2,iA1) = overlap; break; - case Matrix_Order::B2A1A2B1: m(iB2,iA1,iA2,iB1) = overlap; break; - case Matrix_Order::B2A1B1A2: m(iB2,iA1,iB1,iA2) = overlap; break; - case Matrix_Order::B2A2A1B1: m(iB2,iA2,iA1,iB1) = overlap; break; - case Matrix_Order::B2A2B1A1: m(iB2,iA2,iB1,iA1) = overlap; break; - case Matrix_Order::B2B1A1A2: m(iB2,iB1,iA1,iA2) = overlap; break; - case Matrix_Order::B2B1A2A1: m(iB2,iB1,iA2,iA1) = overlap; break; - default: throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); - } - } - } - } - } - } - } - } - } - } - } - } - } - return m; + for( const auto &co3 : center2_orb22_s.at(TA).at(TB) ) + { + const int LA1 = co3.first; + for( const auto &co4 : co3.second ) + { + const size_t NA1 = co4.first; + for( size_t MA1=0; MA1!=2*LA1+1; ++MA1 ) + { + for( const auto &co5 : co4.second ) + { + const int LA2 = co5.first; + for( const auto &co6 : co5.second ) + { + const size_t NA2 = co6.first; + for( size_t MA2=0; MA2!=2*LA2+1; ++MA2 ) + { + for( const auto &co7 : co6.second ) + { + const int LB1 = co7.first; + for( const auto &co8 : co7.second ) + { + const size_t NB1 = co8.first; + for( size_t MB1=0; MB1!=2*LB1+1; ++MB1 ) + { + for( const auto &co9 : co8.second ) + { + const int LB2 = co9.first; + for( const auto &co10 : co9.second ) + { + const size_t NB2 = co10.first; + for( size_t MB2=0; MB2!=2*LB2+1; ++MB2 ) + { + const Tdata overlap = co10.second.cal_overlap( tauA*lat0, tauB*lat0, MA1, MA2, MB1, MB2 ); + const size_t iA1 = index_A1[TA][LA1][NA1][MA1]; + const size_t iA2 = index_A2[TA][LA2][NA2][MA2]; + const size_t iB1 = index_B1[TB][LB1][NB1][MB1]; + const size_t iB2 = index_B2[TB][LB2][NB2][MB2]; + switch(matrix_order) + { + case Matrix_Order::A1A2B1B2: m(iA1,iA2,iB1,iB2) = overlap; break; + case Matrix_Order::A1A2B2B1: m(iA1,iA2,iB2,iB1) = overlap; break; + case Matrix_Order::A1B1A2B2: m(iA1,iB1,iA2,iB2) = overlap; break; + case Matrix_Order::A1B1B2A2: m(iA1,iB1,iB2,iA2) = overlap; break; + case Matrix_Order::A1B2A2B1: m(iA1,iB2,iA2,iB1) = overlap; break; + case Matrix_Order::A1B2B1A2: m(iA1,iB2,iB1,iA2) = overlap; break; + case Matrix_Order::A2A1B1B2: m(iA2,iA1,iB1,iB2) = overlap; break; + case Matrix_Order::A2A1B2B1: m(iA2,iA1,iB2,iB1) = overlap; break; + case Matrix_Order::A2B1A1B2: m(iA2,iB1,iA1,iB2) = overlap; break; + case Matrix_Order::A2B1B2A1: m(iA2,iB1,iB2,iA1) = overlap; break; + case Matrix_Order::A2B2A1B1: m(iA2,iB2,iA1,iB1) = overlap; break; + case Matrix_Order::A2B2B1A1: m(iA2,iB2,iB1,iA1) = overlap; break; + case Matrix_Order::B1A1A2B2: m(iB1,iA1,iA2,iB2) = overlap; break; + case Matrix_Order::B1A1B2A2: m(iB1,iA1,iB2,iA2) = overlap; break; + case Matrix_Order::B1A2A1B2: m(iB1,iA2,iA1,iB2) = overlap; break; + case Matrix_Order::B1A2B2A1: m(iB1,iA2,iB2,iA1) = overlap; break; + case Matrix_Order::B1B2A1A2: m(iB1,iB2,iA1,iA2) = overlap; break; + case Matrix_Order::B1B2A2A1: m(iB1,iB2,iA2,iA1) = overlap; break; + case Matrix_Order::B2A1A2B1: m(iB2,iA1,iA2,iB1) = overlap; break; + case Matrix_Order::B2A1B1A2: m(iB2,iA1,iB1,iA2) = overlap; break; + case Matrix_Order::B2A2A1B1: m(iB2,iA2,iA1,iB1) = overlap; break; + case Matrix_Order::B2A2B1A1: m(iB2,iA2,iB1,iA1) = overlap; break; + case Matrix_Order::B2B1A1A2: m(iB2,iB1,iA1,iA2) = overlap; break; + case Matrix_Order::B2B1A2A1: m(iB2,iB1,iA2,iA1) = overlap; break; + default: throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + } + } + } + } + } + } + } + } + } + } + } + } + } + return m; } template std::array,3> Matrix_Orbs22::cal_grad_overlap_matrix( - const size_t TA, - const size_t TB, - const ModuleBase::Vector3 &tauA, - const ModuleBase::Vector3 &tauB, - const ModuleBase::Element_Basis_Index::IndexLNM &index_A1, - const ModuleBase::Element_Basis_Index::IndexLNM &index_A2, - const ModuleBase::Element_Basis_Index::IndexLNM &index_B1, - const ModuleBase::Element_Basis_Index::IndexLNM &index_B2, - const Matrix_Order &matrix_order) const + const size_t TA, + const size_t TB, + const ModuleBase::Vector3 &tauA, + const ModuleBase::Vector3 &tauB, + const ModuleBase::Element_Basis_Index::IndexLNM &index_A1, + const ModuleBase::Element_Basis_Index::IndexLNM &index_A2, + const ModuleBase::Element_Basis_Index::IndexLNM &index_B1, + const ModuleBase::Element_Basis_Index::IndexLNM &index_B2, + const Matrix_Order &matrix_order) const { - std::array,3> m; - const size_t sizeA1 = index_A1[TA].count_size; - const size_t sizeA2 = index_A2[TA].count_size; - const size_t sizeB1 = index_B1[TB].count_size; - const size_t sizeB2 = index_B2[TB].count_size; - for(int i=0; i({sizeA1, sizeA2, sizeB1, sizeB2}); break; - case Matrix_Order::A1A2B2B1: m[i] = RI::Tensor({sizeA1, sizeA2, sizeB2, sizeB1}); break; - case Matrix_Order::A1B1A2B2: m[i] = RI::Tensor({sizeA1, sizeB1, sizeA2, sizeB2}); break; - case Matrix_Order::A1B1B2A2: m[i] = RI::Tensor({sizeA1, sizeB1, sizeB2, sizeA2}); break; - case Matrix_Order::A1B2A2B1: m[i] = RI::Tensor({sizeA1, sizeB2, sizeA2, sizeB1}); break; - case Matrix_Order::A1B2B1A2: m[i] = RI::Tensor({sizeA1, sizeB2, sizeB1, sizeA2}); break; - case Matrix_Order::A2A1B1B2: m[i] = RI::Tensor({sizeA2, sizeA1, sizeB1, sizeB2}); break; - case Matrix_Order::A2A1B2B1: m[i] = RI::Tensor({sizeA2, sizeA1, sizeB2, sizeB1}); break; - case Matrix_Order::A2B1A1B2: m[i] = RI::Tensor({sizeA2, sizeB1, sizeA1, sizeB2}); break; - case Matrix_Order::A2B1B2A1: m[i] = RI::Tensor({sizeA2, sizeB1, sizeB2, sizeA1}); break; - case Matrix_Order::A2B2A1B1: m[i] = RI::Tensor({sizeA2, sizeB2, sizeA1, sizeB1}); break; - case Matrix_Order::A2B2B1A1: m[i] = RI::Tensor({sizeA2, sizeB2, sizeB1, sizeA1}); break; - case Matrix_Order::B1A1A2B2: m[i] = RI::Tensor({sizeB1, sizeA1, sizeA2, sizeB2}); break; - case Matrix_Order::B1A1B2A2: m[i] = RI::Tensor({sizeB1, sizeA1, sizeB2, sizeA2}); break; - case Matrix_Order::B1A2A1B2: m[i] = RI::Tensor({sizeB1, sizeA2, sizeA1, sizeB2}); break; - case Matrix_Order::B1A2B2A1: m[i] = RI::Tensor({sizeB1, sizeA2, sizeB2, sizeA1}); break; - case Matrix_Order::B1B2A1A2: m[i] = RI::Tensor({sizeB1, sizeB2, sizeA1, sizeA2}); break; - case Matrix_Order::B1B2A2A1: m[i] = RI::Tensor({sizeB1, sizeB2, sizeA2, sizeA1}); break; - case Matrix_Order::B2A1A2B1: m[i] = RI::Tensor({sizeB2, sizeA1, sizeA2, sizeB1}); break; - case Matrix_Order::B2A1B1A2: m[i] = RI::Tensor({sizeB2, sizeA1, sizeB1, sizeA2}); break; - case Matrix_Order::B2A2A1B1: m[i] = RI::Tensor({sizeB2, sizeA2, sizeA1, sizeB1}); break; - case Matrix_Order::B2A2B1A1: m[i] = RI::Tensor({sizeB2, sizeA2, sizeB1, sizeA1}); break; - case Matrix_Order::B2B1A1A2: m[i] = RI::Tensor({sizeB2, sizeB1, sizeA1, sizeA2}); break; - case Matrix_Order::B2B1A2A1: m[i] = RI::Tensor({sizeB2, sizeB1, sizeA2, sizeA1}); break; - default: throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); - } - } - const double lat0 = *this->lat0; - for( const auto &co3 : center2_orb22_s.at(TA).at(TB) ) - { - const int LA1 = co3.first; - for( const auto &co4 : co3.second ) - { - const size_t NA1 = co4.first; - for( size_t MA1=0; MA1!=2*LA1+1; ++MA1 ) - { - for( const auto &co5 : co4.second ) - { - const int LA2 = co5.first; - for( const auto &co6 : co5.second ) - { - const size_t NA2 = co6.first; - for( size_t MA2=0; MA2!=2*LA2+1; ++MA2 ) - { - for( const auto &co7 : co6.second ) - { - const int LB1 = co7.first; - for( const auto &co8 : co7.second ) - { - const size_t NB1 = co8.first; - for( size_t MB1=0; MB1!=2*LB1+1; ++MB1 ) - { - for( const auto &co9 : co8.second ) - { - const int LB2 = co9.first; - for( const auto &co10 : co9.second ) - { - const size_t NB2 = co10.first; - for( size_t MB2=0; MB2!=2*LB2+1; ++MB2 ) - { - const std::array grad_overlap = RI_Util::Vector3_to_array3(co10.second.cal_grad_overlap( tauA*lat0, tauB*lat0, MA1, MA2, MB1, MB2 )); - const size_t iA1 = index_A1[TA][LA1][NA1][MA1]; - const size_t iA2 = index_A2[TA][LA2][NA2][MA2]; - const size_t iB1 = index_B1[TB][LB1][NB1][MB1]; - const size_t iB2 = index_B2[TB][LB2][NB2][MB2]; - for(size_t i=0; i,3> m; + const size_t sizeA1 = index_A1[TA].count_size; + const size_t sizeA2 = index_A2[TA].count_size; + const size_t sizeB1 = index_B1[TB].count_size; + const size_t sizeB2 = index_B2[TB].count_size; + for(int i=0; i({sizeA1, sizeA2, sizeB1, sizeB2}); break; + case Matrix_Order::A1A2B2B1: m[i] = RI::Tensor({sizeA1, sizeA2, sizeB2, sizeB1}); break; + case Matrix_Order::A1B1A2B2: m[i] = RI::Tensor({sizeA1, sizeB1, sizeA2, sizeB2}); break; + case Matrix_Order::A1B1B2A2: m[i] = RI::Tensor({sizeA1, sizeB1, sizeB2, sizeA2}); break; + case Matrix_Order::A1B2A2B1: m[i] = RI::Tensor({sizeA1, sizeB2, sizeA2, sizeB1}); break; + case Matrix_Order::A1B2B1A2: m[i] = RI::Tensor({sizeA1, sizeB2, sizeB1, sizeA2}); break; + case Matrix_Order::A2A1B1B2: m[i] = RI::Tensor({sizeA2, sizeA1, sizeB1, sizeB2}); break; + case Matrix_Order::A2A1B2B1: m[i] = RI::Tensor({sizeA2, sizeA1, sizeB2, sizeB1}); break; + case Matrix_Order::A2B1A1B2: m[i] = RI::Tensor({sizeA2, sizeB1, sizeA1, sizeB2}); break; + case Matrix_Order::A2B1B2A1: m[i] = RI::Tensor({sizeA2, sizeB1, sizeB2, sizeA1}); break; + case Matrix_Order::A2B2A1B1: m[i] = RI::Tensor({sizeA2, sizeB2, sizeA1, sizeB1}); break; + case Matrix_Order::A2B2B1A1: m[i] = RI::Tensor({sizeA2, sizeB2, sizeB1, sizeA1}); break; + case Matrix_Order::B1A1A2B2: m[i] = RI::Tensor({sizeB1, sizeA1, sizeA2, sizeB2}); break; + case Matrix_Order::B1A1B2A2: m[i] = RI::Tensor({sizeB1, sizeA1, sizeB2, sizeA2}); break; + case Matrix_Order::B1A2A1B2: m[i] = RI::Tensor({sizeB1, sizeA2, sizeA1, sizeB2}); break; + case Matrix_Order::B1A2B2A1: m[i] = RI::Tensor({sizeB1, sizeA2, sizeB2, sizeA1}); break; + case Matrix_Order::B1B2A1A2: m[i] = RI::Tensor({sizeB1, sizeB2, sizeA1, sizeA2}); break; + case Matrix_Order::B1B2A2A1: m[i] = RI::Tensor({sizeB1, sizeB2, sizeA2, sizeA1}); break; + case Matrix_Order::B2A1A2B1: m[i] = RI::Tensor({sizeB2, sizeA1, sizeA2, sizeB1}); break; + case Matrix_Order::B2A1B1A2: m[i] = RI::Tensor({sizeB2, sizeA1, sizeB1, sizeA2}); break; + case Matrix_Order::B2A2A1B1: m[i] = RI::Tensor({sizeB2, sizeA2, sizeA1, sizeB1}); break; + case Matrix_Order::B2A2B1A1: m[i] = RI::Tensor({sizeB2, sizeA2, sizeB1, sizeA1}); break; + case Matrix_Order::B2B1A1A2: m[i] = RI::Tensor({sizeB2, sizeB1, sizeA1, sizeA2}); break; + case Matrix_Order::B2B1A2A1: m[i] = RI::Tensor({sizeB2, sizeB1, sizeA2, sizeA1}); break; + default: throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + } + } + const double lat0 = *this->lat0; + for( const auto &co3 : center2_orb22_s.at(TA).at(TB) ) + { + const int LA1 = co3.first; + for( const auto &co4 : co3.second ) + { + const size_t NA1 = co4.first; + for( size_t MA1=0; MA1!=2*LA1+1; ++MA1 ) + { + for( const auto &co5 : co4.second ) + { + const int LA2 = co5.first; + for( const auto &co6 : co5.second ) + { + const size_t NA2 = co6.first; + for( size_t MA2=0; MA2!=2*LA2+1; ++MA2 ) + { + for( const auto &co7 : co6.second ) + { + const int LB1 = co7.first; + for( const auto &co8 : co7.second ) + { + const size_t NB1 = co8.first; + for( size_t MB1=0; MB1!=2*LB1+1; ++MB1 ) + { + for( const auto &co9 : co8.second ) + { + const int LB2 = co9.first; + for( const auto &co10 : co9.second ) + { + const size_t NB2 = co10.first; + for( size_t MB2=0; MB2!=2*LB2+1; ++MB2 ) + { + const std::array grad_overlap = RI_Util::Vector3_to_array3(co10.second.cal_grad_overlap( tauA*lat0, tauB*lat0, MA1, MA2, MB1, MB2 )); + const size_t iA1 = index_A1[TA][LA1][NA1][MA1]; + const size_t iA2 = index_A2[TA][LA2][NA2][MA2]; + const size_t iB1 = index_B1[TB][LB1][NB1][MB1]; + const size_t iB2 = index_B2[TB][LB2][NB2][MB2]; + for(size_t i=0; i std::map < size_t, std::map>>>> Matrix_Orbs22::cal_overlap_matrix_all( - const UnitCell &ucell, - const ModuleBase::Element_Basis_Index::IndexLNM &index_A1, - const ModuleBase::Element_Basis_Index::IndexLNM &index_A2, - const ModuleBase::Element_Basis_Index::IndexLNM &index_B1, - const ModuleBase::Element_Basis_Index::IndexLNM &index_B2 ) const + const UnitCell &ucell, + const ModuleBase::Element_Basis_Index::IndexLNM &index_A1, + const ModuleBase::Element_Basis_Index::IndexLNM &index_A2, + const ModuleBase::Element_Basis_Index::IndexLNM &index_B1, + const ModuleBase::Element_Basis_Index::IndexLNM &index_B2 ) const { - std::map>>>> matrixes; + std::map>>>> matrixes; - for( const auto &co1 : center2_orb22_s ) - { - const size_t TA = co1.first; - for( size_t IA=0; IA!=ucell.atoms[TA].na; ++IA ) - { - const ModuleBase::Vector3 &tauA( ucell.atoms[TA].tau[IA] ); + for( const auto &co1 : center2_orb22_s ) + { + const size_t TA = co1.first; + for( size_t IA=0; IA!=ucell.atoms[TA].na; ++IA ) + { + const ModuleBase::Vector3 &tauA( ucell.atoms[TA].tau[IA] ); - for( const auto &co2 : co1.second ) - { - const size_t TB = co2.first; - for( size_t IB=0; IB!=ucell.atoms[TB].na; ++IB ) - { - const ModuleBase::Vector3 &tauB( ucell.atoms[TB].tau[IB] ); + for( const auto &co2 : co1.second ) + { + const size_t TB = co2.first; + for( size_t IB=0; IB!=ucell.atoms[TB].na; ++IB ) + { + const ModuleBase::Vector3 &tauB( ucell.atoms[TB].tau[IB] ); - matrixes[TA][IA][TB][IB] = cal_overlap_matrix( - TA, - TB, - ucell.atoms[TA].tau[IA], - ucell.atoms[TB].tau[IB], - index_A1, - index_A2, - index_B1, - index_B2, - Matrix_Order::A1B1A2B2); - } - } - } - } - return matrixes; + matrixes[TA][IA][TB][IB] = cal_overlap_matrix( + TA, + TB, + ucell.atoms[TA].tau[IA], + ucell.atoms[TB].tau[IB], + index_A1, + index_A2, + index_B1, + index_B2, + Matrix_Order::A1B1A2B2); + } + } + } + } + return matrixes; } #endif diff --git a/source/source_lcao/module_ri/mix_dmk_2d.h b/source/source_lcao/module_ri/mix_dmk_2d.h index 042935ccb74..62c61c49d9b 100644 --- a/source/source_lcao/module_ri/mix_dmk_2d.h +++ b/source/source_lcao/module_ri/mix_dmk_2d.h @@ -15,37 +15,37 @@ template class Mix_DMk_2D { public: - ~Mix_DMk_2D(); + ~Mix_DMk_2D(); - /** - * @brief Sets the number of k-points. - * @param nks Number of k-points. - */ - void set_nks(const int nks); + /** + * @brief Sets the number of k-points. + * @param nks Number of k-points. + */ + void set_nks(const int nks); - /** - * @brief Sets the mixing mode. - * @param Mixing Mixing pointer. - */ - void set_mixing(Base_Mixing::Mixing* mixing_in); + /** + * @brief Sets the mixing mode. + * @param Mixing Mixing pointer. + */ + void set_mixing(Base_Mixing::Mixing* mixing_in); - /** - * @brief Sets Base_Mixing::Plain_Mixing. - * @param mixing_beta mixing beta for plain mixing. - */ - void set_mixing_plain(const double& mixing_beta); + /** + * @brief Sets Base_Mixing::Plain_Mixing. + * @param mixing_beta mixing beta for plain mixing. + */ + void set_mixing_plain(const double& mixing_beta); - /** - * @brief Mixes the density matrix. - * @param dm Density matrix. - * @param flag_restart Flag indicating whether restart mixing. - */ + /** + * @brief Mixes the density matrix. + * @param dm Density matrix. + * @param flag_restart Flag indicating whether restart mixing. + */ void mix(const std::vector>& dm, const bool flag_restart); - /** - * @brief Returns the density matrix. - * @return Density matrices for each k-points. - */ + /** + * @brief Returns the density matrix. + * @return Density matrices for each k-points. + */ std::vector*> get_DMk_out() const; private: @@ -61,7 +61,7 @@ class Mix_DMk_2D std::vector mix_DMk; Base_Mixing::Mixing* mixing = nullptr; - bool flag_del_mixing = false; + bool flag_del_mixing = false; }; #endif diff --git a/source/source_lcao/module_ri/ri_2d_comm.cpp b/source/source_lcao/module_ri/ri_2d_comm.cpp index 498907a9343..26fe2f2ae2f 100644 --- a/source/source_lcao/module_ri/ri_2d_comm.cpp +++ b/source/source_lcao/module_ri/ri_2d_comm.cpp @@ -15,59 +15,59 @@ auto RI_2D_Comm::get_2D_judge(const UnitCell& ucell, const Parallel_2D& pv) -> std::vector, std::set>> { - ModuleBase::TITLE("RI_2D_Comm","get_2D_judge"); + ModuleBase::TITLE("RI_2D_Comm","get_2D_judge"); - const std::map nspin_b = {{1,1}, {2,1}, {4,2}}; + const std::map nspin_b = {{1,1}, {2,1}, {4,2}}; - std::vector> iat0_list(nspin_b.at(PARAM.inp.nspin)); + std::vector> iat0_list(nspin_b.at(PARAM.inp.nspin)); for (int iwt0_2D = 0; iwt0_2D < pv.nrow; ++iwt0_2D) - { + { const int iwt0 = pv.local2global_row(iwt0_2D); - int iat0=0;int iw0_b=0;int is0_b=0; - std::tie(iat0,iw0_b,is0_b) = RI_2D_Comm::get_iat_iw_is_block(ucell,iwt0); - iat0_list[is0_b].insert(iat0); - } + int iat0=0;int iw0_b=0;int is0_b=0; + std::tie(iat0,iw0_b,is0_b) = RI_2D_Comm::get_iat_iw_is_block(ucell,iwt0); + iat0_list[is0_b].insert(iat0); + } - std::vector> iat1_list(nspin_b.at(PARAM.inp.nspin)); + std::vector> iat1_list(nspin_b.at(PARAM.inp.nspin)); for (int iwt1_2D = 0; iwt1_2D < pv.ncol; ++iwt1_2D) - { + { const int iwt1 = pv.local2global_col(iwt1_2D); - int iat1=0;int iw1_b=0;int is1_b=0; - std::tie(iat1,iw1_b,is1_b) = RI_2D_Comm::get_iat_iw_is_block(ucell,iwt1); - iat1_list[is1_b].insert(iat1); - } + int iat1=0;int iw1_b=0;int is1_b=0; + std::tie(iat1,iw1_b,is1_b) = RI_2D_Comm::get_iat_iw_is_block(ucell,iwt1); + iat1_list[is1_b].insert(iat1); + } - std::vector, std::set>> judge(PARAM.inp.nspin); - switch(PARAM.inp.nspin) - { - case 1: - judge[0] = std::make_tuple( std::move(iat0_list[0]), std::move(iat1_list[0]) ); - break; - case 2: - judge[0] = judge[1] = std::make_tuple( std::move(iat0_list[0]), std::move(iat1_list[0]) ); - break; - case 4: - for(int is0_b=0; is0_b<2; ++is0_b) - for(int is1_b=0; is1_b<2; ++is1_b) - { - const int is_b = RI_2D_Comm::get_is_block(-1, is0_b, is1_b); - judge[is_b] = std::make_tuple( iat0_list[is0_b], iat1_list[is1_b] ); - } - break; - default: - throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); - } - return judge; + std::vector, std::set>> judge(PARAM.inp.nspin); + switch(PARAM.inp.nspin) + { + case 1: + judge[0] = std::make_tuple( std::move(iat0_list[0]), std::move(iat1_list[0]) ); + break; + case 2: + judge[0] = judge[1] = std::make_tuple( std::move(iat0_list[0]), std::move(iat1_list[0]) ); + break; + case 4: + for(int is0_b=0; is0_b<2; ++is0_b) + for(int is1_b=0; is1_b<2; ++is1_b) + { + const int is_b = RI_2D_Comm::get_is_block(-1, is0_b, is1_b); + judge[is_b] = std::make_tuple( iat0_list[is0_b], iat1_list[is1_b] ); + } + break; + default: + throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + } + return judge; } std::vector RI_2D_Comm::get_ik_list(const K_Vectors &kv, const int is_k) { - std::vector ik_list; - for(int ik=0; ik ik_list; + for(int ik=0; ik>>> split_m2D_kto const int nspin, const bool spgsym = false); - // judge[is] = {s0, s1} - extern std::vector, std::set>> + // judge[is] = {s0, s1} + extern std::vector, std::set>> get_2D_judge(const UnitCell& ucell, const Parallel_2D& pv); template @@ -78,19 +78,19 @@ extern std::vector>>> split_m2D_kto hamilt::HContainer& HlocR, const RI::Cell_Nearest* const cell_nearest = nullptr); - template - extern std::vector> Hexxs_to_Hk( - const K_Vectors &kv, - const Parallel_Orbitals &pv, - const std::vector< std::map>>> &Hexxs, - const int ik); - template - std::vector> pulay_mixing( - const Parallel_Orbitals &pv, - std::deque>> &Hk_seq, - const std::vector> &Hk_new, - const double mixing_beta, - const std::string mixing_mode); + template + extern std::vector> Hexxs_to_Hk( + const K_Vectors &kv, + const Parallel_Orbitals &pv, + const std::vector< std::map>>> &Hexxs, + const int ik); + template + std::vector> pulay_mixing( + const Parallel_Orbitals &pv, + std::deque>> &Hk_seq, + const std::vector> &Hk_new, + const double mixing_beta, + const std::string mixing_mode); // DM(R) format conversion: the real-space (DM(R)) counterpart of split_m2D_ktoR, // and the inverse of add_HexxR. dm_container is DensityMatrix::get_dmr_vec(): @@ -105,11 +105,11 @@ extern std::vector>>> split_m2D_kto const int nspin); //private: - extern std::vector get_ik_list(const K_Vectors &kv, const int is_k); - extern inline std::tuple get_iat_iw_is_block(const UnitCell& ucell,const int& iwt); - extern inline int get_is_block(const int is_k, const int is_row_b, const int is_col_b); - extern inline std::tuple split_is_block(const int is_b); - extern inline int get_iwt(const UnitCell& ucell, const int iat, const int iw_b, const int is_b); + extern std::vector get_ik_list(const K_Vectors &kv, const int is_k); + extern inline std::tuple get_iat_iw_is_block(const UnitCell& ucell,const int& iwt); + extern inline int get_is_block(const int is_k, const int is_row_b, const int is_col_b); + extern inline std::tuple split_is_block(const int is_b); + extern inline int get_iwt(const UnitCell& ucell, const int iat, const int iw_b, const int is_b); template extern std::map> comm_map2_first(const MPI_Comm& mpi_comm, diff --git a/source/source_lcao/module_ri/ri_2d_comm.hpp b/source/source_lcao/module_ri/ri_2d_comm.hpp index ead47110b73..692c4925fc9 100644 --- a/source/source_lcao/module_ri/ri_2d_comm.hpp +++ b/source/source_lcao/module_ri/ri_2d_comm.hpp @@ -44,15 +44,15 @@ auto RI_2D_Comm::split_m2D_ktoR(const UnitCell& ucell, const bool spgsym) -> std::vector>>> { - ModuleBase::TITLE("RI_2D_Comm","split_m2D_ktoR"); - ModuleBase::timer::start("RI_2D_Comm", "split_m2D_ktoR"); - const TC period = RI_Util::get_Born_vonKarmen_period(kv); + ModuleBase::TITLE("RI_2D_Comm","split_m2D_ktoR"); + ModuleBase::timer::start("RI_2D_Comm", "split_m2D_ktoR"); + const TC period = RI_Util::get_Born_vonKarmen_period(kv); std::vector>>> mRs_a2D = (period == TC{1, 1, 1}) ? RI_2D_Comm::split_m2D_ktoR_gamma(ucell, mks_2D, pv, nspin) : RI_2D_Comm::split_m2D_ktoR_k(ucell, kv, mks_2D, pv, nspin, spgsym); - ModuleBase::timer::end("RI_2D_Comm", "split_m2D_ktoR"); - return mRs_a2D; + ModuleBase::timer::end("RI_2D_Comm", "split_m2D_ktoR"); + return mRs_a2D; } template @@ -62,10 +62,10 @@ auto RI_2D_Comm::split_m2D_ktoR_gamma(const UnitCell& ucell, const int nspin) -> std::vector>>> { - ModuleBase::TITLE("RI_2D_Comm","split_m2D_ktoR_gamma"); - ModuleBase::timer::start("RI_2D_Comm", "split_m2D_ktoR_gamma"); + ModuleBase::TITLE("RI_2D_Comm","split_m2D_ktoR_gamma"); + ModuleBase::timer::start("RI_2D_Comm", "split_m2D_ktoR_gamma"); - const std::map nspin_k = {{1,1}, {2,2}, {4,1}}; + const std::map nspin_k = {{1,1}, {2,2}, {4,1}}; const double SPIN_multiple = std::map{ {1,0.5}, {2,1}, {4,1} }.at(nspin); // why? const TC cell = {0, 0, 0}; @@ -144,8 +144,8 @@ auto RI_2D_Comm::split_m2D_ktoR_gamma(const UnitCell& ucell, } #endif - ModuleBase::timer::end("RI_2D_Comm", "split_m2D_ktoR_gamma"); - return mRs_a2D; + ModuleBase::timer::end("RI_2D_Comm", "split_m2D_ktoR_gamma"); + return mRs_a2D; } template @@ -157,11 +157,11 @@ auto RI_2D_Comm::split_m2D_ktoR_k(const UnitCell& ucell, const bool spgsym) -> std::vector>>> { - ModuleBase::TITLE("RI_2D_Comm","split_m2D_ktoR_k"); - ModuleBase::timer::start("RI_2D_Comm", "split_m2D_ktoR_k"); + ModuleBase::TITLE("RI_2D_Comm","split_m2D_ktoR_k"); + ModuleBase::timer::start("RI_2D_Comm", "split_m2D_ktoR_k"); - const TC period = RI_Util::get_Born_vonKarmen_period(kv); - const std::map nspin_k = {{1,1}, {2,2}, {4,1}}; + const TC period = RI_Util::get_Born_vonKarmen_period(kv); + const std::map nspin_k = {{1,1}, {2,2}, {4,1}}; const double SPIN_multiple = std::map{ {1,0.5}, {2,1}, {4,1} }.at(nspin); // why? std::vector>>> mRs_a2D(nspin); @@ -258,100 +258,100 @@ auto RI_2D_Comm::split_m2D_ktoR_k(const UnitCell& ucell, } } } // end #pragma omp parallel - ModuleBase::timer::end("RI_2D_Comm", "split_m2D_ktoR_k"); - return mRs_a2D; + ModuleBase::timer::end("RI_2D_Comm", "split_m2D_ktoR_k"); + return mRs_a2D; } template void RI_2D_Comm::add_Hexx( const UnitCell &ucell, - const K_Vectors &kv, - const int ik, + const K_Vectors &kv, + const int ik, const double alpha, - const std::vector>>> &Hs, + const std::vector>>> &Hs, const Parallel_Orbitals& pv, TK* hk) { - ModuleBase::TITLE("RI_2D_Comm","add_Hexx"); - ModuleBase::timer::start("RI_2D_Comm", "add_Hexx"); - - const std::map> is_list = {{1,{0}}, {2,{kv.isk[ik]}}, {4,{0,1,2,3}}}; - for(const int is_b : is_list.at(PARAM.inp.nspin)) - { - int is0_b, is1_b; - std::tie(is0_b,is1_b) = RI_2D_Comm::split_is_block(is_b); - for(const auto &Hs_tmpA : Hs[is_b]) - { - const TA &iat0 = Hs_tmpA.first; - for(const auto &Hs_tmpB : Hs_tmpA.second) - { - const TA &iat1 = Hs_tmpB.first.first; - const TC &cell1 = Hs_tmpB.first.second; + ModuleBase::TITLE("RI_2D_Comm","add_Hexx"); + ModuleBase::timer::start("RI_2D_Comm", "add_Hexx"); + + const std::map> is_list = {{1,{0}}, {2,{kv.isk[ik]}}, {4,{0,1,2,3}}}; + for(const int is_b : is_list.at(PARAM.inp.nspin)) + { + int is0_b, is1_b; + std::tie(is0_b,is1_b) = RI_2D_Comm::split_is_block(is_b); + for(const auto &Hs_tmpA : Hs[is_b]) + { + const TA &iat0 = Hs_tmpA.first; + for(const auto &Hs_tmpB : Hs_tmpA.second) + { + const TA &iat1 = Hs_tmpB.first.first; + const TC &cell1 = Hs_tmpB.first.second; const std::complex frac = alpha - * std::exp( ModuleBase::TWO_PI*ModuleBase::IMAG_UNIT * (kv.kvec_c[ik] * (RI_Util::array3_to_Vector3(cell1)*ucell.latvec)) ); - const RI::Tensor &H = Hs_tmpB.second; - for(size_t iw0_b=0; iw0_b &H = Hs_tmpB.second; + for(size_t iw0_b=0; iw0_b(H(iw0_b, iw1_b)) * RI::Global_Func::convert(frac), pv, hk); - } - } - } - } - } - ModuleBase::timer::end("RI_2D_Comm", "add_Hexx"); + } + } + } + } + } + ModuleBase::timer::end("RI_2D_Comm", "add_Hexx"); } std::tuple RI_2D_Comm::get_iat_iw_is_block(const UnitCell& ucell,const int& iwt) { - const int iat = ucell.iwt2iat[iwt]; - const int iw = ucell.iwt2iw[iwt]; - switch(PARAM.inp.nspin) - { - case 1: case 2: - return std::make_tuple(iat, iw, 0); - case 4: - return std::make_tuple(iat, iw/2, iw%2); - default: - throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); - } + const int iat = ucell.iwt2iat[iwt]; + const int iw = ucell.iwt2iw[iwt]; + switch(PARAM.inp.nspin) + { + case 1: case 2: + return std::make_tuple(iat, iw, 0); + case 4: + return std::make_tuple(iat, iw/2, iw%2); + default: + throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + } } int RI_2D_Comm::get_is_block(const int is_k, const int is_row_b, const int is_col_b) { - switch(PARAM.inp.nspin) - { - case 1: return 0; - case 2: return is_k; - case 4: return is_row_b*2+is_col_b; - default: throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); - } + switch(PARAM.inp.nspin) + { + case 1: return 0; + case 2: return is_k; + case 4: return is_row_b*2+is_col_b; + default: throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + } } std::tuple RI_2D_Comm::split_is_block(const int is_b) { - switch(PARAM.inp.nspin) - { - case 1: case 2: - return std::make_tuple(0, 0); - case 4: - return std::make_tuple(is_b/2, is_b%2); - default: - throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); - } + switch(PARAM.inp.nspin) + { + case 1: case 2: + return std::make_tuple(0, 0); + case 4: + return std::make_tuple(is_b/2, is_b%2); + default: + throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + } } @@ -361,20 +361,20 @@ int RI_2D_Comm::get_iwt(const UnitCell& ucell, const int iw_b, const int is_b) { - const int it = ucell.iat2it[iat]; - const int ia = ucell.iat2ia[iat]; - int iw=-1; - switch(PARAM.inp.nspin) - { - case 1: case 2: - iw = iw_b; break; - case 4: - iw = iw_b*2+is_b; break; - default: - throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); - } - const int iwt = ucell.itiaiw2iwt(it,ia,iw); - return iwt; + const int it = ucell.iat2it[iat]; + const int ia = ucell.iat2ia[iat]; + int iw=-1; + switch(PARAM.inp.nspin) + { + case 1: case 2: + iw = iw_b; break; + case 4: + iw = iw_b*2+is_b; break; + default: + throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__)); + } + const int iwt = ucell.itiaiw2iwt(it,ia,iw); + return iwt; } template diff --git a/source/source_lcao/module_ri/ri_util.h b/source/source_lcao/module_ri/ri_util.h index f5659d87329..086e62fd91e 100644 --- a/source/source_lcao/module_ri/ri_util.h +++ b/source/source_lcao/module_ri/ri_util.h @@ -21,28 +21,28 @@ namespace RI_Util { - template - inline std::array - Vector3_to_array3(const ModuleBase::Vector3 &v) - { - return std::array {v.x, v.y, v.z}; - } - template - inline ModuleBase::Vector3 - array3_to_Vector3(const std::array &v) - { - return ModuleBase::Vector3 {v[0], v[1], v[2]}; - } + template + inline std::array + Vector3_to_array3(const ModuleBase::Vector3 &v) + { + return std::array {v.x, v.y, v.z}; + } + template + inline ModuleBase::Vector3 + array3_to_Vector3(const std::array &v) + { + return ModuleBase::Vector3 {v[0], v[1], v[2]}; + } - template - RI::Tensor - Matrix_to_Tensor(const Tmatrix &m_old) - { - RI::Tensor m_new({static_cast(m_old.nr), static_cast(m_old.nc)}); - for(int ir=0; ir(m_old(ir,ic)); - return m_new; + template + RI::Tensor + Matrix_to_Tensor(const Tmatrix &m_old) + { + RI::Tensor m_new({static_cast(m_old.nr), static_cast(m_old.nc)}); + for(int ir=0; ir(m_old(ir,ic)); + return m_new; } template @@ -57,20 +57,20 @@ namespace RI_Util return m_new; } - std::map>> - update_coulomb_param( - const std::map>> &coulomb_param, - const UnitCell &ucell, - const K_Vectors *p_kv); + std::map>> + update_coulomb_param( + const std::map>> &coulomb_param, + const UnitCell &ucell, + const K_Vectors *p_kv); - std::map>>>> - update_coulomb_settings( - const std::map>> &coulomb_param, - const UnitCell &ucell, - const K_Vectors *p_kv); + update_coulomb_settings( + const std::map>> &coulomb_param, + const UnitCell &ucell, + const K_Vectors *p_kv); } #include "ri_util.hpp" diff --git a/source/source_lcao/module_ri/ri_util.hpp b/source/source_lcao/module_ri/ri_util.hpp index 41ce8270019..c6be2b1fa04 100644 --- a/source/source_lcao/module_ri/ri_util.hpp +++ b/source/source_lcao/module_ri/ri_util.hpp @@ -12,106 +12,106 @@ namespace RI_Util { - inline std::map>> - update_coulomb_param( - const std::map>> &coulomb_param, - const UnitCell &ucell, - const K_Vectors *p_kv) - { - std::map>> coulomb_param_updated = coulomb_param; - for(auto ¶m_list : coulomb_param_updated) - { - for(auto ¶m : param_list.second) - { - if(param.at("singularity_correction") == "spencer") - { - // 4/3 * pi * Rcut^3 = V_{supercell} = V_{unitcell} * Nk - const int nspin0 = (PARAM.inp.nspin==2) ? 2 : 1; - const double Rcut = std::pow(0.75 * p_kv->get_nkstot_nospin() * ucell.omega / (ModuleBase::PI), 1.0/3.0); - param["Rcut"] = ModuleBase::GlobalFunc::TO_STRING(Rcut); - } + inline std::map>> + update_coulomb_param( + const std::map>> &coulomb_param, + const UnitCell &ucell, + const K_Vectors *p_kv) + { + std::map>> coulomb_param_updated = coulomb_param; + for(auto ¶m_list : coulomb_param_updated) + { + for(auto ¶m : param_list.second) + { + if(param.at("singularity_correction") == "spencer") + { + // 4/3 * pi * Rcut^3 = V_{supercell} = V_{unitcell} * Nk + const int nspin0 = (PARAM.inp.nspin==2) ? 2 : 1; + const double Rcut = std::pow(0.75 * p_kv->get_nkstot_nospin() * ucell.omega / (ModuleBase::PI), 1.0/3.0); + param["Rcut"] = ModuleBase::GlobalFunc::TO_STRING(Rcut); + } else if(param.at("singularity_correction") == "revised_spencer") - { - const double bvk_a1 = ucell.a1.norm() * p_kv->nmp[0]; + { + const double bvk_a1 = ucell.a1.norm() * p_kv->nmp[0]; const double bvk_a2 = ucell.a2.norm() * p_kv->nmp[1]; const double bvk_a3 = ucell.a3.norm() * p_kv->nmp[2]; const double Rcut = 0.5 * std::min({bvk_a1, bvk_a2, bvk_a3}); param["Rcut"] = ModuleBase::GlobalFunc::TO_STRING(Rcut); - } - } - } - return coulomb_param_updated; - } + } + } + } + return coulomb_param_updated; + } - inline std::map>>>> - update_coulomb_settings( - const std::map>> &coulomb_param, - const UnitCell &ucell, - const K_Vectors *p_kv) - { - const std::map>> - coulomb_param_updated = update_coulomb_param(coulomb_param, ucell, p_kv); + update_coulomb_settings( + const std::map>> &coulomb_param, + const UnitCell &ucell, + const K_Vectors *p_kv) + { + const std::map>> + coulomb_param_updated = update_coulomb_param(coulomb_param, ucell, p_kv); - // Separate the parameters into Center2 and Ewald methods - std::map>> coulomb_param_center2; - std::map>> coulomb_param_ewald; - for(auto ¶m_list : coulomb_param_updated) - { - switch(param_list.first) - { - case Conv_Coulomb_Pot_K::Coulomb_Type::Fock: - { - for(auto ¶m : param_list.second) - { - if(param.at("singularity_correction") == "spencer" || param.at("singularity_correction") == "limits" - || param.at("singularity_correction") == "revised_spencer") - { - coulomb_param_center2[param_list.first].push_back(param); - } - else if (param.at("singularity_correction") == "massidda" || param.at("singularity_correction") == "carrier" ) - { - coulomb_param_ewald[param_list.first].push_back(param); - } - } - break; - } - case Conv_Coulomb_Pot_K::Coulomb_Type::Erfc: - { - coulomb_param_center2[param_list.first] = param_list.second; // Erfc is always calculated with Center2 method. - break; - } - default: - { - throw std::invalid_argument( std::string(__FILE__) + " line " + std::to_string(__LINE__) ); - } - } - } + // Separate the parameters into Center2 and Ewald methods + std::map>> coulomb_param_center2; + std::map>> coulomb_param_ewald; + for(auto ¶m_list : coulomb_param_updated) + { + switch(param_list.first) + { + case Conv_Coulomb_Pot_K::Coulomb_Type::Fock: + { + for(auto ¶m : param_list.second) + { + if(param.at("singularity_correction") == "spencer" || param.at("singularity_correction") == "limits" + || param.at("singularity_correction") == "revised_spencer") + { + coulomb_param_center2[param_list.first].push_back(param); + } + else if (param.at("singularity_correction") == "massidda" || param.at("singularity_correction") == "carrier" ) + { + coulomb_param_ewald[param_list.first].push_back(param); + } + } + break; + } + case Conv_Coulomb_Pot_K::Coulomb_Type::Erfc: + { + coulomb_param_center2[param_list.first] = param_list.second; // Erfc is always calculated with Center2 method. + break; + } + default: + { + throw std::invalid_argument( std::string(__FILE__) + " line " + std::to_string(__LINE__) ); + } + } + } - std::map>>>> coulomb_settings; - const bool cal_center = !coulomb_param_center2.empty(); - const bool cal_ewald = !coulomb_param_ewald.empty(); - if(cal_center) - { - coulomb_settings[Conv_Coulomb_Pot_K::Coulomb_Method::Center2] = std::make_pair(cal_center, coulomb_param_center2); - } - if(cal_ewald) - { - coulomb_settings[Conv_Coulomb_Pot_K::Coulomb_Method::Ewald] = std::make_pair(cal_ewald, coulomb_param_ewald); - } - if(cal_center && cal_ewald) - { - coulomb_settings[Conv_Coulomb_Pot_K::Coulomb_Method::Center2].first = false; // If both methods are available, only HF for C is needed. - } + const bool cal_center = !coulomb_param_center2.empty(); + const bool cal_ewald = !coulomb_param_ewald.empty(); + if(cal_center) + { + coulomb_settings[Conv_Coulomb_Pot_K::Coulomb_Method::Center2] = std::make_pair(cal_center, coulomb_param_center2); + } + if(cal_ewald) + { + coulomb_settings[Conv_Coulomb_Pot_K::Coulomb_Method::Ewald] = std::make_pair(cal_ewald, coulomb_param_ewald); + } + if(cal_center && cal_ewald) + { + coulomb_settings[Conv_Coulomb_Pot_K::Coulomb_Method::Center2].first = false; // If both methods are available, only HF for C is needed. + } - return coulomb_settings; - } + return coulomb_settings; + } } #endif diff --git a/source/source_lcao/module_ri/ri_util_bvk.h b/source/source_lcao/module_ri/ri_util_bvk.h index 8142a801715..0079e0bab2d 100644 --- a/source/source_lcao/module_ri/ri_util_bvk.h +++ b/source/source_lcao/module_ri/ri_util_bvk.h @@ -17,65 +17,65 @@ namespace RI_Util { - inline std::array - get_Born_vonKarmen_period(const K_Vectors &kv) - { - return std::array{kv.nmp[0], kv.nmp[1], kv.nmp[2]}; - } + inline std::array + get_Born_vonKarmen_period(const K_Vectors &kv) + { + return std::array{kv.nmp[0], kv.nmp[1], kv.nmp[2]}; + } - // Fold a cell index into [-period/2, period/2) to match LibRI's - // Array_Operator::operator%: (c % period + 3 * period / 2) % period - period / 2 - template - inline Tcell fold_cell_centered(const Tcell c, const Tcell period) - { - return (c % period + 3 * period / 2) % period - period / 2; - } + // Fold a cell index into [-period/2, period/2) to match LibRI's + // Array_Operator::operator%: (c % period + 3 * period / 2) % period - period / 2 + template + inline Tcell fold_cell_centered(const Tcell c, const Tcell period) + { + return (c % period + 3 * period / 2) % period - period / 2; + } - template - std::vector> - get_Born_von_Karmen_cells( const std::array &Born_von_Karman_period ) - { - std::vector> Born_von_Karman_cells; - for( Tcell c=0; c{ fold_cell_centered(c, Born_von_Karman_period[0]) }); - return Born_von_Karman_cells; - } + template + std::vector> + get_Born_von_Karmen_cells( const std::array &Born_von_Karman_period ) + { + std::vector> Born_von_Karman_cells; + for( Tcell c=0; c{ fold_cell_centered(c, Born_von_Karman_period[0]) }); + return Born_von_Karman_cells; + } - template - std::vector> - get_Born_von_Karmen_cells( const std::array &Born_von_Karman_period ) - { - std::array sub_Born_von_Karman_period; - for(size_t i=0; i + std::vector> + get_Born_von_Karmen_cells( const std::array &Born_von_Karman_period ) + { + std::array sub_Born_von_Karman_period; + for(size_t i=0; i> Born_von_Karman_cells; - for( const std::array &sub_cell : get_Born_von_Karmen_cells(sub_Born_von_Karman_period) ) - for( Tcell c=0; c cell; - for(size_t i=0; i> Born_von_Karman_cells; + for( const std::array &sub_cell : get_Born_von_Karmen_cells(sub_Born_von_Karman_period) ) + for( Tcell c=0; c cell; + for(size_t i=0; i - std::vector> - get_Born_von_Karmen_cells( const std::array &Born_von_Karman_period ) - { - std::vector> Born_von_Karman_cells; - for( int ix=0; ix{ix,iy,iz} ); - return Born_von_Karman_cells; - } - */ + /* example for Ndim=3: + template + std::vector> + get_Born_von_Karmen_cells( const std::array &Born_von_Karman_period ) + { + std::vector> Born_von_Karman_cells; + for( int ix=0; ix{ix,iy,iz} ); + return Born_von_Karman_cells; + } + */ } #endif diff --git a/source/source_lcao/module_ri/serialization_boost.h b/source/source_lcao/module_ri/serialization_boost.h index 8cc87ee5793..c53d8d9b482 100644 --- a/source/source_lcao/module_ri/serialization_boost.h +++ b/source/source_lcao/module_ri/serialization_boost.h @@ -18,74 +18,74 @@ namespace boost { - namespace serialization - { - // ModuleBase::Vector3 Peize Lin add 2018-07-01 - template - inline void serialize(Archive & ar, ModuleBase::Vector3 & v, const unsigned int version) - { - ar & v.x; - ar & v.y; - ar & v.z; - } + namespace serialization + { + // ModuleBase::Vector3 Peize Lin add 2018-07-01 + template + inline void serialize(Archive & ar, ModuleBase::Vector3 & v, const unsigned int version) + { + ar & v.x; + ar & v.y; + ar & v.z; + } - // Abfs::Vector3_Order Peize Lin add 2018-07-01 - template - inline void serialize(Archive & ar, Abfs::Vector3_Order & v, const unsigned int version) - { - ar & v.x; - ar & v.y; - ar & v.z; - } + // Abfs::Vector3_Order Peize Lin add 2018-07-01 + template + inline void serialize(Archive & ar, Abfs::Vector3_Order & v, const unsigned int version) + { + ar & v.x; + ar & v.y; + ar & v.z; + } - // matrix Peize Lin add 2018-07-01 - template - inline void save( Archive & ar, const ModuleBase::matrix & m, const unsigned int /*file_version*/ ) - { - const collection_size_type nr(m.nr), nc(m.nc); - ar << BOOST_SERIALIZATION_NVP(nr) << BOOST_SERIALIZATION_NVP(nc); - if( nr && nc ) - ar << serialization::make_array( m.c, nr*nc ); - } - template - inline void load( Archive & ar, ModuleBase::matrix &m, const unsigned int /*file_version*/ ) - { - collection_size_type nr, nc; - ar >> BOOST_SERIALIZATION_NVP(nr) >> BOOST_SERIALIZATION_NVP(nc); - m.create(nr,nc,false); - if( nr && nc ) - ar >> serialization::make_array( m.c, nr*nc ); - } - template - inline void serialize( Archive & ar, ModuleBase::matrix & m, const unsigned int file_version ) - { - boost::serialization::split_free(ar, m, file_version); - } + // matrix Peize Lin add 2018-07-01 + template + inline void save( Archive & ar, const ModuleBase::matrix & m, const unsigned int /*file_version*/ ) + { + const collection_size_type nr(m.nr), nc(m.nc); + ar << BOOST_SERIALIZATION_NVP(nr) << BOOST_SERIALIZATION_NVP(nc); + if( nr && nc ) + ar << serialization::make_array( m.c, nr*nc ); + } + template + inline void load( Archive & ar, ModuleBase::matrix &m, const unsigned int /*file_version*/ ) + { + collection_size_type nr, nc; + ar >> BOOST_SERIALIZATION_NVP(nr) >> BOOST_SERIALIZATION_NVP(nc); + m.create(nr,nc,false); + if( nr && nc ) + ar >> serialization::make_array( m.c, nr*nc ); + } + template + inline void serialize( Archive & ar, ModuleBase::matrix & m, const unsigned int file_version ) + { + boost::serialization::split_free(ar, m, file_version); + } - // MatrixWrapper Peize Lin add 2018-07-31 - template - inline void save( Archive & ar, const ModuleBase::Matrix_Wrapper & m, const unsigned int /*file_version*/ ) - { - const collection_size_type nr(m.nr), nc(m.nc); - ar << BOOST_SERIALIZATION_NVP(nr) << BOOST_SERIALIZATION_NVP(nc); - if( nr && nc ) - ar << serialization::make_array( m.c, nr*nc ); - } - template - inline void load( Archive & ar, ModuleBase::Matrix_Wrapper &m, const unsigned int /*file_version*/ ) - { - collection_size_type nr, nc; - ar >> BOOST_SERIALIZATION_NVP(nr) >> BOOST_SERIALIZATION_NVP(nc); - m.create(nr,nc,false); - if( nr && nc ) - ar >> serialization::make_array( m.c, nr*nc ); - } - template - inline void serialize( Archive & ar, ModuleBase::Matrix_Wrapper & m, const unsigned int file_version ) - { - boost::serialization::split_free(ar, m, file_version); - } - } + // MatrixWrapper Peize Lin add 2018-07-31 + template + inline void save( Archive & ar, const ModuleBase::Matrix_Wrapper & m, const unsigned int /*file_version*/ ) + { + const collection_size_type nr(m.nr), nc(m.nc); + ar << BOOST_SERIALIZATION_NVP(nr) << BOOST_SERIALIZATION_NVP(nc); + if( nr && nc ) + ar << serialization::make_array( m.c, nr*nc ); + } + template + inline void load( Archive & ar, ModuleBase::Matrix_Wrapper &m, const unsigned int /*file_version*/ ) + { + collection_size_type nr, nc; + ar >> BOOST_SERIALIZATION_NVP(nr) >> BOOST_SERIALIZATION_NVP(nc); + m.create(nr,nc,false); + if( nr && nc ) + ar >> serialization::make_array( m.c, nr*nc ); + } + template + inline void serialize( Archive & ar, ModuleBase::Matrix_Wrapper & m, const unsigned int file_version ) + { + boost::serialization::split_free(ar, m, file_version); + } + } } diff --git a/source/source_lcao/module_ri/serialization_cereal.h b/source/source_lcao/module_ri/serialization_cereal.h index bd231a87e36..d0c0fa0af64 100644 --- a/source/source_lcao/module_ri/serialization_cereal.h +++ b/source/source_lcao/module_ri/serialization_cereal.h @@ -18,20 +18,20 @@ template void serialize( Archive & ar, Abfs::Vector3_ namespace ModuleBase { - template void serialize( Archive & ar, Vector3 & v ){ ar(v.x); ar(v.y); ar(v.z); } + template void serialize( Archive & ar, Vector3 & v ){ ar(v.x); ar(v.y); ar(v.z); } - template void save( Archive & ar, const matrix & m ) - { - ar(m.nr); ar(m.nc); - ar(cereal::binary_data(m.c, m.nr*m.nc*sizeof(double))); - } - template void load( Archive & ar, matrix & m ) - { - int nr, nc; - ar(nr); ar(nc); - m.create(nr,nc); - ar(cereal::binary_data(m.c, m.nr*m.nc*sizeof(double))); - } + template void save( Archive & ar, const matrix & m ) + { + ar(m.nr); ar(m.nc); + ar(cereal::binary_data(m.c, m.nr*m.nc*sizeof(double))); + } + template void load( Archive & ar, matrix & m ) + { + int nr, nc; + ar(nr); ar(nc); + m.create(nr,nc); + ar(cereal::binary_data(m.c, m.nr*m.nc*sizeof(double))); + } } #include @@ -39,35 +39,35 @@ namespace ModuleBase namespace ModuleBase { - template - void bcast_data_cereal(T &data, const MPI_Comm &mpi_comm, const int &rank_bcast) - { - int my_rank; MPI_Comm_rank( mpi_comm, &my_rank ); - if(my_rank==rank_bcast) - { - std::stringstream ss; - { - cereal::BinaryOutputArchive ar(ss); - ar(data); - } - const int size = ss.str().size(); - MPI_Bcast( const_cast(&size), 1, MPI_INT, rank_bcast, mpi_comm ); - MPI_Bcast( const_cast(ss.str().c_str()), size, MPI_CHAR, rank_bcast, mpi_comm ); - } - else - { - int size; - MPI_Bcast( &size, 1, MPI_INT, rank_bcast, mpi_comm ); - std::vector c(size); - MPI_Bcast( c.data(), size, MPI_CHAR, rank_bcast, mpi_comm ); - std::stringstream ss; - ss.rdbuf()->pubsetbuf(c.data(),size); - { - cereal::BinaryInputArchive ar(ss); - ar(data); - } - } - } + template + void bcast_data_cereal(T &data, const MPI_Comm &mpi_comm, const int &rank_bcast) + { + int my_rank; MPI_Comm_rank( mpi_comm, &my_rank ); + if(my_rank==rank_bcast) + { + std::stringstream ss; + { + cereal::BinaryOutputArchive ar(ss); + ar(data); + } + const int size = ss.str().size(); + MPI_Bcast( const_cast(&size), 1, MPI_INT, rank_bcast, mpi_comm ); + MPI_Bcast( const_cast(ss.str().c_str()), size, MPI_CHAR, rank_bcast, mpi_comm ); + } + else + { + int size; + MPI_Bcast( &size, 1, MPI_INT, rank_bcast, mpi_comm ); + std::vector c(size); + MPI_Bcast( c.data(), size, MPI_CHAR, rank_bcast, mpi_comm ); + std::stringstream ss; + ss.rdbuf()->pubsetbuf(c.data(),size); + { + cereal::BinaryInputArchive ar(ss); + ar(data); + } + } + } } #endif diff --git a/source/source_lcao/module_ri/test_code/element_basis_index_test.cpp b/source/source_lcao/module_ri/test_code/element_basis_index_test.cpp index 0777130374c..205077127eb 100644 --- a/source/source_lcao/module_ri/test_code/element_basis_index_test.cpp +++ b/source/source_lcao/module_ri/test_code/element_basis_index_test.cpp @@ -8,83 +8,83 @@ ModuleBase::Element_Basis_Index::Range construct_range() { - ModuleBase::Element_Basis_Index::Range range; - range.resize(2); - - range[0].resize(3); - range[0][0].N = range[0][1].N = 2; - range[0][2].N = 1; - - range[1].resize(2); - range[1][0].N = 3; - range[1][1].N = 2; - - for( size_t T=0; T!=range.size(); ++T ) - for( size_t L=0; L!=range[T].size(); ++L ) - range[T][L].M=2*L+1; - - return range; + ModuleBase::Element_Basis_Index::Range range; + range.resize(2); + + range[0].resize(3); + range[0][0].N = range[0][1].N = 2; + range[0][2].N = 1; + + range[1].resize(2); + range[1][0].N = 3; + range[1][1].N = 2; + + for( size_t T=0; T!=range.size(); ++T ) + for( size_t L=0; L!=range[T].size(); ++L ) + range[T][L].M=2*L+1; + + return range; } int main() { - const ModuleBase::Element_Basis_Index::Range range = construct_range(); - std::cout<<"range:"<>>> & orbs, const std::string & file_name ) { - std::ofstream ofsN(file_name); - for( size_t T=0; T!=orbs.size(); ++T ) - for( size_t L=0; L!=orbs[T].size(); ++L ) - for( size_t N=0; N!=orbs[T][L].size(); ++N ) - { - ofsN<>> & orbs, const std::string & file_name ) { - std::ofstream ofsN(file_name); - for( size_t T=0; T!=orbs.size(); ++T ) - for( size_t L=0; L!=orbs[T].size(); ++L ) - for( size_t N=0; N!=orbs[T][L].size(); ++N ) - { - ofsN< - Tensor init_Tensor(const std::vector &shape) - { - Tensor t(shape); - for(size_t i=0; isize(); ++i) - t.ptr()[i] = i; - return t; - } - - template - Tensor init_Tensor2(const std::vector &shape) - { - Tensor t(shape); - for(size_t i0=0; i0 - void test_input_output() - { - Inverse_Matrix inv; - - const size_t n_all = 5; - const std::vector n0 = {2,3}; - const std::vector n1 = {1,2,2}; - - Tensor m = init_Tensor({n_all,n_all}); - - std::vector>> ms(n0.size(), std::vector>(n1.size())); - for(size_t Im0=0; Im0({n0[Im0], n1[Im1]}); - - inv.input(m); - std::cout< - void test_inverse() - { - Tensor t = init_Tensor2({5,5}); - Inverse_Matrix inv; - inv.input(t); - inv.cal_inverse(Inverse_Matrix::Method::potrf); - //inv.cal_inverse(Inverse_Matrix::Method::syev); - Tensor tI = inv.output(); - - std::cout< + Tensor init_Tensor(const std::vector &shape) + { + Tensor t(shape); + for(size_t i=0; isize(); ++i) + t.ptr()[i] = i; + return t; + } + + template + Tensor init_Tensor2(const std::vector &shape) + { + Tensor t(shape); + for(size_t i0=0; i0 + void test_input_output() + { + Inverse_Matrix inv; + + const size_t n_all = 5; + const std::vector n0 = {2,3}; + const std::vector n1 = {1,2,2}; + + Tensor m = init_Tensor({n_all,n_all}); + + std::vector>> ms(n0.size(), std::vector>(n1.size())); + for(size_t Im0=0; Im0({n0[Im0], n1[Im1]}); + + inv.input(m); + std::cout< + void test_inverse() + { + Tensor t = init_Tensor2({5,5}); + Inverse_Matrix inv; + inv.input(t); + inv.cal_inverse(Inverse_Matrix::Method::potrf); + //inv.cal_inverse(Inverse_Matrix::Method::syev); + Tensor tI = inv.output(); + + std::cout< descv(9); - ScalapackConnector::descinit(ModuleBase::GlobalFunc::VECTOR_TO_PTR(descv), m, n, mb, nb, irsrc, icsrc, ictxt, mlld, info); - return descv; - }; + auto ofs_pro = [&]() + { + std::ofstream ofs("ofs_"+ModuleBase::GlobalFunc::TO_STRING(my_rank)); + ofs< descv(9); + ScalapackConnector::descinit(ModuleBase::GlobalFunc::VECTOR_TO_PTR(descv), m, n, mb, nb, irsrc, icsrc, ictxt, mlld, info); + return descv; + }; // return init_desc; // }; - auto ofs_matrix = [&](const std::vector& v) - { - std::ofstream ofs("matrix_"+ModuleBase::GlobalFunc::TO_STRING(my_rank)); - for(const double i : v ) - ofs< &descv) - { - std::ofstream ofs("desc_"+ModuleBase::GlobalFunc::TO_STRING(my_rank)); - for(int i=0; i<9; ++i) - ofs<& v) + { + std::ofstream ofs("matrix_"+ModuleBase::GlobalFunc::TO_STRING(my_rank)); + for(const double i : v ) + ofs< &descv) + { + std::ofstream ofs("desc_"+ModuleBase::GlobalFunc::TO_STRING(my_rank)); + for(int i=0; i<9; ++i) + ofs< descv_5321_32 = init_ictxt('R',true)(5,3,2,1,0,0); - int *desc_5321_32 = ModuleBase::GlobalFunc::VECTOR_TO_PTR(descv_5321_32); - - std::vector descv_5521_32 = init_ictxt('R',true)(5,5,2,1,0,0); - int *desc_5521_32 = ModuleBase::GlobalFunc::VECTOR_TO_PTR(descv_5521_32); - - std::vector descv_5522_32 = init_ictxt('R',true)(5,5,2,2,0,0); - int *desc_5522_32 = ModuleBase::GlobalFunc::VECTOR_TO_PTR(descv_5522_32); - - std::vector descv_5511_32 = init_ictxt('R',true)(5,5,1,1,0,0); - int *desc_5511_32 = ModuleBase::GlobalFunc::VECTOR_TO_PTR(descv_5511_32); - ofs_desc(descv_5511_32); + std::vector descv_5321_32 = init_ictxt('R',true)(5,3,2,1,0,0); + int *desc_5321_32 = ModuleBase::GlobalFunc::VECTOR_TO_PTR(descv_5321_32); + + std::vector descv_5521_32 = init_ictxt('R',true)(5,5,2,1,0,0); + int *desc_5521_32 = ModuleBase::GlobalFunc::VECTOR_TO_PTR(descv_5521_32); + + std::vector descv_5522_32 = init_ictxt('R',true)(5,5,2,2,0,0); + int *desc_5522_32 = ModuleBase::GlobalFunc::VECTOR_TO_PTR(descv_5522_32); + + std::vector descv_5511_32 = init_ictxt('R',true)(5,5,1,1,0,0); + int *desc_5511_32 = ModuleBase::GlobalFunc::VECTOR_TO_PTR(descv_5511_32); + ofs_desc(descv_5511_32); */ - std::vector descv_5321_32 = init_desc(5,3,2,1,0,0); - int *desc_5321_32 = ModuleBase::GlobalFunc::VECTOR_TO_PTR(descv_5321_32); - - std::vector descv_5521_32 = init_desc(5,5,2,1,0,0); - int *desc_5521_32 = ModuleBase::GlobalFunc::VECTOR_TO_PTR(descv_5521_32); - - std::vector descv_5522_32 = init_desc(5,5,2,2,0,0); - int *desc_5522_32 = ModuleBase::GlobalFunc::VECTOR_TO_PTR(descv_5522_32); - - std::vector descv_5511_32 = init_desc(5,5,1,1,0,0); - int *desc_5511_32 = ModuleBase::GlobalFunc::VECTOR_TO_PTR(descv_5511_32); - - /* - auto init_matrix_A5624_32 = [&]() - { - switch(my_rank) - { - case 0: return std::vector{0,1,2,3,6,7,8,9}; - case 1: return std::vector{4,5,10,11}; - case 2: return std::vector{12,13,14,15,18,19,20,21}; - case 3: return std::vector{16,17,22,23}; - case 4: return std::vector{24,25,26,27}; - case 5: return std::vector{28,29}; - } - }; - auto init_matrix_I21 = [&]() - { - switch(my_rank) - { - case 0: return std::vector{1,0,0,0,0,0}; - case 1: return std::vector{0,0,0,1,0,0}; - case 2: return std::vector{0,1,0,0,0,0}; - case 3: return std::vector{0,0,0,0,1,0}; - case 4: return std::vector{0,0,1,0,0,0}; - case 5: return std::vector{0,0,0,0,0,1}; - } - }; - auto init_matrix_I11 = [&]() - { - switch(my_rank) - { - case 0: return std::vector{1,0,0,0,0,0}; - case 1: return std::vector{0,0,0,0,1,0}; - case 2: return std::vector{0,0,0,0,0,1}; - case 3: return std::vector{1,0,0,0,0,0}; - case 4: return std::vector{0,1,0,0,0,0}; - case 5: return std::vector{0,0,0,0,0,1}; - } - }; - auto init_matrix_I4411 = [&]() - { - switch(my_rank) - { - case 0: return std::vector{1,0,0,1}; - case 1: return std::vector{0,0,0,0}; - case 2: return std::vector{0,0,0,0}; - case 3: return std::vector{1,0,0,1}; - } - }; - auto init_matrix_I4422 = [&]() - { - switch(my_rank) - { - case 0: return std::vector{1,0,0,1}; - case 1: return std::vector{0,0,0,0}; - case 2: return std::vector{0,0,0,0}; - case 3: return std::vector{1,0,0,1}; - } - }; - auto init_matrix_I5522 = [&]() - { - switch(my_rank) - { - case 0: return std::vector{1,0,0,0,1,0,0,0,1}; - case 1: return std::vector{0,0,0,0,0,0}; - case 2: return std::vector{0,0,0,0,0,0}; - case 3: return std::vector{1,0,0,1}; - } - }; - auto init_matrix_I5511_32 = [&]() - { - switch(my_rank) - { - case 0: return std::vector{1,0,0,0,0}; - case 1: return std::vector{0,0,0,1}; - case 2: return std::vector{0,0,0,0,0,1}; - case 3: return std::vector{1,0,0,0}; - case 4: return std::vector{0,1,0}; - case 5: return std::vector{0,0}; - } - }; - auto init_matrix_I5521_32 = [&]() - { - switch(my_rank) - { - case 0: return std::vector{1,0,0,0,0,0}; - case 1: return std::vector{0,0,1,0}; - case 2: return std::vector{0,1,0,0,0,0}; - case 3: return std::vector{0,0,0,1}; - case 4: return std::vector{0,0,1}; - case 5: return std::vector{0,0}; - } - }; - auto init_matrix_I5522_32 = [&]() - { - switch(my_rank) - { - case 0: return std::vector{1,0,0,0,1,0}; - case 1: return std::vector{0,0,0,0}; - case 2: return std::vector{0,0,0,0,0,0}; - case 3: return std::vector{1,0,0,1}; - case 4: return std::vector{0,0,1}; - case 5: return std::vector{0,0}; - } - }; - auto init_matrix_I3321_11 = [&]() - { - switch(my_rank) - { - case 0: return std::vector{1,0,0,0,1,0,0,0,1}; - } - }; - auto init_matrix_I3321_21 = [&]() - { - switch(my_rank) - { - case 0: return std::vector{1,0,0,0,0,1}; - case 1: return std::vector{0,1,0}; - } - }; - auto init_matrix_A5522_32 = [&]() - { - switch(my_rank) - { - case 0: return std::vector{1,2,5,6,7,10}; - case 1: return std::vector{3,4,8,9}; - case 2: return std::vector{11,12,15,16,17,20}; - case 3: return std::vector{13,14,18,19}; - case 4: return std::vector{21,22,25}; - case 5: return std::vector{23,24}; - } - }; - */ - auto init_matrix_I3311_32 = [&]() - { - switch(my_rank) - { - case 0: return std::vector{1,0}; - case 1: return std::vector{0}; - case 2: return std::vector{0,0}; - case 3: return std::vector{1}; - case 4: return std::vector{0,1}; - case 5: return std::vector{0}; - } - }; - auto init_matrix_I5511_32 = [&]() - { - switch(my_rank) - { - case 0: return std::vector{1,0,0,0,0,0}; - case 1: return std::vector{0,0,0,1}; - case 2: return std::vector{0,0,0,0,0,1}; - case 3: return std::vector{1,0,0,0}; - case 4: return std::vector{0,1,0}; - case 5: return std::vector{0,0}; - } - }; - auto init_matrix_I5521_32 = [&]() - { - switch(my_rank) - { - case 0: return std::vector{1,0,0,0,0,0}; - case 1: return std::vector{0,1,0,0}; - case 2: return std::vector{0,0,1,0,0,0}; - case 3: return std::vector{0,0,0,1}; - case 4: return std::vector{0,0,1}; - case 5: return std::vector{0,0}; - } - }; - auto init_matrix_I5522_32 = [&]() - { - switch(my_rank) - { - case 0: return std::vector{1,0,0,1,0,0}; - case 1: return std::vector{0,0,0,0}; - case 2: return std::vector{0,0,0,0,0,0}; - case 3: return std::vector{1,0,0,1}; - case 4: return std::vector{0,0,1}; - case 5: return std::vector{0,0}; - } - }; - auto init_matrix_A5321_32 = [&]() - { - switch(my_rank) - { - case 0: return std::vector{1,6,3,8}; - case 1: return std::vector{2,7}; - case 2: return std::vector{11,16,13,18}; - case 3: return std::vector{12,17}; - case 4: return std::vector{21,23}; - case 5: return std::vector{22}; - } - }; - auto init_matrix_A5521_32 = [&]() - { - switch(my_rank) - { - case 0: return std::vector{1,6,3,8,5,10}; - case 1: return std::vector{2,7,4,9}; - case 2: return std::vector{11,16,13,18,15,20}; - case 3: return std::vector{12,17,14,19}; - case 4: return std::vector{21,23,25}; - case 5: return std::vector{22,24}; - } - }; - auto init_matrix_A5522_32 = [&]() - { - switch(my_rank) - { - case 0: return std::vector{1,6,2,7,5,10}; - case 1: return std::vector{3,8,4,9}; - case 2: return std::vector{11,16,12,17,15,20}; - case 3: return std::vector{13,18,14,19}; - case 4: return std::vector{21,22,25}; - case 5: return std::vector{23,24}; - } - }; + std::vector descv_5321_32 = init_desc(5,3,2,1,0,0); + int *desc_5321_32 = ModuleBase::GlobalFunc::VECTOR_TO_PTR(descv_5321_32); + + std::vector descv_5521_32 = init_desc(5,5,2,1,0,0); + int *desc_5521_32 = ModuleBase::GlobalFunc::VECTOR_TO_PTR(descv_5521_32); + + std::vector descv_5522_32 = init_desc(5,5,2,2,0,0); + int *desc_5522_32 = ModuleBase::GlobalFunc::VECTOR_TO_PTR(descv_5522_32); + + std::vector descv_5511_32 = init_desc(5,5,1,1,0,0); + int *desc_5511_32 = ModuleBase::GlobalFunc::VECTOR_TO_PTR(descv_5511_32); + + /* + auto init_matrix_A5624_32 = [&]() + { + switch(my_rank) + { + case 0: return std::vector{0,1,2,3,6,7,8,9}; + case 1: return std::vector{4,5,10,11}; + case 2: return std::vector{12,13,14,15,18,19,20,21}; + case 3: return std::vector{16,17,22,23}; + case 4: return std::vector{24,25,26,27}; + case 5: return std::vector{28,29}; + } + }; + auto init_matrix_I21 = [&]() + { + switch(my_rank) + { + case 0: return std::vector{1,0,0,0,0,0}; + case 1: return std::vector{0,0,0,1,0,0}; + case 2: return std::vector{0,1,0,0,0,0}; + case 3: return std::vector{0,0,0,0,1,0}; + case 4: return std::vector{0,0,1,0,0,0}; + case 5: return std::vector{0,0,0,0,0,1}; + } + }; + auto init_matrix_I11 = [&]() + { + switch(my_rank) + { + case 0: return std::vector{1,0,0,0,0,0}; + case 1: return std::vector{0,0,0,0,1,0}; + case 2: return std::vector{0,0,0,0,0,1}; + case 3: return std::vector{1,0,0,0,0,0}; + case 4: return std::vector{0,1,0,0,0,0}; + case 5: return std::vector{0,0,0,0,0,1}; + } + }; + auto init_matrix_I4411 = [&]() + { + switch(my_rank) + { + case 0: return std::vector{1,0,0,1}; + case 1: return std::vector{0,0,0,0}; + case 2: return std::vector{0,0,0,0}; + case 3: return std::vector{1,0,0,1}; + } + }; + auto init_matrix_I4422 = [&]() + { + switch(my_rank) + { + case 0: return std::vector{1,0,0,1}; + case 1: return std::vector{0,0,0,0}; + case 2: return std::vector{0,0,0,0}; + case 3: return std::vector{1,0,0,1}; + } + }; + auto init_matrix_I5522 = [&]() + { + switch(my_rank) + { + case 0: return std::vector{1,0,0,0,1,0,0,0,1}; + case 1: return std::vector{0,0,0,0,0,0}; + case 2: return std::vector{0,0,0,0,0,0}; + case 3: return std::vector{1,0,0,1}; + } + }; + auto init_matrix_I5511_32 = [&]() + { + switch(my_rank) + { + case 0: return std::vector{1,0,0,0,0}; + case 1: return std::vector{0,0,0,1}; + case 2: return std::vector{0,0,0,0,0,1}; + case 3: return std::vector{1,0,0,0}; + case 4: return std::vector{0,1,0}; + case 5: return std::vector{0,0}; + } + }; + auto init_matrix_I5521_32 = [&]() + { + switch(my_rank) + { + case 0: return std::vector{1,0,0,0,0,0}; + case 1: return std::vector{0,0,1,0}; + case 2: return std::vector{0,1,0,0,0,0}; + case 3: return std::vector{0,0,0,1}; + case 4: return std::vector{0,0,1}; + case 5: return std::vector{0,0}; + } + }; + auto init_matrix_I5522_32 = [&]() + { + switch(my_rank) + { + case 0: return std::vector{1,0,0,0,1,0}; + case 1: return std::vector{0,0,0,0}; + case 2: return std::vector{0,0,0,0,0,0}; + case 3: return std::vector{1,0,0,1}; + case 4: return std::vector{0,0,1}; + case 5: return std::vector{0,0}; + } + }; + auto init_matrix_I3321_11 = [&]() + { + switch(my_rank) + { + case 0: return std::vector{1,0,0,0,1,0,0,0,1}; + } + }; + auto init_matrix_I3321_21 = [&]() + { + switch(my_rank) + { + case 0: return std::vector{1,0,0,0,0,1}; + case 1: return std::vector{0,1,0}; + } + }; + auto init_matrix_A5522_32 = [&]() + { + switch(my_rank) + { + case 0: return std::vector{1,2,5,6,7,10}; + case 1: return std::vector{3,4,8,9}; + case 2: return std::vector{11,12,15,16,17,20}; + case 3: return std::vector{13,14,18,19}; + case 4: return std::vector{21,22,25}; + case 5: return std::vector{23,24}; + } + }; + */ + auto init_matrix_I3311_32 = [&]() + { + switch(my_rank) + { + case 0: return std::vector{1,0}; + case 1: return std::vector{0}; + case 2: return std::vector{0,0}; + case 3: return std::vector{1}; + case 4: return std::vector{0,1}; + case 5: return std::vector{0}; + } + }; + auto init_matrix_I5511_32 = [&]() + { + switch(my_rank) + { + case 0: return std::vector{1,0,0,0,0,0}; + case 1: return std::vector{0,0,0,1}; + case 2: return std::vector{0,0,0,0,0,1}; + case 3: return std::vector{1,0,0,0}; + case 4: return std::vector{0,1,0}; + case 5: return std::vector{0,0}; + } + }; + auto init_matrix_I5521_32 = [&]() + { + switch(my_rank) + { + case 0: return std::vector{1,0,0,0,0,0}; + case 1: return std::vector{0,1,0,0}; + case 2: return std::vector{0,0,1,0,0,0}; + case 3: return std::vector{0,0,0,1}; + case 4: return std::vector{0,0,1}; + case 5: return std::vector{0,0}; + } + }; + auto init_matrix_I5522_32 = [&]() + { + switch(my_rank) + { + case 0: return std::vector{1,0,0,1,0,0}; + case 1: return std::vector{0,0,0,0}; + case 2: return std::vector{0,0,0,0,0,0}; + case 3: return std::vector{1,0,0,1}; + case 4: return std::vector{0,0,1}; + case 5: return std::vector{0,0}; + } + }; + auto init_matrix_A5321_32 = [&]() + { + switch(my_rank) + { + case 0: return std::vector{1,6,3,8}; + case 1: return std::vector{2,7}; + case 2: return std::vector{11,16,13,18}; + case 3: return std::vector{12,17}; + case 4: return std::vector{21,23}; + case 5: return std::vector{22}; + } + }; + auto init_matrix_A5521_32 = [&]() + { + switch(my_rank) + { + case 0: return std::vector{1,6,3,8,5,10}; + case 1: return std::vector{2,7,4,9}; + case 2: return std::vector{11,16,13,18,15,20}; + case 3: return std::vector{12,17,14,19}; + case 4: return std::vector{21,23,25}; + case 5: return std::vector{22,24}; + } + }; + auto init_matrix_A5522_32 = [&]() + { + switch(my_rank) + { + case 0: return std::vector{1,6,2,7,5,10}; + case 1: return std::vector{3,8,4,9}; + case 2: return std::vector{11,16,12,17,15,20}; + case 3: return std::vector{13,18,14,19}; + case 4: return std::vector{21,22,25}; + case 5: return std::vector{23,24}; + } + }; - std::vector mA5321_32 = init_matrix_A5321_32(); - std::vector mA5522_32 = init_matrix_A5522_32(); - std::vector mI3311_32 = init_matrix_I3311_32(); - std::vector mI5511_32 = init_matrix_I5511_32(); - std::vector mI5521_32 = init_matrix_I5521_32(); - std::vector mC(100); - ScalapackConnector::pgemm( 'T','N', 3,5,5, 1, ModuleBase::GlobalFunc::VECTOR_TO_PTR(mA5321_32),1,1,desc_5321_32, ModuleBase::GlobalFunc::VECTOR_TO_PTR(mI5511_32),1,1,desc_5511_32, 0, ModuleBase::GlobalFunc::VECTOR_TO_PTR(mC),1,1,desc_5522_32 ); - - auto check_matrix = [&](const std::vector &v1, const std::vector &v2) - { - const size_t len = min(v1.size(),v2.size()); - for(int i=0; i mA5321_32 = init_matrix_A5321_32(); + std::vector mA5522_32 = init_matrix_A5522_32(); + std::vector mI3311_32 = init_matrix_I3311_32(); + std::vector mI5511_32 = init_matrix_I5511_32(); + std::vector mI5521_32 = init_matrix_I5521_32(); + std::vector mC(100); + ScalapackConnector::pgemm( 'T','N', 3,5,5, 1, ModuleBase::GlobalFunc::VECTOR_TO_PTR(mA5321_32),1,1,desc_5321_32, ModuleBase::GlobalFunc::VECTOR_TO_PTR(mI5511_32),1,1,desc_5511_32, 0, ModuleBase::GlobalFunc::VECTOR_TO_PTR(mC),1,1,desc_5522_32 ); + + auto check_matrix = [&](const std::vector &v1, const std::vector &v2) + { + const size_t len = min(v1.size(),v2.size()); + for(int i=0; i static std::ostream & operator<<( std::ostream & os, const std::pair &p ) { - os<<"<"<"; - return os; + os<<"<"<"; + return os; } // Peize Lin add 2016-06-06 template static std::ostream & operator<<( std::ostream & os, const std::vector &v ) { - os<<"["; - for( const T &i : v ) - os< static std::ostream & operator<<( std::ostream & os, const std::valarray &v ) { - os<<"["; - for( const T &i : v ) - os< static std::ostream & operator<<( std::ostream & os, const std::array &v ) { - os<<"["; - for( const T &i : v ) - os< static std::ostream & operator<<( std::ostream & os, const std::set &v ) { - os<<"("; - for( const T &i : v ) - os< static std::ostream & operator<<( std::ostream & os, const std::map &v ) { - for( const auto &i : v ) + for( const auto &i : v ) // os<<"{"< get_memory(const int N) { - std::vector m; - std::string s; - std::ifstream ifs("/proc/meminfo"); - ifs>>s>>s; - m.push_back(stoi(s)/1024); - for(int i=1; i>s>>s>>s; - m.push_back(stoi(s)/1024); - } - ifs.close(); - return m; + std::vector m; + std::string s; + std::ifstream ifs("/proc/meminfo"); + ifs>>s>>s; + m.push_back(stoi(s)/1024); + for(int i=1; i>s>>s>>s; + m.push_back(stoi(s)/1024); + } + ifs.close(); + return m; } #endif // TEST_FUNCTION_H diff --git a/source/source_lcao/module_rt/band_energy.h b/source/source_lcao/module_rt/band_energy.h index 107cd749e59..a2d4736824b 100644 --- a/source/source_lcao/module_rt/band_energy.h +++ b/source/source_lcao/module_rt/band_energy.h @@ -1,5 +1,5 @@ /** - * @file bandenegy.h + * @file band_energy.h * @brief compute band energy ekb * This file originally belonged to file LCAO_evolve.cpp */ diff --git a/source/source_lcao/pulay_fs_center2.cpp b/source/source_lcao/pulay_fs_center2.cpp index 1b4c4e8e136..eacbc5088ab 100644 --- a/source/source_lcao/pulay_fs_center2.cpp +++ b/source/source_lcao/pulay_fs_center2.cpp @@ -2,108 +2,108 @@ template<> // gamma-only, provided xy void PulayForceStress::cal_pulay_fs( - ModuleBase::matrix& force, - ModuleBase::matrix& stress, - const module_dm::DensityMatrix& dm, - const UnitCell& ucell, - const Parallel_Orbitals& pv, - const double* (&dHSx)[3], - const double* (&dHSxy)[6], - const bool& isforce, - const bool& isstress, - Record_adj* ra, - const double& factor_force, - const double& factor_stress) + ModuleBase::matrix& force, + ModuleBase::matrix& stress, + const module_dm::DensityMatrix& dm, + const UnitCell& ucell, + const Parallel_Orbitals& pv, + const double* (&dHSx)[3], + const double* (&dHSxy)[6], + const bool& isforce, + const bool& isstress, + Record_adj* ra, + const double& factor_force, + const double& factor_stress) { - ModuleBase::TITLE("Forces", "cal_pulay_fs"); - ModuleBase::timer::start("Forces", "cal_pulay_fs"); + ModuleBase::TITLE("Forces", "cal_pulay_fs"); + ModuleBase::timer::start("Forces", "cal_pulay_fs"); - const int nspin = PARAM.inp.nspin; - const int nlocal = PARAM.globalv.nlocal; + const int nspin = PARAM.inp.nspin; + const int nlocal = PARAM.globalv.nlocal; - for (int i = 0; i < nlocal; ++i) - { - const int iat = ucell.iwt2iat[i]; - for (int j = 0; j < nlocal; ++j) - { - const int mu = pv.global2local_row(j); - const int nu = pv.global2local_col(i); + for (int i = 0; i < nlocal; ++i) + { + const int iat = ucell.iwt2iat[i]; + for (int j = 0; j < nlocal; ++j) + { + const int mu = pv.global2local_row(j); + const int nu = pv.global2local_col(i); - if (mu >= 0 && nu >= 0) - { - const int index = mu * pv.ncol + nu; - double sum = 0.0; - for (int is = 0; is < nspin; ++is) - { - sum += dm.get_dmk(is + 1, 0, nu, mu); - } - if (isforce) - { - const double sumf = sum * factor_force; - for (int i = 0; i < 3; ++i) - { - force(iat, i) += sumf * 2.0 * dHSx[i][index]; - } - } - if (isstress) - { - const double sums = sum * factor_stress; - int ij = 0; - for (int i = 0; i < 3;++i) - { - for (int j = i; j < 3; ++j) - { - stress(i, j) += sums * dHSxy[ij++][index]; - } - } - } - } - } - } + if (mu >= 0 && nu >= 0) + { + const int index = mu * pv.ncol + nu; + double sum = 0.0; + for (int is = 0; is < nspin; ++is) + { + sum += dm.get_dmk(is + 1, 0, nu, mu); + } + if (isforce) + { + const double sumf = sum * factor_force; + for (int i = 0; i < 3; ++i) + { + force(iat, i) += sumf * 2.0 * dHSx[i][index]; + } + } + if (isstress) + { + const double sums = sum * factor_stress; + int ij = 0; + for (int i = 0; i < 3;++i) + { + for (int j = i; j < 3; ++j) + { + stress(i, j) += sums * dHSxy[ij++][index]; + } + } + } + } + } + } - if (isstress) - { - StressTools::stress_fill(ucell.lat0, ucell.omega, stress); - } + if (isstress) + { + StressTools::stress_fill(ucell.lat0, ucell.omega, stress); + } - ModuleBase::timer::end("Forces", "cal_pulay_fs"); + ModuleBase::timer::end("Forces", "cal_pulay_fs"); } template<> //multi-k, provided xy void PulayForceStress::cal_pulay_fs( - ModuleBase::matrix& force, - ModuleBase::matrix& stress, - const module_dm::DensityMatrix, double>& dm, - const UnitCell& ucell, - const Parallel_Orbitals& pv, - const double* (&dHSx)[3], - const double* (&dHSxy)[6], - const bool& isforce, - const bool& isstress, - Record_adj* ra, - const double& factor_force, - const double& factor_stress) + ModuleBase::matrix& force, + ModuleBase::matrix& stress, + const module_dm::DensityMatrix, double>& dm, + const UnitCell& ucell, + const Parallel_Orbitals& pv, + const double* (&dHSx)[3], + const double* (&dHSxy)[6], + const bool& isforce, + const bool& isstress, + Record_adj* ra, + const double& factor_force, + const double& factor_stress) { - auto stress_func = [](ModuleBase::matrix& local_s, - const double& dm2d1_s, - const double** dHSx, - const double** dHSxy, - const double* dtau, - const int& irr) - { - int ij = 0; - for (int i = 0; i < 3; ++i) - { - for (int j = i; j < 3; ++j) - { - local_s(i, j) += dm2d1_s * dHSxy[ij++][irr]; - } - } - }; - cal_pulay_fs(force, stress, dm, ucell, pv, dHSx, dHSxy, - nullptr, isforce, isstress, ra, - factor_force, factor_stress, stress_func); + auto stress_func = [](ModuleBase::matrix& local_s, + const double& dm2d1_s, + const double** dHSx, + const double** dHSxy, + const double* dtau, + const int& irr) + { + int ij = 0; + for (int i = 0; i < 3; ++i) + { + for (int j = i; j < 3; ++j) + { + local_s(i, j) += dm2d1_s * dHSxy[ij++][irr]; + } + } + }; + cal_pulay_fs(force, stress, dm, ucell, pv, dHSx, dHSxy, + nullptr, isforce, isstress, ra, + factor_force, factor_stress, stress_func); } @@ -122,23 +122,23 @@ void PulayForceStress::cal_pulay_fs( const double& factor_force, const double& factor_stress) { - auto stress_func = [](ModuleBase::matrix& local_s, - const double& dm2d1_s, - const double** dHSx, - const double** dHSxy, - const double* dtau, - const int& irr) - { - for (int i = 0; i < 3; ++i) - { - for (int j = i; j < 3; ++j) - { - local_s(i, j) += dm2d1_s * dHSx[i][irr] * dtau[irr * 3 + j]; - } - } - }; - cal_pulay_fs(force, stress, dm, ucell, pv, dHSx, - nullptr, dtau, isforce, isstress, ra, - factor_force, factor_stress, stress_func); + auto stress_func = [](ModuleBase::matrix& local_s, + const double& dm2d1_s, + const double** dHSx, + const double** dHSxy, + const double* dtau, + const int& irr) + { + for (int i = 0; i < 3; ++i) + { + for (int j = i; j < 3; ++j) + { + local_s(i, j) += dm2d1_s * dHSx[i][irr] * dtau[irr * 3 + j]; + } + } + }; + cal_pulay_fs(force, stress, dm, ucell, pv, dHSx, + nullptr, dtau, isforce, isstress, ra, + factor_force, factor_stress, stress_func); } diff --git a/source/source_lcao/rho_tau_lcao.cpp b/source/source_lcao/rho_tau_lcao.cpp index 172864ae6c3..a448165abb5 100644 --- a/source/source_lcao/rho_tau_lcao.cpp +++ b/source/source_lcao/rho_tau_lcao.cpp @@ -25,10 +25,10 @@ void LCAO_domain::dm2rho(std::vector*> &dmr, if(!skip_normalize)chr->renormalize_rho(nelec, omega); // should be moved somewhere else, mohan 20251024 - if (XC_Functional::get_ked_flag()) - { - dm2tau(dmr, nspin, chr); - } + if (XC_Functional::get_ked_flag()) + { + dm2tau(dmr, nspin, chr); + } // symmetrize of charge density should be here, mohan 20251023 @@ -44,11 +44,11 @@ void LCAO_domain::dm2tau(std::vector*> &dmr, ModuleBase::TITLE("LCAO_domain", "dm2tau"); ModuleBase::timer::start("LCAO_domain", "dm2tau"); - for (int is = 0; is < nspin; is++) - { - ModuleBase::GlobalFunc::ZEROS(chr->kin_r[is], chr->nrxx); - } - ModuleGint::cal_gint_tau(dmr, nspin, chr->kin_r); + for (int is = 0; is < nspin; is++) + { + ModuleBase::GlobalFunc::ZEROS(chr->kin_r[is], chr->nrxx); + } + ModuleGint::cal_gint_tau(dmr, nspin, chr->kin_r); ModuleBase::timer::end("LCAO_domain", "dm2tau"); } diff --git a/source/source_lcao/rho_tau_lcao.h b/source/source_lcao/rho_tau_lcao.h index 0759314bae3..174e8ed9784 100644 --- a/source/source_lcao/rho_tau_lcao.h +++ b/source/source_lcao/rho_tau_lcao.h @@ -7,16 +7,16 @@ // generate charge density from different basis or methods namespace LCAO_domain { - void dm2rho(std::vector*> &dmr, - const int nspin, - Charge* chr, - const double nelec, - const double omega, - const bool skip_normalize); + void dm2rho(std::vector*> &dmr, + const int nspin, + Charge* chr, + const double nelec, + const double omega, + const bool skip_normalize); - void dm2tau(std::vector*> &dmr, - const int nspin, - Charge* chr); + void dm2tau(std::vector*> &dmr, + const int nspin, + Charge* chr); } #endif diff --git a/source/source_lcao/setup_deepks.h b/source/source_lcao/setup_deepks.h index f9ac688fe39..1948aea0443 100644 --- a/source/source_lcao/setup_deepks.h +++ b/source/source_lcao/setup_deepks.h @@ -32,30 +32,30 @@ class Setup_DeePKS std::string dpks_out_type; - void before_runner( - const UnitCell &ucell, // unitcell - const int nks, // k points + void before_runner( + const UnitCell &ucell, // unitcell + const int nks, // k points const LCAO_Orbitals &orb, // orbital info - Parallel_Orbitals &pv, // parallel orbitals - const Input_para &inp); + Parallel_Orbitals &pv, // parallel orbitals + const Input_para &inp); void build_overlap( - const UnitCell &ucell, - const LCAO_Orbitals &orb, - const Parallel_Orbitals &pv, - const Grid_Driver &gd, + const UnitCell &ucell, + const LCAO_Orbitals &orb, + const Parallel_Orbitals &pv, + const Grid_Driver &gd, TwoCenterIntegrator &overlap_orb_alpha, - const Input_para &inp); + const Input_para &inp); void delta_e( - const UnitCell& ucell, + const UnitCell& ucell, const K_Vectors &kv, - const LCAO_Orbitals& orb, - const Parallel_Orbitals &pv, // parallel orbitals - const Grid_Driver &gd, - const std::vector>& dm_vec, + const LCAO_Orbitals& orb, + const Parallel_Orbitals &pv, // parallel orbitals + const Grid_Driver &gd, + const std::vector>& dm_vec, elecstate::fenergy &f_en, - const Input_para &inp); + const Input_para &inp); }; @@ -66,17 +66,17 @@ namespace DeePKS_domain { void write_forces( - const ModuleBase::matrix &fcs, - const ModuleBase::matrix &fvnl_dalpha, - const std::string &dpks_out_type, - const Input_para &inp); + const ModuleBase::matrix &fcs, + const ModuleBase::matrix &fvnl_dalpha, + const std::string &dpks_out_type, + const Input_para &inp); void write_stress( - const ModuleBase::matrix &scs, - const ModuleBase::matrix &svnl_dalpha, - const double &omega, - const std::string &dpks_out_type, - const Input_para &inp); + const ModuleBase::matrix &scs, + const ModuleBase::matrix &svnl_dalpha, + const double &omega, + const std::string &dpks_out_type, + const Input_para &inp); } // namespace DeePKS_domain diff --git a/source/source_lcao/setup_exx.cpp b/source/source_lcao/setup_exx.cpp index 0285c786a9c..c1371d33b96 100644 --- a/source/source_lcao/setup_exx.cpp +++ b/source/source_lcao/setup_exx.cpp @@ -42,12 +42,12 @@ void Exx_NAO::init(const UnitCell& ucell, Exx_Info& exx_info) template void Exx_NAO::before_runner( - UnitCell& ucell, // unitcell - K_Vectors &kv, // k points + UnitCell& ucell, // unitcell + K_Vectors &kv, // k points const LCAO_Orbitals &orb, // orbital info const Parallel_Orbitals &pv, // parallel orbitals - const Input_para& inp, - Exx_Info& exx_info) + const Input_para& inp, + Exx_Info& exx_info) { #ifdef __EXX if (inp.calculation == "scf" || inp.calculation == "relax" || inp.calculation == "cell-relax" @@ -94,13 +94,13 @@ void Exx_NAO::before_runner( template void Exx_NAO::before_scf( - const UnitCell &ucell, // unitcell - const K_Vectors &kv, - const LCAO_Orbitals &orb, // orbital info - Charge_Mixing* p_chgmix, - const int istep, - const Input_para& inp, - Exx_Info& exx_info) + const UnitCell &ucell, // unitcell + const K_Vectors &kv, + const LCAO_Orbitals &orb, // orbital info + Charge_Mixing* p_chgmix, + const int istep, + const Input_para& inp, + Exx_Info& exx_info) { #ifdef __EXX if (inp.calculation != "nscf") @@ -113,11 +113,11 @@ void Exx_NAO::before_scf( { this->exc->exx_beforescf(istep, kv, *p_chgmix, ucell, orb); } - } - else - { - // do nothing - } + } + else + { + // do nothing + } #endif } diff --git a/source/source_lcao/setup_exx.h b/source/source_lcao/setup_exx.h index c0d58d55f69..11f1fb52d96 100644 --- a/source/source_lcao/setup_exx.h +++ b/source/source_lcao/setup_exx.h @@ -31,22 +31,22 @@ class Exx_NAO void init(const UnitCell& ucell, Exx_Info& exx_info); - void before_runner( - UnitCell& ucell, // unitcell - K_Vectors &kv, // k points + void before_runner( + UnitCell& ucell, // unitcell + K_Vectors &kv, // k points const LCAO_Orbitals &orb, // orbital info - const Parallel_Orbitals &pv, // parallel orbitals - const Input_para& inp, - Exx_Info& exx_info); - - void before_scf( - const UnitCell &ucell, // unitcell - const K_Vectors &kv, - const LCAO_Orbitals &orb, // orbital info - Charge_Mixing* p_chgmix, - const int istep, - const Input_para& inp, - Exx_Info& exx_info); + const Parallel_Orbitals &pv, // parallel orbitals + const Input_para& inp, + Exx_Info& exx_info); + + void before_scf( + const UnitCell &ucell, // unitcell + const K_Vectors &kv, + const LCAO_Orbitals &orb, // orbital info + Charge_Mixing* p_chgmix, + const int istep, + const Input_para& inp, + Exx_Info& exx_info); }; diff --git a/source/source_md/fire.cpp b/source/source_md/fire.cpp index b447d50699c..cb4611c6e9c 100644 --- a/source/source_md/fire.cpp +++ b/source/source_md/fire.cpp @@ -88,8 +88,8 @@ void FIRE::print_md(std::ofstream& ofs, const bool& cal_stress) const double max_force = max * ModuleBase::Hartree_to_eV * ModuleBase::ANGSTROM_AU; - ofs << " LARGEST FORCE (eV/A) : " << max_force << std::endl; - std::cout << " LARGEST FORCE (eV/A) : " << max_force << std::endl; + ofs << " LARGEST FORCE (eV/A) : " << max_force << std::endl; + std::cout << " LARGEST FORCE (eV/A) : " << max_force << std::endl; return; } diff --git a/source/source_psi/psi_init_file.cpp b/source/source_psi/psi_init_file.cpp index 40478b5ffef..29a8619e30b 100644 --- a/source/source_psi/psi_init_file.cpp +++ b/source/source_psi/psi_init_file.cpp @@ -57,13 +57,13 @@ void psi_init_file::init_psig(T* psig, const int& ik) const int istep = -1; std::string fn = ModuleIO::filename_output(this->global_readin_dir_,"wf","pw", - ik,this->ik2iktot_,this->nspin_,nkstot, - out_type,out_app_flag,gamma_only,istep); + ik,this->ik2iktot_,this->nspin_,nkstot, + out_type,out_app_flag,gamma_only,istep); ModuleIO::read_wfc_pw(fn, this->pw_wfc_, - this->rank_in_pool_, this->nproc_in_pool_, - this->nbands_start_, this->npol_, - ik, ik_tot, nkstot, wfcatom); + this->rank_in_pool_, this->nproc_in_pool_, + this->nbands_start_, this->npol_, + ik, ik_tot, nkstot, wfcatom); assert(this->nbands_start_ <= wfcatom.nr); for (int ib = 0; ib < this->nbands_start_; ib++) diff --git a/source/source_pw/module_ofdft/kedf_manager.cpp b/source/source_pw/module_ofdft/kedf_manager.cpp index 96a8be470e6..953f406698b 100644 --- a/source/source_pw/module_ofdft/kedf_manager.cpp +++ b/source/source_pw/module_ofdft/kedf_manager.cpp @@ -292,7 +292,7 @@ double KEDF_Manager::get_energy() const { GlobalV::ofs_running << " WARNING: ML >= TF" << std::endl; GlobalV::ofs_running << " ML Term = " << this->ml_->ml_energy - << " Ry, TF Term = " << this->tf_->tf_energy << " Ry." << std::endl; + << " Ry, TF Term = " << this->tf_->tf_energy << " Ry." << std::endl; } } #endif diff --git a/source/source_pw/module_ofdft/kedf_ml.cpp b/source/source_pw/module_ofdft/kedf_ml.cpp index 4c439b8f30f..4fd92a929e8 100644 --- a/source/source_pw/module_ofdft/kedf_ml.cpp +++ b/source/source_pw/module_ofdft/kedf_ml.cpp @@ -109,7 +109,7 @@ void KEDF_ML::set_para( } ofs_running << " feg_net_F = " << this->feg_net_F - << " (Pauli energy enhancement factor in free electron gas)" << std::endl << std::endl; + << " (Pauli energy enhancement factor in free electron gas)" << std::endl << std::endl; } } else @@ -129,8 +129,8 @@ void KEDF_ML::set_para( this->cal_tool->set_para(nx, nelec, tf_weight, vw_weight, chi_p, chi_q, chi_xi, chi_pnl, chi_qnl, nkernel, kernel_type, - kernel_scaling, yukawa_alpha, kernel_file, - this->dV * pw_rho->nxyz, pw_rho, ofs_running); + kernel_scaling, yukawa_alpha, kernel_file, + this->dV * pw_rho->nxyz, pw_rho, ofs_running); } else { diff --git a/source/source_pw/module_ofdft/kedf_ml.h b/source/source_pw/module_ofdft/kedf_ml.h index 9ac90a2bf64..ea3f7d4383e 100644 --- a/source/source_pw/module_ofdft/kedf_ml.h +++ b/source/source_pw/module_ofdft/kedf_ml.h @@ -13,7 +13,7 @@ class KEDF_ML : public ML_Base KEDF_ML() { this->energy_prefactor = 3. /10. * std::pow(3*std::pow(M_PI, 2.0), 2.0/3.0) * 2; - // 10/3*(3*pi^2)^{2/3}, multiply by 2 to convert unit from Hartree to Ry, finally in Ry*Bohr^(-2) + // 10/3*(3*pi^2)^{2/3}, multiply by 2 to convert unit from Hartree to Ry, finally in Ry*Bohr^(-2) this->energy_exponent = 5. / 3.; } diff --git a/source/source_pw/module_ofdft/ml_base.cpp b/source/source_pw/module_ofdft/ml_base.cpp index 2e04cb6231d..e209fda7800 100644 --- a/source/source_pw/module_ofdft/ml_base.cpp +++ b/source/source_pw/module_ofdft/ml_base.cpp @@ -27,7 +27,7 @@ void ML_Base::set_device(const std::string& device_inpt, std::ostream& ofs_runni } else { - std::cout << "--------------- Warning: GPU is unavailable ---------------" << std::endl; + std::cout << "--------------- Warning: GPU is unavailable ---------------" << std::endl; ofs_running << "--------------- Warning: GPU is unavailable ---------------" << std::endl; ofs_running << "------------------- Running Neural Network on CPU -------------------" << std::endl; @@ -264,9 +264,9 @@ void ML_Base::get_potential_(const double * const * prho, const ModulePW::PW_Bas pauli_potential[ir] += factor * (this->energy_exponent * this->enhancement_cpu_ptr[ir] - + this->pot_gamma_term(ir) + this->pot_p_term_1(ir) + this->pot_q_term_1(ir) + + this->pot_gamma_term(ir) + this->pot_p_term_1(ir) + this->pot_q_term_1(ir) + this->pot_xi_term_1(ir) + this->pot_tanhxi_term_1(ir) - + this->pot_tanhp_term_1(ir) + this->pot_tanhq_term_1(ir)); + + this->pot_tanhp_term_1(ir) + this->pot_tanhq_term_1(ir)); rpotential(0, ir) += pauli_potential[ir]; } diff --git a/source/source_pw/module_ofdft/of_print_info.cpp b/source/source_pw/module_ofdft/of_print_info.cpp index 1f3a14b7910..53a3addf769 100644 --- a/source/source_pw/module_ofdft/of_print_info.cpp +++ b/source/source_pw/module_ofdft/of_print_info.cpp @@ -8,13 +8,13 @@ * and write the components of the total energy into running_log. */ void OFDFT::print_info(const int iter, - ModuleBase::TimePoint &iter_time, - const double &energy_current, - const double &energy_last, - const double &normdLdphi, - const elecstate::ElecState *pelec, - KEDF_Manager *kedf_manager, - const bool conv_esolver) + ModuleBase::TimePoint &iter_time, + const double &energy_current, + const double &energy_last, + const double &normdLdphi, + const elecstate::ElecState *pelec, + KEDF_Manager *kedf_manager, + const bool conv_esolver) { if (iter == 0) { @@ -47,11 +47,11 @@ void OFDFT::print_info(const int iter, std::vector titles; std::vector energies_Ry; std::vector energies_eV; - if ((PARAM.inp.out_band[0] > 0 && - ((iter + 1) % PARAM.inp.out_band[0] == 0 || - conv_esolver || - iter == PARAM.inp.scf_nmax)) || - PARAM.inp.init_chg == "file") + if ((PARAM.inp.out_band[0] > 0 && + ((iter + 1) % PARAM.inp.out_band[0] == 0 || + conv_esolver || + iter == PARAM.inp.scf_nmax)) || + PARAM.inp.init_chg == "file") { titles.push_back("E_Total"); energies_Ry.push_back(pelec->f_en.etot); diff --git a/source/source_pw/module_ofdft/of_print_info.h b/source/source_pw/module_ofdft/of_print_info.h index dd45e6bbc6d..eaced920260 100644 --- a/source/source_pw/module_ofdft/of_print_info.h +++ b/source/source_pw/module_ofdft/of_print_info.h @@ -11,13 +11,13 @@ namespace OFDFT { void print_info(const int iter, - ModuleBase::TimePoint &iter_time, - const double &energy_current, - const double &energy_last, - const double &normdLdphi, - const elecstate::ElecState *pelec, - KEDF_Manager *kedf_manager, - const bool conv_esolver); + ModuleBase::TimePoint &iter_time, + const double &energy_current, + const double &energy_last, + const double &normdLdphi, + const elecstate::ElecState *pelec, + KEDF_Manager *kedf_manager, + const bool conv_esolver); } diff --git a/source/source_pw/module_proj/onsite_proj_tools_stress.cpp b/source/source_pw/module_proj/onsite_proj_tools_stress.cpp index db936f1c4d4..6b1dcf67693 100644 --- a/source/source_pw/module_proj/onsite_proj_tools_stress.cpp +++ b/source/source_pw/module_proj/onsite_proj_tools_stress.cpp @@ -30,15 +30,15 @@ double Onsite_Proj_tools::cal_stress_dftu(int ik, #if defined(__CUDA) || defined(__ROCM) if (this->device == base_device::GpuDevice) { - // orb_corr_tmp + // orb_corr_tmp resmem_int_op()(orb_corr_tmp, this->ucell_->ntype); syncmem_int_h2d_op()(orb_corr_tmp, orb_corr, this->ucell_->ntype); - // pot_onsite_tmp + // pot_onsite_tmp resmem_complex_op()(pot_onsite_tmp, size_pot_onsite); syncmem_complex_h2d_op()(pot_onsite_tmp, pot_onsite, size_pot_onsite); - // transfer data from from host to device + // transfer data from from host to device syncmem_var_h2d_op()(d_wg, h_wg, this->nbands * (ik+1)); // Allocate device memory for stress @@ -99,7 +99,7 @@ double Onsite_Proj_tools::cal_stress_dftu(int ik, template double Onsite_Proj_tools::cal_stress_dspin(int ik, int npm, - const ModuleBase::Vector3* lambda, + const ModuleBase::Vector3* lambda, const FPTYPE* h_wg) { double stress_out = 0.0; diff --git a/source/source_pw/module_pwdft/force_pw_onsite.cpp b/source/source_pw/module_pwdft/force_pw_onsite.cpp index 4426581eeb8..859eed2a780 100644 --- a/source/source_pw/module_pwdft/force_pw_onsite.cpp +++ b/source/source_pw/module_pwdft/force_pw_onsite.cpp @@ -12,9 +12,9 @@ template void Forces::cal_force_onsite(ModuleBase::matrix& force_onsite, const ModuleBase::matrix& wg, const ModulePW::PW_Basis_K* wfc_basis, - const UnitCell& ucell_in, - const Plus_U_Base& dftu, - const psi::Psi , Device>* psi_in) + const UnitCell& ucell_in, + const Plus_U_Base& dftu, + const psi::Psi , Device>* psi_in) { ModuleBase::TITLE("Forces", "cal_force_onsite"); if(psi_in == nullptr || wfc_basis == nullptr) diff --git a/source/source_pw/module_pwdft/force_pw_scc.cpp b/source/source_pw/module_pwdft/force_pw_scc.cpp index dbfce6945a3..32b6f7deeec 100644 --- a/source/source_pw/module_pwdft/force_pw_scc.cpp +++ b/source/source_pw/module_pwdft/force_pw_scc.cpp @@ -68,72 +68,72 @@ void Forces::cal_force_scc(ModuleBase::matrix& forcescc, } // work space - std::vector rhocgnt(rho_basis->ngg); + std::vector rhocgnt(rho_basis->ngg); ModuleBase::GlobalFunc::ZEROS(rhocgnt.data(), rho_basis->ngg); rho_basis->real2recip(psic.data(), psic.data()); int igg0 = 0; const int ig0 = rho_basis->ig_gge0; - if (rho_basis->gg_uniq[0] < 1.0e-8) - { - igg0 = 1; - } + if (rho_basis->gg_uniq[0] < 1.0e-8) + { + igg0 = 1; + } double fact = 2.0; - for (int nt = 0; nt < ucell_in.ntype; nt++) - { - // Here we compute the G.ne.0 term - const int mesh = ucell_in.atoms[nt].ncpp.msh; - this->deriv_drhoc_scc(numeric, - mesh, - ucell_in.atoms[nt].ncpp.r.data(), - ucell_in.atoms[nt].ncpp.rab.data(), - ucell_in.atoms[nt].ncpp.rho_at.data(), - rhocgnt.data(), - rho_basis, - ucell_in); - int iat = 0; - for (int it = 0; it < ucell_in.ntype; it++) { - for (int ia = 0; ia < ucell_in.atoms[it].na; ia++) { - if (nt == it) { - const ModuleBase::Vector3 pos - = ucell_in.atoms[it].tau[ia]; - double &force0 = forcescc(iat, 0), - &force1 = forcescc(iat, 1), - &force2 = forcescc(iat, 2); + for (int nt = 0; nt < ucell_in.ntype; nt++) + { + // Here we compute the G.ne.0 term + const int mesh = ucell_in.atoms[nt].ncpp.msh; + this->deriv_drhoc_scc(numeric, + mesh, + ucell_in.atoms[nt].ncpp.r.data(), + ucell_in.atoms[nt].ncpp.rab.data(), + ucell_in.atoms[nt].ncpp.rho_at.data(), + rhocgnt.data(), + rho_basis, + ucell_in); + int iat = 0; + for (int it = 0; it < ucell_in.ntype; it++) { + for (int ia = 0; ia < ucell_in.atoms[it].na; ia++) { + if (nt == it) { + const ModuleBase::Vector3 pos + = ucell_in.atoms[it].tau[ia]; + double &force0 = forcescc(iat, 0), + &force1 = forcescc(iat, 1), + &force2 = forcescc(iat, 2); #ifdef _OPENMP #pragma omp parallel for reduction(+ : force0) reduction(+ : force1) reduction(+ : force2) #endif - for (int ig = 0; ig < rho_basis->npw; ++ig) { - if (ig == ig0) { - continue; - } - const ModuleBase::Vector3 gv - = rho_basis->gcar[ig]; - const double rhocgntigg - = rhocgnt[rho_basis->ig2igg[ig]]; - const double arg = ModuleBase::TWO_PI * (gv * pos); - double sinp = 0.0, cosp = 0.0; - ModuleBase::libm::sincos(arg, &sinp, &cosp); - const std::complex cpm - = std::complex(sinp, cosp) * conj(psic[ig]); - - force0 += fact * rhocgntigg * ucell_in.tpiba - * gv.x * cpm.real(); - force1 += fact * rhocgntigg * ucell_in.tpiba - * gv.y * cpm.real(); - force2 += fact * rhocgntigg * ucell_in.tpiba - * gv.z * cpm.real(); - } - } - iat++; - } - } - } - - - Parallel_Reduce::reduce_pool(forcescc.c, forcescc.nr * forcescc.nc); + for (int ig = 0; ig < rho_basis->npw; ++ig) { + if (ig == ig0) { + continue; + } + const ModuleBase::Vector3 gv + = rho_basis->gcar[ig]; + const double rhocgntigg + = rhocgnt[rho_basis->ig2igg[ig]]; + const double arg = ModuleBase::TWO_PI * (gv * pos); + double sinp = 0.0, cosp = 0.0; + ModuleBase::libm::sincos(arg, &sinp, &cosp); + const std::complex cpm + = std::complex(sinp, cosp) * conj(psic[ig]); + + force0 += fact * rhocgntigg * ucell_in.tpiba + * gv.x * cpm.real(); + force1 += fact * rhocgntigg * ucell_in.tpiba + * gv.y * cpm.real(); + force2 += fact * rhocgntigg * ucell_in.tpiba + * gv.z * cpm.real(); + } + } + iat++; + } + } + } + + + Parallel_Reduce::reduce_pool(forcescc.c, forcescc.nr * forcescc.nc); ModuleBase::timer::end("Forces", "cal_force_scc"); return; @@ -156,7 +156,7 @@ void Forces::deriv_drhoc_scc(const bool& numeric, /// the modulus of g for a given shell /// the fourier transform /// auxiliary memory for integration - std::vector gx_arr(rho_basis->ngg); + std::vector gx_arr(rho_basis->ngg); double* gx_arr_d = nullptr; /// counter on radial mesh points /// counter on g shells @@ -165,12 +165,12 @@ void Forces::deriv_drhoc_scc(const bool& numeric, /// /// G=0 term /// - if (rho_basis->gg_uniq[0] < 1.0e-8) - { - drhocg[0] = 0.0; + if (rho_basis->gg_uniq[0] < 1.0e-8) + { + drhocg[0] = 0.0; igl0 = 1; - } else - { + } else + { igl0 = 0; } @@ -182,19 +182,19 @@ void Forces::deriv_drhoc_scc(const bool& numeric, #ifdef _OPENMP #pragma omp parallel for #endif - for (int igl = igl0; igl < rho_basis->ngg; igl++) - { - gx_arr[igl] = sqrt(rho_basis->gg_uniq[igl]) * ucell_in.tpiba; - } + for (int igl = igl0; igl < rho_basis->ngg; igl++) + { + gx_arr[igl] = sqrt(rho_basis->gg_uniq[igl]) * ucell_in.tpiba; + } - double *r_d = nullptr; + double *r_d = nullptr; double *rhoc_d = nullptr; double *rab_d = nullptr; double *aux_d = nullptr; double *drhocg_d = nullptr; - if (this->device == base_device::GpuDevice) - { - resmem_var_op()(r_d, mesh); + if (this->device == base_device::GpuDevice) + { + resmem_var_op()(r_d, mesh); resmem_var_op()(rhoc_d, mesh); resmem_var_op()(rab_d, mesh); @@ -210,43 +210,43 @@ void Forces::deriv_drhoc_scc(const bool& numeric, syncmem_var_h2d_op()(rhoc_d, rhoc, mesh); } - if(this->device == base_device::GpuDevice) - { - hamilt::cal_stress_drhoc_aux_op()( - r_d, - rhoc_d, - gx_arr_d+igl0, - rab_d, - drhocg_d+igl0, - mesh, - igl0, - rho_basis->ngg-igl0, - ucell_in.omega, - 2); - - syncmem_var_d2h_op()(drhocg+igl0, drhocg_d+igl0, rho_basis->ngg-igl0); - - } - else - { - hamilt::cal_stress_drhoc_aux_op()( - r, - rhoc, - gx_arr.data()+igl0, - rab, - drhocg+igl0, - mesh, - igl0, - rho_basis->ngg-igl0, - ucell_in.omega, - 2); - - } + if(this->device == base_device::GpuDevice) + { + hamilt::cal_stress_drhoc_aux_op()( + r_d, + rhoc_d, + gx_arr_d+igl0, + rab_d, + drhocg_d+igl0, + mesh, + igl0, + rho_basis->ngg-igl0, + ucell_in.omega, + 2); + + syncmem_var_d2h_op()(drhocg+igl0, drhocg_d+igl0, rho_basis->ngg-igl0); + + } + else + { + hamilt::cal_stress_drhoc_aux_op()( + r, + rhoc, + gx_arr.data()+igl0, + rab, + drhocg+igl0, + mesh, + igl0, + rho_basis->ngg-igl0, + ucell_in.omega, + 2); + + } delmem_var_op()(r_d); delmem_var_op()(rhoc_d); delmem_var_op()(rab_d); - delmem_var_op()(aux_d); + delmem_var_op()(aux_d); delmem_var_op()(gx_arr_d); delmem_var_op()(drhocg_d); return; diff --git a/source/source_pw/module_pwdft/kernels/cuda/stress_op.cu b/source/source_pw/module_pwdft/kernels/cuda/stress_op.cu index 9e29a364b6e..3edc438302a 100644 --- a/source/source_pw/module_pwdft/kernels/cuda/stress_op.cu +++ b/source/source_pw/module_pwdft/kernels/cuda/stress_op.cu @@ -344,7 +344,7 @@ __global__ void cal_stress_nl( { for (int ii = threadIdx.x; ii < nproj * nproj; ii += blockDim.x) { const int ip1 = ii / nproj; - const int ip2 = ii % nproj; + const int ip2 = ii % nproj; thrust::complex ps_qq = 0; if(ekb_now != 0) { diff --git a/source/source_pw/module_pwdft/kernels/stress_op.cpp b/source/source_pw/module_pwdft/kernels/stress_op.cpp index aff61a53d69..66f45f3672b 100644 --- a/source/source_pw/module_pwdft/kernels/stress_op.cpp +++ b/source/source_pw/module_pwdft/kernels/stress_op.cpp @@ -590,17 +590,17 @@ void Simpson_Integral assert(mesh&1); asum = 0.00; - const size_t end = mesh-2; + const size_t end = mesh-2; for( size_t i=1; i!=end; i+=2 ) { - const double f1 = func[i]*rab[i]; - asum += f1 + f1 + func[i+1]*rab[i+1]; + const double f1 = func[i]*rab[i]; + asum += f1 + f1 + func[i+1]*rab[i+1]; } - const double f1 = func[mesh-2]*rab[mesh-2]; - asum += f1+f1; - asum += asum; - asum += func[0]*rab[0] + func[mesh-1]*rab[mesh-1]; - asum /= 3.0; + const double f1 = func[mesh-2]*rab[mesh-2]; + asum += f1+f1; + asum += asum; + asum += func[0]*rab[0] + func[mesh-1]*rab[mesh-1]; + asum /= 3.0; return; }// end subroutine simpson diff --git a/source/source_pw/module_pwdft/op_pw_proj.cpp b/source/source_pw/module_pwdft/op_pw_proj.cpp index afaadb6eb2c..fd469e7ce53 100644 --- a/source/source_pw/module_pwdft/op_pw_proj.cpp +++ b/source/source_pw/module_pwdft/op_pw_proj.cpp @@ -13,10 +13,10 @@ namespace hamilt { template OnsiteProj>::OnsiteProj(const int* isk_in, - const UnitCell* ucell_in, - Plus_U_Base* p_dftu, - const bool cal_delta_spin, - const bool cal_dftu) + const UnitCell* ucell_in, + Plus_U_Base* p_dftu, + const bool cal_delta_spin, + const bool cal_dftu) { this->classname = "OnsiteProj"; this->cal_type = calculation_type::pw_onsite; @@ -265,13 +265,13 @@ void OnsiteProj>::setup_pw_dftu_indices() const template void OnsiteProj>::cal_ps_dftu( - const int npol, - const int m) const + const int npol, + const int m) const { - if(!this->has_dftu) - { - return; - } + if(!this->has_dftu) + { + return; + } auto* onsite_p = projectors::OnsiteProjector::get_instance(); const std::complex* becp = onsite_p->get_becp(); @@ -309,59 +309,59 @@ void OnsiteProj>::cal_ps_dftu( template<> void OnsiteProj, base_device::DEVICE_CPU>>::add_onsite_proj( - std::complex *hpsi_in, - const int npol, - const int m, - const int npwx) const + std::complex *hpsi_in, + const int npol, + const int m, + const int npwx) const {} template<> void OnsiteProj, base_device::DEVICE_CPU>>::update_becp( - const std::complex *psi_in, - const int npol, - const int m, - const int npwx) const + const std::complex *psi_in, + const int npol, + const int m, + const int npwx) const {} template<> void OnsiteProj, base_device::DEVICE_CPU>>::cal_ps_delta_spin( - const int npol, - const int m) const + const int npol, + const int m) const {} template<> void OnsiteProj, base_device::DEVICE_CPU>>::cal_ps_dftu( - const int npol, - const int m) const + const int npol, + const int m) const {} #if ((defined __CUDA) || (defined __ROCM)) template<> void OnsiteProj, base_device::DEVICE_GPU>>::add_onsite_proj( - std::complex *hpsi_in, - const int npol, - const int m, - const int npwx) const + std::complex *hpsi_in, + const int npol, + const int m, + const int npwx) const {} template<> void OnsiteProj, base_device::DEVICE_GPU>>::update_becp( - const std::complex *psi_in, - const int npol, - const int m, - const int npwx) const + const std::complex *psi_in, + const int npol, + const int m, + const int npwx) const {} template<> void OnsiteProj, base_device::DEVICE_GPU>>::cal_ps_delta_spin( - const int npol, - const int m) const + const int npol, + const int m) const {} template<> void OnsiteProj, base_device::DEVICE_GPU>>::cal_ps_dftu( - const int npol, - const int m) const + const int npol, + const int m) const {} #endif diff --git a/source/source_pw/module_pwdft/op_pw_proj.h b/source/source_pw/module_pwdft/op_pw_proj.h index 4cece482992..9a07a561ac0 100644 --- a/source/source_pw/module_pwdft/op_pw_proj.h +++ b/source/source_pw/module_pwdft/op_pw_proj.h @@ -43,8 +43,8 @@ class OnsiteProj> : public OperatorPW const int npol, const T* tmpsi_in, T* tmhpsi, - const int ngk = 0, - const bool is_first_node = false)const override; + const int ngk = 0, + const bool is_first_node = false)const override; const int *get_isk() const {return this->isk;} const UnitCell *get_ucell() const {return this->ucell;} diff --git a/source/source_pw/module_pwdft/setup_pwrho.cpp b/source/source_pw/module_pwdft/setup_pwrho.cpp index 019b27ed057..2c620861d38 100644 --- a/source/source_pw/module_pwdft/setup_pwrho.cpp +++ b/source/source_pw/module_pwdft/setup_pwrho.cpp @@ -3,14 +3,14 @@ #include "source_base/parallel_comm.h" // use POOL_WORLD void pw::setup_pwrho( - UnitCell& ucell, // unitcell - const bool double_grid, // for USPP + UnitCell& ucell, // unitcell + const bool double_grid, // for USPP bool &pw_rho_flag, // flag for allocation of pw_rho - ModulePW::PW_Basis* &pw_rho, // pw for rhod - ModulePW::PW_Basis* &pw_rhod, // pw for rhod - ModulePW::PW_Basis_Big* &pw_big, // pw for rhod - const std::string &classname, - const Input_para& inp) // input parameters * + ModulePW::PW_Basis* &pw_rho, // pw for rhod + ModulePW::PW_Basis* &pw_rhod, // pw for rhod + ModulePW::PW_Basis_Big* &pw_big, // pw for rhod + const std::string &classname, + const Input_para& inp) // input parameters * { ModuleBase::TITLE("pw", "setup_pwrho"); @@ -131,9 +131,9 @@ void pw::setup_pwrho( void pw::teardown_pwrho(bool &pw_rho_flag, - const bool double_grid, - ModulePW::PW_Basis* &pw_rho, // pw for rhod - ModulePW::PW_Basis* &pw_rhod) // pw for rhod + const bool double_grid, + ModulePW::PW_Basis* &pw_rho, // pw for rhod + ModulePW::PW_Basis* &pw_rhod) // pw for rhod { if (pw_rho_flag == true) { diff --git a/source/source_pw/module_pwdft/setup_pwrho.h b/source/source_pw/module_pwdft/setup_pwrho.h index 7a6ad1bfd33..7a86da4be51 100644 --- a/source/source_pw/module_pwdft/setup_pwrho.h +++ b/source/source_pw/module_pwdft/setup_pwrho.h @@ -9,20 +9,20 @@ namespace pw { void setup_pwrho( - UnitCell& ucell, // unitcell + UnitCell& ucell, // unitcell const bool double_grid, // for USPP bool &pw_rho_flag, // flag for allocation of pw_rho - ModulePW::PW_Basis* &pw_rho, // pw for rhod - ModulePW::PW_Basis* &pw_rhod, // pw for rhod - ModulePW::PW_Basis_Big* &pw_big, // pw for rhod - const std::string &classname, - const Input_para& inp); // input parameters * + ModulePW::PW_Basis* &pw_rho, // pw for rhod + ModulePW::PW_Basis* &pw_rhod, // pw for rhod + ModulePW::PW_Basis_Big* &pw_big, // pw for rhod + const std::string &classname, + const Input_para& inp); // input parameters * void teardown_pwrho(bool &pw_rho_flag, - const bool double_grid, - ModulePW::PW_Basis* &pw_rho, // pw for rhod - ModulePW::PW_Basis* &pw_rhod); // pw for rhod + const bool double_grid, + ModulePW::PW_Basis* &pw_rho, // pw for rhod + ModulePW::PW_Basis* &pw_rhod); // pw for rhod } diff --git a/source/source_pw/module_pwdft/setup_pwwfc.cpp b/source/source_pw/module_pwdft/setup_pwwfc.cpp index d4c3a683090..7c66e8fe199 100644 --- a/source/source_pw/module_pwdft/setup_pwwfc.cpp +++ b/source/source_pw/module_pwdft/setup_pwwfc.cpp @@ -6,14 +6,14 @@ void pw::teardown_pwwfc(ModulePW::PW_Basis_K* &pw_wfc) { - delete pw_wfc; + delete pw_wfc; } void pw::setup_pwwfc(const Input_para& inp, - const UnitCell& ucell, - const ModulePW::PW_Basis& pw_rho, - K_Vectors& kv, - ModulePW::PW_Basis_K* &pw_wfc) + const UnitCell& ucell, + const ModulePW::PW_Basis& pw_rho, + K_Vectors& kv, + ModulePW::PW_Basis_K* &pw_wfc) { ModuleBase::TITLE("pw", "pw_setup"); diff --git a/source/source_pw/module_pwdft/setup_pwwfc.h b/source/source_pw/module_pwdft/setup_pwwfc.h index d52c0426e0d..b67eb6ceff3 100644 --- a/source/source_pw/module_pwdft/setup_pwwfc.h +++ b/source/source_pw/module_pwdft/setup_pwwfc.h @@ -14,10 +14,10 @@ namespace pw void teardown_pwwfc(ModulePW::PW_Basis_K* &pw_wfc); void setup_pwwfc(const Input_para& inp, - const UnitCell& ucell, - const ModulePW::PW_Basis& pw_rho, - K_Vectors& kv, - ModulePW::PW_Basis_K* &pw_wfc); + const UnitCell& ucell, + const ModulePW::PW_Basis& pw_rho, + K_Vectors& kv, + ModulePW::PW_Basis_K* &pw_wfc); } diff --git a/source/source_pw/module_pwdft/stress_ewa.cpp b/source/source_pw/module_pwdft/stress_ewa.cpp index 8188ccfc8da..8134da9d4c2 100644 --- a/source/source_pw/module_pwdft/stress_ewa.cpp +++ b/source/source_pw/module_pwdft/stress_ewa.cpp @@ -13,101 +13,101 @@ //calcualte the Ewald stress term in PW and LCAO template void Stress_Func::stress_ewa(const UnitCell& ucell, - ModuleBase::matrix& sigma, - ModulePW::PW_Basis* rho_basis, - const bool is_pw) + ModuleBase::matrix& sigma, + ModulePW::PW_Basis* rho_basis, + const bool is_pw) { ModuleBase::TITLE("Stress","stress_ewa"); ModuleBase::timer::start("Stress","stress_ewa"); FPTYPE charge=0; for(int it=0; it < ucell.ntype; it++) - { - charge = charge + ucell.atoms[it].ncpp.zv * ucell.atoms[it].na; - } + { + charge = charge + ucell.atoms[it].ncpp.zv * ucell.atoms[it].na; + } //choose alpha in order to have convergence in the sum over G //upperbound is a safe upper bound for the error ON THE ENERGY FPTYPE alpha=2.9; FPTYPE upperbound=0.0; - do{ - alpha-=0.1; - if(alpha==0.0) - { - ModuleBase::WARNING_QUIT("stres_ew", "optimal alpha not found"); - } - upperbound =ModuleBase::e2 * pow(charge,2) * + do{ + alpha-=0.1; + if(alpha==0.0) + { + ModuleBase::WARNING_QUIT("stres_ew", "optimal alpha not found"); + } + upperbound =ModuleBase::e2 * pow(charge,2) * sqrt( 2 * alpha / (ModuleBase::TWO_PI)) * erfc(sqrt(ucell.tpiba2 * rho_basis->ggecut / 4.0 / alpha)); - } + } while(upperbound>1e-7); //G-space sum here //Determine if this processor contains G=0 and set the constant term FPTYPE sdewald=0.0; - const int ig0 = rho_basis->ig_gge0; + const int ig0 = rho_basis->ig_gge0; if( ig0 >= 0) - { + { sdewald = (ModuleBase::TWO_PI) * ModuleBase::e2 / 4.0 / alpha * pow(charge/ucell.omega,2); } else - { + { sdewald = 0.0; } //sdewald is the diagonal term FPTYPE fact=1.0; - if (PARAM.globalv.gamma_only_pw && is_pw) - { - fact=2.0; - } + if (PARAM.globalv.gamma_only_pw && is_pw) + { + fact=2.0; + } // else fact=1.0; #pragma omp parallel { - ModuleBase::matrix local_sigma(3, 3); - FPTYPE local_sdewald = 0; + ModuleBase::matrix local_sigma(3, 3); + FPTYPE local_sdewald = 0; FPTYPE g2,g2a; FPTYPE arg; std::complex rhostar; FPTYPE sewald; - #pragma omp for + #pragma omp for for(int ig = 0; ig < rho_basis->npw; ig++) - { - if(ig == ig0) - { - continue; - } - g2 = rho_basis->gg[ig]* ucell.tpiba2; - g2a = g2 /4.0/alpha; - rhostar=std::complex(0.0,0.0); - - for(int it=0; it < ucell.ntype; it++) - { - for(int i=0; igcar[ig] * ucell.atoms[it].tau[i]) * (ModuleBase::TWO_PI); - FPTYPE sinp, cosp; + { + if(ig == ig0) + { + continue; + } + g2 = rho_basis->gg[ig]* ucell.tpiba2; + g2a = g2 /4.0/alpha; + rhostar=std::complex(0.0,0.0); + + for(int it=0; it < ucell.ntype; it++) + { + for(int i=0; igcar[ig] * ucell.atoms[it].tau[i]) * (ModuleBase::TWO_PI); + FPTYPE sinp, cosp; ModuleBase::libm::sincos(arg, &sinp, &cosp); - rhostar = rhostar + std::complex(ucell.atoms[it].ncpp.zv * cosp,ucell.atoms[it].ncpp.zv * sinp); - } - } - rhostar /= ucell.omega; - sewald = fact* (ModuleBase::TWO_PI) * ModuleBase::e2 * ModuleBase::libm::exp(-g2a) / g2 * pow(std::abs(rhostar),2); - local_sdewald -= sewald; - for(int l=0;l<3;l++) - { - for(int m=0;mgcar[ig][l] * rho_basis->gcar[ig][m] / g2 * (g2a + 1); - } - } - } + rhostar = rhostar + std::complex(ucell.atoms[it].ncpp.zv * cosp,ucell.atoms[it].ncpp.zv * sinp); + } + } + rhostar /= ucell.omega; + sewald = fact* (ModuleBase::TWO_PI) * ModuleBase::e2 * ModuleBase::libm::exp(-g2a) / g2 * pow(std::abs(rhostar),2); + local_sdewald -= sewald; + for(int l=0;l<3;l++) + { + for(int m=0;mgcar[ig][l] * rho_basis->gcar[ig][m] / g2 * (g2a + 1); + } + } + } //R-space sum here (only for the processor that contains G=0) int *irr=nullptr; @@ -120,89 +120,89 @@ void Stress_Func::stress_ewa(const UnitCell& ucell, int nrm=0; FPTYPE fac=0.0; - if(ig0 >= 0) - { - FPTYPE sqa = sqrt(alpha); - FPTYPE sq8a_2pi = sqrt(8 * alpha / (ModuleBase::TWO_PI)); - rmax = 4.0/sqa/ucell.lat0; - const int mxr = H_Ewald_pw::estimate_mxr(rmax, ucell.G); - - std::vector> r(mxr); - std::vector r2(mxr); - std::vector irr(mxr); - - #pragma omp for - for(long long ijat = 0; ijat < ucell.nat * ucell.nat; ijat++) - { - int it=0; - int i=0; - int jt=0; - int j=0; - ucell.ijat2iaitjajt(ijat, &i, &it, &j, &jt); - if (ucell.atoms[it].na != 0 && ucell.atoms[jt].na != 0) - { - //calculate tau[na]-tau[nb] - d_tau = ucell.atoms[it].tau[i] - ucell.atoms[jt].tau[j]; - //generates nearest-neighbors shells - H_Ewald_pw::rgen(d_tau, rmax, irr.data(), ucell.latvec, ucell.G, r.data(), r2.data(), mxr, nrm, PARAM.inp.test_energy); - for(int nr=0; nr= 0) + { + FPTYPE sqa = sqrt(alpha); + FPTYPE sq8a_2pi = sqrt(8 * alpha / (ModuleBase::TWO_PI)); + rmax = 4.0/sqa/ucell.lat0; + const int mxr = H_Ewald_pw::estimate_mxr(rmax, ucell.G); + + std::vector> r(mxr); + std::vector r2(mxr); + std::vector irr(mxr); + + #pragma omp for + for(long long ijat = 0; ijat < ucell.nat * ucell.nat; ijat++) + { + int it=0; + int i=0; + int jt=0; + int j=0; + ucell.ijat2iaitjajt(ijat, &i, &it, &j, &jt); + if (ucell.atoms[it].na != 0 && ucell.atoms[jt].na != 0) + { + //calculate tau[na]-tau[nb] + d_tau = ucell.atoms[it].tau[i] - ucell.atoms[jt].tau[j]; + //generates nearest-neighbors shells + H_Ewald_pw::rgen(d_tau, rmax, irr.data(), ucell.latvec, ucell.G, r.data(), r2.data(), mxr, nrm, PARAM.inp.test_energy); + for(int nr=0; nr; diff --git a/source/source_pw/module_pwdft/stress_har.cpp b/source/source_pw/module_pwdft/stress_har.cpp index 4f01c03b503..24d572d3a5e 100644 --- a/source/source_pw/module_pwdft/stress_har.cpp +++ b/source/source_pw/module_pwdft/stress_har.cpp @@ -7,21 +7,21 @@ //calculate the Hartree part in PW or LCAO base template void Stress_Func::stress_har(const UnitCell& ucell, - ModuleBase::matrix& sigma, - ModulePW::PW_Basis* rho_basis, - const bool is_pw, - const Charge* const chr) + ModuleBase::matrix& sigma, + ModulePW::PW_Basis* rho_basis, + const bool is_pw, + const Charge* const chr) { ModuleBase::TITLE("Stress","stress_har"); - ModuleBase::timer::start("Stress","stress_har"); + ModuleBase::timer::start("Stress","stress_har"); assert(rho_basis->nmaxgr>0); - std::complex *aux = new std::complex[rho_basis->nmaxgr]; + std::complex *aux = new std::complex[rho_basis->nmaxgr]; - const int nspin_rho = (PARAM.inp.nspin == 2) ? 2 : 1; + const int nspin_rho = (PARAM.inp.nspin == 2) ? 2 : 1; - // Hartree potential VH(r) from n(r) + // Hartree potential VH(r) from n(r) /* blocking rho_basis->nrxx for data locality. @@ -33,125 +33,125 @@ void Stress_Func::stress_har(const UnitCell& ucell, #ifdef _OPENMP #pragma omp parallel for #endif - for (int irb = 0; irb < rho_basis->nrxx; irb += block_ir) - { - // calculate the actual task length of this block - int ir_end = std::min(irb + block_ir, rho_basis->nrxx); + for (int irb = 0; irb < rho_basis->nrxx; irb += block_ir) + { + // calculate the actual task length of this block + int ir_end = std::min(irb + block_ir, rho_basis->nrxx); - { // is = 0 - for (int ir = irb; ir < ir_end; ++ir) - { // initialize aux - aux[ir] = std::complex( chr->rho[0][ir], 0.0 ); - } - } - for (int is = 1; is < nspin_rho; is++) - { - for (int ir = irb; ir < ir_end; ++ir) - { // accumulate aux - aux[ir] += std::complex( chr->rho[is][ir], 0.0 ); - } - } - } - //============================= - // bring rho (aux) to G space - //============================= - rho_basis->real2recip(aux, aux); + { // is = 0 + for (int ir = irb; ir < ir_end; ++ir) + { // initialize aux + aux[ir] = std::complex( chr->rho[0][ir], 0.0 ); + } + } + for (int is = 1; is < nspin_rho; is++) + { + for (int ir = irb; ir < ir_end; ++ir) + { // accumulate aux + aux[ir] += std::complex( chr->rho[is][ir], 0.0 ); + } + } + } + //============================= + // bring rho (aux) to G space + //============================= + rho_basis->real2recip(aux, aux); - const int ig0 = rho_basis->ig_gge0; + const int ig0 = rho_basis->ig_gge0; #ifndef _OPENMP - ModuleBase::matrix& local_sigma = sigma; + ModuleBase::matrix& local_sigma = sigma; #else #pragma omp parallel - { - ModuleBase::matrix local_sigma(3, 3); + { + ModuleBase::matrix local_sigma(3, 3); #pragma omp for #endif - for (int ig = 0 ; ig < rho_basis->npw ; ++ig) - { - if (ig == ig0) - { - continue; - } - const FPTYPE g2 = rho_basis->gg[ig]; - FPTYPE shart= ( conj( aux[ig] ) * aux[ig] ).real()/(ucell.tpiba2 * g2); - for(int l=0;l<3;l++) - { - for(int m=0;mgcar[ig][l] * rho_basis->gcar[ig][m] / g2; - } - } - } + for (int ig = 0 ; ig < rho_basis->npw ; ++ig) + { + if (ig == ig0) + { + continue; + } + const FPTYPE g2 = rho_basis->gg[ig]; + FPTYPE shart= ( conj( aux[ig] ) * aux[ig] ).real()/(ucell.tpiba2 * g2); + for(int l=0;l<3;l++) + { + for(int m=0;mgcar[ig][l] * rho_basis->gcar[ig][m] / g2; + } + } + } #ifdef _OPENMP #pragma omp critical(stress_har_reduce) - { - for(int l=0;l<3;l++) - { - for(int m=0;m; diff --git a/source/source_pw/module_pwdft/stress_kin.cpp b/source/source_pw/module_pwdft/stress_kin.cpp index ba30034d877..048a7c73f1d 100644 --- a/source/source_pw/module_pwdft/stress_kin.cpp +++ b/source/source_pw/module_pwdft/stress_kin.cpp @@ -14,11 +14,11 @@ void Stress_Func::stress_kin(ModuleBase::matrix& sigma, const psi::Psi , Device>* psi_in) { ModuleBase::TITLE("Stress","stress_kin"); - ModuleBase::timer::start("Stress","stress_kin"); + ModuleBase::timer::start("Stress","stress_kin"); - this->ucell = &ucell_in; + this->ucell = &ucell_in; - hamilt::FS_Kin_tools kin_tool(*this->ucell, p_kv, wfc_basis, wg); + hamilt::FS_Kin_tools kin_tool(*this->ucell, p_kv, wfc_basis, wg); for (int ik = 0; ik < wfc_basis->nks; ++ik) { int nbands_occ = wg.nc; @@ -35,9 +35,9 @@ void Stress_Func::stress_kin(ModuleBase::matrix& sigma, kin_tool.cal_stress_kin(ik, npm, true, &psi_in[0](ik, 0, 0)); } kin_tool.symmetrize_stress(p_symm, sigma); - - ModuleBase::timer::end("Stress","stress_kin"); - return; + + ModuleBase::timer::end("Stress","stress_kin"); + return; } template class Stress_Func; diff --git a/source/source_pw/module_pwdft/stress_mgga.cpp b/source/source_pw/module_pwdft/stress_mgga.cpp index c831e9ced5c..7ecbe1cb914 100644 --- a/source/source_pw/module_pwdft/stress_mgga.cpp +++ b/source/source_pw/module_pwdft/stress_mgga.cpp @@ -19,10 +19,10 @@ void Stress_Func::stress_mgga(const UnitCell& ucell, ModulePW::PW_Basis_K* wfc_basis, const psi::Psi , Device>* psi_in) { - if (PARAM.inp.nspin == 4) - { - ModuleBase::WARNING_QUIT("stress_mgga", "noncollinear stress + mGGA not implemented"); - } + if (PARAM.inp.nspin == 4) + { + ModuleBase::WARNING_QUIT("stress_mgga", "noncollinear stress + mGGA not implemented"); + } ModuleBase::timer::start("Stress", "stress_mgga"); @@ -50,27 +50,27 @@ void Stress_Func::stress_mgga(const UnitCell& ucell, for (int ik = 0; ik < p_kv->get_nks(); ik++) { if (PARAM.inp.nspin == 2) - { - current_spin = p_kv->isk[ik]; - } + { + current_spin = p_kv->isk[ik]; + } const int npw = p_kv->ngk[ik]; for (int ibnd = 0; ibnd < PARAM.inp.nbands; ibnd++) { const FPTYPE w1 = wg(ik, ibnd) / ucell.omega; const std::complex* psi = &psi_in[0](ik, ibnd, 0); - XC_Functional::grad_wfc, Device>(ik, - ucell.tpiba, - wfc_basis, - psi, - gradwfc.data>()); + XC_Functional::grad_wfc, Device>(ik, + ucell.tpiba, + wfc_basis, + psi, + gradwfc.data>()); - cal_stress_mgga_solver( - current_spin, - nrxx, - w1, - gradwfc.data>(), - crosstaus.data()); + cal_stress_mgga_solver( + current_spin, + nrxx, + w1, + gradwfc.data>(), + crosstaus.data()); } // band loop // delete[] psi; } // k loop @@ -105,11 +105,11 @@ void Stress_Func::stress_mgga(const UnitCell& ucell, for (int iy = 0; iy < 3; iy++) { FPTYPE delta = 0.0; - if (ix == iy) - { - delta = 1.0; - } - for (int ir = 0; ir < nrxx; ir++) + if (ix == iy) + { + delta = 1.0; + } + for (int ir = 0; ir < nrxx; ir++) { FPTYPE x = v_ofk(is, ir) * (chr->kin_r[is][ir] * delta diff --git a/source/source_pw/module_pwdft/stress_nl.cpp b/source/source_pw/module_pwdft/stress_nl.cpp index 7b9b84925cb..543390582bc 100644 --- a/source/source_pw/module_pwdft/stress_nl.cpp +++ b/source/source_pw/module_pwdft/stress_nl.cpp @@ -107,10 +107,10 @@ void Stress_Func::get_dvnl1(ModuleBase::ComplexMatrix& vkb, Structure_Factor* p_sf, ModulePW::PW_Basis_K* wfc_basis) { - if (PARAM.inp.test_pp) - { - ModuleBase::TITLE("Stress", "get_dvnl1"); - } + if (PARAM.inp.test_pp) + { + ModuleBase::TITLE("Stress", "get_dvnl1"); + } const int npw = wfc_basis->npwk[ik]; const int lmaxkb = nlpp->lmaxkb; @@ -146,25 +146,25 @@ void Stress_Func::get_dvnl1(ModuleBase::ComplexMatrix& vkb, int jkb = 0; for (int it = 0; it < this->ucell->ntype; it++) { - if (PARAM.inp.test_pp > 1) - { - ModuleBase::GlobalFunc::OUT("it", it); - } - // calculate beta in G-space using an interpolation table + if (PARAM.inp.test_pp > 1) + { + ModuleBase::GlobalFunc::OUT("it", it); + } + // calculate beta in G-space using an interpolation table const int nbeta = this->ucell->atoms[it].ncpp.nbeta; const int nh = this->ucell->atoms[it].ncpp.nh; - if (PARAM.inp.test_pp > 1) - { - ModuleBase::GlobalFunc::OUT("nbeta", nbeta); - } + if (PARAM.inp.test_pp > 1) + { + ModuleBase::GlobalFunc::OUT("nbeta", nbeta); + } for (int nb = 0; nb < nbeta; nb++) { - if (PARAM.inp.test_pp > 1) - { - ModuleBase::GlobalFunc::OUT("ib", nb); - } + if (PARAM.inp.test_pp > 1) + { + ModuleBase::GlobalFunc::OUT("ib", nb); + } #ifdef _OPENMP #pragma omp parallel for #endif @@ -233,10 +233,10 @@ void Stress_Func::get_dvnl2(ModuleBase::ComplexMatrix& vkb, Structure_Factor* p_sf, ModulePW::PW_Basis_K* wfc_basis) { - if (PARAM.inp.test_pp) - { - ModuleBase::TITLE("Stress", "get_dvnl2"); - } + if (PARAM.inp.test_pp) + { + ModuleBase::TITLE("Stress", "get_dvnl2"); + } // ModuleBase::timer::start("Stress","get_dvnl2"); const int npw = wfc_basis->npwk[ik]; const int lmaxkb = nlpp->lmaxkb; @@ -271,24 +271,24 @@ void Stress_Func::get_dvnl2(ModuleBase::ComplexMatrix& vkb, for (int it = 0; it < this->ucell->ntype; it++) { if (PARAM.inp.test_pp > 1) - { - ModuleBase::GlobalFunc::OUT("it", it); - } + { + ModuleBase::GlobalFunc::OUT("it", it); + } // calculate beta in G-space using an interpolation table const int nbeta = this->ucell->atoms[it].ncpp.nbeta; const int nh = this->ucell->atoms[it].ncpp.nh; - if (PARAM.inp.test_pp > 1) - { - ModuleBase::GlobalFunc::OUT("nbeta", nbeta); - } + if (PARAM.inp.test_pp > 1) + { + ModuleBase::GlobalFunc::OUT("nbeta", nbeta); + } for (int nb = 0; nb < nbeta; nb++) { - if (PARAM.inp.test_pp > 1) - { - ModuleBase::GlobalFunc::OUT("ib", nb); - } + if (PARAM.inp.test_pp > 1) + { + ModuleBase::GlobalFunc::OUT("ib", nb); + } #ifdef _OPENMP #pragma omp parallel for #endif diff --git a/source/source_pw/module_pwdft/stress_onsite.cpp b/source/source_pw/module_pwdft/stress_onsite.cpp index b8bdef12f98..3412cfee6c2 100644 --- a/source/source_pw/module_pwdft/stress_onsite.cpp +++ b/source/source_pw/module_pwdft/stress_onsite.cpp @@ -106,7 +106,7 @@ void Stress_Func::stress_onsite( sigma_onsite[idx] += dftu_stress; #ifdef __DEBUG - std::cout << " idx=" << idx << " stress=" << sigma_onsite[idx] << std::endl; + std::cout << " idx=" << idx << " stress=" << sigma_onsite[idx] << std::endl; #endif } @@ -155,7 +155,7 @@ void Stress_Func::stress_onsite( // Add to total stress for (int idx = 0; idx < 9; idx++) { - std::cout << " idx=" << idx << " stress=" << sigma_onsite[idx] << std::endl; + std::cout << " idx=" << idx << " stress=" << sigma_onsite[idx] << std::endl; } #endif diff --git a/source/source_pw/module_pwdft/stress_us.cpp b/source/source_pw/module_pwdft/stress_us.cpp index e294640f470..e9bc97d07e2 100644 --- a/source/source_pw/module_pwdft/stress_us.cpp +++ b/source/source_pw/module_pwdft/stress_us.cpp @@ -210,10 +210,10 @@ void Stress_Func::dqvan2(const pseudopot_cell_vnl& nlpp, const ModuleBase::matrix& dylmk0, std::complex* dqg) { - if (PARAM.inp.test_pp) - { - ModuleBase::TITLE("Stress", "dqvan2"); - } + if (PARAM.inp.test_pp) + { + ModuleBase::TITLE("Stress", "dqvan2"); + } // computes the indices which correspond to ih,jh const int nb = nlpp.indv(itype, ih); diff --git a/source/source_pw/module_stodft/sto_dos.cpp b/source/source_pw/module_stodft/sto_dos.cpp index 7d9193d3f98..eb78c6700f3 100644 --- a/source/source_pw/module_stodft/sto_dos.cpp +++ b/source/source_pw/module_stodft/sto_dos.cpp @@ -247,10 +247,10 @@ void Sto_DOS::caldos(const double sigmain, const double de, cons double maxerror = 0; double sum = 0; - ofsdos << ndos << " # number of points" << std::endl; - ofsdos << "#" << std::setw(19) << "energy(eV)" - << std::setw(20) << "dos(eV^-1)" << std::setw(20) << "sum" - << std::setw(20) << "error(eV^-1)" << std::endl; + ofsdos << ndos << " # number of points" << std::endl; + ofsdos << "#" << std::setw(19) << "energy(eV)" + << std::setw(20) << "dos(eV^-1)" << std::setw(20) << "sum" + << std::setw(20) << "error(eV^-1)" << std::endl; for (int ie = 0; ie < ndos; ++ie) { double tmperror = 2.0 * std::abs(error[ie]); diff --git a/source/source_relax/ions_move_basic.cpp b/source/source_relax/ions_move_basic.cpp index b0edadb2844..023ade0bc11 100644 --- a/source/source_relax/ions_move_basic.cpp +++ b/source/source_relax/ions_move_basic.cpp @@ -148,7 +148,7 @@ bool Ions_Move_Basic::check_converged(const UnitCell &ucell, const double ediff = etot_info[0] - etot_info[1]; std::cout << " ETOT DIFF (eV) : " << ediff * ModuleBase::Ry_to_eV << std::endl; std::cout << " LARGEST GRAD (eV/Angstrom) : " - << Ions_Move_Basic::largest_grad * ModuleBase::Ry_to_eV / ModuleBase::BOHR_TO_A + << Ions_Move_Basic::largest_grad * ModuleBase::Ry_to_eV / ModuleBase::BOHR_TO_A << std::endl; ofs << "\n Largest force is " << largest_grad * ModuleBase::Ry_to_eV / ModuleBase::BOHR_TO_A