Line data Source code
1 : // SPDX-FileCopyrightText: 2024 Pairinteraction Developers 2 : // SPDX-License-Identifier: LGPL-3.0-or-later 3 : 4 : #include "pairinteraction/interfaces/TransformationBuilderInterface.hpp" 5 : 6 : #include "pairinteraction/enums/TransformationType.hpp" 7 : #include "pairinteraction/utils/euler.hpp" 8 : 9 : namespace pairinteraction { 10 : 11 344 : IndicesOfBlock::IndicesOfBlock(size_t start, size_t end) : start(start), end(end) {} 12 : 13 680 : size_t IndicesOfBlock::size() const { return end - start; } 14 : 15 112 : IndicesOfBlocksCreator::IndicesOfBlocksCreator(std::initializer_list<size_t> boundaries) 16 112 : : boundaries(boundaries) {} 17 : 18 232 : void IndicesOfBlocksCreator::add(size_t boundary) { boundaries.insert(boundary); } 19 : 20 112 : std::vector<IndicesOfBlock> IndicesOfBlocksCreator::create() const { 21 112 : std::vector<IndicesOfBlock> blocks; 22 112 : if (boundaries.empty()) { 23 0 : return blocks; 24 : } 25 : 26 112 : auto it = boundaries.begin(); 27 112 : size_t start = *it++; 28 : 29 456 : while (it != boundaries.end()) { 30 344 : blocks.emplace_back(start, *it); 31 344 : start = *it++; 32 : } 33 : 34 112 : return blocks; 35 0 : } 36 : 37 0 : size_t IndicesOfBlocksCreator::size() const { 38 0 : return boundaries.empty() ? 0 : boundaries.size() - 1; 39 : } 40 : 41 : template <typename Scalar> 42 110 : Transformation<Scalar>::Transformation(Eigen::SparseMatrix<Scalar, Eigen::RowMajor> matrix, 43 : std::vector<TransformationType> transformation_type) 44 110 : : matrix(std::move(matrix)), transformation_type(std::move(transformation_type)) {} 45 : 46 : template <typename Scalar> 47 112 : Transformation<Scalar>::Transformation(Eigen::SparseMatrix<Scalar, Eigen::RowMajor> matrix) 48 112 : : matrix(std::move(matrix)), transformation_type({TransformationType::ARBITRARY}) {} 49 : 50 0 : Sorting::Sorting(Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic> matrix, 51 0 : std::vector<TransformationType> transformation_type) 52 0 : : matrix(std::move(matrix)), transformation_type(std::move(transformation_type)) {} 53 : 54 0 : Sorting::Sorting(Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic> matrix) 55 0 : : matrix(std::move(matrix)), transformation_type({TransformationType::ARBITRARY}) {} 56 : 57 : template <typename Scalar> 58 : Transformation<Scalar> 59 0 : TransformationBuilderInterface<Scalar>::get_rotator(const std::array<real_t, 3> &to_z_axis, 60 : const std::array<real_t, 3> &to_y_axis) const { 61 0 : auto euler_zyz_angles = euler::get_euler_angles(to_z_axis, to_y_axis); 62 0 : 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 : 72 : INSTANTIATE_TRANSFORMATION(double) 73 : INSTANTIATE_TRANSFORMATION(std::complex<double>) 74 : 75 : #undef INSTANTIATE_TRANSFORMATION 76 : } // namespace pairinteraction