Skip to content

Commit

Permalink
Merge branch 'remove_fourier_projectors' into 'master'
Browse files Browse the repository at this point in the history
Remove the application of the pseudopotentials in Fourier space

See merge request npneq/inq!1178
  • Loading branch information
xavierandrade committed Dec 15, 2024
2 parents ed8fc89 + 70ed75a commit 5b0440f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 288 deletions.
8 changes: 1 addition & 7 deletions src/hamiltonian/atomic_potential.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,14 @@ namespace hamiltonian {
std::unordered_map<std::string, pseudopotential_type> pseudopotential_list_;
bool has_nlcc_;
basis::double_grid double_grid_;
bool fourier_pseudo_;

public:

template <class SpeciesList>
atomic_potential(SpeciesList const & species_list, double gcutoff, options::electrons const & conf = {}):
sep_(0.625), //this is the default from octopus
default_pseudo_set_(species_list.pseudopotentials()),
double_grid_(conf.double_grid_value()),
fourier_pseudo_(conf.fourier_pseudo_value())
double_grid_(conf.double_grid_value())
{

CALI_CXX_MARK_FUNCTION;
Expand Down Expand Up @@ -318,10 +316,6 @@ namespace hamiltonian {
return double_grid_;
}

auto & fourier_pseudo() const {
return fourier_pseudo_;
}

};

}
Expand Down
71 changes: 13 additions & 58 deletions src/hamiltonian/ks_hamiltonian.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <hamiltonian/exchange_operator.hpp>
#include <hamiltonian/projector.hpp>
#include <hamiltonian/projector_all.hpp>
#include <hamiltonian/projector_fourier.hpp>
#include <hamiltonian/relativistic_projector.hpp>
#include <hamiltonian/scalar_potential.hpp>
#include <input/environment.hpp>
Expand Down Expand Up @@ -46,9 +45,6 @@ class ks_hamiltonian {
basis::field_set<basis::real_space, PotentialType> scalar_potential_;
vector3<double, covariant> uniform_vector_potential_;
projector_all projectors_all_;
bool non_local_in_fourier_;
std::unordered_map<std::string, projector_fourier> projectors_fourier_map_;
std::vector<std::unordered_map<std::string, projector_fourier>::iterator> projectors_fourier_;
std::list<relativistic_projector> projectors_rel_;
states::ks_states states_;

Expand All @@ -74,17 +70,12 @@ class ks_hamiltonian {

std::list<projector> projectors;

projectors_fourier_map_.clear();

for(int iatom = 0; iatom < ions.size(); iatom++){
auto && ps = pot.pseudo_for_element(ions.species(iatom));

if(ps.has_total_angular_momentum()){
projectors_rel_.emplace_back(basis, pot.double_grid(), ps, ions.positions()[iatom], iatom);
if(projectors_rel_.back().empty()) projectors_rel_.pop_back();
} else if(non_local_in_fourier_){
auto insert = projectors_fourier_map_.emplace(ions.symbol(iatom), projector_fourier(basis, ps));
insert.first->second.add_coord(basis.cell().metric().to_contravariant(ions.positions()[iatom]));
} else {
projectors.emplace_back(basis, pot.double_grid(), ps, ions.positions()[iatom], iatom);
if(projectors.back().empty()) projectors.pop_back();
Expand All @@ -102,7 +93,6 @@ class ks_hamiltonian {
exchange_(basis.cell(), bzone, exchange_coefficient, use_ace),
scalar_potential_(basis, states.num_density_components()),
uniform_vector_potential_({0.0, 0.0, 0.0}),
non_local_in_fourier_(pot.fourier_pseudo()),
states_(states)
{
scalar_potential_.fill(0.0);
Expand All @@ -111,43 +101,20 @@ class ks_hamiltonian {

////////////////////////////////////////////////////////////////////////////////////////////

void non_local(const states::orbital_set<basis::fourier_space, complex> & phi, states::orbital_set<basis::fourier_space, complex> & vnlphi) const {

if(not non_local_in_fourier_) return;

for(auto it = projectors_fourier_map_.cbegin(); it != projectors_fourier_map_.cend(); ++it){
it->second(phi, vnlphi);
}
}

////////////////////////////////////////////////////////////////////////////////////////////

auto non_local(const states::orbital_set<basis::real_space, complex> & phi) const {

CALI_CXX_MARK_FUNCTION;

if(non_local_in_fourier_) {

auto phi_fs = operations::transform::to_fourier(phi);
states::orbital_set<basis::fourier_space, complex> vnlphi_fs(phi_fs.skeleton());

vnlphi_fs.fill(0.0);
non_local(phi_fs, vnlphi_fs);
return operations::transform::to_real(vnlphi_fs);

} else {

auto proj = projectors_all_.project(phi, phi.kpoint() + uniform_vector_potential_);

states::orbital_set<basis::real_space, complex> vnlphi(phi.skeleton());
vnlphi.fill(0.0);

projectors_all_.apply(proj, vnlphi, phi.kpoint() + uniform_vector_potential_);

for(auto & pr : projectors_rel_) pr.apply(phi, vnlphi, phi.kpoint() + uniform_vector_potential_);

return vnlphi;
}
auto proj = projectors_all_.project(phi, phi.kpoint() + uniform_vector_potential_);

states::orbital_set<basis::real_space, complex> vnlphi(phi.skeleton());
vnlphi.fill(0.0);

projectors_all_.apply(proj, vnlphi, phi.kpoint() + uniform_vector_potential_);

for(auto & pr : projectors_rel_) pr.apply(phi, vnlphi, phi.kpoint() + uniform_vector_potential_);

return vnlphi;
}

////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -157,18 +124,9 @@ class ks_hamiltonian {

CALI_CXX_MARK_FUNCTION;

if(non_local_in_fourier_) {

auto nl_me = operations::overlap_diagonal_normalized(non_local(phi), phi);
auto en = occ_sum(occupations, nl_me);
if(reduce_states and phi.set_comm().size() > 1) phi.set_comm().all_reduce_in_place_n(&en, 1, std::plus<>{});
return en;

} else {
auto en = projectors_all_.energy(phi, phi.kpoint() + uniform_vector_potential_, occupations, reduce_states);
for(auto & pr : projectors_rel_) en += pr.energy(phi, occupations, phi.kpoint() + uniform_vector_potential_);
return en;
}
auto en = projectors_all_.energy(phi, phi.kpoint() + uniform_vector_potential_, occupations, reduce_states);
for(auto & pr : projectors_rel_) en += pr.energy(phi, occupations, phi.kpoint() + uniform_vector_potential_);
return en;

}

Expand All @@ -183,8 +141,6 @@ class ks_hamiltonian {
auto phi_fs = operations::transform::to_fourier(phi);

auto hphi_fs = operations::laplacian(phi_fs, -0.5, -2.0*phi.basis().cell().metric().to_contravariant(phi.kpoint() + uniform_vector_potential_));

non_local(phi_fs, hphi_fs);

auto hphi = operations::transform::to_real(hphi_fs);

Expand Down Expand Up @@ -217,7 +173,6 @@ class ks_hamiltonian {
auto hphi = operations::transform::to_fourier(hphi_rs);

operations::laplacian_add(phi, hphi, -0.5, -2.0*phi.basis().cell().metric().to_contravariant(phi.kpoint() + uniform_vector_potential_));
non_local(phi, hphi);

return hphi;
}
Expand Down
179 changes: 0 additions & 179 deletions src/hamiltonian/projector_fourier.hpp

This file was deleted.

5 changes: 0 additions & 5 deletions src/interface/electrons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,6 @@ the user.
el_opts.save(input::environment::global().comm(), ".inq/default_electrons_options");
}

static void fourier_pseudo() {
auto el_opts = options::electrons::load(".inq/default_electrons_options").fourier_pseudo();
el_opts.save(input::environment::global().comm(), ".inq/default_electrons_options");
}

static void spin_unpolarized() {
auto el_opts = options::electrons::load(".inq/default_electrons_options").spin_unpolarized();
el_opts.save(input::environment::global().comm(), ".inq/default_electrons_options");
Expand Down
Loading

0 comments on commit 5b0440f

Please sign in to comment.