diff --git a/source/module_io/read_input_item_system.cpp b/source/module_io/read_input_item_system.cpp index 3828759674..af0456aa17 100644 --- a/source/module_io/read_input_item_system.cpp +++ b/source/module_io/read_input_item_system.cpp @@ -107,7 +107,7 @@ void ReadInput::item_system() } { Input_Item item("esolver_type"); - item.annotation = "the energy solver: ksdft, sdft, ofdft, tddft, lj, dp"; + item.annotation = "the energy solver: ksdft, sdft, ofdft, tddft, lj, dp, ks-lr, lr"; read_sync_string(input.esolver_type); item.check_value = [](const Input_Item& item, const Parameter& para) { const std::vector esolver_types = { "ksdft", "sdft", "ofdft", "tddft", "lj", "dp", "lr", "ks-lr" }; @@ -124,6 +124,12 @@ void ReadInput::item_system() } } }; + item.reset_value = [](const Input_Item& item, Parameter& para) { + if (para.input.esolver_type == "lr" && para.input.calculation == "scf") + { // for LR-only calculation based on the ground-state, set calculation to "nscf" + para.input.calculation = "nscf"; + } + }; this->add_item(item); } { diff --git a/source/module_io/test_serial/read_input_item_test.cpp b/source/module_io/test_serial/read_input_item_test.cpp index 4a5a21218d..faec37cbc3 100644 --- a/source/module_io/test_serial/read_input_item_test.cpp +++ b/source/module_io/test_serial/read_input_item_test.cpp @@ -79,6 +79,12 @@ TEST_F(InputTest, Item_test) EXPECT_EXIT(it->second.check_value(it->second, param), ::testing::ExitedWithCode(0), ""); output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("NOTICE")); + + param.input.esolver_type = "lr"; + param.input.calculation = "scf"; + it = find_label("esolver_type", readinput.input_lists); + it->second.reset_value(it->second, param); + EXPECT_EQ(param.input.calculation, "nscf"); } { // nspin auto it = find_label("nspin", readinput.input_lists); diff --git a/source/module_lr/esolver_lrtd_lcao.cpp b/source/module_lr/esolver_lrtd_lcao.cpp index 5f696d7aa1..4404775933 100644 --- a/source/module_lr/esolver_lrtd_lcao.cpp +++ b/source/module_lr/esolver_lrtd_lcao.cpp @@ -46,28 +46,6 @@ void LR::ESolver_LR::move_exx_lri(std::shared_ptrvoid LR::ESolver_LR::set_gint() { this->gint_ = &this->gint_g_;this->gint_g_.gridt = &this->gt_; } template<>void LR::ESolver_LR>::set_gint() { this->gint_ = &this->gint_k_; this->gint_k_.gridt = &this->gt_; } -inline double getreal(std::complex x) { return x.real(); } -inline double getreal(double x) { return x; } - -inline void redirect_log(const bool& out_alllog) -{ - GlobalV::ofs_running.close(); - std::stringstream ss; - if (out_alllog) - { - ss << PARAM.globalv.global_out_dir << "running_lr_" << GlobalV::MY_RANK + 1 << ".log"; - GlobalV::ofs_running.open(ss.str()); - } - else - { - if (GlobalV::MY_RANK == 0) - { - ss << PARAM.globalv.global_out_dir << "running_lr.log"; - GlobalV::ofs_running.open(ss.str()); - } - } -} - inline int cal_nupdown_form_occ(const ModuleBase::matrix& wg) { // only for nspin=2 const int& nk = wg.nr / 2; @@ -155,7 +133,6 @@ LR::ESolver_LR::ESolver_LR(ModuleESolver::ESolver_KS_LCAO&& ks_sol , exx_info(GlobalC::exx_info) #endif { - redirect_log(inp.out_alllog); ModuleBase::TITLE("ESolver_LR", "ESolver_LR(KS)"); if (this->input.lr_solver == "spectrum") { @@ -259,7 +236,6 @@ LR::ESolver_LR::ESolver_LR(const Input_para& inp, UnitCell& ucell) : inpu , exx_info(GlobalC::exx_info) #endif { - redirect_log(inp.out_alllog); ModuleBase::TITLE("ESolver_LR", "ESolver_LR(from scratch)"); // xc kernel this->xc_kernel = inp.xc_kernel; @@ -431,6 +407,7 @@ template void LR::ESolver_LR::runner(int istep, UnitCell& cell) { ModuleBase::TITLE("ESolver_LR", "runner"); + ModuleBase::timer::tick("ESolver_LR", "runner"); //allocate 2-particle state and setup 2d division this->setup_eigenvectors_X(); this->pelec->ekb.create(nspin, this->nstates); @@ -494,6 +471,7 @@ void LR::ESolver_LR::runner(int istep, UnitCell& cell) for (int is = 0;is < nspin;++is) { read_states(spin_types[is], this->pelec->ekb.c + is * nstates, this->X[is].template data(), nloc_per_band, nstates); } } } + ModuleBase::timer::tick("ESolver_LR", "runner"); return; } diff --git a/source/module_lr/operator_casida/operator_lr_diag.h b/source/module_lr/operator_casida/operator_lr_diag.h index d6255caabe..99a61d90df 100644 --- a/source/module_lr/operator_casida/operator_lr_diag.h +++ b/source/module_lr/operator_casida/operator_lr_diag.h @@ -46,9 +46,8 @@ namespace LR const bool is_first_node = false)const override { ModuleBase::TITLE("OperatorLRDiag", "act"); - const int nlocal_ph = nk * pX.get_local_size(); // local size of particle-hole basis hsolver::vector_mul_vector_op()(this->ctx, - nk * pX.get_local_size(), + nk * pX.get_local_size(), // local size of particle-hole basis hpsi, psi_in, this->eig_ks_diff.c); diff --git a/source/module_lr/utils/lr_util.cpp b/source/module_lr/utils/lr_util.cpp index a8964d5c97..eb5ec2bc43 100644 --- a/source/module_lr/utils/lr_util.cpp +++ b/source/module_lr/utils/lr_util.cpp @@ -62,8 +62,7 @@ namespace LR_Util template<> void matsym(const double* in, const int n, const Parallel_2D& pmat, double* out) { - for (int i = 0;i < pmat.get_local_size();++i) {out[i] = in[i]; -} + for (int i = 0;i < pmat.get_local_size();++i) { out[i] = in[i]; } const double alpha = 0.5, beta = 0.5; const int i1 = 1; pdtran_(&n, &n, &alpha, in, &i1, &i1, pmat.desc, &beta, out, &i1, &i1, pmat.desc); @@ -71,9 +70,8 @@ namespace LR_Util template<> void matsym(double* inout, const int n, const Parallel_2D& pmat) { - std::vector tmp(n * n); - for (int i = 0;i < pmat.get_local_size();++i) {tmp[i] = inout[i]; -} + std::vector tmp(pmat.get_local_size()); + std::copy(inout, inout + pmat.get_local_size(), tmp.begin()); const double alpha = 0.5, beta = 0.5; const int i1 = 1; pdtran_(&n, &n, &alpha, tmp.data(), &i1, &i1, pmat.desc, &beta, inout, &i1, &i1, pmat.desc); @@ -81,8 +79,7 @@ namespace LR_Util template<> void matsym>(const std::complex* in, const int n, const Parallel_2D& pmat, std::complex* out) { - for (int i = 0;i < pmat.get_local_size();++i) {out[i] = in[i]; -} + for (int i = 0;i < pmat.get_local_size();++i) { out[i] = in[i]; } const std::complex alpha(0.5, 0.0), beta(0.5, 0.0); const int i1 = 1; pztranc_(&n, &n, &alpha, in, &i1, &i1, pmat.desc, &beta, out, &i1, &i1, pmat.desc); @@ -90,9 +87,8 @@ namespace LR_Util template<> void matsym>(std::complex* inout, const int n, const Parallel_2D& pmat) { - std::vector> tmp(n * n); - for (int i = 0;i < pmat.get_local_size();++i) {tmp[i] = inout[i]; -} + std::vector> tmp(pmat.get_local_size()); + std::copy(inout, inout + pmat.get_local_size(), tmp.begin()); const std::complex alpha(0.5, 0.0), beta(0.5, 0.0); const int i1 = 1; pztranc_(&n, &n, &alpha, tmp.data(), &i1, &i1, pmat.desc, &beta, inout, &i1, &i1, pmat.desc); diff --git a/tests/integrate/tools/catch_properties.sh b/tests/integrate/tools/catch_properties.sh index 13af75d5df..fe3b1f703a 100755 --- a/tests/integrate/tools/catch_properties.sh +++ b/tests/integrate/tools/catch_properties.sh @@ -536,10 +536,9 @@ if ! test -z "$out_current" && [ $out_current ]; then fi if [ $is_lr == 1 ]; then - lr_path=OUT.autotest/running_lr.log lrns=$(get_input_key_value "lr_nstates" "INPUT") lrns1=`echo "$lrns + 1" |bc` - grep -A$lrns1 "Excitation Energy" $lr_path | awk 'NR > 2 && $2 ~ /^[0-9]+\.[0-9]+$/ {print $2}' > lr_eig.txt + grep -A$lrns1 "Excitation Energy" $running_path | awk 'NR > 2 && $2 ~ /^[0-9]+\.[0-9]+$/ {print $2}' > lr_eig.txt lreig_tot=`sum_file lr_eig.txt` echo "totexcitationenergyref $lreig_tot" >>$1 fi