Line data Source code
1 : // SPDX-FileCopyrightText: 2024 PairInteraction Developers 2 : // SPDX-License-Identifier: LGPL-3.0-or-later 3 : 4 : #include "pairinteraction/basis/BasisAtom.hpp" 5 : 6 : #include "pairinteraction/database/Database.hpp" 7 : #include "pairinteraction/ket/KetAtom.hpp" 8 : 9 : #include <cassert> 10 : 11 : namespace pairinteraction { 12 : template <typename Scalar> 13 107 : BasisAtom<Scalar>::BasisAtom(Private /*unused*/, ketvec_t &&kets, std::string &&id_of_kets, 14 : Database &database) 15 107 : : Basis<BasisAtom<Scalar>>(std::move(kets)), id_of_kets(std::move(id_of_kets)), 16 214 : database(database) { 17 11396 : for (size_t i = 0; i < this->kets.size(); ++i) { 18 11289 : ket_id_to_ket_index[this->kets[i]->get_id_in_database()] = i; 19 : } 20 107 : } 21 : 22 : template <typename Scalar> 23 899 : Database &BasisAtom<Scalar>::get_database() const { 24 899 : return database; 25 : } 26 : 27 : template <typename Scalar> 28 297 : const std::string &BasisAtom<Scalar>::get_species() const { 29 297 : return this->kets[0]->get_species(); 30 : } 31 : 32 : template <typename Scalar> 33 1251702 : int BasisAtom<Scalar>::get_ket_index_from_id(size_t ket_id) const { 34 1251702 : if (ket_id_to_ket_index.count(ket_id) == 0) { 35 0 : return -1; 36 : } 37 1251702 : return ket_id_to_ket_index.at(ket_id); 38 : } 39 : 40 : template <typename Scalar> 41 2836 : const std::string &BasisAtom<Scalar>::get_id_of_kets() const { 42 2836 : return id_of_kets; 43 : } 44 : 45 : template <typename Scalar> 46 47 : Eigen::VectorX<Scalar> BasisAtom<Scalar>::get_matrix_elements(std::shared_ptr<const ket_t> ket, 47 : OperatorType type, int q) const { 48 47 : auto final = this->get_canonical_state_from_ket(ket); 49 47 : auto matrix_elements = 50 47 : this->get_database().get_matrix_elements(this->shared_from_this(), final, type, q); 51 : 52 47 : assert(static_cast<size_t>(matrix_elements.rows()) == 1); 53 47 : assert(static_cast<size_t>(matrix_elements.cols()) == this->get_number_of_states()); 54 : 55 94 : return matrix_elements.row(0); 56 47 : } 57 : 58 : template <typename Scalar> 59 : Eigen::SparseMatrix<Scalar, Eigen::RowMajor> 60 18 : BasisAtom<Scalar>::get_matrix_elements(std::shared_ptr<const Type> other, OperatorType type, 61 : int q) const { 62 18 : auto matrix_elements = 63 18 : this->get_database().get_matrix_elements(this->shared_from_this(), other, type, q); 64 : 65 18 : assert(static_cast<size_t>(matrix_elements.rows()) == other->get_number_of_states()); 66 18 : assert(static_cast<size_t>(matrix_elements.cols()) == this->get_number_of_states()); 67 : 68 18 : return matrix_elements; 69 0 : } 70 : 71 : // Explicit instantiations 72 : template class BasisAtom<double>; 73 : template class BasisAtom<std::complex<double>>; 74 : } // namespace pairinteraction