Quantum Phenomena Explorer 7.9.8
Interactive quantum-phenomena Explorer Tutor — source documentation
Loading...
Searching...
No Matches
quantumrevivals2d_tests.cpp
Go to the documentation of this file.
1/**
2 * @file quantumrevivals2d_tests.cpp
3 * @brief Implements regression and invariant tests for quantumrevivals2d tests.
4 * @ingroup qpe_tests
5 *
6 * Source: @c tests/quantumrevivals2d_tests.cpp. This file is part of Quantum Phenomena Explorer (QPE),
7 * maintained by Officina Turini. See LICENSE_IT.txt / LICENSE.txt for the
8 * QPE freeware source-available terms and THIRD_PARTY_NOTICES.txt for
9 * third-party components.
10 */
11
13
16
17#include <cmath>
18
19namespace qpe {
20namespace tests {
21namespace {
22
23/**
24 * @brief Creates box.
25 */
27{
28 PotentialScene2D scene;
29 const float half = 3.2f;
30 const float thickness = 1.28f;
31 const float centre = half + 0.5f * thickness;
32 const float span = 2.0f * (half + thickness);
33 for (int sign = -1; sign <= 1; sign += 2) {
34 PotentialObject2D vertical;
36 vertical.value = 120.0f;
37 vertical.centerX = sign * centre;
38 vertical.centerY = 0.0f;
39 vertical.width = thickness;
40 vertical.height = span;
41 scene.add(vertical);
42
43 PotentialObject2D horizontal;
45 horizontal.value = 120.0f;
46 horizontal.centerX = 0.0f;
47 horizontal.centerY = sign * centre;
48 horizontal.width = span;
49 horizontal.height = thickness;
50 scene.add(horizontal);
51 }
52 return scene;
53}
54
55/**
56 * @brief Performs close.
57 * @param a The a value used by the operation.
58 * @param b The b value used by the operation.
59 * @param tolerance The tolerance value used by the operation.
60 */
61bool close(double a, double b, double tolerance)
62{
63 return std::fabs(a - b) <= tolerance;
64}
65
66} // namespace
67
68/**
69 * @brief Runs quantum revivals2 d tests.
70 * @param errorMessage The error message value used by the operation.
71 */
72bool runQuantumRevivals2DTests(std::string &errorMessage)
73{
74 errorMessage.clear();
75 const PotentialScene2D scene = makeBox();
76 QuantumBoxGeometry2D geometry;
77 if (!QuantumRevivals2D::identifyBox(scene, geometry, nullptr)) {
78 errorMessage = "failed to identify valid revival box";
79 return false;
80 }
81 if (!close(geometry.innerWidth, 6.4, 1.0e-5) ||
82 !close(geometry.innerHeight, 6.4, 1.0e-5) ||
83 !close(geometry.wallPotential, 120.0, 1.0e-6)) {
84 errorMessage = "revival box geometry is incorrect";
85 return false;
86 }
87
88 const double expected = 4.0 * 6.4 * 6.4 / 3.14159265358979323846;
89 if (!close(QuantumRevivals2D::revivalTimeX(geometry, 1.0), expected, 1.0e-5) ||
90 !close(QuantumRevivals2D::revivalTimeY(geometry, 1.0), expected, 1.0e-5)) {
91 errorMessage = "hard-wall revival time is incorrect";
92 return false;
93 }
94
95 ComplexField2D field(32u, 32u, 0.25f, 0.25f);
97 packet.centerX = -0.75f;
98 packet.centerY = 0.25f;
99 packet.sigma = 0.6f;
100 packet.momentumX = 1.2f;
101 packet.momentumY = -0.7f;
102 GaussianPacket2D::initialize(field, packet);
103
104 if (!close(QuantumRevivals2D::fidelity(field, field), 1.0, 1.0e-12)) {
105 errorMessage = "self fidelity is not one";
106 return false;
107 }
108
109 const std::vector<float> marginal = QuantumRevivals2D::marginalProbabilityX(field);
110 if (marginal.size() != field.width()) {
111 errorMessage = "wrong marginal size";
112 return false;
113 }
114 double marginalNorm = 0.0;
115 for (float value : marginal) marginalNorm += value * field.dx();
116 if (!close(marginalNorm, field.norm2(), 2.0e-6)) {
117 errorMessage = "x marginal does not integrate to field norm";
118 return false;
119 }
120
121 QuantumRevivalHistory2D history(4u);
122 if (!history.captureReference(field) || !history.append(0.0, field)) {
123 errorMessage = "failed to capture/append revival history";
124 return false;
125 }
126 if (history.size() != 1u || !close(history.samples()[0].fidelity, 1.0, 1.0e-12)) {
127 errorMessage = "initial revival history sample is inconsistent";
128 return false;
129 }
130
131 PotentialScene2D invalid = scene;
132 PotentialObject2D circle;
134 circle.value = 1.0f;
135 circle.radius = 1.0f;
136 invalid.add(circle);
137 QuantumBoxGeometry2D invalidGeometry;
138 if (QuantumRevivals2D::identifyBox(invalid, invalidGeometry, nullptr)) {
139 errorMessage = "invalid mixed scene accepted as revival box";
140 return false;
141 }
142
143 return true;
144}
145
146} // namespace tests
147} // namespace qpe
Owning Cartesian grid of complex scalar samples.
double norm2() const noexcept
Returns the discrete integral of |psi|^2 including dx*dy.
float dx() const noexcept
Returns the X grid spacing.
std::size_t width() const noexcept
Returns the number of samples along X.
static void initialize(ComplexField2D &field, const GaussianPacket2DParams &params)
Initializes ialize.
Implements the Potential Scene2D component.
std::uint64_t add(PotentialObject2D object)
Performs add.
Implements the Quantum Revival History2D component.
bool captureReference(const ComplexField2D &field)
Carries out capture reference.
std::size_t size() const noexcept
Returns size.
const std::vector< QuantumRevivalSample2D > & samples() const noexcept
Samples s.
bool append(double time, const ComplexField2D &field)
Carries out append.
static std::vector< float > marginalProbabilityX(const ComplexField2D &field)
Performs marginal probability x.
static double revivalTimeY(const QuantumBoxGeometry2D &geometry, double mass, double hbar=1.0) noexcept
Performs revival time y.
static double revivalTimeX(const QuantumBoxGeometry2D &geometry, double mass, double hbar=1.0) noexcept
Performs revival time x.
static bool identifyBox(const PotentialScene2D &scene, QuantumBoxGeometry2D &geometry, std::string *reason=nullptr) noexcept
Returns identify box.
static double fidelity(const ComplexField2D &reference, const ComplexField2D &field) noexcept
Performs fidelity.
Declares the gaussianpacket2d physics/numerical component used by QPE experiments.
bool runQuantumRevivals2DTests(std::string &errorMessage)
Runs quantum revivals2 d tests.
Declares the quantumrevivals2d physics/numerical component used by QPE experiments.
Declares regression and invariant tests for quantumrevivals2d tests.
Configuration values for Gaussian Packet2D Params.
Data structure used by the Potential Object2D component.
PotentialObjectType2D type
Data structure used by the Quantum Box Geometry2D component.