Skip to content

Commit

Permalink
move LR-init from driver to esolver; rm some move constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
maki49 committed Jun 23, 2024
1 parent 74cfeaa commit b03b65d
Show file tree
Hide file tree
Showing 21 changed files with 334 additions and 422 deletions.
12 changes: 6 additions & 6 deletions docs/advanced/input_files/input-main.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@
- [lr\_solverl](#lr_solver)
- [lr\_thr](#lr_thr)
- [nvirt](#nvirt)
- [nstates](#nstates)
- [lr_nstates](#lr_nstates)
- [abs\_wavelen\_range](#abs_wavelen_range)
- [out\_wfc\_lr](#out_wfc_lr)
[back to top](#full-list-of-input-keywords)
Expand Down Expand Up @@ -3767,27 +3767,27 @@ Currently supported: `RPA`, `LDA`, `PBE`, `HSE`, `HF`.
### lr_solver

- **Type**: String
- **Description**: The method to solve the Casida equation in LR-TDDFT.
- **Description**: The method to solve the Casida equation $AX=\Omega X$ in LR-TDDFT under Tamm-Dancoff approximation (TDA), where $A_{ai,bj}=(\epsilon_a-\epsilon_i)\delta_{ij}\delta_{ab}+(ai|f_{Hxc}|bj)+\alpha_{EX}(ab|ij)$ is the particle-hole excitation matrix and $X$ is the transition amplitude.
- `dav`: Construct $AX$ and diagonalize the Hamiltonian matrix iteratively with Davidson algorithm.
- `lapack`: Construct the full $A$ matrix and directly diagonalize with LAPACK.
- `spectrum`: Caluclate absorption spectrum only without solving Casida equation. The `OUT.${suffix}/` directory should contain the
- `spectrum`: Calculate absorption spectrum only without solving Casida equation. The `OUT.${suffix}/` directory should contain the
files for LR-TDDFT eigenstates and eigenvalues, i.e. `Excitation_Energy.dat` and `Excitation_Amplitude_${processor_rank}.dat`
output by setting `out_wfc_lr` to true.
- **Default**: dav

### lr_thr

- **Type**: Real
- **Description**: The convergence threshold of iterative diagonalization fo LR-TDDFT.
- **Default**: 1e-6
- **Description**: The convergence threshold of iterative diagonalization solver fo LR-TDDFT. It is a pure-math number with the same as [pw_diag_thr](#pw_diag_thr), but since the Casida equation is a one-shot eigenvalue problem, it is also the convergence threshold of LR-TDDFT.
- **Default**: 1e-2

### nvirt

- **Type**: Integer
- **Description**: The number of virtual orbitals used in the LR-TDDFT calculation.
- **Default**: 1

### nstates
### lr_nstates

- **Type**: Integer
- **Description**: The number of 2-particle states to be solved
Expand Down
2 changes: 1 addition & 1 deletion examples/lr-tddft/lcao_H2O/INPUT
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mixing_type pulay
mixing_beta 0.4
mixing_gg0 0

nstates 2
lr_nstates 2
xc_kernel lda
lr_solver dav
lr_thr 1e-6
Expand Down
2 changes: 1 addition & 1 deletion examples/lr-tddft/lcao_Si2/INPUT
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ smearing_sigma 0.02
mixing_type pulay
mixing_beta 0.4

nstates 10 # for test/debug, you can try a smaller one like 2
lr_nstates 10 # for test/debug, you can try a smaller one like 2
xc_kernel lda
lr_solver dav
lr_thr 1e-2
Expand Down
54 changes: 6 additions & 48 deletions source/driver_run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
#include "module_md/run_md.h"
#include "module_io/para_json.h"

#ifdef __LCAO
#include "module_beyonddft/esolver_lrtd_lcao.h"
#endif
extern "C"
{
#include "module_base/blacs_connector.h"
}
/**
* @brief This is the driver function which defines the workflow of ABACUS calculations.
* It relies on the class Esolver, which is a class that organizes workflows of single point calculations.
Expand All @@ -31,9 +24,8 @@ void Driver::driver_run(void)
ModuleBase::TITLE("Driver", "driver_line");
ModuleBase::timer::tick("Driver", "driver_line");

//! 1: initialize the ESolver
ModuleESolver::ESolver *p_esolver = nullptr;
ModuleESolver::init_esolver(p_esolver);
//! 1: initialize the ESolver
ModuleESolver::ESolver* p_esolver = nullptr;

//! 2: setup cell and atom information

Expand All @@ -49,18 +41,9 @@ void Driver::driver_run(void)
// delete ucell as a GlobalC in near future
GlobalC::ucell.setup_cell(GlobalV::stru_file, GlobalV::ofs_running);

//! 3: initialize Esolver and fill json-structure
#ifdef __LCAO
if (GlobalV::ESOLVER_TYPE == "lr")
// use constructor rather than Init function to initialize reference (instead of pointers) to ucell
if (GlobalV::GAMMA_ONLY_LOCAL)
p_esolver = new ModuleESolver::ESolver_LRTD<double, double>(INPUT, GlobalC::ucell);
else if (GlobalV::NSPIN < 4)
p_esolver = new ModuleESolver::ESolver_LRTD<std::complex<double>, double>(INPUT, GlobalC::ucell);
else
throw std::runtime_error("LR-TDDFT is not implemented for spin polarized case");
else
#endif
ModuleESolver::init_esolver(p_esolver, INPUT, GlobalC::ucell);

//! 3: initialize Esolver and fill json-structure
p_esolver->before_all_runners(INPUT, GlobalC::ucell);

// this Json part should be moved to before_all_runners, mohan 2024-05-12
Expand Down Expand Up @@ -99,33 +82,8 @@ void Driver::driver_run(void)
//! 5: clean up esolver
p_esolver->after_all_runners();

#ifdef __LCAO
//---------beyond DFT: set up the next ESolver---------
if (INPUT.esolver_type == "ks-lr")
{
std::cout << "setting up the esolver for excited state" << std::endl;
// ModuleESolver::ESolver_KS_LCAO* p_esolver_lcao_tmp = dynamic_cast<ModuleESolver::ESolver_KS_LCAO<double, double>*>(p_esolver);
ModuleESolver::ESolver* p_esolver_lr = nullptr;
if (INPUT.gamma_only)
p_esolver_lr = new ModuleESolver::ESolver_LRTD<double, double>(std::move(*dynamic_cast<ModuleESolver::ESolver_KS_LCAO<double, double>*>(p_esolver)), INPUT, GlobalC::ucell);
else
p_esolver_lr = new ModuleESolver::ESolver_LRTD<std::complex<double>, double>(std::move(*dynamic_cast<ModuleESolver::ESolver_KS_LCAO<std::complex<double>, double>*>(p_esolver)), INPUT, GlobalC::ucell);
ModuleESolver::clean_esolver(p_esolver);
p_esolver_lr->runner(0, GlobalC::ucell);
p_esolver_lr->after_all_runners();

std::cout << "before clean lr" << std::endl;
ModuleESolver::clean_esolver(p_esolver_lr);
std::cout << "after clean lr" << std::endl;
} //----------------------beyond DFT------------------------
else
ModuleESolver::clean_esolver(p_esolver);

if (INPUT.basis_type == "lcao")
Cblacs_exit(1); // clean up blacs after all the esolvers are cleaned up without closing MPI
#else
ModuleESolver::clean_esolver(p_esolver);
#endif

ModuleBase::timer::tick("Driver", "driver_line");
return;
}
Loading

0 comments on commit b03b65d

Please sign in to comment.