TRIQS/nda
2.0.0
Multi-dimensional array library for C++
Toggle main menu visibility
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
12
int
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
39
nda::array<std::complex<double>
, 2> B(N, N);
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
}
nda::sym_grp
Class representing a symmetry group.
Definition
sym_grp.hpp:135
nda::array_view
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...
Definition
declarations.hpp:75
nda::array
basic_array< ValueType, Rank, Layout, 'A', ContainerPolicy > array
Alias template of an nda::basic_array with an 'A' algebra.
Definition
declarations.hpp:64
nda.hpp
Includes all relevant headers for the core nda library.
nda::operation
A structure to capture combinations of complex conjugation and sign flip operations.
Definition
sym_grp.hpp:37
sym_grp.hpp
Provides tools to use symmetries with nda objects.
doc
examples
doc_sym_overview.cpp
Generated by
1.17.0