Skip to content
Merged
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
10 changes: 10 additions & 0 deletions source/module_esolver/esolver_fp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#include "esolver.h"

#ifndef __MPI
#include <chrono>
#endif

//! plane wave basis
#include "module_basis/module_pw/pw_basis.h"

Expand Down Expand Up @@ -98,6 +102,12 @@ class ESolver_FP: public ESolver

int pw_rho_flag = false; ///< flag for pw_rho, 0: not initialized, 1: initialized

//! the start time of scf iteration
#ifdef __MPI
double iter_time;
#else
std::chrono::system_clock::time_point iter_time;
#endif
};
} // namespace ModuleESolver

Expand Down
13 changes: 0 additions & 13 deletions source/module_esolver/esolver_ks.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#ifndef ESOLVER_KS_H
#define ESOLVER_KS_H

#ifdef __MPI
#include <mpi.h>
#else
#include <chrono>
#endif

#include <cstring>
//#include <fstream>

Expand Down Expand Up @@ -79,13 +73,6 @@ class ESolver_KS : public ESolver_FP
//! Electronic wavefunctions
psi::Psi<T>* psi = nullptr;

//! the start time of scf iteration
#ifdef __MPI
double iter_time;
#else
std::chrono::system_clock::time_point iter_time;
#endif

std::string basisname; //! esolver_ks_lcao.cpp
double esolver_KS_ne = 0.0; //! number of electrons
double diag_ethr; //! the threshold for diagonalization
Expand Down
6 changes: 5 additions & 1 deletion source/module_esolver/esolver_of.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,12 @@ void ESolver_OF::runner(UnitCell& ucell, const int istep)
if (PARAM.inp.of_ml_local_test) this->ml_->localTest(this->chr.rho, this->pw_rho);
#endif


bool conv_esolver = false; // this conv_esolver is added by mohan 20250302
#ifdef __MPI
this->iter_time = MPI_Wtime();
#else
this->iter_time = std::chrono::system_clock::now();
#endif

while (true)
{
Expand Down
57 changes: 29 additions & 28 deletions source/module_esolver/esolver_of_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,38 +390,32 @@ void ESolver_OF::print_info(const bool conv_esolver)
{
if (this->iter_ == 0)
{
std::cout << "============================== Running OFDFT "
std::cout << " ============================= Running OFDFT "
"=============================="
<< std::endl;
std::cout << "Iter Etot(Ha) Mu(Ha) Theta "
"PotNorm deltaE(Ha)"
std::cout << " ITER ETOT/eV EDIFF/eV EFERMI/eV POTNORM TIME/s"
<< std::endl;
// cout << "======================================== Running OFDFT
// ========================================" << endl; cout << "Iter
// Etot(Ha) Theta PotNorm min/max(den)
// min/max(dE/dPhi)" << endl;
}
// ============ used to compare with PROFESS3.0 ================
// double minDen = this->chr.rho[0][0];
// double maxDen = this->chr.rho[0][0];
// double minPot = this->pdEdphi_[0][0];
// double maxPot = this->pdEdphi_[0][0];
// for (int i = 0; i < this->pw_rho->nrxx; ++i)
// {
// if (this->chr.rho[0][i] < minDen) minDen =
// this->chr.rho[0][i]; if (this->chr.rho[0][i] > maxDen)
// maxDen = this->chr.rho[0][i]; if (this->pdEdphi_[0][i] < minPot)
// minPot = this->pdEdphi_[0][i]; if (this->pdEdphi_[0][i] > maxPot)
// maxPot = this->pdEdphi_[0][i];
// }
std::cout << std::setw(6) << this->iter_ << std::setw(22) << std::scientific << std::setprecision(12)
<< this->energy_current_ / 2. << std::setw(12) << std::setprecision(3) << this->pelec->eferm.get_efval(0) / 2.
<< std::setw(12) << this->theta_[0] << std::setw(12) << this->normdLdphi_ << std::setw(12)
<< (this->energy_current_ - this->energy_last_) / 2. << std::endl;
// ============ used to compare with PROFESS3.0 ================
// << setw(10) << minDen << "/ " << setw(12) << maxDen
// << setw(10) << minPot << "/ " << setw(10) << maxPot << endl;
// =============================================================

std::map<std::string, std::string> prefix_map = {
{"cg1", "CG"},
{"cg2", "CG"},
{"tn", "TN"}
};
std::string iteration = prefix_map[PARAM.inp.of_method] + std::to_string(this->iter_);
#ifdef __MPI
double duration = (double)(MPI_Wtime() - this->iter_time);
#else
double duration
= (std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - this->iter_time)).count()
/ static_cast<double>(1e6);
#endif
std::cout << " " << std::setw(8) << iteration
<< std::setw(18) << std::scientific << std::setprecision(8) << this->energy_current_ * ModuleBase::Ry_to_eV
<< std::setw(18) << (this->energy_current_ - this->energy_last_) * ModuleBase::Ry_to_eV
<< std::setw(13) << std::setprecision(4) << this->pelec->eferm.get_efval(0) * ModuleBase::Ry_to_eV
<< std::setw(13) << std::setprecision(4) << this->normdLdphi_
<< std::setw(6) << std::fixed << std::setprecision(2) << duration << std::endl;

GlobalV::ofs_running << std::setprecision(12);
GlobalV::ofs_running << std::setiosflags(std::ios::right);
Expand Down Expand Up @@ -533,5 +527,12 @@ void ESolver_OF::print_info(const bool conv_esolver)
/*formats=*/{"%20s", "%20.12f", "%20.12f"}, 0);
table << titles << energies_Ry << energies_eV;
GlobalV::ofs_running << table.str() << std::endl;

// reset the iter_time for the next iteration
#ifdef __MPI
this->iter_time = MPI_Wtime();
#else
this->iter_time = std::chrono::system_clock::now();
#endif
}
} // namespace ModuleESolver
Loading