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 : namespace pairinteraction { 10 : template <typename Scalar> 11 88 : BasisAtom<Scalar>::BasisAtom(Private /*unused*/, ketvec_t &&kets, std::string &&id_of_kets, 12 : Database &database) 13 88 : : Basis<BasisAtom<Scalar>>(std::move(kets)), id_of_kets(std::move(id_of_kets)), 14 176 : database(database) { 15 9364 : for (size_t i = 0; i < this->kets.size(); ++i) { 16 9276 : ket_id_to_ket_index[this->kets[i]->get_id_in_database()] = i; 17 : } 18 88 : } 19 : 20 : template <typename Scalar> 21 735 : Database &BasisAtom<Scalar>::get_database() const { 22 735 : return database; 23 : } 24 : 25 : template <typename Scalar> 26 222 : const std::string &BasisAtom<Scalar>::get_species() const { 27 222 : return this->kets[0]->get_species(); 28 : } 29 : 30 : template <typename Scalar> 31 1085182 : int BasisAtom<Scalar>::get_ket_index_from_id(size_t ket_id) const { 32 1085182 : if (ket_id_to_ket_index.count(ket_id) == 0) { 33 0 : return -1; 34 : } 35 1085182 : return ket_id_to_ket_index.at(ket_id); 36 : } 37 : 38 : template <typename Scalar> 39 2260 : const std::string &BasisAtom<Scalar>::get_id_of_kets() const { 40 2260 : return id_of_kets; 41 : } 42 : 43 : template <typename Scalar> 44 68 : Eigen::VectorX<Scalar> BasisAtom<Scalar>::get_matrix_elements(std::shared_ptr<const ket_t> ket, 45 : OperatorType type, int q) const { 46 68 : auto final = this->get_canonical_state_from_ket(ket); 47 68 : auto matrix_elements = 48 68 : this->get_database().get_matrix_elements(this->shared_from_this(), final, type, q); 49 : 50 68 : assert(static_cast<size_t>(matrix_elements.rows()) == 1); 51 68 : assert(static_cast<size_t>(matrix_elements.cols()) == this->get_number_of_states()); 52 : 53 136 : return matrix_elements.row(0); 54 68 : } 55 : 56 : template <typename Scalar> 57 : Eigen::SparseMatrix<Scalar, Eigen::RowMajor> 58 18 : BasisAtom<Scalar>::get_matrix_elements(std::shared_ptr<const Type> other, OperatorType type, 59 : int q) const { 60 18 : auto matrix_elements = 61 18 : this->get_database().get_matrix_elements(this->shared_from_this(), other, type, q); 62 : 63 18 : assert(static_cast<size_t>(matrix_elements.rows()) == other->get_number_of_states()); 64 18 : assert(static_cast<size_t>(matrix_elements.cols()) == this->get_number_of_states()); 65 : 66 18 : return matrix_elements; 67 0 : } 68 : 69 : // Explicit instantiations 70 : template class BasisAtom<double>; 71 : template class BasisAtom<std::complex<double>>; 72 : } // namespace pairinteraction