ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
charge.h
Go to the documentation of this file.
1#ifndef CHARGE_H
2#define CHARGE_H
3
4#include <vector>
5
11// #include "source_estate/fp_energy.h"
13
14//a forward declaration of UnitCell
15class UnitCell;
16
18{
19struct InitRhoCfg;
20}
21
22// Electron Charge Density
23class Charge
24{
25
26 public:
27
28 Charge();
29 ~Charge();
30
31 // rho/rhog/kin_r views alias the vector-backed _space_* storage, so
32 // copying a Charge would duplicate dangling pointers into another
33 // object's vector buffer. Forbid copies until a deep copy is needed.
34 Charge(const Charge&) = delete;
35 Charge& operator=(const Charge&) = delete;
36
37 //==========================================================
38 // MEMBER VARIABLES :
39 // init_chg : "atomic" or "file"
40 // NAME : total number of electrons
41 // NAME : rho (nspin,ncxyz), the charge density in real space
42 // NAME : rho_save (nspin,ncxyz), for charge mixing
43 // NAME : rhog, charge density in G space
44 // NAME : rhog_save, chage density in G space
45 // NAME : rho_core [nrxx], the core charge in real space
46 // NAME : rhog_core [ngm], the core charge in reciprocal space
47 //==========================================================
48
49 double **rho = nullptr;
50 double **rho_save = nullptr;
51
52 std::complex<double> **rhog = nullptr;
53 std::complex<double> **rhog_save = nullptr;
54
55 double **kin_r = nullptr; // kinetic energy density in real space, for meta-GGA
56 double **kin_r_save = nullptr; // same as kin_r, kept for mixing
57 const Parallel_Grid* pgrid = nullptr;
58
59 private:
60
61 // Underlying contiguous storage backing the public rho/rhog/kin_r views.
62 // Each buffer holds nspin rows; rho[is] points at _space_rho.data()+is*nrxx.
63 // Owned here as std::vector so the storage self-manages (no raw new/delete).
64 std::vector<double> _space_rho;
65 std::vector<double> _space_rho_save;
66 std::vector<std::complex<double>> _space_rhog;
67 std::vector<std::complex<double>> _space_rhog_save;
68 std::vector<double> _space_kin_r;
69 std::vector<double> _space_kin_r_save;
70
71 // Pointer arrays backing the public double** views (rho, rhog, etc.)
72 std::vector<double*> _ptrs_rho;
73 std::vector<std::complex<double>*> _ptrs_rhog;
74 std::vector<double*> _ptrs_rho_save;
75 std::vector<std::complex<double>*> _ptrs_rhog_save;
76 std::vector<double*> _ptrs_kin_r;
77 std::vector<double*> _ptrs_kin_r_save;
78
79 // Contiguous storage for rho_core and rhog_core
80 std::vector<double> _space_rho_core;
81 std::vector<std::complex<double>> _space_rhog_core;
82
83 public:
84
85 double *rho_core = nullptr;
86 std::complex<double> *rhog_core = nullptr;
87
88 void set_rhopw(ModulePW::PW_Basis* rhopw_in);
89
101 void init_rho(const UnitCell& ucell,
102 const Parallel_Grid& pgrid,
103 const ModuleBase::ComplexMatrix& strucFac,
105 const void* klist,
106 const void* wfcpw,
107 const module_charge::InitRhoCfg& cfg);
108
118 void allocate(const int &nspin_in, const bool kin_den, const bool meta_gga,
119 const int test_charge);
120
132 void renormalize_rho(const double nelec, const double omega);
133
134 double sum_rho(const double omega) const;
135
137
141 bool get_allocate_rho() const { return allocate_rho; }
142
143 // mohan add 2021-02-20
144 int nrxx=0; // number of r vectors in this processor
145 int nxyz = 0; // total number of r vectors
146 int ngmc=0; // number of g vectors in this processor
147 int nspin=0; // number of spins
148 bool meta_gga = false; // whether the functional is meta-GGA (set by allocate)
149 ModulePW::PW_Basis* rhopw = nullptr;// When double_grid is used, rhopw = rhodpw (dense grid)
150
151 private:
152
153 void destroy(); // free arrays liuyu 2023-03-12
154
156};
157
158#endif // charge
double ** rho
Definition charge.h:49
void save_rho_before_sum_band()
Definition charge.cpp:215
~Charge()
Definition charge.cpp:41
std::vector< std::complex< double > * > _ptrs_rhog
Definition charge.h:73
std::vector< double * > _ptrs_rho
Definition charge.h:72
std::vector< std::complex< double > > _space_rhog_core
Definition charge.h:81
std::complex< double > ** rhog_save
Definition charge.h:53
std::vector< double * > _ptrs_rho_save
Definition charge.h:74
std::complex< double > ** rhog
Definition charge.h:52
std::vector< double * > _ptrs_kin_r
Definition charge.h:76
void renormalize_rho(const double nelec, const double omega)
Renormalize rho so that its integral equals the electron number.
Definition charge.cpp:189
std::complex< double > * rhog_core
Definition charge.h:86
std::vector< std::complex< double > > _space_rhog
Definition charge.h:66
void init_rho(const UnitCell &ucell, const Parallel_Grid &pgrid, const ModuleBase::ComplexMatrix &strucFac, ModuleSymmetry::Symmetry &symm, const void *klist, const void *wfcpw, const module_charge::InitRhoCfg &cfg)
Init charge density from file or atomic pseudo-wave-functions.
Definition chg_init.cpp:28
void set_rhopw(ModulePW::PW_Basis *rhopw_in)
Definition charge.cpp:46
Charge()
Definition charge.cpp:36
double ** kin_r
Definition charge.h:55
std::vector< double > _space_rho_core
Definition charge.h:80
void allocate(const int &nspin_in, const bool kin_den, const bool meta_gga, const int test_charge)
Allocate the rho/rhog/kin_r buffers.
Definition charge.cpp:76
bool meta_gga
Definition charge.h:148
Charge(const Charge &)=delete
std::vector< double > _space_kin_r
Definition charge.h:68
std::vector< std::complex< double > * > _ptrs_rhog_save
Definition charge.h:75
std::vector< double > _space_rho
Definition charge.h:64
Charge & operator=(const Charge &)=delete
std::vector< double > _space_kin_r_save
Definition charge.h:69
const Parallel_Grid * pgrid
Definition charge.h:57
int ngmc
Definition charge.h:146
double ** kin_r_save
Definition charge.h:56
double ** rho_save
Definition charge.h:50
int nrxx
Definition charge.h:144
std::vector< double > _space_rho_save
Definition charge.h:65
double * rho_core
Definition charge.h:85
ModulePW::PW_Basis * rhopw
Definition charge.h:149
bool get_allocate_rho() const
whether allocate() has already claimed the density buffers
Definition charge.h:141
void destroy()
Definition charge.cpp:51
double sum_rho(const double omega) const
Definition charge.cpp:179
int nxyz
Definition charge.h:145
std::vector< double * > _ptrs_kin_r_save
Definition charge.h:77
bool allocate_rho
Definition charge.h:155
int nspin
Definition charge.h:147
std::vector< std::complex< double > > _space_rhog_save
Definition charge.h:67
Definition complexmatrix.h:11
A class which can convert a function of "r" to the corresponding linear superposition of plane waves ...
Definition pw_basis.h:60
Symmetry analysis class.
Definition symmetry.h:24
Definition parallel_grid.h:8
Provide the basic information about unitcell.
Definition unitcell.h:16
Charge-density symmetrization free functions.
Definition charge.h:18
Definition chg_init.h:21
Symmetry analysis class.