forked from deepmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
98 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 52 additions & 33 deletions
85
source/module_beyonddft/operator_casida/operatorA_hxc.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,75 @@ | ||
#pragma once | ||
#include "operatorA_hxc.h" | ||
#include <vector> | ||
#include "module_base/blas_connector.h" | ||
#include "utils/lr_util.h" | ||
|
||
#include "module_beyonddft/utils/lr_util.h" | ||
#include "module_hamilt_lcao/hamilt_lcaodft/DM_gamma_2d_to_grid.h" | ||
#include "module_beyonddft/density/dm_trans.h" | ||
#include "module_beyonddft/AX/AX.h" | ||
namespace hamilt | ||
{ | ||
// for double | ||
template<typename T, typename Device> | ||
void OperatorA_Hxc<T, Device>::act() const | ||
template<typename FPTYPE, typename Device> | ||
psi::Psi<FPTYPE> OperatorA_Hxc<FPTYPE, Device>::act(const psi::Psi<FPTYPE>& psi_in) const | ||
{ | ||
auto block2grid = [](std::vector<ModuleBase::matrix> block, double*** grid)->void {}; | ||
// gamma-only now | ||
// 1. transition density matrix | ||
std::vector<ModuleBase::matrix> dm_trans_2d = cal_dm_trans_blas(*px, *pc); | ||
double*** dm_trans_grid = LR_Util::new_p3(nspin, naos_local_grid, naos_local_grid); | ||
block2grid(dm_trans_2d, dm_trans_grid); | ||
// multi-k needs k-to-R FT | ||
#ifdef __MPI | ||
std::vector<container::Tensor> dm_trans_2d = cal_dm_trans_pblas(psi_in, *pX, *psi_ks, *pc, naos, nocc, nvirt, *pmat); | ||
#else | ||
std::vector<container::Tensor> dm_trans_2d = cal_dm_trans_blas(*pX, *pc); | ||
#endif | ||
double*** dm_trans_grid; | ||
LR_Util::new_p3(dm_trans_grid, nsk, gridt->lgd, gridt->lgd); | ||
//2d block to grid | ||
DMgamma_2dtoGrid dm2g; | ||
#ifdef __MPI | ||
dm2g.setAlltoallvParameter(pmat->comm_2D, naos, pmat->blacs_ctxt, pmat->nb, gridt->lgd, gridt->trace_lo); | ||
#endif | ||
dm2g.cal_dk_gamma_from_2D(LR_Util::ten2mat_double(dm_trans_2d), dm_trans_grid, nsk, naos, gridt->lgd, GlobalV::ofs_running); | ||
|
||
// 2. transition electron density | ||
double** rho_trans = LR_Util::new_p2(nspin, this->gint_g->nbxx); // is nbxx local grid num ? | ||
double** rho_trans; | ||
LR_Util::new_p2(rho_trans, nsk, this->pot->nrxx); | ||
Gint_inout inout_rho(dm_trans_grid, rho_trans, Gint_Tools::job_type::rho); | ||
this->gint_g->cal_gint(&inout_rho); | ||
this->gg->cal_gint(&inout_rho); | ||
|
||
// 3. v_hxc = f_hxc * rho_trans | ||
this->pot->update_from_charge(rho_trans, GlobalC::ucell); | ||
ModuleBase::matrix vr_hxc(nsk, this->pot->nrxx); //grid | ||
this->pot->cal_v_eff(rho_trans, &GlobalC::ucell, vr_hxc); | ||
|
||
// 4. V^{Hxc}_{\mu,\nu}=\int{dr} \phi_\mu(r) v_{Hxc}(r) \phi_\mu(r) | ||
// loop for nspin, or use current spin (how?) | ||
// results are stored in gint_g->pvpR_grid(gamma_only) | ||
// loop for nsk, or use current spin (how?) | ||
// results are stored in gg->pvpR_grid(gamma_only) | ||
// or gint_k->pvpR_reduced(multi_k) | ||
|
||
std::vector<ModuleBase::matrix> v_hxc_local(nspin); // 2D local matrix) | ||
for (int is = 0;is < this->nspin;++is) | ||
std::vector<ModuleBase::matrix> v_hxc_2d(nsk); | ||
this->gg->init_pvpR_grid(gridt->lgd); | ||
auto setter = [this](const int& iw1_all, const int& iw2_all, const double& v, double* out) { | ||
const int ir = this->pmat->global2local_row(iw1_all); | ||
const int ic = this->pmat->global2local_col(iw2_all); | ||
out[ic * this->pmat->nrow + ir] += v; | ||
}; | ||
for (int is = 0;is < this->nsk;++is) | ||
{ | ||
const double* v1_hxc_grid = this->pot->get_effective_v(is); | ||
Gint_intout inout_vlocal(v1_hxc_grid, is, Gint_Tools::job_type::vlocal); | ||
// this->gint_g->cal_gint(&inout); | ||
bool new_e_iteration = false; // what is this? | ||
this->gint_g->cal_vlocal(&inout_vlocal, new_e_iteration); | ||
|
||
// grid-to-2d needs refactor ! | ||
v_hxc_2d[is].create(naos_local_row, naos_local_col); | ||
//LR_Util::grid2block(this->px, this->pc, this->gint_g->pvpR_grid, v_hxc_local.c); | ||
ModuleBase::GlobalFunc::ZEROS(this->gg->get_pvpR_grid(), gridt->lgd * gridt->lgd); | ||
double* vr_hxc_is = &vr_hxc.c[is * this->pot->nrxx]; //current spin | ||
Gint_inout inout_vlocal(vr_hxc_is, Gint_Tools::job_type::vlocal); | ||
this->gg->cal_gint(&inout_vlocal); | ||
v_hxc_2d[is].create(pmat->get_col_size(), pmat->get_row_size()); | ||
this->gg->vl_grid_to_2D(this->gg->get_pvpR_grid(), *pmat, this->gridt->lgd, (is == 0), v_hxc_2d[is].c, setter); | ||
} | ||
this->gg->delete_pvpR_grid(); | ||
|
||
// clear useless matrices | ||
LR_Util::delete_p3(dm_trans_grid, nsk, gridt->lgd); | ||
LR_Util::delete_p2(rho_trans, nsk); | ||
|
||
// 5. [AX]^{Hxc}_{ai}=\sum_{\mu,\nu}c^*_{a,\mu,}V^{Hxc}_{\mu,\nu}c_{\nu,i} | ||
// use 2 pzgemms | ||
this->cal_AX_cVc(v_hxc_2d, this->px); | ||
// result is in which "psi" ? X? | ||
|
||
// final clear | ||
LR_Util::delete_p3(dm_trans_grid); | ||
LR_Util::delete_p2(rho_trans); | ||
return; | ||
#ifdef __MPI | ||
return cal_AX_pblas(LR_Util::mat2ten_double(v_hxc_2d), *this->pmat, *this->psi_ks, *this->pc, naos, nocc, nvirt, *this->pX); | ||
#else | ||
return cal_AX_blas(LR_Util::mat2ten_double(v_hxc_2d), *this->psi_ks, nocc); | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters