Line data Source code
1 : // SPDX-FileCopyrightText: 2024 PairInteraction Developers 2 : // SPDX-License-Identifier: LGPL-3.0-or-later 3 : 4 : #pragma once 5 : 6 : #include "pairinteraction/utils/eigen_assertion.hpp" 7 : #include "pairinteraction/utils/eigen_compat.hpp" 8 : #include "pairinteraction/utils/traits.hpp" 9 : 10 : #include <Eigen/Dense> 11 : #include <array> 12 : #include <complex> 13 : #include <limits> 14 : #include <stdexcept> 15 : #include <unsupported/Eigen/KroneckerProduct> 16 : 17 : using namespace std::complex_literals; 18 : 19 : namespace pairinteraction::spherical { 20 : 21 : extern const Eigen::Matrix3<std::complex<double>> CARTESIAN_TO_SPHERICAL_KAPPA1; 22 : extern const Eigen::Matrix<std::complex<double>, 6, 9> CARTESIAN_TO_SPHERICAL_KAPPA2; 23 : 24 : template <typename Scalar> 25 2752 : inline const Eigen::MatrixX<Scalar> &get_transformator(int kappa) { 26 2752 : if (kappa == 1) { 27 : if constexpr (traits::NumTraits<Scalar>::is_complex_v) { 28 1975 : static const auto mat = Eigen::MatrixX<Scalar>( 29 1 : spherical::CARTESIAN_TO_SPHERICAL_KAPPA1.template cast<Scalar>()); 30 1957 : return mat; 31 : } 32 721 : static const auto mat = Eigen::MatrixX<Scalar>( 33 0 : spherical::CARTESIAN_TO_SPHERICAL_KAPPA1.real().template cast<Scalar>()); 34 718 : return mat; 35 : } 36 58 : if (kappa == 2) { 37 : if constexpr (traits::NumTraits<Scalar>::is_complex_v) { 38 58 : static const auto mat = Eigen::MatrixX<Scalar>( 39 1 : spherical::CARTESIAN_TO_SPHERICAL_KAPPA2.template cast<Scalar>()); 40 57 : return mat; 41 : } 42 4 : static const auto mat = Eigen::MatrixX<Scalar>( 43 2 : spherical::CARTESIAN_TO_SPHERICAL_KAPPA2.real().template cast<Scalar>()); 44 3 : return mat; 45 : } 46 0 : throw std::invalid_argument("Invalid kappa value. Must be 1 or 2."); 47 : } 48 : } // namespace pairinteraction::spherical