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
25 // --------------------------------------------------------------------
27 struct atomic_orbs {
28 long dim = 0;
29 long l = 0;
30 long cls_idx = 0;
31 long dft_idx = 0;
32 // int n_irrep; // are the orbitals reducible into irreps (irep) ( seach "irep" in TRIQS/dft_tools; never used in DMFT routines
33 void serialize(auto &ar) const { ar & dim & l & cls_idx & dft_idx; };
34 void deserialize(auto &ar) { ar & dim & l & cls_idx & dft_idx; };
35
37 bool operator==(atomic_orbs const &) const = default;
38
40 C2PY_IGNORE friend void mpi_broadcast(atomic_orbs &x, mpi::communicator c = {}, int root = 0) {
41 mpi::broadcast(x.dim, c, root);
42 mpi::broadcast(x.l, c, root);
43 mpi::broadcast(x.cls_idx, c, root);
44 mpi::broadcast(x.dft_idx, c, root);
45 }
46 };
47
48 // ==========================================================
77
79
80 // List of all atomic shells spanning the 𝓒 space
81 std::vector<atomic_orbs> _atomic_shells;
82
83 // For each atom, a list of the dimensions of the irreps decomposition of the atomic shell
84 nda::array<std::vector<long>, 2> _irreps_decomp_per_atom;
85
86 // rotation matrices that rotate BACK to the basis of the DFT code basis.
87 // FIXME : CHECK vs INVERSE, EXPLAIN, WRITE NOTE.
88 nda::array<nda::matrix<dcomplex>, 2> _rotation_from_dft_to_local_basis;
89
90 // rotation matrix from the Ylm basis to the dft code
91 nda::array<nda::matrix<dcomplex>, 1> _rotation_from_spherical_to_dft_basis;
92
93 // dimension of the correlated space
94 long _dim_C = 0;
95
96 // atom names
97 std::vector<std::string> _atom_names = {};
98
100 friend void h5_read(h5::group g, std::string const &name, local_space &ls);
101 friend void h5_write(h5::group g, std::string const &name, local_space const &ls);
102
104 C2PY_IGNORE friend void mpi_broadcast(local_space &x, mpi::communicator c = {}, int root = 0) {
105 mpi::broadcast(x._spin_kind, c, root);
106 mpi::broadcast(x._atomic_shells, c, root);
107 mpi::broadcast(x._irreps_decomp_per_atom, c, root);
108 mpi::broadcast(x._rotation_from_dft_to_local_basis, c, root);
109 mpi::broadcast(x._rotation_from_spherical_to_dft_basis, c, root);
110 mpi::broadcast(x._dim_C, c, root);
111 mpi::broadcast(x._atom_names, c, root);
112 }
113
114 public:
116 bool operator==(local_space const &) const = default;
117
127 local_space(spin_kind_e spin_kind, std::vector<atomic_orbs> atomic_shells, nda::array<std::vector<long>, 2> irreps_decomp_per_atom,
128 nda::array<nda::matrix<dcomplex>, 2> rotation_from_dft_to_local_basis,
129 nda::array<nda::matrix<dcomplex>, 1> rotation_from_spherical_to_dft_basis);
130
133 local_space() = default;
136 // ---------------- sigma indices and co. ----------------
138
139
141 [[nodiscard]] spin_kind_e spin_kind() const { return _spin_kind; };
142
144 [[nodiscard]] long n_sigma() const { return _spin_kind == spin_kind_e::NonColinear ? 1 : 2; }
145
147 [[nodiscard]] std::vector<std::string> sigma_names() const {
148 return (_spin_kind == spin_kind_e::NonColinear ? std::vector{"ud"s} : std::vector{"up"s, "down"s});
149 }
150
151 // -------- Atomic shells and related functions -----------
153 [[nodiscard]] long dim() const { return _dim_C; }
154
156 [[nodiscard]] std::vector<atomic_orbs> const &atomic_shells() const { return _atomic_shells; }
157
159 [[nodiscard]] long n_atoms() const { return long(_atomic_shells.size()); }
160
161 // OP : explain the 2 indices : spin ?? [ a, σ] ?
163 [[nodiscard]] nda::array<std::vector<long>, 2> const &atoms_block_decomposition() const { return _irreps_decomp_per_atom; }
164
166 [[nodiscard]] nda::array<nda::matrix<dcomplex>, 2> const &rotation_from_dft_to_local_basis() const { return _rotation_from_dft_to_local_basis; }
167
169 [[nodiscard]] nda::array<nda::matrix<dcomplex>, 1> const &rotation_from_spherical_to_dft_basis() const {
170 return _rotation_from_spherical_to_dft_basis;
171 }
172
174 [[nodiscard]] long first_shell_of_its_equiv_cls(long idx) const;
175
177 [[nodiscard]] std::vector<std::string> atom_names() const { return _atom_names; }
178
180 [[nodiscard]] auto atomic_decomposition() const {
181 return atomic_shells() | stdv::transform([](auto const &s) { return s.dim; });
182 }
183
185
186 // -------- Atomic "view" methods for Green functions and matrices -----------
187
188 // FIXME : IT IS NOT A VIEW, IT IS A COPY
189 // Where do we use this ? do we want a view or a copy ?
191
199 template <typename Mesh> block2_gf<Mesh> atomic_view(block2_gf<Mesh> const &G_C) {
200 // FIXME : ASSERT check the dimension of G_C m x m , one a block, n_sigma ...
201 auto Gout = make_block2_gf(G_C(0, 0).mesh(), this->Gatom_block_shape());
202 auto n_sigma = G_C.size2();
203 for (auto sigma : range(n_sigma))
204 for (auto const &[atom, r_atom] : enumerated_sub_slices(this->atomic_decomposition())) {
205 Gout(atom, sigma).data() = G_C(0, sigma).data()(r_all, r_atom, r_atom);
206 }
207 return Gout;
208 }
209
217 nda::array<nda::matrix<dcomplex>, 2> atomic_view(nda::array<nda::matrix<dcomplex>, 2> const &matrix_C);
218
219 // -------- gf_structs for different block shapes -----------
220
222 [[nodiscard]] C2PY_IGNORE gf_struct2_t Gc_block_shape() const;
223
224 // OP : [a, \sigma] : what is a, sigma ?
227 auto res = nda::zeros<long>(_atomic_shells.size(), n_sigma());
228 for (auto const &[alpha, shell] : enumerate(_atomic_shells)) res(alpha, r_all) = shell.dim;
229 return {.names = {atom_names(), sigma_names()}, .dims = std::move(res)};
230 }
231
233 };
234
235 // -------- stream -----------
236
237 std::ostream &operator<<(std::ostream &out, local_space const &bd);
238
239 // -------- instantiations --------------
240
242 template block2_gf<imfreq> local_space::atomic_view(block2_gf<imfreq> const &G_C);
245} // 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...
#define C2PY_IGNORE
Definition defs.hpp:17
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
spin_kind_e
Kind of σ index.
static constexpr auto r_all
Definition defs.hpp:40
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.