ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
kedf_wt.h
Go to the documentation of this file.
1#ifndef KEDF_WT_H
2#define KEDF_WT_H
3#include <cmath>
4#include <cstdio>
5#include <complex>
6#include <vector>
7
10#include "source_base/timer.h"
12
13#ifdef __CUDA
14#include <cufft.h>
15#endif
16
23{
24 public:
26 {
27 this->stress.create(3, 3);
28 }
30 {
31#ifdef __CUDA
32 this->free_gpu_buffers();
33#endif
34 }
35
36 void set_para(double dV,
37 double alpha,
38 double beta,
39 double nelec,
40 double tf_weight,
41 double vw_weight,
42 double of_wt_rho0,
43 bool of_hold_rho0,
44 bool read_kernel,
45 std::string kernel_file,
46 ModulePW::PW_Basis* pw_rho);
47
48 double get_energy(const double* const* prho, ModulePW::PW_Basis* pw_rho);
49 double get_energy_density(const double* const* prho, int is, int ir, ModulePW::PW_Basis* pw_rho);
50 void tau_wt(const double* const* prho, ModulePW::PW_Basis* pw_rho, double* rtau_wt);
51 void wt_potential(const double* const* prho, ModulePW::PW_Basis* pw_rho, ModuleBase::matrix& rpotential);
52 void get_stress(const double* const* prho, ModulePW::PW_Basis* pw_rho, double vw_weight);
53 double wt_energy = 0.;
55
56 private:
57 double wt_kernel(double eta, double tf_weight, double vw_weight);
58 double diff_linhard(double eta, double vw_weight);
59 void multi_kernel(const double* const* prho, double** rkernel_rho, double exponent, ModulePW::PW_Basis* pw_rho);
60 void read_kernel(std::string file_name, ModulePW::PW_Basis* pw_rho);
61 void fill_kernel(double tf_weight, double vw_weight, ModulePW::PW_Basis* pw_rho);
62
63 double dV_ = 0.;
64 double rho0_ = 0.; // average rho
65 bool hold_rho0_ = false;
66 double kf_ = 0.; // Fermi vector kF = (3 pi^2 rho)^(1/3)
67 double tkf_ = 0.; // 2 * kF
68 double alpha_ = 5. / 6.;
69 double beta_ = 5. / 6.;
70 // double weightWT = 1.;
71 const double c_tf_
72 = 3.0 / 10.0 * std::pow(3 * std::pow(M_PI, 2.0), 2.0 / 3.0)
73 * 2; // 10/3*(3*pi^2)^{2/3}, multiply by 2 to convert unit from Hartree to Ry, finally in Ry*Bohr^(-2)
74 double wt_coef_ = 0.; // coefficient of WT kernel
75 std::vector<double> kernel_;
76
77#ifdef __CUDA
78 void multi_kernel_gpu(const double* const* prho, double** rkernel_rho, int nspin,
79 double exponent, ModulePW::PW_Basis* pw_rho);
80 void free_gpu_buffers();
81
82 // Persistent GPU buffers (lazily allocated once, reused across SCF iterations)
83 double* d_rho_ = nullptr; // real-space input (nrxx doubles)
84 cufftHandle cufft_plan_fwd_ = 0; // cuFFT forward plan
85 cufftHandle cufft_plan_bwd_ = 0; // cuFFT backward plan
86 double* d_result_ = nullptr; // real-space output (nrxx doubles)
87 double* d_kernel_ = nullptr; // WT kernel on device (npw doubles)
88
89 bool gpu_allocated_ = false;
90#endif
91};
92#endif
double alpha_
Definition kedf_wt.h:68
const double c_tf_
Definition kedf_wt.h:72
bool hold_rho0_
Definition kedf_wt.h:65
void set_para(double dV, double alpha, double beta, double nelec, double tf_weight, double vw_weight, double of_wt_rho0, bool of_hold_rho0, bool read_kernel, std::string kernel_file, ModulePW::PW_Basis *pw_rho)
Set the parameters of WT KEDF, and initialize kernel.
Definition kedf_wt.cpp:25
double diff_linhard(double eta, double vw_weight)
The derivative of the WT kernel.
Definition kedf_wt.cpp:432
std::vector< double > kernel_
Definition kedf_wt.h:75
double wt_energy
Definition kedf_wt.h:53
ModuleBase::matrix stress
Definition kedf_wt.h:54
double tkf_
Definition kedf_wt.h:67
void fill_kernel(double tf_weight, double vw_weight, ModulePW::PW_Basis *pw_rho)
Fill the kernel (this->kernel_).
Definition kedf_wt.cpp:503
void tau_wt(const double *const *prho, ModulePW::PW_Basis *pw_rho, double *rtau_wt)
Get the kinetic energy of WT KEDF, and add it onto rtau_wt.
Definition kedf_wt.cpp:153
double wt_coef_
Definition kedf_wt.h:74
void read_kernel(std::string file_name, ModulePW::PW_Basis *pw_rho)
Read the kernel from file.
Definition kedf_wt.cpp:520
void wt_potential(const double *const *prho, ModulePW::PW_Basis *pw_rho, ModuleBase::matrix &rpotential)
Get the potential of WT KEDF, and add it into rpotential, and the WT energy will be calculated and st...
Definition kedf_wt.cpp:191
double dV_
Definition kedf_wt.h:63
double get_energy(const double *const *prho, ModulePW::PW_Basis *pw_rho)
Get the energy of WT KEDF.
Definition kedf_wt.cpp:75
KEDF_WT()
Definition kedf_wt.h:25
~KEDF_WT()
Definition kedf_wt.h:29
void get_stress(const double *const *prho, ModulePW::PW_Basis *pw_rho, double vw_weight)
Get the stress of WT KEDF, and store it into this->stress.
Definition kedf_wt.cpp:260
double kf_
Definition kedf_wt.h:66
double wt_kernel(double eta, double tf_weight, double vw_weight)
Calculate the WT kernel according to Lindhard response function.
Definition kedf_wt.cpp:378
double get_energy_density(const double *const *prho, int is, int ir, ModulePW::PW_Basis *pw_rho)
Get the energy density of LKT KEDF.
Definition kedf_wt.cpp:126
double rho0_
Definition kedf_wt.h:64
double beta_
Definition kedf_wt.h:69
void multi_kernel(const double *const *prho, double **rkernel_rho, double exponent, ModulePW::PW_Basis *pw_rho)
Calculate \int{W(r-r')rho^{exponent}(r') dr'}.
Definition kedf_wt.cpp:463
Definition matrix.h:15
A class which can convert a function of "r" to the corresponding linear superposition of plane waves ...
Definition pw_basis.h:60