Skip to content

Commit b60795e

Browse files
committed
<Feature> In order to check the validity of MPN KEDF, calculate and output TF KEDF when running MPN KEDF.
1 parent dc28b4a commit b60795e

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

source/module_esolver/esolver_fp.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void ESolver_FP::init(Input& inp, UnitCell& cell)
5252
#ifdef __MPI
5353
this->pw_rho->initmpi(GlobalV::NPROC_IN_POOL, GlobalV::RANK_IN_POOL, POOL_WORLD);
5454
#endif
55-
if (this->classname == "ESolver_OF")
55+
if (this->classname == "ESolver_OF" || GlobalV::of_ml_gene_data == 1)
5656
{
5757
this->pw_rho->setfullpw(inp.of_full_pw, inp.of_full_pw_dim);
5858
}

source/module_esolver/esolver_of.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,35 @@ void ESolver_OF::after_opt(const int istep, UnitCell& ucell)
584584
&(ucell),
585585
this->pelec->pot->get_fixed_v());
586586
}
587+
if (this->of_kinetic_ == "mpn" || this->of_kinetic_ == "ml")
588+
{
589+
this->tf_->get_energy(this->pelec->charge->rho);
590+
std::cout << "ML Term = " << this->ml_->ml_energy << " Ry, TF Term = " << this->tf_->tf_energy << " Ry." << std::endl;
591+
if (this->ml_->ml_energy >= this->tf_->tf_energy)
592+
{
593+
std::cout << "WARNING: ML >= TF" << std::endl;
594+
}
595+
}
596+
597+
if (GlobalV::of_ml_gene_data)
598+
{
599+
this->pelec->pot->update_from_charge(pelec->charge, &GlobalC::ucell); // Hartree + XC + external
600+
this->kinetic_potential(pelec->charge->rho, this->pphi_, this->pelec->pot->get_effective_v()); // (kinetic + Hartree + XC + external) * 2 * phi
601+
602+
const double* vr_eff = this->pelec->pot->get_effective_v(0);
603+
for (int ir = 0; ir < this->pw_rho->nrxx; ++ir)
604+
{
605+
this->pdEdphi_[0][ir] = vr_eff[ir];
606+
}
607+
this->mu_[0] = this->cal_mu(this->pphi_[0], this->pdEdphi_[0], this->nelec_[0]);
608+
609+
// === temporary ===
610+
// assert(GlobalV::of_kinetic == "wt" || GlobalV::of_kinetic == "ml");
611+
// =================
612+
std::cout << "Generating Training data..." << std::endl;
613+
std::cout << "mu = " << this->mu_[0] << std::endl;
614+
this->ml_->generateTrainData(pelec->charge->rho, *(this->wt_), *(this->tf_), this->pw_rho, vr_eff);
615+
}
587616
}
588617

589618
/**

source/module_esolver/esolver_of_interface.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ namespace ModuleESolver
1212
void ESolver_OF::init_kedf(Input& inp)
1313
{
1414
//! Thomas-Fermi (TF) KEDF, TF+ KEDF, and Want-Teter (WT) KEDF
15-
if (this->of_kinetic_ == "tf" || this->of_kinetic_ == "tf+" || this->of_kinetic_ == "wt")
15+
if (this->of_kinetic_ == "tf"
16+
|| this->of_kinetic_ == "tf+"
17+
|| this->of_kinetic_ == "wt"
18+
|| this->of_kinetic_ == "ml"
19+
|| this->of_kinetic_ == "mpn")
1620
{
1721
if (this->tf_ == nullptr)
1822
{
@@ -103,6 +107,7 @@ void ESolver_OF::kinetic_potential(double** prho, double** pphi, ModuleBase::mat
103107
if (this->of_kinetic_ == "ml" || this->of_kinetic_ == "mpn")
104108
{
105109
this->ml_->ml_potential(prho, this->pw_rho, rpot);
110+
this->tf_->get_energy(prho); // temp
106111
}
107112

108113
// Before call vw_potential, change rpot to rpot * 2 * pphi
@@ -164,6 +169,11 @@ double ESolver_OF::kinetic_energy()
164169
if (this->of_kinetic_ == "ml" || this->of_kinetic_ == "mpn")
165170
{
166171
kinetic_energy += this->ml_->ml_energy;
172+
if (this->ml_->ml_energy >= this->tf_->tf_energy)
173+
{
174+
std::cout << "WARNING: ML >= TF" << std::endl;
175+
std::cout << "ML Term = " << this->ml_->ml_energy << " Ry, TF Term = " << this->tf_->tf_energy << " Ry." << std::endl;
176+
}
167177
}
168178

169179
return kinetic_energy;

source/module_hamilt_pw/hamilt_ofdft/kedf_ml_pot.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void KEDF_ML::get_potential_(const double * const * prho, ModulePW::PW_Basis *pw
4343
// + xinlterm[ir] + tanhxinlterm[ir] + tanhxi_nlterm[ir]
4444
// + tanhptanh_pnlterm[ir] + tanhqtanh_qnlterm[ir]
4545
// + tanhptanhp_nlterm[ir] + tanhqtanhq_nlterm[ir];
46+
// if (pauli_potential[ir] < 0) pauli_potential[ir] = 0;
4647
rpotential(0, ir) += pauli_potential[ir];
4748

4849
// if (this->enhancement_cpu_ptr[ir] < 0)

0 commit comments

Comments
 (0)