TRIQS/triqs_modest 3.3.0
Brillouin zone summation
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 "./utils/defs.hpp"
9#include "./utils/gf_supp.hpp"
10
11namespace triqs::modest {
12
13 using namespace triqs::gfs;
14
15 // -----------------------------------------------
17 enum class spin_kind_e {
18 Polarized, // σ = 0,1, the object can have different value for different σ
19 NonPolarized, // σ = 0,1, but the object is the same for both σ. Can store only one copy e.g.
20 NonColinear // σ = 0. There is no index, the spin index is grouped with other non-diagonal indices. e.g. Nambu, spin-orbit
21 };
22
23 // --------------------------------------------------------------------
25 struct atomic_orbs {
26 long dim = 0; // dimension of orbital space
27 long l = 0; // angular quantum number
28 long cls_idx = 0; // Equivalent atoms will have the same sort index (sort)
29 long dft_idx = 0; // idx of the atom in the dft code if any, or -1
30 // int n_irrep; // are the orbitals reducible into irreps (irep) ( seach "irep" in TRIQS/dft_tools; never used in DMFT routines
31 };
32
33 // ==========================================================
40
42
44 std::vector<atomic_orbs> _atomic_shells;
45
47 nda::array<std::vector<long>, 2> _irreps_decomp_per_atom;
48
50 // FIXME : CHECK vs INVERSE, EXPLAIN, WRITE NOTE.
51 nda::array<nda::matrix<dcomplex>, 2> _rotation_from_dft_to_local_basis;
52
54 nda::array<nda::matrix<dcomplex>, 1> _rotation_from_spherical_to_dft_basis;
55
57 long _dim_C = 0;
58
60 std::vector<std::string> _atom_names = {};
61
63 friend void h5_read(h5::group g, std::string const &name, local_space &ls);
64 friend void h5_write(h5::group g, std::string const &name, local_space const &ls);
65
66 public:
67 local_space(spin_kind_e spin_kind, std::vector<atomic_orbs> atomic_shells, nda::array<std::vector<long>, 2> irreps_decomp_per_atom,
68 nda::array<nda::matrix<dcomplex>, 2> rotation_from_dft_to_local_basis,
69 nda::array<nda::matrix<dcomplex>, 1> rotation_from_spherical_to_dft_basis);
70
73 local_space() = default;
76 // ---------------- sigma indices and co. ----------------
78
80 [[nodiscard]] spin_kind_e spin_kind() const { return _spin_kind; };
81
83 [[nodiscard]] long n_sigma() const { return _spin_kind == spin_kind_e::NonColinear ? 1 : 2; }
84
86 [[nodiscard]] std::vector<std::string> sigma_names() const {
87 return (_spin_kind == spin_kind_e::NonColinear ? std::vector{"ud"s} : std::vector{"up"s, "down"s});
88 }
89
90 // -------- Atomic shells and related functions -----------
92 [[nodiscard]] long dim() const { return _dim_C; }
93
95 [[nodiscard]] std::vector<atomic_orbs> const &atomic_shells() const { return _atomic_shells; }
96
98 [[nodiscard]] long n_atoms() const { return long(_atomic_shells.size()); }
99
101 // OP : explain the 2 indices : spin ?? [ a, σ] ?
102 [[nodiscard]] nda::array<std::vector<long>, 2> const &atoms_block_decomposition() const { return _irreps_decomp_per_atom; }
103
105 [[nodiscard]] nda::array<nda::matrix<dcomplex>, 2> const &rotation_from_dft_to_local_basis() const { return _rotation_from_dft_to_local_basis; }
106
108 [[nodiscard]] nda::array<nda::matrix<dcomplex>, 1> const &rotation_from_spherical_to_dft_basis() const {
109 return _rotation_from_spherical_to_dft_basis;
110 }
111
113 [[nodiscard]] long first_shell_of_its_equiv_cls(long idx) const;
114
116 [[nodiscard]] std::vector<std::string> atom_names() const { return _atom_names; }
117
119 [[nodiscard]] auto atomic_decomposition() const {
120 return atomic_shells() | stdv::transform([](auto const &s) { return s.dim; });
121 }
123
124 // -------- Atomic "view" methods for Green functions and matrices -----------
125
126 // FIXME : IT IS NOT A VIEW, IT IS A COPY
127 // Where do we use this ? do we want a view or a copy ?
129
137 template <typename Mesh> block2_gf<Mesh> atomic_view(block2_gf<Mesh> const &G_C) {
138 // FIXME : ASSERT check the dimension of G_C m x m , one a block, n_sigma ...
139 auto Gout = make_block2_gf(G_C(0, 0).mesh(), this->Gatom_block_shape());
140 auto n_sigma = G_C.size2();
141 for (auto sigma : range(n_sigma))
142 for (auto const &[atom, r_atom] : enumerated_sub_slices(this->atomic_decomposition())) {
143 Gout(atom, sigma).data() = G_C(0, sigma).data()(r_all, r_atom, r_atom);
144 }
145 return Gout;
146 }
147
156 nda::array<nda::matrix<dcomplex>, 2> atomic_view(nda::array<nda::matrix<dcomplex>, 2> const &matrix_C);
157
158 // -------- gf_structs for different block shapes -----------
159
161 [[nodiscard]] C2PY_IGNORE gf_struct2_t Gc_block_shape() const;
162
164 // OP : [a, \sigma] : what is a, sigma ?
166 auto res = nda::zeros<long>(_atomic_shells.size(), n_sigma());
167 for (auto const &[alpha, shell] : enumerate(_atomic_shells)) res(alpha, r_all) = shell.dim;
168 return {.names = {atom_names(), sigma_names()}, .dims = std::move(res)};
169 }
171 };
172
173 // -------- stream -----------
174
175 std::ostream &operator<<(std::ostream &out, local_space const &bd);
176
177 // -------- instantiations --------------
178
180 template block2_gf<imfreq> local_space::atomic_view(block2_gf<imfreq> const &G_C);
183} // namespace triqs::modest
Describe the atomic orbitals within downfolded space.
spin_kind_e spin_kind() const
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
List of rotation matrices from spherical harmonics to dft specific orbital basis.
block2_gf< Mesh > atomic_view(block2_gf< Mesh > const &G_C)
Views a block2gf 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
List of all (a, sigma) 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
List of all blocks spanning 𝓒 space -> atoms_block_decomposition.
auto atomic_decomposition() const
Generates [dimension of the 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
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_gf
C2PY_IGNORE gf_struct2_t Gc_block_shape() const
Shape of the Green function in the correlated space, without block decomposition.
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 idx of an atomic shell, return the index of the first atomic shell of its equivalence...
#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.