|
| 1 | +#include "esolver_of_tddft.h" |
| 2 | + |
| 3 | +#include "source_io/module_parameter/parameter.h" |
| 4 | +#include "source_io/cube_io.h" |
| 5 | +#include "source_io/output_log.h" |
| 6 | +#include "source_io/write_elecstat_pot.h" |
| 7 | +//-----------temporary------------------------- |
| 8 | +#include "source_base/global_function.h" |
| 9 | +#include "source_estate/module_charge/symmetry_rho.h" |
| 10 | +#include "source_hamilt/module_ewald/H_Ewald_pw.h" |
| 11 | +#include "source_pw/module_pwdft/global.h" |
| 12 | +#include "source_io/print_info.h" |
| 13 | +#include "source_estate/cal_ux.h" |
| 14 | +//-----force------------------- |
| 15 | +#include "source_pw/module_pwdft/forces.h" |
| 16 | +//-----stress------------------ |
| 17 | +#include "source_pw/module_ofdft/of_stress_pw.h" |
| 18 | + |
| 19 | +namespace ModuleESolver |
| 20 | +{ |
| 21 | + |
| 22 | +ESolver_OF_TDDFT::ESolver_OF_TDDFT() |
| 23 | +{ |
| 24 | + this->classname = "ESolver_OF_TDDFT"; |
| 25 | + this->evolve_ofdft=new Evolve_OFDFT(); |
| 26 | +} |
| 27 | + |
| 28 | +ESolver_OF_TDDFT::~ESolver_OF_TDDFT() |
| 29 | +{ |
| 30 | + delete this->evolve_ofdft; |
| 31 | +} |
| 32 | + |
| 33 | + |
| 34 | +void ESolver_OF_TDDFT::runner(UnitCell& ucell, const int istep) |
| 35 | +{ |
| 36 | + ModuleBase::timer::tick("ESolver_OF_TDDFT", "runner"); |
| 37 | + // get Ewald energy, initial rho and phi if necessary |
| 38 | + this->before_opt(istep, ucell); |
| 39 | + this->iter_ = 0; |
| 40 | + |
| 41 | + bool conv_esolver = false; // this conv_esolver is added by mohan 20250302 |
| 42 | +#ifdef __MPI |
| 43 | + this->iter_time = MPI_Wtime(); |
| 44 | +#else |
| 45 | + this->iter_time = std::chrono::system_clock::now(); |
| 46 | +#endif |
| 47 | + |
| 48 | + if (istep==0) |
| 49 | + { |
| 50 | + this->phi_td.resize(PARAM.inp.nspin*this->pw_rho->nrxx); |
| 51 | + } |
| 52 | + |
| 53 | + if ((istep<1) && PARAM.inp.init_chg != "file") |
| 54 | + { |
| 55 | + while (true) |
| 56 | + { |
| 57 | + // once we get a new rho and phi, update potential |
| 58 | + this->update_potential(ucell); |
| 59 | + |
| 60 | + // calculate the energy of new rho and phi |
| 61 | + this->energy_llast_ = this->energy_last_; |
| 62 | + this->energy_last_ = this->energy_current_; |
| 63 | + this->energy_current_ = this->cal_energy(); |
| 64 | + |
| 65 | + |
| 66 | + // check if the job is done |
| 67 | + if (this->check_exit(conv_esolver)) |
| 68 | + { |
| 69 | + break; |
| 70 | + } |
| 71 | + |
| 72 | + // find the optimization direction and step lenghth theta according to the potential |
| 73 | + this->optimize(ucell); |
| 74 | + |
| 75 | + // update the rho and phi based on the direction and theta |
| 76 | + this->update_rho(); |
| 77 | + |
| 78 | + this->iter_++; |
| 79 | + |
| 80 | + ESolver_FP::iter_finish(ucell, istep, this->iter_, conv_esolver); |
| 81 | + } |
| 82 | + |
| 83 | +#ifdef _OPENMP |
| 84 | +#pragma omp parallel for collapse(2) |
| 85 | +#endif |
| 86 | + for (int is = 0; is < PARAM.inp.nspin; ++is) |
| 87 | + { |
| 88 | + for (int ir = 0; ir < this->pw_rho->nrxx; ++ir) |
| 89 | + { |
| 90 | + phi_td[is*this->pw_rho->nrxx+ir]=pphi_[is][ir]; |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + else if ((istep<1) && PARAM.inp.init_chg == "file") |
| 95 | + { |
| 96 | +#ifdef _OPENMP |
| 97 | +#pragma omp parallel for collapse(2) |
| 98 | +#endif |
| 99 | + for (int is = 0; is < PARAM.inp.nspin; ++is) |
| 100 | + { |
| 101 | + for (int ir = 0; ir < this->pw_rho->nrxx; ++ir) |
| 102 | + { |
| 103 | + phi_td[is*this->pw_rho->nrxx+ir]=pphi_[is][ir]; |
| 104 | + } |
| 105 | + } |
| 106 | + conv_esolver=true; |
| 107 | + } |
| 108 | + else |
| 109 | + { |
| 110 | + this->evolve_ofdft->propagate_psi(this->pelec, this->chr, ucell, this->phi_td, this->pw_rho); |
| 111 | +#ifdef _OPENMP |
| 112 | +#pragma omp parallel for collapse(2) |
| 113 | +#endif |
| 114 | + for (int is = 0; is < PARAM.inp.nspin; ++is) |
| 115 | + { |
| 116 | + for (int ir = 0; ir < this->pw_rho->nrxx; ++ir) |
| 117 | + { |
| 118 | + pphi_[is][ir]=std::abs(phi_td[is*this->pw_rho->nrxx+ir]); |
| 119 | + } |
| 120 | + } |
| 121 | + conv_esolver=true; |
| 122 | + } |
| 123 | + |
| 124 | + this->after_opt(istep, ucell, conv_esolver); |
| 125 | + |
| 126 | + ModuleBase::timer::tick("ESolver_OF_TDDFT", "runner"); |
| 127 | +} |
| 128 | + |
| 129 | +} // namespace ModuleESolver |
0 commit comments