SIRIUS 7.5.0
Electronic structure library and applications
hubbard_matrix.hpp
Go to the documentation of this file.
1// Copyright (c) 2013-2021 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 hubbard_matrix.hpp
21 *
22 * \brief Base class for Hubbard occupancy and potential matrices.
23 */
24
25#ifndef __HUBBARD_MATRIX_HPP__
26#define __HUBBARD_MATRIX_HPP__
27
29
30namespace sirius {
31
32/// Describes Hubbard orbital occupancy or potential correction matrices.
34{
35 protected:
37 /// Local part of Hubbard matrix
38 std::vector<sddk::mdarray<std::complex<double>, 3>> local_;
39 /// Non-local part of Hubbard matrix.
40 std::vector<sddk::mdarray<std::complex<double>, 3>> nonlocal_;
41 std::vector<std::pair<int, int>> atomic_orbitals_;
42 std::vector<int> offset_;
43
44 public:
46
47 /// Retrieve or set elements of the Hubbard matrix.
48 /** This functions helps retrieving or setting up the hubbard occupancy
49 * tensors from an external tensor. Retrieving it is done by specifying
50 * "get" in the first argument of the method while setting it is done
51 * with the parameter set up to "set". The second parameter is the
52 * output pointer and the last parameter is the leading dimension of the
53 * tensor.
54 *
55 * The returned result has the same layout than SIRIUS layout, * i.e.,
56 * the harmonic orbitals are stored from m_z = -l..l. The occupancy
57 * matrix can also be accessed through the method occupation_matrix()
58 *
59 * \param [in] what String to set to "set" for initializing sirius ccupancy tensor and "get" for retrieving it.
60 * \param [inout] occ Pointer to external occupancy tensor.
61 * \param [in] ld Leading dimension of the outside tensor.
62 * \return return the occupancy matrix if the first parameter is set to "get". */
63 void access(std::string const& what__, std::complex<double>* ptr__, int ld__);
64
65 void print_local(int ia__, std::ostream& out__) const;
66
67 void print_nonlocal(int idx__, std::ostream& out__) const;
68
69 void zero();
70
71 /// Return a vector containing the occupation numbers for each atomic orbital.
72 auto& local() const
73 {
74 return local_;
75 }
76
77 auto& local(int ia__)
78 {
79 return local_[ia__];
80 }
81
82 auto const& local(int ia__) const
83 {
84 return local_[ia__];
85 }
86
87 auto& nonlocal() const
88 {
89 return nonlocal_;
90 }
91
92 auto& nonlocal(int idx__)
93 {
94 return nonlocal_[idx__];
95 }
96
97 auto const& nonlocal(int idx__) const
98 {
99 return nonlocal_[idx__];
100 }
101
102 const auto& atomic_orbitals() const
103 {
104 return atomic_orbitals_;
105 }
106
107 const auto& atomic_orbitals(const int idx__) const
108 {
109 return atomic_orbitals_[idx__];
110 }
111
112 int offset(const int idx__) const
113 {
114 return offset_[idx__];
115 }
116
117 const auto& offset() const
118 {
119 return offset_;
120 }
121
122 auto const& ctx() const
123 {
124 return ctx_;
125 }
126
127 int find_orbital_index(const int ia__, const int n__, const int l__) const
128 {
129 int at_lvl = 0;
130 for (at_lvl = 0; at_lvl < static_cast<int>(atomic_orbitals_.size()); at_lvl++) {
131 int lo_ind = atomic_orbitals_[at_lvl].second;
132 int atom_id = atomic_orbitals_[at_lvl].first;
133
134 if ((atomic_orbitals_[at_lvl].first == ia__) &&
135 (ctx_.unit_cell().atom(atom_id).type().lo_descriptor_hub(lo_ind).n() == n__) &&
136 (ctx_.unit_cell().atom(atom_id).type().lo_descriptor_hub(lo_ind).l() == l__))
137 break;
138 }
139
140 if (at_lvl == static_cast<int>(atomic_orbitals_.size())) {
141 std::cout << "atom: " << ia__ << "n: " << n__ << ", l: " << l__ << std::endl;
142 RTE_THROW("Found an arbital that is not listed\n");
143 }
144 return at_lvl;
145 }
146};
147
148inline void
149copy(Hubbard_matrix const& src__, Hubbard_matrix& dest__)
150{
151 for (int at_lvl = 0; at_lvl < static_cast<int>(src__.atomic_orbitals().size()); at_lvl++) {
152 sddk::copy(src__.local(at_lvl), dest__.local(at_lvl));
153 }
154 for (int i = 0; i < static_cast<int>(src__.ctx().cfg().hubbard().nonlocal().size()); i++) {
155 sddk::copy(src__.nonlocal(i), dest__.nonlocal(i));
156 }
157}
158
159} // namespace sirius
160
161#endif
Describes Hubbard orbital occupancy or potential correction matrices.
std::vector< sddk::mdarray< std::complex< double >, 3 > > local_
Local part of Hubbard matrix.
void access(std::string const &what__, std::complex< double > *ptr__, int ld__)
Retrieve or set elements of the Hubbard matrix.
std::vector< sddk::mdarray< std::complex< double >, 3 > > nonlocal_
Non-local part of Hubbard matrix.
auto & local() const
Return a vector containing the occupation numbers for each atomic orbital.
Simulation context is a set of parameters and objects describing a single simulation.
void copy(T *target__, T const *source__, size_t n__)
Copy memory inside a device.
Definition: acc.hpp:320
Namespace of the SIRIUS library.
Definition: sirius.f90:5
Contains definition and implementation of Simulation_context class.