33FunctionProperties<Periodic_function<double>> periodic_function_property()
35 auto global_size_func = [](
const Periodic_function<double>& x) ->
double
37 return x.ctx().unit_cell().omega();
40 auto inner_prod_func = [](
const Periodic_function<double>& x,
const Periodic_function<double>& y) ->
double {
41 return sirius::inner(x, y);
44 auto scal_function = [](
double alpha, Periodic_function<double>& x) ->
void {
46 if (x.ctx().full_potential()) {
51 auto copy_function = [](
const Periodic_function<double>& x, Periodic_function<double>& y) ->
void {
53 if (x.ctx().full_potential()) {
58 auto axpy_function = [](
double alpha,
const Periodic_function<double>& x, Periodic_function<double>& y) ->
void {
59 axpy(alpha, x.rg(), y.rg());
60 if (x.ctx().full_potential()) {
61 axpy(alpha, x.mt(), y.mt());
65 auto rotate_function = [](
double c,
double s, Periodic_function<double>& x, Periodic_function<double>& y) ->
void {
68 #pragma omp for schedule(static) nowait
69 for (std::size_t i = 0; i < x.rg().values().size(); ++i) {
70 auto xi = x.rg().value(i);
71 auto yi = y.rg().value(i);
72 x.rg().value(i) = xi * c + yi * s;
73 y.rg().value(i) = xi * -s + yi * c;
75 if (x.ctx().full_potential()) {
76 for (
auto it : x.ctx().unit_cell().spl_num_atoms()) {
78 auto& x_f_mt = x.mt()[ia];
79 auto& y_f_mt = y.mt()[ia];
80 #pragma omp for schedule(static) nowait
81 for (
int i = 0; i < static_cast<int>(x.mt()[ia].size()); i++) {
84 x_f_mt[i] = xi * c + yi * s;
85 y_f_mt[i] = xi * -s + yi * c;
92 return FunctionProperties<Periodic_function<double>>(global_size_func, inner_prod_func, scal_function, copy_function,
93 axpy_function, rotate_function);
101 return 1.0 / x.ctx().unit_cell().omega();
108 if (use_coarse_gvec__) {
109 for (
int igloc = x.ctx().gvec_coarse().skip_g0(); igloc < x.ctx().gvec_coarse().count(); igloc++) {
111 int ig1 = x.ctx().gvec().gvec_base_mapping(igloc);
113 result += std::real(
std::conj(x.
rg().f_pw_local(ig1)) * y.rg().f_pw_local(ig1)) /
117 for (
int igloc = x.ctx().gvec().skip_g0(); igloc < x.ctx().gvec().count(); igloc++) {
118 result += std::real(
std::conj(x.
rg().f_pw_local(igloc)) * y.rg().f_pw_local(igloc)) /
122 if (x.ctx().gvec().reduced()) {
126 x.ctx().comm().allreduce(&result, 1);
132 scale(alpha, x.
rg());
136 copy(x.
rg(), y.rg());
141 axpy(alpha, x.
rg(), y.rg());
146 #pragma omp parallel for schedule(static)
147 for (std::size_t i = 0; i < x.
rg().values().size(); ++i) {
148 auto xi = x.
rg().value(i);
149 auto yi = y.rg().value(i);
150 x.
rg().value(i) = xi * c + yi * s;
151 y.rg().value(i) = xi * -s + yi * c;
156 axpy_function, rotate_function);
159FunctionProperties<density_matrix_t> density_function_property()
169 auto inner_prod_func = [](density_matrix_t
const& x, density_matrix_t
const& y) ->
double {
174 auto scal_function = [](
double alpha, density_matrix_t& x) ->
void {
175 for (std::size_t i = 0; i < x.size(); i++) {
176 for (std::size_t j = 0; j < x[i].size(); j++) {
182 auto copy_function = [](density_matrix_t
const& x, density_matrix_t& y) ->
void {
183 assert(x.size() == y.size());
184 for (std::size_t i = 0; i < x.size(); i++) {
189 auto axpy_function = [](
double alpha, density_matrix_t
const& x, density_matrix_t& y) ->
void {
190 assert(x.size() == y.size());
191 for (std::size_t i = 0; i < x.size(); i++) {
192 for (std::size_t j = 0; j < x[i].size(); j++) {
193 y[i][j] += alpha * x[i][j];
198 auto rotate_function = [](
double c,
double s, density_matrix_t& x, density_matrix_t& y) ->
void {
199 assert(x.size() == y.size());
200 for (std::size_t i = 0; i < x.size(); i++) {
201 for (std::size_t j = 0; j < x[i].size(); j++) {
204 x[i][j] = xi * c + yi * s;
205 y[i][j] = xi * -s + yi * c;
210 return FunctionProperties<density_matrix_t>(global_size_func, inner_prod_func, scal_function,
211 copy_function, axpy_function, rotate_function);
214FunctionProperties<PAW_density<double>> paw_density_function_property()
216 auto global_size_func = [](PAW_density<double>
const& x) ->
double
218 return x.unit_cell().num_paw_atoms();
221 auto inner_prod_func = [](PAW_density<double>
const& x, PAW_density<double>
const& y) ->
double
226 auto scale_func = [](
double alpha, PAW_density<double>& x) ->
void
228 for (
auto it : x.unit_cell().spl_num_paw_atoms()) {
229 int ia = x.unit_cell().paw_atom_index(it.i);
230 for (
int j = 0; j < x.unit_cell().parameters().num_mag_dims() + 1; j++) {
231 x.ae_density(j, ia) *= alpha;
232 x.ps_density(j, ia) *= alpha;
237 auto copy_function = [](PAW_density<double>
const& x, PAW_density<double>& y) ->
void
239 for (
auto it : x.unit_cell().spl_num_paw_atoms()) {
240 int ia = x.unit_cell().paw_atom_index(it.i);
241 for (
int j = 0; j < x.unit_cell().parameters().num_mag_dims() + 1; j++) {
242 sddk::copy(x.ae_density(j, ia), y.ae_density(j, ia));
243 sddk::copy(x.ps_density(j, ia), y.ps_density(j, ia));
248 auto axpy_function = [](
double alpha, PAW_density<double>
const& x, PAW_density<double>& y) ->
void
250 for (
auto it : x.unit_cell().spl_num_paw_atoms()) {
251 int ia = x.unit_cell().paw_atom_index(it.i);
252 for (
int j = 0; j < x.unit_cell().parameters().num_mag_dims() + 1; j++) {
253 y.ae_density(j, ia) = x.ae_density(j, ia) * alpha + y.ae_density(j, ia);
254 y.ps_density(j, ia) = x.ps_density(j, ia) * alpha + y.ps_density(j, ia);
259 auto rotate_function = [](
double c,
double s, PAW_density<double>& x, PAW_density<double>& y) ->
void
261 for (
auto it : x.unit_cell().spl_num_paw_atoms()) {
262 int ia = x.unit_cell().paw_atom_index(it.i);
263 for (
int j = 0; j < x.unit_cell().parameters().num_mag_dims() + 1; j++) {
264 x.ae_density(j, ia) = x.ae_density(j, ia) * c + s * y.ae_density(j, ia);
265 y.ae_density(j, ia) = y.ae_density(j, ia) * c - s * x.ae_density(j, ia);
267 x.ps_density(j, ia) = x.ps_density(j, ia) * c + s * y.ps_density(j, ia);
268 y.ps_density(j, ia) = y.ps_density(j, ia) * c - s * x.ps_density(j, ia);
273 return FunctionProperties<PAW_density<double>>(global_size_func, inner_prod_func, scale_func, copy_function,
274 axpy_function, rotate_function);
277FunctionProperties<Hubbard_matrix> hubbard_matrix_function_property()
279 auto global_size_func = [](Hubbard_matrix
const& x) ->
double
284 auto inner_prod_func = [](Hubbard_matrix
const& x, Hubbard_matrix
const& y) ->
double
290 auto scale_func = [](
double alpha, Hubbard_matrix& x) ->
void
292 for (
size_t at_lvl = 0; at_lvl < x.local().size(); at_lvl++) {
293 for (
size_t i = 0; i < x.local(at_lvl).size(); i++) {
294 x.local(at_lvl)[i] *= alpha;
298 for (
size_t at_lvl = 0; at_lvl < x.nonlocal().size(); at_lvl++) {
299 for (
size_t i = 0; i < x.nonlocal(at_lvl).size(); i++) {
300 x.nonlocal(at_lvl)[i] *= alpha;
305 auto copy_func = [](Hubbard_matrix
const& x, Hubbard_matrix& y) ->
void
307 for (
size_t at_lvl = 0; at_lvl < x.local().size(); at_lvl++) {
311 for (
size_t at_lvl = 0; at_lvl < x.nonlocal().size(); at_lvl++) {
312 sddk::copy(x.nonlocal(at_lvl), y.nonlocal(at_lvl));
316 auto axpy_func = [](
double alpha, Hubbard_matrix
const& x, Hubbard_matrix& y) ->
void
318 for (
size_t at_lvl = 0; at_lvl < x.local().size(); at_lvl++) {
319 for (
size_t i = 0; i < x.local(at_lvl).size(); i++) {
320 y.local(at_lvl)[i] = alpha * x.local(at_lvl)[i] + y.local(at_lvl)[i];
323 for (
size_t at_lvl = 0; at_lvl < x.nonlocal().size(); at_lvl++) {
324 for (
size_t i = 0; i < x.nonlocal(at_lvl).size(); i++) {
325 y.nonlocal(at_lvl)[i] = alpha * x.nonlocal(at_lvl)[i] + y.nonlocal(at_lvl)[i];
330 auto rotate_func = [](
double c,
double s, Hubbard_matrix& x, Hubbard_matrix& y) ->
void
332 for (
size_t at_lvl = 0; at_lvl < x.local().size(); at_lvl++) {
333 for (
size_t i = 0; i < x.local(at_lvl).size(); i++) {
334 auto xi = x.local(at_lvl)[i];
335 auto yi = y.local(at_lvl)[i];
336 x.local(at_lvl)[i] = xi * c + yi * s;
337 y.local(at_lvl)[i] = yi * c - xi * s;
341 for (
size_t at_lvl = 0; at_lvl < x.nonlocal().size(); at_lvl++) {
342 for (
size_t i = 0; i < x.nonlocal(at_lvl).size(); i++) {
343 auto xi = x.nonlocal(at_lvl)[i];
344 auto yi = y.nonlocal(at_lvl)[i];
345 x.nonlocal(at_lvl)[i] = xi * c + yi * s;
346 y.nonlocal(at_lvl)[i] = yi * c - xi * s;
351 return FunctionProperties<Hubbard_matrix>(global_size_func, inner_prod_func, scale_func, copy_func, axpy_func,
Representation of the periodical function on the muffin-tin geometry.
auto & rg()
Return reference to regular space grid component.
Contains declarations of functions required for mixing.
void copy(T *target__, T const *source__, size_t n__)
Copy memory inside a device.
FunctionProperties< Periodic_function< double > > periodic_function_property_modified(bool use_coarse_gvec__)
Only for the PP-PW case.
std::enable_if_t< std::is_same< T, real_type< F > >::value, void > inner(::spla::Context &spla_ctx__, sddk::memory_t mem__, spin_range spins__, W const &wf_i__, band_range br_i__, Wave_functions< T > const &wf_j__, band_range br_j__, la::dmatrix< F > &result__, int irow0__, int jcol0__)
Compute inner product between the two sets of wave-functions.
Namespace of the SIRIUS library.
auto conj(double x__)
Return complex conjugate of a number. For a real value this is the number itself.
Describes operations on a function type used for mixing.