|
| 1 | +#include "source_estate/setup_estate_pw.h" |
| 2 | + |
| 3 | +template <typename T, typename Device> |
| 4 | +void elecstate::setup_estate_pw(UnitCell& ucell, // unitcell |
| 5 | + const K_Vectors &kv, // kpoints |
| 6 | + Structure_Factor &sf, // structure factors |
| 7 | + elecstate::ElecState *pelec, // pointer of electrons |
| 8 | + const Charge &chr, // charge density |
| 9 | + pseudopot_cell_vl &locpp, // local pseudopotentials |
| 10 | + pseudopot_cell_vnl &ppcell, // non-local pseudopotentials |
| 11 | + VSep* vsep_cell, // U-1/2 method |
| 12 | + ModulePW::PW_Basis_K *pw_wfc, // pw for wfc |
| 13 | + const ModulePW::PW_Basis *pw_rho, // pw for rho |
| 14 | + const ModulePW::PW_Basis *pw_rhod, // pw for rhod |
| 15 | + const ModulePW::PW_Basis_Big* pw_big, // pw for big grid |
| 16 | + surchem &solvent, // solvent |
| 17 | + const Input_para& inp) // input parameters |
| 18 | +{ |
| 19 | + ModuleBase::TITLE("elecstate", "setup_estate_pw"); |
| 20 | + |
| 21 | + //! Initialize ElecState, set pelec pointer |
| 22 | + if (pelec == nullptr) |
| 23 | + { |
| 24 | + if (inp.esolver_type == "sdft") |
| 25 | + { |
| 26 | + //! SDFT only supports double precision currently |
| 27 | + pelec = new elecstate::ElecStatePW_SDFT<std::complex<double>, Device>(pw_wfc, |
| 28 | + &chr, &kv, &ucell, &ppcell, |
| 29 | + pw_rhod, pw_rho, pw_big); |
| 30 | + } |
| 31 | + else |
| 32 | + { |
| 33 | + pelec = new elecstate::ElecStatePW<T, Device>(pw_wfc, |
| 34 | + &chr, &kv, &ucell, &ppcell, |
| 35 | + pw_rhod, pw_rho, pw_big); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + //! Set the cell volume variable in pelec |
| 40 | + pelec->omega = ucell.omega; |
| 41 | + |
| 42 | + //! Inititlize the charge density. |
| 43 | + chr.allocate(inp.nspin); |
| 44 | + |
| 45 | + //! Initialize DFT-1/2 |
| 46 | + if (PARAM.inp.dfthalf_type > 0) |
| 47 | + { |
| 48 | + vsep_cell = new VSep; |
| 49 | + vsep_cell->init_vsep(*pw_rhod, ucell.sep_cell); |
| 50 | + } |
| 51 | + |
| 52 | + //! Initialize the potential. |
| 53 | + if (pelec->pot == nullptr) |
| 54 | + { |
| 55 | + pelec->pot = new elecstate::Potential(pw_rhod, |
| 56 | + pw_rho, &ucell, &locpp.vloc, &sf, |
| 57 | + &solvent, &(pelec->f_en.etxc), &(pelec->f_en.vtxc), vsep_cell); |
| 58 | + } |
| 59 | + |
| 60 | + //! Initalize local pseudopotential |
| 61 | + locpp.init_vloc(ucell, pw_rhod); |
| 62 | + ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL"); |
| 63 | + |
| 64 | + //! Initalize non-local pseudopotential |
| 65 | + ppcell.init(ucell, &sf, pw_wfc); |
| 66 | + ppcell.init_vnl(ucell, pw_rhod); |
| 67 | + ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "NON-LOCAL POTENTIAL"); |
| 68 | + |
| 69 | + //! Setup occupations |
| 70 | + if (inp.ocp) |
| 71 | + { |
| 72 | + elecstate::fixed_weights(inp.ocp_kb, |
| 73 | + inp.nbands, |
| 74 | + inp.nelec, |
| 75 | + pelec->klist, |
| 76 | + pelec->wg, |
| 77 | + pelec->skip_weights); |
| 78 | + } |
| 79 | + |
| 80 | + return; |
| 81 | +} |
| 82 | + |
| 83 | + |
| 84 | +void elecstate::teardown_estate_pw(elecstate::ElecState *pelec, VSep* vsep_cell) |
| 85 | +{ |
| 86 | + ModuleBase::TITLE("elecstate", "teardown_estate_pw"); |
| 87 | + |
| 88 | + if (vsep_cell != nullptr) |
| 89 | + { |
| 90 | + delete vsep_cell; |
| 91 | + } |
| 92 | + |
| 93 | + if (pelec != nullptr) |
| 94 | + { |
| 95 | + delete reinterpret_cast<elecstate::ElecStatePW<T, Device>*>(pelec); |
| 96 | + pelec = nullptr; |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | + |
| 101 | +template void elecstate::setup_estate_pw<std::complex<float>, base_device::DEVICE_CPU>( |
| 102 | + UnitCell& ucell, // unitcell |
| 103 | + const K_Vectors &kv, // kpoints |
| 104 | + Structure_Factor &sf, // structure factors |
| 105 | + elecstate::ElecState *pelec, // pointer of electrons |
| 106 | + const Charge &chr, // charge density |
| 107 | + pseudopot_cell_vl &locpp, // local pseudopotentials |
| 108 | + pseudopot_cell_vnl &ppcell, // non-local pseudopotentials |
| 109 | + VSep* vsep_cell, // U-1/2 method |
| 110 | + ModulePW::PW_Basis_K *pw_wfc, // pw for wfc |
| 111 | + const ModulePW::PW_Basis *pw_rho, // pw for rho |
| 112 | + const ModulePW::PW_Basis *pw_rhod, // pw for rhod |
| 113 | + const ModulePW::PW_Basis_Big* pw_big, // pw for big grid |
| 114 | + surchem &solvent, // solvent |
| 115 | + const Input_para& inp); // input parameters |
| 116 | + |
| 117 | +template void elecstate::setup_estate_pw<std::complex<double>, base_device::DEVICE_CPU>( |
| 118 | + UnitCell& ucell, // unitcell |
| 119 | + const K_Vectors &kv, // kpoints |
| 120 | + Structure_Factor &sf, // structure factors |
| 121 | + elecstate::ElecState *pelec, // pointer of electrons |
| 122 | + const Charge &chr, // charge density |
| 123 | + pseudopot_cell_vl &locpp, // local pseudopotentials |
| 124 | + pseudopot_cell_vnl &ppcell, // non-local pseudopotentials |
| 125 | + VSep* vsep_cell, // U-1/2 method |
| 126 | + ModulePW::PW_Basis_K *pw_wfc, // pw for wfc |
| 127 | + const ModulePW::PW_Basis *pw_rho, // pw for rho |
| 128 | + const ModulePW::PW_Basis *pw_rhod, // pw for rhod |
| 129 | + const ModulePW::PW_Basis_Big* pw_big, // pw for big grid |
| 130 | + surchem &solvent, // solvent |
| 131 | + const Input_para& inp); // input parameters |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | +#if ((defined __CUDA) || (defined __ROCM)) |
| 136 | + |
| 137 | +template void elecstate::setup_estate_pw<std::complex<float>, base_device::DEVICE_GPU>( |
| 138 | + UnitCell& ucell, // unitcell |
| 139 | + const K_Vectors &kv, // kpoints |
| 140 | + Structure_Factor &sf, // structure factors |
| 141 | + elecstate::ElecState *pelec, // pointer of electrons |
| 142 | + const Charge &chr, // charge density |
| 143 | + pseudopot_cell_vl &locpp, // local pseudopotentials |
| 144 | + pseudopot_cell_vnl &ppcell, // non-local pseudopotentials |
| 145 | + VSep* vsep_cell, // U-1/2 method |
| 146 | + ModulePW::PW_Basis_K *pw_wfc, // pw for wfc |
| 147 | + const ModulePW::PW_Basis *pw_rho, // pw for rho |
| 148 | + const ModulePW::PW_Basis *pw_rhod, // pw for rhod |
| 149 | + const ModulePW::PW_Basis_Big* pw_big, // pw for big grid |
| 150 | + surchem &solvent, // solvent |
| 151 | + const Input_para& inp); // input parameters |
| 152 | + |
| 153 | +template void elecstate::setup_estate_pw<std::complex<double>, base_device::DEVICE_GPU>( |
| 154 | + UnitCell& ucell, // unitcell |
| 155 | + const K_Vectors &kv, // kpoints |
| 156 | + Structure_Factor &sf, // structure factors |
| 157 | + elecstate::ElecState *pelec, // pointer of electrons |
| 158 | + const Charge &chr, // charge density |
| 159 | + pseudopot_cell_vl &locpp, // local pseudopotentials |
| 160 | + pseudopot_cell_vnl &ppcell, // non-local pseudopotentials |
| 161 | + VSep* vsep_cell, // U-1/2 method |
| 162 | + ModulePW::PW_Basis_K *pw_wfc, // pw for wfc |
| 163 | + const ModulePW::PW_Basis *pw_rho, // pw for rho |
| 164 | + const ModulePW::PW_Basis *pw_rhod, // pw for rhod |
| 165 | + const ModulePW::PW_Basis_Big* pw_big, // pw for big grid |
| 166 | + surchem &solvent, // solvent |
| 167 | + const Input_para& inp); // input parameters |
| 168 | + |
| 169 | +#endif |
0 commit comments