TRIQS/nda 2.0.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
doc_sym_overview.cpp
1#include <nda/nda.hpp>
2#include <nda/sym_grp.hpp>
3
4#include <array>
5#include <complex>
6#include <functional>
7#include <initializer_list>
8#include <iostream>
9#include <tuple>
10#include <vector>
11
12int main() {
13 constexpr int N = 3;
14
15 // typedefs for the symmetry group
16 using idx_t = std::array<long, 2>;
17 using sym_t = std::tuple<idx_t, nda::operation>;
18 using sym_func_t = std::function<sym_t(idx_t const &)>;
19
20 // create an hermitian matrix
21 auto A = nda::array<std::complex<double>, 2>::rand(N, N);
22 for (int i = 0; i < N; ++i) {
23 for (int j = i + 1; j < N; ++j) A(i, j) = std::conj(A(j, i));
24 }
25
26 // hermitian symmetry (satisfies nda::NdaSymmetry)
27 auto h_symmetry = [](idx_t const &x) {
28 idx_t xp = {x[1], x[0]};
29 return sym_t{xp, nda::operation{false, true}}; // sign flip = false, complex conjugate = true
30 };
31
32 // construct the symmetry group
33 auto grp = nda::sym_grp{A, std::vector<sym_func_t>{h_symmetry}};
34
35 // create an initializer function (satisfies nda::NdaInitFunc)
36 auto init_func = [&A](idx_t const &x) { return std::apply(A, x); };
37
38 // initialize a second array using the symmetry group and array A
40 grp.init(B, init_func);
41
42 // output A and B
43 std::cout << A << std::endl;
44 std::cout << B << std::endl;
45
46 // get representative data (should be a vector of size 6)
47 auto vec = grp.get_representative_data(A);
48 std::cout << "\n" << nda::array_view<std::complex<double>, 1>(vec) << std::endl;
49}
Class representing a symmetry group.
Definition sym_grp.hpp:135
basic_array_view< ValueType, Rank, Layout, 'A', default_accessor, borrowed<> > array_view
Alias template of an nda::basic_array_view with an 'A' algebra, nda::default_accessor and nda::borrow...
basic_array< ValueType, Rank, Layout, 'A', ContainerPolicy > array
Alias template of an nda::basic_array with an 'A' algebra.
Includes all relevant headers for the core nda library.
A structure to capture combinations of complex conjugation and sign flip operations.
Definition sym_grp.hpp:37
Provides tools to use symmetries with nda objects.