From e79c1d06d370d251df53e8dbc0b99d3d890cdad1 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Tue, 25 Mar 2025 22:01:35 +0800 Subject: [PATCH 01/22] update some timers --- .../module_basis/module_pw/pw_gatherscatter.h | 38 +++++++++----- source/module_esolver/esolver_fp.h | 2 +- source/module_esolver/esolver_ks.cpp | 18 +++---- source/module_esolver/esolver_ks.h | 8 +-- source/module_esolver/esolver_ks_lcao.cpp | 8 +-- source/module_esolver/esolver_ks_lcao.h | 2 +- .../module_esolver/esolver_ks_lcao_tddft.cpp | 2 +- source/module_esolver/esolver_ks_lcao_tddft.h | 2 +- source/module_esolver/esolver_ks_lcaopw.cpp | 8 +-- source/module_esolver/esolver_ks_lcaopw.h | 2 +- source/module_esolver/esolver_ks_pw.cpp | 6 +-- source/module_esolver/esolver_ks_pw.h | 2 +- source/module_esolver/esolver_sdft_pw.cpp | 8 +-- source/module_esolver/esolver_sdft_pw.h | 2 +- .../hamilt_pwdft/operator_pw/veff_pw.cpp | 52 +++++-------------- source/module_ri/Exx_LRI_interface.h | 4 +- source/module_ri/Exx_LRI_interface.hpp | 2 +- 17 files changed, 76 insertions(+), 90 deletions(-) diff --git a/source/module_basis/module_pw/pw_gatherscatter.h b/source/module_basis/module_pw/pw_gatherscatter.h index 3ce5c6d5a34..bcad2caa0a5 100644 --- a/source/module_basis/module_pw/pw_gatherscatter.h +++ b/source/module_basis/module_pw/pw_gatherscatter.h @@ -14,7 +14,7 @@ namespace ModulePW template void PW_Basis::gatherp_scatters(std::complex* in, std::complex* out) const { - ModuleBase::timer::tick(this->classname, "gatherp_scatters"); + //ModuleBase::timer::tick(this->classname, "gatherp_scatters"); if(this->poolnproc == 1) //In this case nst=nstot, nz = nplane, { @@ -32,7 +32,7 @@ void PW_Basis::gatherp_scatters(std::complex* in, std::complex* out) const outp[iz] = inp[iz]; } } - ModuleBase::timer::tick(this->classname, "gatherp_scatters"); + //ModuleBase::timer::tick(this->classname, "gatherp_scatters"); return; } #ifdef __MPI @@ -55,10 +55,15 @@ void PW_Basis::gatherp_scatters(std::complex* in, std::complex* out) const //exchange data //(nplane,nstot) to (numz[ip],ns, poolnproc) - if(typeid(T) == typeid(double)) - MPI_Alltoallv(out, numr, startr, MPI_DOUBLE_COMPLEX, in, numg, startg, MPI_DOUBLE_COMPLEX, this->pool_world); - else if(typeid(T) == typeid(float)) - MPI_Alltoallv(out, numr, startr, MPI_COMPLEX, in, numg, startg, MPI_COMPLEX, this->pool_world); + if(typeid(T) == typeid(double)) + { + MPI_Alltoallv(out, numr, startr, MPI_DOUBLE_COMPLEX, in, numg, startg, MPI_DOUBLE_COMPLEX, this->pool_world); + } + else if(typeid(T) == typeid(float)) + { + MPI_Alltoallv(out, numr, startr, MPI_COMPLEX, in, numg, startg, MPI_COMPLEX, this->pool_world); + } + // change (nz,ns) to (numz[ip],ns, poolnproc) #ifdef _OPENMP #pragma omp parallel for collapse(2) @@ -80,7 +85,7 @@ void PW_Basis::gatherp_scatters(std::complex* in, std::complex* out) const } #endif - ModuleBase::timer::tick(this->classname, "gatherp_scatters"); + //ModuleBase::timer::tick(this->classname, "gatherp_scatters"); return; } @@ -94,7 +99,7 @@ void PW_Basis::gatherp_scatters(std::complex* in, std::complex* out) const template void PW_Basis::gathers_scatterp(std::complex* in, std::complex* out) const { - ModuleBase::timer::tick(this->classname, "gathers_scatterp"); + //ModuleBase::timer::tick(this->classname, "gathers_scatterp"); if(this->poolnproc == 1) //In this case nrxx=fftnx*fftny*nz, nst = nstot, { @@ -147,10 +152,15 @@ void PW_Basis::gathers_scatterp(std::complex* in, std::complex* out) const //exchange data //(numz[ip],ns, poolnproc) to (nplane,nstot) - if(typeid(T) == typeid(double)) - MPI_Alltoallv(out, numg, startg, MPI_DOUBLE_COMPLEX, in, numr, startr, MPI_DOUBLE_COMPLEX, this->pool_world); - else if(typeid(T) == typeid(float)) - MPI_Alltoallv(out, numg, startg, MPI_COMPLEX, in, numr, startr, MPI_COMPLEX, this->pool_world); + if(typeid(T) == typeid(double)) + { + MPI_Alltoallv(out, numg, startg, MPI_DOUBLE_COMPLEX, in, numr, startr, MPI_DOUBLE_COMPLEX, this->pool_world); + } + else if(typeid(T) == typeid(float)) + { + MPI_Alltoallv(out, numg, startg, MPI_COMPLEX, in, numr, startr, MPI_COMPLEX, this->pool_world); + } + #ifdef _OPENMP #pragma omp parallel for schedule(static, 4096/sizeof(T)) #endif @@ -175,10 +185,10 @@ void PW_Basis::gathers_scatterp(std::complex* in, std::complex* out) const } #endif - ModuleBase::timer::tick(this->classname, "gathers_scatterp"); + //ModuleBase::timer::tick(this->classname, "gathers_scatterp"); return; } -} \ No newline at end of file +} diff --git a/source/module_esolver/esolver_fp.h b/source/module_esolver/esolver_fp.h index 1e7f23c02c7..a4507c7c553 100644 --- a/source/module_esolver/esolver_fp.h +++ b/source/module_esolver/esolver_fp.h @@ -56,7 +56,7 @@ class ESolver_FP: public ESolver //! Something to do after SCF iterations when SCF is converged or comes to the max iter step. virtual void after_scf(UnitCell& ucell, const int istep, const bool conv_esolver); - //! Something to do after hamilt2density function in each iter loop. + //! Something to do after hamilt2rho function in each iter loop. virtual void iter_finish(UnitCell& ucell, const int istep, int& iter, bool &conv_esolver); //! ------------------------------------------------------------------------------ diff --git a/source/module_esolver/esolver_ks.cpp b/source/module_esolver/esolver_ks.cpp index b4e3bcd349e..932da275293 100644 --- a/source/module_esolver/esolver_ks.cpp +++ b/source/module_esolver/esolver_ks.cpp @@ -343,25 +343,25 @@ void ESolver_KS::before_all_runners(UnitCell& ucell, const Input_para } //------------------------------------------------------------------------------ -//! the 5th function of ESolver_KS: hamilt2density_single +//! the 5th function of ESolver_KS: hamilt2rho_single //! mohan add 2024-05-11 //------------------------------------------------------------------------------ template -void ESolver_KS::hamilt2density_single(UnitCell& ucell, const int istep, const int iter, const double ethr) +void ESolver_KS::hamilt2rho_single(UnitCell& ucell, const int istep, const int iter, const double ethr) { - ModuleBase::timer::tick(this->classname, "hamilt2density_single"); + ModuleBase::timer::tick(this->classname, "hamilt2rho_single"); // Temporarily, before HSolver is constructed, it should be overrided by // LCAO, PW, SDFT and TDDFT. // After HSolver is constructed, LCAO, PW, SDFT should delete their own - // hamilt2density_single() and use: - ModuleBase::timer::tick(this->classname, "hamilt2density_single"); + // hamilt2rho_single() and use: + ModuleBase::timer::tick(this->classname, "hamilt2rho_single"); } template -void ESolver_KS::hamilt2density(UnitCell& ucell, const int istep, const int iter, const double ethr) +void ESolver_KS::hamilt2rho(UnitCell& ucell, const int istep, const int iter, const double ethr) { // 7) use Hamiltonian to obtain charge density - this->hamilt2density_single(ucell, istep, iter, diag_ethr); + this->hamilt2rho_single(ucell, istep, iter, diag_ethr); // 8) for MPI: STOGROUP? need to rewrite // It may be changed when more clever parallel algorithm is @@ -398,7 +398,7 @@ void ESolver_KS::hamilt2density(UnitCell& ucell, const int istep, con diag_ethr, PARAM.inp.nelec); - this->hamilt2density_single(ucell, istep, iter, diag_ethr); + this->hamilt2rho_single(ucell, istep, iter, diag_ethr); drho = p_chgmix->get_drho(&this->chr, PARAM.inp.nelec); @@ -458,7 +458,7 @@ void ESolver_KS::runner(UnitCell& ucell, const int istep) this->iter_init(ucell, istep, iter); // 6) use Hamiltonian to obtain charge density - this->hamilt2density(ucell, istep, iter, diag_ethr); + this->hamilt2rho(ucell, istep, iter, diag_ethr); // 7) finish scf iterations this->iter_finish(ucell, istep, iter, conv_esolver); diff --git a/source/module_esolver/esolver_ks.h b/source/module_esolver/esolver_ks.h index 75e6ff91bcd..b0ef3eb279f 100644 --- a/source/module_esolver/esolver_ks.h +++ b/source/module_esolver/esolver_ks.h @@ -48,17 +48,17 @@ class ESolver_KS : public ESolver_FP //! Something to do before SCF iterations. virtual void before_scf(UnitCell& ucell, const int istep) override; - //! Something to do before hamilt2density function in each iter loop. + //! Something to do before hamilt2rho function in each iter loop. virtual void iter_init(UnitCell& ucell, const int istep, const int iter); - //! Something to do after hamilt2density function in each iter loop. + //! Something to do after hamilt2rho function in each iter loop. virtual void iter_finish(UnitCell& ucell, const int istep, int& iter, bool& conv_esolver) override; // calculate electron density from a specific Hamiltonian with ethr - virtual void hamilt2density_single(UnitCell& ucell, const int istep, const int iter, const double ethr); + virtual void hamilt2rho_single(UnitCell& ucell, const int istep, const int iter, const double ethr); // calculate electron density from a specific Hamiltonian - void hamilt2density(UnitCell& ucell, const int istep, const int iter, const double ethr); + void hamilt2rho(UnitCell& ucell, const int istep, const int iter, const double ethr); //! Something to do after SCF iterations when SCF is converged or comes to the max iter step. virtual void after_scf(UnitCell& ucell, const int istep, const bool conv_esolver) override; diff --git a/source/module_esolver/esolver_ks_lcao.cpp b/source/module_esolver/esolver_ks_lcao.cpp index 554be9a3c03..9549cc511e9 100644 --- a/source/module_esolver/esolver_ks_lcao.cpp +++ b/source/module_esolver/esolver_ks_lcao.cpp @@ -739,9 +739,9 @@ void ESolver_KS_LCAO::iter_init(UnitCell& ucell, const int istep, const template -void ESolver_KS_LCAO::hamilt2density_single(UnitCell& ucell, int istep, int iter, double ethr) +void ESolver_KS_LCAO::hamilt2rho_single(UnitCell& ucell, int istep, int iter, double ethr) { - ModuleBase::TITLE("ESolver_KS_LCAO", "hamilt2density_single"); + ModuleBase::TITLE("ESolver_KS_LCAO", "hamilt2rho_single"); // i1) reset energy this->pelec->f_en.eband = 0.0; @@ -781,11 +781,11 @@ void ESolver_KS_LCAO::hamilt2density_single(UnitCell& ucell, int istep, { if (GlobalC::exx_info.info_ri.real_number) { - this->exd->exx_hamilt2density(*this->pelec, this->pv, iter); + this->exd->exx_hamilt2rho(*this->pelec, this->pv, iter); } else { - this->exc->exx_hamilt2density(*this->pelec, this->pv, iter); + this->exc->exx_hamilt2rho(*this->pelec, this->pv, iter); } } #endif diff --git a/source/module_esolver/esolver_ks_lcao.h b/source/module_esolver/esolver_ks_lcao.h index 031400b2cc9..774a3bc16ba 100644 --- a/source/module_esolver/esolver_ks_lcao.h +++ b/source/module_esolver/esolver_ks_lcao.h @@ -67,7 +67,7 @@ class ESolver_KS_LCAO : public ESolver_KS virtual void iter_init(UnitCell& ucell, const int istep, const int iter) override; - virtual void hamilt2density_single(UnitCell& ucell, const int istep, const int iter, const double ethr) override; + virtual void hamilt2rho_single(UnitCell& ucell, const int istep, const int iter, const double ethr) override; virtual void update_pot(UnitCell& ucell, const int istep, const int iter, const bool conv_esolver) override; diff --git a/source/module_esolver/esolver_ks_lcao_tddft.cpp b/source/module_esolver/esolver_ks_lcao_tddft.cpp index 5628f5463df..4c38df56442 100644 --- a/source/module_esolver/esolver_ks_lcao_tddft.cpp +++ b/source/module_esolver/esolver_ks_lcao_tddft.cpp @@ -87,7 +87,7 @@ void ESolver_KS_LCAO_TDDFT::before_all_runners(UnitCell& ucell, const In } template -void ESolver_KS_LCAO_TDDFT::hamilt2density_single(UnitCell& ucell, +void ESolver_KS_LCAO_TDDFT::hamilt2rho_single(UnitCell& ucell, const int istep, const int iter, const double ethr) diff --git a/source/module_esolver/esolver_ks_lcao_tddft.h b/source/module_esolver/esolver_ks_lcao_tddft.h index 9232590fbf0..862b16a6ca1 100644 --- a/source/module_esolver/esolver_ks_lcao_tddft.h +++ b/source/module_esolver/esolver_ks_lcao_tddft.h @@ -58,7 +58,7 @@ class ESolver_KS_LCAO_TDDFT : public ESolver_KS_LCAO, doubl void before_all_runners(UnitCell& ucell, const Input_para& inp) override; protected: - virtual void hamilt2density_single(UnitCell& ucell, const int istep, const int iter, const double ethr) override; + virtual void hamilt2rho_single(UnitCell& ucell, const int istep, const int iter, const double ethr) override; virtual void update_pot(UnitCell& ucell, const int istep, const int iter, const bool conv_esolver) override; diff --git a/source/module_esolver/esolver_ks_lcaopw.cpp b/source/module_esolver/esolver_ks_lcaopw.cpp index 8439265bfd1..045ac5d715d 100644 --- a/source/module_esolver/esolver_ks_lcaopw.cpp +++ b/source/module_esolver/esolver_ks_lcaopw.cpp @@ -132,10 +132,10 @@ namespace ModuleESolver } template - void ESolver_KS_LIP::hamilt2density_single(UnitCell& ucell, const int istep, const int iter, const double ethr) + void ESolver_KS_LIP::hamilt2rho_single(UnitCell& ucell, const int istep, const int iter, const double ethr) { - ModuleBase::TITLE("ESolver_KS_LIP", "hamilt2density_single"); - ModuleBase::timer::tick("ESolver_KS_LIP", "hamilt2density_single"); + ModuleBase::TITLE("ESolver_KS_LIP", "hamilt2rho_single"); + ModuleBase::timer::tick("ESolver_KS_LIP", "hamilt2rho_single"); // reset energy this->pelec->f_en.eband = 0.0; @@ -171,7 +171,7 @@ namespace ModuleESolver // need 'rho(out)' and 'vr (v_h(in) and v_xc(in))' this->pelec->f_en.deband = this->pelec->cal_delta_eband(ucell); - ModuleBase::timer::tick("ESolver_KS_LIP", "hamilt2density_single"); + ModuleBase::timer::tick("ESolver_KS_LIP", "hamilt2rho_single"); } template diff --git a/source/module_esolver/esolver_ks_lcaopw.h b/source/module_esolver/esolver_ks_lcaopw.h index c73b74a38cc..74c12db1f80 100644 --- a/source/module_esolver/esolver_ks_lcaopw.h +++ b/source/module_esolver/esolver_ks_lcaopw.h @@ -30,7 +30,7 @@ namespace ModuleESolver virtual void iter_finish(UnitCell& ucell, const int istep, int& iter, bool& conv_esolver) override; /// All the other interfaces except this one are the same as ESolver_KS_PW. - virtual void hamilt2density_single(UnitCell& ucell, + virtual void hamilt2rho_single(UnitCell& ucell, const int istep, const int iter, const double ethr) override; diff --git a/source/module_esolver/esolver_ks_pw.cpp b/source/module_esolver/esolver_ks_pw.cpp index 4626286801e..8f3822cf529 100644 --- a/source/module_esolver/esolver_ks_pw.cpp +++ b/source/module_esolver/esolver_ks_pw.cpp @@ -450,12 +450,12 @@ void ESolver_KS_PW::iter_init(UnitCell& ucell, const int istep, const // Temporary, it should be replaced by hsolver later. template -void ESolver_KS_PW::hamilt2density_single(UnitCell& ucell, +void ESolver_KS_PW::hamilt2rho_single(UnitCell& ucell, const int istep, const int iter, const double ethr) { - ModuleBase::timer::tick("ESolver_KS_PW", "hamilt2density_single"); + ModuleBase::timer::tick("ESolver_KS_PW", "hamilt2rho_single"); // reset energy this->pelec->f_en.eband = 0.0; @@ -524,7 +524,7 @@ void ESolver_KS_PW::hamilt2density_single(UnitCell& ucell, srho.begin(is, this->chr, this->pw_rhod, ucell.symm); } - ModuleBase::timer::tick("ESolver_KS_PW", "hamilt2density_single"); + ModuleBase::timer::tick("ESolver_KS_PW", "hamilt2rho_single"); } // Temporary, it should be rewritten with Hamilt class. diff --git a/source/module_esolver/esolver_ks_pw.h b/source/module_esolver/esolver_ks_pw.h index d046bd28da1..c1650861771 100644 --- a/source/module_esolver/esolver_ks_pw.h +++ b/source/module_esolver/esolver_ks_pw.h @@ -48,7 +48,7 @@ class ESolver_KS_PW : public ESolver_KS virtual void others(UnitCell& ucell, const int istep) override; - virtual void hamilt2density_single(UnitCell& ucell, const int istep, const int iter, const double ethr) override; + virtual void hamilt2rho_single(UnitCell& ucell, const int istep, const int iter, const double ethr) override; virtual void allocate_hamilt(const UnitCell& ucell); virtual void deallocate_hamilt(); diff --git a/source/module_esolver/esolver_sdft_pw.cpp b/source/module_esolver/esolver_sdft_pw.cpp index d1c9da420ed..85cb3a909f8 100644 --- a/source/module_esolver/esolver_sdft_pw.cpp +++ b/source/module_esolver/esolver_sdft_pw.cpp @@ -132,10 +132,10 @@ void ESolver_SDFT_PW::after_scf(UnitCell& ucell, const int istep, con } template -void ESolver_SDFT_PW::hamilt2density_single(UnitCell& ucell, int istep, int iter, double ethr) +void ESolver_SDFT_PW::hamilt2rho_single(UnitCell& ucell, int istep, int iter, double ethr) { - ModuleBase::TITLE("ESolver_SDFT_PW", "hamilt2density"); - ModuleBase::timer::tick("ESolver_SDFT_PW", "hamilt2density"); + ModuleBase::TITLE("ESolver_SDFT_PW", "hamilt2rho"); + ModuleBase::timer::tick("ESolver_SDFT_PW", "hamilt2rho"); // reset energy this->pelec->f_en.eband = 0.0; @@ -207,7 +207,7 @@ void ESolver_SDFT_PW::hamilt2density_single(UnitCell& ucell, int iste #ifdef __MPI MPI_Bcast(&(this->pelec->f_en.deband), 1, MPI_DOUBLE, 0, BP_WORLD); #endif - ModuleBase::timer::tick("ESolver_SDFT_PW", "hamilt2density"); + ModuleBase::timer::tick("ESolver_SDFT_PW", "hamilt2rho"); } template diff --git a/source/module_esolver/esolver_sdft_pw.h b/source/module_esolver/esolver_sdft_pw.h index 4cb0fe0ddd1..dc284e7b21b 100644 --- a/source/module_esolver/esolver_sdft_pw.h +++ b/source/module_esolver/esolver_sdft_pw.h @@ -35,7 +35,7 @@ class ESolver_SDFT_PW : public ESolver_KS_PW protected: virtual void before_scf(UnitCell& ucell, const int istep) override; - virtual void hamilt2density_single(UnitCell& ucell, const int istep, const int iter, const double ethr) override; + virtual void hamilt2rho_single(UnitCell& ucell, const int istep, const int iter, const double ethr) override; virtual void others(UnitCell& ucell, const int istep) override; diff --git a/source/module_hamilt_pw/hamilt_pwdft/operator_pw/veff_pw.cpp b/source/module_hamilt_pw/hamilt_pwdft/operator_pw/veff_pw.cpp index c931d61f2f8..d6c39132133 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/operator_pw/veff_pw.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/operator_pw/veff_pw.cpp @@ -12,9 +12,11 @@ Veff>::Veff(const int* isk_in, const int veff_col, const ModulePW::PW_Basis_K* wfcpw_in) { - if (isk_in == nullptr || wfcpw_in == nullptr) { + if (isk_in == nullptr || wfcpw_in == nullptr) + { ModuleBase::WARNING_QUIT("VeffPW", "Constuctor of Operator::VeffPW is failed, please check your code!"); } + this->classname = "Veff"; this->cal_type = calculation_type::pw_veff; this->isk = isk_in; @@ -53,67 +55,41 @@ void Veff>::act( int max_npw = nbasis / npol; const int current_spin = this->isk[this->ik]; + #ifdef __DSP wfcpw->fft_bundle.resource_handler(1); #endif - // T *porter = new T[wfcpw->nmaxgr]; + for (int ib = 0; ib < nbands; ib += npol) { if (npol == 1) { - // wfcpw->recip2real(tmpsi_in, porter, this->ik); wfcpw->recip_to_real(tmpsi_in, this->porter, this->ik); - // NOTICE: when MPI threads are larger than number of Z grids + // NOTICE: when MPI threads are larger than the number of Z grids // veff would contain nothing, and nothing should be done in real space // but the 3DFFT can not be skipped, it will cause hanging if(this->veff_col != 0) { veff_op()(this->ctx, this->veff_col, this->porter, this->veff + current_spin * this->veff_col); - // const Real* current_veff = &(this->veff[0](current_spin, 0)); - // for (int ir = 0; ir < this->veff->nc; ++ir) - // { - // porter[ir] *= current_veff[ir]; - // } } - // wfcpw->real2recip(porter, tmhpsi, this->ik, true); wfcpw->real_to_recip(this->porter, tmhpsi, this->ik, true); - // wfcpw->convolution(this->ctx, - // this->ik, - // this->veff_col, - // tmpsi_in, - // this->veff+current_spin, - // tmhpsi, - // true); } else { - // T *porter1 = new T[wfcpw->nmaxgr]; - // fft to real space and doing things. + // FFT to real space and do things. wfcpw->recip_to_real(tmpsi_in, this->porter, this->ik); wfcpw->recip_to_real(tmpsi_in + max_npw, this->porter1, this->ik); if(this->veff_col != 0) { /// denghui added at 20221109 - const Real* current_veff[4]; - for(int is = 0; is < 4; is++) { - current_veff[is] = this->veff + is * this->veff_col ; // for CPU device - } + const Real* current_veff[4]; + for(int is = 0; is < 4; is++) + { + current_veff[is] = this->veff + is * this->veff_col ; // for CPU device + } veff_op()(this->ctx, this->veff_col, this->porter, this->porter1, current_veff); - // T sup, sdown; - // for (int ir = 0; ir < this->veff_col; ir++) { - // sup = this->porter[ir] * (current_veff[0][ir] + current_veff[3][ir]) - // + this->porter1[ir] - // * (current_veff[1][ir] - // - T(0.0, 1.0) * current_veff[2][ir]); - // sdown = this->porter1[ir] * (current_veff[0][ir] - current_veff[3][ir]) - // + this->porter[ir] - // * (current_veff[1][ir] - // + T(0.0, 1.0) * current_veff[2][ir]); - // this->porter[ir] = sup; - // this->porter1[ir] = sdown; - // } } - // (3) fft back to G space. + // FFT back to G space. wfcpw->real_to_recip(this->porter, tmhpsi, this->ik, true); wfcpw->real_to_recip(this->porter1, tmhpsi + max_npw, this->ik, true); } @@ -154,4 +130,4 @@ template class Veff, base_device::DEVICE_GPU>>; // template Veff, base_device::DEVICE_GPU>>::Veff(const // Veff, base_device::DEVICE_GPU>> *veff); #endif -} // namespace hamilt \ No newline at end of file +} // namespace hamilt diff --git a/source/module_ri/Exx_LRI_interface.h b/source/module_ri/Exx_LRI_interface.h index 9c18ebad84f..82ec91b1817 100644 --- a/source/module_ri/Exx_LRI_interface.h +++ b/source/module_ri/Exx_LRI_interface.h @@ -63,8 +63,8 @@ class Exx_LRI_Interface const K_Vectors& kv, const int& iter); - /// @brief in hamilt2density: calculate Hexx and Eexx - void exx_hamilt2density(elecstate::ElecState& elec, const Parallel_Orbitals& pv, const int iter); + /// @brief in hamilt2rho: calculate Hexx and Eexx + void exx_hamilt2rho(elecstate::ElecState& elec, const Parallel_Orbitals& pv, const int iter); /// @brief in iter_finish: write Hexx, do something according to whether SCF is converged void exx_iter_finish(const K_Vectors& kv, diff --git a/source/module_ri/Exx_LRI_interface.hpp b/source/module_ri/Exx_LRI_interface.hpp index 8eecf44cc99..7c52c8ad04b 100644 --- a/source/module_ri/Exx_LRI_interface.hpp +++ b/source/module_ri/Exx_LRI_interface.hpp @@ -157,7 +157,7 @@ void Exx_LRI_Interface::exx_eachiterinit(const int istep, } template -void Exx_LRI_Interface::exx_hamilt2density(elecstate::ElecState& elec, const Parallel_Orbitals& pv, const int iter) +void Exx_LRI_Interface::exx_hamilt2rho(elecstate::ElecState& elec, const Parallel_Orbitals& pv, const int iter) { // Peize Lin add 2020.04.04 if (XC_Functional::get_func_type() == 4 || XC_Functional::get_func_type() == 5) From 3a8b5206d5291e10677adf6e8b26aa925281fc6b Mon Sep 17 00:00:00 2001 From: mohanchen Date: Tue, 25 Mar 2025 22:18:09 +0800 Subject: [PATCH 02/22] update timer --- source/driver_run.cpp | 2 -- source/module_elecstate/potentials/pot_xc.cpp | 8 +++---- .../potentials/potential_new.cpp | 15 ++++++------- .../hamilt_pwdft/operator_pw/nonlocal_pw.cpp | 13 ++++++------ .../hamilt_pwdft/operator_pw/veff_pw.cpp | 4 ++-- source/module_hsolver/diago_iter_assist.cpp | 8 +++---- source/module_hsolver/hsolver_pw.cpp | 21 +++++-------------- 7 files changed, 30 insertions(+), 41 deletions(-) diff --git a/source/driver_run.cpp b/source/driver_run.cpp index 95066d0fa7c..ecf4f044055 100644 --- a/source/driver_run.cpp +++ b/source/driver_run.cpp @@ -26,7 +26,6 @@ void Driver::driver_run() { ModuleBase::TITLE("Driver", "driver_line"); - ModuleBase::timer::tick("Driver", "driver_line"); //! 1: setup cell and atom information // this warning should not be here, mohan 2024-05-22 @@ -93,6 +92,5 @@ void Driver::driver_run() //! 6: output the json file Json::create_Json(&ucell, PARAM); - ModuleBase::timer::tick("Driver", "driver_line"); return; } diff --git a/source/module_elecstate/potentials/pot_xc.cpp b/source/module_elecstate/potentials/pot_xc.cpp index f6b4607f2d2..907363fb17a 100644 --- a/source/module_elecstate/potentials/pot_xc.cpp +++ b/source/module_elecstate/potentials/pot_xc.cpp @@ -12,8 +12,8 @@ namespace elecstate void PotXC::cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix& v_eff) { - ModuleBase::TITLE("PotXC", "cal_v_eff"); - ModuleBase::timer::tick("PotXC", "cal_v_eff"); + ModuleBase::TITLE("PotXC", "cal_veff"); + ModuleBase::timer::tick("PotXC", "cal_veff"); const int nrxx_current = chg->nrxx; //---------------------------------------------------------- @@ -41,7 +41,7 @@ void PotXC::cal_v_eff(const Charge*const chg, const UnitCell*const ucell, Module *(this->vtxc_) = std::get<1>(etxc_vtxc_v); v_eff += std::get<2>(etxc_vtxc_v); } - ModuleBase::timer::tick("PotXC", "cal_v_eff"); + ModuleBase::timer::tick("PotXC", "cal_veff"); } -} // namespace elecstate \ No newline at end of file +} // namespace elecstate diff --git a/source/module_elecstate/potentials/potential_new.cpp b/source/module_elecstate/potentials/potential_new.cpp index 617e18a1788..4fb30c4b557 100644 --- a/source/module_elecstate/potentials/potential_new.cpp +++ b/source/module_elecstate/potentials/potential_new.cpp @@ -163,7 +163,8 @@ void Potential::allocate() void Potential::update_from_charge(const Charge*const chg, const UnitCell*const ucell) { ModuleBase::TITLE("Potential", "update_from_charge"); - ModuleBase::timer::tick("Potential", "update_from_charge"); + //ModuleBase::timer::tick("Potential", "update_from_charge"); + if (!this->fixed_done) { this->cal_fixed_v(this->v_effective_fixed.data()); @@ -216,13 +217,14 @@ void Potential::update_from_charge(const Charge*const chg, const UnitCell*const } #endif - ModuleBase::timer::tick("Potential", "update_from_charge"); + //ModuleBase::timer::tick("Potential", "update_from_charge"); } void Potential::cal_fixed_v(double* vl_pseudo) { ModuleBase::TITLE("Potential", "cal_fixed_v"); ModuleBase::timer::tick("Potential", "cal_fixed_v"); + this->v_effective_fixed.assign(this->v_effective_fixed.size(), 0.0); for (size_t i = 0; i < this->components.size(); i++) { @@ -237,10 +239,11 @@ void Potential::cal_fixed_v(double* vl_pseudo) void Potential::cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix& v_eff) { - ModuleBase::TITLE("Potential", "cal_v_eff"); + ModuleBase::TITLE("Potential", "cal_veff"); + ModuleBase::timer::tick("Potential", "cal_veff"); + const int nspin_current = this->v_effective.nr; const int nrxx = this->v_effective.nc; - ModuleBase::timer::tick("Potential", "cal_v_eff"); // first of all, set v_effective to zero. this->v_effective.zero_out(); @@ -264,7 +267,7 @@ void Potential::cal_v_eff(const Charge*const chg, const UnitCell*const ucell, Mo } } - ModuleBase::timer::tick("Potential", "cal_v_eff"); + ModuleBase::timer::tick("Potential", "cal_veff"); } void Potential::init_pot(int istep, const Charge*const chg) @@ -278,8 +281,6 @@ void Potential::init_pot(int istep, const Charge*const chg) this->update_from_charge(chg, this->ucell_); - // plots - // figure::picture(this->vr_eff1,GlobalC::rhopw->nx,GlobalC::rhopw->ny,GlobalC::rhopw->nz); ModuleBase::timer::tick("Potential", "init_pot"); return; } diff --git a/source/module_hamilt_pw/hamilt_pwdft/operator_pw/nonlocal_pw.cpp b/source/module_hamilt_pw/hamilt_pwdft/operator_pw/nonlocal_pw.cpp index 74823eccc1a..4386bb7ae36 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/operator_pw/nonlocal_pw.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/operator_pw/nonlocal_pw.cpp @@ -216,7 +216,7 @@ void Nonlocal>::act( const int ngk_ik, const bool is_first_node)const { - ModuleBase::timer::tick("Operator", "NonlocalPW"); + ModuleBase::timer::tick("Operator", "nonlocal_pw"); if(is_first_node) { setmem_complex_op()(tmhpsi, 0, nbasis*nbands/npol); @@ -232,9 +232,10 @@ void Nonlocal>::act( //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // qianrui optimize 2021-3-31 int nkb = this->ppcell->nkb; - if (this->nkb_m < nbands * nkb) { - resmem_complex_op()(this->becp, nbands * nkb, "Nonlocal::becp"); - } + if (this->nkb_m < nbands * nkb) + { + resmem_complex_op()(this->becp, nbands * nkb, "Nonlocal::becp"); + } // ModuleBase::ComplexMatrix becp(nbands, nkb, false); char transa = 'C'; char transb = 'N'; @@ -302,7 +303,7 @@ void Nonlocal>::act( delete[] vnlpsi; #endif } - ModuleBase::timer::tick("Operator", "NonlocalPW"); + ModuleBase::timer::tick("Operator", "nonlocal_pw"); } template @@ -338,4 +339,4 @@ template class Nonlocal, base_device::DEVICE_GPU // Nonlocal, base_device::DEVICE_GPU>>::Nonlocal(const // Nonlocal, base_device::DEVICE_GPU>> *nonlocal); #endif -} // namespace hamilt \ No newline at end of file +} // namespace hamilt diff --git a/source/module_hamilt_pw/hamilt_pwdft/operator_pw/veff_pw.cpp b/source/module_hamilt_pw/hamilt_pwdft/operator_pw/veff_pw.cpp index d6c39132133..5d7f1dcf133 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/operator_pw/veff_pw.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/operator_pw/veff_pw.cpp @@ -47,7 +47,7 @@ void Veff>::act( const int ngk_ik, const bool is_first_node)const { - ModuleBase::timer::tick("Operator", "VeffPW"); + ModuleBase::timer::tick("Operator", "veff_pw"); if(is_first_node) { setmem_complex_op()(tmhpsi, 0, nbasis*nbands/npol); @@ -99,7 +99,7 @@ void Veff>::act( #ifdef __DSP wfcpw->fft_bundle.resource_handler(0); #endif - ModuleBase::timer::tick("Operator", "VeffPW"); + ModuleBase::timer::tick("Operator", "veff_pw"); } template diff --git a/source/module_hsolver/diago_iter_assist.cpp b/source/module_hsolver/diago_iter_assist.cpp index e39b8bd44b2..afc865f2ef9 100644 --- a/source/module_hsolver/diago_iter_assist.cpp +++ b/source/module_hsolver/diago_iter_assist.cpp @@ -28,8 +28,8 @@ void DiagoIterAssist::diagH_subspace(const hamilt::Hamilt* // of evc, if set to 0, n_band = nstart, default 0 ) { - ModuleBase::TITLE("DiagoIterAssist", "diagH_subspace"); - ModuleBase::timer::tick("DiagoIterAssist", "diagH_subspace"); + ModuleBase::TITLE("DiagoAssist", "diag_subspace"); + ModuleBase::timer::tick("DiagoAssist", "diag_subspace"); // two case: // 1. pw base: nstart = n_band, psi(nbands * npwx) @@ -143,7 +143,7 @@ void DiagoIterAssist::diagH_subspace(const hamilt::Hamilt* delmem_complex_op()(scc); delmem_complex_op()(vcc); - ModuleBase::timer::tick("DiagoIterAssist", "diagH_subspace"); + ModuleBase::timer::tick("DiagoAssist", "diag_subspace"); } template @@ -608,4 +608,4 @@ template class DiagoIterAssist; template class DiagoIterAssist; #endif #endif -} // namespace hsolver \ No newline at end of file +} // namespace hsolver diff --git a/source/module_hsolver/hsolver_pw.cpp b/source/module_hsolver/hsolver_pw.cpp index 62bff8a9158..a8b9c02eecf 100644 --- a/source/module_hsolver/hsolver_pw.cpp +++ b/source/module_hsolver/hsolver_pw.cpp @@ -375,6 +375,7 @@ void HSolverPW::hamiltSolvePsiK(hamilt::Hamilt* hm, Real* eigenvalue, const int& nk_nums) { + ModuleBase::timer::tick("HSolverPW", "solve_psik"); #ifdef __MPI const diag_comm_info comm_info = {POOL_WORLD, this->rank_in_pool, this->nproc_in_pool}; #else @@ -421,7 +422,6 @@ void HSolverPW::hamiltSolvePsiK(hamilt::Hamilt* hm, // wrap the hpsi_func and spsi_func into a lambda function auto hpsi_func = [hm, cur_nbasis](const ct::Tensor& psi_in, ct::Tensor& hpsi_out) { - ModuleBase::timer::tick("DiagoCG_New", "hpsi_func"); // psi_in should be a 2D tensor: // psi_in.shape() = [nbands, nbasis] const auto ndim = psi_in.shape().ndim(); @@ -436,10 +436,8 @@ void HSolverPW::hamiltSolvePsiK(hamilt::Hamilt* hm, using hpsi_info = typename hamilt::Operator::hpsi_info; hpsi_info info(&psi_wrapper, all_bands_range, hpsi_out.data()); hm->ops->hPsi(info); - ModuleBase::timer::tick("DiagoCG_New", "hpsi_func"); }; auto spsi_func = [this, hm](const ct::Tensor& psi_in, ct::Tensor& spsi_out) { - ModuleBase::timer::tick("DiagoCG_New", "spsi_func"); // psi_in should be a 2D tensor: // psi_in.shape() = [nbands, nbasis] const auto ndim = psi_in.shape().ndim(); @@ -462,17 +460,18 @@ void HSolverPW::hamiltSolvePsiK(hamilt::Hamilt* hm, static_cast((ndim == 1 ? 1 : psi_in.shape().dim_size(0)) * (ndim == 1 ? psi_in.NumElements() : psi_in.shape().dim_size(1)))); } - - ModuleBase::timer::tick("DiagoCG_New", "spsi_func"); }; + auto psi_tensor = ct::TensorMap(psi.get_pointer(), ct::DataTypeToEnum::value, ct::DeviceTypeToEnum::value, ct::TensorShape({psi.get_nbands(), psi.get_nbasis()})); + auto eigen_tensor = ct::TensorMap(eigenvalue, ct::DataTypeToEnum::value, ct::DeviceTypeToEnum::value, ct::TensorShape({psi.get_nbands()})); + auto prec_tensor = ct::TensorMap(pre_condition.data(), ct::DataTypeToEnum::value, ct::DeviceTypeToEnum::value, @@ -491,7 +490,6 @@ void HSolverPW::hamiltSolvePsiK(hamilt::Hamilt* hm, const int ndim = psi.get_current_ngk(); // hpsi_func (X, HX, ld, nvec) -> HX = H(X), X and HX blockvectors of size ld x nvec auto hpsi_func = [hm, cur_nbasis](T* psi_in, T* hpsi_out, const int ld_psi, const int nvec) { - ModuleBase::timer::tick("diago_bpcg", "hpsi_func"); // Convert "pointer data stucture" to a psi::Psi object auto psi_iter_wrapper = psi::Psi(psi_in, 1, nvec, ld_psi, cur_nbasis); @@ -501,8 +499,6 @@ void HSolverPW::hamiltSolvePsiK(hamilt::Hamilt* hm, using hpsi_info = typename hamilt::Operator::hpsi_info; hpsi_info info(&psi_iter_wrapper, bands_range, hpsi_out); hm->ops->hPsi(info); - - ModuleBase::timer::tick("diago_bpcg", "hpsi_func"); }; DiagoBPCG bpcg(pre_condition.data()); bpcg.init_iter(PARAM.inp.nbands, nband_l, nbasis, ndim); @@ -512,7 +508,6 @@ void HSolverPW::hamiltSolvePsiK(hamilt::Hamilt* hm, { // hpsi_func (X, HX, ld, nvec) -> HX = H(X), X and HX blockvectors of size ld x nvec auto hpsi_func = [hm, cur_nbasis](T* psi_in, T* hpsi_out, const int ld_psi, const int nvec) { - ModuleBase::timer::tick("DavSubspace", "hpsi_func"); // Convert "pointer data stucture" to a psi::Psi object auto psi_iter_wrapper = psi::Psi(psi_in, 1, nvec, ld_psi, cur_nbasis); @@ -522,8 +517,6 @@ void HSolverPW::hamiltSolvePsiK(hamilt::Hamilt* hm, using hpsi_info = typename hamilt::Operator::hpsi_info; hpsi_info info(&psi_iter_wrapper, bands_range, hpsi_out); hm->ops->hPsi(info); - - ModuleBase::timer::tick("DavSubspace", "hpsi_func"); }; bool scf = this->calculation_type == "nscf" ? false : true; @@ -565,7 +558,6 @@ void HSolverPW::hamiltSolvePsiK(hamilt::Hamilt* hm, /// wrap hpsi into lambda function, Matrix \times blockvector // hpsi_func (X, HX, ld, nvec) -> HX = H(X), X and HX blockvectors of size ld x nvec auto hpsi_func = [hm, cur_nbasis](T* psi_in, T* hpsi_out, const int ld_psi, const int nvec) { - ModuleBase::timer::tick("David", "hpsi_func"); // Convert pointer of psi_in to a psi::Psi object auto psi_iter_wrapper = psi::Psi(psi_in, 1, nvec, ld_psi, cur_nbasis); @@ -575,8 +567,6 @@ void HSolverPW::hamiltSolvePsiK(hamilt::Hamilt* hm, using hpsi_info = typename hamilt::Operator::hpsi_info; hpsi_info info(&psi_iter_wrapper, bands_range, hpsi_out); hm->ops->hPsi(info); - - ModuleBase::timer::tick("David", "hpsi_func"); }; /// wrap spsi into lambda function, Matrix \times blockvector @@ -587,11 +577,9 @@ void HSolverPW::hamiltSolvePsiK(hamilt::Hamilt* hm, const int ld_psi, // Leading dimension of psi and spsi. const int nvec // Number of vectors(bands) ) { - ModuleBase::timer::tick("David", "spsi_func"); // sPsi determines S=I or not by PARAM.globalv.use_uspp inside // sPsi(psi, spsi, nrow, npw, nbands) hm->sPsi(psi_in, spsi_out, ld_psi, ld_psi, nvec); - ModuleBase::timer::tick("David", "spsi_func"); }; DiagoDavid david(pre_condition.data(), nband, dim, PARAM.inp.pw_diag_ndim, this->use_paw, comm_info); @@ -606,6 +594,7 @@ void HSolverPW::hamiltSolvePsiK(hamilt::Hamilt* hm, ntry_max, notconv_max)); } + ModuleBase::timer::tick("HSolverPW", "solve_psik"); return; } From aabb29af155f4dcb582c2bd5a5bf5ef6a579b274 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Tue, 25 Mar 2025 22:59:30 +0800 Subject: [PATCH 03/22] update output formats --- source/module_cell/klist.cpp | 4 ++-- source/module_cell/print_cell.cpp | 8 +++---- source/module_cell/unitcell.cpp | 6 ++--- .../module_charge/charge_mixing.cpp | 24 ++++++++++--------- source/module_elecstate/read_pseudo.cpp | 6 ++--- source/module_esolver/esolver.cpp | 2 +- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/source/module_cell/klist.cpp b/source/module_cell/klist.cpp index 3c771d3dc6d..405511e5f79 100644 --- a/source/module_cell/klist.cpp +++ b/source/module_cell/klist.cpp @@ -52,7 +52,7 @@ void K_Vectors::set(const UnitCell& ucell, { ModuleBase::TITLE("K_Vectors", "set"); - ofs << "\n\n\n\n"; + ofs << "\n\n"; ofs << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl; ofs << " | |" << std::endl; ofs << " | Setup K-points |" << std::endl; @@ -61,7 +61,7 @@ void K_Vectors::set(const UnitCell& ucell, ofs << " | We treat the spin as another set of k-points. |" << std::endl; ofs << " | |" << std::endl; ofs << " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl; - ofs << "\n\n\n\n"; + ofs << "\n\n"; ofs << "\n SETUP K-POINTS" << std::endl; diff --git a/source/module_cell/print_cell.cpp b/source/module_cell/print_cell.cpp index 7864f051041..1177bbdf41b 100644 --- a/source/module_cell/print_cell.cpp +++ b/source/module_cell/print_cell.cpp @@ -23,8 +23,7 @@ namespace unitcell bool direct = (Coordinate == "Direct"); std::string table; table += direct? "DIRECT COORDINATES\n": FmtCore::format("CARTESIAN COORDINATES ( UNIT = %20.12f Bohr ).\n", lat0); - const std::string redundant_header = direct? "taud_": "tauc_"; - table += FmtCore::format("%8s%20s%20s%20s%8s%20s%20s%20s\n", "atom", "x", "y", "z", "mag", "vx", "vy", "vz"); + table += FmtCore::format("%8s%10s%10s%10s%8s%8s%8s%8s\n", "atom", "x", "y", "z", "mag", "vx", "vy", "vz"); for(int it = 0; it < ntype; it++) { for (int ia = 0; ia < atoms[it].na; ia++) @@ -32,8 +31,7 @@ namespace unitcell const double& x = direct? atoms[it].taud[ia].x: atoms[it].tau[ia].x; const double& y = direct? atoms[it].taud[ia].y: atoms[it].tau[ia].y; const double& z = direct? atoms[it].taud[ia].z: atoms[it].tau[ia].z; - table += FmtCore::format("%5s%-s%-5d%20.10f%20.10f%20.10f%8.4f%20.10f%20.10f%20.10f\n", // I dont know why there must be a redundant "tau[c|d]_" in the output. So ugly, it should be removed! - redundant_header, + table += FmtCore::format(" %-s%-5d%10.3f%10.3f%10.3f%8.3f%8.3f%8.3f%8.3f\n", atoms[it].label, ia+1, x, @@ -140,4 +138,4 @@ namespace unitcell ofs.close(); return; } -} \ No newline at end of file +} diff --git a/source/module_cell/unitcell.cpp b/source/module_cell/unitcell.cpp index b5c8c6b8468..5f4dd37c866 100755 --- a/source/module_cell/unitcell.cpp +++ b/source/module_cell/unitcell.cpp @@ -214,7 +214,7 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log) { if (ok) { - log << "\n\n\n\n"; + log << "\n\n"; log << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" ">>>>>>>>>>>>" << std::endl; @@ -254,7 +254,7 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log) { log << " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" "<<<<<<<<<<<<" << std::endl; - log << "\n\n\n\n"; + log << "\n\n"; log << " READING UNITCELL INFORMATION" << std::endl; //======================== @@ -560,4 +560,4 @@ void UnitCell::compare_atom_labels(std::string label1, std::string label2) { } } } -} \ No newline at end of file +} diff --git a/source/module_elecstate/module_charge/charge_mixing.cpp b/source/module_elecstate/module_charge/charge_mixing.cpp index 0fcc13fc5e7..6f17b84d476 100644 --- a/source/module_elecstate/module_charge/charge_mixing.cpp +++ b/source/module_elecstate/module_charge/charge_mixing.cpp @@ -58,22 +58,24 @@ void Charge_Mixing::set_mixing(const std::string& mixing_mode_in, } // print into running.log - GlobalV::ofs_running<<"\n----------- Double Check Mixing Parameters Begin ------------"<mixing_mode <mixing_beta <mixing_gg0 <mixing_mode); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "mixing_beta", this->mixing_beta); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "mixing_gg0", this->mixing_gg0); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "mixing_gg0_min", PARAM.inp.mixing_gg0_min); + if (PARAM.inp.nspin==2 || PARAM.inp.nspin==4) { - GlobalV::ofs_running<<"mixing_beta_mag: "<< this->mixing_beta_mag <mixing_beta_mag); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "mixing_gg0_mag", PARAM.inp.mixing_gg0_mag); } if (PARAM.inp.mixing_angle > 0) { - GlobalV::ofs_running<<"mixing_angle: "<< PARAM.inp.mixing_angle <mixing_ndim <mixing_ndim); return; } @@ -240,4 +242,4 @@ bool Charge_Mixing::if_scf_oscillate(const int iteration, const double drho, con } return false; -} \ No newline at end of file +} diff --git a/source/module_elecstate/read_pseudo.cpp b/source/module_elecstate/read_pseudo.cpp index f91073e6c99..7921e43bbe6 100644 --- a/source/module_elecstate/read_pseudo.cpp +++ b/source/module_elecstate/read_pseudo.cpp @@ -11,7 +11,7 @@ namespace elecstate { void read_pseudo(std::ofstream& ofs, UnitCell& ucell) { // read in non-local pseudopotential and ouput the projectors. - ofs << "\n\n\n\n"; + ofs << "\n\n"; ofs << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" ">>>>" << std::endl; @@ -54,7 +54,7 @@ void read_pseudo(std::ofstream& ofs, UnitCell& ucell) { ofs << " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" "<<<<" << std::endl; - ofs << "\n\n\n\n"; + ofs << "\n\n"; read_cell_pseudopots(PARAM.inp.pseudo_dir, ofs, ucell); @@ -368,4 +368,4 @@ void print_unitcell_pseudo(const std::string& fn, UnitCell& ucell) return; } -} \ No newline at end of file +} diff --git a/source/module_esolver/esolver.cpp b/source/module_esolver/esolver.cpp index a727a7a095e..46f4e238401 100644 --- a/source/module_esolver/esolver.cpp +++ b/source/module_esolver/esolver.cpp @@ -95,7 +95,7 @@ std::string determine_type() ModuleBase::WARNING_QUIT("ESolver", "No such esolver_type combined with basis_type"); } - GlobalV::ofs_running << " The esolver type has been set to : " << esolver_type << std::endl; + GlobalV::ofs_running << "\n The esolver type: " << esolver_type << std::endl; auto device_info = PARAM.inp.device; From 931f4ac6dcecd66c848e36c43f634c052c5a99e1 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Wed, 26 Mar 2025 12:54:48 +0800 Subject: [PATCH 04/22] update print_cell --- source/module_cell/print_cell.cpp | 3 +-- source/module_cell/test/unitcell_test.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/source/module_cell/print_cell.cpp b/source/module_cell/print_cell.cpp index 1177bbdf41b..d05136753cc 100644 --- a/source/module_cell/print_cell.cpp +++ b/source/module_cell/print_cell.cpp @@ -31,9 +31,8 @@ namespace unitcell const double& x = direct? atoms[it].taud[ia].x: atoms[it].tau[ia].x; const double& y = direct? atoms[it].taud[ia].y: atoms[it].tau[ia].y; const double& z = direct? atoms[it].taud[ia].z: atoms[it].tau[ia].z; - table += FmtCore::format(" %-s%-5d%10.3f%10.3f%10.3f%8.3f%8.3f%8.3f%8.3f\n", + table += FmtCore::format("%8s%10.3f%10.3f%10.3f%8.3f%8.3f%8.3f%8.3f\n", atoms[it].label, - ia+1, x, y, z, diff --git a/source/module_cell/test/unitcell_test.cpp b/source/module_cell/test/unitcell_test.cpp index 08f764a22c7..7d037422bd5 100644 --- a/source/module_cell/test/unitcell_test.cpp +++ b/source/module_cell/test/unitcell_test.cpp @@ -1018,7 +1018,8 @@ TEST_F(UcellTest, PrintTauDirect) ifs.open("print_tau_direct"); std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); EXPECT_THAT(str, testing::HasSubstr("DIRECT COORDINATES")); - EXPECT_THAT(str, testing::HasSubstr("taud_C1 0.1000000000 0.1000000000 0.1000000000")); + EXPECT_THAT(str, testing::HasSubstr(" C 0.100 0.100 0.100 0.000 0.100 0.100 0.100")); + EXPECT_THAT(str, testing::HasSubstr(" H 0.150 0.150 0.150 0.000 0.100 0.100 0.100")); ifs.close(); remove("print_tau_direct"); } @@ -1036,7 +1037,8 @@ TEST_F(UcellTest, PrintTauCartesian) ifs.open("print_tau_Cartesian"); std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); EXPECT_THAT(str, testing::HasSubstr("CARTESIAN COORDINATES")); - EXPECT_THAT(str, testing::HasSubstr("tauc_C1 1.0000000000 1.0000000000 1.0000000000")); + EXPECT_THAT(str, testing::HasSubstr(" C 1.000 1.000 1.000 0.000 0.000 0.000 0.000")); + EXPECT_THAT(str, testing::HasSubstr(" H 1.500 1.500 1.500 0.000 0.000 0.000 0.000")); ifs.close(); remove("print_tau_Cartesian"); } From 71e555697282555df240101215c14ab596fceaeb Mon Sep 17 00:00:00 2001 From: mohanchen Date: Wed, 26 Mar 2025 13:18:11 +0800 Subject: [PATCH 05/22] add ofs in print_tau --- source/module_cell/print_cell.cpp | 5 +++-- source/module_cell/read_atoms.cpp | 2 +- source/module_cell/test/unitcell_test.cpp | 24 +++++++++++++++++------ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/source/module_cell/print_cell.cpp b/source/module_cell/print_cell.cpp index d05136753cc..221a6c259c3 100644 --- a/source/module_cell/print_cell.cpp +++ b/source/module_cell/print_cell.cpp @@ -11,7 +11,8 @@ namespace unitcell void print_tau(Atom* atoms, const std::string& Coordinate, const int ntype, - const double lat0) + const double lat0, + ofstream &ofs) { ModuleBase::TITLE("UnitCell", "print_tau"); // assert (direct || Coordinate == "Cartesian" || Coordinate == "Cartesian_angstrom"); // this line causes abort in unittest ReadAtomPositionsCACXY. @@ -43,7 +44,7 @@ namespace unitcell } } table += "\n"; - GlobalV::ofs_running << table << std::endl; + ofs << table << std::endl; return; } diff --git a/source/module_cell/read_atoms.cpp b/source/module_cell/read_atoms.cpp index 545ef21a5bc..c5b2d6ccabf 100644 --- a/source/module_cell/read_atoms.cpp +++ b/source/module_cell/read_atoms.cpp @@ -556,7 +556,7 @@ bool read_atom_positions(UnitCell& ucell, if (unitcell::check_tau(ucell.atoms, ucell.ntype, ucell.lat0)) { - unitcell::print_tau(ucell.atoms,ucell.Coordinate,ucell.ntype,ucell.lat0); + unitcell::print_tau(ucell.atoms,ucell.Coordinate,ucell.ntype,ucell.lat0,ofs_running); return true; } return false; diff --git a/source/module_cell/test/unitcell_test.cpp b/source/module_cell/test/unitcell_test.cpp index 7d037422bd5..70d058d090b 100644 --- a/source/module_cell/test/unitcell_test.cpp +++ b/source/module_cell/test/unitcell_test.cpp @@ -1010,10 +1010,14 @@ TEST_F(UcellTest, PrintTauDirect) UcellTestPrepare utp = UcellTestLib["C1H2-Index"]; PARAM.input.relax_new = utp.relax_new; ucell = utp.SetUcellInfo(); - GlobalV::ofs_running.open("print_tau_direct"); EXPECT_EQ(ucell->Coordinate, "Direct"); - unitcell::print_tau(ucell->atoms,ucell->Coordinate,ucell->ntype,ucell->lat0); - GlobalV::ofs_running.close(); + + // open a file + std::ofstream ofs("print_tau_direct"); + unitcell::print_tau(ucell->atoms,ucell->Coordinate,ucell->ntype,ucell->lat0,ofs); + ofs.close(); + + // readin the data std::ifstream ifs; ifs.open("print_tau_direct"); std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); @@ -1021,6 +1025,8 @@ TEST_F(UcellTest, PrintTauDirect) EXPECT_THAT(str, testing::HasSubstr(" C 0.100 0.100 0.100 0.000 0.100 0.100 0.100")); EXPECT_THAT(str, testing::HasSubstr(" H 0.150 0.150 0.150 0.000 0.100 0.100 0.100")); ifs.close(); + + // remove the file remove("print_tau_direct"); } @@ -1029,10 +1035,14 @@ TEST_F(UcellTest, PrintTauCartesian) UcellTestPrepare utp = UcellTestLib["C1H2-Cartesian"]; PARAM.input.relax_new = utp.relax_new; ucell = utp.SetUcellInfo(); - GlobalV::ofs_running.open("print_tau_Cartesian"); EXPECT_EQ(ucell->Coordinate, "Cartesian"); - unitcell::print_tau(ucell->atoms,ucell->Coordinate,ucell->ntype,ucell->lat0); - GlobalV::ofs_running.close(); + + // open a file + std::ofstream ofs("print_tau_Cartesian"); + unitcell::print_tau(ucell->atoms,ucell->Coordinate,ucell->ntype,ucell->lat0,ofs); + ofs.close(); + + // readin the data std::ifstream ifs; ifs.open("print_tau_Cartesian"); std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); @@ -1040,6 +1050,8 @@ TEST_F(UcellTest, PrintTauCartesian) EXPECT_THAT(str, testing::HasSubstr(" C 1.000 1.000 1.000 0.000 0.000 0.000 0.000")); EXPECT_THAT(str, testing::HasSubstr(" H 1.500 1.500 1.500 0.000 0.000 0.000 0.000")); ifs.close(); + + // remove the file remove("print_tau_Cartesian"); } From 4353a55af4a183bc154d6f8b6ac7e0c8ded3dee5 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Wed, 26 Mar 2025 13:23:41 +0800 Subject: [PATCH 06/22] update print_tau --- source/module_cell/print_cell.cpp | 2 +- source/module_cell/print_cell.h | 5 +++-- source/module_relax/relax_new/relax.cpp | 4 ++-- source/module_relax/relax_old/ions_move_basic.cpp | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/source/module_cell/print_cell.cpp b/source/module_cell/print_cell.cpp index 221a6c259c3..86ae13a4c53 100644 --- a/source/module_cell/print_cell.cpp +++ b/source/module_cell/print_cell.cpp @@ -12,7 +12,7 @@ namespace unitcell const std::string& Coordinate, const int ntype, const double lat0, - ofstream &ofs) + std::ofstream &ofs) { ModuleBase::TITLE("UnitCell", "print_tau"); // assert (direct || Coordinate == "Cartesian" || Coordinate == "Cartesian_angstrom"); // this line causes abort in unittest ReadAtomPositionsCACXY. diff --git a/source/module_cell/print_cell.h b/source/module_cell/print_cell.h index d20313f2c92..84cffaf069b 100644 --- a/source/module_cell/print_cell.h +++ b/source/module_cell/print_cell.h @@ -8,7 +8,8 @@ namespace unitcell void print_tau(Atom* atoms, const std::string& Coordinate, const int ntype, - const double lat0); + const double lat0, + std::ofstream &ofs); /** * @brief UnitCell class is too heavy, this function would be moved @@ -40,4 +41,4 @@ namespace unitcell const int& iproc = 0); } -#endif \ No newline at end of file +#endif diff --git a/source/module_relax/relax_new/relax.cpp b/source/module_relax/relax_new/relax.cpp index 8dc081d5f92..5e563322d9f 100644 --- a/source/module_relax/relax_new/relax.cpp +++ b/source/module_relax/relax_new/relax.cpp @@ -637,7 +637,7 @@ void Relax::move_cell_ions(UnitCell& ucell, const bool is_new_dir) unitcell::update_pos_taud(ucell.lat,move_ion,ucell.ntype,ucell.nat,ucell.atoms); // Print the structure file. - unitcell::print_tau(ucell.atoms,ucell.Coordinate,ucell.ntype,ucell.lat0); + unitcell::print_tau(ucell.atoms,ucell.Coordinate,ucell.ntype,ucell.lat0,GlobalV::ofs_running); // ================================================================= // Step 4 : update G,GT and other stuff @@ -699,4 +699,4 @@ void Relax::move_cell_ions(UnitCell& ucell, const bool is_new_dir) unitcell::setup_cell_after_vc(ucell,GlobalV::ofs_running); ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "SETUP UNITCELL"); } -} \ No newline at end of file +} diff --git a/source/module_relax/relax_old/ions_move_basic.cpp b/source/module_relax/relax_old/ions_move_basic.cpp index f65c925f2df..a8dabe57437 100644 --- a/source/module_relax/relax_old/ions_move_basic.cpp +++ b/source/module_relax/relax_old/ions_move_basic.cpp @@ -112,7 +112,7 @@ void Ions_Move_Basic::move_atoms(UnitCell &ucell, double *move, double *pos) //-------------------------------------------- // Print out the structure file. //-------------------------------------------- - unitcell::print_tau(ucell.atoms,ucell.Coordinate,ucell.ntype,ucell.lat0); + unitcell::print_tau(ucell.atoms,ucell.Coordinate,ucell.ntype,ucell.lat0,GlobalV::ofs_running); return; } @@ -217,7 +217,7 @@ void Ions_Move_Basic::terminate(const UnitCell &ucell) //----------------------------------------------------------- // Print the structure. //----------------------------------------------------------- - unitcell::print_tau(ucell.atoms,ucell.Coordinate,ucell.ntype,ucell.lat0); + unitcell::print_tau(ucell.atoms,ucell.Coordinate,ucell.ntype,ucell.lat0,GlobalV::ofs_running); return; } From 959fe8bca6778d6421a01f033db78fd0360b7a25 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Wed, 26 Mar 2025 14:13:37 +0800 Subject: [PATCH 07/22] update output formats --- .../module_neighbor/sltk_atom_arrange.cpp | 5 ++-- .../module_cell/module_neighbor/sltk_grid.cpp | 9 ++++--- source/module_cell/print_cell.cpp | 2 +- source/module_cell/read_atoms.cpp | 9 ++++--- source/module_elecstate/elecstate_print.cpp | 20 ++++++++++++--- .../module_gint/cal_psir_ylm.cpp | 6 ++--- source/module_io/print_info.cpp | 25 +++++++++++++------ 7 files changed, 52 insertions(+), 24 deletions(-) diff --git a/source/module_cell/module_neighbor/sltk_atom_arrange.cpp b/source/module_cell/module_neighbor/sltk_atom_arrange.cpp index 548389f55fd..b669fa3d4a5 100644 --- a/source/module_cell/module_neighbor/sltk_atom_arrange.cpp +++ b/source/module_cell/module_neighbor/sltk_atom_arrange.cpp @@ -74,8 +74,9 @@ void atom_arrange::search(const bool pbc_flag, ModuleBase::WARNING_QUIT("atom_arrange::search", " search_radius_bohr < 0,forbidden"); } - ModuleBase::GlobalFunc::OUT(ofs_in, "searching radius is (Bohr))", search_radius_bohr); - ModuleBase::GlobalFunc::OUT(ofs_in, "searching radius unit is (Bohr))", ucell.lat0); + ofs_in << " SEARCH ADJACENT ATOMS" << std::endl; + ModuleBase::GlobalFunc::OUT(ofs_in, "searching radius is (Bohr)", search_radius_bohr); + ModuleBase::GlobalFunc::OUT(ofs_in, "searching radius unit is (Bohr)", ucell.lat0); assert(ucell.nat > 0); diff --git a/source/module_cell/module_neighbor/sltk_grid.cpp b/source/module_cell/module_neighbor/sltk_grid.cpp index 4a409940fe1..73ccbcf9894 100644 --- a/source/module_cell/module_neighbor/sltk_grid.cpp +++ b/source/module_cell/module_neighbor/sltk_grid.cpp @@ -195,9 +195,10 @@ void Grid::setMemberVariables(std::ofstream& ofs_in, // output data to ofs } } } - ModuleBase::GlobalFunc::OUT(ofs_in, "Find the coordinate range of the input atom(unit:lat0)."); - ModuleBase::GlobalFunc::OUT(ofs_in, "min_tau", x_min, y_min, z_min); - ModuleBase::GlobalFunc::OUT(ofs_in, "max_tau", x_max, y_max, z_max); + + ofs_in << " RANGE OF ATOMIC COORDINATES (unit: lat0)" << std::endl; + ModuleBase::GlobalFunc::OUT(ofs_in, "smallest coordinates of atoms", x_min, y_min, z_min); + ModuleBase::GlobalFunc::OUT(ofs_in, "largest coordinates of atoms", x_max, y_max, z_max); this->box_edge_length = sradius + 0.1; // To avoid edge cases, the size of the box is slightly increased. @@ -220,7 +221,7 @@ void Grid::setMemberVariables(std::ofstream& ofs_in, // output data to ofs this->box_nx = glayerX + glayerX_minus; this->box_ny = glayerY + glayerY_minus; this->box_nz = glayerZ + glayerZ_minus; - ModuleBase::GlobalFunc::OUT(ofs_in, "BoxNumber", box_nx, box_ny, box_nz); + ModuleBase::GlobalFunc::OUT(ofs_in, "number of needed cells", box_nx, box_ny, box_nz); atoms_in_box.resize(this->box_nx); for (int i = 0; i < this->box_nx; i++) diff --git a/source/module_cell/print_cell.cpp b/source/module_cell/print_cell.cpp index 86ae13a4c53..ecce588e084 100644 --- a/source/module_cell/print_cell.cpp +++ b/source/module_cell/print_cell.cpp @@ -23,7 +23,7 @@ namespace unitcell assert(std::regex_search(Coordinate, pattern)); bool direct = (Coordinate == "Direct"); std::string table; - table += direct? "DIRECT COORDINATES\n": FmtCore::format("CARTESIAN COORDINATES ( UNIT = %20.12f Bohr ).\n", lat0); + table += direct? "DIRECT COORDINATES\n": FmtCore::format(" CARTESIAN COORDINATES ( UNIT = %15.8f Bohr ).\n", lat0); table += FmtCore::format("%8s%10s%10s%10s%8s%8s%8s%8s\n", "atom", "x", "y", "z", "mag", "vx", "vy", "vz"); for(int it = 0; it < ntype; it++) { diff --git a/source/module_cell/read_atoms.cpp b/source/module_cell/read_atoms.cpp index c5b2d6ccabf..b1feb05609f 100644 --- a/source/module_cell/read_atoms.cpp +++ b/source/module_cell/read_atoms.cpp @@ -514,7 +514,9 @@ bool read_atom_positions(UnitCell& ucell, ucell.atoms[it].m_loc_[ia].x = 1.0; ucell.atoms[it].m_loc_[ia].y = 1.0; ucell.atoms[it].m_loc_[ia].z = 1.0; - ucell.atoms[it].mag[ia] = sqrt(pow(ucell.atoms[it].m_loc_[ia].x,2)+pow(ucell.atoms[it].m_loc_[ia].y,2)+pow(ucell.atoms[it].m_loc_[ia].z,2)); + ucell.atoms[it].mag[ia] = sqrt(pow(ucell.atoms[it].m_loc_[ia].x,2) + +pow(ucell.atoms[it].m_loc_[ia].y,2) + +pow(ucell.atoms[it].m_loc_[ia].z,2)); ModuleBase::GlobalFunc::OUT(ofs_running,"Autoset magnetism for this atom", 1.0, 1.0, 1.0); } } @@ -535,15 +537,16 @@ bool read_atom_positions(UnitCell& ucell, // End Autoset magnetization } // end scan_begin -//check if any atom can move in MD + //check if any atom can move in MD if(!ucell.if_atoms_can_move() && PARAM.inp.calculation=="md" && PARAM.inp.esolver_type!="tddft") { ModuleBase::WARNING("read_atoms", "no atom can move in MD!"); return false; } + ofs_running << std::endl; - ModuleBase::GlobalFunc::OUT(ofs_running,"TOTAL ATOM NUMBER",ucell.nat); + ModuleBase::GlobalFunc::OUT(ofs_running,"total number of atoms",ucell.nat); if (ucell.nat == 0) { diff --git a/source/module_elecstate/elecstate_print.cpp b/source/module_elecstate/elecstate_print.cpp index 1e7972d8ecc..aabbdd9297c 100644 --- a/source/module_elecstate/elecstate_print.cpp +++ b/source/module_elecstate/elecstate_print.cpp @@ -273,7 +273,7 @@ void print_band(const ModuleBase::matrix& ekb, { GlobalV::ofs_running << std::setprecision(6); GlobalV::ofs_running << " Energy (eV) & Occupations for spin=" << klist->isk[ik] + 1 - << " K-point=" << ik + 1 << std::endl; + << " k-point=" << ik + 1 << std::endl; GlobalV::ofs_running << std::setiosflags(std::ios::showpoint); for (int ib = 0; ib < PARAM.globalv.nbands_l; ib++) { @@ -317,7 +317,7 @@ void print_etot(const Magnetism& magnet, GlobalV::ofs_running << std::setprecision(12); GlobalV::ofs_running << std::setiosflags(std::ios::right); - GlobalV::ofs_running << "\n Density error is " << scf_thr << std::endl; + GlobalV::ofs_running << " Electron density error is " << scf_thr << std::endl; if (PARAM.inp.basis_type == "pw") { @@ -327,6 +327,7 @@ void print_etot(const Magnetism& magnet, std::vector titles; std::vector energies_Ry; std::vector energies_eV; + if (printe > 0 && ((iter + 1) % printe == 0 || converged || iter == PARAM.inp.scf_nmax)) { int n_order = std::max(0, Occupy::gaussian_type); @@ -384,7 +385,7 @@ void print_etot(const Magnetism& magnet, } #ifdef __DEEPKS - if (PARAM.inp.deepks_scf) // caoyu add 2021-08-10 + if (PARAM.inp.deepks_scf) { titles.push_back("E_DeePKS"); energies_Ry.push_back(elec.f_en.edeepks_delta); @@ -399,6 +400,7 @@ void print_etot(const Magnetism& magnet, energies_Ry.push_back(elec.f_en.etot_harris); } + // print out the Fermi energy if needed if (PARAM.globalv.two_fermi) { titles.push_back("E_Fermi_up"); @@ -411,6 +413,8 @@ void print_etot(const Magnetism& magnet, titles.push_back("E_Fermi"); energies_Ry.push_back(elec.eferm.ef); } + + // print out the band gap if needed if (PARAM.inp.out_bandgap) { if (!PARAM.globalv.two_fermi) @@ -430,13 +434,21 @@ void print_etot(const Magnetism& magnet, std::transform(energies_Ry.begin(), energies_Ry.end(), energies_eV.begin(), [](double ener) { return ener * ModuleBase::Ry_to_eV; }); + + // for each SCF step, we print out energy FmtTable table({"Energy", "Rydberg", "eV"}, titles.size(), {"%-14s", "%20.10f", "%20.10f"}, {FmtTable::Align::LEFT, FmtTable::Align::CENTER}); + + // print out the titles table << titles << energies_Ry << energies_eV; + GlobalV::ofs_running << table.str() << std::endl; - if (PARAM.inp.out_level == "ie" || PARAM.inp.out_level == "m") // xiaohui add 'm' option, 2015-09-16 + + + + if (PARAM.inp.out_level == "ie" || PARAM.inp.out_level == "m") { std::vector mag; switch (PARAM.inp.nspin) diff --git a/source/module_hamilt_lcao/module_gint/cal_psir_ylm.cpp b/source/module_hamilt_lcao/module_gint/cal_psir_ylm.cpp index d1bda7fa088..0eb9b16e6ba 100644 --- a/source/module_hamilt_lcao/module_gint/cal_psir_ylm.cpp +++ b/source/module_hamilt_lcao/module_gint/cal_psir_ylm.cpp @@ -13,7 +13,7 @@ void cal_psir_ylm( const bool* const* const cal_flag, double* const* const psir_ylm) // cal_flag[bxyz][na_grid], whether the atom-grid distance is larger than cutoff { - ModuleBase::timer::tick("Gint_Tools", "cal_psir_ylm"); +// ModuleBase::timer::tick("Gint_Tools", "cal_psir_ylm"); std::vector ylma; const UnitCell& ucell = *gt.ucell; std::vector it_psi_uniform(gt.nwmax); @@ -107,7 +107,7 @@ void cal_psir_ylm( } // end distance<=(rcuts[it]-1.0e-15) } // end ib } // end id - ModuleBase::timer::tick("Gint_Tools", "cal_psir_ylm"); +// ModuleBase::timer::tick("Gint_Tools", "cal_psir_ylm"); return; } -} \ No newline at end of file +} diff --git a/source/module_io/print_info.cpp b/source/module_io/print_info.cpp index 61a5cc3b23a..6c60b7f7b5c 100644 --- a/source/module_io/print_info.cpp +++ b/source/module_io/print_info.cpp @@ -11,8 +11,13 @@ void setup_parameters(UnitCell& ucell, K_Vectors& kv) { ModuleBase::TITLE("ModuleIO", "setup_parameters"); - if(PARAM.inp.calculation=="scf" || PARAM.inp.calculation=="relax" || PARAM.inp.calculation=="cell-relax" || PARAM.inp.calculation=="nscf" - || PARAM.inp.calculation=="get_pchg" || PARAM.inp.calculation=="get_wf" || PARAM.inp.calculation=="md") + if(PARAM.inp.calculation=="scf" + || PARAM.inp.calculation=="relax" + || PARAM.inp.calculation=="cell-relax" + || PARAM.inp.calculation=="nscf" + || PARAM.inp.calculation=="get_pchg" + || PARAM.inp.calculation=="get_wf" + || PARAM.inp.calculation=="md") { std::cout << " ---------------------------------------------------------" << std::endl; if(PARAM.inp.calculation=="scf") @@ -203,7 +208,7 @@ void print_rhofft(ModulePW::PW_Basis* pw_rhod, << std::endl; } - ofs << "\n\n\n\n"; + ofs << "\n\n"; ofs << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" ">>>>" << std::endl; @@ -231,10 +236,13 @@ void print_rhofft(ModulePW::PW_Basis* pw_rhod, ofs << " | is 'npw' in each processor. " " |" << std::endl; + ofs << " | " + " |" + << std::endl; ofs << " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" "<<<<" << std::endl; - ofs << "\n\n\n\n"; + ofs << "\n\n"; ofs << "\n SETUP THE PLANE WAVE BASIS" << std::endl; double ecut = 4 * PARAM.inp.ecutwfc; @@ -317,7 +325,7 @@ void print_rhofft(ModulePW::PW_Basis* pw_rhod, void print_wfcfft(const Input_para& inp, ModulePW::PW_Basis_K& pw_wfc, std::ofstream& ofs) { - ofs << "\n\n\n\n"; + ofs << "\n\n"; ofs << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" ">>>>" << std::endl; @@ -345,10 +353,13 @@ void print_wfcfft(const Input_para& inp, ModulePW::PW_Basis_K& pw_wfc, std::ofst ofs << " | each k-point is 'npwk[ik]' in each processor " " |" << std::endl; + ofs << " | " + " |" + << std::endl; ofs << " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" "<<<<" << std::endl; - ofs << "\n\n\n\n"; + ofs << "\n\n"; ofs << "\n SETUP PLANE WAVES FOR WAVE FUNCTIONS" << std::endl; double ecut = inp.ecutwfc; @@ -424,4 +435,4 @@ void print_screen(const int& stress_step, const int& force_step, const int& iste GlobalV::ofs_running << " -------------------------------------------" << std::endl; } -} // namespace ModuleIO \ No newline at end of file +} // namespace ModuleIO From 9a8552d0f7fe3544f4591ea61d703233c2d61e8a Mon Sep 17 00:00:00 2001 From: mohanchen Date: Wed, 26 Mar 2025 15:29:24 +0800 Subject: [PATCH 08/22] update md outputs --- source/module_base/memory.cpp | 7 ++-- .../hamilt_lcaodft/FORCE_STRESS.cpp | 11 ++---- source/module_io/output_log.cpp | 38 ++++++++++++++----- source/module_md/md_func.cpp | 13 ++++--- 4 files changed, 45 insertions(+), 24 deletions(-) diff --git a/source/module_base/memory.cpp b/source/module_base/memory.cpp index 8d67f9ea4ca..3f8fe287afd 100644 --- a/source/module_base/memory.cpp +++ b/source/module_base/memory.cpp @@ -385,8 +385,9 @@ void Memory::print_all(std::ofstream &ofs) Parallel_Reduce::reduce_all(Memory::total_gpu); #endif #endif - ofs <<"\n NAME-------------------------|MEMORY(MB)--------" << std::endl; - ofs <0); @@ -440,7 +441,7 @@ void Memory::print_all(std::ofstream &ofs) return; } - ofs <<"\n NAME-------------------------|GPU MEMORY(MB)----" << std::endl; + ofs <<"\n NAME-------------------------|GPU MEMORY(MB)--------------" << std::endl; ofs <0); diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp index fd4118f10c0..51eefdaea67 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp @@ -733,19 +733,14 @@ void Force_Stress_LCAO::getForceStress(UnitCell& ucell, GlobalV::ofs_running << std::setiosflags(std::ios::showpos); GlobalV::ofs_running << std::setiosflags(std::ios::fixed) << std::setprecision(10) << std::endl; ModuleIO::print_stress("OVERLAP STRESS", soverlap, PARAM.inp.test_stress, ry); - // test ModuleIO::print_stress("T STRESS", stvnl_dphi, PARAM.inp.test_stress, ry); ModuleIO::print_stress("VNL STRESS", svnl_dbeta, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("T_VNL STRESS", stvnl, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("VL_dPHI STRESS", svl_dphi, PARAM.inp.test_stress, ry); ModuleIO::print_stress("VL_dVL STRESS", sigmadvl, PARAM.inp.test_stress, ry); ModuleIO::print_stress("HAR STRESS", sigmahar, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("EWALD STRESS", sigmaewa, PARAM.inp.test_stress, ry); ModuleIO::print_stress("cc STRESS", sigmacc, PARAM.inp.test_stress, ry); - // ModuleIO::print_stress("NLCC STRESS",sigmacc,PARAM.inp.test_stress,ry); ModuleIO::print_stress("XC STRESS", sigmaxc, PARAM.inp.test_stress, ry); if (vdw_solver != nullptr) { @@ -760,11 +755,13 @@ void Force_Stress_LCAO::getForceStress(UnitCell& ucell, ModuleIO::print_stress("DeltaSpin STRESS", stress_dspin, PARAM.inp.test_stress, ry); } ModuleIO::print_stress("TOTAL STRESS", scs, PARAM.inp.test_stress, ry); - } // end of test + GlobalV::ofs_running << std::setiosflags(std::ios::left); + // print total stress - ModuleIO::print_stress("TOTAL-STRESS", scs, true, ry); + bool screen = false; + ModuleIO::print_stress("TOTAL-STRESS", scs, screen, ry); double unit_transform = 0.0; unit_transform = ModuleBase::RYDBERG_SI / pow(ModuleBase::BOHR_RADIUS_SI, 3) * 1.0e-8; diff --git a/source/module_io/output_log.cpp b/source/module_io/output_log.cpp index 7bf3a08d993..dd7b81ab1c8 100644 --- a/source/module_io/output_log.cpp +++ b/source/module_io/output_log.cpp @@ -223,7 +223,10 @@ void print_force(std::ofstream& ofs_running, std::vector force_y; std::vector force_z; std::string table; - std::vector titles({name, "", "", ""}); + + ofs_running << " " << name << std::endl; + + std::vector titles({"Atoms", "Force_x", "Force_y", "Force_z"}); int iat = 0; for (int it = 0; it < cell.ntype; it++) { @@ -242,13 +245,24 @@ void print_force(std::ofstream& ofs_running, } } - FmtTable fmt(titles, atom_label.size(), {"%10s", "%20.10f", "%20.10f", "%20.10f"}); + // titles: titles for each column + // atom_label.size(): number of lines in this table + // format for each value in the column + FmtTable fmt(titles, + atom_label.size(), + {"%8s", "%20.10f", "%20.10f", "%20.10f"}, + {FmtTable::Align::RIGHT,FmtTable::Align::RIGHT}); + fmt << atom_label << force_x << force_y << force_z; table = fmt.str(); ofs_running << table << std::endl; - if (PARAM.inp.test_force) { std::cout << table << std::endl; -} + + if (PARAM.inp.test_force) + { + std::cout << table << std::endl; + } } + void print_stress(const std::string& name, const ModuleBase::matrix& scs, const bool screen, const bool ry) { const double output_acc = 1.0e-8; @@ -270,7 +284,10 @@ void print_stress(const std::string& name, const ModuleBase::matrix& scs, const std::vector stress_y; std::vector stress_z; std::string table; - std::vector titles({title, "", ""}); + + GlobalV::ofs_running << " " << title << std::endl; + + std::vector titles({"Stress_x", "Stress_y", "Stress_z"}); for (int i = 0; i < 3; i++) { double sx = scs(i, 0) * unit_transform; @@ -283,14 +300,16 @@ void print_stress(const std::string& name, const ModuleBase::matrix& scs, const double pressure = (scs(0, 0) + scs(1, 1) + scs(2, 2)) / 3.0 * unit_transform; - FmtTable fmt(titles, 3, {"%20.10f", "%20.10f", "%20.10f"}); + FmtTable fmt(titles, 3, {"%20.10f", "%20.10f", "%20.10f"}, + {FmtTable::Align::RIGHT,FmtTable::Align::RIGHT}); + fmt << stress_x << stress_y << stress_z; table = fmt.str(); GlobalV::ofs_running << table; if (name == "TOTAL-STRESS") { - GlobalV::ofs_running << " TOTAL-PRESSURE: " << std::fixed << std::setprecision(6) << pressure << unit - << std::endl + GlobalV::ofs_running << " TOTAL-PRESSURE (DO NOT INCLUDE KINETIC PART OF IONS): " << std::fixed + << std::setprecision(6) << pressure << unit << std::endl; } if (screen) @@ -298,7 +317,8 @@ void print_stress(const std::string& name, const ModuleBase::matrix& scs, const std::cout << table; if (name == "TOTAL-STRESS") { - std::cout << " TOTAL-PRESSURE: " << std::fixed << std::setprecision(6) << pressure << unit << std::endl + std::cout << " TOTAL-PRESSURE (DO NOT INCLUDE KINETIC PART OF IONS): " << std::fixed + << std::setprecision(6) << pressure << unit << std::endl; } } diff --git a/source/module_md/md_func.cpp b/source/module_md/md_func.cpp index 07bc1f03f21..3fa000f095f 100644 --- a/source/module_md/md_func.cpp +++ b/source/module_md/md_func.cpp @@ -293,16 +293,18 @@ void print_stress(std::ofstream& ofs, const ModuleBase::matrix& virial, const Mo for (int i = 0; i < 3; i++) { - stress_scalar += stress(i, i) / 3; - virial_scalar += virial(i, i) / 3; + stress_scalar += stress(i, i) / 3.0; + virial_scalar += virial(i, i) / 3.0; } const double unit_transform = ModuleBase::HARTREE_SI / pow(ModuleBase::BOHR_RADIUS_SI, 3) * 1.0e-8; - ofs << "Virtual Pressure is " << stress_scalar * unit_transform << " kbar " << std::endl; - ofs << "Virial Term is " << virial_scalar * unit_transform << " kbar " << std::endl; - ofs << "Kinetic Term is " << (stress_scalar - virial_scalar) * unit_transform << " kbar " << std::endl; + ofs << " MD PRESSURE (ELECTRONS+IONS) : " << stress_scalar * unit_transform << " KBAR" << std::endl; + ofs << " ELECTRONIC PART OF STRESS: " << virial_scalar * unit_transform << " KBAR" << std::endl; + ofs << " IONIC (KINETIC) PART OF STRESS: " << (stress_scalar - virial_scalar) * unit_transform << " KBAR" << std::endl; + // one should use 'print_stress' function in ../source/module_io/output_log.cpp +/* ofs.unsetf(std::ios::fixed); ofs << std::setprecision(8) << std::endl; ModuleBase::GlobalFunc::NEW_PART("MD STRESS (kbar)"); @@ -312,6 +314,7 @@ void print_stress(std::ofstream& ofs, const ModuleBase::matrix& virial, const Mo << std::setw(15) << stress(i, 2) * unit_transform << std::endl; } ofs << std::setiosflags(std::ios::left); +*/ return; } From eb0a3020ee84a6527b9c3ce4a80ec18914109d3c Mon Sep 17 00:00:00 2001 From: mohanchen Date: Thu, 27 Mar 2025 09:40:51 +0800 Subject: [PATCH 09/22] beging modifying the autotests --- tests/integrate/README.md | 7 ++-- tests/integrate/Single_job.sh | 9 +++-- tests/integrate/tools/run_check.sh | 59 +++++++++++++++++------------- 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/tests/integrate/README.md b/tests/integrate/README.md index 3923895a654..79ffff96d4f 100644 --- a/tests/integrate/README.md +++ b/tests/integrate/README.md @@ -1,9 +1,9 @@ -1, modify file general_info +1. Modify the file general_info -2, try this script for autotest: +2. try this script for autotest: ./Autotest.sh > check.txt -3, if want to focus on No. xxx example, such as 101_PW_OU_PL: +3. if you want to focus on No.xxx example, such as 101_PW_OU_PL: cd 101_PW_OU_PL ./../run_debug.sh $parameter @@ -20,7 +20,6 @@ NOTES: 3, if there is any bug occurs, rename the bug example path to mark it please. ####################### -################## "simple" scripts diff --git a/tests/integrate/Single_job.sh b/tests/integrate/Single_job.sh index 6b8f141d1d2..65815320e60 100755 --- a/tests/integrate/Single_job.sh +++ b/tests/integrate/Single_job.sh @@ -1,9 +1,10 @@ #!/bin/bash -#input parameter: - #none: run and check for this example; - #debug: copy the scripts to debug, then run and check this example; - #other: run this example and generate reference file. +# The note for using the script. +# input parameter: + #'none': run and check for this example; + #'debug': copy scripts to debug, then run and check this example; + #'other': run this example and generate reference file. if test -z $1 then diff --git a/tests/integrate/tools/run_check.sh b/tests/integrate/tools/run_check.sh index 98230887d38..48a5835dc30 100755 --- a/tests/integrate/tools/run_check.sh +++ b/tests/integrate/tools/run_check.sh @@ -21,34 +21,43 @@ check_out(){ done } -test -e ../general_info||echo "plese write the file general_info" -test -e ../general_info||exit 0 +test -e ../general_info|| echo "plese prepare the general_info file." + +test -e ../general_info|| exit 0 + exec_path=`grep EXEC ../general_info|awk '{printf $2}'` + test -e $exec_path || echo "Error! ABACUS path was wrong!!" + test -e $exec_path || exit 0 + CA=`grep CHECKACCURACY ../general_info | awk '{printf $2}'` + NP=`grep NUMBEROFPROCESS ../general_info | awk '{printf $2}'` - path_here=`pwd` - echo "Test in $path_here" - - echo "Begin test with $NP cores" - #parallel test - mpirun -np $NP $exec_path > log.txt - test -d OUT.autotest || echo "Some errors happened in ABACUS!" - test -d OUT.autotest || exit 0 - - #if any input parameters for this script, just generate reference file. - if test -z $1 - then - ../tools/catch_properties.sh result.out - check_out result.out - elif [ $1 == "debug" ] - then - ./catch_properties.sh result.out - check_out result.out - else - ../tools/catch_properties.sh result.ref - rm -r OUT.autotest - rm log.txt - fi +path_here=`pwd` +echo "Test in $path_here" + +echo "Begin testing the example with $NP cores" + +#parallel test +mpirun -np $NP $exec_path > log.txt + +test -d OUT.autotest || echo "Some errors happened in ABACUS!" + +test -d OUT.autotest || exit 0 + +#if any input parameters for this script, just generate reference file. +if test -z $1 +then +../tools/catch_properties.sh result.out +check_out result.out +elif [ $1 == "debug" ] +then +./catch_properties.sh result.out +check_out result.out +else +../tools/catch_properties.sh result.ref +rm -r OUT.autotest +rm log.txt +fi From 2fc86bb3a082aac67bc62a2a8caf508cb473e624 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Thu, 27 Mar 2025 10:39:42 +0800 Subject: [PATCH 10/22] update integrate tests --- source/module_cell/read_atoms.cpp | 2 +- tests/integrate/general_info | 3 +++ tests/integrate/tools/catch_properties.sh | 14 +++++++++----- tests/integrate/tools/run_check.sh | 5 +++-- 4 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 tests/integrate/general_info diff --git a/source/module_cell/read_atoms.cpp b/source/module_cell/read_atoms.cpp index b1feb05609f..78f825281f2 100644 --- a/source/module_cell/read_atoms.cpp +++ b/source/module_cell/read_atoms.cpp @@ -546,7 +546,7 @@ bool read_atom_positions(UnitCell& ucell, ofs_running << std::endl; - ModuleBase::GlobalFunc::OUT(ofs_running,"total number of atoms",ucell.nat); + ModuleBase::GlobalFunc::OUT(ofs_running,"TOTAL ATOM NUMBER",ucell.nat); if (ucell.nat == 0) { diff --git a/tests/integrate/general_info b/tests/integrate/general_info new file mode 100644 index 00000000000..d548f755430 --- /dev/null +++ b/tests/integrate/general_info @@ -0,0 +1,3 @@ +EXEC /xxx/abacus +CHECKACCURACY 1.0e-2 +NUMBEROFPROCESS 1 diff --git a/tests/integrate/tools/catch_properties.sh b/tests/integrate/tools/catch_properties.sh index c72afea9b34..c7e16537802 100755 --- a/tests/integrate/tools/catch_properties.sh +++ b/tests/integrate/tools/catch_properties.sh @@ -77,27 +77,31 @@ word="driver_line" symmetry=$(get_input_key_value "symmetry" "INPUT") out_current=$(get_input_key_value "out_current" "INPUT") test -e $1 && rm $1 -#-------------------------------------------- + +#------------------------------------------------------------ # if NOT non-self-consistent calculations or linear response -#-------------------------------------------- +#------------------------------------------------------------ is_lr=0 if [ ! -z $esolver_type ] && ([ $esolver_type == "lr" ] || [ $esolver_type == "ks-lr" ]); then is_lr=1 fi +#---------------------------- +# total energy information +#---------------------------- if [ $calculation != "get_wf" ]\ && [ $calculation != "get_pchg" ] && [ $calculation != "get_S" ]\ && [ $is_lr == 0 ]; then - #etot=`grep ETOT_ $running_path | awk '{print $2}'` etot=$(grep "ETOT_" "$running_path" | tail -1 | awk '{print $2}') etotperatom=`awk 'BEGIN {x='$etot';y='$natom';printf "%.10f\n",x/y}'` echo "etotref $etot" >>$1 echo "etotperatomref $etotperatom" >>$1 fi - -#echo $etot +#---------------------------- +# force information #echo "hasforce:"$has_force +#---------------------------- if ! test -z "$has_force" && [ $has_force == 1 ]; then nn3=`echo "$natom + 1" |bc` #nn1=`echo "$natom + 1" |bc` diff --git a/tests/integrate/tools/run_check.sh b/tests/integrate/tools/run_check.sh index 48a5835dc30..61a4efb6180 100755 --- a/tests/integrate/tools/run_check.sh +++ b/tests/integrate/tools/run_check.sh @@ -1,6 +1,7 @@ #!/bin/bash - +# check_out: checking the output information +# input: result.out check_out(){ outfile=$1 worddir=`awk '{print $1}' $outfile` @@ -43,7 +44,7 @@ echo "Begin testing the example with $NP cores" #parallel test mpirun -np $NP $exec_path > log.txt -test -d OUT.autotest || echo "Some errors happened in ABACUS!" +test -d OUT.autotest || echo "Some errors occured in ABACUS!" test -d OUT.autotest || exit 0 From 5840f5053b9c1b85c8f79d487bcb7e35d150568f Mon Sep 17 00:00:00 2001 From: mohanchen Date: Thu, 27 Mar 2025 11:11:29 +0800 Subject: [PATCH 11/22] update some timers --- source/driver.cpp | 34 ++--- source/driver_run.cpp | 4 +- tests/integrate/tools/catch_properties.sh | 176 +++++++++++++++++----- 3 files changed, 161 insertions(+), 53 deletions(-) diff --git a/source/driver.cpp b/source/driver.cpp index efd76ca276b..ffa2d4c2f63 100644 --- a/source/driver.cpp +++ b/source/driver.cpp @@ -23,24 +23,27 @@ Driver::~Driver() void Driver::init() { - ModuleBase::TITLE("Driver", "init"); + // 1) Let's start by printing a title. + ModuleBase::TITLE("Driver", "ABACUS_begins"); + // 2) Print the current time, since it may run a long time. time_t time_start = std::time(nullptr); ModuleBase::timer::start(); - // (1) read the input parameters. - // INPUT should be initalized here and then pass to atomic world, mohan - // 2024-05-12 INPUT should not be GlobalC, mohan 2024-05-12 - Driver::reading(); - - // (2) welcome to the atomic world! + // 3) Welcome to the atomic world! Let's do some fancy stuff here. this->atomic_world(); - // (3) output information + // 4) All timers recorders are printed. + ModuleBase::timer::finish(GlobalV::ofs_running); + + // 5) All memory recorders are printed. + ModuleBase::Memory::print_all(GlobalV::ofs_running); + + // 6) Print the final time, hopefully it will not cost too long. time_t time_finish = std::time(nullptr); ModuleIO::print_time(time_start, time_finish); - // (4) close all of the running logs + // 7) Clean up: close all of the running logs ModuleBase::Global_File::close_all_log(GlobalV::MY_RANK, PARAM.inp.out_alllog,PARAM.inp.calculation); } @@ -169,16 +172,13 @@ void Driver::reading() void Driver::atomic_world() { ModuleBase::TITLE("Driver", "atomic_world"); - //-------------------------------------------------- - // choose basis sets: - // pw: plane wave basis set - // lcao_in_pw: LCAO expaned by plane wave basis set - // lcao: linear combination of atomic orbitals - //-------------------------------------------------- + ModuleBase::timer::tick("Driver", "atomic_world"); + + // reading information + this->reading(); // where the actual stuff is done this->driver_run(); - ModuleBase::timer::finish(GlobalV::ofs_running); - ModuleBase::Memory::print_all(GlobalV::ofs_running); + ModuleBase::timer::tick("Driver", "atomic_world"); } diff --git a/source/driver_run.cpp b/source/driver_run.cpp index ecf4f044055..2d24af0176d 100644 --- a/source/driver_run.cpp +++ b/source/driver_run.cpp @@ -25,12 +25,13 @@ */ void Driver::driver_run() { - ModuleBase::TITLE("Driver", "driver_line"); + ModuleBase::TITLE("Driver", "driver_run"); //! 1: setup cell and atom information // this warning should not be here, mohan 2024-05-22 #ifndef __LCAO if (PARAM.inp.basis_type == "lcao_in_pw" || PARAM.inp.basis_type == "lcao") { + ModuleBase::timer::tick("Driver","driver_run"); ModuleBase::WARNING_QUIT("driver", "to use LCAO basis, compile with __LCAO"); } @@ -92,5 +93,6 @@ void Driver::driver_run() //! 6: output the json file Json::create_Json(&ucell, PARAM); + return; } diff --git a/tests/integrate/tools/catch_properties.sh b/tests/integrate/tools/catch_properties.sh index c7e16537802..20f18456fbe 100755 --- a/tests/integrate/tools/catch_properties.sh +++ b/tests/integrate/tools/catch_properties.sh @@ -17,9 +17,7 @@ sum_file(){ done echo $sum } -#answer=`sum_file test.txt` -#echo $answer -#exit 0 + get_input_key_value(){ key=$1 @@ -28,8 +26,10 @@ get_input_key_value(){ echo $value } + file=$1 #echo $1 + calculation=`grep calculation INPUT | awk '{print $2}' | sed s/[[:space:]]//g` running_path=`echo "OUT.autotest/running_$calculation"".log"` natom=`grep -En '(^|[[:space:]])TOTAL ATOM NUMBER($|[[:space:]])' $running_path | tail -1 | awk '{print $6}'` @@ -73,7 +73,7 @@ esolver_type=$(get_input_key_value "esolver_type" "INPUT") rdmft=$(get_input_key_value "rdmft" "INPUT") #echo $running_path base=$(get_input_key_value "basis_type" "INPUT") -word="driver_line" +word_total_time="atomic_world" symmetry=$(get_input_key_value "symmetry" "INPUT") out_current=$(get_input_key_value "out_current" "INPUT") test -e $1 && rm $1 @@ -100,23 +100,22 @@ fi #---------------------------- # force information -#echo "hasforce:"$has_force +# echo "hasforce:"$has_force #---------------------------- if ! test -z "$has_force" && [ $has_force == 1 ]; then nn3=`echo "$natom + 1" |bc` - #nn1=`echo "$natom + 1" |bc` - #nn5=`echo "$natom + 6" |bc` - #grep -A$nn3 "TOTAL-FORCE" $running_path|sed '1,5d'|sed ''$nn1','$nn5'd'|awk '{printf $2"\t"$3"\t"$4"\n"}' > force.txt - grep -A$nn3 "TOTAL-FORCE" $running_path |awk 'NF==4{print $2,$3,$4}' | tail -$natom > force.txt #check the last step result + # check the last step result + grep -A$nn3 "TOTAL-FORCE" $running_path |awk 'NF==4{print $2,$3,$4}' | tail -$natom > force.txt total_force=`sum_file force.txt` rm force.txt echo "totalforceref $total_force" >>$1 fi -#echo $total_force -#echo "has_stress:"$has_stress +#------------------------------- +# stress information +# echo "has_stress:"$has_stress +#------------------------------- if ! test -z "$has_stress" && [ $has_stress == 1 ]; then - #grep -A6 "TOTAL-STRESS" $running_path|sed '1,4d'|sed '4,8d' >stress.txt grep -A4 "TOTAL-STRESS" $running_path| awk 'NF==3' | tail -3> stress.txt total_stress=`sum_file stress.txt` rm stress.txt @@ -124,22 +123,20 @@ if ! test -z "$has_stress" && [ $has_stress == 1 ]; then fi -#echo $total_stress -#if ! test -z "$has_charge" && [ $has_charge == 1 ]; then -# total_charge=`sum_file OUT.autotest/SPIN1_CHG` -# echo "totalchargeref $total_charge" >>$1 -#fi - - -#echo $total_charge +#------------------------------- +# DOS information +# echo $total_charge +#------------------------------- if ! test -z "$has_dos" && [ $has_dos == 1 ]; then total_dos=`cat OUT.autotest/DOS1_smearing.dat | awk 'END {print}' | awk '{print $3}'` echo "totaldosref $total_dos" >> $1 fi -# smearing_dos=`sum_file OUT.autotest/DOS1_smearing.dat` -# echo "totaldossmearing $smearing_dos" >> $1 +#smearing_dos=`sum_file OUT.autotest/DOS1_smearing.dat` +#echo "totaldossmearing $smearing_dos" >> $1 -#echo Onsager coefficiency +#------------------------------- +# Onsager coefficiency +#------------------------------- if ! test -z "$has_cond" && [ $has_cond == 1 ]; then onref=refOnsager.txt oncal=Onsager.txt @@ -148,7 +145,9 @@ if ! test -z "$has_cond" && [ $has_cond == 1 ]; then rm -f je-je.txt Chebycoef fi -#echo $out_dm1 +#------------------------------- +# echo $out_dm1 +#------------------------------- if ! test -z "$out_dm1" && [ $out_dm1 == 1 ]; then dm1ref=refdata-DMR-sparse_SPIN0.csr dm1cal=OUT.autotest/data-DMR-sparse_SPIN0.csr @@ -156,7 +155,9 @@ if ! test -z "$out_dm1" && [ $out_dm1 == 1 ]; then echo "CompareDM1_pass $?" >>$1 fi -#echo $out_pot1 +#------------------------------- +# echo $out_pot1 +#------------------------------- if ! test -z "$out_pot" && [ $out_pot == 1 ]; then pot1ref=refSPIN1_POT.cube pot1cal=OUT.autotest/SPIN1_POT.cube @@ -164,7 +165,9 @@ if ! test -z "$out_pot" && [ $out_pot == 1 ]; then echo "ComparePot1_pass $?" >>$1 fi +#------------------------------- #echo $out_pot2 +#------------------------------- if ! test -z "$out_pot" && [ $out_pot == 2 ]; then pot1ref=refElecStaticPot.cube pot1cal=OUT.autotest/ElecStaticPot.cube @@ -172,7 +175,10 @@ if ! test -z "$out_pot" && [ $out_pot == 2 ]; then echo "ComparePot_pass $?" >>$1 fi -#echo $out_elf +#------------------------------- +# Electron localized function +# echo $out_elf +#------------------------------- if ! test -z "$out_elf" && [ $out_elf == 1 ]; then elf1ref=refELF.cube elf1cal=OUT.autotest/ELF.cube @@ -180,7 +186,10 @@ if ! test -z "$out_elf" && [ $out_elf == 1 ]; then echo "ComparePot1_pass $?" >>$1 fi -#echo $get_s +#------------------------------- +# Overlap matrix +# echo $get_s +#------------------------------- if ! test -z "$get_s" && [ $get_s == "get_S" ]; then sref=refSR.csr scal=OUT.autotest/SR.csr @@ -188,7 +197,10 @@ if ! test -z "$get_s" && [ $get_s == "get_S" ]; then echo "CompareS_pass $?" >>$1 fi -#echo $out_pband +#------------------------------- +# Partial band structure +# echo $out_pband +#------------------------------- if ! test -z "$out_pband" && [ $out_pband == 1 ]; then #pbandref=refPBANDS_1 #pbandcal=OUT.autotest/PBANDS_1 @@ -200,7 +212,10 @@ if ! test -z "$out_pband" && [ $out_pband == 1 ]; then echo "CompareOrb_pass $?" >>$1 fi -#echo $toW90 +#------------------------------- +# Wannier90 information +# echo $toW90 +#------------------------------- if ! test -z "$toW90" && [ $toW90 == 1 ]; then amnref=diamond.amn amncal=OUT.autotest/diamond.amn @@ -218,15 +233,23 @@ if ! test -z "$toW90" && [ $toW90 == 1 ]; then echo "CompareEIG_pass $?" >>$1 fi -#echo total_dos -#echo $has_band +#------------------------------- +# Total DOS +# echo total_dos +# echo $has_band +#------------------------------- if ! test -z "$has_band" && [ $has_band == 1 ]; then bandref=refBANDS_1.dat bandcal=OUT.autotest/BANDS_1.dat python3 ../tools/CompareFile.py $bandref $bandcal 8 echo "CompareBand_pass $?" >>$1 fi -#echo $has_hs + + +#-------------------------------- +# Hamiltonian and overlap matrix +# echo $has_hs +#-------------------------------- if ! test -z "$has_hs" && [ $has_hs == 1 ]; then if ! test -z "$gamma_only" && [ $gamma_only == 1 ]; then href=data-0-H.ref @@ -246,6 +269,9 @@ if ! test -z "$has_hs" && [ $has_hs == 1 ]; then echo "CompareS_pass $?" >>$1 fi +#-------------------------------- +# exchange-correlation potential +#-------------------------------- if ! test -z "$has_xc" && [ $has_xc == 1 ]; then if ! test -z "$gamma_only" && [ $gamma_only == 1 ]; then xcref=k-0-Vxc.ref @@ -262,6 +288,9 @@ if ! test -z "$has_xc" && [ $has_xc == 1 ]; then echo "CompareOrbXC_pass $?" >>$1 fi +#-------------------------------- +# exchange-correlation potential +#-------------------------------- if ! test -z "$has_xc2" && [ $has_xc2 == 1 ]; then xc2ref=Vxc_R_spin0.ref xc2cal=OUT.autotest/Vxc_R_spin0.csr @@ -269,6 +298,9 @@ if ! test -z "$has_xc2" && [ $has_xc2 == 1 ]; then echo "CompareVXC_R_pass $?" >>$1 fi +#-------------------------------- +# separate terms in band enegy +#-------------------------------- if ! test -z "$has_eband_separate" && [ $has_eband_separate == 1 ]; then ekref=kinetic_out.ref ekcal=OUT.autotest/kinetic_out.dat @@ -288,6 +320,9 @@ if ! test -z "$has_eband_separate" && [ $has_eband_separate == 1 ]; then echo "CompareOrbVHartree_pass $?" >>$1 fi +#----------------------------------- +# Hamiltonian and overlap matrices +#----------------------------------- #echo $has_hs2 if ! test -z "$has_hs2" && [ $has_hs2 == 1 ]; then #python3 ../tools/CompareFile.py data-HR-sparse_SPIN0.csr.ref OUT.autotest/data-HR-sparse_SPIN0.csr 8 @@ -296,18 +331,27 @@ if ! test -z "$has_hs2" && [ $has_hs2 == 1 ]; then echo "CompareSR_pass $?" >>$1 fi +#----------------------------------- +# matrix +#----------------------------------- #echo $has_mat_r if ! test -z "$has_mat_r" && [ $has_mat_r == 1 ]; then python3 ../tools/CompareFile.py data-rR-sparse.csr.ref OUT.autotest/data-rR-sparse.csr 8 echo "ComparerR_pass $?" >>$1 fi +#----------------------------------- +# matrix +#----------------------------------- #echo $has_mat_t if ! test -z "$has_mat_t" && [ $has_mat_t == 1 ]; then python3 ../tools/CompareFile.py data-TR-sparse_SPIN0.csr.ref OUT.autotest/data-TR-sparse_SPIN0.csr 8 echo "ComparerTR_pass $?" >>$1 fi +#----------------------------------- +# matrix +#----------------------------------- #echo $has_mat_dh if ! test -z "$has_mat_dh" && [ $has_mat_dh == 1 ]; then python3 ../tools/CompareFile.py data-dHRx-sparse_SPIN0.csr.ref OUT.autotest/data-dHRx-sparse_SPIN0.csr 8 @@ -318,7 +362,10 @@ if ! test -z "$has_mat_dh" && [ $has_mat_dh == 1 ]; then echo "ComparerdHRz_pass $?" >>$1 fi +#--------------------------------------- +# SCAN exchange-correlation information #echo $has_scan +#--------------------------------------- if ! test -z "$has_scan" && [ $has_scan == "scan" ] && \ ! test -z "$out_chg" && [ $out_chg == 1 ]; then python3 ../tools/CompareFile.py SPIN1_CHG.cube.ref OUT.autotest/SPIN1_CHG.cube 8 @@ -327,14 +374,17 @@ if ! test -z "$has_scan" && [ $has_scan == "scan" ] && \ echo "SPIN1_TAU.cube_pass $?" >>$1 fi +#--------------------------------------- +# wave functions in real space # echo "$has_wfc_r" ## test out_wfc_r > 0 +#--------------------------------------- if ! test -z "$has_wfc_r" && [ $has_wfc_r == 1 ]; then if [[ ! -f OUT.autotest/running_scf.log ]];then echo "Can't find file OUT.autotest/running_scf.log" exit 1 fi nband=$(grep NBANDS OUT.autotest/running_scf.log|awk '{print $3}') -allgrid=$(grep "fft grid for wave functions" OUT.autotest/running_scf.log | awk -F "[=,\\\[\\\]]" '{print $3*$4*$5}') + allgrid=$(grep "fft grid for wave functions" OUT.autotest/running_scf.log | awk -F "[=,\\\[\\\]]" '{print $3*$4*$5}') for((band=0;band<$nband;band++));do if [[ -f "OUT.autotest/wfc_realspace/wfc_realspace_0_$band" ]];then variance_wfc_r=`sed -n "13,$"p OUT.autotest/wfc_realspace/wfc_realspace_0_$band | \ @@ -348,7 +398,10 @@ allgrid=$(grep "fft grid for wave functions" OUT.autotest/running_scf.log | awk done fi +#-------------------------------------------- +# wave functions in plane wave basis # echo "$has_wfc_pw" ## test out_wfc_pw > 0 +#-------------------------------------------- if ! test -z "$has_wfc_pw" && [ $has_wfc_pw == 1 ]; then if [[ ! -f OUT.autotest/WAVEFUNC1.txt ]];then echo "Can't find file OUT.autotest/WAVEFUNC1.txt" @@ -369,7 +422,11 @@ if ! test -z "$has_wfc_pw" && [ $has_wfc_pw == 1 ]; then }' OUT.autotest/WAVEFUNC1.txt >> $1 fi -# echo "$has_lowf" ## test out_wfc_lcao > 0 + +#-------------------------------------------- +# wave functions in LCAO basis +# echo "$has_lowf" # test out_wfc_lcao > 0 +#-------------------------------------------- if ! test -z "$has_lowf" && [ $has_lowf == 1 ]; then if ! test -z "$gamma_only" && [ $gamma_only == 1 ]; then wfc_cal=OUT.autotest/WFC_NAO_GAMMA1.txt @@ -400,6 +457,9 @@ if ! test -z "$has_lowf" && [ $has_lowf == 1 ]; then echo "Compare_wfc_lcao_pass $?" >>$1 fi +#-------------------------------------------- +# density matrix information +#-------------------------------------------- if ! test -z "$out_dm" && [ $out_dm == 1 ]; then dmfile=OUT.autotest/SPIN1_DM dmref=SPIN1_DM.ref @@ -412,11 +472,18 @@ if ! test -z "$out_dm" && [ $out_dm == 1 ]; then fi fi +#-------------------------------------------- +# mulliken charge +#-------------------------------------------- if ! test -z "$out_mul" && [ $out_mul == 1 ]; then python3 ../tools/CompareFile.py mulliken.txt.ref OUT.autotest/mulliken.txt 4 echo "Compare_mulliken_pass $?" >>$1 fi +#-------------------------------------------- +# obtain wave functions for each electronic +# state +#-------------------------------------------- if [ $calculation == "get_wf" ]; then nfile=0 # envfiles=`ls OUT.autotest/ | grep ENV$` @@ -444,6 +511,11 @@ if [ $calculation == "get_wf" ]; then fi fi + +#-------------------------------------------- +# obtian electron charge density for each +# electronic state +#-------------------------------------------- if [ $calculation == "get_pchg" ]; then nfile=0 # chgfiles=`ls OUT.autotest/ | grep -E '_CHG$'` @@ -471,6 +543,9 @@ if [ $calculation == "get_pchg" ]; then fi fi +#-------------------------------------------- +# implicit solvation model +#-------------------------------------------- if ! test -z "$imp_sol" && [ $imp_sol == 1 ]; then esol_el=`grep E_sol_el $running_path | awk '{print $3}'` esol_cav=`grep E_sol_cav $running_path | awk '{print $3}'` @@ -478,6 +553,9 @@ if ! test -z "$imp_sol" && [ $imp_sol == 1 ]; then echo "esolcavref $esol_cav" >>$1 fi +#-------------------------------------------- +# random phase approximation +#-------------------------------------------- if ! test -z "$run_rpa" && [ $run_rpa == 1 ]; then Etot_without_rpa=`grep Etot_without_rpa log.txt | awk 'BEGIN{FS=":"} {print $2}' ` echo "Etot_without_rpa $Etot_without_rpa" >> $1 @@ -486,6 +564,9 @@ if ! test -z "$run_rpa" && [ $run_rpa == 1 ]; then python3 ../tools/CompareFile.py $onref $oncal 8 fi +#-------------------------------------------- +# deepks +#-------------------------------------------- if ! test -z "$deepks_out_labels" && [ $deepks_out_labels == 1 ]; then sed '/n_des/d' OUT.autotest/deepks_desc.dat > des_tmp.txt total_des=`sum_file des_tmp.txt 5` @@ -505,6 +586,9 @@ if ! test -z "$deepks_out_labels" && [ $deepks_out_labels == 1 ]; then fi fi +#-------------------------------------------- +# band gap information +#-------------------------------------------- if ! test -z "$deepks_bandgap" && [ $deepks_bandgap == 1 ]; then odelta=`python3 get_odelta.py` echo "odelta $odelta" >>$1 @@ -512,6 +596,10 @@ if ! test -z "$deepks_bandgap" && [ $deepks_bandgap == 1 ]; then echo "oprec $oprec" >> $1 fi + +#-------------------------------------------- +# check vdelta in deepks +#-------------------------------------------- if ! test -z "$deepks_v_delta" && [ $deepks_v_delta == 1 ]; then totalh=`python3 get_sum_numpy.py OUT.autotest/deepks_htot.npy ` echo "totalh $totalh" >>$1 @@ -521,6 +609,9 @@ if ! test -z "$deepks_v_delta" && [ $deepks_v_delta == 1 ]; then echo "totalvdp $totalvdp" >> $1 fi +#-------------------------------------------- +# check vdelta in deepks +#-------------------------------------------- if ! test -z "$deepks_v_delta" && [ $deepks_v_delta == 2 ]; then totalh=`python3 get_sum_numpy.py OUT.autotest/deepks_htot.npy ` echo "totalh $totalh" >>$1 @@ -532,6 +623,9 @@ if ! test -z "$deepks_v_delta" && [ $deepks_v_delta == 2 ]; then echo "total_gevdm $total_gevdm" >> $1 fi +#-------------------------------------------- +# check symmetry +#-------------------------------------------- if ! test -z "$symmetry" && [ $symmetry == 1 ]; then pointgroup=`grep 'POINT GROUP' $running_path | tail -n 2 | head -n 1 | awk '{print $4}'` spacegroup=`grep 'SPACE GROUP' $running_path | tail -n 1 | awk '{print $7}'` @@ -541,6 +635,9 @@ if ! test -z "$symmetry" && [ $symmetry == 1 ]; then echo "nksibzref $nksibz" >>$1 fi +#-------------------------------------------- +# check currents in rt-TDDFT +#-------------------------------------------- if ! test -z "$out_current" && [ $out_current ]; then current1ref=refcurrent_total.dat current1cal=OUT.autotest/current_total.dat @@ -548,6 +645,9 @@ if ! test -z "$out_current" && [ $out_current ]; then echo "CompareCurrent_pass $?" >>$1 fi +#-------------------------------------------- +# Linear response function +#-------------------------------------------- if [ $is_lr == 1 ]; then lrns=$(get_input_key_value "lr_nstates" "INPUT") lrns1=`echo "$lrns + 1" |bc` @@ -556,6 +656,9 @@ if [ $is_lr == 1 ]; then echo "totexcitationenergyref $lreig_tot" >>$1 fi +#-------------------------------------------- +# Check RDMFT method +#-------------------------------------------- if ! test -z "$rdmft" && [[ $rdmft == 1 ]]; then echo "" >>$1 echo "The following energy units are in Rydberg:" >>$1 @@ -590,6 +693,9 @@ if ! test -z "$rdmft" && [[ $rdmft == 1 ]]; then echo "" >>$1 fi +#-------------------------------------------- +# Check time information +#-------------------------------------------- #echo $total_band -ttot=`grep $word $running_path | awk '{print $3}'` +ttot=`grep $word_total_time $running_path | awk '{print $3}'` echo "totaltimeref $ttot" >>$1 From 0189b6c1c142e90b8dc301d46ff38432d936df24 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Thu, 27 Mar 2025 11:20:11 +0800 Subject: [PATCH 12/22] fix total force and total stress --- tests/integrate/tools/catch_properties.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/integrate/tools/catch_properties.sh b/tests/integrate/tools/catch_properties.sh index 20f18456fbe..b62a348d0de 100755 --- a/tests/integrate/tools/catch_properties.sh +++ b/tests/integrate/tools/catch_properties.sh @@ -103,11 +103,12 @@ fi # echo "hasforce:"$has_force #---------------------------- if ! test -z "$has_force" && [ $has_force == 1 ]; then - nn3=`echo "$natom + 1" |bc` + nn3=`echo "$natom + 3" |bc` + # echo "nn3=$nn3" # check the last step result grep -A$nn3 "TOTAL-FORCE" $running_path |awk 'NF==4{print $2,$3,$4}' | tail -$natom > force.txt total_force=`sum_file force.txt` - rm force.txt + rm force.txt echo "totalforceref $total_force" >>$1 fi @@ -116,7 +117,7 @@ fi # echo "has_stress:"$has_stress #------------------------------- if ! test -z "$has_stress" && [ $has_stress == 1 ]; then - grep -A4 "TOTAL-STRESS" $running_path| awk 'NF==3' | tail -3> stress.txt + grep -A6 "TOTAL-STRESS" $running_path| awk 'NF==3' | tail -3> stress.txt total_stress=`sum_file stress.txt` rm stress.txt echo "totalstressref $total_stress" >>$1 From 34bcd1a27eae20b77b51a29e409e88baa3d111c3 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Thu, 27 Mar 2025 11:28:49 +0800 Subject: [PATCH 13/22] update integrate tests --- tests/integrate/general_info | 4 ++-- tests/integrate/tools/run_check.sh | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/integrate/general_info b/tests/integrate/general_info index d548f755430..462616452fb 100644 --- a/tests/integrate/general_info +++ b/tests/integrate/general_info @@ -1,3 +1,3 @@ EXEC /xxx/abacus -CHECKACCURACY 1.0e-2 -NUMBEROFPROCESS 1 +CHECKACCURACY 2 +NUMBEROFPROCESS 4 diff --git a/tests/integrate/tools/run_check.sh b/tests/integrate/tools/run_check.sh index 61a4efb6180..d0066fd1349 100755 --- a/tests/integrate/tools/run_check.sh +++ b/tests/integrate/tools/run_check.sh @@ -6,13 +6,18 @@ check_out(){ outfile=$1 worddir=`awk '{print $1}' $outfile` for word in $worddir; do + # serach result.out and get information cal=`grep "$word" $outfile | awk '{printf "%.'$CA'f\n",$2}'` + # search result.ref and get information ref=`grep "$word" result.ref | awk '{printf "%.'$CA'f\n",$2}'` + # compute the error between 'cal' and 'ref' error=`awk 'BEGIN {x='$ref';y='$cal';printf "%.'$CA'f\n",x-y}'` + # compare the total time if [ $word == "totaltimeref" ]; then echo "$word this-test: $cal ref-1core-test: $ref" break fi + # except the total time, other comparison may lead to 'wrong' results if [ $(echo "$error == 0"|bc) = 0 ]; then echo "----------Wrong!----------" echo "word cal ref error" From 9deffae723cb340462a2d6f5841247b7bca8a14d Mon Sep 17 00:00:00 2001 From: mohanchen Date: Thu, 27 Mar 2025 14:25:35 +0800 Subject: [PATCH 14/22] update print_band --- source/module_elecstate/elecstate_print.cpp | 19 +++++++------ source/module_elecstate/elecstate_print.h | 9 ++++-- .../test/elecstate_print_test.cpp | 28 +++++++++++++------ source/module_esolver/esolver_ks.cpp | 3 +- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/source/module_elecstate/elecstate_print.cpp b/source/module_elecstate/elecstate_print.cpp index 89e9ec38aba..da21f82a0d7 100644 --- a/source/module_elecstate/elecstate_print.cpp +++ b/source/module_elecstate/elecstate_print.cpp @@ -250,13 +250,16 @@ void print_band(const ModuleBase::matrix& ekb, const K_Vectors* klist, const int& ik, const int& printe, - const int& iter) + const int& iter, + std::ofstream &ofs) { + const double largest_eig = 1.0e10; + // check the band energy. bool wrong = false; for (int ib = 0; ib < PARAM.globalv.nbands_l; ++ib) { - if (std::abs(ekb(ik, ib)) > 1.0e10) + if (std::abs(ekb(ik, ib)) > largest_eig) { GlobalV::ofs_warning << " ik=" << ik + 1 << " ib=" << ib + 1 << " " << ekb(ik, ib) << " Ry" << std::endl; wrong = true; @@ -271,18 +274,18 @@ void print_band(const ModuleBase::matrix& ekb, { if (printe > 0 && ((iter + 1) % printe == 0)) { - GlobalV::ofs_running << std::setprecision(6); - GlobalV::ofs_running << " Energy (eV) & Occupations for spin=" << klist->isk[ik] + 1 + ofs << std::setprecision(6); + ofs << " Energy (eV) & Occupations for spin=" << klist->isk[ik] + 1 << " k-point=" << ik + 1 << std::endl; - GlobalV::ofs_running << std::setiosflags(std::ios::showpoint); + ofs << std::setiosflags(std::ios::showpoint); for (int ib = 0; ib < PARAM.globalv.nbands_l; ib++) { - GlobalV::ofs_running << " " << std::setw(6) << ib + 1 << std::setw(15) + ofs << " " << std::setw(6) << ib + 1 << std::setw(15) << ekb(ik, ib) * ModuleBase::Ry_to_eV; // for the first electron iteration, we don't have the energy // spectrum, so we can't get the occupations. - GlobalV::ofs_running << std::setw(15) << wg(ik, ib); - GlobalV::ofs_running << std::endl; + ofs << std::setw(15) << wg(ik, ib); + ofs << std::endl; } } } diff --git a/source/module_elecstate/elecstate_print.h b/source/module_elecstate/elecstate_print.h index a20c2278cc3..e1ad2fb284c 100644 --- a/source/module_elecstate/elecstate_print.h +++ b/source/module_elecstate/elecstate_print.h @@ -1,14 +1,17 @@ #ifndef ELECSATE_PRINT_H #define ELECSATE_PRINT_H + #include "module_elecstate/elecstate.h" + namespace elecstate { - void print_band(const ModuleBase::matrix& ekb, + void print_band(const ModuleBase::matrix& ekb, const ModuleBase::matrix& wg, const K_Vectors* klist, const int& ik, const int& printe, - const int& iter); + const int& iter, + std::ofstream &ofs); void print_format(const std::string& name, const double& value); @@ -30,4 +33,4 @@ namespace elecstate const double& avg_iter = 0, bool print = true); } -#endif \ No newline at end of file +#endif diff --git a/source/module_elecstate/test/elecstate_print_test.cpp b/source/module_elecstate/test/elecstate_print_test.cpp index 4904188cf0e..071bf994fa9 100644 --- a/source/module_elecstate/test/elecstate_print_test.cpp +++ b/source/module_elecstate/test/elecstate_print_test.cpp @@ -163,13 +163,16 @@ TEST_F(ElecStatePrintTest, PrintBand) PARAM.input.nbands = 2; PARAM.sys.nbands_l = 2; GlobalV::MY_RANK = 0; - GlobalV::ofs_running.open("test.dat", std::ios::out); - // print eigenvalue - elecstate::print_band(elecstate.ekb,elecstate.wg,elecstate.klist, 0, 1, 0); - GlobalV::ofs_running.close(); + + std::ofstream ofs; + ofs.open("test.dat", std::ios::out); + // print eigenvalues + elecstate::print_band(elecstate.ekb,elecstate.wg,elecstate.klist, 0, 1, 0, ofs); + ofs.close(); + ifs.open("test.dat", std::ios::in); std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); - EXPECT_THAT(str, testing::HasSubstr("Energy (eV) & Occupations for spin=1 K-point=1")); + EXPECT_THAT(str, testing::HasSubstr("Energy (eV) & Occupations for spin=1 k-point=1")); EXPECT_THAT(str, testing::HasSubstr("1 13.6057 0.100000")); EXPECT_THAT(str, testing::HasSubstr("2 27.2114 0.200000")); ifs.close(); @@ -193,12 +196,19 @@ TEST_F(ElecStatePrintTest, PrintBandWarning) { elecstate.ekb(0, 0) = 1.0e11; PARAM.input.nspin = 4; - GlobalV::ofs_running.open("test.dat", std::ios::out); + + std::ofstream ofs; + ofs.open("test.dat", std::ios::out); testing::internal::CaptureStdout(); - EXPECT_EXIT(elecstate::print_band(elecstate.ekb,elecstate.wg,elecstate.klist, 0, 1, 0), ::testing::ExitedWithCode(1), ""); + + EXPECT_EXIT(elecstate::print_band(elecstate.ekb,elecstate.wg,elecstate.klist, 0, 1, 0, ofs), + ::testing::ExitedWithCode(1), ""); + output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("Eigenvalues are too large!")); - GlobalV::ofs_running.close(); + + ofs.close(); + std::remove("test.dat"); } @@ -370,4 +380,4 @@ TEST_F(ElecStatePrintTest, PrintEtotColorS4) GlobalV::MY_RANK = 0; elecstate::print_etot(ucell.magnet,elecstate, converged, iter, scf_thr, scf_thr_kin, duration, printe, pw_diag_thr, avg_iter, print); delete elecstate.charge; -} \ No newline at end of file +} diff --git a/source/module_esolver/esolver_ks.cpp b/source/module_esolver/esolver_ks.cpp index 2a26b2c7de7..d47c864baee 100644 --- a/source/module_esolver/esolver_ks.cpp +++ b/source/module_esolver/esolver_ks.cpp @@ -550,7 +550,8 @@ void ESolver_KS::iter_finish(UnitCell& ucell, const int istep, int& i this->pelec->klist, ik, PARAM.inp.printe, - iter); + iter, + GlobalV::ofs_running); } // compute magnetization, only for LSDA(spin==2) From 871896029818e3a5b6319ca9b2011a2b949957da Mon Sep 17 00:00:00 2001 From: mohanchen Date: Thu, 27 Mar 2025 14:34:57 +0800 Subject: [PATCH 15/22] fix print_band --- source/module_elecstate/test/elecstate_print_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/module_elecstate/test/elecstate_print_test.cpp b/source/module_elecstate/test/elecstate_print_test.cpp index 071bf994fa9..4b457f2dc03 100644 --- a/source/module_elecstate/test/elecstate_print_test.cpp +++ b/source/module_elecstate/test/elecstate_print_test.cpp @@ -278,7 +278,7 @@ TEST_F(ElecStatePrintTest, PrintEtot) GlobalV::ofs_running.close(); ifs.open("test.dat", std::ios::in); std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); - EXPECT_THAT(str, testing::HasSubstr("Density error is 0.1")); + EXPECT_THAT(str, testing::HasSubstr("Electron density error is 0.1")); EXPECT_THAT(str, testing::HasSubstr("Error Threshold = 0.1")); EXPECT_THAT(str, testing::HasSubstr("E_KohnSham")); EXPECT_THAT(str, testing::HasSubstr("E_vdwD2")); @@ -320,7 +320,7 @@ TEST_F(ElecStatePrintTest, PrintEtot2) GlobalV::ofs_running.close(); ifs.open("test.dat", std::ios::in); std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); - EXPECT_THAT(str, testing::HasSubstr("Density error is 0.1")); + EXPECT_THAT(str, testing::HasSubstr("Electron density error is 0.1")); EXPECT_THAT(str, testing::HasSubstr("Error Threshold = 0.1")); EXPECT_THAT(str, testing::HasSubstr("E_KohnSham")); EXPECT_THAT(str, testing::HasSubstr("E_Harris")); From 05e9cc75e53fe1668bf77143e02880827b9b37f7 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Thu, 27 Mar 2025 17:38:48 +0800 Subject: [PATCH 16/22] update md print out information --- source/module_io/berryphase.cpp | 77 ++----------------------- source/module_io/write_wfc_pw.cpp | 4 +- source/module_md/fire.cpp | 7 ++- source/module_md/md_base.cpp | 10 ++-- source/module_md/md_func.cpp | 6 +- source/module_md/test/fire_test.cpp | 47 +++++++++------ source/module_md/test/langevin_test.cpp | 8 +-- source/module_md/test/md_func_test.cpp | 10 ++-- source/module_md/test/msst_test.cpp | 8 +-- source/module_md/test/nhchain_test.cpp | 11 ++-- source/module_md/test/verlet_test.cpp | 8 +-- 11 files changed, 67 insertions(+), 129 deletions(-) diff --git a/source/module_io/berryphase.cpp b/source/module_io/berryphase.cpp index c27c8b0f628..9efda5a09e9 100644 --- a/source/module_io/berryphase.cpp +++ b/source/module_io/berryphase.cpp @@ -36,7 +36,6 @@ void berryphase::get_occupation_bands() ModuleBase::WARNING_QUIT("berryphase::get_occupation_bands", "not enough bands for berryphase, increase band numbers."); } - // GlobalV::ofs_running << "the berryphase's occ_nbands is " << occ_nbands << std::endl; } #ifdef __LCAO @@ -214,25 +213,6 @@ void berryphase::set_kpoints(const K_Vectors& kv, const int direction) nppstr = mp_z + 1; } - - // test by jingan - /* - GlobalV::ofs_running << "direction is " << direction << std::endl; - GlobalV::ofs_running << "nppstr = " << nppstr << std::endl; - GlobalV::ofs_running << "total std::string is " << total_string << std::endl; - for(int istring = 0; istring < total_string; istring++) - { - GlobalV::ofs_running << " the std::string is " << istring << std::endl; - for(int count = 0; count < nppstr; count++) - { - GlobalV::ofs_running << "(" << kv.kvec_c[ k_index[istring][count] ].x << "," - << kv.kvec_c[ k_index[istring][count] ].y << "," - << kv.kvec_c[ k_index[istring][count] ].z << ")" << std::endl; - } - - } - */ - // test by jingan } #include "../module_base/complexmatrix.h" @@ -251,7 +231,6 @@ double berryphase::stringPhase(const UnitCell& ucell, int ik_2 = 0; ModuleBase::Vector3 G(0.0, 0.0, 0.0); ModuleBase::Vector3 dk = kv.kvec_c[k_index[index_str][1]] - kv.kvec_c[k_index[index_str][0]]; - // GlobalV::ofs_running << "the std::string index is " << index_str << std::endl; for (int k_start = 0; k_start < (nppstr - 1); k_start++) { @@ -351,45 +330,11 @@ double berryphase::stringPhase(const UnitCell& ucell, { if (PARAM.inp.nspin != 4) { - // std::complex my_det = lcao_method.det_berryphase(ik_1,ik_2,dk,nbands); zeta = zeta * lcao_method.det_berryphase(ucell,ik_1, ik_2, dk, nbands, *(this->paraV), psi_in, kv); - // test by jingan - // GlobalV::ofs_running << "methon 1: det = " << my_det << std::endl; - // test by jingan } else { } - - // test by jingan - /* - for (int mb = 0; mb < nbands; mb++) - { - - for (int nb = 0; nb < nbands; nb++) - { - - mat(nb, mb) = lcao_method.unkdotp_LCAO(ik_1,ik_2,nb,mb,dk,kv); - } - } - - std::complex det(1.0,0.0); - int info = 0; - int *ipiv = new int[nbands]; - LapackConnector::zgetrf(nbands, nbands, mat, nbands, ipiv, &info); - for (int ib = 0; ib < nbands; ib++) - { - if (ipiv[ib] != (ib+1)) det = -det * mat(ib,ib); - else det = det * mat(ib,ib); - } - - zeta = zeta*det; - - GlobalV::ofs_running << "methon 2: det = " << det << std::endl; - - delete[] ipiv; - */ - // test by jingan } #endif } @@ -441,9 +386,6 @@ void berryphase::Berry_Phase(const UnitCell& ucell, dtheta = atan2(cphik[istring].imag(), cphik[istring].real()); phik[istring] = (theta0 + dtheta) / (2 * ModuleBase::PI); phik_ave = phik_ave + wistring[istring] * phik[istring]; - // test by jingan - // GlobalV::ofs_running << "phik[" << istring << "] = " << phik[istring] << std::endl; - // test by jingan } if (PARAM.inp.nspin == 1) @@ -466,7 +408,6 @@ void berryphase::Berry_Phase(const UnitCell& ucell, mod_elec_tot = 1; } - // GlobalV::ofs_running << "Berry_Phase end " << std::endl; } void berryphase::Macroscopic_polarization(const UnitCell& ucell, @@ -574,20 +515,16 @@ void berryphase::Macroscopic_polarization(const UnitCell& ucell, polarization_ion[2] = polarization_ion[2] - 2.0 * round(polarization_ion[2] / 2.0); } - // delete[] mod_ion; - // delete[] pdl_ion_R1; - // delete[] pdl_ion_R2; - // delete[] pdl_ion_R3; - // ion polarization end // calculate Macroscopic polarization modulus because berry phase int modulus = 0; - if ((!lodd) && (PARAM.inp.nspin == 1)) { - modulus = 2; - } else { - modulus = 1; - } + if ((!lodd) && (PARAM.inp.nspin == 1)) + { + modulus = 2; + } else { + modulus = 1; + } // test by jingan // GlobalV::ofs_running << "ion polarization end" << std::endl; @@ -736,8 +673,6 @@ void berryphase::Macroscopic_polarization(const UnitCell& ucell, } } - // GlobalV::ofs_running << "the Macroscopic_polarization is over" << std::endl; - return; } diff --git a/source/module_io/write_wfc_pw.cpp b/source/module_io/write_wfc_pw.cpp index d00ca6a41fd..76c461de2b7 100644 --- a/source/module_io/write_wfc_pw.cpp +++ b/source/module_io/write_wfc_pw.cpp @@ -47,9 +47,7 @@ void ModuleIO::write_wfc_pw(const std::string& fn, } } } - // if(GlobalV::MY_RANK!=0) std::cout.clear(); - // std::cout<<"Hello"<* force) void MD_base::print_md(std::ofstream& ofs, const bool& cal_stress) { - if (my_rank) + if (my_rank!=0) { return; } @@ -158,6 +158,7 @@ void MD_base::print_md(std::ofstream& ofs, const bool& cal_stress) press += stress(i, i) / 3; } + // screen output std::cout << " ------------------------------------------------------------------------------------------------" << std::endl; std::cout << " " << std::left << std::setw(20) << "Energy (Ry)" << std::left << std::setw(20) << "Potential (Ry)" @@ -182,9 +183,9 @@ void MD_base::print_md(std::ofstream& ofs, const bool& cal_stress) std::cout << " ------------------------------------------------------------------------------------------------" << std::endl; + // running_log output ofs.unsetf(std::ios::fixed); - ofs << std::setprecision(8) << std::endl; - ofs << std::endl; + ofs << std::setprecision(8); ofs << " ------------------------------------------------------------------------------------------------" << std::endl; ofs << " " << std::left << std::setw(20) << "Energy (Ry)" << std::left << std::setw(20) << "Potential (Ry)" @@ -214,9 +215,6 @@ void MD_base::print_md(std::ofstream& ofs, const bool& cal_stress) MD_func::print_stress(ofs, virial, stress); } - ofs << std::endl; - ofs << std::endl; - return; } diff --git a/source/module_md/md_func.cpp b/source/module_md/md_func.cpp index 3fa000f095f..3c1d80fbe91 100644 --- a/source/module_md/md_func.cpp +++ b/source/module_md/md_func.cpp @@ -299,9 +299,9 @@ void print_stress(std::ofstream& ofs, const ModuleBase::matrix& virial, const Mo const double unit_transform = ModuleBase::HARTREE_SI / pow(ModuleBase::BOHR_RADIUS_SI, 3) * 1.0e-8; - ofs << " MD PRESSURE (ELECTRONS+IONS) : " << stress_scalar * unit_transform << " KBAR" << std::endl; - ofs << " ELECTRONIC PART OF STRESS: " << virial_scalar * unit_transform << " KBAR" << std::endl; - ofs << " IONIC (KINETIC) PART OF STRESS: " << (stress_scalar - virial_scalar) * unit_transform << " KBAR" << std::endl; + ofs << " MD PRESSURE (ELECTRONS+IONS) : " << stress_scalar * unit_transform << " kbar" << std::endl; + ofs << " ELECTRONIC PART OF STRESS: " << virial_scalar * unit_transform << " kbar" << std::endl; + ofs << " IONIC (KINETIC) PART OF STRESS: " << (stress_scalar - virial_scalar) * unit_transform << " kbar" << std::endl; // one should use 'print_stress' function in ../source/module_io/output_log.cpp /* diff --git a/source/module_md/test/fire_test.cpp b/source/module_md/test/fire_test.cpp index 81573498ae6..6365ef2d76a 100644 --- a/source/module_md/test/fire_test.cpp +++ b/source/module_md/test/fire_test.cpp @@ -177,41 +177,54 @@ TEST_F(FIREtest, Restart) TEST_F(FIREtest, PrintMD) { - std::ofstream ofs("running.log"); + std::ofstream ofs("running_fire.log"); mdrun->print_md(ofs, true); ofs.close(); - std::ifstream ifs("running.log"); + std::ifstream ifs("running_fire.log"); std::string output_str; + + // Line 1 getline(ifs, output_str); - getline(ifs, output_str); - getline(ifs, output_str); - EXPECT_THAT( - output_str, + EXPECT_THAT(output_str, testing::HasSubstr( " ------------------------------------------------------------------------------------------------")); + + // Line 2 getline(ifs, output_str); - EXPECT_THAT( - output_str, + EXPECT_THAT(output_str, testing::HasSubstr( " Energy (Ry) Potential (Ry) Kinetic (Ry) Temperature (K) Pressure (kbar) ")); + + // Line 3 getline(ifs, output_str); - EXPECT_THAT( - output_str, + EXPECT_THAT(output_str, testing::HasSubstr( " -0.015365236 -0.023915637 0.0085504016 300 1.0846391 ")); + + // Line 4 getline(ifs, output_str); EXPECT_THAT( output_str, testing::HasSubstr( " ------------------------------------------------------------------------------------------------")); - for (int i = 0; i < 11; ++i) - { - getline(ifs, output_str); - } - EXPECT_THAT(output_str, testing::HasSubstr(" Largest gradient in force is 0.049479926 eV/A")); + + // Line 5 + getline(ifs, output_str); + EXPECT_THAT(output_str, testing::HasSubstr(" MD PRESSURE (ELECTRONS+IONS) : 1.0846391 kbar")); + + // Line 6 + getline(ifs, output_str); + EXPECT_THAT(output_str, testing::HasSubstr(" ELECTRONIC PART OF STRESS: 0.24609992 kbar")); + + // Line 7 getline(ifs, output_str); - EXPECT_THAT(output_str, testing::HasSubstr(" Threshold is -1 eV/A.")); + EXPECT_THAT(output_str, testing::HasSubstr(" IONIC (KINETIC) PART OF STRESS: 0.83853919 kbar")); + + // Line 8 + getline(ifs, output_str); + EXPECT_THAT(output_str, testing::HasSubstr(" LARGEST FORCE (eV/A) : 0.049479926")); + ifs.close(); - remove("running.log"); + //remove("running_fire.log"); } diff --git a/source/module_md/test/langevin_test.cpp b/source/module_md/test/langevin_test.cpp index a06f279c4f3..baf59d3ba0c 100644 --- a/source/module_md/test/langevin_test.cpp +++ b/source/module_md/test/langevin_test.cpp @@ -163,15 +163,13 @@ TEST_F(Langevin_test, restart) TEST_F(Langevin_test, print_md) { - std::ofstream ofs("running.log"); + std::ofstream ofs("running_langevin.log"); mdrun->print_md(ofs, true); ofs.close(); - std::ifstream ifs("running.log"); + std::ifstream ifs("running_langevin.log"); std::string output_str; getline(ifs, output_str); - getline(ifs, output_str); - getline(ifs, output_str); EXPECT_THAT( output_str, testing::HasSubstr( @@ -192,5 +190,5 @@ TEST_F(Langevin_test, print_md) testing::HasSubstr( " ------------------------------------------------------------------------------------------------")); ifs.close(); - remove("running.log"); + remove("running_langevin.log"); } diff --git a/source/module_md/test/md_func_test.cpp b/source/module_md/test/md_func_test.cpp index 54d3ef3ea4d..ddebc68bbcc 100644 --- a/source/module_md/test/md_func_test.cpp +++ b/source/module_md/test/md_func_test.cpp @@ -385,11 +385,12 @@ TEST_F(MD_func_test, print_stress) std::ifstream ifs("running.log"); std::string output_str; getline(ifs, output_str); - EXPECT_THAT(output_str, testing::HasSubstr("Virtual Pressure is 0 kbar ")); + EXPECT_THAT(output_str, testing::HasSubstr("MD PRESSURE (ELECTRONS+IONS) : 0 kbar")); getline(ifs, output_str); - EXPECT_THAT(output_str, testing::HasSubstr("Virial Term is 0 kbar ")); + EXPECT_THAT(output_str, testing::HasSubstr("ELECTRONIC PART OF STRESS: 0 kbar")); getline(ifs, output_str); - EXPECT_THAT(output_str, testing::HasSubstr("Kinetic Term is 0 kbar ")); + EXPECT_THAT(output_str, testing::HasSubstr("IONIC (KINETIC) PART OF STRESS: 0 kbar")); +/* getline(ifs, output_str); getline(ifs, output_str); getline(ifs, output_str); @@ -409,6 +410,7 @@ TEST_F(MD_func_test, print_stress) EXPECT_THAT(output_str, testing::HasSubstr(" 0 0 0")); getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr(" 0 0 0")); +*/ ifs.close(); remove("running.log"); @@ -438,4 +440,4 @@ TEST_F(MD_func_test, current_step_warning) int istep = 0; double temperature = 0.0; EXPECT_EXIT(MD_func::current_md_info(0, file_dir, istep, temperature), ::testing::ExitedWithCode(1), ""); -} \ No newline at end of file +} diff --git a/source/module_md/test/msst_test.cpp b/source/module_md/test/msst_test.cpp index 27b94e5a2d9..f4cf7805d41 100644 --- a/source/module_md/test/msst_test.cpp +++ b/source/module_md/test/msst_test.cpp @@ -219,15 +219,13 @@ TEST_F(MSST_test, restart) TEST_F(MSST_test, print_md) { - std::ofstream ofs("running.log"); + std::ofstream ofs("running_msst.log"); mdrun->print_md(ofs, true); ofs.close(); - std::ifstream ifs("running.log"); + std::ifstream ifs("running_msst.log"); std::string output_str; getline(ifs, output_str); - getline(ifs, output_str); - getline(ifs, output_str); EXPECT_THAT( output_str, testing::HasSubstr( @@ -248,5 +246,5 @@ TEST_F(MSST_test, print_md) testing::HasSubstr( " ------------------------------------------------------------------------------------------------")); ifs.close(); - remove("running.log"); +// remove("running_msst.log"); } diff --git a/source/module_md/test/nhchain_test.cpp b/source/module_md/test/nhchain_test.cpp index 22f0bbf9a0b..6aaacc9869a 100644 --- a/source/module_md/test/nhchain_test.cpp +++ b/source/module_md/test/nhchain_test.cpp @@ -113,7 +113,6 @@ TEST_F(NHC_test, second_half) { mdrun->first_half(GlobalV::ofs_running); mdrun->second_half(); - ; EXPECT_NEAR(mdrun->pos[0].x, -0.00035596392702161582, doublethreshold); EXPECT_NEAR(mdrun->pos[0].y, 0.00026566987683715606, doublethreshold); @@ -146,7 +145,7 @@ TEST_F(NHC_test, write_restart) { mdrun->first_half(GlobalV::ofs_running); mdrun->second_half(); - ; + mdrun->step_ = 1; mdrun->step_rst_ = 2; mdrun->write_restart(PARAM.sys.global_out_dir); @@ -210,15 +209,13 @@ TEST_F(NHC_test, restart) TEST_F(NHC_test, print_md) { - std::ofstream ofs("running.log"); + std::ofstream ofs("running_nhchain.log"); mdrun->print_md(ofs, true); ofs.close(); - std::ifstream ifs("running.log"); + std::ifstream ifs("running_nhchain.log"); std::string output_str; getline(ifs, output_str); - getline(ifs, output_str); - getline(ifs, output_str); EXPECT_THAT( output_str, testing::HasSubstr( @@ -239,5 +236,5 @@ TEST_F(NHC_test, print_md) testing::HasSubstr( " ------------------------------------------------------------------------------------------------")); ifs.close(); - remove("running.log"); + //remove("running_nhchain.log"); } diff --git a/source/module_md/test/verlet_test.cpp b/source/module_md/test/verlet_test.cpp index 578761dcc5e..8ba61ed5e9e 100644 --- a/source/module_md/test/verlet_test.cpp +++ b/source/module_md/test/verlet_test.cpp @@ -304,15 +304,13 @@ TEST_F(Verlet_test, restart) TEST_F(Verlet_test, print_md) { - std::ofstream ofs("running.log"); + std::ofstream ofs("running_verlet.log"); mdrun->print_md(ofs, true); ofs.close(); - std::ifstream ifs("running.log"); + std::ifstream ifs("running_verlet.log"); std::string output_str; getline(ifs, output_str); - getline(ifs, output_str); - getline(ifs, output_str); EXPECT_THAT( output_str, testing::HasSubstr( @@ -333,5 +331,5 @@ TEST_F(Verlet_test, print_md) testing::HasSubstr( " ------------------------------------------------------------------------------------------------")); ifs.close(); - remove("running.log"); +// remove("running_verlet.log"); } From abc61a0ab2ffe2a8d89804cd3c9d94978b355eb6 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Thu, 27 Mar 2025 22:25:04 +0800 Subject: [PATCH 17/22] update print_stress --- source/module_esolver/esolver_dp.cpp | 2 +- source/module_esolver/esolver_lj.cpp | 2 +- .../hamilt_lcaodft/FORCE_STRESS.cpp | 32 ++++++++++--------- .../hamilt_ofdft/of_stress_pw.cpp | 23 ++++++------- .../hamilt_pwdft/stress_pw.cpp | 28 ++++++++-------- .../hamilt_stodft/sto_stress_pw.cpp | 23 ++++++------- source/module_io/output_log.cpp | 13 ++++---- source/module_io/output_log.h | 6 +++- source/module_io/test/outputlog_test.cpp | 30 +++++++++++------ 9 files changed, 89 insertions(+), 70 deletions(-) diff --git a/source/module_esolver/esolver_dp.cpp b/source/module_esolver/esolver_dp.cpp index e1c83b367d4..de642a6598f 100644 --- a/source/module_esolver/esolver_dp.cpp +++ b/source/module_esolver/esolver_dp.cpp @@ -136,7 +136,7 @@ void ESolver_DP::cal_stress(UnitCell& ucell, ModuleBase::matrix& stress) { stress = dp_virial; - ModuleIO::print_stress("TOTAL-STRESS", stress, true, false); + ModuleIO::print_stress("TOTAL-STRESS", stress, true, false, GlobalV::ofs_running); // external stress double unit_transform = ModuleBase::RYDBERG_SI / pow(ModuleBase::BOHR_RADIUS_SI, 3) * 1.0e-8; diff --git a/source/module_esolver/esolver_lj.cpp b/source/module_esolver/esolver_lj.cpp index f4ea687517c..28a4c031258 100644 --- a/source/module_esolver/esolver_lj.cpp +++ b/source/module_esolver/esolver_lj.cpp @@ -104,7 +104,7 @@ void ESolver_LJ::runner(UnitCell& ucell, const int istep) { stress = lj_virial; - ModuleIO::print_stress("TOTAL-STRESS", stress, true, false); + ModuleIO::print_stress("TOTAL-STRESS", stress, true, false, GlobalV::ofs_running); // external stress double unit_transform = ModuleBase::RYDBERG_SI / pow(ModuleBase::BOHR_RADIUS_SI, 3) * 1.0e-8; diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp index 51eefdaea67..d8f5c273251 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp @@ -729,39 +729,41 @@ void Force_Stress_LCAO::getForceStress(UnitCell& ucell, } } + const bool screen = PARAM.inp.test_stress; + GlobalV::ofs_running << "\n PARTS OF STRESS: " << std::endl; GlobalV::ofs_running << std::setiosflags(std::ios::showpos); GlobalV::ofs_running << std::setiosflags(std::ios::fixed) << std::setprecision(10) << std::endl; - ModuleIO::print_stress("OVERLAP STRESS", soverlap, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("T STRESS", stvnl_dphi, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("VNL STRESS", svnl_dbeta, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("T_VNL STRESS", stvnl, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("VL_dPHI STRESS", svl_dphi, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("VL_dVL STRESS", sigmadvl, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("HAR STRESS", sigmahar, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("EWALD STRESS", sigmaewa, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("cc STRESS", sigmacc, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("XC STRESS", sigmaxc, PARAM.inp.test_stress, ry); + ModuleIO::print_stress("OVERLAP STRESS", soverlap, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("T STRESS", stvnl_dphi, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("VNL STRESS", svnl_dbeta, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("T_VNL STRESS", stvnl, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("VL_dPHI STRESS", svl_dphi, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("VL_dVL STRESS", sigmadvl, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("HAR STRESS", sigmahar, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("EWALD STRESS", sigmaewa, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("cc STRESS", sigmacc, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("XC STRESS", sigmaxc, screen, ry, GlobalV::ofs_running); if (vdw_solver != nullptr) { - ModuleIO::print_stress("VDW STRESS", sigmaxc, PARAM.inp.test_stress, ry); + ModuleIO::print_stress("VDW STRESS", sigmaxc, screen, ry, GlobalV::ofs_running); } if (PARAM.inp.dft_plus_u) { - ModuleIO::print_stress("DFTU STRESS", stress_dftu, PARAM.inp.test_stress, ry); + ModuleIO::print_stress("DFTU STRESS", stress_dftu, screen, ry, GlobalV::ofs_running); } if (PARAM.inp.sc_mag_switch) { - ModuleIO::print_stress("DeltaSpin STRESS", stress_dspin, PARAM.inp.test_stress, ry); + ModuleIO::print_stress("DeltaSpin STRESS", stress_dspin, screen, ry, GlobalV::ofs_running); } - ModuleIO::print_stress("TOTAL STRESS", scs, PARAM.inp.test_stress, ry); + ModuleIO::print_stress("TOTAL STRESS", scs, screen, ry, GlobalV::ofs_running); } // end of test GlobalV::ofs_running << std::setiosflags(std::ios::left); // print total stress bool screen = false; - ModuleIO::print_stress("TOTAL-STRESS", scs, screen, ry); + ModuleIO::print_stress("TOTAL-STRESS", scs, screen, ry, GlobalV::ofs_running); double unit_transform = 0.0; unit_transform = ModuleBase::RYDBERG_SI / pow(ModuleBase::BOHR_RADIUS_SI, 3) * 1.0e-8; diff --git a/source/module_hamilt_pw/hamilt_ofdft/of_stress_pw.cpp b/source/module_hamilt_pw/hamilt_ofdft/of_stress_pw.cpp index c3964be8b36..5f42c126247 100644 --- a/source/module_hamilt_pw/hamilt_ofdft/of_stress_pw.cpp +++ b/source/module_hamilt_pw/hamilt_ofdft/of_stress_pw.cpp @@ -99,22 +99,23 @@ void OF_Stress_PW::cal_stress(ModuleBase::matrix& sigmatot, p_symm->symmetrize_mat3(sigmatot, ucell.lat); } - bool ry = false; - ModuleIO::print_stress("TOTAL-STRESS", sigmatot, true, ry); + const bool ry = false; + const bool screen = PARAM.inp.test_stress; + ModuleIO::print_stress("TOTAL-STRESS", sigmatot, true, ry, GlobalV::ofs_running); - if (PARAM.inp.test_stress) + if (screen) { GlobalV::ofs_running << "\n PARTS OF STRESS: " << std::endl; GlobalV::ofs_running << std::setiosflags(std::ios::showpos); GlobalV::ofs_running << std::setiosflags(std::ios::fixed) << std::setprecision(10) << std::endl; - ModuleIO::print_stress("KINETIC STRESS", sigmakin, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("LOCAL STRESS", sigmaloc, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("HARTREE STRESS", sigmahar, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("NON-LOCAL STRESS", sigmanl, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("XC STRESS", sigmaxc, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("EWALD STRESS", sigmaewa, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("NLCC STRESS", sigmaxcc, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("TOTAL STRESS", sigmatot, PARAM.inp.test_stress, ry); + ModuleIO::print_stress("KINETIC STRESS", sigmakin, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("LOCAL STRESS", sigmaloc, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("HARTREE STRESS", sigmahar, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("NON-LOCAL STRESS", sigmanl, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("XC STRESS", sigmaxc, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("EWALD STRESS", sigmaewa, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("NLCC STRESS", sigmaxcc, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("TOTAL STRESS", sigmatot, screen, ry, GlobalV::ofs_running); } ModuleBase::timer::tick("OF_Stress_PW", "cal_stress"); return; diff --git a/source/module_hamilt_pw/hamilt_pwdft/stress_pw.cpp b/source/module_hamilt_pw/hamilt_pwdft/stress_pw.cpp index 827eed53ae8..98cb66b2dcc 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/stress_pw.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/stress_pw.cpp @@ -145,31 +145,31 @@ void Stress_PW::cal_stress(ModuleBase::matrix& sigmatot, p_symm->symmetrize_mat3(sigmatot, ucell.lat); } - bool ry = false; - ModuleIO::print_stress("TOTAL-STRESS", sigmatot, true, ry); + const bool ry = false; + const bool screen = PARAM.inp.test_stress; + ModuleIO::print_stress("TOTAL-STRESS", sigmatot, true, ry, GlobalV::ofs_running); - if (PARAM.inp.test_stress || true) + if (screen) { -// ry = true; GlobalV::ofs_running << "\n PARTS OF STRESS: " << std::endl; GlobalV::ofs_running << std::setiosflags(std::ios::showpos); GlobalV::ofs_running << std::setiosflags(std::ios::fixed) << std::setprecision(10) << std::endl; - ModuleIO::print_stress("KINETIC STRESS", sigmakin, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("LOCAL STRESS", sigmaloc, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("HARTREE STRESS", sigmahar, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("NON-LOCAL STRESS", sigmanl, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("XC STRESS", sigmaxc, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("EWALD STRESS", sigmaewa, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("NLCC STRESS", sigmaxcc, PARAM.inp.test_stress, ry); + ModuleIO::print_stress("KINETIC STRESS", sigmakin, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("LOCAL STRESS", sigmaloc, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("HARTREE STRESS", sigmahar, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("NON-LOCAL STRESS", sigmanl, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("XC STRESS", sigmaxc, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("EWALD STRESS", sigmaewa, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("NLCC STRESS", sigmaxcc, screen, ry, GlobalV::ofs_running); if (PARAM.inp.dft_plus_u || PARAM.inp.sc_mag_switch) { - ModuleIO::print_stress("ONSITE STRESS", sigmaonsite, PARAM.inp.test_stress, ry); + ModuleIO::print_stress("ONSITE STRESS", sigmaonsite, screen, ry, GlobalV::ofs_running); } if (GlobalC::exx_info.info_global.cal_exx) { - ModuleIO::print_stress("EXX STRESS", sigmaexx, PARAM.inp.test_stress, ry); + ModuleIO::print_stress("EXX STRESS", sigmaexx, screen, ry, GlobalV::ofs_running); } - ModuleIO::print_stress("TOTAL STRESS", sigmatot, PARAM.inp.test_stress, ry); + ModuleIO::print_stress("TOTAL STRESS", sigmatot, screen, ry, GlobalV::ofs_running); } ModuleBase::timer::tick("Stress_PW", "cal_stress"); return; diff --git a/source/module_hamilt_pw/hamilt_stodft/sto_stress_pw.cpp b/source/module_hamilt_pw/hamilt_stodft/sto_stress_pw.cpp index 4d77635139d..033a94159dc 100644 --- a/source/module_hamilt_pw/hamilt_stodft/sto_stress_pw.cpp +++ b/source/module_hamilt_pw/hamilt_stodft/sto_stress_pw.cpp @@ -77,22 +77,23 @@ void Sto_Stress_PW::cal_stress(ModuleBase::matrix& sigmatot, } bool ry = false; - ModuleIO::print_stress("TOTAL-STRESS", sigmatot, true, ry); + const bool screen = PARAM.inp.test_stress; + ModuleIO::print_stress("TOTAL-STRESS", sigmatot, true, ry, GlobalV::ofs_running); - if (PARAM.inp.test_stress) + if (screen) { ry = true; GlobalV::ofs_running << "\n PARTS OF STRESS: " << std::endl; GlobalV::ofs_running << std::setiosflags(std::ios::showpos); GlobalV::ofs_running << std::setiosflags(std::ios::fixed) << std::setprecision(10) << std::endl; - ModuleIO::print_stress("KINETIC STRESS", sigmakin, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("LOCAL STRESS", sigmaloc, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("HARTREE STRESS", sigmahar, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("NON-LOCAL STRESS", sigmanl, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("XC STRESS", sigmaxc, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("EWALD STRESS", sigmaewa, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("NLCC STRESS", sigmaxcc, PARAM.inp.test_stress, ry); - ModuleIO::print_stress("TOTAL STRESS", sigmatot, PARAM.inp.test_stress, ry); + ModuleIO::print_stress("KINETIC STRESS", sigmakin, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("LOCAL STRESS", sigmaloc, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("HARTREE STRESS", sigmahar, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("NON-LOCAL STRESS", sigmanl, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("XC STRESS", sigmaxc, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("EWALD STRESS", sigmaewa, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("NLCC STRESS", sigmaxcc, screen, ry, GlobalV::ofs_running); + ModuleIO::print_stress("TOTAL STRESS", sigmatot, screen, ry, GlobalV::ofs_running); } ModuleBase::timer::tick("Sto_Stress_PW", "cal_stress"); return; @@ -237,4 +238,4 @@ void Sto_Stress_PW::sto_stress_nl(ModuleBase::matrix& sigma, template class Sto_Stress_PW; #if ((defined __CUDA) || (defined __ROCM)) template class Sto_Stress_PW; -#endif \ No newline at end of file +#endif diff --git a/source/module_io/output_log.cpp b/source/module_io/output_log.cpp index 1bb46328b78..496e7f53013 100644 --- a/source/module_io/output_log.cpp +++ b/source/module_io/output_log.cpp @@ -262,7 +262,8 @@ void print_force(std::ofstream& ofs_running, } } -void print_stress(const std::string& name, const ModuleBase::matrix& scs, const bool screen, const bool ry) +void print_stress(const std::string& name, const ModuleBase::matrix& scs, + const bool screen, const bool ry, std::ofstream &ofs) { const double output_acc = 1.0e-8; double unit_transform = 1; @@ -284,7 +285,7 @@ void print_stress(const std::string& name, const ModuleBase::matrix& scs, const std::vector stress_z; std::string table; - GlobalV::ofs_running << " " << title << std::endl; + ofs << " " << title << std::endl; std::vector titles({"Stress_x", "Stress_y", "Stress_z"}); for (int i = 0; i < 3; i++) @@ -306,10 +307,10 @@ void print_stress(const std::string& name, const ModuleBase::matrix& scs, const fmt << stress_x << stress_y << stress_z; table = fmt.str(); - GlobalV::ofs_running << table; + ofs << table; if (name == "TOTAL-STRESS") { - GlobalV::ofs_running << " TOTAL-PRESSURE (DO NOT INCLUDE KINETIC PART OF IONS): " << std::fixed + ofs << " TOTAL-PRESSURE (DO NOT INCLUDE KINETIC PART OF IONS): " << std::fixed << std::setprecision(6) << pressure << unit << std::endl; } @@ -326,9 +327,9 @@ void print_stress(const std::string& name, const ModuleBase::matrix& scs, const return; } -void write_head(std::ofstream& ofs_running, const int& istep, const int& iter, const std::string& basisname) +void write_head(std::ofstream& ofs, const int& istep, const int& iter, const std::string& basisname) { - ofs_running << "\n " << basisname << " ALGORITHM --------------- ION=" << std::setw(4) << istep + 1 + ofs << "\n " << basisname << " ALGORITHM --------------- ION=" << std::setw(4) << istep + 1 << " ELEC=" << std::setw(4) << iter << "--------------------------------\n"; } diff --git a/source/module_io/output_log.h b/source/module_io/output_log.h index 2bbc90cd948..8f67e2f7686 100644 --- a/source/module_io/output_log.h +++ b/source/module_io/output_log.h @@ -64,7 +64,11 @@ void print_force(std::ofstream& ofs_running, /// @param name stress term name /// @param f stress components /// @param ry true if the unit of force is a.u. -void print_stress(const std::string& name, const ModuleBase::matrix& scs, const bool screen, const bool ry); +void print_stress(const std::string& name, + const ModuleBase::matrix& scs, + const bool screen, + const bool ry, + std::ofstream &ofs); /// @brief write head for scf iteration /// @param ofs_running output stream diff --git a/source/module_io/test/outputlog_test.cpp b/source/module_io/test/outputlog_test.cpp index 342ad14a8be..a1468e49f7a 100644 --- a/source/module_io/test/outputlog_test.cpp +++ b/source/module_io/test/outputlog_test.cpp @@ -252,31 +252,41 @@ TEST(PrintForce, PrintForce) force(1, 1) = 0.0; force(1, 2) = 0.0; - GlobalV::ofs_running.open("test.txt"); - ModuleIO::print_force(GlobalV::ofs_running, ucell, name, force, false); - GlobalV::ofs_running.close(); + std::ofstream ofs("running_force.txt"); + ModuleIO::print_force(ofs, ucell, name, force, false); + ofs.close(); - std::ifstream ifs("test.txt"); + std::ifstream ifs("running_force.txt"); std::string output_str; + + getline(ifs, output_str); + EXPECT_THAT(output_str, testing::HasSubstr("test")); + getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr("---------------------------------------------------------------------------")); + getline(ifs, output_str); - EXPECT_THAT(output_str, testing::HasSubstr("test")); + EXPECT_THAT(output_str," Atoms Force_x Force_y Force_z"); + getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr("---------------------------------------------------------------------------")); + getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr("Al1 25.7110532015 51.4221064030 77.1331596044")); + getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr("Al2 0.0000000000 0.0000000000 0.0000000000")); + getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr("---------------------------------------------------------------------------")); + ifs.close(); - std::remove("test.txt"); + //std::remove("running_force.txt"); } TEST(PrintStress, PrintStress) @@ -292,11 +302,11 @@ TEST(PrintStress, PrintStress) stress(2, 1) = 0.0; stress(2, 2) = 0.0; - GlobalV::ofs_running.open("test.txt"); + GlobalV::ofs_running.open("running_stress.txt"); ModuleIO::print_stress("TOTAL-STRESS", stress, true, false); GlobalV::ofs_running.close(); - std::ifstream ifs("test.txt"); + std::ifstream ifs("running_stress.txt"); std::string output_str; getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr("----------------------------------------------------------------")); @@ -315,7 +325,7 @@ TEST(PrintStress, PrintStress) getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr(" TOTAL-PRESSURE: 49035.075992 KBAR")); ifs.close(); - std::remove("test.txt"); + //std::remove("running_stress.txt"); } int main(int argc, char** argv) @@ -337,4 +347,4 @@ int main(int argc, char** argv) finishmpi(); #endif return result; -} \ No newline at end of file +} From bda0769a096169518f7c29b70d7000cff20b52fe Mon Sep 17 00:00:00 2001 From: mohanchen Date: Thu, 27 Mar 2025 23:02:30 +0800 Subject: [PATCH 18/22] update print_stress in dp, but still has problems in lj --- source/module_esolver/esolver_dp.cpp | 6 +----- source/module_esolver/esolver_lj.cpp | 5 ++++- source/module_io/output_log.h | 2 +- source/module_io/test/outputlog_test.cpp | 7 ++++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/source/module_esolver/esolver_dp.cpp b/source/module_esolver/esolver_dp.cpp index de642a6598f..1ca9939c359 100644 --- a/source/module_esolver/esolver_dp.cpp +++ b/source/module_esolver/esolver_dp.cpp @@ -28,8 +28,7 @@ #include #include -namespace ModuleESolver -{ +using namespace ModuleESolver; void ESolver_DP::before_all_runners(UnitCell& ucell, const Input_para& inp) { @@ -197,12 +196,9 @@ void ESolver_DP::type_map(const UnitCell& ucell) "The label " + ucell.atoms[it].label + " is not found in the type map."); } atype[iat] = label[ucell.atoms[it].label]; - // if (ia == 0) - // std::cout << "type: " << atype[iat] << std::endl; iat++; } } assert(ucell.nat == iat); } #endif -} // namespace ModuleESolver diff --git a/source/module_esolver/esolver_lj.cpp b/source/module_esolver/esolver_lj.cpp index 28a4c031258..d1459fe4906 100644 --- a/source/module_esolver/esolver_lj.cpp +++ b/source/module_esolver/esolver_lj.cpp @@ -5,6 +5,7 @@ #include "module_io/output_log.h" #include "module_io/cif_io.h" + namespace ModuleESolver { @@ -104,7 +105,9 @@ void ESolver_LJ::runner(UnitCell& ucell, const int istep) { stress = lj_virial; - ModuleIO::print_stress("TOTAL-STRESS", stress, true, false, GlobalV::ofs_running); + const bool screen = true; + const bool ry = false; + ModuleIO::print_stress("TOTAL-STRESS", stress, screen, ry, GlobalV::ofs_running); // external stress double unit_transform = ModuleBase::RYDBERG_SI / pow(ModuleBase::BOHR_RADIUS_SI, 3) * 1.0e-8; diff --git a/source/module_io/output_log.h b/source/module_io/output_log.h index 8f67e2f7686..56108648638 100644 --- a/source/module_io/output_log.h +++ b/source/module_io/output_log.h @@ -54,7 +54,7 @@ void output_vacuum_level(const UnitCell* ucell, /// @param name force term name /// @param force atomic forces /// @param ry true if the unit of force is a.u. -void print_force(std::ofstream& ofs_running, +void print_force(std::ofstream& ofs, const UnitCell& cell, const std::string& name, const ModuleBase::matrix& force, diff --git a/source/module_io/test/outputlog_test.cpp b/source/module_io/test/outputlog_test.cpp index a1468e49f7a..f12cbd8853c 100644 --- a/source/module_io/test/outputlog_test.cpp +++ b/source/module_io/test/outputlog_test.cpp @@ -302,9 +302,10 @@ TEST(PrintStress, PrintStress) stress(2, 1) = 0.0; stress(2, 2) = 0.0; - GlobalV::ofs_running.open("running_stress.txt"); - ModuleIO::print_stress("TOTAL-STRESS", stress, true, false); - GlobalV::ofs_running.close(); + + std::ofstream ofs("running_stress.txt"); + ModuleIO::print_stress("TOTAL-STRESS", stress, true, false, ofs); + ofs.close(); std::ifstream ifs("running_stress.txt"); std::string output_str; From c4b4b1965db3a360308952511ba2cd4b946213f9 Mon Sep 17 00:00:00 2001 From: mohanchen Date: Thu, 27 Mar 2025 23:02:43 +0800 Subject: [PATCH 19/22] fix dp_test.cpp --- source/module_esolver/test/esolver_dp_test.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/module_esolver/test/esolver_dp_test.cpp b/source/module_esolver/test/esolver_dp_test.cpp index ab9ef17331f..7d2a0e3a2dc 100644 --- a/source/module_esolver/test/esolver_dp_test.cpp +++ b/source/module_esolver/test/esolver_dp_test.cpp @@ -20,6 +20,7 @@ * - ESolver_DP::post_process() * - ESolver_DP::type_map() */ + namespace ModuleIO { void print_force(std::ofstream& ofs_running, @@ -29,9 +30,15 @@ void print_force(std::ofstream& ofs_running, bool ry = true) { } -void print_stress(const std::string& name, const ModuleBase::matrix& scs, const bool screen, const bool ry) + +void print_stress(const std::string& name, + const ModuleBase::matrix& scs, + const bool screen, + const bool ry, + std::ofstream &ofs) { } + } // namespace ModuleIO class ESolverDPTest : public ::testing::Test From 1060d4a0c50b39882c61d05bbc62ca724de6d78f Mon Sep 17 00:00:00 2001 From: mohanchen Date: Fri, 28 Mar 2025 20:38:56 +0800 Subject: [PATCH 20/22] update esolver_lj --- source/module_md/test/setcell.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/module_md/test/setcell.h b/source/module_md/test/setcell.h index fedb2478e0e..0e321f7e8e4 100644 --- a/source/module_md/test/setcell.h +++ b/source/module_md/test/setcell.h @@ -29,7 +29,7 @@ void print_force(std::ofstream& ofs_running, bool ry = true) { } -void print_stress(const std::string& name, const ModuleBase::matrix& scs, const bool screen, const bool ry) +void print_stress(const std::string& name, const ModuleBase::matrix& scs, const bool screen, const bool ry, std::ofstream &ofs) { } } // namespace ModuleIO @@ -154,4 +154,4 @@ class Setcell }; }; -#endif \ No newline at end of file +#endif From b0d2d0ac962ddce88488653f4509d44c0ce64c7b Mon Sep 17 00:00:00 2001 From: mohanchen Date: Sat, 29 Mar 2025 15:15:53 +0800 Subject: [PATCH 21/22] set mulliken charge accuracy from 4 to 3 --- tests/integrate/tools/catch_properties.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integrate/tools/catch_properties.sh b/tests/integrate/tools/catch_properties.sh index b62a348d0de..f8d25085b53 100755 --- a/tests/integrate/tools/catch_properties.sh +++ b/tests/integrate/tools/catch_properties.sh @@ -477,7 +477,7 @@ fi # mulliken charge #-------------------------------------------- if ! test -z "$out_mul" && [ $out_mul == 1 ]; then - python3 ../tools/CompareFile.py mulliken.txt.ref OUT.autotest/mulliken.txt 4 + python3 ../tools/CompareFile.py mulliken.txt.ref OUT.autotest/mulliken.txt 3 echo "Compare_mulliken_pass $?" >>$1 fi From 3956c6f856292f0ac76c45be74dc0fd459eba12a Mon Sep 17 00:00:00 2001 From: mohanchen Date: Sun, 30 Mar 2025 22:29:49 +0800 Subject: [PATCH 22/22] update print force and print stress --- source/module_io/test/outputlog_test.cpp | 29 ++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/source/module_io/test/outputlog_test.cpp b/source/module_io/test/outputlog_test.cpp index f12cbd8853c..786f6017dfb 100644 --- a/source/module_io/test/outputlog_test.cpp +++ b/source/module_io/test/outputlog_test.cpp @@ -260,18 +260,19 @@ TEST(PrintForce, PrintForce) std::string output_str; getline(ifs, output_str); - EXPECT_THAT(output_str, testing::HasSubstr("test")); + EXPECT_THAT(output_str, testing::HasSubstr(" test")); getline(ifs, output_str); EXPECT_THAT(output_str, - testing::HasSubstr("---------------------------------------------------------------------------")); + testing::HasSubstr("-------------------------------------------------------------------------")); getline(ifs, output_str); - EXPECT_THAT(output_str," Atoms Force_x Force_y Force_z"); + EXPECT_THAT(output_str, + testing::HasSubstr(" Atoms Force_x Force_y Force_z")); getline(ifs, output_str); EXPECT_THAT(output_str, - testing::HasSubstr("---------------------------------------------------------------------------")); + testing::HasSubstr("-------------------------------------------------------------------------")); getline(ifs, output_str); EXPECT_THAT(output_str, @@ -283,10 +284,10 @@ TEST(PrintForce, PrintForce) getline(ifs, output_str); EXPECT_THAT(output_str, - testing::HasSubstr("---------------------------------------------------------------------------")); + testing::HasSubstr("-------------------------------------------------------------------------")); ifs.close(); - //std::remove("running_force.txt"); + std::remove("running_force.txt"); } TEST(PrintStress, PrintStress) @@ -309,24 +310,34 @@ TEST(PrintStress, PrintStress) std::ifstream ifs("running_stress.txt"); std::string output_str; + getline(ifs, output_str); + EXPECT_THAT(output_str, testing::HasSubstr(" TOTAL-STRESS (KBAR)")); + getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr("----------------------------------------------------------------")); + getline(ifs, output_str); - EXPECT_THAT(output_str, testing::HasSubstr("TOTAL-STRESS (KBAR) ")); + EXPECT_THAT(output_str, testing::HasSubstr(" Stress_x Stress_y Stress_z")); + getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr("----------------------------------------------------------------")); + getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr(" 147105.2279754489 294210.4559508978 441315.6839263467")); + getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr(" 0.0000000000 0.0000000000 0.0000000000")); + getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr(" 0.0000000000 0.0000000000 0.0000000000")); + getline(ifs, output_str); EXPECT_THAT(output_str, testing::HasSubstr("----------------------------------------------------------------")); + getline(ifs, output_str); - EXPECT_THAT(output_str, testing::HasSubstr(" TOTAL-PRESSURE: 49035.075992 KBAR")); + EXPECT_THAT(output_str, testing::HasSubstr(" TOTAL-PRESSURE (DO NOT INCLUDE KINETIC PART OF IONS): 49035.075992 KBAR")); ifs.close(); - //std::remove("running_stress.txt"); + std::remove("running_stress.txt"); } int main(int argc, char** argv)