ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
chg_tools.h
Go to the documentation of this file.
1#ifndef CHG_TOOLS_H
2#define CHG_TOOLS_H
3
4// Free numerical kernels extracted from the Charge class so that the
5// density math (summation, electron-count integration, non-linear core
6// correction) can be tested and reused without dragging in Charge's state.
7// All grid / geometry inputs are passed explicitly instead of being read
8// from Charge members or globals.
9
10#include <complex>
11#include <vector>
12
13class UnitCell;
14namespace ModuleBase
15{
16class ComplexMatrix;
17template <class T>
18class Vector3;
19}
20namespace ModulePW
21{
22class PW_Basis;
23}
24
25namespace module_charge
26{
27
28// Compute the core charge (non-linear core correction) on the real-space
29// 3D mesh. rho_core / rhog_core are the output buffers previously owned by
30// Charge; rhopw supplies the reciprocal-grid geometry and FFT backend.
31void set_rho_core(const UnitCell& ucell,
32 const ModuleBase::ComplexMatrix& structure_factor,
33 const bool* numeric,
34 double* rho_core,
35 std::complex<double>* rhog_core,
36 const ModulePW::PW_Basis& rhopw);
37
38// First-order core-density response (the q-shifted derivative of the
39// core charge, QE addcore convention). Conventions: q_cart is in the
40// same scaled Cartesian units as rhopw.gcar (q_cart = q_frac * ucell.G),
41// so the physical wavevector is K = tpiba * (gcar + q_cart) in 1/bohr;
42// with tau_cart = lat0 * tau (bohr), for the displacement of atom iat
43// along direction dir,
44// drhoc_g(G) = -i K_dir * rho_atc~(|K|) * exp(-i K.tau_cart)
45// where rho_atc~ is the numeric Simpson radial transform
46// 4pi/Omega Int r^2 rho_atc(r) j0(|K| r) dr.
47// Unlike set_rho_core this evaluates per G (|K| differs at every ig, so
48// the gg_uniq shell cache cannot be reused) and carries the
49// single-atom structure-factor phase. Empty output for a non-nlcc atom
50// or an out-of-range (iat, dir); the |K| = 0 harmonic is left zero.
51// Consumed by the DFPT first-order density (DFPT_Rho::compute_drhoc_g
52// delegates here).
53void set_drho_core(const UnitCell& ucell,
54 int iat,
55 int dir,
56 const ModuleBase::Vector3<double>& q_cart,
57 const ModulePW::PW_Basis& rhopw,
58 std::vector<std::complex<double>>& drhoc_g);
59
60// Core-charge form factor at a single physical wavevector k (1/bohr):
61// 4pi/Omega * Int r^2 rho_atc(r) j0(k r) dr (numeric Simpson).
62// The shared radial kernel of every per-point core-charge evaluation
63// (the first-order response above and the DFPT dynmatcc second-order
64// route); the ground-state set_rho_core instead shells it through the
65// cached, multithreaded non_linear_core_correction. scratch is a
66// caller-owned buffer of size mesh reused across calls (the kernel
67// allocates nothing per G).
68double core_charge_form_factor(int mesh,
69 const double* r,
70 const double* rab,
71 const double* rho_atc,
72 double omega,
73 double k,
74 std::vector<double>& scratch);
75
76// Sum the (spin-resolved) charge density over the real-space grid and
77// convert it to a total charge using the cell volume and grid size.
78// rho[is][ir] is the density for spin channel is. nspin0 is the number of
79// spin channels to include (2 for nspin==2, 1 otherwise).
80double sum_rho(double* const* rho,
81 const int nspin0,
82 const int nrxx,
83 const double omega,
84 const int nxyz);
85
86// Integrate a single spin channel rho_in over the grid to obtain the
87// electron number, scaled by omega / nxyz. Reduction over the pool is
88// performed internally under __MPI.
89double cal_rho2ne(const double* rho_in,
90 const int nrxx,
91 const double omega,
92 const int nxyz);
93
94// Check that the charge density integrates to the target electron number.
95// rho[is][ir] is the density for spin channel is. For nspin == 1 or 4 the
96// total density in rho[0] is compared with nelec; for nspin == 2 the spin-up
97// (rho[0]) and spin-down (rho[1]) channels must each integrate to a
98// non-negative number and their sum must match nelec. A mismatch emits a
99// warning; a negative spin-channel electron number aborts the run.
100void check_rho(double* const* rho,
101 const int nspin,
102 const int nrxx,
103 const double omega,
104 const int nxyz,
105 const double nelec);
106
107// Non-linear core correction: Fourier transform of the (numeric) core
108// charge. gg_uniq / ngg supply the reciprocal grid shells previously read
109// from Charge::rhopw.
111struct NlcCtx
112{
113 bool numeric;
114 double omega;
115 double tpiba2;
116 int mesh;
117 const double* r;
118 const double* rab;
119 const double* rhoc;
120 const double* gg_uniq;
121 int ngg;
122};
123
124void non_linear_core_correction(const NlcCtx& ctx,
125 double* rhocg);
126
127} // namespace module_charge
128
129#endif // CHG_TOOLS_H
Definition complexmatrix.h:11
3 elements vector
Definition vector3.h:21
A class which can convert a function of "r" to the corresponding linear superposition of plane waves ...
Definition pw_basis.h:60
Provide the basic information about unitcell.
Definition unitcell.h:16
Definition clebsch_gordan_coeff.cpp:8
Definition pw_op.cpp:3
Charge-density symmetrization free functions.
Definition charge.h:18
void non_linear_core_correction(const NlcCtx &ctx, double *rhocg)
Definition chg_tools.cpp:175
void set_rho_core(const UnitCell &ucell, const ModuleBase::ComplexMatrix &structure_factor, const bool *numeric, double *rho_core, std::complex< double > *rhog_core, const ModulePW::PW_Basis &rhopw)
Definition chg_tools.cpp:259
double core_charge_form_factor(int mesh, const double *r, const double *rab, const double *rho_atc, double omega, double k, std::vector< double > &scratch)
Definition chg_tools.cpp:365
double cal_rho2ne(const double *rho_in, const int nrxx, const double omega, const int nxyz)
Definition chg_tools.cpp:111
void check_rho(double *const *rho, const int nspin, const int nrxx, const double omega, const int nxyz, const double nelec)
Definition chg_tools.cpp:131
void set_drho_core(const UnitCell &ucell, int iat, int dir, const ModuleBase::Vector3< double > &q_cart, const ModulePW::PW_Basis &rhopw, std::vector< std::complex< double > > &drhoc_g)
Definition chg_tools.cpp:385
double sum_rho(double *const *rho, const int nspin0, const int nrxx, const double omega, const int nxyz)
Definition chg_tools.cpp:28
Radial grid and density data for non-linear core correction.
Definition chg_tools.h:112
int mesh
radial mesh size
Definition chg_tools.h:116
bool numeric
whether the pseudo-potential has numeric data
Definition chg_tools.h:113
double omega
cell volume
Definition chg_tools.h:114
const double * r
radial grid points
Definition chg_tools.h:117
const double * gg_uniq
unique |G|^2 values
Definition chg_tools.h:120
const double * rhoc
core charge on the radial grid
Definition chg_tools.h:119
double tpiba2
2*pi/alat squared
Definition chg_tools.h:115
int ngg
number of unique |G|^2 shells
Definition chg_tools.h:121
const double * rab
radial grid weights
Definition chg_tools.h:118