SIRIUS 7.5.0
Electronic structure library and applications
overlap.hpp
1// Copyright (c) 2023 Simon Pintarelli, Anton Kozhevnikov, Thomas Schulthess
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without modification, are permitted provided that
5// the following conditions are met:
6//
7// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
8// following disclaimer.
9// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
10// and the following disclaimer in the documentation and/or other materials provided with the distribution.
11//
12// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
13// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
14// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
15// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
16// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
17// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
18// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19
20#ifndef __OVERLAP_HPP__
21#define __OVERLAP_HPP__
22
23#ifdef SIRIUS_NLCGLIB
24#include "inverse_overlap.hpp"
27#include <nlcglib/interface.hpp>
28
30#include "adaptor.hpp"
31#include <stdexcept>
32#include "SDDK/memory.hpp"
33#include <memory>
34#include <complex>
35
36namespace sirius {
37
38using inverseS = InverseS_k<std::complex<double>>;
39using S = S_k<std::complex<double>>;
40
41template <class op_t>
42class Overlap_operators : public nlcglib::OverlapBase
43{
44 private:
45 using key_t = std::pair<int, int>;
46
47 public:
48 Overlap_operators(const K_point_set& kset, Simulation_context& ctx, const Q_operator<double>& q_op);
49 // virtual void apply(nlcglib::MatrixBaseZ& out, const nlcglib::MatrixBaseZ& in) const override;
50 /// return a functor for nlcglib at given key
51 virtual void apply(const key_t& key, nlcglib::MatrixBaseZ::buffer_t& out,
52 nlcglib::MatrixBaseZ::buffer_t& in) const override;
53 virtual std::vector<std::pair<int, int>> get_keys() const override;
54
55 private:
56 std::map<key_t, std::shared_ptr<op_t>> data_;
57};
58
59template <class op_t>
60Overlap_operators<op_t>::Overlap_operators(const K_point_set& kset, Simulation_context& ctx,
61 const Q_operator<double>& q_op)
62{
63 for (auto it : kset.spl_num_kpoints()) {
64 auto& kp = *kset.get<double>(it.i);
65 for (int ispn = 0; ispn < ctx.num_spins(); ++ispn) {
66 key_t key{it.i.get(), ispn};
67 data_[key] = std::make_shared<op_t>(ctx, q_op, kp.beta_projectors(), ispn);
68 }
69 }
70}
71
72template <class op_t>
73void
74Overlap_operators<op_t>::apply(const key_t& key, nlcglib::MatrixBaseZ::buffer_t& out,
75 nlcglib::MatrixBaseZ::buffer_t& in) const
76{
77 auto& op = data_.at(key);
78 auto array_out = make_matrix_view(out);
79 auto array_in = make_matrix_view(in);
80 // TODO: make sure the processing unit is correct
81 sddk::memory_t pm = out.memtype == nlcglib::memory_type::host ? sddk::memory_t::host : sddk::memory_t::device;
82 op->apply(array_out, array_in, pm);
83}
84
85template <class op_t>
86std::vector<std::pair<int, int>>
87Overlap_operators<op_t>::get_keys() const
88{
89 std::vector<key_t> keys;
90 for (auto& elem : data_) {
91 keys.push_back(elem.first);
92 }
93 return keys;
94}
95
96} // namespace sirius
97#endif /* SIRIUS_NLCGLIB */
98
99#endif /* __OVERLAP_HPP__ */
Contains defintion of nlcglib interface.
provides S⁻¹
Contains declaration and partial implementation of sirius::K_point_set class.
Memory management functions and classes.
@ key
the parser read a key of a value in an object
Namespace of the SIRIUS library.
Definition: sirius.f90:5
Contains declaration of sirius::Non_local_operator class.
Contains definition and implementation of Simulation_context class.