LCOV - code coverage report
Current view: top level - src/basis - BasisAtom.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 29 31 93.5 %
Date: 2025-04-29 15:56:08 Functions: 12 14 85.7 %

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

Generated by: LCOV version 1.16