pairinteraction
A Rydberg Interaction Calculator
BasisAtom.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2024 Pairinteraction Developers
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
5
8
9namespace pairinteraction {
10template <typename Scalar>
11BasisAtom<Scalar>::BasisAtom(Private /*unused*/, ketvec_t &&kets, std::string &&id_of_kets,
12 Database &database)
13 : Basis<BasisAtom<Scalar>>(std::move(kets)), id_of_kets(std::move(id_of_kets)),
14 database(database) {
15 for (size_t i = 0; i < this->kets.size(); ++i) {
16 ket_id_to_ket_index[this->kets[i]->get_id_in_database()] = i;
17 }
18}
19
20template <typename Scalar>
22 return database;
23}
24
25template <typename Scalar>
26const std::string &BasisAtom<Scalar>::get_species() const {
27 return this->kets[0]->get_species();
28}
29
30template <typename Scalar>
32 if (ket_id_to_ket_index.count(ket_id) == 0) {
33 return -1;
34 }
35 return ket_id_to_ket_index.at(ket_id);
36}
37
38template <typename Scalar>
39const std::string &BasisAtom<Scalar>::get_id_of_kets() const {
40 return id_of_kets;
41}
42
43template <typename Scalar>
45 OperatorType type, int q) const {
46 auto final = this->get_canonical_state_from_ket(ket);
47 auto matrix_elements =
48 this->get_database().get_matrix_elements(this->shared_from_this(), final, type, q);
49
50 assert(static_cast<size_t>(matrix_elements.rows()) == 1);
51 assert(static_cast<size_t>(matrix_elements.cols()) == this->get_number_of_states());
52
53 return matrix_elements.row(0);
54}
55
56template <typename Scalar>
57Eigen::SparseMatrix<Scalar, Eigen::RowMajor>
58BasisAtom<Scalar>::get_matrix_elements(std::shared_ptr<const Type> other, OperatorType type,
59 int q) const {
60 auto matrix_elements =
61 this->get_database().get_matrix_elements(this->shared_from_this(), other, type, q);
62
63 assert(static_cast<size_t>(matrix_elements.rows()) == other->get_number_of_states());
64 assert(static_cast<size_t>(matrix_elements.cols()) == this->get_number_of_states());
65
66 return matrix_elements;
67}
68
69// Explicit instantiations
70template class BasisAtom<double>;
71template class BasisAtom<std::complex<double>>;
72} // namespace pairinteraction
Class for creating a basis of atomic kets.
Definition: BasisAtom.hpp:40
int get_ket_index_from_id(size_t ket_id) const
Definition: BasisAtom.cpp:31
const std::string & get_id_of_kets() const
Definition: BasisAtom.cpp:39
BasisAtom(Private, ketvec_t &&kets, std::string &&id_of_kets, Database &database)
Definition: BasisAtom.cpp:11
typename traits::CrtpTraits< Type >::ketvec_t ketvec_t
Definition: BasisAtom.hpp:49
const std::string & get_species() const
Definition: BasisAtom.cpp:26
Database & get_database() const
Definition: BasisAtom.cpp:21
Eigen::VectorX< Scalar > get_matrix_elements(std::shared_ptr< const ket_t > ket, OperatorType type, int q=0) const override
Definition: BasisAtom.cpp:44
Base class for a basis.
Definition: Basis.hpp:41
Matrix< Type, Dynamic, 1 > VectorX