ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
write_dh.h
Go to the documentation of this file.
1#ifndef WRITE_DH_H
2#define WRITE_DH_H
3
5#include "source_cell/klist.h"
11
12#include <array>
13#include <complex>
14#include <fstream>
15#include <vector>
16
18template<typename T, typename... Args>
19std::unique_ptr<T> make_unique(Args &&... args)
20{
21 return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
22}
23
24namespace ModuleIO
25{
26
28{
29 const UnitCell* ucell = nullptr;
30 const Grid_Driver* gd = nullptr;
31 const Parallel_Orbitals* pv = nullptr;
33 const LCAO_Orbitals* orb = nullptr;
34 const K_Vectors* kv = nullptr;
35 const ModuleBase::matrix* v_eff = nullptr;
36 const int* iat2iwt = nullptr;
38 // Dedicated single-component potentials for the Veff-based dH terms. pelec->pot mixes
39 // V^L + V^H + V^XC in get_eff_v(), so cal_dH would read the wrong potential for the
40 // separate V^H / V^XC (and V^L) outputs. Each of these is built with exactly one
41 // component registered ("local" / "hartree" / "xc"); see ctrl_scf_lcao.
45 int nat = 0;
46 int nspin = 1;
47 int istep = 0;
48 bool gamma_only = false;
49 bool append = false;
50 bool also_dhR = false; // whether to write the real-space dH(R) in addition to the k-space dH(k)
51 // per-spin real-space DM (size nspin for nspin=1/2). Used by the Veff Hellmann-Feynman
52 // terms: V^H needs the total density (sum over spins), V^XC the spin-resolved densities.
53 std::vector<const hamilt::HContainer<double>*> dmR;
54 const Charge* chg = nullptr; // ground-state charge for XC Hellmann-Feynman (FDM)
55 std::ofstream* ofs_running = nullptr; // running log for the "Write ... to file" messages
56};
57
58// Returns 0-based atom indices to output (converted from the 1-based user-facing values stored at param[2+]);
59// empty vector (param.size() <= 2) means all atoms. Out-of-range checking is done in
60// write_dh_perI where nat is available: indices >= nat are warned about and silently skipped.
61inline std::vector<int> dh_atom_filter(const std::vector<int>& param)
62{
63 if (param.size() <= 2) // param elements: [on/off][precition][iat1][iat2][...]
64 return {};
65 return std::vector<int>(param.begin() + 2, param.end());
66}
67
68// Shared writer for the per-atom-I dH terms. For every differentiated atom I it writes:
69// - dH(R) in CSR real-space format ({rprefix}{x,y,z}_ia{I}s{spin}[g{step}].csr,
70// via dhr_gen_fname; spin suffix always present)
71// - dH(k) dense matrices ({kprefix}{k}{x,y,z}_ia{I}[s{spin}][g{step}]_nao.txt,
72// via dhk_gen_fname; k is the 1-based k-point index and is always present, the spin
73// suffix only appears when nspin = 2) folded like H(k),
74// so they can be compared directly with the H(k) term matrices (*_nao.txt).
75// g[d] are nat per-I HContainers for direction d=0..2 (already filled by an operator's cal_dH).
76// atom_filter: if non-empty, only the listed 0-based atom indices are written; empty = all atoms.
77void write_dh_perI(WriteDHParams& params,
78 int ispin,
79 const std::string& rprefix,
80 const std::string& kprefix,
81 const std::string& label,
82 const std::string& term_name,
83 std::array<std::vector<hamilt::HContainer<double>*>, 3>& g,
84 const std::vector<int>& atom_filter = {});
85
86void write_dH_components(WriteDHParams& params, const Exx_Info& exx_info);
87
88bool write_dH_t(WriteDHParams& params);
89
90bool write_dH_vnl(WriteDHParams& params);
91
92bool write_dH_vl(WriteDHParams& params);
93
94bool write_dH_vh(WriteDHParams& params);
95
97
98bool write_dH_vxc(WriteDHParams& params);
99
101
102bool write_dH_sum(WriteDHParams& params);
103
104} // namespace ModuleIO
105
106#endif
Definition charge.h:24
Grid_Driver class for neighbor search interface.
Definition sltk_grid_driver.h:63
Class for k-points management.
Definition klist.h:20
Definition orb_read.h:18
Definition matrix.h:15
Definition parallel_orbitals.h:16
Definition two_center_bundle.h:11
Provide the basic information about unitcell.
Definition unitcell.h:16
Definition potential_new.h:58
Definition hcontainer.h:147
#define T
Definition exp.cpp:237
Internal helpers shared by the R-space sparse text writers. Declared here (instead of duplicated in e...
Definition csr_reader.cpp:8
void write_dh_perI(WriteDHParams &params, int ispin, const std::string &rprefix, const std::string &kprefix, const std::string &label, const std::string &term_name, std::array< std::vector< hamilt::HContainer< double > * >, 3 > &g, const std::vector< int > &atom_filter)
Definition write_dh.cpp:27
void write_dH_components(WriteDHParams &params, const Exx_Info &exx_info)
Definition write_dh.cpp:151
bool write_dH_vh(WriteDHParams &params)
Definition write_dh_terms.cpp:273
bool write_dH_vl(WriteDHParams &params)
Definition write_dh_terms.cpp:261
bool write_dH_vxc(WriteDHParams &params)
Definition write_dh_terms.cpp:297
bool write_dH_t(WriteDHParams &params)
Definition write_dh_terms.cpp:214
bool write_dH_sum(WriteDHParams &params)
Definition write_dh_terms.cpp:334
bool write_dH_vxc_pulay(WriteDHParams &params)
Definition write_dh_terms.cpp:311
bool write_dH_vh_pulay(WriteDHParams &params)
Definition write_dh_terms.cpp:285
bool write_dH_vnl(WriteDHParams &params)
Definition write_dh_terms.cpp:238
std::vector< int > dh_atom_filter(const std::vector< int > &param)
Definition write_dh.h:61
Grid_Driver class for neighbor search interface.
Definition write_dh.h:28
int nat
Definition write_dh.h:45
const Charge * chg
Definition write_dh.h:54
std::ofstream * ofs_running
Definition write_dh.h:55
const TwoCenterBundle * two_center_bundle
Definition write_dh.h:32
bool also_dhR
Definition write_dh.h:50
elecstate::Potential * pot_vh
Definition write_dh.h:43
const UnitCell * ucell
Definition write_dh.h:29
const ModuleBase::matrix * v_eff
Definition write_dh.h:35
elecstate::Potential * pot
Definition write_dh.h:37
elecstate::Potential * pot_vl
Definition write_dh.h:42
const Grid_Driver * gd
Definition write_dh.h:30
const LCAO_Orbitals * orb
Definition write_dh.h:33
bool append
Definition write_dh.h:49
std::vector< const hamilt::HContainer< double > * > dmR
Definition write_dh.h:53
int istep
Definition write_dh.h:47
const int * iat2iwt
Definition write_dh.h:36
int nspin
Definition write_dh.h:46
const K_Vectors * kv
Definition write_dh.h:34
bool gamma_only
Definition write_dh.h:48
elecstate::Potential * pot_vxc
Definition write_dh.h:44
const Parallel_Orbitals * pv
Definition write_dh.h:31
std::unique_ptr< T > make_unique(Args &&... args)
for lack of make_unique in c++11
Definition write_dh.h:19