From 697b359592eb496e88fc20cf0b97ce7854fa5c4a Mon Sep 17 00:00:00 2001 From: lyb9812 <88070104+lyb9812@users.noreply.github.com> Date: Mon, 17 Apr 2023 14:51:39 +0800 Subject: [PATCH 01/48] Merge develop branch to TDDFT branch (#2249) * Add the dipole and spectrum post-processing script. (#1928) * Add the Dipole and post-processing script necessary to calculate the spectrum using TDDFT. * fix td_val test bug. * Fix: bug in parsing strings mixed with " ", "\t" (#1951) * Use template to reconstruct parse_expression * Feature: output R matrix at each MD step * Modify'matrix_HS' to 'matrix' for R matrix output * Merge branches 'develop' and 'develop' of https://github.com/1041176461/abacus-develop into develop * Fix: modify index in parse_expression * Fix: bug in parsing strings mixed with " ", "\t" --------- Co-authored-by: jiyuang * solve conflicts * solve conflicts * solve conflicts * solve conflicts * solve conflicts * Fix : bug of multi-kpoint for tddft (#2023) * fix bug of electric field in tddft * fix bug of dipole and electric field * fix bug of multi-kpoint for tddft * unit conversion of out_efield * delete useless paramters for tddft (td_val_elec*) * delete useless parameters for tddft * pack all changes in tddft * solve conflicts * delete td_val --------- Co-authored-by: HeFuxiang94 <78629482+HeFuxiang94@users.noreply.github.com> Co-authored-by: jiyuyang <1041176461@qq.com> Co-authored-by: jiyuang --- docs/advanced/input_files/input-main.md | 21 - .../potentials/H_TDDFT_pw.cpp | 85 ++- .../module_elecstate/potentials/H_TDDFT_pw.h | 2 + .../module_esolver/esolver_ks_lcao_tddft.cpp | 11 +- .../module_tddft/ELEC_evolve.cpp | 3 - .../module_tddft/ELEC_evolve.h | 3 - source/module_io/dipole_io.h | 13 +- source/module_io/input.cpp | 18 - source/module_io/input.h | 3 - source/module_io/input_conv.cpp | 41 +- .../module_io/test/for_testing_input_conv.h | 3 - source/module_io/test/input_conv_test.cpp | 3 - source/module_io/test/input_test.cpp | 6 - source/module_io/test/input_test_para.cpp | 3 - source/module_io/test/support/INPUT | 3 - source/module_io/test/support/witestfile | 709 +++++++++--------- source/module_io/test/write_input_test.cpp | 3 - source/module_io/write_dipole.cpp | 326 +++----- source/module_io/write_input.cpp | 3 - tests/integrate/601_NO_TDDFT_CO/result.ref | 8 +- .../integrate/601_NO_TDDFT_CO_occ/result.ref | 8 +- tests/integrate/601_NO_TDDFT_H2/result.ref | 4 +- .../601_NO_TDDFT_H2_kpoint/result.ref | 4 +- .../601_NO_TDDFT_H2_len_gauss/result.ref | 10 +- .../601_NO_TDDFT_H2_len_gauss_dire/result.ref | 10 +- .../601_NO_TDDFT_H2_len_heavi/result.ref | 10 +- .../601_NO_TDDFT_H2_len_hhg/result.ref | 10 +- .../601_NO_TDDFT_H2_len_trape/result.ref | 10 +- .../601_NO_TDDFT_H2_len_trigo/result.ref | 8 +- .../601_NO_TDDFT_H2_oldedm/result.ref | 4 +- tests/integrate/601_NO_TDDFT_O3/result.ref | 6 +- .../601_NO_TDDFT_graphene_kpoint/result.ref | 4 +- tools/plot-tools/README.md | 165 ++-- tools/plot-tools/abacus_plot/dipole.py | 123 +++ tools/plot-tools/abacus_plot/utils.py | 9 +- 35 files changed, 820 insertions(+), 832 deletions(-) create mode 100644 tools/plot-tools/abacus_plot/dipole.py diff --git a/docs/advanced/input_files/input-main.md b/docs/advanced/input_files/input-main.md index 494cf83099..d0430de33c 100644 --- a/docs/advanced/input_files/input-main.md +++ b/docs/advanced/input_files/input-main.md @@ -312,9 +312,6 @@ - [out\_efield](#out_efield) - [ocp](#ocp) - [ocp\_set](#ocp_set) - - [td\_val\_elec\_01](#td_val_elec_01) - - [td\_val\_elec\_02](#td_val_elec_02) - - [td\_val\_elec\_03](#td_val_elec_03) - [Variables useful for debugging](#variables-useful-for-debugging) - [nurse](#nurse) - [t\_in\_h](#t_in_h) @@ -2588,24 +2585,6 @@ These variables are used to control berry phase and wannier90 interface paramete - **Description**: If ocp is true, the ocp_set is a string to set the number of occupancy, like 1 10 * 1 0 1 representing the 13 band occupancy, 12th band occupancy 0 and the rest 1, the code is parsing this string into an array through a regular expression. - **Default**: none -### td_val_elec_01 - -- **Type**: Integer -- **Description**: Only useful when calculating the dipole. Specifies the number of valence electron associated with the first element. -- **Default**: 1.0 - -### td_val_elec_02 - -- **Type**: Integer -- **Description**: Only useful when calculating the dipole. Specifies the number of valence electron associated with the second element. -- **Default**: 1.0 - -### td_val_elec_03 - -- **Type**: Integer -- **Description**: Only useful when calculating the dipole. Specifies the number of valence electron associated with the third element. -- **Default**: 1.0 - [back to top](#full-list-of-input-keywords) ## Variables useful for debugging diff --git a/source/module_elecstate/potentials/H_TDDFT_pw.cpp b/source/module_elecstate/potentials/H_TDDFT_pw.cpp index a5ab2c513c..a915af5b7b 100644 --- a/source/module_elecstate/potentials/H_TDDFT_pw.cpp +++ b/source/module_elecstate/potentials/H_TDDFT_pw.cpp @@ -1,9 +1,10 @@ #include "H_TDDFT_pw.h" -#include "module_io/input.h" #include "module_base/constants.h" #include "module_base/timer.h" #include "module_hamilt_lcao/module_tddft/ELEC_evolve.h" +#include "module_hamilt_pw/hamilt_pwdft/global.h" +#include "module_io/input.h" #include "module_io/input_conv.h" namespace elecstate @@ -16,7 +17,7 @@ int H_TDDFT_pw::istep = -1; // fuxiang add in 2017-05 //========================================================== -void H_TDDFT_pw::cal_fixed_v(double* vl_pseudo) +void H_TDDFT_pw::cal_fixed_v(double *vl_pseudo) { ModuleBase::TITLE("H_TDDFT_pw", "cal_fixed_v"); @@ -39,18 +40,19 @@ void H_TDDFT_pw::cal_fixed_v(double* vl_pseudo) for (auto direc: ELEC_evolve::td_vext_dire_case) { std::vector vext_space(this->rho_basis_->nrxx, 0.0); - double vext_time = cal_v_time(ttype[count]); + double vext_time = cal_v_time(ttype[count]); if (ELEC_evolve::out_efield && GlobalV::MY_RANK == 0) { std::stringstream as; - as << GlobalV::global_out_dir << "efield_"<rho_basis_->nrxx; ++ir) vl_pseudo[ir] += vext_space[ir] * vext_time; count++; @@ -94,7 +96,7 @@ void H_TDDFT_pw::read_parameters(Input *in) gauss_count = 0; gauss_omega = set_parameters(in->td_gauss_freq, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 gauss_phase = set_parameters(in->td_gauss_phase, 1.0); - gauss_sigma = set_parameters(in->td_gauss_sigma, 1/ModuleBase::AU_to_FS); + gauss_sigma = set_parameters(in->td_gauss_sigma, 1 / ModuleBase::AU_to_FS); gauss_t0 = set_parameters(in->td_gauss_t0, 1.0); gauss_amp = set_parameters(in->td_gauss_amp, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr @@ -163,6 +165,12 @@ void H_TDDFT_pw::cal_v_space_length(std::vector &vext_space, int direc) ModuleBase::TITLE("H_TDDFT_pw", "cal_v_space_length"); ModuleBase::timer::tick("H_TDDFT_pw", "cal_v_space_length"); + double bmod[3]; + for (int i = 0; i < 3; i++) + { + bmod[i] = prepare(GlobalC::ucell, i); + } + for (int ir = 0; ir < this->rho_basis_->nrxx; ++ir) { int i = ir / (this->rho_basis_->ny * this->rho_basis_->nplane); @@ -175,15 +183,15 @@ void H_TDDFT_pw::cal_v_space_length(std::vector &vext_space, int direc) switch (direc) { case 1: - vext_space[ir] = cal_v_space_length_potential(x); + vext_space[ir] = cal_v_space_length_potential(x) / bmod[0]; break; case 2: - vext_space[ir] = cal_v_space_length_potential(y); + vext_space[ir] = cal_v_space_length_potential(y) / bmod[1]; break; case 3: - vext_space[ir] = cal_v_space_length_potential(z); + vext_space[ir] = cal_v_space_length_potential(z) / bmod[2]; break; default: @@ -198,18 +206,18 @@ void H_TDDFT_pw::cal_v_space_length(std::vector &vext_space, int direc) double H_TDDFT_pw::cal_v_space_length_potential(double i) { - double vext_space=0.0; - if (i < this->rho_basis_->nx * lcut1) + double vext_space = 0.0; + if (i < lcut1) { - vext_space = ((i / this->rho_basis_->nx - lcut1)*(lcut2-lcut1) / (lcut1 + 1.0 - lcut2) - lcut1) * this->ucell_->lat0; + vext_space = ((i - lcut1) * (lcut2 - lcut1) / (lcut1 + 1.0 - lcut2) - lcut1) * this->ucell_->lat0; } - else if (i >= this->rho_basis_->nx * lcut1 && i < this->rho_basis_->nx * lcut2) + else if (i >= lcut1 && i < lcut2) { - vext_space = -i / this->rho_basis_->nx * this->ucell_->lat0; + vext_space = -i * this->ucell_->lat0; } - else if (i >= this->rho_basis_->nx * lcut2) + else if (i >= lcut2) { - vext_space = ((i / this->rho_basis_->nx - lcut2)*(lcut2-lcut1) / (lcut1 + 1.0 - lcut2) - lcut2) * this->ucell_->lat0; + vext_space = ((i - lcut2) * (lcut2 - lcut1) / (lcut1 + 1.0 - lcut2) - lcut2) * this->ucell_->lat0; } return vext_space; } @@ -229,6 +237,10 @@ double H_TDDFT_pw::cal_v_time(int t_type) vext_time = cal_v_time_Gauss(); break; + case 1: + vext_time = cal_v_time_trapezoid(); + break; + case 2: vext_time = cal_v_time_trigonometric(); break; @@ -237,9 +249,9 @@ double H_TDDFT_pw::cal_v_time(int t_type) vext_time = cal_v_time_heaviside(); break; - // case 4: - // vext_time = cal_v_time_HHG(); - // break; + // case 4: + // vext_time = cal_v_time_HHG(); + // break; default: std::cout << "time_domain_type of electric field is wrong" << endl; @@ -304,8 +316,7 @@ double H_TDDFT_pw::cal_v_time_trigonometric() const double timenow = istep * dt; - vext_time = amp * cos(omega1 * timenow + phase1) * sin(omega2 * timenow + phase2) - * sin(omega2 * timenow + phase2); + vext_time = amp * cos(omega1 * timenow + phase1) * sin(omega2 * timenow + phase2) * sin(omega2 * timenow + phase2); trigo_count++; return vext_time; @@ -345,4 +356,34 @@ double H_TDDFT_pw::cal_v_time_heaviside() // return vext_time; // } +double H_TDDFT_pw::prepare(const UnitCell &cell, int &dir) +{ + double bvec[3] = {0.0}; + double bmod = 0.0; + if (dir == 0) + { + bvec[0] = cell.G.e11; + bvec[1] = cell.G.e12; + bvec[2] = cell.G.e13; + } + else if (dir == 1) + { + bvec[0] = cell.G.e21; + bvec[1] = cell.G.e22; + bvec[2] = cell.G.e23; + } + else if (dir == 2) + { + bvec[0] = cell.G.e31; + bvec[1] = cell.G.e32; + bvec[2] = cell.G.e33; + } + else + { + ModuleBase::WARNING_QUIT("H_TDDFT_pw::prepare", "direction is wrong!"); + } + bmod = sqrt(pow(bvec[0], 2) + pow(bvec[1], 2) + pow(bvec[2], 2)); + return bmod; +} + } // namespace elecstate diff --git a/source/module_elecstate/potentials/H_TDDFT_pw.h b/source/module_elecstate/potentials/H_TDDFT_pw.h index df9ea2b3d3..e600219b24 100644 --- a/source/module_elecstate/potentials/H_TDDFT_pw.h +++ b/source/module_elecstate/potentials/H_TDDFT_pw.h @@ -109,6 +109,8 @@ class H_TDDFT_pw : public PotBase double cal_v_time_trigonometric(); double cal_v_time_heaviside(); // double cal_v_time_HHG(); + + double prepare(const UnitCell &cell, int &dir); }; } // namespace elecstate diff --git a/source/module_esolver/esolver_ks_lcao_tddft.cpp b/source/module_esolver/esolver_ks_lcao_tddft.cpp index 8c7bc4a2c9..1899cb9dfd 100644 --- a/source/module_esolver/esolver_ks_lcao_tddft.cpp +++ b/source/module_esolver/esolver_ks_lcao_tddft.cpp @@ -365,12 +365,15 @@ void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) = new psi::Psi>(GlobalC::kv.nks, GlobalV::NBANDS, GlobalV::NLOCAL, nullptr); #endif - std::complex *p_psi = &psi[0](0,0,0); - std::complex *p_psi_laststep = &psi_laststep[0](0,0,0); - for (int index = 0; index < psi[0].size(); ++index) + for (int ik = 0; ik < GlobalC::kv.nks; ++ik) { - p_psi_laststep[index] = p_psi[index]; + this->psi->fix_k(ik); + this->psi_laststep->fix_k(ik); + int size0 = psi->get_nbands() * psi->get_nbasis(); + for (int index = 0; index < size0; ++index) + psi_laststep[0].get_pointer()[index] = psi[0].get_pointer()[index]; } + if (istep > 1 && ELEC_evolve::td_edm == 0) this->cal_edm_tddft(); } diff --git a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp b/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp index ade328fce4..66a8fcb1a7 100644 --- a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp +++ b/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp @@ -12,9 +12,6 @@ ELEC_evolve::ELEC_evolve(){}; ELEC_evolve::~ELEC_evolve(){}; double ELEC_evolve::td_force_dt; -int ELEC_evolve::td_val_elec_01; -int ELEC_evolve::td_val_elec_02; -int ELEC_evolve::td_val_elec_03; bool ELEC_evolve::td_vext; std::vector ELEC_evolve::td_vext_dire_case; bool ELEC_evolve::out_dipole; diff --git a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.h b/source/module_hamilt_lcao/module_tddft/ELEC_evolve.h index 86277853c6..6571e72033 100644 --- a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.h +++ b/source/module_hamilt_lcao/module_tddft/ELEC_evolve.h @@ -30,9 +30,6 @@ class ELEC_evolve // fuxiang add 2021-05-25 static double td_force_dt; - static int td_val_elec_01; - static int td_val_elec_02; - static int td_val_elec_03; static bool td_vext; static std::vector td_vext_dire_case; static bool out_dipole; diff --git a/source/module_io/dipole_io.h b/source/module_io/dipole_io.h index fbd3d8f0a2..4817f0e3c1 100644 --- a/source/module_io/dipole_io.h +++ b/source/module_io/dipole_io.h @@ -6,11 +6,14 @@ namespace ModuleIO { void write_dipole(const double *rho_save, - const int &is, - const int &istep, - const std::string &fn, - const int &precision = 11, - const bool for_plot = false); + const int &is, + const int &istep, + const std::string &fn, + const int &precision = 11, + const bool for_plot = false); + +double prepare(const UnitCell &cell, int &dir); + } // namespace ModuleIO #endif diff --git a/source/module_io/input.cpp b/source/module_io/input.cpp index c1787a23a6..1f1eaac91c 100644 --- a/source/module_io/input.cpp +++ b/source/module_io/input.cpp @@ -405,9 +405,6 @@ void Input::Default(void) // tddft //---------------------------------------------------------- td_force_dt = 0.02; - td_val_elec_01 = 1; - td_val_elec_02 = 1; - td_val_elec_03 = 1; td_vext = false; td_vext_dire = "1"; @@ -1524,18 +1521,6 @@ bool Input::Read(const std::string &fn) { read_value(ifs, td_force_dt); } - else if (strcmp("td_val_elec_01", word) == 0) - { - read_value(ifs, td_val_elec_01); - } - else if (strcmp("td_val_elec_02", word) == 0) - { - read_value(ifs, td_val_elec_02); - } - else if (strcmp("td_val_elec_03", word) == 0) - { - read_value(ifs, td_val_elec_03); - } else if (strcmp("td_vext", word) == 0) { read_value(ifs, td_vext); @@ -2969,9 +2954,6 @@ void Input::Bcast() Parallel_Common::bcast_int(vdw_cutoff_period.y); Parallel_Common::bcast_int(vdw_cutoff_period.z); // Fuxiang He add 2016-10-26 - Parallel_Common::bcast_int(td_val_elec_01); - Parallel_Common::bcast_int(td_val_elec_02); - Parallel_Common::bcast_int(td_val_elec_03); Parallel_Common::bcast_double(td_force_dt); Parallel_Common::bcast_bool(td_vext); Parallel_Common::bcast_string(td_vext_dire); diff --git a/source/module_io/input.h b/source/module_io/input.h index 9678b31cce..f9002da4f6 100644 --- a/source/module_io/input.h +++ b/source/module_io/input.h @@ -372,9 +372,6 @@ class Input // Fuxiang He add 2016-10-26 //========================================================== double td_force_dt; //"fs" - int td_val_elec_01; // valence electron 01 - int td_val_elec_02; // valence electron 02 - int td_val_elec_03; // valence electron 03 bool td_vext; // add extern potential or not std::string td_vext_dire; // vext direction bool out_dipole; // output the dipole or not diff --git a/source/module_io/input_conv.cpp b/source/module_io/input_conv.cpp index b7b13928a6..88bc762a23 100644 --- a/source/module_io/input_conv.cpp +++ b/source/module_io/input_conv.cpp @@ -34,20 +34,32 @@ template void Input_Conv::parse_expression(const std::string &fn, s int count = 0; std::string pattern("([0-9]+\\*[0-9.]+|[0-9,.]+)"); std::vector str; - std::string::size_type pos1, pos2; - std::string c = " "; - pos2 = fn.find(c); - pos1 = 0; - while (std::string::npos != pos2) - { - str.push_back(fn.substr(pos1, pos2 - pos1)); - pos1 = pos2 + c.size(); - pos2 = fn.find(c, pos1); - } - if (pos1 != fn.length()) - { - str.push_back(fn.substr(pos1)); + std::stringstream ss(fn); + std::string section; + while (ss >> section) { + int index = 0; + if (str.empty()) { + while (index < section.size() && std::isspace(section[index])) { + index++; + } + } + section.erase(0, index); + str.push_back(section); } + // std::string::size_type pos1, pos2; + // std::string c = " "; + // pos2 = fn.find(c); + // pos1 = 0; + // while (std::string::npos != pos2) + // { + // str.push_back(fn.substr(pos1, pos2 - pos1)); + // pos1 = pos2 + c.size(); + // pos2 = fn.find(c, pos1); + // } + // if (pos1 != fn.length()) + // { + // str.push_back(fn.substr(pos1)); + // } regex_t reg; regcomp(®, pattern.c_str(), REG_EXTENDED); regmatch_t pmatch[1]; @@ -329,9 +341,6 @@ void Input_Conv::Convert(void) //---------------------------------------------------------- #ifdef __LCAO ELEC_evolve::td_force_dt = INPUT.td_force_dt; - ELEC_evolve::td_val_elec_01 = INPUT.td_val_elec_01; - ELEC_evolve::td_val_elec_02 = INPUT.td_val_elec_02; - ELEC_evolve::td_val_elec_03 = INPUT.td_val_elec_03; ELEC_evolve::td_vext = INPUT.td_vext; if (ELEC_evolve::td_vext) { diff --git a/source/module_io/test/for_testing_input_conv.h b/source/module_io/test/for_testing_input_conv.h index 5e5a5f0a08..1d0a17bb92 100644 --- a/source/module_io/test/for_testing_input_conv.h +++ b/source/module_io/test/for_testing_input_conv.h @@ -35,9 +35,6 @@ int hsolver::HSolverLCAO::out_mat_dh = 0; int Local_Orbital_Charge::out_dm = 0; int Local_Orbital_Charge::out_dm1 = 0; double ELEC_evolve::td_force_dt; -int ELEC_evolve::td_val_elec_01; -int ELEC_evolve::td_val_elec_02; -int ELEC_evolve::td_val_elec_03; bool ELEC_evolve::td_vext; std::vector ELEC_evolve::td_vext_dire_case; bool ELEC_evolve::out_dipole; diff --git a/source/module_io/test/input_conv_test.cpp b/source/module_io/test/input_conv_test.cpp index cadf9022d6..fd5f7a07ed 100644 --- a/source/module_io/test/input_conv_test.cpp +++ b/source/module_io/test/input_conv_test.cpp @@ -125,9 +125,6 @@ TEST_F(InputConvTest, Conv) EXPECT_DOUBLE_EQ(elecstate::Gatefield::block_height,0.1); EXPECT_EQ(ELEC_evolve::td_force_dt,0.02); - EXPECT_EQ(ELEC_evolve::td_val_elec_01,1); - EXPECT_EQ(ELEC_evolve::td_val_elec_02,1); - EXPECT_EQ(ELEC_evolve::td_val_elec_03,1); EXPECT_EQ(ELEC_evolve::td_vext,false); EXPECT_EQ(ELEC_evolve::out_dipole,false); EXPECT_EQ(ELEC_evolve::out_efield,false); diff --git a/source/module_io/test/input_test.cpp b/source/module_io/test/input_test.cpp index 1be1966969..b594b63e8d 100644 --- a/source/module_io/test/input_test.cpp +++ b/source/module_io/test/input_test.cpp @@ -250,9 +250,6 @@ TEST_F(InputTest, Default) EXPECT_DOUBLE_EQ(INPUT.soc_lambda,1.0); EXPECT_EQ(INPUT.input_error,0); EXPECT_DOUBLE_EQ(INPUT.td_force_dt,0.02); - EXPECT_EQ(INPUT.td_val_elec_01,1); - EXPECT_EQ(INPUT.td_val_elec_02,1); - EXPECT_EQ(INPUT.td_val_elec_03,1); EXPECT_FALSE(INPUT.td_vext); EXPECT_EQ(INPUT.td_vext_dire,"1"); EXPECT_EQ(INPUT.td_stype,0); @@ -585,9 +582,6 @@ TEST_F(InputTest, Read) EXPECT_DOUBLE_EQ(INPUT.soc_lambda,1.0); EXPECT_EQ(INPUT.input_error,0); EXPECT_DOUBLE_EQ(INPUT.td_force_dt,0.02); - EXPECT_EQ(INPUT.td_val_elec_01,1); - EXPECT_EQ(INPUT.td_val_elec_02,1); - EXPECT_EQ(INPUT.td_val_elec_03,1); EXPECT_EQ(INPUT.td_vext,0); // EXPECT_EQ(INPUT.td_vext_dire,"1"); EXPECT_EQ(INPUT.td_stype,0); diff --git a/source/module_io/test/input_test_para.cpp b/source/module_io/test/input_test_para.cpp index 85aae50512..b4b3afbcba 100644 --- a/source/module_io/test/input_test_para.cpp +++ b/source/module_io/test/input_test_para.cpp @@ -256,9 +256,6 @@ TEST_F(InputParaTest,Bcast) EXPECT_DOUBLE_EQ(INPUT.soc_lambda,1.0); EXPECT_EQ(INPUT.input_error,0); EXPECT_DOUBLE_EQ(INPUT.td_force_dt,0.02); - EXPECT_EQ(INPUT.td_val_elec_01,1); - EXPECT_EQ(INPUT.td_val_elec_02,1); - EXPECT_EQ(INPUT.td_val_elec_03,1); EXPECT_FALSE(INPUT.td_vext); EXPECT_EQ(INPUT.td_vext_dire,"1"); EXPECT_EQ(INPUT.td_stype,0); diff --git a/source/module_io/test/support/INPUT b/source/module_io/test/support/INPUT index 7565ad8493..91b4fc9de4 100644 --- a/source/module_io/test/support/INPUT +++ b/source/module_io/test/support/INPUT @@ -282,9 +282,6 @@ exx_opt_orb_tolerence 0 # #Parameters (16.tddft) td_force_dt 0.02 #time of force change -td_val_elec_01 1 #td_val_elec_01 -td_val_elec_02 1 #td_val_elec_02 -td_val_elec_03 1 #td_val_elec_03 td_vext 0 #add extern potential or not td_vext_dire 1 #extern potential direction td_stype 0 #space domain type diff --git a/source/module_io/test/support/witestfile b/source/module_io/test/support/witestfile index 0495a2b03f..67ce58da05 100644 --- a/source/module_io/test/support/witestfile +++ b/source/module_io/test/support/witestfile @@ -1,356 +1,353 @@ -INPUT_PARAMETERS -#Parameters (1.General) -suffix autotest #the name of main output directory -latname none #the name of lattice name -stru_file ./support/STRU #the filename of file containing atom positions -kpoint_file KPT #the name of file containing k points -pseudo_dir ../../PP_ORB/ #the directory containing pseudo files -orbital_dir ../../PP_ORB/ #the directory containing orbital files -pseudo_rcut 15 #cut-off radius for radial integration -pseudo_mesh 0 #0: use our own mesh to do radial renormalization; 1: use mesh as in QE -lmaxmax 2 #maximum of l channels used -dft_functional hse #exchange correlation functional -xc_temperature 0 #temperature for finite temperature functionals -calculation scf #test; scf; relax; nscf; ienvelope; istate -esolver_type ksdft #the energy solver: ksdft, sdft, ofdft, tddft, lj, dp -ntype 1 #atom species number -nspin 1 #1: single spin; 2: up and down spin; 4: noncollinear spin -kspacing 0 #unit in 1/bohr, should be > 0, default is 0 which means read KPT file -min_dist_coef 0.2 #factor related to the allowed minimum distance between two atoms -nbands 8 #number of bands -nbands_sto 256 #number of stochastic bands -nbands_istate 5 #number of bands around Fermi level for istate calulation -symmetry 1 #the control of symmetry -init_vel False #read velocity from STRU or not -symmetry_prec 1e-05 #accuracy for symmetry -nelec 0 #input number of electrons -out_mul 0 # mulliken charge or not -noncolin 0 #using non-collinear-spin -lspinorb 0 #consider the spin-orbit interaction -kpar 1 #devide all processors into kpar groups and k points will be distributed among each group -bndpar 1 #devide all processors into bndpar groups and bands will be distributed among each group -out_freq_elec 0 #the frequency ( >= 0) of electronic iter to output charge density and wavefunction. 0: output only when converged -dft_plus_dmft 0 #true:DFT+DMFT; false: standard DFT calcullation(default) -rpa 0 #true:generate output files used in rpa calculation; false:(default) -printe 100 #Print out energy for each band for every printe steps -mem_saver 0 #Only for nscf calculations. if set to 1, then a memory saving technique will be used for many k point calculations. -diago_proc 4 #the number of procs used to do diagonalization -nbspline -1 #the order of B-spline basis -wannier_card none #input card for wannier functions -soc_lambda 1 #The fraction of averaged SOC pseudopotential is given by (1-soc_lambda) -cal_force 0 #if calculate the force at the end of the electronic iteration -out_freq_ion 0 #the frequency ( >= 0 ) of ionic step to output charge density and wavefunction. 0: output only when ion steps are finished -device cpu #the computing device for ABACUS - -#Parameters (2.PW) -ecutwfc 20 ##energy cutoff for wave functions -pw_diag_thr 0.01 #threshold for eigenvalues is cg electron iterations -scf_thr 1e-08 #charge density error -init_wfc atomic #start wave functions are from 'atomic', 'atomic+random', 'random' or 'file' -init_chg atomic #start charge is from 'atomic' or file -chg_extrap atomic #atomic; first-order; second-order; dm:coefficients of SIA -out_chg FALSE #>0 output charge density for selected electron steps -out_pot 2 #output realspace potential -out_wfc_pw 0 #output wave functions -out_wfc_r 0 #output wave functions in realspace -out_dos 0 #output energy and dos -out_band false #output energy and band structure -out_proj_band FaLse #output projected band structure -restart_save f #print to disk every step for restart -restart_load F #restart from disk -read_file_dir auto #directory of files for reading -nx 0 #number of points along x axis for FFT grid -ny 0 #number of points along y axis for FFT grid -nz 0 #number of points along z axis for FFT grid -cell_factor 1.2 #used in the construction of the pseudopotential tables -pw_seed 1 #random seed for initializing wave functions - -#Parameters (3.Stochastic DFT) -method_sto 3 #1: slow and save memory, 2: fast and waste memory -npart_sto 1 #Reduce memory when calculating Stochastic DOS -nbands_sto 256 #number of stochstic orbitals -nche_sto 100 #Chebyshev expansion orders -emin_sto 0 #trial energy to guess the lower bound of eigen energies of the Hamitonian operator -emax_sto 0 #trial energy to guess the upper bound of eigen energies of the Hamitonian operator -seed_sto 0 #the random seed to generate stochastic orbitals -initsto_freq 0 #frequency to generate new stochastic orbitals when running md -cal_cond 0 #calculate electronic conductivities -cond_nche 20 #orders of Chebyshev expansions for conductivities -cond_dw 0.1 #frequency interval for conductivities -cond_wcut 10 #cutoff frequency (omega) for conductivities -cond_dt 0.07 #control the t interval -cond_dtbatch 2 #control dt batch -cond_fwhm 0.3 #FWHM for conductivities -cond_nonlocal 1 #Nonlocal effects for conductivities - -#Parameters (4.Relaxation) -ks_solver genelpa #cg; dav; lapack; genelpa; scalapack_gvx; cusolver -scf_nmax 50 ##number of electron iterations -relax_nmax 1 #number of ion iteration steps -out_stru 0 #output the structure files after each ion step -force_thr 0.001 #force threshold, unit: Ry/Bohr -force_thr_ev 0.0257112 #force threshold, unit: eV/Angstrom -force_thr_ev2 0 #force invalid threshold, unit: eV/Angstrom -relax_cg_thr 0.5 #threshold for switching from cg to bfgs, unit: eV/Angstrom -stress_thr 0.01 #stress threshold -press1 0 #target pressure, unit: KBar -press2 0 #target pressure, unit: KBar -press3 0 #target pressure, unit: KBar -relax_bfgs_w1 0.01 #wolfe condition 1 for bfgs -relax_bfgs_w2 0.5 #wolfe condition 2 for bfgs -relax_bfgs_rmax 0.8 #maximal trust radius, unit: Bohr -relax_bfgs_rmin 1e-05 #minimal trust radius, unit: Bohr -relax_bfgs_init 0.5 #initial trust radius, unit: Bohr -cal_stress 0 #calculate the stress or not -fixed_axes None #which axes are fixed -fixed_ibrav 0 #whether to preseve lattice type during relaxation -fixed_atoms 0 #whether to preseve direct coordinates of atoms during relaxation -relax_method cg #bfgs; sd; cg; cg_bfgs; -relax_new TRUE #whether to use the new relaxation method -relax_scale_force 0.5 #controls the size of the first CG step if relax_new is true -out_level ie #ie(for electrons); i(for ions); -out_dm 0 #>0 output density matrix -deepks_out_labels 0 #>0 compute descriptor for deepks -deepks_scf 0 #>0 add V_delta to Hamiltonian -deepks_bandgap 0 #>0 for bandgap label -deepks_out_unittest 0 #if set 1, prints intermediate quantities that shall be used for making unit test -deepks_model #file dir of traced pytorch model: 'model.ptg - -#Parameters (5.LCAO) -basis_type lcao #PW; LCAO in pw; LCAO -nb2d 0 #2d distribution of atoms -gamma_only T #Only for localized orbitals set and gamma point. If set to 1, a fast algorithm is used -search_radius -1 #input search radius (Bohr) -search_pbc 1 #input periodic boundary condition -lcao_ecut 20 #energy cutoff for LCAO -lcao_dk 0.01 #delta k for 1D integration in LCAO -lcao_dr 0.01 #delta r for 1D integration in LCAO -lcao_rmax 30 #max R for 1D two-center integration table -out_mat_hs 0 #output H and S matrix -out_mat_hs2 0 #output H(R) and S(R) matrix -out_hs2_interval 1 #interval for printing H(R) and S(R) matrix during MD -out_element_info 0 #output (projected) wavefunction of each element -out_mat_r 0 #output r(R) matrix -out_wfc_lcao 0 #ouput LCAO wave functions -bx 2 #division of an element grid in FFT grid along x -by 2 #division of an element grid in FFT grid along y -bz 2 #division of an element grid in FFT grid along z - -bessel_nao_smooth 1 -bessel_nao_sigma 0.1 -bessel_nao_ecut default -bessel_nao_rcut 6.0 #-1.0 for forcing manual setting -bessel_nao_tolerence 1E-12 - -bessel_descriptor_lmax 2 # -1 for forcing manual setting -bessel_descriptor_smooth 1 -bessel_descriptor_sigma 0.1 -bessel_descriptor_ecut default -bessel_descriptor_rcut 6.0 #-1.0 for forcing manual setting -bessel_descriptor_tolerence 1E-12 - -#Parameters (6.Smearing) -smearing_method gauss #type of smearing_method: gauss; fd; fixed; mp; mp2; mv -smearing_sigma 0.002 #energy range for smearing - -#Parameters (7.Charge Mixing) -mixing_type pulay #plain; pulay; broyden -mixing_beta 0.7 #mixing parameter: 0 means no new charge -mixing_ndim 8 #mixing dimension in pulay -mixing_gg0 0 #mixing parameter in kerker - -#Parameters (8.DOS) -dos_emin_ev -15 #minimal range for dos -dos_emax_ev 15 #maximal range for dos -dos_edelta_ev 0.01 #delta energy for dos -dos_scale 0.01 #scale dos range by -dos_sigma 0.07 #gauss b coefficeinet(default=0.07) -dos_nche 100 #orders of Chebyshev expansions for dos - -#Parameters (9.Molecular dynamics) -md_type nvt #choose ensemble -md_thermostat nhc #choose thermostat -md_nstep 10 #md steps -md_dt 1 #time step -md_tchain 1 #number of Nose-Hoover chains -md_tfirst -1 #temperature first -md_tlast -1 #temperature last -md_dumpfreq 1 #The period to dump MD information -md_restartfreq 5 #The period to output MD restart information -md_seed -1 #random seed for MD -md_restart 0 #whether restart -lj_rcut 8.5 #cutoff radius of LJ potential -lj_epsilon 0.01032 #the value of epsilon for LJ potential -lj_sigma 3.405 #the value of sigma for LJ potential -pot_file graph.pb #the filename of potential files for CMD such as DP -msst_direction 2 #the direction of shock wave -msst_vel 0 #the velocity of shock wave -msst_vis 0 #artificial viscosity -msst_tscale 0.01 #reduction in initial temperature -msst_qmass -1 #mass of thermostat -md_tfreq 0 #oscillation frequency, used to determine qmass of NHC -md_damp 1 #damping parameter (time units) used to add force in Langevin method -md_nraise 1 #parameters used when md_type=nvt -md_tolerance 100 #tolerance for velocity rescaling (K) -md_pmode iso #NPT ensemble mode: iso, aniso, tri -md_pcouple none #whether couple different components: xyz, xy, yz, xz, none -md_pchain 1 #num of thermostats coupled with barostat -md_pfirst -1 #initial target pressure -md_plast -1 #final target pressure -md_pfreq 0 #oscillation frequency, used to determine qmass of thermostats coupled with barostat -dump_force 0 #output atomic forces into the file MD_dump or not. -dump_vel 0 #output atomic velocities into the file MD_dump or not -dump_virial 0 #output lattice virial into the file MD_dump or not - -#Parameters (10.Electric field and dipole correction) -efield_flag 0 #add electric field -dip_cor_flag 0 #dipole correction -efield_dir 2 #the direction of the electric field or dipole correction -efield_pos_max 0.5 #position of the maximum of the saw-like potential along crystal axis efield_dir -efield_pos_dec 0.1 #zone in the unit cell where the saw-like potential decreases -efield_amp 0 #amplitude of the electric field - -#Parameters (11.Gate field) -gate_flag 0 #compensating charge or not -zgate 0.5 #position of charged plate -relax 0 #allow relaxation along the specific direction -block 0 #add a block potential or not -block_down 0.45 #low bound of the block -block_up 0.55 #high bound of the block -block_height 0.1 #height of the block - -#Parameters (12.Test) -out_alllog F #output information for each processor, when parallel -nurse 0 #for coders -colour 0 #for coders, make their live colourful -t_in_h 1 #calculate the kinetic energy or not -vl_in_h 1 #calculate the local potential or not -vnl_in_h 1 #calculate the nonlocal potential or not -vh_in_h 1 #calculate the hartree potential or not -vion_in_h 1 #calculate the local ionic potential or not -test_force 0 #test the force -test_stress 0 #test the force -test_skip_ewald 0 #skip ewald energy - -#Parameters (13.vdW Correction) -vdw_method d2 #the method of calculating vdw (none ; d2 ; d3_0 ; d3_bj -vdw_s6 default #scale parameter of d2/d3_0/d3_bj -vdw_s8 default #scale parameter of d3_0/d3_bj -vdw_a1 default #damping parameter of d3_0/d3_bj -vdw_a2 default #damping parameter of d3_bj -vdw_d 20 #damping parameter of d2 -vdw_abc 0 #third-order term? -vdw_C6_file default #filename of C6 -vdw_C6_unit Jnm6/mol #unit of C6, Jnm6/mol or eVA6 -vdw_R0_file default #filename of R0 -vdw_R0_unit A #unit of R0, A or Bohr -vdw_cutoff_type radius #expression model of periodic structure, radius or period -vdw_cutoff_radius default #radius cutoff for periodic structure -vdw_radius_unit Bohr #unit of radius cutoff for periodic structure -vdw_cn_thr 40 #radius cutoff for cn -vdw_cn_thr_unit Bohr #unit of cn_thr, Bohr or Angstrom -vdw_cutoff_period 3 3 3 #periods of periodic structure - -#Parameters (14.exx) -exx_hybrid_alpha default # -exx_hse_omega 0.11 # -exx_separate_loop 1 #0 or 1 -exx_hybrid_step 100 # -exx_lambda 0.3 # -exx_real_number default #0 or 1 -exx_pca_threshold 0 # -exx_c_threshold 0 # -exx_v_threshold 0 # -exx_dm_threshold 0 # -exx_schwarz_threshold 0 # -exx_cauchy_threshold 0 # -exx_c_grad_threshold 0 # -exx_v_grad_threshold 0 # -exx_cauchy_grad_threshold 0 # -exx_ccp_threshold 1e-08 # -exx_ccp_rmesh_times default # -exx_distribute_type htime #htime or kmeans1 or kmeans2 -exx_opt_orb_lmax 0 # -exx_opt_orb_ecut 0 # -exx_opt_orb_tolerence 0 # - -#Parameters (16.tddft) -td_force_dt 0.02 #time of force change -td_val_elec_01 1 #td_val_elec_01 -td_val_elec_02 1 #td_val_elec_02 -td_val_elec_03 1 #td_val_elec_03 -td_vext 0 #add extern potential or not -td_vext_dire 1 #extern potential direction -td_stype 0 #space domain type -td_ttype 0 #time domain type -td_tstart 1 #the start step of electric field -td_tend 1000 #the start step of electric field -td_lcut1 0.05 # separator in length gauge -td_lcut2 0.95 # separator in length gauge -# parameters of Gauss electric field -td_gauss_freq 22.13 # fs^-1 -td_gauss_phase 0.0 -td_gauss_sigma 30.0 # fs -td_gauss_t0 100.0 -td_gauss_amp 0.25 # V/A -# parameters of Trapezoid electric field -td_trape_freq 1.60 # fs^-1 -td_trape_phase 0.0 -td_trape_t1 1875 -td_trape_t2 5625 -td_trape_t3 7500 -td_trape_amp 2.74 # V/A -#parameters of Trigonometric electric field -td_trigo_freq1 1.164656 # fs^-1 -td_trigo_freq2 0.029116 # fs^-1 -td_trigo_phase1 0.0 -td_trigo_phase2 0.0 -td_trigo_amp 2.74 # V/A -#parameters of Heaviside electric field -td_heavi_t0 100 -td_heavi_amp 1.0 # V/A -td_print_eij -1.0 # threshold to output Eij elements -td_edm 0 # 0: new edm method 1: old edm method -out_dipole 0 #output dipole or not -out_efield 0 #output efield or not -ocp 0 #change occupation or not -ocp_set none #set occupation - -#Parameters (17.berry_wannier) -berry_phase 0 #calculate berry phase or not -gdir 3 #calculate the polarization in the direction of the lattice vector -towannier90 0 #use wannier90 code interface or not -nnkpfile seedname.nnkp #the wannier90 code nnkp file name -wannier_spin up #calculate spin in wannier90 code interface - -#Parameters (18.implicit_solvation) -imp_sol 0 #calculate implicit solvation correction or not -eb_k 80 #the relative permittivity of the bulk solvent -tau 1.0798e-05 #the effective surface tension parameter -sigma_k 0.6 # the width of the diffuse cavity -nc_k 0.00037 # the cut-off charge density - -#Parameters (19.orbital free density functional theory) -of_kinetic vw #kinetic energy functional, such as tf, vw, wt -of_method tn #optimization method used in OFDFT, including cg1, cg2, tn (default) -of_conv energy #the convergence criterion, potential, energy (default), or both -of_tole 1e-06 #tolerance of the energy change (in Ry) for determining the convergence, default=2e-6 Ry -of_tolp 1e-05 #tolerance of potential for determining the convergence, default=1e-5 in a.u. -of_tf_weight 1 #weight of TF KEDF -of_vw_weight 1 #weight of vW KEDF -of_wt_alpha 0.833333 #parameter alpha of WT KEDF -of_wt_beta 0.833333 #parameter beta of WT KEDF -of_wt_rho0 1 #the average density of system, used in WT KEDF, in Bohr^-3 -of_hold_rho0 0 #If set to 1, the rho0 will be fixed even if the volume of system has changed, it will be set to 1 automaticly if of_wt_rho0 is not zero -of_full_pw 0 #If set to 1, ecut will be ignored when collect planewaves, so that all planewaves will be used -of_full_pw_dim 0 #If of_full_pw = true, dimention of FFT is testricted to be (0) either odd or even; (1) odd only; (2) even only -of_read_kernel 0 #If set to 1, the kernel of WT KEDF will be filled from file of_kernel_file, not from formula. Only usable for WT KEDF -of_kernel_file WTkernel.txt #The name of WT kernel file. - -#Parameters (19.dft+u) -dft_plus_u 0 #true:DFT+U correction; false: standard DFT calcullation(default) -yukawa_lambda -1 #default:0.0 -yukawa_potential 0 #default: false -omc 0 #the mode of occupation matrix control -hubbard_u 0 #Hubbard Coulomb interaction parameter U(ev) -orbital_corr -1 #which correlated orbitals need corrected ; d:2 ,f:3, do not need correction:-1 +INPUT_PARAMETERS +#Parameters (1.General) +suffix autotest #the name of main output directory +latname none #the name of lattice name +stru_file ./support/STRU #the filename of file containing atom positions +kpoint_file KPT #the name of file containing k points +pseudo_dir ../../PP_ORB/ #the directory containing pseudo files +orbital_dir ../../PP_ORB/ #the directory containing orbital files +pseudo_rcut 15 #cut-off radius for radial integration +pseudo_mesh 0 #0: use our own mesh to do radial renormalization; 1: use mesh as in QE +lmaxmax 2 #maximum of l channels used +dft_functional hse #exchange correlation functional +xc_temperature 0 #temperature for finite temperature functionals +calculation scf #test; scf; relax; nscf; ienvelope; istate +esolver_type ksdft #the energy solver: ksdft, sdft, ofdft, tddft, lj, dp +ntype 1 #atom species number +nspin 1 #1: single spin; 2: up and down spin; 4: noncollinear spin +kspacing 0 #unit in 1/bohr, should be > 0, default is 0 which means read KPT file +min_dist_coef 0.2 #factor related to the allowed minimum distance between two atoms +nbands 8 #number of bands +nbands_sto 256 #number of stochastic bands +nbands_istate 5 #number of bands around Fermi level for istate calulation +symmetry 1 #the control of symmetry +init_vel False #read velocity from STRU or not +symmetry_prec 1e-05 #accuracy for symmetry +nelec 0 #input number of electrons +out_mul 0 # mulliken charge or not +noncolin 0 #using non-collinear-spin +lspinorb 0 #consider the spin-orbit interaction +kpar 1 #devide all processors into kpar groups and k points will be distributed among each group +bndpar 1 #devide all processors into bndpar groups and bands will be distributed among each group +out_freq_elec 0 #the frequency ( >= 0) of electronic iter to output charge density and wavefunction. 0: output only when converged +dft_plus_dmft 0 #true:DFT+DMFT; false: standard DFT calcullation(default) +rpa 0 #true:generate output files used in rpa calculation; false:(default) +printe 100 #Print out energy for each band for every printe steps +mem_saver 0 #Only for nscf calculations. if set to 1, then a memory saving technique will be used for many k point calculations. +diago_proc 4 #the number of procs used to do diagonalization +nbspline -1 #the order of B-spline basis +wannier_card none #input card for wannier functions +soc_lambda 1 #The fraction of averaged SOC pseudopotential is given by (1-soc_lambda) +cal_force 0 #if calculate the force at the end of the electronic iteration +out_freq_ion 0 #the frequency ( >= 0 ) of ionic step to output charge density and wavefunction. 0: output only when ion steps are finished +device cpu #the computing device for ABACUS + +#Parameters (2.PW) +ecutwfc 20 ##energy cutoff for wave functions +pw_diag_thr 0.01 #threshold for eigenvalues is cg electron iterations +scf_thr 1e-08 #charge density error +init_wfc atomic #start wave functions are from 'atomic', 'atomic+random', 'random' or 'file' +init_chg atomic #start charge is from 'atomic' or file +chg_extrap atomic #atomic; first-order; second-order; dm:coefficients of SIA +out_chg FALSE #>0 output charge density for selected electron steps +out_pot 2 #output realspace potential +out_wfc_pw 0 #output wave functions +out_wfc_r 0 #output wave functions in realspace +out_dos 0 #output energy and dos +out_band false #output energy and band structure +out_proj_band FaLse #output projected band structure +restart_save f #print to disk every step for restart +restart_load F #restart from disk +read_file_dir auto #directory of files for reading +nx 0 #number of points along x axis for FFT grid +ny 0 #number of points along y axis for FFT grid +nz 0 #number of points along z axis for FFT grid +cell_factor 1.2 #used in the construction of the pseudopotential tables +pw_seed 1 #random seed for initializing wave functions + +#Parameters (3.Stochastic DFT) +method_sto 3 #1: slow and save memory, 2: fast and waste memory +npart_sto 1 #Reduce memory when calculating Stochastic DOS +nbands_sto 256 #number of stochstic orbitals +nche_sto 100 #Chebyshev expansion orders +emin_sto 0 #trial energy to guess the lower bound of eigen energies of the Hamitonian operator +emax_sto 0 #trial energy to guess the upper bound of eigen energies of the Hamitonian operator +seed_sto 0 #the random seed to generate stochastic orbitals +initsto_freq 0 #frequency to generate new stochastic orbitals when running md +cal_cond 0 #calculate electronic conductivities +cond_nche 20 #orders of Chebyshev expansions for conductivities +cond_dw 0.1 #frequency interval for conductivities +cond_wcut 10 #cutoff frequency (omega) for conductivities +cond_dt 0.07 #control the t interval +cond_dtbatch 2 #control dt batch +cond_fwhm 0.3 #FWHM for conductivities +cond_nonlocal 1 #Nonlocal effects for conductivities + +#Parameters (4.Relaxation) +ks_solver genelpa #cg; dav; lapack; genelpa; scalapack_gvx; cusolver +scf_nmax 50 ##number of electron iterations +relax_nmax 1 #number of ion iteration steps +out_stru 0 #output the structure files after each ion step +force_thr 0.001 #force threshold, unit: Ry/Bohr +force_thr_ev 0.0257112 #force threshold, unit: eV/Angstrom +force_thr_ev2 0 #force invalid threshold, unit: eV/Angstrom +relax_cg_thr 0.5 #threshold for switching from cg to bfgs, unit: eV/Angstrom +stress_thr 0.01 #stress threshold +press1 0 #target pressure, unit: KBar +press2 0 #target pressure, unit: KBar +press3 0 #target pressure, unit: KBar +relax_bfgs_w1 0.01 #wolfe condition 1 for bfgs +relax_bfgs_w2 0.5 #wolfe condition 2 for bfgs +relax_bfgs_rmax 0.8 #maximal trust radius, unit: Bohr +relax_bfgs_rmin 1e-05 #minimal trust radius, unit: Bohr +relax_bfgs_init 0.5 #initial trust radius, unit: Bohr +cal_stress 0 #calculate the stress or not +fixed_axes None #which axes are fixed +fixed_ibrav 0 #whether to preseve lattice type during relaxation +fixed_atoms 0 #whether to preseve direct coordinates of atoms during relaxation +relax_method cg #bfgs; sd; cg; cg_bfgs; +relax_new TRUE #whether to use the new relaxation method +relax_scale_force 0.5 #controls the size of the first CG step if relax_new is true +out_level ie #ie(for electrons); i(for ions); +out_dm 0 #>0 output density matrix +deepks_out_labels 0 #>0 compute descriptor for deepks +deepks_scf 0 #>0 add V_delta to Hamiltonian +deepks_bandgap 0 #>0 for bandgap label +deepks_out_unittest 0 #if set 1, prints intermediate quantities that shall be used for making unit test +deepks_model #file dir of traced pytorch model: 'model.ptg + +#Parameters (5.LCAO) +basis_type lcao #PW; LCAO in pw; LCAO +nb2d 0 #2d distribution of atoms +gamma_only T #Only for localized orbitals set and gamma point. If set to 1, a fast algorithm is used +search_radius -1 #input search radius (Bohr) +search_pbc 1 #input periodic boundary condition +lcao_ecut 20 #energy cutoff for LCAO +lcao_dk 0.01 #delta k for 1D integration in LCAO +lcao_dr 0.01 #delta r for 1D integration in LCAO +lcao_rmax 30 #max R for 1D two-center integration table +out_mat_hs 0 #output H and S matrix +out_mat_hs2 0 #output H(R) and S(R) matrix +out_hs2_interval 1 #interval for printing H(R) and S(R) matrix during MD +out_element_info 0 #output (projected) wavefunction of each element +out_mat_r 0 #output r(R) matrix +out_wfc_lcao 0 #ouput LCAO wave functions +bx 2 #division of an element grid in FFT grid along x +by 2 #division of an element grid in FFT grid along y +bz 2 #division of an element grid in FFT grid along z + +bessel_nao_smooth 1 +bessel_nao_sigma 0.1 +bessel_nao_ecut default +bessel_nao_rcut 6.0 #-1.0 for forcing manual setting +bessel_nao_tolerence 1E-12 + +bessel_descriptor_lmax 2 # -1 for forcing manual setting +bessel_descriptor_smooth 1 +bessel_descriptor_sigma 0.1 +bessel_descriptor_ecut default +bessel_descriptor_rcut 6.0 #-1.0 for forcing manual setting +bessel_descriptor_tolerence 1E-12 + +#Parameters (6.Smearing) +smearing_method gauss #type of smearing_method: gauss; fd; fixed; mp; mp2; mv +smearing_sigma 0.002 #energy range for smearing + +#Parameters (7.Charge Mixing) +mixing_type pulay #plain; pulay; broyden +mixing_beta 0.7 #mixing parameter: 0 means no new charge +mixing_ndim 8 #mixing dimension in pulay +mixing_gg0 0 #mixing parameter in kerker + +#Parameters (8.DOS) +dos_emin_ev -15 #minimal range for dos +dos_emax_ev 15 #maximal range for dos +dos_edelta_ev 0.01 #delta energy for dos +dos_scale 0.01 #scale dos range by +dos_sigma 0.07 #gauss b coefficeinet(default=0.07) +dos_nche 100 #orders of Chebyshev expansions for dos + +#Parameters (9.Molecular dynamics) +md_type nvt #choose ensemble +md_thermostat nhc #choose thermostat +md_nstep 10 #md steps +md_dt 1 #time step +md_tchain 1 #number of Nose-Hoover chains +md_tfirst -1 #temperature first +md_tlast -1 #temperature last +md_dumpfreq 1 #The period to dump MD information +md_restartfreq 5 #The period to output MD restart information +md_seed -1 #random seed for MD +md_restart 0 #whether restart +lj_rcut 8.5 #cutoff radius of LJ potential +lj_epsilon 0.01032 #the value of epsilon for LJ potential +lj_sigma 3.405 #the value of sigma for LJ potential +pot_file graph.pb #the filename of potential files for CMD such as DP +msst_direction 2 #the direction of shock wave +msst_vel 0 #the velocity of shock wave +msst_vis 0 #artificial viscosity +msst_tscale 0.01 #reduction in initial temperature +msst_qmass -1 #mass of thermostat +md_tfreq 0 #oscillation frequency, used to determine qmass of NHC +md_damp 1 #damping parameter (time units) used to add force in Langevin method +md_nraise 1 #parameters used when md_type=nvt +md_tolerance 100 #tolerance for velocity rescaling (K) +md_pmode iso #NPT ensemble mode: iso, aniso, tri +md_pcouple none #whether couple different components: xyz, xy, yz, xz, none +md_pchain 1 #num of thermostats coupled with barostat +md_pfirst -1 #initial target pressure +md_plast -1 #final target pressure +md_pfreq 0 #oscillation frequency, used to determine qmass of thermostats coupled with barostat +dump_force 0 #output atomic forces into the file MD_dump or not. +dump_vel 0 #output atomic velocities into the file MD_dump or not +dump_virial 0 #output lattice virial into the file MD_dump or not + +#Parameters (10.Electric field and dipole correction) +efield_flag 0 #add electric field +dip_cor_flag 0 #dipole correction +efield_dir 2 #the direction of the electric field or dipole correction +efield_pos_max 0.5 #position of the maximum of the saw-like potential along crystal axis efield_dir +efield_pos_dec 0.1 #zone in the unit cell where the saw-like potential decreases +efield_amp 0 #amplitude of the electric field + +#Parameters (11.Gate field) +gate_flag 0 #compensating charge or not +zgate 0.5 #position of charged plate +relax 0 #allow relaxation along the specific direction +block 0 #add a block potential or not +block_down 0.45 #low bound of the block +block_up 0.55 #high bound of the block +block_height 0.1 #height of the block + +#Parameters (12.Test) +out_alllog F #output information for each processor, when parallel +nurse 0 #for coders +colour 0 #for coders, make their live colourful +t_in_h 1 #calculate the kinetic energy or not +vl_in_h 1 #calculate the local potential or not +vnl_in_h 1 #calculate the nonlocal potential or not +vh_in_h 1 #calculate the hartree potential or not +vion_in_h 1 #calculate the local ionic potential or not +test_force 0 #test the force +test_stress 0 #test the force +test_skip_ewald 0 #skip ewald energy + +#Parameters (13.vdW Correction) +vdw_method d2 #the method of calculating vdw (none ; d2 ; d3_0 ; d3_bj +vdw_s6 default #scale parameter of d2/d3_0/d3_bj +vdw_s8 default #scale parameter of d3_0/d3_bj +vdw_a1 default #damping parameter of d3_0/d3_bj +vdw_a2 default #damping parameter of d3_bj +vdw_d 20 #damping parameter of d2 +vdw_abc 0 #third-order term? +vdw_C6_file default #filename of C6 +vdw_C6_unit Jnm6/mol #unit of C6, Jnm6/mol or eVA6 +vdw_R0_file default #filename of R0 +vdw_R0_unit A #unit of R0, A or Bohr +vdw_cutoff_type radius #expression model of periodic structure, radius or period +vdw_cutoff_radius default #radius cutoff for periodic structure +vdw_radius_unit Bohr #unit of radius cutoff for periodic structure +vdw_cn_thr 40 #radius cutoff for cn +vdw_cn_thr_unit Bohr #unit of cn_thr, Bohr or Angstrom +vdw_cutoff_period 3 3 3 #periods of periodic structure + +#Parameters (14.exx) +exx_hybrid_alpha default # +exx_hse_omega 0.11 # +exx_separate_loop 1 #0 or 1 +exx_hybrid_step 100 # +exx_lambda 0.3 # +exx_real_number default #0 or 1 +exx_pca_threshold 0 # +exx_c_threshold 0 # +exx_v_threshold 0 # +exx_dm_threshold 0 # +exx_schwarz_threshold 0 # +exx_cauchy_threshold 0 # +exx_c_grad_threshold 0 # +exx_v_grad_threshold 0 # +exx_cauchy_grad_threshold 0 # +exx_ccp_threshold 1e-08 # +exx_ccp_rmesh_times default # +exx_distribute_type htime #htime or kmeans1 or kmeans2 +exx_opt_orb_lmax 0 # +exx_opt_orb_ecut 0 # +exx_opt_orb_tolerence 0 # + +#Parameters (16.tddft) +td_force_dt 0.02 #time of force change +td_vext 0 #add extern potential or not +td_vext_dire 1 #extern potential direction +td_stype 0 #space domain type +td_ttype 0 #time domain type +td_tstart 1 #the start step of electric field +td_tend 1000 #the start step of electric field +td_lcut1 0.05 # separator in length gauge +td_lcut2 0.95 # separator in length gauge +# parameters of Gauss electric field +td_gauss_freq 22.13 # fs^-1 +td_gauss_phase 0.0 +td_gauss_sigma 30.0 # fs +td_gauss_t0 100.0 +td_gauss_amp 0.25 # V/A +# parameters of Trapezoid electric field +td_trape_freq 1.60 # fs^-1 +td_trape_phase 0.0 +td_trape_t1 1875 +td_trape_t2 5625 +td_trape_t3 7500 +td_trape_amp 2.74 # V/A +#parameters of Trigonometric electric field +td_trigo_freq1 1.164656 # fs^-1 +td_trigo_freq2 0.029116 # fs^-1 +td_trigo_phase1 0.0 +td_trigo_phase2 0.0 +td_trigo_amp 2.74 # V/A +#parameters of Heaviside electric field +td_heavi_t0 100 +td_heavi_amp 1.0 # V/A +td_print_eij -1.0 # threshold to output Eij elements +td_edm 0 # 0: new edm method 1: old edm method +out_dipole 0 #output dipole or not +out_efield 0 #output efield or not +ocp 0 #change occupation or not +ocp_set none #set occupation + +#Parameters (17.berry_wannier) +berry_phase 0 #calculate berry phase or not +gdir 3 #calculate the polarization in the direction of the lattice vector +towannier90 0 #use wannier90 code interface or not +nnkpfile seedname.nnkp #the wannier90 code nnkp file name +wannier_spin up #calculate spin in wannier90 code interface + +#Parameters (18.implicit_solvation) +imp_sol 0 #calculate implicit solvation correction or not +eb_k 80 #the relative permittivity of the bulk solvent +tau 1.0798e-05 #the effective surface tension parameter +sigma_k 0.6 # the width of the diffuse cavity +nc_k 0.00037 # the cut-off charge density + +#Parameters (19.orbital free density functional theory) +of_kinetic vw #kinetic energy functional, such as tf, vw, wt +of_method tn #optimization method used in OFDFT, including cg1, cg2, tn (default) +of_conv energy #the convergence criterion, potential, energy (default), or both +of_tole 1e-06 #tolerance of the energy change (in Ry) for determining the convergence, default=2e-6 Ry +of_tolp 1e-05 #tolerance of potential for determining the convergence, default=1e-5 in a.u. +of_tf_weight 1 #weight of TF KEDF +of_vw_weight 1 #weight of vW KEDF +of_wt_alpha 0.833333 #parameter alpha of WT KEDF +of_wt_beta 0.833333 #parameter beta of WT KEDF +of_wt_rho0 1 #the average density of system, used in WT KEDF, in Bohr^-3 +of_hold_rho0 0 #If set to 1, the rho0 will be fixed even if the volume of system has changed, it will be set to 1 automaticly if of_wt_rho0 is not zero +of_full_pw 0 #If set to 1, ecut will be ignored when collect planewaves, so that all planewaves will be used +of_full_pw_dim 0 #If of_full_pw = true, dimention of FFT is testricted to be (0) either odd or even; (1) odd only; (2) even only +of_read_kernel 0 #If set to 1, the kernel of WT KEDF will be filled from file of_kernel_file, not from formula. Only usable for WT KEDF +of_kernel_file WTkernel.txt #The name of WT kernel file. + +#Parameters (19.dft+u) +dft_plus_u 0 #true:DFT+U correction; false: standard DFT calcullation(default) +yukawa_lambda -1 #default:0.0 +yukawa_potential 0 #default: false +omc 0 #the mode of occupation matrix control +hubbard_u 0 #Hubbard Coulomb interaction parameter U(ev) +orbital_corr -1 #which correlated orbitals need corrected ; d:2 ,f:3, do not need correction:-1 diff --git a/source/module_io/test/write_input_test.cpp b/source/module_io/test/write_input_test.cpp index 67a71efce1..f7e9114a92 100644 --- a/source/module_io/test/write_input_test.cpp +++ b/source/module_io/test/write_input_test.cpp @@ -293,9 +293,6 @@ TEST_F(write_input,print) EXPECT_THAT(output,testing::HasSubstr("")); EXPECT_THAT(output,testing::HasSubstr("#Parameters (16.tddft)")); EXPECT_THAT(output,testing::HasSubstr("td_force_dt 0.02 #time of force change")); - EXPECT_THAT(output,testing::HasSubstr("td_val_elec_01 1 #td_val_elec_01")); - EXPECT_THAT(output,testing::HasSubstr("td_val_elec_02 1 #td_val_elec_02")); - EXPECT_THAT(output,testing::HasSubstr("td_val_elec_03 1 #td_val_elec_03")); EXPECT_THAT(output,testing::HasSubstr("td_vext 0 #add extern potential or not")); EXPECT_THAT(output,testing::HasSubstr("td_vext_dire 1 #extern potential direction")); EXPECT_THAT(output,testing::HasSubstr("out_dipole 0 #output dipole or not")); diff --git a/source/module_io/write_dipole.cpp b/source/module_io/write_dipole.cpp index 2e34bc29fe..1b9dc884af 100644 --- a/source/module_io/write_dipole.cpp +++ b/source/module_io/write_dipole.cpp @@ -28,6 +28,12 @@ void ModuleIO::write_dipole(const double *rho_save, } } + double bmod[3]; + for (int i = 0; i < 3; i++) + { + bmod[i] = prepare(GlobalC::ucell, i); + } + #ifndef __MPI double dipole_elec_x = 0.0, dipole_elec_y = 0.0, dipole_elec_z = 0.0; for (int k = 0; k < GlobalC::rhopw->nz; k++) @@ -54,261 +60,73 @@ void ModuleIO::write_dipole(const double *rho_save, ofs << istep << " " << dipole_elec_x << " " << dipole_elec_y << dipole_elec_z; #else - double dipole_elec_x = 0.0, dipole_elec_y = 0.0, dipole_elec_z = 0.0; - // only do in the first pool. - if (GlobalV::MY_POOL == 0) - { - // num_z: how many planes on processor 'ip' - int *num_z = new int[GlobalV::NPROC_IN_POOL]; - ModuleBase::GlobalFunc::ZEROS(num_z, GlobalV::NPROC_IN_POOL); - for (int iz = 0; iz < GlobalC::bigpw->nbz; iz++) - { - int ip = iz % GlobalV::NPROC_IN_POOL; - num_z[ip] += GlobalC::bigpw->bz; - } + double dipole_elec[3] = {0.0, 0.0, 0.0}; - // start_z: start position of z in - // processor ip. - int *start_z = new int[GlobalV::NPROC_IN_POOL]; - ModuleBase::GlobalFunc::ZEROS(start_z, GlobalV::NPROC_IN_POOL); - for (int ip = 1; ip < GlobalV::NPROC_IN_POOL; ip++) - { - start_z[ip] = start_z[ip - 1] + num_z[ip - 1]; - } - - // which_ip: found iz belongs to which ip. - int *which_ip = new int[GlobalC::rhopw->nz]; - ModuleBase::GlobalFunc::ZEROS(which_ip, GlobalC::rhopw->nz); - for (int iz = 0; iz < GlobalC::rhopw->nz; iz++) - { - for (int ip = 0; ip < GlobalV::NPROC_IN_POOL; ip++) - { - if (iz >= start_z[GlobalV::NPROC_IN_POOL - 1]) - { - which_ip[iz] = GlobalV::NPROC_IN_POOL - 1; - break; - } - else if (iz >= start_z[ip] && iz < start_z[ip + 1]) - { - which_ip[iz] = ip; - break; - } - } - // GlobalV::ofs_running << "\n iz=" << iz << " ip=" << which_ip[iz]; - } - - // int count=0; - int nxy = GlobalC::rhopw->nx * GlobalC::rhopw->ny; - double *zpiece = new double[nxy]; - - // save the rho one z by one z. - for (int iz = 0; iz < GlobalC::rhopw->nz; iz++) - { - // std::cout << "\n iz=" << iz << std::endl; - // tag must be different for different iz. - ModuleBase::GlobalFunc::ZEROS(zpiece, nxy); - int tag = iz; - MPI_Status ierror; - - // case 1: the first part of rho in processor 0. - if (which_ip[iz] == 0 && GlobalV::RANK_IN_POOL == 0) - { - for (int ir = 0; ir < nxy; ir++) - { - // mohan change to rho_save on 2012-02-10 - // because this can make our next restart calculation lead - // to the same scf_thr as the one saved. - zpiece[ir] = rho_save[ir * GlobalC::rhopw->nplane + iz - GlobalC::rhopw->startz_current]; - // GlobalV::ofs_running << "\n get zpiece[" << ir << "]=" << zpiece[ir] << " - // ir*GlobalC::pw.nczp+iz=" << ir*GlobalC::pw.nczp+iz; - } - } - // case 2: > first part rho: send the rho to - // processor 0. - else if (which_ip[iz] == GlobalV::RANK_IN_POOL) - { - for (int ir = 0; ir < nxy; ir++) - { - // zpiece[ir] = rho[is][ir*num_z[GlobalV::RANK_IN_POOL]+iz]; - zpiece[ir] = rho_save[ir * GlobalC::rhopw->nplane + iz - GlobalC::rhopw->startz_current]; - // GlobalV::ofs_running << "\n get zpiece[" << ir << "]=" << zpiece[ir] << " - // ir*GlobalC::pw.nczp+iz=" << ir*GlobalC::pw.nczp+iz; - } - MPI_Send(zpiece, nxy, MPI_DOUBLE, 0, tag, POOL_WORLD); - } - - // case 2: > first part rho: processor 0 receive the rho - // from other processors - else if (GlobalV::RANK_IN_POOL == 0) - { - MPI_Recv(zpiece, nxy, MPI_DOUBLE, which_ip[iz], tag, POOL_WORLD, &ierror); - // GlobalV::ofs_running << "\n Receieve First number = " << zpiece[0]; - } - - // write data - if (GlobalV::MY_RANK == 0) - { - // ofs << "\niz=" << iz; - // mohan update 2011-03-30 - for (int iy = 0; iy < GlobalC::rhopw->ny; iy++) - { - for (int ix = 0; ix < GlobalC::rhopw->nx; ix++) - { - /* - if(ixny + iy] * ix * GlobalC::ucell.lat0 * 0.529177 - / GlobalC::rhopw->nx; - dipole_elec_y += zpiece[ix * GlobalC::rhopw->ny + iy] * iy * GlobalC::ucell.lat0 * 0.529177 - / GlobalC::rhopw->ny; - dipole_elec_z += zpiece[ix * GlobalC::rhopw->ny + iy] * iz * GlobalC::ucell.lat0 * 0.529177 - / GlobalC::rhopw->nz; - } - } - } - } // end iz + for (int ir = 0; ir < GlobalC::rhopw->nrxx; ++ir) + { + int i = ir / (GlobalC::rhopw->ny * GlobalC::rhopw->nplane); + int j = ir / GlobalC::rhopw->nplane - i * GlobalC::rhopw->ny; + int k = ir % GlobalC::rhopw->nplane + GlobalC::rhopw->startz_current; + double x = (double)i / GlobalC::rhopw->nx; + double y = (double)j / GlobalC::rhopw->ny; + double z = (double)k / GlobalC::rhopw->nz; + + dipole_elec[0] += rho_save[ir] * x; + dipole_elec[1] += rho_save[ir] * y; + dipole_elec[2] += rho_save[ir] * z; + } - delete[] zpiece; + Parallel_Reduce::reduce_double_pool(dipole_elec[0]); + Parallel_Reduce::reduce_double_pool(dipole_elec[1]); + Parallel_Reduce::reduce_double_pool(dipole_elec[2]); + for (int i = 0; i < 3; ++i) + { + dipole_elec[i] *= GlobalC::ucell.lat0 / bmod[i] * GlobalC::ucell.omega / GlobalC::rhopw->nxyz; + } - double nxyz = GlobalC::rhopw->nx * GlobalC::rhopw->ny * GlobalC::rhopw->nz; - dipole_elec_x *= GlobalC::ucell.omega / static_cast(nxyz); - dipole_elec_y *= GlobalC::ucell.omega / static_cast(nxyz); - dipole_elec_z *= GlobalC::ucell.omega / static_cast(nxyz); + std::cout << std::setprecision(8) << "dipole_elec_x: " << dipole_elec[0] << std::endl; + std::cout << std::setprecision(8) << "dipole_elec_y: " << dipole_elec[1] << std::endl; + std::cout << std::setprecision(8) << "dipole_elec_z: " << dipole_elec[2] << std::endl; - std::cout << std::setprecision(8) << "dipole_elec_x: " << dipole_elec_x << std::endl; - std::cout << std::setprecision(8) << "dipole_elec_y: " << dipole_elec_y << std::endl; - std::cout << std::setprecision(8) << "dipole_elec_z: " << dipole_elec_z << std::endl; + ofs << std::setprecision(8) << istep << " " << dipole_elec[0] << " " << dipole_elec[1] << " " << dipole_elec[2] + << std::endl; - ofs << istep << " " << dipole_elec_x << " " << dipole_elec_y << " " << dipole_elec_z << std::endl; + double dipole_ion[3] = {0.0}; + double dipole_sum = 0.0; - /* - double dipole_ion_x = 0.0, dipole_ion_y = 0.0, dipole_ion_z = 0.0, dipole_sum = 0.0; - if (GlobalC::ucell.ntype == 1) - { - for (int ia = 0; ia < GlobalC::ucell.atoms[0].na; ia++) - { - dipole_ion_x += GlobalC::ucell.atoms[0].taud[ia].x * GlobalC::ucell.lat0 * 0.529177 - * ELEC_evolve::td_val_elec_01; - dipole_ion_y += GlobalC::ucell.atoms[0].taud[ia].y * GlobalC::ucell.lat0 * 0.529177 - * ELEC_evolve::td_val_elec_01; - dipole_ion_z += GlobalC::ucell.atoms[0].taud[ia].z * GlobalC::ucell.lat0 * 0.529177 - * ELEC_evolve::td_val_elec_01; - } - } - else if (GlobalC::ucell.ntype == 2) - { - for (int ia = 0; ia < GlobalC::ucell.atoms[0].na; ia++) - { - dipole_ion_x += GlobalC::ucell.atoms[0].taud[ia].x * GlobalC::ucell.lat0 * 0.529177 - * ELEC_evolve::td_val_elec_01; - dipole_ion_y += GlobalC::ucell.atoms[0].taud[ia].y * GlobalC::ucell.lat0 * 0.529177 - * ELEC_evolve::td_val_elec_01; - dipole_ion_z += GlobalC::ucell.atoms[0].taud[ia].z * GlobalC::ucell.lat0 * 0.529177 - * ELEC_evolve::td_val_elec_01; - } - for (int ia = 0; ia < GlobalC::ucell.atoms[1].na; ia++) - { - dipole_ion_x += GlobalC::ucell.atoms[1].taud[ia].x * GlobalC::ucell.lat0 * 0.529177 - * ELEC_evolve::td_val_elec_02; - dipole_ion_y += GlobalC::ucell.atoms[1].taud[ia].y * GlobalC::ucell.lat0 * 0.529177 - * ELEC_evolve::td_val_elec_02; - dipole_ion_z += GlobalC::ucell.atoms[1].taud[ia].z * GlobalC::ucell.lat0 * 0.529177 - * ELEC_evolve::td_val_elec_02; - } - } - else if (GlobalC::ucell.ntype == 3) + for (int i = 0; i < 3; ++i) + { + for (int it = 0; it < GlobalC::ucell.ntype; ++it) { - for (int ia = 0; ia < GlobalC::ucell.atoms[0].na; ia++) - { - dipole_ion_x += GlobalC::ucell.atoms[0].taud[ia].x * GlobalC::ucell.lat0 * 0.529177 - * ELEC_evolve::td_val_elec_01; - dipole_ion_y += GlobalC::ucell.atoms[0].taud[ia].y * GlobalC::ucell.lat0 * 0.529177 - * ELEC_evolve::td_val_elec_01; - dipole_ion_z += GlobalC::ucell.atoms[0].taud[ia].z * GlobalC::ucell.lat0 * 0.529177 - * ELEC_evolve::td_val_elec_01; - } - for (int ia = 0; ia < GlobalC::ucell.atoms[1].na; ia++) - { - dipole_ion_x += GlobalC::ucell.atoms[1].taud[ia].x * GlobalC::ucell.lat0 * 0.529177 - * ELEC_evolve::td_val_elec_02; - dipole_ion_y += GlobalC::ucell.atoms[1].taud[ia].y * GlobalC::ucell.lat0 * 0.529177 - * ELEC_evolve::td_val_elec_02; - dipole_ion_z += GlobalC::ucell.atoms[1].taud[ia].z * GlobalC::ucell.lat0 * 0.529177 - * ELEC_evolve::td_val_elec_02; - } - for (int ia = 0; ia < GlobalC::ucell.atoms[2].na; ia++) + double sum = 0; + for (int ia = 0; ia < GlobalC::ucell.atoms[it].na; ++ia) { - dipole_ion_x += GlobalC::ucell.atoms[2].taud[ia].x * GlobalC::ucell.lat0 * 0.529177 - * ELEC_evolve::td_val_elec_03; - dipole_ion_y += GlobalC::ucell.atoms[2].taud[ia].y * GlobalC::ucell.lat0 * 0.529177 - * ELEC_evolve::td_val_elec_03; - dipole_ion_z += GlobalC::ucell.atoms[2].taud[ia].z * GlobalC::ucell.lat0 * 0.529177 - * ELEC_evolve::td_val_elec_03; + + sum += GlobalC::ucell.atoms[it].taud[ia][i]; } + dipole_ion[i] += sum * GlobalC::ucell.atoms[it].ncpp.zv; } - else - { - std::cout << "atom ntype is too large!" << std::endl; - } - for(int it=1; it<(GlobalC::ucell.ntype); it++) - { - for(int ia=0; ia None: + self.dipolefile = dipolefile + self._indices, self.dipole_x, self.dipole_y, self.dipole_z = self.read( + self.dipolefile) + self.dt = dt # in fs + self.time = self._indices*dt + self.energies = Freq2eV*self._indices/dt/len(self._indices) + + @classmethod + def read(cls, filename: PathLike): + """Read dipole data file + + :params filename: string of dipole data file + """ + + data = np.loadtxt(filename, dtype=float) + indices = data[:, 0] + x = data[:, 1] + y = data[:, 2] + z = data[:, 3] + + return indices, x, y, z + + @property + def dipole_data(self): + return {0: self.dipole_x, 1: self.dipole_y, 2: self.dipole_z} + + def plot_dipole(self, fig: Figure, ax: axes.Axes, directions: list = [0, 1, 2], time_range: list = []): + """Plot dipole data in x,y,z directions + + :params fig: (matplotlib.figure.Figure) + :params ax: (matplotlib.axes.Axes) + :params directions: (list) 0->X, 1->Y, 2->Z + :params time_range: (list) range of time (in unit fs) to plot + """ + + labels = {0: 'X', 1: 'Y', 2: 'Z'} + + for direc in directions: + ax.plot(self.time, self.dipole_data[direc], label=labels[direc]) + + ax.set_xlabel('Times (fs)') + ax.set_ylabel('Dipole') + ax.legend() + if time_range: + ax.set_xlim(time_range) + + return fig, ax + + @property + def alpha_x(self): + return np.fft.fft(self.dipole_x) + + @property + def alpha_y(self): + return np.fft.fft(self.dipole_y) + + @property + def alpha_z(self): + return np.fft.fft(self.dipole_z) + + @property + def alpha_data(self): + return {0: self.alpha_x, 1: self.alpha_y, 2: self.alpha_z} + + def get_abs(self, direc: int): + S = np.abs(self.alpha_data[direc].imag) + return S + + def plot_abs(self, fig: Figure, ax: axes.Axes, directions: list = [0, 1, 2], x_range: list = [], unit: str = 'eV'): + """Plot Absportion Spectrum under Delta light field in x,y,z directions + + :params fig: (matplotlib.figure.Figure) + :params ax: (matplotlib.axes.Axes) + :params directions: (list) 0->X, 1->Y, 2->Z + :params x_range: (list) range of energies (in unit eV) to plot + :params unit: (str) + """ + + assert unit in ['eV', 'nm'] + labels = {0: 'X', 1: 'Y', 2: 'Z'} + x_data = self.energies if unit == 'eV' else sc.nu2lambda( + sc.eV/sc.h*self.energies)*1e9 + + for direc in directions: + ax.plot(x_data, self.get_abs(direc), label=labels[direc]) + + xlabel = 'Energy (eV)' if unit == 'eV' else 'Wave Length (nm)' + ax.set_xlabel(xlabel) + ax.set_ylabel('Absportion') + ax.legend() + if x_range: + ax.set_xlim(x_range) + + return fig, ax + + +if __name__ == "__main__": + dipolefile = './SPIN1_DIPOLE' + dipole = Dipole(dipolefile, dt=0.0034) + + import matplotlib.pyplot as plt + fig1, ax1 = plt.subplots() + fig1, ax1 = dipole.plot_dipole(fig1, ax1) + fig1.savefig('dipole.png') + + fig2, ax2 = plt.subplots() + x_range = [0, 400] + fig2, ax2 = dipole.plot_abs( + fig2, ax2, x_range=x_range, unit='nm') + fig2.savefig('abs.png') diff --git a/tools/plot-tools/abacus_plot/utils.py b/tools/plot-tools/abacus_plot/utils.py index 7fd3679f1c..55d6ec6804 100644 --- a/tools/plot-tools/abacus_plot/utils.py +++ b/tools/plot-tools/abacus_plot/utils.py @@ -22,6 +22,7 @@ def remove_empty(a: list) -> list: while [] in a: a.remove([]) + def handle_data(data): data.remove('') @@ -31,6 +32,7 @@ def handle_elem(elem): return elist return list(map(handle_elem, data)) + def skip_notes(line: str) -> str: """Delete comments lines with '#' or '//' @@ -332,9 +334,10 @@ def parse_projected_data(orbitals, species: Union[Sequence[Any], Dict[Any, List[ return data, totnum + def key2int(species): """Convert keys of dict in str type to int""" - + new_species = {} if isinstance(species, dict): elements = list(map(int, species.keys())) @@ -352,5 +355,5 @@ def key2int(species): new_species[elem] = [] for l_index in l[i]: new_species[elem].append(int(l_index)) - - return new_species \ No newline at end of file + + return new_species From 6ad349318d70600ce18499ff285a4cda4fdb0664 Mon Sep 17 00:00:00 2001 From: HTZhao <104255052+ESROAMER@users.noreply.github.com> Date: Wed, 19 Apr 2023 14:37:58 +0800 Subject: [PATCH 02/48] New propagator for better Convergence (#2253) * New propagator for better Convergence * Add files via upload * Add files via upload * Modified the code's implementation approach. I have modified the implementation approach of the code, and this one involves less changes to the original code. It also includes handling for multiple k-points. * Delete module_esolver directory * Delete module_hamilt_general directory * Delete module_hamilt_lcao directory * Add files via upload --- .../module_esolver/esolver_ks_lcao_tddft.cpp | 21 +++++++- source/module_esolver/esolver_ks_lcao_tddft.h | 1 + .../module_tddft/ELEC_evolve.cpp | 3 +- .../module_tddft/ELEC_evolve.h | 1 + .../module_tddft/LCAO_evolve.cpp | 50 ++++++++++++++++++- .../module_tddft/LCAO_evolve.h | 2 + 6 files changed, 73 insertions(+), 5 deletions(-) diff --git a/source/module_esolver/esolver_ks_lcao_tddft.cpp b/source/module_esolver/esolver_ks_lcao_tddft.cpp index 1899cb9dfd..4276cb5fb3 100644 --- a/source/module_esolver/esolver_ks_lcao_tddft.cpp +++ b/source/module_esolver/esolver_ks_lcao_tddft.cpp @@ -41,6 +41,9 @@ ESolver_KS_LCAO_TDDFT::~ESolver_KS_LCAO_TDDFT() { // this->orb_con.clear_after_ions(GlobalC::UOT, GlobalC::ORB, GlobalV::deepks_setorb, GlobalC::ucell.infoNL.nproj); delete psi_laststep; + for(int ik = 0; ik < GlobalC::kv.nks; ++ik){ + delete Hk_laststep[ik];} + delete Hk_laststep; } void ESolver_KS_LCAO_TDDFT::Init(Input& inp, UnitCell& ucell) @@ -188,7 +191,7 @@ void ESolver_KS_LCAO_TDDFT::hamilt2density(int istep, int iter, double ethr) if (GlobalV::ESOLVER_TYPE == "tddft" && istep >= 2 && !GlobalV::GAMMA_ONLY_LOCAL) { - ELEC_evolve::evolve_psi(istep, this->p_hamilt, this->LOWF, this->psi, this->psi_laststep, this->pelec_td->ekb); + ELEC_evolve::evolve_psi(istep, this->p_hamilt, this->LOWF, this->psi, this->psi_laststep, this->Hk_laststep, this->pelec_td->ekb); this->pelec_td->psiToRho_td(this->psi[0]); // this->pelec_td->psiToRho(this->psi[0]); } @@ -351,7 +354,7 @@ void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) GlobalC::en.cal_converged(this->pelec); } - // store wfc + // store wfc and Hk laststep if (istep >= 1 && this->conv_elec) { if (this->psi_laststep == nullptr) @@ -364,6 +367,13 @@ void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) this->psi_laststep = new psi::Psi>(GlobalC::kv.nks, GlobalV::NBANDS, GlobalV::NLOCAL, nullptr); #endif + if (this->Hk_laststep == nullptr){ + this->Hk_laststep = new std::complex*[GlobalC::kv.nks]; + for(int ik = 0; ik < GlobalC::kv.nks; ++ik){ + this->Hk_laststep[ik] = new std::complex[this->LOC.ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(Hk_laststep[ik], this->LOC.ParaV->nloc); + } + } for (int ik = 0; ik < GlobalC::kv.nks; ++ik) { @@ -372,8 +382,15 @@ void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) int size0 = psi->get_nbands() * psi->get_nbasis(); for (int index = 0; index < size0; ++index) psi_laststep[0].get_pointer()[index] = psi[0].get_pointer()[index]; + //use for new propagator + this->p_hamilt->updateHk(ik); + //store Hk laststep + hamilt::MatrixBlock> h_mat, s_mat; + this->p_hamilt->matrix(h_mat, s_mat); + BlasConnector::copy(this->LOC.ParaV->nloc, h_mat.p, 1, Hk_laststep[ik], 1); } + if (istep > 1 && ELEC_evolve::td_edm == 0) this->cal_edm_tddft(); } diff --git a/source/module_esolver/esolver_ks_lcao_tddft.h b/source/module_esolver/esolver_ks_lcao_tddft.h index a943cebe5a..6f9da4a185 100644 --- a/source/module_esolver/esolver_ks_lcao_tddft.h +++ b/source/module_esolver/esolver_ks_lcao_tddft.h @@ -22,6 +22,7 @@ class ESolver_KS_LCAO_TDDFT : public ESolver_KS_LCAO void Init(Input& inp, UnitCell& cell) override; psi::Psi>* psi_laststep = nullptr; + std::complex** Hk_laststep = nullptr; //same as pelec elecstate::ElecStateLCAO_TDDFT* pelec_td = nullptr; diff --git a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp b/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp index 66a8fcb1a7..3cfdd30b1d 100644 --- a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp +++ b/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp @@ -25,6 +25,7 @@ void ELEC_evolve::evolve_psi(const int& istep, Local_Orbital_wfc& lowf, psi::Psi>* psi, psi::Psi>* psi_laststep, + std::complex** Hk_laststep, ModuleBase::matrix& ekb) { ModuleBase::TITLE("ELEC_evolve", "eveolve_psi"); @@ -39,7 +40,7 @@ void ELEC_evolve::evolve_psi(const int& istep, Evolve_LCAO_Matrix ELM(lowf.ParaV); psi->fix_k(ik); psi_laststep->fix_k(ik); - ELM.evolve_complex_matrix(ik, phm, psi, psi_laststep, &(ekb(ik, 0))); + ELM.evolve_complex_matrix(ik, phm, psi, psi_laststep, Hk_laststep[ik], &(ekb(ik, 0))); ModuleBase::timer::tick("Efficience", "evolve_k"); } // end k diff --git a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.h b/source/module_hamilt_lcao/module_tddft/ELEC_evolve.h index 6571e72033..eb647b83c3 100644 --- a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.h +++ b/source/module_hamilt_lcao/module_tddft/ELEC_evolve.h @@ -44,6 +44,7 @@ class ELEC_evolve Local_Orbital_wfc& lowf, psi::Psi>* psi, psi::Psi>* psi_laststep, + std::complex** Hk_laststep, ModuleBase::matrix& ekb); }; diff --git a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp b/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp index 66325ee7cf..49b190f6af 100644 --- a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp +++ b/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp @@ -27,6 +27,7 @@ void Evolve_LCAO_Matrix::evolve_complex_matrix(const int& ik, hamilt::Hamilt* p_hamilt, psi::Psi>* psi_k, psi::Psi>* psi_k_laststep, + std::complex* Hk_laststep, double* ekb) const { ModuleBase::TITLE("Evolve_LCAO_Matrix", "evolve_complex_matrix"); @@ -36,7 +37,7 @@ void Evolve_LCAO_Matrix::evolve_complex_matrix(const int& ik, if (GlobalV::ESOLVER_TYPE == "tddft") { #ifdef __MPI - this->using_ScaLAPACK_complex(GlobalV::NBANDS, GlobalV::NLOCAL, psi_k_laststep[0].get_pointer(), p_hamilt, psi_k[0].get_pointer(), ekb); + this->using_ScaLAPACK_complex(GlobalV::NBANDS, GlobalV::NLOCAL, psi_k_laststep[0].get_pointer(), Hk_laststep, p_hamilt, psi_k[0].get_pointer(), ekb); #else this->using_LAPACK_complex(ik, p_hamilt, psi_k[0].get_pointer(), psi_k_laststep[0].get_pointer(), ekb); #endif @@ -344,6 +345,7 @@ void Evolve_LCAO_Matrix::using_ScaLAPACK_complex( const int nband, const int nlocal, const std::complex* psi_k_laststep, + const std::complex* Hk_laststep, hamilt::Hamilt* p_hamilt, std::complex* psi_k, double* ekb) const @@ -361,7 +363,51 @@ void Evolve_LCAO_Matrix::using_ScaLAPACK_complex( complex* Htmp = new complex[this->ParaV->nloc]; ModuleBase::GlobalFunc::ZEROS(Htmp, this->ParaV->nloc); BlasConnector::copy(this->ParaV->nloc, h_mat.p, 1, Htmp, 1); - + + //print test + /*GlobalV::ofs_running << " H(t) matrix :" << endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Hk_laststep[i * this->ParaV->ncol + j].real() << "+" << Hk_laststep[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << endl;} + GlobalV::ofs_running << " H(t+dt) matrix :" << endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Htmp[i * this->ParaV->ncol + j].real() << "+" << Htmp[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << endl;} + // +*/ + + complex mixing = {0.5, 0.0}; + ScalapackConnector::geadd( + 'N', + nlocal, + nlocal, + mixing, + Hk_laststep, + 1, + 1, + this->ParaV->desc, + mixing, + Htmp, + 1, + 1, + this->ParaV->desc + ); + /*GlobalV::ofs_running << " H(t+dt/2) matrix :" << endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Htmp[i * this->ParaV->ncol + j].real() << "+" << Htmp[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << endl;}*/ complex* U_operator = new complex[this->ParaV->nloc]; ModuleBase::GlobalFunc::ZEROS(U_operator, this->ParaV->nloc); diff --git a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h b/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h index dd13e45e2f..1f1f4e1fc0 100644 --- a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h +++ b/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h @@ -22,6 +22,7 @@ class Evolve_LCAO_Matrix hamilt::Hamilt* p_hamilt, psi::Psi>* psi_k, psi::Psi>* psi_k_laststep, + std::complex* Hk_laststep, double* ekb) const; private: @@ -38,6 +39,7 @@ class Evolve_LCAO_Matrix const int nband, const int nlocal, const std::complex* psi_k_laststep, + const std::complex* Hk_laststep, hamilt::Hamilt* p_hamilt, std::complex* psi_k, double* ekb) const; From ea9f4fd28d6e657e0f0e227627b50be424113d02 Mon Sep 17 00:00:00 2001 From: Omega <62006565+Satinelamp@users.noreply.github.com> Date: Fri, 21 Apr 2023 12:42:30 +0800 Subject: [PATCH 03/48] Update dipole.py (#2270) --- tools/plot-tools/abacus_plot/dipole.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/plot-tools/abacus_plot/dipole.py b/tools/plot-tools/abacus_plot/dipole.py index ea9e7609f9..f8543909b3 100644 --- a/tools/plot-tools/abacus_plot/dipole.py +++ b/tools/plot-tools/abacus_plot/dipole.py @@ -93,9 +93,15 @@ def plot_abs(self, fig: Figure, ax: axes.Axes, directions: list = [0, 1, 2], x_r labels = {0: 'X', 1: 'Y', 2: 'Z'} x_data = self.energies if unit == 'eV' else sc.nu2lambda( sc.eV/sc.h*self.energies)*1e9 - + + #plot the adsorption spectra and output the data + adsorption_spectra_data = x_data[:, np.newaxis] for direc in directions: ax.plot(x_data, self.get_abs(direc), label=labels[direc]) + adsorption_spectra_data = np.concatenate((adsorption_spectra_data, self.get_abs(direc)[:, np.newaxis]),axis=1) + if direc != directions[-1]: + adsorption_spectra_data = np.concatenate((adsorption_spectra_data, x_data[:, np.newaxis]),axis=1) + np.savetxt('absorpation_spectra.dat', adsorption_spectra_data) xlabel = 'Energy (eV)' if unit == 'eV' else 'Wave Length (nm)' ax.set_xlabel(xlabel) From 21991715d57e18dc0679497de8ac96fec09865a5 Mon Sep 17 00:00:00 2001 From: lyb9812 <88070104+lyb9812@users.noreply.github.com> Date: Sun, 23 Apr 2023 14:04:13 +0800 Subject: [PATCH 04/48] Simplify matrix multiplication and add new propagator method (#2272) * Add the dipole and spectrum post-processing script. (#1928) * Add the Dipole and post-processing script necessary to calculate the spectrum using TDDFT. * fix td_val test bug. * Fix: bug in parsing strings mixed with " ", "\t" (#1951) * Use template to reconstruct parse_expression * Feature: output R matrix at each MD step * Modify'matrix_HS' to 'matrix' for R matrix output * Merge branches 'develop' and 'develop' of https://github.com/1041176461/abacus-develop into develop * Fix: modify index in parse_expression * Fix: bug in parsing strings mixed with " ", "\t" --------- Co-authored-by: jiyuang * solve conflicts * solve conflicts * solve conflicts * solve conflicts * solve conflicts * Fix : bug of multi-kpoint for tddft (#2023) * fix bug of electric field in tddft * fix bug of dipole and electric field * fix bug of multi-kpoint for tddft * unit conversion of out_efield * delete useless paramters for tddft (td_val_elec*) * delete useless parameters for tddft * pack all changes in tddft * solve conflicts * delete td_val * simplify matrix multiplication and update new propagator for tddft * add autotests for new propagator * fix bug of ekb in tddft * delete temp output * update ref of new propagator * update CASES --------- Co-authored-by: HeFuxiang94 <78629482+HeFuxiang94@users.noreply.github.com> Co-authored-by: jiyuyang <1041176461@qq.com> Co-authored-by: jiyuang Co-authored-by: Qianrui <76200646+Qianruipku@users.noreply.github.com> --- docs/advanced/input_files/input-main.md | 21 + .../module_esolver/esolver_ks_lcao_tddft.cpp | 92 +- .../module_tddft/ELEC_evolve.cpp | 21 +- .../module_tddft/ELEC_evolve.h | 4 +- .../module_tddft/LCAO_evolve.cpp | 1122 ++++++++++++----- .../module_tddft/LCAO_evolve.h | 41 +- source/module_io/input.cpp | 13 + source/module_io/input.h | 3 + source/module_io/test/input_test.cpp | 4 + source/module_io/test/input_test_para.cpp | 2 + source/module_io/test/support/INPUT | 2 + source/module_io/test/support/witestfile | 2 + tests/integrate/601_NO_TDDFT_H2_etrs/INPUT | 35 + tests/integrate/601_NO_TDDFT_H2_etrs/KPT | 4 + tests/integrate/601_NO_TDDFT_H2_etrs/STRU | 22 + .../integrate/601_NO_TDDFT_H2_etrs/result.ref | 5 + tests/integrate/601_NO_TDDFT_H2_halfH/INPUT | 36 + tests/integrate/601_NO_TDDFT_H2_halfH/KPT | 4 + tests/integrate/601_NO_TDDFT_H2_halfH/STRU | 22 + .../601_NO_TDDFT_H2_halfH/result.ref | 5 + tests/integrate/601_NO_TDDFT_H2_taylor/INPUT | 36 + tests/integrate/601_NO_TDDFT_H2_taylor/KPT | 4 + tests/integrate/601_NO_TDDFT_H2_taylor/STRU | 22 + .../601_NO_TDDFT_H2_taylor/result.ref | 5 + tests/integrate/CASES | 5 +- 25 files changed, 1136 insertions(+), 396 deletions(-) create mode 100755 tests/integrate/601_NO_TDDFT_H2_etrs/INPUT create mode 100755 tests/integrate/601_NO_TDDFT_H2_etrs/KPT create mode 100755 tests/integrate/601_NO_TDDFT_H2_etrs/STRU create mode 100644 tests/integrate/601_NO_TDDFT_H2_etrs/result.ref create mode 100755 tests/integrate/601_NO_TDDFT_H2_halfH/INPUT create mode 100755 tests/integrate/601_NO_TDDFT_H2_halfH/KPT create mode 100755 tests/integrate/601_NO_TDDFT_H2_halfH/STRU create mode 100644 tests/integrate/601_NO_TDDFT_H2_halfH/result.ref create mode 100755 tests/integrate/601_NO_TDDFT_H2_taylor/INPUT create mode 100755 tests/integrate/601_NO_TDDFT_H2_taylor/KPT create mode 100755 tests/integrate/601_NO_TDDFT_H2_taylor/STRU create mode 100644 tests/integrate/601_NO_TDDFT_H2_taylor/result.ref diff --git a/docs/advanced/input_files/input-main.md b/docs/advanced/input_files/input-main.md index d0430de33c..743698459d 100644 --- a/docs/advanced/input_files/input-main.md +++ b/docs/advanced/input_files/input-main.md @@ -282,6 +282,8 @@ - [td\_edm](#td_edm) - [td\_print\_eij](#td_print_eij) - [td\_force\_dt](#td_force_dt) + - [td\_htype](#td_htype) + - [propagator](#propagator) - [td\_vext](#td_vext) - [td\_vext\_dire](#td_vext_dire) - [td\_stype](#td_stype) @@ -2321,6 +2323,25 @@ These variables are used to control berry phase and wannier90 interface paramete - **Description**: Time-dependent evolution force changes time step. (fs) - **Default**: 0.02 +### td_htype + +- **Type**: Integer +- **Description**: + type of Hamiltonian to calculate propagator (for propagator = 0 or 1). + - 0: H(t+dt). + - 1: H(t+dt/2). +- **Default**: 0 + +### propagator + +- **Type**: Integer +- **Description**: + method of propagator. + - 0: Crank-Nicolson. + - 1: 4th Taylor expansions of exponential. + - 2: enforced time-reversal symmetry (ETRS). +- **Default**: 0 + ### td_vext - **Type**: Boolean diff --git a/source/module_esolver/esolver_ks_lcao_tddft.cpp b/source/module_esolver/esolver_ks_lcao_tddft.cpp index 4276cb5fb3..7e4f9ad8d0 100644 --- a/source/module_esolver/esolver_ks_lcao_tddft.cpp +++ b/source/module_esolver/esolver_ks_lcao_tddft.cpp @@ -1,11 +1,11 @@ #include "esolver_ks_lcao_tddft.h" #include "module_io/cal_r_overlap_R.h" +#include "module_io/dipole_io.h" #include "module_io/dm_io.h" #include "module_io/rho_io.h" -#include "module_io/dipole_io.h" -#include "module_io/write_HS_R.h" #include "module_io/write_HS.h" +#include "module_io/write_HS_R.h" //--------------temporary---------------------------- #include "module_base/blas_connector.h" @@ -41,9 +41,14 @@ ESolver_KS_LCAO_TDDFT::~ESolver_KS_LCAO_TDDFT() { // this->orb_con.clear_after_ions(GlobalC::UOT, GlobalC::ORB, GlobalV::deepks_setorb, GlobalC::ucell.infoNL.nproj); delete psi_laststep; - for(int ik = 0; ik < GlobalC::kv.nks; ++ik){ - delete Hk_laststep[ik];} + if (Hk_laststep != nullptr) + { + for (int ik = 0; ik < GlobalC::kv.nks; ++ik) + { + delete Hk_laststep[ik]; + } delete Hk_laststep; + } } void ESolver_KS_LCAO_TDDFT::Init(Input& inp, UnitCell& ucell) @@ -191,7 +196,15 @@ void ESolver_KS_LCAO_TDDFT::hamilt2density(int istep, int iter, double ethr) if (GlobalV::ESOLVER_TYPE == "tddft" && istep >= 2 && !GlobalV::GAMMA_ONLY_LOCAL) { - ELEC_evolve::evolve_psi(istep, this->p_hamilt, this->LOWF, this->psi, this->psi_laststep, this->Hk_laststep, this->pelec_td->ekb); + ELEC_evolve::evolve_psi(istep, + this->p_hamilt, + this->LOWF, + this->psi, + this->psi_laststep, + this->Hk_laststep, + this->pelec_td->ekb, + INPUT.td_htype, + INPUT.propagator); this->pelec_td->psiToRho_td(this->psi[0]); // this->pelec_td->psiToRho(this->psi[0]); } @@ -277,7 +290,7 @@ void ESolver_KS_LCAO_TDDFT::hamilt2density(int istep, int iter, double ethr) void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) { - //print Hamiltonian and Overlap matrix + // print Hamiltonian and Overlap matrix if (this->conv_elec) { if (!GlobalV::GAMMA_ONLY_LOCAL) @@ -286,7 +299,7 @@ void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) } for (int ik = 0; ik < GlobalC::kv.nks; ++ik) { - if(hsolver::HSolverLCAO::out_mat_hs) + if (hsolver::HSolverLCAO::out_mat_hs) { this->p_hamilt->updateHk(ik); } @@ -345,7 +358,8 @@ void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) if (!this->conv_elec) { - if(GlobalV::NSPIN==4) GlobalC::ucell.cal_ux(); + if (GlobalV::NSPIN == 4) + GlobalC::ucell.cal_ux(); this->pelec->pot->update_from_charge(this->pelec->charge, &GlobalC::ucell); GlobalC::en.delta_escf(this->pelec); } @@ -367,11 +381,17 @@ void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) this->psi_laststep = new psi::Psi>(GlobalC::kv.nks, GlobalV::NBANDS, GlobalV::NLOCAL, nullptr); #endif - if (this->Hk_laststep == nullptr){ - this->Hk_laststep = new std::complex*[GlobalC::kv.nks]; - for(int ik = 0; ik < GlobalC::kv.nks; ++ik){ - this->Hk_laststep[ik] = new std::complex[this->LOC.ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(Hk_laststep[ik], this->LOC.ParaV->nloc); + + if (INPUT.td_htype == 1) + { + if (this->Hk_laststep == nullptr) + { + this->Hk_laststep = new std::complex*[GlobalC::kv.nks]; + for (int ik = 0; ik < GlobalC::kv.nks; ++ik) + { + this->Hk_laststep[ik] = new std::complex[this->LOC.ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(Hk_laststep[ik], this->LOC.ParaV->nloc); + } } } @@ -382,14 +402,16 @@ void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) int size0 = psi->get_nbands() * psi->get_nbasis(); for (int index = 0; index < size0; ++index) psi_laststep[0].get_pointer()[index] = psi[0].get_pointer()[index]; - //use for new propagator - this->p_hamilt->updateHk(ik); - //store Hk laststep - hamilt::MatrixBlock> h_mat, s_mat; - this->p_hamilt->matrix(h_mat, s_mat); - BlasConnector::copy(this->LOC.ParaV->nloc, h_mat.p, 1, Hk_laststep[ik], 1); + + // store Hamiltonian + if (INPUT.td_htype == 1) + { + this->p_hamilt->updateHk(ik); + hamilt::MatrixBlock> h_mat, s_mat; + this->p_hamilt->matrix(h_mat, s_mat); + BlasConnector::copy(this->LOC.ParaV->nloc, h_mat.p, 1, Hk_laststep[ik], 1); + } } - if (istep > 1 && ELEC_evolve::td_edm == 0) this->cal_edm_tddft(); @@ -433,7 +455,7 @@ void ESolver_KS_LCAO_TDDFT::afterscf(const int istep) const int precision = 3; std::stringstream ssc; ssc << GlobalV::global_out_dir << "SPIN" << is + 1 << "_CHG.cube"; - double& ef_tmp = GlobalC::en.get_ef(is,GlobalV::TWO_EFERMI); + double& ef_tmp = GlobalC::en.get_ef(is, GlobalV::TWO_EFERMI); ModuleIO::write_rho( #ifdef __MPI GlobalC::bigpw->bz, @@ -522,7 +544,7 @@ void ESolver_KS_LCAO_TDDFT::afterscf(const int istep) std::cout << " !! CONVERGENCE HAS NOT BEEN ACHIEVED !!" << std::endl; } - if( GlobalV::CALCULATION != "md" || (istep % hsolver::HSolverLCAO::out_hsR_interval == 0)) + if (GlobalV::CALCULATION != "md" || (istep % hsolver::HSolverLCAO::out_hsR_interval == 0)) { if (hsolver::HSolverLCAO::out_mat_hsR) { @@ -552,7 +574,6 @@ void ESolver_KS_LCAO_TDDFT::afterscf(const int istep) else { r_matrix.out_rR(istep); - } } } @@ -572,14 +593,12 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() complex* tmp2 = new complex[this->LOC.ParaV->nloc]; complex* tmp3 = new complex[this->LOC.ParaV->nloc]; complex* tmp4 = new complex[this->LOC.ParaV->nloc]; - complex* tmp5 = new complex[this->LOC.ParaV->nloc]; ModuleBase::GlobalFunc::ZEROS(Htmp, this->LOC.ParaV->nloc); ModuleBase::GlobalFunc::ZEROS(Sinv, this->LOC.ParaV->nloc); ModuleBase::GlobalFunc::ZEROS(tmp1, this->LOC.ParaV->nloc); ModuleBase::GlobalFunc::ZEROS(tmp2, this->LOC.ParaV->nloc); ModuleBase::GlobalFunc::ZEROS(tmp3, this->LOC.ParaV->nloc); ModuleBase::GlobalFunc::ZEROS(tmp4, this->LOC.ParaV->nloc); - ModuleBase::GlobalFunc::ZEROS(tmp5, this->LOC.ParaV->nloc); const int inc = 1; int nrow = this->LOC.ParaV->nrow; int ncol = this->LOC.ParaV->ncol; @@ -629,8 +648,8 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() const char N_char = 'N', T_char = 'T'; const complex one_float = {1.0, 0.0}, zero_float = {0.0, 0.0}; const complex half_float = {0.5, 0.0}; - pzgemm_(&T_char, - &T_char, + pzgemm_(&N_char, + &N_char, &GlobalV::NLOCAL, &GlobalV::NLOCAL, &GlobalV::NLOCAL, @@ -670,7 +689,7 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() this->LOC.ParaV->desc); pzgemm_(&N_char, - &T_char, + &N_char, &GlobalV::NLOCAL, &GlobalV::NLOCAL, &GlobalV::NLOCAL, @@ -690,7 +709,7 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() this->LOC.ParaV->desc); pzgemm_(&N_char, - &T_char, + &N_char, &GlobalV::NLOCAL, &GlobalV::NLOCAL, &GlobalV::NLOCAL, @@ -723,19 +742,7 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() &one_int, this->LOC.ParaV->desc); - pztranu_(&GlobalV::NLOCAL, - &GlobalV::NLOCAL, - &one_float, - tmp4, - &one_int, - &one_int, - this->LOC.ParaV->desc, - &zero_float, - tmp5, - &one_int, - &one_int, - this->LOC.ParaV->desc); - zcopy_(&this->LOC.ParaV->nloc, tmp5, &inc, this->LOC.edm_k_tddft[ik].c, &inc); + zcopy_(&this->LOC.ParaV->nloc, tmp4, &inc, this->LOC.edm_k_tddft[ik].c, &inc); delete[] Htmp; delete[] Sinv; @@ -743,7 +750,6 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() delete[] tmp2; delete[] tmp3; delete[] tmp4; - delete[] tmp5; delete[] ipiv; #else this->LOC.edm_k_tddft[ik].create(this->LOC.ParaV->ncol, this->LOC.ParaV->nrow); diff --git a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp b/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp index 3cfdd30b1d..4b37b54197 100644 --- a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp +++ b/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp @@ -1,12 +1,12 @@ #include "ELEC_evolve.h" -#include "module_base/timer.h" +#include "LCAO_evolve.h" #include "module_base/parallel_reduce.h" -#include "module_hamilt_pw/hamilt_pwdft/global.h" +#include "module_base/timer.h" #include "module_elecstate/module_charge/symmetry_rho.h" -#include "LCAO_evolve.h" -#include "module_hamilt_lcao/module_dftu/dftu.h" #include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" +#include "module_hamilt_lcao/module_dftu/dftu.h" +#include "module_hamilt_pw/hamilt_pwdft/global.h" ELEC_evolve::ELEC_evolve(){}; ELEC_evolve::~ELEC_evolve(){}; @@ -26,7 +26,9 @@ void ELEC_evolve::evolve_psi(const int& istep, psi::Psi>* psi, psi::Psi>* psi_laststep, std::complex** Hk_laststep, - ModuleBase::matrix& ekb) + ModuleBase::matrix& ekb, + int htype, + int propagator) { ModuleBase::TITLE("ELEC_evolve", "eveolve_psi"); ModuleBase::timer::tick("ELEC_evolve", "evolve_psi"); @@ -40,7 +42,14 @@ void ELEC_evolve::evolve_psi(const int& istep, Evolve_LCAO_Matrix ELM(lowf.ParaV); psi->fix_k(ik); psi_laststep->fix_k(ik); - ELM.evolve_complex_matrix(ik, phm, psi, psi_laststep, Hk_laststep[ik], &(ekb(ik, 0))); + if (Hk_laststep == nullptr) + { + ELM.evolve_complex_matrix(ik, phm, psi, psi_laststep, nullptr, &(ekb(ik, 0)), htype, propagator); + } + else + { + ELM.evolve_complex_matrix(ik, phm, psi, psi_laststep, Hk_laststep[ik], &(ekb(ik, 0)), htype, propagator); + } ModuleBase::timer::tick("Efficience", "evolve_k"); } // end k diff --git a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.h b/source/module_hamilt_lcao/module_tddft/ELEC_evolve.h index eb647b83c3..dfa2b904eb 100644 --- a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.h +++ b/source/module_hamilt_lcao/module_tddft/ELEC_evolve.h @@ -45,7 +45,9 @@ class ELEC_evolve psi::Psi>* psi, psi::Psi>* psi_laststep, std::complex** Hk_laststep, - ModuleBase::matrix& ekb); + ModuleBase::matrix& ekb, + int htype, + int propagator); }; #endif diff --git a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp b/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp index 49b190f6af..cd7649f536 100644 --- a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp +++ b/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp @@ -1,12 +1,12 @@ #include "LCAO_evolve.h" -#include "module_io/input.h" -#include "module_base/scalapack_connector.h" -#include "module_base/lapack_connector.h" -#include "module_io/write_HS.h" -#include "module_hamilt_pw/hamilt_pwdft/global.h" #include "ELEC_evolve.h" +#include "module_base/lapack_connector.h" +#include "module_base/scalapack_connector.h" #include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" +#include "module_hamilt_pw/hamilt_pwdft/global.h" +#include "module_io/input.h" +#include "module_io/write_HS.h" #include // fuxiang add 2016-10-28 @@ -27,8 +27,10 @@ void Evolve_LCAO_Matrix::evolve_complex_matrix(const int& ik, hamilt::Hamilt* p_hamilt, psi::Psi>* psi_k, psi::Psi>* psi_k_laststep, - std::complex* Hk_laststep, - double* ekb) const + std::complex* H_laststep, + double* ekb, + int htype, + int propagator) const { ModuleBase::TITLE("Evolve_LCAO_Matrix", "evolve_complex_matrix"); time_t time_start = time(NULL); @@ -37,7 +39,15 @@ void Evolve_LCAO_Matrix::evolve_complex_matrix(const int& ik, if (GlobalV::ESOLVER_TYPE == "tddft") { #ifdef __MPI - this->using_ScaLAPACK_complex(GlobalV::NBANDS, GlobalV::NLOCAL, psi_k_laststep[0].get_pointer(), Hk_laststep, p_hamilt, psi_k[0].get_pointer(), ekb); + this->using_ScaLAPACK_complex(GlobalV::NBANDS, + GlobalV::NLOCAL, + psi_k_laststep[0].get_pointer(), + H_laststep, + p_hamilt, + psi_k[0].get_pointer(), + ekb, + htype, + propagator); #else this->using_LAPACK_complex(ik, p_hamilt, psi_k[0].get_pointer(), psi_k_laststep[0].get_pointer(), ekb); #endif @@ -341,14 +351,15 @@ void Evolve_LCAO_Matrix::using_LAPACK_complex(const int& ik, #ifdef __MPI -void Evolve_LCAO_Matrix::using_ScaLAPACK_complex( - const int nband, - const int nlocal, - const std::complex* psi_k_laststep, - const std::complex* Hk_laststep, - hamilt::Hamilt* p_hamilt, - std::complex* psi_k, - double* ekb) const +void Evolve_LCAO_Matrix::using_ScaLAPACK_complex(const int nband, + const int nlocal, + const std::complex* psi_k_laststep, + const std::complex* H_laststep, + hamilt::Hamilt* p_hamilt, + std::complex* psi_k, + double* ekb, + int htype, + int propagator) const { ModuleBase::TITLE("Evolve_LCAO_Matrix", "using_ScaLAPACK_complex"); @@ -364,83 +375,68 @@ void Evolve_LCAO_Matrix::using_ScaLAPACK_complex( ModuleBase::GlobalFunc::ZEROS(Htmp, this->ParaV->nloc); BlasConnector::copy(this->ParaV->nloc, h_mat.p, 1, Htmp, 1); - //print test - /*GlobalV::ofs_running << " H(t) matrix :" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - GlobalV::ofs_running << Hk_laststep[i * this->ParaV->ncol + j].real() << "+" << Hk_laststep[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl;} - GlobalV::ofs_running << " H(t+dt) matrix :" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - GlobalV::ofs_running << Htmp[i * this->ParaV->ncol + j].real() << "+" << Htmp[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl;} - // -*/ - - complex mixing = {0.5, 0.0}; - ScalapackConnector::geadd( - 'N', - nlocal, - nlocal, - mixing, - Hk_laststep, - 1, - 1, - this->ParaV->desc, - mixing, - Htmp, - 1, - 1, - this->ParaV->desc - ); - /*GlobalV::ofs_running << " H(t+dt/2) matrix :" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - GlobalV::ofs_running << Htmp[i * this->ParaV->ncol + j].real() << "+" << Htmp[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl;}*/ + complex* Hold = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(Hold, this->ParaV->nloc); + BlasConnector::copy(this->ParaV->nloc, h_mat.p, 1, Hold, 1); + complex* U_operator = new complex[this->ParaV->nloc]; ModuleBase::GlobalFunc::ZEROS(U_operator, this->ParaV->nloc); -// (1)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + // (1)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + /// @brief compute H(t+dt/2) + /// @input H_laststep, Htmp, print_matrix + /// @output Htmp + if (htype == 1 && propagator!=2) + { + half_Hmatrix(nband, nlocal, Htmp, H_laststep, print_matrix); + } + + // (2)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> /// @brief compute U_operator /// @input Stmp, Htmp, print_matrix /// @output U_operator - compute_U_operator(nband, nlocal, Stmp, Htmp, U_operator, print_matrix); + switch (propagator) + { + case 0: + compute_U_operator_CN2(nband, nlocal, Stmp, Htmp, U_operator, print_matrix); + break; + + case 1: + compute_U_operator_taylor(nband, nlocal, Stmp, Htmp, U_operator, print_matrix); + break; + + case 2: + compute_U_operator_etrs(nband, nlocal, Stmp, Htmp, H_laststep, U_operator, print_matrix); + + break; -// (2)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + default: + std::cout << "method of propagator is wrong" << endl; + break; + } + + // (3)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> /// @brief apply U_operator to the wave function of the previous step for new wave function - /// @input U_operator, psi_k_laststep + /// @input U_operator, psi_k_laststep, print_matrix /// @output psi_k - U_to_wfc(nband, nlocal, U_operator, psi_k_laststep, psi_k); - - + U_to_wfc(nband, nlocal, U_operator, psi_k_laststep, psi_k, print_matrix); -// (3)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + // (4)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> /// @brief normalize psi_k /// @input Stmp, psi_not_norm, psi_k, print_matrix /// @output psi_k norm_wfc(nband, nlocal, Stmp, psi_k, print_matrix); + // (5)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -// (4)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - /// @brief compute ekb /// @input Htmp, psi_k /// @output ekb - compute_ekb(nband, nlocal, Htmp, psi_k, ekb); + compute_ekb(nband, nlocal, Hold, psi_k, ekb); delete[] Stmp; delete[] Htmp; @@ -448,14 +444,80 @@ void Evolve_LCAO_Matrix::using_ScaLAPACK_complex( return; } +void Evolve_LCAO_Matrix::half_Hmatrix(const int nband, + const int nlocal, + std::complex* Htmp, + const std::complex* H_laststep, + const int print_matrix) const +{ + if (print_matrix) + { + GlobalV::ofs_running << std::setprecision(10); + GlobalV::ofs_running << endl; + GlobalV::ofs_running << " H(t+dt) :" << endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Htmp[i * this->ParaV->ncol + j].real() << "+" + << Htmp[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << endl; + } + GlobalV::ofs_running << endl; + GlobalV::ofs_running << endl; + GlobalV::ofs_running << " H(t):" << endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << H_laststep[i * this->ParaV->ncol + j].real() << "+" + << H_laststep[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << endl; + } + GlobalV::ofs_running << endl; + } + + complex alpha = {0.5, 0.0}; + complex beta = {0.5, 0.0}; + ScalapackConnector::geadd('N', + nlocal, + nlocal, + alpha, + H_laststep, + 1, + 1, + this->ParaV->desc, + beta, + Htmp, + 1, + 1, + this->ParaV->desc); -void Evolve_LCAO_Matrix::compute_U_operator( - const int nband, - const int nlocal, - const std::complex* Stmp, - const std::complex* Htmp, - std::complex* U_operator, - const int print_matrix) const + if (print_matrix) + { + GlobalV::ofs_running << endl; + GlobalV::ofs_running << " H (t+dt/2) :" << endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Htmp[i * this->ParaV->ncol + j].real() << "+" + << Htmp[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << endl; + } + GlobalV::ofs_running << endl; + } +} + +void Evolve_LCAO_Matrix::compute_U_operator_CN2(const int nband, + const int nlocal, + const std::complex* Stmp, + const std::complex* Htmp, + std::complex* U_operator, + const int print_matrix) const { // (1) copy Htmp to Numerator & Denominator complex* Numerator = new complex[this->ParaV->nloc]; @@ -474,7 +536,8 @@ void Evolve_LCAO_Matrix::compute_U_operator( { for (int j = 0; j < this->ParaV->ncol; j++) { - GlobalV::ofs_running << Stmp[i * this->ParaV->ncol + j].real() << "+" << Stmp[i * this->ParaV->ncol + j].imag() << "i "; + GlobalV::ofs_running << Stmp[i * this->ParaV->ncol + j].real() << "+" + << Stmp[i * this->ParaV->ncol + j].imag() << "i "; } GlobalV::ofs_running << endl; } @@ -485,14 +548,15 @@ void Evolve_LCAO_Matrix::compute_U_operator( { for (int j = 0; j < this->ParaV->ncol; j++) { - GlobalV::ofs_running << Numerator[i * this->ParaV->ncol + j].real() << "+" << Numerator[i * this->ParaV->ncol + j].imag() << "i "; + GlobalV::ofs_running << Numerator[i * this->ParaV->ncol + j].real() << "+" + << Numerator[i * this->ParaV->ncol + j].imag() << "i "; } GlobalV::ofs_running << endl; } GlobalV::ofs_running << endl; } -// ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + // ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> // (2) compute Numerator & Denominator by GEADD // Numerator = Stmp - i*para * Htmp; beta1 = - para = -0.25 * INPUT.mdp.md_dt // Denominator = Stmp + i*para * Htmp; beta2 = para = 0.25 * INPUT.mdp.md_dt @@ -500,128 +564,111 @@ void Evolve_LCAO_Matrix::compute_U_operator( complex beta1 = {0.0, -0.25 * INPUT.mdp.md_dt}; complex beta2 = {0.0, 0.25 * INPUT.mdp.md_dt}; - ScalapackConnector::geadd( - 'N', - nlocal, - nlocal, - alpha, - Stmp, - 1, - 1, - this->ParaV->desc, - beta1, - Numerator, - 1, - 1, - this->ParaV->desc - ); - ScalapackConnector::geadd( - 'N', - nlocal, - nlocal, - alpha, - Stmp, - 1, - 1, - this->ParaV->desc, - beta2, - Denominator, - 1, - 1, - this->ParaV->desc - ); + ScalapackConnector::geadd('N', + nlocal, + nlocal, + alpha, + Stmp, + 1, + 1, + this->ParaV->desc, + beta1, + Numerator, + 1, + 1, + this->ParaV->desc); + ScalapackConnector::geadd('N', + nlocal, + nlocal, + alpha, + Stmp, + 1, + 1, + this->ParaV->desc, + beta2, + Denominator, + 1, + 1, + this->ParaV->desc); if (print_matrix) { + GlobalV::ofs_running << " beta=" << beta1 << endl; GlobalV::ofs_running << " fenmu:" << endl; for (int i = 0; i < this->ParaV->nrow; i++) { for (int j = 0; j < this->ParaV->ncol; j++) { - GlobalV::ofs_running << Denominator[i * this->ParaV->ncol + j].real() << "+" << Denominator[i * this->ParaV->ncol + j].imag() << "i "; + GlobalV::ofs_running << Denominator[i * this->ParaV->ncol + j].real() << "+" + << Denominator[i * this->ParaV->ncol + j].imag() << "i "; } GlobalV::ofs_running << endl; } GlobalV::ofs_running << endl; } -//->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + //->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> // (3) Next, invert Denominator int* ipiv = new int[this->ParaV->nloc]; int info = 0; // (3.1) compute ipiv - ScalapackConnector::getrf( - nlocal, - nlocal, - Denominator, - 1, - 1, - this->ParaV->desc, - ipiv, - &info - ); + ScalapackConnector::getrf(nlocal, nlocal, Denominator, 1, 1, this->ParaV->desc, ipiv, &info); int lwork = -1; int liwotk = -1; std::vector> work(1, 0); std::vector iwork(1, 0); // (3.2) compute work - ScalapackConnector::getri( - nlocal, - Denominator, - 1, - 1, - this->ParaV->desc, - ipiv, - work.data(), - &lwork, - iwork.data(), - &liwotk, - &info - ); + ScalapackConnector::getri(nlocal, + Denominator, + 1, + 1, + this->ParaV->desc, + ipiv, + work.data(), + &lwork, + iwork.data(), + &liwotk, + &info); lwork = work[0].real(); work.resize(lwork, 0); liwotk = iwork[0]; iwork.resize(liwotk, 0); - // (3.3) compute inverse matrix of matrix_A - ScalapackConnector::getri( - nlocal, - Denominator, - 1, - 1, - this->ParaV->desc, - ipiv, - work.data(), - &lwork, - iwork.data(), - &liwotk, - &info - ); + // (3.3) compute inverse matrix of Denominator + ScalapackConnector::getri(nlocal, + Denominator, + 1, + 1, + this->ParaV->desc, + ipiv, + work.data(), + &lwork, + iwork.data(), + &liwotk, + &info); assert(0 == info); -//->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + //->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> // (4) U_operator = Denominator * Numerator; - ScalapackConnector::gemm( - 'N', - 'N', - nlocal, - nlocal, - nlocal, - 1.0, - Denominator, - 1, - 1, - this->ParaV->desc, - Numerator, - 1, - 1, - this->ParaV->desc, - 0.0, - U_operator, - 1, - 1, - this->ParaV->desc - ); + ScalapackConnector::gemm('N', + 'N', + nlocal, + nlocal, + nlocal, + 1.0, + Denominator, + 1, + 1, + this->ParaV->desc, + Numerator, + 1, + 1, + this->ParaV->desc, + 0.0, + U_operator, + 1, + 1, + this->ParaV->desc); if (print_matrix) { @@ -630,7 +677,8 @@ void Evolve_LCAO_Matrix::compute_U_operator( { for (int j = 0; j < this->ParaV->ncol; j++) { - GlobalV::ofs_running << Denominator[i * this->ParaV->ncol + j].real() << "+" << Denominator[i * this->ParaV->ncol + j].imag() << "i "; + GlobalV::ofs_running << Denominator[i * this->ParaV->ncol + j].real() << "+" + << Denominator[i * this->ParaV->ncol + j].imag() << "i "; } GlobalV::ofs_running << endl; } @@ -640,7 +688,8 @@ void Evolve_LCAO_Matrix::compute_U_operator( { for (int j = 0; j < this->ParaV->ncol; j++) { - GlobalV::ofs_running << Numerator[i * this->ParaV->ncol + j].real() << "+" << Numerator[i * this->ParaV->ncol + j].imag() << "i "; + GlobalV::ofs_running << Numerator[i * this->ParaV->ncol + j].real() << "+" + << Numerator[i * this->ParaV->ncol + j].imag() << "i "; } GlobalV::ofs_running << endl; } @@ -663,103 +712,513 @@ void Evolve_LCAO_Matrix::compute_U_operator( } } -// cout << "U_operator Success!!!" <* U_operator, - const std::complex* psi_k_laststep, - std::complex* psi_k) const +void Evolve_LCAO_Matrix::compute_U_operator_taylor(const int nband, + const int nlocal, + const std::complex* Stmp, + const std::complex* Htmp, + std::complex* U_operator, + const int print_matrix) const { + ModuleBase::GlobalFunc::ZEROS(U_operator, this->ParaV->nloc); + complex* A_matrix = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(A_matrix, this->ParaV->nloc); + complex* rank0 = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(rank0, this->ParaV->nloc); + complex* rank2 = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(rank2, this->ParaV->nloc); + complex* rank3 = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(rank3, this->ParaV->nloc); + complex* rank4 = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(rank4, this->ParaV->nloc); + complex* tmp1 = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(tmp1, this->ParaV->nloc); + complex* tmp2 = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(tmp2, this->ParaV->nloc); + complex* Sinv = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(Sinv, this->ParaV->nloc); + BlasConnector::copy(this->ParaV->nloc, Stmp, 1, Sinv, 1); + + if (print_matrix) + { + GlobalV::ofs_running << endl; + GlobalV::ofs_running << " S matrix :" << endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Stmp[i * this->ParaV->ncol + j].real() << "+" + << Stmp[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << endl; + } + GlobalV::ofs_running << endl; + GlobalV::ofs_running << endl; + GlobalV::ofs_running << " H matrix :" << endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Htmp[i * this->ParaV->ncol + j].real() << "+" + << Htmp[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << endl; + } + GlobalV::ofs_running << endl; + } + + // set rank0 + int info; + int myid; + MPI_Comm_rank(this->ParaV->comm_2D, &myid); + int naroc[2]; // maximum number of row or column + + for (int iprow = 0; iprow < this->ParaV->dim0; ++iprow) + { + for (int ipcol = 0; ipcol < this->ParaV->dim1; ++ipcol) + { + const int coord[2] = {iprow, ipcol}; + int src_rank; + info = MPI_Cart_rank(this->ParaV->comm_2D, coord, &src_rank); + if (myid == src_rank) + { + naroc[0] = this->ParaV->nrow; + naroc[1] = this->ParaV->ncol; + for (int j = 0; j < naroc[1]; ++j) + { + int igcol = globalIndex(j, this->ParaV->nb, this->ParaV->dim1, ipcol); + if (igcol >= nlocal) + continue; + for (int i = 0; i < naroc[0]; ++i) + { + int igrow = globalIndex(i, this->ParaV->nb, this->ParaV->dim0, iprow); + if (igrow >= nlocal) + continue; + if (igcol == igrow) + { + rank0[j * naroc[0] + i] = {1.0, 0.0}; + } + else + { + rank0[j * naroc[0] + i] = {0.0, 0.0}; + } + } + } + } + } // loop ipcol + } // loop iprow + + // complex beta = {0.0, -0.5 * INPUT.mdp.md_dt}; + complex beta = {0.0, -0.25 * INPUT.mdp.md_dt}; // for ETRS + + //->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + // invert Stmp + int* ipiv = new int[this->ParaV->nloc]; + // (3.1) compute ipiv + ScalapackConnector::getrf(nlocal, nlocal, Sinv, 1, 1, this->ParaV->desc, ipiv, &info); + int lwork = -1; + int liwotk = -1; + std::vector> work(1, 0); + std::vector iwork(1, 0); + // (3.2) compute work + ScalapackConnector::getri(nlocal, + Sinv, + 1, + 1, + this->ParaV->desc, + ipiv, + work.data(), + &lwork, + iwork.data(), + &liwotk, + &info); + lwork = work[0].real(); + work.resize(lwork, 0); + liwotk = iwork[0]; + iwork.resize(liwotk, 0); + ScalapackConnector::getri(nlocal, + Sinv, + 1, + 1, + this->ParaV->desc, + ipiv, + work.data(), + &lwork, + iwork.data(), + &liwotk, + &info); + assert(0 == info); + + //->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + // A_matrix = - idt S^-1 H ; + ScalapackConnector::gemm('N', + 'N', + nlocal, + nlocal, + nlocal, + beta, + Sinv, + 1, + 1, + this->ParaV->desc, + Htmp, + 1, + 1, + this->ParaV->desc, + 0.0, + U_operator, + 1, + 1, + this->ParaV->desc); + + // rank2 = A^2 ; + ScalapackConnector::gemm('N', + 'N', + nlocal, + nlocal, + nlocal, + 1.0, + U_operator, + 1, + 1, + this->ParaV->desc, + U_operator, + 1, + 1, + this->ParaV->desc, + 0.0, + rank2, + 1, + 1, + this->ParaV->desc); + + // rank3 = A^3 ; + ScalapackConnector::gemm('N', + 'N', + nlocal, + nlocal, + nlocal, + 1.0, + U_operator, + 1, + 1, + this->ParaV->desc, + rank2, + 1, + 1, + this->ParaV->desc, + 0.0, + rank3, + 1, + 1, + this->ParaV->desc); + + // rank4 = A^4 ; + ScalapackConnector::gemm('N', + 'N', + nlocal, + nlocal, + nlocal, + 1.0, + U_operator, + 1, + 1, + this->ParaV->desc, + rank3, + 1, + 1, + this->ParaV->desc, + 0.0, + rank4, + 1, + 1, + this->ParaV->desc); + + complex p1 = {1.0, 0.0}; + complex p2 = {1.0 / 2.0, 0.0}; + complex p3 = {1.0 / 6.0, 0.0}; + complex p4 = {1.0 / 24.0, 0.0}; + + ScalapackConnector::geadd('N', + nlocal, + nlocal, + p1, + rank0, + 1, + 1, + this->ParaV->desc, + p1, + U_operator, + 1, + 1, + this->ParaV->desc); + + ScalapackConnector::geadd('N', + nlocal, + nlocal, + p2, + rank2, + 1, + 1, + this->ParaV->desc, + p1, + U_operator, + 1, + 1, + this->ParaV->desc); + + ScalapackConnector::geadd('N', + nlocal, + nlocal, + p3, + rank3, + 1, + 1, + this->ParaV->desc, + p1, + U_operator, + 1, + 1, + this->ParaV->desc); + + ScalapackConnector::geadd('N', + nlocal, + nlocal, + p4, + rank4, + 1, + 1, + this->ParaV->desc, + p1, + U_operator, + 1, + 1, + this->ParaV->desc); + + if (print_matrix) + { + GlobalV::ofs_running << " A_matrix:" << endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << A_matrix[i * this->ParaV->ncol + j].real() << "+" + << A_matrix[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << endl; + } + GlobalV::ofs_running << endl; + GlobalV::ofs_running << " U operator:" << endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + double aa, bb; + aa = U_operator[i * this->ParaV->ncol + j].real(); + bb = U_operator[i * this->ParaV->ncol + j].imag(); + if (abs(aa) < 1e-8) + aa = 0.0; + if (abs(bb) < 1e-8) + bb = 0.0; + GlobalV::ofs_running << aa << "+" << bb << "i "; + } + GlobalV::ofs_running << endl; + } + } - ScalapackConnector::gemm( - 'N', - 'N', - nlocal, - nband, - nlocal, - 1.0, - U_operator, - 1, - 1, - this->ParaV->desc, - psi_k_laststep, - 1, - 1, - this->ParaV->desc_wfc, - 0.0, - psi_k, - 1, - 1, - this->ParaV->desc_wfc - ); + // cout << "U_operator Success!!!" <* Stmp, + const std::complex* Htmp, + const std::complex* H_laststep, + std::complex* U_operator, + const int print_matrix) const +{ + complex* U1 = new complex[this->ParaV->nloc]; + complex* U2 = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(U1, this->ParaV->nloc); + ModuleBase::GlobalFunc::ZEROS(U2, this->ParaV->nloc); + compute_U_operator_taylor(nband, nlocal, Stmp, Htmp, U1, print_matrix); + compute_U_operator_taylor(nband, nlocal, Stmp, H_laststep, U2, print_matrix); + ScalapackConnector::gemm('N', + 'N', + nlocal, + nlocal, + nlocal, + 1.0, + U1, + 1, + 1, + this->ParaV->desc, + U2, + 1, + 1, + this->ParaV->desc, + 0.0, + U_operator, + 1, + 1, + this->ParaV->desc); +} -void Evolve_LCAO_Matrix::norm_wfc( - const int nband, - const int nlocal, - const std::complex* Stmp, - std::complex* psi_k, - const int print_matrix) const +void Evolve_LCAO_Matrix::U_to_wfc(const int nband, + const int nlocal, + const std::complex* U_operator, + const std::complex* psi_k_laststep, + std::complex* psi_k, + const int print_matrix) const +{ + + ScalapackConnector::gemm('N', + 'N', + nlocal, + nband, + nlocal, + 1.0, + U_operator, + 1, + 1, + this->ParaV->desc, + psi_k_laststep, + 1, + 1, + this->ParaV->desc_wfc, + 0.0, + psi_k, + 1, + 1, + this->ParaV->desc_wfc); + + if (print_matrix) + { + GlobalV::ofs_running << endl; + GlobalV::ofs_running << " psi_k:" << endl; + for (int i = 0; i < this->ParaV->ncol_bands; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + double aa, bb; + aa = psi_k[i * this->ParaV->ncol + j].real(); + bb = psi_k[i * this->ParaV->ncol + j].imag(); + if (abs(aa) < 1e-8) + aa = 0.0; + if (abs(bb) < 1e-8) + bb = 0.0; + GlobalV::ofs_running << aa << "+" << bb << "i "; + } + GlobalV::ofs_running << endl; + } + GlobalV::ofs_running << endl; + GlobalV::ofs_running << " psi_k_laststep:" << endl; + for (int i = 0; i < this->ParaV->ncol_bands; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + double aa, bb; + aa = psi_k_laststep[i * this->ParaV->ncol + j].real(); + bb = psi_k_laststep[i * this->ParaV->ncol + j].imag(); + if (abs(aa) < 1e-8) + aa = 0.0; + if (abs(bb) < 1e-8) + bb = 0.0; + GlobalV::ofs_running << aa << "+" << bb << "i "; + } + GlobalV::ofs_running << endl; + } + GlobalV::ofs_running << endl; + } +} + +void Evolve_LCAO_Matrix::norm_wfc(const int nband, + const int nlocal, + const std::complex* Stmp, + std::complex* psi_k, + const int print_matrix) const { complex* tmp1 = new complex[this->ParaV->nloc_wfc]; ModuleBase::GlobalFunc::ZEROS(tmp1, this->ParaV->nloc_wfc); - + complex* Cij = new complex[this->ParaV->nloc]; ModuleBase::GlobalFunc::ZEROS(Cij, this->ParaV->nloc); - - ScalapackConnector::gemm( - 'N', - 'N', - nlocal, - nband, - nlocal, - 1.0, - Stmp, - 1, - 1, - this->ParaV->desc, - psi_k, - 1, - 1, - this->ParaV->desc_wfc, - 0.0, - tmp1, - 1, - 1, - this->ParaV->desc_wfc - ); - - ScalapackConnector::gemm( - 'C', - 'N', - nband, - nband, - nlocal, - 1.0, - psi_k, - 1, - 1, - this->ParaV->desc_wfc, - tmp1, - 1, - 1, - this->ParaV->desc_wfc, - 0.0, - Cij, - 1, - 1, - this->ParaV->desc - ); + ScalapackConnector::gemm('N', + 'N', + nlocal, + nband, + nlocal, + 1.0, + Stmp, + 1, + 1, + this->ParaV->desc, + psi_k, + 1, + 1, + this->ParaV->desc_wfc, + 0.0, + tmp1, + 1, + 1, + this->ParaV->desc_wfc); + + ScalapackConnector::gemm('C', + 'N', + nband, + nband, + nlocal, + 1.0, + psi_k, + 1, + 1, + this->ParaV->desc_wfc, + tmp1, + 1, + 1, + this->ParaV->desc_wfc, + 0.0, + Cij, + 1, + 1, + this->ParaV->desc_Eij); + + if (print_matrix) + { + GlobalV::ofs_running << "original Cij :" << endl; + for (int i = 0; i < this->ParaV->ncol; i++) + { + for (int j = 0; j < this->ParaV->nrow; j++) + { + double aa, bb; + aa = Cij[i * this->ParaV->ncol + j].real(); + bb = Cij[i * this->ParaV->ncol + j].imag(); + if (abs(aa) < 1e-8) + aa = 0.0; + if (abs(bb) < 1e-8) + bb = 0.0; + GlobalV::ofs_running << aa << "+" << bb << "i "; + } + GlobalV::ofs_running << endl; + } + GlobalV::ofs_running << endl; + } int info; int myid; @@ -801,32 +1260,27 @@ void Evolve_LCAO_Matrix::norm_wfc( } // loop ipcol } // loop iprow - // std::cout << "nlocal" << nlocal << std::endl; - // std::cout << "GlobalV::NLOCAL" << GlobalV::NLOCAL << std::endl; BlasConnector::copy(this->ParaV->nloc_wfc, psi_k, 1, tmp1, 1); - ScalapackConnector::gemm( - 'N', - 'N', - nlocal, - nband, - nband, - 1.0, - tmp1, - 1, - 1, - this->ParaV->desc_wfc, - Cij, - 1, - 1, - this->ParaV->desc, - 0.0, - psi_k, - 1, - 1, - this->ParaV->desc_wfc - ); - + ScalapackConnector::gemm('N', + 'N', + nlocal, + nband, + nband, + 1.0, + tmp1, + 1, + 1, + this->ParaV->desc_wfc, + Cij, + 1, + 1, + this->ParaV->desc_Eij, + 0.0, + psi_k, + 1, + 1, + this->ParaV->desc_wfc); if (print_matrix) { @@ -835,7 +1289,8 @@ void Evolve_LCAO_Matrix::norm_wfc( { for (int j = 0; j < this->ParaV->nrow; j++) { - GlobalV::ofs_running << Cij[i * this->ParaV->ncol + j].real() << "+" << Cij[i * this->ParaV->ncol_bands + j].imag() << "i "; + GlobalV::ofs_running << Cij[i * this->ParaV->ncol + j].real() << "+" + << Cij[i * this->ParaV->ncol + j].imag() << "i "; } GlobalV::ofs_running << endl; } @@ -858,7 +1313,7 @@ void Evolve_LCAO_Matrix::norm_wfc( GlobalV::ofs_running << endl; } GlobalV::ofs_running << endl; - GlobalV::ofs_running << " psi_k nlocal*nlocal:" << endl; + GlobalV::ofs_running << " psi_k before normalization:" << endl; for (int i = 0; i < this->ParaV->ncol; i++) { for (int j = 0; j < this->ParaV->ncol; j++) @@ -878,19 +1333,15 @@ void Evolve_LCAO_Matrix::norm_wfc( GlobalV::ofs_running << endl; } - delete[] tmp1; delete[] Cij; - } - -void Evolve_LCAO_Matrix::compute_ekb( - const int nband, - const int nlocal, - const std::complex* Htmp, - const std::complex* psi_k, - double* ekb) const +void Evolve_LCAO_Matrix::compute_ekb(const int nband, + const int nlocal, + const std::complex* Htmp, + const std::complex* psi_k, + double* ekb) const { complex* tmp1 = new complex[this->ParaV->nloc_wfc]; @@ -899,50 +1350,45 @@ void Evolve_LCAO_Matrix::compute_ekb( complex* Eij = new complex[this->ParaV->nloc]; ModuleBase::GlobalFunc::ZEROS(Eij, this->ParaV->nloc); - ScalapackConnector::gemm( - 'N', - 'N', - nlocal, - nband, - nlocal, - 1.0, - Htmp, - 1, - 1, - this->ParaV->desc, - psi_k, - 1, - 1, - this->ParaV->desc_wfc, - 0.0, - tmp1, - 1, - 1, - this->ParaV->desc_wfc - ); - - ScalapackConnector::gemm( - 'C', - 'N', - nband, - nband, - nlocal, - 1.0, - psi_k, - 1, - 1, - this->ParaV->desc_wfc, - tmp1, - 1, - 1, - this->ParaV->desc_wfc, - 0.0, - Eij, - 1, - 1, - this->ParaV->desc - ); - + ScalapackConnector::gemm('N', + 'N', + nlocal, + nband, + nlocal, + 1.0, + Htmp, + 1, + 1, + this->ParaV->desc, + psi_k, + 1, + 1, + this->ParaV->desc_wfc, + 0.0, + tmp1, + 1, + 1, + this->ParaV->desc_wfc); + + ScalapackConnector::gemm('C', + 'N', + nband, + nband, + nlocal, + 1.0, + psi_k, + 1, + 1, + this->ParaV->desc_wfc, + tmp1, + 1, + 1, + this->ParaV->desc_wfc, + 0.0, + Eij, + 1, + 1, + this->ParaV->desc_Eij); if (ELEC_evolve::td_print_eij > 0.0) { @@ -950,9 +1396,9 @@ void Evolve_LCAO_Matrix::compute_ekb( << "------------------------------------------------------------------------------------------------" << endl; GlobalV::ofs_running << " Eij:" << endl; - for (int i = 0; i < this->ParaV->ncol; i++) + for (int i = 0; i < this->ParaV->nrow_bands; i++) { - for (int j = 0; j < this->ParaV->nrow; j++) + for (int j = 0; j < this->ParaV->ncol_bands; j++) { double aa, bb; aa = Eij[i * this->ParaV->ncol + j].real(); @@ -973,12 +1419,11 @@ void Evolve_LCAO_Matrix::compute_ekb( << endl; } - int info; int myid; int naroc[2]; MPI_Comm_rank(this->ParaV->comm_2D, &myid); - + double* Eii = new double[nband]; ModuleBase::GlobalFunc::ZEROS(Eii, nband); for (int iprow = 0; iprow < this->ParaV->dim0; ++iprow) @@ -1012,11 +1457,10 @@ void Evolve_LCAO_Matrix::compute_ekb( } // loop ipcol } // loop iprow info = MPI_Allreduce(Eii, ekb, nband, MPI_DOUBLE, MPI_SUM, this->ParaV->comm_2D); - + delete[] tmp1; delete[] Eij; delete[] Eii; } - #endif diff --git a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h b/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h index 1f1f4e1fc0..bcf470a771 100644 --- a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h +++ b/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h @@ -22,8 +22,10 @@ class Evolve_LCAO_Matrix hamilt::Hamilt* p_hamilt, psi::Psi>* psi_k, psi::Psi>* psi_k_laststep, - std::complex* Hk_laststep, - double* ekb) const; + std::complex* H_laststep, + double* ekb, + int htype, + int propagator) const; private: // LCAO_Matrix* LM; @@ -39,16 +41,42 @@ class Evolve_LCAO_Matrix const int nband, const int nlocal, const std::complex* psi_k_laststep, - const std::complex* Hk_laststep, + const std::complex* H_laststep, hamilt::Hamilt* p_hamilt, std::complex* psi_k, - double* ekb) const; + double* ekb, + int htype, + int propagator) const; + + void half_Hmatrix( + const int nband, + const int nlocal, + std::complex* Htmp, + const std::complex* H_laststep, + const int print_matrix) const; + + void compute_U_operator_CN2( + const int nband, + const int nlocal, + const std::complex* Stmp, + const std::complex* Htmp, + std::complex* U_operator, + const int print_matrix) const; - void compute_U_operator( + void compute_U_operator_taylor( + const int nband, + const int nlocal, + const std::complex* Stmp, + const std::complex* Htmp, + std::complex* U_operator, + const int print_matrix) const; + + void compute_U_operator_etrs( const int nband, const int nlocal, const std::complex* Stmp, const std::complex* Htmp, + const std::complex* H_laststep, std::complex* U_operator, const int print_matrix) const; @@ -57,7 +85,8 @@ class Evolve_LCAO_Matrix const int nlocal, const std::complex* U_operator, const std::complex* psi_k_laststep, - std::complex* psi_k) const; + std::complex* psi_k, + const int print_matrix) const; void norm_wfc( const int nband, diff --git a/source/module_io/input.cpp b/source/module_io/input.cpp index 1f1eaac91c..200e7a3ccf 100644 --- a/source/module_io/input.cpp +++ b/source/module_io/input.cpp @@ -408,6 +408,9 @@ void Input::Default(void) td_vext = false; td_vext_dire = "1"; + td_htype = 0; + propagator = 0; + out_dipole = false; out_efield = false; @@ -1545,6 +1548,14 @@ bool Input::Read(const std::string &fn) { read_value(ifs, td_edm); } + else if (strcmp("td_htype", word) == 0) + { + read_value(ifs, td_htype); + } + else if (strcmp("propagator", word) == 0) + { + read_value(ifs, propagator); + } else if (strcmp("td_stype", word) == 0) { read_value(ifs, td_stype); @@ -2957,6 +2968,8 @@ void Input::Bcast() Parallel_Common::bcast_double(td_force_dt); Parallel_Common::bcast_bool(td_vext); Parallel_Common::bcast_string(td_vext_dire); + Parallel_Common::bcast_int(td_htype); + Parallel_Common::bcast_int(propagator); Parallel_Common::bcast_int(td_stype); Parallel_Common::bcast_string(td_ttype); Parallel_Common::bcast_int(td_tstart); diff --git a/source/module_io/input.h b/source/module_io/input.h index f9002da4f6..fc2960c1a9 100644 --- a/source/module_io/input.h +++ b/source/module_io/input.h @@ -380,6 +380,9 @@ class Input double td_print_eij; // threshold to output Eij elements int td_edm; //0: new edm method 1: old edm method + int td_htype; // type of Hamiltonian to calculate propagator + int propagator; // method of propagator + int td_stype ; //type of space domain 0 : length gauge 1: velocity gauge std::string td_ttype ; //type of time domain diff --git a/source/module_io/test/input_test.cpp b/source/module_io/test/input_test.cpp index b594b63e8d..6d61502863 100644 --- a/source/module_io/test/input_test.cpp +++ b/source/module_io/test/input_test.cpp @@ -252,6 +252,8 @@ TEST_F(InputTest, Default) EXPECT_DOUBLE_EQ(INPUT.td_force_dt,0.02); EXPECT_FALSE(INPUT.td_vext); EXPECT_EQ(INPUT.td_vext_dire,"1"); + EXPECT_EQ(INPUT.td_htype,0); + EXPECT_EQ(INPUT.propagator,0); EXPECT_EQ(INPUT.td_stype,0); EXPECT_EQ(INPUT.td_ttype,"0"); EXPECT_EQ(INPUT.td_tstart,1); @@ -584,6 +586,8 @@ TEST_F(InputTest, Read) EXPECT_DOUBLE_EQ(INPUT.td_force_dt,0.02); EXPECT_EQ(INPUT.td_vext,0); // EXPECT_EQ(INPUT.td_vext_dire,"1"); + EXPECT_EQ(INPUT.td_htype,0); + EXPECT_EQ(INPUT.propagator,0); EXPECT_EQ(INPUT.td_stype,0); // EXPECT_EQ(INPUT.td_ttype,"0"); EXPECT_EQ(INPUT.td_tstart,1); diff --git a/source/module_io/test/input_test_para.cpp b/source/module_io/test/input_test_para.cpp index b4b3afbcba..af1f917b0d 100644 --- a/source/module_io/test/input_test_para.cpp +++ b/source/module_io/test/input_test_para.cpp @@ -258,6 +258,8 @@ TEST_F(InputParaTest,Bcast) EXPECT_DOUBLE_EQ(INPUT.td_force_dt,0.02); EXPECT_FALSE(INPUT.td_vext); EXPECT_EQ(INPUT.td_vext_dire,"1"); + EXPECT_EQ(INPUT.td_htype,0); + EXPECT_EQ(INPUT.propagator,0); EXPECT_EQ(INPUT.td_stype,0); EXPECT_EQ(INPUT.td_ttype,"0"); EXPECT_EQ(INPUT.td_tstart,1); diff --git a/source/module_io/test/support/INPUT b/source/module_io/test/support/INPUT index 91b4fc9de4..92e7e6e1cc 100644 --- a/source/module_io/test/support/INPUT +++ b/source/module_io/test/support/INPUT @@ -284,6 +284,8 @@ exx_opt_orb_tolerence 0 # td_force_dt 0.02 #time of force change td_vext 0 #add extern potential or not td_vext_dire 1 #extern potential direction +td_htype 0 # type of Hamiltonian to calculate propagator +propagator 0 # method of propagator td_stype 0 #space domain type td_ttype 0 #time domain type td_tstart 1 #the start step of electric field diff --git a/source/module_io/test/support/witestfile b/source/module_io/test/support/witestfile index 67ce58da05..ad0a1e5a37 100644 --- a/source/module_io/test/support/witestfile +++ b/source/module_io/test/support/witestfile @@ -278,6 +278,8 @@ exx_opt_orb_tolerence 0 # td_force_dt 0.02 #time of force change td_vext 0 #add extern potential or not td_vext_dire 1 #extern potential direction +td_htype 0 # type of Hamiltonian to calculate propagator +propagator 0 # method of propagator td_stype 0 #space domain type td_ttype 0 #time domain type td_tstart 1 #the start step of electric field diff --git a/tests/integrate/601_NO_TDDFT_H2_etrs/INPUT b/tests/integrate/601_NO_TDDFT_H2_etrs/INPUT new file mode 100755 index 0000000000..d0ea674f1b --- /dev/null +++ b/tests/integrate/601_NO_TDDFT_H2_etrs/INPUT @@ -0,0 +1,35 @@ +INPUT_PARAMETERS +#Parameters (General) +suffix autotest +pseudo_dir ../../PP_ORB +orbital_dir ../../PP_ORB + +nbands 5 +calculation md +esolver_type tddft + +#Parameter (Accuracy) +ecutwfc 100 +scf_nmax 50 + +ks_solver scalapack_gvx +basis_type lcao +gamma_only 0 +md_nstep 2 + +mixing_type pulay +mixing_beta 0.7 +scf_thr 1.0e-6 + +cal_stress 1 +stress_thr 1e-6 +cal_force 1 +force_thr_ev 1.0e-3 + +propagator 2 + +md_type nve +md_dt 0.05 +init_vel 1 +ocp 1 +ocp_set 1*1 1*1 3*0 diff --git a/tests/integrate/601_NO_TDDFT_H2_etrs/KPT b/tests/integrate/601_NO_TDDFT_H2_etrs/KPT new file mode 100755 index 0000000000..c289c0158a --- /dev/null +++ b/tests/integrate/601_NO_TDDFT_H2_etrs/KPT @@ -0,0 +1,4 @@ +K_POINTS +0 +Gamma +1 1 1 0 0 0 diff --git a/tests/integrate/601_NO_TDDFT_H2_etrs/STRU b/tests/integrate/601_NO_TDDFT_H2_etrs/STRU new file mode 100755 index 0000000000..af32239121 --- /dev/null +++ b/tests/integrate/601_NO_TDDFT_H2_etrs/STRU @@ -0,0 +1,22 @@ +ATOMIC_SPECIES +H 1.00794 H.LDA.UPF + +NUMERICAL_ORBITAL +H_lda_8.0au_100Ry_2s1p.orb + +LATTICE_CONSTANT +15 + +LATTICE_VECTORS +1 0 0 #latvec1 +0 1 0 #latvec2 +0 0 1 #latvec3 + +ATOMIC_POSITIONS +Cartesian + +H #label +0 #magnetism +2 #number of atoms +0.502095122795 0.474071446432 0.509122850526 m 1 1 1 v -1.58317459417e-05 0.000196314331857 0.000681467807833 +0.497904877205 0.525928553568 0.592277149473 m 1 1 1 v 1.58317459417e-05 -0.000196314331857 -0.000681467807833 diff --git a/tests/integrate/601_NO_TDDFT_H2_etrs/result.ref b/tests/integrate/601_NO_TDDFT_H2_etrs/result.ref new file mode 100644 index 0000000000..799a64080a --- /dev/null +++ b/tests/integrate/601_NO_TDDFT_H2_etrs/result.ref @@ -0,0 +1,5 @@ +etotref +etotperatomref +totalforceref 0.714836 +totalstressref 1.295806 +totaltimeref diff --git a/tests/integrate/601_NO_TDDFT_H2_halfH/INPUT b/tests/integrate/601_NO_TDDFT_H2_halfH/INPUT new file mode 100755 index 0000000000..901858802f --- /dev/null +++ b/tests/integrate/601_NO_TDDFT_H2_halfH/INPUT @@ -0,0 +1,36 @@ +INPUT_PARAMETERS +#Parameters (General) +suffix autotest +pseudo_dir ../../PP_ORB +orbital_dir ../../PP_ORB + +nbands 5 +calculation md +esolver_type tddft + +#Parameter (Accuracy) +ecutwfc 100 +scf_nmax 50 + +ks_solver scalapack_gvx +basis_type lcao +gamma_only 0 +md_nstep 2 + +mixing_type pulay +mixing_beta 0.7 +scf_thr 1.0e-6 + +cal_stress 1 +stress_thr 1e-6 +cal_force 1 +force_thr_ev 1.0e-3 + +td_htype 1 +propagator 0 + +md_type nve +md_dt 0.05 +init_vel 1 +ocp 1 +ocp_set 1*1 1*1 3*0 diff --git a/tests/integrate/601_NO_TDDFT_H2_halfH/KPT b/tests/integrate/601_NO_TDDFT_H2_halfH/KPT new file mode 100755 index 0000000000..c289c0158a --- /dev/null +++ b/tests/integrate/601_NO_TDDFT_H2_halfH/KPT @@ -0,0 +1,4 @@ +K_POINTS +0 +Gamma +1 1 1 0 0 0 diff --git a/tests/integrate/601_NO_TDDFT_H2_halfH/STRU b/tests/integrate/601_NO_TDDFT_H2_halfH/STRU new file mode 100755 index 0000000000..af32239121 --- /dev/null +++ b/tests/integrate/601_NO_TDDFT_H2_halfH/STRU @@ -0,0 +1,22 @@ +ATOMIC_SPECIES +H 1.00794 H.LDA.UPF + +NUMERICAL_ORBITAL +H_lda_8.0au_100Ry_2s1p.orb + +LATTICE_CONSTANT +15 + +LATTICE_VECTORS +1 0 0 #latvec1 +0 1 0 #latvec2 +0 0 1 #latvec3 + +ATOMIC_POSITIONS +Cartesian + +H #label +0 #magnetism +2 #number of atoms +0.502095122795 0.474071446432 0.509122850526 m 1 1 1 v -1.58317459417e-05 0.000196314331857 0.000681467807833 +0.497904877205 0.525928553568 0.592277149473 m 1 1 1 v 1.58317459417e-05 -0.000196314331857 -0.000681467807833 diff --git a/tests/integrate/601_NO_TDDFT_H2_halfH/result.ref b/tests/integrate/601_NO_TDDFT_H2_halfH/result.ref new file mode 100644 index 0000000000..d1095ae3ec --- /dev/null +++ b/tests/integrate/601_NO_TDDFT_H2_halfH/result.ref @@ -0,0 +1,5 @@ +etotref -18.11864981293731 +etotperatomref -9.0593249065 +totalforceref 44.341410 +totalstressref 78.497930 +totaltimeref +3.9966 diff --git a/tests/integrate/601_NO_TDDFT_H2_taylor/INPUT b/tests/integrate/601_NO_TDDFT_H2_taylor/INPUT new file mode 100755 index 0000000000..9246c5724e --- /dev/null +++ b/tests/integrate/601_NO_TDDFT_H2_taylor/INPUT @@ -0,0 +1,36 @@ +INPUT_PARAMETERS +#Parameters (General) +suffix autotest +pseudo_dir ../../PP_ORB +orbital_dir ../../PP_ORB + +nbands 5 +calculation md +esolver_type tddft + +#Parameter (Accuracy) +ecutwfc 100 +scf_nmax 50 + +ks_solver scalapack_gvx +basis_type lcao +gamma_only 0 +md_nstep 2 + +mixing_type pulay +mixing_beta 0.7 +scf_thr 1.0e-6 + +cal_stress 1 +stress_thr 1e-6 +cal_force 1 +force_thr_ev 1.0e-3 + +td_htype 1 +propagator 1 + +md_type nve +md_dt 0.05 +init_vel 1 +ocp 1 +ocp_set 1*1 1*1 3*0 diff --git a/tests/integrate/601_NO_TDDFT_H2_taylor/KPT b/tests/integrate/601_NO_TDDFT_H2_taylor/KPT new file mode 100755 index 0000000000..c289c0158a --- /dev/null +++ b/tests/integrate/601_NO_TDDFT_H2_taylor/KPT @@ -0,0 +1,4 @@ +K_POINTS +0 +Gamma +1 1 1 0 0 0 diff --git a/tests/integrate/601_NO_TDDFT_H2_taylor/STRU b/tests/integrate/601_NO_TDDFT_H2_taylor/STRU new file mode 100755 index 0000000000..af32239121 --- /dev/null +++ b/tests/integrate/601_NO_TDDFT_H2_taylor/STRU @@ -0,0 +1,22 @@ +ATOMIC_SPECIES +H 1.00794 H.LDA.UPF + +NUMERICAL_ORBITAL +H_lda_8.0au_100Ry_2s1p.orb + +LATTICE_CONSTANT +15 + +LATTICE_VECTORS +1 0 0 #latvec1 +0 1 0 #latvec2 +0 0 1 #latvec3 + +ATOMIC_POSITIONS +Cartesian + +H #label +0 #magnetism +2 #number of atoms +0.502095122795 0.474071446432 0.509122850526 m 1 1 1 v -1.58317459417e-05 0.000196314331857 0.000681467807833 +0.497904877205 0.525928553568 0.592277149473 m 1 1 1 v 1.58317459417e-05 -0.000196314331857 -0.000681467807833 diff --git a/tests/integrate/601_NO_TDDFT_H2_taylor/result.ref b/tests/integrate/601_NO_TDDFT_H2_taylor/result.ref new file mode 100644 index 0000000000..ab82b76038 --- /dev/null +++ b/tests/integrate/601_NO_TDDFT_H2_taylor/result.ref @@ -0,0 +1,5 @@ +etotref -18.06759546636300 +etotperatomref -9.0337977332 +totalforceref 46.058216 +totalstressref 81.553158 +totaltimeref +3.8555 diff --git a/tests/integrate/CASES b/tests/integrate/CASES index ccf4623199..78face74b9 100644 --- a/tests/integrate/CASES +++ b/tests/integrate/CASES @@ -184,7 +184,7 @@ 315_NO_sol_H2O 316_NO_scan_Si2 320_NO_GO_MD_MSST -320_NO_GO_MD_NHC +320_NO_GO_MD_NVT 345_NO_GO_BS 360_NO_15_GO_PU_AF #381_NO_GO_HSE @@ -192,6 +192,9 @@ #401_NP_KP_sp #401_NP_KP_spd 601_NO_TDDFT_H2 +601_NO_TDDFT_H2_halfH +601_NO_TDDFT_H2_taylor +601_NO_TDDFT_H2_etrs 601_NO_TDDFT_H2_kpoint 601_NO_TDDFT_H2_oldedm 601_NO_TDDFT_CO From 2676e97c664f5d62f04b3147a8da0b958dbeb96f Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Sat, 29 Apr 2023 14:12:00 +0800 Subject: [PATCH 05/48] delete td_htype and update ref of tddft autotests --- tests/integrate/601_NO_TDDFT_CO/result.ref | 10 +++--- .../integrate/601_NO_TDDFT_CO_occ/result.ref | 10 +++--- tests/integrate/601_NO_TDDFT_H2/result.ref | 10 +++--- .../integrate/601_NO_TDDFT_H2_etrs/result.ref | 10 +++--- tests/integrate/601_NO_TDDFT_H2_halfH/INPUT | 36 ------------------- tests/integrate/601_NO_TDDFT_H2_halfH/KPT | 4 --- tests/integrate/601_NO_TDDFT_H2_halfH/STRU | 22 ------------ .../601_NO_TDDFT_H2_halfH/result.ref | 5 --- .../601_NO_TDDFT_H2_kpoint/result.ref | 10 +++--- .../601_NO_TDDFT_H2_len_gauss/result.ref | 10 +++--- .../601_NO_TDDFT_H2_len_gauss_dire/result.ref | 10 +++--- .../601_NO_TDDFT_H2_len_heavi/result.ref | 10 +++--- .../601_NO_TDDFT_H2_len_hhg/result.ref | 10 +++--- .../601_NO_TDDFT_H2_len_trape/result.ref | 10 +++--- .../601_NO_TDDFT_H2_len_trigo/result.ref | 10 +++--- .../601_NO_TDDFT_H2_oldedm/result.ref | 10 +++--- tests/integrate/601_NO_TDDFT_H2_taylor/INPUT | 1 - .../601_NO_TDDFT_H2_taylor/result.ref | 2 +- tests/integrate/601_NO_TDDFT_O3/result.ref | 10 +++--- .../601_NO_TDDFT_graphene_kpoint/result.ref | 10 +++--- tests/integrate/CASES | 1 - 21 files changed, 71 insertions(+), 140 deletions(-) delete mode 100755 tests/integrate/601_NO_TDDFT_H2_halfH/INPUT delete mode 100755 tests/integrate/601_NO_TDDFT_H2_halfH/KPT delete mode 100755 tests/integrate/601_NO_TDDFT_H2_halfH/STRU delete mode 100644 tests/integrate/601_NO_TDDFT_H2_halfH/result.ref diff --git a/tests/integrate/601_NO_TDDFT_CO/result.ref b/tests/integrate/601_NO_TDDFT_CO/result.ref index 27a1c2fe89..4e091bf960 100644 --- a/tests/integrate/601_NO_TDDFT_CO/result.ref +++ b/tests/integrate/601_NO_TDDFT_CO/result.ref @@ -1,5 +1,5 @@ -etotref -602.8643309993128 -etotperatomref -301.4321654997 -totalforceref 16.350762 -totalstressref 30.184735 -totaltimeref +7.1335 +etotref -602.9324267719877 +etotperatomref -301.4662133860 +totalforceref 14.600956 +totalstressref 26.941295 +totaltimeref +7.2570 diff --git a/tests/integrate/601_NO_TDDFT_CO_occ/result.ref b/tests/integrate/601_NO_TDDFT_CO_occ/result.ref index 271e8953a8..8cc9792b73 100644 --- a/tests/integrate/601_NO_TDDFT_CO_occ/result.ref +++ b/tests/integrate/601_NO_TDDFT_CO_occ/result.ref @@ -1,5 +1,5 @@ -etotref -602.8643311305311 -etotperatomref -301.4321655653 -totalforceref 16.350762 -totalstressref 30.185015 -totaltimeref +7.0590 +etotref -602.9324267719870 +etotperatomref -301.4662133860 +totalforceref 14.600956 +totalstressref 26.944193 +totaltimeref +7.2778 diff --git a/tests/integrate/601_NO_TDDFT_H2/result.ref b/tests/integrate/601_NO_TDDFT_H2/result.ref index 9bffc30214..e004ff740e 100644 --- a/tests/integrate/601_NO_TDDFT_H2/result.ref +++ b/tests/integrate/601_NO_TDDFT_H2/result.ref @@ -1,5 +1,5 @@ -etotref -18.05421597483996 -etotperatomref -9.0271079874 -totalforceref 44.953238 -totalstressref 79.612084 -totaltimeref +3.7961 +etotref -18.11864981293731 +etotperatomref -9.0593249065 +totalforceref 44.341410 +totalstressref 78.497930 +totaltimeref +3.9683 diff --git a/tests/integrate/601_NO_TDDFT_H2_etrs/result.ref b/tests/integrate/601_NO_TDDFT_H2_etrs/result.ref index 799a64080a..c739b9afc4 100644 --- a/tests/integrate/601_NO_TDDFT_H2_etrs/result.ref +++ b/tests/integrate/601_NO_TDDFT_H2_etrs/result.ref @@ -1,5 +1,5 @@ -etotref -etotperatomref -totalforceref 0.714836 -totalstressref 1.295806 -totaltimeref +etotref -18.03711173613717 +etotperatomref -9.0185558681 +totalforceref 47.878136 +totalstressref 84.826734 +totaltimeref +3.8888 diff --git a/tests/integrate/601_NO_TDDFT_H2_halfH/INPUT b/tests/integrate/601_NO_TDDFT_H2_halfH/INPUT deleted file mode 100755 index 901858802f..0000000000 --- a/tests/integrate/601_NO_TDDFT_H2_halfH/INPUT +++ /dev/null @@ -1,36 +0,0 @@ -INPUT_PARAMETERS -#Parameters (General) -suffix autotest -pseudo_dir ../../PP_ORB -orbital_dir ../../PP_ORB - -nbands 5 -calculation md -esolver_type tddft - -#Parameter (Accuracy) -ecutwfc 100 -scf_nmax 50 - -ks_solver scalapack_gvx -basis_type lcao -gamma_only 0 -md_nstep 2 - -mixing_type pulay -mixing_beta 0.7 -scf_thr 1.0e-6 - -cal_stress 1 -stress_thr 1e-6 -cal_force 1 -force_thr_ev 1.0e-3 - -td_htype 1 -propagator 0 - -md_type nve -md_dt 0.05 -init_vel 1 -ocp 1 -ocp_set 1*1 1*1 3*0 diff --git a/tests/integrate/601_NO_TDDFT_H2_halfH/KPT b/tests/integrate/601_NO_TDDFT_H2_halfH/KPT deleted file mode 100755 index c289c0158a..0000000000 --- a/tests/integrate/601_NO_TDDFT_H2_halfH/KPT +++ /dev/null @@ -1,4 +0,0 @@ -K_POINTS -0 -Gamma -1 1 1 0 0 0 diff --git a/tests/integrate/601_NO_TDDFT_H2_halfH/STRU b/tests/integrate/601_NO_TDDFT_H2_halfH/STRU deleted file mode 100755 index af32239121..0000000000 --- a/tests/integrate/601_NO_TDDFT_H2_halfH/STRU +++ /dev/null @@ -1,22 +0,0 @@ -ATOMIC_SPECIES -H 1.00794 H.LDA.UPF - -NUMERICAL_ORBITAL -H_lda_8.0au_100Ry_2s1p.orb - -LATTICE_CONSTANT -15 - -LATTICE_VECTORS -1 0 0 #latvec1 -0 1 0 #latvec2 -0 0 1 #latvec3 - -ATOMIC_POSITIONS -Cartesian - -H #label -0 #magnetism -2 #number of atoms -0.502095122795 0.474071446432 0.509122850526 m 1 1 1 v -1.58317459417e-05 0.000196314331857 0.000681467807833 -0.497904877205 0.525928553568 0.592277149473 m 1 1 1 v 1.58317459417e-05 -0.000196314331857 -0.000681467807833 diff --git a/tests/integrate/601_NO_TDDFT_H2_halfH/result.ref b/tests/integrate/601_NO_TDDFT_H2_halfH/result.ref deleted file mode 100644 index d1095ae3ec..0000000000 --- a/tests/integrate/601_NO_TDDFT_H2_halfH/result.ref +++ /dev/null @@ -1,5 +0,0 @@ -etotref -18.11864981293731 -etotperatomref -9.0593249065 -totalforceref 44.341410 -totalstressref 78.497930 -totaltimeref +3.9966 diff --git a/tests/integrate/601_NO_TDDFT_H2_kpoint/result.ref b/tests/integrate/601_NO_TDDFT_H2_kpoint/result.ref index 40dca31f18..4c41f579eb 100644 --- a/tests/integrate/601_NO_TDDFT_H2_kpoint/result.ref +++ b/tests/integrate/601_NO_TDDFT_H2_kpoint/result.ref @@ -1,5 +1,5 @@ -etotref -18.05362763740304 -etotperatomref -9.0268138187 -totalforceref 44.990644 -totalstressref 79.754356 -totaltimeref +3.8596 +etotref -18.11805148765627 +etotperatomref -9.0590257438 +totalforceref 44.379294 +totalstressref 78.642667 +totaltimeref +3.9332 diff --git a/tests/integrate/601_NO_TDDFT_H2_len_gauss/result.ref b/tests/integrate/601_NO_TDDFT_H2_len_gauss/result.ref index f7f4110f52..e1fdbda5d2 100644 --- a/tests/integrate/601_NO_TDDFT_H2_len_gauss/result.ref +++ b/tests/integrate/601_NO_TDDFT_H2_len_gauss/result.ref @@ -1,5 +1,5 @@ -etotref -31.36567798859614 -etotperatomref -15.6828389943 -totalforceref 0.578604 -totalstressref 5.433996 -totaltimeref +3.9632 +etotref -31.36573200236431 +etotperatomref -15.6828660012 +totalforceref 0.553188 +totalstressref 5.401078 +totaltimeref +3.9278 diff --git a/tests/integrate/601_NO_TDDFT_H2_len_gauss_dire/result.ref b/tests/integrate/601_NO_TDDFT_H2_len_gauss_dire/result.ref index 59c1620fa8..09da282a5e 100644 --- a/tests/integrate/601_NO_TDDFT_H2_len_gauss_dire/result.ref +++ b/tests/integrate/601_NO_TDDFT_H2_len_gauss_dire/result.ref @@ -1,5 +1,5 @@ -etotref -31.36554049797190 -etotperatomref -15.6827702490 -totalforceref 0.577232 -totalstressref 5.434161 -totaltimeref +4.0295 +etotref -31.36561540267921 +etotperatomref -15.6828077013 +totalforceref 0.551808 +totalstressref 5.401785 +totaltimeref +4.1191 diff --git a/tests/integrate/601_NO_TDDFT_H2_len_heavi/result.ref b/tests/integrate/601_NO_TDDFT_H2_len_heavi/result.ref index 3e52430584..e27d8ef784 100644 --- a/tests/integrate/601_NO_TDDFT_H2_len_heavi/result.ref +++ b/tests/integrate/601_NO_TDDFT_H2_len_heavi/result.ref @@ -1,5 +1,5 @@ -etotref -38.85116666973314 -etotperatomref -19.4255833349 -totalforceref 0.568498 -totalstressref 77.448537 -totaltimeref +3.8784 +etotref -38.85116687166003 +etotperatomref -19.4255834358 +totalforceref 0.541042 +totalstressref 77.414057 +totaltimeref +3.9307 diff --git a/tests/integrate/601_NO_TDDFT_H2_len_hhg/result.ref b/tests/integrate/601_NO_TDDFT_H2_len_hhg/result.ref index b6d67e9d5b..c565a3407b 100644 --- a/tests/integrate/601_NO_TDDFT_H2_len_hhg/result.ref +++ b/tests/integrate/601_NO_TDDFT_H2_len_hhg/result.ref @@ -1,5 +1,5 @@ -etotref -82.60904651293552 -etotperatomref -41.3045232565 -totalforceref 0.754930 -totalstressref 500.961654 -totaltimeref +4.0425 +etotref -82.60939739426242 +etotperatomref -41.3046986971 +totalforceref 0.725730 +totalstressref 501.148069 +totaltimeref +3.9894 diff --git a/tests/integrate/601_NO_TDDFT_H2_len_trape/result.ref b/tests/integrate/601_NO_TDDFT_H2_len_trape/result.ref index 4f21088bfc..efd0971095 100644 --- a/tests/integrate/601_NO_TDDFT_H2_len_trape/result.ref +++ b/tests/integrate/601_NO_TDDFT_H2_len_trape/result.ref @@ -1,5 +1,5 @@ -etotref -30.92097257037962 -etotperatomref -15.4604862852 -totalforceref 0.578690 -totalstressref 1.159819 -totaltimeref +3.5993 +etotref -30.92097376654489 +etotperatomref -15.4604868833 +totalforceref 0.553928 +totalstressref 1.126626 +totaltimeref +3.6563 diff --git a/tests/integrate/601_NO_TDDFT_H2_len_trigo/result.ref b/tests/integrate/601_NO_TDDFT_H2_len_trigo/result.ref index 542503a9f7..4533830a4d 100644 --- a/tests/integrate/601_NO_TDDFT_H2_len_trigo/result.ref +++ b/tests/integrate/601_NO_TDDFT_H2_len_trigo/result.ref @@ -1,5 +1,5 @@ -etotref -30.91150616526584 -etotperatomref -15.4557530826 -totalforceref 0.578692 -totalstressref 1.068838 -totaltimeref +3.6067 +etotref -30.91150736235756 +etotperatomref -15.4557536812 +totalforceref 0.553934 +totalstressref 1.035650 +totaltimeref +3.6851 diff --git a/tests/integrate/601_NO_TDDFT_H2_oldedm/result.ref b/tests/integrate/601_NO_TDDFT_H2_oldedm/result.ref index ff03624d80..a986219151 100644 --- a/tests/integrate/601_NO_TDDFT_H2_oldedm/result.ref +++ b/tests/integrate/601_NO_TDDFT_H2_oldedm/result.ref @@ -1,5 +1,5 @@ -etotref -18.05362763740304 -etotperatomref -9.0268138187 -totalforceref 44.990644 -totalstressref 79.754356 -totaltimeref +3.8057 +etotref -18.11805148765627 +etotperatomref -9.0590257438 +totalforceref 44.379294 +totalstressref 78.642667 +totaltimeref +3.8941 diff --git a/tests/integrate/601_NO_TDDFT_H2_taylor/INPUT b/tests/integrate/601_NO_TDDFT_H2_taylor/INPUT index 9246c5724e..fd9209a360 100755 --- a/tests/integrate/601_NO_TDDFT_H2_taylor/INPUT +++ b/tests/integrate/601_NO_TDDFT_H2_taylor/INPUT @@ -26,7 +26,6 @@ stress_thr 1e-6 cal_force 1 force_thr_ev 1.0e-3 -td_htype 1 propagator 1 md_type nve diff --git a/tests/integrate/601_NO_TDDFT_H2_taylor/result.ref b/tests/integrate/601_NO_TDDFT_H2_taylor/result.ref index ab82b76038..689ce39369 100644 --- a/tests/integrate/601_NO_TDDFT_H2_taylor/result.ref +++ b/tests/integrate/601_NO_TDDFT_H2_taylor/result.ref @@ -2,4 +2,4 @@ etotref -18.06759546636300 etotperatomref -9.0337977332 totalforceref 46.058216 totalstressref 81.553158 -totaltimeref +3.8555 +totaltimeref +3.9590 diff --git a/tests/integrate/601_NO_TDDFT_O3/result.ref b/tests/integrate/601_NO_TDDFT_O3/result.ref index d9794538f9..ecbf49bf79 100644 --- a/tests/integrate/601_NO_TDDFT_O3/result.ref +++ b/tests/integrate/601_NO_TDDFT_O3/result.ref @@ -1,5 +1,5 @@ -etotref -1335.872362260576 -etotperatomref -445.2907874202 -totalforceref 13.319759 -totalstressref 54.934057 -totaltimeref +23.556 +etotref -1335.908108681581 +etotperatomref -445.3027028939 +totalforceref 11.460530 +totalstressref 49.365672 +totaltimeref +7.5885 diff --git a/tests/integrate/601_NO_TDDFT_graphene_kpoint/result.ref b/tests/integrate/601_NO_TDDFT_graphene_kpoint/result.ref index 2314206da8..bc0a8dc3eb 100644 --- a/tests/integrate/601_NO_TDDFT_graphene_kpoint/result.ref +++ b/tests/integrate/601_NO_TDDFT_graphene_kpoint/result.ref @@ -1,5 +1,5 @@ -etotref -321.2175762983792 -etotperatomref -107.0725254328 -totalforceref 13.778433 -totalstressref 1806.432527 -totaltimeref +35.306 +etotref -321.2175515031428 +etotperatomref -107.0725171677 +totalforceref 13.752222 +totalstressref 1804.951839 +totaltimeref +34.350 diff --git a/tests/integrate/CASES b/tests/integrate/CASES index 07868070a9..ceccf3d1c0 100644 --- a/tests/integrate/CASES +++ b/tests/integrate/CASES @@ -191,7 +191,6 @@ #401_NP_KP_spd #501_NO_neighboring_GaAs512 601_NO_TDDFT_H2 -601_NO_TDDFT_H2_halfH 601_NO_TDDFT_H2_taylor 601_NO_TDDFT_H2_etrs 601_NO_TDDFT_H2_kpoint From 952088e314fdb88c9fb7abc03f86407524576109 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Sat, 29 Apr 2023 14:18:31 +0800 Subject: [PATCH 06/48] delete td_htype --- docs/advanced/input_files/input-main.md | 10 ---------- source/module_esolver/esolver_ks_lcao_tddft.cpp | 6 +++--- source/module_esolver/esolver_ks_lcao_tddft.h | 1 + source/module_io/input.cpp | 6 ------ source/module_io/input.h | 1 - source/module_io/test/input_test.cpp | 2 -- source/module_io/test/input_test_para.cpp | 1 - source/module_io/test/support/INPUT | 1 - 8 files changed, 4 insertions(+), 24 deletions(-) diff --git a/docs/advanced/input_files/input-main.md b/docs/advanced/input_files/input-main.md index 56a903edf2..4f904f49d5 100644 --- a/docs/advanced/input_files/input-main.md +++ b/docs/advanced/input_files/input-main.md @@ -282,7 +282,6 @@ - [td\_edm](#td_edm) - [td\_print\_eij](#td_print_eij) - [td\_force\_dt](#td_force_dt) - - [td\_htype](#td_htype) - [propagator](#propagator) - [td\_vext](#td_vext) - [td\_vext\_dire](#td_vext_dire) @@ -2336,15 +2335,6 @@ These variables are used to control berry phase and wannier90 interface paramete - **Description**: Time-dependent evolution force changes time step. (fs) - **Default**: 0.02 -### td_htype - -- **Type**: Integer -- **Description**: - type of Hamiltonian to calculate propagator (for propagator = 0 or 1). - - 0: H(t+dt). - - 1: H(t+dt/2). -- **Default**: 0 - ### propagator - **Type**: Integer diff --git a/source/module_esolver/esolver_ks_lcao_tddft.cpp b/source/module_esolver/esolver_ks_lcao_tddft.cpp index dc60287a6d..82a0486d88 100644 --- a/source/module_esolver/esolver_ks_lcao_tddft.cpp +++ b/source/module_esolver/esolver_ks_lcao_tddft.cpp @@ -203,7 +203,7 @@ void ESolver_KS_LCAO_TDDFT::hamilt2density(int istep, int iter, double ethr) this->psi_laststep, this->Hk_laststep, this->pelec_td->ekb, - INPUT.td_htype, + td_htype, INPUT.propagator); this->pelec_td->psiToRho_td(this->psi[0]); // this->pelec_td->psiToRho(this->psi[0]); @@ -382,7 +382,7 @@ void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) = new psi::Psi>(GlobalC::kv.nks, GlobalV::NBANDS, GlobalV::NLOCAL, nullptr); #endif - if (INPUT.td_htype == 1) + if (td_htype == 1) { if (this->Hk_laststep == nullptr) { @@ -404,7 +404,7 @@ void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) psi_laststep[0].get_pointer()[index] = psi[0].get_pointer()[index]; // store Hamiltonian - if (INPUT.td_htype == 1) + if (td_htype == 1) { this->p_hamilt->updateHk(ik); hamilt::MatrixBlock> h_mat, s_mat; diff --git a/source/module_esolver/esolver_ks_lcao_tddft.h b/source/module_esolver/esolver_ks_lcao_tddft.h index 6f9da4a185..6df05bb38e 100644 --- a/source/module_esolver/esolver_ks_lcao_tddft.h +++ b/source/module_esolver/esolver_ks_lcao_tddft.h @@ -25,6 +25,7 @@ class ESolver_KS_LCAO_TDDFT : public ESolver_KS_LCAO std::complex** Hk_laststep = nullptr; //same as pelec elecstate::ElecStateLCAO_TDDFT* pelec_td = nullptr; + int td_htype = 1; protected: virtual void hamilt2density(const int istep, const int iter, const double ethr) override; diff --git a/source/module_io/input.cpp b/source/module_io/input.cpp index b5b4dae5c6..76f1967ae5 100644 --- a/source/module_io/input.cpp +++ b/source/module_io/input.cpp @@ -408,7 +408,6 @@ void Input::Default(void) td_vext = false; td_vext_dire = "1"; - td_htype = 0; propagator = 0; out_dipole = false; @@ -1548,10 +1547,6 @@ bool Input::Read(const std::string &fn) { read_value(ifs, td_edm); } - else if (strcmp("td_htype", word) == 0) - { - read_value(ifs, td_htype); - } else if (strcmp("propagator", word) == 0) { read_value(ifs, propagator); @@ -2981,7 +2976,6 @@ void Input::Bcast() Parallel_Common::bcast_double(td_force_dt); Parallel_Common::bcast_bool(td_vext); Parallel_Common::bcast_string(td_vext_dire); - Parallel_Common::bcast_int(td_htype); Parallel_Common::bcast_int(propagator); Parallel_Common::bcast_int(td_stype); Parallel_Common::bcast_string(td_ttype); diff --git a/source/module_io/input.h b/source/module_io/input.h index 6d1821436f..df96fa3501 100644 --- a/source/module_io/input.h +++ b/source/module_io/input.h @@ -380,7 +380,6 @@ class Input double td_print_eij; // threshold to output Eij elements int td_edm; //0: new edm method 1: old edm method - int td_htype; // type of Hamiltonian to calculate propagator int propagator; // method of propagator int td_stype ; //type of space domain 0 : length gauge 1: velocity gauge diff --git a/source/module_io/test/input_test.cpp b/source/module_io/test/input_test.cpp index 447e819c3d..561d28c0f5 100644 --- a/source/module_io/test/input_test.cpp +++ b/source/module_io/test/input_test.cpp @@ -254,7 +254,6 @@ TEST_F(InputTest, Default) EXPECT_DOUBLE_EQ(INPUT.td_force_dt,0.02); EXPECT_FALSE(INPUT.td_vext); EXPECT_EQ(INPUT.td_vext_dire,"1"); - EXPECT_EQ(INPUT.td_htype,0); EXPECT_EQ(INPUT.propagator,0); EXPECT_EQ(INPUT.td_stype,0); EXPECT_EQ(INPUT.td_ttype,"0"); @@ -590,7 +589,6 @@ TEST_F(InputTest, Read) EXPECT_DOUBLE_EQ(INPUT.td_force_dt,0.02); EXPECT_EQ(INPUT.td_vext,0); // EXPECT_EQ(INPUT.td_vext_dire,"1"); - EXPECT_EQ(INPUT.td_htype,0); EXPECT_EQ(INPUT.propagator,0); EXPECT_EQ(INPUT.td_stype,0); // EXPECT_EQ(INPUT.td_ttype,"0"); diff --git a/source/module_io/test/input_test_para.cpp b/source/module_io/test/input_test_para.cpp index 3cfa45d444..315b560cec 100644 --- a/source/module_io/test/input_test_para.cpp +++ b/source/module_io/test/input_test_para.cpp @@ -260,7 +260,6 @@ TEST_F(InputParaTest,Bcast) EXPECT_DOUBLE_EQ(INPUT.td_force_dt,0.02); EXPECT_FALSE(INPUT.td_vext); EXPECT_EQ(INPUT.td_vext_dire,"1"); - EXPECT_EQ(INPUT.td_htype,0); EXPECT_EQ(INPUT.propagator,0); EXPECT_EQ(INPUT.td_stype,0); EXPECT_EQ(INPUT.td_ttype,"0"); diff --git a/source/module_io/test/support/INPUT b/source/module_io/test/support/INPUT index b1a45fe347..3c57394565 100644 --- a/source/module_io/test/support/INPUT +++ b/source/module_io/test/support/INPUT @@ -284,7 +284,6 @@ exx_opt_orb_tolerence 0 # td_force_dt 0.02 #time of force change td_vext 0 #add extern potential or not td_vext_dire 1 #extern potential direction -td_htype 0 # type of Hamiltonian to calculate propagator propagator 0 # method of propagator td_stype 0 #space domain type td_ttype 0 #time domain type From 4ac0f2bf6183643e256a65ddf25ed175b343dbb2 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Wed, 10 May 2023 17:29:50 +0800 Subject: [PATCH 07/48] refactor tddft code --- source/Makefile.Objects | 9 +- .../potentials/H_TDDFT_pw.cpp | 8 +- source/module_esolver/Makefile.Objects | 4 +- .../module_esolver/esolver_ks_lcao_tddft.cpp | 241 +-- source/module_esolver/esolver_ks_lcao_tddft.h | 1 - .../module_tddft/CMakeLists.txt | 9 +- .../module_tddft/ELEC_evolve.cpp | 58 - .../module_tddft/LCAO_evolve.cpp | 1466 ----------------- .../module_tddft/LCAO_evolve.h | 108 -- .../module_tddft/bandenergy.cpp | 147 ++ .../module_tddft/bandenergy.h | 15 + .../module_tddft/evolve_elec.cpp | 81 + .../{ELEC_evolve.h => evolve_elec.h} | 38 +- .../module_tddft/evolve_psi.cpp | 102 ++ .../module_tddft/evolve_psi.h | 18 + .../module_tddft/middle_hamilt.cpp | 65 + .../module_tddft/middle_hamilt.h | 15 + .../module_tddft/norm_psi.cpp | 208 +++ .../module_tddft/norm_psi.h | 16 + .../module_tddft/propagator.cpp | 616 +++++++ .../module_tddft/propagator.h | 57 + .../module_hamilt_lcao/module_tddft/upsi.cpp | 79 + source/module_hamilt_lcao/module_tddft/upsi.h | 17 + source/module_io/input_conv.cpp | 20 +- .../module_io/test/for_testing_input_conv.h | 45 +- source/module_io/test/input_conv_test.cpp | 20 +- source/module_io/write_dipole.cpp | 2 +- .../601_NO_TDDFT_H2_taylor/result.ref | 10 +- 28 files changed, 1545 insertions(+), 1930 deletions(-) delete mode 100644 source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp delete mode 100644 source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp delete mode 100644 source/module_hamilt_lcao/module_tddft/LCAO_evolve.h create mode 100644 source/module_hamilt_lcao/module_tddft/bandenergy.cpp create mode 100644 source/module_hamilt_lcao/module_tddft/bandenergy.h create mode 100644 source/module_hamilt_lcao/module_tddft/evolve_elec.cpp rename source/module_hamilt_lcao/module_tddft/{ELEC_evolve.h => evolve_elec.h} (58%) create mode 100644 source/module_hamilt_lcao/module_tddft/evolve_psi.cpp create mode 100644 source/module_hamilt_lcao/module_tddft/evolve_psi.h create mode 100644 source/module_hamilt_lcao/module_tddft/middle_hamilt.cpp create mode 100644 source/module_hamilt_lcao/module_tddft/middle_hamilt.h create mode 100644 source/module_hamilt_lcao/module_tddft/norm_psi.cpp create mode 100644 source/module_hamilt_lcao/module_tddft/norm_psi.h create mode 100644 source/module_hamilt_lcao/module_tddft/propagator.cpp create mode 100644 source/module_hamilt_lcao/module_tddft/propagator.h create mode 100644 source/module_hamilt_lcao/module_tddft/upsi.cpp create mode 100644 source/module_hamilt_lcao/module_tddft/upsi.h diff --git a/source/Makefile.Objects b/source/Makefile.Objects index 2acb7d866a..daad669562 100644 --- a/source/Makefile.Objects +++ b/source/Makefile.Objects @@ -380,14 +380,19 @@ OBJS_IO_LCAO=cal_r_overlap_R.o\ OBJS_LCAO=DM_gamma.o\ DM_k.o\ - ELEC_evolve.o\ + evolve_elec.o\ + evolve_psi.o\ + bandenergy.o\ + middle_hamilt.o\ + norm_psi.o\ + propagator.o\ + upsi.o\ FORCE_STRESS.o\ FORCE_gamma.o\ FORCE_gamma_edm.o\ FORCE_gamma_tvnl.o\ FORCE_gamma_vl.o\ FORCE_k.o\ - LCAO_evolve.o\ LCAO_gen_fixedH.o\ LCAO_hamilt.o\ LCAO_matrix.o\ diff --git a/source/module_elecstate/potentials/H_TDDFT_pw.cpp b/source/module_elecstate/potentials/H_TDDFT_pw.cpp index a915af5b7b..84fb803aec 100644 --- a/source/module_elecstate/potentials/H_TDDFT_pw.cpp +++ b/source/module_elecstate/potentials/H_TDDFT_pw.cpp @@ -2,7 +2,7 @@ #include "module_base/constants.h" #include "module_base/timer.h" -#include "module_hamilt_lcao/module_tddft/ELEC_evolve.h" +#include "module_hamilt_lcao/module_tddft/evolve_elec.h" #include "module_hamilt_pw/hamilt_pwdft/global.h" #include "module_io/input.h" #include "module_io/input_conv.h" @@ -27,7 +27,7 @@ void H_TDDFT_pw::cal_fixed_v(double *vl_pseudo) read_parameters(&INPUT); // judgement to skip vext - if (!ELEC_evolve::td_vext || istep > tend || istep < tstart) + if (!Evolve_elec::td_vext || istep > tend || istep < tstart) { return; } @@ -37,12 +37,12 @@ void H_TDDFT_pw::cal_fixed_v(double *vl_pseudo) int count = 0; - for (auto direc: ELEC_evolve::td_vext_dire_case) + for (auto direc: Evolve_elec::td_vext_dire_case) { std::vector vext_space(this->rho_basis_->nrxx, 0.0); double vext_time = cal_v_time(ttype[count]); - if (ELEC_evolve::out_efield && GlobalV::MY_RANK == 0) + if (Evolve_elec::out_efield && GlobalV::MY_RANK == 0) { std::stringstream as; as << GlobalV::global_out_dir << "efield_" << count << ".dat"; diff --git a/source/module_esolver/Makefile.Objects b/source/module_esolver/Makefile.Objects index 31cd11b530..c0f298ba16 100644 --- a/source/module_esolver/Makefile.Objects +++ b/source/module_esolver/Makefile.Objects @@ -373,14 +373,14 @@ OBJS_IO_LCAO=cal_r_overlap_R.o\ OBJS_LCAO=DM_gamma.o\ DM_k.o\ - ELEC_evolve.o\ + evolve_elec.o\ FORCE_STRESS.o\ FORCE_gamma.o\ FORCE_gamma_edm.o\ FORCE_gamma_tvnl.o\ FORCE_gamma_vl.o\ FORCE_k.o\ - LCAO_evolve.o\ + evolve_psi.o\ LCAO_gen_fixedH.o\ LCAO_hamilt.o\ LCAO_matrix.o\ diff --git a/source/module_esolver/esolver_ks_lcao_tddft.cpp b/source/module_esolver/esolver_ks_lcao_tddft.cpp index 82a0486d88..d5ecd812ec 100644 --- a/source/module_esolver/esolver_ks_lcao_tddft.cpp +++ b/source/module_esolver/esolver_ks_lcao_tddft.cpp @@ -13,7 +13,7 @@ #include "module_base/scalapack_connector.h" #include "module_elecstate/module_charge/symmetry_rho.h" #include "module_elecstate/occupy.h" -#include "module_hamilt_lcao/module_tddft/ELEC_evolve.h" +#include "module_hamilt_lcao/module_tddft/evolve_elec.h" #include "module_hamilt_pw/hamilt_pwdft/global.h" #include "module_io/print_info.h" @@ -111,84 +111,6 @@ void ESolver_KS_LCAO_TDDFT::Init(Input& inp, UnitCell& ucell) this->pelec_td = dynamic_cast(this->pelec); } -void ESolver_KS_LCAO_TDDFT::eachiterinit(const int istep, const int iter) -{ - // mohan add 2010-07-16 - // used for pulay mixing. - if (iter == 1) - GlobalC::CHR_MIX.reset(); - - // mohan update 2012-06-05 - GlobalC::en.deband_harris = GlobalC::en.delta_e(this->pelec); - - // mohan move it outside 2011-01-13 - // first need to calculate the weight according to - // electrons number. - // mohan add iter > 1 on 2011-04-02 - // because the GlobalC::en.ekb has not value now. - // so the smearing can not be done. - // if (iter > 1 && istep <= 1 && GlobalV::ocp == 0) - // Occupy::calculate_weights(); - - if (GlobalC::wf.init_wfc == "file") - { - if (iter == 1) - { - std::cout << " WAVEFUN -> CHARGE " << std::endl; - - // The occupation should be read in together. - // Occupy::calculate_weights(); //mohan add 2012-02-15 - - // calculate the density matrix using read in wave functions - // and the ncalculate the charge density on grid. - if (this->psi != nullptr) - { - if (istep >= 2) - { - this->pelec_td->psiToRho_td(this->psi[0]); - } - else - { - this->pelec_td->psiToRho(this->psi[0]); - } - } - else - { - this->pelec_td->psiToRho(this->psid[0]); - } - - // calculate the local potential(rho) again. - // the grid integration will do in later grid integration. - - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // a puzzle remains here. - // if I don't renew potential, - // The scf_thr is very small. - // OneElectron, Hartree and - // Exc energy are all correct - // except the band energy. - // - // solved by mohan 2010-09-10 - // there are there rho here: - // rho1: formed by read in orbitals. - // rho2: atomic rho, used to construct H - // rho3: generated by after diagonalize - // here converged because rho3 and rho1 - // are very close. - // so be careful here, make sure - // rho1 and rho2 are the same rho. - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - this->pelec->pot->init_pot(istep, this->pelec->charge); - GlobalC::en.delta_escf(this->pelec); - } - } - - if (!GlobalV::GAMMA_ONLY_LOCAL) - { - this->UHM.GK.renew(); - } -} - void ESolver_KS_LCAO_TDDFT::hamilt2density(int istep, int iter, double ethr) { @@ -196,17 +118,18 @@ void ESolver_KS_LCAO_TDDFT::hamilt2density(int istep, int iter, double ethr) if (GlobalV::ESOLVER_TYPE == "tddft" && istep >= 2 && !GlobalV::GAMMA_ONLY_LOCAL) { - ELEC_evolve::evolve_psi(istep, - this->p_hamilt, - this->LOWF, - this->psi, - this->psi_laststep, - this->Hk_laststep, - this->pelec_td->ekb, - td_htype, - INPUT.propagator); + Evolve_elec::solve_psi(istep, + GlobalV::NBANDS, + GlobalV::NLOCAL, + this->p_hamilt, + this->LOWF, + this->psi, + this->psi_laststep, + this->Hk_laststep, + this->pelec_td->ekb, + td_htype, + INPUT.propagator); this->pelec_td->psiToRho_td(this->psi[0]); - // this->pelec_td->psiToRho(this->psi[0]); } // using HSolverLCAO::solve() else if (this->phsol != nullptr) @@ -231,6 +154,7 @@ void ESolver_KS_LCAO_TDDFT::hamilt2density(int istep, int iter, double ethr) ModuleBase::WARNING_QUIT("ESolver_KS_LCAO", "HSolver has not been initialed!"); } + // print occupation of each band if (iter == 1 && istep <= 2) { GlobalV::ofs_running @@ -259,19 +183,15 @@ void ESolver_KS_LCAO_TDDFT::hamilt2density(int istep, int iter, double ethr) GlobalC::en.demet = this->pelec_td->demet; GlobalC::en.ef = this->pelec_td->ef; - // (3) sum bands to calculate charge density - // if (istep <= 1 ) Occupy::calculate_weights(); - for (int ik = 0; ik < GlobalC::kv.nks; ++ik) { this->pelec_td->print_band(ik, GlobalC::en.printe, iter); } - // (4) mohan add 2010-06-24 // using new charge density. GlobalC::en.calculate_harris(); - // (5) symmetrize the charge density + // symmetrize the charge density only for ground state if (istep <= 1) { Symmetry_rho srho; @@ -281,10 +201,10 @@ void ESolver_KS_LCAO_TDDFT::hamilt2density(int istep, int iter, double ethr) } } - // (6) compute magnetization, only for spin==2 + // compute magnetization, only for spin==2 GlobalC::ucell.magnet.compute_magnetization(pelec->charge, pelec->nelec_spin.data()); - // (7) calculate delta energy + // calculate delta energy GlobalC::en.deband = GlobalC::en.delta_e(this->pelec); } @@ -354,8 +274,7 @@ void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) elecstate::ElecStateLCAO::out_wfc_flag = 0; } - // (9) Calculate new potential according to new Charge Density. - + // Calculate new potential according to new Charge Density if (!this->conv_elec) { if (GlobalV::NSPIN == 4) @@ -413,10 +332,12 @@ void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) } } - if (istep > 1 && ELEC_evolve::td_edm == 0) + // calculate energy density matrix for tddft + if (istep > 1 && Evolve_elec::td_edm == 0) this->cal_edm_tddft(); } + // print "eigen value" for tddft if (this->conv_elec) { GlobalV::ofs_running @@ -443,135 +364,17 @@ void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) void ESolver_KS_LCAO_TDDFT::afterscf(const int istep) { - // if (this->conv_elec || iter == GlobalV::SCF_NMAX) - // { - //-------------------------------------- - // 1. output charge density for converged, - // 0 means don't need to consider iter, - //-------------------------------------- - for (int is = 0; is < GlobalV::NSPIN; is++) { - const int precision = 3; - std::stringstream ssc; - ssc << GlobalV::global_out_dir << "SPIN" << is + 1 << "_CHG.cube"; - double& ef_tmp = GlobalC::en.get_ef(is, GlobalV::TWO_EFERMI); - ModuleIO::write_rho( -#ifdef __MPI - GlobalC::bigpw->bz, - GlobalC::bigpw->nbz, - GlobalC::rhopw->nplane, - GlobalC::rhopw->startz_current, -#endif - pelec->charge->rho_save[is], - is, - GlobalV::NSPIN, - 0, - ssc.str(), - GlobalC::rhopw->nx, - GlobalC::rhopw->ny, - GlobalC::rhopw->nz, - ef_tmp, - &(GlobalC::ucell), - precision); - - if (ELEC_evolve::out_dipole == 1) + if (Evolve_elec::out_dipole == 1) { std::stringstream ss_dipole; ss_dipole << GlobalV::global_out_dir << "SPIN" << is + 1 << "_DIPOLE"; ModuleIO::write_dipole(pelec->charge->rho_save[is], is, istep, ss_dipole.str()); } - - std::stringstream ssd; - if (GlobalV::GAMMA_ONLY_LOCAL) - { - ssd << GlobalV::global_out_dir << "SPIN" << is + 1 << "_DM"; - } - else - { - ssd << GlobalV::global_out_dir << "SPIN" << is + 1 << "_DM_R"; - } - - ModuleIO::write_dm( -#ifdef __MPI - GlobalC::GridT.trace_lo, -#endif - is, - 0, - ssd.str(), - precision, - this->LOC.out_dm, - this->LOC.DM, - ef_tmp, - &(GlobalC::ucell)); - - if (GlobalV::out_pot == 1) // LiuXh add 20200701 - { - std::stringstream ssp; - ssp << GlobalV::global_out_dir << "SPIN" << is + 1 << "_POT.cube"; - this->pelec->pot->write_potential(is, 0, ssp.str(), this->pelec->pot->get_effective_v(), precision); - } - } - - if (this->conv_elec) - { - GlobalV::ofs_running << "\n charge density convergence is achieved" << std::endl; - GlobalV::ofs_running << " final etot is " << GlobalC::en.etot * ModuleBase::Ry_to_eV << " eV" << std::endl; - } - - if (GlobalV::OUT_LEVEL != "m") - { - // this->pelec->print_eigenvalue(GlobalV::ofs_running); } - if (this->conv_elec) - { - // xiaohui add "OUT_LEVEL", 2015-09-16 - if (GlobalV::OUT_LEVEL != "m") - GlobalV::ofs_running << std::setprecision(16); - if (GlobalV::OUT_LEVEL != "m") - GlobalV::ofs_running << " EFERMI = " << GlobalC::en.ef * ModuleBase::Ry_to_eV << " eV" << std::endl; - } - else - { - GlobalV::ofs_running << " !! convergence has not been achieved @_@" << std::endl; - if (GlobalV::OUT_LEVEL == "ie" || GlobalV::OUT_LEVEL == "m") // xiaohui add "m" option, 2015-09-16 - std::cout << " !! CONVERGENCE HAS NOT BEEN ACHIEVED !!" << std::endl; - } - - if( GlobalV::CALCULATION != "md" || (istep % GlobalV::out_interval == 0)) - { - if (hsolver::HSolverLCAO::out_mat_hsR) - { - ModuleIO::output_HS_R(istep, this->pelec->pot->get_effective_v(), this->UHM); // LiuXh add 2019-07-15 - } - - if (hsolver::HSolverLCAO::out_mat_t) - { - ModuleIO::output_T_R(istep, this->UHM); // LiuXh add 2019-07-15 - } - - if (hsolver::HSolverLCAO::out_mat_dh) - { - ModuleIO::output_dH_R(istep, this->pelec->pot->get_effective_v(), this->UHM); // LiuXh add 2019-07-15 - } - - // add by jingan for out r_R matrix 2019.8.14 - if (INPUT.out_mat_r) - { - cal_r_overlap_R r_matrix; - r_matrix.init(*this->LOWF.ParaV); - - if (hsolver::HSolverLCAO::out_mat_hsR) - { - r_matrix.out_rR_other(istep, this->LM.output_R_coor); - } - else - { - r_matrix.out_rR(istep); - } - } - } + ESolver_KS_LCAO::afterscf(istep); } // use the original formula (Hamiltonian matrix) to calculate energy density matrix diff --git a/source/module_esolver/esolver_ks_lcao_tddft.h b/source/module_esolver/esolver_ks_lcao_tddft.h index 6df05bb38e..5121a2b224 100644 --- a/source/module_esolver/esolver_ks_lcao_tddft.h +++ b/source/module_esolver/esolver_ks_lcao_tddft.h @@ -29,7 +29,6 @@ class ESolver_KS_LCAO_TDDFT : public ESolver_KS_LCAO protected: virtual void hamilt2density(const int istep, const int iter, const double ethr) override; - virtual void eachiterinit(const int istep, const int iter) override; virtual void updatepot(const int istep, const int iter) override; virtual void afterscf(const int istep) override; void cal_edm_tddft(); diff --git a/source/module_hamilt_lcao/module_tddft/CMakeLists.txt b/source/module_hamilt_lcao/module_tddft/CMakeLists.txt index 9eb691f495..8e0adf2b7d 100644 --- a/source/module_hamilt_lcao/module_tddft/CMakeLists.txt +++ b/source/module_hamilt_lcao/module_tddft/CMakeLists.txt @@ -1,7 +1,12 @@ if(ENABLE_LCAO) list(APPEND objects - ELEC_evolve.cpp - LCAO_evolve.cpp + evolve_elec.cpp + evolve_psi.cpp + bandenergy.cpp + middle_hamilt.cpp + norm_psi.cpp + propagator.cpp + upsi.cpp ) add_library( diff --git a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp b/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp deleted file mode 100644 index 4b37b54197..0000000000 --- a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "ELEC_evolve.h" - -#include "LCAO_evolve.h" -#include "module_base/parallel_reduce.h" -#include "module_base/timer.h" -#include "module_elecstate/module_charge/symmetry_rho.h" -#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" -#include "module_hamilt_lcao/module_dftu/dftu.h" -#include "module_hamilt_pw/hamilt_pwdft/global.h" - -ELEC_evolve::ELEC_evolve(){}; -ELEC_evolve::~ELEC_evolve(){}; - -double ELEC_evolve::td_force_dt; -bool ELEC_evolve::td_vext; -std::vector ELEC_evolve::td_vext_dire_case; -bool ELEC_evolve::out_dipole; -bool ELEC_evolve::out_efield; -double ELEC_evolve::td_print_eij; // the threshold to output Eij elements -int ELEC_evolve::td_edm; // 0: new edm method 1: old edm method - -// this routine only serves for TDDFT using LCAO basis set -void ELEC_evolve::evolve_psi(const int& istep, - hamilt::Hamilt* phm, - Local_Orbital_wfc& lowf, - psi::Psi>* psi, - psi::Psi>* psi_laststep, - std::complex** Hk_laststep, - ModuleBase::matrix& ekb, - int htype, - int propagator) -{ - ModuleBase::TITLE("ELEC_evolve", "eveolve_psi"); - ModuleBase::timer::tick("ELEC_evolve", "evolve_psi"); - - // pool parallization in future -- mohan note 2021-02-09 - for (int ik = 0; ik < GlobalC::kv.nks; ik++) - { - phm->updateHk(ik); - - ModuleBase::timer::tick("Efficience", "evolve_k"); - Evolve_LCAO_Matrix ELM(lowf.ParaV); - psi->fix_k(ik); - psi_laststep->fix_k(ik); - if (Hk_laststep == nullptr) - { - ELM.evolve_complex_matrix(ik, phm, psi, psi_laststep, nullptr, &(ekb(ik, 0)), htype, propagator); - } - else - { - ELM.evolve_complex_matrix(ik, phm, psi, psi_laststep, Hk_laststep[ik], &(ekb(ik, 0)), htype, propagator); - } - ModuleBase::timer::tick("Efficience", "evolve_k"); - } // end k - - ModuleBase::timer::tick("ELEC_evolve", "evolve_psi"); - return; -} diff --git a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp b/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp deleted file mode 100644 index cd7649f536..0000000000 --- a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp +++ /dev/null @@ -1,1466 +0,0 @@ -#include "LCAO_evolve.h" - -#include "ELEC_evolve.h" -#include "module_base/lapack_connector.h" -#include "module_base/scalapack_connector.h" -#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" -#include "module_hamilt_pw/hamilt_pwdft/global.h" -#include "module_io/input.h" -#include "module_io/write_HS.h" - -#include -// fuxiang add 2016-10-28 - -Evolve_LCAO_Matrix::~Evolve_LCAO_Matrix() -{ -} - -inline int globalIndex(int localindex, int nblk, int nprocs, int myproc) -{ - int iblock, gIndex; - iblock = localindex / nblk; - gIndex = (iblock * nprocs + myproc) * nblk + localindex % nblk; - return gIndex; -} - -void Evolve_LCAO_Matrix::evolve_complex_matrix(const int& ik, - hamilt::Hamilt* p_hamilt, - psi::Psi>* psi_k, - psi::Psi>* psi_k_laststep, - std::complex* H_laststep, - double* ekb, - int htype, - int propagator) const -{ - ModuleBase::TITLE("Evolve_LCAO_Matrix", "evolve_complex_matrix"); - time_t time_start = time(NULL); - GlobalV::ofs_running << " Start Time : " << ctime(&time_start); - - if (GlobalV::ESOLVER_TYPE == "tddft") - { -#ifdef __MPI - this->using_ScaLAPACK_complex(GlobalV::NBANDS, - GlobalV::NLOCAL, - psi_k_laststep[0].get_pointer(), - H_laststep, - p_hamilt, - psi_k[0].get_pointer(), - ekb, - htype, - propagator); -#else - this->using_LAPACK_complex(ik, p_hamilt, psi_k[0].get_pointer(), psi_k_laststep[0].get_pointer(), ekb); -#endif - } - else - { - ModuleBase::WARNING_QUIT("Evolve_LCAO_Matrix::evolve_complex_matrix", - "only esolver_type == tddft cando evolve"); - } - - time_t time_end = time(NULL); - ModuleBase::GlobalFunc::OUT_TIME("evolve(std::complex)", time_start, time_end); - - return; -} - -void Evolve_LCAO_Matrix::using_LAPACK_complex(const int& ik, - hamilt::Hamilt* p_hamilt, - std::complex* psi_k, - std::complex* psi_k_laststep, - double* ekb) const -{ - ModuleBase::TITLE("Evolve_LCAO_Matrix", "using_LAPACK_complex"); - - // Calculate the U operator - - ModuleBase::ComplexMatrix Htmp(GlobalV::NLOCAL, GlobalV::NLOCAL); - ModuleBase::ComplexMatrix Stmp(GlobalV::NLOCAL, GlobalV::NLOCAL); - hamilt::MatrixBlock> h_mat, s_mat; - p_hamilt->matrix(h_mat, s_mat); - for (int i = 0; i < GlobalV::NLOCAL; i++) - { - for (int j = 0; j < GlobalV::NLOCAL; j++) - { - Htmp(i, j) = h_mat.p[i * GlobalV::NLOCAL + j]; - // Htmp(i,j) = (this->LM->Hloc2[i*GlobalV::NLOCAL+j] +this->LM->Hloc2_laststep[i*GlobalV::NLOCAL+j])/2.0; - Stmp(i, j) = s_mat.p[i * GlobalV::NLOCAL + j]; - } - } - - ModuleBase::ComplexMatrix wfc_tmp(GlobalV::NBANDS, GlobalV::NLOCAL, true); - ModuleBase::ComplexMatrix wfc_laststep_tmp(GlobalV::NBANDS, GlobalV::NLOCAL, true); - // wfc_laststep_tmp.c = psi_k_laststep; - - for (int i = 0; i < GlobalV::NBANDS; i++) - { - for (int j = 0; j < GlobalV::NLOCAL; j++) - { - wfc_laststep_tmp.c[i * GlobalV::NLOCAL + j] = psi_k_laststep[i * GlobalV::NLOCAL + j]; - } - } - - /* - GlobalV::ofs_running << " Htmp: " < * work = new std::complex[lwork]; - ModuleBase::GlobalFunc::ZEROS(work, lwork); - int IPIV[GlobalV::NLOCAL]; - - LapackConnector::zgetrf( GlobalV::NLOCAL, GlobalV::NLOCAL, Stmp, GlobalV::NLOCAL, IPIV, &INFO); - LapackConnector::zgetri( GlobalV::NLOCAL, Stmp, GlobalV::NLOCAL, IPIV, work, lwork, &INFO); - */ - /* - std::cout << " S^-1: " <( -S_plus_H(i,j).imag(), S_plus_H(i,j).real() ); - } - } - - ModuleBase::ComplexMatrix Idmat(GlobalV::NLOCAL,GlobalV::NLOCAL); - for(int i=0; i(1.0, 0.0); - else Idmat(i,j) = std::complex(0.0, 0.0); - } - } - */ - ModuleBase::ComplexMatrix Numerator(GlobalV::NLOCAL, GlobalV::NLOCAL); - // Numerator = Idmat - 0.5*INPUT.mdp.md_dt*41.34*Denominator; - // Denominator = Idmat + 0.5*INPUT.mdp.md_dt*41.34*Denominator; - - complex para = {0.0, 1.0}; - para = para * 0.25 * INPUT.mdp.md_dt; - Numerator = Stmp - para * Htmp; - Denominator = Stmp + para * Htmp; - - int info; - int lwork = 3 * GlobalV::NLOCAL - 1; // tmp - std::complex* work = new std::complex[lwork]; - ModuleBase::GlobalFunc::ZEROS(work, lwork); - int* ipiv = new int[GlobalV::NLOCAL]; - - LapackConnector::zgetrf(GlobalV::NLOCAL, GlobalV::NLOCAL, Denominator, GlobalV::NLOCAL, ipiv, &info); - LapackConnector::zgetri(GlobalV::NLOCAL, Denominator, GlobalV::NLOCAL, ipiv, work, lwork, &info); - - ModuleBase::ComplexMatrix U_operator(GlobalV::NLOCAL, GlobalV::NLOCAL); - /* - GlobalV::ofs_running << " Numerator: " <* psi_k_laststep, - const std::complex* H_laststep, - hamilt::Hamilt* p_hamilt, - std::complex* psi_k, - double* ekb, - int htype, - int propagator) const -{ - ModuleBase::TITLE("Evolve_LCAO_Matrix", "using_ScaLAPACK_complex"); - - int print_matrix = 0; - hamilt::MatrixBlock> h_mat, s_mat; - p_hamilt->matrix(h_mat, s_mat); - - complex* Stmp = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(Stmp, this->ParaV->nloc); - BlasConnector::copy(this->ParaV->nloc, s_mat.p, 1, Stmp, 1); - - complex* Htmp = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(Htmp, this->ParaV->nloc); - BlasConnector::copy(this->ParaV->nloc, h_mat.p, 1, Htmp, 1); - - complex* Hold = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(Hold, this->ParaV->nloc); - BlasConnector::copy(this->ParaV->nloc, h_mat.p, 1, Hold, 1); - - complex* U_operator = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(U_operator, this->ParaV->nloc); - - // (1)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - /// @brief compute H(t+dt/2) - /// @input H_laststep, Htmp, print_matrix - /// @output Htmp - if (htype == 1 && propagator!=2) - { - half_Hmatrix(nband, nlocal, Htmp, H_laststep, print_matrix); - } - - // (2)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - /// @brief compute U_operator - /// @input Stmp, Htmp, print_matrix - /// @output U_operator - switch (propagator) - { - case 0: - compute_U_operator_CN2(nband, nlocal, Stmp, Htmp, U_operator, print_matrix); - break; - - case 1: - compute_U_operator_taylor(nband, nlocal, Stmp, Htmp, U_operator, print_matrix); - break; - - case 2: - compute_U_operator_etrs(nband, nlocal, Stmp, Htmp, H_laststep, U_operator, print_matrix); - - break; - - default: - std::cout << "method of propagator is wrong" << endl; - break; - } - - // (3)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - /// @brief apply U_operator to the wave function of the previous step for new wave function - /// @input U_operator, psi_k_laststep, print_matrix - /// @output psi_k - U_to_wfc(nband, nlocal, U_operator, psi_k_laststep, psi_k, print_matrix); - - // (4)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - /// @brief normalize psi_k - /// @input Stmp, psi_not_norm, psi_k, print_matrix - /// @output psi_k - norm_wfc(nband, nlocal, Stmp, psi_k, print_matrix); - - // (5)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - /// @brief compute ekb - /// @input Htmp, psi_k - /// @output ekb - compute_ekb(nband, nlocal, Hold, psi_k, ekb); - - delete[] Stmp; - delete[] Htmp; - delete[] U_operator; - return; -} - -void Evolve_LCAO_Matrix::half_Hmatrix(const int nband, - const int nlocal, - std::complex* Htmp, - const std::complex* H_laststep, - const int print_matrix) const -{ - if (print_matrix) - { - GlobalV::ofs_running << std::setprecision(10); - GlobalV::ofs_running << endl; - GlobalV::ofs_running << " H(t+dt) :" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - GlobalV::ofs_running << Htmp[i * this->ParaV->ncol + j].real() << "+" - << Htmp[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - GlobalV::ofs_running << endl; - GlobalV::ofs_running << " H(t):" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - GlobalV::ofs_running << H_laststep[i * this->ParaV->ncol + j].real() << "+" - << H_laststep[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - } - - complex alpha = {0.5, 0.0}; - complex beta = {0.5, 0.0}; - ScalapackConnector::geadd('N', - nlocal, - nlocal, - alpha, - H_laststep, - 1, - 1, - this->ParaV->desc, - beta, - Htmp, - 1, - 1, - this->ParaV->desc); - - if (print_matrix) - { - GlobalV::ofs_running << endl; - GlobalV::ofs_running << " H (t+dt/2) :" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - GlobalV::ofs_running << Htmp[i * this->ParaV->ncol + j].real() << "+" - << Htmp[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - } -} - -void Evolve_LCAO_Matrix::compute_U_operator_CN2(const int nband, - const int nlocal, - const std::complex* Stmp, - const std::complex* Htmp, - std::complex* U_operator, - const int print_matrix) const -{ - // (1) copy Htmp to Numerator & Denominator - complex* Numerator = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(Numerator, this->ParaV->nloc); - BlasConnector::copy(this->ParaV->nloc, Htmp, 1, Numerator, 1); - - complex* Denominator = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(Denominator, this->ParaV->nloc); - BlasConnector::copy(this->ParaV->nloc, Htmp, 1, Denominator, 1); - - if (print_matrix) - { - GlobalV::ofs_running << endl; - GlobalV::ofs_running << " S matrix :" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - GlobalV::ofs_running << Stmp[i * this->ParaV->ncol + j].real() << "+" - << Stmp[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - GlobalV::ofs_running << endl; - GlobalV::ofs_running << " H matrix :" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - GlobalV::ofs_running << Numerator[i * this->ParaV->ncol + j].real() << "+" - << Numerator[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - } - - // ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - // (2) compute Numerator & Denominator by GEADD - // Numerator = Stmp - i*para * Htmp; beta1 = - para = -0.25 * INPUT.mdp.md_dt - // Denominator = Stmp + i*para * Htmp; beta2 = para = 0.25 * INPUT.mdp.md_dt - complex alpha = {1.0, 0.0}; - complex beta1 = {0.0, -0.25 * INPUT.mdp.md_dt}; - complex beta2 = {0.0, 0.25 * INPUT.mdp.md_dt}; - - ScalapackConnector::geadd('N', - nlocal, - nlocal, - alpha, - Stmp, - 1, - 1, - this->ParaV->desc, - beta1, - Numerator, - 1, - 1, - this->ParaV->desc); - ScalapackConnector::geadd('N', - nlocal, - nlocal, - alpha, - Stmp, - 1, - 1, - this->ParaV->desc, - beta2, - Denominator, - 1, - 1, - this->ParaV->desc); - - if (print_matrix) - { - GlobalV::ofs_running << " beta=" << beta1 << endl; - GlobalV::ofs_running << " fenmu:" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - GlobalV::ofs_running << Denominator[i * this->ParaV->ncol + j].real() << "+" - << Denominator[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - } - - //->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - // (3) Next, invert Denominator - int* ipiv = new int[this->ParaV->nloc]; - int info = 0; - // (3.1) compute ipiv - ScalapackConnector::getrf(nlocal, nlocal, Denominator, 1, 1, this->ParaV->desc, ipiv, &info); - int lwork = -1; - int liwotk = -1; - std::vector> work(1, 0); - std::vector iwork(1, 0); - // (3.2) compute work - ScalapackConnector::getri(nlocal, - Denominator, - 1, - 1, - this->ParaV->desc, - ipiv, - work.data(), - &lwork, - iwork.data(), - &liwotk, - &info); - lwork = work[0].real(); - work.resize(lwork, 0); - liwotk = iwork[0]; - iwork.resize(liwotk, 0); - // (3.3) compute inverse matrix of Denominator - ScalapackConnector::getri(nlocal, - Denominator, - 1, - 1, - this->ParaV->desc, - ipiv, - work.data(), - &lwork, - iwork.data(), - &liwotk, - &info); - assert(0 == info); - - //->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - // (4) U_operator = Denominator * Numerator; - ScalapackConnector::gemm('N', - 'N', - nlocal, - nlocal, - nlocal, - 1.0, - Denominator, - 1, - 1, - this->ParaV->desc, - Numerator, - 1, - 1, - this->ParaV->desc, - 0.0, - U_operator, - 1, - 1, - this->ParaV->desc); - - if (print_matrix) - { - GlobalV::ofs_running << " fenmu^-1:" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - GlobalV::ofs_running << Denominator[i * this->ParaV->ncol + j].real() << "+" - << Denominator[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - GlobalV::ofs_running << " fenzi:" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - GlobalV::ofs_running << Numerator[i * this->ParaV->ncol + j].real() << "+" - << Numerator[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - GlobalV::ofs_running << " U operator:" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - double aa, bb; - aa = U_operator[i * this->ParaV->ncol + j].real(); - bb = U_operator[i * this->ParaV->ncol + j].imag(); - if (abs(aa) < 1e-8) - aa = 0.0; - if (abs(bb) < 1e-8) - bb = 0.0; - GlobalV::ofs_running << aa << "+" << bb << "i "; - } - GlobalV::ofs_running << endl; - } - } - - // cout << "U_operator Success!!!" <* Stmp, - const std::complex* Htmp, - std::complex* U_operator, - const int print_matrix) const -{ - ModuleBase::GlobalFunc::ZEROS(U_operator, this->ParaV->nloc); - complex* A_matrix = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(A_matrix, this->ParaV->nloc); - complex* rank0 = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(rank0, this->ParaV->nloc); - complex* rank2 = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(rank2, this->ParaV->nloc); - complex* rank3 = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(rank3, this->ParaV->nloc); - complex* rank4 = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(rank4, this->ParaV->nloc); - complex* tmp1 = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(tmp1, this->ParaV->nloc); - complex* tmp2 = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(tmp2, this->ParaV->nloc); - complex* Sinv = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(Sinv, this->ParaV->nloc); - BlasConnector::copy(this->ParaV->nloc, Stmp, 1, Sinv, 1); - - if (print_matrix) - { - GlobalV::ofs_running << endl; - GlobalV::ofs_running << " S matrix :" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - GlobalV::ofs_running << Stmp[i * this->ParaV->ncol + j].real() << "+" - << Stmp[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - GlobalV::ofs_running << endl; - GlobalV::ofs_running << " H matrix :" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - GlobalV::ofs_running << Htmp[i * this->ParaV->ncol + j].real() << "+" - << Htmp[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - } - - // set rank0 - int info; - int myid; - MPI_Comm_rank(this->ParaV->comm_2D, &myid); - int naroc[2]; // maximum number of row or column - - for (int iprow = 0; iprow < this->ParaV->dim0; ++iprow) - { - for (int ipcol = 0; ipcol < this->ParaV->dim1; ++ipcol) - { - const int coord[2] = {iprow, ipcol}; - int src_rank; - info = MPI_Cart_rank(this->ParaV->comm_2D, coord, &src_rank); - if (myid == src_rank) - { - naroc[0] = this->ParaV->nrow; - naroc[1] = this->ParaV->ncol; - for (int j = 0; j < naroc[1]; ++j) - { - int igcol = globalIndex(j, this->ParaV->nb, this->ParaV->dim1, ipcol); - if (igcol >= nlocal) - continue; - for (int i = 0; i < naroc[0]; ++i) - { - int igrow = globalIndex(i, this->ParaV->nb, this->ParaV->dim0, iprow); - if (igrow >= nlocal) - continue; - if (igcol == igrow) - { - rank0[j * naroc[0] + i] = {1.0, 0.0}; - } - else - { - rank0[j * naroc[0] + i] = {0.0, 0.0}; - } - } - } - } - } // loop ipcol - } // loop iprow - - // complex beta = {0.0, -0.5 * INPUT.mdp.md_dt}; - complex beta = {0.0, -0.25 * INPUT.mdp.md_dt}; // for ETRS - - //->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - // invert Stmp - int* ipiv = new int[this->ParaV->nloc]; - // (3.1) compute ipiv - ScalapackConnector::getrf(nlocal, nlocal, Sinv, 1, 1, this->ParaV->desc, ipiv, &info); - int lwork = -1; - int liwotk = -1; - std::vector> work(1, 0); - std::vector iwork(1, 0); - // (3.2) compute work - ScalapackConnector::getri(nlocal, - Sinv, - 1, - 1, - this->ParaV->desc, - ipiv, - work.data(), - &lwork, - iwork.data(), - &liwotk, - &info); - lwork = work[0].real(); - work.resize(lwork, 0); - liwotk = iwork[0]; - iwork.resize(liwotk, 0); - ScalapackConnector::getri(nlocal, - Sinv, - 1, - 1, - this->ParaV->desc, - ipiv, - work.data(), - &lwork, - iwork.data(), - &liwotk, - &info); - assert(0 == info); - - //->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - // A_matrix = - idt S^-1 H ; - ScalapackConnector::gemm('N', - 'N', - nlocal, - nlocal, - nlocal, - beta, - Sinv, - 1, - 1, - this->ParaV->desc, - Htmp, - 1, - 1, - this->ParaV->desc, - 0.0, - U_operator, - 1, - 1, - this->ParaV->desc); - - // rank2 = A^2 ; - ScalapackConnector::gemm('N', - 'N', - nlocal, - nlocal, - nlocal, - 1.0, - U_operator, - 1, - 1, - this->ParaV->desc, - U_operator, - 1, - 1, - this->ParaV->desc, - 0.0, - rank2, - 1, - 1, - this->ParaV->desc); - - // rank3 = A^3 ; - ScalapackConnector::gemm('N', - 'N', - nlocal, - nlocal, - nlocal, - 1.0, - U_operator, - 1, - 1, - this->ParaV->desc, - rank2, - 1, - 1, - this->ParaV->desc, - 0.0, - rank3, - 1, - 1, - this->ParaV->desc); - - // rank4 = A^4 ; - ScalapackConnector::gemm('N', - 'N', - nlocal, - nlocal, - nlocal, - 1.0, - U_operator, - 1, - 1, - this->ParaV->desc, - rank3, - 1, - 1, - this->ParaV->desc, - 0.0, - rank4, - 1, - 1, - this->ParaV->desc); - - complex p1 = {1.0, 0.0}; - complex p2 = {1.0 / 2.0, 0.0}; - complex p3 = {1.0 / 6.0, 0.0}; - complex p4 = {1.0 / 24.0, 0.0}; - - ScalapackConnector::geadd('N', - nlocal, - nlocal, - p1, - rank0, - 1, - 1, - this->ParaV->desc, - p1, - U_operator, - 1, - 1, - this->ParaV->desc); - - ScalapackConnector::geadd('N', - nlocal, - nlocal, - p2, - rank2, - 1, - 1, - this->ParaV->desc, - p1, - U_operator, - 1, - 1, - this->ParaV->desc); - - ScalapackConnector::geadd('N', - nlocal, - nlocal, - p3, - rank3, - 1, - 1, - this->ParaV->desc, - p1, - U_operator, - 1, - 1, - this->ParaV->desc); - - ScalapackConnector::geadd('N', - nlocal, - nlocal, - p4, - rank4, - 1, - 1, - this->ParaV->desc, - p1, - U_operator, - 1, - 1, - this->ParaV->desc); - - if (print_matrix) - { - GlobalV::ofs_running << " A_matrix:" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - GlobalV::ofs_running << A_matrix[i * this->ParaV->ncol + j].real() << "+" - << A_matrix[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - GlobalV::ofs_running << " U operator:" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - double aa, bb; - aa = U_operator[i * this->ParaV->ncol + j].real(); - bb = U_operator[i * this->ParaV->ncol + j].imag(); - if (abs(aa) < 1e-8) - aa = 0.0; - if (abs(bb) < 1e-8) - bb = 0.0; - GlobalV::ofs_running << aa << "+" << bb << "i "; - } - GlobalV::ofs_running << endl; - } - } - - // cout << "U_operator Success!!!" <* Stmp, - const std::complex* Htmp, - const std::complex* H_laststep, - std::complex* U_operator, - const int print_matrix) const -{ - complex* U1 = new complex[this->ParaV->nloc]; - complex* U2 = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(U1, this->ParaV->nloc); - ModuleBase::GlobalFunc::ZEROS(U2, this->ParaV->nloc); - compute_U_operator_taylor(nband, nlocal, Stmp, Htmp, U1, print_matrix); - compute_U_operator_taylor(nband, nlocal, Stmp, H_laststep, U2, print_matrix); - ScalapackConnector::gemm('N', - 'N', - nlocal, - nlocal, - nlocal, - 1.0, - U1, - 1, - 1, - this->ParaV->desc, - U2, - 1, - 1, - this->ParaV->desc, - 0.0, - U_operator, - 1, - 1, - this->ParaV->desc); -} - -void Evolve_LCAO_Matrix::U_to_wfc(const int nband, - const int nlocal, - const std::complex* U_operator, - const std::complex* psi_k_laststep, - std::complex* psi_k, - const int print_matrix) const -{ - - ScalapackConnector::gemm('N', - 'N', - nlocal, - nband, - nlocal, - 1.0, - U_operator, - 1, - 1, - this->ParaV->desc, - psi_k_laststep, - 1, - 1, - this->ParaV->desc_wfc, - 0.0, - psi_k, - 1, - 1, - this->ParaV->desc_wfc); - - if (print_matrix) - { - GlobalV::ofs_running << endl; - GlobalV::ofs_running << " psi_k:" << endl; - for (int i = 0; i < this->ParaV->ncol_bands; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - double aa, bb; - aa = psi_k[i * this->ParaV->ncol + j].real(); - bb = psi_k[i * this->ParaV->ncol + j].imag(); - if (abs(aa) < 1e-8) - aa = 0.0; - if (abs(bb) < 1e-8) - bb = 0.0; - GlobalV::ofs_running << aa << "+" << bb << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - GlobalV::ofs_running << " psi_k_laststep:" << endl; - for (int i = 0; i < this->ParaV->ncol_bands; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - double aa, bb; - aa = psi_k_laststep[i * this->ParaV->ncol + j].real(); - bb = psi_k_laststep[i * this->ParaV->ncol + j].imag(); - if (abs(aa) < 1e-8) - aa = 0.0; - if (abs(bb) < 1e-8) - bb = 0.0; - GlobalV::ofs_running << aa << "+" << bb << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - } -} - -void Evolve_LCAO_Matrix::norm_wfc(const int nband, - const int nlocal, - const std::complex* Stmp, - std::complex* psi_k, - const int print_matrix) const -{ - complex* tmp1 = new complex[this->ParaV->nloc_wfc]; - ModuleBase::GlobalFunc::ZEROS(tmp1, this->ParaV->nloc_wfc); - - complex* Cij = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(Cij, this->ParaV->nloc); - - ScalapackConnector::gemm('N', - 'N', - nlocal, - nband, - nlocal, - 1.0, - Stmp, - 1, - 1, - this->ParaV->desc, - psi_k, - 1, - 1, - this->ParaV->desc_wfc, - 0.0, - tmp1, - 1, - 1, - this->ParaV->desc_wfc); - - ScalapackConnector::gemm('C', - 'N', - nband, - nband, - nlocal, - 1.0, - psi_k, - 1, - 1, - this->ParaV->desc_wfc, - tmp1, - 1, - 1, - this->ParaV->desc_wfc, - 0.0, - Cij, - 1, - 1, - this->ParaV->desc_Eij); - - if (print_matrix) - { - GlobalV::ofs_running << "original Cij :" << endl; - for (int i = 0; i < this->ParaV->ncol; i++) - { - for (int j = 0; j < this->ParaV->nrow; j++) - { - double aa, bb; - aa = Cij[i * this->ParaV->ncol + j].real(); - bb = Cij[i * this->ParaV->ncol + j].imag(); - if (abs(aa) < 1e-8) - aa = 0.0; - if (abs(bb) < 1e-8) - bb = 0.0; - GlobalV::ofs_running << aa << "+" << bb << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - } - - int info; - int myid; - MPI_Comm_rank(this->ParaV->comm_2D, &myid); - int naroc[2]; // maximum number of row or column - - for (int iprow = 0; iprow < this->ParaV->dim0; ++iprow) - { - for (int ipcol = 0; ipcol < this->ParaV->dim1; ++ipcol) - { - const int coord[2] = {iprow, ipcol}; - int src_rank; - info = MPI_Cart_rank(this->ParaV->comm_2D, coord, &src_rank); - if (myid == src_rank) - { - naroc[0] = this->ParaV->nrow; - naroc[1] = this->ParaV->ncol; - for (int j = 0; j < naroc[1]; ++j) - { - int igcol = globalIndex(j, this->ParaV->nb, this->ParaV->dim1, ipcol); - if (igcol >= nband) - continue; - for (int i = 0; i < naroc[0]; ++i) - { - int igrow = globalIndex(i, this->ParaV->nb, this->ParaV->dim0, iprow); - if (igrow >= nband) - continue; - if (igcol == igrow) - { - Cij[j * naroc[0] + i] = {1.0 / sqrt(Cij[j * naroc[0] + i].real()), 0.0}; - } - else - { - Cij[j * naroc[0] + i] = {0.0, 0.0}; - } - } - } - } - } // loop ipcol - } // loop iprow - - BlasConnector::copy(this->ParaV->nloc_wfc, psi_k, 1, tmp1, 1); - - ScalapackConnector::gemm('N', - 'N', - nlocal, - nband, - nband, - 1.0, - tmp1, - 1, - 1, - this->ParaV->desc_wfc, - Cij, - 1, - 1, - this->ParaV->desc_Eij, - 0.0, - psi_k, - 1, - 1, - this->ParaV->desc_wfc); - - if (print_matrix) - { - GlobalV::ofs_running << " Cij:" << endl; - for (int i = 0; i < this->ParaV->ncol; i++) - { - for (int j = 0; j < this->ParaV->nrow; j++) - { - GlobalV::ofs_running << Cij[i * this->ParaV->ncol + j].real() << "+" - << Cij[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - GlobalV::ofs_running << endl; - GlobalV::ofs_running << " psi_k:" << endl; - for (int i = 0; i < this->ParaV->ncol_bands; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - double aa, bb; - aa = psi_k[i * this->ParaV->ncol + j].real(); - bb = psi_k[i * this->ParaV->ncol + j].imag(); - if (abs(aa) < 1e-8) - aa = 0.0; - if (abs(bb) < 1e-8) - bb = 0.0; - GlobalV::ofs_running << aa << "+" << bb << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - GlobalV::ofs_running << " psi_k before normalization:" << endl; - for (int i = 0; i < this->ParaV->ncol; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - double aa, bb; - aa = tmp1[i * this->ParaV->ncol + j].real(); - bb = tmp1[i * this->ParaV->ncol + j].imag(); - if (abs(aa) < 1e-8) - aa = 0.0; - if (abs(bb) < 1e-8) - bb = 0.0; - GlobalV::ofs_running << aa << "+" << bb << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - GlobalV::ofs_running << endl; - } - - delete[] tmp1; - delete[] Cij; -} - -void Evolve_LCAO_Matrix::compute_ekb(const int nband, - const int nlocal, - const std::complex* Htmp, - const std::complex* psi_k, - double* ekb) const -{ - - complex* tmp1 = new complex[this->ParaV->nloc_wfc]; - ModuleBase::GlobalFunc::ZEROS(tmp1, this->ParaV->nloc_wfc); - - complex* Eij = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(Eij, this->ParaV->nloc); - - ScalapackConnector::gemm('N', - 'N', - nlocal, - nband, - nlocal, - 1.0, - Htmp, - 1, - 1, - this->ParaV->desc, - psi_k, - 1, - 1, - this->ParaV->desc_wfc, - 0.0, - tmp1, - 1, - 1, - this->ParaV->desc_wfc); - - ScalapackConnector::gemm('C', - 'N', - nband, - nband, - nlocal, - 1.0, - psi_k, - 1, - 1, - this->ParaV->desc_wfc, - tmp1, - 1, - 1, - this->ParaV->desc_wfc, - 0.0, - Eij, - 1, - 1, - this->ParaV->desc_Eij); - - if (ELEC_evolve::td_print_eij > 0.0) - { - GlobalV::ofs_running - << "------------------------------------------------------------------------------------------------" - << endl; - GlobalV::ofs_running << " Eij:" << endl; - for (int i = 0; i < this->ParaV->nrow_bands; i++) - { - for (int j = 0; j < this->ParaV->ncol_bands; j++) - { - double aa, bb; - aa = Eij[i * this->ParaV->ncol + j].real(); - bb = Eij[i * this->ParaV->ncol + j].imag(); - if (abs(aa) < ELEC_evolve::td_print_eij) - aa = 0.0; - if (abs(bb) < ELEC_evolve::td_print_eij) - bb = 0.0; - if (aa > 0.0 || bb > 0.0) - { - GlobalV::ofs_running << i << " " << j << " " << aa << "+" << bb << "i " << endl; - } - } - } - GlobalV::ofs_running << endl; - GlobalV::ofs_running - << "------------------------------------------------------------------------------------------------" - << endl; - } - - int info; - int myid; - int naroc[2]; - MPI_Comm_rank(this->ParaV->comm_2D, &myid); - - double* Eii = new double[nband]; - ModuleBase::GlobalFunc::ZEROS(Eii, nband); - for (int iprow = 0; iprow < this->ParaV->dim0; ++iprow) - { - for (int ipcol = 0; ipcol < this->ParaV->dim1; ++ipcol) - { - const int coord[2] = {iprow, ipcol}; - int src_rank; - info = MPI_Cart_rank(this->ParaV->comm_2D, coord, &src_rank); - if (myid == src_rank) - { - naroc[0] = this->ParaV->nrow; - naroc[1] = this->ParaV->ncol; - for (int j = 0; j < naroc[1]; ++j) - { - int igcol = globalIndex(j, this->ParaV->nb, this->ParaV->dim1, ipcol); - if (igcol >= nband) - continue; - for (int i = 0; i < naroc[0]; ++i) - { - int igrow = globalIndex(i, this->ParaV->nb, this->ParaV->dim0, iprow); - if (igrow >= nband) - continue; - if (igcol == igrow) - { - Eii[igcol] = Eij[j * naroc[0] + i].real(); - } - } - } - } - } // loop ipcol - } // loop iprow - info = MPI_Allreduce(Eii, ekb, nband, MPI_DOUBLE, MPI_SUM, this->ParaV->comm_2D); - - delete[] tmp1; - delete[] Eij; - delete[] Eii; -} - -#endif diff --git a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h b/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h deleted file mode 100644 index bcf470a771..0000000000 --- a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h +++ /dev/null @@ -1,108 +0,0 @@ -#ifndef EVOLVE_LCAO_MATRIX_H -#define EVOLVE_LCAO_MATRIX_H - -#include "module_base/complexmatrix.h" -#include "module_base/global_function.h" -#include "module_base/global_variable.h" -#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" -#include "module_psi/psi.h" -#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h" -#include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_wfc.h" - -class Evolve_LCAO_Matrix -{ - public: - Evolve_LCAO_Matrix(const Parallel_Orbitals* pv) - { - this->ParaV = pv; - } - ~Evolve_LCAO_Matrix(); - - void evolve_complex_matrix(const int& ik, - hamilt::Hamilt* p_hamilt, - psi::Psi>* psi_k, - psi::Psi>* psi_k_laststep, - std::complex* H_laststep, - double* ekb, - int htype, - int propagator) const; - - private: - // LCAO_Matrix* LM; - const Parallel_Orbitals* ParaV; - - void using_LAPACK_complex(const int& ik, - hamilt::Hamilt* p_hamilt, - std::complex* psi_k, - std::complex* psi_k_laststep, - double* ekb) const; -#ifdef __MPI - void using_ScaLAPACK_complex( - const int nband, - const int nlocal, - const std::complex* psi_k_laststep, - const std::complex* H_laststep, - hamilt::Hamilt* p_hamilt, - std::complex* psi_k, - double* ekb, - int htype, - int propagator) const; - - void half_Hmatrix( - const int nband, - const int nlocal, - std::complex* Htmp, - const std::complex* H_laststep, - const int print_matrix) const; - - void compute_U_operator_CN2( - const int nband, - const int nlocal, - const std::complex* Stmp, - const std::complex* Htmp, - std::complex* U_operator, - const int print_matrix) const; - - void compute_U_operator_taylor( - const int nband, - const int nlocal, - const std::complex* Stmp, - const std::complex* Htmp, - std::complex* U_operator, - const int print_matrix) const; - - void compute_U_operator_etrs( - const int nband, - const int nlocal, - const std::complex* Stmp, - const std::complex* Htmp, - const std::complex* H_laststep, - std::complex* U_operator, - const int print_matrix) const; - - void U_to_wfc( - const int nband, - const int nlocal, - const std::complex* U_operator, - const std::complex* psi_k_laststep, - std::complex* psi_k, - const int print_matrix) const; - - void norm_wfc( - const int nband, - const int nlocal, - const std::complex* Stmp, - std::complex* psi_k, - const int print_matrix) const; - - - void compute_ekb( - const int nband, - const int nlocal, - const std::complex* Htmp, - const std::complex* psi_k, - double* ekb) const; - -#endif -}; -#endif diff --git a/source/module_hamilt_lcao/module_tddft/bandenergy.cpp b/source/module_hamilt_lcao/module_tddft/bandenergy.cpp new file mode 100644 index 0000000000..90d25d7dd1 --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/bandenergy.cpp @@ -0,0 +1,147 @@ +#include "bandenergy.h" + +#include +#include + +#include "evolve_elec.h" +#include "module_base/lapack_connector.h" +#include "module_base/scalapack_connector.h" + +#ifdef __MPI + +inline int globalIndex(int localindex, int nblk, int nprocs, int myproc) +{ + int iblock, gIndex; + iblock = localindex / nblk; + gIndex = (iblock * nprocs + myproc) * nblk + localindex % nblk; + return gIndex; +} + +void compute_ekb(const Parallel_Orbitals* pv, + const int nband, + const int nlocal, + const std::complex* Htmp, + const std::complex* psi_k, + double* ekb) +{ + + std::complex* tmp1 = new std::complex[pv->nloc_wfc]; + ModuleBase::GlobalFunc::ZEROS(tmp1, pv->nloc_wfc); + + std::complex* Eij = new std::complex[pv->nloc]; + ModuleBase::GlobalFunc::ZEROS(Eij, pv->nloc); + + ScalapackConnector::gemm('N', + 'N', + nlocal, + nband, + nlocal, + 1.0, + Htmp, + 1, + 1, + pv->desc, + psi_k, + 1, + 1, + pv->desc_wfc, + 0.0, + tmp1, + 1, + 1, + pv->desc_wfc); + + ScalapackConnector::gemm('C', + 'N', + nband, + nband, + nlocal, + 1.0, + psi_k, + 1, + 1, + pv->desc_wfc, + tmp1, + 1, + 1, + pv->desc_wfc, + 0.0, + Eij, + 1, + 1, + pv->desc_Eij); + + if (Evolve_elec::td_print_eij > 0.0) + { + GlobalV::ofs_running + << "------------------------------------------------------------------------------------------------" + << std::endl; + GlobalV::ofs_running << " Eij:" << std::endl; + for (int i = 0; i < pv->nrow_bands; i++) + { + for (int j = 0; j < pv->ncol_bands; j++) + { + double aa, bb; + aa = Eij[i * pv->ncol + j].real(); + bb = Eij[i * pv->ncol + j].imag(); + if (abs(aa) < Evolve_elec::td_print_eij) + aa = 0.0; + if (abs(bb) < Evolve_elec::td_print_eij) + bb = 0.0; + if (aa > 0.0 || bb > 0.0) + { + GlobalV::ofs_running << i << " " << j << " " << aa << "+" << bb << "i " << std::endl; + } + } + } + GlobalV::ofs_running << std::endl; + GlobalV::ofs_running + << "------------------------------------------------------------------------------------------------" + << std::endl; + } + + int info; + int myid; + int naroc[2]; + MPI_Comm_rank(pv->comm_2D, &myid); + + double* Eii = new double[nband]; + ModuleBase::GlobalFunc::ZEROS(Eii, nband); + for (int iprow = 0; iprow < pv->dim0; ++iprow) + { + for (int ipcol = 0; ipcol < pv->dim1; ++ipcol) + { + const int coord[2] = {iprow, ipcol}; + int src_rank; + info = MPI_Cart_rank(pv->comm_2D, coord, &src_rank); + if (myid == src_rank) + { + naroc[0] = pv->nrow; + naroc[1] = pv->ncol; + for (int j = 0; j < naroc[1]; ++j) + { + int igcol = globalIndex(j, pv->nb, pv->dim1, ipcol); + if (igcol >= nband) + continue; + for (int i = 0; i < naroc[0]; ++i) + { + int igrow = globalIndex(i, pv->nb, pv->dim0, iprow); + if (igrow >= nband) + continue; + if (igcol == igrow) + { + Eii[igcol] = Eij[j * naroc[0] + i].real(); + } + } + } + } + } // loop ipcol + } // loop iprow + info = MPI_Allreduce(Eii, ekb, nband, MPI_DOUBLE, MPI_SUM, pv->comm_2D); + + delete[] tmp1; + delete[] Eij; + delete[] Eii; +} + +#endif diff --git a/source/module_hamilt_lcao/module_tddft/bandenergy.h b/source/module_hamilt_lcao/module_tddft/bandenergy.h new file mode 100644 index 0000000000..292b5efd5e --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/bandenergy.h @@ -0,0 +1,15 @@ +#ifndef BANDENERGY_H +#define BANDENERGY_H + +#include "module_basis/module_ao/parallel_orbitals.h" + +#ifdef __MPI +void compute_ekb(const Parallel_Orbitals* pv, + const int nband, + const int nlocal, + const std::complex* Htmp, + const std::complex* psi_k, + double* ekb); +#endif + +#endif \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_tddft/evolve_elec.cpp b/source/module_hamilt_lcao/module_tddft/evolve_elec.cpp new file mode 100644 index 0000000000..181709a5e7 --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/evolve_elec.cpp @@ -0,0 +1,81 @@ +#include "evolve_elec.h" + +#include "evolve_psi.h" +#include "module_base/parallel_reduce.h" +#include "module_base/timer.h" +#include "module_elecstate/module_charge/symmetry_rho.h" +#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" +#include "module_hamilt_lcao/module_dftu/dftu.h" +#include "module_hamilt_pw/hamilt_pwdft/global.h" + +Evolve_elec::Evolve_elec(){}; +Evolve_elec::~Evolve_elec(){}; + +double Evolve_elec::td_force_dt; +bool Evolve_elec::td_vext; +std::vector Evolve_elec::td_vext_dire_case; +bool Evolve_elec::out_dipole; +bool Evolve_elec::out_efield; +double Evolve_elec::td_print_eij; // the threshold to output Eij elements +int Evolve_elec::td_edm; // 0: new edm method 1: old edm method + +// this routine only serves for TDDFT using LCAO basis set +void Evolve_elec::solve_psi(const int& istep, + const int nband, + const int nlocal, + hamilt::Hamilt* phm, + Local_Orbital_wfc& lowf, + psi::Psi>* psi, + psi::Psi>* psi_laststep, + std::complex** Hk_laststep, + ModuleBase::matrix& ekb, + int htype, + int propagator) +{ + ModuleBase::TITLE("Evolve_elec", "eveolve_psi"); + ModuleBase::timer::tick("Evolve_elec", "evolve_psi"); + + for (int ik = 0; ik < GlobalC::kv.nks; ik++) + { + phm->updateHk(ik); + + ModuleBase::timer::tick("Efficience", "evolve_k"); + psi->fix_k(ik); + psi_laststep->fix_k(ik); + if (htype == 0) + { + evolve_psi(nband, + nlocal, + lowf.ParaV, + phm, + psi[0].get_pointer(), + psi_laststep[0].get_pointer(), + nullptr, + &(ekb(ik, 0)), + htype, + propagator); + } + else if (htype == 1) + { + evolve_psi(nband, + nlocal, + lowf.ParaV, + phm, + psi[0].get_pointer(), + psi_laststep[0].get_pointer(), + Hk_laststep[ik], + &(ekb(ik, 0)), + htype, + propagator); + } + else + { + std::cout << "method of htype is wrong" << std::endl; + } + + ModuleBase::timer::tick("Efficience", "evolve_k"); + } // end k + + ModuleBase::timer::tick("Evolve_elec", "evolve_psi"); + return; +} diff --git a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.h b/source/module_hamilt_lcao/module_tddft/evolve_elec.h similarity index 58% rename from source/module_hamilt_lcao/module_tddft/ELEC_evolve.h rename to source/module_hamilt_lcao/module_tddft/evolve_elec.h index dfa2b904eb..ed2e96d97b 100644 --- a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.h +++ b/source/module_hamilt_lcao/module_tddft/evolve_elec.h @@ -1,13 +1,13 @@ -#ifndef ELEC_EVOLVE_H -#define ELEC_EVOLVE_H +#ifndef EVOLVE_ELEC_H +#define EVOLVE_ELEC_H #include "module_base/global_function.h" #include "module_base/global_variable.h" -#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.h" #include "module_esolver/esolver_ks_lcao.h" #include "module_esolver/esolver_ks_lcao_tddft.h" -#include "module_psi/psi.h" +#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.h" #include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" +#include "module_psi/psi.h" //----------------------------------------------------------- // mohan add 2021-02-09 @@ -16,7 +16,7 @@ // k is the index for the points in the first Brillouin zone //----------------------------------------------------------- -class ELEC_evolve +class Evolve_elec { friend class ELEC_scf; @@ -24,10 +24,8 @@ class ELEC_evolve friend class ModuleESolver::ESolver_KS_LCAO_TDDFT; public: - ELEC_evolve(); - ~ELEC_evolve(); - - // fuxiang add 2021-05-25 + Evolve_elec(); + ~Evolve_elec(); static double td_force_dt; static bool td_vext; @@ -36,18 +34,20 @@ class ELEC_evolve static bool out_efield; static double td_print_eij; // the threshold to output Eij elements - static int td_edm; // 0: new edm method 1: old edm method + static int td_edm; // 0: new edm method 1: old edm method private: - static void evolve_psi(const int& istep, - hamilt::Hamilt* phm, - Local_Orbital_wfc& lowf, - psi::Psi>* psi, - psi::Psi>* psi_laststep, - std::complex** Hk_laststep, - ModuleBase::matrix& ekb, - int htype, - int propagator); + static void solve_psi(const int& istep, + const int nband, + const int nlocal, + hamilt::Hamilt* phm, + Local_Orbital_wfc& lowf, + psi::Psi>* psi, + psi::Psi>* psi_laststep, + std::complex** Hk_laststep, + ModuleBase::matrix& ekb, + int htype, + int propagator); }; #endif diff --git a/source/module_hamilt_lcao/module_tddft/evolve_psi.cpp b/source/module_hamilt_lcao/module_tddft/evolve_psi.cpp new file mode 100644 index 0000000000..975ceb2032 --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/evolve_psi.cpp @@ -0,0 +1,102 @@ +#include "evolve_psi.h" + +#include + +#include "bandenergy.h" +#include "middle_hamilt.h" +#include "module_base/lapack_connector.h" +#include "module_base/scalapack_connector.h" +#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" +#include "module_hamilt_pw/hamilt_pwdft/global.h" +#include "module_io/input.h" +#include "norm_psi.h" +#include "propagator.h" +#include "upsi.h" + +void evolve_psi(const int nband, + const int nlocal, + const Parallel_Orbitals* pv, + hamilt::Hamilt* p_hamilt, + std::complex* psi_k, + std::complex* psi_k_laststep, + std::complex* H_laststep, + double* ekb, + int htype, + int propagator) +{ + ModuleBase::TITLE("Evolve_psi", "evolve_psi"); + time_t time_start = time(NULL); + GlobalV::ofs_running << " Start Time : " << ctime(&time_start); + +#ifdef __MPI + + int print_matrix = 0; + hamilt::MatrixBlock> h_mat, s_mat; + p_hamilt->matrix(h_mat, s_mat); + + std::complex* Stmp = new std::complex[pv->nloc]; + ModuleBase::GlobalFunc::ZEROS(Stmp, pv->nloc); + BlasConnector::copy(pv->nloc, s_mat.p, 1, Stmp, 1); + + std::complex* Htmp = new std::complex[pv->nloc]; + ModuleBase::GlobalFunc::ZEROS(Htmp, pv->nloc); + BlasConnector::copy(pv->nloc, h_mat.p, 1, Htmp, 1); + + std::complex* Hold = new std::complex[pv->nloc]; + ModuleBase::GlobalFunc::ZEROS(Hold, pv->nloc); + BlasConnector::copy(pv->nloc, h_mat.p, 1, Hold, 1); + + std::complex* U_operator = new std::complex[pv->nloc]; + ModuleBase::GlobalFunc::ZEROS(U_operator, pv->nloc); + + // (1)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + /// @brief compute H(t+dt/2) + /// @input H_laststep, Htmp, print_matrix + /// @output Htmp + if (htype == 1 && propagator != 2) + { + half_Hmatrix(pv, nband, nlocal, Htmp, H_laststep, print_matrix); + } + + // (2)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + /// @brief compute U_operator + /// @input Stmp, Htmp, print_matrix + /// @output U_operator + Propagator prop(propagator, pv); + prop.compute_propagator(nband, nlocal, Stmp, Htmp, H_laststep, U_operator, print_matrix); + + // (3)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + /// @brief apply U_operator to the wave function of the previous step for new wave function + /// @input U_operator, psi_k_laststep, print_matrix + /// @output psi_k + upsi(pv, nband, nlocal, U_operator, psi_k_laststep, psi_k, print_matrix); + + // (4)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + /// @brief normalize psi_k + /// @input Stmp, psi_not_norm, psi_k, print_matrix + /// @output psi_k + norm_psi(pv, nband, nlocal, Stmp, psi_k, print_matrix); + + // (5)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + /// @brief compute ekb + /// @input Htmp, psi_k + /// @output ekb + compute_ekb(pv, nband, nlocal, Hold, psi_k, ekb); + + delete[] Stmp; + delete[] Htmp; + delete[] Hold; + delete[] U_operator; + +#endif + + time_t time_end = time(NULL); + ModuleBase::GlobalFunc::OUT_TIME("evolve(std::complex)", time_start, time_end); + + return; +} diff --git a/source/module_hamilt_lcao/module_tddft/evolve_psi.h b/source/module_hamilt_lcao/module_tddft/evolve_psi.h new file mode 100644 index 0000000000..e31f2d8e89 --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/evolve_psi.h @@ -0,0 +1,18 @@ +#ifndef ELEC_PSI_H +#define ELEC_PSI_H + +#include "module_basis/module_ao/parallel_orbitals.h" +#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" + +void evolve_psi(const int nband, + const int nlocal, + const Parallel_Orbitals* pv, + hamilt::Hamilt* p_hamilt, + std::complex* psi_k, + std::complex* psi_k_laststep, + std::complex* H_laststep, + double* ekb, + int htype, + int propagator); + +#endif \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_tddft/middle_hamilt.cpp b/source/module_hamilt_lcao/module_tddft/middle_hamilt.cpp new file mode 100644 index 0000000000..3b437c8214 --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/middle_hamilt.cpp @@ -0,0 +1,65 @@ +#include "middle_hamilt.h" + +#include +#include + +#include "module_base/lapack_connector.h" +#include "module_base/scalapack_connector.h" + +#ifdef __MPI + +void half_Hmatrix(const Parallel_Orbitals* pv, + const int nband, + const int nlocal, + std::complex* Htmp, + const std::complex* H_laststep, + const int print_matrix) +{ + if (print_matrix) + { + GlobalV::ofs_running << std::setprecision(10); + GlobalV::ofs_running << std::endl; + GlobalV::ofs_running << " H(t+dt) :" << std::endl; + for (int i = 0; i < pv->nrow; i++) + { + for (int j = 0; j < pv->ncol; j++) + { + GlobalV::ofs_running << Htmp[i * pv->ncol + j].real() << "+" << Htmp[i * pv->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << std::endl; + } + GlobalV::ofs_running << std::endl; + GlobalV::ofs_running << std::endl; + GlobalV::ofs_running << " H(t):" << std::endl; + for (int i = 0; i < pv->nrow; i++) + { + for (int j = 0; j < pv->ncol; j++) + { + GlobalV::ofs_running << H_laststep[i * pv->ncol + j].real() << "+" + << H_laststep[i * pv->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << std::endl; + } + GlobalV::ofs_running << std::endl; + } + + std::complex alpha = {0.5, 0.0}; + std::complex beta = {0.5, 0.0}; + ScalapackConnector::geadd('N', nlocal, nlocal, alpha, H_laststep, 1, 1, pv->desc, beta, Htmp, 1, 1, pv->desc); + + if (print_matrix) + { + GlobalV::ofs_running << std::endl; + GlobalV::ofs_running << " H (t+dt/2) :" << std::endl; + for (int i = 0; i < pv->nrow; i++) + { + for (int j = 0; j < pv->ncol; j++) + { + GlobalV::ofs_running << Htmp[i * pv->ncol + j].real() << "+" << Htmp[i * pv->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << std::endl; + } + GlobalV::ofs_running << std::endl; + } +} +#endif diff --git a/source/module_hamilt_lcao/module_tddft/middle_hamilt.h b/source/module_hamilt_lcao/module_tddft/middle_hamilt.h new file mode 100644 index 0000000000..2dcf92495e --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/middle_hamilt.h @@ -0,0 +1,15 @@ +#ifndef MIDDLE_HAMILT_H +#define MIDDLE_HAMILT_H + +#include "module_basis/module_ao/parallel_orbitals.h" + +#ifdef __MPI +void half_Hmatrix(const Parallel_Orbitals* pv, + const int nband, + const int nlocal, + std::complex* Htmp, + const std::complex* H_laststep, + const int print_matrix); +#endif + +#endif \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_tddft/norm_psi.cpp b/source/module_hamilt_lcao/module_tddft/norm_psi.cpp new file mode 100644 index 0000000000..492ed3465f --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/norm_psi.cpp @@ -0,0 +1,208 @@ +#include "norm_psi.h" + +#include +#include + +#include "module_base/lapack_connector.h" +#include "module_base/scalapack_connector.h" + +#ifdef __MPI + +inline int globalIndex(int localindex, int nblk, int nprocs, int myproc) +{ + int iblock, gIndex; + iblock = localindex / nblk; + gIndex = (iblock * nprocs + myproc) * nblk + localindex % nblk; + return gIndex; +} + +void norm_psi(const Parallel_Orbitals* pv, + const int nband, + const int nlocal, + const std::complex* Stmp, + std::complex* psi_k, + const int print_matrix) +{ + std::complex* tmp1 = new std::complex[pv->nloc_wfc]; + ModuleBase::GlobalFunc::ZEROS(tmp1, pv->nloc_wfc); + + std::complex* Cij = new std::complex[pv->nloc]; + ModuleBase::GlobalFunc::ZEROS(Cij, pv->nloc); + + ScalapackConnector::gemm('N', + 'N', + nlocal, + nband, + nlocal, + 1.0, + Stmp, + 1, + 1, + pv->desc, + psi_k, + 1, + 1, + pv->desc_wfc, + 0.0, + tmp1, + 1, + 1, + pv->desc_wfc); + + ScalapackConnector::gemm('C', + 'N', + nband, + nband, + nlocal, + 1.0, + psi_k, + 1, + 1, + pv->desc_wfc, + tmp1, + 1, + 1, + pv->desc_wfc, + 0.0, + Cij, + 1, + 1, + pv->desc_Eij); + + if (print_matrix) + { + GlobalV::ofs_running << "original Cij :" << std::endl; + for (int i = 0; i < pv->ncol; i++) + { + for (int j = 0; j < pv->nrow; j++) + { + double aa, bb; + aa = Cij[i * pv->ncol + j].real(); + bb = Cij[i * pv->ncol + j].imag(); + if (abs(aa) < 1e-8) + aa = 0.0; + if (abs(bb) < 1e-8) + bb = 0.0; + GlobalV::ofs_running << aa << "+" << bb << "i "; + } + GlobalV::ofs_running << std::endl; + } + GlobalV::ofs_running << std::endl; + } + + int info; + int myid; + MPI_Comm_rank(pv->comm_2D, &myid); + int naroc[2]; // maximum number of row or column + + for (int iprow = 0; iprow < pv->dim0; ++iprow) + { + for (int ipcol = 0; ipcol < pv->dim1; ++ipcol) + { + const int coord[2] = {iprow, ipcol}; + int src_rank; + info = MPI_Cart_rank(pv->comm_2D, coord, &src_rank); + if (myid == src_rank) + { + naroc[0] = pv->nrow; + naroc[1] = pv->ncol; + for (int j = 0; j < naroc[1]; ++j) + { + int igcol = globalIndex(j, pv->nb, pv->dim1, ipcol); + if (igcol >= nband) + continue; + for (int i = 0; i < naroc[0]; ++i) + { + int igrow = globalIndex(i, pv->nb, pv->dim0, iprow); + if (igrow >= nband) + continue; + if (igcol == igrow) + { + Cij[j * naroc[0] + i] = {1.0 / sqrt(Cij[j * naroc[0] + i].real()), 0.0}; + } + else + { + Cij[j * naroc[0] + i] = {0.0, 0.0}; + } + } + } + } + } // loop ipcol + } // loop iprow + + BlasConnector::copy(pv->nloc_wfc, psi_k, 1, tmp1, 1); + + ScalapackConnector::gemm('N', + 'N', + nlocal, + nband, + nband, + 1.0, + tmp1, + 1, + 1, + pv->desc_wfc, + Cij, + 1, + 1, + pv->desc_Eij, + 0.0, + psi_k, + 1, + 1, + pv->desc_wfc); + + if (print_matrix) + { + GlobalV::ofs_running << " Cij:" << std::endl; + for (int i = 0; i < pv->ncol; i++) + { + for (int j = 0; j < pv->nrow; j++) + { + GlobalV::ofs_running << Cij[i * pv->ncol + j].real() << "+" << Cij[i * pv->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << std::endl; + } + GlobalV::ofs_running << std::endl; + GlobalV::ofs_running << std::endl; + GlobalV::ofs_running << " psi_k:" << std::endl; + for (int i = 0; i < pv->ncol_bands; i++) + { + for (int j = 0; j < pv->ncol; j++) + { + double aa, bb; + aa = psi_k[i * pv->ncol + j].real(); + bb = psi_k[i * pv->ncol + j].imag(); + if (abs(aa) < 1e-8) + aa = 0.0; + if (abs(bb) < 1e-8) + bb = 0.0; + GlobalV::ofs_running << aa << "+" << bb << "i "; + } + GlobalV::ofs_running << std::endl; + } + GlobalV::ofs_running << std::endl; + GlobalV::ofs_running << " psi_k before normalization:" << std::endl; + for (int i = 0; i < pv->ncol; i++) + { + for (int j = 0; j < pv->ncol; j++) + { + double aa, bb; + aa = tmp1[i * pv->ncol + j].real(); + bb = tmp1[i * pv->ncol + j].imag(); + if (abs(aa) < 1e-8) + aa = 0.0; + if (abs(bb) < 1e-8) + bb = 0.0; + GlobalV::ofs_running << aa << "+" << bb << "i "; + } + GlobalV::ofs_running << std::endl; + } + GlobalV::ofs_running << std::endl; + GlobalV::ofs_running << std::endl; + } + + delete[] tmp1; + delete[] Cij; +} +#endif diff --git a/source/module_hamilt_lcao/module_tddft/norm_psi.h b/source/module_hamilt_lcao/module_tddft/norm_psi.h new file mode 100644 index 0000000000..c195edc64b --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/norm_psi.h @@ -0,0 +1,16 @@ +#ifndef NORM_PSI_H +#define NORM_PSI_H + +#include "module_basis/module_ao/parallel_orbitals.h" + +#ifdef __MPI +void norm_psi(const Parallel_Orbitals* pv, + const int nband, + const int nlocal, + const std::complex* Stmp, + std::complex* psi_k, + const int print_matrix); + +#endif + +#endif \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_tddft/propagator.cpp b/source/module_hamilt_lcao/module_tddft/propagator.cpp new file mode 100644 index 0000000000..1a1d12fed0 --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/propagator.cpp @@ -0,0 +1,616 @@ +#include "propagator.h" + +#include +#include + +#include "module_base/lapack_connector.h" +#include "module_base/scalapack_connector.h" +#include "module_io/input.h" + +Propagator::~Propagator() +{ +} + +#ifdef __MPI + +inline int globalIndex(int localindex, int nblk, int nprocs, int myproc) +{ + int iblock, gIndex; + iblock = localindex / nblk; + gIndex = (iblock * nprocs + myproc) * nblk + localindex % nblk; + return gIndex; +} + +void Propagator::compute_propagator(const int nband, + const int nlocal, + const std::complex* Stmp, + const std::complex* Htmp, + const std::complex* H_laststep, + std::complex* U_operator, + const int print_matrix) const +{ + switch (ptype) + { + case 0: + compute_propagator_cn2(nband, nlocal, Stmp, Htmp, U_operator, print_matrix); + break; + + case 1: + int tag = 1; + compute_propagator_taylor(nband, nlocal, Stmp, Htmp, U_operator, print_matrix, tag); + break; + + case 2: + compute_propagator_etrs(nband, nlocal, Stmp, Htmp, H_laststep, U_operator, print_matrix); + + break; + + default: + std::cout << "method of propagator is wrong" << std::endl; + break; + } +} + +void Propagator::compute_propagator_cn2(const int nband, + const int nlocal, + const std::complex* Stmp, + const std::complex* Htmp, + std::complex* U_operator, + const int print_matrix) const +{ + // (1) copy Htmp to Numerator & Denominator + std::complex* Numerator = new std::complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(Numerator, this->ParaV->nloc); + BlasConnector::copy(this->ParaV->nloc, Htmp, 1, Numerator, 1); + + std::complex* Denominator = new std::complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(Denominator, this->ParaV->nloc); + BlasConnector::copy(this->ParaV->nloc, Htmp, 1, Denominator, 1); + + if (print_matrix) + { + GlobalV::ofs_running << std::endl; + GlobalV::ofs_running << " S matrix :" << std::endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Stmp[i * this->ParaV->ncol + j].real() << "+" + << Stmp[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << std::endl; + } + GlobalV::ofs_running << std::endl; + GlobalV::ofs_running << std::endl; + GlobalV::ofs_running << " H matrix :" << std::endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Numerator[i * this->ParaV->ncol + j].real() << "+" + << Numerator[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << std::endl; + } + GlobalV::ofs_running << std::endl; + } + + // ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + // (2) compute Numerator & Denominator by GEADD + // Numerator = Stmp - i*para * Htmp; beta1 = - para = -0.25 * INPUT.mdp.md_dt + // Denominator = Stmp + i*para * Htmp; beta2 = para = 0.25 * INPUT.mdp.md_dt + std::complex alpha = {1.0, 0.0}; + std::complex beta1 = {0.0, -0.25 * INPUT.mdp.md_dt}; + std::complex beta2 = {0.0, 0.25 * INPUT.mdp.md_dt}; + + ScalapackConnector::geadd('N', + nlocal, + nlocal, + alpha, + Stmp, + 1, + 1, + this->ParaV->desc, + beta1, + Numerator, + 1, + 1, + this->ParaV->desc); + ScalapackConnector::geadd('N', + nlocal, + nlocal, + alpha, + Stmp, + 1, + 1, + this->ParaV->desc, + beta2, + Denominator, + 1, + 1, + this->ParaV->desc); + + if (print_matrix) + { + GlobalV::ofs_running << " beta=" << beta1 << std::endl; + GlobalV::ofs_running << " fenmu:" << std::endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Denominator[i * this->ParaV->ncol + j].real() << "+" + << Denominator[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << std::endl; + } + GlobalV::ofs_running << std::endl; + } + + //->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + // (3) Next, invert Denominator + int* ipiv = new int[this->ParaV->nloc]; + int info = 0; + // (3.1) compute ipiv + ScalapackConnector::getrf(nlocal, nlocal, Denominator, 1, 1, this->ParaV->desc, ipiv, &info); + int lwork = -1; + int liwotk = -1; + std::vector> work(1, 0); + std::vector iwork(1, 0); + // (3.2) compute work + ScalapackConnector::getri(nlocal, + Denominator, + 1, + 1, + this->ParaV->desc, + ipiv, + work.data(), + &lwork, + iwork.data(), + &liwotk, + &info); + lwork = work[0].real(); + work.resize(lwork, 0); + liwotk = iwork[0]; + iwork.resize(liwotk, 0); + // (3.3) compute inverse matrix of Denominator + ScalapackConnector::getri(nlocal, + Denominator, + 1, + 1, + this->ParaV->desc, + ipiv, + work.data(), + &lwork, + iwork.data(), + &liwotk, + &info); + assert(0 == info); + + //->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + // (4) U_operator = Denominator * Numerator; + ScalapackConnector::gemm('N', + 'N', + nlocal, + nlocal, + nlocal, + 1.0, + Denominator, + 1, + 1, + this->ParaV->desc, + Numerator, + 1, + 1, + this->ParaV->desc, + 0.0, + U_operator, + 1, + 1, + this->ParaV->desc); + + if (print_matrix) + { + GlobalV::ofs_running << " fenmu^-1:" << std::endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Denominator[i * this->ParaV->ncol + j].real() << "+" + << Denominator[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << std::endl; + } + GlobalV::ofs_running << std::endl; + GlobalV::ofs_running << " fenzi:" << std::endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Numerator[i * this->ParaV->ncol + j].real() << "+" + << Numerator[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << std::endl; + } + GlobalV::ofs_running << std::endl; + GlobalV::ofs_running << " U operator:" << std::endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + double aa, bb; + aa = U_operator[i * this->ParaV->ncol + j].real(); + bb = U_operator[i * this->ParaV->ncol + j].imag(); + if (abs(aa) < 1e-8) + aa = 0.0; + if (abs(bb) < 1e-8) + bb = 0.0; + GlobalV::ofs_running << aa << "+" << bb << "i "; + } + GlobalV::ofs_running << std::endl; + } + } + + delete[] Numerator; + delete[] Denominator; + delete[] ipiv; +} + +void Propagator::compute_propagator_taylor(const int nband, + const int nlocal, + const std::complex* Stmp, + const std::complex* Htmp, + std::complex* U_operator, + const int print_matrix, + const int tag) const +{ + ModuleBase::GlobalFunc::ZEROS(U_operator, this->ParaV->nloc); + std::complex* A_matrix = new std::complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(A_matrix, this->ParaV->nloc); + std::complex* rank0 = new std::complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(rank0, this->ParaV->nloc); + std::complex* rank2 = new std::complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(rank2, this->ParaV->nloc); + std::complex* rank3 = new std::complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(rank3, this->ParaV->nloc); + std::complex* rank4 = new std::complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(rank4, this->ParaV->nloc); + std::complex* tmp1 = new std::complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(tmp1, this->ParaV->nloc); + std::complex* tmp2 = new std::complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(tmp2, this->ParaV->nloc); + std::complex* Sinv = new std::complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(Sinv, this->ParaV->nloc); + BlasConnector::copy(this->ParaV->nloc, Stmp, 1, Sinv, 1); + + if (print_matrix) + { + GlobalV::ofs_running << std::endl; + GlobalV::ofs_running << " S matrix :" << std::endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Stmp[i * this->ParaV->ncol + j].real() << "+" + << Stmp[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << std::endl; + } + GlobalV::ofs_running << std::endl; + GlobalV::ofs_running << std::endl; + GlobalV::ofs_running << " H matrix :" << std::endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Htmp[i * this->ParaV->ncol + j].real() << "+" + << Htmp[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << std::endl; + } + GlobalV::ofs_running << std::endl; + } + + // set rank0 + int info; + int myid; + MPI_Comm_rank(this->ParaV->comm_2D, &myid); + int naroc[2]; // maximum number of row or column + + for (int iprow = 0; iprow < this->ParaV->dim0; ++iprow) + { + for (int ipcol = 0; ipcol < this->ParaV->dim1; ++ipcol) + { + const int coord[2] = {iprow, ipcol}; + int src_rank; + info = MPI_Cart_rank(this->ParaV->comm_2D, coord, &src_rank); + if (myid == src_rank) + { + naroc[0] = this->ParaV->nrow; + naroc[1] = this->ParaV->ncol; + for (int j = 0; j < naroc[1]; ++j) + { + int igcol = globalIndex(j, this->ParaV->nb, this->ParaV->dim1, ipcol); + if (igcol >= nlocal) + continue; + for (int i = 0; i < naroc[0]; ++i) + { + int igrow = globalIndex(i, this->ParaV->nb, this->ParaV->dim0, iprow); + if (igrow >= nlocal) + continue; + if (igcol == igrow) + { + rank0[j * naroc[0] + i] = {1.0, 0.0}; + } + else + { + rank0[j * naroc[0] + i] = {0.0, 0.0}; + } + } + } + } + } // loop ipcol + } // loop iprow + + std::complex beta = {0.0, -0.5 * INPUT.mdp.md_dt / tag}; // for ETRS tag=2 , for taylor tag=1 + + //->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + // invert Stmp + int* ipiv = new int[this->ParaV->nloc]; + // (3.1) compute ipiv + ScalapackConnector::getrf(nlocal, nlocal, Sinv, 1, 1, this->ParaV->desc, ipiv, &info); + int lwork = -1; + int liwotk = -1; + std::vector> work(1, 0); + std::vector iwork(1, 0); + // (3.2) compute work + ScalapackConnector::getri(nlocal, + Sinv, + 1, + 1, + this->ParaV->desc, + ipiv, + work.data(), + &lwork, + iwork.data(), + &liwotk, + &info); + lwork = work[0].real(); + work.resize(lwork, 0); + liwotk = iwork[0]; + iwork.resize(liwotk, 0); + ScalapackConnector::getri(nlocal, + Sinv, + 1, + 1, + this->ParaV->desc, + ipiv, + work.data(), + &lwork, + iwork.data(), + &liwotk, + &info); + assert(0 == info); + + // A_matrix = - idt S^-1 H ; + ScalapackConnector::gemm('N', + 'N', + nlocal, + nlocal, + nlocal, + beta, + Sinv, + 1, + 1, + this->ParaV->desc, + Htmp, + 1, + 1, + this->ParaV->desc, + 0.0, + U_operator, + 1, + 1, + this->ParaV->desc); + + // rank2 = A^2 ; + ScalapackConnector::gemm('N', + 'N', + nlocal, + nlocal, + nlocal, + 1.0, + U_operator, + 1, + 1, + this->ParaV->desc, + U_operator, + 1, + 1, + this->ParaV->desc, + 0.0, + rank2, + 1, + 1, + this->ParaV->desc); + + // rank3 = A^3 ; + ScalapackConnector::gemm('N', + 'N', + nlocal, + nlocal, + nlocal, + 1.0, + U_operator, + 1, + 1, + this->ParaV->desc, + rank2, + 1, + 1, + this->ParaV->desc, + 0.0, + rank3, + 1, + 1, + this->ParaV->desc); + + // rank4 = A^4 ; + ScalapackConnector::gemm('N', + 'N', + nlocal, + nlocal, + nlocal, + 1.0, + U_operator, + 1, + 1, + this->ParaV->desc, + rank3, + 1, + 1, + this->ParaV->desc, + 0.0, + rank4, + 1, + 1, + this->ParaV->desc); + + std::complex p1 = {1.0, 0.0}; + std::complex p2 = {1.0 / 2.0, 0.0}; + std::complex p3 = {1.0 / 6.0, 0.0}; + std::complex p4 = {1.0 / 24.0, 0.0}; + + ScalapackConnector::geadd('N', + nlocal, + nlocal, + p1, + rank0, + 1, + 1, + this->ParaV->desc, + p1, + U_operator, + 1, + 1, + this->ParaV->desc); + + ScalapackConnector::geadd('N', + nlocal, + nlocal, + p2, + rank2, + 1, + 1, + this->ParaV->desc, + p1, + U_operator, + 1, + 1, + this->ParaV->desc); + + ScalapackConnector::geadd('N', + nlocal, + nlocal, + p3, + rank3, + 1, + 1, + this->ParaV->desc, + p1, + U_operator, + 1, + 1, + this->ParaV->desc); + + ScalapackConnector::geadd('N', + nlocal, + nlocal, + p4, + rank4, + 1, + 1, + this->ParaV->desc, + p1, + U_operator, + 1, + 1, + this->ParaV->desc); + + if (print_matrix) + { + GlobalV::ofs_running << " A_matrix:" << std::endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << A_matrix[i * this->ParaV->ncol + j].real() << "+" + << A_matrix[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << std::endl; + } + GlobalV::ofs_running << std::endl; + GlobalV::ofs_running << " U operator:" << std::endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + double aa, bb; + aa = U_operator[i * this->ParaV->ncol + j].real(); + bb = U_operator[i * this->ParaV->ncol + j].imag(); + if (abs(aa) < 1e-8) + aa = 0.0; + if (abs(bb) < 1e-8) + bb = 0.0; + GlobalV::ofs_running << aa << "+" << bb << "i "; + } + GlobalV::ofs_running << std::endl; + } + } + + delete[] rank0; + delete[] rank2; + delete[] rank3; + delete[] rank4; + delete[] tmp1; + delete[] tmp2; + delete[] ipiv; +} + +void Propagator::compute_propagator_etrs(const int nband, + const int nlocal, + const std::complex* Stmp, + const std::complex* Htmp, + const std::complex* H_laststep, + std::complex* U_operator, + const int print_matrix) const +{ + std::complex* U1 = new std::complex[this->ParaV->nloc]; + std::complex* U2 = new std::complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(U1, this->ParaV->nloc); + ModuleBase::GlobalFunc::ZEROS(U2, this->ParaV->nloc); + int tag = 2; + compute_propagator_taylor(nband, nlocal, Stmp, Htmp, U1, print_matrix, tag); + compute_propagator_taylor(nband, nlocal, Stmp, H_laststep, U2, print_matrix, tag); + ScalapackConnector::gemm('N', + 'N', + nlocal, + nlocal, + nlocal, + 1.0, + U1, + 1, + 1, + this->ParaV->desc, + U2, + 1, + 1, + this->ParaV->desc, + 0.0, + U_operator, + 1, + 1, + this->ParaV->desc); +} + +#endif \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_tddft/propagator.h b/source/module_hamilt_lcao/module_tddft/propagator.h new file mode 100644 index 0000000000..f52fb5f193 --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/propagator.h @@ -0,0 +1,57 @@ +#ifndef PROPAGATOR_H +#define PROPAGATOR_H + +#include "module_basis/module_ao/parallel_orbitals.h" + +class Propagator +{ + public: + Propagator(const int ptype, const Parallel_Orbitals* pv) + { + this->ptype = ptype; + this->ParaV = pv; + } + ~Propagator(); + +#ifdef __MPI + void compute_propagator(const int nband, + const int nlocal, + const std::complex* Stmp, + const std::complex* Htmp, + const std::complex* H_laststep, + std::complex* U_operator, + const int print_matrix) const; +#endif + + private: + int ptype; // type of propagator + const Parallel_Orbitals* ParaV; + +#ifdef __MPI + + void compute_propagator_cn2(const int nband, + const int nlocal, + const std::complex* Stmp, + const std::complex* Htmp, + std::complex* U_operator, + const int print_matrix) const; + + void compute_propagator_taylor(const int nband, + const int nlocal, + const std::complex* Stmp, + const std::complex* Htmp, + std::complex* U_operator, + const int print_matrix, + const int tag) const; + + void compute_propagator_etrs(const int nband, + const int nlocal, + const std::complex* Stmp, + const std::complex* Htmp, + const std::complex* H_laststep, + std::complex* U_operator, + const int print_matrix) const; +#endif +}; + +#endif \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_tddft/upsi.cpp b/source/module_hamilt_lcao/module_tddft/upsi.cpp new file mode 100644 index 0000000000..6e1c2a9b4e --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/upsi.cpp @@ -0,0 +1,79 @@ +#include "upsi.h" + +#include +#include + +#include "module_base/lapack_connector.h" +#include "module_base/scalapack_connector.h" + +#ifdef __MPI +void upsi(const Parallel_Orbitals* pv, + const int nband, + const int nlocal, + const std::complex* U_operator, + const std::complex* psi_k_laststep, + std::complex* psi_k, + const int print_matrix) +{ + + ScalapackConnector::gemm('N', + 'N', + nlocal, + nband, + nlocal, + 1.0, + U_operator, + 1, + 1, + pv->desc, + psi_k_laststep, + 1, + 1, + pv->desc_wfc, + 0.0, + psi_k, + 1, + 1, + pv->desc_wfc); + + if (print_matrix) + { + GlobalV::ofs_running << std::endl; + GlobalV::ofs_running << " psi_k:" << std::endl; + for (int i = 0; i < pv->ncol_bands; i++) + { + for (int j = 0; j < pv->ncol; j++) + { + double aa, bb; + aa = psi_k[i * pv->ncol + j].real(); + bb = psi_k[i * pv->ncol + j].imag(); + if (abs(aa) < 1e-8) + aa = 0.0; + if (abs(bb) < 1e-8) + bb = 0.0; + GlobalV::ofs_running << aa << "+" << bb << "i "; + } + GlobalV::ofs_running << std::endl; + } + GlobalV::ofs_running << std::endl; + GlobalV::ofs_running << " psi_k_laststep:" << std::endl; + for (int i = 0; i < pv->ncol_bands; i++) + { + for (int j = 0; j < pv->ncol; j++) + { + double aa, bb; + aa = psi_k_laststep[i * pv->ncol + j].real(); + bb = psi_k_laststep[i * pv->ncol + j].imag(); + if (abs(aa) < 1e-8) + aa = 0.0; + if (abs(bb) < 1e-8) + bb = 0.0; + GlobalV::ofs_running << aa << "+" << bb << "i "; + } + GlobalV::ofs_running << std::endl; + } + GlobalV::ofs_running << std::endl; + } +} + +#endif diff --git a/source/module_hamilt_lcao/module_tddft/upsi.h b/source/module_hamilt_lcao/module_tddft/upsi.h new file mode 100644 index 0000000000..016fb9a1da --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/upsi.h @@ -0,0 +1,17 @@ +#ifndef UPSI_H +#define UPSI_H + +#include "module_basis/module_ao/parallel_orbitals.h" + +#ifdef __MPI +void upsi(const Parallel_Orbitals* pv, + const int nband, + const int nlocal, + const std::complex* U_operator, + const std::complex* psi_k_laststep, + std::complex* psi_k, + const int print_matrix); + +#endif + +#endif \ No newline at end of file diff --git a/source/module_io/input_conv.cpp b/source/module_io/input_conv.cpp index a7ac785d28..7d45807b6e 100644 --- a/source/module_io/input_conv.cpp +++ b/source/module_io/input_conv.cpp @@ -15,12 +15,12 @@ #include "src_ri/exx_abfs-jle.h" #endif #ifdef __LCAO +#include "module_basis/module_ao/ORB_read.h" #include "module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.h" #include "module_hamilt_lcao/hamilt_lcaodft/global_fp.h" #include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_charge.h" #include "module_hamilt_lcao/module_dftu/dftu.h" -#include "module_hamilt_lcao/module_tddft/ELEC_evolve.h" -#include "module_basis/module_ao/ORB_read.h" +#include "module_hamilt_lcao/module_tddft/evolve_elec.h" #endif #include "module_base/timer.h" #include "module_elecstate/elecstate_lcao.h" @@ -368,16 +368,16 @@ void Input_Conv::Convert(void) // Fuxiang He add 2016-10-26 //---------------------------------------------------------- #ifdef __LCAO - ELEC_evolve::td_force_dt = INPUT.td_force_dt; - ELEC_evolve::td_vext = INPUT.td_vext; - if (ELEC_evolve::td_vext) + Evolve_elec::td_force_dt = INPUT.td_force_dt; + Evolve_elec::td_vext = INPUT.td_vext; + if (Evolve_elec::td_vext) { - parse_expression(INPUT.td_vext_dire, ELEC_evolve::td_vext_dire_case); + parse_expression(INPUT.td_vext_dire, Evolve_elec::td_vext_dire_case); } - ELEC_evolve::out_dipole = INPUT.out_dipole; - ELEC_evolve::out_efield = INPUT.out_efield ; - ELEC_evolve::td_print_eij = INPUT.td_print_eij; - ELEC_evolve::td_edm = INPUT.td_edm; + Evolve_elec::out_dipole = INPUT.out_dipole; + Evolve_elec::out_efield = INPUT.out_efield; + Evolve_elec::td_print_eij = INPUT.td_print_eij; + Evolve_elec::td_edm = INPUT.td_edm; #endif // setting for constrained DFT, jiyy add 2020.10.11 diff --git a/source/module_io/test/for_testing_input_conv.h b/source/module_io/test/for_testing_input_conv.h index c8031e85cd..616e11545c 100644 --- a/source/module_io/test/for_testing_input_conv.h +++ b/source/module_io/test/for_testing_input_conv.h @@ -1,29 +1,28 @@ #define private public -#include "module_cell/unitcell.h" -#include "module_hamilt_pw/hamilt_pwdft/wavefunc.h" -#include "module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.h" -#include "module_relax/relax_old/bfgs_basic.h" -#include "module_relax/relax_old/ions_move_basic.h" -#include "module_relax/relax_old/lattice_change_basic.h" -#include "module_relax/relax_old/ions_move_cg.h" #include "module_cell/module_symmetry/symmetry.h" -#include "module_hamilt_pw/hamilt_pwdft/structure_factor.h" +#include "module_cell/unitcell.h" +#include "module_elecstate/elecstate_lcao.h" #include "module_elecstate/energy.h" -#include "module_hamilt_lcao/module_dftu/dftu.h" +#include "module_elecstate/module_charge/charge_mixing.h" +#include "module_elecstate/occupy.h" #include "module_elecstate/potentials/efield.h" #include "module_elecstate/potentials/gatefield.h" -#include "module_elecstate/potentials/gatefield.h" -#include "module_hamilt_lcao/module_tddft/ELEC_evolve.h" -#include "module_io/restart.h" -#include "module_hamilt_pw/hamilt_pwdft/VNL_in_pw.h" -#include "module_elecstate/occupy.h" -#include "module_elecstate/module_charge/charge_mixing.h" +#include "module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.h" #include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_charge.h" +#include "module_hamilt_lcao/module_dftu/dftu.h" +#include "module_hamilt_lcao/module_tddft/evolve_elec.h" +#include "module_hamilt_pw/hamilt_pwdft/VNL_in_pw.h" +#include "module_hamilt_pw/hamilt_pwdft/structure_factor.h" +#include "module_hamilt_pw/hamilt_pwdft/wavefunc.h" #include "module_hsolver/hsolver_lcao.h" -#include "module_elecstate/elecstate_lcao.h" #include "module_io/berryphase.h" +#include "module_io/restart.h" #include "module_md/md_func.h" +#include "module_relax/relax_old/bfgs_basic.h" +#include "module_relax/relax_old/ions_move_basic.h" +#include "module_relax/relax_old/ions_move_cg.h" +#include "module_relax/relax_old/lattice_change_basic.h" bool berryphase::berry_phase_flag=false; int elecstate::ElecStateLCAO::out_wfc_lcao = 0; @@ -34,13 +33,13 @@ int hsolver::HSolverLCAO::out_mat_t = 0; int hsolver::HSolverLCAO::out_mat_dh = 0; int Local_Orbital_Charge::out_dm = 0; int Local_Orbital_Charge::out_dm1 = 0; -double ELEC_evolve::td_force_dt; -bool ELEC_evolve::td_vext; -std::vector ELEC_evolve::td_vext_dire_case; -bool ELEC_evolve::out_dipole; -bool ELEC_evolve::out_efield; -double ELEC_evolve::td_print_eij; -int ELEC_evolve::td_edm; +double Evolve_elec::td_force_dt; +bool Evolve_elec::td_vext; +std::vector Evolve_elec::td_vext_dire_case; +bool Evolve_elec::out_dipole; +bool Evolve_elec::out_efield; +double Evolve_elec::td_print_eij; +int Evolve_elec::td_edm; double elecstate::Gatefield::zgate = 0.5; bool elecstate::Gatefield::relax = false; bool elecstate::Gatefield::block = false; diff --git a/source/module_io/test/input_conv_test.cpp b/source/module_io/test/input_conv_test.cpp index c39d20e0a6..4d61b6c498 100644 --- a/source/module_io/test/input_conv_test.cpp +++ b/source/module_io/test/input_conv_test.cpp @@ -125,13 +125,13 @@ TEST_F(InputConvTest, Conv) EXPECT_DOUBLE_EQ(elecstate::Gatefield::block_down,0.45); EXPECT_DOUBLE_EQ(elecstate::Gatefield::block_up,0.55); EXPECT_DOUBLE_EQ(elecstate::Gatefield::block_height,0.1); - EXPECT_EQ(ELEC_evolve::td_force_dt,0.02); - EXPECT_EQ(ELEC_evolve::td_vext,false); - EXPECT_EQ(ELEC_evolve::out_dipole,false); - EXPECT_EQ(ELEC_evolve::out_efield,false); - EXPECT_EQ(ELEC_evolve::td_print_eij,-1.0); - EXPECT_EQ(ELEC_evolve::td_edm,0); - EXPECT_EQ(GlobalV::ocp,false); + EXPECT_EQ(Evolve_elec::td_force_dt, 0.02); + EXPECT_EQ(Evolve_elec::td_vext, false); + EXPECT_EQ(Evolve_elec::out_dipole, false); + EXPECT_EQ(Evolve_elec::out_efield, false); + EXPECT_EQ(Evolve_elec::td_print_eij, -1.0); + EXPECT_EQ(Evolve_elec::td_edm, 0); + EXPECT_EQ(GlobalV::ocp,false); EXPECT_EQ(GlobalV::ocp_set,INPUT.ocp_set); EXPECT_EQ(GlobalV::out_mul,0); EXPECT_EQ(GlobalC::ppcell.cell_factor,1.2); @@ -516,9 +516,9 @@ TEST_F(InputConvTest,parse ) INPUT.Default(); std::string input_file = "./support/INPUT"; INPUT.Read(input_file); - ELEC_evolve::td_vext=true; - Input_Conv::Convert(); - EXPECT_EQ(ELEC_evolve::td_vext_dire_case.size(),0); + Evolve_elec::td_vext = true; + Input_Conv::Convert(); + EXPECT_EQ(Evolve_elec::td_vext_dire_case.size(), 0); } TEST_F(InputConvTest,parse2 ) diff --git a/source/module_io/write_dipole.cpp b/source/module_io/write_dipole.cpp index 1b9dc884af..e7b5e6ee97 100644 --- a/source/module_io/write_dipole.cpp +++ b/source/module_io/write_dipole.cpp @@ -1,6 +1,6 @@ #include "module_base/parallel_reduce.h" #include "module_elecstate/module_charge/charge.h" -#include "module_hamilt_lcao/module_tddft/ELEC_evolve.h" +#include "module_hamilt_lcao/module_tddft/evolve_elec.h" #include "module_hamilt_pw/hamilt_pwdft/global.h" #include "module_io/dipole_io.h" diff --git a/tests/integrate/601_NO_TDDFT_H2_taylor/result.ref b/tests/integrate/601_NO_TDDFT_H2_taylor/result.ref index 689ce39369..a6d0fcd531 100644 --- a/tests/integrate/601_NO_TDDFT_H2_taylor/result.ref +++ b/tests/integrate/601_NO_TDDFT_H2_taylor/result.ref @@ -1,5 +1,5 @@ -etotref -18.06759546636300 -etotperatomref -9.0337977332 -totalforceref 46.058216 -totalstressref 81.553158 -totaltimeref +3.9590 +etotref -17.65560405098635 +etotperatomref -8.8278020255 +totalforceref 26.351130 +totalstressref 46.577654 +totaltimeref +4.0140 From f1f9204287b7266c43ea61289ea17050119cd2a5 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Thu, 11 May 2023 00:34:37 +0800 Subject: [PATCH 08/48] move read_paramter of electric field to input_conv.cpp for tddft --- .../potentials/H_TDDFT_pw.cpp | 99 +++++++++++-------- .../module_elecstate/potentials/H_TDDFT_pw.h | 74 ++++++-------- source/module_io/input_conv.cpp | 7 +- 3 files changed, 93 insertions(+), 87 deletions(-) diff --git a/source/module_elecstate/potentials/H_TDDFT_pw.cpp b/source/module_elecstate/potentials/H_TDDFT_pw.cpp index 84fb803aec..699c742a6d 100644 --- a/source/module_elecstate/potentials/H_TDDFT_pw.cpp +++ b/source/module_elecstate/potentials/H_TDDFT_pw.cpp @@ -11,11 +11,57 @@ namespace elecstate { int H_TDDFT_pw::istep = -1; -//========================================================== -// this function aims to add external time-dependent potential -// (eg: linear potential) used in tddft -// fuxiang add in 2017-05 -//========================================================== + +int H_TDDFT_pw::stype; // 0 : length gauge 1: velocity gauge + +std::vector H_TDDFT_pw::ttype; +// 0 Gauss type function. +// 1 trapezoid type function. +// 2 Trigonometric functions, sin^2. +// 3 heaviside function. +// 4 HHG function. + +int H_TDDFT_pw::tstart; +int H_TDDFT_pw::tend; +double H_TDDFT_pw::dt; + +// space domain parameters + +// length gauge +double H_TDDFT_pw::lcut1; +double H_TDDFT_pw::lcut2; + +// time domain parameters + +// Gauss +int H_TDDFT_pw::gauss_count; +std::vector H_TDDFT_pw::gauss_omega; // time(a.u.)^-1 +std::vector H_TDDFT_pw::gauss_phase; +std::vector H_TDDFT_pw::gauss_sigma; // time(a.u.) +std::vector H_TDDFT_pw::gauss_t0; +std::vector H_TDDFT_pw::gauss_amp; // Ry/bohr + +// trapezoid +int H_TDDFT_pw::trape_count; +std::vector H_TDDFT_pw::trape_omega; // time(a.u.)^-1 +std::vector H_TDDFT_pw::trape_phase; +std::vector H_TDDFT_pw::trape_t1; +std::vector H_TDDFT_pw::trape_t2; +std::vector H_TDDFT_pw::trape_t3; +std::vector H_TDDFT_pw::trape_amp; // Ry/bohr + +// Trigonometric +int H_TDDFT_pw::trigo_count; +std::vector H_TDDFT_pw::trigo_omega1; // time(a.u.)^-1 +std::vector H_TDDFT_pw::trigo_omega2; // time(a.u.)^-1 +std::vector H_TDDFT_pw::trigo_phase1; +std::vector H_TDDFT_pw::trigo_phase2; +std::vector H_TDDFT_pw::trigo_amp; // Ry/bohr + +// Heaviside +int H_TDDFT_pw::heavi_count; +std::vector H_TDDFT_pw::heavi_t0; +std::vector H_TDDFT_pw::heavi_amp; // Ry/bohr void H_TDDFT_pw::cal_fixed_v(double *vl_pseudo) { @@ -24,8 +70,6 @@ void H_TDDFT_pw::cal_fixed_v(double *vl_pseudo) // time evolve H_TDDFT_pw::istep++; - read_parameters(&INPUT); - // judgement to skip vext if (!Evolve_elec::td_vext || istep > tend || istep < tstart) { @@ -36,6 +80,10 @@ void H_TDDFT_pw::cal_fixed_v(double *vl_pseudo) ModuleBase::timer::tick("H_TDDFT_pw", "cal_fixed_v"); int count = 0; + gauss_count = 0; + trape_count = 0; + trigo_count = 0; + heavi_count = 0; for (auto direc: Evolve_elec::td_vext_dire_case) { @@ -82,7 +130,7 @@ void H_TDDFT_pw::read_parameters(Input *in) tstart = in->td_tstart; tend = in->td_tend; - dt = in->mdp.md_dt; + dt = in->mdp.md_dt / ModuleBase::AU_to_FS; // space domain parameters @@ -93,7 +141,6 @@ void H_TDDFT_pw::read_parameters(Input *in) // time domain parameters // Gauss - gauss_count = 0; gauss_omega = set_parameters(in->td_gauss_freq, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 gauss_phase = set_parameters(in->td_gauss_phase, 1.0); gauss_sigma = set_parameters(in->td_gauss_sigma, 1 / ModuleBase::AU_to_FS); @@ -101,7 +148,6 @@ void H_TDDFT_pw::read_parameters(Input *in) gauss_amp = set_parameters(in->td_gauss_amp, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr // trapezoid - trape_count = 0; trape_omega = set_parameters(in->td_trape_freq, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 trape_phase = set_parameters(in->td_trape_phase, 1.0); trape_t1 = set_parameters(in->td_trape_t1, 1.0); @@ -110,7 +156,6 @@ void H_TDDFT_pw::read_parameters(Input *in) trape_amp = set_parameters(in->td_trape_amp, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr // Trigonometric - trigo_count = 0; trigo_omega1 = set_parameters(in->td_trigo_freq1, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 trigo_omega2 = set_parameters(in->td_trigo_freq2, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 trigo_phase1 = set_parameters(in->td_trigo_phase1, 1.0); @@ -118,21 +163,9 @@ void H_TDDFT_pw::read_parameters(Input *in) trigo_amp = set_parameters(in->td_trigo_amp, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr // Heaviside - heavi_count = 0; heavi_t0 = set_parameters(in->td_heavi_t0, 1.0); heavi_amp = set_parameters(in->td_heavi_amp, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr - // HHG - // hhg_count = 0; - // hhg_amp1 = set_parameters(in->td_hhg_amp1, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr - // hhg_amp2 = set_parameters(in->td_hhg_amp2, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr - // hhg_omega1 = set_parameters(in->td_hhg_freq1, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 - // hhg_omega2 = set_parameters(in->td_hhg_freq2, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 - // hhg_phase1 = set_parameters(in->td_hhg_phase1, 1.0); - // hhg_phase2 = set_parameters(in->td_hhg_phase2, 1.0); - // hhg_t0 = set_parameters(in->td_hhg_t0, 1.0); - // hhg_sigma = set_parameters(in->td_hhg_sigma, 1/ModuleBase::AU_to_FS); - return; } @@ -336,26 +369,6 @@ double H_TDDFT_pw::cal_v_time_heaviside() return vext_time; } -// double H_TDDFT_pw::cal_v_time_HHG() -// { -// double vext_time = 0.0; -// double t0 = *(hhg_t0.begin() + hhg_count); -// double omega1 = *(hhg_omega1.begin() + hhg_count); -// double phase1 = *(hhg_phase1.begin() + hhg_count); -// double omega2 = *(hhg_omega2.begin() + hhg_count); -// double phase2 = *(hhg_phase2.begin() + hhg_count); -// double amp1 = *(hhg_amp1.begin() + hhg_count); -// double amp2 = *(hhg_amp2.begin() + hhg_count); -// double sigma = *(trigo_amp2.begin() + trigo_count); - -// double hhg_t = (istep - t0) * dt; -// vext_time = (cos(omega1 * hhg_t + phase1) * amp1 + cos(omega2 * hhg_t + phase2) * amp2) -// * exp(-hhg_t * hhg_t * 0.5 / (sigma * sigma)); -// hhg_count++; - -// return vext_time; -// } - double H_TDDFT_pw::prepare(const UnitCell &cell, int &dir) { double bvec[3] = {0.0}; diff --git a/source/module_elecstate/potentials/H_TDDFT_pw.h b/source/module_elecstate/potentials/H_TDDFT_pw.h index e600219b24..1cba4c2cd8 100644 --- a/source/module_elecstate/potentials/H_TDDFT_pw.h +++ b/source/module_elecstate/potentials/H_TDDFT_pw.h @@ -21,6 +21,8 @@ class H_TDDFT_pw : public PotBase void cal_fixed_v(double* vl_pseudo) override; + static void read_parameters(Input *in); + private: // internal time-step, //-------hypothesis------- @@ -29,72 +31,60 @@ class H_TDDFT_pw : public PotBase static int istep; // parameters - int stype ; // 0 : length gauge 1: velocity gauge + static int stype; // 0 : length gauge 1: velocity gauge - std::vector ttype ; + static std::vector ttype; // 0 Gauss type function. // 1 trapezoid type function. // 2 Trigonometric functions, sin^2. // 3 heaviside function. // 4 HHG function. - int tstart; - int tend; - double dt; + static int tstart; + static int tend; + static double dt; // space domain parameters //length gauge - double lcut1; - double lcut2; + static double lcut1; + static double lcut2; // time domain parameters // Gauss - int gauss_count; - std::vector gauss_omega; // time(a.u.)^-1 - std::vector gauss_phase ; - std::vector gauss_sigma ; // time(a.u.) - std::vector gauss_t0 ; - std::vector gauss_amp ; // Ry/bohr + static int gauss_count; + static std::vector gauss_omega; // time(a.u.)^-1 + static std::vector gauss_phase; + static std::vector gauss_sigma; // time(a.u.) + static std::vector gauss_t0; + static std::vector gauss_amp; // Ry/bohr // trapezoid - int trape_count; - std::vector trape_omega ; // time(a.u.)^-1 - std::vector trape_phase ; - std::vector trape_t1 ; - std::vector trape_t2 ; - std::vector trape_t3 ; - std::vector trape_amp ; // Ry/bohr + static int trape_count; + static std::vector trape_omega; // time(a.u.)^-1 + static std::vector trape_phase; + static std::vector trape_t1; + static std::vector trape_t2; + static std::vector trape_t3; + static std::vector trape_amp; // Ry/bohr // Trigonometric - int trigo_count; - std::vector trigo_omega1 ; // time(a.u.)^-1 - std::vector trigo_omega2 ; // time(a.u.)^-1 - std::vector trigo_phase1 ; - std::vector trigo_phase2 ; - std::vector trigo_amp ; // Ry/bohr + static int trigo_count; + static std::vector trigo_omega1; // time(a.u.)^-1 + static std::vector trigo_omega2; // time(a.u.)^-1 + static std::vector trigo_phase1; + static std::vector trigo_phase2; + static std::vector trigo_amp; // Ry/bohr // Heaviside - int heavi_count; - std::vector heavi_t0; - std::vector heavi_amp; // Ry/bohr - - // HHG - // int hhg_count = 0; - // std::vector hhg_amp1; // Ry/bohr - // std::vector hhg_amp2; // Ry/bohr - // std::vector hhg_omega1; // time(a.u.)^-1 - // std::vector hhg_omega2; // time(a.u.)^-1 - // std::vector hhg_phase1; - // std::vector hhg_phase2; - // std::vector hhg_t0; - // std::vector hhg_sigma; // time(a.u.) + static int heavi_count; + static std::vector heavi_t0; + static std::vector heavi_amp; // Ry/bohr const UnitCell* ucell_ = nullptr; - std::vector set_parameters(std::string params, double c); - void read_parameters(Input* in); + static std::vector set_parameters(std::string params, double c); // potential of electric field in space domain : length gauge and velocity gauge void cal_v_space(std::vector &vext_space, int direc); diff --git a/source/module_io/input_conv.cpp b/source/module_io/input_conv.cpp index 7d45807b6e..6da249fd43 100644 --- a/source/module_io/input_conv.cpp +++ b/source/module_io/input_conv.cpp @@ -24,13 +24,15 @@ #endif #include "module_base/timer.h" #include "module_elecstate/elecstate_lcao.h" +#include "module_elecstate/potentials/H_TDDFT_pw.h" #include "module_elecstate/potentials/efield.h" #include "module_elecstate/potentials/gatefield.h" #include "module_hsolver/hsolver_lcao.h" -#include "module_psi/kernels/device.h" #include "module_md/md_func.h" +#include "module_psi/kernels/device.h" -template void Input_Conv::parse_expression(const std::string &fn, std::vector &vec) +template +void Input_Conv::parse_expression(const std::string &fn, std::vector &vec) { ModuleBase::TITLE("Input_Conv", "parse_expression"); int count = 0; @@ -378,6 +380,7 @@ void Input_Conv::Convert(void) Evolve_elec::out_efield = INPUT.out_efield; Evolve_elec::td_print_eij = INPUT.td_print_eij; Evolve_elec::td_edm = INPUT.td_edm; + elecstate::H_TDDFT_pw::read_parameters(&INPUT); #endif // setting for constrained DFT, jiyy add 2020.10.11 From 2d4e3435f7e97343ec7943c5c85cc6e9f6e01c16 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Thu, 11 May 2023 15:54:32 +0800 Subject: [PATCH 09/48] sve conflicts --- source/module_esolver/esolver_ks_lcao_tddft.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/source/module_esolver/esolver_ks_lcao_tddft.cpp b/source/module_esolver/esolver_ks_lcao_tddft.cpp index 1e4c63c259..78c3740592 100644 --- a/source/module_esolver/esolver_ks_lcao_tddft.cpp +++ b/source/module_esolver/esolver_ks_lcao_tddft.cpp @@ -203,16 +203,11 @@ void ESolver_KS_LCAO_TDDFT::hamilt2density(int istep, int iter, double ethr) } } -<<<<<<< HEAD - // compute magnetization, only for spin==2 - GlobalC::ucell.magnet.compute_magnetization(pelec->charge, pelec->nelec_spin.data()); -======= // (6) compute magnetization, only for spin==2 GlobalC::ucell.magnet.compute_magnetization(this->pelec->charge->nrxx, this->pelec->charge->nxyz, this->pelec->charge->rho, pelec->nelec_spin.data()); ->>>>>>> 51d94c7bad2beb01a4d553221f6b5d6d2b8d39ef // calculate delta energy GlobalC::en.deband = GlobalC::en.delta_e(this->pelec); From 3c9a4773fada7b4687a6fc2e215eab1a3027f68f Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Thu, 11 May 2023 16:02:40 +0800 Subject: [PATCH 10/48] move definition of tag --- source/module_hamilt_lcao/module_tddft/propagator.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/module_hamilt_lcao/module_tddft/propagator.cpp b/source/module_hamilt_lcao/module_tddft/propagator.cpp index 1a1d12fed0..6afeb4b6bf 100644 --- a/source/module_hamilt_lcao/module_tddft/propagator.cpp +++ b/source/module_hamilt_lcao/module_tddft/propagator.cpp @@ -29,6 +29,7 @@ void Propagator::compute_propagator(const int nband, std::complex* U_operator, const int print_matrix) const { + int tag; switch (ptype) { case 0: @@ -36,7 +37,7 @@ void Propagator::compute_propagator(const int nband, break; case 1: - int tag = 1; + tag = 1; compute_propagator_taylor(nband, nlocal, Stmp, Htmp, U_operator, print_matrix, tag); break; From b93d3bc7f75a48d8b4df7d621976644cc9479589 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Thu, 11 May 2023 17:36:56 +0800 Subject: [PATCH 11/48] convert read_parameter --- source/module_elecstate/potentials/H_TDDFT_pw.cpp | 2 ++ source/module_io/input_conv.cpp | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/source/module_elecstate/potentials/H_TDDFT_pw.cpp b/source/module_elecstate/potentials/H_TDDFT_pw.cpp index 699c742a6d..17f5e2ee51 100644 --- a/source/module_elecstate/potentials/H_TDDFT_pw.cpp +++ b/source/module_elecstate/potentials/H_TDDFT_pw.cpp @@ -70,6 +70,8 @@ void H_TDDFT_pw::cal_fixed_v(double *vl_pseudo) // time evolve H_TDDFT_pw::istep++; + read_parameters(&INPUT); + // judgement to skip vext if (!Evolve_elec::td_vext || istep > tend || istep < tstart) { diff --git a/source/module_io/input_conv.cpp b/source/module_io/input_conv.cpp index 8c0013ec9b..2b2fd4a271 100644 --- a/source/module_io/input_conv.cpp +++ b/source/module_io/input_conv.cpp @@ -389,7 +389,6 @@ void Input_Conv::Convert(void) Evolve_elec::out_efield = INPUT.out_efield; Evolve_elec::td_print_eij = INPUT.td_print_eij; Evolve_elec::td_edm = INPUT.td_edm; - elecstate::H_TDDFT_pw::read_parameters(&INPUT); #endif // setting for constrained DFT, jiyy add 2020.10.11 From 345b2153cd0f795d56a705d3f36bc0fbbfe8f762 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Thu, 11 May 2023 17:50:33 +0800 Subject: [PATCH 12/48] add namespace module_tddft --- .../potentials/H_TDDFT_pw.cpp | 6 +-- .../module_esolver/esolver_ks_lcao_tddft.cpp | 26 ++++++------- .../module_tddft/bandenergy.cpp | 4 ++ .../module_tddft/bandenergy.h | 4 +- .../module_tddft/evolve_elec.cpp | 3 ++ .../module_tddft/evolve_elec.h | 4 +- .../module_tddft/evolve_psi.cpp | 3 ++ .../module_tddft/evolve_psi.h | 3 ++ .../module_tddft/middle_hamilt.cpp | 3 ++ .../module_tddft/middle_hamilt.h | 3 ++ .../module_tddft/norm_psi.cpp | 3 ++ .../module_tddft/norm_psi.h | 3 ++ .../module_tddft/propagator.cpp | 5 ++- .../module_tddft/propagator.h | 3 ++ .../module_tddft/test/CMakeLists.txt | 10 +++++ .../module_tddft/test/upsi_test.cpp | 37 +++++++++++++++++++ .../module_hamilt_lcao/module_tddft/upsi.cpp | 3 ++ source/module_hamilt_lcao/module_tddft/upsi.h | 3 ++ source/module_io/input_conv.cpp | 16 ++++---- .../module_io/test/for_testing_input_conv.h | 14 +++---- source/module_io/test/input_conv_test.cpp | 16 ++++---- 21 files changed, 130 insertions(+), 42 deletions(-) create mode 100644 source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt create mode 100644 source/module_hamilt_lcao/module_tddft/test/upsi_test.cpp diff --git a/source/module_elecstate/potentials/H_TDDFT_pw.cpp b/source/module_elecstate/potentials/H_TDDFT_pw.cpp index 17f5e2ee51..bd3a84a24e 100644 --- a/source/module_elecstate/potentials/H_TDDFT_pw.cpp +++ b/source/module_elecstate/potentials/H_TDDFT_pw.cpp @@ -73,7 +73,7 @@ void H_TDDFT_pw::cal_fixed_v(double *vl_pseudo) read_parameters(&INPUT); // judgement to skip vext - if (!Evolve_elec::td_vext || istep > tend || istep < tstart) + if (!module_tddft::Evolve_elec::td_vext || istep > tend || istep < tstart) { return; } @@ -87,12 +87,12 @@ void H_TDDFT_pw::cal_fixed_v(double *vl_pseudo) trigo_count = 0; heavi_count = 0; - for (auto direc: Evolve_elec::td_vext_dire_case) + for (auto direc: module_tddft::Evolve_elec::td_vext_dire_case) { std::vector vext_space(this->rho_basis_->nrxx, 0.0); double vext_time = cal_v_time(ttype[count]); - if (Evolve_elec::out_efield && GlobalV::MY_RANK == 0) + if (module_tddft::Evolve_elec::out_efield && GlobalV::MY_RANK == 0) { std::stringstream as; as << GlobalV::global_out_dir << "efield_" << count << ".dat"; diff --git a/source/module_esolver/esolver_ks_lcao_tddft.cpp b/source/module_esolver/esolver_ks_lcao_tddft.cpp index 78c3740592..713c1d27bf 100644 --- a/source/module_esolver/esolver_ks_lcao_tddft.cpp +++ b/source/module_esolver/esolver_ks_lcao_tddft.cpp @@ -120,17 +120,17 @@ void ESolver_KS_LCAO_TDDFT::hamilt2density(int istep, int iter, double ethr) if (GlobalV::ESOLVER_TYPE == "tddft" && istep >= 2 && !GlobalV::GAMMA_ONLY_LOCAL) { - Evolve_elec::solve_psi(istep, - GlobalV::NBANDS, - GlobalV::NLOCAL, - this->p_hamilt, - this->LOWF, - this->psi, - this->psi_laststep, - this->Hk_laststep, - this->pelec_td->ekb, - td_htype, - INPUT.propagator); + module_tddft::Evolve_elec::solve_psi(istep, + GlobalV::NBANDS, + GlobalV::NLOCAL, + this->p_hamilt, + this->LOWF, + this->psi, + this->psi_laststep, + this->Hk_laststep, + this->pelec_td->ekb, + td_htype, + INPUT.propagator); this->pelec_td->psiToRho_td(this->psi[0]); } // using HSolverLCAO::solve() @@ -338,7 +338,7 @@ void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) } // calculate energy density matrix for tddft - if (istep > 1 && Evolve_elec::td_edm == 0) + if (istep > 1 && module_tddft::Evolve_elec::td_edm == 0) this->cal_edm_tddft(); } @@ -371,7 +371,7 @@ void ESolver_KS_LCAO_TDDFT::afterscf(const int istep) { for (int is = 0; is < GlobalV::NSPIN; is++) { - if (Evolve_elec::out_dipole == 1) + if (module_tddft::Evolve_elec::out_dipole == 1) { std::stringstream ss_dipole; ss_dipole << GlobalV::global_out_dir << "SPIN" << is + 1 << "_DIPOLE"; diff --git a/source/module_hamilt_lcao/module_tddft/bandenergy.cpp b/source/module_hamilt_lcao/module_tddft/bandenergy.cpp index 90d25d7dd1..d09f1129c8 100644 --- a/source/module_hamilt_lcao/module_tddft/bandenergy.cpp +++ b/source/module_hamilt_lcao/module_tddft/bandenergy.cpp @@ -7,6 +7,8 @@ #include "module_base/lapack_connector.h" #include "module_base/scalapack_connector.h" +namespace module_tddft +{ #ifdef __MPI inline int globalIndex(int localindex, int nblk, int nprocs, int myproc) @@ -145,3 +147,5 @@ void compute_ekb(const Parallel_Orbitals* pv, } #endif + +} // namespace module_tddft \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_tddft/bandenergy.h b/source/module_hamilt_lcao/module_tddft/bandenergy.h index 292b5efd5e..238556319f 100644 --- a/source/module_hamilt_lcao/module_tddft/bandenergy.h +++ b/source/module_hamilt_lcao/module_tddft/bandenergy.h @@ -3,6 +3,8 @@ #include "module_basis/module_ao/parallel_orbitals.h" +namespace module_tddft +{ #ifdef __MPI void compute_ekb(const Parallel_Orbitals* pv, const int nband, @@ -11,5 +13,5 @@ void compute_ekb(const Parallel_Orbitals* pv, const std::complex* psi_k, double* ekb); #endif - +} // namespace module_tddft #endif \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_tddft/evolve_elec.cpp b/source/module_hamilt_lcao/module_tddft/evolve_elec.cpp index 181709a5e7..89d25b64ba 100644 --- a/source/module_hamilt_lcao/module_tddft/evolve_elec.cpp +++ b/source/module_hamilt_lcao/module_tddft/evolve_elec.cpp @@ -8,6 +8,8 @@ #include "module_hamilt_lcao/module_dftu/dftu.h" #include "module_hamilt_pw/hamilt_pwdft/global.h" +namespace module_tddft +{ Evolve_elec::Evolve_elec(){}; Evolve_elec::~Evolve_elec(){}; @@ -79,3 +81,4 @@ void Evolve_elec::solve_psi(const int& istep, ModuleBase::timer::tick("Evolve_elec", "evolve_psi"); return; } +} // namespace module_tddft \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_tddft/evolve_elec.h b/source/module_hamilt_lcao/module_tddft/evolve_elec.h index ed2e96d97b..4857240923 100644 --- a/source/module_hamilt_lcao/module_tddft/evolve_elec.h +++ b/source/module_hamilt_lcao/module_tddft/evolve_elec.h @@ -16,6 +16,8 @@ // k is the index for the points in the first Brillouin zone //----------------------------------------------------------- +namespace module_tddft +{ class Evolve_elec { @@ -49,5 +51,5 @@ class Evolve_elec int htype, int propagator); }; - +} // namespace module_tddft #endif diff --git a/source/module_hamilt_lcao/module_tddft/evolve_psi.cpp b/source/module_hamilt_lcao/module_tddft/evolve_psi.cpp index 975ceb2032..ebd578efdb 100644 --- a/source/module_hamilt_lcao/module_tddft/evolve_psi.cpp +++ b/source/module_hamilt_lcao/module_tddft/evolve_psi.cpp @@ -13,6 +13,8 @@ #include "propagator.h" #include "upsi.h" +namespace module_tddft +{ void evolve_psi(const int nband, const int nlocal, const Parallel_Orbitals* pv, @@ -100,3 +102,4 @@ void evolve_psi(const int nband, return; } +} // namespace module_tddft \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_tddft/evolve_psi.h b/source/module_hamilt_lcao/module_tddft/evolve_psi.h index e31f2d8e89..31d76ea35f 100644 --- a/source/module_hamilt_lcao/module_tddft/evolve_psi.h +++ b/source/module_hamilt_lcao/module_tddft/evolve_psi.h @@ -4,6 +4,8 @@ #include "module_basis/module_ao/parallel_orbitals.h" #include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" +namespace module_tddft +{ void evolve_psi(const int nband, const int nlocal, const Parallel_Orbitals* pv, @@ -14,5 +16,6 @@ void evolve_psi(const int nband, double* ekb, int htype, int propagator); +} #endif \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_tddft/middle_hamilt.cpp b/source/module_hamilt_lcao/module_tddft/middle_hamilt.cpp index 3b437c8214..72ed8b68e0 100644 --- a/source/module_hamilt_lcao/module_tddft/middle_hamilt.cpp +++ b/source/module_hamilt_lcao/module_tddft/middle_hamilt.cpp @@ -6,6 +6,8 @@ #include "module_base/lapack_connector.h" #include "module_base/scalapack_connector.h" +namespace module_tddft +{ #ifdef __MPI void half_Hmatrix(const Parallel_Orbitals* pv, @@ -63,3 +65,4 @@ void half_Hmatrix(const Parallel_Orbitals* pv, } } #endif +} // namespace module_tddft \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_tddft/middle_hamilt.h b/source/module_hamilt_lcao/module_tddft/middle_hamilt.h index 2dcf92495e..59841a4724 100644 --- a/source/module_hamilt_lcao/module_tddft/middle_hamilt.h +++ b/source/module_hamilt_lcao/module_tddft/middle_hamilt.h @@ -3,6 +3,8 @@ #include "module_basis/module_ao/parallel_orbitals.h" +namespace module_tddft +{ #ifdef __MPI void half_Hmatrix(const Parallel_Orbitals* pv, const int nband, @@ -11,5 +13,6 @@ void half_Hmatrix(const Parallel_Orbitals* pv, const std::complex* H_laststep, const int print_matrix); #endif +} // namespace module_tddft #endif \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_tddft/norm_psi.cpp b/source/module_hamilt_lcao/module_tddft/norm_psi.cpp index 492ed3465f..19cd0a5f84 100644 --- a/source/module_hamilt_lcao/module_tddft/norm_psi.cpp +++ b/source/module_hamilt_lcao/module_tddft/norm_psi.cpp @@ -6,6 +6,8 @@ #include "module_base/lapack_connector.h" #include "module_base/scalapack_connector.h" +namespace module_tddft +{ #ifdef __MPI inline int globalIndex(int localindex, int nblk, int nprocs, int myproc) @@ -206,3 +208,4 @@ void norm_psi(const Parallel_Orbitals* pv, delete[] Cij; } #endif +} // namespace module_tddft diff --git a/source/module_hamilt_lcao/module_tddft/norm_psi.h b/source/module_hamilt_lcao/module_tddft/norm_psi.h index c195edc64b..0c5703c8de 100644 --- a/source/module_hamilt_lcao/module_tddft/norm_psi.h +++ b/source/module_hamilt_lcao/module_tddft/norm_psi.h @@ -3,6 +3,8 @@ #include "module_basis/module_ao/parallel_orbitals.h" +namespace module_tddft +{ #ifdef __MPI void norm_psi(const Parallel_Orbitals* pv, const int nband, @@ -12,5 +14,6 @@ void norm_psi(const Parallel_Orbitals* pv, const int print_matrix); #endif +} // namespace module_tddft #endif \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_tddft/propagator.cpp b/source/module_hamilt_lcao/module_tddft/propagator.cpp index 6afeb4b6bf..f2711ed2f8 100644 --- a/source/module_hamilt_lcao/module_tddft/propagator.cpp +++ b/source/module_hamilt_lcao/module_tddft/propagator.cpp @@ -7,6 +7,8 @@ #include "module_base/scalapack_connector.h" #include "module_io/input.h" +namespace module_tddft +{ Propagator::~Propagator() { } @@ -614,4 +616,5 @@ void Propagator::compute_propagator_etrs(const int nband, this->ParaV->desc); } -#endif \ No newline at end of file +#endif +} // namespace module_tddft \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_tddft/propagator.h b/source/module_hamilt_lcao/module_tddft/propagator.h index f52fb5f193..f3abe1027e 100644 --- a/source/module_hamilt_lcao/module_tddft/propagator.h +++ b/source/module_hamilt_lcao/module_tddft/propagator.h @@ -3,6 +3,8 @@ #include "module_basis/module_ao/parallel_orbitals.h" +namespace module_tddft +{ class Propagator { public: @@ -53,5 +55,6 @@ class Propagator const int print_matrix) const; #endif }; +} // namespace module_tddft #endif \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt b/source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt new file mode 100644 index 0000000000..3f30bc0515 --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.10) +project(UpsiTest) + +find_package(GTest REQUIRED) +include_directories(${GTEST_INCLUDE_DIRS}) + +add_executable(UpsiTest upsi_test.cpp) +target_include_directories(UpsiTest PRIVATE ../../../module_basis/module_ao) +target_link_libraries(UpsiTest ${GTEST_BOTH_LIBRARIES} pthread) + diff --git a/source/module_hamilt_lcao/module_tddft/test/upsi_test.cpp b/source/module_hamilt_lcao/module_tddft/test/upsi_test.cpp new file mode 100644 index 0000000000..2d6e48e4e0 --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/test/upsi_test.cpp @@ -0,0 +1,37 @@ +// upsi_test.cpp + +#include "../upsi.h" + +#include + +TEST(UpsiTest, ScalarProduct) +{ + // Set up test inputs + int nband = 2; + int nlocal = 3; + std::complex U_operator[9] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; + std::complex psi_k_laststep[6] = {7.0, 8.0, 9.0, 10.0, 11.0, 12.0}; + std::complex expected_result[4] = {58.0, 64.0, 139.0, 154.0}; + std::complex actual_result[4]; + + Parallel_Orbitals pv; + pv.desc[0] = 1; // Set dummy values for the parallelization descriptors + pv.desc_wfc[0] = 1; + pv.ncol_bands = nband; + pv.ncol = nlocal; + + // Call the function being tested + upsi(&pv, nband, nlocal, U_operator, psi_k_laststep, actual_result, false); + + // Check the result + for (int i = 0; i < 6; i++) + { + EXPECT_EQ(actual_result[i], expected_result[i]); + } +} + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/source/module_hamilt_lcao/module_tddft/upsi.cpp b/source/module_hamilt_lcao/module_tddft/upsi.cpp index 6e1c2a9b4e..35c0b03b5e 100644 --- a/source/module_hamilt_lcao/module_tddft/upsi.cpp +++ b/source/module_hamilt_lcao/module_tddft/upsi.cpp @@ -6,6 +6,8 @@ #include "module_base/lapack_connector.h" #include "module_base/scalapack_connector.h" +namespace module_tddft +{ #ifdef __MPI void upsi(const Parallel_Orbitals* pv, const int nband, @@ -77,3 +79,4 @@ void upsi(const Parallel_Orbitals* pv, } #endif +} // namespace module_tddft diff --git a/source/module_hamilt_lcao/module_tddft/upsi.h b/source/module_hamilt_lcao/module_tddft/upsi.h index 016fb9a1da..647840e387 100644 --- a/source/module_hamilt_lcao/module_tddft/upsi.h +++ b/source/module_hamilt_lcao/module_tddft/upsi.h @@ -3,6 +3,8 @@ #include "module_basis/module_ao/parallel_orbitals.h" +namespace module_tddft +{ #ifdef __MPI void upsi(const Parallel_Orbitals* pv, const int nband, @@ -13,5 +15,6 @@ void upsi(const Parallel_Orbitals* pv, const int print_matrix); #endif +} // namespace module_tddft #endif \ No newline at end of file diff --git a/source/module_io/input_conv.cpp b/source/module_io/input_conv.cpp index 2b2fd4a271..711c7518b1 100644 --- a/source/module_io/input_conv.cpp +++ b/source/module_io/input_conv.cpp @@ -379,16 +379,16 @@ void Input_Conv::Convert(void) // Fuxiang He add 2016-10-26 //---------------------------------------------------------- #ifdef __LCAO - Evolve_elec::td_force_dt = INPUT.td_force_dt; - Evolve_elec::td_vext = INPUT.td_vext; - if (Evolve_elec::td_vext) + module_tddft::Evolve_elec::td_force_dt = INPUT.td_force_dt; + module_tddft::Evolve_elec::td_vext = INPUT.td_vext; + if (module_tddft::Evolve_elec::td_vext) { - parse_expression(INPUT.td_vext_dire, Evolve_elec::td_vext_dire_case); + parse_expression(INPUT.td_vext_dire, module_tddft::Evolve_elec::td_vext_dire_case); } - Evolve_elec::out_dipole = INPUT.out_dipole; - Evolve_elec::out_efield = INPUT.out_efield; - Evolve_elec::td_print_eij = INPUT.td_print_eij; - Evolve_elec::td_edm = INPUT.td_edm; + module_tddft::Evolve_elec::out_dipole = INPUT.out_dipole; + module_tddft::Evolve_elec::out_efield = INPUT.out_efield; + module_tddft::Evolve_elec::td_print_eij = INPUT.td_print_eij; + module_tddft::Evolve_elec::td_edm = INPUT.td_edm; #endif // setting for constrained DFT, jiyy add 2020.10.11 diff --git a/source/module_io/test/for_testing_input_conv.h b/source/module_io/test/for_testing_input_conv.h index 6f245e2375..dcdad3b628 100644 --- a/source/module_io/test/for_testing_input_conv.h +++ b/source/module_io/test/for_testing_input_conv.h @@ -33,13 +33,13 @@ int hsolver::HSolverLCAO::out_mat_t = 0; int hsolver::HSolverLCAO::out_mat_dh = 0; int Local_Orbital_Charge::out_dm = 0; int Local_Orbital_Charge::out_dm1 = 0; -double Evolve_elec::td_force_dt; -bool Evolve_elec::td_vext; -std::vector Evolve_elec::td_vext_dire_case; -bool Evolve_elec::out_dipole; -bool Evolve_elec::out_efield; -double Evolve_elec::td_print_eij; -int Evolve_elec::td_edm; +double module_tddft::Evolve_elec::td_force_dt; +bool module_tddft::Evolve_elec::td_vext; +std::vector module_tddft::Evolve_elec::td_vext_dire_case; +bool module_tddft::Evolve_elec::out_dipole; +bool module_tddft::Evolve_elec::out_efield; +double module_tddft::Evolve_elec::td_print_eij; +int module_tddft::Evolve_elec::td_edm; double elecstate::Gatefield::zgate = 0.5; bool elecstate::Gatefield::relax = false; bool elecstate::Gatefield::block = false; diff --git a/source/module_io/test/input_conv_test.cpp b/source/module_io/test/input_conv_test.cpp index 96461daaf1..eb23891523 100644 --- a/source/module_io/test/input_conv_test.cpp +++ b/source/module_io/test/input_conv_test.cpp @@ -125,12 +125,12 @@ TEST_F(InputConvTest, Conv) EXPECT_DOUBLE_EQ(elecstate::Gatefield::block_down,0.45); EXPECT_DOUBLE_EQ(elecstate::Gatefield::block_up,0.55); EXPECT_DOUBLE_EQ(elecstate::Gatefield::block_height,0.1); - EXPECT_EQ(Evolve_elec::td_force_dt, 0.02); - EXPECT_EQ(Evolve_elec::td_vext, false); - EXPECT_EQ(Evolve_elec::out_dipole, false); - EXPECT_EQ(Evolve_elec::out_efield, false); - EXPECT_EQ(Evolve_elec::td_print_eij, -1.0); - EXPECT_EQ(Evolve_elec::td_edm, 0); + EXPECT_EQ(module_tddft::Evolve_elec::td_force_dt, 0.02); + EXPECT_EQ(module_tddft::Evolve_elec::td_vext, false); + EXPECT_EQ(module_tddft::Evolve_elec::out_dipole, false); + EXPECT_EQ(module_tddft::Evolve_elec::out_efield, false); + EXPECT_EQ(module_tddft::Evolve_elec::td_print_eij, -1.0); + EXPECT_EQ(module_tddft::Evolve_elec::td_edm, 0); EXPECT_EQ(GlobalV::ocp,false); EXPECT_EQ(GlobalV::ocp_set,INPUT.ocp_set); EXPECT_EQ(GlobalV::out_mul,0); @@ -515,9 +515,9 @@ TEST_F(InputConvTest,parse ) INPUT.Default(); std::string input_file = "./support/INPUT"; INPUT.Read(input_file); - Evolve_elec::td_vext = true; + module_tddft::Evolve_elec::td_vext = true; Input_Conv::Convert(); - EXPECT_EQ(Evolve_elec::td_vext_dire_case.size(), 0); + EXPECT_EQ(module_tddft::Evolve_elec::td_vext_dire_case.size(), 0); } TEST_F(InputConvTest,parse2 ) From aa8341c55905e0a293f11cfe5519b2a5fa82a376 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Thu, 11 May 2023 17:53:24 +0800 Subject: [PATCH 13/48] remove tmp file --- .../module_tddft/test/CMakeLists.txt | 10 ----- .../module_tddft/test/upsi_test.cpp | 37 ------------------- 2 files changed, 47 deletions(-) delete mode 100644 source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt delete mode 100644 source/module_hamilt_lcao/module_tddft/test/upsi_test.cpp diff --git a/source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt b/source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt deleted file mode 100644 index 3f30bc0515..0000000000 --- a/source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -cmake_minimum_required(VERSION 3.10) -project(UpsiTest) - -find_package(GTest REQUIRED) -include_directories(${GTEST_INCLUDE_DIRS}) - -add_executable(UpsiTest upsi_test.cpp) -target_include_directories(UpsiTest PRIVATE ../../../module_basis/module_ao) -target_link_libraries(UpsiTest ${GTEST_BOTH_LIBRARIES} pthread) - diff --git a/source/module_hamilt_lcao/module_tddft/test/upsi_test.cpp b/source/module_hamilt_lcao/module_tddft/test/upsi_test.cpp deleted file mode 100644 index 2d6e48e4e0..0000000000 --- a/source/module_hamilt_lcao/module_tddft/test/upsi_test.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// upsi_test.cpp - -#include "../upsi.h" - -#include - -TEST(UpsiTest, ScalarProduct) -{ - // Set up test inputs - int nband = 2; - int nlocal = 3; - std::complex U_operator[9] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; - std::complex psi_k_laststep[6] = {7.0, 8.0, 9.0, 10.0, 11.0, 12.0}; - std::complex expected_result[4] = {58.0, 64.0, 139.0, 154.0}; - std::complex actual_result[4]; - - Parallel_Orbitals pv; - pv.desc[0] = 1; // Set dummy values for the parallelization descriptors - pv.desc_wfc[0] = 1; - pv.ncol_bands = nband; - pv.ncol = nlocal; - - // Call the function being tested - upsi(&pv, nband, nlocal, U_operator, psi_k_laststep, actual_result, false); - - // Check the result - for (int i = 0; i < 6; i++) - { - EXPECT_EQ(actual_result[i], expected_result[i]); - } -} - -int main(int argc, char **argv) -{ - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} From fca26fab48f32036c59b0b6fc0601a5a69c82687 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Mon, 15 May 2023 11:04:34 +0800 Subject: [PATCH 14/48] move read_paramters of electric field in tddft to input_conv.cpp --- source/module_elecstate/potentials/H_TDDFT_pw.h | 5 +++-- source/module_io/input_conv.cpp | 1 + source/module_io/test/CMakeLists.txt | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/source/module_elecstate/potentials/H_TDDFT_pw.h b/source/module_elecstate/potentials/H_TDDFT_pw.h index 1cba4c2cd8..2221c68ea6 100644 --- a/source/module_elecstate/potentials/H_TDDFT_pw.h +++ b/source/module_elecstate/potentials/H_TDDFT_pw.h @@ -1,8 +1,9 @@ #ifndef H_TDDFT_PW_H #define H_TDDFT_PW_H -#include "pot_base.h" #include "module_io/input.h" +#include "module_io/input_conv.h" +#include "pot_base.h" namespace elecstate { @@ -21,7 +22,7 @@ class H_TDDFT_pw : public PotBase void cal_fixed_v(double* vl_pseudo) override; - static void read_parameters(Input *in); + static void read_parameters(Input* in); private: // internal time-step, diff --git a/source/module_io/input_conv.cpp b/source/module_io/input_conv.cpp index 711c7518b1..c0a6082a90 100644 --- a/source/module_io/input_conv.cpp +++ b/source/module_io/input_conv.cpp @@ -389,6 +389,7 @@ void Input_Conv::Convert(void) module_tddft::Evolve_elec::out_efield = INPUT.out_efield; module_tddft::Evolve_elec::td_print_eij = INPUT.td_print_eij; module_tddft::Evolve_elec::td_edm = INPUT.td_edm; + elecstate::H_TDDFT_pw::read_parameters(&INPUT); #endif // setting for constrained DFT, jiyy add 2020.10.11 diff --git a/source/module_io/test/CMakeLists.txt b/source/module_io/test/CMakeLists.txt index f39753567c..db6cbe4c7f 100644 --- a/source/module_io/test/CMakeLists.txt +++ b/source/module_io/test/CMakeLists.txt @@ -27,7 +27,7 @@ add_test(NAME io_input_test_para4 AddTest( TARGET io_input_conv LIBS ${math_libs} base device - SOURCES input_conv_test.cpp ../input.cpp ../input_conv.cpp + SOURCES input_conv_test.cpp ../input.cpp ../input_conv.cpp ../../module_elecstate/potentials/H_TDDFT_pw.cpp ) AddTest( From 7e2c1f1ce266e8355781130da70534f3a6e8d492 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Mon, 15 May 2023 11:25:28 +0800 Subject: [PATCH 15/48] add force of tddft efield --- .../potentials/H_TDDFT_pw.cpp | 37 +++++++++++++------ .../module_elecstate/potentials/H_TDDFT_pw.h | 9 ++++- .../hamilt_lcaodft/FORCE_STRESS.cpp | 19 ++++++++++ 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/source/module_elecstate/potentials/H_TDDFT_pw.cpp b/source/module_elecstate/potentials/H_TDDFT_pw.cpp index bd3a84a24e..0718cde1fa 100644 --- a/source/module_elecstate/potentials/H_TDDFT_pw.cpp +++ b/source/module_elecstate/potentials/H_TDDFT_pw.cpp @@ -12,6 +12,10 @@ namespace elecstate int H_TDDFT_pw::istep = -1; +double H_TDDFT_pw::amp; +double H_TDDFT_pw::bmod; +double H_TDDFT_pw::bvec[3]; + int H_TDDFT_pw::stype; // 0 : length gauge 1: velocity gauge std::vector H_TDDFT_pw::ttype; @@ -200,11 +204,7 @@ void H_TDDFT_pw::cal_v_space_length(std::vector &vext_space, int direc) ModuleBase::TITLE("H_TDDFT_pw", "cal_v_space_length"); ModuleBase::timer::tick("H_TDDFT_pw", "cal_v_space_length"); - double bmod[3]; - for (int i = 0; i < 3; i++) - { - bmod[i] = prepare(GlobalC::ucell, i); - } + prepare(GlobalC::ucell, direc); for (int ir = 0; ir < this->rho_basis_->nrxx; ++ir) { @@ -218,15 +218,15 @@ void H_TDDFT_pw::cal_v_space_length(std::vector &vext_space, int direc) switch (direc) { case 1: - vext_space[ir] = cal_v_space_length_potential(x) / bmod[0]; + vext_space[ir] = cal_v_space_length_potential(x) / bmod; break; case 2: - vext_space[ir] = cal_v_space_length_potential(y) / bmod[1]; + vext_space[ir] = cal_v_space_length_potential(y) / bmod; break; case 3: - vext_space[ir] = cal_v_space_length_potential(z) / bmod[2]; + vext_space[ir] = cal_v_space_length_potential(z) / bmod; break; default: @@ -371,10 +371,8 @@ double H_TDDFT_pw::cal_v_time_heaviside() return vext_time; } -double H_TDDFT_pw::prepare(const UnitCell &cell, int &dir) +void H_TDDFT_pw::prepare(const UnitCell& cell, int& dir) { - double bvec[3] = {0.0}; - double bmod = 0.0; if (dir == 0) { bvec[0] = cell.G.e11; @@ -398,7 +396,22 @@ double H_TDDFT_pw::prepare(const UnitCell &cell, int &dir) ModuleBase::WARNING_QUIT("H_TDDFT_pw::prepare", "direction is wrong!"); } bmod = sqrt(pow(bvec[0], 2) + pow(bvec[1], 2) + pow(bvec[2], 2)); - return bmod; +} + +void H_TDDFT_pw ::compute_force(const UnitCell& cell, ModuleBase::matrix& fdip) +{ + int iat = 0; + for (int it = 0; it < cell.ntype; ++it) + { + for (int ia = 0; ia < cell.atoms[it].na; ++ia) + { + for (int jj = 0; jj < 3; ++jj) + { + fdip(iat, jj) = ModuleBase::e2 * amp * cell.atoms[it].ncpp.zv * bvec[jj] / bmod; + } + ++iat; + } + } } } // namespace elecstate diff --git a/source/module_elecstate/potentials/H_TDDFT_pw.h b/source/module_elecstate/potentials/H_TDDFT_pw.h index 2221c68ea6..17a7e41097 100644 --- a/source/module_elecstate/potentials/H_TDDFT_pw.h +++ b/source/module_elecstate/potentials/H_TDDFT_pw.h @@ -24,6 +24,8 @@ class H_TDDFT_pw : public PotBase static void read_parameters(Input* in); + static void compute_force(const UnitCell& cell, ModuleBase::matrix& fdip); + private: // internal time-step, //-------hypothesis------- @@ -31,6 +33,11 @@ class H_TDDFT_pw : public PotBase //------------------------ static int istep; + static double amp; + + static double bmod; + static double bvec[3]; + // parameters static int stype; // 0 : length gauge 1: velocity gauge @@ -101,7 +108,7 @@ class H_TDDFT_pw : public PotBase double cal_v_time_heaviside(); // double cal_v_time_HHG(); - double prepare(const UnitCell &cell, int &dir); + void prepare(const UnitCell& cell, int& dir); }; } // namespace elecstate diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp index 8b110b18fc..034543764c 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp @@ -167,6 +167,15 @@ void Force_Stress_LCAO::getForceStress( fefield.create(nat, 3); elecstate::Efield::compute_force(GlobalC::ucell, fefield); } + + // implement force from E-field of tddft + ModuleBase::matrix fefield_tddft; + if (GlobalV::ESOLVER_TYPE == "TDDFT" && isforce) + { + fefield_tddft.create(nat, 3); + elecstate::Efield::compute_force(GlobalC::ucell, fefield_tddft); + } + //implement force from gate field ModuleBase::matrix fgate; if(GlobalV::GATE_FLAG&&isforce) @@ -277,6 +286,11 @@ void Force_Stress_LCAO::getForceStress( { fcs(iat, i) += fefield(iat, i); } + // E-field force of tddft + if (GlobalV::ESOLVER_TYPE == "TDDFT") + { + fcs(iat, i) += fefield_tddft(iat, i); + } //Gate field force if(GlobalV::GATE_FLAG) { @@ -419,6 +433,11 @@ void Force_Stress_LCAO::getForceStress( f_pw.print("EFIELD FORCE", fefield,0); //this->print_force("EFIELD FORCE",fefield,1,ry); } + if (GlobalV::ESOLVER_TYPE == "TDDFT") + { + f_pw.print("EFIELD_TDDFT FORCE", fefield_tddft, 0); + // this->print_force("EFIELD_TDDFT FORCE",fefield_tddft,1,ry); + } if(GlobalV::GATE_FLAG) { f_pw.print("GATEFIELD FORCE", fgate,0); From db18fee7e5ea5d0479fa81c810aeb6618e1b41fd Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Mon, 15 May 2023 12:04:28 +0800 Subject: [PATCH 16/48] add annotations --- .../module_elecstate/potentials/H_TDDFT_pw.h | 11 +++++ .../module_tddft/bandenergy.h | 15 ++++++ .../module_tddft/evolve_psi.h | 5 ++ .../module_tddft/middle_hamilt.h | 16 +++++++ .../module_tddft/norm_psi.h | 16 +++++++ .../module_tddft/propagator.h | 48 +++++++++++++++++++ source/module_hamilt_lcao/module_tddft/upsi.h | 17 +++++++ 7 files changed, 128 insertions(+) diff --git a/source/module_elecstate/potentials/H_TDDFT_pw.h b/source/module_elecstate/potentials/H_TDDFT_pw.h index 17a7e41097..72f26d9ccd 100644 --- a/source/module_elecstate/potentials/H_TDDFT_pw.h +++ b/source/module_elecstate/potentials/H_TDDFT_pw.h @@ -22,8 +22,19 @@ class H_TDDFT_pw : public PotBase void cal_fixed_v(double* vl_pseudo) override; + /** + * @brief read paramers of electric field and convert units + * + * @param in input + */ static void read_parameters(Input* in); + /** + * @brief compute force of electric field + * + * @param[in] cell information of cell + * @param[out] fdip force of electric field + */ static void compute_force(const UnitCell& cell, ModuleBase::matrix& fdip); private: diff --git a/source/module_hamilt_lcao/module_tddft/bandenergy.h b/source/module_hamilt_lcao/module_tddft/bandenergy.h index 238556319f..e7f361f658 100644 --- a/source/module_hamilt_lcao/module_tddft/bandenergy.h +++ b/source/module_hamilt_lcao/module_tddft/bandenergy.h @@ -1,3 +1,8 @@ +/** + * @file bandenegy.h + * @brief compute band energy ekb + * This file originally belonged to file LCAO_evolve.cpp + */ #ifndef BANDENERGY_H #define BANDENERGY_H @@ -6,6 +11,16 @@ namespace module_tddft { #ifdef __MPI +/** + * @brief compute band energy ekb + * + * @param[in] pv information of parallel + * @param[in] nband number of bands + * @param[in] nlocal number of orbitals + * @param[in] Htmp Hamiltonian + * @param[in] psi_k psi of this step + * @param[out] ekb band energy + */ void compute_ekb(const Parallel_Orbitals* pv, const int nband, const int nlocal, diff --git a/source/module_hamilt_lcao/module_tddft/evolve_psi.h b/source/module_hamilt_lcao/module_tddft/evolve_psi.h index 31d76ea35f..e905b837a5 100644 --- a/source/module_hamilt_lcao/module_tddft/evolve_psi.h +++ b/source/module_hamilt_lcao/module_tddft/evolve_psi.h @@ -1,3 +1,8 @@ +/** + * @file evolve_psi.h + * @brief evolve the wave function + * This file originally belonged to file LCAO_evolve.cpp + */ #ifndef ELEC_PSI_H #define ELEC_PSI_H diff --git a/source/module_hamilt_lcao/module_tddft/middle_hamilt.h b/source/module_hamilt_lcao/module_tddft/middle_hamilt.h index 59841a4724..6f6da7e8f8 100644 --- a/source/module_hamilt_lcao/module_tddft/middle_hamilt.h +++ b/source/module_hamilt_lcao/module_tddft/middle_hamilt.h @@ -1,3 +1,8 @@ +/** + * @file middle_hamilt.h + * @brief compute H(t+dt/2) + * This file originally belonged to file LCAO_evolve.cpp + */ #ifndef MIDDLE_HAMILT_H #define MIDDLE_HAMILT_H @@ -6,6 +11,17 @@ namespace module_tddft { #ifdef __MPI +/** + * @brief compute H(t+dt/2) + * + * @param[in] pv information of parallel + * @param[in] nband number of bands + * @param[in] nlocal number of orbitals + * @param[in] Htmp H(t+dt) + * @param[in] H_laststep H(t) + * @param[in] print_matirx print internal matrix or not + * @param[out] Htmp H(t+dt/2) + */ void half_Hmatrix(const Parallel_Orbitals* pv, const int nband, const int nlocal, diff --git a/source/module_hamilt_lcao/module_tddft/norm_psi.h b/source/module_hamilt_lcao/module_tddft/norm_psi.h index 0c5703c8de..69287a1532 100644 --- a/source/module_hamilt_lcao/module_tddft/norm_psi.h +++ b/source/module_hamilt_lcao/module_tddft/norm_psi.h @@ -1,3 +1,8 @@ +/** + * @file norm_psi.h + * @brief normalize the wave function + * This file originally belonged to file LCAO_evolve.cpp + */ #ifndef NORM_PSI_H #define NORM_PSI_H @@ -6,6 +11,17 @@ namespace module_tddft { #ifdef __MPI +/** + * @brief normalize the wave function + * + * @param[in] pv information of parallel + * @param[in] nband number of bands + * @param[in] nlocal number of orbitals + * @param[in] Stmp overlap matrix + * @param[in] psi_k psi of this step + * @param[in] print_matirx print internal matrix or not + * @param[out] psi_k psi of this step after normalization + */ void norm_psi(const Parallel_Orbitals* pv, const int nband, const int nlocal, diff --git a/source/module_hamilt_lcao/module_tddft/propagator.h b/source/module_hamilt_lcao/module_tddft/propagator.h index f3abe1027e..7d9e65b2c4 100644 --- a/source/module_hamilt_lcao/module_tddft/propagator.h +++ b/source/module_hamilt_lcao/module_tddft/propagator.h @@ -1,3 +1,8 @@ +/** + * @file propagator.h + * @brief compute propagtor to evolve the wave function + * This file originally belonged to file LCAO_evolve.cpp + */ #ifndef PROPAGATOR_H #define PROPAGATOR_H @@ -16,6 +21,17 @@ class Propagator ~Propagator(); #ifdef __MPI + /** + * @brief compute propagator + * + * @param[in] nband number of bands + * @param[in] nlocal number of orbitals + * @param[in] Stmp overlap matrix + * @param[in] Htmp H(t+dt/2) or H(t+dt) + * @param[in] H_laststep H(t) + * @param[in] print_matirx print internal matrix or not + * @param[out] U_operator operator of propagator + */ void compute_propagator(const int nband, const int nlocal, const std::complex* Stmp, @@ -31,6 +47,16 @@ class Propagator #ifdef __MPI + /** + * @brief compute propagator of method Crank-Nicolson + * + * @param[in] nband number of bands + * @param[in] nlocal number of orbitals + * @param[in] Stmp overlap matrix + * @param[in] Htmp H(t+dt/2) or H(t+dt) + * @param[in] print_matirx print internal matrix or not + * @param[out] U_operator operator of propagator + */ void compute_propagator_cn2(const int nband, const int nlocal, const std::complex* Stmp, @@ -38,6 +64,17 @@ class Propagator std::complex* U_operator, const int print_matrix) const; + /** + * @brief compute propagator of method 4th Taylor + * + * @param[in] nband number of bands + * @param[in] nlocal number of orbitals + * @param[in] Stmp overlap matrix + * @param[in] Htmp H(t+dt/2) or H(t+dt) + * @param[in] print_matirx print internal matrix or not + * @param[in] tag a parametre different for 4th Taylor and ETRS + * @param[out] U_operator operator of propagator + */ void compute_propagator_taylor(const int nband, const int nlocal, const std::complex* Stmp, @@ -46,6 +83,17 @@ class Propagator const int print_matrix, const int tag) const; + /** + * @brief compute propagator of method ETRS + * + * @param[in] nband number of bands + * @param[in] nlocal number of orbitals + * @param[in] Stmp overlap matrix + * @param[in] Htmp H(t+dt/2) or H(t+dt) + * @param[in] H_laststep H(t) + * @param[in] print_matirx print internal matrix or not + * @param[out] U_operator operator of propagator + */ void compute_propagator_etrs(const int nband, const int nlocal, const std::complex* Stmp, diff --git a/source/module_hamilt_lcao/module_tddft/upsi.h b/source/module_hamilt_lcao/module_tddft/upsi.h index 647840e387..7233eee77c 100644 --- a/source/module_hamilt_lcao/module_tddft/upsi.h +++ b/source/module_hamilt_lcao/module_tddft/upsi.h @@ -1,3 +1,9 @@ +/** + * @file upsi.h + * @brief apply U_operator to the wave function of the previous step for new wave function + * This file originally belonged to file LCAO_evolve.cpp + */ + #ifndef UPSI_H #define UPSI_H @@ -6,6 +12,17 @@ namespace module_tddft { #ifdef __MPI +/** + * @brief apply U_operator to the wave function of the previous step for new wave function + * + * @param[in] pv information of parallel + * @param[in] nband number of bands + * @param[in] nlocal number of orbitals + * @param[in] U_operator operator of propagator + * @param[in] psi_k_laststep psi of last step + * @param[in] print_matirx print internal matrix or not + * @param[out] psi_k psi of this step + */ void upsi(const Parallel_Orbitals* pv, const int nband, const int nlocal, From 3d61fe9f73c68cb17a1964ff062eddc3eb33ed90 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Mon, 15 May 2023 13:52:30 +0800 Subject: [PATCH 17/48] move read_parameters from H_TDDFT_pw.cpp to input_conv.cpp --- .../potentials/H_TDDFT_pw.cpp | 61 ---------------- .../module_elecstate/potentials/H_TDDFT_pw.h | 33 ++++----- source/module_io/input_conv.cpp | 69 ++++++++++++++++++- source/module_io/input_conv.h | 25 ++++++- source/module_io/test/CMakeLists.txt | 2 +- 5 files changed, 103 insertions(+), 87 deletions(-) diff --git a/source/module_elecstate/potentials/H_TDDFT_pw.cpp b/source/module_elecstate/potentials/H_TDDFT_pw.cpp index 0718cde1fa..5366e9e187 100644 --- a/source/module_elecstate/potentials/H_TDDFT_pw.cpp +++ b/source/module_elecstate/potentials/H_TDDFT_pw.cpp @@ -74,8 +74,6 @@ void H_TDDFT_pw::cal_fixed_v(double *vl_pseudo) // time evolve H_TDDFT_pw::istep++; - read_parameters(&INPUT); - // judgement to skip vext if (!module_tddft::Evolve_elec::td_vext || istep > tend || istep < tstart) { @@ -116,65 +114,6 @@ void H_TDDFT_pw::cal_fixed_v(double *vl_pseudo) return; } -std::vector H_TDDFT_pw::set_parameters(std::string params, double c) -{ - std::vector params_ori; - std::vector params_out; - Input_Conv::parse_expression(params, params_ori); - for (auto param: params_ori) - params_out.emplace_back(param * c); - - return params_out; -} - -void H_TDDFT_pw::read_parameters(Input *in) -{ - stype = in->td_stype; - - Input_Conv::parse_expression(in->td_ttype, ttype); - - tstart = in->td_tstart; - tend = in->td_tend; - - dt = in->mdp.md_dt / ModuleBase::AU_to_FS; - - // space domain parameters - - // length gauge - lcut1 = in->td_lcut1; - lcut2 = in->td_lcut2; - - // time domain parameters - - // Gauss - gauss_omega = set_parameters(in->td_gauss_freq, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 - gauss_phase = set_parameters(in->td_gauss_phase, 1.0); - gauss_sigma = set_parameters(in->td_gauss_sigma, 1 / ModuleBase::AU_to_FS); - gauss_t0 = set_parameters(in->td_gauss_t0, 1.0); - gauss_amp = set_parameters(in->td_gauss_amp, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr - - // trapezoid - trape_omega = set_parameters(in->td_trape_freq, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 - trape_phase = set_parameters(in->td_trape_phase, 1.0); - trape_t1 = set_parameters(in->td_trape_t1, 1.0); - trape_t2 = set_parameters(in->td_trape_t2, 1.0); - trape_t3 = set_parameters(in->td_trape_t3, 1.0); - trape_amp = set_parameters(in->td_trape_amp, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr - - // Trigonometric - trigo_omega1 = set_parameters(in->td_trigo_freq1, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 - trigo_omega2 = set_parameters(in->td_trigo_freq2, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 - trigo_phase1 = set_parameters(in->td_trigo_phase1, 1.0); - trigo_phase2 = set_parameters(in->td_trigo_phase2, 1.0); - trigo_amp = set_parameters(in->td_trigo_amp, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr - - // Heaviside - heavi_t0 = set_parameters(in->td_heavi_t0, 1.0); - heavi_amp = set_parameters(in->td_heavi_amp, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr - - return; -} - void H_TDDFT_pw::cal_v_space(std::vector &vext_space, int direc) { ModuleBase::TITLE("H_TDDFT_pw", "cal_v_space"); diff --git a/source/module_elecstate/potentials/H_TDDFT_pw.h b/source/module_elecstate/potentials/H_TDDFT_pw.h index 72f26d9ccd..b2cfd39bb8 100644 --- a/source/module_elecstate/potentials/H_TDDFT_pw.h +++ b/source/module_elecstate/potentials/H_TDDFT_pw.h @@ -22,13 +22,6 @@ class H_TDDFT_pw : public PotBase void cal_fixed_v(double* vl_pseudo) override; - /** - * @brief read paramers of electric field and convert units - * - * @param in input - */ - static void read_parameters(Input* in); - /** * @brief compute force of electric field * @@ -37,18 +30,6 @@ class H_TDDFT_pw : public PotBase */ static void compute_force(const UnitCell& cell, ModuleBase::matrix& fdip); - private: - // internal time-step, - //-------hypothesis------- - // Vext will evolve by time, every time cal_fixed_v() is called, istep++ - //------------------------ - static int istep; - - static double amp; - - static double bmod; - static double bvec[3]; - // parameters static int stype; // 0 : length gauge 1: velocity gauge @@ -101,9 +82,19 @@ class H_TDDFT_pw : public PotBase static std::vector heavi_t0; static std::vector heavi_amp; // Ry/bohr - const UnitCell* ucell_ = nullptr; + private: + // internal time-step, + //-------hypothesis------- + // Vext will evolve by time, every time cal_fixed_v() is called, istep++ + //------------------------ + static int istep; + + static double amp; - static std::vector set_parameters(std::string params, double c); + static double bmod; + static double bvec[3]; + + const UnitCell* ucell_ = nullptr; // potential of electric field in space domain : length gauge and velocity gauge void cal_v_space(std::vector &vext_space, int direc); diff --git a/source/module_io/input_conv.cpp b/source/module_io/input_conv.cpp index c0a6082a90..963e160492 100644 --- a/source/module_io/input_conv.cpp +++ b/source/module_io/input_conv.cpp @@ -112,6 +112,73 @@ void Input_Conv::parse_expression(const std::string &fn, std::vector &vec) regfree(®); } +std::vector Input_Conv::convert_units(std::string params, double c) +{ + std::vector params_ori; + std::vector params_out; + parse_expression(params, params_ori); + for (auto param: params_ori) + params_out.emplace_back(param * c); + + return params_out; +} + +void Input_Conv::read_td_efield(Input* in) +{ + elecstate::H_TDDFT_pw::stype = in->td_stype; + + parse_expression(in->td_ttype, elecstate::H_TDDFT_pw::ttype); + + elecstate::H_TDDFT_pw::tstart = in->td_tstart; + elecstate::H_TDDFT_pw::tend = in->td_tend; + + elecstate::H_TDDFT_pw::dt = in->mdp.md_dt / ModuleBase::AU_to_FS; + + // space domain parameters + + // length gauge + elecstate::H_TDDFT_pw::lcut1 = in->td_lcut1; + elecstate::H_TDDFT_pw::lcut2 = in->td_lcut2; + + // time domain parameters + + // Gauss + elecstate::H_TDDFT_pw::gauss_omega + = convert_units(in->td_gauss_freq, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 + elecstate::H_TDDFT_pw::gauss_phase = convert_units(in->td_gauss_phase, 1.0); + elecstate::H_TDDFT_pw::gauss_sigma = convert_units(in->td_gauss_sigma, 1 / ModuleBase::AU_to_FS); + elecstate::H_TDDFT_pw::gauss_t0 = convert_units(in->td_gauss_t0, 1.0); + elecstate::H_TDDFT_pw::gauss_amp + = convert_units(in->td_gauss_amp, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr + + // trapezoid + elecstate::H_TDDFT_pw::trape_omega + = convert_units(in->td_trape_freq, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 + elecstate::H_TDDFT_pw::trape_phase = convert_units(in->td_trape_phase, 1.0); + elecstate::H_TDDFT_pw::trape_t1 = convert_units(in->td_trape_t1, 1.0); + elecstate::H_TDDFT_pw::trape_t2 = convert_units(in->td_trape_t2, 1.0); + elecstate::H_TDDFT_pw::trape_t3 = convert_units(in->td_trape_t3, 1.0); + elecstate::H_TDDFT_pw::trape_amp + = convert_units(in->td_trape_amp, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr + + // Trigonometric + elecstate::H_TDDFT_pw::trigo_omega1 + = convert_units(in->td_trigo_freq1, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 + elecstate::H_TDDFT_pw::trigo_omega2 + = convert_units(in->td_trigo_freq2, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 + elecstate::H_TDDFT_pw::trigo_phase1 = convert_units(in->td_trigo_phase1, 1.0); + elecstate::H_TDDFT_pw::trigo_phase2 = convert_units(in->td_trigo_phase2, 1.0); + elecstate::H_TDDFT_pw::trigo_amp + = convert_units(in->td_trigo_amp, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr + + // Heaviside + elecstate::H_TDDFT_pw::heavi_t0 = convert_units(in->td_heavi_t0, 1.0); + elecstate::H_TDDFT_pw::heavi_amp + = convert_units(in->td_heavi_amp, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr + + return; +} + void Input_Conv::Convert(void) { ModuleBase::TITLE("Input_Conv", "Convert"); @@ -389,7 +456,7 @@ void Input_Conv::Convert(void) module_tddft::Evolve_elec::out_efield = INPUT.out_efield; module_tddft::Evolve_elec::td_print_eij = INPUT.td_print_eij; module_tddft::Evolve_elec::td_edm = INPUT.td_edm; - elecstate::H_TDDFT_pw::read_parameters(&INPUT); + read_td_efield(&INPUT); #endif // setting for constrained DFT, jiyy add 2020.10.11 diff --git a/source/module_io/input_conv.h b/source/module_io/input_conv.h index f25ddb54f7..80b1132106 100644 --- a/source/module_io/input_conv.h +++ b/source/module_io/input_conv.h @@ -5,15 +5,18 @@ #ifndef INPUT_CONVERT_H #define INPUT_CONVERT_H -#include -#include -#include #include #include #include + +#include +#include +#include #include #include +#include "module_io/input.h" + using namespace std; namespace Input_Conv @@ -24,6 +27,22 @@ void Convert(void); // fn (string): expressions such as "3*1 0 2*0.5 3*0" // arr (vector): stores parsing results, for example, "3*1 0 2*0.5 1*1.5" can be parsed as [1, 1, 1, 0, 0.5, 0.5, 1.5] template void parse_expression(const std::string &fn, std::vector &arr); + +/** + * @brief convert units + * + * @param params input parameter + * @param c coefficients of unit conversion + * @return parameter after unit vonversion + */ +std::vector convert_units(std::string params, double c); + +/** + * @brief read paramers of electric field for tddft and convert units + * + * @param in input + */ +void read_td_efield(Input* in); } // namespace Input_Conv #endif // Input_Convert diff --git a/source/module_io/test/CMakeLists.txt b/source/module_io/test/CMakeLists.txt index db6cbe4c7f..f39753567c 100644 --- a/source/module_io/test/CMakeLists.txt +++ b/source/module_io/test/CMakeLists.txt @@ -27,7 +27,7 @@ add_test(NAME io_input_test_para4 AddTest( TARGET io_input_conv LIBS ${math_libs} base device - SOURCES input_conv_test.cpp ../input.cpp ../input_conv.cpp ../../module_elecstate/potentials/H_TDDFT_pw.cpp + SOURCES input_conv_test.cpp ../input.cpp ../input_conv.cpp ) AddTest( From 5325b4957b40ac6bdd254d9483e526180a5b6f2a Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Mon, 15 May 2023 14:20:46 +0800 Subject: [PATCH 18/48] add ifdef __LCAO --- source/module_io/input_conv.cpp | 2 ++ source/module_io/input_conv.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/source/module_io/input_conv.cpp b/source/module_io/input_conv.cpp index 963e160492..9335a2f31a 100644 --- a/source/module_io/input_conv.cpp +++ b/source/module_io/input_conv.cpp @@ -112,6 +112,7 @@ void Input_Conv::parse_expression(const std::string &fn, std::vector &vec) regfree(®); } +#ifdef __LCAO std::vector Input_Conv::convert_units(std::string params, double c) { std::vector params_ori; @@ -178,6 +179,7 @@ void Input_Conv::read_td_efield(Input* in) return; } +#endif void Input_Conv::Convert(void) { diff --git a/source/module_io/input_conv.h b/source/module_io/input_conv.h index 80b1132106..191f3f2a60 100644 --- a/source/module_io/input_conv.h +++ b/source/module_io/input_conv.h @@ -28,6 +28,7 @@ void Convert(void); // arr (vector): stores parsing results, for example, "3*1 0 2*0.5 1*1.5" can be parsed as [1, 1, 1, 0, 0.5, 0.5, 1.5] template void parse_expression(const std::string &fn, std::vector &arr); +#ifdef __LCAO /** * @brief convert units * @@ -43,6 +44,7 @@ std::vector convert_units(std::string params, double c); * @param in input */ void read_td_efield(Input* in); +#endif } // namespace Input_Conv #endif // Input_Convert From 090ad00fe92a0417a962d40ab50fa4f278bfe984 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Mon, 15 May 2023 15:13:27 +0800 Subject: [PATCH 19/48] remove input parameter of read_td_efield --- source/module_io/input_conv.cpp | 52 ++++++++++++++++----------------- source/module_io/input_conv.h | 4 +-- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/source/module_io/input_conv.cpp b/source/module_io/input_conv.cpp index 9335a2f31a..eafa33d08e 100644 --- a/source/module_io/input_conv.cpp +++ b/source/module_io/input_conv.cpp @@ -124,58 +124,58 @@ std::vector Input_Conv::convert_units(std::string params, double c) return params_out; } -void Input_Conv::read_td_efield(Input* in) +void Input_Conv::read_td_efield() { - elecstate::H_TDDFT_pw::stype = in->td_stype; + elecstate::H_TDDFT_pw::stype = INPUT.td_stype; - parse_expression(in->td_ttype, elecstate::H_TDDFT_pw::ttype); + parse_expression(INPUT.td_ttype, elecstate::H_TDDFT_pw::ttype); - elecstate::H_TDDFT_pw::tstart = in->td_tstart; - elecstate::H_TDDFT_pw::tend = in->td_tend; + elecstate::H_TDDFT_pw::tstart = INPUT.td_tstart; + elecstate::H_TDDFT_pw::tend = INPUT.td_tend; - elecstate::H_TDDFT_pw::dt = in->mdp.md_dt / ModuleBase::AU_to_FS; + elecstate::H_TDDFT_pw::dt = INPUT.mdp.md_dt / ModuleBase::AU_to_FS; // space domain parameters // length gauge - elecstate::H_TDDFT_pw::lcut1 = in->td_lcut1; - elecstate::H_TDDFT_pw::lcut2 = in->td_lcut2; + elecstate::H_TDDFT_pw::lcut1 = INPUT.td_lcut1; + elecstate::H_TDDFT_pw::lcut2 = INPUT.td_lcut2; // time domain parameters // Gauss elecstate::H_TDDFT_pw::gauss_omega - = convert_units(in->td_gauss_freq, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 - elecstate::H_TDDFT_pw::gauss_phase = convert_units(in->td_gauss_phase, 1.0); - elecstate::H_TDDFT_pw::gauss_sigma = convert_units(in->td_gauss_sigma, 1 / ModuleBase::AU_to_FS); - elecstate::H_TDDFT_pw::gauss_t0 = convert_units(in->td_gauss_t0, 1.0); + = convert_units(INPUT.td_gauss_freq, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 + elecstate::H_TDDFT_pw::gauss_phase = convert_units(INPUT.td_gauss_phase, 1.0); + elecstate::H_TDDFT_pw::gauss_sigma = convert_units(INPUT.td_gauss_sigma, 1 / ModuleBase::AU_to_FS); + elecstate::H_TDDFT_pw::gauss_t0 = convert_units(INPUT.td_gauss_t0, 1.0); elecstate::H_TDDFT_pw::gauss_amp - = convert_units(in->td_gauss_amp, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr + = convert_units(INPUT.td_gauss_amp, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr // trapezoid elecstate::H_TDDFT_pw::trape_omega - = convert_units(in->td_trape_freq, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 - elecstate::H_TDDFT_pw::trape_phase = convert_units(in->td_trape_phase, 1.0); - elecstate::H_TDDFT_pw::trape_t1 = convert_units(in->td_trape_t1, 1.0); - elecstate::H_TDDFT_pw::trape_t2 = convert_units(in->td_trape_t2, 1.0); - elecstate::H_TDDFT_pw::trape_t3 = convert_units(in->td_trape_t3, 1.0); + = convert_units(INPUT.td_trape_freq, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 + elecstate::H_TDDFT_pw::trape_phase = convert_units(INPUT.td_trape_phase, 1.0); + elecstate::H_TDDFT_pw::trape_t1 = convert_units(INPUT.td_trape_t1, 1.0); + elecstate::H_TDDFT_pw::trape_t2 = convert_units(INPUT.td_trape_t2, 1.0); + elecstate::H_TDDFT_pw::trape_t3 = convert_units(INPUT.td_trape_t3, 1.0); elecstate::H_TDDFT_pw::trape_amp - = convert_units(in->td_trape_amp, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr + = convert_units(INPUT.td_trape_amp, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr // Trigonometric elecstate::H_TDDFT_pw::trigo_omega1 - = convert_units(in->td_trigo_freq1, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 + = convert_units(INPUT.td_trigo_freq1, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 elecstate::H_TDDFT_pw::trigo_omega2 - = convert_units(in->td_trigo_freq2, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 - elecstate::H_TDDFT_pw::trigo_phase1 = convert_units(in->td_trigo_phase1, 1.0); - elecstate::H_TDDFT_pw::trigo_phase2 = convert_units(in->td_trigo_phase2, 1.0); + = convert_units(INPUT.td_trigo_freq2, 2 * ModuleBase::PI * ModuleBase::AU_to_FS); // time(a.u.)^-1 + elecstate::H_TDDFT_pw::trigo_phase1 = convert_units(INPUT.td_trigo_phase1, 1.0); + elecstate::H_TDDFT_pw::trigo_phase2 = convert_units(INPUT.td_trigo_phase2, 1.0); elecstate::H_TDDFT_pw::trigo_amp - = convert_units(in->td_trigo_amp, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr + = convert_units(INPUT.td_trigo_amp, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr // Heaviside - elecstate::H_TDDFT_pw::heavi_t0 = convert_units(in->td_heavi_t0, 1.0); + elecstate::H_TDDFT_pw::heavi_t0 = convert_units(INPUT.td_heavi_t0, 1.0); elecstate::H_TDDFT_pw::heavi_amp - = convert_units(in->td_heavi_amp, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr + = convert_units(INPUT.td_heavi_amp, ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); // Ry/bohr return; } diff --git a/source/module_io/input_conv.h b/source/module_io/input_conv.h index 191f3f2a60..58f6fa0f81 100644 --- a/source/module_io/input_conv.h +++ b/source/module_io/input_conv.h @@ -40,10 +40,8 @@ std::vector convert_units(std::string params, double c); /** * @brief read paramers of electric field for tddft and convert units - * - * @param in input */ -void read_td_efield(Input* in); +void read_td_efield(); #endif } // namespace Input_Conv From 328ea91e78368d76ceade916eacdd1f91cc9668e Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Mon, 15 May 2023 15:18:22 +0800 Subject: [PATCH 20/48] remove input parameter of read_td_efield --- source/module_io/input_conv.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/module_io/input_conv.cpp b/source/module_io/input_conv.cpp index eafa33d08e..e3f01bdc9e 100644 --- a/source/module_io/input_conv.cpp +++ b/source/module_io/input_conv.cpp @@ -458,7 +458,7 @@ void Input_Conv::Convert(void) module_tddft::Evolve_elec::out_efield = INPUT.out_efield; module_tddft::Evolve_elec::td_print_eij = INPUT.td_print_eij; module_tddft::Evolve_elec::td_edm = INPUT.td_edm; - read_td_efield(&INPUT); + read_td_efield(); #endif // setting for constrained DFT, jiyy add 2020.10.11 From 729a668dfdeb8f943c346497894306dbdebb4e0b Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Mon, 15 May 2023 21:03:14 +0800 Subject: [PATCH 21/48] fix bug for input UTs --- source/module_io/input_conv.cpp | 2 +- source/module_io/input_conv.h | 3 +- .../module_io/test/for_testing_input_conv.h | 55 +++++++++++++++++++ 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/source/module_io/input_conv.cpp b/source/module_io/input_conv.cpp index e3f01bdc9e..e425097e0c 100644 --- a/source/module_io/input_conv.cpp +++ b/source/module_io/input_conv.cpp @@ -16,6 +16,7 @@ #endif #ifdef __LCAO #include "module_basis/module_ao/ORB_read.h" +#include "module_elecstate/potentials/H_TDDFT_pw.h" #include "module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.h" #include "module_hamilt_lcao/hamilt_lcaodft/global_fp.h" #include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_charge.h" @@ -24,7 +25,6 @@ #endif #include "module_base/timer.h" #include "module_elecstate/elecstate_lcao.h" -#include "module_elecstate/potentials/H_TDDFT_pw.h" #include "module_elecstate/potentials/efield.h" #include "module_elecstate/potentials/gatefield.h" #include "module_hsolver/hsolver_lcao.h" diff --git a/source/module_io/input_conv.h b/source/module_io/input_conv.h index 58f6fa0f81..54730e7e3c 100644 --- a/source/module_io/input_conv.h +++ b/source/module_io/input_conv.h @@ -15,8 +15,6 @@ #include #include -#include "module_io/input.h" - using namespace std; namespace Input_Conv @@ -43,6 +41,7 @@ std::vector convert_units(std::string params, double c); */ void read_td_efield(); #endif + } // namespace Input_Conv #endif // Input_Convert diff --git a/source/module_io/test/for_testing_input_conv.h b/source/module_io/test/for_testing_input_conv.h index dcdad3b628..7a390d33fb 100644 --- a/source/module_io/test/for_testing_input_conv.h +++ b/source/module_io/test/for_testing_input_conv.h @@ -6,6 +6,7 @@ #include "module_elecstate/energy.h" #include "module_elecstate/module_charge/charge_mixing.h" #include "module_elecstate/occupy.h" +#include "module_elecstate/potentials/H_TDDFT_pw.h" #include "module_elecstate/potentials/efield.h" #include "module_elecstate/potentials/gatefield.h" #include "module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.h" @@ -50,6 +51,60 @@ int elecstate::Efield::efield_dir; double elecstate::Efield::efield_pos_max; double elecstate::Efield::efield_pos_dec; double elecstate::Efield::efield_amp; + +// parameters of electric field for tddft + +int elecstate::H_TDDFT_pw::stype; // 0 : length gauge 1: velocity gauge + +std::vector elecstate::H_TDDFT_pw::ttype; +// 0 Gauss type function. +// 1 trapezoid type function. +// 2 Trigonometric functions, sin^2. +// 3 heaviside function. +// 4 HHG function. + +int elecstate::H_TDDFT_pw::tstart; +int elecstate::H_TDDFT_pw::tend; +double elecstate::H_TDDFT_pw::dt; + +// space domain parameters + +// length gauge +double elecstate::H_TDDFT_pw::lcut1; +double elecstate::H_TDDFT_pw::lcut2; + +// time domain parameters + +// Gauss +int elecstate::H_TDDFT_pw::gauss_count; +std::vector elecstate::H_TDDFT_pw::gauss_omega; // time(a.u.)^-1 +std::vector elecstate::H_TDDFT_pw::gauss_phase; +std::vector elecstate::H_TDDFT_pw::gauss_sigma; // time(a.u.) +std::vector elecstate::H_TDDFT_pw::gauss_t0; +std::vector elecstate::H_TDDFT_pw::gauss_amp; // Ry/bohr + +// trapezoid +int elecstate::H_TDDFT_pw::trape_count; +std::vector elecstate::H_TDDFT_pw::trape_omega; // time(a.u.)^-1 +std::vector elecstate::H_TDDFT_pw::trape_phase; +std::vector elecstate::H_TDDFT_pw::trape_t1; +std::vector elecstate::H_TDDFT_pw::trape_t2; +std::vector elecstate::H_TDDFT_pw::trape_t3; +std::vector elecstate::H_TDDFT_pw::trape_amp; // Ry/bohr + +// Trigonometric +int elecstate::H_TDDFT_pw::trigo_count; +std::vector elecstate::H_TDDFT_pw::trigo_omega1; // time(a.u.)^-1 +std::vector elecstate::H_TDDFT_pw::trigo_omega2; // time(a.u.)^-1 +std::vector elecstate::H_TDDFT_pw::trigo_phase1; +std::vector elecstate::H_TDDFT_pw::trigo_phase2; +std::vector elecstate::H_TDDFT_pw::trigo_amp; // Ry/bohr + +// Heaviside +int elecstate::H_TDDFT_pw::heavi_count; +std::vector elecstate::H_TDDFT_pw::heavi_t0; +std::vector elecstate::H_TDDFT_pw::heavi_amp; // Ry/bohr + double Force_Stress_LCAO::force_invalid_threshold_ev = 0.0; double BFGS_Basic::relax_bfgs_w1 = -1.0; double BFGS_Basic::relax_bfgs_w2 = -1.0; From f9ca299f03f64681686025c520043ff5d4120dce Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Tue, 16 May 2023 10:59:25 +0800 Subject: [PATCH 22/48] change name of parameters of compute_force in H_TDDFT_pw.h --- source/module_elecstate/potentials/H_TDDFT_pw.cpp | 4 ++-- source/module_elecstate/potentials/H_TDDFT_pw.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/module_elecstate/potentials/H_TDDFT_pw.cpp b/source/module_elecstate/potentials/H_TDDFT_pw.cpp index 5366e9e187..c1b67cc64d 100644 --- a/source/module_elecstate/potentials/H_TDDFT_pw.cpp +++ b/source/module_elecstate/potentials/H_TDDFT_pw.cpp @@ -337,7 +337,7 @@ void H_TDDFT_pw::prepare(const UnitCell& cell, int& dir) bmod = sqrt(pow(bvec[0], 2) + pow(bvec[1], 2) + pow(bvec[2], 2)); } -void H_TDDFT_pw ::compute_force(const UnitCell& cell, ModuleBase::matrix& fdip) +void H_TDDFT_pw ::compute_force(const UnitCell& cell, ModuleBase::matrix& fe) { int iat = 0; for (int it = 0; it < cell.ntype; ++it) @@ -346,7 +346,7 @@ void H_TDDFT_pw ::compute_force(const UnitCell& cell, ModuleBase::matrix& fdip) { for (int jj = 0; jj < 3; ++jj) { - fdip(iat, jj) = ModuleBase::e2 * amp * cell.atoms[it].ncpp.zv * bvec[jj] / bmod; + fe(iat, jj) = ModuleBase::e2 * amp * cell.atoms[it].ncpp.zv * bvec[jj] / bmod; } ++iat; } diff --git a/source/module_elecstate/potentials/H_TDDFT_pw.h b/source/module_elecstate/potentials/H_TDDFT_pw.h index b2cfd39bb8..15b97f9afd 100644 --- a/source/module_elecstate/potentials/H_TDDFT_pw.h +++ b/source/module_elecstate/potentials/H_TDDFT_pw.h @@ -26,9 +26,9 @@ class H_TDDFT_pw : public PotBase * @brief compute force of electric field * * @param[in] cell information of cell - * @param[out] fdip force of electric field + * @param[out] fe force of electric field F=qE */ - static void compute_force(const UnitCell& cell, ModuleBase::matrix& fdip); + static void compute_force(const UnitCell& cell, ModuleBase::matrix& fe); // parameters static int stype; // 0 : length gauge 1: velocity gauge From ee10c650658a8edbbc2df3bab6e3cb249afc347e Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Tue, 16 May 2023 11:03:51 +0800 Subject: [PATCH 23/48] improve annotation --- source/module_io/input_conv.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/module_io/input_conv.h b/source/module_io/input_conv.h index 54730e7e3c..f553dea9e8 100644 --- a/source/module_io/input_conv.h +++ b/source/module_io/input_conv.h @@ -28,11 +28,11 @@ template void parse_expression(const std::string &fn, std::vector convert_units(std::string params, double c); From 18dfa10045e6f7216db349a504e48cdc03aedfb7 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Tue, 16 May 2023 16:07:53 +0800 Subject: [PATCH 24/48] solve conflicts --- source/module_esolver/esolver_ks_lcao_tddft.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/source/module_esolver/esolver_ks_lcao_tddft.cpp b/source/module_esolver/esolver_ks_lcao_tddft.cpp index ddfab64852..3de3a66acf 100644 --- a/source/module_esolver/esolver_ks_lcao_tddft.cpp +++ b/source/module_esolver/esolver_ks_lcao_tddft.cpp @@ -178,11 +178,6 @@ void ESolver_KS_LCAO_TDDFT::hamilt2density(int istep, int iter, double ethr) << endl; } - // transform energy for print - GlobalC::en.eband = this->pelec_td->eband; - GlobalC::en.demet = this->pelec_td->demet; - GlobalC::en.ef = this->pelec_td->ef; - for (int ik = 0; ik < GlobalC::kv.nks; ++ik) { this->pelec_td->print_band(ik, INPUT.printe, iter); From 08e8b481e3bc4307781e88f3e7ead8a64f3b443a Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Tue, 16 May 2023 16:19:38 +0800 Subject: [PATCH 25/48] solve conflicts --- source/module_io/test/for_testing_input_conv.h | 1 - 1 file changed, 1 deletion(-) diff --git a/source/module_io/test/for_testing_input_conv.h b/source/module_io/test/for_testing_input_conv.h index 31ec476938..8048fdcdc0 100644 --- a/source/module_io/test/for_testing_input_conv.h +++ b/source/module_io/test/for_testing_input_conv.h @@ -3,7 +3,6 @@ #include "module_cell/module_symmetry/symmetry.h" #include "module_cell/unitcell.h" #include "module_elecstate/elecstate_lcao.h" -#include "module_elecstate/energy.h" #include "module_elecstate/module_charge/charge_mixing.h" #include "module_elecstate/occupy.h" #include "module_elecstate/potentials/H_TDDFT_pw.h" From a40e106436c4641c85f255eefc84a24da676dfef Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Tue, 16 May 2023 16:34:23 +0800 Subject: [PATCH 26/48] add UT for read_td_efield --- source/module_io/test/input_conv_test.cpp | 59 +++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/source/module_io/test/input_conv_test.cpp b/source/module_io/test/input_conv_test.cpp index 2e9b934242..78df97be8f 100644 --- a/source/module_io/test/input_conv_test.cpp +++ b/source/module_io/test/input_conv_test.cpp @@ -16,6 +16,8 @@ #define private public #include "module_io/input.h" +using ::testing::ElementsAre; + class InputConvTest : public testing::Test { protected: @@ -534,4 +536,61 @@ TEST_F(InputConvTest,ParseExpressionDouble) EXPECT_DOUBLE_EQ(vec[3],0.5); } +TEST_F(InputConvTest, ConvertUnitsWithEmptyParams) +{ + std::string params = ""; + double c = 2.0; + std::vector expected = {}; + std::vector result = Input_Conv::convert_units(params, c); + EXPECT_EQ(result, expected); +} + +TEST_F(InputConvTest, ConvertUnitsWithSingleParam) +{ + std::string params = "1.23"; + double c = 2.0; + std::vector expected = {2.46}; + std::vector result = Input_Conv::convert_units(params, c); + EXPECT_EQ(result, expected); +} + +TEST_F(InputConvTest, ConvertUnitsWithMultipleParams) +{ + std::string params = "1.23 4.56 7.89"; + double c = 0.5; + std::vector expected = {0.615, 2.28, 3.945}; + std::vector result = Input_Conv::convert_units(params, c); + EXPECT_EQ(result, expected); +} + +TEST(InputConvTest, ReadTdEfieldTest) +{ + Input_Conv::read_td_efield(); + + EXPECT_EQ(elecstate::H_TDDFT_pw::stype, 0); + EXPECT_THAT(elecstate::H_TDDFT_pw::ttype, ElementsAre(0)); + EXPECT_EQ(elecstate::H_TDDFT_pw::tstart, 1); + EXPECT_EQ(elecstate::H_TDDFT_pw::tend, 1000); + EXPECT_EQ(elecstate::H_TDDFT_pw::lcut1, 0.05); + EXPECT_EQ(elecstate::H_TDDFT_pw::lcut2, 0.95); + EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_omega, ElementsAre(22.13 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); + EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_phase, ElementsAre(0.0)); + EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_sigma, ElementsAre(30.0 / ModuleBase::AU_to_FS)); + EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_t0, ElementsAre(100.0)); + EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_amp, ElementsAre(0.25 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_omega, ElementsAre(1.60 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_phase, ElementsAre(0.0)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t1, ElementsAre(1875)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t2, ElementsAre(5625)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t3, ElementsAre(7500)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_amp, ElementsAre(2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_omega1, ElementsAre(1.164656 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_omega2, ElementsAre(0.029116 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_phase1, ElementsAre(0.0)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_phase2, ElementsAre(0.0)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_amp, ElementsAre(2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); + EXPECT_THAT(elecstate::H_TDDFT_pw::heavi_t0, ElementsAre(100)); + EXPECT_THAT(elecstate::H_TDDFT_pw::heavi_amp, ElementsAre(1.00 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); +} + #undef private From 8b3d63702b0b3546e6303cca394ced67546c7ce2 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Tue, 16 May 2023 17:07:05 +0800 Subject: [PATCH 27/48] add ifdef __LCAO --- source/module_io/test/input_conv_test.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/module_io/test/input_conv_test.cpp b/source/module_io/test/input_conv_test.cpp index 78df97be8f..7292e352d4 100644 --- a/source/module_io/test/input_conv_test.cpp +++ b/source/module_io/test/input_conv_test.cpp @@ -554,6 +554,7 @@ TEST_F(InputConvTest, ConvertUnitsWithSingleParam) EXPECT_EQ(result, expected); } +#ifdef __LCAO TEST_F(InputConvTest, ConvertUnitsWithMultipleParams) { std::string params = "1.23 4.56 7.89"; @@ -592,5 +593,6 @@ TEST(InputConvTest, ReadTdEfieldTest) EXPECT_THAT(elecstate::H_TDDFT_pw::heavi_t0, ElementsAre(100)); EXPECT_THAT(elecstate::H_TDDFT_pw::heavi_amp, ElementsAre(1.00 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); } +#endif #undef private From b2335c8656704e516a85dab37c447a41ead199e5 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Tue, 16 May 2023 17:32:39 +0800 Subject: [PATCH 28/48] add ifdef __LCAO --- source/module_io/test/input_conv_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/module_io/test/input_conv_test.cpp b/source/module_io/test/input_conv_test.cpp index 7292e352d4..7e1cbb81df 100644 --- a/source/module_io/test/input_conv_test.cpp +++ b/source/module_io/test/input_conv_test.cpp @@ -536,6 +536,7 @@ TEST_F(InputConvTest,ParseExpressionDouble) EXPECT_DOUBLE_EQ(vec[3],0.5); } +#ifdef __LCAO TEST_F(InputConvTest, ConvertUnitsWithEmptyParams) { std::string params = ""; @@ -554,7 +555,6 @@ TEST_F(InputConvTest, ConvertUnitsWithSingleParam) EXPECT_EQ(result, expected); } -#ifdef __LCAO TEST_F(InputConvTest, ConvertUnitsWithMultipleParams) { std::string params = "1.23 4.56 7.89"; From d4a48aa1028db3b62f2d351f29f31718e129e470 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Tue, 16 May 2023 21:59:02 +0800 Subject: [PATCH 29/48] mistake for TEST and TEST_F --- source/module_io/test/input_conv_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/module_io/test/input_conv_test.cpp b/source/module_io/test/input_conv_test.cpp index 7e1cbb81df..4cfc6da7c5 100644 --- a/source/module_io/test/input_conv_test.cpp +++ b/source/module_io/test/input_conv_test.cpp @@ -564,7 +564,7 @@ TEST_F(InputConvTest, ConvertUnitsWithMultipleParams) EXPECT_EQ(result, expected); } -TEST(InputConvTest, ReadTdEfieldTest) +TEST_F(InputConvTest, ReadTdEfieldTest) { Input_Conv::read_td_efield(); From fa1b3d957a32dc82994f8c0f8d625aa59727b65f Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Tue, 16 May 2023 23:00:32 +0800 Subject: [PATCH 30/48] fix ReadTdEfieldTest --- source/module_io/test/input_conv_test.cpp | 40 +++++++++++------------ 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/source/module_io/test/input_conv_test.cpp b/source/module_io/test/input_conv_test.cpp index 4cfc6da7c5..88ebbaa3d5 100644 --- a/source/module_io/test/input_conv_test.cpp +++ b/source/module_io/test/input_conv_test.cpp @@ -16,8 +16,6 @@ #define private public #include "module_io/input.h" -using ::testing::ElementsAre; - class InputConvTest : public testing::Test { protected: @@ -569,29 +567,29 @@ TEST_F(InputConvTest, ReadTdEfieldTest) Input_Conv::read_td_efield(); EXPECT_EQ(elecstate::H_TDDFT_pw::stype, 0); - EXPECT_THAT(elecstate::H_TDDFT_pw::ttype, ElementsAre(0)); + EXPECT_EQ(elecstate::H_TDDFT_pw::ttype[0], ElementsAre(0)); EXPECT_EQ(elecstate::H_TDDFT_pw::tstart, 1); EXPECT_EQ(elecstate::H_TDDFT_pw::tend, 1000); EXPECT_EQ(elecstate::H_TDDFT_pw::lcut1, 0.05); EXPECT_EQ(elecstate::H_TDDFT_pw::lcut2, 0.95); - EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_omega, ElementsAre(22.13 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); - EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_phase, ElementsAre(0.0)); - EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_sigma, ElementsAre(30.0 / ModuleBase::AU_to_FS)); - EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_t0, ElementsAre(100.0)); - EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_amp, ElementsAre(0.25 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_omega, ElementsAre(1.60 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_phase, ElementsAre(0.0)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t1, ElementsAre(1875)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t2, ElementsAre(5625)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t3, ElementsAre(7500)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_amp, ElementsAre(2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_omega1, ElementsAre(1.164656 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_omega2, ElementsAre(0.029116 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_phase1, ElementsAre(0.0)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_phase2, ElementsAre(0.0)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_amp, ElementsAre(2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); - EXPECT_THAT(elecstate::H_TDDFT_pw::heavi_t0, ElementsAre(100)); - EXPECT_THAT(elecstate::H_TDDFT_pw::heavi_amp, ElementsAre(1.00 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); + EXPECT_EQ(elecstate::H_TDDFT_pw::gauss_omega[0], 22.13 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS); + EXPECT_EQ(elecstate::H_TDDFT_pw::gauss_phase[0], 0.0) + EXPECT_EQ(elecstate::H_TDDFT_pw::gauss_sigma[0], 30.0 / ModuleBase::AU_to_FS) + EXPECT_EQ(elecstate::H_TDDFT_pw::gauss_t0[0], 100.0) + EXPECT_EQ(elecstate::H_TDDFT_pw::gauss_amp[0], 0.25 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV) + EXPECT_EQ(elecstate::H_TDDFT_pw::trape_omega[0], 1.60 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS) + EXPECT_EQ(elecstate::H_TDDFT_pw::trape_phase[0], 0.0) + EXPECT_EQ(elecstate::H_TDDFT_pw::trape_t1[0], 1875) + EXPECT_EQ(elecstate::H_TDDFT_pw::trape_t2[0], 5625) + EXPECT_EQ(elecstate::H_TDDFT_pw::trape_t3[0], 7500) + EXPECT_EQ(elecstate::H_TDDFT_pw::trape_amp[0], 2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV) + EXPECT_EQ(elecstate::H_TDDFT_pw::trigo_omega1[0], 1.164656 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS) + EXPECT_EQ(elecstate::H_TDDFT_pw::trigo_omega2[0], 0.029116 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS) + EXPECT_EQ(elecstate::H_TDDFT_pw::trigo_phase1[0], 0.0) + EXPECT_EQ(elecstate::H_TDDFT_pw::trigo_phase2[0], 0.0) + EXPECT_EQ(elecstate::H_TDDFT_pw::trigo_amp[0], 2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV) + EXPECT_EQ(elecstate::H_TDDFT_pw::heavi_t0[0], 100) + EXPECT_EQ(elecstate::H_TDDFT_pw::heavi_amp[0], 1.00 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV) } #endif From 025f9f760229c312a0513b84c9a7b6e3afb9c855 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Tue, 16 May 2023 23:35:22 +0800 Subject: [PATCH 31/48] fix ReadTdEfieldTest --- source/module_io/test/input_conv_test.cpp | 36 +++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/source/module_io/test/input_conv_test.cpp b/source/module_io/test/input_conv_test.cpp index 88ebbaa3d5..e8c67382d3 100644 --- a/source/module_io/test/input_conv_test.cpp +++ b/source/module_io/test/input_conv_test.cpp @@ -567,29 +567,29 @@ TEST_F(InputConvTest, ReadTdEfieldTest) Input_Conv::read_td_efield(); EXPECT_EQ(elecstate::H_TDDFT_pw::stype, 0); - EXPECT_EQ(elecstate::H_TDDFT_pw::ttype[0], ElementsAre(0)); + EXPECT_EQ(elecstate::H_TDDFT_pw::ttype[0], 0); EXPECT_EQ(elecstate::H_TDDFT_pw::tstart, 1); EXPECT_EQ(elecstate::H_TDDFT_pw::tend, 1000); EXPECT_EQ(elecstate::H_TDDFT_pw::lcut1, 0.05); EXPECT_EQ(elecstate::H_TDDFT_pw::lcut2, 0.95); EXPECT_EQ(elecstate::H_TDDFT_pw::gauss_omega[0], 22.13 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS); - EXPECT_EQ(elecstate::H_TDDFT_pw::gauss_phase[0], 0.0) - EXPECT_EQ(elecstate::H_TDDFT_pw::gauss_sigma[0], 30.0 / ModuleBase::AU_to_FS) - EXPECT_EQ(elecstate::H_TDDFT_pw::gauss_t0[0], 100.0) - EXPECT_EQ(elecstate::H_TDDFT_pw::gauss_amp[0], 0.25 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV) - EXPECT_EQ(elecstate::H_TDDFT_pw::trape_omega[0], 1.60 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS) - EXPECT_EQ(elecstate::H_TDDFT_pw::trape_phase[0], 0.0) - EXPECT_EQ(elecstate::H_TDDFT_pw::trape_t1[0], 1875) - EXPECT_EQ(elecstate::H_TDDFT_pw::trape_t2[0], 5625) - EXPECT_EQ(elecstate::H_TDDFT_pw::trape_t3[0], 7500) - EXPECT_EQ(elecstate::H_TDDFT_pw::trape_amp[0], 2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV) - EXPECT_EQ(elecstate::H_TDDFT_pw::trigo_omega1[0], 1.164656 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS) - EXPECT_EQ(elecstate::H_TDDFT_pw::trigo_omega2[0], 0.029116 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS) - EXPECT_EQ(elecstate::H_TDDFT_pw::trigo_phase1[0], 0.0) - EXPECT_EQ(elecstate::H_TDDFT_pw::trigo_phase2[0], 0.0) - EXPECT_EQ(elecstate::H_TDDFT_pw::trigo_amp[0], 2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV) - EXPECT_EQ(elecstate::H_TDDFT_pw::heavi_t0[0], 100) - EXPECT_EQ(elecstate::H_TDDFT_pw::heavi_amp[0], 1.00 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV) + EXPECT_EQ(elecstate::H_TDDFT_pw::gauss_phase[0], 0.0); + EXPECT_EQ(elecstate::H_TDDFT_pw::gauss_sigma[0], 30.0 / ModuleBase::AU_to_FS); + EXPECT_EQ(elecstate::H_TDDFT_pw::gauss_t0[0], 100.0); + EXPECT_EQ(elecstate::H_TDDFT_pw::gauss_amp[0], 0.25 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); + EXPECT_EQ(elecstate::H_TDDFT_pw::trape_omega[0], 1.60 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS); + EXPECT_EQ(elecstate::H_TDDFT_pw::trape_phase[0], 0.0); + EXPECT_EQ(elecstate::H_TDDFT_pw::trape_t1[0], 1875); + EXPECT_EQ(elecstate::H_TDDFT_pw::trape_t2[0], 5625); + EXPECT_EQ(elecstate::H_TDDFT_pw::trape_t3[0], 7500); + EXPECT_EQ(elecstate::H_TDDFT_pw::trape_amp[0], 2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); + EXPECT_EQ(elecstate::H_TDDFT_pw::trigo_omega1[0], 1.164656 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS); + EXPECT_EQ(elecstate::H_TDDFT_pw::trigo_omega2[0], 0.029116 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS); + EXPECT_EQ(elecstate::H_TDDFT_pw::trigo_phase1[0], 0.0); + EXPECT_EQ(elecstate::H_TDDFT_pw::trigo_phase2[0], 0.0); + EXPECT_EQ(elecstate::H_TDDFT_pw::trigo_amp[0], 2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); + EXPECT_EQ(elecstate::H_TDDFT_pw::heavi_t0[0], 100); + EXPECT_EQ(elecstate::H_TDDFT_pw::heavi_amp[0], 1.00 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); } #endif From 1e6563bfc888ec2d44ae4d7a6e6bacc5bf2b91de Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Wed, 17 May 2023 00:35:34 +0800 Subject: [PATCH 32/48] add doublenear() for EXPECT_EQ in ReadEfieldTest --- source/module_io/test/input_conv_test.cpp | 40 +++++++++++------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/source/module_io/test/input_conv_test.cpp b/source/module_io/test/input_conv_test.cpp index e8c67382d3..eb87cd7b28 100644 --- a/source/module_io/test/input_conv_test.cpp +++ b/source/module_io/test/input_conv_test.cpp @@ -562,34 +562,34 @@ TEST_F(InputConvTest, ConvertUnitsWithMultipleParams) EXPECT_EQ(result, expected); } -TEST_F(InputConvTest, ReadTdEfieldTest) +TEST(InputConvTest, ReadTdEfieldTest) { Input_Conv::read_td_efield(); EXPECT_EQ(elecstate::H_TDDFT_pw::stype, 0); - EXPECT_EQ(elecstate::H_TDDFT_pw::ttype[0], 0); + EXPECT_THAT(elecstate::H_TDDFT_pw::ttype, DoubleNear(0)); EXPECT_EQ(elecstate::H_TDDFT_pw::tstart, 1); EXPECT_EQ(elecstate::H_TDDFT_pw::tend, 1000); EXPECT_EQ(elecstate::H_TDDFT_pw::lcut1, 0.05); EXPECT_EQ(elecstate::H_TDDFT_pw::lcut2, 0.95); - EXPECT_EQ(elecstate::H_TDDFT_pw::gauss_omega[0], 22.13 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS); - EXPECT_EQ(elecstate::H_TDDFT_pw::gauss_phase[0], 0.0); - EXPECT_EQ(elecstate::H_TDDFT_pw::gauss_sigma[0], 30.0 / ModuleBase::AU_to_FS); - EXPECT_EQ(elecstate::H_TDDFT_pw::gauss_t0[0], 100.0); - EXPECT_EQ(elecstate::H_TDDFT_pw::gauss_amp[0], 0.25 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); - EXPECT_EQ(elecstate::H_TDDFT_pw::trape_omega[0], 1.60 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS); - EXPECT_EQ(elecstate::H_TDDFT_pw::trape_phase[0], 0.0); - EXPECT_EQ(elecstate::H_TDDFT_pw::trape_t1[0], 1875); - EXPECT_EQ(elecstate::H_TDDFT_pw::trape_t2[0], 5625); - EXPECT_EQ(elecstate::H_TDDFT_pw::trape_t3[0], 7500); - EXPECT_EQ(elecstate::H_TDDFT_pw::trape_amp[0], 2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); - EXPECT_EQ(elecstate::H_TDDFT_pw::trigo_omega1[0], 1.164656 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS); - EXPECT_EQ(elecstate::H_TDDFT_pw::trigo_omega2[0], 0.029116 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS); - EXPECT_EQ(elecstate::H_TDDFT_pw::trigo_phase1[0], 0.0); - EXPECT_EQ(elecstate::H_TDDFT_pw::trigo_phase2[0], 0.0); - EXPECT_EQ(elecstate::H_TDDFT_pw::trigo_amp[0], 2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); - EXPECT_EQ(elecstate::H_TDDFT_pw::heavi_t0[0], 100); - EXPECT_EQ(elecstate::H_TDDFT_pw::heavi_amp[0], 1.00 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV); + EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_omega, DoubleNear(22.13 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); + EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_phase, DoubleNear(0.0)); + EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_sigma, DoubleNear(30.0 / ModuleBase::AU_to_FS)); + EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_t0, DoubleNear(100.0)); + EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_amp, DoubleNear(0.25 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_omega, DoubleNear(1.60 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_phase, DoubleNear(0.0)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t1, DoubleNear(1875)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t2, DoubleNear(5625)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t3, DoubleNear(7500)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_amp, DoubleNear(2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_omega1, DoubleNear(1.164656 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_omega2, DoubleNear(0.029116 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_phase1, DoubleNear(0.0)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_phase2, DoubleNear(0.0)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_amp, DoubleNear(2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); + EXPECT_THAT(elecstate::H_TDDFT_pw::heavi_t0, DoubleNear(100)); + EXPECT_THAT(elecstate::H_TDDFT_pw::heavi_amp, DoubleNear(1.00 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); } #endif From 73dd38e9a38f7e282d848b952af7b47445d97819 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Wed, 17 May 2023 01:21:36 +0800 Subject: [PATCH 33/48] add nampspace for doublenear --- source/module_io/test/input_conv_test.cpp | 46 +++++++++++++---------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/source/module_io/test/input_conv_test.cpp b/source/module_io/test/input_conv_test.cpp index eb87cd7b28..c72bd70c70 100644 --- a/source/module_io/test/input_conv_test.cpp +++ b/source/module_io/test/input_conv_test.cpp @@ -567,29 +567,37 @@ TEST(InputConvTest, ReadTdEfieldTest) Input_Conv::read_td_efield(); EXPECT_EQ(elecstate::H_TDDFT_pw::stype, 0); - EXPECT_THAT(elecstate::H_TDDFT_pw::ttype, DoubleNear(0)); + EXPECT_THAT(elecstate::H_TDDFT_pw::ttype, testing::DoubleNear(0)); EXPECT_EQ(elecstate::H_TDDFT_pw::tstart, 1); EXPECT_EQ(elecstate::H_TDDFT_pw::tend, 1000); EXPECT_EQ(elecstate::H_TDDFT_pw::lcut1, 0.05); EXPECT_EQ(elecstate::H_TDDFT_pw::lcut2, 0.95); - EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_omega, DoubleNear(22.13 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); - EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_phase, DoubleNear(0.0)); - EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_sigma, DoubleNear(30.0 / ModuleBase::AU_to_FS)); - EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_t0, DoubleNear(100.0)); - EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_amp, DoubleNear(0.25 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_omega, DoubleNear(1.60 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_phase, DoubleNear(0.0)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t1, DoubleNear(1875)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t2, DoubleNear(5625)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t3, DoubleNear(7500)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_amp, DoubleNear(2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_omega1, DoubleNear(1.164656 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_omega2, DoubleNear(0.029116 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_phase1, DoubleNear(0.0)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_phase2, DoubleNear(0.0)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_amp, DoubleNear(2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); - EXPECT_THAT(elecstate::H_TDDFT_pw::heavi_t0, DoubleNear(100)); - EXPECT_THAT(elecstate::H_TDDFT_pw::heavi_amp, DoubleNear(1.00 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); + EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_omega, + testing::DoubleNear(22.13 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); + EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_phase, testing::DoubleNear(0.0)); + EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_sigma, testing::DoubleNear(30.0 / ModuleBase::AU_to_FS)); + EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_t0, testing::DoubleNear(100.0)); + EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_amp, + testing::DoubleNear(0.25 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_omega, + testing::DoubleNear(1.60 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_phase, testing::DoubleNear(0.0)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t1, testing::DoubleNear(1875)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t2, testing::DoubleNear(5625)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t3, testing::DoubleNear(7500)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_amp, + testing::DoubleNear(2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_omega1, + testing::DoubleNear(1.164656 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_omega2, + testing::DoubleNear(0.029116 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_phase1, testing::DoubleNear(0.0)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_phase2, testing::DoubleNear(0.0)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_amp, + testing::DoubleNear(2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); + EXPECT_THAT(elecstate::H_TDDFT_pw::heavi_t0, testing::DoubleNear(100)); + EXPECT_THAT(elecstate::H_TDDFT_pw::heavi_amp, + testing::DoubleNear(1.00 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); } #endif From 443e86fd4e23d716a0e3a37fe45f1c9b9f898f33 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Wed, 17 May 2023 01:44:43 +0800 Subject: [PATCH 34/48] add nampspace for doublenear --- source/module_io/test/input_conv_test.cpp | 46 +++++++++++------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/source/module_io/test/input_conv_test.cpp b/source/module_io/test/input_conv_test.cpp index c72bd70c70..caccebc242 100644 --- a/source/module_io/test/input_conv_test.cpp +++ b/source/module_io/test/input_conv_test.cpp @@ -567,36 +567,36 @@ TEST(InputConvTest, ReadTdEfieldTest) Input_Conv::read_td_efield(); EXPECT_EQ(elecstate::H_TDDFT_pw::stype, 0); - EXPECT_THAT(elecstate::H_TDDFT_pw::ttype, testing::DoubleNear(0)); - EXPECT_EQ(elecstate::H_TDDFT_pw::tstart, 1); - EXPECT_EQ(elecstate::H_TDDFT_pw::tend, 1000); - EXPECT_EQ(elecstate::H_TDDFT_pw::lcut1, 0.05); - EXPECT_EQ(elecstate::H_TDDFT_pw::lcut2, 0.95); - EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_omega, + EXPECT_EQ(elecstate::H_TDDFT_pw::ttype[0], 0); + EXPECT_EQ(elecstate::H_TDDFT_pw::tstart[0], 1); + EXPECT_EQ(elecstate::H_TDDFT_pw::tend[0], 1000); + EXPECT_EQ(elecstate::H_TDDFT_pw::lcut1[0], 0.05); + EXPECT_EQ(elecstate::H_TDDFT_pw::lcut2[0], 0.95); + EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_omega[0], testing::DoubleNear(22.13 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); - EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_phase, testing::DoubleNear(0.0)); - EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_sigma, testing::DoubleNear(30.0 / ModuleBase::AU_to_FS)); - EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_t0, testing::DoubleNear(100.0)); - EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_amp, + EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_phase[0], testing::DoubleNear(0.0)); + EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_sigma[0], testing::DoubleNear(30.0 / ModuleBase::AU_to_FS)); + EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_t0[0], testing::DoubleNear(100.0)); + EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_amp[0], testing::DoubleNear(0.25 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_omega, + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_omega[0], testing::DoubleNear(1.60 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_phase, testing::DoubleNear(0.0)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t1, testing::DoubleNear(1875)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t2, testing::DoubleNear(5625)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t3, testing::DoubleNear(7500)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_amp, + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_phase[0], testing::DoubleNear(0.0)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t1[0], testing::DoubleNear(1875)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t2[0], testing::DoubleNear(5625)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t3[0], testing::DoubleNear(7500)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trape_amp[0], testing::DoubleNear(2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_omega1, + EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_omega1[0], testing::DoubleNear(1.164656 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_omega2, + EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_omega2[0], testing::DoubleNear(0.029116 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_phase1, testing::DoubleNear(0.0)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_phase2, testing::DoubleNear(0.0)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_amp, + EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_phase1[0], testing::DoubleNear(0.0)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_phase2[0], testing::DoubleNear(0.0)); + EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_amp[0], testing::DoubleNear(2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); - EXPECT_THAT(elecstate::H_TDDFT_pw::heavi_t0, testing::DoubleNear(100)); - EXPECT_THAT(elecstate::H_TDDFT_pw::heavi_amp, + EXPECT_THAT(elecstate::H_TDDFT_pw::heavi_t0[0], testing::DoubleNear(100)); + EXPECT_THAT(elecstate::H_TDDFT_pw::heavi_amp[0], testing::DoubleNear(1.00 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); } #endif From 49af77d6b4a11ab48282961e3a19c2c248055157 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Wed, 17 May 2023 01:58:35 +0800 Subject: [PATCH 35/48] mistake --- source/module_io/test/input_conv_test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/module_io/test/input_conv_test.cpp b/source/module_io/test/input_conv_test.cpp index caccebc242..366b4cfd2b 100644 --- a/source/module_io/test/input_conv_test.cpp +++ b/source/module_io/test/input_conv_test.cpp @@ -568,10 +568,10 @@ TEST(InputConvTest, ReadTdEfieldTest) EXPECT_EQ(elecstate::H_TDDFT_pw::stype, 0); EXPECT_EQ(elecstate::H_TDDFT_pw::ttype[0], 0); - EXPECT_EQ(elecstate::H_TDDFT_pw::tstart[0], 1); - EXPECT_EQ(elecstate::H_TDDFT_pw::tend[0], 1000); - EXPECT_EQ(elecstate::H_TDDFT_pw::lcut1[0], 0.05); - EXPECT_EQ(elecstate::H_TDDFT_pw::lcut2[0], 0.95); + EXPECT_EQ(elecstate::H_TDDFT_pw::tstart, 1); + EXPECT_EQ(elecstate::H_TDDFT_pw::tend, 1000); + EXPECT_EQ(elecstate::H_TDDFT_pw::lcut1, 0.05); + EXPECT_EQ(elecstate::H_TDDFT_pw::lcut2, 0.95); EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_omega[0], testing::DoubleNear(22.13 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_phase[0], testing::DoubleNear(0.0)); From cf1107bbd7d17786caee876a06347a45743eb9ea Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Wed, 17 May 2023 02:16:00 +0800 Subject: [PATCH 36/48] replace doublenear with EXPECT_NEAR --- source/module_io/test/input_conv_test.cpp | 44 ++++++++++------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/source/module_io/test/input_conv_test.cpp b/source/module_io/test/input_conv_test.cpp index 366b4cfd2b..c4c9ef0f89 100644 --- a/source/module_io/test/input_conv_test.cpp +++ b/source/module_io/test/input_conv_test.cpp @@ -572,32 +572,24 @@ TEST(InputConvTest, ReadTdEfieldTest) EXPECT_EQ(elecstate::H_TDDFT_pw::tend, 1000); EXPECT_EQ(elecstate::H_TDDFT_pw::lcut1, 0.05); EXPECT_EQ(elecstate::H_TDDFT_pw::lcut2, 0.95); - EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_omega[0], - testing::DoubleNear(22.13 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); - EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_phase[0], testing::DoubleNear(0.0)); - EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_sigma[0], testing::DoubleNear(30.0 / ModuleBase::AU_to_FS)); - EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_t0[0], testing::DoubleNear(100.0)); - EXPECT_THAT(elecstate::H_TDDFT_pw::gauss_amp[0], - testing::DoubleNear(0.25 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_omega[0], - testing::DoubleNear(1.60 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_phase[0], testing::DoubleNear(0.0)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t1[0], testing::DoubleNear(1875)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t2[0], testing::DoubleNear(5625)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_t3[0], testing::DoubleNear(7500)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trape_amp[0], - testing::DoubleNear(2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_omega1[0], - testing::DoubleNear(1.164656 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_omega2[0], - testing::DoubleNear(0.029116 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_phase1[0], testing::DoubleNear(0.0)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_phase2[0], testing::DoubleNear(0.0)); - EXPECT_THAT(elecstate::H_TDDFT_pw::trigo_amp[0], - testing::DoubleNear(2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); - EXPECT_THAT(elecstate::H_TDDFT_pw::heavi_t0[0], testing::DoubleNear(100)); - EXPECT_THAT(elecstate::H_TDDFT_pw::heavi_amp[0], - testing::DoubleNear(1.00 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV)); + EXPECT_NEAR(elecstate::H_TDDFT_pw::gauss_omega[0], 22.13 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS, 1e-8); + EXPECT_EQ(elecstate::H_TDDFT_pw::gauss_phase[0], 0.0); + EXPECT_NEAR(elecstate::H_TDDFT_pw::gauss_sigma[0], 30.0 / ModuleBase::AU_to_FS, 1e-8); + EXPECT_EQ(elecstate::H_TDDFT_pw::gauss_t0[0], 100.0); + EXPECT_NEAR(elecstate::H_TDDFT_pw::gauss_amp[0], 0.25 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV, 1e-8); + EXPECT_NEAR(elecstate::H_TDDFT_pw::trape_omega[0], 1.60 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS, 1e-8); + EXPECT_EQ(elecstate::H_TDDFT_pw::trape_phase[0], 0.0); + EXPECT_EQ(elecstate::H_TDDFT_pw::trape_t1[0], 1875); + EXPECT_EQ(elecstate::H_TDDFT_pw::trape_t2[0], 5625); + EXPECT_EQ(elecstate::H_TDDFT_pw::trape_t3[0], 7500); + EXPECT_NEAR(elecstate::H_TDDFT_pw::trape_amp[0], 2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV, 1e-8); + EXPECT_NEAR(elecstate::H_TDDFT_pw::trigo_omega1[0], 1.164656 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS, 1e-8); + EXPECT_NEAR(elecstate::H_TDDFT_pw::trigo_omega2[0], 0.029116 * 2 * ModuleBase::PI * ModuleBase::AU_to_FS, 1e-8); + EXPECT_EQ(elecstate::H_TDDFT_pw::trigo_phase1[0], 0.0); + EXPECT_EQ(elecstate::H_TDDFT_pw::trigo_phase2[0], 0.0); + EXPECT_NEAR(elecstate::H_TDDFT_pw::trigo_amp[0], 2.74 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV, 1e-8); + EXPECT_EQ(elecstate::H_TDDFT_pw::heavi_t0[0], 100); + EXPECT_NEAR(elecstate::H_TDDFT_pw::heavi_amp[0], 1.00 * ModuleBase::BOHR_TO_A / ModuleBase::Ry_to_eV, 1e-8); } #endif From 14264e00354b693a70620b83f09e418f713a9325 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Wed, 17 May 2023 05:34:17 +0800 Subject: [PATCH 37/48] TEST_F --- source/module_io/test/input_conv_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/module_io/test/input_conv_test.cpp b/source/module_io/test/input_conv_test.cpp index c4c9ef0f89..9d6f911d0f 100644 --- a/source/module_io/test/input_conv_test.cpp +++ b/source/module_io/test/input_conv_test.cpp @@ -562,7 +562,7 @@ TEST_F(InputConvTest, ConvertUnitsWithMultipleParams) EXPECT_EQ(result, expected); } -TEST(InputConvTest, ReadTdEfieldTest) +TEST_F(InputConvTest, ReadTdEfieldTest) { Input_Conv::read_td_efield(); From ab573e61e735188d4d55b9f228673ec6b53b9e0b Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Wed, 17 May 2023 15:58:40 +0800 Subject: [PATCH 38/48] delete nband in propagator --- .../module_tddft/evolve_psi.cpp | 2 +- .../module_tddft/propagator.cpp | 22 ++++++++----------- .../module_tddft/propagator.h | 16 ++++---------- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/source/module_hamilt_lcao/module_tddft/evolve_psi.cpp b/source/module_hamilt_lcao/module_tddft/evolve_psi.cpp index ebd578efdb..c30f9891c7 100644 --- a/source/module_hamilt_lcao/module_tddft/evolve_psi.cpp +++ b/source/module_hamilt_lcao/module_tddft/evolve_psi.cpp @@ -67,7 +67,7 @@ void evolve_psi(const int nband, /// @input Stmp, Htmp, print_matrix /// @output U_operator Propagator prop(propagator, pv); - prop.compute_propagator(nband, nlocal, Stmp, Htmp, H_laststep, U_operator, print_matrix); + prop.compute_propagator(nlocal, Stmp, Htmp, H_laststep, U_operator, print_matrix); // (3)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> diff --git a/source/module_hamilt_lcao/module_tddft/propagator.cpp b/source/module_hamilt_lcao/module_tddft/propagator.cpp index f2711ed2f8..c48e4142ff 100644 --- a/source/module_hamilt_lcao/module_tddft/propagator.cpp +++ b/source/module_hamilt_lcao/module_tddft/propagator.cpp @@ -23,8 +23,7 @@ inline int globalIndex(int localindex, int nblk, int nprocs, int myproc) return gIndex; } -void Propagator::compute_propagator(const int nband, - const int nlocal, +void Propagator::compute_propagator(const int nlocal, const std::complex* Stmp, const std::complex* Htmp, const std::complex* H_laststep, @@ -35,16 +34,16 @@ void Propagator::compute_propagator(const int nband, switch (ptype) { case 0: - compute_propagator_cn2(nband, nlocal, Stmp, Htmp, U_operator, print_matrix); + compute_propagator_cn2(nlocal, Stmp, Htmp, U_operator, print_matrix); break; case 1: tag = 1; - compute_propagator_taylor(nband, nlocal, Stmp, Htmp, U_operator, print_matrix, tag); + compute_propagator_taylor(nlocal, Stmp, Htmp, U_operator, print_matrix, tag); break; case 2: - compute_propagator_etrs(nband, nlocal, Stmp, Htmp, H_laststep, U_operator, print_matrix); + compute_propagator_etrs(nlocal, Stmp, Htmp, H_laststep, U_operator, print_matrix); break; @@ -54,8 +53,7 @@ void Propagator::compute_propagator(const int nband, } } -void Propagator::compute_propagator_cn2(const int nband, - const int nlocal, +void Propagator::compute_propagator_cn2(const int nlocal, const std::complex* Stmp, const std::complex* Htmp, std::complex* U_operator, @@ -259,8 +257,7 @@ void Propagator::compute_propagator_cn2(const int nband, delete[] ipiv; } -void Propagator::compute_propagator_taylor(const int nband, - const int nlocal, +void Propagator::compute_propagator_taylor(const int nlocal, const std::complex* Stmp, const std::complex* Htmp, std::complex* U_operator, @@ -580,8 +577,7 @@ void Propagator::compute_propagator_taylor(const int nband, delete[] ipiv; } -void Propagator::compute_propagator_etrs(const int nband, - const int nlocal, +void Propagator::compute_propagator_etrs(const int nlocal, const std::complex* Stmp, const std::complex* Htmp, const std::complex* H_laststep, @@ -593,8 +589,8 @@ void Propagator::compute_propagator_etrs(const int nband, ModuleBase::GlobalFunc::ZEROS(U1, this->ParaV->nloc); ModuleBase::GlobalFunc::ZEROS(U2, this->ParaV->nloc); int tag = 2; - compute_propagator_taylor(nband, nlocal, Stmp, Htmp, U1, print_matrix, tag); - compute_propagator_taylor(nband, nlocal, Stmp, H_laststep, U2, print_matrix, tag); + compute_propagator_taylor(nlocal, Stmp, Htmp, U1, print_matrix, tag); + compute_propagator_taylor(nlocal, Stmp, H_laststep, U2, print_matrix, tag); ScalapackConnector::gemm('N', 'N', nlocal, diff --git a/source/module_hamilt_lcao/module_tddft/propagator.h b/source/module_hamilt_lcao/module_tddft/propagator.h index 7d9e65b2c4..a156ca1355 100644 --- a/source/module_hamilt_lcao/module_tddft/propagator.h +++ b/source/module_hamilt_lcao/module_tddft/propagator.h @@ -24,7 +24,6 @@ class Propagator /** * @brief compute propagator * - * @param[in] nband number of bands * @param[in] nlocal number of orbitals * @param[in] Stmp overlap matrix * @param[in] Htmp H(t+dt/2) or H(t+dt) @@ -32,8 +31,7 @@ class Propagator * @param[in] print_matirx print internal matrix or not * @param[out] U_operator operator of propagator */ - void compute_propagator(const int nband, - const int nlocal, + void compute_propagator(const int nlocal, const std::complex* Stmp, const std::complex* Htmp, const std::complex* H_laststep, @@ -50,15 +48,13 @@ class Propagator /** * @brief compute propagator of method Crank-Nicolson * - * @param[in] nband number of bands * @param[in] nlocal number of orbitals * @param[in] Stmp overlap matrix * @param[in] Htmp H(t+dt/2) or H(t+dt) * @param[in] print_matirx print internal matrix or not * @param[out] U_operator operator of propagator */ - void compute_propagator_cn2(const int nband, - const int nlocal, + void compute_propagator_cn2(const int nlocal, const std::complex* Stmp, const std::complex* Htmp, std::complex* U_operator, @@ -67,7 +63,6 @@ class Propagator /** * @brief compute propagator of method 4th Taylor * - * @param[in] nband number of bands * @param[in] nlocal number of orbitals * @param[in] Stmp overlap matrix * @param[in] Htmp H(t+dt/2) or H(t+dt) @@ -75,8 +70,7 @@ class Propagator * @param[in] tag a parametre different for 4th Taylor and ETRS * @param[out] U_operator operator of propagator */ - void compute_propagator_taylor(const int nband, - const int nlocal, + void compute_propagator_taylor(const int nlocal, const std::complex* Stmp, const std::complex* Htmp, std::complex* U_operator, @@ -86,7 +80,6 @@ class Propagator /** * @brief compute propagator of method ETRS * - * @param[in] nband number of bands * @param[in] nlocal number of orbitals * @param[in] Stmp overlap matrix * @param[in] Htmp H(t+dt/2) or H(t+dt) @@ -94,8 +87,7 @@ class Propagator * @param[in] print_matirx print internal matrix or not * @param[out] U_operator operator of propagator */ - void compute_propagator_etrs(const int nband, - const int nlocal, + void compute_propagator_etrs(const int nlocal, const std::complex* Stmp, const std::complex* Htmp, const std::complex* H_laststep, From 075f0f737d2a5ba52bd599b0caa8ceb03062979b Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Thu, 1 Jun 2023 14:35:32 +0800 Subject: [PATCH 39/48] add UT for module tddft --- source/module_base/blacs_connector.h | 5 +- .../module_tddft/CMakeLists.txt | 4 + .../module_tddft/test/CMakeLists.txt | 13 ++ .../module_tddft/test/bandenergy_test.cpp | 101 ++++++++++++++ .../module_tddft/test/middle_hamilt_test.cpp | 100 ++++++++++++++ .../module_tddft/test/norm_psi_test.cpp | 117 +++++++++++++++++ .../module_tddft/test/propagator_test1.cpp | 107 +++++++++++++++ .../module_tddft/test/propagator_test2.cpp | 118 +++++++++++++++++ .../module_tddft/test/propagator_test3.cpp | 123 ++++++++++++++++++ .../module_tddft/test/tddft_test.cpp | 42 ++++++ .../module_tddft/test/tddft_test.h | 50 +++++++ .../module_tddft/test/upsi_test1.cpp | 76 +++++++++++ .../module_tddft/test/upsi_test2.cpp | 69 ++++++++++ .../module_tddft/test/upsi_test3.cpp | 86 ++++++++++++ 14 files changed, 1009 insertions(+), 2 deletions(-) create mode 100644 source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt create mode 100644 source/module_hamilt_lcao/module_tddft/test/bandenergy_test.cpp create mode 100644 source/module_hamilt_lcao/module_tddft/test/middle_hamilt_test.cpp create mode 100644 source/module_hamilt_lcao/module_tddft/test/norm_psi_test.cpp create mode 100644 source/module_hamilt_lcao/module_tddft/test/propagator_test1.cpp create mode 100644 source/module_hamilt_lcao/module_tddft/test/propagator_test2.cpp create mode 100644 source/module_hamilt_lcao/module_tddft/test/propagator_test3.cpp create mode 100644 source/module_hamilt_lcao/module_tddft/test/tddft_test.cpp create mode 100644 source/module_hamilt_lcao/module_tddft/test/tddft_test.h create mode 100644 source/module_hamilt_lcao/module_tddft/test/upsi_test1.cpp create mode 100644 source/module_hamilt_lcao/module_tddft/test/upsi_test2.cpp create mode 100644 source/module_hamilt_lcao/module_tddft/test/upsi_test3.cpp diff --git a/source/module_base/blacs_connector.h b/source/module_base/blacs_connector.h index d29ac47fae..98fd06fcde 100644 --- a/source/module_base/blacs_connector.h +++ b/source/module_base/blacs_connector.h @@ -33,7 +33,8 @@ extern "C" void Cblacs_gridmap(int* icontxt, int *usermap, int ldumap, int nprow, int npcol); // Informational and Miscellaneous void Cblacs_gridinfo(int icontxt, int* nprow, int *npcol, int *myprow, int *mypcol); - int Cblacs_pnum(int icontxt, int prow, int pcol); - void Cblacs_pcoord(int icontxt, int pnum, int *prow, int *pcol); + void Cblacs_gridinit(int* icontxt, char* layout, int nprow, int npcol); + int Cblacs_pnum(int icontxt, int prow, int pcol); + void Cblacs_pcoord(int icontxt, int pnum, int *prow, int *pcol); void Cblacs_exit(int icontxt); } diff --git a/source/module_hamilt_lcao/module_tddft/CMakeLists.txt b/source/module_hamilt_lcao/module_tddft/CMakeLists.txt index 8e0adf2b7d..f41dad565d 100644 --- a/source/module_hamilt_lcao/module_tddft/CMakeLists.txt +++ b/source/module_hamilt_lcao/module_tddft/CMakeLists.txt @@ -19,4 +19,8 @@ if(ENABLE_LCAO) add_coverage(tddft) endif() + IF (BUILD_TESTING) + add_subdirectory(test) + endif() + endif() diff --git a/source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt b/source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt new file mode 100644 index 0000000000..a0d03c7caf --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt @@ -0,0 +1,13 @@ +remove_definitions(-D __MPI) + +AddTest( + TARGET tddft_test + LIBS ${math_libs} base device + SOURCES tddft_test.cpp upsi_test1.cpp upsi_test2.cpp upsi_test3.cpp propagator_test1.cpp propagator_test2.cpp propagator_test3.cpp middle_hamilt_test.cpp norm_psi_test.cpp bandenergy_test.cpp ../upsi.cpp ../propagator.cpp ../middle_hamilt.cpp ../norm_psi.cpp ../bandenergy.cpp +) + +add_test(NAME tddft_test_np1 + COMMAND mpirun -np 1 ./tddft_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +) + diff --git a/source/module_hamilt_lcao/module_tddft/test/bandenergy_test.cpp b/source/module_hamilt_lcao/module_tddft/test/bandenergy_test.cpp new file mode 100644 index 0000000000..a82ec70182 --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/test/bandenergy_test.cpp @@ -0,0 +1,101 @@ +#include "module_hamilt_lcao/module_tddft/bandenergy.h" + +#include +#include +#include + +#include "module_basis/module_ao/parallel_orbitals.h" +#include "module_hamilt_lcao/module_tddft/evolve_elec.h" +#include "tddft_test.h" + +/************************************************ + * unit test of functions in bandenergy.h + ***********************************************/ + +/** + * - Tested Function + * - compute_ekb + * - compute band energy ekb . + */ + +#define doublethreshold 1e-8 +double module_tddft::Evolve_elec::td_print_eij = -1; + +TEST(BandEnergyTest, testBandEnergy) +{ + std::complex* psi_k; + std::complex* Htmp; + double* ekb; + int nband = 3; + int nlocal = 4; + bool print_matrix = false; + Parallel_Orbitals* pv; + pv = new Parallel_Orbitals(); + pv->nloc = nlocal * nlocal; + pv->nloc_wfc = nlocal * nband; + pv->ncol = nlocal; + pv->nrow = nlocal; + pv->ncol_bands = nband; + pv->dim0 = 1; + pv->dim1 = 1; + + int dim[2]; + int period[2] = {1, 1}; + int reorder = 0; + dim[0] = nprow; + dim[1] = npcol; + + MPI_Cart_create(MPI_COMM_WORLD, 2, dim, period, reorder, &pv->comm_2D); + + // Initialize input matrices + int info; + int mb = 1, nb = 1, lda = nband, ldc = nlocal; + int irsrc = 0, icsrc = 0, lld = numroc_(&nlocal, &mb, &myprow, &irsrc, &nprow), + lld1 = numroc_(&nband, &mb, &myprow, &irsrc, &nprow); + descinit_(pv->desc, &nlocal, &nlocal, &mb, &nb, &irsrc, &icsrc, &ictxt, &lld, &info); + descinit_(pv->desc_wfc, &nlocal, &nband, &mb, &nb, &irsrc, &icsrc, &ictxt, &lld, &info); + descinit_(pv->desc_Eij, &nband, &nband, &mb, &nb, &irsrc, &icsrc, &ictxt, &lld, &info); + + // Initialize data + Htmp = new std::complex[nlocal * nlocal]; + psi_k = new std::complex[nlocal * nband]; + ekb = new double[nband]; + + for (int i = 0; i < nlocal; ++i) + { + for (int j = 0; j < nlocal; ++j) + { + if (i == j) + { + Htmp[i * nlocal + j] = std::complex(1.0, 0.0); + } + } + } + Htmp[1] = 0.5; + Htmp[4] = 0.5; + + psi_k[0] = 1.0; + psi_k[1] = 1.0; + psi_k[2] = 0.0; + psi_k[3] = 0.0; + psi_k[4] = 2.0; + psi_k[5] = 1.0; + psi_k[6] = 1.0; + psi_k[7] = 0.0; + psi_k[8] = 3.0; + psi_k[9] = 0.0; + psi_k[10] = 0.0; + psi_k[11] = 1.0; + + // Call the function + module_tddft::compute_ekb(pv, nband, nlocal, Htmp, psi_k, ekb); + + // Check the results + EXPECT_NEAR(ekb[0], 3.0, doublethreshold); + EXPECT_NEAR(ekb[1], 8.0, doublethreshold); + EXPECT_NEAR(ekb[2], 10.0, doublethreshold); + + delete[] psi_k; + delete[] Htmp; + delete[] ekb; +} diff --git a/source/module_hamilt_lcao/module_tddft/test/middle_hamilt_test.cpp b/source/module_hamilt_lcao/module_tddft/test/middle_hamilt_test.cpp new file mode 100644 index 0000000000..9a5b208fe0 --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/test/middle_hamilt_test.cpp @@ -0,0 +1,100 @@ +#include "module_hamilt_lcao/module_tddft/middle_hamilt.h" + +#include +#include +#include + +#include "module_basis/module_ao/parallel_orbitals.h" +#include "tddft_test.h" + +/************************************************ + * unit test of functions in middle_hamilt.h + ***********************************************/ + +/** + * - Tested Function + * - half_Hmatrix + * - compute H(t+dt/2). + */ + +#define doublethreshold 1e-8 + +TEST(MiddleHamiltTest, testMiddleHamilt) +{ + std::complex* Htmp; + std::complex* Hlaststep; + int nband = 3; + int nlocal = 4; + bool print_matrix = false; + Parallel_Orbitals* pv; + pv = new Parallel_Orbitals(); + pv->nloc = nlocal * nlocal; + pv->ncol = nlocal; + pv->nrow = nlocal; + + // Initialize input matrices + int info; + int mb = 1, nb = 1, lda = nlocal, ldc = nlocal; + int irsrc = 0, icsrc = 0, lld = numroc_(&nlocal, &mb, &myprow, &irsrc, &nprow); + descinit_(pv->desc, &nlocal, &nlocal, &mb, &nb, &irsrc, &icsrc, &ictxt, &lld, &info); + + // Initialize data + Htmp = new std::complex[nlocal * nlocal]; + Hlaststep = new std::complex[nlocal * nlocal]; + + for (int i = 0; i < nlocal; ++i) + { + for (int j = 0; j < nlocal; ++j) + { + if (i == j) + { + Htmp[i * nlocal + j] = std::complex(1.0, 0.0); + Hlaststep[i * nlocal + j] = std::complex(1.0 + 0.2 * (i * nlocal + j), 0.0); + } + else + { + Hlaststep[i * nlocal + j] = std::complex(0.2 * (i * nlocal + j), 0.0); + } + } + } + + // Call the function + module_tddft::half_Hmatrix(pv, nband, nlocal, Htmp, Hlaststep, print_matrix); + + // Check the results + EXPECT_NEAR(Htmp[0].real(), 1.0, doublethreshold); + EXPECT_NEAR(Htmp[0].imag(), 0.0, doublethreshold); + EXPECT_NEAR(Htmp[1].real(), 0.1, doublethreshold); + EXPECT_NEAR(Htmp[1].imag(), 0.0, doublethreshold); + EXPECT_NEAR(Htmp[2].real(), 0.2, doublethreshold); + EXPECT_NEAR(Htmp[2].imag(), 0.0, doublethreshold); + EXPECT_NEAR(Htmp[3].real(), 0.3, doublethreshold); + EXPECT_NEAR(Htmp[3].imag(), 0.0, doublethreshold); + EXPECT_NEAR(Htmp[4].real(), 0.4, doublethreshold); + EXPECT_NEAR(Htmp[4].imag(), 0.0, doublethreshold); + EXPECT_NEAR(Htmp[5].real(), 1.5, doublethreshold); + EXPECT_NEAR(Htmp[5].imag(), 0.0, doublethreshold); + EXPECT_NEAR(Htmp[6].real(), 0.6, doublethreshold); + EXPECT_NEAR(Htmp[6].imag(), 0.0, doublethreshold); + EXPECT_NEAR(Htmp[7].real(), 0.7, doublethreshold); + EXPECT_NEAR(Htmp[7].imag(), 0.0, doublethreshold); + EXPECT_NEAR(Htmp[8].real(), 0.8, doublethreshold); + EXPECT_NEAR(Htmp[8].imag(), 0.0, doublethreshold); + EXPECT_NEAR(Htmp[9].real(), 0.9, doublethreshold); + EXPECT_NEAR(Htmp[9].imag(), 0.0, doublethreshold); + EXPECT_NEAR(Htmp[10].real(), 2.0, doublethreshold); + EXPECT_NEAR(Htmp[10].imag(), 0.0, doublethreshold); + EXPECT_NEAR(Htmp[11].real(), 1.1, doublethreshold); + EXPECT_NEAR(Htmp[11].imag(), 0.0, doublethreshold); + EXPECT_NEAR(Htmp[12].real(), 1.2, doublethreshold); + EXPECT_NEAR(Htmp[12].imag(), 0.0, doublethreshold); + EXPECT_NEAR(Htmp[13].real(), 1.3, doublethreshold); + EXPECT_NEAR(Htmp[13].imag(), 0.0, doublethreshold); + EXPECT_NEAR(Htmp[14].real(), 1.4, doublethreshold); + EXPECT_NEAR(Htmp[14].imag(), 0.0, doublethreshold); + EXPECT_NEAR(Htmp[15].real(), 2.5, doublethreshold); + EXPECT_NEAR(Htmp[15].imag(), 0.0, doublethreshold); + + delete[] Htmp; + delete[] Hlaststep; +} diff --git a/source/module_hamilt_lcao/module_tddft/test/norm_psi_test.cpp b/source/module_hamilt_lcao/module_tddft/test/norm_psi_test.cpp new file mode 100644 index 0000000000..a62ad7f9a2 --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/test/norm_psi_test.cpp @@ -0,0 +1,117 @@ +#include "module_hamilt_lcao/module_tddft/norm_psi.h" + +#include +#include +#include + +#include "module_basis/module_ao/parallel_orbitals.h" +#include "tddft_test.h" + +/************************************************ + * unit test of functions in norm_psi.h + ***********************************************/ + +/** + * - Tested Function + * - norm_psi + * - normalize the wave function. + */ + +#define doublethreshold 1e-8 + +TEST(NormPsiTest, testNormPsi) +{ + std::complex* psi_k; + std::complex* Stmp; + int nband = 3; + int nlocal = 4; + bool print_matrix = false; + Parallel_Orbitals* pv; + pv = new Parallel_Orbitals(); + pv->nloc = nlocal * nlocal; + pv->nloc_wfc = nlocal * nband; + pv->ncol = nlocal; + pv->nrow = nlocal; + pv->ncol_bands = nband; + pv->dim0 = 1; + pv->dim1 = 1; + + int dim[2]; + int period[2] = {1, 1}; + int reorder = 0; + dim[0] = nprow; + dim[1] = npcol; + + MPI_Cart_create(MPI_COMM_WORLD, 2, dim, period, reorder, &pv->comm_2D); + + // Initialize input matrices + int info; + int mb = 1, nb = 1, lda = nband, ldc = nlocal; + int irsrc = 0, icsrc = 0, lld = numroc_(&nlocal, &mb, &myprow, &irsrc, &nprow), + lld1 = numroc_(&nband, &mb, &myprow, &irsrc, &nprow); + descinit_(pv->desc, &nlocal, &nlocal, &mb, &nb, &irsrc, &icsrc, &ictxt, &lld, &info); + descinit_(pv->desc_wfc, &nlocal, &nband, &mb, &nb, &irsrc, &icsrc, &ictxt, &lld, &info); + descinit_(pv->desc_Eij, &nband, &nband, &mb, &nb, &irsrc, &icsrc, &ictxt, &lld, &info); + + // Initialize data + Stmp = new std::complex[nlocal * nlocal]; + psi_k = new std::complex[nlocal * nband]; + + for (int i = 0; i < nlocal; ++i) + { + for (int j = 0; j < nlocal; ++j) + { + if (i == j) + { + Stmp[i * nlocal + j] = std::complex(1.0, 0.0); + } + } + } + Stmp[1] = 0.5; + Stmp[4] = 0.5; + + psi_k[0] = 1.0; + psi_k[1] = 1.0; + psi_k[2] = 0.0; + psi_k[3] = 0.0; + psi_k[4] = 2.0; + psi_k[5] = 1.0; + psi_k[6] = 1.0; + psi_k[7] = 0.0; + psi_k[8] = 3.0; + psi_k[9] = 0.0; + psi_k[10] = 0.0; + psi_k[11] = 1.0; + + // Call the function + module_tddft::norm_psi(pv, nband, nlocal, Stmp, psi_k, print_matrix); + + // Check the results + EXPECT_NEAR(psi_k[0].real(), 0.577350269189626, doublethreshold); + EXPECT_NEAR(psi_k[0].imag(), 0.0, doublethreshold); + EXPECT_NEAR(psi_k[1].real(), 0.577350269189626, doublethreshold); + EXPECT_NEAR(psi_k[1].imag(), 0.0, doublethreshold); + EXPECT_NEAR(psi_k[2].real(), 0.0, doublethreshold); + EXPECT_NEAR(psi_k[2].imag(), 0.0, doublethreshold); + EXPECT_NEAR(psi_k[3].real(), 0.0, doublethreshold); + EXPECT_NEAR(psi_k[3].imag(), 0.0, doublethreshold); + EXPECT_NEAR(psi_k[4].real(), 0.707106781186547, doublethreshold); + EXPECT_NEAR(psi_k[4].imag(), 0.0, doublethreshold); + EXPECT_NEAR(psi_k[5].real(), 0.353553390593274, doublethreshold); + EXPECT_NEAR(psi_k[5].imag(), 0.0, doublethreshold); + EXPECT_NEAR(psi_k[6].real(), 0.353553390593274, doublethreshold); + EXPECT_NEAR(psi_k[6].imag(), 0.0, doublethreshold); + EXPECT_NEAR(psi_k[7].real(), 0.0, doublethreshold); + EXPECT_NEAR(psi_k[7].imag(), 0.0, doublethreshold); + EXPECT_NEAR(psi_k[8].real(), 0.948683298050514, doublethreshold); + EXPECT_NEAR(psi_k[8].imag(), 0.0, doublethreshold); + EXPECT_NEAR(psi_k[9].real(), 0.0, doublethreshold); + EXPECT_NEAR(psi_k[9].imag(), 0.0, doublethreshold); + EXPECT_NEAR(psi_k[10].real(), 0.0, doublethreshold); + EXPECT_NEAR(psi_k[10].imag(), 0.0, doublethreshold); + EXPECT_NEAR(psi_k[11].real(), 0.316227766016838, doublethreshold); + EXPECT_NEAR(psi_k[11].imag(), 0.0, doublethreshold); + + delete[] psi_k; + delete[] Stmp; +} diff --git a/source/module_hamilt_lcao/module_tddft/test/propagator_test1.cpp b/source/module_hamilt_lcao/module_tddft/test/propagator_test1.cpp new file mode 100644 index 0000000000..56e4056d97 --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/test/propagator_test1.cpp @@ -0,0 +1,107 @@ +#include +#include +#include + +#include "module_basis/module_ao/parallel_orbitals.h" +#include "module_hamilt_lcao/module_tddft/propagator.h" +#include "module_io/input.h" +#include "tddft_test.h" + +/************************************************ + * unit test of functions in propagator.h + ***********************************************/ + +/** + * - Tested Function + * - Propagator::compute_propagator_cn2 + * - compute propagator of method Crank-Nicolson. + */ + +Input INPUT; +#define doublethreshold 1e-8 + +TEST(PropagatorTest, testPropagatorCN) +{ + std::complex* U_operator; + std::complex* Stmp; + std::complex* Htmp; + int nlocal = 4; + bool print_matrix = false; + Parallel_Orbitals* pv; + pv = new Parallel_Orbitals(); + pv->nloc = nlocal * nlocal; + pv->ncol = nlocal; + INPUT.mdp.md_dt = 4; + + // Initialize input matrices + int info; + int mb = 1, nb = 1, lda = nlocal, ldc = nlocal; + int irsrc = 0, icsrc = 0, lld = numroc_(&nlocal, &mb, &myprow, &irsrc, &nprow); + descinit_(pv->desc, &nlocal, &nlocal, &mb, &nb, &irsrc, &icsrc, &ictxt, &lld, &info); + + // Initialize data + U_operator = new std::complex[nlocal * nlocal]; + Stmp = new std::complex[nlocal * nlocal]; + Htmp = new std::complex[nlocal * nlocal]; + + for (int i = 0; i < nlocal * nlocal; ++i) + { + U_operator[i] = std::complex(0.0, 0.0); + } + for (int i = 0; i < nlocal; ++i) + { + for (int j = 0; j < nlocal; ++j) + { + if (i == j) + { + Htmp[i * nlocal + j] = std::complex(1.0, 0.0); + Stmp[i * nlocal + j] = std::complex(1.0, 0.0); + } + } + } + Stmp[1] = 0.5; + Stmp[4] = 0.5; + + // Call the function + int propagator = 0; + module_tddft::Propagator prop(propagator, pv); + prop.compute_propagator(nlocal, Stmp, Htmp, nullptr, U_operator, print_matrix); + + // Check the results + EXPECT_NEAR(U_operator[0].real(), -0.107692307692308, doublethreshold); + EXPECT_NEAR(U_operator[0].imag(), -0.861538461538462, doublethreshold); + EXPECT_NEAR(U_operator[1].real(), 0.492307692307692, doublethreshold); + EXPECT_NEAR(U_operator[1].imag(), -0.0615384615384615, doublethreshold); + EXPECT_NEAR(U_operator[2].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[2].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[3].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[3].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[4].real(), 0.492307692307692, doublethreshold); + EXPECT_NEAR(U_operator[4].imag(), -0.0615384615384615, doublethreshold); + EXPECT_NEAR(U_operator[5].real(), -0.107692307692308, doublethreshold); + EXPECT_NEAR(U_operator[5].imag(), -0.861538461538462, doublethreshold); + EXPECT_NEAR(U_operator[6].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[6].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[7].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[7].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[8].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[8].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[9].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[9].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[10].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[10].imag(), -1.0, doublethreshold); + EXPECT_NEAR(U_operator[11].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[11].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[12].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[12].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[13].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[13].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[14].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[14].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[15].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[15].imag(), -1.0, doublethreshold); + + delete[] U_operator; + delete[] Htmp; + delete[] Stmp; +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_tddft/test/propagator_test2.cpp b/source/module_hamilt_lcao/module_tddft/test/propagator_test2.cpp new file mode 100644 index 0000000000..ad10ebbbb0 --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/test/propagator_test2.cpp @@ -0,0 +1,118 @@ +#include +#include +#include + +#include "module_basis/module_ao/parallel_orbitals.h" +#include "module_hamilt_lcao/module_tddft/propagator.h" +#include "module_io/input.h" +#include "tddft_test.h" + +/************************************************ + * unit test of functions in propagator.h + ***********************************************/ + +/** + * - Tested Function + * - Propagator::compute_propagator_taylor + * - compute propagator of method 4th Taylor expansion. + */ + +#define doublethreshold 1e-8 + +TEST(PropagatorTest, testPropagatorTaylor) +{ + std::complex* U_operator; + std::complex* Stmp; + std::complex* Htmp; + int nlocal = 4; + bool print_matrix = false; + Parallel_Orbitals* pv; + pv = new Parallel_Orbitals(); + pv->nloc = nlocal * nlocal; + pv->ncol = nlocal; + pv->nrow = nlocal; + pv->dim0 = 1; + pv->dim1 = 1; + + int dim[2]; + int period[2] = {1, 1}; + int reorder = 0; + dim[0] = nprow; + dim[1] = npcol; + + MPI_Cart_create(MPI_COMM_WORLD, 2, dim, period, reorder, &pv->comm_2D); + + INPUT.mdp.md_dt = 4; + + // Initialize input matrices + int info; + int mb = 1, nb = 1, lda = nlocal, ldc = nlocal; + int irsrc = 0, icsrc = 0, lld = numroc_(&nlocal, &mb, &myprow, &irsrc, &nprow); + descinit_(pv->desc, &nlocal, &nlocal, &mb, &nb, &irsrc, &icsrc, &ictxt, &lld, &info); + + // Initialize data + U_operator = new std::complex[nlocal * nlocal]; + Stmp = new std::complex[nlocal * nlocal]; + Htmp = new std::complex[nlocal * nlocal]; + + for (int i = 0; i < nlocal * nlocal; ++i) + { + U_operator[i] = std::complex(0.0, 0.0); + } + for (int i = 0; i < nlocal; ++i) + { + for (int j = 0; j < nlocal; ++j) + { + if (i == j) + { + Htmp[i * nlocal + j] = std::complex(1.0, 0.0); + Stmp[i * nlocal + j] = std::complex(1.0, 0.0); + } + } + } + Stmp[1] = 0.5; + Stmp[4] = 0.5; + + // Call the function + int propagator = 1; + module_tddft::Propagator prop(propagator, pv); + prop.compute_propagator(nlocal, Stmp, Htmp, nullptr, U_operator, print_matrix); + + // Check the results + EXPECT_NEAR(U_operator[0].real(), 1.95473251028807, doublethreshold); + EXPECT_NEAR(U_operator[0].imag(), 2.8641975308642, doublethreshold); + EXPECT_NEAR(U_operator[1].real(), -1.7119341563786, doublethreshold); + EXPECT_NEAR(U_operator[1].imag(), -3.80246913580247, doublethreshold); + EXPECT_NEAR(U_operator[2].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[2].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[3].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[3].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[4].real(), -1.7119341563786, doublethreshold); + EXPECT_NEAR(U_operator[4].imag(), -3.80246913580247, doublethreshold); + EXPECT_NEAR(U_operator[5].real(), 1.95473251028807, doublethreshold); + EXPECT_NEAR(U_operator[5].imag(), 2.8641975308642, doublethreshold); + EXPECT_NEAR(U_operator[6].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[6].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[7].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[7].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[8].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[8].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[9].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[9].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[10].real(), -0.333333333333333, doublethreshold); + EXPECT_NEAR(U_operator[10].imag(), -0.666666666666667, doublethreshold); + EXPECT_NEAR(U_operator[11].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[11].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[12].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[12].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[13].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[13].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[14].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[14].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[15].real(), -0.333333333333333, doublethreshold); + EXPECT_NEAR(U_operator[15].imag(), -0.666666666666667, doublethreshold); + + delete[] U_operator; + delete[] Htmp; + delete[] Stmp; +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_tddft/test/propagator_test3.cpp b/source/module_hamilt_lcao/module_tddft/test/propagator_test3.cpp new file mode 100644 index 0000000000..bb4dc06b22 --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/test/propagator_test3.cpp @@ -0,0 +1,123 @@ +#include +#include +#include + +#include "module_basis/module_ao/parallel_orbitals.h" +#include "module_hamilt_lcao/module_tddft/propagator.h" +#include "module_io/input.h" +#include "tddft_test.h" + +/************************************************ + * unit test of functions in propagator.h + ***********************************************/ + +/** + * - Tested Function + * - Propagator::compute_propagator_etrs + * - compute propagator of method ETRS. + */ + +#define doublethreshold 1e-8 + +TEST(PropagatorTest, testPropagatorETRS) +{ + std::complex* U_operator; + std::complex* Stmp; + std::complex* Htmp; + std::complex* Hlaststep; + int nlocal = 4; + bool print_matrix = false; + Parallel_Orbitals* pv; + pv = new Parallel_Orbitals(); + pv->nloc = nlocal * nlocal; + pv->ncol = nlocal; + pv->nrow = nlocal; + pv->dim0 = 1; + pv->dim1 = 1; + + int dim[2]; + int period[2] = {1, 1}; + int reorder = 0; + dim[0] = nprow; + dim[1] = npcol; + + MPI_Cart_create(MPI_COMM_WORLD, 2, dim, period, reorder, &pv->comm_2D); + + INPUT.mdp.md_dt = 4; + + // Initialize input matrices + int info; + int mb = 1, nb = 1, lda = nlocal, ldc = nlocal; + int irsrc = 0, icsrc = 0, lld = numroc_(&nlocal, &mb, &myprow, &irsrc, &nprow); + descinit_(pv->desc, &nlocal, &nlocal, &mb, &nb, &irsrc, &icsrc, &ictxt, &lld, &info); + + // Initialize data + U_operator = new std::complex[nlocal * nlocal]; + Stmp = new std::complex[nlocal * nlocal]; + Htmp = new std::complex[nlocal * nlocal]; + Hlaststep = new std::complex[nlocal * nlocal]; + + for (int i = 0; i < nlocal * nlocal; ++i) + { + U_operator[i] = std::complex(0.0, 0.0); + } + for (int i = 0; i < nlocal; ++i) + { + for (int j = 0; j < nlocal; ++j) + { + if (i == j) + { + Htmp[i * nlocal + j] = std::complex(1.0, 0.0); + Hlaststep[i * nlocal + j] = std::complex(1.0, 0.0); + Stmp[i * nlocal + j] = std::complex(1.0, 0.0); + } + } + } + Stmp[1] = 0.5; + Stmp[4] = 0.5; + Hlaststep[0] = 1.1; + + // Call the function + int propagator = 2; + module_tddft::Propagator prop(propagator, pv); + prop.compute_propagator(nlocal, Stmp, Htmp, Hlaststep, U_operator, print_matrix); + + // Check the results + EXPECT_NEAR(U_operator[0].real(), -0.0105865569272976, doublethreshold); + EXPECT_NEAR(U_operator[0].imag(), -0.228336412132297, doublethreshold); + EXPECT_NEAR(U_operator[1].real(), 0.195527023319616, doublethreshold); + EXPECT_NEAR(U_operator[1].imag(), -0.728701844231062, doublethreshold); + EXPECT_NEAR(U_operator[2].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[2].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[3].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[3].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[4].real(), 0.247662246608749, doublethreshold); + EXPECT_NEAR(U_operator[4].imag(), -0.694263679317177, doublethreshold); + EXPECT_NEAR(U_operator[5].real(), -0.0219180003048316, doublethreshold); + EXPECT_NEAR(U_operator[5].imag(), -0.300090839811004, doublethreshold); + EXPECT_NEAR(U_operator[6].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[6].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[7].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[7].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[8].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[8].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[9].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[9].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[10].real(), -0.401041666666667, doublethreshold); + EXPECT_NEAR(U_operator[10].imag(), -0.902777777777778, doublethreshold); + EXPECT_NEAR(U_operator[11].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[11].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[12].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[12].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[13].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[13].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[14].real(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[14].imag(), 0.0, doublethreshold); + EXPECT_NEAR(U_operator[15].real(), -0.401041666666667, doublethreshold); + EXPECT_NEAR(U_operator[15].imag(), -0.902777777777778, doublethreshold); + + delete[] U_operator; + delete[] Htmp; + delete[] Stmp; + delete[] Hlaststep; +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_tddft/test/tddft_test.cpp b/source/module_hamilt_lcao/module_tddft/test/tddft_test.cpp new file mode 100644 index 0000000000..a534b80791 --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/test/tddft_test.cpp @@ -0,0 +1,42 @@ +#include "tddft_test.h" + +#include +#include + +#include "module_base/blacs_connector.h" +#include "module_base/scalapack_connector.h" +#include "module_basis/module_ao/parallel_orbitals.h" + +/************************************************ + * unit test of module_tddft + ***********************************************/ + +int myprow, nprow, ictxt, mypcol, npcol; +; + +int main(int argc, char** argv) +{ + int myrank; + int mysize; + + MPI_Init(NULL, NULL); + MPI_Comm_size(MPI_COMM_WORLD, &mysize); + MPI_Comm_rank(MPI_COMM_WORLD, &myrank); + + // Set up BLACS context and grid + int nprocs; + nprow = 1; + npcol = 1; + Cblacs_pinfo(&myrank, &mysize); + Cblacs_get(-1, 0, &ictxt); + Cblacs_gridinit(&ictxt, "Row", nprow, npcol); + Cblacs_gridinfo(ictxt, &nprow, &npcol, &myprow, &mypcol); + + int result = 0; + testing::InitGoogleTest(&argc, argv); + result = RUN_ALL_TESTS(); + + Cblacs_exit(ictxt); + // MPI_Finalize(); + return result; +} \ No newline at end of file diff --git a/source/module_hamilt_lcao/module_tddft/test/tddft_test.h b/source/module_hamilt_lcao/module_tddft/test/tddft_test.h new file mode 100644 index 0000000000..c13f0b0e4e --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/test/tddft_test.h @@ -0,0 +1,50 @@ +#ifndef __TDDFTTEST +#define __TDDFTTEST +#include + +#include "gtest/gtest.h" +#include "module_basis/module_ao/parallel_orbitals.h" + +using namespace std; +extern int myprow, nprow, ictxt, mypcol, npcol; + +class TDDFTTEST : public testing::Test +{ + public: + static void SetUpTestCase() + { + cout << "\033[32m" + << "============================" + << "\033[0m" << endl; + cout << "\033[32m" + << "= TDDFT MODULE TEST START =" + << "\033[0m" << endl; + cout << "\033[32m" + << "============================" + << "\033[0m" << endl; + } + static void TearDownTestCase() + { + cout << "\033[32m" + << "============================" + << "\033[0m" << endl; + cout << "\033[32m" + << "= TDDFT MODULE TEST END =" + << "\033[0m" << endl; + cout << "\033[32m" + << "============================" + << "\033[0m" << endl; + } + void SetUp() + { + cout << "\033[32m" + << "[ CASE ]" + << "\033[0m" + << " "; + } + void TearDown() + { + } +}; + +#endif diff --git a/source/module_hamilt_lcao/module_tddft/test/upsi_test1.cpp b/source/module_hamilt_lcao/module_tddft/test/upsi_test1.cpp new file mode 100644 index 0000000000..e73221f80b --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/test/upsi_test1.cpp @@ -0,0 +1,76 @@ +#include +#include +#include + +#include "module_basis/module_ao/parallel_orbitals.h" +#include "module_hamilt_lcao/module_tddft/upsi.h" +#include "tddft_test.h" + +#define doublethreshold 1e-8 + +/************************************************ + * unit test of functions in upsi.h + ***********************************************/ + +/** + * - Tested Function + * - upsi + * - apply U_operator to the wave function of the previous step for new wave function. + */ + +Parallel_Orbitals::Parallel_Orbitals() +{ +} +Parallel_Orbitals::~Parallel_Orbitals() +{ +} + +TEST(UpsiTest, testUpsi1) +{ + std::complex* U_operator; + std::complex* psi_k_laststep; + std::complex* psi_k; + int nband = 2; + int nlocal = 2; + bool print_matrix = false; + Parallel_Orbitals* pv; + pv = new Parallel_Orbitals(); + pv->nloc = nlocal * nband; + pv->ncol = nlocal; + pv->ncol_bands = nband; + + // Initialize input matrices + int info; + int mb = 1, nb = 1, lda = nband, ldc = nlocal; + int irsrc = 0, icsrc = 0, lld = numroc_(&nlocal, &mb, &myprow, &irsrc, &nprow); + descinit_(pv->desc, &nlocal, &nlocal, &mb, &nb, &irsrc, &icsrc, &ictxt, &lld, &info); + descinit_(pv->desc_wfc, &nlocal, &nband, &mb, &nb, &irsrc, &icsrc, &ictxt, &lld, &info); + + // Initialize data + U_operator = new std::complex[nlocal * nlocal]; + psi_k_laststep = new std::complex[nlocal * nband]; + psi_k = new std::complex[nlocal * nband]; + + for (int i = 0; i < nlocal * nlocal; ++i) + { + U_operator[i] = std::complex(1.0, 0.0); + } + for (int i = 0; i < nlocal * nband; ++i) + { + psi_k_laststep[i] = std::complex(1.0, 0.0); + psi_k[i] = std::complex(0.0, 0.0); + } + + // Call the function + module_tddft::upsi(pv, nband, nlocal, U_operator, psi_k_laststep, psi_k, print_matrix); + + // Check the results + for (int i = 0; i < nlocal * nband; ++i) + { + EXPECT_NEAR(psi_k[i].real(), nlocal, doublethreshold); + EXPECT_NEAR(psi_k[i].imag(), 0.0, doublethreshold); + } + delete[] U_operator; + delete[] psi_k; + delete[] psi_k_laststep; +} diff --git a/source/module_hamilt_lcao/module_tddft/test/upsi_test2.cpp b/source/module_hamilt_lcao/module_tddft/test/upsi_test2.cpp new file mode 100644 index 0000000000..33ca60f7a6 --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/test/upsi_test2.cpp @@ -0,0 +1,69 @@ +#include +#include +#include + +#include "module_basis/module_ao/parallel_orbitals.h" +#include "module_hamilt_lcao/module_tddft/upsi.h" +#include "tddft_test.h" + +#define doublethreshold 1e-8 + +/************************************************ + * unit test of functions in upsi.h + ***********************************************/ + +/** + * - Tested Function + * - upsi + * - apply U_operator to the wave function of the previous step for new wave function. + */ + +TEST(UpsiTest, testUpsi2) +{ + std::complex* U_operator; + std::complex* psi_k_laststep; + std::complex* psi_k; + int nband = 3; + int nlocal = 4; + bool print_matrix = false; + Parallel_Orbitals* pv; + pv = new Parallel_Orbitals(); + pv->nloc = nlocal * nband; + pv->ncol = nlocal; + pv->ncol_bands = nband; + + // Initialize input matrices + int info; + int mb = 1, nb = 1, lda = nband, ldc = nlocal; + int irsrc = 0, icsrc = 0, lld = numroc_(&nlocal, &mb, &myprow, &irsrc, &nprow); + descinit_(pv->desc, &nlocal, &nlocal, &mb, &nb, &irsrc, &icsrc, &ictxt, &lld, &info); + descinit_(pv->desc_wfc, &nlocal, &nband, &mb, &nb, &irsrc, &icsrc, &ictxt, &lld, &info); + + // Initialize data + U_operator = new std::complex[nlocal * nlocal]; + psi_k_laststep = new std::complex[nlocal * nband]; + psi_k = new std::complex[nlocal * nband]; + + for (int i = 0; i < nlocal * nlocal; ++i) + { + U_operator[i] = std::complex(1.0, 0.0); + } + for (int i = 0; i < nlocal * nband; ++i) + { + psi_k_laststep[i] = std::complex(2.0, 0.0); + psi_k[i] = std::complex(0.0, 0.0); + } + + // Call the function + module_tddft::upsi(pv, nband, nlocal, U_operator, psi_k_laststep, psi_k, print_matrix); + + // Check the results + for (int i = 0; i < nlocal * nband; ++i) + { + EXPECT_NEAR(psi_k[i].real(), 2.0 * nlocal, doublethreshold); + EXPECT_NEAR(psi_k[i].imag(), 0.0, doublethreshold); + } + delete[] U_operator; + delete[] psi_k; + delete[] psi_k_laststep; +} diff --git a/source/module_hamilt_lcao/module_tddft/test/upsi_test3.cpp b/source/module_hamilt_lcao/module_tddft/test/upsi_test3.cpp new file mode 100644 index 0000000000..576adf60ee --- /dev/null +++ b/source/module_hamilt_lcao/module_tddft/test/upsi_test3.cpp @@ -0,0 +1,86 @@ +#include +#include +#include + +#include "module_basis/module_ao/parallel_orbitals.h" +#include "module_hamilt_lcao/module_tddft/upsi.h" +#include "tddft_test.h" + +#define doublethreshold 1e-8 + +/************************************************ + * unit test of functions in upsi.h + ***********************************************/ + +/** + * - Tested Function + * - upsi + * - apply U_operator to the wave function of the previous step for new wave function. + */ + +TEST(UpsiTest, testUpsi3) +{ + std::complex* U_operator; + std::complex* psi_k_laststep; + std::complex* psi_k; + int nband = 3; + int nlocal = 4; + bool print_matrix = false; + Parallel_Orbitals* pv; + pv = new Parallel_Orbitals(); + pv->nloc = nlocal * nband; + pv->ncol = nlocal; + pv->ncol_bands = nband; + + // Initialize input matrices + int info; + int mb = 1, nb = 1, lda = nband, ldc = nlocal; + int irsrc = 0, icsrc = 0, lld = numroc_(&nlocal, &mb, &myprow, &irsrc, &nprow); + descinit_(pv->desc, &nlocal, &nlocal, &mb, &nb, &irsrc, &icsrc, &ictxt, &lld, &info); + descinit_(pv->desc_wfc, &nlocal, &nband, &mb, &nb, &irsrc, &icsrc, &ictxt, &lld, &info); + + // Initialize data + U_operator = new std::complex[nlocal * nlocal]; + psi_k_laststep = new std::complex[nlocal * nband]; + psi_k = new std::complex[nlocal * nband]; + + for (int i = 0; i < nlocal; ++i) + { + for (int j = 0; j < nlocal; ++j) + { + if (i == j) + { + U_operator[i * nlocal + j] = std::complex(1.0, 0.0); + } + else + { + U_operator[i * nlocal + j] = std::complex(0.0, 0.0); + } + } + } + + for (int i = 0; i < nlocal; ++i) + { + for (int j = 0; j < nband; ++j) + { + psi_k_laststep[i * nband + j] = std::complex(i * nband + j, 0.0); + psi_k[i * nband + j] = std::complex(0.0, 0.0); + } + } + + // Call the function + module_tddft::upsi(pv, nband, nlocal, U_operator, psi_k_laststep, psi_k, print_matrix); + + // Check the results + for (int i = 0; i < nlocal; ++i) + { + for (int j = 0; j < nband; ++j) + { + EXPECT_NEAR(psi_k[i * nband + j].real(), i * nband + j, doublethreshold); + EXPECT_NEAR(psi_k[i].imag(), 0.0, doublethreshold); + } + } + delete[] U_operator; + delete[] psi_k; + delete[] psi_k_laststep; +} From f371f4c2f8221deb7d62a7f307b7aa06335946a5 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Thu, 1 Jun 2023 15:42:12 +0800 Subject: [PATCH 40/48] comment add_test --- .../module_hamilt_lcao/module_tddft/test/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt b/source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt index a0d03c7caf..be5586e79d 100644 --- a/source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt +++ b/source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt @@ -6,8 +6,8 @@ AddTest( SOURCES tddft_test.cpp upsi_test1.cpp upsi_test2.cpp upsi_test3.cpp propagator_test1.cpp propagator_test2.cpp propagator_test3.cpp middle_hamilt_test.cpp norm_psi_test.cpp bandenergy_test.cpp ../upsi.cpp ../propagator.cpp ../middle_hamilt.cpp ../norm_psi.cpp ../bandenergy.cpp ) -add_test(NAME tddft_test_np1 - COMMAND mpirun -np 1 ./tddft_test - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} -) +# add_test(NAME tddft_test_np1 +# COMMAND mpirun -np 1 ./tddft_test +# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +# ) From 4c1b31b94960e6481511c147228d370e37e6ce0e Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Thu, 1 Jun 2023 16:16:27 +0800 Subject: [PATCH 41/48] fix bug of prepare() in H_TDDFT_pw.cpp --- source/module_elecstate/potentials/H_TDDFT_pw.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/module_elecstate/potentials/H_TDDFT_pw.cpp b/source/module_elecstate/potentials/H_TDDFT_pw.cpp index c1b67cc64d..ef47e62b90 100644 --- a/source/module_elecstate/potentials/H_TDDFT_pw.cpp +++ b/source/module_elecstate/potentials/H_TDDFT_pw.cpp @@ -312,19 +312,19 @@ double H_TDDFT_pw::cal_v_time_heaviside() void H_TDDFT_pw::prepare(const UnitCell& cell, int& dir) { - if (dir == 0) + if (dir == 1) { bvec[0] = cell.G.e11; bvec[1] = cell.G.e12; bvec[2] = cell.G.e13; } - else if (dir == 1) + else if (dir == 2) { bvec[0] = cell.G.e21; bvec[1] = cell.G.e22; bvec[2] = cell.G.e23; } - else if (dir == 2) + else if (dir == 3) { bvec[0] = cell.G.e31; bvec[1] = cell.G.e32; From ca8066897a8a7290b12710a5676192a81b2367ac Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Fri, 2 Jun 2023 17:10:49 +0800 Subject: [PATCH 42/48] split tddft_test --- .../module_tddft/test/CMakeLists.txt | 35 +++++++++++++++---- .../module_tddft/test/bandenergy_test.cpp | 7 ++++ .../module_tddft/test/middle_hamilt_test.cpp | 7 ++++ .../module_tddft/test/norm_psi_test.cpp | 7 ++++ .../module_tddft/test/propagator_test1.cpp | 7 ++++ .../module_tddft/test/tddft_test.cpp | 18 +++++++--- 6 files changed, 69 insertions(+), 12 deletions(-) diff --git a/source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt b/source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt index be5586e79d..4ae6dbe018 100644 --- a/source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt +++ b/source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt @@ -1,13 +1,34 @@ remove_definitions(-D __MPI) +add_library(tddft_test_lib tddft_test.cpp) + +AddTest( + TARGET middle_hamilt_test + LIBS ${math_libs} base device tddft_test_lib + SOURCES middle_hamilt_test.cpp ../middle_hamilt.cpp +) + +AddTest( + TARGET bandenergy_test + LIBS ${math_libs} base device tddft_test_lib + SOURCES bandenergy_test.cpp ../bandenergy.cpp +) + +AddTest( + TARGET norm_psi_test + LIBS ${math_libs} base device tddft_test_lib + SOURCES norm_psi_test.cpp ../norm_psi.cpp +) + AddTest( - TARGET tddft_test - LIBS ${math_libs} base device - SOURCES tddft_test.cpp upsi_test1.cpp upsi_test2.cpp upsi_test3.cpp propagator_test1.cpp propagator_test2.cpp propagator_test3.cpp middle_hamilt_test.cpp norm_psi_test.cpp bandenergy_test.cpp ../upsi.cpp ../propagator.cpp ../middle_hamilt.cpp ../norm_psi.cpp ../bandenergy.cpp + TARGET upsi_test + LIBS ${math_libs} base device tddft_test_lib + SOURCES upsi_test1.cpp upsi_test2.cpp upsi_test3.cpp ../upsi.cpp ) -# add_test(NAME tddft_test_np1 -# COMMAND mpirun -np 1 ./tddft_test -# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} -# ) +AddTest( + TARGET propagator_test + LIBS ${math_libs} base device tddft_test_lib + SOURCES propagator_test1.cpp propagator_test2.cpp propagator_test3.cpp ../propagator.cpp +) diff --git a/source/module_hamilt_lcao/module_tddft/test/bandenergy_test.cpp b/source/module_hamilt_lcao/module_tddft/test/bandenergy_test.cpp index a82ec70182..190cb6a176 100644 --- a/source/module_hamilt_lcao/module_tddft/test/bandenergy_test.cpp +++ b/source/module_hamilt_lcao/module_tddft/test/bandenergy_test.cpp @@ -21,6 +21,13 @@ #define doublethreshold 1e-8 double module_tddft::Evolve_elec::td_print_eij = -1; +Parallel_Orbitals::Parallel_Orbitals() +{ +} +Parallel_Orbitals::~Parallel_Orbitals() +{ +} + TEST(BandEnergyTest, testBandEnergy) { std::complex* psi_k; diff --git a/source/module_hamilt_lcao/module_tddft/test/middle_hamilt_test.cpp b/source/module_hamilt_lcao/module_tddft/test/middle_hamilt_test.cpp index 9a5b208fe0..8387a82de7 100644 --- a/source/module_hamilt_lcao/module_tddft/test/middle_hamilt_test.cpp +++ b/source/module_hamilt_lcao/module_tddft/test/middle_hamilt_test.cpp @@ -19,6 +19,13 @@ #define doublethreshold 1e-8 +Parallel_Orbitals::Parallel_Orbitals() +{ +} +Parallel_Orbitals::~Parallel_Orbitals() +{ +} + TEST(MiddleHamiltTest, testMiddleHamilt) { std::complex* Htmp; diff --git a/source/module_hamilt_lcao/module_tddft/test/norm_psi_test.cpp b/source/module_hamilt_lcao/module_tddft/test/norm_psi_test.cpp index a62ad7f9a2..a3e7bd4f63 100644 --- a/source/module_hamilt_lcao/module_tddft/test/norm_psi_test.cpp +++ b/source/module_hamilt_lcao/module_tddft/test/norm_psi_test.cpp @@ -19,6 +19,13 @@ #define doublethreshold 1e-8 +Parallel_Orbitals::Parallel_Orbitals() +{ +} +Parallel_Orbitals::~Parallel_Orbitals() +{ +} + TEST(NormPsiTest, testNormPsi) { std::complex* psi_k; diff --git a/source/module_hamilt_lcao/module_tddft/test/propagator_test1.cpp b/source/module_hamilt_lcao/module_tddft/test/propagator_test1.cpp index 56e4056d97..ce17a13185 100644 --- a/source/module_hamilt_lcao/module_tddft/test/propagator_test1.cpp +++ b/source/module_hamilt_lcao/module_tddft/test/propagator_test1.cpp @@ -20,6 +20,13 @@ Input INPUT; #define doublethreshold 1e-8 +Parallel_Orbitals::Parallel_Orbitals() +{ +} +Parallel_Orbitals::~Parallel_Orbitals() +{ +} + TEST(PropagatorTest, testPropagatorCN) { std::complex* U_operator; diff --git a/source/module_hamilt_lcao/module_tddft/test/tddft_test.cpp b/source/module_hamilt_lcao/module_tddft/test/tddft_test.cpp index a534b80791..fdf114cceb 100644 --- a/source/module_hamilt_lcao/module_tddft/test/tddft_test.cpp +++ b/source/module_hamilt_lcao/module_tddft/test/tddft_test.cpp @@ -12,9 +12,8 @@ ***********************************************/ int myprow, nprow, ictxt, mypcol, npcol; -; -int main(int argc, char** argv) +void MPIInit() { int myrank; int mysize; @@ -31,12 +30,21 @@ int main(int argc, char** argv) Cblacs_get(-1, 0, &ictxt); Cblacs_gridinit(&ictxt, "Row", nprow, npcol); Cblacs_gridinfo(ictxt, &nprow, &npcol, &myprow, &mypcol); +} + +/************************************************ + * unit test of module_tddft + ***********************************************/ +int main(int argc, char** argv) +{ + MPIInit(); int result = 0; testing::InitGoogleTest(&argc, argv); result = RUN_ALL_TESTS(); Cblacs_exit(ictxt); - // MPI_Finalize(); - return result; -} \ No newline at end of file + + MPI_Finalize(); + return 0; +} From 784721903035a207952a41dd478539b503fa01ac Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Sat, 3 Jun 2023 02:32:58 +0800 Subject: [PATCH 43/48] fix bug --- source/module_hamilt_lcao/module_tddft/test/tddft_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/module_hamilt_lcao/module_tddft/test/tddft_test.cpp b/source/module_hamilt_lcao/module_tddft/test/tddft_test.cpp index fdf114cceb..fedb46a976 100644 --- a/source/module_hamilt_lcao/module_tddft/test/tddft_test.cpp +++ b/source/module_hamilt_lcao/module_tddft/test/tddft_test.cpp @@ -45,6 +45,6 @@ int main(int argc, char** argv) Cblacs_exit(ictxt); - MPI_Finalize(); + // MPI_Finalize(); return 0; } From 0f5fa2885050d2d3ec86481915aafab09d45d85c Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Tue, 6 Jun 2023 03:22:07 +0800 Subject: [PATCH 44/48] fix bug of UT for tddft --- source/module_hamilt_lcao/module_tddft/test/bandenergy_test.cpp | 1 + source/module_hamilt_lcao/module_tddft/test/norm_psi_test.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/source/module_hamilt_lcao/module_tddft/test/bandenergy_test.cpp b/source/module_hamilt_lcao/module_tddft/test/bandenergy_test.cpp index 190cb6a176..45ef2d6359 100644 --- a/source/module_hamilt_lcao/module_tddft/test/bandenergy_test.cpp +++ b/source/module_hamilt_lcao/module_tddft/test/bandenergy_test.cpp @@ -45,6 +45,7 @@ TEST(BandEnergyTest, testBandEnergy) pv->ncol_bands = nband; pv->dim0 = 1; pv->dim1 = 1; + pv->nb = 1; int dim[2]; int period[2] = {1, 1}; diff --git a/source/module_hamilt_lcao/module_tddft/test/norm_psi_test.cpp b/source/module_hamilt_lcao/module_tddft/test/norm_psi_test.cpp index a3e7bd4f63..5a1bdc0361 100644 --- a/source/module_hamilt_lcao/module_tddft/test/norm_psi_test.cpp +++ b/source/module_hamilt_lcao/module_tddft/test/norm_psi_test.cpp @@ -42,6 +42,7 @@ TEST(NormPsiTest, testNormPsi) pv->ncol_bands = nband; pv->dim0 = 1; pv->dim1 = 1; + pv->nb = 1; int dim[2]; int period[2] = {1, 1}; From abcbeb71b8b7cd234a60172b333c833c48295a48 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Tue, 6 Jun 2023 07:22:59 +0800 Subject: [PATCH 45/48] add tddft prefix --- .../module_tddft/test/CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt b/source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt index 4ae6dbe018..675806ca8d 100644 --- a/source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt +++ b/source/module_hamilt_lcao/module_tddft/test/CMakeLists.txt @@ -3,31 +3,31 @@ remove_definitions(-D __MPI) add_library(tddft_test_lib tddft_test.cpp) AddTest( - TARGET middle_hamilt_test + TARGET tddft_middle_hamilt_test LIBS ${math_libs} base device tddft_test_lib SOURCES middle_hamilt_test.cpp ../middle_hamilt.cpp ) AddTest( - TARGET bandenergy_test + TARGET tddft_bandenergy_test LIBS ${math_libs} base device tddft_test_lib SOURCES bandenergy_test.cpp ../bandenergy.cpp ) AddTest( - TARGET norm_psi_test + TARGET tddft_norm_psi_test LIBS ${math_libs} base device tddft_test_lib SOURCES norm_psi_test.cpp ../norm_psi.cpp ) AddTest( - TARGET upsi_test + TARGET tddft_upsi_test LIBS ${math_libs} base device tddft_test_lib SOURCES upsi_test1.cpp upsi_test2.cpp upsi_test3.cpp ../upsi.cpp ) AddTest( - TARGET propagator_test + TARGET tddft_propagator_test LIBS ${math_libs} base device tddft_test_lib SOURCES propagator_test1.cpp propagator_test2.cpp propagator_test3.cpp ../propagator.cpp ) From 60eef9e8438c7241756824d7fc4282047be908ad Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Tue, 6 Jun 2023 11:30:29 +0800 Subject: [PATCH 46/48] add UT for cblacs_gridinit --- source/module_base/test/CMakeLists.txt | 5 ++ .../module_base/test/blacs_connector_test.cpp | 53 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 source/module_base/test/blacs_connector_test.cpp diff --git a/source/module_base/test/CMakeLists.txt b/source/module_base/test/CMakeLists.txt index dc55ca3aed..c281e8beab 100644 --- a/source/module_base/test/CMakeLists.txt +++ b/source/module_base/test/CMakeLists.txt @@ -4,6 +4,11 @@ AddTest( LIBS ${math_libs} SOURCES blas_connector_test.cpp ) +AddTest( + TARGET base_blacs_connector + LIBS ${math_libs} + SOURCES blacs_connector_test.cpp +) AddTest( TARGET base_timer SOURCES timer_test.cpp ../timer.cpp diff --git a/source/module_base/test/blacs_connector_test.cpp b/source/module_base/test/blacs_connector_test.cpp new file mode 100644 index 0000000000..17cd92d268 --- /dev/null +++ b/source/module_base/test/blacs_connector_test.cpp @@ -0,0 +1,53 @@ +#include "../blacs_connector.h" + +#include + +#include "gtest/gtest.h" + +/************************************************ + * unit test of functions in blacs_connector.h + ***********************************************/ + +/** + * - Tested Function + * - Cblacs_gridinit + * - Initializes a grid of processors with a given number of rows and columns. + * The function creates a cartesian topology of all the processors initialized + * by the BLS library. In this topology, each processor is identified by its + * coordinates (row, col) in the grid. + */ + +TEST(blacs_connector, Cblacs_gridinit) +{ + int icontxt; + char layout[] = "ROW"; + int nprow = 1; + int npcol = 1; + + int myid, nprocs; + Cblacs_pinfo(&myid, &nprocs); + Cblacs_get(-1, 0, &icontxt); + + // Call the Cblacs_gridinit() function + Cblacs_gridinit(&icontxt, layout, nprow, npcol); + + // Check if the grid context handle is created successfully + EXPECT_EQ(icontxt, 0); +} + +int main(int argc, char** argv) +{ + int myrank; + int mysize; + + MPI_Init(&argc, &argv); + MPI_Comm_size(MPI_COMM_WORLD, &mysize); + MPI_Comm_rank(MPI_COMM_WORLD, &myrank); + + testing::InitGoogleTest(&argc, argv); + + int result = 0; + result = RUN_ALL_TESTS(); + MPI_Finalize(); + return 0; +} From c84c9da72ec0ed4f19da375b30eb38bcc2ef50cf Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Tue, 6 Jun 2023 11:34:29 +0800 Subject: [PATCH 47/48] fix bug of UT for tddft --- source/module_hamilt_lcao/module_tddft/test/propagator_test2.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/source/module_hamilt_lcao/module_tddft/test/propagator_test2.cpp b/source/module_hamilt_lcao/module_tddft/test/propagator_test2.cpp index ad10ebbbb0..e015e17f45 100644 --- a/source/module_hamilt_lcao/module_tddft/test/propagator_test2.cpp +++ b/source/module_hamilt_lcao/module_tddft/test/propagator_test2.cpp @@ -33,6 +33,7 @@ TEST(PropagatorTest, testPropagatorTaylor) pv->nrow = nlocal; pv->dim0 = 1; pv->dim1 = 1; + pv->nb = 1; int dim[2]; int period[2] = {1, 1}; From e7a11c4877cf558195af9455d9d4b8b039f174e0 Mon Sep 17 00:00:00 2001 From: lyb9812 Date: Tue, 6 Jun 2023 14:14:30 +0800 Subject: [PATCH 48/48] fix bug of UT for tddft --- source/module_hamilt_lcao/module_tddft/test/propagator_test3.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/source/module_hamilt_lcao/module_tddft/test/propagator_test3.cpp b/source/module_hamilt_lcao/module_tddft/test/propagator_test3.cpp index bb4dc06b22..4023b518fe 100644 --- a/source/module_hamilt_lcao/module_tddft/test/propagator_test3.cpp +++ b/source/module_hamilt_lcao/module_tddft/test/propagator_test3.cpp @@ -34,6 +34,7 @@ TEST(PropagatorTest, testPropagatorETRS) pv->nrow = nlocal; pv->dim0 = 1; pv->dim1 = 1; + pv->nb = 1; int dim[2]; int period[2] = {1, 1};