librpa.hpp Source File

librpa.hpp Source File#

LibRPA: librpa.hpp Source File
LibRPA
librpa.hpp
Go to the documentation of this file.
1#pragma once
16
17#include "librpa_enums.h"
18#include "librpa_options.h"
19#include "librpa_handler.h"
20
21#include <vector>
22#include <complex>
23
27namespace librpa
28{
29
30/* Enums */
36
38
40
42
44
47{
48 std::vector<std::complex<double>> sigc;
49 std::vector<double> eqp;
50};
51
54{
55 std::vector<std::complex<double>> sigc;
56 std::vector<double> spectral_function;
57};
58
59
60/* Options */
72{
73public:
76
83
93};
94
95
96/* Global environment functions */
97
103const char* get_build_info(void);
104
111
118
125
136void init_global(Switch switch_redirect_stdout = LIBRPA_SWITCH_OFF, const char *redirect_path = "stdout",
137 Switch switch_process_output = LIBRPA_SWITCH_ON);
138
144void set_output_level(Verbose output_level);
145
152
160
165void test(void);
166
171void print_profile(void);
172
173/* C++ handler definition, input and compute methods declarations */
174
197{
198private:
199 LibrpaHandler *h_ = nullptr;
200public:
202 Handler(): h_(nullptr) {};
203
208 Handler(MPI_Comm comm);
209
214 const LibrpaHandler *get_c_handler() const { return h_; }
215
220 void init(MPI_Comm comm);
221
225 void free();
226
233
234 /* Input (set) functions */
235
244 void set_scf_dimension(int nspins, int nkpts, int nstates, int nbasis, int nspinor = 1);
245
255 void set_wg_ekb_efermi(int nspins, int nkpts, int nstates, const double *wg, const double *ekb,
256 double efermi);
257
267 void set_wfc(int ispin, int ik, int nstates_local, int nbasis_local, const double *wfc_real,
268 const double *wfc_imag);
269
280 void set_wfc_spinor(int ik, int nstates_local, int nbasis_local,
281 const double* wfc_up_real, const double* wfc_up_imag,
282 const double* wfc_dn_real, const double* wfc_dn_imag);
283
292 void set_wfc_packed(int ispin, int ik, int nstates_local, int nbasis_local,
293 const std::complex<double> *wfc);
294
303 void set_wfc_spinor_packed(int ik, int nstates_local, int nbasis_local,
304 const std::complex<double> *wfc_up,
305 const std::complex<double> *wfc_dn);
306
312 void set_ao_basis_wfc(const std::vector<size_t> &nbs_wfc,
313 const std::vector<std::vector<int>> &l_shells = {});
314
320 void set_ao_basis_aux(const std::vector<size_t> &nbs_aux,
321 const std::vector<std::vector<int>> &l_shells = {});
322
328 void set_ao_basis_aux_shrink(const std::vector<size_t> &nbs_aux_shrink,
329 const std::vector<std::vector<int>> &l_shells = {});
330
339 void set_basis_convention(int bloch_phase, int bloch_ratom, LibrpaAngularOrder order,
340 LibrpaRshCoeff nega_m, LibrpaRshCoeff posi_m);
341
349 void set_symmetry_operations(int n_symops, int row_conv, const int* rotmats,
350 const double* trans = nullptr);
351
357 void set_latvec_and_G(const double lat_mat[9], const double G_mat[9]);
358
364 void set_atoms(const std::vector<int> &types, const std::vector<double> &pos_cart);
365
375 void set_kgrids_kvec(int nk1, int nk2, int nk3, int nkpts,
376 const double *kvecs, const double *kweights = nullptr);
377
386 void set_kgrids_kvec(int nk1, int nk2, int nk3, const std::vector<double> &kvecs,
387 const std::vector<double> &kweights = {});
388
393 void set_kq_mapping(const std::vector<int> &map_q_ks);
394
407 void set_lri_coeff(LibrpaParallelRouting routing, int I, int J, int nbasis_i, int nbasis_j,
408 int naux_mu, const int R[3], const double *Cs_in,
409 int shrink_aux = 0);
410
422 void set_aux_bare_coulomb_k_atom_pair(int ik, int I, int J, int naux_mu, int naux_nu,
423 const double *Vq_real_in, const double *Vq_imag_in,
424 double vq_threshold);
425
436 void set_aux_bare_coulomb_k_atom_pair_packed(int ik, int I, int J, int naux_mu, int naux_nu,
437 const std::complex<double> *Vq,
438 double vq_threshold);
439
451 void set_aux_cut_coulomb_k_atom_pair(int ik, int I, int J, int naux_mu, int naux_nu,
452 const double *Vq_real_in, const double *Vq_imag_in,
453 double vq_threshold);
454
465 void set_aux_cut_coulomb_k_atom_pair_packed(int ik, int I, int J, int naux_mu, int naux_nu,
466 const std::complex<double> *Vq,
467 double vq_threshold);
468
479 void set_aux_bare_coulomb_k_2d_block(int ik, int mu_begin, int mu_end, int nu_begin, int nu_end,
480 const double *Vq_real_in, const double *Vq_imag_in);
481
491 void set_aux_bare_coulomb_k_2d_block_packed(int ik, int mu_begin, int mu_end,
492 int nu_begin, int nu_end,
493 const std::complex<double> *Vq);
494
505 void set_aux_cut_coulomb_k_2d_block(int ik, int mu_begin, int mu_end, int nu_begin, int nu_end,
506 const double *Vq_real_in, const double *Vq_imag_in);
507
517 void set_aux_cut_coulomb_k_2d_block_packed(int ik, int mu_begin, int mu_end,
518 int nu_begin, int nu_end,
519 const std::complex<double> *Vq);
520
526 void set_dielect_func_imagfreq(const std::vector<double> &omegas_imag,
527 const std::vector<double> &dielect_func);
528
537 void set_velocity_matrix(int n_spins, int n_kpts, int n_states,
538 const double *velocity_real, const double *velocity_imag);
539
547 void set_velocity_matrix_packed(int n_spins, int n_kpts, int n_states,
548 const std::complex<double> *velocity);
549
555 void set_band_kvec(int n_kpts_band, const double *kfrac_band);
556
565 void set_band_occ_eigval(int n_spins, int n_kpts_band, int n_states, const double *occ,
566 const double *eig);
567
577 void set_wfc_band(int ispin, int ik_band, int nstates_local, int nbasis_local,
578 const double *wfc_real, const double *wfc_imag);
579
590 void set_wfc_band_spinor(int ik_band, int nstates_local, int nbasis_local,
591 const double* wfc_up_real, const double* wfc_up_imag,
592 const double* wfc_dn_real, const double* wfc_dn_imag);
593
602 void set_wfc_band_packed(int ispin, int ik_band, int nstates_local, int nbasis_local,
603 const std::complex<double> *wfc);
604
613 void set_wfc_band_spinor_packed(int ik_band, int nstates_local, int nbasis_local,
614 const std::complex<double> *wfc_up,
615 const std::complex<double> *wfc_dn);
616
619
620 /* Compute (build/get) functions */
621
629 std::vector<double> &omegas, std::vector<double> &weights);
630
638 std::vector<std::complex<double>> &rpa_corr_ibzk_contrib);
639
644 void build_exx(const Options &opts);
645
655 std::vector<double>
656 get_exx_pot_kgrid(const Options &opts, const int n_spins, const std::vector<int> &iks_this,
657 int i_state_low, int i_state_high);
658
669 std::vector<double>
670 get_exx_pot_band_k(const Options &opts, const int n_spins, const std::vector<int> &iks_band_this,
671 int i_state_low, int i_state_high);
672
677 void build_g0w0_sigma(const Options &opts);
678
691 std::vector<std::complex<double>>
692 get_g0w0_sigc_kgrid(const Options &opts, const int n_spins, const std::vector<int> &iks_this,
693 int i_state_low, int i_state_high, const std::vector<double> &vxc, const std::vector<double> &vexx);
694
707 get_g0w0_qpe_kgrid(const Options &opts, const int n_spins, const std::vector<int> &iks_this,
708 int i_state_low, int i_state_high, const std::vector<double> &vxc,
709 const std::vector<double> &vexx);
710
724 std::vector<double>
726 const Options &opts, const int n_spins, const std::vector<int> &iks_this,
727 int i_state_low, int i_state_high, const std::vector<double> &omegas,
728 const std::vector<double> &vxc, const std::vector<double> &vexx);
729
744 const Options &opts, const int n_spins, const std::vector<int> &iks_this,
745 int i_state_low, int i_state_high, const std::vector<double> &omegas,
746 const std::vector<double> &vxc, const std::vector<double> &vexx);
747
760 std::vector<std::complex<double>>
761 get_g0w0_sigc_band_k(const Options &opts, const int n_spins, const std::vector<int> &iks_band_this,
762 int i_state_low, int i_state_high, const std::vector<double> &vxc_band, const std::vector<double> &vexx_band);
763
776 get_g0w0_qpe_band_k(const Options &opts, const int n_spins,
777 const std::vector<int> &iks_band_this, int i_state_low,
778 int i_state_high, const std::vector<double> &vxc_band,
779 const std::vector<double> &vexx_band);
780
794 std::vector<double>
796 const Options &opts, const int n_spins, const std::vector<int> &iks_band_this,
797 int i_state_low, int i_state_high, const std::vector<double> &omegas,
798 const std::vector<double> &vxc_band, const std::vector<double> &vexx_band);
799
814 const Options &opts, const int n_spins, const std::vector<int> &iks_band_this,
815 int i_state_low, int i_state_high, const std::vector<double> &omegas,
816 const std::vector<double> &vxc_band, const std::vector<double> &vexx_band);
817
818 /* Utility functions */
819};
820
821}
void set_latvec_and_G(const double lat_mat[9], const double G_mat[9])
Set direct and reciprocal lattice vectors.
void set_kgrids_kvec(int nk1, int nk2, int nk3, const std::vector< double > &kvecs, const std::vector< double > &kweights={})
Set loaded SCF k-points from vectors.
void set_aux_bare_coulomb_k_atom_pair_packed(int ik, int I, int J, int naux_mu, int naux_nu, const std::complex< double > *Vq, double vq_threshold)
Set bare Coulomb matrix elements from a packed complex atom-pair matrix.
void set_wfc_packed(int ispin, int ik, int nstates_local, int nbasis_local, const std::complex< double > *wfc)
Set wavefunction coefficients from a packed complex array.
void set_ao_basis_aux(const std::vector< size_t > &nbs_aux, const std::vector< std::vector< int > > &l_shells={})
Set the auxiliary atomic-orbital basis.
G0W0QpeResult get_g0w0_qpe_band_k(const Options &opts, const int n_spins, const std::vector< int > &iks_band_this, int i_state_low, int i_state_high, const std::vector< double > &vxc_band, const std::vector< double > &vexx_band)
Get G0W0 correlation self-energies and quasiparticle energies for band-k states.
void set_kq_mapping(const std::vector< int > &map_q_ks)
Set the mapping from loaded SCF k-points to Coulomb q-points.
double get_rpa_correlation_energy(const Options &opts, std::vector< std::complex< double > > &rpa_corr_ibzk_contrib)
Compute RPA correlation energy.
G0W0QpeResult get_g0w0_qpe_kgrid(const Options &opts, const int n_spins, const std::vector< int > &iks_this, int i_state_low, int i_state_high, const std::vector< double > &vxc, const std::vector< double > &vexx)
Get G0W0 correlation self-energies and quasiparticle energies for k-grid states.
void set_wfc(int ispin, int ik, int nstates_local, int nbasis_local, const double *wfc_real, const double *wfc_imag)
Set wavefunction coefficients from separate real and imaginary arrays.
std::vector< double > get_g0w0_spectral_function_kgrid(const Options &opts, const int n_spins, const std::vector< int > &iks_this, int i_state_low, int i_state_high, const std::vector< double > &omegas, const std::vector< double > &vxc, const std::vector< double > &vexx)
Get G0W0 spectral functions for k-grid states.
void set_dielect_func_imagfreq(const std::vector< double > &omegas_imag, const std::vector< double > &dielect_func)
Set the dielectric function on the imaginary-frequency axis.
void reset_band_data()
Reset band structure data.
void set_aux_cut_coulomb_k_atom_pair(int ik, int I, int J, int naux_mu, int naux_nu, const double *Vq_real_in, const double *Vq_imag_in, double vq_threshold)
Set truncated Coulomb matrix elements in atom-pair format.
G0W0SpectralFunctionResult get_g0w0_spectral_function_with_sigc_band_k(const Options &opts, const int n_spins, const std::vector< int > &iks_band_this, int i_state_low, int i_state_high, const std::vector< double > &omegas, const std::vector< double > &vxc_band, const std::vector< double > &vexx_band)
Get G0W0 spectral functions and continued self-energies for band-k states.
void set_basis_convention(int bloch_phase, int bloch_ratom, LibrpaAngularOrder order, LibrpaRshCoeff nega_m, LibrpaRshCoeff posi_m)
Set basis-convention metadata used by symmetry reductions.
void set_wfc_spinor(int ik, int nstates_local, int nbasis_local, const double *wfc_up_real, const double *wfc_up_imag, const double *wfc_dn_real, const double *wfc_dn_imag)
Set spinor wavefunction coefficients from separate real and imaginary arrays.
void get_imaginary_frequency_grids(const Options &opts, std::vector< double > &omegas, std::vector< double > &weights)
Construct imaginary-frequency grids.
void init(MPI_Comm comm)
Initialize handler with given MPI communicator.
std::vector< std::complex< double > > get_g0w0_sigc_kgrid(const Options &opts, const int n_spins, const std::vector< int > &iks_this, int i_state_low, int i_state_high, const std::vector< double > &vxc, const std::vector< double > &vexx)
Get G0W0 correlation self-energy for k-grid states.
~Handler()
Defatul destructor - automatically frees handler if not already freed.
void set_atoms(const std::vector< int > &types, const std::vector< double > &pos_cart)
Set atom types and Cartesian coordinates.
void set_lri_coeff(LibrpaParallelRouting routing, int I, int J, int nbasis_i, int nbasis_j, int naux_mu, const int R[3], const double *Cs_in, int shrink_aux=0)
Set local RI coefficients.
void set_aux_cut_coulomb_k_atom_pair_packed(int ik, int I, int J, int naux_mu, int naux_nu, const std::complex< double > *Vq, double vq_threshold)
Set truncated Coulomb matrix elements from a packed complex atom-pair matrix.
void set_aux_bare_coulomb_k_atom_pair(int ik, int I, int J, int naux_mu, int naux_nu, const double *Vq_real_in, const double *Vq_imag_in, double vq_threshold)
Set bare Coulomb matrix elements in atom-pair format.
void set_wfc_band_spinor(int ik_band, int nstates_local, int nbasis_local, const double *wfc_up_real, const double *wfc_up_imag, const double *wfc_dn_real, const double *wfc_dn_imag)
Set spinor band-k wavefunctions from separate real and imaginary arrays.
std::vector< double > get_g0w0_spectral_function_band_k(const Options &opts, const int n_spins, const std::vector< int > &iks_band_this, int i_state_low, int i_state_high, const std::vector< double > &omegas, const std::vector< double > &vxc_band, const std::vector< double > &vexx_band)
Get G0W0 spectral functions for band k-point states.
void set_aux_cut_coulomb_k_2d_block_packed(int ik, int mu_begin, int mu_end, int nu_begin, int nu_end, const std::complex< double > *Vq)
Set a truncated Coulomb matrix block from packed complex values.
G0W0SpectralFunctionResult get_g0w0_spectral_function_with_sigc_kgrid(const Options &opts, const int n_spins, const std::vector< int > &iks_this, int i_state_low, int i_state_high, const std::vector< double > &omegas, const std::vector< double > &vxc, const std::vector< double > &vexx)
Get G0W0 spectral functions and continued self-energies for k-grid states.
void set_ao_basis_aux_shrink(const std::vector< size_t > &nbs_aux_shrink, const std::vector< std::vector< int > > &l_shells={})
Set the compressed auxiliary atomic-orbital basis.
void set_aux_bare_coulomb_k_2d_block_packed(int ik, int mu_begin, int mu_end, int nu_begin, int nu_end, const std::complex< double > *Vq)
Set a bare Coulomb matrix block from packed complex values.
void set_aux_cut_coulomb_k_2d_block(int ik, int mu_begin, int mu_end, int nu_begin, int nu_end, const double *Vq_real_in, const double *Vq_imag_in)
Set a truncated Coulomb matrix block.
void set_scf_dimension(int nspins, int nkpts, int nstates, int nbasis, int nspinor=1)
Set mean-field wavefunction dimensions.
void set_wfc_band(int ispin, int ik_band, int nstates_local, int nbasis_local, const double *wfc_real, const double *wfc_imag)
Set band-k wavefunctions from separate real and imaginary arrays.
void set_wfc_spinor_packed(int ik, int nstates_local, int nbasis_local, const std::complex< double > *wfc_up, const std::complex< double > *wfc_dn)
Set spinor wavefunction coefficients from packed complex arrays.
std::vector< std::complex< double > > get_g0w0_sigc_band_k(const Options &opts, const int n_spins, const std::vector< int > &iks_band_this, int i_state_low, int i_state_high, const std::vector< double > &vxc_band, const std::vector< double > &vexx_band)
Get G0W0 correlation self-energy for band k-points.
void set_wfc_band_spinor_packed(int ik_band, int nstates_local, int nbasis_local, const std::complex< double > *wfc_up, const std::complex< double > *wfc_dn)
Set spinor band-k wavefunctions from packed complex values.
void build_g0w0_sigma(const Options &opts)
Build G0W0 self-energy matrix in real space.
void set_wfc_band_packed(int ispin, int ik_band, int nstates_local, int nbasis_local, const std::complex< double > *wfc)
Set band-k wavefunctions from packed complex values.
std::vector< double > get_exx_pot_kgrid(const Options &opts, const int n_spins, const std::vector< int > &iks_this, int i_state_low, int i_state_high)
Get exact-exchange potential for k-grid states.
void build_exx(const Options &opts)
Build exact-exchange matrix in real space.
void set_symmetry_operations(int n_symops, int row_conv, const int *rotmats, const double *trans=nullptr)
Set real-space symmetry operations.
const LibrpaHandler * get_c_handler() const
Get underlying C handler.
Definition librpa.hpp:214
void set_wg_ekb_efermi(int nspins, int nkpts, int nstates, const double *wg, const double *ekb, double efermi)
Set occupation numbers, eigenvalues, and Fermi level.
void set_aux_bare_coulomb_k_2d_block(int ik, int mu_begin, int mu_end, int nu_begin, int nu_end, const double *Vq_real_in, const double *Vq_imag_in)
Set a bare Coulomb matrix block.
void set_ao_basis_wfc(const std::vector< size_t > &nbs_wfc, const std::vector< std::vector< int > > &l_shells={})
Set the wavefunction atomic-orbital basis.
void set_kgrids_kvec(int nk1, int nk2, int nk3, int nkpts, const double *kvecs, const double *kweights=nullptr)
Set loaded SCF k-points from arrays.
void set_band_kvec(int n_kpts_band, const double *kfrac_band)
Set k-points for band-structure calculations.
void free()
Free handler and release resources.
Handler()
Default constructor (creates null handler).
Definition librpa.hpp:202
std::vector< double > get_exx_pot_band_k(const Options &opts, const int n_spins, const std::vector< int > &iks_band_this, int i_state_low, int i_state_high)
Get exact-exchange potential for band k-points.
void set_velocity_matrix_packed(int n_spins, int n_kpts, int n_states, const std::complex< double > *velocity)
Set velocity matrices from packed complex values.
Handler(MPI_Comm comm)
Construct and initialize handler with MPI communicator.
void set_band_occ_eigval(int n_spins, int n_kpts_band, int n_states, const double *occ, const double *eig)
Set occupation numbers and eigenvalues for band k-points.
void set_velocity_matrix(int n_spins, int n_kpts, int n_states, const double *velocity_real, const double *velocity_imag)
Set velocity matrices from separate real and imaginary arrays.
C++ wrapper for runtime options.
Definition librpa.hpp:72
Options()
Construct with default options.
Definition librpa.hpp:75
void set_restart_from_dir(const char *restart_from_dir)
Set directory to read restart checkpoint files from.
Definition librpa.hpp:89
void set_output_dir(const char *output_dir)
Set output directory.
Definition librpa.hpp:82
Enumeration types and constants for LibRPA.
int LibrpaKind
Type of DFT code (reserved for future use).
Definition librpa_enums.h:125
LibrpaAngularOrder
Ordering of real spherical harmonics inside one angular-momentum shell.
Definition librpa_enums.h:53
int LibrpaSwitch
Boolean switch type.
Definition librpa_enums.h:117
#define LIBRPA_SWITCH_OFF
Switch value for disabled/off state (equivalent to false).
Definition librpa_enums.h:23
LibrpaRshCoeff
Coefficient-pair convention for one nonzero real spherical harmonic branch.
Definition librpa_enums.h:68
#define LIBRPA_SWITCH_ON
Switch value for enabled/on state (equivalent to true).
Definition librpa_enums.h:26
int LibrpaVerbose
Verbosity level for runtime output.
Definition librpa_enums.h:133
LibrpaParallelRouting
Parallel routing strategy for distributed memory calculations.
Definition librpa_enums.h:83
LibrpaTimeFreqGrid
Type of time or frequency grid for integration.
Definition librpa_enums.h:101
Handler management for LibRPA instances.
Runtime options for LibRPA calculations.
void librpa_set_output_dir(LibrpaOptions *opts, const char *output_dir)
Set the output directory for LibRPA results.
void librpa_set_restart_from_dir(LibrpaOptions *opts, const char *restart_from_dir)
Set the directory to read restart checkpoint files from.
void librpa_init_options(LibrpaOptions *opts)
Initialize runtime options to default values.
Main namespace for LibRPA C++ API.
Definition file_reader.hpp:25
const char * get_build_info(void)
Get build information string.
void set_output_level(Verbose output_level)
Set the global LibRPA stdout verbosity.
void print_profile(void)
Print profiling information.
int get_minor_version(void)
Get minor version number.
void init_global(Switch switch_redirect_stdout=LIBRPA_SWITCH_OFF, const char *redirect_path="stdout", Switch switch_process_output=LIBRPA_SWITCH_ON)
Initialize the global LibRPA environment.
void finalize_global(void)
Finalize the global LibRPA environment.
LibrpaParallelRouting ParallelRouting
Parallel routing strategy (C++ alias).
Definition librpa.hpp:35
LibrpaKind Kind
DFT code kind type (C++ alias, reserved)
Definition librpa.hpp:41
void test(void)
Run internal self-tests.
int get_patch_version(void)
Get patch version number.
LibrpaVerbose Verbose
Verbosity level type (C++ alias)
Definition librpa.hpp:43
Verbose get_output_level(void)
Get the global LibRPA stdout verbosity.
LibrpaTimeFreqGrid TimeFreqGrid
Time/frequency grid type (C++ alias)
Definition librpa.hpp:37
int get_major_version(void)
Get major version number.
LibrpaSwitch Switch
Boolean switch type (C++ alias)
Definition librpa.hpp:39
Opaque handle to a LibRPA instance.
Definition librpa_handler.h:26
Runtime options structure for LibRPA calculations.
Definition librpa_options.h:35
char restart_from_dir[LIBRPA_MAX_STRLEN]
Definition librpa_options.h:55
char output_dir[LIBRPA_MAX_STRLEN]
Definition librpa_options.h:45
G0W0 correlation self-energies and quasiparticle energies.
Definition librpa.hpp:47
std::vector< std::complex< double > > sigc
Correlation self-energies.
Definition librpa.hpp:48
std::vector< double > eqp
Quasiparticle energies.
Definition librpa.hpp:49
G0W0 spectral functions and continued correlation self-energies.
Definition librpa.hpp:54
std::vector< double > spectral_function
Spectral-function values.
Definition librpa.hpp:56
std::vector< std::complex< double > > sigc
Continued correlation self-energies.
Definition librpa.hpp:55