Quantum Phenomena Explorer 7.9.8
Interactive quantum-phenomena Explorer Tutor — source documentation
Loading...
Searching...
No Matches
blochoscillations2d_tests.cpp
Go to the documentation of this file.
1/**
2 * @file blochoscillations2d_tests.cpp
3 * @brief Implements regression and invariant tests for blochoscillations2d tests.
4 * @ingroup qpe_tests
5 *
6 * Source: @c tests/blochoscillations2d_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
15
16#include <cmath>
17
18namespace qpe {
19namespace tests {
20namespace {
21
22/**
23 * @brief Performs close.
24 * @param a The a value used by the operation.
25 * @param b The b value used by the operation.
26 * @param tolerance The tolerance value used by the operation.
27 */
28bool close(double a, double b, double tolerance = 1.0e-9)
29{
30 return std::fabs(a - b) <= tolerance;
31}
32
33/**
34 * @brief Creates scene.
35 */
37{
38 PotentialScene2D scene;
39 for (int i = -4; i <= 4; ++i) {
42 well.value = -1.0f;
43 well.centerX = static_cast<float>(2.56 * i);
44 well.centerY = 0.0f;
45 well.width = 1.28f;
46 well.height = 40.96f;
47 scene.add(well);
48 }
51 force.value = 0.0f;
52 force.slopeX = 0.08f;
53 force.slopeY = 0.0f;
54 scene.add(force);
55 return scene;
56}
57
58} // namespace
59
60/**
61 * @brief Runs bloch oscillations2 d tests.
62 * @param errorMessage The error message value used by the operation.
63 */
64bool runBlochOscillations2DTests(std::string &errorMessage)
65{
66 errorMessage.clear();
67 const PotentialScene2D scene = makeScene();
69 if (!BlochOscillations2D::identify(scene, geometry, nullptr)) { errorMessage = "failed to identify valid lattice"; return false; }
70 if (geometry.wellCount != 9) { errorMessage = "wrong lattice well count"; return false; }
71 if (!close(geometry.spacing, 2.56, 1.0e-6)) { errorMessage = "wrong lattice spacing"; return false; }
72 if (!close(geometry.wellWidth, 1.28, 1.0e-6)) { errorMessage = "wrong well width"; return false; }
73 if (!close(geometry.wellDepth, 1.0, 1.0e-9)) { errorMessage = "wrong well depth"; return false; }
74 if (!close(geometry.forceX, -0.08, 1.0e-7)) { errorMessage = "wrong force sign/magnitude"; return false; }
75
76 const double period = BlochOscillations2D::blochPeriod(geometry, 1.0);
77 const double expected = 2.0 * 3.14159265358979323846 / (0.08 * 2.56);
78 if (!close(period, expected, 1.0e-5)) { errorMessage = "wrong Bloch period"; return false; }
79
80 const double edge = BlochOscillations2D::zoneEdgeMomentum(geometry, 1.0);
81 if (!close(edge, 3.14159265358979323846 / 2.56, 1.0e-6)) { errorMessage = "wrong Brillouin-zone edge"; return false; }
82
83 const double p0 = 0.0;
84 if (!close(BlochOscillations2D::reducedZoneMomentum(geometry, p0, 0.0), 0.0, 1.0e-12)) { errorMessage = "wrong initial reduced momentum"; return false; }
85 if (!close(BlochOscillations2D::reducedZoneMomentum(geometry, p0, period), 0.0, 1.0e-6)) { errorMessage = "reduced momentum does not repeat after one period"; return false; }
86 if (!close(std::fabs(BlochOscillations2D::reducedZoneMomentum(geometry, p0, 0.5 * period)),
87 edge, 1.0e-6)) { errorMessage = "reduced momentum does not reach zone edge at half period"; return false; }
88
89 PotentialScene2D invalid = scene;
92 extra.radius = 1.0f;
93 extra.value = 1.0f;
94 invalid.add(extra);
95 BlochLatticeGeometry2D invalidGeometry;
96 if (BlochOscillations2D::identify(invalid, invalidGeometry, nullptr)) { errorMessage = "invalid mixed scene accepted"; return false; }
97
98 return true;
99}
100
101} // namespace tests
102} // namespace qpe
Declares the blochoscillations2d physics/numerical component used by QPE experiments.
Declares regression and invariant tests for blochoscillations2d tests.
static bool identify(const PotentialScene2D &scene, BlochLatticeGeometry2D &geometry, std::string *reason=nullptr) noexcept
Returns identify.
static double reducedZoneMomentum(const BlochLatticeGeometry2D &geometry, double initialMomentum, double time, double hbar=1.0) noexcept
Performs reduced zone momentum.
static double zoneEdgeMomentum(const BlochLatticeGeometry2D &geometry, double hbar=1.0) noexcept
Performs zone edge momentum.
static double blochPeriod(const BlochLatticeGeometry2D &geometry, double hbar=1.0) noexcept
Performs bloch period.
Implements the Potential Scene2D component.
std::uint64_t add(PotentialObject2D object)
Performs add.
bool close(double a, double b, double tolerance=1.0e-9)
Performs close.
bool runBlochOscillations2DTests(std::string &errorMessage)
Runs bloch oscillations2 d tests.
Data structure used by the Bloch Lattice Geometry2D component.
Data structure used by the Potential Object2D component.
PotentialObjectType2D type