CDT++
Causal Dynamical Triangulations in C++
Loading...
Searching...
No Matches
Move_tracker.hpp
Go to the documentation of this file.
1/*******************************************************************************
2 Causal Dynamical Triangulations in C++ using CGAL
3
4 Copyright © 2021 Adam Getchell
5 ******************************************************************************/
6
10
11#ifndef CDT_PLUSPLUS_MOVE_TRACKER_HPP
12#define CDT_PLUSPLUS_MOVE_TRACKER_HPP
13
14#include <array>
15#include <cstddef>
16#include <gsl/util>
17#include <span>
18
19#include "Settings.hpp"
20#include "Utilities.hpp"
21
22namespace move_tracker
23{
24 static inline Int_precision constexpr NUMBER_OF_3D_MOVES = 5;
25 static inline Int_precision constexpr NUMBER_OF_4D_MOVES = 7;
26
30 enum class [[nodiscard("This contains data!")]] move_type{
31 TWO_THREE = 0, THREE_TWO = 1, TWO_SIX = 2, SIX_TWO = 3, FOUR_FOUR = 4};
32
39 template <typename Enumeration>
40 auto as_integer(Enumeration value) -> std::underlying_type_t<Enumeration>
41 {
42 return static_cast<std::underlying_type_t<Enumeration>>(value);
43 } // as_integer
44
50 inline auto as_move(int const move_choice) -> move_type
51 {
52 if (move_choice == 0) { return move_type::TWO_THREE; }
53 if (move_choice == 1) { return move_type::THREE_TWO; }
54 if (move_choice == 2) { return move_type::TWO_SIX; }
55 if (move_choice == 3) { return move_type::SIX_TWO; }
56 return move_type::FOUR_FOUR;
57 } // as_move
58
63 [[nodiscard]] inline auto generate_random_move_3() -> move_type
64 {
65 auto move_choice = utilities::generate_random_int(0, 4);
66#ifndef NDEBUG
67 fmt::print("Move choice = {}\n", move_choice);
68#endif
69 return as_move(move_choice);
70 } // generate_random_move_3
71
77 auto constexpr moves_per_dimension(Int_precision const dim) -> Int_precision
78 {
79 if (dim == 3) { return NUMBER_OF_3D_MOVES; }
80 if (dim == 4) { return NUMBER_OF_4D_MOVES; }
81 return 0; // Error condition
82 } // moves_per_dimension
83
88 template <typename ManifoldType>
90 {
91 using Container =
92 std::array<Int_precision, moves_per_dimension(ManifoldType::dimension)>;
93
94 Container moves = {0}; // NOLINT
95
96 public:
101 auto moves_view() const { return std::span(moves); }
102
108 auto operator[](gsl::index index) -> auto&
109 {
110 return gsl::at(moves, index);
111 } // operator[]
112
118 auto operator[](move_type const move) const -> auto&
119 {
120 return gsl::at(moves, as_integer(move));
121 } // operator[]
122
128 auto operator+=(MoveTracker const& rhs)
129 {
130 for (std::size_t i = 0; i < moves.size(); ++i)
131 {
132 moves[i] += rhs.moves[i];
133 }
134 return *this;
135 } // operator+=
136
141 auto total() const noexcept
142 {
143 return std::accumulate(moves.begin(), moves.end(), 0);
144 } // total
145
150 auto size() const noexcept { return moves.size(); }
151
152 // 3D
153
158 auto two_three_moves() -> auto& { return gsl::at(moves, 0); }
159
164 auto two_three_moves() const { return gsl::at(moves, 0); }
165
170 auto three_two_moves() -> auto& { return gsl::at(moves, 1); }
171
176 auto three_two_moves() const { return gsl::at(moves, 1); }
177
182 auto two_six_moves() -> auto& { return gsl::at(moves, 2); }
183
188 auto two_six_moves() const { return gsl::at(moves, 2); }
189
194 auto six_two_moves() -> auto& { return gsl::at(moves, 3); }
195
200 auto six_two_moves() const { return gsl::at(moves, 3); }
201
206 auto four_four_moves() -> auto& { return gsl::at(moves, 4); }
207
212 auto four_four_moves() const { return gsl::at(moves, 4); }
213
214 // 4D
216 auto two_four_moves() -> auto& { return gsl::at(moves, 0); }
217
219 auto two_four_moves() const { return gsl::at(moves, 0); }
220
222 auto four_two_moves() -> auto& { return gsl::at(moves, 1); }
223
225 auto four_two_moves() const { return gsl::at(moves, 1); }
226
228 auto three_three_moves() -> auto& { return gsl::at(moves, 2); }
229
231 auto three_three_moves() const { return gsl::at(moves, 2); }
232
234 auto four_six_moves() -> auto& { return gsl::at(moves, 3); }
235
237 auto four_six_moves() const { return gsl::at(moves, 3); }
238
240 auto six_four_moves() -> auto& { return gsl::at(moves, 4); }
241
243 auto six_four_moves() const { return gsl::at(moves, 4); }
244
246 auto two_eight_moves() -> auto& { return gsl::at(moves, 5); } // NOLINT
247
249 auto two_eight_moves() const { return gsl::at(moves, 5); } // NOLINT
250
252 auto eight_two_moves() -> auto& { return gsl::at(moves, 6); } // NOLINT
253
255 auto eight_two_moves() const { return gsl::at(moves, 6); } // NOLINT
256
258 void reset() { moves.fill(0); }
259 };
260
261} // namespace move_tracker
262
263#endif // CDT_PLUSPLUS_MOVE_TRACKER_HPP
auto generate_random_move_3() -> move_type
Generate random 3D ergodic move.
auto as_integer(Enumeration value) -> std::underlying_type_t< Enumeration >
Convert enum to integer.
move_type
The types of 3D ergodic moves.
auto constexpr moves_per_dimension(Int_precision const dim) -> Int_precision
Determine the ergodic moves for a given dimensionality.
auto as_move(int const move_choice) -> move_type
Convert integer to move_type.
Global integer and precision settings.
std::int_fast32_t Int_precision
Definition: Settings.hpp:31
Utility functions.
The data and methods to track ergodic moves.
auto operator+=(MoveTracker const &rhs)
The += operator for MoveTracker.
auto two_six_moves() const
Read access to (2,6) moves.
auto four_six_moves() const
Read access to (4,6) moves.
auto six_two_moves() const
Read access to (6,2) moves.
auto two_three_moves() const
Read access to (2,3) moves.
auto two_four_moves() const
Read access to (2,4) moves.
auto two_eight_moves() const
Read access to (2,8) moves.
auto two_six_moves() -> auto &
Write access to (2,6) moves.
auto three_three_moves() -> auto &
Write access to (3,3) moves.
auto three_three_moves() const
Read access to (3,3) moves.
auto two_eight_moves() -> auto &
Write access to (2,8) moves.
auto four_two_moves() const
Read access to (4,2) moves.
auto six_four_moves() const
Read access to (6,4) moves.
auto two_four_moves() -> auto &
Write access to (2,4) moves.
auto three_two_moves() const
Read access to (3,2) moves.
auto size() const noexcept
Container size.
auto four_six_moves() -> auto &
Write access to (4,6) moves.
auto four_two_moves() -> auto &
Write access to (4,2) moves.
auto total() const noexcept
Total moves.
auto moves_view() const
Get a view of the moves.
auto four_four_moves() -> auto &
Write access to (4,4) moves.
auto six_four_moves() -> auto &
Write access to (6,4) moves.
auto eight_two_moves() -> auto &
Write access to (8,2) moves.
void reset()
Reset all moves counts to zero.
auto operator[](gsl::index index) -> auto &
The [] operator for MoveTracker.
auto six_two_moves() -> auto &
Write access to (6,2) moves.
auto eight_two_moves() const
Read access to (8,2) moves.
auto three_two_moves() -> auto &
Write access to (3,2) moves.
auto operator[](move_type const move) const -> auto &
The [] operator for MoveTracker.
auto two_three_moves() -> auto &
Write access to (2,3) moves.
auto four_four_moves() const
Read access to (4,4) moves.