Skip to content

Commit c14b2c7

Browse files
committed
add gga cut-off
1 parent 788a887 commit c14b2c7

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

source/module_lr/potentials/xc_kernel.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,23 @@ inline void add_assign_op(const std::vector<T>& src, std::vector<T>& dst)
9393
{
9494
add_op(src, dst, dst);
9595
}
96+
template<typename Telement, typename Tscalar>
97+
inline void cutoff_grid_data_spin2(std::vector<Telement>& func, const std::vector<Tscalar>& mask)
98+
{
99+
const int& nrxx = mask.size() / 2;
100+
assert(func.size() % nrxx == 0 && func.size() / nrxx > 1);
101+
const int n_component = func.size() / nrxx;
102+
#ifdef _OPENMP
103+
#pragma omp parallel for schedule(static, 4096)
104+
#endif
105+
for (int ir = 0;ir < nrxx;++ir)
106+
{
107+
const int& i2 = 2 * ir;
108+
const int& istart = n_component * ir;
109+
std::for_each(func.begin() + istart, func.begin() + istart + n_component - 1, [&](Telement& f) { f *= mask[i2]; }); //spin-up
110+
std::for_each(func.begin() + istart + 1, func.begin() + istart + n_component, [&](Telement& f) { f *= mask[i2 + 1]; }); //spin-down
111+
}
112+
}
96113

97114
#ifdef USE_LIBXC
98115
void LR::KernelXC::f_xc_libxc(const int& nspin, const double& omega, const double& tpiba, const double* const* const rho_gs, const double* const rho_core)
@@ -191,7 +208,8 @@ void LR::KernelXC::f_xc_libxc(const int& nspin, const double& omega, const doubl
191208

192209
xc_func_set_dens_threshold(&func, rho_threshold);
193210

194-
//cut off grho if not LDA (future subfunc)
211+
//cut off function
212+
const std::vector<double> sgn = XC_Functional_Libxc::cal_sgn(rho_threshold, grho_threshold, func, nspin, nrxx, rho, sigma);
195213

196214
// Libxc interfaces overwrite (instead of add onto) the output arrays, so we need temporary copies
197215
std::vector<double> vrho_tmp(this->vrho_.size());
@@ -207,9 +225,19 @@ void LR::KernelXC::f_xc_libxc(const int& nspin, const double& omega, const doubl
207225
break;
208226
case XC_FAMILY_GGA:
209227
case XC_FAMILY_HYB_GGA:
228+
{
210229
xc_gga_vxc(&func, nrxx, rho.data(), sigma.data(), vrho_tmp.data(), vsigma_tmp.data());
211230
xc_gga_fxc(&func, nrxx, rho.data(), sigma.data(), v2rho2_tmp.data(), v2rhosigma_tmp.data(), v2sigma2_tmp.data());
231+
// std::cout << "max element of v2sigma2_tmp: " << *std::max_element(v2sigma2_tmp.begin(), v2sigma2_tmp.end()) << std::endl;
232+
// std::cout << "rho corresponding to max element of v2sigma2_tmp: " << rho[(std::max_element(v2sigma2_tmp.begin(), v2sigma2_tmp.end()) - v2sigma2_tmp.begin()) / 6] << std::endl;
233+
// cut off by sgn
234+
cutoff_grid_data_spin2(vrho_tmp, sgn);
235+
cutoff_grid_data_spin2(vsigma_tmp, sgn);
236+
cutoff_grid_data_spin2(v2rho2_tmp, sgn);
237+
cutoff_grid_data_spin2(v2rhosigma_tmp, sgn);
238+
cutoff_grid_data_spin2(v2sigma2_tmp, sgn);
212239
break;
240+
}
213241
default:
214242
throw std::domain_error("func.info->family =" + std::to_string(func.info->family)
215243
+ " unfinished in " + std::string(__FILE__) + " line " + std::to_string(__LINE__));

0 commit comments

Comments
 (0)