1#ifndef ABACUS_SOURCE_LCAO_MODULE_LR_UTILS_LR_UTIL_H
2#define ABACUS_SOURCE_LCAO_MODULE_LR_UTILS_LR_UTIL_H
24template <>
struct ToComplex<double> {
using type = std::complex<double>; };
26template <>
struct ToComplex<float> {
using type = std::complex<float>; };
42 const std::vector<double>&
prepare_xc_sigma(
const std::vector<double>& sigma,
44 std::vector<double>& hse_buffer);
57 const std::vector<double> &sigma,
59 std::vector<double> &hse_buffer,
60 std::vector<double> &jacobian);
74 static const std::set<std::string> l = {
"hf",
"hse",
"pbe0",
"b3lyp",
75 "cam_pbeh",
"lc_pbe",
"lc_wpbe",
"lrc_wpbe",
"lrc_wpbeh" };
82 if (std::set<std::string>({
"lda",
"pwlda",
"pbe"}).count(name))
96 template <
typename TCell>
104 int cal_nocc(
double nelec,
int nspin,
int nupdown);
111 const std::vector<int>& x_virtual,
const std::vector<int>& z_virtual);
120 std::pair<ModuleBase::matrix, std::vector<std::pair<int, int>>>
126 inline double inner_product(
const double* vec1,
const double* vec2,
const int& size)
129 for (
int i = 0; i < size; ++i)
131 result += vec1[i] * vec2[i];
137 const std::complex<double>* vec2,
140 std::complex<double> result = 0.0;
141 for (
int i = 0; i < size; ++i)
143 result += std::conj(vec1[i]) * vec2[i];
150 template <
typename T>
153 template <
typename T>
164 void matsym(
const T* in,
const int n,
T* out);
167 void matsym(
T* inout,
const int n);
190 template<
typename T,
typename Device>
193 template<
typename T,
typename Device>
202 template <
typename T>
203 void global2local_X(
T* local_X,
const T* global_X,
const int nband,
const int nk,
204 const std::vector<int>& nocc,
const std::vector<int>& nvirt,
const std::vector<Parallel_Blkcyclic>& pX,
205 const bool openshell);
211 template <
typename T>
213 static MPI_Datatype
value() {
return MPI_DATATYPE_NULL; }
217 static MPI_Datatype
value() {
return MPI_INT; }
221 static MPI_Datatype
value() {
return MPI_DOUBLE; }
225 static MPI_Datatype
value() {
return MPI_DOUBLE_COMPLEX; }
228 template <
typename T>
229 void pA2pX(
T* X_pX,
const T* X_pA,
const int nband,
const int nk,
230 const std::vector<int>& nocc,
const std::vector<int>& nvirt,
232 const int row_offset,
const int col_offset,
const bool openshell,
233 const int my_rank,
const int nproc);
237 template <
typename T>
239 const bool row_major,
const std::size_t global_nrow,
const std::size_t global_ncol);
242 template <
typename T>
259 std::string
tolower(
const std::string& str);
260 std::string
toupper(
const std::string& str);
264std::vector<T>
operator+(
const std::vector<T>& a,
const std::vector<T>& b)
266 const int maxsize = std::max(a.size(), b.size());
267 const int minsize = std::min(a.size(), b.size());
268 std::vector<T> c(maxsize);
269 for (
int i = 0; i < minsize; ++i)
273 for (
int i = minsize; i < maxsize; ++i)
275 c[i] = (a.size() > b.size() ? a[i] : b[i]);
Parallel block-cyclic matrix distribution.
Definition parallel_blkcyc.h:25
Provide the basic information about unitcell.
Definition unitcell.h:16
A class for representing the shape of a tensor.
Definition tensor_shape.h:13
A multi-dimensional array of elements of a single data type.
Definition tensor.h:32
#define complex
Definition elpa_new.h:28
#define T
Definition exp.cpp:237
std::vector< T > operator+(const std::vector< T > &a, const std::vector< T > &b)
=================operators======================= (should ot in namespace LR_Util)
Definition lr_util.h:264
container::DeviceType DEV
Definition bse_util.h:63
container::DataType DAT
================ Container ===============
Definition bse_util.h:62
Definition exciton_plotter.cpp:368
void scatter_full_to_2d(const Parallel_Blkcyclic &pv, const T *fullmat, T *submat, const bool col_first=false)
scatter full matrix to 2d block-cyclic distributed matrix
Definition lr_util.hpp:593
void global2local_X(T *local_X, const T *global_X, const int nband, const int nk, const std::vector< int > &nocc, const std::vector< int > &nvirt, const std::vector< Parallel_Blkcyclic > &pX, const bool openshell)
assign global X to 2d-matrix, its col is band(excition state), and row is { spin, k-point,...
Definition lr_util.hpp:292
int lapack_linear_solver(const T *A, T *x, const T *b, const int n, const int nrhs)
solve linear equations Ax=b using LAPACK
double hse_sigma_floor()
Existing HSE sigma floor (bohr^-8), shared by LR and the GS fallback.
Definition lr_util.cpp:12
int cal_nelec(const TCell &ucell)
calculate the number of electrons
Definition lr_util.hpp:22
ct::Tensor newTensor(const ct::TensorShape &shape)
Definition lr_util.h:156
int cal_nocc_window(int requested_nocc, int nocc_max)
Retain a positive user window, otherwise use all occupied orbitals.
Definition lr_util.cpp:167
void matsym(const T *in, const int n, T *out)
Definition lr_util.hpp:79
bool is_hermitian(const T *mat, const Parallel_Blkcyclic &pmat, const double threshold, const int my_rank)
Definition lr_util.hpp:107
void setup_2d_division(Parallel_Blkcyclic &pv, int nb, int gr, int gc)
=================2D-block Parallel===============
Definition lr_util.cpp:436
void diag_lapack(const int &n, T *mat, double *eig)
diagonalize a hermitian matrix
int cal_nocc(int nelec)
=================PHYSICS====================
Definition lr_util.cpp:149
bool has_local_xc(const std::string &name)
check if the xc functional has local xc kernel
Definition lr_util.h:80
std::string toupper(const std::string &str)
Definition lr_util.cpp:575
std::string tolower(const std::string &str)
=================string option====================
Definition lr_util.cpp:569
void matantisym(T *inout, const int n, const Parallel_Blkcyclic &pmat)
void diag_lapack_nh(const int &n, T *mat, std::complex< double > *eig)
diagonalize a general matrix
double inner_product(const double *vec1, const double *vec2, const int &size)
=================ALGORITHM====================
Definition lr_util.h:126
std::string force_window_warning(const int basis_size, const int gs_bands, const int skipped_occupied, const std::vector< int > &x_virtual, const std::vector< int > &z_virtual)
Diagnose resolved force windows without modifying X, Z or their energies.
Definition lr_util.cpp:52
psi::Psi< T, Device > bfirst_to_k1_wrapper(const psi::Psi< T, Device > &psi_bfirst)
psi(nb, nk, nbasis) -> psi(nk=1, nbands=nb, nk * nbasis) without memory copy
Definition lr_util.hpp:271
psi::Psi< T, Device > k1_to_bfirst_wrapper(const psi::Psi< T, Device > &psi_kfirst, int nk_in, int nbasis_in)
psi(nk=1, nbands=nb, nk * nbasis) -> psi(nb, nk, nbasis) without memory copy
Definition lr_util.hpp:252
void _allocate_2order_nested_ptr(T **&p2, size_t size1, size_t size2)
new 2d pointer
Definition lr_util.hpp:44
void gather_2d_to_full(const Parallel_Blkcyclic &pv, const T *submat, T *fullmat, const bool row_major, const std::size_t global_nrow, const std::size_t global_ncol)
gather 2d matrix to full matrix the defination of row and col is consistent with setup_2d_division
Definition lr_util.hpp:571
void check_force_pp(const UnitCell &cell, const bool cal_force, const std::string &calculation)
Reject unsupported NLCC force requests after pseudopotentials have been loaded.
Definition lr_util.cpp:91
void _deallocate_2order_nested_ptr(T **p2, size_t size)
delete 2d pointer
Definition lr_util.hpp:58
int spin_population_difference(const ModuleBase::matrix &wg, const int kpar, const int rank_in_pool)
Sum k-point spin populations before rounding; count each pool only once.
Definition lr_util.cpp:13
void pA2pX(T *X_pX, const T *X_pA, const int nband, const int nk, const std::vector< int > &nocc, const std::vector< int > &nvirt, const std::vector< Parallel_Blkcyclic > &pX, const Parallel_Blkcyclic &pA, const int row_offset, const int col_offset, const bool openshell, const int my_rank, const int nproc)
assign X in pA to X in pX
Definition lr_util.hpp:367
bool is_symmetric(const T *mat, const Parallel_Blkcyclic &pmat, const double threshold, const int my_rank)
Definition lr_util.hpp:172
std::pair< ModuleBase::matrix, std::vector< std::pair< int, int > > > set_ix_map_diagonal(bool mode, int nocc, int nvirt)
set the index map: ix to (ic, iv) and vice versa by diagonal traverse the c-v pairs leftdown -> right...
Definition lr_util.cpp:177
void mattrans(const T *in, const int n, const Parallel_Blkcyclic &pmat, T *out)
const std::vector< double > & prepare_xc_sigma(const std::vector< double > &sigma, const bool is_hse06, std::vector< double > &hse_buffer)
Preserve signed sigma invariants except for the existing HSE06 stabilization.
Definition lr_util.cpp:111
const std::set< std::string > & hybrid_xc_list()
the xc kernels that carry an exact-exchange (EXX) term
Definition lr_util.h:72
DataType
Definition tensor_enums.h:15
DeviceType
Definition tensor_enums.h:28
#define threshold
Definition sph_bessel_rec_test.cpp:4
static MPI_Datatype value()
Definition lr_util.h:221
static MPI_Datatype value()
Definition lr_util.h:217
static MPI_Datatype value()
Definition lr_util.h:225
Struct to get MPI_traits for different data types.
Definition lr_util.h:212
static MPI_Datatype value()
Definition lr_util.h:213
std::complex< double > type
Definition lr_util.h:24
std::complex< float > type
Definition lr_util.h:26
std::complex< double > type
Definition lr_util.h:25
std::complex< float > type
Definition lr_util.h:27
static constexpr DataType value
Definition tensor_enums.h:61
static constexpr DeviceType value
Definition tensor_enums.h:36
int rank_in_pool
Definition pw_test.cpp:12