pairinteraction
A Rydberg Interaction Calculator
test_dipole_operator.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2024 Pairinteraction Developers
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
6
7#include <filesystem>
8#include <spdlog/spdlog.h>
9
10int main(int argc, char **argv) {
11 // Call the setup function to configure logging
13
14 // Create a database instance
15 std::filesystem::path database_dir;
16 bool download_missing = false;
17
18 for (int i = 1; i < argc; ++i) {
19 bool found = pairinteraction::args::parse_download_missing(i, argc, argv, download_missing);
20 if (!found) {
21 pairinteraction::args::parse_database_dir(i, argc, argv, database_dir);
22 }
23 }
24
25 pairinteraction::Database database(download_missing, true, database_dir);
26
27 // Test the calculation of a dipole operator
28 bool success = true;
29
30 // Create a dipole operator coupling two specific states
32 .set_species("Rb")
37 .create(database);
38
40 .set_species("Rb")
45 .create(database);
46
47 auto basis_ket1_ket2 =
48 pairinteraction::BasisAtomCreator<double>().append_ket(ket1).append_ket(ket2).create(
49 database);
50
53 double dipole_ket1_ket2_value = dipole_ket1_ket2.get_matrix().coeff(0, 1);
54
55 double reference = 1247.5985544327225;
56
57 if (std::abs(dipole_ket1_ket2_value - reference) >
58 10 * std::numeric_limits<double>::epsilon()) {
59 SPDLOG_ERROR("The dipole operator value is not correct. Value: {}", dipole_ket1_ket2_value);
60 success = false;
61 }
62
63 dipole_ket1_ket2 = 2 * dipole_ket1_ket2;
64 dipole_ket1_ket2_value = dipole_ket1_ket2.get_matrix().coeff(0, 1);
65
66 if (std::abs(dipole_ket1_ket2_value - 2 * reference) >
67 10 * std::numeric_limits<double>::epsilon()) {
68 SPDLOG_ERROR("The dipole operator value is not correct after multiplication by a scalar.");
69 success = false;
70 }
71
72 dipole_ket1_ket2 = dipole_ket1_ket2 + dipole_ket1_ket2;
73 dipole_ket1_ket2_value = dipole_ket1_ket2.get_matrix().coeff(0, 1);
74
75 if (std::abs(dipole_ket1_ket2_value - 4 * reference) >
76 10 * std::numeric_limits<double>::epsilon()) {
77 SPDLOG_ERROR("The dipole operator value is not correct after summation.");
78 success = false;
79 }
80
81 // Create dipole operators in a typical basis
83 .set_species("Sr88_singlet")
85 .restrict_quantum_number_l(0, 3)
86 .create(database);
87
94
95 if (dipole_0.get_matrix().rows() != 64) {
96 SPDLOG_ERROR("Wrong dimension.");
97 success = false;
98 }
99
100 if (dipole_p.get_matrix().rows() != 64) {
101 SPDLOG_ERROR("Wrong dimension.");
102 success = false;
103 }
104
105 if (dipole_m.get_matrix().rows() != 64) {
106 SPDLOG_ERROR("Wrong dimension.");
107 success = false;
108 }
109
110 if (dipole_0.get_matrix().nonZeros() != 288) {
111 SPDLOG_ERROR("Wrong number of non-zeros.");
112 success = false;
113 }
114
115 if (dipole_p.get_matrix().nonZeros() != 288) {
116 SPDLOG_ERROR("Wrong number of non-zeros.");
117 success = false;
118 }
119
120 if (dipole_m.get_matrix().nonZeros() != 288) {
121 SPDLOG_ERROR("Wrong number of non-zeros.");
122 success = false;
123 }
124
125 return success ? 0 : 1;
126}
Builder class for creating BasisAtom objects.
BasisAtomCreator< Scalar > & append_ket(const std::shared_ptr< const ket_t > &ket)
BasisAtomCreator< Scalar > & restrict_quantum_number_n(int min, int max)
Builder class for creating KetAtom objects.
KetAtomCreator & set_quantum_number_n(int value)
std::shared_ptr< const KetAtom > create(Database &database) const
KetAtomCreator & set_quantum_number_j(double value)
KetAtomCreator & set_quantum_number_l(double value)
KetAtomCreator & set_species(const std::string &value)
KetAtomCreator & set_quantum_number_m(double value)
const Eigen::SparseMatrix< scalar_t, Eigen::RowMajor > & get_matrix() const
Definition: Operator.cpp:74
bool parse_database_dir(int &i, int argc, char **const argv, std::filesystem::path &database_dir)
Definition: args.hpp:21
bool parse_download_missing(int &i, int argc, char **const argv, bool &download_missing)
Definition: args.hpp:11
void setup()
Definition: setup.cpp:18
int main(int argc, char **argv)