1#ifndef ABACUS_LR_GRADIENT_AMPLITUDES_H
2#define ABACUS_LR_GRADIENT_AMPLITUDES_H
11 const int down_size,
const int ispin,
const bool openshell)
15 return state * nk * (up_size + down_size) + ispin * nk * up_size;
17 const int channel_size = ispin == 0 ? up_size : down_size;
18 return state * nk * channel_size;
23 const std::vector<double>& mixing, std::vector<T>& previous)
25 if (group.size() != mixing.size())
27 throw std::invalid_argument(
"JT mixing must contain one coefficient per root");
29 previous.assign(n,
T(0));
30 for (
size_t k = 0; k < group.size(); ++k)
32 for (
int i = 0; i < n; ++i)
34 previous[i] += mixing[k] * Xall[group[k] * n + i];
37 double norm_squared = 0.0;
38 for (
const T& value: previous)
43 if (norm_squared <= 0.0)
45 throw std::runtime_error(
"JT reference has zero norm");
47 const double scale = 1.0 / std::sqrt(norm_squared);
48 for (
T& value: previous)
55void follow_root(
const T* Xall,
const int n,
const int nstates,
const int initial_state,
56 int& target_state, std::vector<T>& previous, std::ostream& ofs)
61 target_state = initial_state;
65 int reference_size = previous.size();
67 if (reference_size > 0)
69 std::vector<T> ov(nstates,
T(0));
70 for (
int j = 0; j < nstates; ++j)
72 const T*
const Xj = Xall + j * n;
74 for (
int i = 0; i < n; ++i)
87 double best_ov = -1.0;
88 for (
int j = 0; j < nstates; ++j)
90 const double a = std::abs(ov[j]);
98 if (best != target_state)
100 ofs <<
" EXCITED-STATE RELAX: followed root moved from index "
101 << target_state <<
" to " << best <<
" (overlap " << best_ov
102 <<
"); the states crossed and the index no longer names the same state."
110 ofs <<
" WARNING: largest amplitude overlap with the previous step is"
113 <<
". The followed state may have left the window spanned by"
114 " lr_nstates; consider raising lr_nstates or reducing the ionic step."
122 previous.assign(Xall + target_state * n, Xall + (target_state + 1) * n);
132 const std::vector<Parallel_Blkcyclic>& px,
const std::vector<Parallel_Blkcyclic>& px_z,
133 const std::vector<int>& nocc,
const std::vector<int>& nvirt,
134 const int nk,
const int nloc,
const int nloc_z,
135 const int ispin,
const int istate_begin,
const int nst)
143 const std::vector<int> chan = openshell ? std::vector<int>{ 0, 1 }
144 : std::vector<int>{ ispin };
145 const int ix = openshell ? 0 : ispin;
148 for (
const int is : chan)
152 for (
int ist = 0;ist < nst;++ist)
154 const T*
const src = X[ix].template data<T>()
155 + (istate_begin + ist) * nloc + soff_ch;
156 T*
const dst = Xz.
data<
T>() + ist * nloc_z + zoff_ch;
157 for (
int ik = 0;ik < nk;++ik)
159 const int soff = ik * pxs.
size();
160 const int zoff = ik * pxz.
size();
165 for (
int o = 0;o < nocc[is];++o)
167 for (
int v = 0;v < nvirt[is];++v)
179 soff_ch += nk * pxs.
size();
180 zoff_ch += nk * pxz.
size();
Parallel block-cyclic matrix distribution.
Definition parallel_blkcyc.h:25
int irloc(const int irglb) const
Definition parallel_blkcyc.h:78
int nrloc() const
Definition parallel_blkcyc.h:35
bool in_this_processor(const int irglb, const int icglb) const
Definition parallel_blkcyc.cpp:58
std::size_t size() const
Definition parallel_blkcyc.h:48
int icloc(const int icglb) const
Definition parallel_blkcyc.h:83
A multi-dimensional array of elements of a single data type.
Definition tensor.h:32
void * data() const
Get a pointer to the data buffer of the tensor.
Definition tensor.cpp:73
void zero()
Set all elements in current tensor object to zero.
Definition tensor.cpp:97
#define T
Definition exp.cpp:237
ct::Tensor newTensor(const ct::TensorShape &shape)
Definition lr_util.h:156
double get_conj(const double &x)
Definition lr_util.hpp:70
Definition esolver_lr_lcao_tddft.h:28
ct::Tensor pad_amplitudes(const std::vector< ct::Tensor > &X, const bool openshell, const std::vector< Parallel_Blkcyclic > &px, const std::vector< Parallel_Blkcyclic > &px_z, const std::vector< int > &nocc, const std::vector< int > &nvirt, const int nk, const int nloc, const int nloc_z, const int ispin, const int istate_begin, const int nst)
Definition lr_amp.h:131
void follow_root(const T *Xall, const int n, const int nstates, const int initial_state, int &target_state, std::vector< T > &previous, std::ostream &ofs)
Definition lr_amp.h:55
void save_mixed_root(const T *Xall, const int n, const std::vector< int > &group, const std::vector< double > &mixing, std::vector< T > &previous)
Definition lr_amp.h:22
int electron_hole_offset(const int state, const int nk, const int up_size, const int down_size, const int ispin, const bool openshell)
Definition lr_amp.h:10
void reduce_all(T &object)
reduce in all process
Definition depend_mock.cpp:14