Quantum Phenomena Explorer 7.9.8
Interactive quantum-phenomena Explorer Tutor — source documentation
Loading...
Searching...
No Matches
wavefunctioncrosssection2d_tests.cpp
Go to the documentation of this file.
1/**
2 * @file wavefunctioncrosssection2d_tests.cpp
3 * @brief Implements regression and invariant tests for wavefunctioncrosssection2d tests.
4 * @ingroup qpe_tests
5 *
6 * Source: @c tests/wavefunctioncrosssection2d_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 {
21
22/**
23 * @brief Runs wave function cross section2 d tests.
24 * @param error Output diagnostic text on failure.
25 */
26bool runWaveFunctionCrossSection2DTests(std::string &error)
27{
28 error.clear();
29 ComplexField2D field(5u, 5u, 1.0f, 1.0f);
30 for (std::size_t y = 0u; y < field.height(); ++y) {
31 for (std::size_t x = 0u; x < field.width(); ++x) {
32 const float re = static_cast<float>(10u * y + x);
33 const float im = static_cast<float>(x) * 0.5f;
34 field(x, y) = ComplexField2D::Value(re, im);
35 }
36 }
37
38 const WaveFunctionCrossSection2DData horizontal =
41 if (horizontal.coordinate.size() != 5u ||
42 std::fabs(horizontal.actualPosition) > 1.0e-9) {
43 error = "horizontal section size or snapped position is wrong";
44 return false;
45 }
46 if (std::fabs(horizontal.realPart[3] - 23.0) > 1.0e-9) {
47 error = "horizontal section sampled the wrong row/value";
48 return false;
49 }
50 const double expectedP = 23.0 * 23.0 + 1.5 * 1.5;
51 if (std::fabs(horizontal.probability[3] - expectedP) > 1.0e-9) {
52 error = "probability value is inconsistent with complex sample";
53 return false;
54 }
55
56 const WaveFunctionCrossSection2DData vertical =
58 field, CrossSectionAxis::VerticalX, -1.1);
59 if (vertical.coordinate.size() != 5u ||
60 std::fabs(vertical.actualPosition + 1.0) > 1.0e-9) {
61 error = "vertical section size or snapped position is wrong";
62 return false;
63 }
64 if (std::fabs(vertical.realPart[4] - 41.0) > 1.0e-9) {
65 error = "vertical section sampled the wrong column/value";
66 return false;
67 }
68
69 return true;
70}
71
72} // namespace tests
73} // namespace qpe
Owning Cartesian grid of complex scalar samples.
std::size_t height() const noexcept
Returns the number of samples along Y.
std::complex< float > Value
std::size_t width() const noexcept
Returns the number of samples along X.
static WaveFunctionCrossSection2DData sample(const ComplexField2D &field, CrossSectionAxis axis, double position)
Performs sample.
Declares the complex scalar field container representing two-dimensional wave functions.
bool runWaveFunctionCrossSection2DTests(std::string &error)
Runs wave function cross section2 d tests.
Data structure used by the Wave Function Cross Section2D Data component.
Declares the wavefunctioncrosssection2d physics/numerical component used by QPE experiments.
Declares regression and invariant tests for wavefunctioncrosssection2d tests.