LCOV - code coverage report
Current view: top level - src/basis - BasisAtom.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 31 33 93.9 %
Date: 2026-04-17 09:20:02 Functions: 14 14 100.0 %

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

Generated by: LCOV version 1.16