Skip to content

Commit

Permalink
Merge branch 'template_for_magnetic_perturbation' into 'master'
Browse files Browse the repository at this point in the history
Template for magnetic perturbation

See merge request npneq/inq!1143
  • Loading branch information
xavierandrade committed Oct 9, 2024
2 parents 122a887 + 6e1a74e commit c45427c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/hamiltonian/self_consistency.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ class self_consistency {
if(has_induced_vector_potential()){
hamiltonian.uniform_vector_potential_ += induced_vector_potential_;
}

//the magnetic perturbation is not implemented yet
assert(not pert_.has_magnetic_field());

}

Expand Down
15 changes: 15 additions & 0 deletions src/perturbations/blend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@ class blend {
}
}

auto has_magnetic_field() const {
for(auto & pert : perts_){
auto has = std::visit([&](auto per) { return per.has_magnetic_field(); }, pert);
if(has) return true;
}
return false;
}

template<typename MagneticField>
void magnetic_field(double const time, MagneticField & magnetic) const {
for(auto & pert : perts_){
std::visit([&](auto per) { per.magnetic_field(time, magnetic); }, pert);
}
}

void save(parallel::communicator & comm, std::string const & dirname) const {
auto error_message = "INQ error: Cannot save the perturbations::blend to directory '" + dirname + "'.";

Expand Down
8 changes: 8 additions & 0 deletions src/perturbations/none.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ class none {
void potential(const double time, PotentialType & potential) const {
}

auto has_magnetic_field() const {
return false;
}

template<typename MagneticField>
void magnetic_field(const double time, MagneticField & magnetic) const {
}

template<class OStream>
friend OStream & operator<<(OStream & out, none const & self){
return out;
Expand Down
10 changes: 10 additions & 0 deletions src/perturbations/sum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,17 @@ class sum {
perta_.potential(time, potential);
pertb_.potential(time, potential);
}

auto has_magnetic_field() const {
return perta_.has_magnetic_field() or pertb_.has_magnetic_field();
}

template<typename MagneticField>
void magnetic_field(const double time, MagneticField & magnetic) const {
perta_.magnetic_field(time, magnetic);
pertb_.magnetic_field(time, magnetic);
}

template<class OStream>
friend OStream & operator<<(OStream & out, sum const & self){
out << self.perta_;
Expand Down

0 comments on commit c45427c

Please sign in to comment.