Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion source/source_esolver/esolver_fp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ void ESolver_FP::before_all_runners(BaseCell& basecell, const Input_para& inp)

this->inp_ = &inp;

SurchemParameters surchem_parameters;
surchem_parameters.eb_k = inp.eb_k;
surchem_parameters.tau = inp.tau;
surchem_parameters.sigma_k = inp.sigma_k;
surchem_parameters.nc_k = inp.nc_k;
this->solvent.set_parameters(surchem_parameters);

XCFunctionalParameters xc_parameters;
xc_parameters.xc_temperature = inp.xc_temperature;
xc_parameters.exx_fock_alpha = inp.exx_fock_alpha;
xc_parameters.exx_erfc_alpha = inp.exx_erfc_alpha;
xc_parameters.xc_exch_ext = inp.xc_exch_ext;
xc_parameters.xc_corr_ext = inp.xc_corr_ext;
XC_Functional::set_runtime_parameters(xc_parameters);

ModuleBase::TITLE("ESolver_FP", "before_all_runners");

//! 1) read pseudopotentials
Expand Down Expand Up @@ -211,7 +226,7 @@ void ESolver_FP::before_scf(UnitCell& ucell, const int istep)
//! calculate ewald energy
if (!this->inp_->test_skip_ewald)
{
this->pelec->f_en.ewald_energy = H_Ewald_pw::compute_ewald(ucell, this->pw_rhod, this->sf.strucFac);
this->pelec->f_en.ewald_energy = H_Ewald_pw::compute_ewald(ucell, this->pw_rhod, this->sf.strucFac, this->inp_->test_energy, GlobalV::ofs_running);
}

//! set direction of magnetism, used in non-collinear case
Expand Down
7 changes: 6 additions & 1 deletion source/source_esolver/esolver_ks_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
this->pw_rho->nx, this->pw_rho->ny, this->pw_rho->nz,
0, 0, this->pw_big->nbzp_start,
this->pw_big->nbx, this->pw_big->nby, this->pw_big->nbzp,
orb_.Phi, ucell, this->gd));
orb_.Phi, ucell, this->gd,
this->inp_->nspin,
PARAM.globalv.gamma_only_local,
PARAM.globalv.domag,
this->inp_->device == "gpu",
this->inp_->nstream));
ModuleGint::Gint::set_gint_info(gint_info_.get());

// 7) For each atom, calculate the adjacent atoms in different cells
Expand Down
7 changes: 6 additions & 1 deletion source/source_esolver/esolver_lr_lcao_bse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ void ESolver_BSE<T, TR>::before_all_runners(BaseCell& basecell, const Input_para
this->pw_big->nbzp,
this->orb_.Phi,
ucell,
this->gd));
this->gd,
inp.nspin,
PARAM.globalv.gamma_only_local,
PARAM.globalv.domag,
inp.device == "gpu",
inp.nstream));
ModuleGint::Gint::set_gint_info(this->gint_info_.get());

this->pot.resize(this->nspin, nullptr);
Expand Down
7 changes: 6 additions & 1 deletion source/source_esolver/esolver_lr_lcao_tddft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,12 @@ void ModuleESolver::ESolver_LR<T, TR>::initialize_from_unitcell_(UnitCell& ucell
this->pw_big->nbzp,
orb.Phi,
ucell,
this->gd));
this->gd,
this->inp_->nspin,
PARAM.globalv.gamma_only_local,
PARAM.globalv.domag,
this->inp_->device == "gpu",
this->inp_->nstream));
ModuleGint::Gint::set_gint_info(gint_info_.get());
// if EXX from scratch, init 2-center integral and calculate Cs, Vs
#ifdef __EXX
Expand Down
7 changes: 6 additions & 1 deletion source/source_esolver/lcao_others.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ void ESolver_KS_LCAO<TK, TR>::others(BaseCell& basecell, const int istep)
this->pw_big->nbzp,
orb_.Phi,
ucell,
this->gd));
this->gd,
this->inp_->nspin,
gamma_only_local,
PARAM.globalv.domag,
this->inp_->device == "gpu",
this->inp_->nstream));
ModuleGint::Gint::set_gint_info(gint_info_.get());

// (2)For each atom, calculate the adjacent atoms in different cells
Expand Down
48 changes: 25 additions & 23 deletions source/source_hamilt/module_ewald/h_ewald_pw.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "h_ewald_pw.h"
#include "source_base/global_function.h"
#include "source_base/parallel_comm.h"
#include "source_io/module_parameter/parameter.h"
#include "source_base/mymath.h" // use heapsort
#include "source_io/module_parameter/parameter.h"
#include "dnrm2.h"
#include "source_base/parallel_reduce.h"
#include "source_base/constants.h"
Expand All @@ -27,7 +26,9 @@ int H_Ewald_pw::estimate_mxr(const double &rmax, const ModuleBase::Matrix3 &bg)

double H_Ewald_pw::compute_ewald(const UnitCell& cell,
const ModulePW::PW_Basis* rho_basis,
const ModuleBase::ComplexMatrix& strucFac)
const ModuleBase::ComplexMatrix& strucFac,
const int test_energy,
std::ofstream& output_stream)
{
ModuleBase::TITLE("H_Ewald_pw","compute_ewald");
ModuleBase::timer::start("H_Ewald_pw","compute_ewald");
Expand Down Expand Up @@ -73,9 +74,9 @@ double H_Ewald_pw::compute_ewald(const UnitCell& cell,
charge += cell.atoms[it].na * cell.atoms[it].ncpp.zv;//mohan modify 2007-11-7
}
}
if(PARAM.inp.test_energy)
if(test_energy)
{
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Total ionic charge",charge);
ModuleBase::GlobalFunc::OUT(output_stream,"Total ionic charge",charge);
}

// (2) calculate the converged value: alpha
Expand All @@ -94,10 +95,10 @@ double H_Ewald_pw::compute_ewald(const UnitCell& cell,
erfc(sqrt(cell.tpiba2 * rho_basis->ggecut / 4.0 / alpha));
}
while (upperbound > 1.0e-7);
if(PARAM.inp.test_energy)
if(test_energy)
{
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"alpha",alpha);
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Upper bound",upperbound);
ModuleBase::GlobalFunc::OUT(output_stream,"alpha",alpha);
ModuleBase::GlobalFunc::OUT(output_stream,"Upper bound",upperbound);
}

// G-space sum here.
Expand All @@ -123,7 +124,7 @@ double H_Ewald_pw::compute_ewald(const UnitCell& cell,
// but that's not the term "gamma_only" I want to use in LCAO,
fact = 1.0;

//GlobalV::ofs_running << "\n pwb.gstart = " << pwb.gstart << std::endl;
//output_stream << "\n pwb.gstart = " << pwb.gstart << std::endl;
const int ig0 = rho_basis->ig_gge0;
for (int ig = 0; ig < rho_basis->npw; ig++)
{
Expand Down Expand Up @@ -165,9 +166,9 @@ double H_Ewald_pw::compute_ewald(const UnitCell& cell,
rmax = 4.0 / sqrt(alpha) / cell.lat0;
mxr = H_Ewald_pw::estimate_mxr(rmax, cell.G);

if(PARAM.inp.test_energy)
if(test_energy)
{
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"mxr",mxr);
ModuleBase::GlobalFunc::OUT(output_stream,"mxr",mxr);
}
std::vector<ModuleBase::Vector3<double>> vec_r(mxr);
std::vector<double> vec_r2(mxr);
Expand All @@ -177,9 +178,9 @@ double H_Ewald_pw::compute_ewald(const UnitCell& cell,
double* r2 = vec_r2.data();

#ifdef __MPI
if(PARAM.inp.test_energy)
if(test_energy)
{
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"rmax(unit lat0)",rmax);
ModuleBase::GlobalFunc::OUT(output_stream,"rmax(unit lat0)",rmax);
}

int size = 0;
Expand Down Expand Up @@ -209,11 +210,11 @@ double H_Ewald_pw::compute_ewald(const UnitCell& cell,
// calculate tau[na1]-tau[na2]
dtau = cell.atoms[it1].tau[ia1] - cell.atoms[it2].tau[ia2];
// generates nearest-neighbors shells
H_Ewald_pw::rgen(dtau, rmax, irr, cell.latvec, cell.G, r, r2, mxr, nrm);
H_Ewald_pw::rgen(dtau, rmax, irr, cell.latvec, cell.G, r, r2, mxr, nrm, test_energy);
// at-->cell.latvec, bg-->G
// and sum to the real space part

if(PARAM.inp.test_energy>1)
if(test_energy>1)
{
ModuleBase::GlobalFunc::OUT("dtau.x",dtau.x);
ModuleBase::GlobalFunc::OUT("dtau.y",dtau.y);
Expand All @@ -228,7 +229,7 @@ double H_Ewald_pw::compute_ewald(const UnitCell& cell,
erfc(sqrt(alpha) * rr) / rr;
}
}
if (PARAM.inp.test_energy>1)
if (test_energy>1)
{
ModuleBase::GlobalFunc::OUT("ewaldr",ewaldr);
}
Expand All @@ -237,7 +238,7 @@ double H_Ewald_pw::compute_ewald(const UnitCell& cell,
#else
if (rho_basis->ig_gge0 >= 0)
{
if(PARAM.inp.test_energy) ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"rmax(unit lat0)",rmax);
if(test_energy) ModuleBase::GlobalFunc::OUT(output_stream,"rmax(unit lat0)",rmax);
// with this choice terms up to ZiZj*erfc(4) are counted (erfc(4)=2x10^-8
int nt1=0;
int nt2=0;
Expand All @@ -253,11 +254,11 @@ double H_Ewald_pw::compute_ewald(const UnitCell& cell,
//calculate tau[na]-tau[nb]
dtau = cell.atoms[nt1].tau[na] - cell.atoms[nt2].tau[nb];
//generates nearest-neighbors shells
H_Ewald_pw::rgen(dtau, rmax, irr, cell.latvec, cell.G, r, r2, mxr, nrm);
H_Ewald_pw::rgen(dtau, rmax, irr, cell.latvec, cell.G, r, r2, mxr, nrm, test_energy);
// at-->cell.latvec, bg-->G
// and sum to the real space part

if (PARAM.inp.test_energy>1)
if (test_energy>1)
{
ModuleBase::GlobalFunc::OUT("dtau.x",dtau.x);
ModuleBase::GlobalFunc::OUT("dtau.y",dtau.y);
Expand All @@ -272,7 +273,7 @@ double H_Ewald_pw::compute_ewald(const UnitCell& cell,
erfc(sqrt(alpha) * rr) / rr;
}
} // enddo
if (PARAM.inp.test_energy>1) ModuleBase::GlobalFunc::OUT("ewaldr",ewaldr);
if (test_energy>1) ModuleBase::GlobalFunc::OUT("ewaldr",ewaldr);
} // enddo
} // enddo
} // nt2
Expand All @@ -285,7 +286,7 @@ double H_Ewald_pw::compute_ewald(const UnitCell& cell,
// mohan fix bug 2010-07-26
Parallel_Reduce::reduce_pool(ewalds);

if (PARAM.inp.test_energy>1)
if (test_energy>1)
{
ModuleBase::GlobalFunc::OUT("ewaldg",ewaldg);
ModuleBase::GlobalFunc::OUT("ewaldr",ewaldr);
Expand All @@ -306,7 +307,8 @@ void H_Ewald_pw::rgen(
ModuleBase::Vector3<double> *r,
double *r2,
const int mxr,
int &nrm)
int &nrm,
const int test_energy)
{
//-------------------------------------------------------------------
// generates neighbours shells (in units of alat) with length
Expand Down Expand Up @@ -377,7 +379,7 @@ void H_Ewald_pw::rgen(

nm3 = (int)(dnrm2(3, bg1, 1) * rmax + 2);

if (PARAM.inp.test_energy>1)
if (test_energy>1)
{
ModuleBase::GlobalFunc::OUT("nm1",nm1);
ModuleBase::GlobalFunc::OUT("nm2",nm2);
Expand Down
10 changes: 7 additions & 3 deletions source/source_hamilt/module_ewald/h_ewald_pw.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#ifndef H_EWALD_PW_H
#define H_EWALD_PW_H

#include "source_base/global_function.h"
#include "source_cell/unitcell.h"
#include "source_basis/module_pw/pw_basis.h"

#include <fstream>

class H_Ewald_pw
{
public:
Expand All @@ -14,7 +15,9 @@ class H_Ewald_pw
// compute the Ewald energy
static double compute_ewald(const UnitCell& cell,
const ModulePW::PW_Basis* rho_basis,
const ModuleBase::ComplexMatrix& strucFac);
const ModuleBase::ComplexMatrix& strucFac,
int test_energy,
std::ofstream& output_stream);

public:
static int estimate_mxr(const double &rmax, const ModuleBase::Matrix3 &bg);
Expand All @@ -28,7 +31,8 @@ class H_Ewald_pw
ModuleBase::Vector3<double> *r,
double *r2,
const int mxr,
int &nrm
int &nrm,
int test_energy
);

// the coefficient of ewald method
Expand Down
5 changes: 5 additions & 0 deletions source/source_hamilt/module_gint/gint.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class Gint
gint_info_ = gint_info;
}

static const GintInfo& get_gint_info()
{
return *gint_info_;
}

protected:
static GintInfo* gint_info_;
};
Expand Down
10 changes: 5 additions & 5 deletions source/source_hamilt/module_gint/gint_common.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "gint_common.h"
#include "source_hamilt/module_hcontainer/hcontainer.h"
#include "source_hamilt/module_hcontainer/hcontainer_funcs.h"
#include "source_io/module_parameter/parameter.h"
#include "source_base/tool_quit.h"
#include <cassert>
#include <type_traits>
Expand Down Expand Up @@ -179,7 +178,7 @@ void merge_hr_part_to_hR(const std::vector<hamilt::HContainer<double>>& hr_gint_
std::vector<int> clx_i = {1, 0, 0, -1};
std::vector<int> clx_j = {0, -1, 1, 0};
for (int is = 0; is < 4; is++){
if(!PARAM.globalv.domag && (is==1 || is==2)) continue;
if(!gint_info.get_domag() && (is==1 || is==2)) continue;
hR_tmp->set_zero();
hamilt::HContainer<std::complex<double>>* hRGint_tmpCd = new hamilt::HContainer<std::complex<double>>(ucell_in->nat);
hRGint_tmpCd->insert_ijrs( &(gint_info.get_ijr_info()), *(ucell_in));
Expand Down Expand Up @@ -311,9 +310,9 @@ void dm_2d_to_gint(
ModuleBase::TITLE("Gint", "dm_2d_to_gint");
ModuleBase::timer::start("Gint", "dm_2d_to_gint");

if (PARAM.inp.nspin != 4)
if (gint_info.get_nspin() != 4)
{
// dm_gint.size() usually equals to PARAM.inp.nspin,
// dm_gint.size() usually equals to the configured nspin,
// but there is exception within source_lcao/module_lr
for (int is = 0; is < dm_gint.size(); is++)
{
Expand Down Expand Up @@ -404,6 +403,7 @@ void wfc_2d_to_gint(const T* wfc_2d,
ModuleBase::TITLE("Gint", "wfc_2d_to_gint");
ModuleBase::timer::start("Gint", "wfc_2d_to_gint");

const int requested_nbands = nbands;
#ifdef __MPI
// dimension related
nlocal = pv.desc_wfc[2];
Expand Down Expand Up @@ -459,7 +459,7 @@ void wfc_2d_to_gint(const T* wfc_2d,
for (int j = 0; j < naroc[1]; ++j)
{
int igcol = globalIndex(j, nb, dim1, ipcol);
if (igcol >= PARAM.inp.nbands)
if (igcol >= requested_nbands)
{
continue;
}
Expand Down
23 changes: 16 additions & 7 deletions source/source_hamilt/module_gint/gint_info.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <cmath>
#include <map>
#include "source_io/module_parameter/parameter.h"
#include "source_base/timer.h"
#include "gint_info.h"
#include "gint_type.h"
Expand All @@ -15,8 +14,9 @@ GintInfo::GintInfo(
int startidx_bx, int startidx_by, int startidx_bz,
int nbx_local, int nby_local, int nbz_local,
const Numerical_Orbital* Phi,
const UnitCell& ucell, Grid_Driver& gd)
: ucell_(&ucell)
const UnitCell& ucell, Grid_Driver& gd,
const int nspin, const bool gamma_only, const bool domag, const bool use_gpu, const int nstream)
: ucell_(&ucell), nspin_(nspin), gamma_only_(gamma_only), domag_(domag), use_gpu_(use_gpu)
{
// initialize the unitcell information
unitcell_info_ = std::make_shared<UnitCellInfo>(ucell_->a1 * ucell_->lat0, ucell_->a2 * ucell_->lat0, ucell_->a3 * ucell_->lat0,
Expand Down Expand Up @@ -46,16 +46,16 @@ GintInfo::GintInfo(
init_atoms_(ucell_->ntype, ucell_->atoms, Phi);

// initialize trace_lo_ and lgd_
init_trace_lo_(ucell, PARAM.inp.nspin);
init_trace_lo_(ucell, nspin_);

// initialize the ijr_info
// this step needs to be done after init_atoms_, because it requires the information of is_atom_on_bgrid
init_ijr_info_(ucell, gd);

#ifdef __CUDA
if(PARAM.inp.device == "gpu")
if(use_gpu_)
{
streams_num_ = PARAM.inp.nstream; // the default value of num_stream is 4
streams_num_ = nstream; // the default value of num_stream is 4
const int batch_size = nbz_local;
init_bgrid_batches_(batch_size);
gpu_vars_ = std::make_shared<GintGpuVars>(biggrid_info_, ucell, Phi);
Expand Down Expand Up @@ -151,7 +151,16 @@ void GintInfo::init_atoms_(int ntype, const Atom* atoms, const Numerical_Orbital

void GintInfo::init_trace_lo_(const UnitCell& ucell, const int nspin)
{
this->trace_lo_ = std::vector<int>(PARAM.globalv.nlocal, -1);
int nlocal = 0;
for (int it = 0; it < ucell.ntype; ++it)
{
nlocal += ucell.atoms[it].nw * ucell.atoms[it].na;
}
if (nspin == 4)
{
nlocal *= 2;
}
this->trace_lo_ = std::vector<int>(nlocal, -1);
this->lgd_ = 0;
int iat = 0;
int iw_all = 0;
Expand Down
Loading
Loading