|
1 | 1 | #include "write_dH.h" |
2 | 2 |
|
3 | 3 | #include "source_base/timer.h" |
| 4 | +#include "source_io/module_hs/write_HS.h" |
4 | 5 | #include "source_io/module_hs/write_HS_R.h" |
5 | 6 | #include "source_io/module_output/ucell_io.h" |
6 | 7 | #include "source_io/module_parameter/parameter.h" |
7 | 8 | #include "source_lcao/module_hcontainer/hcontainer_funcs.h" |
8 | 9 | #include "source_lcao/module_hcontainer/output_hcontainer.h" |
9 | 10 |
|
| 11 | +#include <complex> |
10 | 12 | #include <fstream> |
11 | 13 | #include <iomanip> |
| 14 | +#include <string> |
12 | 15 |
|
13 | 16 | namespace ModuleIO |
14 | 17 | { |
15 | 18 |
|
| 19 | +void write_dh_perI(WriteDHParams& params, |
| 20 | + int ispin, |
| 21 | + const std::string& rprefix, |
| 22 | + const std::string& kprefix, |
| 23 | + const std::string& label, |
| 24 | + std::vector<hamilt::HContainer<double>*>& gx, |
| 25 | + std::vector<hamilt::HContainer<double>*>& gy, |
| 26 | + std::vector<hamilt::HContainer<double>*>& gz) |
| 27 | +{ |
| 28 | + const UnitCell& ucell = *params.ucell; |
| 29 | + const Parallel_Orbitals& pv = *params.pv; |
| 30 | + const int nat = params.nat; |
| 31 | + const int nspin = params.nspin; |
| 32 | + const int nbasis = gx[0]->get_nbasis(); |
| 33 | + |
| 34 | + const char dirc[3] = {'x', 'y', 'z'}; |
| 35 | + std::vector<hamilt::HContainer<double>*>* g[3] = {&gx, &gy, &gz}; |
| 36 | + |
| 37 | + // k-space (dense, folded like H(k)) parameters |
| 38 | + const int nspin_k = (nspin == 2 ? 2 : 1); |
| 39 | + const int nks = params.kv->get_nks() / nspin_k; |
| 40 | + const int nlocal = PARAM.globalv.nlocal; |
| 41 | + const std::string global_out_dir = PARAM.globalv.global_out_dir; |
| 42 | + const bool out_app_flag = PARAM.inp.out_app_flag; |
| 43 | + const std::string r_dir |
| 44 | + = (PARAM.inp.calculation == "md" && !out_app_flag) ? PARAM.globalv.global_matrix_dir : global_out_dir; |
| 45 | + |
| 46 | +#ifdef __MPI |
| 47 | + Parallel_Orbitals serialV; |
| 48 | + serialV.init(nbasis, nbasis, nbasis, pv.comm()); |
| 49 | + serialV.set_serial(nbasis, nbasis); |
| 50 | + serialV.set_atomic_trace(params.iat2iwt, nat, nbasis); |
| 51 | +#endif |
| 52 | + |
| 53 | + for (int iat = 0; iat < nat; ++iat) |
| 54 | + { |
| 55 | + for (int d = 0; d < 3; ++d) |
| 56 | + { |
| 57 | + hamilt::HContainer<double>* hR = (*g[d])[iat]; |
| 58 | + const std::string tag = std::string(1, dirc[d]) + "_iat" + std::to_string(iat + 1); |
| 59 | + |
| 60 | + // ---- real space dH(R), CSR ---- |
| 61 | +#ifdef __MPI |
| 62 | + hamilt::HContainer<double> hR_s(&serialV); |
| 63 | + hamilt::gatherParallels(*hR, &hR_s, 0); |
| 64 | + if (GlobalV::MY_RANK == 0) |
| 65 | +#endif |
| 66 | + { |
| 67 | + std::string fr = r_dir + ModuleIO::dhr_gen_fname(rprefix + tag, ispin, params.append, params.istep); |
| 68 | +#ifdef __MPI |
| 69 | + ModuleIO::write_hcontainer_csr(fr, &ucell, 8, &hR_s, params.istep, ispin, nspin, label); |
| 70 | +#else |
| 71 | + ModuleIO::write_hcontainer_csr(fr, &ucell, 8, hR, params.istep, ispin, nspin, label); |
| 72 | +#endif |
| 73 | + } |
| 74 | + |
| 75 | + // ---- k space dH(k), dense (folded like H(k), comparable to *_nao.txt) ---- |
| 76 | + // build the filename directly (filename_output only accepts a fixed property set) |
| 77 | + for (int ik = 0; ik < nks; ++ik) |
| 78 | + { |
| 79 | + std::vector<std::complex<double>> hk(static_cast<size_t>(nlocal) * nlocal, 0); |
| 80 | + hamilt::folding_HR(*hR, hk.data(), params.kv->kvec_d[ik], nlocal, 0); |
| 81 | + std::string fk = global_out_dir + kprefix + tag; |
| 82 | + if (nks > 1) |
| 83 | + { |
| 84 | + fk += "_ik" + std::to_string(params.kv->ik2iktot[ik]); |
| 85 | + } |
| 86 | + fk += "_nao.txt"; |
| 87 | + ModuleIO::save_mat(params.istep, |
| 88 | + hk.data(), |
| 89 | + nlocal, |
| 90 | + false, |
| 91 | + 8, |
| 92 | + false, |
| 93 | + out_app_flag, |
| 94 | + fk, |
| 95 | + pv, |
| 96 | + GlobalV::DRANK); |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | +} |
| 101 | + |
16 | 102 | bool any_dh_term_enabled() |
17 | 103 | { |
18 | 104 | return PARAM.inp.out_mat_dh_t[0] || PARAM.inp.out_mat_dh_vl[0] || PARAM.inp.out_mat_dh_vnl[0] |
@@ -88,6 +174,11 @@ bool write_dH_sum(WriteDHParams& params) |
88 | 174 | dH_sum_y.set_zero(); |
89 | 175 | dH_sum_z.set_zero(); |
90 | 176 |
|
| 177 | + if (dH_sum_x.size_atom_pairs() == 0) |
| 178 | + { |
| 179 | + continue; |
| 180 | + } |
| 181 | + |
91 | 182 | const int nbasis = dH_sum_x.get_nbasis(); |
92 | 183 |
|
93 | 184 | #ifdef __MPI |
|
0 commit comments