SIRIUS 7.5.0
Electronic structure library and applications
make_periodic_function.hpp
Go to the documentation of this file.
1// Copyright (c) 2013-2023 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/** \file make_periodic_function.hpp
21 *
22 * \brief Generate plane-wave coefficients of the periodic function from the form-factors.
23 */
24
25#ifndef __MAKE_PERIODIC_FUNCTION_HPP__
26#define __MAKE_PERIODIC_FUNCTION_HPP__
27
28namespace sirius {
29
30/// Make periodic function out of form factors.
31/** Return vector of plane-wave coefficients */
32template <index_domain_t index_domain, typename F>
33inline auto
35 sddk::mdarray<std::complex<double>, 2> const& phase_factors_t__, F&& form_factors__)
36{
37 PROFILE("sirius::make_periodic_function");
38
39 const double fourpi_omega = fourpi / uc__.omega();
40
41 auto const ngv = (index_domain == index_domain_t::local) ? gv__.count() : gv__.num_gvec();
43 f_pw.zero();
44
45 #pragma omp parallel for schedule(static)
46 for (int igloc = 0; igloc < gv__.count(); igloc++) {
47 /* global index of G-vector */
48 const int ig = gv__.offset() + igloc;
49 const double g = gv__.gvec_len<index_domain_t::local>(igloc);
50
51 auto const j = (index_domain == index_domain_t::local) ? igloc : ig;
52 for (int iat = 0; iat < uc__.num_atom_types(); iat++) {
53 f_pw[j] += fourpi_omega * std::conj(phase_factors_t__(igloc, iat)) * form_factors__(iat, g);
54 }
55 }
56
57 if (index_domain == index_domain_t::global) {
58 gv__.comm().allgather(&f_pw[0], gv__.count(), gv__.offset());
59 }
60
61 return f_pw;
62}
63
64/// Make periodic out of form factors computed for G-shells.
65template <index_domain_t index_domain>
66inline auto
68 sddk::mdarray<std::complex<double>, 2> const& phase_factors_t__,
69 sddk::mdarray<double, 2> const& form_factors__)
70{
71 PROFILE("sirius::make_periodic_function");
72
73 const double fourpi_omega = fourpi / uc__.omega();
74
75 auto const ngv = (index_domain == index_domain_t::local) ? gv__.count() : gv__.num_gvec();
77 f_pw.zero();
78
79 #pragma omp parallel for schedule(static)
80 for (int igloc = 0; igloc < gv__.count(); igloc++) {
81 /* global index of G-vector */
82 const int ig = gv__.offset() + igloc;
83 const int igsh = gv__.shell(ig);
84
85 auto const j = (index_domain == index_domain_t::local) ? igloc : ig;
86 for (int iat = 0; iat < uc__.num_atom_types(); iat++) {
87 f_pw[j] += fourpi_omega * std::conj(phase_factors_t__(igloc, iat)) * form_factors__(igsh, iat);
88 }
89 }
90
91 if (index_domain == index_domain_t::global) {
92 gv__.comm().allgather(&f_pw[0], gv__.count(), gv__.offset());
93 }
94
95 return f_pw;
96}
97
98}
99
100#endif
Representation of a unit cell.
Definition: unit_cell.hpp:43
double omega() const
Unit cell volume.
Definition: unit_cell.hpp:275
int num_atom_types() const
Number of atom types.
Definition: unit_cell.hpp:281
A set of G-vectors for FFTs and G+k basis functions.
Definition: gvec.hpp:130
double gvec_len(int ig__) const
Return length of the G-vector.
Definition: gvec.hpp:637
int num_gvec() const
Return the total number of G-vectors within the cutoff.
Definition: gvec.hpp:478
int offset() const
Offset (in the global index) of G-vectors for a fine-grained distribution for a current MPI rank.
Definition: gvec.hpp:520
int count() const
Number of G-vectors for a fine-grained distribution for the current MPI rank.
Definition: gvec.hpp:506
int shell(int ig__) const
Return index of the G-vector shell by the G-vector index.
Definition: gvec.hpp:608
void allgather(T *buffer__, int const *recvcounts__, int const *displs__) const
In-place MPI_Allgatherv.
Multidimensional array with the column-major (Fortran) order.
Definition: memory.hpp:660
void zero(memory_t mem__, size_t idx0__, size_t n__)
Zero n elements starting from idx0.
Definition: memory.hpp:1316
Namespace of the SIRIUS library.
Definition: sirius.f90:5
auto make_periodic_function(Unit_cell const &uc__, fft::Gvec const &gv__, sddk::mdarray< std::complex< double >, 2 > const &phase_factors_t__, F &&form_factors__)
Make periodic function out of form factors.
@ global
Global index.
const double fourpi
Definition: constants.hpp:48
auto conj(double x__)
Return complex conjugate of a number. For a real value this is the number itself.
Definition: math_tools.hpp:165