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 <mpi/mpi.hpp>
9#include "./utils/defs.hpp"
10#include "./utils/gf_supp.hpp"
11
12namespace triqs::modest {
13
14 using namespace triqs::gfs;
15
16 // -----------------------------------------------
18 enum class spin_kind_e {
19 Polarized, // σ = 0,1, the object can have different value for different σ
20 NonPolarized, // σ = 0,1, but the object is the same for both σ. Can store only one copy e.g.
21 NonColinear // σ = 0. There is no index, the spin index is grouped with other non-diagonal indices. e.g. Nambu, spin-orbit
22 };
23
24 // --------------------------------------------------------------------
26 struct atomic_orbs {
27 long dim = 0;
28 long l = 0;
29 long cls_idx = 0;
30 long dft_idx = 0;
31 // int n_irrep; // are the orbitals reducible into irreps (irep) ( seach "irep" in TRIQS/dft_tools; never used in DMFT routines
32 void serialize(auto &ar) const { ar & dim & l & cls_idx & dft_idx; };
33 void deserialize(auto &ar) { ar & dim & l & cls_idx & dft_idx; };
34
36 bool operator==(atomic_orbs const &) const = default;
37
39 friend void mpi_broadcast(atomic_orbs &x, mpi::communicator c = {}, int root = 0) {
40 mpi::broadcast(x.dim, c, root);
41 mpi::broadcast(x.l, c, root);
42 mpi::broadcast(x.cls_idx, c, root);
43 mpi::broadcast(x.dft_idx, c, root);
44 }
45 };
46
47 // ==========================================================
76
78
79 // List of all atomic shells spanning the 𝓒 space
80 std::vector<atomic_orbs> _atomic_shells;
81
82 // For each atom, a list of the dimensions of the irreps decomposition of the atomic shell
83 nda::array<std::vector<long>, 2> _irreps_decomp_per_atom;
84
85 // rotation matrices that rotate BACK to the basis of the DFT code basis.
86 // FIXME : CHECK vs INVERSE, EXPLAIN, WRITE NOTE.
87 nda::array<nda::matrix<dcomplex>, 2> _rotation_from_dft_to_local_basis;
88
89 // rotation matrix from the Ylm basis to the dft code
90 nda::array<nda::matrix<dcomplex>, 1> _rotation_from_spherical_to_dft_basis;
91
92 // dimension of the correlated space
93 long _dim_C = 0;
94
95 // atom names
96 std::vector<std::string> _atom_names = {};
97
99 friend void h5_read(h5::group g, std::string const &name, local_space &ls);
100 friend void h5_write(h5::group g, std::string const &name, local_space const &ls);
101
103 friend void mpi_broadcast(local_space &x, mpi::communicator c = {}, int root = 0) {
104 mpi::broadcast(x._spin_kind, c, root);
105 mpi::broadcast(x._atomic_shells, c, root);
106 mpi::broadcast(x._irreps_decomp_per_atom, c, root);
107 mpi::broadcast(x._rotation_from_dft_to_local_basis, c, root);
108 mpi::broadcast(x._rotation_from_spherical_to_dft_basis, c, root);
109 mpi::broadcast(x._dim_C, c, root);
110 mpi::broadcast(x._atom_names, c, root);
111 }
112
113 public:
115 bool operator==(local_space const &) const = default;
116
126 local_space(spin_kind_e spin_kind, std::vector<atomic_orbs> atomic_shells, nda::array<std::vector<long>, 2> irreps_decomp_per_atom,
127 nda::array<nda::matrix<dcomplex>, 2> rotation_from_dft_to_local_basis,
128 nda::array<nda::matrix<dcomplex>, 1> rotation_from_spherical_to_dft_basis);
129
132 local_space() = default;
135 // ---------------- sigma indices and co. ----------------
137
138
140 [[nodiscard]] spin_kind_e spin_kind() const { return _spin_kind; };
141
143 [[nodiscard]] long n_sigma() const { return _spin_kind == spin_kind_e::NonColinear ? 1 : 2; }
144
146 [[nodiscard]] std::vector<std::string> sigma_names() const {
147 return (_spin_kind == spin_kind_e::NonColinear ? std::vector{"ud"s} : std::vector{"up"s, "down"s});
148 }
149
150 // -------- Atomic shells and related functions -----------
152 [[nodiscard]] long dim() const { return _dim_C; }
153
155 [[nodiscard]] std::vector<atomic_orbs> const &atomic_shells() const { return _atomic_shells; }
156
158 [[nodiscard]] long n_atoms() const { return long(_atomic_shells.size()); }
159
160 // OP : explain the 2 indices : spin ?? [ a, σ] ?
162 [[nodiscard]] nda::array<std::vector<long>, 2> const &atoms_block_decomposition() const { return _irreps_decomp_per_atom; }
163
165 [[nodiscard]] nda::array<nda::matrix<dcomplex>, 2> const &rotation_from_dft_to_local_basis() const { return _rotation_from_dft_to_local_basis; }
166
168 [[nodiscard]] nda::array<nda::matrix<dcomplex>, 1> const &rotation_from_spherical_to_dft_basis() const {
169 return _rotation_from_spherical_to_dft_basis;
170 }
171
173 [[nodiscard]] long first_shell_of_its_equiv_cls(long idx) const;
174
176 [[nodiscard]] std::vector<std::string> atom_names() const { return _atom_names; }
177
179 [[nodiscard]] auto atomic_decomposition() const {
180 return atomic_shells() | stdv::transform([](auto const &s) { return s.dim; });
181 }
182
184
185 // -------- Atomic "view" methods for Green functions and matrices -----------
186
187 // FIXME : IT IS NOT A VIEW, IT IS A COPY
188 // Where do we use this ? do we want a view or a copy ?
190
198 template <typename Mesh> block2_gf<Mesh> atomic_view(block2_gf<Mesh> const &G_C) {
199 // FIXME : ASSERT check the dimension of G_C m x m , one a block, n_sigma ...
200 auto Gout = make_block2_gf(G_C(0, 0).mesh(), this->Gatom_block_shape());
201 auto n_sigma = G_C.size2();
202 for (auto sigma : range(n_sigma))
203 for (auto const &[atom, r_atom] : enumerated_sub_slices(this->atomic_decomposition())) {
204 Gout(atom, sigma).data() = G_C(0, sigma).data()(r_all, r_atom, r_atom);
205 }
206 return Gout;
207 }
208
216 nda::array<nda::matrix<dcomplex>, 2> atomic_view(nda::array<nda::matrix<dcomplex>, 2> const &matrix_C);
217
218 // -------- gf_structs for different block shapes -----------
219
221 [[nodiscard]] C2PY_IGNORE gf_struct2_t Gc_block_shape() const;
222
223 // OP : [a, \sigma] : what is a, sigma ?
226 auto res = nda::zeros<long>(_atomic_shells.size(), n_sigma());
227 for (auto const &[alpha, shell] : enumerate(_atomic_shells)) res(alpha, r_all) = shell.dim;
228 return {.names = {atom_names(), sigma_names()}, .dims = std::move(res)};
229 }
230
232 };
233
234 // -------- stream -----------
235
236 std::ostream &operator<<(std::ostream &out, local_space const &bd);
237
238 // -------- instantiations --------------
239
241 template block2_gf<imfreq> local_space::atomic_view(block2_gf<imfreq> const &G_C);
244} // 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.
friend void mpi_broadcast(local_space &x, mpi::communicator c={}, int root=0)
MPI broadcast.
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.
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
friend void mpi_broadcast(atomic_orbs &x, mpi::communicator c={}, int root=0)
MPI broadcast.
long dim
Dimension of the orbital space.