Skip to content

Commit a414bba

Browse files
committed
update grad and lapl
1 parent 681a7a7 commit a414bba

File tree

7 files changed

+62
-41
lines changed

7 files changed

+62
-41
lines changed

source/Makefile.Objects

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,6 @@ OBJS_TENSOR=tensor.o\
718718

719719
OBJS_LR=lr_util.o\
720720
lr_util_hcontainer.o\
721-
lr_util_xc.o\
722721
AX_parallel.o\
723722
AX_serial.o\
724723
dm_trans_parallel.o\

source/module_lr/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ if(ENABLE_LCAO)
77
list(APPEND objects
88
utils/lr_util.cpp
99
utils/lr_util_hcontainer.cpp
10-
utils/lr_util_xc.cpp
1110
AX/AX_parallel.cpp
1211
AX/AX_serial.cpp
1312
dm_trans/dm_trans_parallel.cpp

source/module_lr/potentials/pot_hxc_lrtd.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "module_hamilt_general/module_xc/xc_functional.h"
77
#include <set>
88
#include "module_lr/utils/lr_util.h"
9+
#include "module_lr/utils/lr_util_xc.hpp"
910
#include "module_io/cube_io.h"
1011
#include "module_hamilt_pw/hamilt_pwdft/global.h" // tmp, for pgrid
1112
#define FXC_PARA_TYPE const double* const rho, ModuleBase::matrix& v_eff, const std::vector<int>& ispin_op = { 0,0 }

source/module_lr/potentials/xc_kernel.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "module_parameter/parameter.h"
44
#include "module_base/timer.h"
55
#include "module_lr/utils/lr_util.h"
6+
#include "module_lr/utils/lr_util_xc.hpp"
67
#ifdef USE_LIBXC
78
#include <xc.h>
89
#include "module_hamilt_general/module_xc/xc_functional_libxc.h"
@@ -184,7 +185,7 @@ void LR::KernelXC::f_xc_libxc(const int& nspin, const double& omega, const doubl
184185
// + v2s2.at(ir * 6 + 3) * sigma[ir * 3]; //down-down
185186
// }
186187
// for (int isig = 0;isig < 3;++isig)
187-
// LR_Util::laplace(v2sigma2_sigma_r.data() + isig * nrxx, v2sigma2_sigma_r.data() + isig * nrxx, *(chg_gs->rhopw), tpiba2);
188+
// LR_Util::lapl(v2sigma2_sigma_r.data() + isig * nrxx, v2sigma2_sigma_r.data() + isig * nrxx, *(chg_gs->rhopw), tpiba2);
188189
// // 3. $\nabla^2(v^\sigma)$
189190
// std::vector<double> lap_vsigma(3 * nrxx);
190191
// for (int ir = 0;ir < nrxx;++ir)
@@ -194,7 +195,7 @@ void LR::KernelXC::f_xc_libxc(const int& nspin, const double& omega, const doubl
194195
// lap_vsigma[2 * nrxx + ir] = vs.at(ir * 3 + 2) * 2.0;
195196
// }
196197
// for (int isig = 0;isig < 3;++isig)
197-
// LR_Util::laplace(lap_vsigma.data() + isig * nrxx, lap_vsigma.data() + isig * nrxx, *(chg_gs->rhopw), tpiba2);
198+
// LR_Util::lapl(lap_vsigma.data() + isig * nrxx, lap_vsigma.data() + isig * nrxx, *(chg_gs->rhopw), tpiba2);
198199
// // add to v2rho2
199200
// BlasConnector::axpy(3 * nrxx, 1.0, v2r2.data(), 1, to_mul_rho_.data(), 1);
200201
// BlasConnector::axpy(3 * nrxx, -1.0, div_v2rhosigma_gdrho_r.data(), 1, to_mul_rho_.data(), 1);

source/module_lr/utils/lr_util.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
using DAT = container::DataType;
1313
using DEV = container::DeviceType;
1414

15+
#ifndef TO_COMPLEX_H
16+
#define TO_COMPLEX_H
17+
template <typename T> struct ToComplex;
18+
template <> struct ToComplex<double> { using type = std::complex<double>; };
19+
template <> struct ToComplex<std::complex<double>> { using type = std::complex<double>; };
20+
template <> struct ToComplex<float> { using type = std::complex<float>; };
21+
template <> struct ToComplex<std::complex<float>> { using type = std::complex<float>; };
22+
#endif
23+
1524
namespace LR_Util
1625
{
1726
/// =====================PHYSICS====================
@@ -36,15 +45,7 @@ namespace LR_Util
3645
std::pair<ModuleBase::matrix, std::vector<std::pair<int, int>>>
3746
set_ix_map_diagonal(bool mode, int nc, int nv);
3847

39-
/// operators to calculate XC kernels
40-
void grad(const double* rhor,
41-
ModuleBase::Vector3<double>* gdr,
42-
const ModulePW::PW_Basis& rho_basis,
43-
const double& tpiba);
44-
void laplace(const double* rhor,
45-
double* lapn,
46-
const ModulePW::PW_Basis& rho_basis,
47-
const double& tpiba2);
48+
// Operators to calculate xc kernel have been moved into lr_util_xc.hpp.
4849
/// =================ALGORITHM====================
4950

5051
//====== newers and deleters========

source/module_lr/utils/lr_util_xc.cpp

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#pragma once
2+
#include "lr_util.h"
3+
namespace LR_Util
4+
{
5+
template<typename T>
6+
void grad(const T* rhor,
7+
ModuleBase::Vector3<T>* gdr,
8+
const ModulePW::PW_Basis& rho_basis,
9+
const double& tpiba)
10+
{
11+
std::vector<typename ToComplex<T>::type> rhog(rho_basis.npw);
12+
rho_basis.real2recip(rhor, rhog.data());
13+
XC_Functional::grad_rho(rhog.data(), gdr, &rho_basis, tpiba);
14+
}
15+
template<typename T>
16+
void grad(const std::vector<T>& rhor,
17+
std::vector<ModuleBase::Vector3<T>>& gdr,
18+
const ModulePW::PW_Basis& rho_basis,
19+
const double& tpiba)
20+
{
21+
grad(rhor.data(), gdr.data(), rho_basis, tpiba);
22+
}
23+
24+
template<typename T>
25+
void lapl(const T* rhor, T* lapn,
26+
const ModulePW::PW_Basis& rho_basis,
27+
const double& tpiba2)
28+
{
29+
ModuleBase::GlobalFunc::ZEROS(lapn, rho_basis.nrxx);
30+
std::vector<typename ToComplex<T>::type> rhog(rho_basis.npw);
31+
std::vector<T> tmp_rhor(rho_basis.nrxx);
32+
rho_basis.real2recip(rhor, rhog.data());
33+
for (int i = 0;i < 3;++i)
34+
{
35+
for (int ig = 0; ig < rho_basis.npw; ig++) { rhog[ig] *= pow(rho_basis.gcar[ig][i], 2); }
36+
rho_basis.recip2real(rhog.data(), tmp_rhor.data());
37+
for (int ir = 0; ir < rho_basis.nrxx; ir++) { lapn[ir] -= tmp_rhor[ir] * tpiba2; }
38+
}
39+
}
40+
template<typename T>
41+
void lapl(const std::vector<T>& rhor,
42+
std::vector<T>& lapn,
43+
const ModulePW::PW_Basis& rho_basis,
44+
const double& tpiba2)
45+
{
46+
lapl(rhor.data(), lapn.data(), rho_basis, tpiba2);
47+
}
48+
}

0 commit comments

Comments
 (0)