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 "./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;
27 long l = 0;
28 long cls_idx = 0;
29 long dft_idx = 0;
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 // ==========================================================
62
64
65 // List of all atomic shells spanning the 𝓒 space
66 std::vector<atomic_orbs> _atomic_shells;
67
68 // For each atom, a list of the dimensions of the irreps decomposition of the atomic shell
69 nda::array<std::vector<long>, 2> _irreps_decomp_per_atom;
70
71 // rotation matrices that rotate BACK to the basis of the DFT code basis.
72 // FIXME : CHECK vs INVERSE, EXPLAIN, WRITE NOTE.
73 nda::array<nda::matrix<dcomplex>, 2> _rotation_from_dft_to_local_basis;
74
75 // rotation matrix from the Ylm basis to the dft code
76 nda::array<nda::matrix<dcomplex>, 1> _rotation_from_spherical_to_dft_basis;
77
78 // dimension of the correlated space
79 long _dim_C = 0;
80
81 // atom names
82 std::vector<std::string> _atom_names = {};
83
85 friend void h5_read(h5::group g, std::string const &name, local_space &ls);
86 friend void h5_write(h5::group g, std::string const &name, local_space const &ls);
87
88 public:
98 local_space(spin_kind_e spin_kind, std::vector<atomic_orbs> atomic_shells, nda::array<std::vector<long>, 2> irreps_decomp_per_atom,
99 nda::array<nda::matrix<dcomplex>, 2> rotation_from_dft_to_local_basis,
100 nda::array<nda::matrix<dcomplex>, 1> rotation_from_spherical_to_dft_basis);
101
104 local_space() = default;
107 // ---------------- sigma indices and co. ----------------
109
110
112 [[nodiscard]] spin_kind_e spin_kind() const { return _spin_kind; };
113
115 [[nodiscard]] long n_sigma() const { return _spin_kind == spin_kind_e::NonColinear ? 1 : 2; }
116
118 [[nodiscard]] std::vector<std::string> sigma_names() const {
119 return (_spin_kind == spin_kind_e::NonColinear ? std::vector{"ud"s} : std::vector{"up"s, "down"s});
120 }
121
122 // -------- Atomic shells and related functions -----------
124 [[nodiscard]] long dim() const { return _dim_C; }
125
127 [[nodiscard]] std::vector<atomic_orbs> const &atomic_shells() const { return _atomic_shells; }
128
130 [[nodiscard]] long n_atoms() const { return long(_atomic_shells.size()); }
131
132 // OP : explain the 2 indices : spin ?? [ a, σ] ?
134 [[nodiscard]] nda::array<std::vector<long>, 2> const &atoms_block_decomposition() const { return _irreps_decomp_per_atom; }
135
137 [[nodiscard]] nda::array<nda::matrix<dcomplex>, 2> const &rotation_from_dft_to_local_basis() const { return _rotation_from_dft_to_local_basis; }
138
140 [[nodiscard]] nda::array<nda::matrix<dcomplex>, 1> const &rotation_from_spherical_to_dft_basis() const {
141 return _rotation_from_spherical_to_dft_basis;
142 }
143
145 [[nodiscard]] long first_shell_of_its_equiv_cls(long idx) const;
146
148 [[nodiscard]] std::vector<std::string> atom_names() const { return _atom_names; }
149
151 [[nodiscard]] auto atomic_decomposition() const {
152 return atomic_shells() | stdv::transform([](auto const &s) { return s.dim; });
153 }
154
156
157 // -------- Atomic "view" methods for Green functions and matrices -----------
158
159 // FIXME : IT IS NOT A VIEW, IT IS A COPY
160 // Where do we use this ? do we want a view or a copy ?
162
170 template <typename Mesh> block2_gf<Mesh> atomic_view(block2_gf<Mesh> const &G_C) {
171 // FIXME : ASSERT check the dimension of G_C m x m , one a block, n_sigma ...
172 auto Gout = make_block2_gf(G_C(0, 0).mesh(), this->Gatom_block_shape());
173 auto n_sigma = G_C.size2();
174 for (auto sigma : range(n_sigma))
175 for (auto const &[atom, r_atom] : enumerated_sub_slices(this->atomic_decomposition())) {
176 Gout(atom, sigma).data() = G_C(0, sigma).data()(r_all, r_atom, r_atom);
177 }
178 return Gout;
179 }
180
188 nda::array<nda::matrix<dcomplex>, 2> atomic_view(nda::array<nda::matrix<dcomplex>, 2> const &matrix_C);
189
190 // -------- gf_structs for different block shapes -----------
191
193 [[nodiscard]] C2PY_IGNORE gf_struct2_t Gc_block_shape() const;
194
195 // OP : [a, \sigma] : what is a, sigma ?
198 auto res = nda::zeros<long>(_atomic_shells.size(), n_sigma());
199 for (auto const &[alpha, shell] : enumerate(_atomic_shells)) res(alpha, r_all) = shell.dim;
200 return {.names = {atom_names(), sigma_names()}, .dims = std::move(res)};
201 }
202
204 };
205
206 // -------- stream -----------
207
208 std::ostream &operator<<(std::ostream &out, local_space const &bd);
209
210 // -------- instantiations --------------
211
213 template block2_gf<imfreq> local_space::atomic_view(block2_gf<imfreq> const &G_C);
216} // 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
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 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.
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.
long dim
Dimension of the orbital space.