libri_utils.h Source File

LibRPA: libri_utils.h Source File
LibRPA
libri_utils.h
1 #pragma once
2 #include <utility>
3 #include <ostream>
4 #include <set>
5 #include <array>
6 #include "atoms.h"
7 #include "vector3_order.h"
8 #ifdef LIBRPA_USE_LIBRI
9 #include <RI/global/Tensor.h>
10 #else
11 #include "libri_stub.h"
12 #endif
13 
14 template <typename TA, typename Tcell>
16 {
17  typedef std::array<Tcell, 3> TC;
18  typedef std::pair<TA, TC> TAC;
19 };
20 
21 template <typename TA, typename Tcell, typename TAout = TA, typename Tcellout = Tcell>
22 std::pair<std::set<TAout>, std::set<typename libri_types<TAout, Tcellout>::TAC>>
23 get_s0_s1_for_comm_map2(const std::vector<std::pair<TA, TA>>& atpairs,
24  const std::vector<Vector3_Order<Tcell>>& cells)
25 {
26  std::set<TAout> set_s0;
27  std::set<typename libri_types<TAout, Tcellout>::TAC> set_s1;
28  for (const auto& atpair: atpairs)
29  {
30  set_s0.insert(atpair.first);
31  for (const auto& cell: cells)
32  {
33  typename libri_types<TA, Tcell>::TC c {cell.x, cell.y, cell.z};
34  set_s1.insert({atpair.second, c});
35  }
36  }
37  return {set_s0, set_s1};
38 }
39 
40 template <typename TA, typename TAout = TA>
41 std::pair<std::set<TAout>, std::set<TAout>>
42 get_s0_s1_for_comm_map2_first(const std::vector<std::pair<TA, TA>>& atpairs)
43 {
44  std::set<TAout> set_s0;
45  std::set<TAout> set_s1;
46  for (const auto& atpair: atpairs)
47  {
48  set_s0.insert(atpair.first);
49  set_s1.insert(atpair.second);
50  }
51  return {set_s0, set_s1};
52 }
53 
54 template <typename TA, typename TAout = TA>
55 std::pair<std::set<TAout>, std::set<TAout>>
56 get_s0_s1_for_comm_map2_first(const std::set<std::pair<TA, TA>>& atpairs)
57 {
58  std::set<TAout> set_s0;
59  std::set<TAout> set_s1;
60  for (const auto& atpair: atpairs)
61  {
62  set_s0.insert(atpair.first);
63  set_s1.insert(atpair.second);
64  }
65  return {set_s0, set_s1};
66 }
67 
68 #ifdef LIBRPA_USE_LIBRI
69 template <typename T>
70 std::ostream& operator<<(std::ostream& os, const RI::Tensor<T>& t)
71 {
72  switch (t.shape.size())
73  {
74  case 1:
75  {
76  for (size_t i0 = 0; i0 < t.shape[0]; ++i0) os << t(i0) << " ";
77  os << std::endl;
78  return os;
79  }
80  case 2:
81  {
82  for (size_t i0 = 0; i0 < t.shape[0]; ++i0)
83  {
84  for (size_t i1 = 0; i1 < t.shape[1]; ++i1)
85  os << (std::abs(t(i0, i1)) > 1E-10 ? t(i0, i1) : 0) << " ";
86  os << std::endl;
87  }
88  return os;
89  }
90  case 3:
91  {
92  os << "[" << std::endl;
93  for (size_t i0 = 0; i0 < t.shape[0]; ++i0)
94  {
95  for (size_t i1 = 0; i1 < t.shape[1]; ++i1)
96  {
97  for (size_t i2 = 0; i2 < t.shape[2]; ++i2) os << t(i0, i1, i2) << " ";
98  os << std::endl;
99  }
100  os << std::endl;
101  }
102  os << "]" << std::endl;
103  return os;
104  }
105  default:
106  throw std::invalid_argument(std::string(__FILE__) + " line " +
107  std::to_string(__LINE__));
108  }
109 }
110 #endif
Utilies to handle atomic model and related data.
Definition: libri_stub.h:19
Definition: vector3_order.h:15
Definition: libri_utils.h:16