pairinteraction
A Rydberg Interaction Calculator
TransformationBuilderInterface.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2024 Pairinteraction Developers
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
5
8
9namespace pairinteraction {
10
11IndicesOfBlock::IndicesOfBlock(size_t start, size_t end) : start(start), end(end) {}
12
13size_t IndicesOfBlock::size() const { return end - start; }
14
15IndicesOfBlocksCreator::IndicesOfBlocksCreator(std::initializer_list<size_t> boundaries)
16 : boundaries(boundaries) {}
17
18void IndicesOfBlocksCreator::add(size_t boundary) { boundaries.insert(boundary); }
19
20std::vector<IndicesOfBlock> IndicesOfBlocksCreator::create() const {
21 std::vector<IndicesOfBlock> blocks;
22 if (boundaries.empty()) {
23 return blocks;
24 }
25
26 auto it = boundaries.begin();
27 size_t start = *it++;
28
29 while (it != boundaries.end()) {
30 blocks.emplace_back(start, *it);
31 start = *it++;
32 }
33
34 return blocks;
35}
36
38 return boundaries.empty() ? 0 : boundaries.size() - 1;
39}
40
41template <typename Scalar>
42Transformation<Scalar>::Transformation(Eigen::SparseMatrix<Scalar, Eigen::RowMajor> matrix,
43 std::vector<TransformationType> transformation_type)
44 : matrix(std::move(matrix)), transformation_type(std::move(transformation_type)) {}
45
46template <typename Scalar>
47Transformation<Scalar>::Transformation(Eigen::SparseMatrix<Scalar, Eigen::RowMajor> matrix)
48 : matrix(std::move(matrix)), transformation_type({TransformationType::ARBITRARY}) {}
49
50Sorting::Sorting(Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic> matrix,
51 std::vector<TransformationType> transformation_type)
52 : matrix(std::move(matrix)), transformation_type(std::move(transformation_type)) {}
53
54Sorting::Sorting(Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic> matrix)
55 : matrix(std::move(matrix)), transformation_type({TransformationType::ARBITRARY}) {}
56
57template <typename Scalar>
58Transformation<Scalar>
59TransformationBuilderInterface<Scalar>::get_rotator(const std::array<real_t, 3> &to_z_axis,
60 const std::array<real_t, 3> &to_y_axis) const {
61 auto euler_zyz_angles = euler::get_euler_angles(to_z_axis, to_y_axis);
62 return this->get_rotator(euler_zyz_angles[0], euler_zyz_angles[1], euler_zyz_angles[2]);
63}
64
65// Explicit instantiations
66// NOLINTBEGIN(bugprone-macro-parentheses, cppcoreguidelines-macro-usage)
67#define INSTANTIATE_TRANSFORMATION(SCALAR) \
68 template struct Transformation<SCALAR>; \
69 template class TransformationBuilderInterface<SCALAR>;
70// NOLINTEND(bugprone-macro-parentheses, cppcoreguidelines-macro-usage)
71
73INSTANTIATE_TRANSFORMATION(std::complex<double>)
74
75#undef INSTANTIATE_TRANSFORMATION
76} // namespace pairinteraction
#define INSTANTIATE_TRANSFORMATION(SCALAR)
IndicesOfBlocksCreator(std::initializer_list< size_t > boundaries)
std::vector< IndicesOfBlock > create() const
virtual Transformation< Scalar > get_rotator(real_t alpha, real_t beta, real_t gamma) const =0
std::array< Real, 3 > get_euler_angles(std::array< Real, 3 > to_z_axis, std::array< Real, 3 > to_y_axis)
Extract the Euler angles alpha, beta, gamma.
Definition: euler.hpp:61