25#ifndef __NLCGLIB_ADAPTOR_HPP__
26#define __NLCGLIB_ADAPTOR_HPP__
29#include <nlcglib/interface.hpp>
40class Matrix :
public nlcglib::MatrixBaseZ
43 Matrix(std::vector<buffer_t>
const& data, std::vector<kindex_t>
const& indices, MPI_Comm mpi_comm = MPI_COMM_SELF)
50 Matrix(std::vector<buffer_t>&& data, std::vector<kindex_t>&& indices, MPI_Comm mpi_comm = MPI_COMM_SELF)
51 : data{std::forward<std::vector<buffer_t>>(data)}
52 , indices{std::forward<std::vector<kindex_t>>(indices)}
57 buffer_t get(
int i)
override;
58 const buffer_t get(
int i)
const override;
60 int size()
const override
65 MPI_Comm mpicomm(
int i)
const override
67 return data[i].mpi_comm;
70 MPI_Comm mpicomm()
const override
75 kindex_t kpoint_index(
int i)
const override
81 std::vector<buffer_t> data;
82 std::vector<kindex_t> indices;
87class Array1d :
public nlcglib::VectorBaseZ
90 Array1d(std::vector<std::vector<double>>
const& data, std::vector<kindex_t>
const& indices,
91 MPI_Comm mpi_comm = MPI_COMM_SELF)
98 Array1d(std::vector<std::vector<double>>&& data, std::vector<kindex_t>&& indices, MPI_Comm mpi_comm = MPI_COMM_SELF)
99 : data{std::forward<decltype(data)>(data)}
100 , indices{std::forward<decltype(indices)>(indices)}
105 buffer_t get(
int i)
override;
106 const buffer_t get(
int i)
const override;
108 int size()
const override
113 MPI_Comm mpicomm(
int i)
const override
116 return MPI_COMM_SELF;
119 MPI_Comm mpicomm()
const override
124 kindex_t kpoint_index(
int i)
const override
126 assert(i <
static_cast<int>(indices.size()));
131 std::vector<std::vector<double>> data;
132 std::vector<kindex_t> indices;
136class Scalar :
public nlcglib::ScalarBaseZ
139 Scalar(std::vector<double>
const& data__, std::vector<kindex_t>
const& indices__, MPI_Comm mpi_comm = MPI_COMM_SELF)
146 Scalar(std::vector<double>&& data__, std::vector<kindex_t>&& indices__, MPI_Comm mpi_comm = MPI_COMM_SELF)
147 : data{std::forward<decltype(data)>(data__)}
148 , indices{std::forward<decltype(indices)>(indices__)}
153 buffer_t get(
int i)
override
158 const buffer_t get(
int i)
const override
163 int size()
const override
168 MPI_Comm mpicomm(
int i)
const override
171 return MPI_COMM_SELF;
174 MPI_Comm mpicomm()
const override
179 kindex_t kpoint_index(
int i)
const override
185 std::vector<double> data;
186 std::vector<kindex_t> indices;
195 int nelectrons()
override;
196 int occupancy()
override;
197 void compute()
override;
198 double get_total_energy()
override;
199 std::map<std::string, double> get_energy_components()
override;
200 std::shared_ptr<nlcglib::MatrixBaseZ> get_hphi(nlcglib::memory_type)
override;
201 std::shared_ptr<nlcglib::MatrixBaseZ> get_sphi(nlcglib::memory_type)
override;
202 std::shared_ptr<nlcglib::MatrixBaseZ> get_C(nlcglib::memory_type)
override;
203 std::shared_ptr<nlcglib::VectorBaseZ> get_fn()
override;
204 void set_fn(
const std::vector<std::pair<int, int>>& keys,
const std::vector<std::vector<double>>& fn)
override;
205 std::shared_ptr<nlcglib::VectorBaseZ> get_ek()
override;
206 std::shared_ptr<nlcglib::VectorBaseZ> get_gkvec_ekin()
override;
207 std::shared_ptr<nlcglib::ScalarBaseZ> get_kpoint_weights()
override;
208 void set_chemical_potential(
double)
override;
209 double get_chemical_potential()
override;
210 void print_info()
const override;
217 std::vector<std::shared_ptr<wf::Wave_functions<double>>>
hphis_;
219 std::vector<std::shared_ptr<wf::Wave_functions<double>>>
sphis_;
221 std::vector<wf::Wave_functions<double>*>
cphis_;
222 double etot_{std::nan(
"1")};
223 std::map<std::string, double> energy_components_;
226template <
class numeric_t>
228make_matrix_view(nlcglib::buffer_protocol<numeric_t, 2>& buf)
230 int nrows = buf.size[0];
231 int ncols = buf.size[1];
233 if (buf.stride[0] != 1 || buf.stride[1] != nrows) {
234 RTE_THROW(
"strides not compatible with sddk::mdarray");
237 numeric_t *device_ptr{
nullptr}, *host_ptr{
nullptr};
239 switch (buf.memtype) {
240 case nlcglib::memory_type::device: {
241 device_ptr = buf.data;
244 case nlcglib::memory_type::host: {
249 RTE_THROW(
"buffer protocol invalid memory type.");
253 return sddk::matrix<numeric_t>(host_ptr, device_ptr, nrows, ncols);
TODO: Array1d owns data...
Generate charge density and magnetization from occupied spinor wave-functions.
std::vector< wf::Wave_functions< double > * > cphis_
original wfct
std::vector< std::shared_ptr< wf::Wave_functions< double > > > hphis_
H*psi.
std::vector< std::shared_ptr< wf::Wave_functions< double > > > sphis_
S*spi.
Generate effective potential from charge density and magnetization.
Contains definition and partial implementation of sirius::Density class.
Contains declaration and partial implementation of sirius::K_point_set class.
Namespace of the SIRIUS library.
Contains declaration and partial implementation of sirius::Potential class.
Contains declaration and implementation of Wave_functions class.