TRIQS/triqs_modest 3.3.0
Modular Electronic Structure Toolkit
Loading...
Searching...
No Matches
local_space.hpp
Go to the documentation of this file.
1// Copyright (c) 2025--present, The Simons Foundation
2// This file is part of TRIQS/modest and is licensed under the terms of GPLv3 or later.
3// SPDX-License-Identifier: GPL-3.0-or-later
4// See LICENSE in the root of this distribution for details.
5
6#pragma once
7#include <triqs/gfs.hpp>
8#include <triqs/utility/macros.hpp>
9#include <mpi/mpi.hpp>
10#include "./utils/defs.hpp"
11#include "./utils/gf_supp.hpp"
12
13namespace triqs::modest {
14
15 using namespace triqs::gfs;
16
17 // -----------------------------------------------
19 enum class spin_kind_e {
20 Polarized, // σ = 0,1, the object can have different value for different σ
21 NonPolarized, // σ = 0,1, but the object is the same for both σ. Can store only one copy e.g.
22 NonColinear // σ = 0. There is no index, the spin index is grouped with other non-diagonal indices. e.g. Nambu, spin-orbit
23 };
24
27 switch (sk) {
28 case spin_kind_e::Polarized: return 2;
29 case spin_kind_e::NonPolarized: return 2;
30 case spin_kind_e::NonColinear: return 1;
31 }
32 __builtin_unreachable();
33 }
34
35 // --------------------------------------------------------------------
37 struct atomic_orbs {
38 long dim = 0;
39 long l = 0;
40 long cls_idx = 0;
41 long dft_idx = 0;
42 // int n_irrep; // are the orbitals reducible into irreps (irep) ( seach "irep" in TRIQS/dft_tools; never used in DMFT routines
43 void serialize(auto &ar) const { ar & dim & l & cls_idx & dft_idx; };
44 void deserialize(auto &ar) { ar & dim & l & cls_idx & dft_idx; };
45
47 bool operator==(atomic_orbs const &) const = default;
48
50 C2PY_IGNORE friend void mpi_broadcast(atomic_orbs &x, mpi::communicator c = {}, int root = 0) {
51 mpi::broadcast(x.dim, c, root);
52 mpi::broadcast(x.l, c, root);
53 mpi::broadcast(x.cls_idx, c, root);
54 mpi::broadcast(x.dft_idx, c, root);
55 }
56 };
57
58 // ==========================================================
87
89
90 // List of all atomic shells spanning the 𝓒 space
91 std::vector<atomic_orbs> _atomic_shells;
92
93 // For each atom, a list of the dimensions of the irreps decomposition of the atomic shell
94 nda::array<std::vector<long>, 2> _irreps_decomp_per_atom;
95
96 // rotation matrices that rotate BACK to the basis of the DFT code basis.
97 // FIXME : CHECK vs INVERSE, EXPLAIN, WRITE NOTE.
98 nda::array<nda::matrix<dcomplex>, 2> _rotation_from_dft_to_local_basis;
99
100 // rotation matrix from the Ylm basis to the dft code
101 nda::array<nda::matrix<dcomplex>, 1> _rotation_from_spherical_to_dft_basis;
102
103 // dimension of the correlated space
104 long _dim_C = 0;
105
106 // atom names
107 std::vector<std::string> _atom_names = {};
108
110 friend void h5_read(h5::group g, std::string const &name, local_space &ls);
111 friend void h5_write(h5::group g, std::string const &name, local_space const &ls);
112
114 C2PY_IGNORE friend void mpi_broadcast(local_space &x, mpi::communicator c = {}, int root = 0) {
115 mpi::broadcast(x._spin_kind, c, root);
116 mpi::broadcast(x._atomic_shells, c, root);
117 mpi::broadcast(x._irreps_decomp_per_atom, c, root);
118 mpi::broadcast(x._rotation_from_dft_to_local_basis, c, root);
119 mpi::broadcast(x._rotation_from_spherical_to_dft_basis, c, root);
120 mpi::broadcast(x._dim_C, c, root);
121 mpi::broadcast(x._atom_names, c, root);
122 }
123
124 public:
126 bool operator==(local_space const &) const = default;
127
137 local_space(spin_kind_e spin_kind, std::vector<atomic_orbs> atomic_shells, nda::array<std::vector<long>, 2> irreps_decomp_per_atom,
138 nda::array<nda::matrix<dcomplex>, 2> rotation_from_dft_to_local_basis,
139 nda::array<nda::matrix<dcomplex>, 1> rotation_from_spherical_to_dft_basis);
140
143 local_space() = default;
146 // ---------------- sigma indices and co. ----------------
148
149
151 [[nodiscard]] spin_kind_e spin_kind() const { return _spin_kind; };
152
154 [[nodiscard]] long n_sigma() const { return n_sigma_from_spin_kind(_spin_kind); }
155
157 [[nodiscard]] std::vector<std::string> sigma_names() const {
158 return (_spin_kind == spin_kind_e::NonColinear ? std::vector{"ud"s} : std::vector{"up"s, "down"s});
159 }
160
161 // -------- Atomic shells and related functions -----------
163 [[nodiscard]] long dim() const { return _dim_C; }
164
166 [[nodiscard]] std::vector<atomic_orbs> const &atomic_shells() const { return _atomic_shells; }
167
169 [[nodiscard]] long n_atoms() const { return long(_atomic_shells.size()); }
170
171 // OP : explain the 2 indices : spin ?? [ a, σ] ?
173 [[nodiscard]] nda::array<std::vector<long>, 2> const &atoms_block_decomposition() const { return _irreps_decomp_per_atom; }
174
176 [[nodiscard]] nda::array<nda::matrix<dcomplex>, 2> const &rotation_from_dft_to_local_basis() const { return _rotation_from_dft_to_local_basis; }
177
179 [[nodiscard]] nda::array<nda::matrix<dcomplex>, 1> const &rotation_from_spherical_to_dft_basis() const {
180 return _rotation_from_spherical_to_dft_basis;
181 }
182
184 [[nodiscard]] long first_shell_of_its_equiv_cls(long idx) const;
185
187 [[nodiscard]] std::vector<std::string> atom_names() const { return _atom_names; }
188
190 [[nodiscard]] auto atomic_decomposition() const {
191 return atomic_shells() | stdv::transform([](auto const &s) { return s.dim; });
192 }
193
195
196 // -------- Atomic "view" methods for Green functions and matrices -----------
197
198 // FIXME : IT IS NOT A VIEW, IT IS A COPY
199 // Where do we use this ? do we want a view or a copy ?
201
209 template <typename Mesh> block2_gf<Mesh> atomic_view(block2_gf<Mesh> const &G_C) {
210 // FIXME : ASSERT check the dimension of G_C m x m , one a block, n_sigma ...
211 auto Gout = make_block2_gf(G_C(0, 0).mesh(), this->Gatom_block_shape());
212 auto n_sigma = G_C.size2();
213 for (auto sigma : range(n_sigma))
214 for (auto const &[atom, r_atom] : enumerated_sub_slices(this->atomic_decomposition())) {
215 Gout(atom, sigma).data() = G_C(0, sigma).data()(r_all, r_atom, r_atom);
216 }
217 return Gout;
218 }
219
227 nda::array<nda::matrix<dcomplex>, 2> atomic_view(nda::array<nda::matrix<dcomplex>, 2> const &matrix_C);
228
229 // -------- gf_structs for different block shapes -----------
230
232 [[nodiscard]] C2PY_IGNORE gf_struct2_t Gc_block_shape() const;
233
234 // OP : [a, \sigma] : what is a, sigma ?
236 [[nodiscard]] C2PY_IGNORE gf_struct2_t Gatom_block_shape() const {
237 auto res = nda::zeros<long>(_atomic_shells.size(), n_sigma());
238 for (auto const &[alpha, shell] : enumerate(_atomic_shells)) res(alpha, r_all) = shell.dim;
239 return {.names = {atom_names(), sigma_names()}, .dims = std::move(res)};
240 }
241
243 };
244
245 // -------- stream -----------
246
247 std::ostream &operator<<(std::ostream &out, local_space const &bd);
248
249 // -------- instantiations --------------
250
252 template block2_gf<imfreq> local_space::atomic_view(block2_gf<imfreq> const &G_C);
255} // namespace triqs::modest
Describe the atomic orbitals within downfolded space.
spin_kind_e spin_kind() const
Spin kind of index.
friend void h5_write(h5::group g, std::string const &name, local_space const &ls)
Definition h5.cpp:88
nda::array< nda::matrix< dcomplex >, 1 > const & rotation_from_spherical_to_dft_basis() const
Array of rotation matrices from spherical harmonics to dft specific orbital basis.
block2_gf< Mesh > atomic_view(block2_gf< Mesh > const &G_C)
Views a 2-dim block GF according to the atomic decomposition.
long n_sigma() const
Dimension of the index.
nda::array< nda::matrix< dcomplex >, 2 > const & rotation_from_dft_to_local_basis() const
2-dim array of all local rotation matices that rotate the data.
std::vector< std::string > atom_names() const
Names of the atoms in the orbital set.
nda::array< std::vector< long >, 2 > const & atoms_block_decomposition() const
2-dim array of all blocks spanning space -> atoms_block_decomposition.
auto atomic_decomposition() const
Transformed view containing the dimension of each atomic shell.
long dim() const
Dimension of the correlated space.
friend void h5_read(h5::group g, std::string const &name, local_space &ls)
h5 read/write
Definition h5.cpp:81
bool operator==(local_space const &) const =default
Equality comparison operator.
std::vector< atomic_orbs > const & atomic_shells() const
List of all atomic shells spanning the space.
long n_atoms() const
The number of atoms.
std::vector< std::string > sigma_names() const
Names of spin indices for naming blocks in block GFs.
C2PY_IGNORE gf_struct2_t Gc_block_shape() const
Shape of the Green function in the correlated space, without block decomposition.
C2PY_IGNORE friend void mpi_broadcast(local_space &x, mpi::communicator c={}, int root=0)
MPI broadcast.
C2PY_IGNORE gf_struct2_t Gatom_block_shape() const
Shape of the Green function in the correlated space, decomposed by atomic shells.
long first_shell_of_its_equiv_cls(long idx) const
Given the index of an atomic shell, return the index of the first atomic shell of its equivalence cla...
block2_gf< Mesh, matrix_valued > make_block2_gf(Mesh const &mesh, gf_struct2_t const &gf_s)
Definition gf_supp.hpp:41
std::ostream & operator<<(std::ostream &out, one_body_elements_on_grid const &)
Definition printing.cpp:73
long n_sigma_from_spin_kind(spin_kind_e sk)
Number of σ channels for a given spin_kind_e.
spin_kind_e
Kind of σ index.
static constexpr auto r_all
Definition defs.hpp:33
generator< std::pair< long, nda::range > > enumerated_sub_slices(auto sub_div)
Info on an atomic shell.
bool operator==(atomic_orbs const &) const =default
Equality comparison operator.
long dft_idx
Index of the atom in the dft code if any, or .
long cls_idx
Equivalent atoms will have the same sort index (sort).
long l
Angular quantum number.
void serialize(auto &ar) const
C2PY_IGNORE friend void mpi_broadcast(atomic_orbs &x, mpi::communicator c={}, int root=0)
MPI broadcast.
long dim
Dimension of the orbital space.