SIRIUS 7.5.0
Electronic structure library and applications
generate_spinor_wave_functions.cpp
1// Copyright (c) 2013-2018 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 generate_spinor_wave_functions.hpp
21 *
22 * \brief Generate LAPW spinor wave functions from first-variational states.
23 */
24
25#include "k_point/k_point.hpp"
26
27namespace sirius {
28
29template <typename T>
31{
32 PROFILE("sirius::K_point::generate_spinor_wave_functions");
33
34 if (ctx_.cfg().control().use_second_variation()) {
35 int nfv = ctx_.num_fv_states();
36
37 if (!ctx_.need_sv()) {
38 /* copy eigen-states and exit */
39 wf::copy(sddk::memory_t::host, *fv_states_, wf::spin_index(0), wf::band_range(0, ctx_.num_fv_states()),
40 *spinor_wave_functions_ , wf::spin_index(0), wf::band_range(0, ctx_.num_fv_states()));
41 return;
42 }
43
44 int nbnd = (ctx_.num_mag_dims() == 3) ? ctx_.num_bands() : nfv;
45
46 if (ctx_.processing_unit() == sddk::device_t::GPU) {
47 //fv_states().allocate(sddk::spin_range(0), get_memory_pool(sddk::memory_t::device));
48 ////fv_states().copy_to(sddk::spin_range(0), sddk::memory_t::device, 0, nfv);
49 sv_eigen_vectors_[0].allocate(get_memory_pool(sddk::memory_t::device)).copy_to(sddk::memory_t::device);
50 if (ctx_.num_mag_dims() == 1) {
51 sv_eigen_vectors_[1].allocate(get_memory_pool(sddk::memory_t::device)).copy_to(sddk::memory_t::device);
52 }
53 //if (is_device_memory(ctx_.preferred_memory_t())) {
54 // for (int ispn = 0; ispn < ctx_.num_spins(); ispn++) {
55 // spinor_wave_functions().allocate(sddk::spin_range(ispn), get_memory_pool(sddk::memory_t::device));
56 // spinor_wave_functions().copy_to(sddk::spin_range(ispn), sddk::memory_t::device, 0, nbnd);
57 // }
58 //}
59 }
60
61 for (int ispn = 0; ispn < ctx_.num_spins(); ispn++) {
62 int s, o;
63
64 if (ctx_.num_mag_dims() == 3) {
65 /* in case of non-collinear magnetism sv_eigen_vectors is a single 2Nx2N matrix */
66 s = 0;
67 o = ispn * nfv; /* offset for spin up is 0, for spin dn is nfv */
68 } else {
69 /* sv_eigen_vectors is composed of two NxN matrices */
70 s = ispn;
71 o = 0;
72 }
73 /* multiply consecutively up and dn blocks */
74 wf::transform(ctx_.spla_context(), sddk::memory_t::host, sv_eigen_vectors_[s], o, 0, 1.0, *fv_states_,
75 wf::spin_index(0), wf::band_range(0, nfv), 0.0, *spinor_wave_functions_, wf::spin_index(ispn),
76 wf::band_range(0, nbnd));
77 }
78
79 if (ctx_.processing_unit() == sddk::device_t::GPU) {
80 sv_eigen_vectors_[0].deallocate(sddk::memory_t::device);
81 if (ctx_.num_mag_dims() == 3) {
82 sv_eigen_vectors_[1].deallocate(sddk::memory_t::device);
83 }
84 }
85 } else {
86 RTE_THROW("not implemented");
87 }
88}
89
91#ifdef SIRIUS_USE_FP32
93#endif
94
95} // namespace sirius
void generate_spinor_wave_functions()
Generate two-component spinor wave functions.
Describe a range of bands.
Contains definition of sirius::K_point class.
std::enable_if_t< std::is_same< T, real_type< F > >::value, void > transform(::spla::Context &spla_ctx__, sddk::memory_t mem__, la::dmatrix< F > const &M__, int irow0__, int jcol0__, real_type< F > alpha__, Wave_functions< T > const &wf_in__, spin_index s_in__, band_range br_in__, real_type< F > beta__, Wave_functions< T > &wf_out__, spin_index s_out__, band_range br_out__)
Apply linear transformation to the wave-functions.
void copy(sddk::memory_t mem__, Wave_functions< T > const &in__, wf::spin_index s_in__, wf::band_range br_in__, Wave_functions< F > &out__, wf::spin_index s_out__, wf::band_range br_out__)
Copy wave-functions.
Namespace of the SIRIUS library.
Definition: sirius.f90:5