1#ifndef ABACUS_SOURCE_LCAO_MODULE_LR_UTILS_LR_UTIL_PRINT_H
2#define ABACUS_SOURCE_LCAO_MODULE_LR_UTILS_LR_UTIL_PRINT_H
10#include <RI/global/Tensor.h>
17 const int nstates,
const std::string& channel)
19 const std::ios_base::fmtflags flags = log.flags();
20 const std::streamsize precision = log.precision();
21 log <<
" LR excitation energies: " << channel <<
'\n';
22 log <<
" State Excitation Energy (Ry, eV)\n";
23 log << std::defaultfloat << std::setprecision(6);
24 for (
int state = 0; state < nstates; ++state)
26 log << state <<
' ' << energies[state] <<
' '
29 log <<
" End LR excitation energies\n";
31 log.precision(precision);
41 int read_value(std::ifstream& ifs,
T* ptr,
const int& size) {
for (
int i = 0;i < size;++i) { ifs >> ptr[i]; }
return size; }
42 template<
typename T,
typename... Args>
43 int read_value(std::ifstream& ifs,
T* ptr,
const int& size, Args&&... args)
46 for (
int i = 0;i < size;++i) { size_now +=
read_value(ifs, ptr + size_now, args...); }
49 template<
typename T,
typename... Args>
52 std::ifstream ifs(
file);
54 std::cerr <<
"Error: Cannot open file " <<
file << std::endl;
57 const int res =
read_value(ifs, ptr, size, args...);
65 for (
int i = 0;i < size;++i) { ofs <<
filter(ptr[i]) <<
" "; }
69 template<
typename T,
typename... Args>
70 int write_value(std::ofstream& ofs,
const T* ptr,
const int& size, Args&&... args)
73 for (
int i = 0;i < size;++i) { size_now +=
write_value(ofs, ptr + size_now, args...); }
77 template<
typename T,
typename... Args>
78 int write_value(
const std::string&
file,
const int& prec,
const T* ptr,
const int& size, Args&&... args)
80 std::ofstream ofs(
file);
82 std::cerr <<
"Error: Cannot open file " <<
file << std::endl;
85 ofs << std::setprecision(prec) << std::scientific;
86 const int res =
write_value(ofs, ptr, size, args...);
93 for (
int i = 0;i < size;++i) { std::cout <<
filter(ptr[i]) <<
" "; }
94 std::cout << std::endl;
97 template<
typename T,
typename... Args>
101 for (
int i = 0;i < size;++i) { size_now +=
print_value(ptr + size_now, args...); }
102 std::cout << std::endl;
109 assert(
psi.get_k_first() == 0);
110 std::cout << label <<
": band " << ib <<
"\n";
111 for (
int ik = 0;ik <
psi.get_nk();++ik)
113 std::cout <<
"iks=" << ik <<
"\n";
114 for (
int i = 0;i <
psi.get_nbasis();++i)
116 std::cout <<
filter(
psi(ib, ik, i)) <<
" ";
124 assert(
psi.get_k_first() == 0);
125 std::ofstream ofs(filename +
"_" + std::to_string(rank) +
".dat");
126 ofs << std::setprecision(precision) << std::scientific;
127 ofs <<
psi.get_nbands() <<
" " <<
psi.get_nk() <<
" " <<
psi.get_nbasis() <<
"\n";
133 const std::string& filename,
const int& rank,
const double&
threshold = 1e-10,
const int& precision = 8)
135 std::ofstream ofs(filename +
"_" + std::to_string(rank) +
".dat");
136 ofs << std::setprecision(precision) << std::scientific;
137 ofs << nband <<
" " << nk <<
" " << nbasis <<
"\n";
138 assert(nband * nk * nbasis ==
write_value(ofs,
psi, nband, nk, nbasis));
144 std::ifstream ifs(filename +
"_" + std::to_string(rank) +
".dat");
145 int nbands, nks, nbasis;
146 ifs >> nbands >> nks >> nbasis;
148 assert(
psi.size() ==
read_value(ifs,
psi.get_pointer(), nbands, nks, nbasis));
152 template<
typename T >
155 assert(
psi.get_k_first() == 1);
156 for (
int ik = 0;ik <
psi.get_nk();++ik)
158 std::cout << label <<
": k " << ik <<
"\n";
159 for (
int ib = 0;ib <
psi.get_nbands();++ib)
161 std::cout <<
"ib=" << ib <<
": ";
162 for (
int i = 0;i <
psi.get_nbasis();++i)
164 std::cout <<
filter(
psi(ik, ib, i)) <<
" ";
173 std::cout << label <<
"\n";
174 for (
int j = 0; j < pmat->
ncloc(); ++j)
176 for (
int i = 0; i < pmat->
nrloc(); ++i)
180 std::cout << std::endl;
187 std::cout <<
"first " << nnz <<
" non-zero elements of " << label <<
"\n";
188 int inz = 0;
int i = 0;
189 while (inz < nnz && i < nrxx) {
if (rho[++i] - 0.0 >
threshold) { std::cout << rho[i] <<
" ";++inz; } };
193 using TC = std::array<int, 3>;
194 using TAC = std::pair<int, TC>;
196 using TLRIX = std::map<int, std::map<TAC, std::vector<T>>>;
201 std::cout << label <<
"\n";
202 for (
const auto& tmp1 : CsX)
204 const int& iat1 = tmp1.first;
205 for (
const auto& tmp2 : tmp1.second)
207 const int& iat2 = tmp2.first.first;
208 const auto& R = tmp2.first.second;
209 auto& t = tmp2.second;
210 const int nocc = t.size() / nvirt;
211 std::cout <<
"iat1=" << iat1 <<
" iat2=" << iat2 <<
" R=(" << R[0] <<
" " << R[1] <<
" " << R[2] <<
")\n";
212 for (
int io = 0;io < nocc;++io)
214 for (
int iv = 0;iv < nvirt;++iv) { std::cout <<
filter(t[io * nvirt + iv]) <<
" "; }
223 template <
typename T>
224 using TLRI = std::map<int, std::map<TAC, RI::Tensor<T>>>;
226 void print_CV(
const TLRI<T>& Cs,
const std::string& label,
const double&
threshold = 1e-10)
228 std::cout << label <<
"\n";
229 for (
const auto& tmp1 : Cs)
231 const int& iat1 = tmp1.first;
232 for (
const auto& tmp2 : tmp1.second)
234 const int& iat2 = tmp2.first.first;
235 const auto& R = tmp2.first.second;
236 auto& t = tmp2.second;
237 if (R !=
TC({ 0, 0, 0 })) {
continue;}
238 std::cout <<
"iat1=" << iat1 <<
" iat2=" << iat2 <<
" R=(" << R[0] <<
" " << R[1] <<
" " << R[2] <<
")\n";
239 if (t.shape.size() == 2)
241 for (
int iabf1 = 0;iabf1 < t.shape[0];++iabf1)
243 for (
int iabf2 = 0;iabf2 < t.shape[1];++iabf2)
245 std::cout <<
filter(t(iabf1, iabf2)) <<
" ";
250 else if (t.shape.size() == 3)
252 const int nabf = t.shape[0];
253 const int nw1 = t.shape[1];
254 const int nw2 = t.shape[2];
255 std::cout <<
"size: " << nabf <<
" " << nw1 <<
" " << nw2 <<
"\n";
256 for (
int iabf = 0;iabf < nabf;++iabf)
258 for (
int iw1 = 0;iw1 < nw1;++iw1)
260 for (
int iw2 = 0;iw2 < nw2;++iw2)
262 std::cout <<
filter(t(iabf, iw1, iw2)) <<
" ";
Parallel block-cyclic matrix distribution.
Definition parallel_blkcyc.h:25
int ncloc() const
Definition parallel_blkcyc.h:40
int nrloc() const
Definition parallel_blkcyc.h:35
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
#define T
Definition exp.cpp:237
Definition exciton_plotter.cpp:368
void print_psi_bandfirst(const psi::Psi< T > &psi, const std::string &label, const int &ib, const double &threshold=1e-10)
Definition lr_util_print.h:107
psi::Psi< T > read_psi_bandfirst(const std::string &filename, const int &rank)
Definition lr_util_print.h:142
void print_grid_nonzero(T *rho, const int &nrxx, const int &nnz, const std::string &label, const double &threshold=1e-5)
Definition lr_util_print.h:185
void print_tensor(const container::Tensor &t, const std::string &label, const Parallel_Blkcyclic *pmat, const double &threshold=1e-10)
Definition lr_util_print.h:171
void print_excitation_energies(std::ostream &log, const double *energies, const int nstates, const std::string &channel)
Definition lr_util_print.h:16
std::pair< int, TC > TAC
Definition lr_util_print.h:194
void print_psi_kfirst(const psi::Psi< T > &psi, const std::string &label, const double &threshold=1e-10)
Definition lr_util_print.h:153
int read_value(std::ifstream &ifs, T *ptr, const int &size)
Definition lr_util_print.h:41
std::map< int, std::map< TAC, std::vector< T > > > TLRIX
Definition lr_util_print.h:196
constexpr T filter(const T &v, const double &threshold=1e-10)
Definition lr_util_print.h:35
int write_value(std::ofstream &ofs, const T *ptr, const int &size)
Definition lr_util_print.h:63
void write_psi_bandfirst(const psi::Psi< T > &psi, const std::string &filename, const int &rank, const double &threshold=1e-10, const int &precision=8)
Definition lr_util_print.h:122
void print_CsX(const TLRIX< T > &CsX, const int nvirt, const std::string &label, const double &threshold=1e-10)
Definition lr_util_print.h:199
std::array< int, 3 > TC
Definition lr_util_print.h:193
int print_value(const T *ptr, const int &size)
Definition lr_util_print.h:91
const double Ry_to_eV
Definition constants.h:81
Definition diag_lcao.h:14
file(GLOB ATen_CORE_SRCS "*.cpp") set(ATen_CPU_SRCS $
Definition CMakeLists.txt:1
#define threshold
Definition sph_bessel_rec_test.cpp:4
std::map< int, std::map< TAC, RI::Tensor< T > > > TLRI
Definition test_write_ri_cv.cpp:12