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 1025 : BasisAtom<Scalar>::BasisAtom(Private /*unused*/, ketvec_t &&kets, std::string &&canonical_basis_id, 14 : Database &database) 15 1025 : : Basis<BasisAtom<Scalar>>(std::move(kets)), canonical_basis_id(std::move(canonical_basis_id)), 16 2050 : database(database) { 17 40825 : for (size_t i = 0; i < this->kets.size(); ++i) { 18 39800 : ket_id_to_ket_index[this->kets[i]->get_id_in_database()] = i; 19 : } 20 1025 : } 21 : 22 : template <typename Scalar> 23 14421 : Database &BasisAtom<Scalar>::get_database() const { 24 14421 : return database; 25 : } 26 : 27 : template <typename Scalar> 28 10794 : const std::string &BasisAtom<Scalar>::get_species() const { 29 10794 : return this->kets[0]->get_species(); 30 : } 31 : 32 : template <typename Scalar> 33 1580562 : int BasisAtom<Scalar>::get_ket_index_from_id(size_t ket_id) const { 34 1580562 : if (!ket_id_to_ket_index.contains(ket_id)) { 35 0 : return -1; 36 : } 37 1580562 : return ket_id_to_ket_index.at(ket_id); 38 : } 39 : 40 : template <typename Scalar> 41 9614 : const std::string &BasisAtom<Scalar>::get_canonical_basis_id() const { 42 9614 : return canonical_basis_id; 43 : } 44 : 45 : template <typename Scalar> 46 : Eigen::SparseMatrix<Scalar, Eigen::RowMajor> 47 573 : BasisAtom<Scalar>::get_matrix_elements(std::shared_ptr<const Type> other, OperatorType type, 48 : int q) const { 49 573 : auto matrix_elements = this->get_database().get_matrix_elements_in_canonical_basis( 50 : this->shared_from_this(), other, type, q); 51 573 : matrix_elements = 52 573 : other->get_coefficients().adjoint() * matrix_elements * this->get_coefficients(); 53 : 54 573 : assert(static_cast<size_t>(matrix_elements.rows()) == other->get_number_of_states()); 55 573 : assert(static_cast<size_t>(matrix_elements.cols()) == this->get_number_of_states()); 56 : 57 573 : return matrix_elements; 58 0 : } 59 : 60 : // Explicit instantiations 61 : template class BasisAtom<double>; 62 : template class BasisAtom<std::complex<double>>; 63 : } // namespace pairinteraction