SIRIUS 7.5.0
Electronic structure library and applications
apply_hamiltonian.hpp
Go to the documentation of this file.
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/** \file apply_hamiltonian.hpp
21 *
22 * \brief Helper function for nlcglib.
23 */
24
25#ifndef __APPLY_HAMILTONIAN_HPP__
26#define __APPLY_HAMILTONIAN_HPP__
27
30#include "density/density.hpp"
32#include <memory>
33#include <complex>
34
35namespace sirius {
36
37inline void
38apply_hamiltonian(Hamiltonian0<double>& H0, K_point<double>& kp, wf::Wave_functions<double>& wf_out,
39 wf::Wave_functions<double>& wf, std::shared_ptr<wf::Wave_functions<double>> swf)
40{
41 /////////////////////////////////////////////////////////////
42 // // TODO: Hubbard needs manual call to copy to device // //
43 /////////////////////////////////////////////////////////////
44
45 int num_wf = wf.num_wf();
46 int num_sc = wf.num_sc();
47 if (num_wf != wf_out.num_wf() || wf_out.num_sc() != num_sc) {
48 RTE_THROW("num_sc or num_wf do not match");
49 }
50 auto H = H0(kp);
51 auto& ctx = H0.ctx();
52
53 /* apply H to all wave functions */
54 int N = 0;
55 int n = num_wf;
56 for (int ispn_step = 0; ispn_step < ctx.num_spinors(); ispn_step++) {
57 // sping_range: 2 for non-collinear magnetism, otherwise ispn_step
58 auto spin_range = wf::spin_range((ctx.num_mag_dims() == 3) ? 2 : ispn_step);
59 H.apply_h_s<std::complex<double>>(spin_range, wf::band_range(N, n), wf, &wf_out, swf.get());
60 }
61}
62
63} // namespace sirius
64
65#endif /* __APPLY_HAMILTONIAN_HPP__ */
Contains definition and partial implementation of sirius::Density class.
Contains declaration and definition of sirius::Hamiltonian class.
Namespace of the SIRIUS library.
Definition: sirius.f90:5
Contains declaration and partial implementation of sirius::Potential class.
Contains declaration and implementation of Wave_functions class.