Skip to content

Commit 0056c36

Browse files
authored
roll back to original grad_rho
1 parent 4725616 commit 0056c36

3 files changed

Lines changed: 5 additions & 112 deletions

File tree

source/source_hamilt/module_surchem/cal_vcav.cpp

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,6 @@
44
#include "surchem.h"
55

66

7-
static void local_grad_rho(const UnitCell& ucell,
8-
const ModulePW::PW_Basis* rho_basis,
9-
const std::complex<double>* rho_G,
10-
ModuleBase::Vector3<double>* grad_R,
11-
std::complex<double>* aux_G,
12-
double* aux_R)
13-
{
14-
15-
for (int i = 0; i < 3; ++i)
16-
{
17-
// 1. iG * rho(G)
18-
for (int ig = 0; ig < rho_basis->npw; ig++) {
19-
aux_G[ig] = ModuleBase::IMAG_UNIT * rho_G[ig] * rho_basis->gcar[ig][i];
20-
}
21-
22-
// 2. FFT: G -> R
23-
24-
rho_basis->recip2real(aux_G, aux_R);
25-
26-
// 3. 2pi/a
27-
for (int ir = 0; ir < rho_basis->nrxx; ir++) {
28-
grad_R[ir][i] = aux_R[ir] * ucell.tpiba;
29-
}
30-
}
31-
}
32-
33-
347
void lapl_rho(const double& tpiba2,
358
const std::complex<double>* rhog,
369
double* lapn,
@@ -111,10 +84,7 @@ void surchem::createcavity(const UnitCell& ucell,
11184
ModuleBase::GlobalFunc::ZEROS(lapn, rho_basis->nrxx);
11285

11386

114-
std::complex<double> *aux_G = new std::complex<double>[rho_basis->npw];
115-
double *aux_R = new double[rho_basis->nrxx];
116-
117-
local_grad_rho(ucell, rho_basis, ps_totn, nablan, aux_G, aux_R);
87+
XC_Functional::grad_rho(ps_totn, nablan, rho_basis, ucell.tpiba);
11888

11989
// | \nabla n |^2
12090
for (int ir = 0; ir < rho_basis->nrxx; ir++)
@@ -164,7 +134,7 @@ void surchem::createcavity(const UnitCell& ucell,
164134
ModuleBase::Vector3<double> *ggn = new ModuleBase::Vector3<double>[rho_basis->nrxx];
165135

166136

167-
local_grad_rho(ucell, rho_basis, inv_gn, ggn, aux_G, aux_R);
137+
XC_Functional::grad_rho(inv_gn, ggn, rho_basis, ucell.tpiba);
168138

169139
// --------------------------------------------------------
170140
// add -(\nabla n . \nabla(1/ |\nabla n|)) to Vcav
@@ -181,8 +151,7 @@ void surchem::createcavity(const UnitCell& ucell,
181151
}
182152

183153

184-
delete[] aux_G;
185-
delete[] aux_R;
154+
186155
delete[] nablan;
187156
delete[] nablan_2;
188157
delete[] sqrt_nablan_2;

source/source_hamilt/module_surchem/cal_vel.cpp

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,6 @@
44
#include "surchem.h"
55

66

7-
static void local_grad_rho_vel(const UnitCell& ucell,
8-
const ModulePW::PW_Basis* rho_basis,
9-
const std::complex<double>* rho_G,
10-
ModuleBase::Vector3<double>* grad_R,
11-
std::complex<double>* aux_G,
12-
double* aux_R)
13-
{
14-
for (int i = 0; i < 3; ++i)
15-
{
16-
// 1. iG * rho(G)
17-
for (int ig = 0; ig < rho_basis->npw; ig++) {
18-
aux_G[ig] = ModuleBase::IMAG_UNIT * rho_G[ig] * rho_basis->gcar[ig][i];
19-
}
20-
21-
// 2. FFT: G -> R
22-
rho_basis->recip2real(aux_G, aux_R);
23-
24-
// 3. 2pi/a
25-
for (int ir = 0; ir < rho_basis->nrxx; ir++) {
26-
grad_R[ir][i] = aux_R[ir] * ucell.tpiba;
27-
}
28-
}
29-
}
307

318
void shape_gradn(const double* PS_TOTN_real, const ModulePW::PW_Basis* rho_basis, double* eprime)
329
{
@@ -40,24 +17,6 @@ void shape_gradn(const double* PS_TOTN_real, const ModulePW::PW_Basis* rho_basis
4017
}
4118
}
4219

43-
static void local_grad_rho_vel_tpiba(const double tpiba,
44-
const ModulePW::PW_Basis* rho_basis,
45-
const std::complex<double>* rho_G,
46-
ModuleBase::Vector3<double>* grad_R,
47-
std::complex<double>* aux_G,
48-
double* aux_R)
49-
{
50-
for (int i = 0; i < 3; ++i)
51-
{
52-
for (int ig = 0; ig < rho_basis->npw; ig++) {
53-
aux_G[ig] = ModuleBase::IMAG_UNIT * rho_G[ig] * rho_basis->gcar[ig][i];
54-
}
55-
rho_basis->recip2real(aux_G, aux_R);
56-
for (int ir = 0; ir < rho_basis->nrxx; ir++) {
57-
grad_R[ir][i] = aux_R[ir] * tpiba;
58-
}
59-
}
60-
}
6120

6221
void eps_pot(const double* PS_TOTN_real,
6322
const double& tpiba,
@@ -80,17 +39,7 @@ void eps_pot(const double* PS_TOTN_real,
8039
double *phisq = new double[rho_basis->nrxx];
8140

8241

83-
84-
std::complex<double> *aux_G = new std::complex<double>[rho_basis->npw];
85-
double *aux_R = new double[rho_basis->nrxx];
86-
87-
88-
local_grad_rho_vel_tpiba(tpiba, rho_basis, phi, nabla_phi, aux_G, aux_R);
89-
90-
91-
delete[] aux_G;
92-
delete[] aux_R;
93-
42+
XC_Functional::grad_rho(phi, nabla_phi, rho_basis, tpiba);
9443

9544

9645
for (int ir = 0; ir < rho_basis->nrxx; ir++)
@@ -174,7 +123,6 @@ void surchem::cal_vel(const UnitCell& cell,
174123
this->Ael *= cell.omega / rho_basis->nxyz;
175124

176125
// the 2nd item of tmp_Vel
177-
// eps_pot internally calls shape_gradn and now the SAFE local_grad_rho_vel_tpiba
178126
eps_pot(PS_TOTN_real, cell.tpiba, Sol_phi, rho_basis, epsilon, epspot);
179127

180128
for (int i = 0; i < rho_basis->nrxx; i++)

source/source_hamilt/module_surchem/minimize_cg.cpp

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -177,30 +177,6 @@ void surchem::minimize_cg(const UnitCell& ucell,
177177
delete[] aux_grad_grad_phi_real;
178178
}
179179

180-
void helper_grad_rho(const UnitCell& ucell,
181-
const ModulePW::PW_Basis* rho_basis,
182-
const std::complex<double>* rho_G, // G
183-
ModuleBase::Vector3<double>* grad_rho_R, // R
184-
std::complex<double>* buffer_G,
185-
double* buffer_R)
186-
{
187-
for (int i = 0; i < 3; ++i)
188-
{
189-
190-
for (int ig = 0; ig < rho_basis->npw; ig++)
191-
{
192-
buffer_G[ig] = ModuleBase::IMAG_UNIT * rho_G[ig] * rho_basis->gcar[ig][i];
193-
}
194-
195-
rho_basis->recip2real(buffer_G, buffer_R);
196-
197-
198-
for (int ir = 0; ir < rho_basis->nrxx; ir++)
199-
{
200-
grad_rho_R[ir][i] = buffer_R[ir] * ucell.tpiba;
201-
}
202-
}
203-
}
204180

205181
void surchem::Leps2(const UnitCell& ucell,
206182
const ModulePW::PW_Basis* rho_basis,
@@ -217,7 +193,7 @@ void surchem::Leps2(const UnitCell& ucell,
217193
double* aux_R) // size: nrxx
218194
{
219195

220-
helper_grad_rho(ucell, rho_basis, phi, grad_phi_R, aux_G, aux_R);
196+
XC_Functional::grad_rho(phi, grad_phi_R, rho_basis, ucell.tpiba);
221197

222198

223199
for (int ir = 0; ir < rho_basis->nrxx; ir++)

0 commit comments

Comments
 (0)